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