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