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