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