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