David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
| 3 | * Copyright (c) 2003-2006 QLogic Corporation |
| 4 | * |
| 5 | * See LICENSE.qla4xxx for copyright and licensing details. |
| 6 | */ |
| 7 | #include <linux/moduleparam.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9 | |
| 10 | #include <scsi/scsi_tcq.h> |
| 11 | #include <scsi/scsicam.h> |
| 12 | |
| 13 | #include "ql4_def.h" |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 14 | #include "ql4_version.h" |
| 15 | #include "ql4_glbl.h" |
| 16 | #include "ql4_dbg.h" |
| 17 | #include "ql4_inline.h" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Driver version |
| 21 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 22 | static char qla4xxx_version_str[40]; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * SRB allocation cache |
| 26 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 27 | static struct kmem_cache *srb_cachep; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Module parameter information and variables |
| 31 | */ |
| 32 | int ql4xdiscoverywait = 60; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 33 | module_param(ql4xdiscoverywait, int, S_IRUGO | S_IWUSR); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 34 | MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time"); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 35 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 36 | int ql4xdontresethba = 0; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 37 | module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 38 | MODULE_PARM_DESC(ql4xdontresethba, |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 39 | "Don't reset the HBA for driver recovery \n" |
| 40 | " 0 - It will reset HBA (Default)\n" |
| 41 | " 1 - It will NOT reset HBA"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 42 | |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 43 | int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 44 | module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 45 | MODULE_PARM_DESC(ql4xextended_error_logging, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 46 | "Option to enable extended error logging, " |
| 47 | "Default is 0 - no logging, 1 - debug logging"); |
| 48 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 49 | int ql4xenablemsix = 1; |
| 50 | module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR); |
| 51 | MODULE_PARM_DESC(ql4xenablemsix, |
| 52 | "Set to enable MSI or MSI-X interrupt mechanism.\n" |
| 53 | " 0 = enable INTx interrupt mechanism.\n" |
| 54 | " 1 = enable MSI-X interrupt mechanism (Default).\n" |
| 55 | " 2 = enable MSI interrupt mechanism."); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 56 | |
Mike Christie | d510d96 | 2008-07-11 19:50:33 -0500 | [diff] [blame] | 57 | #define QL4_DEF_QDEPTH 32 |
| 58 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 59 | /* |
| 60 | * SCSI host template entry points |
| 61 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 62 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * iSCSI template entry points |
| 66 | */ |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 67 | static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost, |
| 68 | enum iscsi_tgt_dscvr type, uint32_t enable, |
| 69 | struct sockaddr *dst_addr); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 70 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
| 71 | enum iscsi_param param, char *buf); |
| 72 | static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess, |
| 73 | enum iscsi_param param, char *buf); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 74 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 75 | enum iscsi_host_param param, char *buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 76 | static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 77 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * SCSI host template entry points |
| 81 | */ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 82 | static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 83 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 84 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 85 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 86 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); |
| 87 | static int qla4xxx_slave_alloc(struct scsi_device *device); |
| 88 | static int qla4xxx_slave_configure(struct scsi_device *device); |
| 89 | static void qla4xxx_slave_destroy(struct scsi_device *sdev); |
Mike Christie | 024f801 | 2008-03-04 13:26:54 -0600 | [diff] [blame] | 90 | static void qla4xxx_scan_start(struct Scsi_Host *shost); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 91 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 92 | static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
| 93 | QLA82XX_LEGACY_INTR_CONFIG; |
| 94 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 95 | static struct scsi_host_template qla4xxx_driver_template = { |
| 96 | .module = THIS_MODULE, |
| 97 | .name = DRIVER_NAME, |
| 98 | .proc_name = DRIVER_NAME, |
| 99 | .queuecommand = qla4xxx_queuecommand, |
| 100 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 101 | .eh_abort_handler = qla4xxx_eh_abort, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 102 | .eh_device_reset_handler = qla4xxx_eh_device_reset, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 103 | .eh_target_reset_handler = qla4xxx_eh_target_reset, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 104 | .eh_host_reset_handler = qla4xxx_eh_host_reset, |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 105 | .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 106 | |
| 107 | .slave_configure = qla4xxx_slave_configure, |
| 108 | .slave_alloc = qla4xxx_slave_alloc, |
| 109 | .slave_destroy = qla4xxx_slave_destroy, |
| 110 | |
Mike Christie | 921601b | 2008-01-31 13:36:49 -0600 | [diff] [blame] | 111 | .scan_finished = iscsi_scan_finished, |
Mike Christie | 024f801 | 2008-03-04 13:26:54 -0600 | [diff] [blame] | 112 | .scan_start = qla4xxx_scan_start, |
Mike Christie | 921601b | 2008-01-31 13:36:49 -0600 | [diff] [blame] | 113 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 114 | .this_id = -1, |
| 115 | .cmd_per_lun = 3, |
| 116 | .use_clustering = ENABLE_CLUSTERING, |
| 117 | .sg_tablesize = SG_ALL, |
| 118 | |
| 119 | .max_sectors = 0xFFFF, |
| 120 | }; |
| 121 | |
| 122 | static struct iscsi_transport qla4xxx_iscsi_transport = { |
| 123 | .owner = THIS_MODULE, |
| 124 | .name = DRIVER_NAME, |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 125 | .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD | |
| 126 | CAP_DATA_PATH_OFFLOAD, |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 127 | .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS | |
Vikas Chaudhary | 3b2bef1 | 2010-07-10 14:51:30 +0530 | [diff] [blame] | 128 | ISCSI_TARGET_NAME | ISCSI_TPGT | |
| 129 | ISCSI_TARGET_ALIAS, |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 130 | .host_param_mask = ISCSI_HOST_HWADDRESS | |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 131 | ISCSI_HOST_IPADDRESS | |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 132 | ISCSI_HOST_INITIATOR_NAME, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 133 | .tgt_dscvr = qla4xxx_tgt_dscvr, |
| 134 | .get_conn_param = qla4xxx_conn_get_param, |
| 135 | .get_session_param = qla4xxx_sess_get_param, |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 136 | .get_host_param = qla4xxx_host_get_param, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 137 | .session_recovery_timedout = qla4xxx_recovery_timedout, |
| 138 | }; |
| 139 | |
| 140 | static struct scsi_transport_template *qla4xxx_scsi_transport; |
| 141 | |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 142 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| 143 | { |
| 144 | struct iscsi_cls_session *session; |
| 145 | struct ddb_entry *ddb_entry; |
| 146 | |
| 147 | session = starget_to_session(scsi_target(sc->device)); |
| 148 | ddb_entry = session->dd_data; |
| 149 | |
| 150 | /* if we are not logged in then the LLD is going to clean up the cmd */ |
| 151 | if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) |
| 152 | return BLK_EH_RESET_TIMER; |
| 153 | else |
| 154 | return BLK_EH_NOT_HANDLED; |
| 155 | } |
| 156 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 157 | static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session) |
| 158 | { |
| 159 | struct ddb_entry *ddb_entry = session->dd_data; |
| 160 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 161 | |
Mike Christie | 568d303 | 2008-01-31 13:36:47 -0600 | [diff] [blame] | 162 | if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { |
| 163 | atomic_set(&ddb_entry->state, DDB_STATE_DEAD); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 164 | |
Vikas Chaudhary | 3013cea | 2010-07-30 14:25:46 +0530 | [diff] [blame] | 165 | DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout " |
Mike Christie | 568d303 | 2008-01-31 13:36:47 -0600 | [diff] [blame] | 166 | "of (%d) secs exhausted, marking device DEAD.\n", |
| 167 | ha->host_no, __func__, ddb_entry->fw_ddb_index, |
Vikas Chaudhary | 3013cea | 2010-07-30 14:25:46 +0530 | [diff] [blame] | 168 | QL4_SESS_RECOVERY_TMO)); |
Mike Christie | 568d303 | 2008-01-31 13:36:47 -0600 | [diff] [blame] | 169 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 172 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 173 | enum iscsi_host_param param, char *buf) |
| 174 | { |
| 175 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 176 | int len; |
| 177 | |
| 178 | switch (param) { |
| 179 | case ISCSI_HOST_PARAM_HWADDRESS: |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 180 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 181 | break; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 182 | case ISCSI_HOST_PARAM_IPADDRESS: |
| 183 | len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0], |
| 184 | ha->ip_address[1], ha->ip_address[2], |
| 185 | ha->ip_address[3]); |
| 186 | break; |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 187 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 188 | len = sprintf(buf, "%s\n", ha->name_string); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 189 | break; |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 190 | default: |
| 191 | return -ENOSYS; |
| 192 | } |
| 193 | |
| 194 | return len; |
| 195 | } |
| 196 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 197 | static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess, |
| 198 | enum iscsi_param param, char *buf) |
| 199 | { |
| 200 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 201 | int len; |
| 202 | |
| 203 | switch (param) { |
| 204 | case ISCSI_PARAM_TARGET_NAME: |
| 205 | len = snprintf(buf, PAGE_SIZE - 1, "%s\n", |
| 206 | ddb_entry->iscsi_name); |
| 207 | break; |
| 208 | case ISCSI_PARAM_TPGT: |
| 209 | len = sprintf(buf, "%u\n", ddb_entry->tpgt); |
| 210 | break; |
Vikas Chaudhary | 3b2bef1 | 2010-07-10 14:51:30 +0530 | [diff] [blame] | 211 | case ISCSI_PARAM_TARGET_ALIAS: |
| 212 | len = snprintf(buf, PAGE_SIZE - 1, "%s\n", |
| 213 | ddb_entry->iscsi_alias); |
| 214 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 215 | default: |
| 216 | return -ENOSYS; |
| 217 | } |
| 218 | |
| 219 | return len; |
| 220 | } |
| 221 | |
| 222 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
| 223 | enum iscsi_param param, char *buf) |
| 224 | { |
| 225 | struct iscsi_cls_session *session; |
| 226 | struct ddb_entry *ddb_entry; |
| 227 | int len; |
| 228 | |
| 229 | session = iscsi_dev_to_session(conn->dev.parent); |
| 230 | ddb_entry = session->dd_data; |
| 231 | |
| 232 | switch (param) { |
| 233 | case ISCSI_PARAM_CONN_PORT: |
| 234 | len = sprintf(buf, "%hu\n", ddb_entry->port); |
| 235 | break; |
| 236 | case ISCSI_PARAM_CONN_ADDRESS: |
| 237 | /* TODO: what are the ipv6 bits */ |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 238 | len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 239 | break; |
| 240 | default: |
| 241 | return -ENOSYS; |
| 242 | } |
| 243 | |
| 244 | return len; |
| 245 | } |
| 246 | |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 247 | static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost, |
| 248 | enum iscsi_tgt_dscvr type, uint32_t enable, |
| 249 | struct sockaddr *dst_addr) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 250 | { |
| 251 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 252 | struct sockaddr_in *addr; |
| 253 | struct sockaddr_in6 *addr6; |
| 254 | int ret = 0; |
| 255 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 256 | ha = (struct scsi_qla_host *) shost->hostdata; |
| 257 | |
| 258 | switch (type) { |
| 259 | case ISCSI_TGT_DSCVR_SEND_TARGETS: |
| 260 | if (dst_addr->sa_family == AF_INET) { |
| 261 | addr = (struct sockaddr_in *)dst_addr; |
| 262 | if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr, |
| 263 | addr->sin_port) != QLA_SUCCESS) |
| 264 | ret = -EIO; |
| 265 | } else if (dst_addr->sa_family == AF_INET6) { |
| 266 | /* |
| 267 | * TODO: fix qla4xxx_send_tgts |
| 268 | */ |
| 269 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 270 | if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr, |
| 271 | addr6->sin6_port) != QLA_SUCCESS) |
| 272 | ret = -EIO; |
| 273 | } else |
| 274 | ret = -ENOSYS; |
| 275 | break; |
| 276 | default: |
| 277 | ret = -ENOSYS; |
| 278 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 279 | return ret; |
| 280 | } |
| 281 | |
| 282 | void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry) |
| 283 | { |
| 284 | if (!ddb_entry->sess) |
| 285 | return; |
| 286 | |
| 287 | if (ddb_entry->conn) { |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 288 | atomic_set(&ddb_entry->state, DDB_STATE_DEAD); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 289 | iscsi_remove_session(ddb_entry->sess); |
| 290 | } |
| 291 | iscsi_free_session(ddb_entry->sess); |
| 292 | } |
| 293 | |
| 294 | int qla4xxx_add_sess(struct ddb_entry *ddb_entry) |
| 295 | { |
| 296 | int err; |
| 297 | |
Vikas Chaudhary | 3013cea | 2010-07-30 14:25:46 +0530 | [diff] [blame] | 298 | ddb_entry->sess->recovery_tmo = QL4_SESS_RECOVERY_TMO; |
| 299 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 300 | err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index); |
| 301 | if (err) { |
| 302 | DEBUG2(printk(KERN_ERR "Could not add session.\n")); |
| 303 | return err; |
| 304 | } |
| 305 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 306 | ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 307 | if (!ddb_entry->conn) { |
| 308 | iscsi_remove_session(ddb_entry->sess); |
| 309 | DEBUG2(printk(KERN_ERR "Could not add connection.\n")); |
| 310 | return -ENOMEM; |
| 311 | } |
Mike Christie | b635930 | 2008-01-31 13:36:44 -0600 | [diff] [blame] | 312 | |
| 313 | /* finally ready to go */ |
| 314 | iscsi_unblock_session(ddb_entry->sess); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha) |
| 319 | { |
| 320 | struct ddb_entry *ddb_entry; |
| 321 | struct iscsi_cls_session *sess; |
| 322 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 323 | sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport, |
| 324 | sizeof(struct ddb_entry)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 325 | if (!sess) |
| 326 | return NULL; |
| 327 | |
| 328 | ddb_entry = sess->dd_data; |
| 329 | memset(ddb_entry, 0, sizeof(*ddb_entry)); |
| 330 | ddb_entry->ha = ha; |
| 331 | ddb_entry->sess = sess; |
| 332 | return ddb_entry; |
| 333 | } |
| 334 | |
Mike Christie | 024f801 | 2008-03-04 13:26:54 -0600 | [diff] [blame] | 335 | static void qla4xxx_scan_start(struct Scsi_Host *shost) |
| 336 | { |
| 337 | struct scsi_qla_host *ha = shost_priv(shost); |
| 338 | struct ddb_entry *ddb_entry, *ddbtemp; |
| 339 | |
| 340 | /* finish setup of sessions that were already setup in firmware */ |
| 341 | list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) { |
| 342 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) |
| 343 | qla4xxx_add_sess(ddb_entry); |
| 344 | } |
| 345 | } |
| 346 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 347 | /* |
| 348 | * Timer routines |
| 349 | */ |
| 350 | |
| 351 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, |
| 352 | unsigned long interval) |
| 353 | { |
| 354 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| 355 | __func__, ha->host->host_no)); |
| 356 | init_timer(&ha->timer); |
| 357 | ha->timer.expires = jiffies + interval * HZ; |
| 358 | ha->timer.data = (unsigned long)ha; |
| 359 | ha->timer.function = (void (*)(unsigned long))func; |
| 360 | add_timer(&ha->timer); |
| 361 | ha->timer_active = 1; |
| 362 | } |
| 363 | |
| 364 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| 365 | { |
| 366 | del_timer_sync(&ha->timer); |
| 367 | ha->timer_active = 0; |
| 368 | } |
| 369 | |
| 370 | /*** |
| 371 | * qla4xxx_mark_device_missing - mark a device as missing. |
| 372 | * @ha: Pointer to host adapter structure. |
| 373 | * @ddb_entry: Pointer to device database entry |
| 374 | * |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 375 | * This routine marks a device missing and close connection. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 376 | **/ |
| 377 | void qla4xxx_mark_device_missing(struct scsi_qla_host *ha, |
| 378 | struct ddb_entry *ddb_entry) |
| 379 | { |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 380 | if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) { |
| 381 | atomic_set(&ddb_entry->state, DDB_STATE_MISSING); |
| 382 | DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n", |
| 383 | ha->host_no, ddb_entry->fw_ddb_index)); |
| 384 | } else |
| 385 | DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no, |
| 386 | ddb_entry->fw_ddb_index)) |
| 387 | |
Mike Christie | b635930 | 2008-01-31 13:36:44 -0600 | [diff] [blame] | 388 | iscsi_block_session(ddb_entry->sess); |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 389 | iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 392 | /** |
| 393 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| 394 | * @ha: Pointer to host adapter structure. |
| 395 | * |
| 396 | * This routine marks a device missing and resets the relogin retry count. |
| 397 | **/ |
| 398 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| 399 | { |
| 400 | struct ddb_entry *ddb_entry, *ddbtemp; |
| 401 | list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) { |
| 402 | qla4xxx_mark_device_missing(ha, ddb_entry); |
| 403 | } |
| 404 | } |
| 405 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 406 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| 407 | struct ddb_entry *ddb_entry, |
| 408 | struct scsi_cmnd *cmd, |
| 409 | void (*done)(struct scsi_cmnd *)) |
| 410 | { |
| 411 | struct srb *srb; |
| 412 | |
| 413 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 414 | if (!srb) |
| 415 | return srb; |
| 416 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 417 | kref_init(&srb->srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 418 | srb->ha = ha; |
| 419 | srb->ddb = ddb_entry; |
| 420 | srb->cmd = cmd; |
| 421 | srb->flags = 0; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 422 | CMD_SP(cmd) = (void *)srb; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 423 | cmd->scsi_done = done; |
| 424 | |
| 425 | return srb; |
| 426 | } |
| 427 | |
| 428 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| 429 | { |
| 430 | struct scsi_cmnd *cmd = srb->cmd; |
| 431 | |
| 432 | if (srb->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 433 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 434 | srb->flags &= ~SRB_DMA_VALID; |
| 435 | } |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 436 | CMD_SP(cmd) = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 439 | void qla4xxx_srb_compl(struct kref *ref) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 440 | { |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 441 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 442 | struct scsi_cmnd *cmd = srb->cmd; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 443 | struct scsi_qla_host *ha = srb->ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 444 | |
| 445 | qla4xxx_srb_free_dma(ha, srb); |
| 446 | |
| 447 | mempool_free(srb, ha->srb_mempool); |
| 448 | |
| 449 | cmd->scsi_done(cmd); |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
| 454 | * @cmd: Pointer to Linux's SCSI command structure |
| 455 | * @done_fn: Function that the driver calls to notify the SCSI mid-layer |
| 456 | * that the command has been processed. |
| 457 | * |
| 458 | * Remarks: |
| 459 | * This routine is invoked by Linux to send a SCSI command to the driver. |
| 460 | * The mid-level driver tries to ensure that queuecommand never gets |
| 461 | * invoked concurrently with itself or the interrupt handler (although |
| 462 | * the interrupt handler may call this routine as part of request- |
| 463 | * completion handling). Unfortunely, it sometimes calls the scheduler |
| 464 | * in interrupt context which is a big NO! NO!. |
| 465 | **/ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 466 | static int qla4xxx_queuecommand_lck(struct scsi_cmnd *cmd, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 467 | void (*done)(struct scsi_cmnd *)) |
| 468 | { |
| 469 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 470 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 471 | struct iscsi_cls_session *sess = ddb_entry->sess; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 472 | struct srb *srb; |
| 473 | int rval; |
| 474 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 475 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 476 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 477 | cmd->result = DID_NO_CONNECT << 16; |
| 478 | else |
| 479 | cmd->result = DID_REQUEUE << 16; |
| 480 | goto qc_fail_command; |
| 481 | } |
| 482 | |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 483 | if (!sess) { |
| 484 | cmd->result = DID_IMM_RETRY << 16; |
| 485 | goto qc_fail_command; |
| 486 | } |
| 487 | |
| 488 | rval = iscsi_session_chkready(sess); |
| 489 | if (rval) { |
| 490 | cmd->result = rval; |
| 491 | goto qc_fail_command; |
| 492 | } |
| 493 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 494 | if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { |
| 495 | if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) { |
| 496 | cmd->result = DID_NO_CONNECT << 16; |
| 497 | goto qc_fail_command; |
| 498 | } |
Mike Christie | c5e98e9 | 2008-08-17 15:24:39 -0500 | [diff] [blame] | 499 | return SCSI_MLQUEUE_TARGET_BUSY; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 502 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 503 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 504 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 505 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 506 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| 507 | !test_bit(AF_ONLINE, &ha->flags) || |
| 508 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 509 | goto qc_host_busy; |
| 510 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 511 | spin_unlock_irq(ha->host->host_lock); |
| 512 | |
| 513 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done); |
| 514 | if (!srb) |
| 515 | goto qc_host_busy_lock; |
| 516 | |
| 517 | rval = qla4xxx_send_command_to_isp(ha, srb); |
| 518 | if (rval != QLA_SUCCESS) |
| 519 | goto qc_host_busy_free_sp; |
| 520 | |
| 521 | spin_lock_irq(ha->host->host_lock); |
| 522 | return 0; |
| 523 | |
| 524 | qc_host_busy_free_sp: |
| 525 | qla4xxx_srb_free_dma(ha, srb); |
| 526 | mempool_free(srb, ha->srb_mempool); |
| 527 | |
| 528 | qc_host_busy_lock: |
| 529 | spin_lock_irq(ha->host->host_lock); |
| 530 | |
| 531 | qc_host_busy: |
| 532 | return SCSI_MLQUEUE_HOST_BUSY; |
| 533 | |
| 534 | qc_fail_command: |
| 535 | done(cmd); |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 540 | static DEF_SCSI_QCMD(qla4xxx_queuecommand) |
| 541 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 542 | /** |
| 543 | * qla4xxx_mem_free - frees memory allocated to adapter |
| 544 | * @ha: Pointer to host adapter structure. |
| 545 | * |
| 546 | * Frees memory previously allocated by qla4xxx_mem_alloc |
| 547 | **/ |
| 548 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| 549 | { |
| 550 | if (ha->queues) |
| 551 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| 552 | ha->queues_dma); |
| 553 | |
| 554 | ha->queues_len = 0; |
| 555 | ha->queues = NULL; |
| 556 | ha->queues_dma = 0; |
| 557 | ha->request_ring = NULL; |
| 558 | ha->request_dma = 0; |
| 559 | ha->response_ring = NULL; |
| 560 | ha->response_dma = 0; |
| 561 | ha->shadow_regs = NULL; |
| 562 | ha->shadow_regs_dma = 0; |
| 563 | |
| 564 | /* Free srb pool. */ |
| 565 | if (ha->srb_mempool) |
| 566 | mempool_destroy(ha->srb_mempool); |
| 567 | |
| 568 | ha->srb_mempool = NULL; |
| 569 | |
| 570 | /* release io space registers */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 571 | if (is_qla8022(ha)) { |
| 572 | if (ha->nx_pcibase) |
| 573 | iounmap( |
| 574 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 575 | } else if (ha->reg) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 576 | iounmap(ha->reg); |
| 577 | pci_release_regions(ha->pdev); |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| 582 | * @ha: Pointer to host adapter structure |
| 583 | * |
| 584 | * Allocates DMA memory for request and response queues. Also allocates memory |
| 585 | * for srbs. |
| 586 | **/ |
| 587 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| 588 | { |
| 589 | unsigned long align; |
| 590 | |
| 591 | /* Allocate contiguous block of DMA memory for queues. */ |
| 592 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 593 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| 594 | sizeof(struct shadow_regs) + |
| 595 | MEM_ALIGN_VALUE + |
| 596 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 597 | ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, |
| 598 | &ha->queues_dma, GFP_KERNEL); |
| 599 | if (ha->queues == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 600 | ql4_printk(KERN_WARNING, ha, |
| 601 | "Memory Allocation failed - queues.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 602 | |
| 603 | goto mem_alloc_error_exit; |
| 604 | } |
| 605 | memset(ha->queues, 0, ha->queues_len); |
| 606 | |
| 607 | /* |
| 608 | * As per RISC alignment requirements -- the bus-address must be a |
| 609 | * multiple of the request-ring size (in bytes). |
| 610 | */ |
| 611 | align = 0; |
| 612 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| 613 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| 614 | (MEM_ALIGN_VALUE - 1)); |
| 615 | |
| 616 | /* Update request and response queue pointers. */ |
| 617 | ha->request_dma = ha->queues_dma + align; |
| 618 | ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| 619 | ha->response_dma = ha->queues_dma + align + |
| 620 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| 621 | ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| 622 | (REQUEST_QUEUE_DEPTH * |
| 623 | QUEUE_SIZE)); |
| 624 | ha->shadow_regs_dma = ha->queues_dma + align + |
| 625 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 626 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| 627 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| 628 | (REQUEST_QUEUE_DEPTH * |
| 629 | QUEUE_SIZE) + |
| 630 | (RESPONSE_QUEUE_DEPTH * |
| 631 | QUEUE_SIZE)); |
| 632 | |
| 633 | /* Allocate memory for srb pool. */ |
| 634 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 635 | mempool_free_slab, srb_cachep); |
| 636 | if (ha->srb_mempool == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 637 | ql4_printk(KERN_WARNING, ha, |
| 638 | "Memory Allocation failed - SRB Pool.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 639 | |
| 640 | goto mem_alloc_error_exit; |
| 641 | } |
| 642 | |
| 643 | return QLA_SUCCESS; |
| 644 | |
| 645 | mem_alloc_error_exit: |
| 646 | qla4xxx_mem_free(ha); |
| 647 | return QLA_ERROR; |
| 648 | } |
| 649 | |
| 650 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 651 | * qla4_8xxx_check_fw_alive - Check firmware health |
| 652 | * @ha: Pointer to host adapter structure. |
| 653 | * |
| 654 | * Context: Interrupt |
| 655 | **/ |
| 656 | static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
| 657 | { |
| 658 | uint32_t fw_heartbeat_counter, halt_status; |
| 659 | |
| 660 | fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 661 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| 662 | if (fw_heartbeat_counter == 0xffffffff) { |
| 663 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| 664 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| 665 | ha->host_no, __func__)); |
| 666 | return; |
| 667 | } |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 668 | |
| 669 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| 670 | ha->seconds_since_last_heartbeat++; |
| 671 | /* FW not alive after 2 seconds */ |
| 672 | if (ha->seconds_since_last_heartbeat == 2) { |
| 673 | ha->seconds_since_last_heartbeat = 0; |
| 674 | halt_status = qla4_8xxx_rd_32(ha, |
| 675 | QLA82XX_PEG_HALT_STATUS1); |
Nilesh Javali | 2103363 | 2010-07-30 14:28:07 +0530 | [diff] [blame] | 676 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 677 | /* Since we cannot change dev_state in interrupt |
| 678 | * context, set appropriate DPC flag then wakeup |
| 679 | * DPC */ |
| 680 | if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| 681 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 682 | else { |
| 683 | printk("scsi%ld: %s: detect abort needed!\n", |
| 684 | ha->host_no, __func__); |
| 685 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 686 | } |
| 687 | qla4xxx_wake_dpc(ha); |
Nilesh Javali | 2103363 | 2010-07-30 14:28:07 +0530 | [diff] [blame] | 688 | qla4xxx_mailbox_premature_completion(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 689 | } |
Lalit Chandivade | 99457d7 | 2010-10-06 22:49:32 -0700 | [diff] [blame] | 690 | } else |
| 691 | ha->seconds_since_last_heartbeat = 0; |
| 692 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 693 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * qla4_8xxx_watchdog - Poll dev state |
| 698 | * @ha: Pointer to host adapter structure. |
| 699 | * |
| 700 | * Context: Interrupt |
| 701 | **/ |
| 702 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| 703 | { |
| 704 | uint32_t dev_state; |
| 705 | |
| 706 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 707 | |
| 708 | /* don't poll if reset is going on */ |
| 709 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags)) { |
| 710 | if (dev_state == QLA82XX_DEV_NEED_RESET && |
| 711 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| 712 | printk("scsi%ld: %s: HW State: NEED RESET!\n", |
| 713 | ha->host_no, __func__); |
| 714 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 715 | qla4xxx_wake_dpc(ha); |
Nilesh Javali | 2103363 | 2010-07-30 14:28:07 +0530 | [diff] [blame] | 716 | qla4xxx_mailbox_premature_completion(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 717 | } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT && |
| 718 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 719 | printk("scsi%ld: %s: HW State: NEED QUIES!\n", |
| 720 | ha->host_no, __func__); |
| 721 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| 722 | qla4xxx_wake_dpc(ha); |
| 723 | } else { |
| 724 | /* Check firmware health */ |
| 725 | qla4_8xxx_check_fw_alive(ha); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 731 | * qla4xxx_timer - checks every second for work to do. |
| 732 | * @ha: Pointer to host adapter structure. |
| 733 | **/ |
| 734 | static void qla4xxx_timer(struct scsi_qla_host *ha) |
| 735 | { |
| 736 | struct ddb_entry *ddb_entry, *dtemp; |
| 737 | int start_dpc = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 738 | uint16_t w; |
| 739 | |
| 740 | /* If we are in the middle of AER/EEH processing |
| 741 | * skip any processing and reschedule the timer |
| 742 | */ |
| 743 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 744 | mod_timer(&ha->timer, jiffies + HZ); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | /* Hardware read to trigger an EEH error during mailbox waits. */ |
| 749 | if (!pci_channel_offline(ha->pdev)) |
| 750 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 751 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 752 | if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) { |
| 753 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s exited. HBA GOING AWAY\n", |
| 754 | __func__)); |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | if (is_qla8022(ha)) { |
| 759 | qla4_8xxx_watchdog(ha); |
| 760 | } |
| 761 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 762 | /* Search for relogin's to time-out and port down retry. */ |
| 763 | list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) { |
| 764 | /* Count down time between sending relogins */ |
| 765 | if (adapter_up(ha) && |
| 766 | !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 767 | atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { |
| 768 | if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| 769 | INVALID_ENTRY) { |
| 770 | if (atomic_read(&ddb_entry->retry_relogin_timer) |
| 771 | == 0) { |
| 772 | atomic_set(&ddb_entry-> |
| 773 | retry_relogin_timer, |
| 774 | INVALID_ENTRY); |
| 775 | set_bit(DPC_RELOGIN_DEVICE, |
| 776 | &ha->dpc_flags); |
| 777 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 778 | DEBUG2(printk("scsi%ld: %s: ddb [%d]" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 779 | " login device\n", |
| 780 | ha->host_no, __func__, |
| 781 | ddb_entry->fw_ddb_index)); |
| 782 | } else |
| 783 | atomic_dec(&ddb_entry-> |
| 784 | retry_relogin_timer); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /* Wait for relogin to timeout */ |
| 789 | if (atomic_read(&ddb_entry->relogin_timer) && |
| 790 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| 791 | /* |
| 792 | * If the relogin times out and the device is |
| 793 | * still NOT ONLINE then try and relogin again. |
| 794 | */ |
| 795 | if (atomic_read(&ddb_entry->state) != |
| 796 | DDB_STATE_ONLINE && |
| 797 | ddb_entry->fw_ddb_device_state == |
| 798 | DDB_DS_SESSION_FAILED) { |
| 799 | /* Reset retry relogin timer */ |
| 800 | atomic_inc(&ddb_entry->relogin_retry_count); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 801 | DEBUG2(printk("scsi%ld: ddb [%d] relogin" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 802 | " timed out-retrying" |
| 803 | " relogin (%d)\n", |
| 804 | ha->host_no, |
| 805 | ddb_entry->fw_ddb_index, |
| 806 | atomic_read(&ddb_entry-> |
| 807 | relogin_retry_count)) |
| 808 | ); |
| 809 | start_dpc++; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 810 | DEBUG(printk("scsi%ld:%d:%d: ddb [%d] " |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 811 | "initate relogin after" |
| 812 | " %d seconds\n", |
| 813 | ha->host_no, ddb_entry->bus, |
| 814 | ddb_entry->target, |
| 815 | ddb_entry->fw_ddb_index, |
| 816 | ddb_entry->default_time2wait + 4) |
| 817 | ); |
| 818 | |
| 819 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 820 | ddb_entry->default_time2wait + 4); |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 825 | if (!is_qla8022(ha)) { |
| 826 | /* Check for heartbeat interval. */ |
| 827 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| 828 | ha->heartbeat_interval != 0) { |
| 829 | ha->seconds_since_last_heartbeat++; |
| 830 | if (ha->seconds_since_last_heartbeat > |
| 831 | ha->heartbeat_interval + 2) |
| 832 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 833 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 834 | } |
| 835 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 836 | /* Wakeup the dpc routine for this adapter, if needed. */ |
| 837 | if ((start_dpc || |
| 838 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 839 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| 840 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 841 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 842 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 843 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 844 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 845 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 846 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 847 | test_bit(DPC_AEN, &ha->dpc_flags)) && |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 848 | !test_bit(AF_DPC_SCHEDULED, &ha->flags) && |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 849 | ha->dpc_thread) { |
| 850 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| 851 | " - dpc flags = 0x%lx\n", |
| 852 | ha->host_no, __func__, ha->dpc_flags)); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 853 | qla4xxx_wake_dpc(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /* Reschedule timer thread to call us back in one second */ |
| 857 | mod_timer(&ha->timer, jiffies + HZ); |
| 858 | |
| 859 | DEBUG2(ha->seconds_since_last_intr++); |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| 864 | * @ha: Pointer to host adapter structure. |
| 865 | * |
| 866 | * This routine stalls the driver until all outstanding commands are returned. |
| 867 | * Caller must release the Hardware Lock prior to calling this routine. |
| 868 | **/ |
| 869 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| 870 | { |
| 871 | uint32_t index = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 872 | unsigned long flags; |
| 873 | struct scsi_cmnd *cmd; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 874 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 875 | unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
| 876 | |
| 877 | DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " |
| 878 | "complete\n", WAIT_CMD_TOV)); |
| 879 | |
| 880 | while (!time_after_eq(jiffies, wtime)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 881 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 882 | /* Find a command that hasn't completed. */ |
| 883 | for (index = 0; index < ha->host->can_queue; index++) { |
| 884 | cmd = scsi_host_find_tag(ha->host, index); |
Mike Christie | a1e0063 | 2010-10-26 05:45:30 -0700 | [diff] [blame] | 885 | /* |
| 886 | * We cannot just check if the index is valid, |
| 887 | * becase if we are run from the scsi eh, then |
| 888 | * the scsi/block layer is going to prevent |
| 889 | * the tag from being released. |
| 890 | */ |
| 891 | if (cmd != NULL && CMD_SP(cmd)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 892 | break; |
| 893 | } |
| 894 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 895 | |
| 896 | /* If No Commands are pending, wait is complete */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 897 | if (index == ha->host->can_queue) |
| 898 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 899 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 900 | msleep(1000); |
| 901 | } |
| 902 | /* If we timed out on waiting for commands to come back |
| 903 | * return ERROR. */ |
| 904 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 907 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 908 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 909 | uint32_t ctrl_status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 910 | unsigned long flags = 0; |
| 911 | |
| 912 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 913 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 914 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 915 | return QLA_ERROR; |
| 916 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 917 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 918 | |
| 919 | /* |
| 920 | * If the SCSI Reset Interrupt bit is set, clear it. |
| 921 | * Otherwise, the Soft Reset won't work. |
| 922 | */ |
| 923 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 924 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| 925 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 926 | |
| 927 | /* Issue Soft Reset */ |
| 928 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| 929 | readl(&ha->reg->ctrl_status); |
| 930 | |
| 931 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 932 | return QLA_SUCCESS; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /** |
| 936 | * qla4xxx_soft_reset - performs soft reset. |
| 937 | * @ha: Pointer to host adapter structure. |
| 938 | **/ |
| 939 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| 940 | { |
| 941 | uint32_t max_wait_time; |
| 942 | unsigned long flags = 0; |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 943 | int status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 944 | uint32_t ctrl_status; |
| 945 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 946 | status = qla4xxx_hw_reset(ha); |
| 947 | if (status != QLA_SUCCESS) |
| 948 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 949 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 950 | status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 951 | /* Wait until the Network Reset Intr bit is cleared */ |
| 952 | max_wait_time = RESET_INTR_TOV; |
| 953 | do { |
| 954 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 955 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 956 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 957 | |
| 958 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| 959 | break; |
| 960 | |
| 961 | msleep(1000); |
| 962 | } while ((--max_wait_time)); |
| 963 | |
| 964 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| 965 | DEBUG2(printk(KERN_WARNING |
| 966 | "scsi%ld: Network Reset Intr not cleared by " |
| 967 | "Network function, clearing it now!\n", |
| 968 | ha->host_no)); |
| 969 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 970 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| 971 | readl(&ha->reg->ctrl_status); |
| 972 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 973 | } |
| 974 | |
| 975 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 976 | max_wait_time = SOFT_RESET_TOV; |
| 977 | do { |
| 978 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 979 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 980 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 981 | |
| 982 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| 983 | status = QLA_SUCCESS; |
| 984 | break; |
| 985 | } |
| 986 | |
| 987 | msleep(1000); |
| 988 | } while ((--max_wait_time)); |
| 989 | |
| 990 | /* |
| 991 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| 992 | * after the soft reset has taken place. |
| 993 | */ |
| 994 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 995 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 996 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| 997 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 998 | readl(&ha->reg->ctrl_status); |
| 999 | } |
| 1000 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1001 | |
| 1002 | /* If soft reset fails then most probably the bios on other |
| 1003 | * function is also enabled. |
| 1004 | * Since the initialization is sequential the other fn |
| 1005 | * wont be able to acknowledge the soft reset. |
| 1006 | * Issue a force soft reset to workaround this scenario. |
| 1007 | */ |
| 1008 | if (max_wait_time == 0) { |
| 1009 | /* Issue Force Soft Reset */ |
| 1010 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1011 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| 1012 | readl(&ha->reg->ctrl_status); |
| 1013 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1014 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 1015 | max_wait_time = SOFT_RESET_TOV; |
| 1016 | do { |
| 1017 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1018 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 1019 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1020 | |
| 1021 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| 1022 | status = QLA_SUCCESS; |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | msleep(1000); |
| 1027 | } while ((--max_wait_time)); |
| 1028 | } |
| 1029 | |
| 1030 | return status; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1034 | * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1035 | * @ha: Pointer to host adapter structure. |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1036 | * @res: returned scsi status |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1037 | * |
| 1038 | * This routine is called just prior to a HARD RESET to return all |
| 1039 | * outstanding commands back to the Operating System. |
| 1040 | * Caller should make sure that the following locks are released |
| 1041 | * before this calling routine: Hardware lock, and io_request_lock. |
| 1042 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1043 | static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1044 | { |
| 1045 | struct srb *srb; |
| 1046 | int i; |
| 1047 | unsigned long flags; |
| 1048 | |
| 1049 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1050 | for (i = 0; i < ha->host->can_queue; i++) { |
| 1051 | srb = qla4xxx_del_from_active_array(ha, i); |
| 1052 | if (srb != NULL) { |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1053 | srb->cmd->result = res; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 1054 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1060 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| 1061 | { |
| 1062 | clear_bit(AF_ONLINE, &ha->flags); |
| 1063 | |
| 1064 | /* Disable the board */ |
| 1065 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
| 1066 | set_bit(AF_HBA_GOING_AWAY, &ha->flags); |
| 1067 | |
| 1068 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 1069 | qla4xxx_mark_all_devices_missing(ha); |
| 1070 | clear_bit(AF_INIT_DONE, &ha->flags); |
| 1071 | } |
| 1072 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1073 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1074 | * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| 1075 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1076 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1077 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1078 | { |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1079 | int status = QLA_ERROR; |
| 1080 | uint8_t reset_chip = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1081 | |
| 1082 | /* Stall incoming I/O until we are done */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1083 | scsi_block_requests(ha->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1084 | clear_bit(AF_ONLINE, &ha->flags); |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 1085 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1086 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1087 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1088 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1089 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1090 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 1091 | reset_chip = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1092 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1093 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| 1094 | * do not reset adapter, jump to initialize_adapter */ |
| 1095 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| 1096 | status = QLA_SUCCESS; |
| 1097 | goto recover_ha_init_adapter; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1100 | /* For the ISP-82xx adapter, issue a stop_firmware if invoked |
| 1101 | * from eh_host_reset or ioctl module */ |
| 1102 | if (is_qla8022(ha) && !reset_chip && |
| 1103 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 1104 | |
| 1105 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1106 | "scsi%ld: %s - Performing stop_firmware...\n", |
| 1107 | ha->host_no, __func__)); |
| 1108 | status = ha->isp_ops->reset_firmware(ha); |
| 1109 | if (status == QLA_SUCCESS) { |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 1110 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 1111 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1112 | ha->isp_ops->disable_intrs(ha); |
| 1113 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 1114 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 1115 | } else { |
| 1116 | /* If the stop_firmware fails then |
| 1117 | * reset the entire chip */ |
| 1118 | reset_chip = 1; |
| 1119 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 1120 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | /* Issue full chip reset if recovering from a catastrophic error, |
| 1125 | * or if stop_firmware fails for ISP-82xx. |
| 1126 | * This is the default case for ISP-4xxx */ |
| 1127 | if (!is_qla8022(ha) || reset_chip) { |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 1128 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 1129 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1130 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 1131 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 1132 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1133 | "scsi%ld: %s - Performing chip reset..\n", |
| 1134 | ha->host_no, __func__)); |
| 1135 | status = ha->isp_ops->reset_chip(ha); |
| 1136 | } |
| 1137 | |
| 1138 | /* Flush any pending ddb changed AENs */ |
| 1139 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 1140 | |
| 1141 | recover_ha_init_adapter: |
| 1142 | /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| 1143 | if (status == QLA_SUCCESS) { |
| 1144 | /* For ISP-4xxx, force function 1 to always initialize |
| 1145 | * before function 3 to prevent both funcions from |
| 1146 | * stepping on top of the other */ |
| 1147 | if (!is_qla8022(ha) && (ha->mac_index == 3)) |
| 1148 | ssleep(6); |
| 1149 | |
| 1150 | /* NOTE: AF_ONLINE flag set upon successful completion of |
| 1151 | * qla4xxx_initialize_adapter */ |
| 1152 | status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST); |
| 1153 | } |
| 1154 | |
| 1155 | /* Retry failed adapter initialization, if necessary |
| 1156 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| 1157 | * case to prevent ping-pong resets between functions */ |
| 1158 | if (!test_bit(AF_ONLINE, &ha->flags) && |
| 1159 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1160 | /* Adapter initialization failed, see if we can retry |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1161 | * resetting the ha. |
| 1162 | * Since we don't want to block the DPC for too long |
| 1163 | * with multiple resets in the same thread, |
| 1164 | * utilize DPC to retry */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1165 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| 1166 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| 1167 | DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| 1168 | "(%d) more times\n", ha->host_no, |
| 1169 | ha->retry_reset_ha_cnt)); |
| 1170 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 1171 | status = QLA_ERROR; |
| 1172 | } else { |
| 1173 | if (ha->retry_reset_ha_cnt > 0) { |
| 1174 | /* Schedule another Reset HA--DPC will retry */ |
| 1175 | ha->retry_reset_ha_cnt--; |
| 1176 | DEBUG2(printk("scsi%ld: recover adapter - " |
| 1177 | "retry remaining %d\n", |
| 1178 | ha->host_no, |
| 1179 | ha->retry_reset_ha_cnt)); |
| 1180 | status = QLA_ERROR; |
| 1181 | } |
| 1182 | |
| 1183 | if (ha->retry_reset_ha_cnt == 0) { |
| 1184 | /* Recover adapter retries have been exhausted. |
| 1185 | * Adapter DEAD */ |
| 1186 | DEBUG2(printk("scsi%ld: recover adapter " |
| 1187 | "failed - board disabled\n", |
| 1188 | ha->host_no)); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1189 | qla4xxx_dead_adapter_cleanup(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1190 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 1191 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1192 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1193 | &ha->dpc_flags); |
| 1194 | status = QLA_ERROR; |
| 1195 | } |
| 1196 | } |
| 1197 | } else { |
| 1198 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1199 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1200 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 1201 | } |
| 1202 | |
| 1203 | ha->adapter_error_count++; |
| 1204 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1205 | if (test_bit(AF_ONLINE, &ha->flags)) |
| 1206 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1207 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1208 | scsi_unblock_requests(ha->host); |
| 1209 | |
| 1210 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 1211 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
| 1212 | status == QLA_ERROR ? "FAILED" : "SUCCEDED")); |
| 1213 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1214 | return status; |
| 1215 | } |
| 1216 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1217 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| 1218 | { |
| 1219 | if (ha->dpc_thread && |
| 1220 | !test_bit(AF_DPC_SCHEDULED, &ha->flags)) { |
| 1221 | set_bit(AF_DPC_SCHEDULED, &ha->flags); |
| 1222 | queue_work(ha->dpc_thread, &ha->dpc_work); |
| 1223 | } |
| 1224 | } |
| 1225 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1226 | /** |
| 1227 | * qla4xxx_do_dpc - dpc routine |
| 1228 | * @data: in our case pointer to adapter structure |
| 1229 | * |
| 1230 | * This routine is a task that is schedule by the interrupt handler |
| 1231 | * to perform the background processing for interrupts. We put it |
| 1232 | * on a task queue that is consumed whenever the scheduler runs; that's |
| 1233 | * so you can do anything (i.e. put the process to sleep etc). In fact, |
| 1234 | * the mid-level tries to sleep when it reaches the driver threshold |
| 1235 | * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| 1236 | **/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1237 | static void qla4xxx_do_dpc(struct work_struct *work) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1238 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1239 | struct scsi_qla_host *ha = |
| 1240 | container_of(work, struct scsi_qla_host, dpc_work); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1241 | struct ddb_entry *ddb_entry, *dtemp; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1242 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1243 | |
David C Somayajulu | f26b904 | 2006-11-15 16:41:09 -0800 | [diff] [blame] | 1244 | DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1245 | "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| 1246 | ha->host_no, __func__, ha->flags, ha->dpc_flags)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* Initialization not yet finished. Don't do anything yet. */ |
| 1249 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
Vikas Chaudhary | 0753b48 | 2010-07-30 14:27:19 +0530 | [diff] [blame] | 1250 | goto do_dpc_exit; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1251 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1252 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 1253 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| 1254 | ha->host_no, __func__, ha->flags)); |
| 1255 | goto do_dpc_exit; |
| 1256 | } |
| 1257 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1258 | /* HBA is in the process of being permanently disabled. |
| 1259 | * Don't process anything */ |
| 1260 | if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) |
| 1261 | return; |
| 1262 | |
| 1263 | if (is_qla8022(ha)) { |
| 1264 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
| 1265 | qla4_8xxx_idc_lock(ha); |
| 1266 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 1267 | QLA82XX_DEV_FAILED); |
| 1268 | qla4_8xxx_idc_unlock(ha); |
| 1269 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 1270 | qla4_8xxx_device_state_handler(ha); |
| 1271 | } |
| 1272 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 1273 | qla4_8xxx_need_qsnt_handler(ha); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| 1278 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1279 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1280 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
| 1281 | if (ql4xdontresethba) { |
| 1282 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 1283 | ha->host_no, __func__)); |
| 1284 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 1285 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 1286 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 1287 | goto dpc_post_reset_ha; |
| 1288 | } |
| 1289 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| 1290 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 1291 | qla4xxx_recover_adapter(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1292 | |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1293 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1294 | uint8_t wait_time = RESET_INTR_TOV; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1295 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1296 | while ((readw(&ha->reg->ctrl_status) & |
| 1297 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| 1298 | if (--wait_time == 0) |
| 1299 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1300 | msleep(1000); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1301 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1302 | if (wait_time == 0) |
| 1303 | DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| 1304 | "bit not cleared-- resetting\n", |
| 1305 | ha->host_no, __func__)); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1306 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1307 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| 1308 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1309 | status = qla4xxx_recover_adapter(ha); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1310 | } |
| 1311 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 1312 | if (status == QLA_SUCCESS) |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1313 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1317 | dpc_post_reset_ha: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1318 | /* ---- process AEN? --- */ |
| 1319 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 1320 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| 1321 | |
| 1322 | /* ---- Get DHCP IP Address? --- */ |
| 1323 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 1324 | qla4xxx_get_dhcp_ip_address(ha); |
| 1325 | |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1326 | /* ---- link change? --- */ |
| 1327 | if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
| 1328 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 1329 | /* ---- link down? --- */ |
| 1330 | list_for_each_entry_safe(ddb_entry, dtemp, |
| 1331 | &ha->ddb_list, list) { |
| 1332 | if (atomic_read(&ddb_entry->state) == |
| 1333 | DDB_STATE_ONLINE) |
| 1334 | qla4xxx_mark_device_missing(ha, |
| 1335 | ddb_entry); |
| 1336 | } |
| 1337 | } else { |
| 1338 | /* ---- link up? --- * |
| 1339 | * F/W will auto login to all devices ONLY ONCE after |
| 1340 | * link up during driver initialization and runtime |
| 1341 | * fatal error recovery. Therefore, the driver must |
| 1342 | * manually relogin to devices when recovering from |
| 1343 | * connection failures, logouts, expired KATO, etc. */ |
| 1344 | |
| 1345 | list_for_each_entry_safe(ddb_entry, dtemp, |
| 1346 | &ha->ddb_list, list) { |
| 1347 | if ((atomic_read(&ddb_entry->state) == |
| 1348 | DDB_STATE_MISSING) || |
| 1349 | (atomic_read(&ddb_entry->state) == |
| 1350 | DDB_STATE_DEAD)) { |
| 1351 | if (ddb_entry->fw_ddb_device_state == |
| 1352 | DDB_DS_SESSION_ACTIVE) { |
| 1353 | atomic_set(&ddb_entry->state, |
| 1354 | DDB_STATE_ONLINE); |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1355 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1356 | "scsi%ld: %s: ddb[%d]" |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1357 | " marked ONLINE\n", |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1358 | ha->host_no, __func__, |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1359 | ddb_entry->fw_ddb_index); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 1360 | |
| 1361 | iscsi_unblock_session( |
| 1362 | ddb_entry->sess); |
| 1363 | } else |
| 1364 | qla4xxx_relogin_device( |
| 1365 | ha, ddb_entry); |
| 1366 | } |
| 1367 | |
| 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1372 | /* ---- relogin device? --- */ |
| 1373 | if (adapter_up(ha) && |
| 1374 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| 1375 | list_for_each_entry_safe(ddb_entry, dtemp, |
| 1376 | &ha->ddb_list, list) { |
| 1377 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 1378 | atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) |
| 1379 | qla4xxx_relogin_device(ha, ddb_entry); |
| 1380 | |
| 1381 | /* |
| 1382 | * If mbx cmd times out there is no point |
| 1383 | * in continuing further. |
| 1384 | * With large no of targets this can hang |
| 1385 | * the system. |
| 1386 | */ |
| 1387 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| 1388 | printk(KERN_WARNING "scsi%ld: %s: " |
| 1389 | "need to reset hba\n", |
| 1390 | ha->host_no, __func__); |
| 1391 | break; |
| 1392 | } |
| 1393 | } |
| 1394 | } |
Vikas Chaudhary | 0753b48 | 2010-07-30 14:27:19 +0530 | [diff] [blame] | 1395 | |
| 1396 | do_dpc_exit: |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1397 | clear_bit(AF_DPC_SCHEDULED, &ha->flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * qla4xxx_free_adapter - release the adapter |
| 1402 | * @ha: pointer to adapter structure |
| 1403 | **/ |
| 1404 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| 1405 | { |
| 1406 | |
| 1407 | if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) { |
| 1408 | /* Turn-off interrupts on the card. */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1409 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1412 | /* Remove timer thread, if present */ |
| 1413 | if (ha->timer_active) |
| 1414 | qla4xxx_stop_timer(ha); |
| 1415 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1416 | /* Kill the kernel thread for this host */ |
| 1417 | if (ha->dpc_thread) |
| 1418 | destroy_workqueue(ha->dpc_thread); |
| 1419 | |
| 1420 | /* Put firmware in known state */ |
| 1421 | ha->isp_ops->reset_firmware(ha); |
| 1422 | |
| 1423 | if (is_qla8022(ha)) { |
| 1424 | qla4_8xxx_idc_lock(ha); |
| 1425 | qla4_8xxx_clear_drv_active(ha); |
| 1426 | qla4_8xxx_idc_unlock(ha); |
| 1427 | } |
| 1428 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1429 | /* Detach interrupts */ |
| 1430 | if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags)) |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1431 | qla4xxx_free_irqs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1432 | |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 1433 | /* free extra memory */ |
| 1434 | qla4xxx_mem_free(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1435 | } |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 1436 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1437 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| 1438 | { |
| 1439 | int status = 0; |
| 1440 | uint8_t revision_id; |
| 1441 | unsigned long mem_base, mem_len, db_base, db_len; |
| 1442 | struct pci_dev *pdev = ha->pdev; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1443 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1444 | status = pci_request_regions(pdev, DRIVER_NAME); |
| 1445 | if (status) { |
| 1446 | printk(KERN_WARNING |
| 1447 | "scsi(%ld) Failed to reserve PIO regions (%s) " |
| 1448 | "status=%d\n", ha->host_no, pci_name(pdev), status); |
| 1449 | goto iospace_error_exit; |
| 1450 | } |
| 1451 | |
| 1452 | pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id); |
| 1453 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
| 1454 | __func__, revision_id)); |
| 1455 | ha->revision_id = revision_id; |
| 1456 | |
| 1457 | /* remap phys address */ |
| 1458 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 1459 | mem_len = pci_resource_len(pdev, 0); |
| 1460 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| 1461 | __func__, mem_base, mem_len)); |
| 1462 | |
| 1463 | /* mapping of pcibase pointer */ |
| 1464 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| 1465 | if (!ha->nx_pcibase) { |
| 1466 | printk(KERN_ERR |
| 1467 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| 1468 | pci_release_regions(ha->pdev); |
| 1469 | goto iospace_error_exit; |
| 1470 | } |
| 1471 | |
| 1472 | /* Mapping of IO base pointer, door bell read and write pointer */ |
| 1473 | |
| 1474 | /* mapping of IO base pointer */ |
| 1475 | ha->qla4_8xxx_reg = |
| 1476 | (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase + |
| 1477 | 0xbc000 + (ha->pdev->devfn << 11)); |
| 1478 | |
| 1479 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 1480 | db_len = pci_resource_len(pdev, 4); |
| 1481 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 1482 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| 1483 | QLA82XX_CAM_RAM_DB2); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1484 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 1485 | return 0; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1486 | iospace_error_exit: |
| 1487 | return -ENOMEM; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /*** |
| 1491 | * qla4xxx_iospace_config - maps registers |
| 1492 | * @ha: pointer to adapter structure |
| 1493 | * |
| 1494 | * This routines maps HBA's registers from the pci address space |
| 1495 | * into the kernel virtual address space for memory mapped i/o. |
| 1496 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1497 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1498 | { |
| 1499 | unsigned long pio, pio_len, pio_flags; |
| 1500 | unsigned long mmio, mmio_len, mmio_flags; |
| 1501 | |
| 1502 | pio = pci_resource_start(ha->pdev, 0); |
| 1503 | pio_len = pci_resource_len(ha->pdev, 0); |
| 1504 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 1505 | if (pio_flags & IORESOURCE_IO) { |
| 1506 | if (pio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1507 | ql4_printk(KERN_WARNING, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1508 | "Invalid PCI I/O region size\n"); |
| 1509 | pio = 0; |
| 1510 | } |
| 1511 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1512 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1513 | pio = 0; |
| 1514 | } |
| 1515 | |
| 1516 | /* Use MMIO operations for all accesses. */ |
| 1517 | mmio = pci_resource_start(ha->pdev, 1); |
| 1518 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 1519 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 1520 | |
| 1521 | if (!(mmio_flags & IORESOURCE_MEM)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1522 | ql4_printk(KERN_ERR, ha, |
| 1523 | "region #0 not an MMIO resource, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1524 | |
| 1525 | goto iospace_error_exit; |
| 1526 | } |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1527 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1528 | if (mmio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1529 | ql4_printk(KERN_ERR, ha, |
| 1530 | "Invalid PCI mem region size, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1531 | goto iospace_error_exit; |
| 1532 | } |
| 1533 | |
| 1534 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1535 | ql4_printk(KERN_WARNING, ha, |
| 1536 | "Failed to reserve PIO/MMIO regions\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1537 | |
| 1538 | goto iospace_error_exit; |
| 1539 | } |
| 1540 | |
| 1541 | ha->pio_address = pio; |
| 1542 | ha->pio_length = pio_len; |
| 1543 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| 1544 | if (!ha->reg) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1545 | ql4_printk(KERN_ERR, ha, |
| 1546 | "cannot remap MMIO, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1547 | |
| 1548 | goto iospace_error_exit; |
| 1549 | } |
| 1550 | |
| 1551 | return 0; |
| 1552 | |
| 1553 | iospace_error_exit: |
| 1554 | return -ENOMEM; |
| 1555 | } |
| 1556 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1557 | static struct isp_operations qla4xxx_isp_ops = { |
| 1558 | .iospace_config = qla4xxx_iospace_config, |
| 1559 | .pci_config = qla4xxx_pci_config, |
| 1560 | .disable_intrs = qla4xxx_disable_intrs, |
| 1561 | .enable_intrs = qla4xxx_enable_intrs, |
| 1562 | .start_firmware = qla4xxx_start_firmware, |
| 1563 | .intr_handler = qla4xxx_intr_handler, |
| 1564 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| 1565 | .reset_chip = qla4xxx_soft_reset, |
| 1566 | .reset_firmware = qla4xxx_hw_reset, |
| 1567 | .queue_iocb = qla4xxx_queue_iocb, |
| 1568 | .complete_iocb = qla4xxx_complete_iocb, |
| 1569 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 1570 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| 1571 | .get_sys_info = qla4xxx_get_sys_info, |
| 1572 | }; |
| 1573 | |
| 1574 | static struct isp_operations qla4_8xxx_isp_ops = { |
| 1575 | .iospace_config = qla4_8xxx_iospace_config, |
| 1576 | .pci_config = qla4_8xxx_pci_config, |
| 1577 | .disable_intrs = qla4_8xxx_disable_intrs, |
| 1578 | .enable_intrs = qla4_8xxx_enable_intrs, |
| 1579 | .start_firmware = qla4_8xxx_load_risc, |
| 1580 | .intr_handler = qla4_8xxx_intr_handler, |
| 1581 | .interrupt_service_routine = qla4_8xxx_interrupt_service_routine, |
| 1582 | .reset_chip = qla4_8xxx_isp_reset, |
| 1583 | .reset_firmware = qla4_8xxx_stop_firmware, |
| 1584 | .queue_iocb = qla4_8xxx_queue_iocb, |
| 1585 | .complete_iocb = qla4_8xxx_complete_iocb, |
| 1586 | .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out, |
| 1587 | .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in, |
| 1588 | .get_sys_info = qla4_8xxx_get_sys_info, |
| 1589 | }; |
| 1590 | |
| 1591 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 1592 | { |
| 1593 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| 1594 | } |
| 1595 | |
| 1596 | uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 1597 | { |
| 1598 | return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out)); |
| 1599 | } |
| 1600 | |
| 1601 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 1602 | { |
| 1603 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); |
| 1604 | } |
| 1605 | |
| 1606 | uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 1607 | { |
| 1608 | return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in)); |
| 1609 | } |
| 1610 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1611 | /** |
| 1612 | * qla4xxx_probe_adapter - callback function to probe HBA |
| 1613 | * @pdev: pointer to pci_dev structure |
| 1614 | * @pci_device_id: pointer to pci_device entry |
| 1615 | * |
| 1616 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. |
| 1617 | * It returns zero if successful. It also initializes all data necessary for |
| 1618 | * the driver. |
| 1619 | **/ |
| 1620 | static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev, |
| 1621 | const struct pci_device_id *ent) |
| 1622 | { |
| 1623 | int ret = -ENODEV, status; |
| 1624 | struct Scsi_Host *host; |
| 1625 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1626 | uint8_t init_retry_count = 0; |
| 1627 | char buf[34]; |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1628 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1629 | |
| 1630 | if (pci_enable_device(pdev)) |
| 1631 | return -1; |
| 1632 | |
| 1633 | host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha)); |
| 1634 | if (host == NULL) { |
| 1635 | printk(KERN_WARNING |
| 1636 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); |
| 1637 | goto probe_disable_device; |
| 1638 | } |
| 1639 | |
| 1640 | /* Clear our data area */ |
| 1641 | ha = (struct scsi_qla_host *) host->hostdata; |
| 1642 | memset(ha, 0, sizeof(*ha)); |
| 1643 | |
| 1644 | /* Save the information from PCI BIOS. */ |
| 1645 | ha->pdev = pdev; |
| 1646 | ha->host = host; |
| 1647 | ha->host_no = host->host_no; |
| 1648 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1649 | pci_enable_pcie_error_reporting(pdev); |
| 1650 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1651 | /* Setup Runtime configurable options */ |
| 1652 | if (is_qla8022(ha)) { |
| 1653 | ha->isp_ops = &qla4_8xxx_isp_ops; |
| 1654 | rwlock_init(&ha->hw_lock); |
| 1655 | ha->qdr_sn_window = -1; |
| 1656 | ha->ddr_mn_window = -1; |
| 1657 | ha->curr_window = 255; |
| 1658 | ha->func_num = PCI_FUNC(ha->pdev->devfn); |
| 1659 | nx_legacy_intr = &legacy_intr[ha->func_num]; |
| 1660 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; |
| 1661 | ha->nx_legacy_intr.tgt_status_reg = |
| 1662 | nx_legacy_intr->tgt_status_reg; |
| 1663 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; |
| 1664 | ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg; |
| 1665 | } else { |
| 1666 | ha->isp_ops = &qla4xxx_isp_ops; |
| 1667 | } |
| 1668 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1669 | /* Set EEH reset type to fundamental if required by hba */ |
| 1670 | if (is_qla8022(ha)) |
| 1671 | pdev->needs_freset = 1; |
| 1672 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1673 | /* Configure PCI I/O space. */ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1674 | ret = ha->isp_ops->iospace_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1675 | if (ret) |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1676 | goto probe_failed_ioconfig; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1677 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1678 | ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n", |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1679 | pdev->device, pdev->irq, ha->reg); |
| 1680 | |
| 1681 | qla4xxx_config_dma_addressing(ha); |
| 1682 | |
| 1683 | /* Initialize lists and spinlocks. */ |
| 1684 | INIT_LIST_HEAD(&ha->ddb_list); |
| 1685 | INIT_LIST_HEAD(&ha->free_srb_q); |
| 1686 | |
| 1687 | mutex_init(&ha->mbox_sem); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1688 | init_completion(&ha->mbx_intr_comp); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1689 | |
| 1690 | spin_lock_init(&ha->hardware_lock); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1691 | |
| 1692 | /* Allocate dma buffers */ |
| 1693 | if (qla4xxx_mem_alloc(ha)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1694 | ql4_printk(KERN_WARNING, ha, |
| 1695 | "[ERROR] Failed to allocate memory for adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1696 | |
| 1697 | ret = -ENOMEM; |
| 1698 | goto probe_failed; |
| 1699 | } |
| 1700 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1701 | if (is_qla8022(ha)) |
| 1702 | (void) qla4_8xxx_get_flash_info(ha); |
| 1703 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1704 | /* |
| 1705 | * Initialize the Host adapter request/response queues and |
| 1706 | * firmware |
| 1707 | * NOTE: interrupts enabled upon successful completion |
| 1708 | */ |
| 1709 | status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1710 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
| 1711 | init_retry_count++ < MAX_INIT_RETRIES) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1712 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
| 1713 | "(%d)\n", __func__, init_retry_count)); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1714 | |
| 1715 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) |
| 1716 | continue; |
| 1717 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1718 | status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST); |
| 1719 | } |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1720 | |
| 1721 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1722 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1723 | |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame^] | 1724 | if (is_qla8022(ha) && ql4xdontresethba) { |
| 1725 | /* Put the device in failed state. */ |
| 1726 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); |
| 1727 | qla4_8xxx_idc_lock(ha); |
| 1728 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 1729 | QLA82XX_DEV_FAILED); |
| 1730 | qla4_8xxx_idc_unlock(ha); |
| 1731 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1732 | ret = -ENODEV; |
| 1733 | goto probe_failed; |
| 1734 | } |
| 1735 | |
| 1736 | host->cmd_per_lun = 3; |
| 1737 | host->max_channel = 0; |
| 1738 | host->max_lun = MAX_LUNS - 1; |
| 1739 | host->max_id = MAX_TARGETS; |
| 1740 | host->max_cmd_len = IOCB_MAX_CDB_LEN; |
| 1741 | host->can_queue = MAX_SRBS ; |
| 1742 | host->transportt = qla4xxx_scsi_transport; |
| 1743 | |
| 1744 | ret = scsi_init_shared_tag_map(host, MAX_SRBS); |
| 1745 | if (ret) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1746 | ql4_printk(KERN_WARNING, ha, |
| 1747 | "scsi_init_shared_tag_map failed\n"); |
| 1748 | goto probe_failed; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | /* Startup the kernel thread for this host adapter. */ |
| 1752 | DEBUG2(printk("scsi: %s: Starting kernel thread for " |
| 1753 | "qla4xxx_dpc\n", __func__)); |
| 1754 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); |
| 1755 | ha->dpc_thread = create_singlethread_workqueue(buf); |
| 1756 | if (!ha->dpc_thread) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1757 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1758 | ret = -ENODEV; |
| 1759 | goto probe_failed; |
| 1760 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1761 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1762 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1763 | /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc |
| 1764 | * (which is called indirectly by qla4xxx_initialize_adapter), |
| 1765 | * so that irqs will be registered after crbinit but before |
| 1766 | * mbx_intr_enable. |
| 1767 | */ |
| 1768 | if (!is_qla8022(ha)) { |
| 1769 | ret = qla4xxx_request_irqs(ha); |
| 1770 | if (ret) { |
| 1771 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " |
| 1772 | "interrupt %d already in use.\n", pdev->irq); |
| 1773 | goto probe_failed; |
| 1774 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1775 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1776 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1777 | pci_save_state(ha->pdev); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1778 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1779 | |
| 1780 | /* Start timer thread. */ |
| 1781 | qla4xxx_start_timer(ha, qla4xxx_timer, 1); |
| 1782 | |
| 1783 | set_bit(AF_INIT_DONE, &ha->flags); |
| 1784 | |
| 1785 | pci_set_drvdata(pdev, ha); |
| 1786 | |
| 1787 | ret = scsi_add_host(host, &pdev->dev); |
| 1788 | if (ret) |
| 1789 | goto probe_failed; |
| 1790 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1791 | printk(KERN_INFO |
| 1792 | " QLogic iSCSI HBA Driver version: %s\n" |
| 1793 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", |
| 1794 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), |
| 1795 | ha->host_no, ha->firmware_version[0], ha->firmware_version[1], |
| 1796 | ha->patch_number, ha->build_number); |
Mike Christie | 921601b | 2008-01-31 13:36:49 -0600 | [diff] [blame] | 1797 | scsi_scan_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1798 | return 0; |
| 1799 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1800 | probe_failed: |
| 1801 | qla4xxx_free_adapter(ha); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1802 | |
| 1803 | probe_failed_ioconfig: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1804 | pci_disable_pcie_error_reporting(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1805 | scsi_host_put(ha->host); |
| 1806 | |
| 1807 | probe_disable_device: |
| 1808 | pci_disable_device(pdev); |
| 1809 | |
| 1810 | return ret; |
| 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * qla4xxx_remove_adapter - calback function to remove adapter. |
| 1815 | * @pci_dev: PCI device pointer |
| 1816 | **/ |
| 1817 | static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev) |
| 1818 | { |
| 1819 | struct scsi_qla_host *ha; |
| 1820 | |
| 1821 | ha = pci_get_drvdata(pdev); |
| 1822 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1823 | set_bit(AF_HBA_GOING_AWAY, &ha->flags); |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 1824 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1825 | /* remove devs from iscsi_sessions to scsi_devices */ |
| 1826 | qla4xxx_free_ddb_list(ha); |
| 1827 | |
| 1828 | scsi_remove_host(ha->host); |
| 1829 | |
| 1830 | qla4xxx_free_adapter(ha); |
| 1831 | |
| 1832 | scsi_host_put(ha->host); |
| 1833 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1834 | pci_disable_pcie_error_reporting(pdev); |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1835 | pci_disable_device(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1836 | pci_set_drvdata(pdev, NULL); |
| 1837 | } |
| 1838 | |
| 1839 | /** |
| 1840 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. |
| 1841 | * @ha: HA context |
| 1842 | * |
| 1843 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 1844 | * supported addressing method. |
| 1845 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 1846 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1847 | { |
| 1848 | int retval; |
| 1849 | |
| 1850 | /* Update our PCI device dma_mask for full 64 bit mask */ |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1851 | if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) { |
| 1852 | if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1853 | dev_dbg(&ha->pdev->dev, |
| 1854 | "Failed to set 64 bit PCI consistent mask; " |
| 1855 | "using 32 bit.\n"); |
| 1856 | retval = pci_set_consistent_dma_mask(ha->pdev, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1857 | DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1858 | } |
| 1859 | } else |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1860 | retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) |
| 1864 | { |
| 1865 | struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target); |
| 1866 | struct ddb_entry *ddb = sess->dd_data; |
| 1867 | |
| 1868 | sdev->hostdata = ddb; |
| 1869 | sdev->tagged_supported = 1; |
Mike Christie | d510d96 | 2008-07-11 19:50:33 -0500 | [diff] [blame] | 1870 | scsi_activate_tcq(sdev, QL4_DEF_QDEPTH); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1871 | return 0; |
| 1872 | } |
| 1873 | |
| 1874 | static int qla4xxx_slave_configure(struct scsi_device *sdev) |
| 1875 | { |
| 1876 | sdev->tagged_supported = 1; |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
| 1880 | static void qla4xxx_slave_destroy(struct scsi_device *sdev) |
| 1881 | { |
| 1882 | scsi_deactivate_tcq(sdev, 1); |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * qla4xxx_del_from_active_array - returns an active srb |
| 1887 | * @ha: Pointer to host adapter structure. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1888 | * @index: index into the active_array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1889 | * |
| 1890 | * This routine removes and returns the srb at the specified index |
| 1891 | **/ |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1892 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
| 1893 | uint32_t index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1894 | { |
| 1895 | struct srb *srb = NULL; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1896 | struct scsi_cmnd *cmd = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1897 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1898 | cmd = scsi_host_find_tag(ha->host, index); |
| 1899 | if (!cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1900 | return srb; |
| 1901 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1902 | srb = (struct srb *)CMD_SP(cmd); |
| 1903 | if (!srb) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1904 | return srb; |
| 1905 | |
| 1906 | /* update counters */ |
| 1907 | if (srb->flags & SRB_DMA_VALID) { |
| 1908 | ha->req_q_count += srb->iocb_cnt; |
| 1909 | ha->iocb_cnt -= srb->iocb_cnt; |
| 1910 | if (srb->cmd) |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1911 | srb->cmd->host_scribble = |
| 1912 | (unsigned char *)(unsigned long) MAX_SRBS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1913 | } |
| 1914 | return srb; |
| 1915 | } |
| 1916 | |
| 1917 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1918 | * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 1919 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1920 | * @cmd: Scsi Command to wait on. |
| 1921 | * |
| 1922 | * This routine waits for the command to be returned by the Firmware |
| 1923 | * for some max time. |
| 1924 | **/ |
| 1925 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, |
| 1926 | struct scsi_cmnd *cmd) |
| 1927 | { |
| 1928 | int done = 0; |
| 1929 | struct srb *rp; |
| 1930 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1931 | int ret = SUCCESS; |
| 1932 | |
| 1933 | /* Dont wait on command if PCI error is being handled |
| 1934 | * by PCI AER driver |
| 1935 | */ |
| 1936 | if (unlikely(pci_channel_offline(ha->pdev)) || |
| 1937 | (test_bit(AF_EEH_BUSY, &ha->flags))) { |
| 1938 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", |
| 1939 | ha->host_no, __func__); |
| 1940 | return ret; |
| 1941 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1942 | |
| 1943 | do { |
| 1944 | /* Checking to see if its returned to OS */ |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1945 | rp = (struct srb *) CMD_SP(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1946 | if (rp == NULL) { |
| 1947 | done++; |
| 1948 | break; |
| 1949 | } |
| 1950 | |
| 1951 | msleep(2000); |
| 1952 | } while (max_wait_time--); |
| 1953 | |
| 1954 | return done; |
| 1955 | } |
| 1956 | |
| 1957 | /** |
| 1958 | * qla4xxx_wait_for_hba_online - waits for HBA to come online |
| 1959 | * @ha: Pointer to host adapter structure |
| 1960 | **/ |
| 1961 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) |
| 1962 | { |
| 1963 | unsigned long wait_online; |
| 1964 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 1965 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1966 | while (time_before(jiffies, wait_online)) { |
| 1967 | |
| 1968 | if (adapter_up(ha)) |
| 1969 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1970 | |
| 1971 | msleep(2000); |
| 1972 | } |
| 1973 | |
| 1974 | return QLA_ERROR; |
| 1975 | } |
| 1976 | |
| 1977 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 1978 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1979 | * @ha: pointer to HBA |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1980 | * @t: target id |
| 1981 | * @l: lun id |
| 1982 | * |
| 1983 | * This function waits for all outstanding commands to a lun to complete. It |
| 1984 | * returns 0 if all pending commands are returned and 1 otherwise. |
| 1985 | **/ |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 1986 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
| 1987 | struct scsi_target *stgt, |
| 1988 | struct scsi_device *sdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1989 | { |
| 1990 | int cnt; |
| 1991 | int status = 0; |
| 1992 | struct scsi_cmnd *cmd; |
| 1993 | |
| 1994 | /* |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 1995 | * Waiting for all commands for the designated target or dev |
| 1996 | * in the active array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1997 | */ |
| 1998 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { |
| 1999 | cmd = scsi_host_find_tag(ha->host, cnt); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2000 | if (cmd && stgt == scsi_target(cmd->device) && |
| 2001 | (!sdev || sdev == cmd->device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2002 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 2003 | status++; |
| 2004 | break; |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | return status; |
| 2009 | } |
| 2010 | |
| 2011 | /** |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2012 | * qla4xxx_eh_abort - callback for abort task. |
| 2013 | * @cmd: Pointer to Linux's SCSI command structure |
| 2014 | * |
| 2015 | * This routine is called by the Linux OS to abort the specified |
| 2016 | * command. |
| 2017 | **/ |
| 2018 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) |
| 2019 | { |
| 2020 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 2021 | unsigned int id = cmd->device->id; |
| 2022 | unsigned int lun = cmd->device->lun; |
| 2023 | unsigned long serial = cmd->serial_number; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 2024 | unsigned long flags; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2025 | struct srb *srb = NULL; |
| 2026 | int ret = SUCCESS; |
| 2027 | int wait = 0; |
| 2028 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2029 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2030 | "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n", |
| 2031 | ha->host_no, id, lun, cmd, serial); |
| 2032 | |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 2033 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2034 | srb = (struct srb *) CMD_SP(cmd); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 2035 | if (!srb) { |
| 2036 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2037 | return SUCCESS; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 2038 | } |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2039 | kref_get(&srb->srb_ref); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 2040 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2041 | |
| 2042 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { |
| 2043 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", |
| 2044 | ha->host_no, id, lun)); |
| 2045 | ret = FAILED; |
| 2046 | } else { |
| 2047 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n", |
| 2048 | ha->host_no, id, lun)); |
| 2049 | wait = 1; |
| 2050 | } |
| 2051 | |
| 2052 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| 2053 | |
| 2054 | /* Wait for command to complete */ |
| 2055 | if (wait) { |
| 2056 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 2057 | DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n", |
| 2058 | ha->host_no, id, lun)); |
| 2059 | ret = FAILED; |
| 2060 | } |
| 2061 | } |
| 2062 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2063 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2064 | "scsi%ld:%d:%d: Abort command - %s\n", |
| 2065 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeded" : "failed"); |
| 2066 | |
| 2067 | return ret; |
| 2068 | } |
| 2069 | |
| 2070 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2071 | * qla4xxx_eh_device_reset - callback for target reset. |
| 2072 | * @cmd: Pointer to Linux's SCSI command structure |
| 2073 | * |
| 2074 | * This routine is called by the Linux OS to reset all luns on the |
| 2075 | * specified target. |
| 2076 | **/ |
| 2077 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 2078 | { |
| 2079 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 2080 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2081 | int ret = FAILED, stat; |
| 2082 | |
Karen Higgins | 612f734 | 2009-07-15 15:03:01 -0500 | [diff] [blame] | 2083 | if (!ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2084 | return ret; |
| 2085 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 2086 | ret = iscsi_block_scsi_eh(cmd); |
| 2087 | if (ret) |
| 2088 | return ret; |
| 2089 | ret = FAILED; |
| 2090 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2091 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2092 | "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no, |
| 2093 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 2094 | |
| 2095 | DEBUG2(printk(KERN_INFO |
| 2096 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," |
| 2097 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2098 | cmd, jiffies, cmd->request->timeout / HZ, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2099 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 2100 | |
| 2101 | /* FIXME: wait for hba to go online */ |
| 2102 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); |
| 2103 | if (stat != QLA_SUCCESS) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2104 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2105 | goto eh_dev_reset_done; |
| 2106 | } |
| 2107 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2108 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 2109 | cmd->device)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2110 | ql4_printk(KERN_INFO, ha, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2111 | "DEVICE RESET FAILED - waiting for " |
| 2112 | "commands.\n"); |
| 2113 | goto eh_dev_reset_done; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 2116 | /* Send marker. */ |
| 2117 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 2118 | MM_LUN_RESET) != QLA_SUCCESS) |
| 2119 | goto eh_dev_reset_done; |
| 2120 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2121 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2122 | "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n", |
| 2123 | ha->host_no, cmd->device->channel, cmd->device->id, |
| 2124 | cmd->device->lun); |
| 2125 | |
| 2126 | ret = SUCCESS; |
| 2127 | |
| 2128 | eh_dev_reset_done: |
| 2129 | |
| 2130 | return ret; |
| 2131 | } |
| 2132 | |
| 2133 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2134 | * qla4xxx_eh_target_reset - callback for target reset. |
| 2135 | * @cmd: Pointer to Linux's SCSI command structure |
| 2136 | * |
| 2137 | * This routine is called by the Linux OS to reset the target. |
| 2138 | **/ |
| 2139 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) |
| 2140 | { |
| 2141 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 2142 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 2143 | int stat, ret; |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2144 | |
| 2145 | if (!ddb_entry) |
| 2146 | return FAILED; |
| 2147 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 2148 | ret = iscsi_block_scsi_eh(cmd); |
| 2149 | if (ret) |
| 2150 | return ret; |
| 2151 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2152 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 2153 | "WARM TARGET RESET ISSUED.\n"); |
| 2154 | |
| 2155 | DEBUG2(printk(KERN_INFO |
| 2156 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " |
| 2157 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2158 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2159 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 2160 | |
| 2161 | stat = qla4xxx_reset_target(ha, ddb_entry); |
| 2162 | if (stat != QLA_SUCCESS) { |
| 2163 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 2164 | "WARM TARGET RESET FAILED.\n"); |
| 2165 | return FAILED; |
| 2166 | } |
| 2167 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2168 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 2169 | NULL)) { |
| 2170 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 2171 | "WARM TARGET DEVICE RESET FAILED - " |
| 2172 | "waiting for commands.\n"); |
| 2173 | return FAILED; |
| 2174 | } |
| 2175 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 2176 | /* Send marker. */ |
| 2177 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 2178 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { |
| 2179 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 2180 | "WARM TARGET DEVICE RESET FAILED - " |
| 2181 | "marker iocb failed.\n"); |
| 2182 | return FAILED; |
| 2183 | } |
| 2184 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 2185 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 2186 | "WARM TARGET RESET SUCCEEDED.\n"); |
| 2187 | return SUCCESS; |
| 2188 | } |
| 2189 | |
| 2190 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2191 | * qla4xxx_eh_host_reset - kernel callback |
| 2192 | * @cmd: Pointer to Linux's SCSI command structure |
| 2193 | * |
| 2194 | * This routine is invoked by the Linux kernel to perform fatal error |
| 2195 | * recovery on the specified adapter. |
| 2196 | **/ |
| 2197 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 2198 | { |
| 2199 | int return_status = FAILED; |
| 2200 | struct scsi_qla_host *ha; |
| 2201 | |
| 2202 | ha = (struct scsi_qla_host *) cmd->device->host->hostdata; |
| 2203 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2204 | if (ql4xdontresethba) { |
| 2205 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 2206 | ha->host_no, __func__)); |
| 2207 | return FAILED; |
| 2208 | } |
| 2209 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2210 | ql4_printk(KERN_INFO, ha, |
Karen Higgins | dca05c4 | 2009-07-15 15:03:00 -0500 | [diff] [blame] | 2211 | "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2212 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 2213 | |
| 2214 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 2215 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " |
| 2216 | "DEAD.\n", ha->host_no, cmd->device->channel, |
| 2217 | __func__)); |
| 2218 | |
| 2219 | return FAILED; |
| 2220 | } |
| 2221 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2222 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| 2223 | if (is_qla8022(ha)) |
| 2224 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 2225 | else |
| 2226 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2227 | } |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 2228 | |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2229 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2230 | return_status = SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2231 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2232 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2233 | return_status == FAILED ? "FAILED" : "SUCCEDED"); |
| 2234 | |
| 2235 | return return_status; |
| 2236 | } |
| 2237 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2238 | /* PCI AER driver recovers from all correctable errors w/o |
| 2239 | * driver intervention. For uncorrectable errors PCI AER |
| 2240 | * driver calls the following device driver's callbacks |
| 2241 | * |
| 2242 | * - Fatal Errors - link_reset |
| 2243 | * - Non-Fatal Errors - driver's pci_error_detected() which |
| 2244 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. |
| 2245 | * |
| 2246 | * PCI AER driver calls |
| 2247 | * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled |
| 2248 | * returns RECOVERED or NEED_RESET if fw_hung |
| 2249 | * NEED_RESET - driver's slot_reset() |
| 2250 | * DISCONNECT - device is dead & cannot recover |
| 2251 | * RECOVERED - driver's pci_resume() |
| 2252 | */ |
| 2253 | static pci_ers_result_t |
| 2254 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 2255 | { |
| 2256 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 2257 | |
| 2258 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", |
| 2259 | ha->host_no, __func__, state); |
| 2260 | |
| 2261 | if (!is_aer_supported(ha)) |
| 2262 | return PCI_ERS_RESULT_NONE; |
| 2263 | |
| 2264 | switch (state) { |
| 2265 | case pci_channel_io_normal: |
| 2266 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 2267 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 2268 | case pci_channel_io_frozen: |
| 2269 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 2270 | qla4xxx_mailbox_premature_completion(ha); |
| 2271 | qla4xxx_free_irqs(ha); |
| 2272 | pci_disable_device(pdev); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2273 | /* Return back all IOs */ |
| 2274 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2275 | return PCI_ERS_RESULT_NEED_RESET; |
| 2276 | case pci_channel_io_perm_failure: |
| 2277 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 2278 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); |
| 2279 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 2280 | return PCI_ERS_RESULT_DISCONNECT; |
| 2281 | } |
| 2282 | return PCI_ERS_RESULT_NEED_RESET; |
| 2283 | } |
| 2284 | |
| 2285 | /** |
| 2286 | * qla4xxx_pci_mmio_enabled() gets called if |
| 2287 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER |
| 2288 | * and read/write to the device still works. |
| 2289 | **/ |
| 2290 | static pci_ers_result_t |
| 2291 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 2292 | { |
| 2293 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 2294 | |
| 2295 | if (!is_aer_supported(ha)) |
| 2296 | return PCI_ERS_RESULT_NONE; |
| 2297 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2298 | return PCI_ERS_RESULT_RECOVERED; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2299 | } |
| 2300 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2301 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2302 | { |
| 2303 | uint32_t rval = QLA_ERROR; |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2304 | uint32_t ret = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2305 | int fn; |
| 2306 | struct pci_dev *other_pdev = NULL; |
| 2307 | |
| 2308 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); |
| 2309 | |
| 2310 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 2311 | |
| 2312 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 2313 | clear_bit(AF_ONLINE, &ha->flags); |
| 2314 | qla4xxx_mark_all_devices_missing(ha); |
| 2315 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | fn = PCI_FUNC(ha->pdev->devfn); |
| 2319 | while (fn > 0) { |
| 2320 | fn--; |
| 2321 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at " |
| 2322 | "func %x\n", ha->host_no, __func__, fn); |
| 2323 | /* Get the pci device given the domain, bus, |
| 2324 | * slot/function number */ |
| 2325 | other_pdev = |
| 2326 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 2327 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 2328 | fn)); |
| 2329 | |
| 2330 | if (!other_pdev) |
| 2331 | continue; |
| 2332 | |
| 2333 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 2334 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI " |
| 2335 | "func in enabled state%x\n", ha->host_no, |
| 2336 | __func__, fn); |
| 2337 | pci_dev_put(other_pdev); |
| 2338 | break; |
| 2339 | } |
| 2340 | pci_dev_put(other_pdev); |
| 2341 | } |
| 2342 | |
| 2343 | /* The first function on the card, the reset owner will |
| 2344 | * start & initialize the firmware. The other functions |
| 2345 | * on the card will reset the firmware context |
| 2346 | */ |
| 2347 | if (!fn) { |
| 2348 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " |
| 2349 | "0x%x is the owner\n", ha->host_no, __func__, |
| 2350 | ha->pdev->devfn); |
| 2351 | |
| 2352 | qla4_8xxx_idc_lock(ha); |
| 2353 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 2354 | QLA82XX_DEV_COLD); |
| 2355 | |
| 2356 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION, |
| 2357 | QLA82XX_IDC_VERSION); |
| 2358 | |
| 2359 | qla4_8xxx_idc_unlock(ha); |
| 2360 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
| 2361 | rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST); |
| 2362 | qla4_8xxx_idc_lock(ha); |
| 2363 | |
| 2364 | if (rval != QLA_SUCCESS) { |
| 2365 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 2366 | "FAILED\n", ha->host_no, __func__); |
| 2367 | qla4_8xxx_clear_drv_active(ha); |
| 2368 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 2369 | QLA82XX_DEV_FAILED); |
| 2370 | } else { |
| 2371 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 2372 | "READY\n", ha->host_no, __func__); |
| 2373 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 2374 | QLA82XX_DEV_READY); |
| 2375 | /* Clear driver state register */ |
| 2376 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0); |
| 2377 | qla4_8xxx_set_drv_active(ha); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2378 | ret = qla4xxx_request_irqs(ha); |
| 2379 | if (ret) { |
| 2380 | ql4_printk(KERN_WARNING, ha, "Failed to " |
| 2381 | "reserve interrupt %d already in use.\n", |
| 2382 | ha->pdev->irq); |
| 2383 | rval = QLA_ERROR; |
| 2384 | } else { |
| 2385 | ha->isp_ops->enable_intrs(ha); |
| 2386 | rval = QLA_SUCCESS; |
| 2387 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2388 | } |
| 2389 | qla4_8xxx_idc_unlock(ha); |
| 2390 | } else { |
| 2391 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " |
| 2392 | "the reset owner\n", ha->host_no, __func__, |
| 2393 | ha->pdev->devfn); |
| 2394 | if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) == |
| 2395 | QLA82XX_DEV_READY)) { |
| 2396 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
| 2397 | rval = qla4xxx_initialize_adapter(ha, |
| 2398 | PRESERVE_DDB_LIST); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2399 | if (rval == QLA_SUCCESS) { |
| 2400 | ret = qla4xxx_request_irqs(ha); |
| 2401 | if (ret) { |
| 2402 | ql4_printk(KERN_WARNING, ha, "Failed to" |
| 2403 | " reserve interrupt %d already in" |
| 2404 | " use.\n", ha->pdev->irq); |
| 2405 | rval = QLA_ERROR; |
| 2406 | } else { |
| 2407 | ha->isp_ops->enable_intrs(ha); |
| 2408 | rval = QLA_SUCCESS; |
| 2409 | } |
| 2410 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2411 | qla4_8xxx_idc_lock(ha); |
| 2412 | qla4_8xxx_set_drv_active(ha); |
| 2413 | qla4_8xxx_idc_unlock(ha); |
| 2414 | } |
| 2415 | } |
| 2416 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 2417 | return rval; |
| 2418 | } |
| 2419 | |
| 2420 | static pci_ers_result_t |
| 2421 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) |
| 2422 | { |
| 2423 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 2424 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 2425 | int rc; |
| 2426 | |
| 2427 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", |
| 2428 | ha->host_no, __func__); |
| 2429 | |
| 2430 | if (!is_aer_supported(ha)) |
| 2431 | return PCI_ERS_RESULT_NONE; |
| 2432 | |
| 2433 | /* Restore the saved state of PCIe device - |
| 2434 | * BAR registers, PCI Config space, PCIX, MSI, |
| 2435 | * IOV states |
| 2436 | */ |
| 2437 | pci_restore_state(pdev); |
| 2438 | |
| 2439 | /* pci_restore_state() clears the saved_state flag of the device |
| 2440 | * save restored state which resets saved_state flag |
| 2441 | */ |
| 2442 | pci_save_state(pdev); |
| 2443 | |
| 2444 | /* Initialize device or resume if in suspended state */ |
| 2445 | rc = pci_enable_device(pdev); |
| 2446 | if (rc) { |
| 2447 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Cant re-enable " |
| 2448 | "device after reset\n", ha->host_no, __func__); |
| 2449 | goto exit_slot_reset; |
| 2450 | } |
| 2451 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 2452 | ha->isp_ops->disable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2453 | |
| 2454 | if (is_qla8022(ha)) { |
| 2455 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { |
| 2456 | ret = PCI_ERS_RESULT_RECOVERED; |
| 2457 | goto exit_slot_reset; |
| 2458 | } else |
| 2459 | goto exit_slot_reset; |
| 2460 | } |
| 2461 | |
| 2462 | exit_slot_reset: |
| 2463 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" |
| 2464 | "device after reset\n", ha->host_no, __func__, ret); |
| 2465 | return ret; |
| 2466 | } |
| 2467 | |
| 2468 | static void |
| 2469 | qla4xxx_pci_resume(struct pci_dev *pdev) |
| 2470 | { |
| 2471 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 2472 | int ret; |
| 2473 | |
| 2474 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", |
| 2475 | ha->host_no, __func__); |
| 2476 | |
| 2477 | ret = qla4xxx_wait_for_hba_online(ha); |
| 2478 | if (ret != QLA_SUCCESS) { |
| 2479 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " |
| 2480 | "resume I/O from slot/link_reset\n", ha->host_no, |
| 2481 | __func__); |
| 2482 | } |
| 2483 | |
| 2484 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 2485 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 2486 | } |
| 2487 | |
| 2488 | static struct pci_error_handlers qla4xxx_err_handler = { |
| 2489 | .error_detected = qla4xxx_pci_error_detected, |
| 2490 | .mmio_enabled = qla4xxx_pci_mmio_enabled, |
| 2491 | .slot_reset = qla4xxx_pci_slot_reset, |
| 2492 | .resume = qla4xxx_pci_resume, |
| 2493 | }; |
| 2494 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2495 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
| 2496 | { |
| 2497 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 2498 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, |
| 2499 | .subvendor = PCI_ANY_ID, |
| 2500 | .subdevice = PCI_ANY_ID, |
| 2501 | }, |
| 2502 | { |
| 2503 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 2504 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, |
| 2505 | .subvendor = PCI_ANY_ID, |
| 2506 | .subdevice = PCI_ANY_ID, |
| 2507 | }, |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 2508 | { |
| 2509 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 2510 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, |
| 2511 | .subvendor = PCI_ANY_ID, |
| 2512 | .subdevice = PCI_ANY_ID, |
| 2513 | }, |
Vikas Chaudhary | f4f5df2 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2514 | { |
| 2515 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 2516 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, |
| 2517 | .subvendor = PCI_ANY_ID, |
| 2518 | .subdevice = PCI_ANY_ID, |
| 2519 | }, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2520 | {0, 0}, |
| 2521 | }; |
| 2522 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); |
| 2523 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 2524 | static struct pci_driver qla4xxx_pci_driver = { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2525 | .name = DRIVER_NAME, |
| 2526 | .id_table = qla4xxx_pci_tbl, |
| 2527 | .probe = qla4xxx_probe_adapter, |
| 2528 | .remove = qla4xxx_remove_adapter, |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2529 | .err_handler = &qla4xxx_err_handler, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2530 | }; |
| 2531 | |
| 2532 | static int __init qla4xxx_module_init(void) |
| 2533 | { |
| 2534 | int ret; |
| 2535 | |
| 2536 | /* Allocate cache for SRBs. */ |
| 2537 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 2538 | SLAB_HWCACHE_ALIGN, NULL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2539 | if (srb_cachep == NULL) { |
| 2540 | printk(KERN_ERR |
| 2541 | "%s: Unable to allocate SRB cache..." |
| 2542 | "Failing load!\n", DRIVER_NAME); |
| 2543 | ret = -ENOMEM; |
| 2544 | goto no_srp_cache; |
| 2545 | } |
| 2546 | |
| 2547 | /* Derive version string. */ |
| 2548 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 2549 | if (ql4xextended_error_logging) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2550 | strcat(qla4xxx_version_str, "-debug"); |
| 2551 | |
| 2552 | qla4xxx_scsi_transport = |
| 2553 | iscsi_register_transport(&qla4xxx_iscsi_transport); |
| 2554 | if (!qla4xxx_scsi_transport){ |
| 2555 | ret = -ENODEV; |
| 2556 | goto release_srb_cache; |
| 2557 | } |
| 2558 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2559 | ret = pci_register_driver(&qla4xxx_pci_driver); |
| 2560 | if (ret) |
| 2561 | goto unregister_transport; |
| 2562 | |
| 2563 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); |
| 2564 | return 0; |
Doug Maxey | 5ae16db | 2006-10-05 23:50:07 -0500 | [diff] [blame] | 2565 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2566 | unregister_transport: |
| 2567 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 2568 | release_srb_cache: |
| 2569 | kmem_cache_destroy(srb_cachep); |
| 2570 | no_srp_cache: |
| 2571 | return ret; |
| 2572 | } |
| 2573 | |
| 2574 | static void __exit qla4xxx_module_exit(void) |
| 2575 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2576 | pci_unregister_driver(&qla4xxx_pci_driver); |
| 2577 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 2578 | kmem_cache_destroy(srb_cachep); |
| 2579 | } |
| 2580 | |
| 2581 | module_init(qla4xxx_module_init); |
| 2582 | module_exit(qla4xxx_module_exit); |
| 2583 | |
| 2584 | MODULE_AUTHOR("QLogic Corporation"); |
| 2585 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); |
| 2586 | MODULE_LICENSE("GPL"); |
| 2587 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |