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