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