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