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