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