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