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