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