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