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