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