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