Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLOGIC LINUX SOFTWARE |
| 3 | * |
| 4 | * QLogic ISP2x00 device driver for Linux 2.6.x |
| 5 | * Copyright (C) 2003-2004 QLogic Corporation |
| 6 | * (www.qlogic.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2, or (at your option) any |
| 11 | * later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | */ |
| 19 | #include "qla_def.h" |
| 20 | |
| 21 | #include <linux/moduleparam.h> |
| 22 | #include <linux/vmalloc.h> |
| 23 | #include <linux/smp_lock.h> |
| 24 | #include <linux/delay.h> |
| 25 | |
| 26 | #include <scsi/scsi_tcq.h> |
| 27 | #include <scsi/scsicam.h> |
| 28 | #include <scsi/scsi_transport.h> |
| 29 | #include <scsi/scsi_transport_fc.h> |
| 30 | |
| 31 | /* |
| 32 | * Driver version |
| 33 | */ |
| 34 | char qla2x00_version_str[40]; |
| 35 | |
| 36 | /* |
| 37 | * SRB allocation cache |
| 38 | */ |
| 39 | char srb_cachep_name[16]; |
| 40 | kmem_cache_t *srb_cachep; |
| 41 | |
| 42 | /* |
| 43 | * Stats for all adpaters. |
| 44 | */ |
| 45 | struct _qla2x00stats qla2x00_stats; |
| 46 | |
| 47 | /* |
| 48 | * Ioctl related information. |
| 49 | */ |
| 50 | int num_hosts; |
| 51 | int apiHBAInstance; |
| 52 | |
| 53 | /* |
| 54 | * Module parameter information and variables |
| 55 | */ |
| 56 | int ql2xmaxqdepth; |
| 57 | module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR); |
| 58 | MODULE_PARM_DESC(ql2xmaxqdepth, |
| 59 | "Maximum queue depth to report for target devices."); |
| 60 | |
| 61 | int ql2xlogintimeout = 20; |
| 62 | module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR); |
| 63 | MODULE_PARM_DESC(ql2xlogintimeout, |
| 64 | "Login timeout value in seconds."); |
| 65 | |
| 66 | int qlport_down_retry; |
| 67 | module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); |
| 68 | MODULE_PARM_DESC(qlport_down_retry, |
| 69 | "Maximum number of command retries to a port that returns" |
| 70 | "a PORT-DOWN status."); |
| 71 | |
| 72 | int ql2xretrycount = 20; |
| 73 | module_param(ql2xretrycount, int, S_IRUGO|S_IWUSR); |
| 74 | MODULE_PARM_DESC(ql2xretrycount, |
| 75 | "Maximum number of mid-layer retries allowed for a command. " |
| 76 | "Default value is 20, "); |
| 77 | |
| 78 | int displayConfig; |
| 79 | module_param(displayConfig, int, S_IRUGO|S_IWUSR); |
| 80 | MODULE_PARM_DESC(displayConfig, |
| 81 | "If 1 then display the configuration used in /etc/modprobe.conf."); |
| 82 | |
| 83 | int ql2xplogiabsentdevice; |
| 84 | module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); |
| 85 | MODULE_PARM_DESC(ql2xplogiabsentdevice, |
| 86 | "Option to enable PLOGI to devices that are not present after " |
| 87 | "a Fabric scan. This is needed for several broken switches." |
| 88 | "Default is 0 - no PLOGI. 1 - perfom PLOGI."); |
| 89 | |
| 90 | int ql2xenablezio = 0; |
| 91 | module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR); |
| 92 | MODULE_PARM_DESC(ql2xenablezio, |
| 93 | "Option to enable ZIO:If 1 then enable it otherwise" |
| 94 | " use the default set in the NVRAM." |
| 95 | " Default is 0 : disabled"); |
| 96 | |
| 97 | int ql2xintrdelaytimer = 10; |
| 98 | module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR); |
| 99 | MODULE_PARM_DESC(ql2xintrdelaytimer, |
| 100 | "ZIO: Waiting time for Firmware before it generates an " |
| 101 | "interrupt to the host to notify completion of request."); |
| 102 | |
| 103 | int ConfigRequired; |
| 104 | module_param(ConfigRequired, int, S_IRUGO|S_IRUSR); |
| 105 | MODULE_PARM_DESC(ConfigRequired, |
| 106 | "If 1, then only configured devices passed in through the" |
| 107 | "ql2xopts parameter will be presented to the OS"); |
| 108 | |
| 109 | int Bind = BIND_BY_PORT_NAME; |
| 110 | module_param(Bind, int, S_IRUGO|S_IRUSR); |
| 111 | MODULE_PARM_DESC(Bind, |
| 112 | "Target persistent binding method: " |
| 113 | "0 by Portname (default); 1 by PortID; 2 by Nodename. "); |
| 114 | |
| 115 | int ql2xsuspendcount = SUSPEND_COUNT; |
| 116 | module_param(ql2xsuspendcount, int, S_IRUGO|S_IWUSR); |
| 117 | MODULE_PARM_DESC(ql2xsuspendcount, |
| 118 | "Number of 6-second suspend iterations to perform while a " |
| 119 | "target returns a <NOT READY> status. Default is 10 " |
| 120 | "iterations."); |
| 121 | |
| 122 | int ql2xdoinitscan = 1; |
| 123 | module_param(ql2xdoinitscan, int, S_IRUGO|S_IWUSR); |
| 124 | MODULE_PARM_DESC(ql2xdoinitscan, |
| 125 | "Signal mid-layer to perform scan after driver load: 0 -- no " |
| 126 | "signal sent to mid-layer."); |
| 127 | |
| 128 | int ql2xloginretrycount = 0; |
| 129 | module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR); |
| 130 | MODULE_PARM_DESC(ql2xloginretrycount, |
| 131 | "Specify an alternate value for the NVRAM login retry count."); |
| 132 | |
| 133 | /* |
| 134 | * Proc structures and functions |
| 135 | */ |
| 136 | struct info_str { |
| 137 | char *buffer; |
| 138 | int length; |
| 139 | off_t offset; |
| 140 | int pos; |
| 141 | }; |
| 142 | |
| 143 | static void copy_mem_info(struct info_str *, char *, int); |
| 144 | static int copy_info(struct info_str *, char *, ...); |
| 145 | |
| 146 | static void qla2x00_free_device(scsi_qla_host_t *); |
| 147 | |
| 148 | static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha); |
| 149 | |
| 150 | /* |
| 151 | * SCSI host template entry points |
| 152 | */ |
| 153 | static int qla2xxx_slave_configure(struct scsi_device * device); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 154 | static int qla2xxx_slave_alloc(struct scsi_device *); |
| 155 | static void qla2xxx_slave_destroy(struct scsi_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | static int qla2x00_queuecommand(struct scsi_cmnd *cmd, |
| 157 | void (*fn)(struct scsi_cmnd *)); |
| 158 | static int qla2xxx_eh_abort(struct scsi_cmnd *); |
| 159 | static int qla2xxx_eh_device_reset(struct scsi_cmnd *); |
| 160 | static int qla2xxx_eh_bus_reset(struct scsi_cmnd *); |
| 161 | static int qla2xxx_eh_host_reset(struct scsi_cmnd *); |
| 162 | static int qla2x00_loop_reset(scsi_qla_host_t *ha); |
| 163 | static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *); |
| 164 | |
| 165 | static int qla2x00_proc_info(struct Scsi_Host *, char *, char **, |
| 166 | off_t, int, int); |
| 167 | |
| 168 | static struct scsi_host_template qla2x00_driver_template = { |
| 169 | .module = THIS_MODULE, |
| 170 | .name = "qla2xxx", |
| 171 | .proc_name = "qla2xxx", |
| 172 | .proc_info = qla2x00_proc_info, |
| 173 | .queuecommand = qla2x00_queuecommand, |
| 174 | |
| 175 | .eh_abort_handler = qla2xxx_eh_abort, |
| 176 | .eh_device_reset_handler = qla2xxx_eh_device_reset, |
| 177 | .eh_bus_reset_handler = qla2xxx_eh_bus_reset, |
| 178 | .eh_host_reset_handler = qla2xxx_eh_host_reset, |
| 179 | |
| 180 | .slave_configure = qla2xxx_slave_configure, |
| 181 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 182 | .slave_alloc = qla2xxx_slave_alloc, |
| 183 | .slave_destroy = qla2xxx_slave_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | .this_id = -1, |
| 185 | .cmd_per_lun = 3, |
| 186 | .use_clustering = ENABLE_CLUSTERING, |
| 187 | .sg_tablesize = SG_ALL, |
| 188 | |
| 189 | /* |
| 190 | * The RISC allows for each command to transfer (2^32-1) bytes of data, |
| 191 | * which equates to 0x800000 sectors. |
| 192 | */ |
| 193 | .max_sectors = 0xFFFF, |
| 194 | }; |
| 195 | |
| 196 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; |
| 197 | |
| 198 | static void qla2x00_display_fc_names(scsi_qla_host_t *); |
| 199 | |
| 200 | /* TODO Convert to inlines |
| 201 | * |
| 202 | * Timer routines |
| 203 | */ |
| 204 | #define WATCH_INTERVAL 1 /* number of seconds */ |
| 205 | |
| 206 | static void qla2x00_timer(scsi_qla_host_t *); |
| 207 | |
| 208 | static __inline__ void qla2x00_start_timer(scsi_qla_host_t *, |
| 209 | void *, unsigned long); |
| 210 | static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long); |
| 211 | static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *); |
| 212 | |
| 213 | static inline void |
| 214 | qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval) |
| 215 | { |
| 216 | init_timer(&ha->timer); |
| 217 | ha->timer.expires = jiffies + interval * HZ; |
| 218 | ha->timer.data = (unsigned long)ha; |
| 219 | ha->timer.function = (void (*)(unsigned long))func; |
| 220 | add_timer(&ha->timer); |
| 221 | ha->timer_active = 1; |
| 222 | } |
| 223 | |
| 224 | static inline void |
| 225 | qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval) |
| 226 | { |
| 227 | mod_timer(&ha->timer, jiffies + interval * HZ); |
| 228 | } |
| 229 | |
| 230 | static __inline__ void |
| 231 | qla2x00_stop_timer(scsi_qla_host_t *ha) |
| 232 | { |
| 233 | del_timer_sync(&ha->timer); |
| 234 | ha->timer_active = 0; |
| 235 | } |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | static int qla2x00_do_dpc(void *data); |
| 238 | |
| 239 | static void qla2x00_rst_aen(scsi_qla_host_t *); |
| 240 | |
| 241 | static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *); |
| 242 | static void qla2x00_mem_free(scsi_qla_host_t *ha); |
| 243 | static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha); |
| 244 | static void qla2x00_free_sp_pool(scsi_qla_host_t *ha); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 245 | static srb_t *qla2x00_get_new_sp(scsi_qla_host_t *); |
| 246 | static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *); |
| 247 | void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t, |
| 250 | size_t); |
| 251 | static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t, |
| 252 | size_t); |
| 253 | static struct bin_attribute sysfs_fw_dump_attr = { |
| 254 | .attr = { |
| 255 | .name = "fw_dump", |
| 256 | .mode = S_IRUSR | S_IWUSR, |
| 257 | .owner = THIS_MODULE, |
| 258 | }, |
| 259 | .size = 0, |
| 260 | .read = qla2x00_sysfs_read_fw_dump, |
| 261 | .write = qla2x00_sysfs_write_fw_dump, |
| 262 | }; |
| 263 | static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t, |
| 264 | size_t); |
| 265 | static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t, |
| 266 | size_t); |
| 267 | static struct bin_attribute sysfs_nvram_attr = { |
| 268 | .attr = { |
| 269 | .name = "nvram", |
| 270 | .mode = S_IRUSR | S_IWUSR, |
| 271 | .owner = THIS_MODULE, |
| 272 | }, |
| 273 | .size = sizeof(nvram_t), |
| 274 | .read = qla2x00_sysfs_read_nvram, |
| 275 | .write = qla2x00_sysfs_write_nvram, |
| 276 | }; |
| 277 | |
| 278 | /* -------------------------------------------------------------------------- */ |
| 279 | |
| 280 | |
| 281 | /* SysFS attributes. */ |
| 282 | static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, |
| 283 | loff_t off, size_t count) |
| 284 | { |
| 285 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 286 | struct device, kobj))); |
| 287 | |
| 288 | if (ha->fw_dump_reading == 0) |
| 289 | return 0; |
| 290 | if (off > ha->fw_dump_buffer_len) |
| 291 | return 0; |
| 292 | if (off + count > ha->fw_dump_buffer_len) |
| 293 | count = ha->fw_dump_buffer_len - off; |
| 294 | |
| 295 | memcpy(buf, &ha->fw_dump_buffer[off], count); |
| 296 | |
| 297 | return (count); |
| 298 | } |
| 299 | |
| 300 | static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, |
| 301 | loff_t off, size_t count) |
| 302 | { |
| 303 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 304 | struct device, kobj))); |
| 305 | int reading; |
| 306 | uint32_t dump_size; |
| 307 | |
| 308 | if (off != 0) |
| 309 | return (0); |
| 310 | |
| 311 | reading = simple_strtol(buf, NULL, 10); |
| 312 | switch (reading) { |
| 313 | case 0: |
| 314 | if (ha->fw_dump_reading == 1) { |
| 315 | qla_printk(KERN_INFO, ha, |
| 316 | "Firmware dump cleared on (%ld).\n", |
| 317 | ha->host_no); |
| 318 | |
| 319 | vfree(ha->fw_dump_buffer); |
| 320 | free_pages((unsigned long)ha->fw_dump, |
| 321 | ha->fw_dump_order); |
| 322 | |
| 323 | ha->fw_dump_reading = 0; |
| 324 | ha->fw_dump_buffer = NULL; |
| 325 | ha->fw_dump = NULL; |
| 326 | } |
| 327 | break; |
| 328 | case 1: |
| 329 | if (ha->fw_dump != NULL && !ha->fw_dump_reading) { |
| 330 | ha->fw_dump_reading = 1; |
| 331 | |
| 332 | dump_size = FW_DUMP_SIZE_1M; |
| 333 | if (ha->fw_memory_size < 0x20000) |
| 334 | dump_size = FW_DUMP_SIZE_128K; |
| 335 | else if (ha->fw_memory_size < 0x80000) |
| 336 | dump_size = FW_DUMP_SIZE_512K; |
| 337 | ha->fw_dump_buffer = (char *)vmalloc(dump_size); |
| 338 | if (ha->fw_dump_buffer == NULL) { |
| 339 | qla_printk(KERN_WARNING, ha, |
| 340 | "Unable to allocate memory for firmware " |
| 341 | "dump buffer (%d).\n", dump_size); |
| 342 | |
| 343 | ha->fw_dump_reading = 0; |
| 344 | return (count); |
| 345 | } |
| 346 | qla_printk(KERN_INFO, ha, |
| 347 | "Firmware dump ready for read on (%ld).\n", |
| 348 | ha->host_no); |
| 349 | memset(ha->fw_dump_buffer, 0, dump_size); |
| 350 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 351 | qla2100_ascii_fw_dump(ha); |
| 352 | else |
| 353 | qla2300_ascii_fw_dump(ha); |
| 354 | ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer); |
| 355 | } |
| 356 | break; |
| 357 | } |
| 358 | return (count); |
| 359 | } |
| 360 | |
| 361 | static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, |
| 362 | loff_t off, size_t count) |
| 363 | { |
| 364 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 365 | struct device, kobj))); |
| 366 | uint16_t *witer; |
| 367 | unsigned long flags; |
| 368 | uint16_t cnt; |
| 369 | |
| 370 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t)) |
| 371 | return 0; |
| 372 | |
| 373 | /* Read NVRAM. */ |
| 374 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 375 | qla2x00_lock_nvram_access(ha); |
| 376 | witer = (uint16_t *)buf; |
| 377 | for (cnt = 0; cnt < count / 2; cnt++) { |
| 378 | *witer = cpu_to_le16(qla2x00_get_nvram_word(ha, |
| 379 | cnt+ha->nvram_base)); |
| 380 | witer++; |
| 381 | } |
| 382 | qla2x00_unlock_nvram_access(ha); |
| 383 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 384 | |
| 385 | return (count); |
| 386 | } |
| 387 | |
| 388 | static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, |
| 389 | loff_t off, size_t count) |
| 390 | { |
| 391 | struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, |
| 392 | struct device, kobj))); |
| 393 | uint8_t *iter; |
| 394 | uint16_t *witer; |
| 395 | unsigned long flags; |
| 396 | uint16_t cnt; |
| 397 | uint8_t chksum; |
| 398 | |
| 399 | if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t)) |
| 400 | return 0; |
| 401 | |
| 402 | /* Checksum NVRAM. */ |
| 403 | iter = (uint8_t *)buf; |
| 404 | chksum = 0; |
| 405 | for (cnt = 0; cnt < count - 1; cnt++) |
| 406 | chksum += *iter++; |
| 407 | chksum = ~chksum + 1; |
| 408 | *iter = chksum; |
| 409 | |
| 410 | /* Write NVRAM. */ |
| 411 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 412 | qla2x00_lock_nvram_access(ha); |
| 413 | qla2x00_release_nvram_protection(ha); |
| 414 | witer = (uint16_t *)buf; |
| 415 | for (cnt = 0; cnt < count / 2; cnt++) { |
| 416 | qla2x00_write_nvram_word(ha, cnt+ha->nvram_base, |
| 417 | cpu_to_le16(*witer)); |
| 418 | witer++; |
| 419 | } |
| 420 | qla2x00_unlock_nvram_access(ha); |
| 421 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 422 | |
| 423 | return (count); |
| 424 | } |
| 425 | |
| 426 | /* -------------------------------------------------------------------------- */ |
| 427 | static char * |
| 428 | qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str) |
| 429 | { |
| 430 | static char *pci_bus_modes[] = { |
| 431 | "33", "66", "100", "133", |
| 432 | }; |
| 433 | uint16_t pci_bus; |
| 434 | |
| 435 | strcpy(str, "PCI"); |
| 436 | pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; |
| 437 | if (pci_bus) { |
| 438 | strcat(str, "-X ("); |
| 439 | strcat(str, pci_bus_modes[pci_bus]); |
| 440 | } else { |
| 441 | pci_bus = (ha->pci_attr & BIT_8) >> 8; |
| 442 | strcat(str, " ("); |
| 443 | strcat(str, pci_bus_modes[pci_bus]); |
| 444 | } |
| 445 | strcat(str, " MHz)"); |
| 446 | |
| 447 | return (str); |
| 448 | } |
| 449 | |
| 450 | char * |
| 451 | qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str) |
| 452 | { |
| 453 | char un_str[10]; |
| 454 | |
| 455 | sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, |
| 456 | ha->fw_minor_version, |
| 457 | ha->fw_subminor_version); |
| 458 | |
| 459 | if (ha->fw_attributes & BIT_9) { |
| 460 | strcat(str, "FLX"); |
| 461 | return (str); |
| 462 | } |
| 463 | |
| 464 | switch (ha->fw_attributes & 0xFF) { |
| 465 | case 0x7: |
| 466 | strcat(str, "EF"); |
| 467 | break; |
| 468 | case 0x17: |
| 469 | strcat(str, "TP"); |
| 470 | break; |
| 471 | case 0x37: |
| 472 | strcat(str, "IP"); |
| 473 | break; |
| 474 | case 0x77: |
| 475 | strcat(str, "VI"); |
| 476 | break; |
| 477 | default: |
| 478 | sprintf(un_str, "(%x)", ha->fw_attributes); |
| 479 | strcat(str, un_str); |
| 480 | break; |
| 481 | } |
| 482 | if (ha->fw_attributes & 0x100) |
| 483 | strcat(str, "X"); |
| 484 | |
| 485 | return (str); |
| 486 | } |
| 487 | |
| 488 | /************************************************************************** |
| 489 | * qla2x00_queuecommand |
| 490 | * |
| 491 | * Description: |
| 492 | * Queue a command to the controller. |
| 493 | * |
| 494 | * Input: |
| 495 | * cmd - pointer to Scsi cmd structure |
| 496 | * fn - pointer to Scsi done function |
| 497 | * |
| 498 | * Returns: |
| 499 | * 0 - Always |
| 500 | * |
| 501 | * Note: |
| 502 | * The mid-level driver tries to ensures that queuecommand never gets invoked |
| 503 | * concurrently with itself or the interrupt handler (although the |
| 504 | * interrupt handler may call this routine as part of request-completion |
| 505 | * handling). |
| 506 | **************************************************************************/ |
| 507 | static int |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 508 | qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 510 | scsi_qla_host_t *ha = to_qla_host(cmd->device->host); |
| 511 | os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata; |
| 512 | fc_port_t *fcport = tq->fcport; |
| 513 | os_lun_t *lq; |
| 514 | srb_t *sp; |
| 515 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 517 | lq = GET_LU_Q(ha, cmd->device->id, cmd->device->lun); |
| 518 | if (!fcport || !lq) { |
| 519 | cmd->result = DID_NO_CONNECT << 16; |
| 520 | goto qc_fail_command; |
| 521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 523 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
| 524 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || |
| 525 | atomic_read(&ha->loop_state) == LOOP_DEAD) { |
| 526 | cmd->result = DID_NO_CONNECT << 16; |
| 527 | goto qc_fail_command; |
| 528 | } |
| 529 | goto qc_host_busy; |
| 530 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | spin_unlock_irq(ha->host->host_lock); |
| 533 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 534 | /* Allocate a command packet from the "sp" pool. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | if ((sp = qla2x00_get_new_sp(ha)) == NULL) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 536 | goto qc_host_busy_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 539 | sp->ha = ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | sp->cmd = cmd; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 541 | sp->tgt_queue = tq; |
| 542 | |
| 543 | sp->lun_queue = lq; |
| 544 | lq->io_cnt++; |
| 545 | sp->fclun = lq->fclun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | sp->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | sp->err_id = 0; |
| 549 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 550 | CMD_SP(cmd) = (void *)sp; |
| 551 | cmd->scsi_done = done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 553 | rval = qla2x00_start_scsi(sp); |
| 554 | if (rval != QLA_SUCCESS) |
| 555 | goto qc_host_busy_free_sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 557 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 558 | if (ha->flags.online && ha->flags.process_response_queue && |
| 559 | ha->response_ring_ptr->signature != RESPONSE_PROCESSED) { |
| 560 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 562 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 563 | qla2x00_process_response_queue(ha); |
| 564 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | spin_lock_irq(ha->host->host_lock); |
| 568 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 569 | return 0; |
| 570 | |
| 571 | qc_host_busy_free_sp: |
| 572 | qla2x00_sp_free_dma(ha, sp); |
| 573 | CMD_SP(cmd) = NULL; |
| 574 | mempool_free(sp, ha->srb_mempool); |
| 575 | |
| 576 | qc_host_busy_lock: |
| 577 | spin_lock_irq(ha->host->host_lock); |
| 578 | |
| 579 | qc_host_busy: |
| 580 | return SCSI_MLQUEUE_HOST_BUSY; |
| 581 | |
| 582 | qc_fail_command: |
| 583 | done(cmd); |
| 584 | |
| 585 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* |
| 589 | * qla2x00_eh_wait_on_command |
| 590 | * Waits for the command to be returned by the Firmware for some |
| 591 | * max time. |
| 592 | * |
| 593 | * Input: |
| 594 | * ha = actual ha whose done queue will contain the command |
| 595 | * returned by firmware. |
| 596 | * cmd = Scsi Command to wait on. |
| 597 | * flag = Abort/Reset(Bus or Device Reset) |
| 598 | * |
| 599 | * Return: |
| 600 | * Not Found : 0 |
| 601 | * Found : 1 |
| 602 | */ |
| 603 | static int |
| 604 | qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd) |
| 605 | { |
| 606 | #define ABORT_POLLING_PERIOD HZ |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 607 | #define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD)) |
| 608 | unsigned long wait_iter = ABORT_WAIT_ITER; |
| 609 | int ret = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 611 | while (CMD_SP(cmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 613 | schedule_timeout(ABORT_POLLING_PERIOD); |
| 614 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 615 | if (--wait_iter) |
| 616 | break; |
| 617 | } |
| 618 | if (CMD_SP(cmd)) |
| 619 | ret = QLA_FUNCTION_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 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* |
| 625 | * qla2x00_wait_for_hba_online |
| 626 | * Wait till the HBA is online after going through |
| 627 | * <= MAX_RETRIES_OF_ISP_ABORT or |
| 628 | * finally HBA is disabled ie marked offline |
| 629 | * |
| 630 | * Input: |
| 631 | * ha - pointer to host adapter structure |
| 632 | * |
| 633 | * Note: |
| 634 | * Does context switching-Release SPIN_LOCK |
| 635 | * (if any) before calling this routine. |
| 636 | * |
| 637 | * Return: |
| 638 | * Success (Adapter is online) : 0 |
| 639 | * Failed (Adapter is offline/disabled) : 1 |
| 640 | */ |
| 641 | static int |
| 642 | qla2x00_wait_for_hba_online(scsi_qla_host_t *ha) |
| 643 | { |
| 644 | int return_status; |
| 645 | unsigned long wait_online; |
| 646 | |
| 647 | wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
| 648 | while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) || |
| 649 | test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) || |
| 650 | test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) || |
| 651 | ha->dpc_active) && time_before(jiffies, wait_online)) { |
| 652 | |
| 653 | msleep(1000); |
| 654 | } |
| 655 | if (ha->flags.online) |
| 656 | return_status = QLA_SUCCESS; |
| 657 | else |
| 658 | return_status = QLA_FUNCTION_FAILED; |
| 659 | |
| 660 | DEBUG2(printk("%s return_status=%d\n",__func__,return_status)); |
| 661 | |
| 662 | return (return_status); |
| 663 | } |
| 664 | |
| 665 | /* |
| 666 | * qla2x00_wait_for_loop_ready |
| 667 | * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop |
| 668 | * to be in LOOP_READY state. |
| 669 | * Input: |
| 670 | * ha - pointer to host adapter structure |
| 671 | * |
| 672 | * Note: |
| 673 | * Does context switching-Release SPIN_LOCK |
| 674 | * (if any) before calling this routine. |
| 675 | * |
| 676 | * |
| 677 | * Return: |
| 678 | * Success (LOOP_READY) : 0 |
| 679 | * Failed (LOOP_NOT_READY) : 1 |
| 680 | */ |
| 681 | static inline int |
| 682 | qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha) |
| 683 | { |
| 684 | int return_status = QLA_SUCCESS; |
| 685 | unsigned long loop_timeout ; |
| 686 | |
| 687 | /* wait for 5 min at the max for loop to be ready */ |
| 688 | loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
| 689 | |
| 690 | while ((!atomic_read(&ha->loop_down_timer) && |
| 691 | atomic_read(&ha->loop_state) == LOOP_DOWN) || |
| 692 | test_bit(CFG_ACTIVE, &ha->cfg_flags) || |
| 693 | atomic_read(&ha->loop_state) != LOOP_READY) { |
| 694 | msleep(1000); |
| 695 | if (time_after_eq(jiffies, loop_timeout)) { |
| 696 | return_status = QLA_FUNCTION_FAILED; |
| 697 | break; |
| 698 | } |
| 699 | } |
| 700 | return (return_status); |
| 701 | } |
| 702 | |
| 703 | /************************************************************************** |
| 704 | * qla2xxx_eh_abort |
| 705 | * |
| 706 | * Description: |
| 707 | * The abort function will abort the specified command. |
| 708 | * |
| 709 | * Input: |
| 710 | * cmd = Linux SCSI command packet to be aborted. |
| 711 | * |
| 712 | * Returns: |
| 713 | * Either SUCCESS or FAILED. |
| 714 | * |
| 715 | * Note: |
| 716 | **************************************************************************/ |
| 717 | int |
| 718 | qla2xxx_eh_abort(struct scsi_cmnd *cmd) |
| 719 | { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 720 | scsi_qla_host_t *ha = to_qla_host(cmd->device->host); |
| 721 | srb_t *sp; |
| 722 | int ret, i; |
| 723 | unsigned int id, lun; |
| 724 | unsigned long serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 726 | if (!CMD_SP(cmd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | return FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 729 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 731 | id = cmd->device->id; |
| 732 | lun = cmd->device->lun; |
| 733 | serial = cmd->serial_number; |
| 734 | |
| 735 | /* Check active list for command command. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | spin_unlock_irq(ha->host->host_lock); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 737 | spin_lock(&ha->hardware_lock); |
| 738 | for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { |
| 739 | sp = ha->outstanding_cmds[i]; |
| 740 | |
| 741 | if (sp == NULL) |
| 742 | continue; |
| 743 | |
| 744 | if (sp->cmd != cmd) |
| 745 | continue; |
| 746 | |
| 747 | DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld " |
| 748 | "sp->state=%x\n", __func__, ha->host_no, sp, serial, |
| 749 | sp->state)); |
| 750 | DEBUG3(qla2x00_print_scsi_cmd(cmd);) |
| 751 | |
| 752 | spin_unlock(&ha->hardware_lock); |
| 753 | if (qla2x00_abort_command(ha, sp)) { |
| 754 | DEBUG2(printk("%s(%ld): abort_command " |
| 755 | "mbx failed.\n", __func__, ha->host_no)); |
| 756 | } else { |
| 757 | DEBUG3(printk("%s(%ld): abort_command " |
| 758 | "mbx success.\n", __func__, ha->host_no)); |
| 759 | ret = SUCCESS; |
| 760 | } |
| 761 | spin_lock(&ha->hardware_lock); |
| 762 | |
| 763 | break; |
| 764 | } |
| 765 | |
| 766 | /* Wait for the command to be returned. */ |
| 767 | if (ret == SUCCESS) { |
| 768 | spin_unlock(&ha->hardware_lock); |
| 769 | if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) { |
| 770 | qla_printk(KERN_ERR, ha, |
| 771 | "scsi(%ld:%d:%d): Abort handler timed out -- %lx " |
| 772 | "%x.\n", ha->host_no, id, lun, serial, ret); |
| 773 | } |
| 774 | spin_lock(&ha->hardware_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | spin_lock_irq(ha->host->host_lock); |
| 777 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 778 | qla_printk(KERN_INFO, ha, |
| 779 | "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no, |
| 780 | id, lun, serial, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 782 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /************************************************************************** |
| 786 | * qla2x00_eh_wait_for_pending_target_commands |
| 787 | * |
| 788 | * Description: |
| 789 | * Waits for all the commands to come back from the specified target. |
| 790 | * |
| 791 | * Input: |
| 792 | * ha - pointer to scsi_qla_host structure. |
| 793 | * t - target |
| 794 | * Returns: |
| 795 | * Either SUCCESS or FAILED. |
| 796 | * |
| 797 | * Note: |
| 798 | **************************************************************************/ |
| 799 | static int |
| 800 | qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t) |
| 801 | { |
| 802 | int cnt; |
| 803 | int status; |
| 804 | srb_t *sp; |
| 805 | struct scsi_cmnd *cmd; |
| 806 | |
| 807 | status = 0; |
| 808 | |
| 809 | /* |
| 810 | * Waiting for all commands for the designated target in the active |
| 811 | * array |
| 812 | */ |
| 813 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
| 814 | spin_lock(&ha->hardware_lock); |
| 815 | sp = ha->outstanding_cmds[cnt]; |
| 816 | if (sp) { |
| 817 | cmd = sp->cmd; |
| 818 | spin_unlock(&ha->hardware_lock); |
| 819 | if (cmd->device->id == t) { |
| 820 | if (!qla2x00_eh_wait_on_command(ha, cmd)) { |
| 821 | status = 1; |
| 822 | break; |
| 823 | } |
| 824 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 825 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | spin_unlock(&ha->hardware_lock); |
| 827 | } |
| 828 | } |
| 829 | return (status); |
| 830 | } |
| 831 | |
| 832 | |
| 833 | /************************************************************************** |
| 834 | * qla2xxx_eh_device_reset |
| 835 | * |
| 836 | * Description: |
| 837 | * The device reset function will reset the target and abort any |
| 838 | * executing commands. |
| 839 | * |
| 840 | * NOTE: The use of SP is undefined within this context. Do *NOT* |
| 841 | * attempt to use this value, even if you determine it is |
| 842 | * non-null. |
| 843 | * |
| 844 | * Input: |
| 845 | * cmd = Linux SCSI command packet of the command that cause the |
| 846 | * bus device reset. |
| 847 | * |
| 848 | * Returns: |
| 849 | * SUCCESS/FAILURE (defined as macro in scsi.h). |
| 850 | * |
| 851 | **************************************************************************/ |
| 852 | int |
| 853 | qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 854 | { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 855 | scsi_qla_host_t *ha = to_qla_host(cmd->device->host); |
| 856 | os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata; |
| 857 | fc_port_t *fcport = tq->fcport; |
| 858 | os_lun_t *lq; |
| 859 | srb_t *sp; |
| 860 | int ret; |
| 861 | unsigned int id, lun; |
| 862 | unsigned long serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 864 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 866 | id = cmd->device->id; |
| 867 | lun = cmd->device->lun; |
| 868 | serial = cmd->serial_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 870 | sp = (srb_t *) CMD_SP(cmd); |
| 871 | lq = GET_LU_Q(ha, id, lun); |
| 872 | if (!sp || !fcport || !lq) |
| 873 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 876 | "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] | 877 | |
| 878 | spin_unlock_irq(ha->host->host_lock); |
| 879 | |
| 880 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | spin_lock_irq(ha->host->host_lock); |
| 882 | goto eh_dev_reset_done; |
| 883 | } |
| 884 | |
| 885 | if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 886 | if (qla2x00_device_reset(ha, fcport) == 0) |
| 887 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
| 889 | #if defined(LOGOUT_AFTER_DEVICE_RESET) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 890 | if (ret == SUCCESS) { |
| 891 | if (fcport->flags & FC_FABRIC_DEVICE) { |
| 892 | qla2x00_fabric_logout(ha, fcport->loop_id); |
| 893 | qla2x00_mark_device_lost(ha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | #endif |
| 897 | } else { |
| 898 | DEBUG2(printk(KERN_INFO |
| 899 | "%s failed: loop not ready\n",__func__);) |
| 900 | } |
| 901 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 902 | if (ret == FAILED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | DEBUG3(printk("%s(%ld): device reset failed\n", |
| 904 | __func__, ha->host_no)); |
| 905 | qla_printk(KERN_INFO, ha, "%s: device reset failed\n", |
| 906 | __func__); |
| 907 | |
| 908 | goto eh_dev_reset_done; |
| 909 | } |
| 910 | |
| 911 | /* |
| 912 | * If we are coming down the EH path, wait for all commands to |
| 913 | * complete for the device. |
| 914 | */ |
| 915 | if (cmd->device->host->eh_active) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 916 | if (qla2x00_eh_wait_for_pending_target_commands(ha, id)) |
| 917 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 919 | if (ret == FAILED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | DEBUG3(printk("%s(%ld): failed while waiting for " |
| 921 | "commands\n", __func__, ha->host_no)); |
| 922 | qla_printk(KERN_INFO, ha, |
| 923 | "%s: failed while waiting for commands\n", |
| 924 | __func__); |
| 925 | |
| 926 | goto eh_dev_reset_done; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 931 | "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] | 932 | |
| 933 | eh_dev_reset_done: |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 934 | spin_lock_irq(ha->host->host_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 936 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | /************************************************************************** |
| 940 | * qla2x00_eh_wait_for_pending_commands |
| 941 | * |
| 942 | * Description: |
| 943 | * Waits for all the commands to come back from the specified host. |
| 944 | * |
| 945 | * Input: |
| 946 | * ha - pointer to scsi_qla_host structure. |
| 947 | * |
| 948 | * Returns: |
| 949 | * 1 : SUCCESS |
| 950 | * 0 : FAILED |
| 951 | * |
| 952 | * Note: |
| 953 | **************************************************************************/ |
| 954 | static int |
| 955 | qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha) |
| 956 | { |
| 957 | int cnt; |
| 958 | int status; |
| 959 | srb_t *sp; |
| 960 | struct scsi_cmnd *cmd; |
| 961 | |
| 962 | status = 1; |
| 963 | |
| 964 | /* |
| 965 | * Waiting for all commands for the designated target in the active |
| 966 | * array |
| 967 | */ |
| 968 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { |
| 969 | spin_lock(&ha->hardware_lock); |
| 970 | sp = ha->outstanding_cmds[cnt]; |
| 971 | if (sp) { |
| 972 | cmd = sp->cmd; |
| 973 | spin_unlock(&ha->hardware_lock); |
| 974 | status = qla2x00_eh_wait_on_command(ha, cmd); |
| 975 | if (status == 0) |
| 976 | break; |
| 977 | } |
| 978 | else { |
| 979 | spin_unlock(&ha->hardware_lock); |
| 980 | } |
| 981 | } |
| 982 | return (status); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | /************************************************************************** |
| 987 | * qla2xxx_eh_bus_reset |
| 988 | * |
| 989 | * Description: |
| 990 | * The bus reset function will reset the bus and abort any executing |
| 991 | * commands. |
| 992 | * |
| 993 | * Input: |
| 994 | * cmd = Linux SCSI command packet of the command that cause the |
| 995 | * bus reset. |
| 996 | * |
| 997 | * Returns: |
| 998 | * SUCCESS/FAILURE (defined as macro in scsi.h). |
| 999 | * |
| 1000 | **************************************************************************/ |
| 1001 | int |
| 1002 | qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) |
| 1003 | { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1004 | scsi_qla_host_t *ha = to_qla_host(cmd->device->host); |
| 1005 | os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata; |
| 1006 | fc_port_t *fcport = tq->fcport; |
| 1007 | os_lun_t *lq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | srb_t *sp; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1009 | int ret; |
| 1010 | unsigned int id, lun; |
| 1011 | unsigned long serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1013 | ret = FAILED; |
| 1014 | |
| 1015 | id = cmd->device->id; |
| 1016 | lun = cmd->device->lun; |
| 1017 | serial = cmd->serial_number; |
| 1018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | sp = (srb_t *) CMD_SP(cmd); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1020 | lq = GET_LU_Q(ha, id, lun); |
| 1021 | if (!sp || !fcport || !lq) |
| 1022 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
| 1024 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1025 | "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] | 1026 | |
| 1027 | spin_unlock_irq(ha->host->host_lock); |
| 1028 | |
| 1029 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 1030 | DEBUG2(printk("%s failed:board disabled\n",__func__)); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1031 | goto eh_bus_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1035 | if (qla2x00_loop_reset(ha) == QLA_SUCCESS) |
| 1036 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1038 | if (ret == FAILED) |
| 1039 | goto eh_bus_reset_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
| 1041 | /* Waiting for our command in done_queue to be returned to OS.*/ |
| 1042 | if (cmd->device->host->eh_active) |
| 1043 | if (!qla2x00_eh_wait_for_pending_commands(ha)) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1044 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1046 | eh_bus_reset_done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1048 | (ret == FAILED) ? "failed" : "succeded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1050 | spin_lock_irq(ha->host->host_lock); |
| 1051 | |
| 1052 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | /************************************************************************** |
| 1056 | * qla2xxx_eh_host_reset |
| 1057 | * |
| 1058 | * Description: |
| 1059 | * The reset function will reset the Adapter. |
| 1060 | * |
| 1061 | * Input: |
| 1062 | * cmd = Linux SCSI command packet of the command that cause the |
| 1063 | * adapter reset. |
| 1064 | * |
| 1065 | * Returns: |
| 1066 | * Either SUCCESS or FAILED. |
| 1067 | * |
| 1068 | * Note: |
| 1069 | **************************************************************************/ |
| 1070 | int |
| 1071 | qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 1072 | { |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1073 | scsi_qla_host_t *ha = to_qla_host(cmd->device->host); |
| 1074 | os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata; |
| 1075 | fc_port_t *fcport = tq->fcport; |
| 1076 | os_lun_t *lq; |
| 1077 | srb_t *sp; |
| 1078 | int ret; |
| 1079 | unsigned int id, lun; |
| 1080 | unsigned long serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1082 | ret = FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1084 | id = cmd->device->id; |
| 1085 | lun = cmd->device->lun; |
| 1086 | serial = cmd->serial_number; |
| 1087 | |
| 1088 | sp = (srb_t *) CMD_SP(cmd); |
| 1089 | lq = GET_LU_Q(ha, id, lun); |
| 1090 | if (!sp || !fcport || !lq) |
| 1091 | return ret; |
| 1092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | qla_printk(KERN_INFO, ha, |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1094 | "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] | 1095 | |
| 1096 | spin_unlock_irq(ha->host->host_lock); |
| 1097 | |
| 1098 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1099 | goto eh_host_reset_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* |
| 1102 | * Fixme-may be dpc thread is active and processing |
| 1103 | * loop_resync,so wait a while for it to |
| 1104 | * be completed and then issue big hammer.Otherwise |
| 1105 | * it may cause I/O failure as big hammer marks the |
| 1106 | * devices as lost kicking of the port_down_timer |
| 1107 | * while dpc is stuck for the mailbox to complete. |
| 1108 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | qla2x00_wait_for_loop_ready(ha); |
| 1110 | set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 1111 | if (qla2x00_abort_isp(ha)) { |
| 1112 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 1113 | /* failed. schedule dpc to try */ |
| 1114 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 1115 | |
| 1116 | if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1117 | goto eh_host_reset_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 1120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | /* Waiting for our command in done_queue to be returned to OS.*/ |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1122 | if (qla2x00_eh_wait_for_pending_commands(ha)) |
| 1123 | ret = SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1125 | eh_host_reset_lock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | spin_lock_irq(ha->host->host_lock); |
| 1127 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1128 | qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, |
| 1129 | (ret == FAILED) ? "failed" : "succeded"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1131 | return ret; |
| 1132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
| 1134 | /* |
| 1135 | * qla2x00_loop_reset |
| 1136 | * Issue loop reset. |
| 1137 | * |
| 1138 | * Input: |
| 1139 | * ha = adapter block pointer. |
| 1140 | * |
| 1141 | * Returns: |
| 1142 | * 0 = success |
| 1143 | */ |
| 1144 | static int |
| 1145 | qla2x00_loop_reset(scsi_qla_host_t *ha) |
| 1146 | { |
| 1147 | int status = QLA_SUCCESS; |
| 1148 | uint16_t t; |
| 1149 | os_tgt_t *tq; |
| 1150 | |
| 1151 | if (ha->flags.enable_lip_reset) { |
| 1152 | status = qla2x00_lip_reset(ha); |
| 1153 | } |
| 1154 | |
| 1155 | if (status == QLA_SUCCESS && ha->flags.enable_target_reset) { |
| 1156 | for (t = 0; t < MAX_FIBRE_DEVICES; t++) { |
| 1157 | if ((tq = TGT_Q(ha, t)) == NULL) |
| 1158 | continue; |
| 1159 | |
| 1160 | if (tq->fcport == NULL) |
| 1161 | continue; |
| 1162 | |
| 1163 | status = qla2x00_target_reset(ha, 0, t); |
| 1164 | if (status != QLA_SUCCESS) { |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | if (status == QLA_SUCCESS && |
| 1171 | ((!ha->flags.enable_target_reset && |
| 1172 | !ha->flags.enable_lip_reset) || |
| 1173 | ha->flags.enable_lip_full_login)) { |
| 1174 | |
| 1175 | status = qla2x00_full_login_lip(ha); |
| 1176 | } |
| 1177 | |
| 1178 | /* Issue marker command only when we are going to start the I/O */ |
| 1179 | ha->marker_needed = 1; |
| 1180 | |
| 1181 | if (status) { |
| 1182 | /* Empty */ |
| 1183 | DEBUG2_3(printk("%s(%ld): **** FAILED ****\n", |
| 1184 | __func__, |
| 1185 | ha->host_no);) |
| 1186 | } else { |
| 1187 | /* Empty */ |
| 1188 | DEBUG3(printk("%s(%ld): exiting normally.\n", |
| 1189 | __func__, |
| 1190 | ha->host_no);) |
| 1191 | } |
| 1192 | |
| 1193 | return(status); |
| 1194 | } |
| 1195 | |
| 1196 | /* |
| 1197 | * qla2x00_device_reset |
| 1198 | * Issue bus device reset message to the target. |
| 1199 | * |
| 1200 | * Input: |
| 1201 | * ha = adapter block pointer. |
| 1202 | * t = SCSI ID. |
| 1203 | * TARGET_QUEUE_LOCK must be released. |
| 1204 | * ADAPTER_STATE_LOCK must be released. |
| 1205 | * |
| 1206 | * Context: |
| 1207 | * Kernel context. |
| 1208 | */ |
| 1209 | static int |
| 1210 | qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport) |
| 1211 | { |
| 1212 | /* Abort Target command will clear Reservation */ |
| 1213 | return qla2x00_abort_target(reset_fcport); |
| 1214 | } |
| 1215 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1216 | static int |
| 1217 | qla2xxx_slave_alloc(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | { |
| 1219 | scsi_qla_host_t *ha = to_qla_host(sdev->host); |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1220 | os_tgt_t *tq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1222 | tq = (os_tgt_t *) TGT_Q(ha, sdev->id); |
| 1223 | if (!tq) |
| 1224 | return -ENXIO; |
| 1225 | if (!tq->fcport) |
| 1226 | return -ENXIO; |
| 1227 | |
| 1228 | sdev->hostdata = tq; |
| 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
| 1233 | static int |
| 1234 | qla2xxx_slave_configure(struct scsi_device *sdev) |
| 1235 | { |
| 1236 | if (sdev->tagged_supported) |
| 1237 | scsi_activate_tcq(sdev, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | else |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1239 | scsi_deactivate_tcq(sdev, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1241 | return 0; |
| 1242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 1244 | static void |
| 1245 | qla2xxx_slave_destroy(struct scsi_device *sdev) |
| 1246 | { |
| 1247 | sdev->hostdata = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. |
| 1252 | * @ha: HA context |
| 1253 | * |
| 1254 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 1255 | * supported addressing method. |
| 1256 | */ |
| 1257 | static void |
| 1258 | qla2x00_config_dma_addressing(scsi_qla_host_t *ha) |
| 1259 | { |
| 1260 | /* Assume 32bit DMA address */ |
| 1261 | ha->flags.enable_64bit_addressing = 0; |
| 1262 | ha->calc_request_entries = qla2x00_calc_iocbs_32; |
| 1263 | ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32; |
| 1264 | |
| 1265 | /* |
| 1266 | * Given the two variants pci_set_dma_mask(), allow the compiler to |
| 1267 | * assist in setting the proper dma mask. |
| 1268 | */ |
| 1269 | if (sizeof(dma_addr_t) > 4) { |
| 1270 | if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) { |
| 1271 | ha->flags.enable_64bit_addressing = 1; |
| 1272 | ha->calc_request_entries = qla2x00_calc_iocbs_64; |
| 1273 | ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64; |
| 1274 | |
| 1275 | if (pci_set_consistent_dma_mask(ha->pdev, |
| 1276 | DMA_64BIT_MASK)) { |
| 1277 | qla_printk(KERN_DEBUG, ha, |
| 1278 | "Failed to set 64 bit PCI consistent mask; " |
| 1279 | "using 32 bit.\n"); |
| 1280 | pci_set_consistent_dma_mask(ha->pdev, |
| 1281 | DMA_32BIT_MASK); |
| 1282 | } |
| 1283 | } else { |
| 1284 | qla_printk(KERN_DEBUG, ha, |
| 1285 | "Failed to set 64 bit PCI DMA mask, falling back " |
| 1286 | "to 32 bit MASK.\n"); |
| 1287 | pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK); |
| 1288 | } |
| 1289 | } else { |
| 1290 | pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | static int |
| 1295 | qla2x00_iospace_config(scsi_qla_host_t *ha) |
| 1296 | { |
| 1297 | unsigned long pio, pio_len, pio_flags; |
| 1298 | unsigned long mmio, mmio_len, mmio_flags; |
| 1299 | |
| 1300 | /* We only need PIO for Flash operations on ISP2312 v2 chips. */ |
| 1301 | pio = pci_resource_start(ha->pdev, 0); |
| 1302 | pio_len = pci_resource_len(ha->pdev, 0); |
| 1303 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 1304 | if (pio_flags & IORESOURCE_IO) { |
| 1305 | if (pio_len < MIN_IOBASE_LEN) { |
| 1306 | qla_printk(KERN_WARNING, ha, |
| 1307 | "Invalid PCI I/O region size (%s)...\n", |
| 1308 | pci_name(ha->pdev)); |
| 1309 | pio = 0; |
| 1310 | } |
| 1311 | } else { |
| 1312 | qla_printk(KERN_WARNING, ha, |
| 1313 | "region #0 not a PIO resource (%s)...\n", |
| 1314 | pci_name(ha->pdev)); |
| 1315 | pio = 0; |
| 1316 | } |
| 1317 | |
| 1318 | /* Use MMIO operations for all accesses. */ |
| 1319 | mmio = pci_resource_start(ha->pdev, 1); |
| 1320 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 1321 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 1322 | |
| 1323 | if (!(mmio_flags & IORESOURCE_MEM)) { |
| 1324 | qla_printk(KERN_ERR, ha, |
| 1325 | "region #0 not an MMIO resource (%s), aborting\n", |
| 1326 | pci_name(ha->pdev)); |
| 1327 | goto iospace_error_exit; |
| 1328 | } |
| 1329 | if (mmio_len < MIN_IOBASE_LEN) { |
| 1330 | qla_printk(KERN_ERR, ha, |
| 1331 | "Invalid PCI mem region size (%s), aborting\n", |
| 1332 | pci_name(ha->pdev)); |
| 1333 | goto iospace_error_exit; |
| 1334 | } |
| 1335 | |
| 1336 | if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) { |
| 1337 | qla_printk(KERN_WARNING, ha, |
| 1338 | "Failed to reserve PIO/MMIO regions (%s)\n", |
| 1339 | pci_name(ha->pdev)); |
| 1340 | |
| 1341 | goto iospace_error_exit; |
| 1342 | } |
| 1343 | |
| 1344 | ha->pio_address = pio; |
| 1345 | ha->pio_length = pio_len; |
| 1346 | ha->iobase = ioremap(mmio, MIN_IOBASE_LEN); |
| 1347 | if (!ha->iobase) { |
| 1348 | qla_printk(KERN_ERR, ha, |
| 1349 | "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev)); |
| 1350 | |
| 1351 | goto iospace_error_exit; |
| 1352 | } |
| 1353 | |
| 1354 | return (0); |
| 1355 | |
| 1356 | iospace_error_exit: |
| 1357 | return (-ENOMEM); |
| 1358 | } |
| 1359 | |
| 1360 | /* |
| 1361 | * PCI driver interface |
| 1362 | */ |
| 1363 | int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info) |
| 1364 | { |
| 1365 | int ret; |
| 1366 | device_reg_t __iomem *reg; |
| 1367 | struct Scsi_Host *host; |
| 1368 | scsi_qla_host_t *ha; |
| 1369 | unsigned long flags = 0; |
| 1370 | unsigned long wait_switch = 0; |
| 1371 | char pci_info[20]; |
| 1372 | char fw_str[30]; |
| 1373 | |
| 1374 | if (pci_enable_device(pdev)) |
| 1375 | return -1; |
| 1376 | |
| 1377 | host = scsi_host_alloc(&qla2x00_driver_template, |
| 1378 | sizeof(scsi_qla_host_t)); |
| 1379 | if (host == NULL) { |
| 1380 | printk(KERN_WARNING |
| 1381 | "qla2xxx: Couldn't allocate host from scsi layer!\n"); |
| 1382 | goto probe_disable_device; |
| 1383 | } |
| 1384 | |
| 1385 | /* Clear our data area */ |
| 1386 | ha = (scsi_qla_host_t *)host->hostdata; |
| 1387 | memset(ha, 0, sizeof(scsi_qla_host_t)); |
| 1388 | |
| 1389 | ha->pdev = pdev; |
| 1390 | ha->host = host; |
| 1391 | ha->host_no = host->host_no; |
| 1392 | ha->brd_info = brd_info; |
| 1393 | sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no); |
| 1394 | |
| 1395 | /* Configure PCI I/O space */ |
| 1396 | ret = qla2x00_iospace_config(ha); |
| 1397 | if (ret != 0) { |
| 1398 | goto probe_failed; |
| 1399 | } |
| 1400 | |
| 1401 | /* Sanitize the information from PCI BIOS. */ |
| 1402 | host->irq = pdev->irq; |
| 1403 | |
| 1404 | qla_printk(KERN_INFO, ha, |
| 1405 | "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name, |
| 1406 | host->irq, ha->iobase); |
| 1407 | |
| 1408 | spin_lock_init(&ha->hardware_lock); |
| 1409 | |
| 1410 | /* 4.23 Initialize /proc/scsi/qla2x00 counters */ |
| 1411 | ha->actthreads = 0; |
| 1412 | ha->qthreads = 0; |
| 1413 | ha->total_isr_cnt = 0; |
| 1414 | ha->total_isp_aborts = 0; |
| 1415 | ha->total_lip_cnt = 0; |
| 1416 | ha->total_dev_errs = 0; |
| 1417 | ha->total_ios = 0; |
| 1418 | ha->total_bytes = 0; |
| 1419 | |
| 1420 | ha->prev_topology = 0; |
| 1421 | ha->ports = MAX_BUSES; |
| 1422 | |
| 1423 | if (IS_QLA2100(ha)) { |
| 1424 | ha->max_targets = MAX_TARGETS_2100; |
| 1425 | ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; |
| 1426 | ha->request_q_length = REQUEST_ENTRY_CNT_2100; |
| 1427 | ha->response_q_length = RESPONSE_ENTRY_CNT_2100; |
| 1428 | ha->last_loop_id = SNS_LAST_LOOP_ID_2100; |
| 1429 | host->sg_tablesize = 32; |
| 1430 | } else if (IS_QLA2200(ha)) { |
| 1431 | ha->max_targets = MAX_TARGETS_2200; |
| 1432 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 1433 | ha->request_q_length = REQUEST_ENTRY_CNT_2200; |
| 1434 | ha->response_q_length = RESPONSE_ENTRY_CNT_2100; |
| 1435 | ha->last_loop_id = SNS_LAST_LOOP_ID_2100; |
| 1436 | } else /*if (IS_QLA2300(ha))*/ { |
| 1437 | ha->max_targets = MAX_TARGETS_2200; |
| 1438 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
| 1439 | ha->request_q_length = REQUEST_ENTRY_CNT_2200; |
| 1440 | ha->response_q_length = RESPONSE_ENTRY_CNT_2300; |
| 1441 | ha->last_loop_id = SNS_LAST_LOOP_ID_2300; |
| 1442 | } |
| 1443 | host->can_queue = ha->request_q_length + 128; |
| 1444 | |
| 1445 | /* load the F/W, read paramaters, and init the H/W */ |
| 1446 | ha->instance = num_hosts; |
| 1447 | |
| 1448 | init_MUTEX(&ha->mbx_cmd_sem); |
| 1449 | init_MUTEX_LOCKED(&ha->mbx_intr_sem); |
| 1450 | |
| 1451 | INIT_LIST_HEAD(&ha->list); |
| 1452 | INIT_LIST_HEAD(&ha->fcports); |
| 1453 | INIT_LIST_HEAD(&ha->rscn_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
| 1455 | /* |
| 1456 | * These locks are used to prevent more than one CPU |
| 1457 | * from modifying the queue at the same time. The |
| 1458 | * higher level "host_lock" will reduce most |
| 1459 | * contention for these locks. |
| 1460 | */ |
| 1461 | spin_lock_init(&ha->mbx_reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
| 1463 | ha->dpc_pid = -1; |
| 1464 | init_completion(&ha->dpc_inited); |
| 1465 | init_completion(&ha->dpc_exited); |
| 1466 | |
| 1467 | qla2x00_config_dma_addressing(ha); |
| 1468 | if (qla2x00_mem_alloc(ha)) { |
| 1469 | qla_printk(KERN_WARNING, ha, |
| 1470 | "[ERROR] Failed to allocate memory for adapter\n"); |
| 1471 | |
| 1472 | goto probe_failed; |
| 1473 | } |
| 1474 | |
| 1475 | if (qla2x00_initialize_adapter(ha) && |
| 1476 | !(ha->device_flags & DFLG_NO_CABLE)) { |
| 1477 | |
| 1478 | qla_printk(KERN_WARNING, ha, |
| 1479 | "Failed to initialize adapter\n"); |
| 1480 | |
| 1481 | DEBUG2(printk("scsi(%ld): Failed to initialize adapter - " |
| 1482 | "Adapter flags %x.\n", |
| 1483 | ha->host_no, ha->device_flags)); |
| 1484 | |
| 1485 | goto probe_failed; |
| 1486 | } |
| 1487 | |
| 1488 | /* |
| 1489 | * Startup the kernel thread for this host adapter |
| 1490 | */ |
| 1491 | ha->dpc_should_die = 0; |
| 1492 | ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0); |
| 1493 | if (ha->dpc_pid < 0) { |
| 1494 | qla_printk(KERN_WARNING, ha, |
| 1495 | "Unable to start DPC thread!\n"); |
| 1496 | |
| 1497 | goto probe_failed; |
| 1498 | } |
| 1499 | wait_for_completion(&ha->dpc_inited); |
| 1500 | |
| 1501 | host->this_id = 255; |
| 1502 | host->cmd_per_lun = 3; |
| 1503 | host->max_cmd_len = MAX_CMDSZ; |
| 1504 | host->max_channel = ha->ports - 1; |
| 1505 | host->max_lun = ha->max_luns; |
| 1506 | BUG_ON(qla2xxx_transport_template == NULL); |
| 1507 | host->transportt = qla2xxx_transport_template; |
| 1508 | host->unique_id = ha->instance; |
| 1509 | host->max_id = ha->max_targets; |
| 1510 | |
| 1511 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1512 | ret = request_irq(host->irq, qla2100_intr_handler, |
| 1513 | SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha); |
| 1514 | else |
| 1515 | ret = request_irq(host->irq, qla2300_intr_handler, |
| 1516 | SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha); |
| 1517 | if (ret != 0) { |
| 1518 | qla_printk(KERN_WARNING, ha, |
| 1519 | "Failed to reserve interrupt %d already in use.\n", |
| 1520 | host->irq); |
| 1521 | goto probe_failed; |
| 1522 | } |
| 1523 | |
| 1524 | /* Initialized the timer */ |
| 1525 | qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL); |
| 1526 | |
| 1527 | DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", |
| 1528 | ha->host_no, ha)); |
| 1529 | |
| 1530 | reg = ha->iobase; |
| 1531 | |
| 1532 | /* Disable ISP interrupts. */ |
| 1533 | qla2x00_disable_intrs(ha); |
| 1534 | |
| 1535 | /* Ensure mailbox registers are free. */ |
| 1536 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1537 | WRT_REG_WORD(®->semaphore, 0); |
| 1538 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 1539 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 1540 | |
| 1541 | /* Enable proper parity */ |
| 1542 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1543 | if (IS_QLA2300(ha)) |
| 1544 | /* SRAM parity */ |
| 1545 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1)); |
| 1546 | else |
| 1547 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1548 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7)); |
| 1549 | } |
| 1550 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1551 | |
| 1552 | /* Enable chip interrupts. */ |
| 1553 | qla2x00_enable_intrs(ha); |
| 1554 | |
| 1555 | /* v2.19.5b6 */ |
| 1556 | /* |
| 1557 | * Wait around max loop_reset_delay secs for the devices to come |
| 1558 | * on-line. We don't want Linux scanning before we are ready. |
| 1559 | * |
| 1560 | */ |
| 1561 | for (wait_switch = jiffies + (ha->loop_reset_delay * HZ); |
| 1562 | time_before(jiffies,wait_switch) && |
| 1563 | !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES)) |
| 1564 | && (ha->device_flags & SWITCH_FOUND) ;) { |
| 1565 | |
| 1566 | qla2x00_check_fabric_devices(ha); |
| 1567 | |
| 1568 | msleep(10); |
| 1569 | } |
| 1570 | |
| 1571 | pci_set_drvdata(pdev, ha); |
| 1572 | ha->flags.init_done = 1; |
| 1573 | num_hosts++; |
| 1574 | |
| 1575 | /* List the target we have found */ |
| 1576 | if (displayConfig) { |
| 1577 | qla2x00_display_fc_names(ha); |
| 1578 | } |
| 1579 | |
| 1580 | if (scsi_add_host(host, &pdev->dev)) |
| 1581 | goto probe_failed; |
| 1582 | |
| 1583 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr); |
| 1584 | sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr); |
| 1585 | |
| 1586 | qla_printk(KERN_INFO, ha, "\n" |
| 1587 | " QLogic Fibre Channel HBA Driver: %s\n" |
| 1588 | " QLogic %s - %s\n" |
| 1589 | " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str, |
| 1590 | ha->model_number, ha->model_desc ? ha->model_desc: "", |
| 1591 | ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info), |
| 1592 | pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-', |
| 1593 | ha->host_no, qla2x00_get_fw_version_str(ha, fw_str)); |
| 1594 | |
| 1595 | if (ql2xdoinitscan) |
| 1596 | scsi_scan_host(host); |
| 1597 | |
| 1598 | return 0; |
| 1599 | |
| 1600 | probe_failed: |
| 1601 | qla2x00_free_device(ha); |
| 1602 | |
| 1603 | scsi_host_put(host); |
| 1604 | |
| 1605 | probe_disable_device: |
| 1606 | pci_disable_device(pdev); |
| 1607 | |
| 1608 | return -1; |
| 1609 | } |
| 1610 | EXPORT_SYMBOL_GPL(qla2x00_probe_one); |
| 1611 | |
| 1612 | void qla2x00_remove_one(struct pci_dev *pdev) |
| 1613 | { |
| 1614 | scsi_qla_host_t *ha; |
| 1615 | |
| 1616 | ha = pci_get_drvdata(pdev); |
| 1617 | |
| 1618 | sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, |
| 1619 | &sysfs_fw_dump_attr); |
| 1620 | sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr); |
| 1621 | |
| 1622 | scsi_remove_host(ha->host); |
| 1623 | |
| 1624 | qla2x00_free_device(ha); |
| 1625 | |
| 1626 | scsi_host_put(ha->host); |
| 1627 | |
| 1628 | pci_set_drvdata(pdev, NULL); |
| 1629 | } |
| 1630 | EXPORT_SYMBOL_GPL(qla2x00_remove_one); |
| 1631 | |
| 1632 | static void |
| 1633 | qla2x00_free_device(scsi_qla_host_t *ha) |
| 1634 | { |
| 1635 | int ret; |
| 1636 | |
| 1637 | /* Abort any outstanding IO descriptors. */ |
| 1638 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 1639 | qla2x00_cancel_io_descriptors(ha); |
| 1640 | |
| 1641 | /* turn-off interrupts on the card */ |
| 1642 | if (ha->interrupts_on) |
| 1643 | qla2x00_disable_intrs(ha); |
| 1644 | |
| 1645 | /* Disable timer */ |
| 1646 | if (ha->timer_active) |
| 1647 | qla2x00_stop_timer(ha); |
| 1648 | |
| 1649 | /* Kill the kernel thread for this host */ |
| 1650 | if (ha->dpc_pid >= 0) { |
| 1651 | ha->dpc_should_die = 1; |
| 1652 | wmb(); |
| 1653 | ret = kill_proc(ha->dpc_pid, SIGHUP, 1); |
| 1654 | if (ret) { |
| 1655 | qla_printk(KERN_ERR, ha, |
| 1656 | "Unable to signal DPC thread -- (%d)\n", ret); |
| 1657 | |
| 1658 | /* TODO: SOMETHING MORE??? */ |
| 1659 | } else { |
| 1660 | wait_for_completion(&ha->dpc_exited); |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | qla2x00_mem_free(ha); |
| 1665 | |
| 1666 | |
| 1667 | ha->flags.online = 0; |
| 1668 | |
| 1669 | /* Detach interrupts */ |
| 1670 | if (ha->pdev->irq) |
| 1671 | free_irq(ha->pdev->irq, ha); |
| 1672 | |
| 1673 | /* release io space registers */ |
| 1674 | if (ha->iobase) |
| 1675 | iounmap(ha->iobase); |
| 1676 | pci_release_regions(ha->pdev); |
| 1677 | |
| 1678 | pci_disable_device(ha->pdev); |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | /* |
| 1683 | * The following support functions are adopted to handle |
| 1684 | * the re-entrant qla2x00_proc_info correctly. |
| 1685 | */ |
| 1686 | static void |
| 1687 | copy_mem_info(struct info_str *info, char *data, int len) |
| 1688 | { |
| 1689 | if (info->pos + len > info->offset + info->length) |
| 1690 | len = info->offset + info->length - info->pos; |
| 1691 | |
| 1692 | if (info->pos + len < info->offset) { |
| 1693 | info->pos += len; |
| 1694 | return; |
| 1695 | } |
| 1696 | |
| 1697 | if (info->pos < info->offset) { |
| 1698 | off_t partial; |
| 1699 | |
| 1700 | partial = info->offset - info->pos; |
| 1701 | data += partial; |
| 1702 | info->pos += partial; |
| 1703 | len -= partial; |
| 1704 | } |
| 1705 | |
| 1706 | if (len > 0) { |
| 1707 | memcpy(info->buffer, data, len); |
| 1708 | info->pos += len; |
| 1709 | info->buffer += len; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | static int |
| 1714 | copy_info(struct info_str *info, char *fmt, ...) |
| 1715 | { |
| 1716 | va_list args; |
| 1717 | char buf[256]; |
| 1718 | int len; |
| 1719 | |
| 1720 | va_start(args, fmt); |
| 1721 | len = vsprintf(buf, fmt, args); |
| 1722 | va_end(args); |
| 1723 | |
| 1724 | copy_mem_info(info, buf, len); |
| 1725 | |
| 1726 | return (len); |
| 1727 | } |
| 1728 | |
| 1729 | /************************************************************************* |
| 1730 | * qla2x00_proc_info |
| 1731 | * |
| 1732 | * Description: |
| 1733 | * Return information to handle /proc support for the driver. |
| 1734 | * |
| 1735 | * inout : decides the direction of the dataflow and the meaning of the |
| 1736 | * variables |
| 1737 | * buffer: If inout==0 data is being written to it else read from it |
| 1738 | * (ptr to a page buffer) |
| 1739 | * *start: If inout==0 start of the valid data in the buffer |
| 1740 | * offset: If inout==0 starting offset from the beginning of all |
| 1741 | * possible data to return. |
| 1742 | * length: If inout==0 max number of bytes to be written into the buffer |
| 1743 | * else number of bytes in "buffer" |
| 1744 | * Returns: |
| 1745 | * < 0: error. errno value. |
| 1746 | * >= 0: sizeof data returned. |
| 1747 | *************************************************************************/ |
| 1748 | int |
| 1749 | qla2x00_proc_info(struct Scsi_Host *shost, char *buffer, |
| 1750 | char **start, off_t offset, int length, int inout) |
| 1751 | { |
| 1752 | struct info_str info; |
| 1753 | int retval = -EINVAL; |
| 1754 | os_lun_t *up; |
| 1755 | os_tgt_t *tq; |
| 1756 | unsigned int t, l; |
| 1757 | uint32_t tmp_sn; |
| 1758 | uint32_t *flags; |
| 1759 | uint8_t *loop_state; |
| 1760 | scsi_qla_host_t *ha; |
| 1761 | char fw_info[30]; |
| 1762 | |
| 1763 | DEBUG3(printk(KERN_INFO |
| 1764 | "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n", |
| 1765 | buffer, offset, length);) |
| 1766 | |
| 1767 | ha = (scsi_qla_host_t *) shost->hostdata; |
| 1768 | |
| 1769 | if (inout) { |
| 1770 | /* Has data been written to the file? */ |
| 1771 | DEBUG3(printk( |
| 1772 | "%s: has data been written to the file. \n", |
| 1773 | __func__);) |
| 1774 | |
| 1775 | return -ENOSYS; |
| 1776 | } |
| 1777 | |
| 1778 | if (start) { |
| 1779 | *start = buffer; |
| 1780 | } |
| 1781 | |
| 1782 | info.buffer = buffer; |
| 1783 | info.length = length; |
| 1784 | info.offset = offset; |
| 1785 | info.pos = 0; |
| 1786 | |
| 1787 | /* start building the print buffer */ |
| 1788 | copy_info(&info, |
| 1789 | "QLogic PCI to Fibre Channel Host Adapter for %s:\n" |
| 1790 | " Firmware version %s, ", |
| 1791 | ha->model_number, qla2x00_get_fw_version_str(ha, fw_info)); |
| 1792 | |
| 1793 | copy_info(&info, "Driver version %s\n", qla2x00_version_str); |
| 1794 | |
| 1795 | tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | |
| 1796 | ha->serial1; |
| 1797 | copy_info(&info, "ISP: %s, Serial# %c%05d\n", |
| 1798 | ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000)); |
| 1799 | |
| 1800 | copy_info(&info, |
| 1801 | "Request Queue = 0x%llx, Response Queue = 0x%llx\n", |
| 1802 | (unsigned long long)ha->request_dma, |
| 1803 | (unsigned long long)ha->response_dma); |
| 1804 | |
| 1805 | copy_info(&info, |
| 1806 | "Request Queue count = %d, Response Queue count = %d\n", |
| 1807 | ha->request_q_length, ha->response_q_length); |
| 1808 | |
| 1809 | copy_info(&info, |
| 1810 | "Total number of active commands = %ld\n", |
| 1811 | ha->actthreads); |
| 1812 | |
| 1813 | copy_info(&info, |
| 1814 | "Total number of interrupts = %ld\n", |
| 1815 | (long)ha->total_isr_cnt); |
| 1816 | |
| 1817 | copy_info(&info, |
| 1818 | " Device queue depth = 0x%x\n", |
| 1819 | (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth); |
| 1820 | |
| 1821 | copy_info(&info, |
| 1822 | "Number of free request entries = %d\n", ha->req_q_cnt); |
| 1823 | |
| 1824 | copy_info(&info, |
| 1825 | "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout); |
| 1826 | |
| 1827 | copy_info(&info, |
| 1828 | "Number of ISP aborts = %ld\n", ha->total_isp_aborts); |
| 1829 | |
| 1830 | copy_info(&info, |
| 1831 | "Number of loop resyncs = %ld\n", ha->total_loop_resync); |
| 1832 | |
| 1833 | copy_info(&info, |
| 1834 | "Number of retries for empty slots = %ld\n", |
| 1835 | qla2x00_stats.outarray_full); |
| 1836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | flags = (uint32_t *) &ha->flags; |
| 1838 | |
| 1839 | if (atomic_read(&ha->loop_state) == LOOP_DOWN) { |
| 1840 | loop_state = "DOWN"; |
| 1841 | } else if (atomic_read(&ha->loop_state) == LOOP_UP) { |
| 1842 | loop_state = "UP"; |
| 1843 | } else if (atomic_read(&ha->loop_state) == LOOP_READY) { |
| 1844 | loop_state = "READY"; |
| 1845 | } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) { |
| 1846 | loop_state = "TIMEOUT"; |
| 1847 | } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) { |
| 1848 | loop_state = "UPDATE"; |
| 1849 | } else { |
| 1850 | loop_state = "UNKNOWN"; |
| 1851 | } |
| 1852 | |
| 1853 | copy_info(&info, |
| 1854 | "Host adapter:loop state = <%s>, flags = 0x%lx\n", |
| 1855 | loop_state , *flags); |
| 1856 | |
| 1857 | copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags); |
| 1858 | |
| 1859 | copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags); |
| 1860 | |
| 1861 | copy_info(&info, "Link down Timeout = %3.3d\n", |
| 1862 | ha->link_down_timeout); |
| 1863 | |
| 1864 | copy_info(&info, "Port down retry = %3.3d\n", |
| 1865 | ha->port_down_retry_count); |
| 1866 | |
| 1867 | copy_info(&info, "Login retry count = %3.3d\n", |
| 1868 | ha->login_retry_count); |
| 1869 | |
| 1870 | copy_info(&info, |
| 1871 | "Commands retried with dropped frame(s) = %d\n", |
| 1872 | ha->dropped_frame_error_cnt); |
| 1873 | |
| 1874 | copy_info(&info, |
| 1875 | "Product ID = %04x %04x %04x %04x\n", ha->product_id[0], |
| 1876 | ha->product_id[1], ha->product_id[2], ha->product_id[3]); |
| 1877 | |
| 1878 | copy_info(&info, "\n"); |
| 1879 | |
| 1880 | /* 2.25 node/port display to proc */ |
| 1881 | /* Display the node name for adapter */ |
| 1882 | copy_info(&info, "\nSCSI Device Information:\n"); |
| 1883 | copy_info(&info, |
| 1884 | "scsi-qla%d-adapter-node=" |
| 1885 | "%02x%02x%02x%02x%02x%02x%02x%02x;\n", |
| 1886 | (int)ha->instance, |
| 1887 | ha->init_cb->node_name[0], |
| 1888 | ha->init_cb->node_name[1], |
| 1889 | ha->init_cb->node_name[2], |
| 1890 | ha->init_cb->node_name[3], |
| 1891 | ha->init_cb->node_name[4], |
| 1892 | ha->init_cb->node_name[5], |
| 1893 | ha->init_cb->node_name[6], |
| 1894 | ha->init_cb->node_name[7]); |
| 1895 | |
| 1896 | /* display the port name for adapter */ |
| 1897 | copy_info(&info, |
| 1898 | "scsi-qla%d-adapter-port=" |
| 1899 | "%02x%02x%02x%02x%02x%02x%02x%02x;\n", |
| 1900 | (int)ha->instance, |
| 1901 | ha->init_cb->port_name[0], |
| 1902 | ha->init_cb->port_name[1], |
| 1903 | ha->init_cb->port_name[2], |
| 1904 | ha->init_cb->port_name[3], |
| 1905 | ha->init_cb->port_name[4], |
| 1906 | ha->init_cb->port_name[5], |
| 1907 | ha->init_cb->port_name[6], |
| 1908 | ha->init_cb->port_name[7]); |
| 1909 | |
| 1910 | /* Print out device port names */ |
| 1911 | for (t = 0; t < MAX_FIBRE_DEVICES; t++) { |
| 1912 | if ((tq = TGT_Q(ha, t)) == NULL) |
| 1913 | continue; |
| 1914 | |
| 1915 | copy_info(&info, |
| 1916 | "scsi-qla%d-target-%d=" |
| 1917 | "%02x%02x%02x%02x%02x%02x%02x%02x;\n", |
| 1918 | (int)ha->instance, t, |
| 1919 | tq->port_name[0], tq->port_name[1], |
| 1920 | tq->port_name[2], tq->port_name[3], |
| 1921 | tq->port_name[4], tq->port_name[5], |
| 1922 | tq->port_name[6], tq->port_name[7]); |
| 1923 | } |
| 1924 | |
| 1925 | copy_info(&info, "\nSCSI LUN Information:\n"); |
| 1926 | copy_info(&info, |
| 1927 | "(Id:Lun) * - indicates lun is not registered with the OS.\n"); |
| 1928 | |
| 1929 | /* scan for all equipment stats */ |
| 1930 | for (t = 0; t < MAX_FIBRE_DEVICES; t++) { |
| 1931 | /* scan all luns */ |
| 1932 | for (l = 0; l < ha->max_luns; l++) { |
| 1933 | up = (os_lun_t *) GET_LU_Q(ha, t, l); |
| 1934 | |
| 1935 | if (up == NULL) { |
| 1936 | continue; |
| 1937 | } |
| 1938 | if (up->fclun == NULL) { |
| 1939 | continue; |
| 1940 | } |
| 1941 | |
| 1942 | copy_info(&info, |
| 1943 | "(%2d:%2d): Total reqs %ld,", |
| 1944 | t,l,up->io_cnt); |
| 1945 | |
| 1946 | copy_info(&info, |
| 1947 | " Pending reqs %ld,", |
| 1948 | up->out_cnt); |
| 1949 | |
| 1950 | if (up->io_cnt < 4) { |
| 1951 | copy_info(&info, |
| 1952 | " flags 0x%x*,", |
| 1953 | (int)up->q_flag); |
| 1954 | } else { |
| 1955 | copy_info(&info, |
| 1956 | " flags 0x%x,", |
| 1957 | (int)up->q_flag); |
| 1958 | } |
| 1959 | |
| 1960 | copy_info(&info, |
| 1961 | " %ld:%d:%02x %02x", |
| 1962 | up->fclun->fcport->ha->instance, |
| 1963 | up->fclun->fcport->cur_path, |
| 1964 | up->fclun->fcport->loop_id, |
| 1965 | up->fclun->device_type); |
| 1966 | |
| 1967 | copy_info(&info, "\n"); |
| 1968 | |
| 1969 | if (info.pos >= info.offset + info.length) { |
| 1970 | /* No need to continue */ |
| 1971 | goto profile_stop; |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | if (info.pos >= info.offset + info.length) { |
| 1976 | /* No need to continue */ |
| 1977 | break; |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | profile_stop: |
| 1982 | |
| 1983 | retval = info.pos > info.offset ? info.pos - info.offset : 0; |
| 1984 | |
| 1985 | DEBUG3(printk(KERN_INFO |
| 1986 | "Exiting proc_info: info.pos=%d, offset=0x%lx, " |
| 1987 | "length=0x%x\n", info.pos, offset, length);) |
| 1988 | |
| 1989 | return (retval); |
| 1990 | } |
| 1991 | |
| 1992 | /* |
| 1993 | * qla2x00_display_fc_names |
| 1994 | * This routine will the node names of the different devices found |
| 1995 | * after port inquiry. |
| 1996 | * |
| 1997 | * Input: |
| 1998 | * cmd = SCSI command structure |
| 1999 | * |
| 2000 | * Returns: |
| 2001 | * None. |
| 2002 | */ |
| 2003 | static void |
| 2004 | qla2x00_display_fc_names(scsi_qla_host_t *ha) |
| 2005 | { |
| 2006 | uint16_t tgt; |
| 2007 | os_tgt_t *tq; |
| 2008 | |
| 2009 | /* Display the node name for adapter */ |
| 2010 | qla_printk(KERN_INFO, ha, |
| 2011 | "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n", |
| 2012 | (int)ha->instance, |
| 2013 | ha->init_cb->node_name[0], |
| 2014 | ha->init_cb->node_name[1], |
| 2015 | ha->init_cb->node_name[2], |
| 2016 | ha->init_cb->node_name[3], |
| 2017 | ha->init_cb->node_name[4], |
| 2018 | ha->init_cb->node_name[5], |
| 2019 | ha->init_cb->node_name[6], |
| 2020 | ha->init_cb->node_name[7]); |
| 2021 | |
| 2022 | /* display the port name for adapter */ |
| 2023 | qla_printk(KERN_INFO, ha, |
| 2024 | "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n", |
| 2025 | (int)ha->instance, |
| 2026 | ha->init_cb->port_name[0], |
| 2027 | ha->init_cb->port_name[1], |
| 2028 | ha->init_cb->port_name[2], |
| 2029 | ha->init_cb->port_name[3], |
| 2030 | ha->init_cb->port_name[4], |
| 2031 | ha->init_cb->port_name[5], |
| 2032 | ha->init_cb->port_name[6], |
| 2033 | ha->init_cb->port_name[7]); |
| 2034 | |
| 2035 | /* Print out device port names */ |
| 2036 | for (tgt = 0; tgt < MAX_TARGETS; tgt++) { |
| 2037 | if ((tq = ha->otgt[tgt]) == NULL) |
| 2038 | continue; |
| 2039 | |
| 2040 | if (tq->fcport == NULL) |
| 2041 | continue; |
| 2042 | |
| 2043 | switch (ha->binding_type) { |
| 2044 | case BIND_BY_PORT_NAME: |
| 2045 | qla_printk(KERN_INFO, ha, |
| 2046 | "scsi-qla%d-tgt-%d-di-0-port=" |
| 2047 | "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n", |
| 2048 | (int)ha->instance, |
| 2049 | tgt, |
| 2050 | tq->port_name[0], |
| 2051 | tq->port_name[1], |
| 2052 | tq->port_name[2], |
| 2053 | tq->port_name[3], |
| 2054 | tq->port_name[4], |
| 2055 | tq->port_name[5], |
| 2056 | tq->port_name[6], |
| 2057 | tq->port_name[7]); |
| 2058 | |
| 2059 | break; |
| 2060 | |
| 2061 | case BIND_BY_PORT_ID: |
| 2062 | qla_printk(KERN_INFO, ha, |
| 2063 | "scsi-qla%d-tgt-%d-di-0-pid=" |
| 2064 | "%02x%02x%02x\\;\n", |
| 2065 | (int)ha->instance, |
| 2066 | tgt, |
| 2067 | tq->d_id.b.domain, |
| 2068 | tq->d_id.b.area, |
| 2069 | tq->d_id.b.al_pa); |
| 2070 | break; |
| 2071 | } |
| 2072 | |
| 2073 | #if VSA |
| 2074 | qla_printk(KERN_INFO, ha, |
| 2075 | "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt); |
| 2076 | #endif |
| 2077 | } |
| 2078 | } |
| 2079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
| 2081 | /* |
| 2082 | * qla2x00_mark_device_lost Updates fcport state when device goes offline. |
| 2083 | * |
| 2084 | * Input: ha = adapter block pointer. fcport = port structure pointer. |
| 2085 | * |
| 2086 | * Return: None. |
| 2087 | * |
| 2088 | * Context: |
| 2089 | */ |
| 2090 | void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport, |
| 2091 | int do_login) |
| 2092 | { |
| 2093 | /* |
| 2094 | * We may need to retry the login, so don't change the state of the |
| 2095 | * port but do the retries. |
| 2096 | */ |
| 2097 | if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD) |
| 2098 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 2099 | |
| 2100 | if (!do_login) |
| 2101 | return; |
| 2102 | |
| 2103 | if (fcport->login_retry == 0) { |
| 2104 | fcport->login_retry = ha->login_retry_count; |
| 2105 | set_bit(RELOGIN_NEEDED, &ha->dpc_flags); |
| 2106 | |
| 2107 | DEBUG(printk("scsi(%ld): Port login retry: " |
| 2108 | "%02x%02x%02x%02x%02x%02x%02x%02x, " |
| 2109 | "id = 0x%04x retry cnt=%d\n", |
| 2110 | ha->host_no, |
| 2111 | fcport->port_name[0], |
| 2112 | fcport->port_name[1], |
| 2113 | fcport->port_name[2], |
| 2114 | fcport->port_name[3], |
| 2115 | fcport->port_name[4], |
| 2116 | fcport->port_name[5], |
| 2117 | fcport->port_name[6], |
| 2118 | fcport->port_name[7], |
| 2119 | fcport->loop_id, |
| 2120 | fcport->login_retry)); |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | /* |
| 2125 | * qla2x00_mark_all_devices_lost |
| 2126 | * Updates fcport state when device goes offline. |
| 2127 | * |
| 2128 | * Input: |
| 2129 | * ha = adapter block pointer. |
| 2130 | * fcport = port structure pointer. |
| 2131 | * |
| 2132 | * Return: |
| 2133 | * None. |
| 2134 | * |
| 2135 | * Context: |
| 2136 | */ |
| 2137 | void |
| 2138 | qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha) |
| 2139 | { |
| 2140 | fc_port_t *fcport; |
| 2141 | |
| 2142 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2143 | if (fcport->port_type != FCT_TARGET) |
| 2144 | continue; |
| 2145 | |
| 2146 | /* |
| 2147 | * No point in marking the device as lost, if the device is |
| 2148 | * already DEAD. |
| 2149 | */ |
| 2150 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) |
| 2151 | continue; |
| 2152 | |
| 2153 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | /* |
| 2158 | * qla2x00_mem_alloc |
| 2159 | * Allocates adapter memory. |
| 2160 | * |
| 2161 | * Returns: |
| 2162 | * 0 = success. |
| 2163 | * 1 = failure. |
| 2164 | */ |
| 2165 | static uint8_t |
| 2166 | qla2x00_mem_alloc(scsi_qla_host_t *ha) |
| 2167 | { |
| 2168 | char name[16]; |
| 2169 | uint8_t status = 1; |
| 2170 | int retry= 10; |
| 2171 | |
| 2172 | do { |
| 2173 | /* |
| 2174 | * This will loop only once if everything goes well, else some |
| 2175 | * number of retries will be performed to get around a kernel |
| 2176 | * bug where available mem is not allocated until after a |
| 2177 | * little delay and a retry. |
| 2178 | */ |
| 2179 | ha->request_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 2180 | (ha->request_q_length + 1) * sizeof(request_t), |
| 2181 | &ha->request_dma, GFP_KERNEL); |
| 2182 | if (ha->request_ring == NULL) { |
| 2183 | qla_printk(KERN_WARNING, ha, |
| 2184 | "Memory Allocation failed - request_ring\n"); |
| 2185 | |
| 2186 | qla2x00_mem_free(ha); |
| 2187 | msleep(100); |
| 2188 | |
| 2189 | continue; |
| 2190 | } |
| 2191 | |
| 2192 | ha->response_ring = dma_alloc_coherent(&ha->pdev->dev, |
| 2193 | (ha->response_q_length + 1) * sizeof(response_t), |
| 2194 | &ha->response_dma, GFP_KERNEL); |
| 2195 | if (ha->response_ring == NULL) { |
| 2196 | qla_printk(KERN_WARNING, ha, |
| 2197 | "Memory Allocation failed - response_ring\n"); |
| 2198 | |
| 2199 | qla2x00_mem_free(ha); |
| 2200 | msleep(100); |
| 2201 | |
| 2202 | continue; |
| 2203 | } |
| 2204 | |
| 2205 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE, |
| 2206 | &ha->gid_list_dma, GFP_KERNEL); |
| 2207 | if (ha->gid_list == NULL) { |
| 2208 | qla_printk(KERN_WARNING, ha, |
| 2209 | "Memory Allocation failed - gid_list\n"); |
| 2210 | |
| 2211 | qla2x00_mem_free(ha); |
| 2212 | msleep(100); |
| 2213 | |
| 2214 | continue; |
| 2215 | } |
| 2216 | |
| 2217 | ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev, |
| 2218 | sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL); |
| 2219 | if (ha->rlc_rsp == NULL) { |
| 2220 | qla_printk(KERN_WARNING, ha, |
| 2221 | "Memory Allocation failed - rlc"); |
| 2222 | |
| 2223 | qla2x00_mem_free(ha); |
| 2224 | msleep(100); |
| 2225 | |
| 2226 | continue; |
| 2227 | } |
| 2228 | |
| 2229 | snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no); |
| 2230 | ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, |
| 2231 | DMA_POOL_SIZE, 8, 0); |
| 2232 | if (ha->s_dma_pool == NULL) { |
| 2233 | qla_printk(KERN_WARNING, ha, |
| 2234 | "Memory Allocation failed - s_dma_pool\n"); |
| 2235 | |
| 2236 | qla2x00_mem_free(ha); |
| 2237 | msleep(100); |
| 2238 | |
| 2239 | continue; |
| 2240 | } |
| 2241 | |
| 2242 | /* get consistent memory allocated for init control block */ |
| 2243 | ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 2244 | &ha->init_cb_dma); |
| 2245 | if (ha->init_cb == NULL) { |
| 2246 | qla_printk(KERN_WARNING, ha, |
| 2247 | "Memory Allocation failed - init_cb\n"); |
| 2248 | |
| 2249 | qla2x00_mem_free(ha); |
| 2250 | msleep(100); |
| 2251 | |
| 2252 | continue; |
| 2253 | } |
| 2254 | memset(ha->init_cb, 0, sizeof(init_cb_t)); |
| 2255 | |
| 2256 | /* Get consistent memory allocated for Get Port Database cmd */ |
| 2257 | ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 2258 | &ha->iodesc_pd_dma); |
| 2259 | if (ha->iodesc_pd == NULL) { |
| 2260 | /* error */ |
| 2261 | qla_printk(KERN_WARNING, ha, |
| 2262 | "Memory Allocation failed - iodesc_pd\n"); |
| 2263 | |
| 2264 | qla2x00_mem_free(ha); |
| 2265 | msleep(100); |
| 2266 | |
| 2267 | continue; |
| 2268 | } |
| 2269 | memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE); |
| 2270 | |
| 2271 | /* Allocate ioctl related memory. */ |
| 2272 | if (qla2x00_alloc_ioctl_mem(ha)) { |
| 2273 | qla_printk(KERN_WARNING, ha, |
| 2274 | "Memory Allocation failed - ioctl_mem\n"); |
| 2275 | |
| 2276 | qla2x00_mem_free(ha); |
| 2277 | msleep(100); |
| 2278 | |
| 2279 | continue; |
| 2280 | } |
| 2281 | |
| 2282 | if (qla2x00_allocate_sp_pool(ha)) { |
| 2283 | qla_printk(KERN_WARNING, ha, |
| 2284 | "Memory Allocation failed - " |
| 2285 | "qla2x00_allocate_sp_pool()\n"); |
| 2286 | |
| 2287 | qla2x00_mem_free(ha); |
| 2288 | msleep(100); |
| 2289 | |
| 2290 | continue; |
| 2291 | } |
| 2292 | |
| 2293 | /* Allocate memory for SNS commands */ |
| 2294 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2295 | /* Get consistent memory allocated for SNS commands */ |
| 2296 | ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, |
| 2297 | sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, |
| 2298 | GFP_KERNEL); |
| 2299 | if (ha->sns_cmd == NULL) { |
| 2300 | /* error */ |
| 2301 | qla_printk(KERN_WARNING, ha, |
| 2302 | "Memory Allocation failed - sns_cmd\n"); |
| 2303 | |
| 2304 | qla2x00_mem_free(ha); |
| 2305 | msleep(100); |
| 2306 | |
| 2307 | continue; |
| 2308 | } |
| 2309 | memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt)); |
| 2310 | } else { |
| 2311 | /* Get consistent memory allocated for MS IOCB */ |
| 2312 | ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
| 2313 | &ha->ms_iocb_dma); |
| 2314 | if (ha->ms_iocb == NULL) { |
| 2315 | /* error */ |
| 2316 | qla_printk(KERN_WARNING, ha, |
| 2317 | "Memory Allocation failed - ms_iocb\n"); |
| 2318 | |
| 2319 | qla2x00_mem_free(ha); |
| 2320 | msleep(100); |
| 2321 | |
| 2322 | continue; |
| 2323 | } |
| 2324 | memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t)); |
| 2325 | |
| 2326 | /* |
| 2327 | * Get consistent memory allocated for CT SNS |
| 2328 | * commands |
| 2329 | */ |
| 2330 | ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, |
| 2331 | sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, |
| 2332 | GFP_KERNEL); |
| 2333 | if (ha->ct_sns == NULL) { |
| 2334 | /* error */ |
| 2335 | qla_printk(KERN_WARNING, ha, |
| 2336 | "Memory Allocation failed - ct_sns\n"); |
| 2337 | |
| 2338 | qla2x00_mem_free(ha); |
| 2339 | msleep(100); |
| 2340 | |
| 2341 | continue; |
| 2342 | } |
| 2343 | memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt)); |
| 2344 | } |
| 2345 | |
| 2346 | /* Done all allocations without any error. */ |
| 2347 | status = 0; |
| 2348 | |
| 2349 | } while (retry-- && status != 0); |
| 2350 | |
| 2351 | if (status) { |
| 2352 | printk(KERN_WARNING |
| 2353 | "%s(): **** FAILED ****\n", __func__); |
| 2354 | } |
| 2355 | |
| 2356 | return(status); |
| 2357 | } |
| 2358 | |
| 2359 | /* |
| 2360 | * qla2x00_mem_free |
| 2361 | * Frees all adapter allocated memory. |
| 2362 | * |
| 2363 | * Input: |
| 2364 | * ha = adapter block pointer. |
| 2365 | */ |
| 2366 | static void |
| 2367 | qla2x00_mem_free(scsi_qla_host_t *ha) |
| 2368 | { |
| 2369 | uint32_t t; |
| 2370 | struct list_head *fcpl, *fcptemp; |
| 2371 | fc_port_t *fcport; |
| 2372 | struct list_head *fcll, *fcltemp; |
| 2373 | fc_lun_t *fclun; |
| 2374 | unsigned long wtime;/* max wait time if mbx cmd is busy. */ |
| 2375 | |
| 2376 | if (ha == NULL) { |
| 2377 | /* error */ |
| 2378 | DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__)); |
| 2379 | return; |
| 2380 | } |
| 2381 | |
| 2382 | /* Free the target queues */ |
| 2383 | for (t = 0; t < MAX_TARGETS; t++) { |
| 2384 | qla2x00_tgt_free(ha, t); |
| 2385 | } |
| 2386 | |
| 2387 | /* Make sure all other threads are stopped. */ |
| 2388 | wtime = 60 * HZ; |
| 2389 | while (ha->dpc_wait && wtime) { |
| 2390 | set_current_state(TASK_INTERRUPTIBLE); |
| 2391 | wtime = schedule_timeout(wtime); |
| 2392 | } |
| 2393 | |
| 2394 | /* free ioctl memory */ |
| 2395 | qla2x00_free_ioctl_mem(ha); |
| 2396 | |
| 2397 | /* free sp pool */ |
| 2398 | qla2x00_free_sp_pool(ha); |
| 2399 | |
| 2400 | if (ha->sns_cmd) |
| 2401 | dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), |
| 2402 | ha->sns_cmd, ha->sns_cmd_dma); |
| 2403 | |
| 2404 | if (ha->ct_sns) |
| 2405 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), |
| 2406 | ha->ct_sns, ha->ct_sns_dma); |
| 2407 | |
| 2408 | if (ha->ms_iocb) |
| 2409 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); |
| 2410 | |
| 2411 | if (ha->iodesc_pd) |
| 2412 | dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma); |
| 2413 | |
| 2414 | if (ha->init_cb) |
| 2415 | dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma); |
| 2416 | |
| 2417 | if (ha->s_dma_pool) |
| 2418 | dma_pool_destroy(ha->s_dma_pool); |
| 2419 | |
| 2420 | if (ha->rlc_rsp) |
| 2421 | dma_free_coherent(&ha->pdev->dev, |
| 2422 | sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp, |
| 2423 | ha->rlc_rsp_dma); |
| 2424 | |
| 2425 | if (ha->gid_list) |
| 2426 | dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, |
| 2427 | ha->gid_list_dma); |
| 2428 | |
| 2429 | if (ha->response_ring) |
| 2430 | dma_free_coherent(&ha->pdev->dev, |
| 2431 | (ha->response_q_length + 1) * sizeof(response_t), |
| 2432 | ha->response_ring, ha->response_dma); |
| 2433 | |
| 2434 | if (ha->request_ring) |
| 2435 | dma_free_coherent(&ha->pdev->dev, |
| 2436 | (ha->request_q_length + 1) * sizeof(request_t), |
| 2437 | ha->request_ring, ha->request_dma); |
| 2438 | |
| 2439 | ha->sns_cmd = NULL; |
| 2440 | ha->sns_cmd_dma = 0; |
| 2441 | ha->ct_sns = NULL; |
| 2442 | ha->ct_sns_dma = 0; |
| 2443 | ha->ms_iocb = NULL; |
| 2444 | ha->ms_iocb_dma = 0; |
| 2445 | ha->iodesc_pd = NULL; |
| 2446 | ha->iodesc_pd_dma = 0; |
| 2447 | ha->init_cb = NULL; |
| 2448 | ha->init_cb_dma = 0; |
| 2449 | |
| 2450 | ha->s_dma_pool = NULL; |
| 2451 | |
| 2452 | ha->rlc_rsp = NULL; |
| 2453 | ha->rlc_rsp_dma = 0; |
| 2454 | ha->gid_list = NULL; |
| 2455 | ha->gid_list_dma = 0; |
| 2456 | |
| 2457 | ha->response_ring = NULL; |
| 2458 | ha->response_dma = 0; |
| 2459 | ha->request_ring = NULL; |
| 2460 | ha->request_dma = 0; |
| 2461 | |
| 2462 | list_for_each_safe(fcpl, fcptemp, &ha->fcports) { |
| 2463 | fcport = list_entry(fcpl, fc_port_t, list); |
| 2464 | |
| 2465 | /* fc luns */ |
| 2466 | list_for_each_safe(fcll, fcltemp, &fcport->fcluns) { |
| 2467 | fclun = list_entry(fcll, fc_lun_t, list); |
| 2468 | |
| 2469 | list_del_init(&fclun->list); |
| 2470 | kfree(fclun); |
| 2471 | } |
| 2472 | |
| 2473 | /* fc ports */ |
| 2474 | list_del_init(&fcport->list); |
| 2475 | kfree(fcport); |
| 2476 | } |
| 2477 | INIT_LIST_HEAD(&ha->fcports); |
| 2478 | |
| 2479 | if (ha->fw_dump) |
| 2480 | free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order); |
| 2481 | |
| 2482 | if (ha->fw_dump_buffer) |
| 2483 | vfree(ha->fw_dump_buffer); |
| 2484 | |
| 2485 | ha->fw_dump = NULL; |
| 2486 | ha->fw_dump_reading = 0; |
| 2487 | ha->fw_dump_buffer = NULL; |
| 2488 | } |
| 2489 | |
| 2490 | /* |
| 2491 | * qla2x00_allocate_sp_pool |
| 2492 | * This routine is called during initialization to allocate |
| 2493 | * memory for local srb_t. |
| 2494 | * |
| 2495 | * Input: |
| 2496 | * ha = adapter block pointer. |
| 2497 | * |
| 2498 | * Context: |
| 2499 | * Kernel context. |
| 2500 | * |
| 2501 | * Note: Sets the ref_count for non Null sp to one. |
| 2502 | */ |
| 2503 | static int |
| 2504 | qla2x00_allocate_sp_pool(scsi_qla_host_t *ha) |
| 2505 | { |
| 2506 | int rval; |
| 2507 | |
| 2508 | rval = QLA_SUCCESS; |
| 2509 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 2510 | mempool_free_slab, srb_cachep); |
| 2511 | if (ha->srb_mempool == NULL) { |
| 2512 | qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n"); |
| 2513 | rval = QLA_FUNCTION_FAILED; |
| 2514 | } |
| 2515 | return (rval); |
| 2516 | } |
| 2517 | |
| 2518 | /* |
| 2519 | * This routine frees all adapter allocated memory. |
| 2520 | * |
| 2521 | */ |
| 2522 | static void |
| 2523 | qla2x00_free_sp_pool( scsi_qla_host_t *ha) |
| 2524 | { |
| 2525 | if (ha->srb_mempool) { |
| 2526 | mempool_destroy(ha->srb_mempool); |
| 2527 | ha->srb_mempool = NULL; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | /************************************************************************** |
| 2532 | * qla2x00_do_dpc |
| 2533 | * This kernel thread is a task that is schedule by the interrupt handler |
| 2534 | * to perform the background processing for interrupts. |
| 2535 | * |
| 2536 | * Notes: |
| 2537 | * This task always run in the context of a kernel thread. It |
| 2538 | * is kick-off by the driver's detect code and starts up |
| 2539 | * up one per adapter. It immediately goes to sleep and waits for |
| 2540 | * some fibre event. When either the interrupt handler or |
| 2541 | * the timer routine detects a event it will one of the task |
| 2542 | * bits then wake us up. |
| 2543 | **************************************************************************/ |
| 2544 | static int |
| 2545 | qla2x00_do_dpc(void *data) |
| 2546 | { |
| 2547 | DECLARE_MUTEX_LOCKED(sem); |
| 2548 | scsi_qla_host_t *ha; |
| 2549 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | uint8_t status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | uint16_t next_loopid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | |
| 2553 | ha = (scsi_qla_host_t *)data; |
| 2554 | |
| 2555 | lock_kernel(); |
| 2556 | |
| 2557 | daemonize("%s_dpc", ha->host_str); |
| 2558 | allow_signal(SIGHUP); |
| 2559 | |
| 2560 | ha->dpc_wait = &sem; |
| 2561 | |
| 2562 | set_user_nice(current, -20); |
| 2563 | |
| 2564 | unlock_kernel(); |
| 2565 | |
| 2566 | complete(&ha->dpc_inited); |
| 2567 | |
| 2568 | while (1) { |
| 2569 | DEBUG3(printk("qla2x00: DPC handler sleeping\n")); |
| 2570 | |
| 2571 | if (down_interruptible(&sem)) |
| 2572 | break; |
| 2573 | |
| 2574 | if (ha->dpc_should_die) |
| 2575 | break; |
| 2576 | |
| 2577 | DEBUG3(printk("qla2x00: DPC handler waking up\n")); |
| 2578 | |
| 2579 | /* Initialization not yet finished. Don't do anything yet. */ |
| 2580 | if (!ha->flags.init_done || ha->dpc_active) |
| 2581 | continue; |
| 2582 | |
| 2583 | DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no)); |
| 2584 | |
| 2585 | ha->dpc_active = 1; |
| 2586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | if (ha->flags.mbox_busy) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | ha->dpc_active = 0; |
| 2589 | continue; |
| 2590 | } |
| 2591 | |
| 2592 | if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) { |
| 2593 | |
| 2594 | DEBUG(printk("scsi(%ld): dpc: sched " |
| 2595 | "qla2x00_abort_isp ha = %p\n", |
| 2596 | ha->host_no, ha)); |
| 2597 | if (!(test_and_set_bit(ABORT_ISP_ACTIVE, |
| 2598 | &ha->dpc_flags))) { |
| 2599 | |
| 2600 | if (qla2x00_abort_isp(ha)) { |
| 2601 | /* failed. retry later */ |
| 2602 | set_bit(ISP_ABORT_NEEDED, |
| 2603 | &ha->dpc_flags); |
| 2604 | } |
| 2605 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); |
| 2606 | } |
| 2607 | DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", |
| 2608 | ha->host_no)); |
| 2609 | } |
| 2610 | |
| 2611 | if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) && |
| 2612 | (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) { |
| 2613 | |
| 2614 | DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n", |
| 2615 | ha->host_no)); |
| 2616 | |
| 2617 | qla2x00_rst_aen(ha); |
| 2618 | clear_bit(RESET_ACTIVE, &ha->dpc_flags); |
| 2619 | } |
| 2620 | |
| 2621 | /* Retry each device up to login retry count */ |
| 2622 | if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) && |
| 2623 | !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) && |
| 2624 | atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 2625 | |
| 2626 | DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", |
| 2627 | ha->host_no)); |
| 2628 | |
| 2629 | next_loopid = 0; |
| 2630 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2631 | if (fcport->port_type != FCT_TARGET) |
| 2632 | continue; |
| 2633 | |
| 2634 | /* |
| 2635 | * If the port is not ONLINE then try to login |
| 2636 | * to it if we haven't run out of retries. |
| 2637 | */ |
| 2638 | if (atomic_read(&fcport->state) != FCS_ONLINE && |
| 2639 | fcport->login_retry) { |
| 2640 | |
| 2641 | fcport->login_retry--; |
| 2642 | if (fcport->flags & FCF_FABRIC_DEVICE) { |
| 2643 | if (fcport->flags & |
| 2644 | FCF_TAPE_PRESENT) |
| 2645 | qla2x00_fabric_logout( |
| 2646 | ha, |
| 2647 | fcport->loop_id); |
| 2648 | status = qla2x00_fabric_login( |
| 2649 | ha, fcport, &next_loopid); |
| 2650 | } else |
| 2651 | status = |
| 2652 | qla2x00_local_device_login( |
| 2653 | ha, fcport->loop_id); |
| 2654 | |
| 2655 | if (status == QLA_SUCCESS) { |
| 2656 | fcport->old_loop_id = fcport->loop_id; |
| 2657 | |
| 2658 | DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n", |
| 2659 | ha->host_no, fcport->loop_id)); |
| 2660 | |
| 2661 | fcport->port_login_retry_count = |
| 2662 | ha->port_down_retry_count * PORT_RETRY_TIME; |
| 2663 | atomic_set(&fcport->state, FCS_ONLINE); |
| 2664 | atomic_set(&fcport->port_down_timer, |
| 2665 | ha->port_down_retry_count * PORT_RETRY_TIME); |
| 2666 | |
| 2667 | fcport->login_retry = 0; |
| 2668 | } else if (status == 1) { |
| 2669 | set_bit(RELOGIN_NEEDED, &ha->dpc_flags); |
| 2670 | /* retry the login again */ |
| 2671 | DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n", |
| 2672 | ha->host_no, |
| 2673 | fcport->login_retry, fcport->loop_id)); |
| 2674 | } else { |
| 2675 | fcport->login_retry = 0; |
| 2676 | } |
| 2677 | } |
| 2678 | if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) |
| 2679 | break; |
| 2680 | } |
| 2681 | DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", |
| 2682 | ha->host_no)); |
| 2683 | } |
| 2684 | |
| 2685 | if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) && |
| 2686 | atomic_read(&ha->loop_state) != LOOP_DOWN) { |
| 2687 | |
| 2688 | clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags); |
| 2689 | DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n", |
| 2690 | ha->host_no)); |
| 2691 | |
| 2692 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 2693 | |
| 2694 | DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n", |
| 2695 | ha->host_no)); |
| 2696 | } |
| 2697 | |
| 2698 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { |
| 2699 | |
| 2700 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n", |
| 2701 | ha->host_no)); |
| 2702 | |
| 2703 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, |
| 2704 | &ha->dpc_flags))) { |
| 2705 | |
| 2706 | qla2x00_loop_resync(ha); |
| 2707 | |
| 2708 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 2709 | } |
| 2710 | |
| 2711 | DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n", |
| 2712 | ha->host_no)); |
| 2713 | } |
| 2714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) { |
| 2716 | |
| 2717 | DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n", |
| 2718 | ha->host_no)); |
| 2719 | |
| 2720 | qla2x00_rescan_fcports(ha); |
| 2721 | |
| 2722 | DEBUG(printk("scsi(%ld): Rescan flagged fcports..." |
| 2723 | "end.\n", |
| 2724 | ha->host_no)); |
| 2725 | } |
| 2726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | if (!ha->interrupts_on) |
| 2728 | qla2x00_enable_intrs(ha); |
| 2729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | ha->dpc_active = 0; |
| 2731 | } /* End of while(1) */ |
| 2732 | |
| 2733 | DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no)); |
| 2734 | |
| 2735 | /* |
| 2736 | * Make sure that nobody tries to wake us up again. |
| 2737 | */ |
| 2738 | ha->dpc_wait = NULL; |
| 2739 | ha->dpc_active = 0; |
| 2740 | |
| 2741 | complete_and_exit(&ha->dpc_exited, 0); |
| 2742 | } |
| 2743 | |
| 2744 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | * qla2x00_rst_aen |
| 2746 | * Processes asynchronous reset. |
| 2747 | * |
| 2748 | * Input: |
| 2749 | * ha = adapter block pointer. |
| 2750 | */ |
| 2751 | static void |
| 2752 | qla2x00_rst_aen(scsi_qla_host_t *ha) |
| 2753 | { |
| 2754 | if (ha->flags.online && !ha->flags.reset_active && |
| 2755 | !atomic_read(&ha->loop_down_timer) && |
| 2756 | !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) { |
| 2757 | do { |
| 2758 | clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); |
| 2759 | |
| 2760 | /* |
| 2761 | * Issue marker command only when we are going to start |
| 2762 | * the I/O. |
| 2763 | */ |
| 2764 | ha->marker_needed = 1; |
| 2765 | } while (!atomic_read(&ha->loop_down_timer) && |
| 2766 | (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags))); |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | |
| 2771 | /* |
| 2772 | * This routine will allocate SP from the free queue |
| 2773 | * input: |
| 2774 | * scsi_qla_host_t * |
| 2775 | * output: |
| 2776 | * srb_t * or NULL |
| 2777 | */ |
| 2778 | static srb_t * |
| 2779 | qla2x00_get_new_sp(scsi_qla_host_t *ha) |
| 2780 | { |
| 2781 | srb_t *sp; |
| 2782 | |
| 2783 | sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 2784 | if (sp) |
| 2785 | atomic_set(&sp->ref_count, 1); |
| 2786 | return (sp); |
| 2787 | } |
| 2788 | |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 2789 | static void |
| 2790 | qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp) |
| 2791 | { |
| 2792 | struct scsi_cmnd *cmd = sp->cmd; |
| 2793 | |
| 2794 | if (sp->flags & SRB_DMA_VALID) { |
| 2795 | if (cmd->use_sg) { |
| 2796 | dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer, |
| 2797 | cmd->use_sg, cmd->sc_data_direction); |
| 2798 | } else if (cmd->request_bufflen) { |
| 2799 | dma_unmap_single(&ha->pdev->dev, sp->dma_handle, |
| 2800 | cmd->request_bufflen, cmd->sc_data_direction); |
| 2801 | } |
| 2802 | sp->flags &= ~SRB_DMA_VALID; |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | void |
| 2807 | qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp) |
| 2808 | { |
| 2809 | struct scsi_cmnd *cmd = sp->cmd; |
| 2810 | |
| 2811 | qla2x00_sp_free_dma(ha, sp); |
| 2812 | |
| 2813 | CMD_SP(cmd) = NULL; |
| 2814 | mempool_free(sp, ha->srb_mempool); |
| 2815 | |
| 2816 | cmd->scsi_done(cmd); |
| 2817 | } |
| 2818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | /************************************************************************** |
| 2820 | * qla2x00_timer |
| 2821 | * |
| 2822 | * Description: |
| 2823 | * One second timer |
| 2824 | * |
| 2825 | * Context: Interrupt |
| 2826 | ***************************************************************************/ |
| 2827 | static void |
| 2828 | qla2x00_timer(scsi_qla_host_t *ha) |
| 2829 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | unsigned long cpu_flags = 0; |
| 2831 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | int start_dpc = 0; |
| 2833 | int index; |
| 2834 | srb_t *sp; |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 2835 | int t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | |
| 2837 | /* |
| 2838 | * Ports - Port down timer. |
| 2839 | * |
| 2840 | * Whenever, a port is in the LOST state we start decrementing its port |
| 2841 | * down timer every second until it reaches zero. Once it reaches zero |
| 2842 | * the port it marked DEAD. |
| 2843 | */ |
| 2844 | t = 0; |
| 2845 | list_for_each_entry(fcport, &ha->fcports, list) { |
| 2846 | if (fcport->port_type != FCT_TARGET) |
| 2847 | continue; |
| 2848 | |
| 2849 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
| 2850 | |
| 2851 | if (atomic_read(&fcport->port_down_timer) == 0) |
| 2852 | continue; |
| 2853 | |
| 2854 | if (atomic_dec_and_test(&fcport->port_down_timer) != 0) |
| 2855 | atomic_set(&fcport->state, FCS_DEVICE_DEAD); |
| 2856 | |
| 2857 | DEBUG(printk("scsi(%ld): fcport-%d - port retry count: " |
| 2858 | "%d remainning\n", |
| 2859 | ha->host_no, |
| 2860 | t, atomic_read(&fcport->port_down_timer))); |
| 2861 | } |
| 2862 | t++; |
| 2863 | } /* End of for fcport */ |
| 2864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | |
| 2866 | /* Loop down handler. */ |
| 2867 | if (atomic_read(&ha->loop_down_timer) > 0 && |
| 2868 | !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) { |
| 2869 | |
| 2870 | if (atomic_read(&ha->loop_down_timer) == |
| 2871 | ha->loop_down_abort_time) { |
| 2872 | |
| 2873 | DEBUG(printk("scsi(%ld): Loop Down - aborting the " |
| 2874 | "queues before time expire\n", |
| 2875 | ha->host_no)); |
| 2876 | |
| 2877 | if (!IS_QLA2100(ha) && ha->link_down_timeout) |
| 2878 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 2879 | |
| 2880 | /* Schedule an ISP abort to return any tape commands. */ |
| 2881 | spin_lock_irqsave(&ha->hardware_lock, cpu_flags); |
| 2882 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; |
| 2883 | index++) { |
| 2884 | sp = ha->outstanding_cmds[index]; |
| 2885 | if (!sp) |
| 2886 | continue; |
| 2887 | if (!(sp->fclun->fcport->flags & |
| 2888 | FCF_TAPE_PRESENT)) |
| 2889 | continue; |
| 2890 | |
| 2891 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 2892 | break; |
| 2893 | } |
| 2894 | spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags); |
| 2895 | |
| 2896 | set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags); |
| 2897 | start_dpc++; |
| 2898 | } |
| 2899 | |
| 2900 | /* if the loop has been down for 4 minutes, reinit adapter */ |
| 2901 | if (atomic_dec_and_test(&ha->loop_down_timer) != 0) { |
| 2902 | DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - " |
| 2903 | "restarting queues.\n", |
| 2904 | ha->host_no)); |
| 2905 | |
| 2906 | set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags); |
| 2907 | start_dpc++; |
| 2908 | |
| 2909 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 2910 | DEBUG(printk("scsi(%ld): Loop down - " |
| 2911 | "aborting ISP.\n", |
| 2912 | ha->host_no)); |
| 2913 | qla_printk(KERN_WARNING, ha, |
| 2914 | "Loop down - aborting ISP.\n"); |
| 2915 | |
| 2916 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); |
| 2917 | } |
| 2918 | } |
| 2919 | DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n", |
| 2920 | ha->host_no, |
| 2921 | atomic_read(&ha->loop_down_timer))); |
| 2922 | } |
| 2923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | /* Schedule the DPC routine if needed */ |
| 2925 | if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) || |
| 2926 | test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) || |
| 2927 | start_dpc || |
| 2928 | test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) || |
| f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame^] | 2929 | test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) && |
| 2931 | ha->dpc_wait && !ha->dpc_active) { |
| 2932 | |
| 2933 | up(ha->dpc_wait); |
| 2934 | } |
| 2935 | |
| 2936 | qla2x00_restart_timer(ha, WATCH_INTERVAL); |
| 2937 | } |
| 2938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | /* XXX(hch): crude hack to emulate a down_timeout() */ |
| 2940 | int |
| 2941 | qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout) |
| 2942 | { |
| 2943 | const unsigned int step = HZ/10; |
| 2944 | |
| 2945 | do { |
| 2946 | if (!down_trylock(sema)) |
| 2947 | return 0; |
| 2948 | set_current_state(TASK_INTERRUPTIBLE); |
| 2949 | if (schedule_timeout(step)) |
| 2950 | break; |
| 2951 | } while ((timeout -= step) > 0); |
| 2952 | |
| 2953 | return -ETIMEDOUT; |
| 2954 | } |
| 2955 | |
| 2956 | static void |
| 2957 | qla2xxx_get_port_id(struct scsi_target *starget) |
| 2958 | { |
| 2959 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2960 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 2961 | struct fc_port *fc; |
| 2962 | |
| 2963 | list_for_each_entry(fc, &ha->fcports, list) { |
| 2964 | if (fc->os_target_id == starget->id) { |
| 2965 | fc_starget_port_id(starget) = fc->d_id.b.domain << 16 | |
| 2966 | fc->d_id.b.area << 8 | |
| 2967 | fc->d_id.b.al_pa; |
| 2968 | return; |
| 2969 | } |
| 2970 | } |
| 2971 | fc_starget_port_id(starget) = -1; |
| 2972 | } |
| 2973 | |
| 2974 | static void |
| 2975 | qla2xxx_get_port_name(struct scsi_target *starget) |
| 2976 | { |
| 2977 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2978 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 2979 | struct fc_port *fc; |
| 2980 | |
| 2981 | list_for_each_entry(fc, &ha->fcports, list) { |
| 2982 | if (fc->os_target_id == starget->id) { |
| 2983 | fc_starget_port_name(starget) = |
| 2984 | __be64_to_cpu(*(uint64_t *)fc->port_name); |
| 2985 | return; |
| 2986 | } |
| 2987 | } |
| 2988 | fc_starget_port_name(starget) = -1; |
| 2989 | } |
| 2990 | |
| 2991 | static void |
| 2992 | qla2xxx_get_node_name(struct scsi_target *starget) |
| 2993 | { |
| 2994 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
| 2995 | scsi_qla_host_t *ha = to_qla_host(shost); |
| 2996 | struct fc_port *fc; |
| 2997 | |
| 2998 | list_for_each_entry(fc, &ha->fcports, list) { |
| 2999 | if (fc->os_target_id == starget->id) { |
| 3000 | fc_starget_node_name(starget) = |
| 3001 | __be64_to_cpu(*(uint64_t *)fc->node_name); |
| 3002 | return; |
| 3003 | } |
| 3004 | } |
| 3005 | fc_starget_node_name(starget) = -1; |
| 3006 | } |
| 3007 | |
| 3008 | static struct fc_function_template qla2xxx_transport_functions = { |
| 3009 | .get_starget_port_id = qla2xxx_get_port_id, |
| 3010 | .show_starget_port_id = 1, |
| 3011 | .get_starget_port_name = qla2xxx_get_port_name, |
| 3012 | .show_starget_port_name = 1, |
| 3013 | .get_starget_node_name = qla2xxx_get_node_name, |
| 3014 | .show_starget_node_name = 1, |
| 3015 | }; |
| 3016 | |
| 3017 | /** |
| 3018 | * qla2x00_module_init - Module initialization. |
| 3019 | **/ |
| 3020 | static int __init |
| 3021 | qla2x00_module_init(void) |
| 3022 | { |
| 3023 | /* Allocate cache for SRBs. */ |
| 3024 | sprintf(srb_cachep_name, "qla2xxx_srbs"); |
| 3025 | srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0, |
| 3026 | SLAB_HWCACHE_ALIGN, NULL, NULL); |
| 3027 | if (srb_cachep == NULL) { |
| 3028 | printk(KERN_ERR |
| 3029 | "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); |
| 3030 | return -ENOMEM; |
| 3031 | } |
| 3032 | |
| 3033 | /* Derive version string. */ |
| 3034 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); |
| 3035 | #if DEBUG_QLA2100 |
| 3036 | strcat(qla2x00_version_str, "-debug"); |
| 3037 | #endif |
| 3038 | |
| 3039 | qla2xxx_transport_template = fc_attach_transport(&qla2xxx_transport_functions); |
| 3040 | if (!qla2xxx_transport_template) |
| 3041 | return -ENODEV; |
| 3042 | |
| 3043 | printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n"); |
| 3044 | return 0; |
| 3045 | } |
| 3046 | |
| 3047 | /** |
| 3048 | * qla2x00_module_exit - Module cleanup. |
| 3049 | **/ |
| 3050 | static void __exit |
| 3051 | qla2x00_module_exit(void) |
| 3052 | { |
| 3053 | /* Free SRBs cache. */ |
| 3054 | if (srb_cachep != NULL) { |
| 3055 | if (kmem_cache_destroy(srb_cachep) != 0) { |
| 3056 | printk(KERN_ERR |
| 3057 | "qla2xxx: Unable to free SRB cache...Memory pools " |
| 3058 | "still active?\n"); |
| 3059 | } |
| 3060 | srb_cachep = NULL; |
| 3061 | } |
| 3062 | |
| 3063 | fc_release_transport(qla2xxx_transport_template); |
| 3064 | } |
| 3065 | |
| 3066 | module_init(qla2x00_module_init); |
| 3067 | module_exit(qla2x00_module_exit); |
| 3068 | |
| 3069 | MODULE_AUTHOR("QLogic Corporation"); |
| 3070 | MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver"); |
| 3071 | MODULE_LICENSE("GPL"); |
| 3072 | MODULE_VERSION(QLA2XXX_VERSION); |