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