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