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