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