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