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