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