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> |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 11 | #include <linux/inet.h> |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 12 | |
| 13 | #include <scsi/scsi_tcq.h> |
| 14 | #include <scsi/scsicam.h> |
| 15 | |
| 16 | #include "ql4_def.h" |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 17 | #include "ql4_version.h" |
| 18 | #include "ql4_glbl.h" |
| 19 | #include "ql4_dbg.h" |
| 20 | #include "ql4_inline.h" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * Driver version |
| 24 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 25 | static char qla4xxx_version_str[40]; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * SRB allocation cache |
| 29 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 30 | static struct kmem_cache *srb_cachep; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Module parameter information and variables |
| 34 | */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 35 | int ql4xdisablesysfsboot = 1; |
| 36 | module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR); |
| 37 | MODULE_PARM_DESC(ql4xdisablesysfsboot, |
| 38 | "Set to disable exporting boot targets to sysfs\n" |
| 39 | " 0 - Export boot targets\n" |
| 40 | " 1 - Do not export boot targets (Default)"); |
| 41 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 42 | int ql4xdontresethba = 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 43 | module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 44 | MODULE_PARM_DESC(ql4xdontresethba, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 45 | "Don't reset the HBA for driver recovery \n" |
| 46 | " 0 - It will reset HBA (Default)\n" |
| 47 | " 1 - It will NOT reset HBA"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 48 | |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 49 | int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 50 | module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 51 | MODULE_PARM_DESC(ql4xextended_error_logging, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 52 | "Option to enable extended error logging, " |
| 53 | "Default is 0 - no logging, 1 - debug logging"); |
| 54 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 55 | int ql4xenablemsix = 1; |
| 56 | module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR); |
| 57 | MODULE_PARM_DESC(ql4xenablemsix, |
| 58 | "Set to enable MSI or MSI-X interrupt mechanism.\n" |
| 59 | " 0 = enable INTx interrupt mechanism.\n" |
| 60 | " 1 = enable MSI-X interrupt mechanism (Default).\n" |
| 61 | " 2 = enable MSI interrupt mechanism."); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 62 | |
Mike Christie | d510d96 | 2008-07-11 19:50:33 -0500 | [diff] [blame] | 63 | #define QL4_DEF_QDEPTH 32 |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 64 | static int ql4xmaxqdepth = QL4_DEF_QDEPTH; |
| 65 | module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR); |
| 66 | MODULE_PARM_DESC(ql4xmaxqdepth, |
| 67 | "Maximum queue depth to report for target devices.\n" |
| 68 | " Default: 32."); |
Mike Christie | d510d96 | 2008-07-11 19:50:33 -0500 | [diff] [blame] | 69 | |
Vikas Chaudhary | 3038727 | 2011-03-21 03:34:32 -0700 | [diff] [blame] | 70 | static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO; |
| 71 | module_param(ql4xsess_recovery_tmo, int, S_IRUGO); |
| 72 | MODULE_PARM_DESC(ql4xsess_recovery_tmo, |
| 73 | "Target Session Recovery Timeout.\n" |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 74 | " Default: 120 sec."); |
Vikas Chaudhary | 3038727 | 2011-03-21 03:34:32 -0700 | [diff] [blame] | 75 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 76 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 77 | /* |
| 78 | * SCSI host template entry points |
| 79 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 80 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * iSCSI template entry points |
| 84 | */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 85 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
| 86 | enum iscsi_param param, char *buf); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 87 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 88 | enum iscsi_host_param param, char *buf); |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 89 | static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, |
| 90 | uint32_t len); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 91 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 92 | enum iscsi_param_type param_type, |
| 93 | int param, char *buf); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 94 | 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] | 95 | static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost, |
| 96 | struct sockaddr *dst_addr, |
| 97 | int non_blocking); |
| 98 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms); |
| 99 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep); |
| 100 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 101 | enum iscsi_param param, char *buf); |
| 102 | static int qla4xxx_conn_start(struct iscsi_cls_conn *conn); |
| 103 | static struct iscsi_cls_conn * |
| 104 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx); |
| 105 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 106 | struct iscsi_cls_conn *cls_conn, |
| 107 | uint64_t transport_fd, int is_leading); |
| 108 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn); |
| 109 | static struct iscsi_cls_session * |
| 110 | qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, |
| 111 | uint16_t qdepth, uint32_t initial_cmdsn); |
| 112 | static void qla4xxx_session_destroy(struct iscsi_cls_session *sess); |
| 113 | static void qla4xxx_task_work(struct work_struct *wdata); |
| 114 | static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t); |
| 115 | static int qla4xxx_task_xmit(struct iscsi_task *); |
| 116 | static void qla4xxx_task_cleanup(struct iscsi_task *); |
| 117 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session); |
| 118 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 119 | struct iscsi_stats *stats); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 120 | /* |
| 121 | * SCSI host template entry points |
| 122 | */ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 123 | static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 124 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 125 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 126 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 127 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); |
| 128 | static int qla4xxx_slave_alloc(struct scsi_device *device); |
| 129 | static int qla4xxx_slave_configure(struct scsi_device *device); |
| 130 | static void qla4xxx_slave_destroy(struct scsi_device *sdev); |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 131 | static umode_t ql4_attr_is_visible(int param_type, int param); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 132 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 133 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 134 | static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
| 135 | QLA82XX_LEGACY_INTR_CONFIG; |
| 136 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 137 | static struct scsi_host_template qla4xxx_driver_template = { |
| 138 | .module = THIS_MODULE, |
| 139 | .name = DRIVER_NAME, |
| 140 | .proc_name = DRIVER_NAME, |
| 141 | .queuecommand = qla4xxx_queuecommand, |
| 142 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 143 | .eh_abort_handler = qla4xxx_eh_abort, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 144 | .eh_device_reset_handler = qla4xxx_eh_device_reset, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 145 | .eh_target_reset_handler = qla4xxx_eh_target_reset, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 146 | .eh_host_reset_handler = qla4xxx_eh_host_reset, |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 147 | .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 148 | |
| 149 | .slave_configure = qla4xxx_slave_configure, |
| 150 | .slave_alloc = qla4xxx_slave_alloc, |
| 151 | .slave_destroy = qla4xxx_slave_destroy, |
| 152 | |
| 153 | .this_id = -1, |
| 154 | .cmd_per_lun = 3, |
| 155 | .use_clustering = ENABLE_CLUSTERING, |
| 156 | .sg_tablesize = SG_ALL, |
| 157 | |
| 158 | .max_sectors = 0xFFFF, |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 159 | .shost_attrs = qla4xxx_host_attrs, |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 160 | .host_reset = qla4xxx_host_reset, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 161 | .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static struct iscsi_transport qla4xxx_iscsi_transport = { |
| 165 | .owner = THIS_MODULE, |
| 166 | .name = DRIVER_NAME, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 167 | .caps = CAP_TEXT_NEGO | |
| 168 | CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST | |
| 169 | CAP_DATADGST | CAP_LOGIN_OFFLOAD | |
| 170 | CAP_MULTI_R2T, |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 171 | .attr_is_visible = ql4_attr_is_visible, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 172 | .create_session = qla4xxx_session_create, |
| 173 | .destroy_session = qla4xxx_session_destroy, |
| 174 | .start_conn = qla4xxx_conn_start, |
| 175 | .create_conn = qla4xxx_conn_create, |
| 176 | .bind_conn = qla4xxx_conn_bind, |
| 177 | .stop_conn = iscsi_conn_stop, |
| 178 | .destroy_conn = qla4xxx_conn_destroy, |
| 179 | .set_param = iscsi_set_param, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 180 | .get_conn_param = qla4xxx_conn_get_param, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 181 | .get_session_param = iscsi_session_get_param, |
| 182 | .get_ep_param = qla4xxx_get_ep_param, |
| 183 | .ep_connect = qla4xxx_ep_connect, |
| 184 | .ep_poll = qla4xxx_ep_poll, |
| 185 | .ep_disconnect = qla4xxx_ep_disconnect, |
| 186 | .get_stats = qla4xxx_conn_get_stats, |
| 187 | .send_pdu = iscsi_conn_send_pdu, |
| 188 | .xmit_task = qla4xxx_task_xmit, |
| 189 | .cleanup_task = qla4xxx_task_cleanup, |
| 190 | .alloc_pdu = qla4xxx_alloc_pdu, |
| 191 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 192 | .get_host_param = qla4xxx_host_get_param, |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 193 | .set_iface_param = qla4xxx_iface_set_param, |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 194 | .get_iface_param = qla4xxx_get_iface_param, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 195 | .bsg_request = qla4xxx_bsg_request, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | static struct scsi_transport_template *qla4xxx_scsi_transport; |
| 199 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 200 | static umode_t ql4_attr_is_visible(int param_type, int param) |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 201 | { |
| 202 | switch (param_type) { |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 203 | case ISCSI_HOST_PARAM: |
| 204 | switch (param) { |
| 205 | case ISCSI_HOST_PARAM_HWADDRESS: |
| 206 | case ISCSI_HOST_PARAM_IPADDRESS: |
| 207 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
| 208 | return S_IRUGO; |
| 209 | default: |
| 210 | return 0; |
| 211 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 212 | case ISCSI_PARAM: |
| 213 | switch (param) { |
Mike Christie | 590134f | 2011-10-17 22:42:13 -0500 | [diff] [blame] | 214 | case ISCSI_PARAM_PERSISTENT_ADDRESS: |
| 215 | case ISCSI_PARAM_PERSISTENT_PORT: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 216 | case ISCSI_PARAM_CONN_ADDRESS: |
| 217 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 218 | case ISCSI_PARAM_TARGET_NAME: |
| 219 | case ISCSI_PARAM_TPGT: |
| 220 | case ISCSI_PARAM_TARGET_ALIAS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 221 | case ISCSI_PARAM_MAX_BURST: |
| 222 | case ISCSI_PARAM_MAX_R2T: |
| 223 | case ISCSI_PARAM_FIRST_BURST: |
| 224 | case ISCSI_PARAM_MAX_RECV_DLENGTH: |
| 225 | case ISCSI_PARAM_MAX_XMIT_DLENGTH: |
Mike Christie | de37920 | 2011-08-14 20:42:56 -0500 | [diff] [blame] | 226 | case ISCSI_PARAM_IFACE_NAME: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 227 | return S_IRUGO; |
| 228 | default: |
| 229 | return 0; |
| 230 | } |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 231 | case ISCSI_NET_PARAM: |
| 232 | switch (param) { |
| 233 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 234 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 235 | case ISCSI_NET_PARAM_IPV4_GW: |
| 236 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 237 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 238 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 239 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 240 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 241 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 242 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 243 | case ISCSI_NET_PARAM_VLAN_ID: |
| 244 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 245 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 246 | case ISCSI_NET_PARAM_MTU: |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 247 | case ISCSI_NET_PARAM_PORT: |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 248 | return S_IRUGO; |
| 249 | default: |
| 250 | return 0; |
| 251 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 257 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 258 | enum iscsi_param_type param_type, |
| 259 | int param, char *buf) |
| 260 | { |
| 261 | struct Scsi_Host *shost = iscsi_iface_to_shost(iface); |
| 262 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 263 | int len = -ENOSYS; |
| 264 | |
| 265 | if (param_type != ISCSI_NET_PARAM) |
| 266 | return -ENOSYS; |
| 267 | |
| 268 | switch (param) { |
| 269 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 270 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| 271 | break; |
| 272 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 273 | len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask); |
| 274 | break; |
| 275 | case ISCSI_NET_PARAM_IPV4_GW: |
| 276 | len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); |
| 277 | break; |
| 278 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 279 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 280 | len = sprintf(buf, "%s\n", |
| 281 | (ha->ip_config.ipv4_options & |
| 282 | IPOPT_IPV4_PROTOCOL_ENABLE) ? |
| 283 | "enabled" : "disabled"); |
| 284 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 285 | len = sprintf(buf, "%s\n", |
| 286 | (ha->ip_config.ipv6_options & |
| 287 | IPV6_OPT_IPV6_PROTOCOL_ENABLE) ? |
| 288 | "enabled" : "disabled"); |
| 289 | break; |
| 290 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 291 | len = sprintf(buf, "%s\n", |
| 292 | (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ? |
| 293 | "dhcp" : "static"); |
| 294 | break; |
| 295 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 296 | if (iface->iface_num == 0) |
| 297 | len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0); |
| 298 | if (iface->iface_num == 1) |
| 299 | len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1); |
| 300 | break; |
| 301 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 302 | len = sprintf(buf, "%pI6\n", |
| 303 | &ha->ip_config.ipv6_link_local_addr); |
| 304 | break; |
| 305 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 306 | len = sprintf(buf, "%pI6\n", |
| 307 | &ha->ip_config.ipv6_default_router_addr); |
| 308 | break; |
| 309 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 310 | len = sprintf(buf, "%s\n", |
| 311 | (ha->ip_config.ipv6_addl_options & |
| 312 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? |
| 313 | "nd" : "static"); |
| 314 | break; |
| 315 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 316 | len = sprintf(buf, "%s\n", |
| 317 | (ha->ip_config.ipv6_addl_options & |
| 318 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? |
| 319 | "auto" : "static"); |
| 320 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 321 | case ISCSI_NET_PARAM_VLAN_ID: |
| 322 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 323 | len = sprintf(buf, "%d\n", |
| 324 | (ha->ip_config.ipv4_vlan_tag & |
| 325 | ISCSI_MAX_VLAN_ID)); |
| 326 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 327 | len = sprintf(buf, "%d\n", |
| 328 | (ha->ip_config.ipv6_vlan_tag & |
| 329 | ISCSI_MAX_VLAN_ID)); |
| 330 | break; |
| 331 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 332 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 333 | len = sprintf(buf, "%d\n", |
| 334 | ((ha->ip_config.ipv4_vlan_tag >> 13) & |
| 335 | ISCSI_MAX_VLAN_PRIORITY)); |
| 336 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 337 | len = sprintf(buf, "%d\n", |
| 338 | ((ha->ip_config.ipv6_vlan_tag >> 13) & |
| 339 | ISCSI_MAX_VLAN_PRIORITY)); |
| 340 | break; |
| 341 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 342 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 343 | len = sprintf(buf, "%s\n", |
| 344 | (ha->ip_config.ipv4_options & |
| 345 | IPOPT_VLAN_TAGGING_ENABLE) ? |
| 346 | "enabled" : "disabled"); |
| 347 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 348 | len = sprintf(buf, "%s\n", |
| 349 | (ha->ip_config.ipv6_options & |
| 350 | IPV6_OPT_VLAN_TAGGING_ENABLE) ? |
| 351 | "enabled" : "disabled"); |
| 352 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 353 | case ISCSI_NET_PARAM_MTU: |
| 354 | len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size); |
| 355 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 356 | case ISCSI_NET_PARAM_PORT: |
| 357 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 358 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port); |
| 359 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 360 | len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port); |
| 361 | break; |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 362 | default: |
| 363 | len = -ENOSYS; |
| 364 | } |
| 365 | |
| 366 | return len; |
| 367 | } |
| 368 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 369 | static struct iscsi_endpoint * |
| 370 | qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, |
| 371 | int non_blocking) |
| 372 | { |
| 373 | int ret; |
| 374 | struct iscsi_endpoint *ep; |
| 375 | struct qla_endpoint *qla_ep; |
| 376 | struct scsi_qla_host *ha; |
| 377 | struct sockaddr_in *addr; |
| 378 | struct sockaddr_in6 *addr6; |
| 379 | |
| 380 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 381 | if (!shost) { |
| 382 | ret = -ENXIO; |
| 383 | printk(KERN_ERR "%s: shost is NULL\n", |
| 384 | __func__); |
| 385 | return ERR_PTR(ret); |
| 386 | } |
| 387 | |
| 388 | ha = iscsi_host_priv(shost); |
| 389 | |
| 390 | ep = iscsi_create_endpoint(sizeof(struct qla_endpoint)); |
| 391 | if (!ep) { |
| 392 | ret = -ENOMEM; |
| 393 | return ERR_PTR(ret); |
| 394 | } |
| 395 | |
| 396 | qla_ep = ep->dd_data; |
| 397 | memset(qla_ep, 0, sizeof(struct qla_endpoint)); |
| 398 | if (dst_addr->sa_family == AF_INET) { |
| 399 | memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in)); |
| 400 | addr = (struct sockaddr_in *)&qla_ep->dst_addr; |
| 401 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__, |
| 402 | (char *)&addr->sin_addr)); |
| 403 | } else if (dst_addr->sa_family == AF_INET6) { |
| 404 | memcpy(&qla_ep->dst_addr, dst_addr, |
| 405 | sizeof(struct sockaddr_in6)); |
| 406 | addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr; |
| 407 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__, |
| 408 | (char *)&addr6->sin6_addr)); |
| 409 | } |
| 410 | |
| 411 | qla_ep->host = shost; |
| 412 | |
| 413 | return ep; |
| 414 | } |
| 415 | |
| 416 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) |
| 417 | { |
| 418 | struct qla_endpoint *qla_ep; |
| 419 | struct scsi_qla_host *ha; |
| 420 | int ret = 0; |
| 421 | |
| 422 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 423 | qla_ep = ep->dd_data; |
| 424 | ha = to_qla_host(qla_ep->host); |
| 425 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 426 | if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags)) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 427 | ret = 1; |
| 428 | |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep) |
| 433 | { |
| 434 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 435 | iscsi_destroy_endpoint(ep); |
| 436 | } |
| 437 | |
| 438 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 439 | enum iscsi_param param, |
| 440 | char *buf) |
| 441 | { |
| 442 | struct qla_endpoint *qla_ep = ep->dd_data; |
| 443 | struct sockaddr *dst_addr; |
| 444 | |
| 445 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 446 | |
| 447 | switch (param) { |
| 448 | case ISCSI_PARAM_CONN_PORT: |
| 449 | case ISCSI_PARAM_CONN_ADDRESS: |
| 450 | if (!qla_ep) |
| 451 | return -ENOTCONN; |
| 452 | |
| 453 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 454 | if (!dst_addr) |
| 455 | return -ENOTCONN; |
| 456 | |
| 457 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 458 | &qla_ep->dst_addr, param, buf); |
| 459 | default: |
| 460 | return -ENOSYS; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 465 | struct iscsi_stats *stats) |
| 466 | { |
| 467 | struct iscsi_session *sess; |
| 468 | struct iscsi_cls_session *cls_sess; |
| 469 | struct ddb_entry *ddb_entry; |
| 470 | struct scsi_qla_host *ha; |
| 471 | struct ql_iscsi_stats *ql_iscsi_stats; |
| 472 | int stats_size; |
| 473 | int ret; |
| 474 | dma_addr_t iscsi_stats_dma; |
| 475 | |
| 476 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 477 | |
| 478 | cls_sess = iscsi_conn_to_session(cls_conn); |
| 479 | sess = cls_sess->dd_data; |
| 480 | ddb_entry = sess->dd_data; |
| 481 | ha = ddb_entry->ha; |
| 482 | |
| 483 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 484 | /* Allocate memory */ |
| 485 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 486 | &iscsi_stats_dma, GFP_KERNEL); |
| 487 | if (!ql_iscsi_stats) { |
| 488 | ql4_printk(KERN_ERR, ha, |
| 489 | "Unable to allocate memory for iscsi stats\n"); |
| 490 | goto exit_get_stats; |
| 491 | } |
| 492 | |
| 493 | ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size, |
| 494 | iscsi_stats_dma); |
| 495 | if (ret != QLA_SUCCESS) { |
| 496 | ql4_printk(KERN_ERR, ha, |
| 497 | "Unable to retreive iscsi stats\n"); |
| 498 | goto free_stats; |
| 499 | } |
| 500 | |
| 501 | /* octets */ |
| 502 | stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets); |
| 503 | stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets); |
| 504 | /* xmit pdus */ |
| 505 | stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus); |
| 506 | stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus); |
| 507 | stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus); |
| 508 | stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus); |
| 509 | stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus); |
| 510 | stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus); |
| 511 | stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus); |
| 512 | stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus); |
| 513 | /* recv pdus */ |
| 514 | stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus); |
| 515 | stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus); |
| 516 | stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus); |
| 517 | stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus); |
| 518 | stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus); |
| 519 | stats->logoutrsp_pdus = |
| 520 | le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus); |
| 521 | stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus); |
| 522 | stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus); |
| 523 | stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus); |
| 524 | |
| 525 | free_stats: |
| 526 | dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats, |
| 527 | iscsi_stats_dma); |
| 528 | exit_get_stats: |
| 529 | return; |
| 530 | } |
| 531 | |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 532 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| 533 | { |
| 534 | struct iscsi_cls_session *session; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 535 | struct iscsi_session *sess; |
| 536 | unsigned long flags; |
| 537 | enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 538 | |
| 539 | session = starget_to_session(scsi_target(sc->device)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 540 | sess = session->dd_data; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 541 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 542 | spin_lock_irqsave(&session->lock, flags); |
| 543 | if (session->state == ISCSI_SESSION_FAILED) |
| 544 | ret = BLK_EH_RESET_TIMER; |
| 545 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 546 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 547 | return ret; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 550 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 551 | enum iscsi_host_param param, char *buf) |
| 552 | { |
| 553 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 554 | int len; |
| 555 | |
| 556 | switch (param) { |
| 557 | case ISCSI_HOST_PARAM_HWADDRESS: |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 558 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 559 | break; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 560 | case ISCSI_HOST_PARAM_IPADDRESS: |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 561 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 562 | break; |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 563 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 564 | len = sprintf(buf, "%s\n", ha->name_string); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 565 | break; |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 566 | default: |
| 567 | return -ENOSYS; |
| 568 | } |
| 569 | |
| 570 | return len; |
| 571 | } |
| 572 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 573 | static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
| 574 | { |
| 575 | if (ha->iface_ipv4) |
| 576 | return; |
| 577 | |
| 578 | /* IPv4 */ |
| 579 | ha->iface_ipv4 = iscsi_create_iface(ha->host, |
| 580 | &qla4xxx_iscsi_transport, |
| 581 | ISCSI_IFACE_TYPE_IPV4, 0, 0); |
| 582 | if (!ha->iface_ipv4) |
| 583 | ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " |
| 584 | "iface0.\n"); |
| 585 | } |
| 586 | |
| 587 | static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) |
| 588 | { |
| 589 | if (!ha->iface_ipv6_0) |
| 590 | /* IPv6 iface-0 */ |
| 591 | ha->iface_ipv6_0 = iscsi_create_iface(ha->host, |
| 592 | &qla4xxx_iscsi_transport, |
| 593 | ISCSI_IFACE_TYPE_IPV6, 0, |
| 594 | 0); |
| 595 | if (!ha->iface_ipv6_0) |
| 596 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 597 | "iface0.\n"); |
| 598 | |
| 599 | if (!ha->iface_ipv6_1) |
| 600 | /* IPv6 iface-1 */ |
| 601 | ha->iface_ipv6_1 = iscsi_create_iface(ha->host, |
| 602 | &qla4xxx_iscsi_transport, |
| 603 | ISCSI_IFACE_TYPE_IPV6, 1, |
| 604 | 0); |
| 605 | if (!ha->iface_ipv6_1) |
| 606 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 607 | "iface1.\n"); |
| 608 | } |
| 609 | |
| 610 | static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) |
| 611 | { |
| 612 | if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) |
| 613 | qla4xxx_create_ipv4_iface(ha); |
| 614 | |
| 615 | if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) |
| 616 | qla4xxx_create_ipv6_iface(ha); |
| 617 | } |
| 618 | |
| 619 | static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) |
| 620 | { |
| 621 | if (ha->iface_ipv4) { |
| 622 | iscsi_destroy_iface(ha->iface_ipv4); |
| 623 | ha->iface_ipv4 = NULL; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) |
| 628 | { |
| 629 | if (ha->iface_ipv6_0) { |
| 630 | iscsi_destroy_iface(ha->iface_ipv6_0); |
| 631 | ha->iface_ipv6_0 = NULL; |
| 632 | } |
| 633 | if (ha->iface_ipv6_1) { |
| 634 | iscsi_destroy_iface(ha->iface_ipv6_1); |
| 635 | ha->iface_ipv6_1 = NULL; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) |
| 640 | { |
| 641 | qla4xxx_destroy_ipv4_iface(ha); |
| 642 | qla4xxx_destroy_ipv6_iface(ha); |
| 643 | } |
| 644 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 645 | static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
| 646 | struct iscsi_iface_param_info *iface_param, |
| 647 | struct addr_ctrl_blk *init_fw_cb) |
| 648 | { |
| 649 | /* |
| 650 | * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. |
| 651 | * iface_num 1 is valid only for IPv6 Addr. |
| 652 | */ |
| 653 | switch (iface_param->param) { |
| 654 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 655 | if (iface_param->iface_num & 0x1) |
| 656 | /* IPv6 Addr 1 */ |
| 657 | memcpy(init_fw_cb->ipv6_addr1, iface_param->value, |
| 658 | sizeof(init_fw_cb->ipv6_addr1)); |
| 659 | else |
| 660 | /* IPv6 Addr 0 */ |
| 661 | memcpy(init_fw_cb->ipv6_addr0, iface_param->value, |
| 662 | sizeof(init_fw_cb->ipv6_addr0)); |
| 663 | break; |
| 664 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 665 | if (iface_param->iface_num & 0x1) |
| 666 | break; |
| 667 | memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], |
| 668 | sizeof(init_fw_cb->ipv6_if_id)); |
| 669 | break; |
| 670 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 671 | if (iface_param->iface_num & 0x1) |
| 672 | break; |
| 673 | memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, |
| 674 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 675 | break; |
| 676 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 677 | /* Autocfg applies to even interface */ |
| 678 | if (iface_param->iface_num & 0x1) |
| 679 | break; |
| 680 | |
| 681 | if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) |
| 682 | init_fw_cb->ipv6_addtl_opts &= |
| 683 | cpu_to_le16( |
| 684 | ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 685 | else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) |
| 686 | init_fw_cb->ipv6_addtl_opts |= |
| 687 | cpu_to_le16( |
| 688 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 689 | else |
| 690 | ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " |
| 691 | "IPv6 addr\n"); |
| 692 | break; |
| 693 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 694 | /* Autocfg applies to even interface */ |
| 695 | if (iface_param->iface_num & 0x1) |
| 696 | break; |
| 697 | |
| 698 | if (iface_param->value[0] == |
| 699 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) |
| 700 | init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( |
| 701 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 702 | else if (iface_param->value[0] == |
| 703 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) |
| 704 | init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( |
| 705 | ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 706 | else |
| 707 | ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " |
| 708 | "IPv6 linklocal addr\n"); |
| 709 | break; |
| 710 | case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: |
| 711 | /* Autocfg applies to even interface */ |
| 712 | if (iface_param->iface_num & 0x1) |
| 713 | break; |
| 714 | |
| 715 | if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) |
| 716 | memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, |
| 717 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 718 | break; |
| 719 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 720 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 721 | init_fw_cb->ipv6_opts |= |
| 722 | cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 723 | qla4xxx_create_ipv6_iface(ha); |
| 724 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 725 | init_fw_cb->ipv6_opts &= |
| 726 | cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & |
| 727 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 728 | qla4xxx_destroy_ipv6_iface(ha); |
| 729 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 730 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 731 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 732 | if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) |
| 733 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 734 | init_fw_cb->ipv6_vlan_tag = |
| 735 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 736 | break; |
| 737 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 738 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 739 | init_fw_cb->ipv6_opts |= |
| 740 | cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE); |
| 741 | else |
| 742 | init_fw_cb->ipv6_opts &= |
| 743 | cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 744 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 745 | case ISCSI_NET_PARAM_MTU: |
| 746 | init_fw_cb->eth_mtu_size = |
| 747 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 748 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 749 | case ISCSI_NET_PARAM_PORT: |
| 750 | /* Autocfg applies to even interface */ |
| 751 | if (iface_param->iface_num & 0x1) |
| 752 | break; |
| 753 | |
| 754 | init_fw_cb->ipv6_port = |
| 755 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 756 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 757 | default: |
| 758 | ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", |
| 759 | iface_param->param); |
| 760 | break; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, |
| 765 | struct iscsi_iface_param_info *iface_param, |
| 766 | struct addr_ctrl_blk *init_fw_cb) |
| 767 | { |
| 768 | switch (iface_param->param) { |
| 769 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 770 | memcpy(init_fw_cb->ipv4_addr, iface_param->value, |
| 771 | sizeof(init_fw_cb->ipv4_addr)); |
| 772 | break; |
| 773 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 774 | memcpy(init_fw_cb->ipv4_subnet, iface_param->value, |
| 775 | sizeof(init_fw_cb->ipv4_subnet)); |
| 776 | break; |
| 777 | case ISCSI_NET_PARAM_IPV4_GW: |
| 778 | memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, |
| 779 | sizeof(init_fw_cb->ipv4_gw_addr)); |
| 780 | break; |
| 781 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 782 | if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) |
| 783 | init_fw_cb->ipv4_tcp_opts |= |
| 784 | cpu_to_le16(TCPOPT_DHCP_ENABLE); |
| 785 | else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) |
| 786 | init_fw_cb->ipv4_tcp_opts &= |
| 787 | cpu_to_le16(~TCPOPT_DHCP_ENABLE); |
| 788 | else |
| 789 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); |
| 790 | break; |
| 791 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 792 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 793 | init_fw_cb->ipv4_ip_opts |= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 794 | cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 795 | qla4xxx_create_ipv4_iface(ha); |
| 796 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 797 | init_fw_cb->ipv4_ip_opts &= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 798 | cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 799 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 800 | qla4xxx_destroy_ipv4_iface(ha); |
| 801 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 802 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 803 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 804 | if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) |
| 805 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 806 | init_fw_cb->ipv4_vlan_tag = |
| 807 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 808 | break; |
| 809 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 810 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 811 | init_fw_cb->ipv4_ip_opts |= |
| 812 | cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE); |
| 813 | else |
| 814 | init_fw_cb->ipv4_ip_opts &= |
| 815 | cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 816 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 817 | case ISCSI_NET_PARAM_MTU: |
| 818 | init_fw_cb->eth_mtu_size = |
| 819 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 820 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 821 | case ISCSI_NET_PARAM_PORT: |
| 822 | init_fw_cb->ipv4_port = |
| 823 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 824 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 825 | default: |
| 826 | ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", |
| 827 | iface_param->param); |
| 828 | break; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | static void |
| 833 | qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) |
| 834 | { |
| 835 | struct addr_ctrl_blk_def *acb; |
| 836 | acb = (struct addr_ctrl_blk_def *)init_fw_cb; |
| 837 | memset(acb->reserved1, 0, sizeof(acb->reserved1)); |
| 838 | memset(acb->reserved2, 0, sizeof(acb->reserved2)); |
| 839 | memset(acb->reserved3, 0, sizeof(acb->reserved3)); |
| 840 | memset(acb->reserved4, 0, sizeof(acb->reserved4)); |
| 841 | memset(acb->reserved5, 0, sizeof(acb->reserved5)); |
| 842 | memset(acb->reserved6, 0, sizeof(acb->reserved6)); |
| 843 | memset(acb->reserved7, 0, sizeof(acb->reserved7)); |
| 844 | memset(acb->reserved8, 0, sizeof(acb->reserved8)); |
| 845 | memset(acb->reserved9, 0, sizeof(acb->reserved9)); |
| 846 | memset(acb->reserved10, 0, sizeof(acb->reserved10)); |
| 847 | memset(acb->reserved11, 0, sizeof(acb->reserved11)); |
| 848 | memset(acb->reserved12, 0, sizeof(acb->reserved12)); |
| 849 | memset(acb->reserved13, 0, sizeof(acb->reserved13)); |
| 850 | memset(acb->reserved14, 0, sizeof(acb->reserved14)); |
| 851 | memset(acb->reserved15, 0, sizeof(acb->reserved15)); |
| 852 | } |
| 853 | |
| 854 | static int |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 855 | qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len) |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 856 | { |
| 857 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 858 | int rval = 0; |
| 859 | struct iscsi_iface_param_info *iface_param = NULL; |
| 860 | struct addr_ctrl_blk *init_fw_cb = NULL; |
| 861 | dma_addr_t init_fw_cb_dma; |
| 862 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 863 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 864 | uint32_t rem = len; |
| 865 | struct nlattr *attr; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 866 | |
| 867 | init_fw_cb = dma_alloc_coherent(&ha->pdev->dev, |
| 868 | sizeof(struct addr_ctrl_blk), |
| 869 | &init_fw_cb_dma, GFP_KERNEL); |
| 870 | if (!init_fw_cb) { |
| 871 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", |
| 872 | __func__); |
| 873 | return -ENOMEM; |
| 874 | } |
| 875 | |
| 876 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 877 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 878 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 879 | |
| 880 | if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { |
| 881 | ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); |
| 882 | rval = -EIO; |
| 883 | goto exit_init_fw_cb; |
| 884 | } |
| 885 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 886 | nla_for_each_attr(attr, data, len, rem) { |
| 887 | iface_param = nla_data(attr); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 888 | |
| 889 | if (iface_param->param_type != ISCSI_NET_PARAM) |
| 890 | continue; |
| 891 | |
| 892 | switch (iface_param->iface_type) { |
| 893 | case ISCSI_IFACE_TYPE_IPV4: |
| 894 | switch (iface_param->iface_num) { |
| 895 | case 0: |
| 896 | qla4xxx_set_ipv4(ha, iface_param, init_fw_cb); |
| 897 | break; |
| 898 | default: |
| 899 | /* Cannot have more than one IPv4 interface */ |
| 900 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface " |
| 901 | "number = %d\n", |
| 902 | iface_param->iface_num); |
| 903 | break; |
| 904 | } |
| 905 | break; |
| 906 | case ISCSI_IFACE_TYPE_IPV6: |
| 907 | switch (iface_param->iface_num) { |
| 908 | case 0: |
| 909 | case 1: |
| 910 | qla4xxx_set_ipv6(ha, iface_param, init_fw_cb); |
| 911 | break; |
| 912 | default: |
| 913 | /* Cannot have more than two IPv6 interface */ |
| 914 | ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface " |
| 915 | "number = %d\n", |
| 916 | iface_param->iface_num); |
| 917 | break; |
| 918 | } |
| 919 | break; |
| 920 | default: |
| 921 | ql4_printk(KERN_ERR, ha, "Invalid iface type\n"); |
| 922 | break; |
| 923 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); |
| 927 | |
| 928 | rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, |
| 929 | sizeof(struct addr_ctrl_blk), |
| 930 | FLASH_OPT_RMW_COMMIT); |
| 931 | if (rval != QLA_SUCCESS) { |
| 932 | ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", |
| 933 | __func__); |
| 934 | rval = -EIO; |
| 935 | goto exit_init_fw_cb; |
| 936 | } |
| 937 | |
Vikas Chaudhary | ce505f9 | 2011-12-01 22:42:10 -0800 | [diff] [blame] | 938 | rval = qla4xxx_disable_acb(ha); |
| 939 | if (rval != QLA_SUCCESS) { |
| 940 | ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n", |
| 941 | __func__); |
| 942 | rval = -EIO; |
| 943 | goto exit_init_fw_cb; |
| 944 | } |
| 945 | |
| 946 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 947 | DISABLE_ACB_TOV * HZ); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 948 | |
| 949 | qla4xxx_initcb_to_acb(init_fw_cb); |
| 950 | |
| 951 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); |
| 952 | if (rval != QLA_SUCCESS) { |
| 953 | ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", |
| 954 | __func__); |
| 955 | rval = -EIO; |
| 956 | goto exit_init_fw_cb; |
| 957 | } |
| 958 | |
| 959 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 960 | qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, |
| 961 | init_fw_cb_dma); |
| 962 | |
| 963 | exit_init_fw_cb: |
| 964 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), |
| 965 | init_fw_cb, init_fw_cb_dma); |
| 966 | |
| 967 | return rval; |
| 968 | } |
| 969 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 970 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 971 | enum iscsi_param param, char *buf) |
| 972 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 973 | struct iscsi_conn *conn; |
| 974 | struct qla_conn *qla_conn; |
| 975 | struct sockaddr *dst_addr; |
| 976 | int len = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 977 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 978 | conn = cls_conn->dd_data; |
| 979 | qla_conn = conn->dd_data; |
| 980 | dst_addr = &qla_conn->qla_ep->dst_addr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 981 | |
| 982 | switch (param) { |
| 983 | case ISCSI_PARAM_CONN_PORT: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 984 | case ISCSI_PARAM_CONN_ADDRESS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 985 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 986 | dst_addr, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 987 | default: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 988 | return iscsi_conn_get_param(cls_conn, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | return len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 992 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 995 | int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index) |
| 996 | { |
| 997 | uint32_t mbx_sts = 0; |
| 998 | uint16_t tmp_ddb_index; |
| 999 | int ret; |
| 1000 | |
| 1001 | get_ddb_index: |
| 1002 | tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES); |
| 1003 | |
| 1004 | if (tmp_ddb_index >= MAX_DDB_ENTRIES) { |
| 1005 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1006 | "Free DDB index not available\n")); |
| 1007 | ret = QLA_ERROR; |
| 1008 | goto exit_get_ddb_index; |
| 1009 | } |
| 1010 | |
| 1011 | if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map)) |
| 1012 | goto get_ddb_index; |
| 1013 | |
| 1014 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1015 | "Found a free DDB index at %d\n", tmp_ddb_index)); |
| 1016 | ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts); |
| 1017 | if (ret == QLA_ERROR) { |
| 1018 | if (mbx_sts == MBOX_STS_COMMAND_ERROR) { |
| 1019 | ql4_printk(KERN_INFO, ha, |
| 1020 | "DDB index = %d not available trying next\n", |
| 1021 | tmp_ddb_index); |
| 1022 | goto get_ddb_index; |
| 1023 | } |
| 1024 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1025 | "Free FW DDB not available\n")); |
| 1026 | } |
| 1027 | |
| 1028 | *ddb_index = tmp_ddb_index; |
| 1029 | |
| 1030 | exit_get_ddb_index: |
| 1031 | return ret; |
| 1032 | } |
| 1033 | |
| 1034 | static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha, |
| 1035 | struct ddb_entry *ddb_entry, |
| 1036 | char *existing_ipaddr, |
| 1037 | char *user_ipaddr) |
| 1038 | { |
| 1039 | uint8_t dst_ipaddr[IPv6_ADDR_LEN]; |
| 1040 | char formatted_ipaddr[DDB_IPADDR_LEN]; |
| 1041 | int status = QLA_SUCCESS, ret = 0; |
| 1042 | |
| 1043 | if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) { |
| 1044 | ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 1045 | '\0', NULL); |
| 1046 | if (ret == 0) { |
| 1047 | status = QLA_ERROR; |
| 1048 | goto out_match; |
| 1049 | } |
| 1050 | ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr); |
| 1051 | } else { |
| 1052 | ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 1053 | '\0', NULL); |
| 1054 | if (ret == 0) { |
| 1055 | status = QLA_ERROR; |
| 1056 | goto out_match; |
| 1057 | } |
| 1058 | ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr); |
| 1059 | } |
| 1060 | |
| 1061 | if (strcmp(existing_ipaddr, formatted_ipaddr)) |
| 1062 | status = QLA_ERROR; |
| 1063 | |
| 1064 | out_match: |
| 1065 | return status; |
| 1066 | } |
| 1067 | |
| 1068 | static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha, |
| 1069 | struct iscsi_cls_conn *cls_conn) |
| 1070 | { |
| 1071 | int idx = 0, max_ddbs, rval; |
| 1072 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 1073 | struct iscsi_session *sess, *existing_sess; |
| 1074 | struct iscsi_conn *conn, *existing_conn; |
| 1075 | struct ddb_entry *ddb_entry; |
| 1076 | |
| 1077 | sess = cls_sess->dd_data; |
| 1078 | conn = cls_conn->dd_data; |
| 1079 | |
| 1080 | if (sess->targetname == NULL || |
| 1081 | conn->persistent_address == NULL || |
| 1082 | conn->persistent_port == 0) |
| 1083 | return QLA_ERROR; |
| 1084 | |
| 1085 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 1086 | MAX_DEV_DB_ENTRIES; |
| 1087 | |
| 1088 | for (idx = 0; idx < max_ddbs; idx++) { |
| 1089 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 1090 | if (ddb_entry == NULL) |
| 1091 | continue; |
| 1092 | |
| 1093 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 1094 | continue; |
| 1095 | |
| 1096 | existing_sess = ddb_entry->sess->dd_data; |
| 1097 | existing_conn = ddb_entry->conn->dd_data; |
| 1098 | |
| 1099 | if (existing_sess->targetname == NULL || |
| 1100 | existing_conn->persistent_address == NULL || |
| 1101 | existing_conn->persistent_port == 0) |
| 1102 | continue; |
| 1103 | |
| 1104 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1105 | "IQN = %s User IQN = %s\n", |
| 1106 | existing_sess->targetname, |
| 1107 | sess->targetname)); |
| 1108 | |
| 1109 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1110 | "IP = %s User IP = %s\n", |
| 1111 | existing_conn->persistent_address, |
| 1112 | conn->persistent_address)); |
| 1113 | |
| 1114 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1115 | "Port = %d User Port = %d\n", |
| 1116 | existing_conn->persistent_port, |
| 1117 | conn->persistent_port)); |
| 1118 | |
| 1119 | if (strcmp(existing_sess->targetname, sess->targetname)) |
| 1120 | continue; |
| 1121 | rval = qla4xxx_match_ipaddress(ha, ddb_entry, |
| 1122 | existing_conn->persistent_address, |
| 1123 | conn->persistent_address); |
| 1124 | if (rval == QLA_ERROR) |
| 1125 | continue; |
| 1126 | if (existing_conn->persistent_port != conn->persistent_port) |
| 1127 | continue; |
| 1128 | break; |
| 1129 | } |
| 1130 | |
| 1131 | if (idx == max_ddbs) |
| 1132 | return QLA_ERROR; |
| 1133 | |
| 1134 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1135 | "Match found in fwdb sessions\n")); |
| 1136 | return QLA_SUCCESS; |
| 1137 | } |
| 1138 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1139 | static struct iscsi_cls_session * |
| 1140 | qla4xxx_session_create(struct iscsi_endpoint *ep, |
| 1141 | uint16_t cmds_max, uint16_t qdepth, |
| 1142 | uint32_t initial_cmdsn) |
| 1143 | { |
| 1144 | struct iscsi_cls_session *cls_sess; |
| 1145 | struct scsi_qla_host *ha; |
| 1146 | struct qla_endpoint *qla_ep; |
| 1147 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1148 | uint16_t ddb_index; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1149 | struct iscsi_session *sess; |
| 1150 | struct sockaddr *dst_addr; |
| 1151 | int ret; |
| 1152 | |
| 1153 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1154 | if (!ep) { |
| 1155 | printk(KERN_ERR "qla4xxx: missing ep.\n"); |
| 1156 | return NULL; |
| 1157 | } |
| 1158 | |
| 1159 | qla_ep = ep->dd_data; |
| 1160 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 1161 | ha = to_qla_host(qla_ep->host); |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 1162 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1163 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 1164 | if (ret == QLA_ERROR) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1165 | return NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1166 | |
| 1167 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host, |
| 1168 | cmds_max, sizeof(struct ddb_entry), |
| 1169 | sizeof(struct ql4_task_data), |
| 1170 | initial_cmdsn, ddb_index); |
| 1171 | if (!cls_sess) |
| 1172 | return NULL; |
| 1173 | |
| 1174 | sess = cls_sess->dd_data; |
| 1175 | ddb_entry = sess->dd_data; |
| 1176 | ddb_entry->fw_ddb_index = ddb_index; |
| 1177 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 1178 | ddb_entry->ha = ha; |
| 1179 | ddb_entry->sess = cls_sess; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1180 | ddb_entry->unblock_sess = qla4xxx_unblock_ddb; |
| 1181 | ddb_entry->ddb_change = qla4xxx_ddb_change; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1182 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 1183 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| 1184 | ha->tot_ddbs++; |
| 1185 | |
| 1186 | return cls_sess; |
| 1187 | } |
| 1188 | |
| 1189 | static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess) |
| 1190 | { |
| 1191 | struct iscsi_session *sess; |
| 1192 | struct ddb_entry *ddb_entry; |
| 1193 | struct scsi_qla_host *ha; |
| 1194 | unsigned long flags; |
| 1195 | |
| 1196 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1197 | sess = cls_sess->dd_data; |
| 1198 | ddb_entry = sess->dd_data; |
| 1199 | ha = ddb_entry->ha; |
| 1200 | |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 1201 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 1202 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1203 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1204 | qla4xxx_free_ddb(ha, ddb_entry); |
| 1205 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1206 | iscsi_session_teardown(cls_sess); |
| 1207 | } |
| 1208 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1209 | static struct iscsi_cls_conn * |
| 1210 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx) |
| 1211 | { |
| 1212 | struct iscsi_cls_conn *cls_conn; |
| 1213 | struct iscsi_session *sess; |
| 1214 | struct ddb_entry *ddb_entry; |
| 1215 | |
| 1216 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1217 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), |
| 1218 | conn_idx); |
Mike Christie | ff1d031 | 2011-12-01 21:38:43 -0600 | [diff] [blame] | 1219 | if (!cls_conn) |
| 1220 | return NULL; |
| 1221 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1222 | sess = cls_sess->dd_data; |
| 1223 | ddb_entry = sess->dd_data; |
| 1224 | ddb_entry->conn = cls_conn; |
| 1225 | |
| 1226 | return cls_conn; |
| 1227 | } |
| 1228 | |
| 1229 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 1230 | struct iscsi_cls_conn *cls_conn, |
| 1231 | uint64_t transport_fd, int is_leading) |
| 1232 | { |
| 1233 | struct iscsi_conn *conn; |
| 1234 | struct qla_conn *qla_conn; |
| 1235 | struct iscsi_endpoint *ep; |
| 1236 | |
| 1237 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1238 | |
| 1239 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
| 1240 | return -EINVAL; |
| 1241 | ep = iscsi_lookup_endpoint(transport_fd); |
| 1242 | conn = cls_conn->dd_data; |
| 1243 | qla_conn = conn->dd_data; |
| 1244 | qla_conn->qla_ep = ep->dd_data; |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn) |
| 1249 | { |
| 1250 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 1251 | struct iscsi_session *sess; |
| 1252 | struct ddb_entry *ddb_entry; |
| 1253 | struct scsi_qla_host *ha; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1254 | struct dev_db_entry *fw_ddb_entry = NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1255 | dma_addr_t fw_ddb_entry_dma; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1256 | uint32_t mbx_sts = 0; |
| 1257 | int ret = 0; |
| 1258 | int status = QLA_SUCCESS; |
| 1259 | |
| 1260 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1261 | sess = cls_sess->dd_data; |
| 1262 | ddb_entry = sess->dd_data; |
| 1263 | ha = ddb_entry->ha; |
| 1264 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1265 | /* Check if we have matching FW DDB, if yes then do not |
| 1266 | * login to this target. This could cause target to logout previous |
| 1267 | * connection |
| 1268 | */ |
| 1269 | ret = qla4xxx_match_fwdb_session(ha, cls_conn); |
| 1270 | if (ret == QLA_SUCCESS) { |
| 1271 | ql4_printk(KERN_INFO, ha, |
| 1272 | "Session already exist in FW.\n"); |
| 1273 | ret = -EEXIST; |
| 1274 | goto exit_conn_start; |
| 1275 | } |
| 1276 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1277 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1278 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 1279 | if (!fw_ddb_entry) { |
| 1280 | ql4_printk(KERN_ERR, ha, |
| 1281 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1282 | ret = -ENOMEM; |
| 1283 | goto exit_conn_start; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts); |
| 1287 | if (ret) { |
| 1288 | /* If iscsid is stopped and started then no need to do |
| 1289 | * set param again since ddb state will be already |
| 1290 | * active and FW does not allow set ddb to an |
| 1291 | * active session. |
| 1292 | */ |
| 1293 | if (mbx_sts) |
| 1294 | if (ddb_entry->fw_ddb_device_state == |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 1295 | DDB_DS_SESSION_ACTIVE) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1296 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1297 | goto exit_set_param; |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 1298 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1299 | |
| 1300 | ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n", |
| 1301 | __func__, ddb_entry->fw_ddb_index); |
| 1302 | goto exit_conn_start; |
| 1303 | } |
| 1304 | |
| 1305 | status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| 1306 | if (status == QLA_ERROR) { |
Manish Rangankar | 0e7e850 | 2011-07-25 13:48:54 -0500 | [diff] [blame] | 1307 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| 1308 | sess->targetname); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1309 | ret = -EINVAL; |
| 1310 | goto exit_conn_start; |
| 1311 | } |
| 1312 | |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 1313 | if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) |
| 1314 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| 1315 | |
| 1316 | DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__, |
| 1317 | ddb_entry->fw_ddb_device_state)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1318 | |
| 1319 | exit_set_param: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1320 | ret = 0; |
| 1321 | |
| 1322 | exit_conn_start: |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1323 | if (fw_ddb_entry) |
| 1324 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1325 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1326 | return ret; |
| 1327 | } |
| 1328 | |
| 1329 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| 1330 | { |
| 1331 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 1332 | struct iscsi_session *sess; |
| 1333 | struct scsi_qla_host *ha; |
| 1334 | struct ddb_entry *ddb_entry; |
| 1335 | int options; |
| 1336 | |
| 1337 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1338 | sess = cls_sess->dd_data; |
| 1339 | ddb_entry = sess->dd_data; |
| 1340 | ha = ddb_entry->ha; |
| 1341 | |
| 1342 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 1343 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) |
| 1344 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | static void qla4xxx_task_work(struct work_struct *wdata) |
| 1348 | { |
| 1349 | struct ql4_task_data *task_data; |
| 1350 | struct scsi_qla_host *ha; |
| 1351 | struct passthru_status *sts; |
| 1352 | struct iscsi_task *task; |
| 1353 | struct iscsi_hdr *hdr; |
| 1354 | uint8_t *data; |
| 1355 | uint32_t data_len; |
| 1356 | struct iscsi_conn *conn; |
| 1357 | int hdr_len; |
| 1358 | itt_t itt; |
| 1359 | |
| 1360 | task_data = container_of(wdata, struct ql4_task_data, task_work); |
| 1361 | ha = task_data->ha; |
| 1362 | task = task_data->task; |
| 1363 | sts = &task_data->sts; |
| 1364 | hdr_len = sizeof(struct iscsi_hdr); |
| 1365 | |
| 1366 | DEBUG3(printk(KERN_INFO "Status returned\n")); |
| 1367 | DEBUG3(qla4xxx_dump_buffer(sts, 64)); |
| 1368 | DEBUG3(printk(KERN_INFO "Response buffer")); |
| 1369 | DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64)); |
| 1370 | |
| 1371 | conn = task->conn; |
| 1372 | |
| 1373 | switch (sts->completionStatus) { |
| 1374 | case PASSTHRU_STATUS_COMPLETE: |
| 1375 | hdr = (struct iscsi_hdr *)task_data->resp_buffer; |
| 1376 | /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */ |
| 1377 | itt = sts->handle; |
| 1378 | hdr->itt = itt; |
| 1379 | data = task_data->resp_buffer + hdr_len; |
| 1380 | data_len = task_data->resp_len - hdr_len; |
| 1381 | iscsi_complete_pdu(conn, hdr, data, data_len); |
| 1382 | break; |
| 1383 | default: |
| 1384 | ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n", |
| 1385 | sts->completionStatus); |
| 1386 | break; |
| 1387 | } |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 1392 | { |
| 1393 | struct ql4_task_data *task_data; |
| 1394 | struct iscsi_session *sess; |
| 1395 | struct ddb_entry *ddb_entry; |
| 1396 | struct scsi_qla_host *ha; |
| 1397 | int hdr_len; |
| 1398 | |
| 1399 | sess = task->conn->session; |
| 1400 | ddb_entry = sess->dd_data; |
| 1401 | ha = ddb_entry->ha; |
| 1402 | task_data = task->dd_data; |
| 1403 | memset(task_data, 0, sizeof(struct ql4_task_data)); |
| 1404 | |
| 1405 | if (task->sc) { |
| 1406 | ql4_printk(KERN_INFO, ha, |
| 1407 | "%s: SCSI Commands not implemented\n", __func__); |
| 1408 | return -EINVAL; |
| 1409 | } |
| 1410 | |
| 1411 | hdr_len = sizeof(struct iscsi_hdr); |
| 1412 | task_data->ha = ha; |
| 1413 | task_data->task = task; |
| 1414 | |
| 1415 | if (task->data_count) { |
| 1416 | task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data, |
| 1417 | task->data_count, |
| 1418 | PCI_DMA_TODEVICE); |
| 1419 | } |
| 1420 | |
| 1421 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 1422 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 1423 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1424 | task_data->resp_len = task->conn->max_recv_dlength + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1425 | task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| 1426 | task_data->resp_len, |
| 1427 | &task_data->resp_dma, |
| 1428 | GFP_ATOMIC); |
| 1429 | if (!task_data->resp_buffer) |
| 1430 | goto exit_alloc_pdu; |
| 1431 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1432 | task_data->req_len = task->data_count + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1433 | task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev, |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1434 | task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1435 | &task_data->req_dma, |
| 1436 | GFP_ATOMIC); |
| 1437 | if (!task_data->req_buffer) |
| 1438 | goto exit_alloc_pdu; |
| 1439 | |
| 1440 | task->hdr = task_data->req_buffer; |
| 1441 | |
| 1442 | INIT_WORK(&task_data->task_work, qla4xxx_task_work); |
| 1443 | |
| 1444 | return 0; |
| 1445 | |
| 1446 | exit_alloc_pdu: |
| 1447 | if (task_data->resp_buffer) |
| 1448 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 1449 | task_data->resp_buffer, task_data->resp_dma); |
| 1450 | |
| 1451 | if (task_data->req_buffer) |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1452 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1453 | task_data->req_buffer, task_data->req_dma); |
| 1454 | return -ENOMEM; |
| 1455 | } |
| 1456 | |
| 1457 | static void qla4xxx_task_cleanup(struct iscsi_task *task) |
| 1458 | { |
| 1459 | struct ql4_task_data *task_data; |
| 1460 | struct iscsi_session *sess; |
| 1461 | struct ddb_entry *ddb_entry; |
| 1462 | struct scsi_qla_host *ha; |
| 1463 | int hdr_len; |
| 1464 | |
| 1465 | hdr_len = sizeof(struct iscsi_hdr); |
| 1466 | sess = task->conn->session; |
| 1467 | ddb_entry = sess->dd_data; |
| 1468 | ha = ddb_entry->ha; |
| 1469 | task_data = task->dd_data; |
| 1470 | |
| 1471 | if (task->data_count) { |
| 1472 | dma_unmap_single(&ha->pdev->dev, task_data->data_dma, |
| 1473 | task->data_count, PCI_DMA_TODEVICE); |
| 1474 | } |
| 1475 | |
| 1476 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 1477 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 1478 | |
| 1479 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 1480 | task_data->resp_buffer, task_data->resp_dma); |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1481 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1482 | task_data->req_buffer, task_data->req_dma); |
| 1483 | return; |
| 1484 | } |
| 1485 | |
| 1486 | static int qla4xxx_task_xmit(struct iscsi_task *task) |
| 1487 | { |
| 1488 | struct scsi_cmnd *sc = task->sc; |
| 1489 | struct iscsi_session *sess = task->conn->session; |
| 1490 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 1491 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 1492 | |
| 1493 | if (!sc) |
| 1494 | return qla4xxx_send_passthru0(task); |
| 1495 | |
| 1496 | ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n", |
| 1497 | __func__); |
| 1498 | return -ENOSYS; |
| 1499 | } |
| 1500 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1501 | static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha, |
| 1502 | struct dev_db_entry *fw_ddb_entry, |
| 1503 | struct iscsi_cls_session *cls_sess, |
| 1504 | struct iscsi_cls_conn *cls_conn) |
| 1505 | { |
| 1506 | int buflen = 0; |
| 1507 | struct iscsi_session *sess; |
| 1508 | struct iscsi_conn *conn; |
| 1509 | char ip_addr[DDB_IPADDR_LEN]; |
| 1510 | uint16_t options = 0; |
| 1511 | |
| 1512 | sess = cls_sess->dd_data; |
| 1513 | conn = cls_conn->dd_data; |
| 1514 | |
| 1515 | conn->max_recv_dlength = BYTE_UNITS * |
| 1516 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 1517 | |
| 1518 | conn->max_xmit_dlength = BYTE_UNITS * |
| 1519 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 1520 | |
| 1521 | sess->initial_r2t_en = |
| 1522 | (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 1523 | |
| 1524 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 1525 | |
| 1526 | sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 1527 | |
| 1528 | sess->first_burst = BYTE_UNITS * |
| 1529 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 1530 | |
| 1531 | sess->max_burst = BYTE_UNITS * |
| 1532 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 1533 | |
| 1534 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 1535 | |
| 1536 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 1537 | |
| 1538 | conn->persistent_port = le16_to_cpu(fw_ddb_entry->port); |
| 1539 | |
| 1540 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 1541 | |
| 1542 | options = le16_to_cpu(fw_ddb_entry->options); |
| 1543 | if (options & DDB_OPT_IPV6_DEVICE) |
| 1544 | sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 1545 | else |
| 1546 | sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 1547 | |
| 1548 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME, |
| 1549 | (char *)fw_ddb_entry->iscsi_name, buflen); |
| 1550 | iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME, |
| 1551 | (char *)ha->name_string, buflen); |
| 1552 | iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS, |
| 1553 | (char *)ip_addr, buflen); |
| 1554 | } |
| 1555 | |
| 1556 | void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha, |
| 1557 | struct ddb_entry *ddb_entry) |
| 1558 | { |
| 1559 | struct iscsi_cls_session *cls_sess; |
| 1560 | struct iscsi_cls_conn *cls_conn; |
| 1561 | uint32_t ddb_state; |
| 1562 | dma_addr_t fw_ddb_entry_dma; |
| 1563 | struct dev_db_entry *fw_ddb_entry; |
| 1564 | |
| 1565 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1566 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 1567 | if (!fw_ddb_entry) { |
| 1568 | ql4_printk(KERN_ERR, ha, |
| 1569 | "%s: Unable to allocate dma buffer\n", __func__); |
| 1570 | goto exit_session_conn_fwddb_param; |
| 1571 | } |
| 1572 | |
| 1573 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 1574 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 1575 | NULL, NULL, NULL) == QLA_ERROR) { |
| 1576 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 1577 | "get_ddb_entry for fw_ddb_index %d\n", |
| 1578 | ha->host_no, __func__, |
| 1579 | ddb_entry->fw_ddb_index)); |
| 1580 | goto exit_session_conn_fwddb_param; |
| 1581 | } |
| 1582 | |
| 1583 | cls_sess = ddb_entry->sess; |
| 1584 | |
| 1585 | cls_conn = ddb_entry->conn; |
| 1586 | |
| 1587 | /* Update params */ |
| 1588 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 1589 | |
| 1590 | exit_session_conn_fwddb_param: |
| 1591 | if (fw_ddb_entry) |
| 1592 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1593 | fw_ddb_entry, fw_ddb_entry_dma); |
| 1594 | } |
| 1595 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1596 | void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha, |
| 1597 | struct ddb_entry *ddb_entry) |
| 1598 | { |
| 1599 | struct iscsi_cls_session *cls_sess; |
| 1600 | struct iscsi_cls_conn *cls_conn; |
| 1601 | struct iscsi_session *sess; |
| 1602 | struct iscsi_conn *conn; |
| 1603 | uint32_t ddb_state; |
| 1604 | dma_addr_t fw_ddb_entry_dma; |
| 1605 | struct dev_db_entry *fw_ddb_entry; |
| 1606 | |
| 1607 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1608 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 1609 | if (!fw_ddb_entry) { |
| 1610 | ql4_printk(KERN_ERR, ha, |
| 1611 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1612 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 1616 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 1617 | NULL, NULL, NULL) == QLA_ERROR) { |
| 1618 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 1619 | "get_ddb_entry for fw_ddb_index %d\n", |
| 1620 | ha->host_no, __func__, |
| 1621 | ddb_entry->fw_ddb_index)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1622 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | cls_sess = ddb_entry->sess; |
| 1626 | sess = cls_sess->dd_data; |
| 1627 | |
| 1628 | cls_conn = ddb_entry->conn; |
| 1629 | conn = cls_conn->dd_data; |
| 1630 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1631 | /* Update timers after login */ |
| 1632 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 1633 | (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) && |
| 1634 | (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ? |
| 1635 | le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1636 | ddb_entry->default_time2wait = |
| 1637 | le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 1638 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1639 | /* Update params */ |
| 1640 | conn->max_recv_dlength = BYTE_UNITS * |
| 1641 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 1642 | |
| 1643 | conn->max_xmit_dlength = BYTE_UNITS * |
| 1644 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 1645 | |
| 1646 | sess->initial_r2t_en = |
| 1647 | (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 1648 | |
| 1649 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 1650 | |
| 1651 | sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 1652 | |
| 1653 | sess->first_burst = BYTE_UNITS * |
| 1654 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 1655 | |
| 1656 | sess->max_burst = BYTE_UNITS * |
| 1657 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 1658 | |
| 1659 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 1660 | |
| 1661 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 1662 | |
| 1663 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 1664 | |
| 1665 | memcpy(sess->initiatorname, ha->name_string, |
| 1666 | min(sizeof(ha->name_string), sizeof(sess->initiatorname))); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1667 | |
| 1668 | exit_session_conn_param: |
| 1669 | if (fw_ddb_entry) |
| 1670 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1671 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1672 | } |
| 1673 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1674 | /* |
| 1675 | * Timer routines |
| 1676 | */ |
| 1677 | |
| 1678 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, |
| 1679 | unsigned long interval) |
| 1680 | { |
| 1681 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| 1682 | __func__, ha->host->host_no)); |
| 1683 | init_timer(&ha->timer); |
| 1684 | ha->timer.expires = jiffies + interval * HZ; |
| 1685 | ha->timer.data = (unsigned long)ha; |
| 1686 | ha->timer.function = (void (*)(unsigned long))func; |
| 1687 | add_timer(&ha->timer); |
| 1688 | ha->timer_active = 1; |
| 1689 | } |
| 1690 | |
| 1691 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| 1692 | { |
| 1693 | del_timer_sync(&ha->timer); |
| 1694 | ha->timer_active = 0; |
| 1695 | } |
| 1696 | |
| 1697 | /*** |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1698 | * qla4xxx_mark_device_missing - blocks the session |
| 1699 | * @cls_session: Pointer to the session to be blocked |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1700 | * @ddb_entry: Pointer to device database entry |
| 1701 | * |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1702 | * This routine marks a device missing and close connection. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1703 | **/ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1704 | void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1705 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1706 | iscsi_block_session(cls_session); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1709 | /** |
| 1710 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| 1711 | * @ha: Pointer to host adapter structure. |
| 1712 | * |
| 1713 | * This routine marks a device missing and resets the relogin retry count. |
| 1714 | **/ |
| 1715 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| 1716 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1717 | iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1718 | } |
| 1719 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1720 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| 1721 | struct ddb_entry *ddb_entry, |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1722 | struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1723 | { |
| 1724 | struct srb *srb; |
| 1725 | |
| 1726 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 1727 | if (!srb) |
| 1728 | return srb; |
| 1729 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 1730 | kref_init(&srb->srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1731 | srb->ha = ha; |
| 1732 | srb->ddb = ddb_entry; |
| 1733 | srb->cmd = cmd; |
| 1734 | srb->flags = 0; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1735 | CMD_SP(cmd) = (void *)srb; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1736 | |
| 1737 | return srb; |
| 1738 | } |
| 1739 | |
| 1740 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| 1741 | { |
| 1742 | struct scsi_cmnd *cmd = srb->cmd; |
| 1743 | |
| 1744 | if (srb->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 1745 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1746 | srb->flags &= ~SRB_DMA_VALID; |
| 1747 | } |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 1748 | CMD_SP(cmd) = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 1751 | void qla4xxx_srb_compl(struct kref *ref) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1752 | { |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 1753 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1754 | struct scsi_cmnd *cmd = srb->cmd; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 1755 | struct scsi_qla_host *ha = srb->ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1756 | |
| 1757 | qla4xxx_srb_free_dma(ha, srb); |
| 1758 | |
| 1759 | mempool_free(srb, ha->srb_mempool); |
| 1760 | |
| 1761 | cmd->scsi_done(cmd); |
| 1762 | } |
| 1763 | |
| 1764 | /** |
| 1765 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1766 | * @host: scsi host |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1767 | * @cmd: Pointer to Linux's SCSI command structure |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1768 | * |
| 1769 | * Remarks: |
| 1770 | * This routine is invoked by Linux to send a SCSI command to the driver. |
| 1771 | * The mid-level driver tries to ensure that queuecommand never gets |
| 1772 | * invoked concurrently with itself or the interrupt handler (although |
| 1773 | * the interrupt handler may call this routine as part of request- |
| 1774 | * completion handling). Unfortunely, it sometimes calls the scheduler |
| 1775 | * in interrupt context which is a big NO! NO!. |
| 1776 | **/ |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1777 | static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1778 | { |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1779 | struct scsi_qla_host *ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1780 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 1781 | struct iscsi_cls_session *sess = ddb_entry->sess; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1782 | struct srb *srb; |
| 1783 | int rval; |
| 1784 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 1785 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 1786 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 1787 | cmd->result = DID_NO_CONNECT << 16; |
| 1788 | else |
| 1789 | cmd->result = DID_REQUEUE << 16; |
| 1790 | goto qc_fail_command; |
| 1791 | } |
| 1792 | |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 1793 | if (!sess) { |
| 1794 | cmd->result = DID_IMM_RETRY << 16; |
| 1795 | goto qc_fail_command; |
| 1796 | } |
| 1797 | |
| 1798 | rval = iscsi_session_chkready(sess); |
| 1799 | if (rval) { |
| 1800 | cmd->result = rval; |
| 1801 | goto qc_fail_command; |
| 1802 | } |
| 1803 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1804 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 1805 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 1806 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 1807 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 1808 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| 1809 | !test_bit(AF_ONLINE, &ha->flags) || |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1810 | !test_bit(AF_LINK_UP, &ha->flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1811 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 1812 | goto qc_host_busy; |
| 1813 | |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1814 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1815 | if (!srb) |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1816 | goto qc_host_busy; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1817 | |
| 1818 | rval = qla4xxx_send_command_to_isp(ha, srb); |
| 1819 | if (rval != QLA_SUCCESS) |
| 1820 | goto qc_host_busy_free_sp; |
| 1821 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1822 | return 0; |
| 1823 | |
| 1824 | qc_host_busy_free_sp: |
| 1825 | qla4xxx_srb_free_dma(ha, srb); |
| 1826 | mempool_free(srb, ha->srb_mempool); |
| 1827 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1828 | qc_host_busy: |
| 1829 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1830 | |
| 1831 | qc_fail_command: |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 1832 | cmd->scsi_done(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * qla4xxx_mem_free - frees memory allocated to adapter |
| 1839 | * @ha: Pointer to host adapter structure. |
| 1840 | * |
| 1841 | * Frees memory previously allocated by qla4xxx_mem_alloc |
| 1842 | **/ |
| 1843 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| 1844 | { |
| 1845 | if (ha->queues) |
| 1846 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| 1847 | ha->queues_dma); |
| 1848 | |
| 1849 | ha->queues_len = 0; |
| 1850 | ha->queues = NULL; |
| 1851 | ha->queues_dma = 0; |
| 1852 | ha->request_ring = NULL; |
| 1853 | ha->request_dma = 0; |
| 1854 | ha->response_ring = NULL; |
| 1855 | ha->response_dma = 0; |
| 1856 | ha->shadow_regs = NULL; |
| 1857 | ha->shadow_regs_dma = 0; |
| 1858 | |
| 1859 | /* Free srb pool. */ |
| 1860 | if (ha->srb_mempool) |
| 1861 | mempool_destroy(ha->srb_mempool); |
| 1862 | |
| 1863 | ha->srb_mempool = NULL; |
| 1864 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1865 | if (ha->chap_dma_pool) |
| 1866 | dma_pool_destroy(ha->chap_dma_pool); |
| 1867 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 1868 | if (ha->chap_list) |
| 1869 | vfree(ha->chap_list); |
| 1870 | ha->chap_list = NULL; |
| 1871 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1872 | if (ha->fw_ddb_dma_pool) |
| 1873 | dma_pool_destroy(ha->fw_ddb_dma_pool); |
| 1874 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1875 | /* release io space registers */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1876 | if (is_qla8022(ha)) { |
| 1877 | if (ha->nx_pcibase) |
| 1878 | iounmap( |
| 1879 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 1880 | } else if (ha->reg) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1881 | iounmap(ha->reg); |
| 1882 | pci_release_regions(ha->pdev); |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| 1887 | * @ha: Pointer to host adapter structure |
| 1888 | * |
| 1889 | * Allocates DMA memory for request and response queues. Also allocates memory |
| 1890 | * for srbs. |
| 1891 | **/ |
| 1892 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| 1893 | { |
| 1894 | unsigned long align; |
| 1895 | |
| 1896 | /* Allocate contiguous block of DMA memory for queues. */ |
| 1897 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 1898 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| 1899 | sizeof(struct shadow_regs) + |
| 1900 | MEM_ALIGN_VALUE + |
| 1901 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 1902 | ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, |
| 1903 | &ha->queues_dma, GFP_KERNEL); |
| 1904 | if (ha->queues == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1905 | ql4_printk(KERN_WARNING, ha, |
| 1906 | "Memory Allocation failed - queues.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1907 | |
| 1908 | goto mem_alloc_error_exit; |
| 1909 | } |
| 1910 | memset(ha->queues, 0, ha->queues_len); |
| 1911 | |
| 1912 | /* |
| 1913 | * As per RISC alignment requirements -- the bus-address must be a |
| 1914 | * multiple of the request-ring size (in bytes). |
| 1915 | */ |
| 1916 | align = 0; |
| 1917 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| 1918 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| 1919 | (MEM_ALIGN_VALUE - 1)); |
| 1920 | |
| 1921 | /* Update request and response queue pointers. */ |
| 1922 | ha->request_dma = ha->queues_dma + align; |
| 1923 | ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| 1924 | ha->response_dma = ha->queues_dma + align + |
| 1925 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| 1926 | ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| 1927 | (REQUEST_QUEUE_DEPTH * |
| 1928 | QUEUE_SIZE)); |
| 1929 | ha->shadow_regs_dma = ha->queues_dma + align + |
| 1930 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 1931 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| 1932 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| 1933 | (REQUEST_QUEUE_DEPTH * |
| 1934 | QUEUE_SIZE) + |
| 1935 | (RESPONSE_QUEUE_DEPTH * |
| 1936 | QUEUE_SIZE)); |
| 1937 | |
| 1938 | /* Allocate memory for srb pool. */ |
| 1939 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 1940 | mempool_free_slab, srb_cachep); |
| 1941 | if (ha->srb_mempool == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 1942 | ql4_printk(KERN_WARNING, ha, |
| 1943 | "Memory Allocation failed - SRB Pool.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1944 | |
| 1945 | goto mem_alloc_error_exit; |
| 1946 | } |
| 1947 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1948 | ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev, |
| 1949 | CHAP_DMA_BLOCK_SIZE, 8, 0); |
| 1950 | |
| 1951 | if (ha->chap_dma_pool == NULL) { |
| 1952 | ql4_printk(KERN_WARNING, ha, |
| 1953 | "%s: chap_dma_pool allocation failed..\n", __func__); |
| 1954 | goto mem_alloc_error_exit; |
| 1955 | } |
| 1956 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1957 | ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev, |
| 1958 | DDB_DMA_BLOCK_SIZE, 8, 0); |
| 1959 | |
| 1960 | if (ha->fw_ddb_dma_pool == NULL) { |
| 1961 | ql4_printk(KERN_WARNING, ha, |
| 1962 | "%s: fw_ddb_dma_pool allocation failed..\n", |
| 1963 | __func__); |
| 1964 | goto mem_alloc_error_exit; |
| 1965 | } |
| 1966 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1967 | return QLA_SUCCESS; |
| 1968 | |
| 1969 | mem_alloc_error_exit: |
| 1970 | qla4xxx_mem_free(ha); |
| 1971 | return QLA_ERROR; |
| 1972 | } |
| 1973 | |
| 1974 | /** |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 1975 | * qla4_8xxx_check_temp - Check the ISP82XX temperature. |
| 1976 | * @ha: adapter block pointer. |
| 1977 | * |
| 1978 | * Note: The caller should not hold the idc lock. |
| 1979 | **/ |
| 1980 | static int qla4_8xxx_check_temp(struct scsi_qla_host *ha) |
| 1981 | { |
| 1982 | uint32_t temp, temp_state, temp_val; |
| 1983 | int status = QLA_SUCCESS; |
| 1984 | |
| 1985 | temp = qla4_8xxx_rd_32(ha, CRB_TEMP_STATE); |
| 1986 | |
| 1987 | temp_state = qla82xx_get_temp_state(temp); |
| 1988 | temp_val = qla82xx_get_temp_val(temp); |
| 1989 | |
| 1990 | if (temp_state == QLA82XX_TEMP_PANIC) { |
| 1991 | ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C" |
| 1992 | " exceeds maximum allowed. Hardware has been shut" |
| 1993 | " down.\n", temp_val); |
| 1994 | status = QLA_ERROR; |
| 1995 | } else if (temp_state == QLA82XX_TEMP_WARN) { |
| 1996 | if (ha->temperature == QLA82XX_TEMP_NORMAL) |
| 1997 | ql4_printk(KERN_WARNING, ha, "Device temperature %d" |
| 1998 | " degrees C exceeds operating range." |
| 1999 | " Immediate action needed.\n", temp_val); |
| 2000 | } else { |
| 2001 | if (ha->temperature == QLA82XX_TEMP_WARN) |
| 2002 | ql4_printk(KERN_INFO, ha, "Device temperature is" |
| 2003 | " now %d degrees C in normal range.\n", |
| 2004 | temp_val); |
| 2005 | } |
| 2006 | ha->temperature = temp_state; |
| 2007 | return status; |
| 2008 | } |
| 2009 | |
| 2010 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2011 | * qla4_8xxx_check_fw_alive - Check firmware health |
| 2012 | * @ha: Pointer to host adapter structure. |
| 2013 | * |
| 2014 | * Context: Interrupt |
| 2015 | **/ |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2016 | static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2017 | { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2018 | uint32_t fw_heartbeat_counter; |
| 2019 | int status = QLA_SUCCESS; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2020 | |
| 2021 | fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2022 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| 2023 | if (fw_heartbeat_counter == 0xffffffff) { |
| 2024 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| 2025 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| 2026 | ha->host_no, __func__)); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2027 | return status; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2028 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2029 | |
| 2030 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| 2031 | ha->seconds_since_last_heartbeat++; |
| 2032 | /* FW not alive after 2 seconds */ |
| 2033 | if (ha->seconds_since_last_heartbeat == 2) { |
| 2034 | ha->seconds_since_last_heartbeat = 0; |
Vikas Chaudhary | 68d92eb | 2011-05-17 23:17:05 -0700 | [diff] [blame] | 2035 | |
| 2036 | ql4_printk(KERN_INFO, ha, |
| 2037 | "scsi(%ld): %s, Dumping hw/fw registers:\n " |
| 2038 | " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:" |
| 2039 | " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:" |
| 2040 | " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:" |
| 2041 | " 0x%x,\n PEG_NET_4_PC: 0x%x\n", |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2042 | ha->host_no, __func__, |
| 2043 | qla4_8xxx_rd_32(ha, |
| 2044 | QLA82XX_PEG_HALT_STATUS1), |
Vikas Chaudhary | 68d92eb | 2011-05-17 23:17:05 -0700 | [diff] [blame] | 2045 | qla4_8xxx_rd_32(ha, |
| 2046 | QLA82XX_PEG_HALT_STATUS2), |
| 2047 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 + |
| 2048 | 0x3c), |
| 2049 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 + |
| 2050 | 0x3c), |
| 2051 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 + |
| 2052 | 0x3c), |
| 2053 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 + |
| 2054 | 0x3c), |
| 2055 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 + |
| 2056 | 0x3c)); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2057 | status = QLA_ERROR; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2058 | } |
Lalit Chandivade | 99457d7 | 2010-10-06 22:49:32 -0700 | [diff] [blame] | 2059 | } else |
| 2060 | ha->seconds_since_last_heartbeat = 0; |
| 2061 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2062 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2063 | return status; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | /** |
| 2067 | * qla4_8xxx_watchdog - Poll dev state |
| 2068 | * @ha: Pointer to host adapter structure. |
| 2069 | * |
| 2070 | * Context: Interrupt |
| 2071 | **/ |
| 2072 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| 2073 | { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2074 | uint32_t dev_state, halt_status; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2075 | |
| 2076 | /* don't poll if reset is going on */ |
Lalit Chandivade | d56a1f7 | 2010-12-02 22:12:45 -0800 | [diff] [blame] | 2077 | if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 2078 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
Vikas Chaudhary | 977f46a | 2011-05-17 23:17:08 -0700 | [diff] [blame] | 2079 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2080 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 2081 | |
| 2082 | if (qla4_8xxx_check_temp(ha)) { |
Giridhar Malavali | e6bd0eb | 2012-01-11 02:44:16 -0800 | [diff] [blame^] | 2083 | ql4_printk(KERN_INFO, ha, "disabling pause" |
| 2084 | " transmit on port 0 & 1.\n"); |
| 2085 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 2086 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 2087 | CRB_NIU_XG_PAUSE_CTL_P1); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 2088 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 2089 | qla4xxx_wake_dpc(ha); |
| 2090 | } else if (dev_state == QLA82XX_DEV_NEED_RESET && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2091 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 2092 | if (!ql4xdontresethba) { |
| 2093 | ql4_printk(KERN_INFO, ha, "%s: HW State: " |
| 2094 | "NEED RESET!\n", __func__); |
| 2095 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2096 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 2097 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2098 | } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT && |
| 2099 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 2100 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
| 2101 | __func__); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2102 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| 2103 | qla4xxx_wake_dpc(ha); |
| 2104 | } else { |
| 2105 | /* Check firmware health */ |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2106 | if (qla4_8xxx_check_fw_alive(ha)) { |
Giridhar Malavali | e6bd0eb | 2012-01-11 02:44:16 -0800 | [diff] [blame^] | 2107 | ql4_printk(KERN_INFO, ha, "disabling pause" |
| 2108 | " transmit on port 0 & 1.\n"); |
| 2109 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 2110 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 2111 | CRB_NIU_XG_PAUSE_CTL_P1); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2112 | halt_status = qla4_8xxx_rd_32(ha, |
| 2113 | QLA82XX_PEG_HALT_STATUS1); |
| 2114 | |
| 2115 | /* Since we cannot change dev_state in interrupt |
| 2116 | * context, set appropriate DPC flag then wakeup |
| 2117 | * DPC */ |
| 2118 | if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| 2119 | set_bit(DPC_HA_UNRECOVERABLE, |
| 2120 | &ha->dpc_flags); |
| 2121 | else { |
| 2122 | ql4_printk(KERN_INFO, ha, "%s: detect " |
| 2123 | "abort needed!\n", __func__); |
| 2124 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2125 | } |
| 2126 | qla4xxx_mailbox_premature_completion(ha); |
| 2127 | qla4xxx_wake_dpc(ha); |
| 2128 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2129 | } |
| 2130 | } |
| 2131 | } |
| 2132 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 2133 | static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2134 | { |
| 2135 | struct iscsi_session *sess; |
| 2136 | struct ddb_entry *ddb_entry; |
| 2137 | struct scsi_qla_host *ha; |
| 2138 | |
| 2139 | sess = cls_sess->dd_data; |
| 2140 | ddb_entry = sess->dd_data; |
| 2141 | ha = ddb_entry->ha; |
| 2142 | |
| 2143 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 2144 | return; |
| 2145 | |
| 2146 | if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 2147 | !iscsi_is_session_online(cls_sess)) { |
| 2148 | if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| 2149 | INVALID_ENTRY) { |
| 2150 | if (atomic_read(&ddb_entry->retry_relogin_timer) == |
| 2151 | 0) { |
| 2152 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 2153 | INVALID_ENTRY); |
| 2154 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 2155 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 2156 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2157 | "%s: index [%d] login device\n", |
| 2158 | __func__, ddb_entry->fw_ddb_index)); |
| 2159 | } else |
| 2160 | atomic_dec(&ddb_entry->retry_relogin_timer); |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | /* Wait for relogin to timeout */ |
| 2165 | if (atomic_read(&ddb_entry->relogin_timer) && |
| 2166 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| 2167 | /* |
| 2168 | * If the relogin times out and the device is |
| 2169 | * still NOT ONLINE then try and relogin again. |
| 2170 | */ |
| 2171 | if (!iscsi_is_session_online(cls_sess)) { |
| 2172 | /* Reset retry relogin timer */ |
| 2173 | atomic_inc(&ddb_entry->relogin_retry_count); |
| 2174 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2175 | "%s: index[%d] relogin timed out-retrying" |
| 2176 | " relogin (%d), retry (%d)\n", __func__, |
| 2177 | ddb_entry->fw_ddb_index, |
| 2178 | atomic_read(&ddb_entry->relogin_retry_count), |
| 2179 | ddb_entry->default_time2wait + 4)); |
| 2180 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 2181 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 2182 | ddb_entry->default_time2wait + 4); |
| 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2187 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2188 | * qla4xxx_timer - checks every second for work to do. |
| 2189 | * @ha: Pointer to host adapter structure. |
| 2190 | **/ |
| 2191 | static void qla4xxx_timer(struct scsi_qla_host *ha) |
| 2192 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2193 | int start_dpc = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2194 | uint16_t w; |
| 2195 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2196 | iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb); |
| 2197 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2198 | /* If we are in the middle of AER/EEH processing |
| 2199 | * skip any processing and reschedule the timer |
| 2200 | */ |
| 2201 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 2202 | mod_timer(&ha->timer, jiffies + HZ); |
| 2203 | return; |
| 2204 | } |
| 2205 | |
| 2206 | /* Hardware read to trigger an EEH error during mailbox waits. */ |
| 2207 | if (!pci_channel_offline(ha->pdev)) |
| 2208 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2209 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2210 | if (is_qla8022(ha)) { |
| 2211 | qla4_8xxx_watchdog(ha); |
| 2212 | } |
| 2213 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2214 | if (!is_qla8022(ha)) { |
| 2215 | /* Check for heartbeat interval. */ |
| 2216 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| 2217 | ha->heartbeat_interval != 0) { |
| 2218 | ha->seconds_since_last_heartbeat++; |
| 2219 | if (ha->seconds_since_last_heartbeat > |
| 2220 | ha->heartbeat_interval + 2) |
| 2221 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2222 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2225 | /* Wakeup the dpc routine for this adapter, if needed. */ |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 2226 | if (start_dpc || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2227 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 2228 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| 2229 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2230 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2231 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 2232 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 2233 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2234 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 2235 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 2236 | test_bit(DPC_AEN, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2237 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| 2238 | " - dpc flags = 0x%lx\n", |
| 2239 | ha->host_no, __func__, ha->dpc_flags)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2240 | qla4xxx_wake_dpc(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | /* Reschedule timer thread to call us back in one second */ |
| 2244 | mod_timer(&ha->timer, jiffies + HZ); |
| 2245 | |
| 2246 | DEBUG2(ha->seconds_since_last_intr++); |
| 2247 | } |
| 2248 | |
| 2249 | /** |
| 2250 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| 2251 | * @ha: Pointer to host adapter structure. |
| 2252 | * |
| 2253 | * This routine stalls the driver until all outstanding commands are returned. |
| 2254 | * Caller must release the Hardware Lock prior to calling this routine. |
| 2255 | **/ |
| 2256 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| 2257 | { |
| 2258 | uint32_t index = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2259 | unsigned long flags; |
| 2260 | struct scsi_cmnd *cmd; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2261 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2262 | unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
| 2263 | |
| 2264 | DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " |
| 2265 | "complete\n", WAIT_CMD_TOV)); |
| 2266 | |
| 2267 | while (!time_after_eq(jiffies, wtime)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2268 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2269 | /* Find a command that hasn't completed. */ |
| 2270 | for (index = 0; index < ha->host->can_queue; index++) { |
| 2271 | cmd = scsi_host_find_tag(ha->host, index); |
Mike Christie | a1e0063 | 2010-10-26 05:45:30 -0700 | [diff] [blame] | 2272 | /* |
| 2273 | * We cannot just check if the index is valid, |
| 2274 | * becase if we are run from the scsi eh, then |
| 2275 | * the scsi/block layer is going to prevent |
| 2276 | * the tag from being released. |
| 2277 | */ |
| 2278 | if (cmd != NULL && CMD_SP(cmd)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2279 | break; |
| 2280 | } |
| 2281 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2282 | |
| 2283 | /* If No Commands are pending, wait is complete */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2284 | if (index == ha->host->can_queue) |
| 2285 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2286 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2287 | msleep(1000); |
| 2288 | } |
| 2289 | /* If we timed out on waiting for commands to come back |
| 2290 | * return ERROR. */ |
| 2291 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2294 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2295 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2296 | uint32_t ctrl_status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2297 | unsigned long flags = 0; |
| 2298 | |
| 2299 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2300 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2301 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 2302 | return QLA_ERROR; |
| 2303 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2304 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2305 | |
| 2306 | /* |
| 2307 | * If the SCSI Reset Interrupt bit is set, clear it. |
| 2308 | * Otherwise, the Soft Reset won't work. |
| 2309 | */ |
| 2310 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 2311 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| 2312 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 2313 | |
| 2314 | /* Issue Soft Reset */ |
| 2315 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| 2316 | readl(&ha->reg->ctrl_status); |
| 2317 | |
| 2318 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2319 | return QLA_SUCCESS; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /** |
| 2323 | * qla4xxx_soft_reset - performs soft reset. |
| 2324 | * @ha: Pointer to host adapter structure. |
| 2325 | **/ |
| 2326 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| 2327 | { |
| 2328 | uint32_t max_wait_time; |
| 2329 | unsigned long flags = 0; |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 2330 | int status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2331 | uint32_t ctrl_status; |
| 2332 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 2333 | status = qla4xxx_hw_reset(ha); |
| 2334 | if (status != QLA_SUCCESS) |
| 2335 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2336 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 2337 | status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2338 | /* Wait until the Network Reset Intr bit is cleared */ |
| 2339 | max_wait_time = RESET_INTR_TOV; |
| 2340 | do { |
| 2341 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2342 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 2343 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2344 | |
| 2345 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| 2346 | break; |
| 2347 | |
| 2348 | msleep(1000); |
| 2349 | } while ((--max_wait_time)); |
| 2350 | |
| 2351 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| 2352 | DEBUG2(printk(KERN_WARNING |
| 2353 | "scsi%ld: Network Reset Intr not cleared by " |
| 2354 | "Network function, clearing it now!\n", |
| 2355 | ha->host_no)); |
| 2356 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2357 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| 2358 | readl(&ha->reg->ctrl_status); |
| 2359 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2360 | } |
| 2361 | |
| 2362 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 2363 | max_wait_time = SOFT_RESET_TOV; |
| 2364 | do { |
| 2365 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2366 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 2367 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2368 | |
| 2369 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| 2370 | status = QLA_SUCCESS; |
| 2371 | break; |
| 2372 | } |
| 2373 | |
| 2374 | msleep(1000); |
| 2375 | } while ((--max_wait_time)); |
| 2376 | |
| 2377 | /* |
| 2378 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| 2379 | * after the soft reset has taken place. |
| 2380 | */ |
| 2381 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2382 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 2383 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| 2384 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 2385 | readl(&ha->reg->ctrl_status); |
| 2386 | } |
| 2387 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2388 | |
| 2389 | /* If soft reset fails then most probably the bios on other |
| 2390 | * function is also enabled. |
| 2391 | * Since the initialization is sequential the other fn |
| 2392 | * wont be able to acknowledge the soft reset. |
| 2393 | * Issue a force soft reset to workaround this scenario. |
| 2394 | */ |
| 2395 | if (max_wait_time == 0) { |
| 2396 | /* Issue Force Soft Reset */ |
| 2397 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2398 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| 2399 | readl(&ha->reg->ctrl_status); |
| 2400 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2401 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 2402 | max_wait_time = SOFT_RESET_TOV; |
| 2403 | do { |
| 2404 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2405 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 2406 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2407 | |
| 2408 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| 2409 | status = QLA_SUCCESS; |
| 2410 | break; |
| 2411 | } |
| 2412 | |
| 2413 | msleep(1000); |
| 2414 | } while ((--max_wait_time)); |
| 2415 | } |
| 2416 | |
| 2417 | return status; |
| 2418 | } |
| 2419 | |
| 2420 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2421 | * 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] | 2422 | * @ha: Pointer to host adapter structure. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2423 | * @res: returned scsi status |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2424 | * |
| 2425 | * This routine is called just prior to a HARD RESET to return all |
| 2426 | * outstanding commands back to the Operating System. |
| 2427 | * Caller should make sure that the following locks are released |
| 2428 | * before this calling routine: Hardware lock, and io_request_lock. |
| 2429 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2430 | 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] | 2431 | { |
| 2432 | struct srb *srb; |
| 2433 | int i; |
| 2434 | unsigned long flags; |
| 2435 | |
| 2436 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2437 | for (i = 0; i < ha->host->can_queue; i++) { |
| 2438 | srb = qla4xxx_del_from_active_array(ha, i); |
| 2439 | if (srb != NULL) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2440 | srb->cmd->result = res; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2441 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2442 | } |
| 2443 | } |
| 2444 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2447 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| 2448 | { |
| 2449 | clear_bit(AF_ONLINE, &ha->flags); |
| 2450 | |
| 2451 | /* Disable the board */ |
| 2452 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2453 | |
| 2454 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 2455 | qla4xxx_mark_all_devices_missing(ha); |
| 2456 | clear_bit(AF_INIT_DONE, &ha->flags); |
| 2457 | } |
| 2458 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2459 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session) |
| 2460 | { |
| 2461 | struct iscsi_session *sess; |
| 2462 | struct ddb_entry *ddb_entry; |
| 2463 | |
| 2464 | sess = cls_session->dd_data; |
| 2465 | ddb_entry = sess->dd_data; |
| 2466 | ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2467 | |
| 2468 | if (ddb_entry->ddb_type == FLASH_DDB) |
| 2469 | iscsi_block_session(ddb_entry->sess); |
| 2470 | else |
| 2471 | iscsi_session_failure(cls_session->dd_data, |
| 2472 | ISCSI_ERR_CONN_FAILED); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2473 | } |
| 2474 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2475 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2476 | * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| 2477 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2478 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2479 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2480 | { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2481 | int status = QLA_ERROR; |
| 2482 | uint8_t reset_chip = 0; |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 2483 | uint32_t dev_state; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2484 | unsigned long wait; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2485 | |
| 2486 | /* Stall incoming I/O until we are done */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2487 | scsi_block_requests(ha->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2488 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2489 | clear_bit(AF_LINK_UP, &ha->flags); |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 2490 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2491 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2492 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2493 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2494 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2495 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
| 2496 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2497 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 2498 | reset_chip = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2499 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2500 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| 2501 | * do not reset adapter, jump to initialize_adapter */ |
| 2502 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| 2503 | status = QLA_SUCCESS; |
| 2504 | goto recover_ha_init_adapter; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2507 | /* For the ISP-82xx adapter, issue a stop_firmware if invoked |
| 2508 | * from eh_host_reset or ioctl module */ |
| 2509 | if (is_qla8022(ha) && !reset_chip && |
| 2510 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 2511 | |
| 2512 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2513 | "scsi%ld: %s - Performing stop_firmware...\n", |
| 2514 | ha->host_no, __func__)); |
| 2515 | status = ha->isp_ops->reset_firmware(ha); |
| 2516 | if (status == QLA_SUCCESS) { |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 2517 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 2518 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2519 | ha->isp_ops->disable_intrs(ha); |
| 2520 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 2521 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 2522 | } else { |
| 2523 | /* If the stop_firmware fails then |
| 2524 | * reset the entire chip */ |
| 2525 | reset_chip = 1; |
| 2526 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 2527 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | /* Issue full chip reset if recovering from a catastrophic error, |
| 2532 | * or if stop_firmware fails for ISP-82xx. |
| 2533 | * This is the default case for ISP-4xxx */ |
| 2534 | if (!is_qla8022(ha) || reset_chip) { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2535 | if (!is_qla8022(ha)) |
| 2536 | goto chip_reset; |
| 2537 | |
| 2538 | /* Check if 82XX firmware is alive or not |
| 2539 | * We may have arrived here from NEED_RESET |
| 2540 | * detection only */ |
| 2541 | if (test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 2542 | goto chip_reset; |
| 2543 | |
| 2544 | wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ); |
| 2545 | while (time_before(jiffies, wait)) { |
| 2546 | if (qla4_8xxx_check_fw_alive(ha)) { |
| 2547 | qla4xxx_mailbox_premature_completion(ha); |
| 2548 | break; |
| 2549 | } |
| 2550 | |
| 2551 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 2552 | schedule_timeout(HZ); |
| 2553 | } |
| 2554 | |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 2555 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 2556 | qla4xxx_cmd_wait(ha); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2557 | chip_reset: |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2558 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 2559 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 2560 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2561 | "scsi%ld: %s - Performing chip reset..\n", |
| 2562 | ha->host_no, __func__)); |
| 2563 | status = ha->isp_ops->reset_chip(ha); |
| 2564 | } |
| 2565 | |
| 2566 | /* Flush any pending ddb changed AENs */ |
| 2567 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 2568 | |
| 2569 | recover_ha_init_adapter: |
| 2570 | /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| 2571 | if (status == QLA_SUCCESS) { |
| 2572 | /* For ISP-4xxx, force function 1 to always initialize |
| 2573 | * before function 3 to prevent both funcions from |
| 2574 | * stepping on top of the other */ |
| 2575 | if (!is_qla8022(ha) && (ha->mac_index == 3)) |
| 2576 | ssleep(6); |
| 2577 | |
| 2578 | /* NOTE: AF_ONLINE flag set upon successful completion of |
| 2579 | * qla4xxx_initialize_adapter */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2580 | status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | /* Retry failed adapter initialization, if necessary |
| 2584 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| 2585 | * case to prevent ping-pong resets between functions */ |
| 2586 | if (!test_bit(AF_ONLINE, &ha->flags) && |
| 2587 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2588 | /* Adapter initialization failed, see if we can retry |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2589 | * resetting the ha. |
| 2590 | * Since we don't want to block the DPC for too long |
| 2591 | * with multiple resets in the same thread, |
| 2592 | * utilize DPC to retry */ |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 2593 | if (is_qla8022(ha)) { |
| 2594 | qla4_8xxx_idc_lock(ha); |
| 2595 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 2596 | qla4_8xxx_idc_unlock(ha); |
| 2597 | if (dev_state == QLA82XX_DEV_FAILED) { |
| 2598 | ql4_printk(KERN_INFO, ha, "%s: don't retry " |
| 2599 | "recover adapter. H/W is in Failed " |
| 2600 | "state\n", __func__); |
| 2601 | qla4xxx_dead_adapter_cleanup(ha); |
| 2602 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 2603 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2604 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 2605 | &ha->dpc_flags); |
| 2606 | status = QLA_ERROR; |
| 2607 | |
| 2608 | goto exit_recover; |
| 2609 | } |
| 2610 | } |
| 2611 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2612 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| 2613 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| 2614 | DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| 2615 | "(%d) more times\n", ha->host_no, |
| 2616 | ha->retry_reset_ha_cnt)); |
| 2617 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 2618 | status = QLA_ERROR; |
| 2619 | } else { |
| 2620 | if (ha->retry_reset_ha_cnt > 0) { |
| 2621 | /* Schedule another Reset HA--DPC will retry */ |
| 2622 | ha->retry_reset_ha_cnt--; |
| 2623 | DEBUG2(printk("scsi%ld: recover adapter - " |
| 2624 | "retry remaining %d\n", |
| 2625 | ha->host_no, |
| 2626 | ha->retry_reset_ha_cnt)); |
| 2627 | status = QLA_ERROR; |
| 2628 | } |
| 2629 | |
| 2630 | if (ha->retry_reset_ha_cnt == 0) { |
| 2631 | /* Recover adapter retries have been exhausted. |
| 2632 | * Adapter DEAD */ |
| 2633 | DEBUG2(printk("scsi%ld: recover adapter " |
| 2634 | "failed - board disabled\n", |
| 2635 | ha->host_no)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2636 | qla4xxx_dead_adapter_cleanup(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2637 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 2638 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2639 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2640 | &ha->dpc_flags); |
| 2641 | status = QLA_ERROR; |
| 2642 | } |
| 2643 | } |
| 2644 | } else { |
| 2645 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2646 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2647 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 2648 | } |
| 2649 | |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 2650 | exit_recover: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2651 | ha->adapter_error_count++; |
| 2652 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2653 | if (test_bit(AF_ONLINE, &ha->flags)) |
| 2654 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2655 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2656 | scsi_unblock_requests(ha->host); |
| 2657 | |
| 2658 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 2659 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2660 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2661 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2662 | return status; |
| 2663 | } |
| 2664 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2665 | static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session) |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 2666 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2667 | struct iscsi_session *sess; |
| 2668 | struct ddb_entry *ddb_entry; |
| 2669 | struct scsi_qla_host *ha; |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 2670 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2671 | sess = cls_session->dd_data; |
| 2672 | ddb_entry = sess->dd_data; |
| 2673 | ha = ddb_entry->ha; |
| 2674 | if (!iscsi_is_session_online(cls_session)) { |
| 2675 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| 2676 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 2677 | " unblock session\n", ha->host_no, __func__, |
| 2678 | ddb_entry->fw_ddb_index); |
| 2679 | iscsi_unblock_session(ddb_entry->sess); |
| 2680 | } else { |
| 2681 | /* Trigger relogin */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2682 | if (ddb_entry->ddb_type == FLASH_DDB) { |
| 2683 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 2684 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 2685 | } else |
| 2686 | iscsi_session_failure(cls_session->dd_data, |
| 2687 | ISCSI_ERR_CONN_FAILED); |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | } |
| 2691 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2692 | int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session) |
| 2693 | { |
| 2694 | struct iscsi_session *sess; |
| 2695 | struct ddb_entry *ddb_entry; |
| 2696 | struct scsi_qla_host *ha; |
| 2697 | |
| 2698 | sess = cls_session->dd_data; |
| 2699 | ddb_entry = sess->dd_data; |
| 2700 | ha = ddb_entry->ha; |
| 2701 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 2702 | " unblock session\n", ha->host_no, __func__, |
| 2703 | ddb_entry->fw_ddb_index); |
| 2704 | |
| 2705 | iscsi_unblock_session(ddb_entry->sess); |
| 2706 | |
| 2707 | /* Start scan target */ |
| 2708 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 2709 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 2710 | " start scan\n", ha->host_no, __func__, |
| 2711 | ddb_entry->fw_ddb_index); |
| 2712 | scsi_queue_work(ha->host, &ddb_entry->sess->scan_work); |
| 2713 | } |
| 2714 | return QLA_SUCCESS; |
| 2715 | } |
| 2716 | |
| 2717 | int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session) |
| 2718 | { |
| 2719 | struct iscsi_session *sess; |
| 2720 | struct ddb_entry *ddb_entry; |
| 2721 | struct scsi_qla_host *ha; |
| 2722 | |
| 2723 | sess = cls_session->dd_data; |
| 2724 | ddb_entry = sess->dd_data; |
| 2725 | ha = ddb_entry->ha; |
| 2726 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 2727 | " unblock user space session\n", ha->host_no, __func__, |
| 2728 | ddb_entry->fw_ddb_index); |
| 2729 | iscsi_conn_start(ddb_entry->conn); |
| 2730 | iscsi_conn_login_event(ddb_entry->conn, |
| 2731 | ISCSI_CONN_STATE_LOGGED_IN); |
| 2732 | |
| 2733 | return QLA_SUCCESS; |
| 2734 | } |
| 2735 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2736 | static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
| 2737 | { |
| 2738 | iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices); |
| 2739 | } |
| 2740 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2741 | static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| 2742 | { |
| 2743 | uint16_t relogin_timer; |
| 2744 | struct iscsi_session *sess; |
| 2745 | struct ddb_entry *ddb_entry; |
| 2746 | struct scsi_qla_host *ha; |
| 2747 | |
| 2748 | sess = cls_sess->dd_data; |
| 2749 | ddb_entry = sess->dd_data; |
| 2750 | ha = ddb_entry->ha; |
| 2751 | |
| 2752 | relogin_timer = max(ddb_entry->default_relogin_timeout, |
| 2753 | (uint16_t)RELOGIN_TOV); |
| 2754 | atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| 2755 | |
| 2756 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2757 | "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no, |
| 2758 | ddb_entry->fw_ddb_index, relogin_timer)); |
| 2759 | |
| 2760 | qla4xxx_login_flash_ddb(cls_sess); |
| 2761 | } |
| 2762 | |
| 2763 | static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess) |
| 2764 | { |
| 2765 | struct iscsi_session *sess; |
| 2766 | struct ddb_entry *ddb_entry; |
| 2767 | struct scsi_qla_host *ha; |
| 2768 | |
| 2769 | sess = cls_sess->dd_data; |
| 2770 | ddb_entry = sess->dd_data; |
| 2771 | ha = ddb_entry->ha; |
| 2772 | |
| 2773 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 2774 | return; |
| 2775 | |
| 2776 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 2777 | !iscsi_is_session_online(cls_sess)) { |
| 2778 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2779 | "relogin issued\n")); |
| 2780 | qla4xxx_relogin_flash_ddb(cls_sess); |
| 2781 | } |
| 2782 | } |
| 2783 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2784 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| 2785 | { |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 2786 | if (ha->dpc_thread) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2787 | queue_work(ha->dpc_thread, &ha->dpc_work); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2788 | } |
| 2789 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2790 | /** |
| 2791 | * qla4xxx_do_dpc - dpc routine |
| 2792 | * @data: in our case pointer to adapter structure |
| 2793 | * |
| 2794 | * This routine is a task that is schedule by the interrupt handler |
| 2795 | * to perform the background processing for interrupts. We put it |
| 2796 | * on a task queue that is consumed whenever the scheduler runs; that's |
| 2797 | * so you can do anything (i.e. put the process to sleep etc). In fact, |
| 2798 | * the mid-level tries to sleep when it reaches the driver threshold |
| 2799 | * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| 2800 | **/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2801 | static void qla4xxx_do_dpc(struct work_struct *work) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2802 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2803 | struct scsi_qla_host *ha = |
| 2804 | container_of(work, struct scsi_qla_host, dpc_work); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2805 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2806 | |
David C Somayajulu | f26b904 | 2006-11-15 16:41:09 -0800 | [diff] [blame] | 2807 | DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2808 | "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| 2809 | ha->host_no, __func__, ha->flags, ha->dpc_flags)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2810 | |
| 2811 | /* Initialization not yet finished. Don't do anything yet. */ |
| 2812 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 2813 | return; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2814 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2815 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 2816 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| 2817 | ha->host_no, __func__, ha->flags)); |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 2818 | return; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2819 | } |
| 2820 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2821 | if (is_qla8022(ha)) { |
| 2822 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
| 2823 | qla4_8xxx_idc_lock(ha); |
| 2824 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 2825 | QLA82XX_DEV_FAILED); |
| 2826 | qla4_8xxx_idc_unlock(ha); |
| 2827 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 2828 | qla4_8xxx_device_state_handler(ha); |
| 2829 | } |
| 2830 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 2831 | qla4_8xxx_need_qsnt_handler(ha); |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| 2836 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2837 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2838 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
| 2839 | if (ql4xdontresethba) { |
| 2840 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 2841 | ha->host_no, __func__)); |
| 2842 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2843 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 2844 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 2845 | goto dpc_post_reset_ha; |
| 2846 | } |
| 2847 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| 2848 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 2849 | qla4xxx_recover_adapter(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2850 | |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2851 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2852 | uint8_t wait_time = RESET_INTR_TOV; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2853 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2854 | while ((readw(&ha->reg->ctrl_status) & |
| 2855 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| 2856 | if (--wait_time == 0) |
| 2857 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2858 | msleep(1000); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2859 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2860 | if (wait_time == 0) |
| 2861 | DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| 2862 | "bit not cleared-- resetting\n", |
| 2863 | ha->host_no, __func__)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2864 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2865 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| 2866 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2867 | status = qla4xxx_recover_adapter(ha); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2868 | } |
| 2869 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 2870 | if (status == QLA_SUCCESS) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2871 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2872 | } |
| 2873 | } |
| 2874 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2875 | dpc_post_reset_ha: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2876 | /* ---- process AEN? --- */ |
| 2877 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 2878 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| 2879 | |
| 2880 | /* ---- Get DHCP IP Address? --- */ |
| 2881 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 2882 | qla4xxx_get_dhcp_ip_address(ha); |
| 2883 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2884 | /* ---- relogin device? --- */ |
| 2885 | if (adapter_up(ha) && |
| 2886 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| 2887 | iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin); |
| 2888 | } |
| 2889 | |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 2890 | /* ---- link change? --- */ |
| 2891 | if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
| 2892 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 2893 | /* ---- link down? --- */ |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 2894 | qla4xxx_mark_all_devices_missing(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 2895 | } else { |
| 2896 | /* ---- link up? --- * |
| 2897 | * F/W will auto login to all devices ONLY ONCE after |
| 2898 | * link up during driver initialization and runtime |
| 2899 | * fatal error recovery. Therefore, the driver must |
| 2900 | * manually relogin to devices when recovering from |
| 2901 | * connection failures, logouts, expired KATO, etc. */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2902 | if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) { |
| 2903 | qla4xxx_build_ddb_list(ha, ha->is_reset); |
| 2904 | iscsi_host_for_each_session(ha->host, |
| 2905 | qla4xxx_login_flash_ddb); |
| 2906 | } else |
| 2907 | qla4xxx_relogin_all_devices(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 2908 | } |
| 2909 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | /** |
| 2913 | * qla4xxx_free_adapter - release the adapter |
| 2914 | * @ha: pointer to adapter structure |
| 2915 | **/ |
| 2916 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| 2917 | { |
Sarang Radke | 8a28896 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 2918 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2919 | |
| 2920 | if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) { |
| 2921 | /* Turn-off interrupts on the card. */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2922 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2925 | /* Remove timer thread, if present */ |
| 2926 | if (ha->timer_active) |
| 2927 | qla4xxx_stop_timer(ha); |
| 2928 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2929 | /* Kill the kernel thread for this host */ |
| 2930 | if (ha->dpc_thread) |
| 2931 | destroy_workqueue(ha->dpc_thread); |
| 2932 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2933 | /* Kill the kernel thread for this host */ |
| 2934 | if (ha->task_wq) |
| 2935 | destroy_workqueue(ha->task_wq); |
| 2936 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2937 | /* Put firmware in known state */ |
| 2938 | ha->isp_ops->reset_firmware(ha); |
| 2939 | |
| 2940 | if (is_qla8022(ha)) { |
| 2941 | qla4_8xxx_idc_lock(ha); |
| 2942 | qla4_8xxx_clear_drv_active(ha); |
| 2943 | qla4_8xxx_idc_unlock(ha); |
| 2944 | } |
| 2945 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2946 | /* Detach interrupts */ |
| 2947 | if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2948 | qla4xxx_free_irqs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2949 | |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 2950 | /* free extra memory */ |
| 2951 | qla4xxx_mem_free(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2952 | } |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 2953 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2954 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| 2955 | { |
| 2956 | int status = 0; |
| 2957 | uint8_t revision_id; |
| 2958 | unsigned long mem_base, mem_len, db_base, db_len; |
| 2959 | struct pci_dev *pdev = ha->pdev; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2960 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2961 | status = pci_request_regions(pdev, DRIVER_NAME); |
| 2962 | if (status) { |
| 2963 | printk(KERN_WARNING |
| 2964 | "scsi(%ld) Failed to reserve PIO regions (%s) " |
| 2965 | "status=%d\n", ha->host_no, pci_name(pdev), status); |
| 2966 | goto iospace_error_exit; |
| 2967 | } |
| 2968 | |
| 2969 | pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id); |
| 2970 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
| 2971 | __func__, revision_id)); |
| 2972 | ha->revision_id = revision_id; |
| 2973 | |
| 2974 | /* remap phys address */ |
| 2975 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 2976 | mem_len = pci_resource_len(pdev, 0); |
| 2977 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| 2978 | __func__, mem_base, mem_len)); |
| 2979 | |
| 2980 | /* mapping of pcibase pointer */ |
| 2981 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| 2982 | if (!ha->nx_pcibase) { |
| 2983 | printk(KERN_ERR |
| 2984 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| 2985 | pci_release_regions(ha->pdev); |
| 2986 | goto iospace_error_exit; |
| 2987 | } |
| 2988 | |
| 2989 | /* Mapping of IO base pointer, door bell read and write pointer */ |
| 2990 | |
| 2991 | /* mapping of IO base pointer */ |
| 2992 | ha->qla4_8xxx_reg = |
| 2993 | (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase + |
| 2994 | 0xbc000 + (ha->pdev->devfn << 11)); |
| 2995 | |
| 2996 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 2997 | db_len = pci_resource_len(pdev, 4); |
| 2998 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 2999 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| 3000 | QLA82XX_CAM_RAM_DB2); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3001 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 3002 | return 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3003 | iospace_error_exit: |
| 3004 | return -ENOMEM; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | /*** |
| 3008 | * qla4xxx_iospace_config - maps registers |
| 3009 | * @ha: pointer to adapter structure |
| 3010 | * |
| 3011 | * This routines maps HBA's registers from the pci address space |
| 3012 | * into the kernel virtual address space for memory mapped i/o. |
| 3013 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3014 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3015 | { |
| 3016 | unsigned long pio, pio_len, pio_flags; |
| 3017 | unsigned long mmio, mmio_len, mmio_flags; |
| 3018 | |
| 3019 | pio = pci_resource_start(ha->pdev, 0); |
| 3020 | pio_len = pci_resource_len(ha->pdev, 0); |
| 3021 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 3022 | if (pio_flags & IORESOURCE_IO) { |
| 3023 | if (pio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3024 | ql4_printk(KERN_WARNING, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3025 | "Invalid PCI I/O region size\n"); |
| 3026 | pio = 0; |
| 3027 | } |
| 3028 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3029 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3030 | pio = 0; |
| 3031 | } |
| 3032 | |
| 3033 | /* Use MMIO operations for all accesses. */ |
| 3034 | mmio = pci_resource_start(ha->pdev, 1); |
| 3035 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 3036 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 3037 | |
| 3038 | if (!(mmio_flags & IORESOURCE_MEM)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3039 | ql4_printk(KERN_ERR, ha, |
| 3040 | "region #0 not an MMIO resource, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3041 | |
| 3042 | goto iospace_error_exit; |
| 3043 | } |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3044 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3045 | if (mmio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3046 | ql4_printk(KERN_ERR, ha, |
| 3047 | "Invalid PCI mem region size, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3048 | goto iospace_error_exit; |
| 3049 | } |
| 3050 | |
| 3051 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3052 | ql4_printk(KERN_WARNING, ha, |
| 3053 | "Failed to reserve PIO/MMIO regions\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3054 | |
| 3055 | goto iospace_error_exit; |
| 3056 | } |
| 3057 | |
| 3058 | ha->pio_address = pio; |
| 3059 | ha->pio_length = pio_len; |
| 3060 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| 3061 | if (!ha->reg) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3062 | ql4_printk(KERN_ERR, ha, |
| 3063 | "cannot remap MMIO, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3064 | |
| 3065 | goto iospace_error_exit; |
| 3066 | } |
| 3067 | |
| 3068 | return 0; |
| 3069 | |
| 3070 | iospace_error_exit: |
| 3071 | return -ENOMEM; |
| 3072 | } |
| 3073 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3074 | static struct isp_operations qla4xxx_isp_ops = { |
| 3075 | .iospace_config = qla4xxx_iospace_config, |
| 3076 | .pci_config = qla4xxx_pci_config, |
| 3077 | .disable_intrs = qla4xxx_disable_intrs, |
| 3078 | .enable_intrs = qla4xxx_enable_intrs, |
| 3079 | .start_firmware = qla4xxx_start_firmware, |
| 3080 | .intr_handler = qla4xxx_intr_handler, |
| 3081 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| 3082 | .reset_chip = qla4xxx_soft_reset, |
| 3083 | .reset_firmware = qla4xxx_hw_reset, |
| 3084 | .queue_iocb = qla4xxx_queue_iocb, |
| 3085 | .complete_iocb = qla4xxx_complete_iocb, |
| 3086 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 3087 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| 3088 | .get_sys_info = qla4xxx_get_sys_info, |
| 3089 | }; |
| 3090 | |
| 3091 | static struct isp_operations qla4_8xxx_isp_ops = { |
| 3092 | .iospace_config = qla4_8xxx_iospace_config, |
| 3093 | .pci_config = qla4_8xxx_pci_config, |
| 3094 | .disable_intrs = qla4_8xxx_disable_intrs, |
| 3095 | .enable_intrs = qla4_8xxx_enable_intrs, |
| 3096 | .start_firmware = qla4_8xxx_load_risc, |
| 3097 | .intr_handler = qla4_8xxx_intr_handler, |
| 3098 | .interrupt_service_routine = qla4_8xxx_interrupt_service_routine, |
| 3099 | .reset_chip = qla4_8xxx_isp_reset, |
| 3100 | .reset_firmware = qla4_8xxx_stop_firmware, |
| 3101 | .queue_iocb = qla4_8xxx_queue_iocb, |
| 3102 | .complete_iocb = qla4_8xxx_complete_iocb, |
| 3103 | .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out, |
| 3104 | .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in, |
| 3105 | .get_sys_info = qla4_8xxx_get_sys_info, |
| 3106 | }; |
| 3107 | |
| 3108 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 3109 | { |
| 3110 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| 3111 | } |
| 3112 | |
| 3113 | uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 3114 | { |
| 3115 | return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out)); |
| 3116 | } |
| 3117 | |
| 3118 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 3119 | { |
| 3120 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); |
| 3121 | } |
| 3122 | |
| 3123 | uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 3124 | { |
| 3125 | return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in)); |
| 3126 | } |
| 3127 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3128 | static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf) |
| 3129 | { |
| 3130 | struct scsi_qla_host *ha = data; |
| 3131 | char *str = buf; |
| 3132 | int rc; |
| 3133 | |
| 3134 | switch (type) { |
| 3135 | case ISCSI_BOOT_ETH_FLAGS: |
| 3136 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 3137 | break; |
| 3138 | case ISCSI_BOOT_ETH_INDEX: |
| 3139 | rc = sprintf(str, "0\n"); |
| 3140 | break; |
| 3141 | case ISCSI_BOOT_ETH_MAC: |
| 3142 | rc = sysfs_format_mac(str, ha->my_mac, |
| 3143 | MAC_ADDR_LEN); |
| 3144 | break; |
| 3145 | default: |
| 3146 | rc = -ENOSYS; |
| 3147 | break; |
| 3148 | } |
| 3149 | return rc; |
| 3150 | } |
| 3151 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 3152 | static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3153 | { |
| 3154 | int rc; |
| 3155 | |
| 3156 | switch (type) { |
| 3157 | case ISCSI_BOOT_ETH_FLAGS: |
| 3158 | case ISCSI_BOOT_ETH_MAC: |
| 3159 | case ISCSI_BOOT_ETH_INDEX: |
| 3160 | rc = S_IRUGO; |
| 3161 | break; |
| 3162 | default: |
| 3163 | rc = 0; |
| 3164 | break; |
| 3165 | } |
| 3166 | return rc; |
| 3167 | } |
| 3168 | |
| 3169 | static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf) |
| 3170 | { |
| 3171 | struct scsi_qla_host *ha = data; |
| 3172 | char *str = buf; |
| 3173 | int rc; |
| 3174 | |
| 3175 | switch (type) { |
| 3176 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 3177 | rc = sprintf(str, "%s\n", ha->name_string); |
| 3178 | break; |
| 3179 | default: |
| 3180 | rc = -ENOSYS; |
| 3181 | break; |
| 3182 | } |
| 3183 | return rc; |
| 3184 | } |
| 3185 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 3186 | static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3187 | { |
| 3188 | int rc; |
| 3189 | |
| 3190 | switch (type) { |
| 3191 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 3192 | rc = S_IRUGO; |
| 3193 | break; |
| 3194 | default: |
| 3195 | rc = 0; |
| 3196 | break; |
| 3197 | } |
| 3198 | return rc; |
| 3199 | } |
| 3200 | |
| 3201 | static ssize_t |
| 3202 | qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type, |
| 3203 | char *buf) |
| 3204 | { |
| 3205 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 3206 | char *str = buf; |
| 3207 | int rc; |
| 3208 | |
| 3209 | switch (type) { |
| 3210 | case ISCSI_BOOT_TGT_NAME: |
| 3211 | rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name); |
| 3212 | break; |
| 3213 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 3214 | if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1) |
| 3215 | rc = sprintf(buf, "%pI4\n", |
| 3216 | &boot_conn->dest_ipaddr.ip_address); |
| 3217 | else |
| 3218 | rc = sprintf(str, "%pI6\n", |
| 3219 | &boot_conn->dest_ipaddr.ip_address); |
| 3220 | break; |
| 3221 | case ISCSI_BOOT_TGT_PORT: |
| 3222 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 3223 | break; |
| 3224 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 3225 | rc = sprintf(str, "%.*s\n", |
| 3226 | boot_conn->chap.target_chap_name_length, |
| 3227 | (char *)&boot_conn->chap.target_chap_name); |
| 3228 | break; |
| 3229 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 3230 | rc = sprintf(str, "%.*s\n", |
| 3231 | boot_conn->chap.target_secret_length, |
| 3232 | (char *)&boot_conn->chap.target_secret); |
| 3233 | break; |
| 3234 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 3235 | rc = sprintf(str, "%.*s\n", |
| 3236 | boot_conn->chap.intr_chap_name_length, |
| 3237 | (char *)&boot_conn->chap.intr_chap_name); |
| 3238 | break; |
| 3239 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 3240 | rc = sprintf(str, "%.*s\n", |
| 3241 | boot_conn->chap.intr_secret_length, |
| 3242 | (char *)&boot_conn->chap.intr_secret); |
| 3243 | break; |
| 3244 | case ISCSI_BOOT_TGT_FLAGS: |
| 3245 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 3246 | break; |
| 3247 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 3248 | rc = sprintf(str, "0\n"); |
| 3249 | break; |
| 3250 | default: |
| 3251 | rc = -ENOSYS; |
| 3252 | break; |
| 3253 | } |
| 3254 | return rc; |
| 3255 | } |
| 3256 | |
| 3257 | static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf) |
| 3258 | { |
| 3259 | struct scsi_qla_host *ha = data; |
| 3260 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess); |
| 3261 | |
| 3262 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 3263 | } |
| 3264 | |
| 3265 | static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf) |
| 3266 | { |
| 3267 | struct scsi_qla_host *ha = data; |
| 3268 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess); |
| 3269 | |
| 3270 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 3271 | } |
| 3272 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 3273 | static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3274 | { |
| 3275 | int rc; |
| 3276 | |
| 3277 | switch (type) { |
| 3278 | case ISCSI_BOOT_TGT_NAME: |
| 3279 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 3280 | case ISCSI_BOOT_TGT_PORT: |
| 3281 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 3282 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 3283 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 3284 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 3285 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 3286 | case ISCSI_BOOT_TGT_FLAGS: |
| 3287 | rc = S_IRUGO; |
| 3288 | break; |
| 3289 | default: |
| 3290 | rc = 0; |
| 3291 | break; |
| 3292 | } |
| 3293 | return rc; |
| 3294 | } |
| 3295 | |
| 3296 | static void qla4xxx_boot_release(void *data) |
| 3297 | { |
| 3298 | struct scsi_qla_host *ha = data; |
| 3299 | |
| 3300 | scsi_host_put(ha->host); |
| 3301 | } |
| 3302 | |
| 3303 | static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) |
| 3304 | { |
| 3305 | dma_addr_t buf_dma; |
| 3306 | uint32_t addr, pri_addr, sec_addr; |
| 3307 | uint32_t offset; |
| 3308 | uint16_t func_num; |
| 3309 | uint8_t val; |
| 3310 | uint8_t *buf = NULL; |
| 3311 | size_t size = 13 * sizeof(uint8_t); |
| 3312 | int ret = QLA_SUCCESS; |
| 3313 | |
| 3314 | func_num = PCI_FUNC(ha->pdev->devfn); |
| 3315 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 3316 | ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n", |
| 3317 | __func__, ha->pdev->device, func_num); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3318 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 3319 | if (is_qla40XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3320 | if (func_num == 1) { |
| 3321 | addr = NVRAM_PORT0_BOOT_MODE; |
| 3322 | pri_addr = NVRAM_PORT0_BOOT_PRI_TGT; |
| 3323 | sec_addr = NVRAM_PORT0_BOOT_SEC_TGT; |
| 3324 | } else if (func_num == 3) { |
| 3325 | addr = NVRAM_PORT1_BOOT_MODE; |
| 3326 | pri_addr = NVRAM_PORT1_BOOT_PRI_TGT; |
| 3327 | sec_addr = NVRAM_PORT1_BOOT_SEC_TGT; |
| 3328 | } else { |
| 3329 | ret = QLA_ERROR; |
| 3330 | goto exit_boot_info; |
| 3331 | } |
| 3332 | |
| 3333 | /* Check Boot Mode */ |
| 3334 | val = rd_nvram_byte(ha, addr); |
| 3335 | if (!(val & 0x07)) { |
| 3336 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 3337 | "%s: Failed Boot options : 0x%x\n", |
| 3338 | __func__, val)); |
| 3339 | ret = QLA_ERROR; |
| 3340 | goto exit_boot_info; |
| 3341 | } |
| 3342 | |
| 3343 | /* get primary valid target index */ |
| 3344 | val = rd_nvram_byte(ha, pri_addr); |
| 3345 | if (val & BIT_7) |
| 3346 | ddb_index[0] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3347 | |
| 3348 | /* get secondary valid target index */ |
| 3349 | val = rd_nvram_byte(ha, sec_addr); |
| 3350 | if (val & BIT_7) |
| 3351 | ddb_index[1] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3352 | |
| 3353 | } else if (is_qla8022(ha)) { |
| 3354 | buf = dma_alloc_coherent(&ha->pdev->dev, size, |
| 3355 | &buf_dma, GFP_KERNEL); |
| 3356 | if (!buf) { |
| 3357 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 3358 | "%s: Unable to allocate dma buffer\n", |
| 3359 | __func__)); |
| 3360 | ret = QLA_ERROR; |
| 3361 | goto exit_boot_info; |
| 3362 | } |
| 3363 | |
| 3364 | if (ha->port_num == 0) |
| 3365 | offset = BOOT_PARAM_OFFSET_PORT0; |
| 3366 | else if (ha->port_num == 1) |
| 3367 | offset = BOOT_PARAM_OFFSET_PORT1; |
| 3368 | else { |
| 3369 | ret = QLA_ERROR; |
| 3370 | goto exit_boot_info_free; |
| 3371 | } |
| 3372 | addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) + |
| 3373 | offset; |
| 3374 | if (qla4xxx_get_flash(ha, buf_dma, addr, |
| 3375 | 13 * sizeof(uint8_t)) != QLA_SUCCESS) { |
| 3376 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash" |
| 3377 | "failed\n", ha->host_no, __func__)); |
| 3378 | ret = QLA_ERROR; |
| 3379 | goto exit_boot_info_free; |
| 3380 | } |
| 3381 | /* Check Boot Mode */ |
| 3382 | if (!(buf[1] & 0x07)) { |
| 3383 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3384 | "Failed: Boot options : 0x%x\n", |
| 3385 | buf[1])); |
| 3386 | ret = QLA_ERROR; |
| 3387 | goto exit_boot_info_free; |
| 3388 | } |
| 3389 | |
| 3390 | /* get primary valid target index */ |
| 3391 | if (buf[2] & BIT_7) |
| 3392 | ddb_index[0] = buf[2] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3393 | |
| 3394 | /* get secondary valid target index */ |
| 3395 | if (buf[11] & BIT_7) |
| 3396 | ddb_index[1] = buf[11] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3397 | } else { |
| 3398 | ret = QLA_ERROR; |
| 3399 | goto exit_boot_info; |
| 3400 | } |
| 3401 | |
| 3402 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary" |
| 3403 | " target ID %d\n", __func__, ddb_index[0], |
| 3404 | ddb_index[1])); |
| 3405 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3406 | ha->pri_ddb_idx = ddb_index[0]; |
| 3407 | ha->sec_ddb_idx = ddb_index[1]; |
| 3408 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3409 | exit_boot_info_free: |
| 3410 | dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma); |
| 3411 | exit_boot_info: |
| 3412 | return ret; |
| 3413 | } |
| 3414 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 3415 | /** |
| 3416 | * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password |
| 3417 | * @ha: pointer to adapter structure |
| 3418 | * @username: CHAP username to be returned |
| 3419 | * @password: CHAP password to be returned |
| 3420 | * |
| 3421 | * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP |
| 3422 | * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/. |
| 3423 | * So from the CHAP cache find the first BIDI CHAP entry and set it |
| 3424 | * to the boot record in sysfs. |
| 3425 | **/ |
| 3426 | static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username, |
| 3427 | char *password) |
| 3428 | { |
| 3429 | int i, ret = -EINVAL; |
| 3430 | int max_chap_entries = 0; |
| 3431 | struct ql4_chap_table *chap_table; |
| 3432 | |
| 3433 | if (is_qla8022(ha)) |
| 3434 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 3435 | sizeof(struct ql4_chap_table); |
| 3436 | else |
| 3437 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 3438 | |
| 3439 | if (!ha->chap_list) { |
| 3440 | ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n"); |
| 3441 | return ret; |
| 3442 | } |
| 3443 | |
| 3444 | mutex_lock(&ha->chap_sem); |
| 3445 | for (i = 0; i < max_chap_entries; i++) { |
| 3446 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 3447 | if (chap_table->cookie != |
| 3448 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 3449 | continue; |
| 3450 | } |
| 3451 | |
| 3452 | if (chap_table->flags & BIT_7) /* local */ |
| 3453 | continue; |
| 3454 | |
| 3455 | if (!(chap_table->flags & BIT_6)) /* Not BIDI */ |
| 3456 | continue; |
| 3457 | |
| 3458 | strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN); |
| 3459 | strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN); |
| 3460 | ret = 0; |
| 3461 | break; |
| 3462 | } |
| 3463 | mutex_unlock(&ha->chap_sem); |
| 3464 | |
| 3465 | return ret; |
| 3466 | } |
| 3467 | |
| 3468 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3469 | static int qla4xxx_get_boot_target(struct scsi_qla_host *ha, |
| 3470 | struct ql4_boot_session_info *boot_sess, |
| 3471 | uint16_t ddb_index) |
| 3472 | { |
| 3473 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 3474 | struct dev_db_entry *fw_ddb_entry; |
| 3475 | dma_addr_t fw_ddb_entry_dma; |
| 3476 | uint16_t idx; |
| 3477 | uint16_t options; |
| 3478 | int ret = QLA_SUCCESS; |
| 3479 | |
| 3480 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3481 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3482 | if (!fw_ddb_entry) { |
| 3483 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 3484 | "%s: Unable to allocate dma buffer.\n", |
| 3485 | __func__)); |
| 3486 | ret = QLA_ERROR; |
| 3487 | return ret; |
| 3488 | } |
| 3489 | |
| 3490 | if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry, |
| 3491 | fw_ddb_entry_dma, ddb_index)) { |
| 3492 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 3493 | "%s: Flash DDB read Failed\n", __func__)); |
| 3494 | ret = QLA_ERROR; |
| 3495 | goto exit_boot_target; |
| 3496 | } |
| 3497 | |
| 3498 | /* Update target name and IP from DDB */ |
| 3499 | memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name, |
| 3500 | min(sizeof(boot_sess->target_name), |
| 3501 | sizeof(fw_ddb_entry->iscsi_name))); |
| 3502 | |
| 3503 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3504 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 3505 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 3506 | &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN); |
| 3507 | } else { |
| 3508 | boot_conn->dest_ipaddr.ip_type = 0x1; |
| 3509 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 3510 | &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN); |
| 3511 | } |
| 3512 | |
| 3513 | boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port); |
| 3514 | |
| 3515 | /* update chap information */ |
| 3516 | idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3517 | |
| 3518 | if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 3519 | |
| 3520 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n")); |
| 3521 | |
| 3522 | ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap. |
| 3523 | target_chap_name, |
| 3524 | (char *)&boot_conn->chap.target_secret, |
| 3525 | idx); |
| 3526 | if (ret) { |
| 3527 | ql4_printk(KERN_ERR, ha, "Failed to set chap\n"); |
| 3528 | ret = QLA_ERROR; |
| 3529 | goto exit_boot_target; |
| 3530 | } |
| 3531 | |
| 3532 | boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 3533 | boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 3534 | } |
| 3535 | |
| 3536 | if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 3537 | |
| 3538 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n")); |
| 3539 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 3540 | ret = qla4xxx_get_bidi_chap(ha, |
| 3541 | (char *)&boot_conn->chap.intr_chap_name, |
| 3542 | (char *)&boot_conn->chap.intr_secret); |
| 3543 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3544 | if (ret) { |
| 3545 | ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n"); |
| 3546 | ret = QLA_ERROR; |
| 3547 | goto exit_boot_target; |
| 3548 | } |
| 3549 | |
| 3550 | boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 3551 | boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 3552 | } |
| 3553 | |
| 3554 | exit_boot_target: |
| 3555 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3556 | fw_ddb_entry, fw_ddb_entry_dma); |
| 3557 | return ret; |
| 3558 | } |
| 3559 | |
| 3560 | static int qla4xxx_get_boot_info(struct scsi_qla_host *ha) |
| 3561 | { |
| 3562 | uint16_t ddb_index[2]; |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3563 | int ret = QLA_ERROR; |
| 3564 | int rval; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3565 | |
| 3566 | memset(ddb_index, 0, sizeof(ddb_index)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3567 | ddb_index[0] = 0xffff; |
| 3568 | ddb_index[1] = 0xffff; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3569 | ret = get_fw_boot_info(ha, ddb_index); |
| 3570 | if (ret != QLA_SUCCESS) { |
| 3571 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 3572 | "%s: Failed to set boot info.\n", __func__)); |
| 3573 | return ret; |
| 3574 | } |
| 3575 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3576 | if (ql4xdisablesysfsboot) |
| 3577 | return QLA_SUCCESS; |
| 3578 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3579 | if (ddb_index[0] == 0xffff) |
| 3580 | goto sec_target; |
| 3581 | |
| 3582 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3583 | ddb_index[0]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3584 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3585 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get " |
| 3586 | "primary target\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3587 | } else |
| 3588 | ret = QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3589 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3590 | sec_target: |
| 3591 | if (ddb_index[1] == 0xffff) |
| 3592 | goto exit_get_boot_info; |
| 3593 | |
| 3594 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3595 | ddb_index[1]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3596 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3597 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get " |
| 3598 | "secondary target\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 3599 | } else |
| 3600 | ret = QLA_SUCCESS; |
| 3601 | |
| 3602 | exit_get_boot_info: |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3603 | return ret; |
| 3604 | } |
| 3605 | |
| 3606 | static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha) |
| 3607 | { |
| 3608 | struct iscsi_boot_kobj *boot_kobj; |
| 3609 | |
| 3610 | if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3611 | return QLA_ERROR; |
| 3612 | |
| 3613 | if (ql4xdisablesysfsboot) { |
| 3614 | ql4_printk(KERN_INFO, ha, |
| 3615 | "%s: syfsboot disabled - driver will trigger login" |
| 3616 | "and publish session for discovery .\n", __func__); |
| 3617 | return QLA_SUCCESS; |
| 3618 | } |
| 3619 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3620 | |
| 3621 | ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no); |
| 3622 | if (!ha->boot_kset) |
| 3623 | goto kset_free; |
| 3624 | |
| 3625 | if (!scsi_host_get(ha->host)) |
| 3626 | goto kset_free; |
| 3627 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha, |
| 3628 | qla4xxx_show_boot_tgt_pri_info, |
| 3629 | qla4xxx_tgt_get_attr_visibility, |
| 3630 | qla4xxx_boot_release); |
| 3631 | if (!boot_kobj) |
| 3632 | goto put_host; |
| 3633 | |
| 3634 | if (!scsi_host_get(ha->host)) |
| 3635 | goto kset_free; |
| 3636 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha, |
| 3637 | qla4xxx_show_boot_tgt_sec_info, |
| 3638 | qla4xxx_tgt_get_attr_visibility, |
| 3639 | qla4xxx_boot_release); |
| 3640 | if (!boot_kobj) |
| 3641 | goto put_host; |
| 3642 | |
| 3643 | if (!scsi_host_get(ha->host)) |
| 3644 | goto kset_free; |
| 3645 | boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha, |
| 3646 | qla4xxx_show_boot_ini_info, |
| 3647 | qla4xxx_ini_get_attr_visibility, |
| 3648 | qla4xxx_boot_release); |
| 3649 | if (!boot_kobj) |
| 3650 | goto put_host; |
| 3651 | |
| 3652 | if (!scsi_host_get(ha->host)) |
| 3653 | goto kset_free; |
| 3654 | boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha, |
| 3655 | qla4xxx_show_boot_eth_info, |
| 3656 | qla4xxx_eth_get_attr_visibility, |
| 3657 | qla4xxx_boot_release); |
| 3658 | if (!boot_kobj) |
| 3659 | goto put_host; |
| 3660 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3661 | return QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 3662 | |
| 3663 | put_host: |
| 3664 | scsi_host_put(ha->host); |
| 3665 | kset_free: |
| 3666 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 3667 | return -ENOMEM; |
| 3668 | } |
| 3669 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 3670 | |
| 3671 | /** |
| 3672 | * qla4xxx_create chap_list - Create CHAP list from FLASH |
| 3673 | * @ha: pointer to adapter structure |
| 3674 | * |
| 3675 | * Read flash and make a list of CHAP entries, during login when a CHAP entry |
| 3676 | * is received, it will be checked in this list. If entry exist then the CHAP |
| 3677 | * entry index is set in the DDB. If CHAP entry does not exist in this list |
| 3678 | * then a new entry is added in FLASH in CHAP table and the index obtained is |
| 3679 | * used in the DDB. |
| 3680 | **/ |
| 3681 | static void qla4xxx_create_chap_list(struct scsi_qla_host *ha) |
| 3682 | { |
| 3683 | int rval = 0; |
| 3684 | uint8_t *chap_flash_data = NULL; |
| 3685 | uint32_t offset; |
| 3686 | dma_addr_t chap_dma; |
| 3687 | uint32_t chap_size = 0; |
| 3688 | |
| 3689 | if (is_qla40XX(ha)) |
| 3690 | chap_size = MAX_CHAP_ENTRIES_40XX * |
| 3691 | sizeof(struct ql4_chap_table); |
| 3692 | else /* Single region contains CHAP info for both |
| 3693 | * ports which is divided into half for each port. |
| 3694 | */ |
| 3695 | chap_size = ha->hw.flt_chap_size / 2; |
| 3696 | |
| 3697 | chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size, |
| 3698 | &chap_dma, GFP_KERNEL); |
| 3699 | if (!chap_flash_data) { |
| 3700 | ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n"); |
| 3701 | return; |
| 3702 | } |
| 3703 | if (is_qla40XX(ha)) |
| 3704 | offset = FLASH_CHAP_OFFSET; |
| 3705 | else { |
| 3706 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 3707 | if (ha->port_num == 1) |
| 3708 | offset += chap_size; |
| 3709 | } |
| 3710 | |
| 3711 | rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 3712 | if (rval != QLA_SUCCESS) |
| 3713 | goto exit_chap_list; |
| 3714 | |
| 3715 | if (ha->chap_list == NULL) |
| 3716 | ha->chap_list = vmalloc(chap_size); |
| 3717 | if (ha->chap_list == NULL) { |
| 3718 | ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n"); |
| 3719 | goto exit_chap_list; |
| 3720 | } |
| 3721 | |
| 3722 | memcpy(ha->chap_list, chap_flash_data, chap_size); |
| 3723 | |
| 3724 | exit_chap_list: |
| 3725 | dma_free_coherent(&ha->pdev->dev, chap_size, |
| 3726 | chap_flash_data, chap_dma); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3729 | static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry, |
| 3730 | struct ql4_tuple_ddb *tddb) |
| 3731 | { |
| 3732 | struct scsi_qla_host *ha; |
| 3733 | struct iscsi_cls_session *cls_sess; |
| 3734 | struct iscsi_cls_conn *cls_conn; |
| 3735 | struct iscsi_session *sess; |
| 3736 | struct iscsi_conn *conn; |
| 3737 | |
| 3738 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3739 | ha = ddb_entry->ha; |
| 3740 | cls_sess = ddb_entry->sess; |
| 3741 | sess = cls_sess->dd_data; |
| 3742 | cls_conn = ddb_entry->conn; |
| 3743 | conn = cls_conn->dd_data; |
| 3744 | |
| 3745 | tddb->tpgt = sess->tpgt; |
| 3746 | tddb->port = conn->persistent_port; |
| 3747 | strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE); |
| 3748 | strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN); |
| 3749 | } |
| 3750 | |
| 3751 | static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry, |
| 3752 | struct ql4_tuple_ddb *tddb) |
| 3753 | { |
| 3754 | uint16_t options = 0; |
| 3755 | |
| 3756 | tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3757 | memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
| 3758 | min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name))); |
| 3759 | |
| 3760 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3761 | if (options & DDB_OPT_IPV6_DEVICE) |
| 3762 | sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 3763 | else |
| 3764 | sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 3765 | |
| 3766 | tddb->port = le16_to_cpu(fw_ddb_entry->port); |
| 3767 | } |
| 3768 | |
| 3769 | static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha, |
| 3770 | struct ql4_tuple_ddb *old_tddb, |
| 3771 | struct ql4_tuple_ddb *new_tddb) |
| 3772 | { |
| 3773 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 3774 | return QLA_ERROR; |
| 3775 | |
| 3776 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr)) |
| 3777 | return QLA_ERROR; |
| 3778 | |
| 3779 | if (old_tddb->port != new_tddb->port) |
| 3780 | return QLA_ERROR; |
| 3781 | |
| 3782 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3783 | "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]", |
| 3784 | old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr, |
| 3785 | old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt, |
| 3786 | new_tddb->ip_addr, new_tddb->iscsi_name)); |
| 3787 | |
| 3788 | return QLA_SUCCESS; |
| 3789 | } |
| 3790 | |
| 3791 | static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, |
| 3792 | struct dev_db_entry *fw_ddb_entry) |
| 3793 | { |
| 3794 | struct ddb_entry *ddb_entry; |
| 3795 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 3796 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 3797 | int idx; |
| 3798 | int ret = QLA_ERROR; |
| 3799 | |
| 3800 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 3801 | if (!fw_tddb) { |
| 3802 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 3803 | "Memory Allocation failed.\n")); |
| 3804 | ret = QLA_SUCCESS; |
| 3805 | goto exit_check; |
| 3806 | } |
| 3807 | |
| 3808 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 3809 | if (!tmp_tddb) { |
| 3810 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 3811 | "Memory Allocation failed.\n")); |
| 3812 | ret = QLA_SUCCESS; |
| 3813 | goto exit_check; |
| 3814 | } |
| 3815 | |
| 3816 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb); |
| 3817 | |
| 3818 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 3819 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 3820 | if (ddb_entry == NULL) |
| 3821 | continue; |
| 3822 | |
| 3823 | qla4xxx_get_param_ddb(ddb_entry, tmp_tddb); |
| 3824 | if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb)) { |
| 3825 | ret = QLA_SUCCESS; /* found */ |
| 3826 | goto exit_check; |
| 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | exit_check: |
| 3831 | if (fw_tddb) |
| 3832 | vfree(fw_tddb); |
| 3833 | if (tmp_tddb) |
| 3834 | vfree(tmp_tddb); |
| 3835 | return ret; |
| 3836 | } |
| 3837 | |
| 3838 | static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, |
| 3839 | struct list_head *list_nt, |
| 3840 | struct dev_db_entry *fw_ddb_entry) |
| 3841 | { |
| 3842 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 3843 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 3844 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 3845 | int ret = QLA_ERROR; |
| 3846 | |
| 3847 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 3848 | if (!fw_tddb) { |
| 3849 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 3850 | "Memory Allocation failed.\n")); |
| 3851 | ret = QLA_SUCCESS; |
| 3852 | goto exit_check; |
| 3853 | } |
| 3854 | |
| 3855 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 3856 | if (!tmp_tddb) { |
| 3857 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 3858 | "Memory Allocation failed.\n")); |
| 3859 | ret = QLA_SUCCESS; |
| 3860 | goto exit_check; |
| 3861 | } |
| 3862 | |
| 3863 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb); |
| 3864 | |
| 3865 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 3866 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb); |
| 3867 | if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb)) { |
| 3868 | ret = QLA_SUCCESS; /* found */ |
| 3869 | goto exit_check; |
| 3870 | } |
| 3871 | } |
| 3872 | |
| 3873 | exit_check: |
| 3874 | if (fw_tddb) |
| 3875 | vfree(fw_tddb); |
| 3876 | if (tmp_tddb) |
| 3877 | vfree(tmp_tddb); |
| 3878 | return ret; |
| 3879 | } |
| 3880 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 3881 | static void qla4xxx_free_ddb_list(struct list_head *list_ddb) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3882 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 3883 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3884 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 3885 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 3886 | list_del_init(&ddb_idx->list); |
| 3887 | vfree(ddb_idx); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3888 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha, |
| 3892 | struct dev_db_entry *fw_ddb_entry) |
| 3893 | { |
| 3894 | struct iscsi_endpoint *ep; |
| 3895 | struct sockaddr_in *addr; |
| 3896 | struct sockaddr_in6 *addr6; |
| 3897 | struct sockaddr *dst_addr; |
| 3898 | char *ip; |
| 3899 | |
| 3900 | /* TODO: need to destroy on unload iscsi_endpoint*/ |
| 3901 | dst_addr = vmalloc(sizeof(*dst_addr)); |
| 3902 | if (!dst_addr) |
| 3903 | return NULL; |
| 3904 | |
| 3905 | if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) { |
| 3906 | dst_addr->sa_family = AF_INET6; |
| 3907 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 3908 | ip = (char *)&addr6->sin6_addr; |
| 3909 | memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 3910 | addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 3911 | |
| 3912 | } else { |
| 3913 | dst_addr->sa_family = AF_INET; |
| 3914 | addr = (struct sockaddr_in *)dst_addr; |
| 3915 | ip = (char *)&addr->sin_addr; |
| 3916 | memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN); |
| 3917 | addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 3918 | } |
| 3919 | |
| 3920 | ep = qla4xxx_ep_connect(ha->host, dst_addr, 0); |
| 3921 | vfree(dst_addr); |
| 3922 | return ep; |
| 3923 | } |
| 3924 | |
| 3925 | static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx) |
| 3926 | { |
| 3927 | if (ql4xdisablesysfsboot) |
| 3928 | return QLA_SUCCESS; |
| 3929 | if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx) |
| 3930 | return QLA_ERROR; |
| 3931 | return QLA_SUCCESS; |
| 3932 | } |
| 3933 | |
| 3934 | static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha, |
| 3935 | struct ddb_entry *ddb_entry) |
| 3936 | { |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 3937 | uint16_t def_timeout; |
| 3938 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3939 | ddb_entry->ddb_type = FLASH_DDB; |
| 3940 | ddb_entry->fw_ddb_index = INVALID_ENTRY; |
| 3941 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 3942 | ddb_entry->ha = ha; |
| 3943 | ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb; |
| 3944 | ddb_entry->ddb_change = qla4xxx_flash_ddb_change; |
| 3945 | |
| 3946 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 3947 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 3948 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 3949 | def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3950 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 3951 | (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ? |
| 3952 | def_timeout : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3953 | ddb_entry->default_time2wait = |
| 3954 | le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait); |
| 3955 | } |
| 3956 | |
| 3957 | static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha) |
| 3958 | { |
| 3959 | uint32_t idx = 0; |
| 3960 | uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */ |
| 3961 | uint32_t sts[MBOX_REG_COUNT]; |
| 3962 | uint32_t ip_state; |
| 3963 | unsigned long wtime; |
| 3964 | int ret; |
| 3965 | |
| 3966 | wtime = jiffies + (HZ * IP_CONFIG_TOV); |
| 3967 | do { |
| 3968 | for (idx = 0; idx < IP_ADDR_COUNT; idx++) { |
| 3969 | if (ip_idx[idx] == -1) |
| 3970 | continue; |
| 3971 | |
| 3972 | ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts); |
| 3973 | |
| 3974 | if (ret == QLA_ERROR) { |
| 3975 | ip_idx[idx] = -1; |
| 3976 | continue; |
| 3977 | } |
| 3978 | |
| 3979 | ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT; |
| 3980 | |
| 3981 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3982 | "Waiting for IP state for idx = %d, state = 0x%x\n", |
| 3983 | ip_idx[idx], ip_state)); |
| 3984 | if (ip_state == IP_ADDRSTATE_UNCONFIGURED || |
| 3985 | ip_state == IP_ADDRSTATE_INVALID || |
| 3986 | ip_state == IP_ADDRSTATE_PREFERRED || |
| 3987 | ip_state == IP_ADDRSTATE_DEPRICATED || |
| 3988 | ip_state == IP_ADDRSTATE_DISABLING) |
| 3989 | ip_idx[idx] = -1; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | /* Break if all IP states checked */ |
| 3993 | if ((ip_idx[0] == -1) && |
| 3994 | (ip_idx[1] == -1) && |
| 3995 | (ip_idx[2] == -1) && |
| 3996 | (ip_idx[3] == -1)) |
| 3997 | break; |
| 3998 | schedule_timeout_uninterruptible(HZ); |
| 3999 | } while (time_after(wtime, jiffies)); |
| 4000 | } |
| 4001 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4002 | static void qla4xxx_build_st_list(struct scsi_qla_host *ha, |
| 4003 | struct list_head *list_st) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4004 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4005 | struct qla_ddb_index *st_ddb_idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4006 | int max_ddbs; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4007 | int fw_idx_size; |
| 4008 | struct dev_db_entry *fw_ddb_entry; |
| 4009 | dma_addr_t fw_ddb_dma; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4010 | int ret; |
| 4011 | uint32_t idx = 0, next_idx = 0; |
| 4012 | uint32_t state = 0, conn_err = 0; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4013 | uint16_t conn_id = 0; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4014 | |
| 4015 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 4016 | &fw_ddb_dma); |
| 4017 | if (fw_ddb_entry == NULL) { |
| 4018 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4019 | goto exit_st_list; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4020 | } |
| 4021 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4022 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 4023 | MAX_DEV_DB_ENTRIES; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4024 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 4025 | |
| 4026 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4027 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 4028 | NULL, &next_idx, &state, |
| 4029 | &conn_err, NULL, &conn_id); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4030 | if (ret == QLA_ERROR) |
| 4031 | break; |
| 4032 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4033 | /* Check if ST, add to the list_st */ |
| 4034 | if (strlen((char *) fw_ddb_entry->iscsi_name) != 0) |
| 4035 | goto continue_next_st; |
| 4036 | |
| 4037 | st_ddb_idx = vzalloc(fw_idx_size); |
| 4038 | if (!st_ddb_idx) |
| 4039 | break; |
| 4040 | |
| 4041 | st_ddb_idx->fw_ddb_idx = idx; |
| 4042 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4043 | list_add_tail(&st_ddb_idx->list, list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4044 | continue_next_st: |
| 4045 | if (next_idx == 0) |
| 4046 | break; |
| 4047 | } |
| 4048 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4049 | exit_st_list: |
| 4050 | if (fw_ddb_entry) |
| 4051 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 4052 | } |
| 4053 | |
| 4054 | /** |
| 4055 | * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list |
| 4056 | * @ha: pointer to adapter structure |
| 4057 | * @list_ddb: List from which failed ddb to be removed |
| 4058 | * |
| 4059 | * Iterate over the list of DDBs and find and remove DDBs that are either in |
| 4060 | * no connection active state or failed state |
| 4061 | **/ |
| 4062 | static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha, |
| 4063 | struct list_head *list_ddb) |
| 4064 | { |
| 4065 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 4066 | uint32_t next_idx = 0; |
| 4067 | uint32_t state = 0, conn_err = 0; |
| 4068 | int ret; |
| 4069 | |
| 4070 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 4071 | ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx, |
| 4072 | NULL, 0, NULL, &next_idx, &state, |
| 4073 | &conn_err, NULL, NULL); |
| 4074 | if (ret == QLA_ERROR) |
| 4075 | continue; |
| 4076 | |
| 4077 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 4078 | state == DDB_DS_SESSION_FAILED) { |
| 4079 | list_del_init(&ddb_idx->list); |
| 4080 | vfree(ddb_idx); |
| 4081 | } |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha, |
| 4086 | struct dev_db_entry *fw_ddb_entry, |
| 4087 | int is_reset) |
| 4088 | { |
| 4089 | struct iscsi_cls_session *cls_sess; |
| 4090 | struct iscsi_session *sess; |
| 4091 | struct iscsi_cls_conn *cls_conn; |
| 4092 | struct iscsi_endpoint *ep; |
| 4093 | uint16_t cmds_max = 32; |
| 4094 | uint16_t conn_id = 0; |
| 4095 | uint32_t initial_cmdsn = 0; |
| 4096 | int ret = QLA_SUCCESS; |
| 4097 | |
| 4098 | struct ddb_entry *ddb_entry = NULL; |
| 4099 | |
| 4100 | /* Create session object, with INVALID_ENTRY, |
| 4101 | * the targer_id would get set when we issue the login |
| 4102 | */ |
| 4103 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host, |
| 4104 | cmds_max, sizeof(struct ddb_entry), |
| 4105 | sizeof(struct ql4_task_data), |
| 4106 | initial_cmdsn, INVALID_ENTRY); |
| 4107 | if (!cls_sess) { |
| 4108 | ret = QLA_ERROR; |
| 4109 | goto exit_setup; |
| 4110 | } |
| 4111 | |
| 4112 | /* |
| 4113 | * so calling module_put function to decrement the |
| 4114 | * reference count. |
| 4115 | **/ |
| 4116 | module_put(qla4xxx_iscsi_transport.owner); |
| 4117 | sess = cls_sess->dd_data; |
| 4118 | ddb_entry = sess->dd_data; |
| 4119 | ddb_entry->sess = cls_sess; |
| 4120 | |
| 4121 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 4122 | memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry, |
| 4123 | sizeof(struct dev_db_entry)); |
| 4124 | |
| 4125 | qla4xxx_setup_flash_ddb_entry(ha, ddb_entry); |
| 4126 | |
| 4127 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id); |
| 4128 | |
| 4129 | if (!cls_conn) { |
| 4130 | ret = QLA_ERROR; |
| 4131 | goto exit_setup; |
| 4132 | } |
| 4133 | |
| 4134 | ddb_entry->conn = cls_conn; |
| 4135 | |
| 4136 | /* Setup ep, for displaying attributes in sysfs */ |
| 4137 | ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry); |
| 4138 | if (ep) { |
| 4139 | ep->conn = cls_conn; |
| 4140 | cls_conn->ep = ep; |
| 4141 | } else { |
| 4142 | DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n")); |
| 4143 | ret = QLA_ERROR; |
| 4144 | goto exit_setup; |
| 4145 | } |
| 4146 | |
| 4147 | /* Update sess/conn params */ |
| 4148 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 4149 | |
| 4150 | if (is_reset == RESET_ADAPTER) { |
| 4151 | iscsi_block_session(cls_sess); |
| 4152 | /* Use the relogin path to discover new devices |
| 4153 | * by short-circuting the logic of setting |
| 4154 | * timer to relogin - instead set the flags |
| 4155 | * to initiate login right away. |
| 4156 | */ |
| 4157 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4158 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 4159 | } |
| 4160 | |
| 4161 | exit_setup: |
| 4162 | return ret; |
| 4163 | } |
| 4164 | |
| 4165 | static void qla4xxx_build_nt_list(struct scsi_qla_host *ha, |
| 4166 | struct list_head *list_nt, int is_reset) |
| 4167 | { |
| 4168 | struct dev_db_entry *fw_ddb_entry; |
| 4169 | dma_addr_t fw_ddb_dma; |
| 4170 | int max_ddbs; |
| 4171 | int fw_idx_size; |
| 4172 | int ret; |
| 4173 | uint32_t idx = 0, next_idx = 0; |
| 4174 | uint32_t state = 0, conn_err = 0; |
| 4175 | uint16_t conn_id = 0; |
| 4176 | struct qla_ddb_index *nt_ddb_idx; |
| 4177 | |
| 4178 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 4179 | &fw_ddb_dma); |
| 4180 | if (fw_ddb_entry == NULL) { |
| 4181 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 4182 | goto exit_nt_list; |
| 4183 | } |
| 4184 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 4185 | MAX_DEV_DB_ENTRIES; |
| 4186 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 4187 | |
| 4188 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 4189 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 4190 | NULL, &next_idx, &state, |
| 4191 | &conn_err, NULL, &conn_id); |
| 4192 | if (ret == QLA_ERROR) |
| 4193 | break; |
| 4194 | |
| 4195 | if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS) |
| 4196 | goto continue_next_nt; |
| 4197 | |
| 4198 | /* Check if NT, then add to list it */ |
| 4199 | if (strlen((char *) fw_ddb_entry->iscsi_name) == 0) |
| 4200 | goto continue_next_nt; |
| 4201 | |
| 4202 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 4203 | state == DDB_DS_SESSION_FAILED)) |
| 4204 | goto continue_next_nt; |
| 4205 | |
| 4206 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4207 | "Adding DDB to session = 0x%x\n", idx)); |
| 4208 | if (is_reset == INIT_ADAPTER) { |
| 4209 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 4210 | if (!nt_ddb_idx) |
| 4211 | break; |
| 4212 | |
| 4213 | nt_ddb_idx->fw_ddb_idx = idx; |
| 4214 | |
| 4215 | memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry, |
| 4216 | sizeof(struct dev_db_entry)); |
| 4217 | |
| 4218 | if (qla4xxx_is_flash_ddb_exists(ha, list_nt, |
| 4219 | fw_ddb_entry) == QLA_SUCCESS) { |
| 4220 | vfree(nt_ddb_idx); |
| 4221 | goto continue_next_nt; |
| 4222 | } |
| 4223 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 4224 | } else if (is_reset == RESET_ADAPTER) { |
| 4225 | if (qla4xxx_is_session_exists(ha, fw_ddb_entry) == |
| 4226 | QLA_SUCCESS) |
| 4227 | goto continue_next_nt; |
| 4228 | } |
| 4229 | |
| 4230 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset); |
| 4231 | if (ret == QLA_ERROR) |
| 4232 | goto exit_nt_list; |
| 4233 | |
| 4234 | continue_next_nt: |
| 4235 | if (next_idx == 0) |
| 4236 | break; |
| 4237 | } |
| 4238 | |
| 4239 | exit_nt_list: |
| 4240 | if (fw_ddb_entry) |
| 4241 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * qla4xxx_build_ddb_list - Build ddb list and setup sessions |
| 4246 | * @ha: pointer to adapter structure |
| 4247 | * @is_reset: Is this init path or reset path |
| 4248 | * |
| 4249 | * Create a list of sendtargets (st) from firmware DDBs, issue send targets |
| 4250 | * using connection open, then create the list of normal targets (nt) |
| 4251 | * from firmware DDBs. Based on the list of nt setup session and connection |
| 4252 | * objects. |
| 4253 | **/ |
| 4254 | void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset) |
| 4255 | { |
| 4256 | uint16_t tmo = 0; |
| 4257 | struct list_head list_st, list_nt; |
| 4258 | struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp; |
| 4259 | unsigned long wtime; |
| 4260 | |
| 4261 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 4262 | set_bit(AF_BUILD_DDB_LIST, &ha->flags); |
| 4263 | ha->is_reset = is_reset; |
| 4264 | return; |
| 4265 | } |
| 4266 | |
| 4267 | INIT_LIST_HEAD(&list_st); |
| 4268 | INIT_LIST_HEAD(&list_nt); |
| 4269 | |
| 4270 | qla4xxx_build_st_list(ha, &list_st); |
| 4271 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4272 | /* Before issuing conn open mbox, ensure all IPs states are configured |
| 4273 | * Note, conn open fails if IPs are not configured |
| 4274 | */ |
| 4275 | qla4xxx_wait_for_ip_configuration(ha); |
| 4276 | |
| 4277 | /* Go thru the STs and fire the sendtargets by issuing conn open mbx */ |
| 4278 | list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) { |
| 4279 | qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx); |
| 4280 | } |
| 4281 | |
| 4282 | /* Wait to ensure all sendtargets are done for min 12 sec wait */ |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 4283 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 4284 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 4285 | ha->def_timeout : LOGIN_TOV); |
| 4286 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4287 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4288 | "Default time to wait for build ddb %d\n", tmo)); |
| 4289 | |
| 4290 | wtime = jiffies + (HZ * tmo); |
| 4291 | do { |
Nilesh Javali | f1f2e60 | 2011-12-16 01:58:57 -0800 | [diff] [blame] | 4292 | if (list_empty(&list_st)) |
| 4293 | break; |
| 4294 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4295 | qla4xxx_remove_failed_ddb(ha, &list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4296 | schedule_timeout_uninterruptible(HZ / 10); |
| 4297 | } while (time_after(wtime, jiffies)); |
| 4298 | |
| 4299 | /* Free up the sendtargets list */ |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4300 | qla4xxx_free_ddb_list(&list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4301 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4302 | qla4xxx_build_nt_list(ha, &list_nt, is_reset); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4303 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4304 | qla4xxx_free_ddb_list(&list_nt); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4305 | |
| 4306 | qla4xxx_free_ddb_index(ha); |
| 4307 | } |
| 4308 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4309 | /** |
| 4310 | * qla4xxx_probe_adapter - callback function to probe HBA |
| 4311 | * @pdev: pointer to pci_dev structure |
| 4312 | * @pci_device_id: pointer to pci_device entry |
| 4313 | * |
| 4314 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. |
| 4315 | * It returns zero if successful. It also initializes all data necessary for |
| 4316 | * the driver. |
| 4317 | **/ |
| 4318 | static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev, |
| 4319 | const struct pci_device_id *ent) |
| 4320 | { |
| 4321 | int ret = -ENODEV, status; |
| 4322 | struct Scsi_Host *host; |
| 4323 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4324 | uint8_t init_retry_count = 0; |
| 4325 | char buf[34]; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4326 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 4327 | uint32_t dev_state; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4328 | |
| 4329 | if (pci_enable_device(pdev)) |
| 4330 | return -1; |
| 4331 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4332 | host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4333 | if (host == NULL) { |
| 4334 | printk(KERN_WARNING |
| 4335 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); |
| 4336 | goto probe_disable_device; |
| 4337 | } |
| 4338 | |
| 4339 | /* Clear our data area */ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4340 | ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4341 | memset(ha, 0, sizeof(*ha)); |
| 4342 | |
| 4343 | /* Save the information from PCI BIOS. */ |
| 4344 | ha->pdev = pdev; |
| 4345 | ha->host = host; |
| 4346 | ha->host_no = host->host_no; |
| 4347 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4348 | pci_enable_pcie_error_reporting(pdev); |
| 4349 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4350 | /* Setup Runtime configurable options */ |
| 4351 | if (is_qla8022(ha)) { |
| 4352 | ha->isp_ops = &qla4_8xxx_isp_ops; |
| 4353 | rwlock_init(&ha->hw_lock); |
| 4354 | ha->qdr_sn_window = -1; |
| 4355 | ha->ddr_mn_window = -1; |
| 4356 | ha->curr_window = 255; |
| 4357 | ha->func_num = PCI_FUNC(ha->pdev->devfn); |
| 4358 | nx_legacy_intr = &legacy_intr[ha->func_num]; |
| 4359 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; |
| 4360 | ha->nx_legacy_intr.tgt_status_reg = |
| 4361 | nx_legacy_intr->tgt_status_reg; |
| 4362 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; |
| 4363 | ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg; |
| 4364 | } else { |
| 4365 | ha->isp_ops = &qla4xxx_isp_ops; |
| 4366 | } |
| 4367 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4368 | /* Set EEH reset type to fundamental if required by hba */ |
| 4369 | if (is_qla8022(ha)) |
| 4370 | pdev->needs_freset = 1; |
| 4371 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4372 | /* Configure PCI I/O space. */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4373 | ret = ha->isp_ops->iospace_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4374 | if (ret) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4375 | goto probe_failed_ioconfig; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4376 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4377 | 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] | 4378 | pdev->device, pdev->irq, ha->reg); |
| 4379 | |
| 4380 | qla4xxx_config_dma_addressing(ha); |
| 4381 | |
| 4382 | /* Initialize lists and spinlocks. */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4383 | INIT_LIST_HEAD(&ha->free_srb_q); |
| 4384 | |
| 4385 | mutex_init(&ha->mbox_sem); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 4386 | mutex_init(&ha->chap_sem); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4387 | init_completion(&ha->mbx_intr_comp); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 4388 | init_completion(&ha->disable_acb_comp); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4389 | |
| 4390 | spin_lock_init(&ha->hardware_lock); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4391 | |
| 4392 | /* Allocate dma buffers */ |
| 4393 | if (qla4xxx_mem_alloc(ha)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4394 | ql4_printk(KERN_WARNING, ha, |
| 4395 | "[ERROR] Failed to allocate memory for adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4396 | |
| 4397 | ret = -ENOMEM; |
| 4398 | goto probe_failed; |
| 4399 | } |
| 4400 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4401 | host->cmd_per_lun = 3; |
| 4402 | host->max_channel = 0; |
| 4403 | host->max_lun = MAX_LUNS - 1; |
| 4404 | host->max_id = MAX_TARGETS; |
| 4405 | host->max_cmd_len = IOCB_MAX_CDB_LEN; |
| 4406 | host->can_queue = MAX_SRBS ; |
| 4407 | host->transportt = qla4xxx_scsi_transport; |
| 4408 | |
| 4409 | ret = scsi_init_shared_tag_map(host, MAX_SRBS); |
| 4410 | if (ret) { |
| 4411 | ql4_printk(KERN_WARNING, ha, |
| 4412 | "%s: scsi_init_shared_tag_map failed\n", __func__); |
| 4413 | goto probe_failed; |
| 4414 | } |
| 4415 | |
| 4416 | pci_set_drvdata(pdev, ha); |
| 4417 | |
| 4418 | ret = scsi_add_host(host, &pdev->dev); |
| 4419 | if (ret) |
| 4420 | goto probe_failed; |
| 4421 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4422 | if (is_qla8022(ha)) |
| 4423 | (void) qla4_8xxx_get_flash_info(ha); |
| 4424 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4425 | /* |
| 4426 | * Initialize the Host adapter request/response queues and |
| 4427 | * firmware |
| 4428 | * NOTE: interrupts enabled upon successful completion |
| 4429 | */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4430 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4431 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
| 4432 | init_retry_count++ < MAX_INIT_RETRIES) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 4433 | |
| 4434 | if (is_qla8022(ha)) { |
| 4435 | qla4_8xxx_idc_lock(ha); |
| 4436 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| 4437 | qla4_8xxx_idc_unlock(ha); |
| 4438 | if (dev_state == QLA82XX_DEV_FAILED) { |
| 4439 | ql4_printk(KERN_WARNING, ha, "%s: don't retry " |
| 4440 | "initialize adapter. H/W is in failed state\n", |
| 4441 | __func__); |
| 4442 | break; |
| 4443 | } |
| 4444 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4445 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
| 4446 | "(%d)\n", __func__, init_retry_count)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4447 | |
| 4448 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) |
| 4449 | continue; |
| 4450 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4451 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4452 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4453 | |
| 4454 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4455 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4456 | |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 4457 | if (is_qla8022(ha) && ql4xdontresethba) { |
| 4458 | /* Put the device in failed state. */ |
| 4459 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); |
| 4460 | qla4_8xxx_idc_lock(ha); |
| 4461 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 4462 | QLA82XX_DEV_FAILED); |
| 4463 | qla4_8xxx_idc_unlock(ha); |
| 4464 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4465 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4466 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4469 | /* Startup the kernel thread for this host adapter. */ |
| 4470 | DEBUG2(printk("scsi: %s: Starting kernel thread for " |
| 4471 | "qla4xxx_dpc\n", __func__)); |
| 4472 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); |
| 4473 | ha->dpc_thread = create_singlethread_workqueue(buf); |
| 4474 | if (!ha->dpc_thread) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4475 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4476 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4477 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4478 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4479 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4480 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4481 | sprintf(buf, "qla4xxx_%lu_task", ha->host_no); |
| 4482 | ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1); |
| 4483 | if (!ha->task_wq) { |
| 4484 | ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n"); |
| 4485 | ret = -ENODEV; |
| 4486 | goto remove_host; |
| 4487 | } |
| 4488 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4489 | /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc |
| 4490 | * (which is called indirectly by qla4xxx_initialize_adapter), |
| 4491 | * so that irqs will be registered after crbinit but before |
| 4492 | * mbx_intr_enable. |
| 4493 | */ |
| 4494 | if (!is_qla8022(ha)) { |
| 4495 | ret = qla4xxx_request_irqs(ha); |
| 4496 | if (ret) { |
| 4497 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " |
| 4498 | "interrupt %d already in use.\n", pdev->irq); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4499 | goto remove_host; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4500 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4501 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4502 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4503 | pci_save_state(ha->pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4504 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4505 | |
| 4506 | /* Start timer thread. */ |
| 4507 | qla4xxx_start_timer(ha, qla4xxx_timer, 1); |
| 4508 | |
| 4509 | set_bit(AF_INIT_DONE, &ha->flags); |
| 4510 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4511 | printk(KERN_INFO |
| 4512 | " QLogic iSCSI HBA Driver version: %s\n" |
| 4513 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", |
| 4514 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), |
| 4515 | ha->host_no, ha->firmware_version[0], ha->firmware_version[1], |
| 4516 | ha->patch_number, ha->build_number); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 4517 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4518 | if (qla4xxx_setup_boot_info(ha)) |
| 4519 | ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n", |
| 4520 | __func__); |
| 4521 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4522 | /* Perform the build ddb list and login to each */ |
| 4523 | qla4xxx_build_ddb_list(ha, INIT_ADAPTER); |
| 4524 | iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb); |
| 4525 | |
| 4526 | qla4xxx_create_chap_list(ha); |
| 4527 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 4528 | qla4xxx_create_ifaces(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4529 | return 0; |
| 4530 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4531 | remove_host: |
| 4532 | scsi_remove_host(ha->host); |
| 4533 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4534 | probe_failed: |
| 4535 | qla4xxx_free_adapter(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4536 | |
| 4537 | probe_failed_ioconfig: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4538 | pci_disable_pcie_error_reporting(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4539 | scsi_host_put(ha->host); |
| 4540 | |
| 4541 | probe_disable_device: |
| 4542 | pci_disable_device(pdev); |
| 4543 | |
| 4544 | return ret; |
| 4545 | } |
| 4546 | |
| 4547 | /** |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 4548 | * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize |
| 4549 | * @ha: pointer to adapter structure |
| 4550 | * |
| 4551 | * Mark the other ISP-4xxx port to indicate that the driver is being removed, |
| 4552 | * so that the other port will not re-initialize while in the process of |
| 4553 | * removing the ha due to driver unload or hba hotplug. |
| 4554 | **/ |
| 4555 | static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha) |
| 4556 | { |
| 4557 | struct scsi_qla_host *other_ha = NULL; |
| 4558 | struct pci_dev *other_pdev = NULL; |
| 4559 | int fn = ISP4XXX_PCI_FN_2; |
| 4560 | |
| 4561 | /*iscsi function numbers for ISP4xxx is 1 and 3*/ |
| 4562 | if (PCI_FUNC(ha->pdev->devfn) & BIT_1) |
| 4563 | fn = ISP4XXX_PCI_FN_1; |
| 4564 | |
| 4565 | other_pdev = |
| 4566 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 4567 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 4568 | fn)); |
| 4569 | |
| 4570 | /* Get other_ha if other_pdev is valid and state is enable*/ |
| 4571 | if (other_pdev) { |
| 4572 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 4573 | other_ha = pci_get_drvdata(other_pdev); |
| 4574 | if (other_ha) { |
| 4575 | set_bit(AF_HA_REMOVAL, &other_ha->flags); |
| 4576 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " |
| 4577 | "Prevent %s reinit\n", __func__, |
| 4578 | dev_name(&other_ha->pdev->dev))); |
| 4579 | } |
| 4580 | } |
| 4581 | pci_dev_put(other_pdev); |
| 4582 | } |
| 4583 | } |
| 4584 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4585 | static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha) |
| 4586 | { |
| 4587 | struct ddb_entry *ddb_entry; |
| 4588 | int options; |
| 4589 | int idx; |
| 4590 | |
| 4591 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 4592 | |
| 4593 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 4594 | if ((ddb_entry != NULL) && |
| 4595 | (ddb_entry->ddb_type == FLASH_DDB)) { |
| 4596 | |
| 4597 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 4598 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) |
| 4599 | == QLA_ERROR) |
| 4600 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", |
| 4601 | __func__); |
| 4602 | |
| 4603 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 4604 | /* |
| 4605 | * we have decremented the reference count of the driver |
| 4606 | * when we setup the session to have the driver unload |
| 4607 | * to be seamless without actually destroying the |
| 4608 | * session |
| 4609 | **/ |
| 4610 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 4611 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 4612 | qla4xxx_free_ddb(ha, ddb_entry); |
| 4613 | iscsi_session_teardown(ddb_entry->sess); |
| 4614 | } |
| 4615 | } |
| 4616 | } |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 4617 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4618 | * qla4xxx_remove_adapter - calback function to remove adapter. |
| 4619 | * @pci_dev: PCI device pointer |
| 4620 | **/ |
| 4621 | static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev) |
| 4622 | { |
| 4623 | struct scsi_qla_host *ha; |
| 4624 | |
| 4625 | ha = pci_get_drvdata(pdev); |
| 4626 | |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 4627 | if (!is_qla8022(ha)) |
| 4628 | qla4xxx_prevent_other_port_reinit(ha); |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 4629 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 4630 | /* destroy iface from sysfs */ |
| 4631 | qla4xxx_destroy_ifaces(ha); |
| 4632 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4633 | if ((!ql4xdisablesysfsboot) && ha->boot_kset) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4634 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 4635 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4636 | qla4xxx_destroy_fw_ddb_session(ha); |
| 4637 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4638 | scsi_remove_host(ha->host); |
| 4639 | |
| 4640 | qla4xxx_free_adapter(ha); |
| 4641 | |
| 4642 | scsi_host_put(ha->host); |
| 4643 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4644 | pci_disable_pcie_error_reporting(pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4645 | pci_disable_device(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4646 | pci_set_drvdata(pdev, NULL); |
| 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. |
| 4651 | * @ha: HA context |
| 4652 | * |
| 4653 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 4654 | * supported addressing method. |
| 4655 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 4656 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4657 | { |
| 4658 | int retval; |
| 4659 | |
| 4660 | /* Update our PCI device dma_mask for full 64 bit mask */ |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4661 | if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) { |
| 4662 | if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4663 | dev_dbg(&ha->pdev->dev, |
| 4664 | "Failed to set 64 bit PCI consistent mask; " |
| 4665 | "using 32 bit.\n"); |
| 4666 | retval = pci_set_consistent_dma_mask(ha->pdev, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4667 | DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4668 | } |
| 4669 | } else |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4670 | retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4671 | } |
| 4672 | |
| 4673 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) |
| 4674 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4675 | struct iscsi_cls_session *cls_sess; |
| 4676 | struct iscsi_session *sess; |
| 4677 | struct ddb_entry *ddb; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 4678 | int queue_depth = QL4_DEF_QDEPTH; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4679 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4680 | cls_sess = starget_to_session(sdev->sdev_target); |
| 4681 | sess = cls_sess->dd_data; |
| 4682 | ddb = sess->dd_data; |
| 4683 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4684 | sdev->hostdata = ddb; |
| 4685 | sdev->tagged_supported = 1; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 4686 | |
| 4687 | if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) |
| 4688 | queue_depth = ql4xmaxqdepth; |
| 4689 | |
| 4690 | scsi_activate_tcq(sdev, queue_depth); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4691 | return 0; |
| 4692 | } |
| 4693 | |
| 4694 | static int qla4xxx_slave_configure(struct scsi_device *sdev) |
| 4695 | { |
| 4696 | sdev->tagged_supported = 1; |
| 4697 | return 0; |
| 4698 | } |
| 4699 | |
| 4700 | static void qla4xxx_slave_destroy(struct scsi_device *sdev) |
| 4701 | { |
| 4702 | scsi_deactivate_tcq(sdev, 1); |
| 4703 | } |
| 4704 | |
| 4705 | /** |
| 4706 | * qla4xxx_del_from_active_array - returns an active srb |
| 4707 | * @ha: Pointer to host adapter structure. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 4708 | * @index: index into the active_array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4709 | * |
| 4710 | * This routine removes and returns the srb at the specified index |
| 4711 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4712 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
| 4713 | uint32_t index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4714 | { |
| 4715 | struct srb *srb = NULL; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4716 | struct scsi_cmnd *cmd = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4717 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4718 | cmd = scsi_host_find_tag(ha->host, index); |
| 4719 | if (!cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4720 | return srb; |
| 4721 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4722 | srb = (struct srb *)CMD_SP(cmd); |
| 4723 | if (!srb) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4724 | return srb; |
| 4725 | |
| 4726 | /* update counters */ |
| 4727 | if (srb->flags & SRB_DMA_VALID) { |
| 4728 | ha->req_q_count += srb->iocb_cnt; |
| 4729 | ha->iocb_cnt -= srb->iocb_cnt; |
| 4730 | if (srb->cmd) |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4731 | srb->cmd->host_scribble = |
| 4732 | (unsigned char *)(unsigned long) MAX_SRBS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4733 | } |
| 4734 | return srb; |
| 4735 | } |
| 4736 | |
| 4737 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4738 | * 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] | 4739 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4740 | * @cmd: Scsi Command to wait on. |
| 4741 | * |
| 4742 | * This routine waits for the command to be returned by the Firmware |
| 4743 | * for some max time. |
| 4744 | **/ |
| 4745 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, |
| 4746 | struct scsi_cmnd *cmd) |
| 4747 | { |
| 4748 | int done = 0; |
| 4749 | struct srb *rp; |
| 4750 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4751 | int ret = SUCCESS; |
| 4752 | |
| 4753 | /* Dont wait on command if PCI error is being handled |
| 4754 | * by PCI AER driver |
| 4755 | */ |
| 4756 | if (unlikely(pci_channel_offline(ha->pdev)) || |
| 4757 | (test_bit(AF_EEH_BUSY, &ha->flags))) { |
| 4758 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", |
| 4759 | ha->host_no, __func__); |
| 4760 | return ret; |
| 4761 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4762 | |
| 4763 | do { |
| 4764 | /* Checking to see if its returned to OS */ |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4765 | rp = (struct srb *) CMD_SP(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4766 | if (rp == NULL) { |
| 4767 | done++; |
| 4768 | break; |
| 4769 | } |
| 4770 | |
| 4771 | msleep(2000); |
| 4772 | } while (max_wait_time--); |
| 4773 | |
| 4774 | return done; |
| 4775 | } |
| 4776 | |
| 4777 | /** |
| 4778 | * qla4xxx_wait_for_hba_online - waits for HBA to come online |
| 4779 | * @ha: Pointer to host adapter structure |
| 4780 | **/ |
| 4781 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) |
| 4782 | { |
| 4783 | unsigned long wait_online; |
| 4784 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 4785 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4786 | while (time_before(jiffies, wait_online)) { |
| 4787 | |
| 4788 | if (adapter_up(ha)) |
| 4789 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4790 | |
| 4791 | msleep(2000); |
| 4792 | } |
| 4793 | |
| 4794 | return QLA_ERROR; |
| 4795 | } |
| 4796 | |
| 4797 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4798 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 4799 | * @ha: pointer to HBA |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4800 | * @t: target id |
| 4801 | * @l: lun id |
| 4802 | * |
| 4803 | * This function waits for all outstanding commands to a lun to complete. It |
| 4804 | * returns 0 if all pending commands are returned and 1 otherwise. |
| 4805 | **/ |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4806 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
| 4807 | struct scsi_target *stgt, |
| 4808 | struct scsi_device *sdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4809 | { |
| 4810 | int cnt; |
| 4811 | int status = 0; |
| 4812 | struct scsi_cmnd *cmd; |
| 4813 | |
| 4814 | /* |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4815 | * Waiting for all commands for the designated target or dev |
| 4816 | * in the active array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4817 | */ |
| 4818 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { |
| 4819 | cmd = scsi_host_find_tag(ha->host, cnt); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4820 | if (cmd && stgt == scsi_target(cmd->device) && |
| 4821 | (!sdev || sdev == cmd->device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4822 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 4823 | status++; |
| 4824 | break; |
| 4825 | } |
| 4826 | } |
| 4827 | } |
| 4828 | return status; |
| 4829 | } |
| 4830 | |
| 4831 | /** |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4832 | * qla4xxx_eh_abort - callback for abort task. |
| 4833 | * @cmd: Pointer to Linux's SCSI command structure |
| 4834 | * |
| 4835 | * This routine is called by the Linux OS to abort the specified |
| 4836 | * command. |
| 4837 | **/ |
| 4838 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) |
| 4839 | { |
| 4840 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 4841 | unsigned int id = cmd->device->id; |
| 4842 | unsigned int lun = cmd->device->lun; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 4843 | unsigned long flags; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4844 | struct srb *srb = NULL; |
| 4845 | int ret = SUCCESS; |
| 4846 | int wait = 0; |
| 4847 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4848 | ql4_printk(KERN_INFO, ha, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 4849 | "scsi%ld:%d:%d: Abort command issued cmd=%p\n", |
| 4850 | ha->host_no, id, lun, cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4851 | |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 4852 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4853 | srb = (struct srb *) CMD_SP(cmd); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 4854 | if (!srb) { |
| 4855 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4856 | return SUCCESS; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 4857 | } |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4858 | kref_get(&srb->srb_ref); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 4859 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4860 | |
| 4861 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { |
| 4862 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", |
| 4863 | ha->host_no, id, lun)); |
| 4864 | ret = FAILED; |
| 4865 | } else { |
| 4866 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n", |
| 4867 | ha->host_no, id, lun)); |
| 4868 | wait = 1; |
| 4869 | } |
| 4870 | |
| 4871 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| 4872 | |
| 4873 | /* Wait for command to complete */ |
| 4874 | if (wait) { |
| 4875 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 4876 | DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n", |
| 4877 | ha->host_no, id, lun)); |
| 4878 | ret = FAILED; |
| 4879 | } |
| 4880 | } |
| 4881 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4882 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4883 | "scsi%ld:%d:%d: Abort command - %s\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4884 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed"); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4885 | |
| 4886 | return ret; |
| 4887 | } |
| 4888 | |
| 4889 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4890 | * qla4xxx_eh_device_reset - callback for target reset. |
| 4891 | * @cmd: Pointer to Linux's SCSI command structure |
| 4892 | * |
| 4893 | * This routine is called by the Linux OS to reset all luns on the |
| 4894 | * specified target. |
| 4895 | **/ |
| 4896 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 4897 | { |
| 4898 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 4899 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4900 | int ret = FAILED, stat; |
| 4901 | |
Karen Higgins | 612f734 | 2009-07-15 15:03:01 -0500 | [diff] [blame] | 4902 | if (!ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4903 | return ret; |
| 4904 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 4905 | ret = iscsi_block_scsi_eh(cmd); |
| 4906 | if (ret) |
| 4907 | return ret; |
| 4908 | ret = FAILED; |
| 4909 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4910 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4911 | "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no, |
| 4912 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 4913 | |
| 4914 | DEBUG2(printk(KERN_INFO |
| 4915 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," |
| 4916 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 4917 | cmd, jiffies, cmd->request->timeout / HZ, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4918 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 4919 | |
| 4920 | /* FIXME: wait for hba to go online */ |
| 4921 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); |
| 4922 | if (stat != QLA_SUCCESS) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4923 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4924 | goto eh_dev_reset_done; |
| 4925 | } |
| 4926 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4927 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 4928 | cmd->device)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4929 | ql4_printk(KERN_INFO, ha, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4930 | "DEVICE RESET FAILED - waiting for " |
| 4931 | "commands.\n"); |
| 4932 | goto eh_dev_reset_done; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4933 | } |
| 4934 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 4935 | /* Send marker. */ |
| 4936 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 4937 | MM_LUN_RESET) != QLA_SUCCESS) |
| 4938 | goto eh_dev_reset_done; |
| 4939 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4940 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4941 | "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n", |
| 4942 | ha->host_no, cmd->device->channel, cmd->device->id, |
| 4943 | cmd->device->lun); |
| 4944 | |
| 4945 | ret = SUCCESS; |
| 4946 | |
| 4947 | eh_dev_reset_done: |
| 4948 | |
| 4949 | return ret; |
| 4950 | } |
| 4951 | |
| 4952 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4953 | * qla4xxx_eh_target_reset - callback for target reset. |
| 4954 | * @cmd: Pointer to Linux's SCSI command structure |
| 4955 | * |
| 4956 | * This routine is called by the Linux OS to reset the target. |
| 4957 | **/ |
| 4958 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) |
| 4959 | { |
| 4960 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 4961 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 4962 | int stat, ret; |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4963 | |
| 4964 | if (!ddb_entry) |
| 4965 | return FAILED; |
| 4966 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 4967 | ret = iscsi_block_scsi_eh(cmd); |
| 4968 | if (ret) |
| 4969 | return ret; |
| 4970 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4971 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 4972 | "WARM TARGET RESET ISSUED.\n"); |
| 4973 | |
| 4974 | DEBUG2(printk(KERN_INFO |
| 4975 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " |
| 4976 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 4977 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4978 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 4979 | |
| 4980 | stat = qla4xxx_reset_target(ha, ddb_entry); |
| 4981 | if (stat != QLA_SUCCESS) { |
| 4982 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 4983 | "WARM TARGET RESET FAILED.\n"); |
| 4984 | return FAILED; |
| 4985 | } |
| 4986 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 4987 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 4988 | NULL)) { |
| 4989 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 4990 | "WARM TARGET DEVICE RESET FAILED - " |
| 4991 | "waiting for commands.\n"); |
| 4992 | return FAILED; |
| 4993 | } |
| 4994 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 4995 | /* Send marker. */ |
| 4996 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 4997 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { |
| 4998 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 4999 | "WARM TARGET DEVICE RESET FAILED - " |
| 5000 | "marker iocb failed.\n"); |
| 5001 | return FAILED; |
| 5002 | } |
| 5003 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 5004 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 5005 | "WARM TARGET RESET SUCCEEDED.\n"); |
| 5006 | return SUCCESS; |
| 5007 | } |
| 5008 | |
| 5009 | /** |
Sarang Radke | 8a28896 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 5010 | * qla4xxx_is_eh_active - check if error handler is running |
| 5011 | * @shost: Pointer to SCSI Host struct |
| 5012 | * |
| 5013 | * This routine finds that if reset host is called in EH |
| 5014 | * scenario or from some application like sg_reset |
| 5015 | **/ |
| 5016 | static int qla4xxx_is_eh_active(struct Scsi_Host *shost) |
| 5017 | { |
| 5018 | if (shost->shost_state == SHOST_RECOVERY) |
| 5019 | return 1; |
| 5020 | return 0; |
| 5021 | } |
| 5022 | |
| 5023 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5024 | * qla4xxx_eh_host_reset - kernel callback |
| 5025 | * @cmd: Pointer to Linux's SCSI command structure |
| 5026 | * |
| 5027 | * This routine is invoked by the Linux kernel to perform fatal error |
| 5028 | * recovery on the specified adapter. |
| 5029 | **/ |
| 5030 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 5031 | { |
| 5032 | int return_status = FAILED; |
| 5033 | struct scsi_qla_host *ha; |
| 5034 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5035 | ha = to_qla_host(cmd->device->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5036 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5037 | if (ql4xdontresethba) { |
| 5038 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 5039 | ha->host_no, __func__)); |
Sarang Radke | 8a28896 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 5040 | |
| 5041 | /* Clear outstanding srb in queues */ |
| 5042 | if (qla4xxx_is_eh_active(cmd->device->host)) |
| 5043 | qla4xxx_abort_active_cmds(ha, DID_ABORT << 16); |
| 5044 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5045 | return FAILED; |
| 5046 | } |
| 5047 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5048 | ql4_printk(KERN_INFO, ha, |
Karen Higgins | dca05c4 | 2009-07-15 15:03:00 -0500 | [diff] [blame] | 5049 | "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5050 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 5051 | |
| 5052 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 5053 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " |
| 5054 | "DEAD.\n", ha->host_no, cmd->device->channel, |
| 5055 | __func__)); |
| 5056 | |
| 5057 | return FAILED; |
| 5058 | } |
| 5059 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5060 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| 5061 | if (is_qla8022(ha)) |
| 5062 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 5063 | else |
| 5064 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 5065 | } |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 5066 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5067 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5068 | return_status = SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5069 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5070 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5071 | return_status == FAILED ? "FAILED" : "SUCCEEDED"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5072 | |
| 5073 | return return_status; |
| 5074 | } |
| 5075 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 5076 | static int qla4xxx_context_reset(struct scsi_qla_host *ha) |
| 5077 | { |
| 5078 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 5079 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 5080 | struct addr_ctrl_blk_def *acb = NULL; |
| 5081 | uint32_t acb_len = sizeof(struct addr_ctrl_blk_def); |
| 5082 | int rval = QLA_SUCCESS; |
| 5083 | dma_addr_t acb_dma; |
| 5084 | |
| 5085 | acb = dma_alloc_coherent(&ha->pdev->dev, |
| 5086 | sizeof(struct addr_ctrl_blk_def), |
| 5087 | &acb_dma, GFP_KERNEL); |
| 5088 | if (!acb) { |
| 5089 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n", |
| 5090 | __func__); |
| 5091 | rval = -ENOMEM; |
| 5092 | goto exit_port_reset; |
| 5093 | } |
| 5094 | |
| 5095 | memset(acb, 0, acb_len); |
| 5096 | |
| 5097 | rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len); |
| 5098 | if (rval != QLA_SUCCESS) { |
| 5099 | rval = -EIO; |
| 5100 | goto exit_free_acb; |
| 5101 | } |
| 5102 | |
| 5103 | rval = qla4xxx_disable_acb(ha); |
| 5104 | if (rval != QLA_SUCCESS) { |
| 5105 | rval = -EIO; |
| 5106 | goto exit_free_acb; |
| 5107 | } |
| 5108 | |
| 5109 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 5110 | DISABLE_ACB_TOV * HZ); |
| 5111 | |
| 5112 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma); |
| 5113 | if (rval != QLA_SUCCESS) { |
| 5114 | rval = -EIO; |
| 5115 | goto exit_free_acb; |
| 5116 | } |
| 5117 | |
| 5118 | exit_free_acb: |
| 5119 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def), |
| 5120 | acb, acb_dma); |
| 5121 | exit_port_reset: |
| 5122 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__, |
| 5123 | rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED")); |
| 5124 | return rval; |
| 5125 | } |
| 5126 | |
| 5127 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type) |
| 5128 | { |
| 5129 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 5130 | int rval = QLA_SUCCESS; |
| 5131 | |
| 5132 | if (ql4xdontresethba) { |
| 5133 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n", |
| 5134 | __func__)); |
| 5135 | rval = -EPERM; |
| 5136 | goto exit_host_reset; |
| 5137 | } |
| 5138 | |
| 5139 | rval = qla4xxx_wait_for_hba_online(ha); |
| 5140 | if (rval != QLA_SUCCESS) { |
| 5141 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host " |
| 5142 | "adapter\n", __func__)); |
| 5143 | rval = -EIO; |
| 5144 | goto exit_host_reset; |
| 5145 | } |
| 5146 | |
| 5147 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 5148 | goto recover_adapter; |
| 5149 | |
| 5150 | switch (reset_type) { |
| 5151 | case SCSI_ADAPTER_RESET: |
| 5152 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 5153 | break; |
| 5154 | case SCSI_FIRMWARE_RESET: |
| 5155 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| 5156 | if (is_qla8022(ha)) |
| 5157 | /* set firmware context reset */ |
| 5158 | set_bit(DPC_RESET_HA_FW_CONTEXT, |
| 5159 | &ha->dpc_flags); |
| 5160 | else { |
| 5161 | rval = qla4xxx_context_reset(ha); |
| 5162 | goto exit_host_reset; |
| 5163 | } |
| 5164 | } |
| 5165 | break; |
| 5166 | } |
| 5167 | |
| 5168 | recover_adapter: |
| 5169 | rval = qla4xxx_recover_adapter(ha); |
| 5170 | if (rval != QLA_SUCCESS) { |
| 5171 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n", |
| 5172 | __func__)); |
| 5173 | rval = -EIO; |
| 5174 | } |
| 5175 | |
| 5176 | exit_host_reset: |
| 5177 | return rval; |
| 5178 | } |
| 5179 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5180 | /* PCI AER driver recovers from all correctable errors w/o |
| 5181 | * driver intervention. For uncorrectable errors PCI AER |
| 5182 | * driver calls the following device driver's callbacks |
| 5183 | * |
| 5184 | * - Fatal Errors - link_reset |
| 5185 | * - Non-Fatal Errors - driver's pci_error_detected() which |
| 5186 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. |
| 5187 | * |
| 5188 | * PCI AER driver calls |
| 5189 | * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled |
| 5190 | * returns RECOVERED or NEED_RESET if fw_hung |
| 5191 | * NEED_RESET - driver's slot_reset() |
| 5192 | * DISCONNECT - device is dead & cannot recover |
| 5193 | * RECOVERED - driver's pci_resume() |
| 5194 | */ |
| 5195 | static pci_ers_result_t |
| 5196 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 5197 | { |
| 5198 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 5199 | |
| 5200 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", |
| 5201 | ha->host_no, __func__, state); |
| 5202 | |
| 5203 | if (!is_aer_supported(ha)) |
| 5204 | return PCI_ERS_RESULT_NONE; |
| 5205 | |
| 5206 | switch (state) { |
| 5207 | case pci_channel_io_normal: |
| 5208 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 5209 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 5210 | case pci_channel_io_frozen: |
| 5211 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 5212 | qla4xxx_mailbox_premature_completion(ha); |
| 5213 | qla4xxx_free_irqs(ha); |
| 5214 | pci_disable_device(pdev); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5215 | /* Return back all IOs */ |
| 5216 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5217 | return PCI_ERS_RESULT_NEED_RESET; |
| 5218 | case pci_channel_io_perm_failure: |
| 5219 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 5220 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); |
| 5221 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 5222 | return PCI_ERS_RESULT_DISCONNECT; |
| 5223 | } |
| 5224 | return PCI_ERS_RESULT_NEED_RESET; |
| 5225 | } |
| 5226 | |
| 5227 | /** |
| 5228 | * qla4xxx_pci_mmio_enabled() gets called if |
| 5229 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER |
| 5230 | * and read/write to the device still works. |
| 5231 | **/ |
| 5232 | static pci_ers_result_t |
| 5233 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 5234 | { |
| 5235 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 5236 | |
| 5237 | if (!is_aer_supported(ha)) |
| 5238 | return PCI_ERS_RESULT_NONE; |
| 5239 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5240 | return PCI_ERS_RESULT_RECOVERED; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5241 | } |
| 5242 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5243 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5244 | { |
| 5245 | uint32_t rval = QLA_ERROR; |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5246 | uint32_t ret = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5247 | int fn; |
| 5248 | struct pci_dev *other_pdev = NULL; |
| 5249 | |
| 5250 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); |
| 5251 | |
| 5252 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 5253 | |
| 5254 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 5255 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5256 | clear_bit(AF_LINK_UP, &ha->flags); |
| 5257 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5258 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | fn = PCI_FUNC(ha->pdev->devfn); |
| 5262 | while (fn > 0) { |
| 5263 | fn--; |
| 5264 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at " |
| 5265 | "func %x\n", ha->host_no, __func__, fn); |
| 5266 | /* Get the pci device given the domain, bus, |
| 5267 | * slot/function number */ |
| 5268 | other_pdev = |
| 5269 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 5270 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 5271 | fn)); |
| 5272 | |
| 5273 | if (!other_pdev) |
| 5274 | continue; |
| 5275 | |
| 5276 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 5277 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI " |
| 5278 | "func in enabled state%x\n", ha->host_no, |
| 5279 | __func__, fn); |
| 5280 | pci_dev_put(other_pdev); |
| 5281 | break; |
| 5282 | } |
| 5283 | pci_dev_put(other_pdev); |
| 5284 | } |
| 5285 | |
| 5286 | /* The first function on the card, the reset owner will |
| 5287 | * start & initialize the firmware. The other functions |
| 5288 | * on the card will reset the firmware context |
| 5289 | */ |
| 5290 | if (!fn) { |
| 5291 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " |
| 5292 | "0x%x is the owner\n", ha->host_no, __func__, |
| 5293 | ha->pdev->devfn); |
| 5294 | |
| 5295 | qla4_8xxx_idc_lock(ha); |
| 5296 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 5297 | QLA82XX_DEV_COLD); |
| 5298 | |
| 5299 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION, |
| 5300 | QLA82XX_IDC_VERSION); |
| 5301 | |
| 5302 | qla4_8xxx_idc_unlock(ha); |
| 5303 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5304 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5305 | qla4_8xxx_idc_lock(ha); |
| 5306 | |
| 5307 | if (rval != QLA_SUCCESS) { |
| 5308 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 5309 | "FAILED\n", ha->host_no, __func__); |
| 5310 | qla4_8xxx_clear_drv_active(ha); |
| 5311 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 5312 | QLA82XX_DEV_FAILED); |
| 5313 | } else { |
| 5314 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 5315 | "READY\n", ha->host_no, __func__); |
| 5316 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| 5317 | QLA82XX_DEV_READY); |
| 5318 | /* Clear driver state register */ |
| 5319 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0); |
| 5320 | qla4_8xxx_set_drv_active(ha); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5321 | ret = qla4xxx_request_irqs(ha); |
| 5322 | if (ret) { |
| 5323 | ql4_printk(KERN_WARNING, ha, "Failed to " |
| 5324 | "reserve interrupt %d already in use.\n", |
| 5325 | ha->pdev->irq); |
| 5326 | rval = QLA_ERROR; |
| 5327 | } else { |
| 5328 | ha->isp_ops->enable_intrs(ha); |
| 5329 | rval = QLA_SUCCESS; |
| 5330 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5331 | } |
| 5332 | qla4_8xxx_idc_unlock(ha); |
| 5333 | } else { |
| 5334 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " |
| 5335 | "the reset owner\n", ha->host_no, __func__, |
| 5336 | ha->pdev->devfn); |
| 5337 | if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) == |
| 5338 | QLA82XX_DEV_READY)) { |
| 5339 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5340 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5341 | if (rval == QLA_SUCCESS) { |
| 5342 | ret = qla4xxx_request_irqs(ha); |
| 5343 | if (ret) { |
| 5344 | ql4_printk(KERN_WARNING, ha, "Failed to" |
| 5345 | " reserve interrupt %d already in" |
| 5346 | " use.\n", ha->pdev->irq); |
| 5347 | rval = QLA_ERROR; |
| 5348 | } else { |
| 5349 | ha->isp_ops->enable_intrs(ha); |
| 5350 | rval = QLA_SUCCESS; |
| 5351 | } |
| 5352 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5353 | qla4_8xxx_idc_lock(ha); |
| 5354 | qla4_8xxx_set_drv_active(ha); |
| 5355 | qla4_8xxx_idc_unlock(ha); |
| 5356 | } |
| 5357 | } |
| 5358 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 5359 | return rval; |
| 5360 | } |
| 5361 | |
| 5362 | static pci_ers_result_t |
| 5363 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) |
| 5364 | { |
| 5365 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 5366 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 5367 | int rc; |
| 5368 | |
| 5369 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", |
| 5370 | ha->host_no, __func__); |
| 5371 | |
| 5372 | if (!is_aer_supported(ha)) |
| 5373 | return PCI_ERS_RESULT_NONE; |
| 5374 | |
| 5375 | /* Restore the saved state of PCIe device - |
| 5376 | * BAR registers, PCI Config space, PCIX, MSI, |
| 5377 | * IOV states |
| 5378 | */ |
| 5379 | pci_restore_state(pdev); |
| 5380 | |
| 5381 | /* pci_restore_state() clears the saved_state flag of the device |
| 5382 | * save restored state which resets saved_state flag |
| 5383 | */ |
| 5384 | pci_save_state(pdev); |
| 5385 | |
| 5386 | /* Initialize device or resume if in suspended state */ |
| 5387 | rc = pci_enable_device(pdev); |
| 5388 | if (rc) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5389 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5390 | "device after reset\n", ha->host_no, __func__); |
| 5391 | goto exit_slot_reset; |
| 5392 | } |
| 5393 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 5394 | ha->isp_ops->disable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5395 | |
| 5396 | if (is_qla8022(ha)) { |
| 5397 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { |
| 5398 | ret = PCI_ERS_RESULT_RECOVERED; |
| 5399 | goto exit_slot_reset; |
| 5400 | } else |
| 5401 | goto exit_slot_reset; |
| 5402 | } |
| 5403 | |
| 5404 | exit_slot_reset: |
| 5405 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" |
| 5406 | "device after reset\n", ha->host_no, __func__, ret); |
| 5407 | return ret; |
| 5408 | } |
| 5409 | |
| 5410 | static void |
| 5411 | qla4xxx_pci_resume(struct pci_dev *pdev) |
| 5412 | { |
| 5413 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 5414 | int ret; |
| 5415 | |
| 5416 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", |
| 5417 | ha->host_no, __func__); |
| 5418 | |
| 5419 | ret = qla4xxx_wait_for_hba_online(ha); |
| 5420 | if (ret != QLA_SUCCESS) { |
| 5421 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " |
| 5422 | "resume I/O from slot/link_reset\n", ha->host_no, |
| 5423 | __func__); |
| 5424 | } |
| 5425 | |
| 5426 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5427 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 5428 | } |
| 5429 | |
| 5430 | static struct pci_error_handlers qla4xxx_err_handler = { |
| 5431 | .error_detected = qla4xxx_pci_error_detected, |
| 5432 | .mmio_enabled = qla4xxx_pci_mmio_enabled, |
| 5433 | .slot_reset = qla4xxx_pci_slot_reset, |
| 5434 | .resume = qla4xxx_pci_resume, |
| 5435 | }; |
| 5436 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5437 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
| 5438 | { |
| 5439 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 5440 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, |
| 5441 | .subvendor = PCI_ANY_ID, |
| 5442 | .subdevice = PCI_ANY_ID, |
| 5443 | }, |
| 5444 | { |
| 5445 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 5446 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, |
| 5447 | .subvendor = PCI_ANY_ID, |
| 5448 | .subdevice = PCI_ANY_ID, |
| 5449 | }, |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 5450 | { |
| 5451 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 5452 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, |
| 5453 | .subvendor = PCI_ANY_ID, |
| 5454 | .subdevice = PCI_ANY_ID, |
| 5455 | }, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5456 | { |
| 5457 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 5458 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, |
| 5459 | .subvendor = PCI_ANY_ID, |
| 5460 | .subdevice = PCI_ANY_ID, |
| 5461 | }, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5462 | {0, 0}, |
| 5463 | }; |
| 5464 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); |
| 5465 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 5466 | static struct pci_driver qla4xxx_pci_driver = { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5467 | .name = DRIVER_NAME, |
| 5468 | .id_table = qla4xxx_pci_tbl, |
| 5469 | .probe = qla4xxx_probe_adapter, |
| 5470 | .remove = qla4xxx_remove_adapter, |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5471 | .err_handler = &qla4xxx_err_handler, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5472 | }; |
| 5473 | |
| 5474 | static int __init qla4xxx_module_init(void) |
| 5475 | { |
| 5476 | int ret; |
| 5477 | |
| 5478 | /* Allocate cache for SRBs. */ |
| 5479 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 5480 | SLAB_HWCACHE_ALIGN, NULL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5481 | if (srb_cachep == NULL) { |
| 5482 | printk(KERN_ERR |
| 5483 | "%s: Unable to allocate SRB cache..." |
| 5484 | "Failing load!\n", DRIVER_NAME); |
| 5485 | ret = -ENOMEM; |
| 5486 | goto no_srp_cache; |
| 5487 | } |
| 5488 | |
| 5489 | /* Derive version string. */ |
| 5490 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 5491 | if (ql4xextended_error_logging) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5492 | strcat(qla4xxx_version_str, "-debug"); |
| 5493 | |
| 5494 | qla4xxx_scsi_transport = |
| 5495 | iscsi_register_transport(&qla4xxx_iscsi_transport); |
| 5496 | if (!qla4xxx_scsi_transport){ |
| 5497 | ret = -ENODEV; |
| 5498 | goto release_srb_cache; |
| 5499 | } |
| 5500 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5501 | ret = pci_register_driver(&qla4xxx_pci_driver); |
| 5502 | if (ret) |
| 5503 | goto unregister_transport; |
| 5504 | |
| 5505 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); |
| 5506 | return 0; |
Doug Maxey | 5ae16db | 2006-10-05 23:50:07 -0500 | [diff] [blame] | 5507 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5508 | unregister_transport: |
| 5509 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 5510 | release_srb_cache: |
| 5511 | kmem_cache_destroy(srb_cachep); |
| 5512 | no_srp_cache: |
| 5513 | return ret; |
| 5514 | } |
| 5515 | |
| 5516 | static void __exit qla4xxx_module_exit(void) |
| 5517 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5518 | pci_unregister_driver(&qla4xxx_pci_driver); |
| 5519 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 5520 | kmem_cache_destroy(srb_cachep); |
| 5521 | } |
| 5522 | |
| 5523 | module_init(qla4xxx_module_init); |
| 5524 | module_exit(qla4xxx_module_exit); |
| 5525 | |
| 5526 | MODULE_AUTHOR("QLogic Corporation"); |
| 5527 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); |
| 5528 | MODULE_LICENSE("GPL"); |
| 5529 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |