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