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