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