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