Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
01e58d8e | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
8 | ||
9 | #include <linux/moduleparam.h> | |
10 | #include <linux/vmalloc.h> | |
1da177e4 | 11 | #include <linux/delay.h> |
39a11240 | 12 | #include <linux/kthread.h> |
e1e82b6f | 13 | #include <linux/mutex.h> |
3420d36c | 14 | #include <linux/kobject.h> |
5a0e3ad6 | 15 | #include <linux/slab.h> |
1da177e4 LT |
16 | |
17 | #include <scsi/scsi_tcq.h> | |
18 | #include <scsi/scsicam.h> | |
19 | #include <scsi/scsi_transport.h> | |
20 | #include <scsi/scsi_transport_fc.h> | |
21 | ||
22 | /* | |
23 | * Driver version | |
24 | */ | |
25 | char qla2x00_version_str[40]; | |
26 | ||
27 | /* | |
28 | * SRB allocation cache | |
29 | */ | |
e18b890b | 30 | static struct kmem_cache *srb_cachep; |
1da177e4 | 31 | |
1da177e4 LT |
32 | int ql2xlogintimeout = 20; |
33 | module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR); | |
34 | MODULE_PARM_DESC(ql2xlogintimeout, | |
35 | "Login timeout value in seconds."); | |
36 | ||
a7b61842 | 37 | int qlport_down_retry; |
1da177e4 LT |
38 | module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); |
39 | MODULE_PARM_DESC(qlport_down_retry, | |
900d9f98 | 40 | "Maximum number of command retries to a port that returns " |
1da177e4 LT |
41 | "a PORT-DOWN status."); |
42 | ||
1da177e4 LT |
43 | int ql2xplogiabsentdevice; |
44 | module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); | |
45 | MODULE_PARM_DESC(ql2xplogiabsentdevice, | |
46 | "Option to enable PLOGI to devices that are not present after " | |
900d9f98 | 47 | "a Fabric scan. This is needed for several broken switches. " |
1da177e4 LT |
48 | "Default is 0 - no PLOGI. 1 - perfom PLOGI."); |
49 | ||
1da177e4 LT |
50 | int ql2xloginretrycount = 0; |
51 | module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR); | |
52 | MODULE_PARM_DESC(ql2xloginretrycount, | |
53 | "Specify an alternate value for the NVRAM login retry count."); | |
54 | ||
a7a167bf AV |
55 | int ql2xallocfwdump = 1; |
56 | module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR); | |
57 | MODULE_PARM_DESC(ql2xallocfwdump, | |
58 | "Option to enable allocation of memory for a firmware dump " | |
59 | "during HBA initialization. Memory allocation requirements " | |
60 | "vary by ISP type. Default is 1 - allocate memory."); | |
61 | ||
11010fec | 62 | int ql2xextended_error_logging; |
27d94035 | 63 | module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR); |
11010fec | 64 | MODULE_PARM_DESC(ql2xextended_error_logging, |
0181944f AV |
65 | "Option to enable extended error logging, " |
66 | "Default is 0 - no logging. 1 - log errors."); | |
67 | ||
1da177e4 LT |
68 | static void qla2x00_free_device(scsi_qla_host_t *); |
69 | ||
7e47e5ca | 70 | int ql2xfdmienable=1; |
cca5335c AV |
71 | module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR); |
72 | MODULE_PARM_DESC(ql2xfdmienable, | |
73 | "Enables FDMI registratons " | |
74 | "Default is 0 - no FDMI. 1 - perfom FDMI."); | |
75 | ||
df7baa50 AV |
76 | #define MAX_Q_DEPTH 32 |
77 | static int ql2xmaxqdepth = MAX_Q_DEPTH; | |
78 | module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR); | |
79 | MODULE_PARM_DESC(ql2xmaxqdepth, | |
80 | "Maximum queue depth to report for target devices."); | |
81 | ||
e5896bd5 AV |
82 | int ql2xiidmaenable=1; |
83 | module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR); | |
84 | MODULE_PARM_DESC(ql2xiidmaenable, | |
85 | "Enables iIDMA settings " | |
86 | "Default is 1 - perform iIDMA. 0 - no iIDMA."); | |
87 | ||
73208dfd AC |
88 | int ql2xmaxqueues = 1; |
89 | module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR); | |
90 | MODULE_PARM_DESC(ql2xmaxqueues, | |
91 | "Enables MQ settings " | |
92 | "Default is 1 for single queue. Set it to number \ | |
93 | of queues in MQ mode."); | |
68ca949c AC |
94 | |
95 | int ql2xmultique_tag; | |
96 | module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR); | |
97 | MODULE_PARM_DESC(ql2xmultique_tag, | |
98 | "Enables CPU affinity settings for the driver " | |
99 | "Default is 0 for no affinity of request and response IO. " | |
100 | "Set it to 1 to turn on the cpu affinity."); | |
e337d907 AV |
101 | |
102 | int ql2xfwloadbin; | |
103 | module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR); | |
104 | MODULE_PARM_DESC(ql2xfwloadbin, | |
105 | "Option to specify location from which to load ISP firmware:\n" | |
106 | " 2 -- load firmware via the request_firmware() (hotplug)\n" | |
107 | " interface.\n" | |
108 | " 1 -- load firmware from flash.\n" | |
109 | " 0 -- use default semantics.\n"); | |
110 | ||
ae97c91e AV |
111 | int ql2xetsenable; |
112 | module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR); | |
113 | MODULE_PARM_DESC(ql2xetsenable, | |
114 | "Enables firmware ETS burst." | |
115 | "Default is 0 - skip ETS enablement."); | |
116 | ||
1da177e4 | 117 | /* |
fa2a1ce5 | 118 | * SCSI host template entry points |
1da177e4 LT |
119 | */ |
120 | static int qla2xxx_slave_configure(struct scsi_device * device); | |
f4f051eb | 121 | static int qla2xxx_slave_alloc(struct scsi_device *); |
1e99e33a AV |
122 | static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time); |
123 | static void qla2xxx_scan_start(struct Scsi_Host *); | |
f4f051eb | 124 | static void qla2xxx_slave_destroy(struct scsi_device *); |
a5326f86 | 125 | static int qla2xxx_queuecommand(struct scsi_cmnd *cmd, |
fca29703 | 126 | void (*fn)(struct scsi_cmnd *)); |
1da177e4 LT |
127 | static int qla2xxx_eh_abort(struct scsi_cmnd *); |
128 | static int qla2xxx_eh_device_reset(struct scsi_cmnd *); | |
523ec773 | 129 | static int qla2xxx_eh_target_reset(struct scsi_cmnd *); |
1da177e4 LT |
130 | static int qla2xxx_eh_bus_reset(struct scsi_cmnd *); |
131 | static int qla2xxx_eh_host_reset(struct scsi_cmnd *); | |
1da177e4 | 132 | |
e881a172 | 133 | static int qla2x00_change_queue_depth(struct scsi_device *, int, int); |
ce7e4af7 AV |
134 | static int qla2x00_change_queue_type(struct scsi_device *, int); |
135 | ||
a5326f86 | 136 | struct scsi_host_template qla2xxx_driver_template = { |
1da177e4 | 137 | .module = THIS_MODULE, |
cb63067a | 138 | .name = QLA2XXX_DRIVER_NAME, |
a5326f86 | 139 | .queuecommand = qla2xxx_queuecommand, |
fca29703 AV |
140 | |
141 | .eh_abort_handler = qla2xxx_eh_abort, | |
142 | .eh_device_reset_handler = qla2xxx_eh_device_reset, | |
523ec773 | 143 | .eh_target_reset_handler = qla2xxx_eh_target_reset, |
fca29703 AV |
144 | .eh_bus_reset_handler = qla2xxx_eh_bus_reset, |
145 | .eh_host_reset_handler = qla2xxx_eh_host_reset, | |
146 | ||
147 | .slave_configure = qla2xxx_slave_configure, | |
148 | ||
149 | .slave_alloc = qla2xxx_slave_alloc, | |
150 | .slave_destroy = qla2xxx_slave_destroy, | |
ed677086 AV |
151 | .scan_finished = qla2xxx_scan_finished, |
152 | .scan_start = qla2xxx_scan_start, | |
ce7e4af7 AV |
153 | .change_queue_depth = qla2x00_change_queue_depth, |
154 | .change_queue_type = qla2x00_change_queue_type, | |
fca29703 AV |
155 | .this_id = -1, |
156 | .cmd_per_lun = 3, | |
157 | .use_clustering = ENABLE_CLUSTERING, | |
158 | .sg_tablesize = SG_ALL, | |
159 | ||
160 | .max_sectors = 0xFFFF, | |
afb046e2 | 161 | .shost_attrs = qla2x00_host_attrs, |
fca29703 AV |
162 | }; |
163 | ||
1da177e4 | 164 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; |
2c3dfe3f | 165 | struct scsi_transport_template *qla2xxx_transport_vport_template = NULL; |
1da177e4 | 166 | |
1da177e4 LT |
167 | /* TODO Convert to inlines |
168 | * | |
169 | * Timer routines | |
170 | */ | |
1da177e4 | 171 | |
2c3dfe3f | 172 | __inline__ void |
e315cd28 | 173 | qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval) |
1da177e4 | 174 | { |
e315cd28 AC |
175 | init_timer(&vha->timer); |
176 | vha->timer.expires = jiffies + interval * HZ; | |
177 | vha->timer.data = (unsigned long)vha; | |
178 | vha->timer.function = (void (*)(unsigned long))func; | |
179 | add_timer(&vha->timer); | |
180 | vha->timer_active = 1; | |
1da177e4 LT |
181 | } |
182 | ||
183 | static inline void | |
e315cd28 | 184 | qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval) |
1da177e4 | 185 | { |
e315cd28 | 186 | mod_timer(&vha->timer, jiffies + interval * HZ); |
1da177e4 LT |
187 | } |
188 | ||
a824ebb3 | 189 | static __inline__ void |
e315cd28 | 190 | qla2x00_stop_timer(scsi_qla_host_t *vha) |
1da177e4 | 191 | { |
e315cd28 AC |
192 | del_timer_sync(&vha->timer); |
193 | vha->timer_active = 0; | |
1da177e4 LT |
194 | } |
195 | ||
1da177e4 LT |
196 | static int qla2x00_do_dpc(void *data); |
197 | ||
198 | static void qla2x00_rst_aen(scsi_qla_host_t *); | |
199 | ||
73208dfd AC |
200 | static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t, |
201 | struct req_que **, struct rsp_que **); | |
e315cd28 AC |
202 | static void qla2x00_mem_free(struct qla_hw_data *); |
203 | static void qla2x00_sp_free_dma(srb_t *); | |
1da177e4 | 204 | |
1da177e4 | 205 | /* -------------------------------------------------------------------------- */ |
73208dfd AC |
206 | static int qla2x00_alloc_queues(struct qla_hw_data *ha) |
207 | { | |
2afa19a9 | 208 | ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues, |
73208dfd AC |
209 | GFP_KERNEL); |
210 | if (!ha->req_q_map) { | |
211 | qla_printk(KERN_WARNING, ha, | |
212 | "Unable to allocate memory for request queue ptrs\n"); | |
213 | goto fail_req_map; | |
214 | } | |
215 | ||
2afa19a9 | 216 | ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues, |
73208dfd AC |
217 | GFP_KERNEL); |
218 | if (!ha->rsp_q_map) { | |
219 | qla_printk(KERN_WARNING, ha, | |
220 | "Unable to allocate memory for response queue ptrs\n"); | |
221 | goto fail_rsp_map; | |
222 | } | |
223 | set_bit(0, ha->rsp_qid_map); | |
224 | set_bit(0, ha->req_qid_map); | |
225 | return 1; | |
226 | ||
227 | fail_rsp_map: | |
228 | kfree(ha->req_q_map); | |
229 | ha->req_q_map = NULL; | |
230 | fail_req_map: | |
231 | return -ENOMEM; | |
232 | } | |
233 | ||
2afa19a9 | 234 | static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req) |
73208dfd | 235 | { |
73208dfd AC |
236 | if (req && req->ring) |
237 | dma_free_coherent(&ha->pdev->dev, | |
238 | (req->length + 1) * sizeof(request_t), | |
239 | req->ring, req->dma); | |
240 | ||
241 | kfree(req); | |
242 | req = NULL; | |
243 | } | |
244 | ||
2afa19a9 AC |
245 | static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp) |
246 | { | |
247 | if (rsp && rsp->ring) | |
248 | dma_free_coherent(&ha->pdev->dev, | |
249 | (rsp->length + 1) * sizeof(response_t), | |
250 | rsp->ring, rsp->dma); | |
251 | ||
252 | kfree(rsp); | |
253 | rsp = NULL; | |
254 | } | |
255 | ||
73208dfd AC |
256 | static void qla2x00_free_queues(struct qla_hw_data *ha) |
257 | { | |
258 | struct req_que *req; | |
259 | struct rsp_que *rsp; | |
260 | int cnt; | |
261 | ||
2afa19a9 | 262 | for (cnt = 0; cnt < ha->max_req_queues; cnt++) { |
73208dfd | 263 | req = ha->req_q_map[cnt]; |
2afa19a9 | 264 | qla2x00_free_req_que(ha, req); |
73208dfd | 265 | } |
73208dfd AC |
266 | kfree(ha->req_q_map); |
267 | ha->req_q_map = NULL; | |
2afa19a9 AC |
268 | |
269 | for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) { | |
270 | rsp = ha->rsp_q_map[cnt]; | |
271 | qla2x00_free_rsp_que(ha, rsp); | |
272 | } | |
273 | kfree(ha->rsp_q_map); | |
274 | ha->rsp_q_map = NULL; | |
73208dfd AC |
275 | } |
276 | ||
68ca949c AC |
277 | static int qla25xx_setup_mode(struct scsi_qla_host *vha) |
278 | { | |
279 | uint16_t options = 0; | |
280 | int ques, req, ret; | |
281 | struct qla_hw_data *ha = vha->hw; | |
282 | ||
7163ea81 AC |
283 | if (!(ha->fw_attributes & BIT_6)) { |
284 | qla_printk(KERN_INFO, ha, | |
285 | "Firmware is not multi-queue capable\n"); | |
286 | goto fail; | |
287 | } | |
68ca949c | 288 | if (ql2xmultique_tag) { |
68ca949c AC |
289 | /* create a request queue for IO */ |
290 | options |= BIT_7; | |
291 | req = qla25xx_create_req_que(ha, options, 0, 0, -1, | |
292 | QLA_DEFAULT_QUE_QOS); | |
293 | if (!req) { | |
294 | qla_printk(KERN_WARNING, ha, | |
295 | "Can't create request queue\n"); | |
296 | goto fail; | |
297 | } | |
7163ea81 | 298 | ha->wq = create_workqueue("qla2xxx_wq"); |
68ca949c AC |
299 | vha->req = ha->req_q_map[req]; |
300 | options |= BIT_1; | |
301 | for (ques = 1; ques < ha->max_rsp_queues; ques++) { | |
302 | ret = qla25xx_create_rsp_que(ha, options, 0, 0, req); | |
303 | if (!ret) { | |
304 | qla_printk(KERN_WARNING, ha, | |
305 | "Response Queue create failed\n"); | |
306 | goto fail2; | |
307 | } | |
308 | } | |
7163ea81 AC |
309 | ha->flags.cpu_affinity_enabled = 1; |
310 | ||
68ca949c AC |
311 | DEBUG2(qla_printk(KERN_INFO, ha, |
312 | "CPU affinity mode enabled, no. of response" | |
313 | " queues:%d, no. of request queues:%d\n", | |
314 | ha->max_rsp_queues, ha->max_req_queues)); | |
315 | } | |
316 | return 0; | |
317 | fail2: | |
318 | qla25xx_delete_queues(vha); | |
7163ea81 AC |
319 | destroy_workqueue(ha->wq); |
320 | ha->wq = NULL; | |
68ca949c AC |
321 | fail: |
322 | ha->mqenable = 0; | |
7163ea81 AC |
323 | kfree(ha->req_q_map); |
324 | kfree(ha->rsp_q_map); | |
325 | ha->max_req_queues = ha->max_rsp_queues = 1; | |
68ca949c AC |
326 | return 1; |
327 | } | |
328 | ||
1da177e4 | 329 | static char * |
e315cd28 | 330 | qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str) |
1da177e4 | 331 | { |
e315cd28 | 332 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
333 | static char *pci_bus_modes[] = { |
334 | "33", "66", "100", "133", | |
335 | }; | |
336 | uint16_t pci_bus; | |
337 | ||
338 | strcpy(str, "PCI"); | |
339 | pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; | |
340 | if (pci_bus) { | |
341 | strcat(str, "-X ("); | |
342 | strcat(str, pci_bus_modes[pci_bus]); | |
343 | } else { | |
344 | pci_bus = (ha->pci_attr & BIT_8) >> 8; | |
345 | strcat(str, " ("); | |
346 | strcat(str, pci_bus_modes[pci_bus]); | |
347 | } | |
348 | strcat(str, " MHz)"); | |
349 | ||
350 | return (str); | |
351 | } | |
352 | ||
fca29703 | 353 | static char * |
e315cd28 | 354 | qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str) |
fca29703 AV |
355 | { |
356 | static char *pci_bus_modes[] = { "33", "66", "100", "133", }; | |
e315cd28 | 357 | struct qla_hw_data *ha = vha->hw; |
fca29703 AV |
358 | uint32_t pci_bus; |
359 | int pcie_reg; | |
360 | ||
361 | pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP); | |
362 | if (pcie_reg) { | |
363 | char lwstr[6]; | |
364 | uint16_t pcie_lstat, lspeed, lwidth; | |
365 | ||
366 | pcie_reg += 0x12; | |
367 | pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat); | |
368 | lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3); | |
369 | lwidth = (pcie_lstat & | |
370 | (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4; | |
371 | ||
372 | strcpy(str, "PCIe ("); | |
373 | if (lspeed == 1) | |
c87a0d8c | 374 | strcat(str, "2.5GT/s "); |
c3a2f0df | 375 | else if (lspeed == 2) |
c87a0d8c | 376 | strcat(str, "5.0GT/s "); |
fca29703 AV |
377 | else |
378 | strcat(str, "<unknown> "); | |
379 | snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth); | |
380 | strcat(str, lwstr); | |
381 | ||
382 | return str; | |
383 | } | |
384 | ||
385 | strcpy(str, "PCI"); | |
386 | pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8; | |
387 | if (pci_bus == 0 || pci_bus == 8) { | |
388 | strcat(str, " ("); | |
389 | strcat(str, pci_bus_modes[pci_bus >> 3]); | |
390 | } else { | |
391 | strcat(str, "-X "); | |
392 | if (pci_bus & BIT_2) | |
393 | strcat(str, "Mode 2"); | |
394 | else | |
395 | strcat(str, "Mode 1"); | |
396 | strcat(str, " ("); | |
397 | strcat(str, pci_bus_modes[pci_bus & ~BIT_2]); | |
398 | } | |
399 | strcat(str, " MHz)"); | |
400 | ||
401 | return str; | |
402 | } | |
403 | ||
e5f82ab8 | 404 | static char * |
e315cd28 | 405 | qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str) |
1da177e4 LT |
406 | { |
407 | char un_str[10]; | |
e315cd28 | 408 | struct qla_hw_data *ha = vha->hw; |
fa2a1ce5 | 409 | |
1da177e4 LT |
410 | sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, |
411 | ha->fw_minor_version, | |
412 | ha->fw_subminor_version); | |
413 | ||
414 | if (ha->fw_attributes & BIT_9) { | |
415 | strcat(str, "FLX"); | |
416 | return (str); | |
417 | } | |
418 | ||
419 | switch (ha->fw_attributes & 0xFF) { | |
420 | case 0x7: | |
421 | strcat(str, "EF"); | |
422 | break; | |
423 | case 0x17: | |
424 | strcat(str, "TP"); | |
425 | break; | |
426 | case 0x37: | |
427 | strcat(str, "IP"); | |
428 | break; | |
429 | case 0x77: | |
430 | strcat(str, "VI"); | |
431 | break; | |
432 | default: | |
433 | sprintf(un_str, "(%x)", ha->fw_attributes); | |
434 | strcat(str, un_str); | |
435 | break; | |
436 | } | |
437 | if (ha->fw_attributes & 0x100) | |
438 | strcat(str, "X"); | |
439 | ||
440 | return (str); | |
441 | } | |
442 | ||
e5f82ab8 | 443 | static char * |
e315cd28 | 444 | qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str) |
fca29703 | 445 | { |
e315cd28 | 446 | struct qla_hw_data *ha = vha->hw; |
f0883ac6 | 447 | |
3a03eb79 AV |
448 | sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version, |
449 | ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes); | |
fca29703 | 450 | return str; |
fca29703 AV |
451 | } |
452 | ||
453 | static inline srb_t * | |
e315cd28 | 454 | qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport, |
fca29703 AV |
455 | struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
456 | { | |
457 | srb_t *sp; | |
e315cd28 | 458 | struct qla_hw_data *ha = vha->hw; |
fca29703 AV |
459 | |
460 | sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); | |
461 | if (!sp) | |
462 | return sp; | |
463 | ||
fca29703 AV |
464 | sp->fcport = fcport; |
465 | sp->cmd = cmd; | |
466 | sp->flags = 0; | |
467 | CMD_SP(cmd) = (void *)sp; | |
468 | cmd->scsi_done = done; | |
cf53b069 | 469 | sp->ctx = NULL; |
fca29703 AV |
470 | |
471 | return sp; | |
472 | } | |
473 | ||
1da177e4 | 474 | static int |
a5326f86 | 475 | qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
fca29703 | 476 | { |
e315cd28 | 477 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
fca29703 | 478 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
19a7b4ae | 479 | struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); |
e315cd28 AC |
480 | struct qla_hw_data *ha = vha->hw; |
481 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
fca29703 AV |
482 | srb_t *sp; |
483 | int rval; | |
484 | ||
85880801 AV |
485 | if (ha->flags.eeh_busy) { |
486 | if (ha->flags.pci_channel_io_perm_failure) | |
b9b12f73 | 487 | cmd->result = DID_NO_CONNECT << 16; |
85880801 AV |
488 | else |
489 | cmd->result = DID_REQUEUE << 16; | |
14e660e6 SJ |
490 | goto qc24_fail_command; |
491 | } | |
492 | ||
19a7b4ae JSEC |
493 | rval = fc_remote_port_chkready(rport); |
494 | if (rval) { | |
495 | cmd->result = rval; | |
fca29703 AV |
496 | goto qc24_fail_command; |
497 | } | |
498 | ||
387f96b4 | 499 | /* Close window on fcport/rport state-transitioning. */ |
7b594131 MC |
500 | if (fcport->drport) |
501 | goto qc24_target_busy; | |
387f96b4 | 502 | |
fca29703 AV |
503 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
504 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || | |
e315cd28 | 505 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { |
fca29703 AV |
506 | cmd->result = DID_NO_CONNECT << 16; |
507 | goto qc24_fail_command; | |
508 | } | |
7b594131 | 509 | goto qc24_target_busy; |
fca29703 AV |
510 | } |
511 | ||
e315cd28 | 512 | spin_unlock_irq(vha->host->host_lock); |
fca29703 | 513 | |
e315cd28 | 514 | sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done); |
fca29703 AV |
515 | if (!sp) |
516 | goto qc24_host_busy_lock; | |
517 | ||
e315cd28 | 518 | rval = ha->isp_ops->start_scsi(sp); |
fca29703 AV |
519 | if (rval != QLA_SUCCESS) |
520 | goto qc24_host_busy_free_sp; | |
521 | ||
e315cd28 | 522 | spin_lock_irq(vha->host->host_lock); |
fca29703 AV |
523 | |
524 | return 0; | |
525 | ||
526 | qc24_host_busy_free_sp: | |
e315cd28 AC |
527 | qla2x00_sp_free_dma(sp); |
528 | mempool_free(sp, ha->srb_mempool); | |
fca29703 AV |
529 | |
530 | qc24_host_busy_lock: | |
e315cd28 | 531 | spin_lock_irq(vha->host->host_lock); |
fca29703 AV |
532 | return SCSI_MLQUEUE_HOST_BUSY; |
533 | ||
7b594131 MC |
534 | qc24_target_busy: |
535 | return SCSI_MLQUEUE_TARGET_BUSY; | |
536 | ||
fca29703 AV |
537 | qc24_fail_command: |
538 | done(cmd); | |
539 | ||
540 | return 0; | |
541 | } | |
542 | ||
543 | ||
1da177e4 LT |
544 | /* |
545 | * qla2x00_eh_wait_on_command | |
546 | * Waits for the command to be returned by the Firmware for some | |
547 | * max time. | |
548 | * | |
549 | * Input: | |
1da177e4 | 550 | * cmd = Scsi Command to wait on. |
1da177e4 LT |
551 | * |
552 | * Return: | |
553 | * Not Found : 0 | |
554 | * Found : 1 | |
555 | */ | |
556 | static int | |
e315cd28 | 557 | qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd) |
1da177e4 | 558 | { |
fe74c71f AV |
559 | #define ABORT_POLLING_PERIOD 1000 |
560 | #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD)) | |
f4f051eb | 561 | unsigned long wait_iter = ABORT_WAIT_ITER; |
85880801 AV |
562 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
563 | struct qla_hw_data *ha = vha->hw; | |
f4f051eb | 564 | int ret = QLA_SUCCESS; |
1da177e4 | 565 | |
85880801 AV |
566 | if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) { |
567 | DEBUG17(qla_printk(KERN_WARNING, ha, "return:eh_wait\n")); | |
568 | return ret; | |
569 | } | |
570 | ||
d970432c | 571 | while (CMD_SP(cmd) && wait_iter--) { |
fe74c71f | 572 | msleep(ABORT_POLLING_PERIOD); |
f4f051eb AV |
573 | } |
574 | if (CMD_SP(cmd)) | |
575 | ret = QLA_FUNCTION_FAILED; | |
1da177e4 | 576 | |
f4f051eb | 577 | return ret; |
1da177e4 LT |
578 | } |
579 | ||
580 | /* | |
581 | * qla2x00_wait_for_hba_online | |
fa2a1ce5 | 582 | * Wait till the HBA is online after going through |
1da177e4 LT |
583 | * <= MAX_RETRIES_OF_ISP_ABORT or |
584 | * finally HBA is disabled ie marked offline | |
585 | * | |
586 | * Input: | |
587 | * ha - pointer to host adapter structure | |
fa2a1ce5 AV |
588 | * |
589 | * Note: | |
1da177e4 LT |
590 | * Does context switching-Release SPIN_LOCK |
591 | * (if any) before calling this routine. | |
592 | * | |
593 | * Return: | |
594 | * Success (Adapter is online) : 0 | |
595 | * Failed (Adapter is offline/disabled) : 1 | |
596 | */ | |
854165f4 | 597 | int |
e315cd28 | 598 | qla2x00_wait_for_hba_online(scsi_qla_host_t *vha) |
1da177e4 | 599 | { |
fca29703 AV |
600 | int return_status; |
601 | unsigned long wait_online; | |
e315cd28 AC |
602 | struct qla_hw_data *ha = vha->hw; |
603 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
1da177e4 | 604 | |
fa2a1ce5 | 605 | wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
e315cd28 AC |
606 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || |
607 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || | |
608 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || | |
609 | ha->dpc_active) && time_before(jiffies, wait_online)) { | |
1da177e4 LT |
610 | |
611 | msleep(1000); | |
612 | } | |
e315cd28 | 613 | if (base_vha->flags.online) |
fa2a1ce5 | 614 | return_status = QLA_SUCCESS; |
1da177e4 LT |
615 | else |
616 | return_status = QLA_FUNCTION_FAILED; | |
617 | ||
1da177e4 LT |
618 | return (return_status); |
619 | } | |
620 | ||
2533cf67 LC |
621 | int |
622 | qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha) | |
623 | { | |
624 | int return_status; | |
625 | unsigned long wait_reset; | |
626 | struct qla_hw_data *ha = vha->hw; | |
627 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
628 | ||
629 | wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ); | |
630 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || | |
631 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || | |
632 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || | |
633 | ha->dpc_active) && time_before(jiffies, wait_reset)) { | |
634 | ||
635 | msleep(1000); | |
636 | ||
637 | if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) && | |
638 | ha->flags.chip_reset_done) | |
639 | break; | |
640 | } | |
641 | if (ha->flags.chip_reset_done) | |
642 | return_status = QLA_SUCCESS; | |
643 | else | |
644 | return_status = QLA_FUNCTION_FAILED; | |
645 | ||
646 | return return_status; | |
647 | } | |
648 | ||
1da177e4 LT |
649 | /* |
650 | * qla2x00_wait_for_loop_ready | |
651 | * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop | |
fa2a1ce5 | 652 | * to be in LOOP_READY state. |
1da177e4 LT |
653 | * Input: |
654 | * ha - pointer to host adapter structure | |
fa2a1ce5 AV |
655 | * |
656 | * Note: | |
1da177e4 LT |
657 | * Does context switching-Release SPIN_LOCK |
658 | * (if any) before calling this routine. | |
fa2a1ce5 | 659 | * |
1da177e4 LT |
660 | * |
661 | * Return: | |
662 | * Success (LOOP_READY) : 0 | |
663 | * Failed (LOOP_NOT_READY) : 1 | |
664 | */ | |
fa2a1ce5 | 665 | static inline int |
e315cd28 | 666 | qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha) |
1da177e4 LT |
667 | { |
668 | int return_status = QLA_SUCCESS; | |
669 | unsigned long loop_timeout ; | |
e315cd28 AC |
670 | struct qla_hw_data *ha = vha->hw; |
671 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
1da177e4 LT |
672 | |
673 | /* wait for 5 min at the max for loop to be ready */ | |
fa2a1ce5 | 674 | loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
1da177e4 | 675 | |
e315cd28 AC |
676 | while ((!atomic_read(&base_vha->loop_down_timer) && |
677 | atomic_read(&base_vha->loop_state) == LOOP_DOWN) || | |
678 | atomic_read(&base_vha->loop_state) != LOOP_READY) { | |
679 | if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) { | |
57680080 RA |
680 | return_status = QLA_FUNCTION_FAILED; |
681 | break; | |
682 | } | |
1da177e4 LT |
683 | msleep(1000); |
684 | if (time_after_eq(jiffies, loop_timeout)) { | |
685 | return_status = QLA_FUNCTION_FAILED; | |
686 | break; | |
687 | } | |
688 | } | |
fa2a1ce5 | 689 | return (return_status); |
1da177e4 LT |
690 | } |
691 | ||
692 | /************************************************************************** | |
693 | * qla2xxx_eh_abort | |
694 | * | |
695 | * Description: | |
696 | * The abort function will abort the specified command. | |
697 | * | |
698 | * Input: | |
699 | * cmd = Linux SCSI command packet to be aborted. | |
700 | * | |
701 | * Returns: | |
702 | * Either SUCCESS or FAILED. | |
703 | * | |
704 | * Note: | |
2ea00202 | 705 | * Only return FAILED if command not returned by firmware. |
1da177e4 | 706 | **************************************************************************/ |
e5f82ab8 | 707 | static int |
1da177e4 LT |
708 | qla2xxx_eh_abort(struct scsi_cmnd *cmd) |
709 | { | |
e315cd28 | 710 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
f4f051eb | 711 | srb_t *sp; |
17d98630 | 712 | int ret, i; |
f4f051eb AV |
713 | unsigned int id, lun; |
714 | unsigned long serial; | |
18e144d3 | 715 | unsigned long flags; |
2ea00202 | 716 | int wait = 0; |
e315cd28 | 717 | struct qla_hw_data *ha = vha->hw; |
67c2e93a | 718 | struct req_que *req = vha->req; |
17d98630 | 719 | srb_t *spt; |
1da177e4 | 720 | |
65d430fa | 721 | fc_block_scsi_eh(cmd); |
07db5183 | 722 | |
f4f051eb | 723 | if (!CMD_SP(cmd)) |
2ea00202 | 724 | return SUCCESS; |
1da177e4 | 725 | |
2ea00202 | 726 | ret = SUCCESS; |
1da177e4 | 727 | |
f4f051eb AV |
728 | id = cmd->device->id; |
729 | lun = cmd->device->lun; | |
730 | serial = cmd->serial_number; | |
17d98630 AC |
731 | spt = (srb_t *) CMD_SP(cmd); |
732 | if (!spt) | |
733 | return SUCCESS; | |
1da177e4 | 734 | |
f4f051eb | 735 | /* Check active list for command command. */ |
e315cd28 | 736 | spin_lock_irqsave(&ha->hardware_lock, flags); |
17d98630 AC |
737 | for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { |
738 | sp = req->outstanding_cmds[i]; | |
1da177e4 | 739 | |
17d98630 AC |
740 | if (sp == NULL) |
741 | continue; | |
cf53b069 AV |
742 | if (sp->ctx) |
743 | continue; | |
17d98630 AC |
744 | if (sp->cmd != cmd) |
745 | continue; | |
1da177e4 | 746 | |
17d98630 AC |
747 | DEBUG2(printk("%s(%ld): aborting sp %p from RISC." |
748 | " pid=%ld.\n", __func__, vha->host_no, sp, serial)); | |
749 | ||
750 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2afa19a9 | 751 | if (ha->isp_ops->abort_command(sp)) { |
17d98630 AC |
752 | DEBUG2(printk("%s(%ld): abort_command " |
753 | "mbx failed.\n", __func__, vha->host_no)); | |
2ac4b64f | 754 | ret = FAILED; |
17d98630 AC |
755 | } else { |
756 | DEBUG3(printk("%s(%ld): abort_command " | |
757 | "mbx success.\n", __func__, vha->host_no)); | |
758 | wait = 1; | |
73208dfd | 759 | } |
17d98630 AC |
760 | spin_lock_irqsave(&ha->hardware_lock, flags); |
761 | break; | |
f4f051eb | 762 | } |
e315cd28 | 763 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
1da177e4 | 764 | |
f4f051eb | 765 | /* Wait for the command to be returned. */ |
2ea00202 | 766 | if (wait) { |
e315cd28 | 767 | if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) { |
fa2a1ce5 | 768 | qla_printk(KERN_ERR, ha, |
f4f051eb | 769 | "scsi(%ld:%d:%d): Abort handler timed out -- %lx " |
e315cd28 | 770 | "%x.\n", vha->host_no, id, lun, serial, ret); |
2ea00202 | 771 | ret = FAILED; |
f4f051eb | 772 | } |
1da177e4 | 773 | } |
1da177e4 | 774 | |
fa2a1ce5 | 775 | qla_printk(KERN_INFO, ha, |
2ea00202 | 776 | "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n", |
e315cd28 | 777 | vha->host_no, id, lun, wait, serial, ret); |
1da177e4 | 778 | |
f4f051eb AV |
779 | return ret; |
780 | } | |
1da177e4 | 781 | |
523ec773 AV |
782 | enum nexus_wait_type { |
783 | WAIT_HOST = 0, | |
784 | WAIT_TARGET, | |
785 | WAIT_LUN, | |
786 | }; | |
787 | ||
f4f051eb | 788 | static int |
e315cd28 | 789 | qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t, |
17d98630 | 790 | unsigned int l, srb_t *sp, enum nexus_wait_type type) |
f4f051eb | 791 | { |
17d98630 | 792 | int cnt, match, status; |
18e144d3 | 793 | unsigned long flags; |
e315cd28 | 794 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 795 | struct req_que *req; |
1da177e4 | 796 | |
523ec773 | 797 | status = QLA_SUCCESS; |
17d98630 AC |
798 | if (!sp) |
799 | return status; | |
800 | ||
e315cd28 | 801 | spin_lock_irqsave(&ha->hardware_lock, flags); |
67c2e93a | 802 | req = vha->req; |
17d98630 AC |
803 | for (cnt = 1; status == QLA_SUCCESS && |
804 | cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { | |
805 | sp = req->outstanding_cmds[cnt]; | |
806 | if (!sp) | |
523ec773 | 807 | continue; |
cf53b069 AV |
808 | if (sp->ctx) |
809 | continue; | |
17d98630 AC |
810 | if (vha->vp_idx != sp->fcport->vha->vp_idx) |
811 | continue; | |
812 | match = 0; | |
813 | switch (type) { | |
814 | case WAIT_HOST: | |
815 | match = 1; | |
816 | break; | |
817 | case WAIT_TARGET: | |
818 | match = sp->cmd->device->id == t; | |
819 | break; | |
820 | case WAIT_LUN: | |
821 | match = (sp->cmd->device->id == t && | |
822 | sp->cmd->device->lun == l); | |
823 | break; | |
73208dfd | 824 | } |
17d98630 AC |
825 | if (!match) |
826 | continue; | |
827 | ||
828 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
829 | status = qla2x00_eh_wait_on_command(sp->cmd); | |
830 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1da177e4 | 831 | } |
e315cd28 | 832 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
523ec773 AV |
833 | |
834 | return status; | |
1da177e4 LT |
835 | } |
836 | ||
523ec773 AV |
837 | static char *reset_errors[] = { |
838 | "HBA not online", | |
839 | "HBA not ready", | |
840 | "Task management failed", | |
841 | "Waiting for command completions", | |
842 | }; | |
1da177e4 | 843 | |
e5f82ab8 | 844 | static int |
523ec773 | 845 | __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type, |
2afa19a9 | 846 | struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int)) |
1da177e4 | 847 | { |
e315cd28 | 848 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
bdf79621 | 849 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
523ec773 | 850 | int err; |
1da177e4 | 851 | |
65d430fa | 852 | fc_block_scsi_eh(cmd); |
07db5183 | 853 | |
b0328bee | 854 | if (!fcport) |
523ec773 | 855 | return FAILED; |
1da177e4 | 856 | |
e315cd28 AC |
857 | qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n", |
858 | vha->host_no, cmd->device->id, cmd->device->lun, name); | |
1da177e4 | 859 | |
523ec773 | 860 | err = 0; |
e315cd28 | 861 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) |
523ec773 AV |
862 | goto eh_reset_failed; |
863 | err = 1; | |
e315cd28 | 864 | if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS) |
523ec773 AV |
865 | goto eh_reset_failed; |
866 | err = 2; | |
2afa19a9 AC |
867 | if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1) |
868 | != QLA_SUCCESS) | |
523ec773 AV |
869 | goto eh_reset_failed; |
870 | err = 3; | |
e315cd28 | 871 | if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id, |
17d98630 | 872 | cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS) |
523ec773 AV |
873 | goto eh_reset_failed; |
874 | ||
e315cd28 AC |
875 | qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n", |
876 | vha->host_no, cmd->device->id, cmd->device->lun, name); | |
523ec773 AV |
877 | |
878 | return SUCCESS; | |
879 | ||
880 | eh_reset_failed: | |
e315cd28 AC |
881 | qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n" |
882 | , vha->host_no, cmd->device->id, cmd->device->lun, name, | |
523ec773 AV |
883 | reset_errors[err]); |
884 | return FAILED; | |
885 | } | |
1da177e4 | 886 | |
523ec773 AV |
887 | static int |
888 | qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) | |
889 | { | |
e315cd28 AC |
890 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
891 | struct qla_hw_data *ha = vha->hw; | |
1da177e4 | 892 | |
523ec773 AV |
893 | return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd, |
894 | ha->isp_ops->lun_reset); | |
1da177e4 LT |
895 | } |
896 | ||
1da177e4 | 897 | static int |
523ec773 | 898 | qla2xxx_eh_target_reset(struct scsi_cmnd *cmd) |
1da177e4 | 899 | { |
e315cd28 AC |
900 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
901 | struct qla_hw_data *ha = vha->hw; | |
1da177e4 | 902 | |
523ec773 AV |
903 | return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd, |
904 | ha->isp_ops->target_reset); | |
1da177e4 LT |
905 | } |
906 | ||
1da177e4 LT |
907 | /************************************************************************** |
908 | * qla2xxx_eh_bus_reset | |
909 | * | |
910 | * Description: | |
911 | * The bus reset function will reset the bus and abort any executing | |
912 | * commands. | |
913 | * | |
914 | * Input: | |
915 | * cmd = Linux SCSI command packet of the command that cause the | |
916 | * bus reset. | |
917 | * | |
918 | * Returns: | |
919 | * SUCCESS/FAILURE (defined as macro in scsi.h). | |
920 | * | |
921 | **************************************************************************/ | |
e5f82ab8 | 922 | static int |
1da177e4 LT |
923 | qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) |
924 | { | |
e315cd28 | 925 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
bdf79621 | 926 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
2c3dfe3f | 927 | int ret = FAILED; |
f4f051eb AV |
928 | unsigned int id, lun; |
929 | unsigned long serial; | |
17d98630 | 930 | srb_t *sp = (srb_t *) CMD_SP(cmd); |
f4f051eb | 931 | |
65d430fa | 932 | fc_block_scsi_eh(cmd); |
07db5183 | 933 | |
f4f051eb AV |
934 | id = cmd->device->id; |
935 | lun = cmd->device->lun; | |
936 | serial = cmd->serial_number; | |
1da177e4 | 937 | |
b0328bee | 938 | if (!fcport) |
f4f051eb | 939 | return ret; |
1da177e4 | 940 | |
e315cd28 | 941 | qla_printk(KERN_INFO, vha->hw, |
749af3d5 | 942 | "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun); |
1da177e4 | 943 | |
e315cd28 | 944 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
1da177e4 | 945 | DEBUG2(printk("%s failed:board disabled\n",__func__)); |
f4f051eb | 946 | goto eh_bus_reset_done; |
1da177e4 LT |
947 | } |
948 | ||
e315cd28 AC |
949 | if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) { |
950 | if (qla2x00_loop_reset(vha) == QLA_SUCCESS) | |
f4f051eb | 951 | ret = SUCCESS; |
1da177e4 | 952 | } |
f4f051eb AV |
953 | if (ret == FAILED) |
954 | goto eh_bus_reset_done; | |
1da177e4 | 955 | |
9a41a62b | 956 | /* Flush outstanding commands. */ |
17d98630 | 957 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) != |
523ec773 | 958 | QLA_SUCCESS) |
9a41a62b | 959 | ret = FAILED; |
1da177e4 | 960 | |
f4f051eb | 961 | eh_bus_reset_done: |
e315cd28 | 962 | qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__, |
f4f051eb | 963 | (ret == FAILED) ? "failed" : "succeded"); |
1da177e4 | 964 | |
f4f051eb | 965 | return ret; |
1da177e4 LT |
966 | } |
967 | ||
968 | /************************************************************************** | |
969 | * qla2xxx_eh_host_reset | |
970 | * | |
971 | * Description: | |
972 | * The reset function will reset the Adapter. | |
973 | * | |
974 | * Input: | |
975 | * cmd = Linux SCSI command packet of the command that cause the | |
976 | * adapter reset. | |
977 | * | |
978 | * Returns: | |
979 | * Either SUCCESS or FAILED. | |
980 | * | |
981 | * Note: | |
982 | **************************************************************************/ | |
e5f82ab8 | 983 | static int |
1da177e4 LT |
984 | qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) |
985 | { | |
e315cd28 | 986 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
bdf79621 | 987 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
e315cd28 | 988 | struct qla_hw_data *ha = vha->hw; |
2c3dfe3f | 989 | int ret = FAILED; |
f4f051eb AV |
990 | unsigned int id, lun; |
991 | unsigned long serial; | |
17d98630 | 992 | srb_t *sp = (srb_t *) CMD_SP(cmd); |
e315cd28 | 993 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 994 | |
65d430fa | 995 | fc_block_scsi_eh(cmd); |
07db5183 | 996 | |
f4f051eb AV |
997 | id = cmd->device->id; |
998 | lun = cmd->device->lun; | |
999 | serial = cmd->serial_number; | |
1000 | ||
b0328bee | 1001 | if (!fcport) |
f4f051eb | 1002 | return ret; |
1da177e4 | 1003 | |
1da177e4 | 1004 | qla_printk(KERN_INFO, ha, |
e315cd28 | 1005 | "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun); |
1da177e4 | 1006 | |
e315cd28 | 1007 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) |
f4f051eb | 1008 | goto eh_host_reset_lock; |
1da177e4 LT |
1009 | |
1010 | /* | |
1011 | * Fixme-may be dpc thread is active and processing | |
fa2a1ce5 | 1012 | * loop_resync,so wait a while for it to |
1da177e4 LT |
1013 | * be completed and then issue big hammer.Otherwise |
1014 | * it may cause I/O failure as big hammer marks the | |
1015 | * devices as lost kicking of the port_down_timer | |
1016 | * while dpc is stuck for the mailbox to complete. | |
1017 | */ | |
e315cd28 AC |
1018 | qla2x00_wait_for_loop_ready(vha); |
1019 | if (vha != base_vha) { | |
1020 | if (qla2x00_vp_abort_isp(vha)) | |
f4f051eb | 1021 | goto eh_host_reset_lock; |
e315cd28 | 1022 | } else { |
68ca949c AC |
1023 | if (ha->wq) |
1024 | flush_workqueue(ha->wq); | |
1025 | ||
e315cd28 AC |
1026 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
1027 | if (qla2x00_abort_isp(base_vha)) { | |
1028 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | |
1029 | /* failed. schedule dpc to try */ | |
1030 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); | |
1031 | ||
1032 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) | |
1033 | goto eh_host_reset_lock; | |
1034 | } | |
1035 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | |
fa2a1ce5 | 1036 | } |
1da177e4 | 1037 | |
e315cd28 | 1038 | /* Waiting for command to be returned to OS.*/ |
17d98630 | 1039 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) == |
e315cd28 | 1040 | QLA_SUCCESS) |
f4f051eb | 1041 | ret = SUCCESS; |
1da177e4 | 1042 | |
f4f051eb | 1043 | eh_host_reset_lock: |
f4f051eb AV |
1044 | qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, |
1045 | (ret == FAILED) ? "failed" : "succeded"); | |
1da177e4 | 1046 | |
f4f051eb AV |
1047 | return ret; |
1048 | } | |
1da177e4 LT |
1049 | |
1050 | /* | |
1051 | * qla2x00_loop_reset | |
1052 | * Issue loop reset. | |
1053 | * | |
1054 | * Input: | |
1055 | * ha = adapter block pointer. | |
1056 | * | |
1057 | * Returns: | |
1058 | * 0 = success | |
1059 | */ | |
a4722cf2 | 1060 | int |
e315cd28 | 1061 | qla2x00_loop_reset(scsi_qla_host_t *vha) |
1da177e4 | 1062 | { |
0c8c39af | 1063 | int ret; |
bdf79621 | 1064 | struct fc_port *fcport; |
e315cd28 | 1065 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 1066 | |
55e5ed27 AV |
1067 | if (ha->flags.enable_target_reset) { |
1068 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
1069 | if (fcport->port_type != FCT_TARGET) | |
1070 | continue; | |
1071 | ||
1072 | ret = ha->isp_ops->target_reset(fcport, 0, 0); | |
1073 | if (ret != QLA_SUCCESS) { | |
1074 | DEBUG2_3(printk("%s(%ld): bus_reset failed: " | |
1075 | "target_reset=%d d_id=%x.\n", __func__, | |
1076 | vha->host_no, ret, fcport->d_id.b24)); | |
1077 | } | |
1078 | } | |
1079 | } | |
1080 | ||
0d6e61bc | 1081 | if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) { |
e315cd28 | 1082 | ret = qla2x00_full_login_lip(vha); |
0c8c39af | 1083 | if (ret != QLA_SUCCESS) { |
749af3d5 | 1084 | DEBUG2_3(printk("%s(%ld): failed: " |
e315cd28 | 1085 | "full_login_lip=%d.\n", __func__, vha->host_no, |
0c8c39af | 1086 | ret)); |
749af3d5 AC |
1087 | } |
1088 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
1089 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
1090 | qla2x00_mark_all_devices_lost(vha, 0); | |
1091 | qla2x00_wait_for_loop_ready(vha); | |
0c8c39af AV |
1092 | } |
1093 | ||
0d6e61bc | 1094 | if (ha->flags.enable_lip_reset) { |
e315cd28 | 1095 | ret = qla2x00_lip_reset(vha); |
0c8c39af | 1096 | if (ret != QLA_SUCCESS) { |
749af3d5 | 1097 | DEBUG2_3(printk("%s(%ld): failed: " |
e315cd28 AC |
1098 | "lip_reset=%d.\n", __func__, vha->host_no, ret)); |
1099 | } else | |
1100 | qla2x00_wait_for_loop_ready(vha); | |
1da177e4 LT |
1101 | } |
1102 | ||
1da177e4 | 1103 | /* Issue marker command only when we are going to start the I/O */ |
e315cd28 | 1104 | vha->marker_needed = 1; |
1da177e4 | 1105 | |
0c8c39af | 1106 | return QLA_SUCCESS; |
1da177e4 LT |
1107 | } |
1108 | ||
df4bf0bb | 1109 | void |
e315cd28 | 1110 | qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res) |
df4bf0bb | 1111 | { |
73208dfd | 1112 | int que, cnt; |
df4bf0bb AV |
1113 | unsigned long flags; |
1114 | srb_t *sp; | |
ac280b67 | 1115 | struct srb_ctx *ctx; |
e315cd28 | 1116 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 1117 | struct req_que *req; |
df4bf0bb AV |
1118 | |
1119 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
2afa19a9 | 1120 | for (que = 0; que < ha->max_req_queues; que++) { |
29bdccbe | 1121 | req = ha->req_q_map[que]; |
73208dfd AC |
1122 | if (!req) |
1123 | continue; | |
1124 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { | |
1125 | sp = req->outstanding_cmds[cnt]; | |
e612d465 | 1126 | if (sp) { |
73208dfd | 1127 | req->outstanding_cmds[cnt] = NULL; |
ac280b67 AV |
1128 | if (!sp->ctx) { |
1129 | sp->cmd->result = res; | |
1130 | qla2x00_sp_compl(ha, sp); | |
1131 | } else { | |
1132 | ctx = sp->ctx; | |
db3ad7f8 GM |
1133 | if (ctx->type == SRB_LOGIN_CMD || ctx->type == SRB_LOGOUT_CMD) { |
1134 | del_timer_sync(&ctx->timer); | |
1135 | ctx->free(sp); | |
1136 | } else { | |
1137 | struct srb_bsg* sp_bsg = (struct srb_bsg*)sp->ctx; | |
1138 | if (sp_bsg->bsg_job->request->msgcode == FC_BSG_HST_CT) | |
1139 | kfree(sp->fcport); | |
1140 | sp_bsg->bsg_job->req->errors = 0; | |
1141 | sp_bsg->bsg_job->reply->result = res; | |
1142 | sp_bsg->bsg_job->job_done(sp_bsg->bsg_job); | |
1143 | kfree(sp->ctx); | |
1144 | mempool_free(sp, ha->srb_mempool); | |
1145 | } | |
ac280b67 | 1146 | } |
73208dfd | 1147 | } |
df4bf0bb AV |
1148 | } |
1149 | } | |
1150 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1151 | } | |
1152 | ||
f4f051eb AV |
1153 | static int |
1154 | qla2xxx_slave_alloc(struct scsi_device *sdev) | |
1da177e4 | 1155 | { |
bdf79621 | 1156 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
1da177e4 | 1157 | |
19a7b4ae | 1158 | if (!rport || fc_remote_port_chkready(rport)) |
f4f051eb | 1159 | return -ENXIO; |
bdf79621 | 1160 | |
19a7b4ae | 1161 | sdev->hostdata = *(fc_port_t **)rport->dd_data; |
1da177e4 | 1162 | |
f4f051eb AV |
1163 | return 0; |
1164 | } | |
1da177e4 | 1165 | |
f4f051eb AV |
1166 | static int |
1167 | qla2xxx_slave_configure(struct scsi_device *sdev) | |
1168 | { | |
e315cd28 AC |
1169 | scsi_qla_host_t *vha = shost_priv(sdev->host); |
1170 | struct qla_hw_data *ha = vha->hw; | |
8482e118 | 1171 | struct fc_rport *rport = starget_to_rport(sdev->sdev_target); |
2afa19a9 | 1172 | struct req_que *req = vha->req; |
8482e118 | 1173 | |
f4f051eb | 1174 | if (sdev->tagged_supported) |
73208dfd | 1175 | scsi_activate_tcq(sdev, req->max_q_depth); |
f4f051eb | 1176 | else |
73208dfd | 1177 | scsi_deactivate_tcq(sdev, req->max_q_depth); |
1da177e4 | 1178 | |
85821c90 | 1179 | rport->dev_loss_tmo = ha->port_down_retry_count; |
8482e118 | 1180 | |
f4f051eb AV |
1181 | return 0; |
1182 | } | |
1da177e4 | 1183 | |
f4f051eb AV |
1184 | static void |
1185 | qla2xxx_slave_destroy(struct scsi_device *sdev) | |
1186 | { | |
1187 | sdev->hostdata = NULL; | |
1da177e4 LT |
1188 | } |
1189 | ||
c45dd305 GM |
1190 | static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth) |
1191 | { | |
1192 | fc_port_t *fcport = (struct fc_port *) sdev->hostdata; | |
1193 | ||
1194 | if (!scsi_track_queue_full(sdev, qdepth)) | |
1195 | return; | |
1196 | ||
1197 | DEBUG2(qla_printk(KERN_INFO, fcport->vha->hw, | |
1198 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n", | |
1199 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, | |
1200 | sdev->queue_depth)); | |
1201 | } | |
1202 | ||
1203 | static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth) | |
1204 | { | |
1205 | fc_port_t *fcport = sdev->hostdata; | |
1206 | struct scsi_qla_host *vha = fcport->vha; | |
1207 | struct qla_hw_data *ha = vha->hw; | |
1208 | struct req_que *req = NULL; | |
1209 | ||
1210 | req = vha->req; | |
1211 | if (!req) | |
1212 | return; | |
1213 | ||
1214 | if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth) | |
1215 | return; | |
1216 | ||
1217 | if (sdev->ordered_tags) | |
1218 | scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth); | |
1219 | else | |
1220 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth); | |
1221 | ||
1222 | DEBUG2(qla_printk(KERN_INFO, ha, | |
1223 | "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n", | |
1224 | fcport->vha->host_no, sdev->channel, sdev->id, sdev->lun, | |
1225 | sdev->queue_depth)); | |
1226 | } | |
1227 | ||
ce7e4af7 | 1228 | static int |
e881a172 | 1229 | qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) |
ce7e4af7 | 1230 | { |
c45dd305 GM |
1231 | switch (reason) { |
1232 | case SCSI_QDEPTH_DEFAULT: | |
1233 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | |
1234 | break; | |
1235 | case SCSI_QDEPTH_QFULL: | |
1236 | qla2x00_handle_queue_full(sdev, qdepth); | |
1237 | break; | |
1238 | case SCSI_QDEPTH_RAMP_UP: | |
1239 | qla2x00_adjust_sdev_qdepth_up(sdev, qdepth); | |
1240 | break; | |
1241 | default: | |
08002af2 | 1242 | return -EOPNOTSUPP; |
c45dd305 | 1243 | } |
e881a172 | 1244 | |
ce7e4af7 AV |
1245 | return sdev->queue_depth; |
1246 | } | |
1247 | ||
1248 | static int | |
1249 | qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type) | |
1250 | { | |
1251 | if (sdev->tagged_supported) { | |
1252 | scsi_set_tag_type(sdev, tag_type); | |
1253 | if (tag_type) | |
1254 | scsi_activate_tcq(sdev, sdev->queue_depth); | |
1255 | else | |
1256 | scsi_deactivate_tcq(sdev, sdev->queue_depth); | |
1257 | } else | |
1258 | tag_type = 0; | |
1259 | ||
1260 | return tag_type; | |
1261 | } | |
1262 | ||
1da177e4 LT |
1263 | /** |
1264 | * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. | |
1265 | * @ha: HA context | |
1266 | * | |
1267 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated | |
1268 | * supported addressing method. | |
1269 | */ | |
1270 | static void | |
53303c42 | 1271 | qla2x00_config_dma_addressing(struct qla_hw_data *ha) |
1da177e4 | 1272 | { |
7524f9b9 | 1273 | /* Assume a 32bit DMA mask. */ |
1da177e4 | 1274 | ha->flags.enable_64bit_addressing = 0; |
1da177e4 | 1275 | |
6a35528a | 1276 | if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) { |
7524f9b9 AV |
1277 | /* Any upper-dword bits set? */ |
1278 | if (MSD(dma_get_required_mask(&ha->pdev->dev)) && | |
6a35528a | 1279 | !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
7524f9b9 | 1280 | /* Ok, a 64bit DMA mask is applicable. */ |
1da177e4 | 1281 | ha->flags.enable_64bit_addressing = 1; |
fd34f556 AV |
1282 | ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64; |
1283 | ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64; | |
7524f9b9 | 1284 | return; |
1da177e4 | 1285 | } |
1da177e4 | 1286 | } |
7524f9b9 | 1287 | |
284901a9 YH |
1288 | dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32)); |
1289 | pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32)); | |
1da177e4 LT |
1290 | } |
1291 | ||
fd34f556 | 1292 | static void |
e315cd28 | 1293 | qla2x00_enable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1294 | { |
1295 | unsigned long flags = 0; | |
1296 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | |
1297 | ||
1298 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1299 | ha->interrupts_on = 1; | |
1300 | /* enable risc and host interrupts */ | |
1301 | WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC); | |
1302 | RD_REG_WORD(®->ictrl); | |
1303 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1304 | ||
1305 | } | |
1306 | ||
1307 | static void | |
e315cd28 | 1308 | qla2x00_disable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1309 | { |
1310 | unsigned long flags = 0; | |
1311 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | |
1312 | ||
1313 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1314 | ha->interrupts_on = 0; | |
1315 | /* disable risc and host interrupts */ | |
1316 | WRT_REG_WORD(®->ictrl, 0); | |
1317 | RD_REG_WORD(®->ictrl); | |
1318 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1319 | } | |
1320 | ||
1321 | static void | |
e315cd28 | 1322 | qla24xx_enable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1323 | { |
1324 | unsigned long flags = 0; | |
1325 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
1326 | ||
1327 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1328 | ha->interrupts_on = 1; | |
1329 | WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT); | |
1330 | RD_REG_DWORD(®->ictrl); | |
1331 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1332 | } | |
1333 | ||
1334 | static void | |
e315cd28 | 1335 | qla24xx_disable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1336 | { |
1337 | unsigned long flags = 0; | |
1338 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
1339 | ||
124f85e6 AV |
1340 | if (IS_NOPOLLING_TYPE(ha)) |
1341 | return; | |
fd34f556 AV |
1342 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1343 | ha->interrupts_on = 0; | |
1344 | WRT_REG_DWORD(®->ictrl, 0); | |
1345 | RD_REG_DWORD(®->ictrl); | |
1346 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1347 | } | |
1348 | ||
1349 | static struct isp_operations qla2100_isp_ops = { | |
1350 | .pci_config = qla2100_pci_config, | |
1351 | .reset_chip = qla2x00_reset_chip, | |
1352 | .chip_diag = qla2x00_chip_diag, | |
1353 | .config_rings = qla2x00_config_rings, | |
1354 | .reset_adapter = qla2x00_reset_adapter, | |
1355 | .nvram_config = qla2x00_nvram_config, | |
1356 | .update_fw_options = qla2x00_update_fw_options, | |
1357 | .load_risc = qla2x00_load_risc, | |
1358 | .pci_info_str = qla2x00_pci_info_str, | |
1359 | .fw_version_str = qla2x00_fw_version_str, | |
1360 | .intr_handler = qla2100_intr_handler, | |
1361 | .enable_intrs = qla2x00_enable_intrs, | |
1362 | .disable_intrs = qla2x00_disable_intrs, | |
1363 | .abort_command = qla2x00_abort_command, | |
523ec773 AV |
1364 | .target_reset = qla2x00_abort_target, |
1365 | .lun_reset = qla2x00_lun_reset, | |
fd34f556 AV |
1366 | .fabric_login = qla2x00_login_fabric, |
1367 | .fabric_logout = qla2x00_fabric_logout, | |
1368 | .calc_req_entries = qla2x00_calc_iocbs_32, | |
1369 | .build_iocbs = qla2x00_build_scsi_iocbs_32, | |
1370 | .prep_ms_iocb = qla2x00_prep_ms_iocb, | |
1371 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, | |
1372 | .read_nvram = qla2x00_read_nvram_data, | |
1373 | .write_nvram = qla2x00_write_nvram_data, | |
1374 | .fw_dump = qla2100_fw_dump, | |
1375 | .beacon_on = NULL, | |
1376 | .beacon_off = NULL, | |
1377 | .beacon_blink = NULL, | |
1378 | .read_optrom = qla2x00_read_optrom_data, | |
1379 | .write_optrom = qla2x00_write_optrom_data, | |
1380 | .get_flash_version = qla2x00_get_flash_version, | |
e315cd28 | 1381 | .start_scsi = qla2x00_start_scsi, |
fd34f556 AV |
1382 | }; |
1383 | ||
1384 | static struct isp_operations qla2300_isp_ops = { | |
1385 | .pci_config = qla2300_pci_config, | |
1386 | .reset_chip = qla2x00_reset_chip, | |
1387 | .chip_diag = qla2x00_chip_diag, | |
1388 | .config_rings = qla2x00_config_rings, | |
1389 | .reset_adapter = qla2x00_reset_adapter, | |
1390 | .nvram_config = qla2x00_nvram_config, | |
1391 | .update_fw_options = qla2x00_update_fw_options, | |
1392 | .load_risc = qla2x00_load_risc, | |
1393 | .pci_info_str = qla2x00_pci_info_str, | |
1394 | .fw_version_str = qla2x00_fw_version_str, | |
1395 | .intr_handler = qla2300_intr_handler, | |
1396 | .enable_intrs = qla2x00_enable_intrs, | |
1397 | .disable_intrs = qla2x00_disable_intrs, | |
1398 | .abort_command = qla2x00_abort_command, | |
523ec773 AV |
1399 | .target_reset = qla2x00_abort_target, |
1400 | .lun_reset = qla2x00_lun_reset, | |
fd34f556 AV |
1401 | .fabric_login = qla2x00_login_fabric, |
1402 | .fabric_logout = qla2x00_fabric_logout, | |
1403 | .calc_req_entries = qla2x00_calc_iocbs_32, | |
1404 | .build_iocbs = qla2x00_build_scsi_iocbs_32, | |
1405 | .prep_ms_iocb = qla2x00_prep_ms_iocb, | |
1406 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, | |
1407 | .read_nvram = qla2x00_read_nvram_data, | |
1408 | .write_nvram = qla2x00_write_nvram_data, | |
1409 | .fw_dump = qla2300_fw_dump, | |
1410 | .beacon_on = qla2x00_beacon_on, | |
1411 | .beacon_off = qla2x00_beacon_off, | |
1412 | .beacon_blink = qla2x00_beacon_blink, | |
1413 | .read_optrom = qla2x00_read_optrom_data, | |
1414 | .write_optrom = qla2x00_write_optrom_data, | |
1415 | .get_flash_version = qla2x00_get_flash_version, | |
e315cd28 | 1416 | .start_scsi = qla2x00_start_scsi, |
fd34f556 AV |
1417 | }; |
1418 | ||
1419 | static struct isp_operations qla24xx_isp_ops = { | |
1420 | .pci_config = qla24xx_pci_config, | |
1421 | .reset_chip = qla24xx_reset_chip, | |
1422 | .chip_diag = qla24xx_chip_diag, | |
1423 | .config_rings = qla24xx_config_rings, | |
1424 | .reset_adapter = qla24xx_reset_adapter, | |
1425 | .nvram_config = qla24xx_nvram_config, | |
1426 | .update_fw_options = qla24xx_update_fw_options, | |
1427 | .load_risc = qla24xx_load_risc, | |
1428 | .pci_info_str = qla24xx_pci_info_str, | |
1429 | .fw_version_str = qla24xx_fw_version_str, | |
1430 | .intr_handler = qla24xx_intr_handler, | |
1431 | .enable_intrs = qla24xx_enable_intrs, | |
1432 | .disable_intrs = qla24xx_disable_intrs, | |
1433 | .abort_command = qla24xx_abort_command, | |
523ec773 AV |
1434 | .target_reset = qla24xx_abort_target, |
1435 | .lun_reset = qla24xx_lun_reset, | |
fd34f556 AV |
1436 | .fabric_login = qla24xx_login_fabric, |
1437 | .fabric_logout = qla24xx_fabric_logout, | |
1438 | .calc_req_entries = NULL, | |
1439 | .build_iocbs = NULL, | |
1440 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
1441 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
1442 | .read_nvram = qla24xx_read_nvram_data, | |
1443 | .write_nvram = qla24xx_write_nvram_data, | |
1444 | .fw_dump = qla24xx_fw_dump, | |
1445 | .beacon_on = qla24xx_beacon_on, | |
1446 | .beacon_off = qla24xx_beacon_off, | |
1447 | .beacon_blink = qla24xx_beacon_blink, | |
1448 | .read_optrom = qla24xx_read_optrom_data, | |
1449 | .write_optrom = qla24xx_write_optrom_data, | |
1450 | .get_flash_version = qla24xx_get_flash_version, | |
e315cd28 | 1451 | .start_scsi = qla24xx_start_scsi, |
fd34f556 AV |
1452 | }; |
1453 | ||
c3a2f0df AV |
1454 | static struct isp_operations qla25xx_isp_ops = { |
1455 | .pci_config = qla25xx_pci_config, | |
1456 | .reset_chip = qla24xx_reset_chip, | |
1457 | .chip_diag = qla24xx_chip_diag, | |
1458 | .config_rings = qla24xx_config_rings, | |
1459 | .reset_adapter = qla24xx_reset_adapter, | |
1460 | .nvram_config = qla24xx_nvram_config, | |
1461 | .update_fw_options = qla24xx_update_fw_options, | |
1462 | .load_risc = qla24xx_load_risc, | |
1463 | .pci_info_str = qla24xx_pci_info_str, | |
1464 | .fw_version_str = qla24xx_fw_version_str, | |
1465 | .intr_handler = qla24xx_intr_handler, | |
1466 | .enable_intrs = qla24xx_enable_intrs, | |
1467 | .disable_intrs = qla24xx_disable_intrs, | |
1468 | .abort_command = qla24xx_abort_command, | |
523ec773 AV |
1469 | .target_reset = qla24xx_abort_target, |
1470 | .lun_reset = qla24xx_lun_reset, | |
c3a2f0df AV |
1471 | .fabric_login = qla24xx_login_fabric, |
1472 | .fabric_logout = qla24xx_fabric_logout, | |
1473 | .calc_req_entries = NULL, | |
1474 | .build_iocbs = NULL, | |
1475 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
1476 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
1477 | .read_nvram = qla25xx_read_nvram_data, | |
1478 | .write_nvram = qla25xx_write_nvram_data, | |
1479 | .fw_dump = qla25xx_fw_dump, | |
1480 | .beacon_on = qla24xx_beacon_on, | |
1481 | .beacon_off = qla24xx_beacon_off, | |
1482 | .beacon_blink = qla24xx_beacon_blink, | |
338c9161 | 1483 | .read_optrom = qla25xx_read_optrom_data, |
c3a2f0df AV |
1484 | .write_optrom = qla24xx_write_optrom_data, |
1485 | .get_flash_version = qla24xx_get_flash_version, | |
e315cd28 | 1486 | .start_scsi = qla24xx_start_scsi, |
c3a2f0df AV |
1487 | }; |
1488 | ||
3a03eb79 AV |
1489 | static struct isp_operations qla81xx_isp_ops = { |
1490 | .pci_config = qla25xx_pci_config, | |
1491 | .reset_chip = qla24xx_reset_chip, | |
1492 | .chip_diag = qla24xx_chip_diag, | |
1493 | .config_rings = qla24xx_config_rings, | |
1494 | .reset_adapter = qla24xx_reset_adapter, | |
1495 | .nvram_config = qla81xx_nvram_config, | |
1496 | .update_fw_options = qla81xx_update_fw_options, | |
eaac30be | 1497 | .load_risc = qla81xx_load_risc, |
3a03eb79 AV |
1498 | .pci_info_str = qla24xx_pci_info_str, |
1499 | .fw_version_str = qla24xx_fw_version_str, | |
1500 | .intr_handler = qla24xx_intr_handler, | |
1501 | .enable_intrs = qla24xx_enable_intrs, | |
1502 | .disable_intrs = qla24xx_disable_intrs, | |
1503 | .abort_command = qla24xx_abort_command, | |
1504 | .target_reset = qla24xx_abort_target, | |
1505 | .lun_reset = qla24xx_lun_reset, | |
1506 | .fabric_login = qla24xx_login_fabric, | |
1507 | .fabric_logout = qla24xx_fabric_logout, | |
1508 | .calc_req_entries = NULL, | |
1509 | .build_iocbs = NULL, | |
1510 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
1511 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
3d79038f AV |
1512 | .read_nvram = NULL, |
1513 | .write_nvram = NULL, | |
3a03eb79 AV |
1514 | .fw_dump = qla81xx_fw_dump, |
1515 | .beacon_on = qla24xx_beacon_on, | |
1516 | .beacon_off = qla24xx_beacon_off, | |
1517 | .beacon_blink = qla24xx_beacon_blink, | |
1518 | .read_optrom = qla25xx_read_optrom_data, | |
1519 | .write_optrom = qla24xx_write_optrom_data, | |
1520 | .get_flash_version = qla24xx_get_flash_version, | |
1521 | .start_scsi = qla24xx_start_scsi, | |
3a03eb79 AV |
1522 | }; |
1523 | ||
ea5b6382 | 1524 | static inline void |
e315cd28 | 1525 | qla2x00_set_isp_flags(struct qla_hw_data *ha) |
ea5b6382 AV |
1526 | { |
1527 | ha->device_type = DT_EXTENDED_IDS; | |
1528 | switch (ha->pdev->device) { | |
1529 | case PCI_DEVICE_ID_QLOGIC_ISP2100: | |
1530 | ha->device_type |= DT_ISP2100; | |
1531 | ha->device_type &= ~DT_EXTENDED_IDS; | |
441d1072 | 1532 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
ea5b6382 AV |
1533 | break; |
1534 | case PCI_DEVICE_ID_QLOGIC_ISP2200: | |
1535 | ha->device_type |= DT_ISP2200; | |
1536 | ha->device_type &= ~DT_EXTENDED_IDS; | |
441d1072 | 1537 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
ea5b6382 AV |
1538 | break; |
1539 | case PCI_DEVICE_ID_QLOGIC_ISP2300: | |
1540 | ha->device_type |= DT_ISP2300; | |
4a59f71d | 1541 | ha->device_type |= DT_ZIO_SUPPORTED; |
441d1072 | 1542 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
1543 | break; |
1544 | case PCI_DEVICE_ID_QLOGIC_ISP2312: | |
1545 | ha->device_type |= DT_ISP2312; | |
4a59f71d | 1546 | ha->device_type |= DT_ZIO_SUPPORTED; |
441d1072 | 1547 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
1548 | break; |
1549 | case PCI_DEVICE_ID_QLOGIC_ISP2322: | |
1550 | ha->device_type |= DT_ISP2322; | |
4a59f71d | 1551 | ha->device_type |= DT_ZIO_SUPPORTED; |
ea5b6382 AV |
1552 | if (ha->pdev->subsystem_vendor == 0x1028 && |
1553 | ha->pdev->subsystem_device == 0x0170) | |
1554 | ha->device_type |= DT_OEM_001; | |
441d1072 | 1555 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
1556 | break; |
1557 | case PCI_DEVICE_ID_QLOGIC_ISP6312: | |
1558 | ha->device_type |= DT_ISP6312; | |
441d1072 | 1559 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
1560 | break; |
1561 | case PCI_DEVICE_ID_QLOGIC_ISP6322: | |
1562 | ha->device_type |= DT_ISP6322; | |
441d1072 | 1563 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
1564 | break; |
1565 | case PCI_DEVICE_ID_QLOGIC_ISP2422: | |
1566 | ha->device_type |= DT_ISP2422; | |
4a59f71d | 1567 | ha->device_type |= DT_ZIO_SUPPORTED; |
e428924c | 1568 | ha->device_type |= DT_FWI2; |
c76f2c01 | 1569 | ha->device_type |= DT_IIDMA; |
441d1072 | 1570 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 AV |
1571 | break; |
1572 | case PCI_DEVICE_ID_QLOGIC_ISP2432: | |
1573 | ha->device_type |= DT_ISP2432; | |
4a59f71d | 1574 | ha->device_type |= DT_ZIO_SUPPORTED; |
e428924c | 1575 | ha->device_type |= DT_FWI2; |
c76f2c01 | 1576 | ha->device_type |= DT_IIDMA; |
441d1072 | 1577 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 1578 | break; |
4d4df193 HK |
1579 | case PCI_DEVICE_ID_QLOGIC_ISP8432: |
1580 | ha->device_type |= DT_ISP8432; | |
1581 | ha->device_type |= DT_ZIO_SUPPORTED; | |
1582 | ha->device_type |= DT_FWI2; | |
1583 | ha->device_type |= DT_IIDMA; | |
1584 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
1585 | break; | |
044cc6c8 AV |
1586 | case PCI_DEVICE_ID_QLOGIC_ISP5422: |
1587 | ha->device_type |= DT_ISP5422; | |
e428924c | 1588 | ha->device_type |= DT_FWI2; |
441d1072 | 1589 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 1590 | break; |
044cc6c8 AV |
1591 | case PCI_DEVICE_ID_QLOGIC_ISP5432: |
1592 | ha->device_type |= DT_ISP5432; | |
e428924c | 1593 | ha->device_type |= DT_FWI2; |
441d1072 | 1594 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 1595 | break; |
c3a2f0df AV |
1596 | case PCI_DEVICE_ID_QLOGIC_ISP2532: |
1597 | ha->device_type |= DT_ISP2532; | |
1598 | ha->device_type |= DT_ZIO_SUPPORTED; | |
1599 | ha->device_type |= DT_FWI2; | |
1600 | ha->device_type |= DT_IIDMA; | |
441d1072 | 1601 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 1602 | break; |
3a03eb79 AV |
1603 | case PCI_DEVICE_ID_QLOGIC_ISP8001: |
1604 | ha->device_type |= DT_ISP8001; | |
1605 | ha->device_type |= DT_ZIO_SUPPORTED; | |
1606 | ha->device_type |= DT_FWI2; | |
1607 | ha->device_type |= DT_IIDMA; | |
1608 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
1609 | break; | |
ea5b6382 | 1610 | } |
e5b68a61 AC |
1611 | |
1612 | /* Get adapter physical port no from interrupt pin register. */ | |
1613 | pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no); | |
1614 | if (ha->port_no & 1) | |
1615 | ha->flags.port0 = 1; | |
1616 | else | |
1617 | ha->flags.port0 = 0; | |
ea5b6382 AV |
1618 | } |
1619 | ||
1da177e4 | 1620 | static int |
e315cd28 | 1621 | qla2x00_iospace_config(struct qla_hw_data *ha) |
1da177e4 | 1622 | { |
3776541d | 1623 | resource_size_t pio; |
73208dfd | 1624 | uint16_t msix; |
68ca949c | 1625 | int cpus; |
1da177e4 | 1626 | |
285d0321 AV |
1627 | if (pci_request_selected_regions(ha->pdev, ha->bars, |
1628 | QLA2XXX_DRIVER_NAME)) { | |
1629 | qla_printk(KERN_WARNING, ha, | |
1630 | "Failed to reserve PIO/MMIO regions (%s)\n", | |
1631 | pci_name(ha->pdev)); | |
1632 | ||
1633 | goto iospace_error_exit; | |
1634 | } | |
1635 | if (!(ha->bars & 1)) | |
1636 | goto skip_pio; | |
1637 | ||
1da177e4 LT |
1638 | /* We only need PIO for Flash operations on ISP2312 v2 chips. */ |
1639 | pio = pci_resource_start(ha->pdev, 0); | |
3776541d AV |
1640 | if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) { |
1641 | if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) { | |
1da177e4 LT |
1642 | qla_printk(KERN_WARNING, ha, |
1643 | "Invalid PCI I/O region size (%s)...\n", | |
1644 | pci_name(ha->pdev)); | |
1645 | pio = 0; | |
1646 | } | |
1647 | } else { | |
1648 | qla_printk(KERN_WARNING, ha, | |
1649 | "region #0 not a PIO resource (%s)...\n", | |
1650 | pci_name(ha->pdev)); | |
1651 | pio = 0; | |
1652 | } | |
285d0321 | 1653 | ha->pio_address = pio; |
1da177e4 | 1654 | |
285d0321 | 1655 | skip_pio: |
1da177e4 | 1656 | /* Use MMIO operations for all accesses. */ |
3776541d | 1657 | if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) { |
1da177e4 | 1658 | qla_printk(KERN_ERR, ha, |
3776541d | 1659 | "region #1 not an MMIO resource (%s), aborting\n", |
1da177e4 LT |
1660 | pci_name(ha->pdev)); |
1661 | goto iospace_error_exit; | |
1662 | } | |
3776541d | 1663 | if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) { |
1da177e4 LT |
1664 | qla_printk(KERN_ERR, ha, |
1665 | "Invalid PCI mem region size (%s), aborting\n", | |
1666 | pci_name(ha->pdev)); | |
1667 | goto iospace_error_exit; | |
1668 | } | |
1669 | ||
3776541d | 1670 | ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN); |
1da177e4 LT |
1671 | if (!ha->iobase) { |
1672 | qla_printk(KERN_ERR, ha, | |
1673 | "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev)); | |
1674 | ||
1675 | goto iospace_error_exit; | |
1676 | } | |
1677 | ||
73208dfd | 1678 | /* Determine queue resources */ |
2afa19a9 | 1679 | ha->max_req_queues = ha->max_rsp_queues = 1; |
68ca949c | 1680 | if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) && |
2afa19a9 | 1681 | (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))) |
17d98630 AC |
1682 | goto mqiobase_exit; |
1683 | ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3), | |
1684 | pci_resource_len(ha->pdev, 3)); | |
1685 | if (ha->mqiobase) { | |
1686 | /* Read MSIX vector size of the board */ | |
1687 | pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix); | |
1688 | ha->msix_count = msix; | |
68ca949c AC |
1689 | /* Max queues are bounded by available msix vectors */ |
1690 | /* queue 0 uses two msix vectors */ | |
1691 | if (ql2xmultique_tag) { | |
1692 | cpus = num_online_cpus(); | |
27dc9c5a | 1693 | ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ? |
68ca949c AC |
1694 | (cpus + 1) : (ha->msix_count - 1); |
1695 | ha->max_req_queues = 2; | |
1696 | } else if (ql2xmaxqueues > 1) { | |
2afa19a9 AC |
1697 | ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ? |
1698 | QLA_MQ_SIZE : ql2xmaxqueues; | |
1699 | DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no" | |
1700 | " of request queues:%d\n", ha->max_req_queues)); | |
1701 | } | |
68ca949c AC |
1702 | qla_printk(KERN_INFO, ha, |
1703 | "MSI-X vector count: %d\n", msix); | |
2afa19a9 AC |
1704 | } else |
1705 | qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n"); | |
17d98630 AC |
1706 | |
1707 | mqiobase_exit: | |
2afa19a9 | 1708 | ha->msix_count = ha->max_rsp_queues + 1; |
1da177e4 LT |
1709 | return (0); |
1710 | ||
1711 | iospace_error_exit: | |
1712 | return (-ENOMEM); | |
1713 | } | |
1714 | ||
1e99e33a AV |
1715 | static void |
1716 | qla2xxx_scan_start(struct Scsi_Host *shost) | |
1717 | { | |
e315cd28 | 1718 | scsi_qla_host_t *vha = shost_priv(shost); |
1e99e33a | 1719 | |
cbc8eb67 AV |
1720 | if (vha->hw->flags.running_gold_fw) |
1721 | return; | |
1722 | ||
e315cd28 AC |
1723 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
1724 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
1725 | set_bit(RSCN_UPDATE, &vha->dpc_flags); | |
1726 | set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags); | |
1e99e33a AV |
1727 | } |
1728 | ||
1729 | static int | |
1730 | qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
1731 | { | |
e315cd28 | 1732 | scsi_qla_host_t *vha = shost_priv(shost); |
1e99e33a | 1733 | |
e315cd28 | 1734 | if (!vha->host) |
1e99e33a | 1735 | return 1; |
e315cd28 | 1736 | if (time > vha->hw->loop_reset_delay * HZ) |
1e99e33a AV |
1737 | return 1; |
1738 | ||
e315cd28 | 1739 | return atomic_read(&vha->loop_state) == LOOP_READY; |
1e99e33a AV |
1740 | } |
1741 | ||
1da177e4 LT |
1742 | /* |
1743 | * PCI driver interface | |
1744 | */ | |
7ee61397 AV |
1745 | static int __devinit |
1746 | qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | |
1da177e4 | 1747 | { |
a1541d5a | 1748 | int ret = -ENODEV; |
1da177e4 | 1749 | struct Scsi_Host *host; |
e315cd28 AC |
1750 | scsi_qla_host_t *base_vha = NULL; |
1751 | struct qla_hw_data *ha; | |
29856e28 | 1752 | char pci_info[30]; |
1da177e4 | 1753 | char fw_str[30]; |
5433383e | 1754 | struct scsi_host_template *sht; |
c51da4ec | 1755 | int bars, max_id, mem_only = 0; |
e315cd28 | 1756 | uint16_t req_length = 0, rsp_length = 0; |
73208dfd AC |
1757 | struct req_que *req = NULL; |
1758 | struct rsp_que *rsp = NULL; | |
1da177e4 | 1759 | |
285d0321 | 1760 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
a5326f86 | 1761 | sht = &qla2xxx_driver_template; |
5433383e | 1762 | if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || |
8bc69e7d | 1763 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 || |
4d4df193 | 1764 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 || |
8bc69e7d | 1765 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 || |
c3a2f0df | 1766 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 || |
3a03eb79 AV |
1767 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 || |
1768 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) { | |
285d0321 | 1769 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
09483916 | 1770 | mem_only = 1; |
285d0321 AV |
1771 | } |
1772 | ||
09483916 BH |
1773 | if (mem_only) { |
1774 | if (pci_enable_device_mem(pdev)) | |
1775 | goto probe_out; | |
1776 | } else { | |
1777 | if (pci_enable_device(pdev)) | |
1778 | goto probe_out; | |
1779 | } | |
285d0321 | 1780 | |
0927678f JB |
1781 | /* This may fail but that's ok */ |
1782 | pci_enable_pcie_error_reporting(pdev); | |
285d0321 | 1783 | |
e315cd28 AC |
1784 | ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL); |
1785 | if (!ha) { | |
1786 | DEBUG(printk("Unable to allocate memory for ha\n")); | |
1787 | goto probe_out; | |
1da177e4 | 1788 | } |
e315cd28 | 1789 | ha->pdev = pdev; |
1da177e4 LT |
1790 | |
1791 | /* Clear our data area */ | |
285d0321 | 1792 | ha->bars = bars; |
09483916 | 1793 | ha->mem_only = mem_only; |
df4bf0bb | 1794 | spin_lock_init(&ha->hardware_lock); |
1da177e4 | 1795 | |
ea5b6382 AV |
1796 | /* Set ISP-type information. */ |
1797 | qla2x00_set_isp_flags(ha); | |
ca79cf66 DG |
1798 | |
1799 | /* Set EEH reset type to fundamental if required by hba */ | |
1800 | if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) { | |
1801 | pdev->needs_freset = 1; | |
ca79cf66 DG |
1802 | } |
1803 | ||
1da177e4 LT |
1804 | /* Configure PCI I/O space */ |
1805 | ret = qla2x00_iospace_config(ha); | |
a1541d5a | 1806 | if (ret) |
e315cd28 | 1807 | goto probe_hw_failed; |
1da177e4 | 1808 | |
1da177e4 | 1809 | qla_printk(KERN_INFO, ha, |
5433383e AV |
1810 | "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq, |
1811 | ha->iobase); | |
1da177e4 | 1812 | |
1da177e4 | 1813 | ha->prev_topology = 0; |
fca29703 | 1814 | ha->init_cb_size = sizeof(init_cb_t); |
d8b45213 | 1815 | ha->link_data_rate = PORT_SPEED_UNKNOWN; |
854165f4 | 1816 | ha->optrom_size = OPTROM_SIZE_2300; |
1da177e4 | 1817 | |
abbd8870 | 1818 | /* Assign ISP specific operations. */ |
e315cd28 | 1819 | max_id = MAX_TARGETS_2200; |
1da177e4 | 1820 | if (IS_QLA2100(ha)) { |
e315cd28 | 1821 | max_id = MAX_TARGETS_2100; |
1da177e4 | 1822 | ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; |
e315cd28 AC |
1823 | req_length = REQUEST_ENTRY_CNT_2100; |
1824 | rsp_length = RESPONSE_ENTRY_CNT_2100; | |
1825 | ha->max_loop_id = SNS_LAST_LOOP_ID_2100; | |
abbd8870 | 1826 | ha->gid_list_info_size = 4; |
3a03eb79 AV |
1827 | ha->flash_conf_off = ~0; |
1828 | ha->flash_data_off = ~0; | |
1829 | ha->nvram_conf_off = ~0; | |
1830 | ha->nvram_data_off = ~0; | |
fd34f556 | 1831 | ha->isp_ops = &qla2100_isp_ops; |
1da177e4 | 1832 | } else if (IS_QLA2200(ha)) { |
1da177e4 | 1833 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
1834 | req_length = REQUEST_ENTRY_CNT_2200; |
1835 | rsp_length = RESPONSE_ENTRY_CNT_2100; | |
1836 | ha->max_loop_id = SNS_LAST_LOOP_ID_2100; | |
abbd8870 | 1837 | ha->gid_list_info_size = 4; |
3a03eb79 AV |
1838 | ha->flash_conf_off = ~0; |
1839 | ha->flash_data_off = ~0; | |
1840 | ha->nvram_conf_off = ~0; | |
1841 | ha->nvram_data_off = ~0; | |
fd34f556 | 1842 | ha->isp_ops = &qla2100_isp_ops; |
fca29703 | 1843 | } else if (IS_QLA23XX(ha)) { |
1da177e4 | 1844 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
1845 | req_length = REQUEST_ENTRY_CNT_2200; |
1846 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
1847 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
abbd8870 | 1848 | ha->gid_list_info_size = 6; |
854165f4 AV |
1849 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
1850 | ha->optrom_size = OPTROM_SIZE_2322; | |
3a03eb79 AV |
1851 | ha->flash_conf_off = ~0; |
1852 | ha->flash_data_off = ~0; | |
1853 | ha->nvram_conf_off = ~0; | |
1854 | ha->nvram_data_off = ~0; | |
fd34f556 | 1855 | ha->isp_ops = &qla2300_isp_ops; |
4d4df193 | 1856 | } else if (IS_QLA24XX_TYPE(ha)) { |
fca29703 | 1857 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
1858 | req_length = REQUEST_ENTRY_CNT_24XX; |
1859 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
1860 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
2c3dfe3f | 1861 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
fca29703 | 1862 | ha->gid_list_info_size = 8; |
854165f4 | 1863 | ha->optrom_size = OPTROM_SIZE_24XX; |
73208dfd | 1864 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX; |
fd34f556 | 1865 | ha->isp_ops = &qla24xx_isp_ops; |
3a03eb79 AV |
1866 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
1867 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | |
1868 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | |
1869 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | |
c3a2f0df | 1870 | } else if (IS_QLA25XX(ha)) { |
c3a2f0df | 1871 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
1872 | req_length = REQUEST_ENTRY_CNT_24XX; |
1873 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
1874 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
c3a2f0df | 1875 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
c3a2f0df AV |
1876 | ha->gid_list_info_size = 8; |
1877 | ha->optrom_size = OPTROM_SIZE_25XX; | |
73208dfd | 1878 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
c3a2f0df | 1879 | ha->isp_ops = &qla25xx_isp_ops; |
3a03eb79 AV |
1880 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
1881 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | |
1882 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | |
1883 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | |
1884 | } else if (IS_QLA81XX(ha)) { | |
1885 | ha->mbx_count = MAILBOX_REGISTER_COUNT; | |
1886 | req_length = REQUEST_ENTRY_CNT_24XX; | |
1887 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
1888 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
1889 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
1890 | ha->gid_list_info_size = 8; | |
1891 | ha->optrom_size = OPTROM_SIZE_81XX; | |
40859ae5 | 1892 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
3a03eb79 AV |
1893 | ha->isp_ops = &qla81xx_isp_ops; |
1894 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX; | |
1895 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX; | |
1896 | ha->nvram_conf_off = ~0; | |
1897 | ha->nvram_data_off = ~0; | |
1da177e4 | 1898 | } |
1da177e4 | 1899 | |
6c2f527c | 1900 | mutex_init(&ha->vport_lock); |
0b05a1f0 MB |
1901 | init_completion(&ha->mbx_cmd_comp); |
1902 | complete(&ha->mbx_cmd_comp); | |
1903 | init_completion(&ha->mbx_intr_comp); | |
1da177e4 | 1904 | |
2c3dfe3f | 1905 | set_bit(0, (unsigned long *) ha->vp_idx_map); |
1da177e4 | 1906 | |
53303c42 | 1907 | qla2x00_config_dma_addressing(ha); |
73208dfd | 1908 | ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp); |
e315cd28 | 1909 | if (!ret) { |
1da177e4 LT |
1910 | qla_printk(KERN_WARNING, ha, |
1911 | "[ERROR] Failed to allocate memory for adapter\n"); | |
1912 | ||
e315cd28 AC |
1913 | goto probe_hw_failed; |
1914 | } | |
1915 | ||
73208dfd | 1916 | req->max_q_depth = MAX_Q_DEPTH; |
e315cd28 | 1917 | if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU) |
73208dfd AC |
1918 | req->max_q_depth = ql2xmaxqdepth; |
1919 | ||
e315cd28 AC |
1920 | |
1921 | base_vha = qla2x00_create_host(sht, ha); | |
1922 | if (!base_vha) { | |
1923 | qla_printk(KERN_WARNING, ha, | |
1924 | "[ERROR] Failed to allocate memory for scsi_host\n"); | |
1925 | ||
a1541d5a | 1926 | ret = -ENOMEM; |
6e9f21f3 | 1927 | qla2x00_mem_free(ha); |
2afa19a9 AC |
1928 | qla2x00_free_req_que(ha, req); |
1929 | qla2x00_free_rsp_que(ha, rsp); | |
e315cd28 | 1930 | goto probe_hw_failed; |
1da177e4 LT |
1931 | } |
1932 | ||
e315cd28 AC |
1933 | pci_set_drvdata(pdev, base_vha); |
1934 | ||
e315cd28 | 1935 | host = base_vha->host; |
2afa19a9 | 1936 | base_vha->req = req; |
73208dfd AC |
1937 | host->can_queue = req->length + 128; |
1938 | if (IS_QLA2XXX_MIDTYPE(ha)) | |
e315cd28 | 1939 | base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx; |
73208dfd | 1940 | else |
e315cd28 AC |
1941 | base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER + |
1942 | base_vha->vp_idx; | |
e315cd28 AC |
1943 | if (IS_QLA2100(ha)) |
1944 | host->sg_tablesize = 32; | |
1945 | host->max_id = max_id; | |
1946 | host->this_id = 255; | |
1947 | host->cmd_per_lun = 3; | |
1948 | host->unique_id = host->host_no; | |
1949 | host->max_cmd_len = MAX_CMDSZ; | |
1950 | host->max_channel = MAX_BUSES - 1; | |
1951 | host->max_lun = MAX_LUNS; | |
1952 | host->transportt = qla2xxx_transport_template; | |
9a069e19 | 1953 | sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC); |
e315cd28 | 1954 | |
73208dfd AC |
1955 | /* Set up the irqs */ |
1956 | ret = qla2x00_request_irqs(ha, rsp); | |
1957 | if (ret) | |
6e9f21f3 | 1958 | goto probe_init_failed; |
90a86fc0 JC |
1959 | |
1960 | pci_save_state(pdev); | |
1961 | ||
73208dfd | 1962 | /* Alloc arrays of request and response ring ptrs */ |
7163ea81 | 1963 | que_init: |
73208dfd AC |
1964 | if (!qla2x00_alloc_queues(ha)) { |
1965 | qla_printk(KERN_WARNING, ha, | |
1966 | "[ERROR] Failed to allocate memory for queue" | |
1967 | " pointers\n"); | |
6e9f21f3 | 1968 | goto probe_init_failed; |
73208dfd AC |
1969 | } |
1970 | ha->rsp_q_map[0] = rsp; | |
1971 | ha->req_q_map[0] = req; | |
2afa19a9 AC |
1972 | rsp->req = req; |
1973 | req->rsp = rsp; | |
1974 | set_bit(0, ha->req_qid_map); | |
1975 | set_bit(0, ha->rsp_qid_map); | |
08029990 AV |
1976 | /* FWI2-capable only. */ |
1977 | req->req_q_in = &ha->iobase->isp24.req_q_in; | |
1978 | req->req_q_out = &ha->iobase->isp24.req_q_out; | |
1979 | rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in; | |
1980 | rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out; | |
17d98630 | 1981 | if (ha->mqenable) { |
08029990 AV |
1982 | req->req_q_in = &ha->mqiobase->isp25mq.req_q_in; |
1983 | req->req_q_out = &ha->mqiobase->isp25mq.req_q_out; | |
1984 | rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in; | |
1985 | rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out; | |
17d98630 AC |
1986 | } |
1987 | ||
e315cd28 | 1988 | if (qla2x00_initialize_adapter(base_vha)) { |
1da177e4 LT |
1989 | qla_printk(KERN_WARNING, ha, |
1990 | "Failed to initialize adapter\n"); | |
1991 | ||
1992 | DEBUG2(printk("scsi(%ld): Failed to initialize adapter - " | |
1993 | "Adapter flags %x.\n", | |
e315cd28 | 1994 | base_vha->host_no, base_vha->device_flags)); |
1da177e4 | 1995 | |
a1541d5a | 1996 | ret = -ENODEV; |
1da177e4 LT |
1997 | goto probe_failed; |
1998 | } | |
1999 | ||
7163ea81 AC |
2000 | if (ha->mqenable) { |
2001 | if (qla25xx_setup_mode(base_vha)) { | |
68ca949c AC |
2002 | qla_printk(KERN_WARNING, ha, |
2003 | "Can't create queues, falling back to single" | |
2004 | " queue mode\n"); | |
7163ea81 AC |
2005 | goto que_init; |
2006 | } | |
2007 | } | |
68ca949c | 2008 | |
cbc8eb67 AV |
2009 | if (ha->flags.running_gold_fw) |
2010 | goto skip_dpc; | |
2011 | ||
1da177e4 LT |
2012 | /* |
2013 | * Startup the kernel thread for this host adapter | |
2014 | */ | |
39a11240 | 2015 | ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha, |
e315cd28 | 2016 | "%s_dpc", base_vha->host_str); |
39a11240 | 2017 | if (IS_ERR(ha->dpc_thread)) { |
1da177e4 LT |
2018 | qla_printk(KERN_WARNING, ha, |
2019 | "Unable to start DPC thread!\n"); | |
39a11240 | 2020 | ret = PTR_ERR(ha->dpc_thread); |
1da177e4 LT |
2021 | goto probe_failed; |
2022 | } | |
1da177e4 | 2023 | |
cbc8eb67 | 2024 | skip_dpc: |
e315cd28 AC |
2025 | list_add_tail(&base_vha->list, &ha->vp_list); |
2026 | base_vha->host->irq = ha->pdev->irq; | |
1da177e4 LT |
2027 | |
2028 | /* Initialized the timer */ | |
e315cd28 | 2029 | qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL); |
1da177e4 LT |
2030 | |
2031 | DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", | |
e315cd28 | 2032 | base_vha->host_no, ha)); |
d19044c3 | 2033 | |
a1541d5a AV |
2034 | ret = scsi_add_host(host, &pdev->dev); |
2035 | if (ret) | |
2036 | goto probe_failed; | |
2037 | ||
1486400f MR |
2038 | base_vha->flags.init_done = 1; |
2039 | base_vha->flags.online = 1; | |
2040 | ||
048feec5 AV |
2041 | ha->isp_ops->enable_intrs(ha); |
2042 | ||
1e99e33a AV |
2043 | scsi_scan_host(host); |
2044 | ||
e315cd28 | 2045 | qla2x00_alloc_sysfs_attr(base_vha); |
a1541d5a | 2046 | |
e315cd28 | 2047 | qla2x00_init_host_attr(base_vha); |
a1541d5a | 2048 | |
e315cd28 | 2049 | qla2x00_dfs_setup(base_vha); |
df613b96 | 2050 | |
1da177e4 LT |
2051 | qla_printk(KERN_INFO, ha, "\n" |
2052 | " QLogic Fibre Channel HBA Driver: %s\n" | |
2053 | " QLogic %s - %s\n" | |
5433383e AV |
2054 | " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n", |
2055 | qla2x00_version_str, ha->model_number, | |
e315cd28 AC |
2056 | ha->model_desc ? ha->model_desc : "", pdev->device, |
2057 | ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev), | |
2058 | ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no, | |
2059 | ha->isp_ops->fw_version_str(base_vha, fw_str)); | |
1da177e4 | 2060 | |
1da177e4 LT |
2061 | return 0; |
2062 | ||
6e9f21f3 | 2063 | probe_init_failed: |
2afa19a9 AC |
2064 | qla2x00_free_req_que(ha, req); |
2065 | qla2x00_free_rsp_que(ha, rsp); | |
2066 | ha->max_req_queues = ha->max_rsp_queues = 0; | |
6e9f21f3 | 2067 | |
1da177e4 | 2068 | probe_failed: |
b9978769 AV |
2069 | if (base_vha->timer_active) |
2070 | qla2x00_stop_timer(base_vha); | |
2071 | base_vha->flags.online = 0; | |
2072 | if (ha->dpc_thread) { | |
2073 | struct task_struct *t = ha->dpc_thread; | |
2074 | ||
2075 | ha->dpc_thread = NULL; | |
2076 | kthread_stop(t); | |
2077 | } | |
2078 | ||
e315cd28 | 2079 | qla2x00_free_device(base_vha); |
1da177e4 | 2080 | |
e315cd28 | 2081 | scsi_host_put(base_vha->host); |
1da177e4 | 2082 | |
e315cd28 AC |
2083 | probe_hw_failed: |
2084 | if (ha->iobase) | |
2085 | iounmap(ha->iobase); | |
2086 | ||
2087 | pci_release_selected_regions(ha->pdev, ha->bars); | |
2088 | kfree(ha); | |
2089 | ha = NULL; | |
1da177e4 | 2090 | |
a1541d5a | 2091 | probe_out: |
e315cd28 | 2092 | pci_disable_device(pdev); |
a1541d5a | 2093 | return ret; |
1da177e4 | 2094 | } |
1da177e4 | 2095 | |
4c993f76 | 2096 | static void |
7ee61397 | 2097 | qla2x00_remove_one(struct pci_dev *pdev) |
1da177e4 | 2098 | { |
e315cd28 AC |
2099 | scsi_qla_host_t *base_vha, *vha, *temp; |
2100 | struct qla_hw_data *ha; | |
2101 | ||
2102 | base_vha = pci_get_drvdata(pdev); | |
2103 | ha = base_vha->hw; | |
2104 | ||
2105 | list_for_each_entry_safe(vha, temp, &ha->vp_list, list) { | |
2106 | if (vha && vha->fc_vport) | |
2107 | fc_vport_terminate(vha->fc_vport); | |
2108 | } | |
1da177e4 | 2109 | |
e315cd28 | 2110 | set_bit(UNLOADING, &base_vha->dpc_flags); |
1da177e4 | 2111 | |
b9978769 AV |
2112 | qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); |
2113 | ||
e315cd28 | 2114 | qla2x00_dfs_remove(base_vha); |
c795c1e4 | 2115 | |
e315cd28 | 2116 | qla84xx_put_chip(base_vha); |
c795c1e4 | 2117 | |
b9978769 AV |
2118 | /* Disable timer */ |
2119 | if (base_vha->timer_active) | |
2120 | qla2x00_stop_timer(base_vha); | |
2121 | ||
2122 | base_vha->flags.online = 0; | |
2123 | ||
68ca949c AC |
2124 | /* Flush the work queue and remove it */ |
2125 | if (ha->wq) { | |
2126 | flush_workqueue(ha->wq); | |
2127 | destroy_workqueue(ha->wq); | |
2128 | ha->wq = NULL; | |
2129 | } | |
2130 | ||
b9978769 AV |
2131 | /* Kill the kernel thread for this host */ |
2132 | if (ha->dpc_thread) { | |
2133 | struct task_struct *t = ha->dpc_thread; | |
2134 | ||
2135 | /* | |
2136 | * qla2xxx_wake_dpc checks for ->dpc_thread | |
2137 | * so we need to zero it out. | |
2138 | */ | |
2139 | ha->dpc_thread = NULL; | |
2140 | kthread_stop(t); | |
2141 | } | |
2142 | ||
e315cd28 | 2143 | qla2x00_free_sysfs_attr(base_vha); |
df613b96 | 2144 | |
e315cd28 | 2145 | fc_remove_host(base_vha->host); |
4d4df193 | 2146 | |
e315cd28 | 2147 | scsi_remove_host(base_vha->host); |
1da177e4 | 2148 | |
e315cd28 | 2149 | qla2x00_free_device(base_vha); |
bdf79621 | 2150 | |
e315cd28 | 2151 | scsi_host_put(base_vha->host); |
1da177e4 | 2152 | |
e315cd28 AC |
2153 | if (ha->iobase) |
2154 | iounmap(ha->iobase); | |
1da177e4 | 2155 | |
73208dfd AC |
2156 | if (ha->mqiobase) |
2157 | iounmap(ha->mqiobase); | |
2158 | ||
e315cd28 AC |
2159 | pci_release_selected_regions(ha->pdev, ha->bars); |
2160 | kfree(ha); | |
2161 | ha = NULL; | |
1da177e4 | 2162 | |
90a86fc0 JC |
2163 | pci_disable_pcie_error_reporting(pdev); |
2164 | ||
665db93b | 2165 | pci_disable_device(pdev); |
1da177e4 LT |
2166 | pci_set_drvdata(pdev, NULL); |
2167 | } | |
1da177e4 LT |
2168 | |
2169 | static void | |
e315cd28 | 2170 | qla2x00_free_device(scsi_qla_host_t *vha) |
1da177e4 | 2171 | { |
e315cd28 | 2172 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 2173 | |
85880801 AV |
2174 | qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16); |
2175 | ||
2176 | /* Disable timer */ | |
2177 | if (vha->timer_active) | |
2178 | qla2x00_stop_timer(vha); | |
2179 | ||
2180 | /* Kill the kernel thread for this host */ | |
2181 | if (ha->dpc_thread) { | |
2182 | struct task_struct *t = ha->dpc_thread; | |
2183 | ||
2184 | /* | |
2185 | * qla2xxx_wake_dpc checks for ->dpc_thread | |
2186 | * so we need to zero it out. | |
2187 | */ | |
2188 | ha->dpc_thread = NULL; | |
2189 | kthread_stop(t); | |
2190 | } | |
2191 | ||
2afa19a9 AC |
2192 | qla25xx_delete_queues(vha); |
2193 | ||
df613b96 | 2194 | if (ha->flags.fce_enabled) |
e315cd28 | 2195 | qla2x00_disable_fce_trace(vha, NULL, NULL); |
df613b96 | 2196 | |
a7a167bf | 2197 | if (ha->eft) |
e315cd28 | 2198 | qla2x00_disable_eft_trace(vha); |
a7a167bf | 2199 | |
f6ef3b18 | 2200 | /* Stop currently executing firmware. */ |
e315cd28 | 2201 | qla2x00_try_to_stop_firmware(vha); |
1da177e4 | 2202 | |
85880801 AV |
2203 | vha->flags.online = 0; |
2204 | ||
f6ef3b18 AV |
2205 | /* turn-off interrupts on the card */ |
2206 | if (ha->interrupts_on) | |
fd34f556 | 2207 | ha->isp_ops->disable_intrs(ha); |
f6ef3b18 | 2208 | |
e315cd28 | 2209 | qla2x00_free_irqs(vha); |
1da177e4 | 2210 | |
e315cd28 | 2211 | qla2x00_mem_free(ha); |
73208dfd AC |
2212 | |
2213 | qla2x00_free_queues(ha); | |
1da177e4 LT |
2214 | } |
2215 | ||
d97994dc | 2216 | static inline void |
e315cd28 | 2217 | qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport, |
d97994dc AV |
2218 | int defer) |
2219 | { | |
d97994dc | 2220 | struct fc_rport *rport; |
67becc00 | 2221 | scsi_qla_host_t *base_vha; |
d97994dc AV |
2222 | |
2223 | if (!fcport->rport) | |
2224 | return; | |
2225 | ||
2226 | rport = fcport->rport; | |
2227 | if (defer) { | |
67becc00 | 2228 | base_vha = pci_get_drvdata(vha->hw->pdev); |
e315cd28 | 2229 | spin_lock_irq(vha->host->host_lock); |
d97994dc | 2230 | fcport->drport = rport; |
e315cd28 | 2231 | spin_unlock_irq(vha->host->host_lock); |
67becc00 AV |
2232 | set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); |
2233 | qla2xxx_wake_dpc(base_vha); | |
5f3a9a20 | 2234 | } else |
d97994dc | 2235 | fc_remote_port_delete(rport); |
d97994dc AV |
2236 | } |
2237 | ||
1da177e4 LT |
2238 | /* |
2239 | * qla2x00_mark_device_lost Updates fcport state when device goes offline. | |
2240 | * | |
2241 | * Input: ha = adapter block pointer. fcport = port structure pointer. | |
2242 | * | |
2243 | * Return: None. | |
2244 | * | |
2245 | * Context: | |
2246 | */ | |
e315cd28 | 2247 | void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport, |
d97994dc | 2248 | int do_login, int defer) |
1da177e4 | 2249 | { |
2c3dfe3f | 2250 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
e315cd28 AC |
2251 | vha->vp_idx == fcport->vp_idx) { |
2252 | atomic_set(&fcport->state, FCS_DEVICE_LOST); | |
2253 | qla2x00_schedule_rport_del(vha, fcport, defer); | |
2254 | } | |
fa2a1ce5 | 2255 | /* |
1da177e4 LT |
2256 | * We may need to retry the login, so don't change the state of the |
2257 | * port but do the retries. | |
2258 | */ | |
2259 | if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD) | |
2260 | atomic_set(&fcport->state, FCS_DEVICE_LOST); | |
2261 | ||
2262 | if (!do_login) | |
2263 | return; | |
2264 | ||
2265 | if (fcport->login_retry == 0) { | |
e315cd28 AC |
2266 | fcport->login_retry = vha->hw->login_retry_count; |
2267 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
1da177e4 LT |
2268 | |
2269 | DEBUG(printk("scsi(%ld): Port login retry: " | |
2270 | "%02x%02x%02x%02x%02x%02x%02x%02x, " | |
2271 | "id = 0x%04x retry cnt=%d\n", | |
e315cd28 | 2272 | vha->host_no, |
1da177e4 LT |
2273 | fcport->port_name[0], |
2274 | fcport->port_name[1], | |
2275 | fcport->port_name[2], | |
2276 | fcport->port_name[3], | |
2277 | fcport->port_name[4], | |
2278 | fcport->port_name[5], | |
2279 | fcport->port_name[6], | |
2280 | fcport->port_name[7], | |
2281 | fcport->loop_id, | |
2282 | fcport->login_retry)); | |
2283 | } | |
2284 | } | |
2285 | ||
2286 | /* | |
2287 | * qla2x00_mark_all_devices_lost | |
2288 | * Updates fcport state when device goes offline. | |
2289 | * | |
2290 | * Input: | |
2291 | * ha = adapter block pointer. | |
2292 | * fcport = port structure pointer. | |
2293 | * | |
2294 | * Return: | |
2295 | * None. | |
2296 | * | |
2297 | * Context: | |
2298 | */ | |
2299 | void | |
e315cd28 | 2300 | qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer) |
1da177e4 LT |
2301 | { |
2302 | fc_port_t *fcport; | |
2303 | ||
e315cd28 | 2304 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
0d6e61bc | 2305 | if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx) |
1da177e4 | 2306 | continue; |
0d6e61bc | 2307 | |
1da177e4 LT |
2308 | /* |
2309 | * No point in marking the device as lost, if the device is | |
2310 | * already DEAD. | |
2311 | */ | |
2312 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) | |
2313 | continue; | |
e315cd28 | 2314 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
0d6e61bc AV |
2315 | if (defer) |
2316 | qla2x00_schedule_rport_del(vha, fcport, defer); | |
2317 | else if (vha->vp_idx == fcport->vp_idx) | |
2318 | qla2x00_schedule_rport_del(vha, fcport, defer); | |
2319 | } | |
2320 | atomic_set(&fcport->state, FCS_DEVICE_LOST); | |
1da177e4 LT |
2321 | } |
2322 | } | |
2323 | ||
2324 | /* | |
2325 | * qla2x00_mem_alloc | |
2326 | * Allocates adapter memory. | |
2327 | * | |
2328 | * Returns: | |
2329 | * 0 = success. | |
e8711085 | 2330 | * !0 = failure. |
1da177e4 | 2331 | */ |
e8711085 | 2332 | static int |
73208dfd AC |
2333 | qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len, |
2334 | struct req_que **req, struct rsp_que **rsp) | |
1da177e4 LT |
2335 | { |
2336 | char name[16]; | |
1da177e4 | 2337 | |
e8711085 | 2338 | ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size, |
e315cd28 | 2339 | &ha->init_cb_dma, GFP_KERNEL); |
e8711085 | 2340 | if (!ha->init_cb) |
e315cd28 | 2341 | goto fail; |
e8711085 | 2342 | |
e315cd28 AC |
2343 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE, |
2344 | &ha->gid_list_dma, GFP_KERNEL); | |
2345 | if (!ha->gid_list) | |
e8711085 | 2346 | goto fail_free_init_cb; |
1da177e4 | 2347 | |
e8711085 AV |
2348 | ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
2349 | if (!ha->srb_mempool) | |
e315cd28 | 2350 | goto fail_free_gid_list; |
e8711085 AV |
2351 | |
2352 | /* Get memory for cached NVRAM */ | |
2353 | ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL); | |
2354 | if (!ha->nvram) | |
2355 | goto fail_free_srb_mempool; | |
2356 | ||
e315cd28 AC |
2357 | snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME, |
2358 | ha->pdev->device); | |
2359 | ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, | |
2360 | DMA_POOL_SIZE, 8, 0); | |
2361 | if (!ha->s_dma_pool) | |
2362 | goto fail_free_nvram; | |
2363 | ||
e8711085 AV |
2364 | /* Allocate memory for SNS commands */ |
2365 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | |
e315cd28 | 2366 | /* Get consistent memory allocated for SNS commands */ |
e8711085 | 2367 | ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, |
e315cd28 | 2368 | sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL); |
e8711085 | 2369 | if (!ha->sns_cmd) |
e315cd28 | 2370 | goto fail_dma_pool; |
e8711085 | 2371 | } else { |
e315cd28 | 2372 | /* Get consistent memory allocated for MS IOCB */ |
e8711085 | 2373 | ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
e315cd28 | 2374 | &ha->ms_iocb_dma); |
e8711085 | 2375 | if (!ha->ms_iocb) |
e315cd28 AC |
2376 | goto fail_dma_pool; |
2377 | /* Get consistent memory allocated for CT SNS commands */ | |
e8711085 | 2378 | ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, |
e315cd28 | 2379 | sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL); |
e8711085 AV |
2380 | if (!ha->ct_sns) |
2381 | goto fail_free_ms_iocb; | |
1da177e4 LT |
2382 | } |
2383 | ||
e315cd28 | 2384 | /* Allocate memory for request ring */ |
73208dfd AC |
2385 | *req = kzalloc(sizeof(struct req_que), GFP_KERNEL); |
2386 | if (!*req) { | |
e315cd28 AC |
2387 | DEBUG(printk("Unable to allocate memory for req\n")); |
2388 | goto fail_req; | |
2389 | } | |
73208dfd AC |
2390 | (*req)->length = req_len; |
2391 | (*req)->ring = dma_alloc_coherent(&ha->pdev->dev, | |
2392 | ((*req)->length + 1) * sizeof(request_t), | |
2393 | &(*req)->dma, GFP_KERNEL); | |
2394 | if (!(*req)->ring) { | |
e315cd28 AC |
2395 | DEBUG(printk("Unable to allocate memory for req_ring\n")); |
2396 | goto fail_req_ring; | |
2397 | } | |
2398 | /* Allocate memory for response ring */ | |
73208dfd AC |
2399 | *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); |
2400 | if (!*rsp) { | |
2401 | qla_printk(KERN_WARNING, ha, | |
2402 | "Unable to allocate memory for rsp\n"); | |
e315cd28 AC |
2403 | goto fail_rsp; |
2404 | } | |
73208dfd AC |
2405 | (*rsp)->hw = ha; |
2406 | (*rsp)->length = rsp_len; | |
2407 | (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev, | |
2408 | ((*rsp)->length + 1) * sizeof(response_t), | |
2409 | &(*rsp)->dma, GFP_KERNEL); | |
2410 | if (!(*rsp)->ring) { | |
2411 | qla_printk(KERN_WARNING, ha, | |
2412 | "Unable to allocate memory for rsp_ring\n"); | |
e315cd28 AC |
2413 | goto fail_rsp_ring; |
2414 | } | |
73208dfd AC |
2415 | (*req)->rsp = *rsp; |
2416 | (*rsp)->req = *req; | |
2417 | /* Allocate memory for NVRAM data for vports */ | |
2418 | if (ha->nvram_npiv_size) { | |
2419 | ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) * | |
2420 | ha->nvram_npiv_size, GFP_KERNEL); | |
2421 | if (!ha->npiv_info) { | |
2422 | qla_printk(KERN_WARNING, ha, | |
2423 | "Unable to allocate memory for npiv info\n"); | |
2424 | goto fail_npiv_info; | |
2425 | } | |
2426 | } else | |
2427 | ha->npiv_info = NULL; | |
e8711085 | 2428 | |
b64b0e8f AV |
2429 | /* Get consistent memory allocated for EX-INIT-CB. */ |
2430 | if (IS_QLA81XX(ha)) { | |
2431 | ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | |
2432 | &ha->ex_init_cb_dma); | |
2433 | if (!ha->ex_init_cb) | |
2434 | goto fail_ex_init_cb; | |
2435 | } | |
2436 | ||
e315cd28 AC |
2437 | INIT_LIST_HEAD(&ha->vp_list); |
2438 | return 1; | |
2439 | ||
b64b0e8f AV |
2440 | fail_ex_init_cb: |
2441 | kfree(ha->npiv_info); | |
73208dfd AC |
2442 | fail_npiv_info: |
2443 | dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) * | |
2444 | sizeof(response_t), (*rsp)->ring, (*rsp)->dma); | |
2445 | (*rsp)->ring = NULL; | |
2446 | (*rsp)->dma = 0; | |
e315cd28 | 2447 | fail_rsp_ring: |
73208dfd | 2448 | kfree(*rsp); |
e315cd28 | 2449 | fail_rsp: |
73208dfd AC |
2450 | dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) * |
2451 | sizeof(request_t), (*req)->ring, (*req)->dma); | |
2452 | (*req)->ring = NULL; | |
2453 | (*req)->dma = 0; | |
e315cd28 | 2454 | fail_req_ring: |
73208dfd | 2455 | kfree(*req); |
e315cd28 AC |
2456 | fail_req: |
2457 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), | |
2458 | ha->ct_sns, ha->ct_sns_dma); | |
2459 | ha->ct_sns = NULL; | |
2460 | ha->ct_sns_dma = 0; | |
e8711085 AV |
2461 | fail_free_ms_iocb: |
2462 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); | |
2463 | ha->ms_iocb = NULL; | |
2464 | ha->ms_iocb_dma = 0; | |
e315cd28 AC |
2465 | fail_dma_pool: |
2466 | dma_pool_destroy(ha->s_dma_pool); | |
2467 | ha->s_dma_pool = NULL; | |
e8711085 AV |
2468 | fail_free_nvram: |
2469 | kfree(ha->nvram); | |
2470 | ha->nvram = NULL; | |
2471 | fail_free_srb_mempool: | |
2472 | mempool_destroy(ha->srb_mempool); | |
2473 | ha->srb_mempool = NULL; | |
e8711085 AV |
2474 | fail_free_gid_list: |
2475 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, | |
e315cd28 | 2476 | ha->gid_list_dma); |
e8711085 AV |
2477 | ha->gid_list = NULL; |
2478 | ha->gid_list_dma = 0; | |
e315cd28 AC |
2479 | fail_free_init_cb: |
2480 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, | |
2481 | ha->init_cb_dma); | |
2482 | ha->init_cb = NULL; | |
2483 | ha->init_cb_dma = 0; | |
e8711085 | 2484 | fail: |
e315cd28 | 2485 | DEBUG(printk("%s: Memory allocation failure\n", __func__)); |
e8711085 | 2486 | return -ENOMEM; |
1da177e4 LT |
2487 | } |
2488 | ||
2489 | /* | |
2490 | * qla2x00_mem_free | |
2491 | * Frees all adapter allocated memory. | |
2492 | * | |
2493 | * Input: | |
2494 | * ha = adapter block pointer. | |
2495 | */ | |
a824ebb3 | 2496 | static void |
e315cd28 | 2497 | qla2x00_mem_free(struct qla_hw_data *ha) |
1da177e4 | 2498 | { |
e8711085 AV |
2499 | if (ha->srb_mempool) |
2500 | mempool_destroy(ha->srb_mempool); | |
1da177e4 | 2501 | |
df613b96 AV |
2502 | if (ha->fce) |
2503 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, | |
e315cd28 | 2504 | ha->fce_dma); |
df613b96 | 2505 | |
a7a167bf AV |
2506 | if (ha->fw_dump) { |
2507 | if (ha->eft) | |
2508 | dma_free_coherent(&ha->pdev->dev, | |
e315cd28 | 2509 | ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma); |
a7a167bf AV |
2510 | vfree(ha->fw_dump); |
2511 | } | |
2512 | ||
11bbc1d8 AV |
2513 | if (ha->dcbx_tlv) |
2514 | dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, | |
2515 | ha->dcbx_tlv, ha->dcbx_tlv_dma); | |
2516 | ||
ce0423f4 AV |
2517 | if (ha->xgmac_data) |
2518 | dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE, | |
2519 | ha->xgmac_data, ha->xgmac_data_dma); | |
2520 | ||
1da177e4 LT |
2521 | if (ha->sns_cmd) |
2522 | dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), | |
e315cd28 | 2523 | ha->sns_cmd, ha->sns_cmd_dma); |
1da177e4 LT |
2524 | |
2525 | if (ha->ct_sns) | |
2526 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), | |
e315cd28 | 2527 | ha->ct_sns, ha->ct_sns_dma); |
1da177e4 | 2528 | |
88729e53 AV |
2529 | if (ha->sfp_data) |
2530 | dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma); | |
2531 | ||
ad0ecd61 JC |
2532 | if (ha->edc_data) |
2533 | dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma); | |
2534 | ||
1da177e4 LT |
2535 | if (ha->ms_iocb) |
2536 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); | |
2537 | ||
b64b0e8f AV |
2538 | if (ha->ex_init_cb) |
2539 | dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma); | |
2540 | ||
1da177e4 LT |
2541 | if (ha->s_dma_pool) |
2542 | dma_pool_destroy(ha->s_dma_pool); | |
2543 | ||
1da177e4 LT |
2544 | if (ha->gid_list) |
2545 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, | |
e315cd28 | 2546 | ha->gid_list_dma); |
1da177e4 | 2547 | |
e315cd28 AC |
2548 | if (ha->init_cb) |
2549 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, | |
2550 | ha->init_cb, ha->init_cb_dma); | |
2551 | vfree(ha->optrom_buffer); | |
2552 | kfree(ha->nvram); | |
73208dfd | 2553 | kfree(ha->npiv_info); |
1da177e4 | 2554 | |
e8711085 | 2555 | ha->srb_mempool = NULL; |
a7a167bf AV |
2556 | ha->eft = NULL; |
2557 | ha->eft_dma = 0; | |
1da177e4 LT |
2558 | ha->sns_cmd = NULL; |
2559 | ha->sns_cmd_dma = 0; | |
2560 | ha->ct_sns = NULL; | |
2561 | ha->ct_sns_dma = 0; | |
2562 | ha->ms_iocb = NULL; | |
2563 | ha->ms_iocb_dma = 0; | |
1da177e4 LT |
2564 | ha->init_cb = NULL; |
2565 | ha->init_cb_dma = 0; | |
b64b0e8f AV |
2566 | ha->ex_init_cb = NULL; |
2567 | ha->ex_init_cb_dma = 0; | |
1da177e4 LT |
2568 | |
2569 | ha->s_dma_pool = NULL; | |
2570 | ||
1da177e4 LT |
2571 | ha->gid_list = NULL; |
2572 | ha->gid_list_dma = 0; | |
2573 | ||
e315cd28 AC |
2574 | ha->fw_dump = NULL; |
2575 | ha->fw_dumped = 0; | |
2576 | ha->fw_dump_reading = 0; | |
e315cd28 | 2577 | } |
1da177e4 | 2578 | |
e315cd28 AC |
2579 | struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, |
2580 | struct qla_hw_data *ha) | |
2581 | { | |
2582 | struct Scsi_Host *host; | |
2583 | struct scsi_qla_host *vha = NULL; | |
854165f4 | 2584 | |
e315cd28 AC |
2585 | host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); |
2586 | if (host == NULL) { | |
2587 | printk(KERN_WARNING | |
2588 | "qla2xxx: Couldn't allocate host from scsi layer!\n"); | |
2589 | goto fail; | |
2590 | } | |
2591 | ||
2592 | /* Clear our data area */ | |
2593 | vha = shost_priv(host); | |
2594 | memset(vha, 0, sizeof(scsi_qla_host_t)); | |
2595 | ||
2596 | vha->host = host; | |
2597 | vha->host_no = host->host_no; | |
2598 | vha->hw = ha; | |
2599 | ||
2600 | INIT_LIST_HEAD(&vha->vp_fcports); | |
2601 | INIT_LIST_HEAD(&vha->work_list); | |
2602 | INIT_LIST_HEAD(&vha->list); | |
2603 | ||
f999f4c1 AV |
2604 | spin_lock_init(&vha->work_lock); |
2605 | ||
e315cd28 AC |
2606 | sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no); |
2607 | return vha; | |
2608 | ||
2609 | fail: | |
2610 | return vha; | |
1da177e4 LT |
2611 | } |
2612 | ||
01ef66bb | 2613 | static struct qla_work_evt * |
f999f4c1 | 2614 | qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type) |
0971de7f AV |
2615 | { |
2616 | struct qla_work_evt *e; | |
2617 | ||
f999f4c1 | 2618 | e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC); |
0971de7f AV |
2619 | if (!e) |
2620 | return NULL; | |
2621 | ||
2622 | INIT_LIST_HEAD(&e->list); | |
2623 | e->type = type; | |
2624 | e->flags = QLA_EVT_FLAG_FREE; | |
2625 | return e; | |
2626 | } | |
2627 | ||
01ef66bb | 2628 | static int |
f999f4c1 | 2629 | qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
0971de7f | 2630 | { |
f999f4c1 | 2631 | unsigned long flags; |
0971de7f | 2632 | |
f999f4c1 | 2633 | spin_lock_irqsave(&vha->work_lock, flags); |
e315cd28 | 2634 | list_add_tail(&e->list, &vha->work_list); |
f999f4c1 | 2635 | spin_unlock_irqrestore(&vha->work_lock, flags); |
e315cd28 | 2636 | qla2xxx_wake_dpc(vha); |
f999f4c1 | 2637 | |
0971de7f AV |
2638 | return QLA_SUCCESS; |
2639 | } | |
2640 | ||
2641 | int | |
e315cd28 | 2642 | qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code, |
0971de7f AV |
2643 | u32 data) |
2644 | { | |
2645 | struct qla_work_evt *e; | |
2646 | ||
f999f4c1 | 2647 | e = qla2x00_alloc_work(vha, QLA_EVT_AEN); |
0971de7f AV |
2648 | if (!e) |
2649 | return QLA_FUNCTION_FAILED; | |
2650 | ||
2651 | e->u.aen.code = code; | |
2652 | e->u.aen.data = data; | |
f999f4c1 | 2653 | return qla2x00_post_work(vha, e); |
0971de7f AV |
2654 | } |
2655 | ||
8a659571 AV |
2656 | int |
2657 | qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb) | |
2658 | { | |
2659 | struct qla_work_evt *e; | |
2660 | ||
f999f4c1 | 2661 | e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK); |
8a659571 AV |
2662 | if (!e) |
2663 | return QLA_FUNCTION_FAILED; | |
2664 | ||
2665 | memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t)); | |
f999f4c1 | 2666 | return qla2x00_post_work(vha, e); |
8a659571 AV |
2667 | } |
2668 | ||
ac280b67 AV |
2669 | #define qla2x00_post_async_work(name, type) \ |
2670 | int qla2x00_post_async_##name##_work( \ | |
2671 | struct scsi_qla_host *vha, \ | |
2672 | fc_port_t *fcport, uint16_t *data) \ | |
2673 | { \ | |
2674 | struct qla_work_evt *e; \ | |
2675 | \ | |
2676 | e = qla2x00_alloc_work(vha, type); \ | |
2677 | if (!e) \ | |
2678 | return QLA_FUNCTION_FAILED; \ | |
2679 | \ | |
2680 | e->u.logio.fcport = fcport; \ | |
2681 | if (data) { \ | |
2682 | e->u.logio.data[0] = data[0]; \ | |
2683 | e->u.logio.data[1] = data[1]; \ | |
2684 | } \ | |
2685 | return qla2x00_post_work(vha, e); \ | |
2686 | } | |
2687 | ||
2688 | qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN); | |
2689 | qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE); | |
2690 | qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT); | |
2691 | qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE); | |
2692 | ||
3420d36c AV |
2693 | int |
2694 | qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code) | |
2695 | { | |
2696 | struct qla_work_evt *e; | |
2697 | ||
2698 | e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT); | |
2699 | if (!e) | |
2700 | return QLA_FUNCTION_FAILED; | |
2701 | ||
2702 | e->u.uevent.code = code; | |
2703 | return qla2x00_post_work(vha, e); | |
2704 | } | |
2705 | ||
2706 | static void | |
2707 | qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code) | |
2708 | { | |
2709 | char event_string[40]; | |
2710 | char *envp[] = { event_string, NULL }; | |
2711 | ||
2712 | switch (code) { | |
2713 | case QLA_UEVENT_CODE_FW_DUMP: | |
2714 | snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld", | |
2715 | vha->host_no); | |
2716 | break; | |
2717 | default: | |
2718 | /* do nothing */ | |
2719 | break; | |
2720 | } | |
2721 | kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp); | |
2722 | } | |
2723 | ||
ac280b67 | 2724 | void |
e315cd28 | 2725 | qla2x00_do_work(struct scsi_qla_host *vha) |
0971de7f | 2726 | { |
f999f4c1 AV |
2727 | struct qla_work_evt *e, *tmp; |
2728 | unsigned long flags; | |
2729 | LIST_HEAD(work); | |
0971de7f | 2730 | |
f999f4c1 AV |
2731 | spin_lock_irqsave(&vha->work_lock, flags); |
2732 | list_splice_init(&vha->work_list, &work); | |
2733 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
2734 | ||
2735 | list_for_each_entry_safe(e, tmp, &work, list) { | |
0971de7f | 2736 | list_del_init(&e->list); |
0971de7f AV |
2737 | |
2738 | switch (e->type) { | |
2739 | case QLA_EVT_AEN: | |
e315cd28 | 2740 | fc_host_post_event(vha->host, fc_get_event_number(), |
0971de7f AV |
2741 | e->u.aen.code, e->u.aen.data); |
2742 | break; | |
8a659571 AV |
2743 | case QLA_EVT_IDC_ACK: |
2744 | qla81xx_idc_ack(vha, e->u.idc_ack.mb); | |
2745 | break; | |
ac280b67 AV |
2746 | case QLA_EVT_ASYNC_LOGIN: |
2747 | qla2x00_async_login(vha, e->u.logio.fcport, | |
2748 | e->u.logio.data); | |
2749 | break; | |
2750 | case QLA_EVT_ASYNC_LOGIN_DONE: | |
2751 | qla2x00_async_login_done(vha, e->u.logio.fcport, | |
2752 | e->u.logio.data); | |
2753 | break; | |
2754 | case QLA_EVT_ASYNC_LOGOUT: | |
2755 | qla2x00_async_logout(vha, e->u.logio.fcport); | |
2756 | break; | |
2757 | case QLA_EVT_ASYNC_LOGOUT_DONE: | |
2758 | qla2x00_async_logout_done(vha, e->u.logio.fcport, | |
2759 | e->u.logio.data); | |
2760 | break; | |
3420d36c AV |
2761 | case QLA_EVT_UEVENT: |
2762 | qla2x00_uevent_emit(vha, e->u.uevent.code); | |
2763 | break; | |
0971de7f AV |
2764 | } |
2765 | if (e->flags & QLA_EVT_FLAG_FREE) | |
2766 | kfree(e); | |
e315cd28 | 2767 | } |
e315cd28 | 2768 | } |
f999f4c1 | 2769 | |
e315cd28 AC |
2770 | /* Relogins all the fcports of a vport |
2771 | * Context: dpc thread | |
2772 | */ | |
2773 | void qla2x00_relogin(struct scsi_qla_host *vha) | |
2774 | { | |
2775 | fc_port_t *fcport; | |
c6b2fca8 | 2776 | int status; |
e315cd28 AC |
2777 | uint16_t next_loopid = 0; |
2778 | struct qla_hw_data *ha = vha->hw; | |
ac280b67 | 2779 | uint16_t data[2]; |
e315cd28 AC |
2780 | |
2781 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
2782 | /* | |
2783 | * If the port is not ONLINE then try to login | |
2784 | * to it if we haven't run out of retries. | |
2785 | */ | |
2786 | if (atomic_read(&fcport->state) != | |
2787 | FCS_ONLINE && fcport->login_retry) { | |
2788 | ||
ac280b67 | 2789 | fcport->login_retry--; |
e315cd28 | 2790 | if (fcport->flags & FCF_FABRIC_DEVICE) { |
f08b7251 | 2791 | if (fcport->flags & FCF_FCP2_DEVICE) |
e315cd28 AC |
2792 | ha->isp_ops->fabric_logout(vha, |
2793 | fcport->loop_id, | |
2794 | fcport->d_id.b.domain, | |
2795 | fcport->d_id.b.area, | |
2796 | fcport->d_id.b.al_pa); | |
2797 | ||
ac280b67 AV |
2798 | if (IS_ALOGIO_CAPABLE(ha)) { |
2799 | data[0] = 0; | |
2800 | data[1] = QLA_LOGIO_LOGIN_RETRIED; | |
2801 | status = qla2x00_post_async_login_work( | |
2802 | vha, fcport, data); | |
2803 | if (status == QLA_SUCCESS) | |
2804 | continue; | |
2805 | /* Attempt a retry. */ | |
2806 | status = 1; | |
2807 | } else | |
2808 | status = qla2x00_fabric_login(vha, | |
2809 | fcport, &next_loopid); | |
e315cd28 AC |
2810 | } else |
2811 | status = qla2x00_local_device_login(vha, | |
2812 | fcport); | |
2813 | ||
e315cd28 AC |
2814 | if (status == QLA_SUCCESS) { |
2815 | fcport->old_loop_id = fcport->loop_id; | |
2816 | ||
2817 | DEBUG(printk("scsi(%ld): port login OK: logged " | |
2818 | "in ID 0x%x\n", vha->host_no, fcport->loop_id)); | |
2819 | ||
2820 | qla2x00_update_fcport(vha, fcport); | |
2821 | ||
2822 | } else if (status == 1) { | |
2823 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
2824 | /* retry the login again */ | |
2825 | DEBUG(printk("scsi(%ld): Retrying" | |
2826 | " %d login again loop_id 0x%x\n", | |
2827 | vha->host_no, fcport->login_retry, | |
2828 | fcport->loop_id)); | |
2829 | } else { | |
2830 | fcport->login_retry = 0; | |
2831 | } | |
2832 | ||
2833 | if (fcport->login_retry == 0 && status != QLA_SUCCESS) | |
2834 | fcport->loop_id = FC_NO_LOOP_ID; | |
2835 | } | |
2836 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | |
2837 | break; | |
0971de7f | 2838 | } |
0971de7f AV |
2839 | } |
2840 | ||
1da177e4 LT |
2841 | /************************************************************************** |
2842 | * qla2x00_do_dpc | |
2843 | * This kernel thread is a task that is schedule by the interrupt handler | |
2844 | * to perform the background processing for interrupts. | |
2845 | * | |
2846 | * Notes: | |
2847 | * This task always run in the context of a kernel thread. It | |
2848 | * is kick-off by the driver's detect code and starts up | |
2849 | * up one per adapter. It immediately goes to sleep and waits for | |
2850 | * some fibre event. When either the interrupt handler or | |
2851 | * the timer routine detects a event it will one of the task | |
2852 | * bits then wake us up. | |
2853 | **************************************************************************/ | |
2854 | static int | |
2855 | qla2x00_do_dpc(void *data) | |
2856 | { | |
2c3dfe3f | 2857 | int rval; |
e315cd28 AC |
2858 | scsi_qla_host_t *base_vha; |
2859 | struct qla_hw_data *ha; | |
1da177e4 | 2860 | |
e315cd28 AC |
2861 | ha = (struct qla_hw_data *)data; |
2862 | base_vha = pci_get_drvdata(ha->pdev); | |
1da177e4 | 2863 | |
1da177e4 LT |
2864 | set_user_nice(current, -20); |
2865 | ||
39a11240 | 2866 | while (!kthread_should_stop()) { |
1da177e4 LT |
2867 | DEBUG3(printk("qla2x00: DPC handler sleeping\n")); |
2868 | ||
39a11240 CH |
2869 | set_current_state(TASK_INTERRUPTIBLE); |
2870 | schedule(); | |
2871 | __set_current_state(TASK_RUNNING); | |
1da177e4 LT |
2872 | |
2873 | DEBUG3(printk("qla2x00: DPC handler waking up\n")); | |
2874 | ||
2875 | /* Initialization not yet finished. Don't do anything yet. */ | |
e315cd28 | 2876 | if (!base_vha->flags.init_done) |
1da177e4 LT |
2877 | continue; |
2878 | ||
85880801 AV |
2879 | if (ha->flags.eeh_busy) { |
2880 | DEBUG17(qla_printk(KERN_WARNING, ha, | |
2881 | "qla2x00_do_dpc: dpc_flags: %lx\n", | |
2882 | base_vha->dpc_flags)); | |
2883 | continue; | |
2884 | } | |
2885 | ||
e315cd28 | 2886 | DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no)); |
1da177e4 LT |
2887 | |
2888 | ha->dpc_active = 1; | |
2889 | ||
1da177e4 | 2890 | if (ha->flags.mbox_busy) { |
1da177e4 LT |
2891 | ha->dpc_active = 0; |
2892 | continue; | |
2893 | } | |
2894 | ||
e315cd28 | 2895 | qla2x00_do_work(base_vha); |
0971de7f | 2896 | |
e315cd28 AC |
2897 | if (test_and_clear_bit(ISP_ABORT_NEEDED, |
2898 | &base_vha->dpc_flags)) { | |
1da177e4 LT |
2899 | |
2900 | DEBUG(printk("scsi(%ld): dpc: sched " | |
2901 | "qla2x00_abort_isp ha = %p\n", | |
e315cd28 | 2902 | base_vha->host_no, ha)); |
1da177e4 | 2903 | if (!(test_and_set_bit(ABORT_ISP_ACTIVE, |
e315cd28 | 2904 | &base_vha->dpc_flags))) { |
1da177e4 | 2905 | |
e315cd28 | 2906 | if (qla2x00_abort_isp(base_vha)) { |
1da177e4 LT |
2907 | /* failed. retry later */ |
2908 | set_bit(ISP_ABORT_NEEDED, | |
e315cd28 | 2909 | &base_vha->dpc_flags); |
99363ef8 | 2910 | } |
e315cd28 AC |
2911 | clear_bit(ABORT_ISP_ACTIVE, |
2912 | &base_vha->dpc_flags); | |
99363ef8 SJ |
2913 | } |
2914 | ||
1da177e4 | 2915 | DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", |
e315cd28 | 2916 | base_vha->host_no)); |
1da177e4 LT |
2917 | } |
2918 | ||
e315cd28 AC |
2919 | if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) { |
2920 | qla2x00_update_fcports(base_vha); | |
2921 | clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); | |
c9c5ced9 | 2922 | } |
d97994dc | 2923 | |
e315cd28 AC |
2924 | if (test_and_clear_bit(RESET_MARKER_NEEDED, |
2925 | &base_vha->dpc_flags) && | |
2926 | (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) { | |
1da177e4 LT |
2927 | |
2928 | DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n", | |
e315cd28 | 2929 | base_vha->host_no)); |
1da177e4 | 2930 | |
e315cd28 AC |
2931 | qla2x00_rst_aen(base_vha); |
2932 | clear_bit(RESET_ACTIVE, &base_vha->dpc_flags); | |
1da177e4 LT |
2933 | } |
2934 | ||
2935 | /* Retry each device up to login retry count */ | |
e315cd28 AC |
2936 | if ((test_and_clear_bit(RELOGIN_NEEDED, |
2937 | &base_vha->dpc_flags)) && | |
2938 | !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) && | |
2939 | atomic_read(&base_vha->loop_state) != LOOP_DOWN) { | |
1da177e4 LT |
2940 | |
2941 | DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", | |
e315cd28 AC |
2942 | base_vha->host_no)); |
2943 | qla2x00_relogin(base_vha); | |
2944 | ||
1da177e4 | 2945 | DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", |
e315cd28 | 2946 | base_vha->host_no)); |
1da177e4 LT |
2947 | } |
2948 | ||
e315cd28 AC |
2949 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, |
2950 | &base_vha->dpc_flags)) { | |
1da177e4 LT |
2951 | |
2952 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n", | |
e315cd28 | 2953 | base_vha->host_no)); |
1da177e4 LT |
2954 | |
2955 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, | |
e315cd28 | 2956 | &base_vha->dpc_flags))) { |
1da177e4 | 2957 | |
e315cd28 | 2958 | rval = qla2x00_loop_resync(base_vha); |
1da177e4 | 2959 | |
e315cd28 AC |
2960 | clear_bit(LOOP_RESYNC_ACTIVE, |
2961 | &base_vha->dpc_flags); | |
1da177e4 LT |
2962 | } |
2963 | ||
2964 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n", | |
e315cd28 | 2965 | base_vha->host_no)); |
1da177e4 LT |
2966 | } |
2967 | ||
e315cd28 AC |
2968 | if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) && |
2969 | atomic_read(&base_vha->loop_state) == LOOP_READY) { | |
2970 | clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags); | |
2971 | qla2xxx_flash_npiv_conf(base_vha); | |
272976ca AV |
2972 | } |
2973 | ||
1da177e4 | 2974 | if (!ha->interrupts_on) |
fd34f556 | 2975 | ha->isp_ops->enable_intrs(ha); |
1da177e4 | 2976 | |
e315cd28 AC |
2977 | if (test_and_clear_bit(BEACON_BLINK_NEEDED, |
2978 | &base_vha->dpc_flags)) | |
2979 | ha->isp_ops->beacon_blink(base_vha); | |
f6df144c | 2980 | |
e315cd28 | 2981 | qla2x00_do_dpc_all_vps(base_vha); |
2c3dfe3f | 2982 | |
1da177e4 LT |
2983 | ha->dpc_active = 0; |
2984 | } /* End of while(1) */ | |
2985 | ||
e315cd28 | 2986 | DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no)); |
1da177e4 LT |
2987 | |
2988 | /* | |
2989 | * Make sure that nobody tries to wake us up again. | |
2990 | */ | |
1da177e4 LT |
2991 | ha->dpc_active = 0; |
2992 | ||
ac280b67 AV |
2993 | /* Cleanup any residual CTX SRBs. */ |
2994 | qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); | |
2995 | ||
39a11240 CH |
2996 | return 0; |
2997 | } | |
2998 | ||
2999 | void | |
e315cd28 | 3000 | qla2xxx_wake_dpc(struct scsi_qla_host *vha) |
39a11240 | 3001 | { |
e315cd28 | 3002 | struct qla_hw_data *ha = vha->hw; |
c795c1e4 AV |
3003 | struct task_struct *t = ha->dpc_thread; |
3004 | ||
e315cd28 | 3005 | if (!test_bit(UNLOADING, &vha->dpc_flags) && t) |
c795c1e4 | 3006 | wake_up_process(t); |
1da177e4 LT |
3007 | } |
3008 | ||
1da177e4 LT |
3009 | /* |
3010 | * qla2x00_rst_aen | |
3011 | * Processes asynchronous reset. | |
3012 | * | |
3013 | * Input: | |
3014 | * ha = adapter block pointer. | |
3015 | */ | |
3016 | static void | |
e315cd28 | 3017 | qla2x00_rst_aen(scsi_qla_host_t *vha) |
1da177e4 | 3018 | { |
e315cd28 AC |
3019 | if (vha->flags.online && !vha->flags.reset_active && |
3020 | !atomic_read(&vha->loop_down_timer) && | |
3021 | !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) { | |
1da177e4 | 3022 | do { |
e315cd28 | 3023 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
3024 | |
3025 | /* | |
3026 | * Issue marker command only when we are going to start | |
3027 | * the I/O. | |
3028 | */ | |
e315cd28 AC |
3029 | vha->marker_needed = 1; |
3030 | } while (!atomic_read(&vha->loop_down_timer) && | |
3031 | (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags))); | |
1da177e4 LT |
3032 | } |
3033 | } | |
3034 | ||
f4f051eb | 3035 | static void |
e315cd28 | 3036 | qla2x00_sp_free_dma(srb_t *sp) |
f4f051eb AV |
3037 | { |
3038 | struct scsi_cmnd *cmd = sp->cmd; | |
3039 | ||
3040 | if (sp->flags & SRB_DMA_VALID) { | |
385d70b4 | 3041 | scsi_dma_unmap(cmd); |
f4f051eb AV |
3042 | sp->flags &= ~SRB_DMA_VALID; |
3043 | } | |
fca29703 | 3044 | CMD_SP(cmd) = NULL; |
f4f051eb AV |
3045 | } |
3046 | ||
3047 | void | |
73208dfd | 3048 | qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp) |
f4f051eb AV |
3049 | { |
3050 | struct scsi_cmnd *cmd = sp->cmd; | |
3051 | ||
e315cd28 | 3052 | qla2x00_sp_free_dma(sp); |
f4f051eb | 3053 | |
f4f051eb AV |
3054 | mempool_free(sp, ha->srb_mempool); |
3055 | ||
3056 | cmd->scsi_done(cmd); | |
3057 | } | |
bdf79621 | 3058 | |
1da177e4 LT |
3059 | /************************************************************************** |
3060 | * qla2x00_timer | |
3061 | * | |
3062 | * Description: | |
3063 | * One second timer | |
3064 | * | |
3065 | * Context: Interrupt | |
3066 | ***************************************************************************/ | |
2c3dfe3f | 3067 | void |
e315cd28 | 3068 | qla2x00_timer(scsi_qla_host_t *vha) |
1da177e4 | 3069 | { |
1da177e4 LT |
3070 | unsigned long cpu_flags = 0; |
3071 | fc_port_t *fcport; | |
1da177e4 LT |
3072 | int start_dpc = 0; |
3073 | int index; | |
3074 | srb_t *sp; | |
f4f051eb | 3075 | int t; |
85880801 | 3076 | uint16_t w; |
e315cd28 | 3077 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 3078 | struct req_que *req; |
85880801 AV |
3079 | |
3080 | /* Hardware read to raise pending EEH errors during mailbox waits. */ | |
3081 | if (!pci_channel_offline(ha->pdev)) | |
3082 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); | |
1da177e4 LT |
3083 | /* |
3084 | * Ports - Port down timer. | |
3085 | * | |
3086 | * Whenever, a port is in the LOST state we start decrementing its port | |
3087 | * down timer every second until it reaches zero. Once it reaches zero | |
fa2a1ce5 | 3088 | * the port it marked DEAD. |
1da177e4 LT |
3089 | */ |
3090 | t = 0; | |
e315cd28 | 3091 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
1da177e4 LT |
3092 | if (fcport->port_type != FCT_TARGET) |
3093 | continue; | |
3094 | ||
3095 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { | |
3096 | ||
3097 | if (atomic_read(&fcport->port_down_timer) == 0) | |
3098 | continue; | |
3099 | ||
fa2a1ce5 | 3100 | if (atomic_dec_and_test(&fcport->port_down_timer) != 0) |
1da177e4 | 3101 | atomic_set(&fcport->state, FCS_DEVICE_DEAD); |
fa2a1ce5 | 3102 | |
1da177e4 | 3103 | DEBUG(printk("scsi(%ld): fcport-%d - port retry count: " |
fca29703 | 3104 | "%d remaining\n", |
e315cd28 | 3105 | vha->host_no, |
1da177e4 LT |
3106 | t, atomic_read(&fcport->port_down_timer))); |
3107 | } | |
3108 | t++; | |
3109 | } /* End of for fcport */ | |
3110 | ||
1da177e4 LT |
3111 | |
3112 | /* Loop down handler. */ | |
e315cd28 AC |
3113 | if (atomic_read(&vha->loop_down_timer) > 0 && |
3114 | !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) | |
3115 | && vha->flags.online) { | |
1da177e4 | 3116 | |
e315cd28 AC |
3117 | if (atomic_read(&vha->loop_down_timer) == |
3118 | vha->loop_down_abort_time) { | |
1da177e4 LT |
3119 | |
3120 | DEBUG(printk("scsi(%ld): Loop Down - aborting the " | |
3121 | "queues before time expire\n", | |
e315cd28 | 3122 | vha->host_no)); |
1da177e4 | 3123 | |
e315cd28 AC |
3124 | if (!IS_QLA2100(ha) && vha->link_down_timeout) |
3125 | atomic_set(&vha->loop_state, LOOP_DEAD); | |
1da177e4 | 3126 | |
f08b7251 AV |
3127 | /* |
3128 | * Schedule an ISP abort to return any FCP2-device | |
3129 | * commands. | |
3130 | */ | |
2c3dfe3f | 3131 | /* NPIV - scan physical port only */ |
e315cd28 | 3132 | if (!vha->vp_idx) { |
2c3dfe3f SJ |
3133 | spin_lock_irqsave(&ha->hardware_lock, |
3134 | cpu_flags); | |
73208dfd | 3135 | req = ha->req_q_map[0]; |
2c3dfe3f SJ |
3136 | for (index = 1; |
3137 | index < MAX_OUTSTANDING_COMMANDS; | |
3138 | index++) { | |
3139 | fc_port_t *sfcp; | |
3140 | ||
e315cd28 | 3141 | sp = req->outstanding_cmds[index]; |
2c3dfe3f SJ |
3142 | if (!sp) |
3143 | continue; | |
cf53b069 AV |
3144 | if (sp->ctx) |
3145 | continue; | |
2c3dfe3f | 3146 | sfcp = sp->fcport; |
f08b7251 | 3147 | if (!(sfcp->flags & FCF_FCP2_DEVICE)) |
2c3dfe3f | 3148 | continue; |
bdf79621 | 3149 | |
2c3dfe3f | 3150 | set_bit(ISP_ABORT_NEEDED, |
e315cd28 | 3151 | &vha->dpc_flags); |
2c3dfe3f SJ |
3152 | break; |
3153 | } | |
3154 | spin_unlock_irqrestore(&ha->hardware_lock, | |
e315cd28 | 3155 | cpu_flags); |
1da177e4 | 3156 | } |
1da177e4 LT |
3157 | start_dpc++; |
3158 | } | |
3159 | ||
3160 | /* if the loop has been down for 4 minutes, reinit adapter */ | |
e315cd28 | 3161 | if (atomic_dec_and_test(&vha->loop_down_timer) != 0) { |
0d6e61bc | 3162 | if (!(vha->device_flags & DFLG_NO_CABLE)) { |
1da177e4 LT |
3163 | DEBUG(printk("scsi(%ld): Loop down - " |
3164 | "aborting ISP.\n", | |
e315cd28 | 3165 | vha->host_no)); |
1da177e4 LT |
3166 | qla_printk(KERN_WARNING, ha, |
3167 | "Loop down - aborting ISP.\n"); | |
3168 | ||
e315cd28 | 3169 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
3170 | } |
3171 | } | |
fca29703 | 3172 | DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n", |
e315cd28 AC |
3173 | vha->host_no, |
3174 | atomic_read(&vha->loop_down_timer))); | |
1da177e4 LT |
3175 | } |
3176 | ||
f6df144c AV |
3177 | /* Check if beacon LED needs to be blinked */ |
3178 | if (ha->beacon_blink_led == 1) { | |
e315cd28 | 3179 | set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags); |
f6df144c AV |
3180 | start_dpc++; |
3181 | } | |
3182 | ||
550bf57d | 3183 | /* Process any deferred work. */ |
e315cd28 | 3184 | if (!list_empty(&vha->work_list)) |
550bf57d AV |
3185 | start_dpc++; |
3186 | ||
1da177e4 | 3187 | /* Schedule the DPC routine if needed */ |
e315cd28 AC |
3188 | if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || |
3189 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || | |
3190 | test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) || | |
1da177e4 | 3191 | start_dpc || |
e315cd28 AC |
3192 | test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) || |
3193 | test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) || | |
3194 | test_bit(VP_DPC_NEEDED, &vha->dpc_flags) || | |
3195 | test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) | |
3196 | qla2xxx_wake_dpc(vha); | |
1da177e4 | 3197 | |
e315cd28 | 3198 | qla2x00_restart_timer(vha, WATCH_INTERVAL); |
1da177e4 LT |
3199 | } |
3200 | ||
5433383e AV |
3201 | /* Firmware interface routines. */ |
3202 | ||
3a03eb79 | 3203 | #define FW_BLOBS 7 |
5433383e AV |
3204 | #define FW_ISP21XX 0 |
3205 | #define FW_ISP22XX 1 | |
3206 | #define FW_ISP2300 2 | |
3207 | #define FW_ISP2322 3 | |
48c02fde | 3208 | #define FW_ISP24XX 4 |
c3a2f0df | 3209 | #define FW_ISP25XX 5 |
3a03eb79 | 3210 | #define FW_ISP81XX 6 |
5433383e | 3211 | |
bb8ee499 AV |
3212 | #define FW_FILE_ISP21XX "ql2100_fw.bin" |
3213 | #define FW_FILE_ISP22XX "ql2200_fw.bin" | |
3214 | #define FW_FILE_ISP2300 "ql2300_fw.bin" | |
3215 | #define FW_FILE_ISP2322 "ql2322_fw.bin" | |
3216 | #define FW_FILE_ISP24XX "ql2400_fw.bin" | |
c3a2f0df | 3217 | #define FW_FILE_ISP25XX "ql2500_fw.bin" |
3a03eb79 | 3218 | #define FW_FILE_ISP81XX "ql8100_fw.bin" |
bb8ee499 | 3219 | |
e1e82b6f | 3220 | static DEFINE_MUTEX(qla_fw_lock); |
5433383e AV |
3221 | |
3222 | static struct fw_blob qla_fw_blobs[FW_BLOBS] = { | |
bb8ee499 AV |
3223 | { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, }, |
3224 | { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, }, | |
3225 | { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, }, | |
3226 | { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, }, | |
3227 | { .name = FW_FILE_ISP24XX, }, | |
c3a2f0df | 3228 | { .name = FW_FILE_ISP25XX, }, |
3a03eb79 | 3229 | { .name = FW_FILE_ISP81XX, }, |
5433383e AV |
3230 | }; |
3231 | ||
3232 | struct fw_blob * | |
e315cd28 | 3233 | qla2x00_request_firmware(scsi_qla_host_t *vha) |
5433383e | 3234 | { |
e315cd28 | 3235 | struct qla_hw_data *ha = vha->hw; |
5433383e AV |
3236 | struct fw_blob *blob; |
3237 | ||
3238 | blob = NULL; | |
3239 | if (IS_QLA2100(ha)) { | |
3240 | blob = &qla_fw_blobs[FW_ISP21XX]; | |
3241 | } else if (IS_QLA2200(ha)) { | |
3242 | blob = &qla_fw_blobs[FW_ISP22XX]; | |
48c02fde | 3243 | } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
5433383e | 3244 | blob = &qla_fw_blobs[FW_ISP2300]; |
48c02fde | 3245 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
5433383e | 3246 | blob = &qla_fw_blobs[FW_ISP2322]; |
4d4df193 | 3247 | } else if (IS_QLA24XX_TYPE(ha)) { |
5433383e | 3248 | blob = &qla_fw_blobs[FW_ISP24XX]; |
c3a2f0df AV |
3249 | } else if (IS_QLA25XX(ha)) { |
3250 | blob = &qla_fw_blobs[FW_ISP25XX]; | |
3a03eb79 AV |
3251 | } else if (IS_QLA81XX(ha)) { |
3252 | blob = &qla_fw_blobs[FW_ISP81XX]; | |
5433383e AV |
3253 | } |
3254 | ||
e1e82b6f | 3255 | mutex_lock(&qla_fw_lock); |
5433383e AV |
3256 | if (blob->fw) |
3257 | goto out; | |
3258 | ||
3259 | if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) { | |
3260 | DEBUG2(printk("scsi(%ld): Failed to load firmware image " | |
e315cd28 | 3261 | "(%s).\n", vha->host_no, blob->name)); |
5433383e AV |
3262 | blob->fw = NULL; |
3263 | blob = NULL; | |
3264 | goto out; | |
3265 | } | |
3266 | ||
3267 | out: | |
e1e82b6f | 3268 | mutex_unlock(&qla_fw_lock); |
5433383e AV |
3269 | return blob; |
3270 | } | |
3271 | ||
3272 | static void | |
3273 | qla2x00_release_firmware(void) | |
3274 | { | |
3275 | int idx; | |
3276 | ||
e1e82b6f | 3277 | mutex_lock(&qla_fw_lock); |
5433383e AV |
3278 | for (idx = 0; idx < FW_BLOBS; idx++) |
3279 | if (qla_fw_blobs[idx].fw) | |
3280 | release_firmware(qla_fw_blobs[idx].fw); | |
e1e82b6f | 3281 | mutex_unlock(&qla_fw_lock); |
5433383e AV |
3282 | } |
3283 | ||
14e660e6 SJ |
3284 | static pci_ers_result_t |
3285 | qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
3286 | { | |
85880801 AV |
3287 | scsi_qla_host_t *vha = pci_get_drvdata(pdev); |
3288 | struct qla_hw_data *ha = vha->hw; | |
3289 | ||
3290 | DEBUG2(qla_printk(KERN_WARNING, ha, "error_detected:state %x\n", | |
3291 | state)); | |
b9b12f73 | 3292 | |
14e660e6 SJ |
3293 | switch (state) { |
3294 | case pci_channel_io_normal: | |
85880801 | 3295 | ha->flags.eeh_busy = 0; |
14e660e6 SJ |
3296 | return PCI_ERS_RESULT_CAN_RECOVER; |
3297 | case pci_channel_io_frozen: | |
85880801 | 3298 | ha->flags.eeh_busy = 1; |
90a86fc0 | 3299 | qla2x00_free_irqs(vha); |
14e660e6 SJ |
3300 | pci_disable_device(pdev); |
3301 | return PCI_ERS_RESULT_NEED_RESET; | |
3302 | case pci_channel_io_perm_failure: | |
85880801 AV |
3303 | ha->flags.pci_channel_io_perm_failure = 1; |
3304 | qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16); | |
14e660e6 SJ |
3305 | return PCI_ERS_RESULT_DISCONNECT; |
3306 | } | |
3307 | return PCI_ERS_RESULT_NEED_RESET; | |
3308 | } | |
3309 | ||
3310 | static pci_ers_result_t | |
3311 | qla2xxx_pci_mmio_enabled(struct pci_dev *pdev) | |
3312 | { | |
3313 | int risc_paused = 0; | |
3314 | uint32_t stat; | |
3315 | unsigned long flags; | |
e315cd28 AC |
3316 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
3317 | struct qla_hw_data *ha = base_vha->hw; | |
14e660e6 SJ |
3318 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
3319 | struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; | |
3320 | ||
3321 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
3322 | if (IS_QLA2100(ha) || IS_QLA2200(ha)){ | |
3323 | stat = RD_REG_DWORD(®->hccr); | |
3324 | if (stat & HCCR_RISC_PAUSE) | |
3325 | risc_paused = 1; | |
3326 | } else if (IS_QLA23XX(ha)) { | |
3327 | stat = RD_REG_DWORD(®->u.isp2300.host_status); | |
3328 | if (stat & HSR_RISC_PAUSED) | |
3329 | risc_paused = 1; | |
3330 | } else if (IS_FWI2_CAPABLE(ha)) { | |
3331 | stat = RD_REG_DWORD(®24->host_status); | |
3332 | if (stat & HSRX_RISC_PAUSED) | |
3333 | risc_paused = 1; | |
3334 | } | |
3335 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3336 | ||
3337 | if (risc_paused) { | |
3338 | qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, " | |
3339 | "Dumping firmware!\n"); | |
e315cd28 | 3340 | ha->isp_ops->fw_dump(base_vha, 0); |
14e660e6 SJ |
3341 | |
3342 | return PCI_ERS_RESULT_NEED_RESET; | |
3343 | } else | |
3344 | return PCI_ERS_RESULT_RECOVERED; | |
3345 | } | |
3346 | ||
3347 | static pci_ers_result_t | |
3348 | qla2xxx_pci_slot_reset(struct pci_dev *pdev) | |
3349 | { | |
3350 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; | |
e315cd28 AC |
3351 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
3352 | struct qla_hw_data *ha = base_vha->hw; | |
90a86fc0 JC |
3353 | struct rsp_que *rsp; |
3354 | int rc, retries = 10; | |
09483916 | 3355 | |
85880801 AV |
3356 | DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n")); |
3357 | ||
90a86fc0 JC |
3358 | /* Workaround: qla2xxx driver which access hardware earlier |
3359 | * needs error state to be pci_channel_io_online. | |
3360 | * Otherwise mailbox command timesout. | |
3361 | */ | |
3362 | pdev->error_state = pci_channel_io_normal; | |
3363 | ||
3364 | pci_restore_state(pdev); | |
3365 | ||
8c1496bd RL |
3366 | /* pci_restore_state() clears the saved_state flag of the device |
3367 | * save restored state which resets saved_state flag | |
3368 | */ | |
3369 | pci_save_state(pdev); | |
3370 | ||
09483916 BH |
3371 | if (ha->mem_only) |
3372 | rc = pci_enable_device_mem(pdev); | |
3373 | else | |
3374 | rc = pci_enable_device(pdev); | |
14e660e6 | 3375 | |
09483916 | 3376 | if (rc) { |
14e660e6 SJ |
3377 | qla_printk(KERN_WARNING, ha, |
3378 | "Can't re-enable PCI device after reset.\n"); | |
14e660e6 SJ |
3379 | return ret; |
3380 | } | |
14e660e6 | 3381 | |
90a86fc0 JC |
3382 | rsp = ha->rsp_q_map[0]; |
3383 | if (qla2x00_request_irqs(ha, rsp)) | |
3384 | return ret; | |
3385 | ||
e315cd28 | 3386 | if (ha->isp_ops->pci_config(base_vha)) |
14e660e6 SJ |
3387 | return ret; |
3388 | ||
90a86fc0 JC |
3389 | while (ha->flags.mbox_busy && retries--) |
3390 | msleep(1000); | |
85880801 | 3391 | |
e315cd28 AC |
3392 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
3393 | if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS) | |
14e660e6 | 3394 | ret = PCI_ERS_RESULT_RECOVERED; |
e315cd28 | 3395 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
14e660e6 | 3396 | |
90a86fc0 JC |
3397 | pci_cleanup_aer_uncorrect_error_status(pdev); |
3398 | ||
85880801 AV |
3399 | DEBUG17(qla_printk(KERN_WARNING, ha, |
3400 | "slot_reset-return:ret=%x\n", ret)); | |
3401 | ||
14e660e6 SJ |
3402 | return ret; |
3403 | } | |
3404 | ||
3405 | static void | |
3406 | qla2xxx_pci_resume(struct pci_dev *pdev) | |
3407 | { | |
e315cd28 AC |
3408 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
3409 | struct qla_hw_data *ha = base_vha->hw; | |
14e660e6 SJ |
3410 | int ret; |
3411 | ||
85880801 AV |
3412 | DEBUG17(qla_printk(KERN_WARNING, ha, "pci_resume\n")); |
3413 | ||
e315cd28 | 3414 | ret = qla2x00_wait_for_hba_online(base_vha); |
14e660e6 SJ |
3415 | if (ret != QLA_SUCCESS) { |
3416 | qla_printk(KERN_ERR, ha, | |
3417 | "the device failed to resume I/O " | |
3418 | "from slot/link_reset"); | |
3419 | } | |
85880801 AV |
3420 | |
3421 | ha->flags.eeh_busy = 0; | |
14e660e6 SJ |
3422 | } |
3423 | ||
3424 | static struct pci_error_handlers qla2xxx_err_handler = { | |
3425 | .error_detected = qla2xxx_pci_error_detected, | |
3426 | .mmio_enabled = qla2xxx_pci_mmio_enabled, | |
3427 | .slot_reset = qla2xxx_pci_slot_reset, | |
3428 | .resume = qla2xxx_pci_resume, | |
3429 | }; | |
3430 | ||
5433383e | 3431 | static struct pci_device_id qla2xxx_pci_tbl[] = { |
47f5e069 AV |
3432 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) }, |
3433 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) }, | |
3434 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) }, | |
3435 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) }, | |
3436 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) }, | |
3437 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) }, | |
3438 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) }, | |
3439 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) }, | |
3440 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) }, | |
4d4df193 | 3441 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) }, |
47f5e069 AV |
3442 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) }, |
3443 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) }, | |
c3a2f0df | 3444 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) }, |
3a03eb79 | 3445 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) }, |
5433383e AV |
3446 | { 0 }, |
3447 | }; | |
3448 | MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl); | |
3449 | ||
fca29703 | 3450 | static struct pci_driver qla2xxx_pci_driver = { |
cb63067a | 3451 | .name = QLA2XXX_DRIVER_NAME, |
0a21ef1e JB |
3452 | .driver = { |
3453 | .owner = THIS_MODULE, | |
3454 | }, | |
fca29703 | 3455 | .id_table = qla2xxx_pci_tbl, |
7ee61397 | 3456 | .probe = qla2x00_probe_one, |
4c993f76 | 3457 | .remove = qla2x00_remove_one, |
14e660e6 | 3458 | .err_handler = &qla2xxx_err_handler, |
fca29703 AV |
3459 | }; |
3460 | ||
1da177e4 LT |
3461 | /** |
3462 | * qla2x00_module_init - Module initialization. | |
3463 | **/ | |
3464 | static int __init | |
3465 | qla2x00_module_init(void) | |
3466 | { | |
fca29703 AV |
3467 | int ret = 0; |
3468 | ||
1da177e4 | 3469 | /* Allocate cache for SRBs. */ |
354d6b21 | 3470 | srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, |
20c2df83 | 3471 | SLAB_HWCACHE_ALIGN, NULL); |
1da177e4 LT |
3472 | if (srb_cachep == NULL) { |
3473 | printk(KERN_ERR | |
3474 | "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); | |
3475 | return -ENOMEM; | |
3476 | } | |
3477 | ||
3478 | /* Derive version string. */ | |
3479 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); | |
11010fec | 3480 | if (ql2xextended_error_logging) |
0181944f AV |
3481 | strcat(qla2x00_version_str, "-debug"); |
3482 | ||
1c97a12a AV |
3483 | qla2xxx_transport_template = |
3484 | fc_attach_transport(&qla2xxx_transport_functions); | |
2c3dfe3f SJ |
3485 | if (!qla2xxx_transport_template) { |
3486 | kmem_cache_destroy(srb_cachep); | |
1da177e4 | 3487 | return -ENODEV; |
2c3dfe3f SJ |
3488 | } |
3489 | qla2xxx_transport_vport_template = | |
3490 | fc_attach_transport(&qla2xxx_transport_vport_functions); | |
3491 | if (!qla2xxx_transport_vport_template) { | |
3492 | kmem_cache_destroy(srb_cachep); | |
3493 | fc_release_transport(qla2xxx_transport_template); | |
1da177e4 | 3494 | return -ENODEV; |
2c3dfe3f | 3495 | } |
1da177e4 | 3496 | |
fd9a29f0 AV |
3497 | printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n", |
3498 | qla2x00_version_str); | |
7ee61397 | 3499 | ret = pci_register_driver(&qla2xxx_pci_driver); |
fca29703 AV |
3500 | if (ret) { |
3501 | kmem_cache_destroy(srb_cachep); | |
3502 | fc_release_transport(qla2xxx_transport_template); | |
2c3dfe3f | 3503 | fc_release_transport(qla2xxx_transport_vport_template); |
fca29703 AV |
3504 | } |
3505 | return ret; | |
1da177e4 LT |
3506 | } |
3507 | ||
3508 | /** | |
3509 | * qla2x00_module_exit - Module cleanup. | |
3510 | **/ | |
3511 | static void __exit | |
3512 | qla2x00_module_exit(void) | |
3513 | { | |
7ee61397 | 3514 | pci_unregister_driver(&qla2xxx_pci_driver); |
5433383e | 3515 | qla2x00_release_firmware(); |
354d6b21 | 3516 | kmem_cache_destroy(srb_cachep); |
1da177e4 | 3517 | fc_release_transport(qla2xxx_transport_template); |
2c3dfe3f | 3518 | fc_release_transport(qla2xxx_transport_vport_template); |
1da177e4 LT |
3519 | } |
3520 | ||
3521 | module_init(qla2x00_module_init); | |
3522 | module_exit(qla2x00_module_exit); | |
3523 | ||
3524 | MODULE_AUTHOR("QLogic Corporation"); | |
3525 | MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver"); | |
3526 | MODULE_LICENSE("GPL"); | |
3527 | MODULE_VERSION(QLA2XXX_VERSION); | |
bb8ee499 AV |
3528 | MODULE_FIRMWARE(FW_FILE_ISP21XX); |
3529 | MODULE_FIRMWARE(FW_FILE_ISP22XX); | |
3530 | MODULE_FIRMWARE(FW_FILE_ISP2300); | |
3531 | MODULE_FIRMWARE(FW_FILE_ISP2322); | |
3532 | MODULE_FIRMWARE(FW_FILE_ISP24XX); | |
61623fc3 | 3533 | MODULE_FIRMWARE(FW_FILE_ISP25XX); |