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