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