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