David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
Vikas Chaudhary | 4a4f51e | 2013-08-16 07:03:04 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2013 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 | a511b4a | 2014-02-24 22:06:57 -0500 | [diff] [blame] | 86 | int ql4xmdcapmask = 0; |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 87 | module_param(ql4xmdcapmask, int, S_IRUGO); |
| 88 | MODULE_PARM_DESC(ql4xmdcapmask, |
| 89 | " Set the Minidump driver capture mask level.\n" |
Tej Parkash | a511b4a | 2014-02-24 22:06:57 -0500 | [diff] [blame] | 90 | "\t\t Default is 0 (firmware default capture mask)\n" |
Tej Parkash | b410982 | 2014-02-24 22:06:58 -0500 | [diff] [blame] | 91 | "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF"); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 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); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 152 | static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, |
| 153 | int len); |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 154 | static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len); |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 155 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 156 | /* |
| 157 | * SCSI host template entry points |
| 158 | */ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 159 | static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 160 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 161 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 162 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 163 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); |
| 164 | static int qla4xxx_slave_alloc(struct scsi_device *device); |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 165 | static umode_t qla4_attr_is_visible(int param_type, int param); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 166 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 167 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 168 | /* |
| 169 | * iSCSI Flash DDB sysfs entry points |
| 170 | */ |
| 171 | static int |
| 172 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 173 | struct iscsi_bus_flash_conn *fnode_conn, |
| 174 | void *data, int len); |
| 175 | static int |
| 176 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 177 | int param, char *buf); |
| 178 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 179 | int len); |
| 180 | static int |
| 181 | qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess); |
| 182 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 183 | struct iscsi_bus_flash_conn *fnode_conn); |
| 184 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 185 | struct iscsi_bus_flash_conn *fnode_conn); |
| 186 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess); |
| 187 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 188 | static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
| 189 | QLA82XX_LEGACY_INTR_CONFIG; |
| 190 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 191 | static struct scsi_host_template qla4xxx_driver_template = { |
| 192 | .module = THIS_MODULE, |
| 193 | .name = DRIVER_NAME, |
| 194 | .proc_name = DRIVER_NAME, |
| 195 | .queuecommand = qla4xxx_queuecommand, |
| 196 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 197 | .eh_abort_handler = qla4xxx_eh_abort, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 198 | .eh_device_reset_handler = qla4xxx_eh_device_reset, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 199 | .eh_target_reset_handler = qla4xxx_eh_target_reset, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 200 | .eh_host_reset_handler = qla4xxx_eh_host_reset, |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 201 | .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 202 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 203 | .slave_alloc = qla4xxx_slave_alloc, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 204 | .change_queue_depth = scsi_change_queue_depth, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 205 | |
| 206 | .this_id = -1, |
| 207 | .cmd_per_lun = 3, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 208 | .sg_tablesize = SG_ALL, |
| 209 | |
| 210 | .max_sectors = 0xFFFF, |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 211 | .shost_attrs = qla4xxx_host_attrs, |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 212 | .host_reset = qla4xxx_host_reset, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 213 | .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | static struct iscsi_transport qla4xxx_iscsi_transport = { |
| 217 | .owner = THIS_MODULE, |
| 218 | .name = DRIVER_NAME, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 219 | .caps = CAP_TEXT_NEGO | |
| 220 | CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST | |
| 221 | CAP_DATADGST | CAP_LOGIN_OFFLOAD | |
| 222 | CAP_MULTI_R2T, |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 223 | .attr_is_visible = qla4_attr_is_visible, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 224 | .create_session = qla4xxx_session_create, |
| 225 | .destroy_session = qla4xxx_session_destroy, |
| 226 | .start_conn = qla4xxx_conn_start, |
| 227 | .create_conn = qla4xxx_conn_create, |
| 228 | .bind_conn = qla4xxx_conn_bind, |
| 229 | .stop_conn = iscsi_conn_stop, |
| 230 | .destroy_conn = qla4xxx_conn_destroy, |
| 231 | .set_param = iscsi_set_param, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 232 | .get_conn_param = qla4xxx_conn_get_param, |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 233 | .get_session_param = qla4xxx_session_get_param, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 234 | .get_ep_param = qla4xxx_get_ep_param, |
| 235 | .ep_connect = qla4xxx_ep_connect, |
| 236 | .ep_poll = qla4xxx_ep_poll, |
| 237 | .ep_disconnect = qla4xxx_ep_disconnect, |
| 238 | .get_stats = qla4xxx_conn_get_stats, |
| 239 | .send_pdu = iscsi_conn_send_pdu, |
| 240 | .xmit_task = qla4xxx_task_xmit, |
| 241 | .cleanup_task = qla4xxx_task_cleanup, |
| 242 | .alloc_pdu = qla4xxx_alloc_pdu, |
| 243 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 244 | .get_host_param = qla4xxx_host_get_param, |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 245 | .set_iface_param = qla4xxx_iface_set_param, |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 246 | .get_iface_param = qla4xxx_get_iface_param, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 247 | .bsg_request = qla4xxx_bsg_request, |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 248 | .send_ping = qla4xxx_send_ping, |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 249 | .get_chap = qla4xxx_get_chap_list, |
| 250 | .delete_chap = qla4xxx_delete_chap, |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 251 | .set_chap = qla4xxx_set_chap_entry, |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 252 | .get_flashnode_param = qla4xxx_sysfs_ddb_get_param, |
| 253 | .set_flashnode_param = qla4xxx_sysfs_ddb_set_param, |
| 254 | .new_flashnode = qla4xxx_sysfs_ddb_add, |
| 255 | .del_flashnode = qla4xxx_sysfs_ddb_delete, |
| 256 | .login_flashnode = qla4xxx_sysfs_ddb_login, |
| 257 | .logout_flashnode = qla4xxx_sysfs_ddb_logout, |
| 258 | .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid, |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 259 | .get_host_stats = qla4xxx_get_host_stats, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | static struct scsi_transport_template *qla4xxx_scsi_transport; |
| 263 | |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 264 | static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha) |
| 265 | { |
| 266 | u32 reg_val = 0; |
| 267 | int rval = QLA_SUCCESS; |
| 268 | |
| 269 | if (is_qla8022(ha)) |
| 270 | reg_val = readl(&ha->qla4_82xx_reg->host_status); |
| 271 | else if (is_qla8032(ha) || is_qla8042(ha)) |
| 272 | reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER); |
| 273 | else |
| 274 | reg_val = readw(&ha->reg->ctrl_status); |
| 275 | |
| 276 | if (reg_val == QL4_ISP_REG_DISCONNECT) |
| 277 | rval = QLA_ERROR; |
| 278 | |
| 279 | return rval; |
| 280 | } |
| 281 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 282 | static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num, |
| 283 | uint32_t iface_type, uint32_t payload_size, |
| 284 | uint32_t pid, struct sockaddr *dst_addr) |
| 285 | { |
| 286 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 287 | struct sockaddr_in *addr; |
| 288 | struct sockaddr_in6 *addr6; |
| 289 | uint32_t options = 0; |
| 290 | uint8_t ipaddr[IPv6_ADDR_LEN]; |
| 291 | int rval; |
| 292 | |
| 293 | memset(ipaddr, 0, IPv6_ADDR_LEN); |
| 294 | /* IPv4 to IPv4 */ |
| 295 | if ((iface_type == ISCSI_IFACE_TYPE_IPV4) && |
| 296 | (dst_addr->sa_family == AF_INET)) { |
| 297 | addr = (struct sockaddr_in *)dst_addr; |
| 298 | memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN); |
| 299 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 " |
| 300 | "dest: %pI4\n", __func__, |
| 301 | &ha->ip_config.ip_address, ipaddr)); |
| 302 | rval = qla4xxx_ping_iocb(ha, options, payload_size, pid, |
| 303 | ipaddr); |
| 304 | if (rval) |
| 305 | rval = -EINVAL; |
| 306 | } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) && |
| 307 | (dst_addr->sa_family == AF_INET6)) { |
| 308 | /* IPv6 to IPv6 */ |
| 309 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 310 | memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN); |
| 311 | |
| 312 | options |= PING_IPV6_PROTOCOL_ENABLE; |
| 313 | |
| 314 | /* Ping using LinkLocal address */ |
| 315 | if ((iface_num == 0) || (iface_num == 1)) { |
| 316 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping " |
| 317 | "src: %pI6 dest: %pI6\n", __func__, |
| 318 | &ha->ip_config.ipv6_link_local_addr, |
| 319 | ipaddr)); |
| 320 | options |= PING_IPV6_LINKLOCAL_ADDR; |
| 321 | rval = qla4xxx_ping_iocb(ha, options, payload_size, |
| 322 | pid, ipaddr); |
| 323 | } else { |
| 324 | ql4_printk(KERN_WARNING, ha, "%s: iface num = %d " |
| 325 | "not supported\n", __func__, iface_num); |
| 326 | rval = -ENOSYS; |
| 327 | goto exit_send_ping; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * If ping using LinkLocal address fails, try ping using |
| 332 | * IPv6 address |
| 333 | */ |
| 334 | if (rval != QLA_SUCCESS) { |
| 335 | options &= ~PING_IPV6_LINKLOCAL_ADDR; |
| 336 | if (iface_num == 0) { |
| 337 | options |= PING_IPV6_ADDR0; |
| 338 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 " |
| 339 | "Ping src: %pI6 " |
| 340 | "dest: %pI6\n", __func__, |
| 341 | &ha->ip_config.ipv6_addr0, |
| 342 | ipaddr)); |
| 343 | } else if (iface_num == 1) { |
| 344 | options |= PING_IPV6_ADDR1; |
| 345 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 " |
| 346 | "Ping src: %pI6 " |
| 347 | "dest: %pI6\n", __func__, |
| 348 | &ha->ip_config.ipv6_addr1, |
| 349 | ipaddr)); |
| 350 | } |
| 351 | rval = qla4xxx_ping_iocb(ha, options, payload_size, |
| 352 | pid, ipaddr); |
| 353 | if (rval) |
| 354 | rval = -EINVAL; |
| 355 | } |
| 356 | } else |
| 357 | rval = -ENOSYS; |
| 358 | exit_send_ping: |
| 359 | return rval; |
| 360 | } |
| 361 | |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 362 | static umode_t qla4_attr_is_visible(int param_type, int param) |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 363 | { |
| 364 | switch (param_type) { |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 365 | case ISCSI_HOST_PARAM: |
| 366 | switch (param) { |
| 367 | case ISCSI_HOST_PARAM_HWADDRESS: |
| 368 | case ISCSI_HOST_PARAM_IPADDRESS: |
| 369 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 370 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 371 | case ISCSI_HOST_PARAM_PORT_SPEED: |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 372 | return S_IRUGO; |
| 373 | default: |
| 374 | return 0; |
| 375 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 376 | case ISCSI_PARAM: |
| 377 | switch (param) { |
Mike Christie | 590134f | 2011-10-17 22:42:13 -0500 | [diff] [blame] | 378 | case ISCSI_PARAM_PERSISTENT_ADDRESS: |
| 379 | case ISCSI_PARAM_PERSISTENT_PORT: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 380 | case ISCSI_PARAM_CONN_ADDRESS: |
| 381 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 382 | case ISCSI_PARAM_TARGET_NAME: |
| 383 | case ISCSI_PARAM_TPGT: |
| 384 | case ISCSI_PARAM_TARGET_ALIAS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 385 | case ISCSI_PARAM_MAX_BURST: |
| 386 | case ISCSI_PARAM_MAX_R2T: |
| 387 | case ISCSI_PARAM_FIRST_BURST: |
| 388 | case ISCSI_PARAM_MAX_RECV_DLENGTH: |
| 389 | case ISCSI_PARAM_MAX_XMIT_DLENGTH: |
Mike Christie | de37920 | 2011-08-14 20:42:56 -0500 | [diff] [blame] | 390 | case ISCSI_PARAM_IFACE_NAME: |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 391 | case ISCSI_PARAM_CHAP_OUT_IDX: |
| 392 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 393 | case ISCSI_PARAM_USERNAME: |
| 394 | case ISCSI_PARAM_PASSWORD: |
| 395 | case ISCSI_PARAM_USERNAME_IN: |
| 396 | case ISCSI_PARAM_PASSWORD_IN: |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 397 | case ISCSI_PARAM_AUTO_SND_TGT_DISABLE: |
| 398 | case ISCSI_PARAM_DISCOVERY_SESS: |
| 399 | case ISCSI_PARAM_PORTAL_TYPE: |
| 400 | case ISCSI_PARAM_CHAP_AUTH_EN: |
| 401 | case ISCSI_PARAM_DISCOVERY_LOGOUT_EN: |
| 402 | case ISCSI_PARAM_BIDI_CHAP_EN: |
| 403 | case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 404 | case ISCSI_PARAM_DEF_TIME2WAIT: |
| 405 | case ISCSI_PARAM_DEF_TIME2RETAIN: |
| 406 | case ISCSI_PARAM_HDRDGST_EN: |
| 407 | case ISCSI_PARAM_DATADGST_EN: |
| 408 | case ISCSI_PARAM_INITIAL_R2T_EN: |
| 409 | case ISCSI_PARAM_IMM_DATA_EN: |
| 410 | case ISCSI_PARAM_PDU_INORDER_EN: |
| 411 | case ISCSI_PARAM_DATASEQ_INORDER_EN: |
| 412 | case ISCSI_PARAM_MAX_SEGMENT_SIZE: |
| 413 | case ISCSI_PARAM_TCP_TIMESTAMP_STAT: |
| 414 | case ISCSI_PARAM_TCP_WSF_DISABLE: |
| 415 | case ISCSI_PARAM_TCP_NAGLE_DISABLE: |
| 416 | case ISCSI_PARAM_TCP_TIMER_SCALE: |
| 417 | case ISCSI_PARAM_TCP_TIMESTAMP_EN: |
| 418 | case ISCSI_PARAM_TCP_XMIT_WSF: |
| 419 | case ISCSI_PARAM_TCP_RECV_WSF: |
| 420 | case ISCSI_PARAM_IP_FRAGMENT_DISABLE: |
| 421 | case ISCSI_PARAM_IPV4_TOS: |
| 422 | case ISCSI_PARAM_IPV6_TC: |
| 423 | case ISCSI_PARAM_IPV6_FLOW_LABEL: |
| 424 | case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6: |
| 425 | case ISCSI_PARAM_KEEPALIVE_TMO: |
| 426 | case ISCSI_PARAM_LOCAL_PORT: |
| 427 | case ISCSI_PARAM_ISID: |
| 428 | case ISCSI_PARAM_TSID: |
| 429 | case ISCSI_PARAM_DEF_TASKMGMT_TMO: |
| 430 | case ISCSI_PARAM_ERL: |
| 431 | case ISCSI_PARAM_STATSN: |
| 432 | case ISCSI_PARAM_EXP_STATSN: |
| 433 | case ISCSI_PARAM_DISCOVERY_PARENT_IDX: |
| 434 | case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: |
Adheer Chandravanshi | fb734ee3 | 2013-11-22 05:28:22 -0500 | [diff] [blame] | 435 | case ISCSI_PARAM_LOCAL_IPADDR: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 436 | return S_IRUGO; |
| 437 | default: |
| 438 | return 0; |
| 439 | } |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 440 | case ISCSI_NET_PARAM: |
| 441 | switch (param) { |
| 442 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 443 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 444 | case ISCSI_NET_PARAM_IPV4_GW: |
| 445 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 446 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 447 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 448 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 449 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 450 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 451 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 452 | case ISCSI_NET_PARAM_VLAN_ID: |
| 453 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 454 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 455 | case ISCSI_NET_PARAM_MTU: |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 456 | case ISCSI_NET_PARAM_PORT: |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 457 | case ISCSI_NET_PARAM_IPADDR_STATE: |
| 458 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: |
| 459 | case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: |
| 460 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 461 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 462 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 463 | case ISCSI_NET_PARAM_TCP_WSF: |
| 464 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 465 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 466 | case ISCSI_NET_PARAM_CACHE_ID: |
| 467 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 468 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 469 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 470 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 471 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 472 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 473 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 474 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 475 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 476 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 477 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 478 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 479 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 480 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 481 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 482 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 483 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 484 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 485 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
| 486 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
| 487 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
| 488 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
| 489 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 490 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 491 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 492 | return S_IRUGO; |
| 493 | default: |
| 494 | return 0; |
| 495 | } |
| 496 | case ISCSI_IFACE_PARAM: |
| 497 | switch (param) { |
| 498 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 499 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 500 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 501 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 502 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 503 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 504 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 505 | case ISCSI_IFACE_PARAM_ERL: |
| 506 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 507 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 508 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 509 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 510 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 511 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 512 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 513 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 514 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 515 | case ISCSI_IFACE_PARAM_INITIATOR_NAME: |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 516 | return S_IRUGO; |
| 517 | default: |
| 518 | return 0; |
| 519 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 520 | case ISCSI_FLASHNODE_PARAM: |
| 521 | switch (param) { |
| 522 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 523 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 524 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 525 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 526 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 527 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 528 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 529 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 530 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 531 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 532 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 533 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 534 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 535 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 536 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 537 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 538 | case ISCSI_FLASHNODE_ERL: |
| 539 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 540 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 541 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 542 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 543 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 544 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 545 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 546 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 547 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 548 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 549 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 550 | case ISCSI_FLASHNODE_MAX_R2T: |
| 551 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 552 | case ISCSI_FLASHNODE_ISID: |
| 553 | case ISCSI_FLASHNODE_TSID: |
| 554 | case ISCSI_FLASHNODE_PORT: |
| 555 | case ISCSI_FLASHNODE_MAX_BURST: |
| 556 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 557 | case ISCSI_FLASHNODE_IPADDR: |
| 558 | case ISCSI_FLASHNODE_ALIAS: |
| 559 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 560 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 561 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 562 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 563 | case ISCSI_FLASHNODE_IPV6_TC: |
| 564 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 565 | case ISCSI_FLASHNODE_NAME: |
| 566 | case ISCSI_FLASHNODE_TPGT: |
| 567 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 568 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 569 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 570 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 571 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 572 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 573 | case ISCSI_FLASHNODE_USERNAME: |
| 574 | case ISCSI_FLASHNODE_PASSWORD: |
| 575 | case ISCSI_FLASHNODE_STATSN: |
| 576 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 577 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 578 | return S_IRUGO; |
| 579 | default: |
| 580 | return 0; |
| 581 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
Adheer Chandravanshi | ea507a2 | 2013-11-22 05:28:23 -0500 | [diff] [blame] | 587 | /** |
| 588 | * qla4xxx_create chap_list - Create CHAP list from FLASH |
| 589 | * @ha: pointer to adapter structure |
| 590 | * |
| 591 | * Read flash and make a list of CHAP entries, during login when a CHAP entry |
| 592 | * is received, it will be checked in this list. If entry exist then the CHAP |
| 593 | * entry index is set in the DDB. If CHAP entry does not exist in this list |
| 594 | * then a new entry is added in FLASH in CHAP table and the index obtained is |
| 595 | * used in the DDB. |
| 596 | **/ |
| 597 | static void qla4xxx_create_chap_list(struct scsi_qla_host *ha) |
| 598 | { |
| 599 | int rval = 0; |
| 600 | uint8_t *chap_flash_data = NULL; |
| 601 | uint32_t offset; |
| 602 | dma_addr_t chap_dma; |
| 603 | uint32_t chap_size = 0; |
| 604 | |
| 605 | if (is_qla40XX(ha)) |
| 606 | chap_size = MAX_CHAP_ENTRIES_40XX * |
| 607 | sizeof(struct ql4_chap_table); |
| 608 | else /* Single region contains CHAP info for both |
| 609 | * ports which is divided into half for each port. |
| 610 | */ |
| 611 | chap_size = ha->hw.flt_chap_size / 2; |
| 612 | |
| 613 | chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size, |
| 614 | &chap_dma, GFP_KERNEL); |
| 615 | if (!chap_flash_data) { |
| 616 | ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n"); |
| 617 | return; |
| 618 | } |
| 619 | |
| 620 | if (is_qla40XX(ha)) { |
| 621 | offset = FLASH_CHAP_OFFSET; |
| 622 | } else { |
| 623 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 624 | if (ha->port_num == 1) |
| 625 | offset += chap_size; |
| 626 | } |
| 627 | |
| 628 | rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 629 | if (rval != QLA_SUCCESS) |
| 630 | goto exit_chap_list; |
| 631 | |
| 632 | if (ha->chap_list == NULL) |
| 633 | ha->chap_list = vmalloc(chap_size); |
| 634 | if (ha->chap_list == NULL) { |
| 635 | ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n"); |
| 636 | goto exit_chap_list; |
| 637 | } |
| 638 | |
| 639 | memset(ha->chap_list, 0, chap_size); |
| 640 | memcpy(ha->chap_list, chap_flash_data, chap_size); |
| 641 | |
| 642 | exit_chap_list: |
| 643 | dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma); |
| 644 | } |
| 645 | |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 646 | static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha, |
| 647 | int16_t chap_index, |
| 648 | struct ql4_chap_table **chap_entry) |
| 649 | { |
| 650 | int rval = QLA_ERROR; |
| 651 | int max_chap_entries; |
| 652 | |
| 653 | if (!ha->chap_list) { |
| 654 | ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n"); |
| 655 | rval = QLA_ERROR; |
| 656 | goto exit_get_chap; |
| 657 | } |
| 658 | |
| 659 | if (is_qla80XX(ha)) |
| 660 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 661 | sizeof(struct ql4_chap_table); |
| 662 | else |
| 663 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 664 | |
| 665 | if (chap_index > max_chap_entries) { |
| 666 | ql4_printk(KERN_ERR, ha, "Invalid Chap index\n"); |
| 667 | rval = QLA_ERROR; |
| 668 | goto exit_get_chap; |
| 669 | } |
| 670 | |
| 671 | *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index; |
| 672 | if ((*chap_entry)->cookie != |
| 673 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 674 | rval = QLA_ERROR; |
| 675 | *chap_entry = NULL; |
| 676 | } else { |
| 677 | rval = QLA_SUCCESS; |
| 678 | } |
| 679 | |
| 680 | exit_get_chap: |
| 681 | return rval; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * qla4xxx_find_free_chap_index - Find the first free chap index |
| 686 | * @ha: pointer to adapter structure |
| 687 | * @chap_index: CHAP index to be returned |
| 688 | * |
| 689 | * Find the first free chap index available in the chap table |
| 690 | * |
| 691 | * Note: Caller should acquire the chap lock before getting here. |
| 692 | **/ |
| 693 | static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha, |
| 694 | uint16_t *chap_index) |
| 695 | { |
| 696 | int i, rval; |
| 697 | int free_index = -1; |
| 698 | int max_chap_entries = 0; |
| 699 | struct ql4_chap_table *chap_table; |
| 700 | |
| 701 | if (is_qla80XX(ha)) |
| 702 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 703 | sizeof(struct ql4_chap_table); |
| 704 | else |
| 705 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 706 | |
| 707 | if (!ha->chap_list) { |
| 708 | ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n"); |
| 709 | rval = QLA_ERROR; |
| 710 | goto exit_find_chap; |
| 711 | } |
| 712 | |
| 713 | for (i = 0; i < max_chap_entries; i++) { |
| 714 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 715 | |
| 716 | if ((chap_table->cookie != |
| 717 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) && |
| 718 | (i > MAX_RESRV_CHAP_IDX)) { |
| 719 | free_index = i; |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | if (free_index != -1) { |
| 725 | *chap_index = free_index; |
| 726 | rval = QLA_SUCCESS; |
| 727 | } else { |
| 728 | rval = QLA_ERROR; |
| 729 | } |
| 730 | |
| 731 | exit_find_chap: |
| 732 | return rval; |
| 733 | } |
| 734 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 735 | static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx, |
| 736 | uint32_t *num_entries, char *buf) |
| 737 | { |
| 738 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 739 | struct ql4_chap_table *chap_table; |
| 740 | struct iscsi_chap_rec *chap_rec; |
| 741 | int max_chap_entries = 0; |
| 742 | int valid_chap_entries = 0; |
| 743 | int ret = 0, i; |
| 744 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 745 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 746 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 747 | sizeof(struct ql4_chap_table); |
| 748 | else |
| 749 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 750 | |
| 751 | ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n", |
| 752 | __func__, *num_entries, chap_tbl_idx); |
| 753 | |
| 754 | if (!buf) { |
| 755 | ret = -ENOMEM; |
| 756 | goto exit_get_chap_list; |
| 757 | } |
| 758 | |
Adheer Chandravanshi | ea507a2 | 2013-11-22 05:28:23 -0500 | [diff] [blame] | 759 | qla4xxx_create_chap_list(ha); |
| 760 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 761 | chap_rec = (struct iscsi_chap_rec *) buf; |
| 762 | mutex_lock(&ha->chap_sem); |
| 763 | for (i = chap_tbl_idx; i < max_chap_entries; i++) { |
| 764 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 765 | if (chap_table->cookie != |
| 766 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) |
| 767 | continue; |
| 768 | |
| 769 | chap_rec->chap_tbl_idx = i; |
Rickard Strandqvist | bdbb966 | 2014-07-26 16:49:32 +0200 | [diff] [blame] | 770 | strlcpy(chap_rec->username, chap_table->name, |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 771 | ISCSI_CHAP_AUTH_NAME_MAX_LEN); |
Rickard Strandqvist | bdbb966 | 2014-07-26 16:49:32 +0200 | [diff] [blame] | 772 | strlcpy(chap_rec->password, chap_table->secret, |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 773 | QL4_CHAP_MAX_SECRET_LEN); |
| 774 | chap_rec->password_length = chap_table->secret_len; |
| 775 | |
| 776 | if (chap_table->flags & BIT_7) /* local */ |
| 777 | chap_rec->chap_type = CHAP_TYPE_OUT; |
| 778 | |
| 779 | if (chap_table->flags & BIT_6) /* peer */ |
| 780 | chap_rec->chap_type = CHAP_TYPE_IN; |
| 781 | |
| 782 | chap_rec++; |
| 783 | |
| 784 | valid_chap_entries++; |
| 785 | if (valid_chap_entries == *num_entries) |
| 786 | break; |
| 787 | else |
| 788 | continue; |
| 789 | } |
| 790 | mutex_unlock(&ha->chap_sem); |
| 791 | |
| 792 | exit_get_chap_list: |
| 793 | ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n", |
| 794 | __func__, valid_chap_entries); |
| 795 | *num_entries = valid_chap_entries; |
| 796 | return ret; |
| 797 | } |
| 798 | |
| 799 | static int __qla4xxx_is_chap_active(struct device *dev, void *data) |
| 800 | { |
| 801 | int ret = 0; |
| 802 | uint16_t *chap_tbl_idx = (uint16_t *) data; |
| 803 | struct iscsi_cls_session *cls_session; |
| 804 | struct iscsi_session *sess; |
| 805 | struct ddb_entry *ddb_entry; |
| 806 | |
| 807 | if (!iscsi_is_session_dev(dev)) |
| 808 | goto exit_is_chap_active; |
| 809 | |
| 810 | cls_session = iscsi_dev_to_session(dev); |
| 811 | sess = cls_session->dd_data; |
| 812 | ddb_entry = sess->dd_data; |
| 813 | |
| 814 | if (iscsi_session_chkready(cls_session)) |
| 815 | goto exit_is_chap_active; |
| 816 | |
| 817 | if (ddb_entry->chap_tbl_idx == *chap_tbl_idx) |
| 818 | ret = 1; |
| 819 | |
| 820 | exit_is_chap_active: |
| 821 | return ret; |
| 822 | } |
| 823 | |
| 824 | static int qla4xxx_is_chap_active(struct Scsi_Host *shost, |
| 825 | uint16_t chap_tbl_idx) |
| 826 | { |
| 827 | int ret = 0; |
| 828 | |
| 829 | ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx, |
| 830 | __qla4xxx_is_chap_active); |
| 831 | |
| 832 | return ret; |
| 833 | } |
| 834 | |
| 835 | static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx) |
| 836 | { |
| 837 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 838 | struct ql4_chap_table *chap_table; |
| 839 | dma_addr_t chap_dma; |
| 840 | int max_chap_entries = 0; |
| 841 | uint32_t offset = 0; |
| 842 | uint32_t chap_size; |
| 843 | int ret = 0; |
| 844 | |
Souptick Joarder | 8d35a9d | 2018-02-15 00:30:20 +0530 | [diff] [blame] | 845 | chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma); |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 846 | if (chap_table == NULL) |
| 847 | return -ENOMEM; |
| 848 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 849 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 850 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 851 | sizeof(struct ql4_chap_table); |
| 852 | else |
| 853 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 854 | |
| 855 | if (chap_tbl_idx > max_chap_entries) { |
| 856 | ret = -EINVAL; |
| 857 | goto exit_delete_chap; |
| 858 | } |
| 859 | |
| 860 | /* Check if chap index is in use. |
| 861 | * If chap is in use don't delet chap entry */ |
| 862 | ret = qla4xxx_is_chap_active(shost, chap_tbl_idx); |
| 863 | if (ret) { |
| 864 | ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot " |
| 865 | "delete from flash\n", chap_tbl_idx); |
| 866 | ret = -EBUSY; |
| 867 | goto exit_delete_chap; |
| 868 | } |
| 869 | |
| 870 | chap_size = sizeof(struct ql4_chap_table); |
| 871 | if (is_qla40XX(ha)) |
| 872 | offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size); |
| 873 | else { |
| 874 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 875 | /* flt_chap_size is CHAP table size for both ports |
| 876 | * so divide it by 2 to calculate the offset for second port |
| 877 | */ |
| 878 | if (ha->port_num == 1) |
| 879 | offset += (ha->hw.flt_chap_size / 2); |
| 880 | offset += (chap_tbl_idx * chap_size); |
| 881 | } |
| 882 | |
| 883 | ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 884 | if (ret != QLA_SUCCESS) { |
| 885 | ret = -EINVAL; |
| 886 | goto exit_delete_chap; |
| 887 | } |
| 888 | |
| 889 | DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n", |
| 890 | __le16_to_cpu(chap_table->cookie))); |
| 891 | |
| 892 | if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) { |
| 893 | ql4_printk(KERN_ERR, ha, "No valid chap entry found\n"); |
| 894 | goto exit_delete_chap; |
| 895 | } |
| 896 | |
| 897 | chap_table->cookie = __constant_cpu_to_le16(0xFFFF); |
| 898 | |
| 899 | offset = FLASH_CHAP_OFFSET | |
| 900 | (chap_tbl_idx * sizeof(struct ql4_chap_table)); |
| 901 | ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size, |
| 902 | FLASH_OPT_RMW_COMMIT); |
| 903 | if (ret == QLA_SUCCESS && ha->chap_list) { |
| 904 | mutex_lock(&ha->chap_sem); |
| 905 | /* Update ha chap_list cache */ |
| 906 | memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx, |
| 907 | chap_table, sizeof(struct ql4_chap_table)); |
| 908 | mutex_unlock(&ha->chap_sem); |
| 909 | } |
| 910 | if (ret != QLA_SUCCESS) |
| 911 | ret = -EINVAL; |
| 912 | |
| 913 | exit_delete_chap: |
| 914 | dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma); |
| 915 | return ret; |
| 916 | } |
| 917 | |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 918 | /** |
| 919 | * qla4xxx_set_chap_entry - Make chap entry with given information |
| 920 | * @shost: pointer to host |
| 921 | * @data: chap info - credentials, index and type to make chap entry |
| 922 | * @len: length of data |
| 923 | * |
| 924 | * Add or update chap entry with the given information |
| 925 | **/ |
| 926 | static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len) |
| 927 | { |
| 928 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 929 | struct iscsi_chap_rec chap_rec; |
| 930 | struct ql4_chap_table *chap_entry = NULL; |
| 931 | struct iscsi_param_info *param_info; |
| 932 | struct nlattr *attr; |
| 933 | int max_chap_entries = 0; |
| 934 | int type; |
| 935 | int rem = len; |
| 936 | int rc = 0; |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 937 | int size; |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 938 | |
| 939 | memset(&chap_rec, 0, sizeof(chap_rec)); |
| 940 | |
| 941 | nla_for_each_attr(attr, data, len, rem) { |
| 942 | param_info = nla_data(attr); |
| 943 | |
| 944 | switch (param_info->param) { |
| 945 | case ISCSI_CHAP_PARAM_INDEX: |
| 946 | chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value; |
| 947 | break; |
| 948 | case ISCSI_CHAP_PARAM_CHAP_TYPE: |
| 949 | chap_rec.chap_type = param_info->value[0]; |
| 950 | break; |
| 951 | case ISCSI_CHAP_PARAM_USERNAME: |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 952 | size = min_t(size_t, sizeof(chap_rec.username), |
| 953 | param_info->len); |
| 954 | memcpy(chap_rec.username, param_info->value, size); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 955 | break; |
| 956 | case ISCSI_CHAP_PARAM_PASSWORD: |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 957 | size = min_t(size_t, sizeof(chap_rec.password), |
| 958 | param_info->len); |
| 959 | memcpy(chap_rec.password, param_info->value, size); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 960 | break; |
| 961 | case ISCSI_CHAP_PARAM_PASSWORD_LEN: |
| 962 | chap_rec.password_length = param_info->value[0]; |
| 963 | break; |
| 964 | default: |
| 965 | ql4_printk(KERN_ERR, ha, |
| 966 | "%s: No such sysfs attribute\n", __func__); |
| 967 | rc = -ENOSYS; |
| 968 | goto exit_set_chap; |
| 969 | }; |
| 970 | } |
| 971 | |
| 972 | if (chap_rec.chap_type == CHAP_TYPE_IN) |
| 973 | type = BIDI_CHAP; |
| 974 | else |
| 975 | type = LOCAL_CHAP; |
| 976 | |
| 977 | if (is_qla80XX(ha)) |
| 978 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 979 | sizeof(struct ql4_chap_table); |
| 980 | else |
| 981 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 982 | |
| 983 | mutex_lock(&ha->chap_sem); |
| 984 | if (chap_rec.chap_tbl_idx < max_chap_entries) { |
| 985 | rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx, |
| 986 | &chap_entry); |
| 987 | if (!rc) { |
| 988 | if (!(type == qla4xxx_get_chap_type(chap_entry))) { |
| 989 | ql4_printk(KERN_INFO, ha, |
| 990 | "Type mismatch for CHAP entry %d\n", |
| 991 | chap_rec.chap_tbl_idx); |
| 992 | rc = -EINVAL; |
| 993 | goto exit_unlock_chap; |
| 994 | } |
| 995 | |
| 996 | /* If chap index is in use then don't modify it */ |
| 997 | rc = qla4xxx_is_chap_active(shost, |
| 998 | chap_rec.chap_tbl_idx); |
| 999 | if (rc) { |
| 1000 | ql4_printk(KERN_INFO, ha, |
| 1001 | "CHAP entry %d is in use\n", |
| 1002 | chap_rec.chap_tbl_idx); |
| 1003 | rc = -EBUSY; |
| 1004 | goto exit_unlock_chap; |
| 1005 | } |
| 1006 | } |
| 1007 | } else { |
| 1008 | rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx); |
| 1009 | if (rc) { |
| 1010 | ql4_printk(KERN_INFO, ha, "CHAP entry not available\n"); |
| 1011 | rc = -EBUSY; |
| 1012 | goto exit_unlock_chap; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password, |
| 1017 | chap_rec.chap_tbl_idx, type); |
| 1018 | |
| 1019 | exit_unlock_chap: |
| 1020 | mutex_unlock(&ha->chap_sem); |
| 1021 | |
| 1022 | exit_set_chap: |
| 1023 | return rc; |
| 1024 | } |
| 1025 | |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 1026 | |
| 1027 | static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len) |
| 1028 | { |
| 1029 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 1030 | struct iscsi_offload_host_stats *host_stats = NULL; |
| 1031 | int host_stats_size; |
| 1032 | int ret = 0; |
| 1033 | int ddb_idx = 0; |
| 1034 | struct ql_iscsi_stats *ql_iscsi_stats = NULL; |
| 1035 | int stats_size; |
| 1036 | dma_addr_t iscsi_stats_dma; |
| 1037 | |
| 1038 | DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__)); |
| 1039 | |
| 1040 | host_stats_size = sizeof(struct iscsi_offload_host_stats); |
| 1041 | |
| 1042 | if (host_stats_size != len) { |
| 1043 | ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n", |
| 1044 | __func__, len, host_stats_size); |
| 1045 | ret = -EINVAL; |
| 1046 | goto exit_host_stats; |
| 1047 | } |
| 1048 | host_stats = (struct iscsi_offload_host_stats *)buf; |
| 1049 | |
| 1050 | if (!buf) { |
| 1051 | ret = -ENOMEM; |
| 1052 | goto exit_host_stats; |
| 1053 | } |
| 1054 | |
| 1055 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 1056 | |
| 1057 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 1058 | &iscsi_stats_dma, GFP_KERNEL); |
| 1059 | if (!ql_iscsi_stats) { |
| 1060 | ql4_printk(KERN_ERR, ha, |
| 1061 | "Unable to allocate memory for iscsi stats\n"); |
Mike Christie | 7f3976f | 2014-07-12 15:51:49 -0500 | [diff] [blame] | 1062 | ret = -ENOMEM; |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 1063 | goto exit_host_stats; |
| 1064 | } |
| 1065 | |
| 1066 | ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size, |
| 1067 | iscsi_stats_dma); |
| 1068 | if (ret != QLA_SUCCESS) { |
| 1069 | ql4_printk(KERN_ERR, ha, |
| 1070 | "Unable to retrieve iscsi stats\n"); |
Mike Christie | 7f3976f | 2014-07-12 15:51:49 -0500 | [diff] [blame] | 1071 | ret = -EIO; |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 1072 | goto exit_host_stats; |
| 1073 | } |
| 1074 | host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames); |
| 1075 | host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes); |
| 1076 | host_stats->mactx_multicast_frames = |
| 1077 | le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames); |
| 1078 | host_stats->mactx_broadcast_frames = |
| 1079 | le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames); |
| 1080 | host_stats->mactx_pause_frames = |
| 1081 | le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames); |
| 1082 | host_stats->mactx_control_frames = |
| 1083 | le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames); |
| 1084 | host_stats->mactx_deferral = |
| 1085 | le64_to_cpu(ql_iscsi_stats->mac_tx_deferral); |
| 1086 | host_stats->mactx_excess_deferral = |
| 1087 | le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral); |
| 1088 | host_stats->mactx_late_collision = |
| 1089 | le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision); |
| 1090 | host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort); |
| 1091 | host_stats->mactx_single_collision = |
| 1092 | le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision); |
| 1093 | host_stats->mactx_multiple_collision = |
| 1094 | le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision); |
| 1095 | host_stats->mactx_collision = |
| 1096 | le64_to_cpu(ql_iscsi_stats->mac_tx_collision); |
| 1097 | host_stats->mactx_frames_dropped = |
| 1098 | le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped); |
| 1099 | host_stats->mactx_jumbo_frames = |
| 1100 | le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames); |
| 1101 | host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames); |
| 1102 | host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes); |
| 1103 | host_stats->macrx_unknown_control_frames = |
| 1104 | le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames); |
| 1105 | host_stats->macrx_pause_frames = |
| 1106 | le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames); |
| 1107 | host_stats->macrx_control_frames = |
| 1108 | le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames); |
| 1109 | host_stats->macrx_dribble = |
| 1110 | le64_to_cpu(ql_iscsi_stats->mac_rx_dribble); |
| 1111 | host_stats->macrx_frame_length_error = |
| 1112 | le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error); |
| 1113 | host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber); |
| 1114 | host_stats->macrx_carrier_sense_error = |
| 1115 | le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error); |
| 1116 | host_stats->macrx_frame_discarded = |
| 1117 | le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded); |
| 1118 | host_stats->macrx_frames_dropped = |
| 1119 | le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped); |
| 1120 | host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error); |
| 1121 | host_stats->mac_encoding_error = |
| 1122 | le64_to_cpu(ql_iscsi_stats->mac_encoding_error); |
| 1123 | host_stats->macrx_length_error_large = |
| 1124 | le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large); |
| 1125 | host_stats->macrx_length_error_small = |
| 1126 | le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small); |
| 1127 | host_stats->macrx_multicast_frames = |
| 1128 | le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames); |
| 1129 | host_stats->macrx_broadcast_frames = |
| 1130 | le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames); |
| 1131 | host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets); |
| 1132 | host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes); |
| 1133 | host_stats->iptx_fragments = |
| 1134 | le64_to_cpu(ql_iscsi_stats->ip_tx_fragments); |
| 1135 | host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets); |
| 1136 | host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes); |
| 1137 | host_stats->iprx_fragments = |
| 1138 | le64_to_cpu(ql_iscsi_stats->ip_rx_fragments); |
| 1139 | host_stats->ip_datagram_reassembly = |
| 1140 | le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly); |
| 1141 | host_stats->ip_invalid_address_error = |
| 1142 | le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error); |
| 1143 | host_stats->ip_error_packets = |
| 1144 | le64_to_cpu(ql_iscsi_stats->ip_error_packets); |
| 1145 | host_stats->ip_fragrx_overlap = |
| 1146 | le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap); |
| 1147 | host_stats->ip_fragrx_outoforder = |
| 1148 | le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder); |
| 1149 | host_stats->ip_datagram_reassembly_timeout = |
| 1150 | le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout); |
| 1151 | host_stats->ipv6tx_packets = |
| 1152 | le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets); |
| 1153 | host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes); |
| 1154 | host_stats->ipv6tx_fragments = |
| 1155 | le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments); |
| 1156 | host_stats->ipv6rx_packets = |
| 1157 | le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets); |
| 1158 | host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes); |
| 1159 | host_stats->ipv6rx_fragments = |
| 1160 | le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments); |
| 1161 | host_stats->ipv6_datagram_reassembly = |
| 1162 | le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly); |
| 1163 | host_stats->ipv6_invalid_address_error = |
| 1164 | le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error); |
| 1165 | host_stats->ipv6_error_packets = |
| 1166 | le64_to_cpu(ql_iscsi_stats->ipv6_error_packets); |
| 1167 | host_stats->ipv6_fragrx_overlap = |
| 1168 | le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap); |
| 1169 | host_stats->ipv6_fragrx_outoforder = |
| 1170 | le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder); |
| 1171 | host_stats->ipv6_datagram_reassembly_timeout = |
| 1172 | le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout); |
| 1173 | host_stats->tcptx_segments = |
| 1174 | le64_to_cpu(ql_iscsi_stats->tcp_tx_segments); |
| 1175 | host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes); |
| 1176 | host_stats->tcprx_segments = |
| 1177 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segments); |
| 1178 | host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte); |
| 1179 | host_stats->tcp_duplicate_ack_retx = |
| 1180 | le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx); |
| 1181 | host_stats->tcp_retx_timer_expired = |
| 1182 | le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired); |
| 1183 | host_stats->tcprx_duplicate_ack = |
| 1184 | le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack); |
| 1185 | host_stats->tcprx_pure_ackr = |
| 1186 | le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr); |
| 1187 | host_stats->tcptx_delayed_ack = |
| 1188 | le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack); |
| 1189 | host_stats->tcptx_pure_ack = |
| 1190 | le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack); |
| 1191 | host_stats->tcprx_segment_error = |
| 1192 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error); |
| 1193 | host_stats->tcprx_segment_outoforder = |
| 1194 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder); |
| 1195 | host_stats->tcprx_window_probe = |
| 1196 | le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe); |
| 1197 | host_stats->tcprx_window_update = |
| 1198 | le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update); |
| 1199 | host_stats->tcptx_window_probe_persist = |
| 1200 | le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist); |
| 1201 | host_stats->ecc_error_correction = |
| 1202 | le64_to_cpu(ql_iscsi_stats->ecc_error_correction); |
| 1203 | host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx); |
| 1204 | host_stats->iscsi_data_bytes_tx = |
| 1205 | le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx); |
| 1206 | host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx); |
| 1207 | host_stats->iscsi_data_bytes_rx = |
| 1208 | le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx); |
| 1209 | host_stats->iscsi_io_completed = |
| 1210 | le64_to_cpu(ql_iscsi_stats->iscsi_io_completed); |
| 1211 | host_stats->iscsi_unexpected_io_rx = |
| 1212 | le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx); |
| 1213 | host_stats->iscsi_format_error = |
| 1214 | le64_to_cpu(ql_iscsi_stats->iscsi_format_error); |
| 1215 | host_stats->iscsi_hdr_digest_error = |
| 1216 | le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error); |
| 1217 | host_stats->iscsi_data_digest_error = |
| 1218 | le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error); |
| 1219 | host_stats->iscsi_sequence_error = |
| 1220 | le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error); |
| 1221 | exit_host_stats: |
| 1222 | if (ql_iscsi_stats) |
| 1223 | dma_free_coherent(&ha->pdev->dev, host_stats_size, |
| 1224 | ql_iscsi_stats, iscsi_stats_dma); |
| 1225 | |
| 1226 | ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n", |
| 1227 | __func__); |
| 1228 | return ret; |
| 1229 | } |
| 1230 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1231 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 1232 | enum iscsi_param_type param_type, |
| 1233 | int param, char *buf) |
| 1234 | { |
| 1235 | struct Scsi_Host *shost = iscsi_iface_to_shost(iface); |
| 1236 | struct scsi_qla_host *ha = to_qla_host(shost); |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1237 | int ival; |
| 1238 | char *pval = NULL; |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1239 | int len = -ENOSYS; |
| 1240 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1241 | if (param_type == ISCSI_NET_PARAM) { |
| 1242 | switch (param) { |
| 1243 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 1244 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| 1245 | break; |
| 1246 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 1247 | len = sprintf(buf, "%pI4\n", |
| 1248 | &ha->ip_config.subnet_mask); |
| 1249 | break; |
| 1250 | case ISCSI_NET_PARAM_IPV4_GW: |
| 1251 | len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); |
| 1252 | break; |
| 1253 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 1254 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1255 | OP_STATE(ha->ip_config.ipv4_options, |
| 1256 | IPOPT_IPV4_PROTOCOL_ENABLE, pval); |
| 1257 | } else { |
| 1258 | OP_STATE(ha->ip_config.ipv6_options, |
| 1259 | IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval); |
| 1260 | } |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1261 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1262 | len = sprintf(buf, "%s\n", pval); |
| 1263 | break; |
| 1264 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1265 | len = sprintf(buf, "%s\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1266 | (ha->ip_config.tcp_options & |
| 1267 | TCPOPT_DHCP_ENABLE) ? |
| 1268 | "dhcp" : "static"); |
| 1269 | break; |
| 1270 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 1271 | if (iface->iface_num == 0) |
| 1272 | len = sprintf(buf, "%pI6\n", |
| 1273 | &ha->ip_config.ipv6_addr0); |
| 1274 | if (iface->iface_num == 1) |
| 1275 | len = sprintf(buf, "%pI6\n", |
| 1276 | &ha->ip_config.ipv6_addr1); |
| 1277 | break; |
| 1278 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 1279 | len = sprintf(buf, "%pI6\n", |
| 1280 | &ha->ip_config.ipv6_link_local_addr); |
| 1281 | break; |
| 1282 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 1283 | len = sprintf(buf, "%pI6\n", |
| 1284 | &ha->ip_config.ipv6_default_router_addr); |
| 1285 | break; |
| 1286 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 1287 | pval = (ha->ip_config.ipv6_addl_options & |
| 1288 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? |
| 1289 | "nd" : "static"; |
| 1290 | |
| 1291 | len = sprintf(buf, "%s\n", pval); |
| 1292 | break; |
| 1293 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 1294 | pval = (ha->ip_config.ipv6_addl_options & |
| 1295 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? |
| 1296 | "auto" : "static"; |
| 1297 | |
| 1298 | len = sprintf(buf, "%s\n", pval); |
| 1299 | break; |
| 1300 | case ISCSI_NET_PARAM_VLAN_ID: |
| 1301 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1302 | ival = ha->ip_config.ipv4_vlan_tag & |
| 1303 | ISCSI_MAX_VLAN_ID; |
| 1304 | else |
| 1305 | ival = ha->ip_config.ipv6_vlan_tag & |
| 1306 | ISCSI_MAX_VLAN_ID; |
| 1307 | |
| 1308 | len = sprintf(buf, "%d\n", ival); |
| 1309 | break; |
| 1310 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 1311 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1312 | ival = (ha->ip_config.ipv4_vlan_tag >> 13) & |
| 1313 | ISCSI_MAX_VLAN_PRIORITY; |
| 1314 | else |
| 1315 | ival = (ha->ip_config.ipv6_vlan_tag >> 13) & |
| 1316 | ISCSI_MAX_VLAN_PRIORITY; |
| 1317 | |
| 1318 | len = sprintf(buf, "%d\n", ival); |
| 1319 | break; |
| 1320 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 1321 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1322 | OP_STATE(ha->ip_config.ipv4_options, |
| 1323 | IPOPT_VLAN_TAGGING_ENABLE, pval); |
| 1324 | } else { |
| 1325 | OP_STATE(ha->ip_config.ipv6_options, |
| 1326 | IPV6_OPT_VLAN_TAGGING_ENABLE, pval); |
| 1327 | } |
| 1328 | len = sprintf(buf, "%s\n", pval); |
| 1329 | break; |
| 1330 | case ISCSI_NET_PARAM_MTU: |
| 1331 | len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size); |
| 1332 | break; |
| 1333 | case ISCSI_NET_PARAM_PORT: |
| 1334 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1335 | len = sprintf(buf, "%d\n", |
| 1336 | ha->ip_config.ipv4_port); |
| 1337 | else |
| 1338 | len = sprintf(buf, "%d\n", |
| 1339 | ha->ip_config.ipv6_port); |
| 1340 | break; |
| 1341 | case ISCSI_NET_PARAM_IPADDR_STATE: |
| 1342 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1343 | pval = iscsi_get_ipaddress_state_name( |
| 1344 | ha->ip_config.ipv4_addr_state); |
| 1345 | } else { |
| 1346 | if (iface->iface_num == 0) |
| 1347 | pval = iscsi_get_ipaddress_state_name( |
| 1348 | ha->ip_config.ipv6_addr0_state); |
| 1349 | else if (iface->iface_num == 1) |
| 1350 | pval = iscsi_get_ipaddress_state_name( |
| 1351 | ha->ip_config.ipv6_addr1_state); |
| 1352 | } |
| 1353 | |
| 1354 | len = sprintf(buf, "%s\n", pval); |
| 1355 | break; |
| 1356 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: |
| 1357 | pval = iscsi_get_ipaddress_state_name( |
| 1358 | ha->ip_config.ipv6_link_local_state); |
| 1359 | len = sprintf(buf, "%s\n", pval); |
| 1360 | break; |
| 1361 | case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: |
| 1362 | pval = iscsi_get_router_state_name( |
| 1363 | ha->ip_config.ipv6_default_router_state); |
| 1364 | len = sprintf(buf, "%s\n", pval); |
| 1365 | break; |
| 1366 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 1367 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1368 | OP_STATE(~ha->ip_config.tcp_options, |
| 1369 | TCPOPT_DELAYED_ACK_DISABLE, pval); |
| 1370 | } else { |
| 1371 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1372 | IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval); |
| 1373 | } |
| 1374 | len = sprintf(buf, "%s\n", pval); |
| 1375 | break; |
| 1376 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 1377 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1378 | OP_STATE(~ha->ip_config.tcp_options, |
| 1379 | TCPOPT_NAGLE_ALGO_DISABLE, pval); |
| 1380 | } else { |
| 1381 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1382 | IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval); |
| 1383 | } |
| 1384 | len = sprintf(buf, "%s\n", pval); |
| 1385 | break; |
| 1386 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 1387 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1388 | OP_STATE(~ha->ip_config.tcp_options, |
| 1389 | TCPOPT_WINDOW_SCALE_DISABLE, pval); |
| 1390 | } else { |
| 1391 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1392 | IPV6_TCPOPT_WINDOW_SCALE_DISABLE, |
| 1393 | pval); |
| 1394 | } |
| 1395 | len = sprintf(buf, "%s\n", pval); |
| 1396 | break; |
| 1397 | case ISCSI_NET_PARAM_TCP_WSF: |
| 1398 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1399 | len = sprintf(buf, "%d\n", |
| 1400 | ha->ip_config.tcp_wsf); |
| 1401 | else |
| 1402 | len = sprintf(buf, "%d\n", |
| 1403 | ha->ip_config.ipv6_tcp_wsf); |
| 1404 | break; |
| 1405 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 1406 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1407 | ival = (ha->ip_config.tcp_options & |
| 1408 | TCPOPT_TIMER_SCALE) >> 1; |
| 1409 | else |
| 1410 | ival = (ha->ip_config.ipv6_tcp_options & |
| 1411 | IPV6_TCPOPT_TIMER_SCALE) >> 1; |
| 1412 | |
| 1413 | len = sprintf(buf, "%d\n", ival); |
| 1414 | break; |
| 1415 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 1416 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1417 | OP_STATE(ha->ip_config.tcp_options, |
| 1418 | TCPOPT_TIMESTAMP_ENABLE, pval); |
| 1419 | } else { |
| 1420 | OP_STATE(ha->ip_config.ipv6_tcp_options, |
| 1421 | IPV6_TCPOPT_TIMESTAMP_EN, pval); |
| 1422 | } |
| 1423 | len = sprintf(buf, "%s\n", pval); |
| 1424 | break; |
| 1425 | case ISCSI_NET_PARAM_CACHE_ID: |
| 1426 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1427 | len = sprintf(buf, "%d\n", |
| 1428 | ha->ip_config.ipv4_cache_id); |
| 1429 | else |
| 1430 | len = sprintf(buf, "%d\n", |
| 1431 | ha->ip_config.ipv6_cache_id); |
| 1432 | break; |
| 1433 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 1434 | OP_STATE(ha->ip_config.tcp_options, |
| 1435 | TCPOPT_DNS_SERVER_IP_EN, pval); |
| 1436 | |
| 1437 | len = sprintf(buf, "%s\n", pval); |
| 1438 | break; |
| 1439 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 1440 | OP_STATE(ha->ip_config.tcp_options, |
| 1441 | TCPOPT_SLP_DA_INFO_EN, pval); |
| 1442 | |
| 1443 | len = sprintf(buf, "%s\n", pval); |
| 1444 | break; |
| 1445 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 1446 | OP_STATE(ha->ip_config.ipv4_options, |
| 1447 | IPOPT_IPV4_TOS_EN, pval); |
| 1448 | |
| 1449 | len = sprintf(buf, "%s\n", pval); |
| 1450 | break; |
| 1451 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 1452 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos); |
| 1453 | break; |
| 1454 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 1455 | OP_STATE(ha->ip_config.ipv4_options, |
| 1456 | IPOPT_GRAT_ARP_EN, pval); |
| 1457 | |
| 1458 | len = sprintf(buf, "%s\n", pval); |
| 1459 | break; |
| 1460 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 1461 | OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN, |
| 1462 | pval); |
| 1463 | |
| 1464 | len = sprintf(buf, "%s\n", pval); |
| 1465 | break; |
| 1466 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 1467 | pval = (ha->ip_config.ipv4_alt_cid_len) ? |
| 1468 | (char *)ha->ip_config.ipv4_alt_cid : ""; |
| 1469 | |
| 1470 | len = sprintf(buf, "%s\n", pval); |
| 1471 | break; |
| 1472 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 1473 | OP_STATE(ha->ip_config.ipv4_options, |
| 1474 | IPOPT_REQ_VID_EN, pval); |
| 1475 | |
| 1476 | len = sprintf(buf, "%s\n", pval); |
| 1477 | break; |
| 1478 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 1479 | OP_STATE(ha->ip_config.ipv4_options, |
| 1480 | IPOPT_USE_VID_EN, pval); |
| 1481 | |
| 1482 | len = sprintf(buf, "%s\n", pval); |
| 1483 | break; |
| 1484 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 1485 | pval = (ha->ip_config.ipv4_vid_len) ? |
| 1486 | (char *)ha->ip_config.ipv4_vid : ""; |
| 1487 | |
| 1488 | len = sprintf(buf, "%s\n", pval); |
| 1489 | break; |
| 1490 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 1491 | OP_STATE(ha->ip_config.ipv4_options, |
| 1492 | IPOPT_LEARN_IQN_EN, pval); |
| 1493 | |
| 1494 | len = sprintf(buf, "%s\n", pval); |
| 1495 | break; |
| 1496 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 1497 | OP_STATE(~ha->ip_config.ipv4_options, |
| 1498 | IPOPT_FRAGMENTATION_DISABLE, pval); |
| 1499 | |
| 1500 | len = sprintf(buf, "%s\n", pval); |
| 1501 | break; |
| 1502 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 1503 | OP_STATE(ha->ip_config.ipv4_options, |
| 1504 | IPOPT_IN_FORWARD_EN, pval); |
| 1505 | |
| 1506 | len = sprintf(buf, "%s\n", pval); |
| 1507 | break; |
| 1508 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 1509 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1510 | OP_STATE(ha->ip_config.ipv4_options, |
| 1511 | IPOPT_ARP_REDIRECT_EN, pval); |
| 1512 | } else { |
| 1513 | OP_STATE(ha->ip_config.ipv6_options, |
| 1514 | IPV6_OPT_REDIRECT_EN, pval); |
| 1515 | } |
| 1516 | len = sprintf(buf, "%s\n", pval); |
| 1517 | break; |
| 1518 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 1519 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl); |
| 1520 | break; |
| 1521 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 1522 | OP_STATE(ha->ip_config.ipv6_options, |
| 1523 | IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval); |
| 1524 | |
| 1525 | len = sprintf(buf, "%s\n", pval); |
| 1526 | break; |
| 1527 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 1528 | OP_STATE(ha->ip_config.ipv6_addl_options, |
| 1529 | IPV6_ADDOPT_MLD_EN, pval); |
| 1530 | |
| 1531 | len = sprintf(buf, "%s\n", pval); |
| 1532 | break; |
| 1533 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 1534 | len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl); |
| 1535 | break; |
| 1536 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1537 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1538 | ha->ip_config.ipv6_traffic_class); |
| 1539 | break; |
| 1540 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1541 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1542 | ha->ip_config.ipv6_hop_limit); |
| 1543 | break; |
| 1544 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1545 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1546 | ha->ip_config.ipv6_nd_reach_time); |
| 1547 | break; |
| 1548 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1549 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1550 | ha->ip_config.ipv6_nd_rexmit_timer); |
| 1551 | break; |
| 1552 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 1553 | len = sprintf(buf, "%d\n", |
| 1554 | ha->ip_config.ipv6_nd_stale_timeout); |
| 1555 | break; |
| 1556 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 1557 | len = sprintf(buf, "%d\n", |
| 1558 | ha->ip_config.ipv6_dup_addr_detect_count); |
| 1559 | break; |
| 1560 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 1561 | len = sprintf(buf, "%d\n", |
| 1562 | ha->ip_config.ipv6_gw_advrt_mtu); |
| 1563 | break; |
| 1564 | default: |
| 1565 | len = -ENOSYS; |
| 1566 | } |
| 1567 | } else if (param_type == ISCSI_IFACE_PARAM) { |
| 1568 | switch (param) { |
| 1569 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 1570 | len = sprintf(buf, "%d\n", ha->ip_config.def_timeout); |
| 1571 | break; |
| 1572 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 1573 | OP_STATE(ha->ip_config.iscsi_options, |
| 1574 | ISCSIOPTS_HEADER_DIGEST_EN, pval); |
| 1575 | |
| 1576 | len = sprintf(buf, "%s\n", pval); |
| 1577 | break; |
| 1578 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 1579 | OP_STATE(ha->ip_config.iscsi_options, |
| 1580 | ISCSIOPTS_DATA_DIGEST_EN, pval); |
| 1581 | |
| 1582 | len = sprintf(buf, "%s\n", pval); |
| 1583 | break; |
| 1584 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 1585 | OP_STATE(ha->ip_config.iscsi_options, |
| 1586 | ISCSIOPTS_IMMEDIATE_DATA_EN, pval); |
| 1587 | |
| 1588 | len = sprintf(buf, "%s\n", pval); |
| 1589 | break; |
| 1590 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 1591 | OP_STATE(ha->ip_config.iscsi_options, |
| 1592 | ISCSIOPTS_INITIAL_R2T_EN, pval); |
| 1593 | |
| 1594 | len = sprintf(buf, "%s\n", pval); |
| 1595 | break; |
| 1596 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 1597 | OP_STATE(ha->ip_config.iscsi_options, |
| 1598 | ISCSIOPTS_DATA_SEQ_INORDER_EN, pval); |
| 1599 | |
| 1600 | len = sprintf(buf, "%s\n", pval); |
| 1601 | break; |
| 1602 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 1603 | OP_STATE(ha->ip_config.iscsi_options, |
| 1604 | ISCSIOPTS_DATA_PDU_INORDER_EN, pval); |
| 1605 | |
| 1606 | len = sprintf(buf, "%s\n", pval); |
| 1607 | break; |
| 1608 | case ISCSI_IFACE_PARAM_ERL: |
| 1609 | len = sprintf(buf, "%d\n", |
| 1610 | (ha->ip_config.iscsi_options & |
| 1611 | ISCSIOPTS_ERL)); |
| 1612 | break; |
| 1613 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 1614 | len = sprintf(buf, "%u\n", |
| 1615 | ha->ip_config.iscsi_max_pdu_size * |
| 1616 | BYTE_UNITS); |
| 1617 | break; |
| 1618 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 1619 | len = sprintf(buf, "%u\n", |
| 1620 | ha->ip_config.iscsi_first_burst_len * |
| 1621 | BYTE_UNITS); |
| 1622 | break; |
| 1623 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 1624 | len = sprintf(buf, "%d\n", |
| 1625 | ha->ip_config.iscsi_max_outstnd_r2t); |
| 1626 | break; |
| 1627 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 1628 | len = sprintf(buf, "%u\n", |
| 1629 | ha->ip_config.iscsi_max_burst_len * |
| 1630 | BYTE_UNITS); |
| 1631 | break; |
| 1632 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 1633 | OP_STATE(ha->ip_config.iscsi_options, |
| 1634 | ISCSIOPTS_CHAP_AUTH_EN, pval); |
| 1635 | |
| 1636 | len = sprintf(buf, "%s\n", pval); |
| 1637 | break; |
| 1638 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 1639 | OP_STATE(ha->ip_config.iscsi_options, |
| 1640 | ISCSIOPTS_BIDI_CHAP_EN, pval); |
| 1641 | |
| 1642 | len = sprintf(buf, "%s\n", pval); |
| 1643 | break; |
| 1644 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 1645 | OP_STATE(ha->ip_config.iscsi_options, |
| 1646 | ISCSIOPTS_DISCOVERY_AUTH_EN, pval); |
| 1647 | |
| 1648 | len = sprintf(buf, "%s\n", pval); |
| 1649 | break; |
| 1650 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 1651 | OP_STATE(ha->ip_config.iscsi_options, |
| 1652 | ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval); |
| 1653 | |
| 1654 | len = sprintf(buf, "%s\n", pval); |
| 1655 | break; |
| 1656 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 1657 | OP_STATE(ha->ip_config.iscsi_options, |
| 1658 | ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval); |
| 1659 | |
| 1660 | len = sprintf(buf, "%s\n", pval); |
| 1661 | break; |
| 1662 | case ISCSI_IFACE_PARAM_INITIATOR_NAME: |
| 1663 | len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name); |
| 1664 | break; |
| 1665 | default: |
| 1666 | len = -ENOSYS; |
| 1667 | } |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | return len; |
| 1671 | } |
| 1672 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1673 | static struct iscsi_endpoint * |
| 1674 | qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, |
| 1675 | int non_blocking) |
| 1676 | { |
| 1677 | int ret; |
| 1678 | struct iscsi_endpoint *ep; |
| 1679 | struct qla_endpoint *qla_ep; |
| 1680 | struct scsi_qla_host *ha; |
| 1681 | struct sockaddr_in *addr; |
| 1682 | struct sockaddr_in6 *addr6; |
| 1683 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1684 | if (!shost) { |
| 1685 | ret = -ENXIO; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1686 | pr_err("%s: shost is NULL\n", __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1687 | return ERR_PTR(ret); |
| 1688 | } |
| 1689 | |
| 1690 | ha = iscsi_host_priv(shost); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1691 | ep = iscsi_create_endpoint(sizeof(struct qla_endpoint)); |
| 1692 | if (!ep) { |
| 1693 | ret = -ENOMEM; |
| 1694 | return ERR_PTR(ret); |
| 1695 | } |
| 1696 | |
| 1697 | qla_ep = ep->dd_data; |
| 1698 | memset(qla_ep, 0, sizeof(struct qla_endpoint)); |
| 1699 | if (dst_addr->sa_family == AF_INET) { |
| 1700 | memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in)); |
| 1701 | addr = (struct sockaddr_in *)&qla_ep->dst_addr; |
| 1702 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__, |
| 1703 | (char *)&addr->sin_addr)); |
| 1704 | } else if (dst_addr->sa_family == AF_INET6) { |
| 1705 | memcpy(&qla_ep->dst_addr, dst_addr, |
| 1706 | sizeof(struct sockaddr_in6)); |
| 1707 | addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr; |
| 1708 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__, |
| 1709 | (char *)&addr6->sin6_addr)); |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1710 | } else { |
| 1711 | ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n", |
| 1712 | __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | qla_ep->host = shost; |
| 1716 | |
| 1717 | return ep; |
| 1718 | } |
| 1719 | |
| 1720 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) |
| 1721 | { |
| 1722 | struct qla_endpoint *qla_ep; |
| 1723 | struct scsi_qla_host *ha; |
| 1724 | int ret = 0; |
| 1725 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1726 | qla_ep = ep->dd_data; |
| 1727 | ha = to_qla_host(qla_ep->host); |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1728 | DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1729 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1730 | if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags)) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1731 | ret = 1; |
| 1732 | |
| 1733 | return ret; |
| 1734 | } |
| 1735 | |
| 1736 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep) |
| 1737 | { |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1738 | struct qla_endpoint *qla_ep; |
| 1739 | struct scsi_qla_host *ha; |
| 1740 | |
| 1741 | qla_ep = ep->dd_data; |
| 1742 | ha = to_qla_host(qla_ep->host); |
| 1743 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__, |
| 1744 | ha->host_no)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1745 | iscsi_destroy_endpoint(ep); |
| 1746 | } |
| 1747 | |
| 1748 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 1749 | enum iscsi_param param, |
| 1750 | char *buf) |
| 1751 | { |
| 1752 | struct qla_endpoint *qla_ep = ep->dd_data; |
| 1753 | struct sockaddr *dst_addr; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1754 | struct scsi_qla_host *ha; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1755 | |
Adheer Chandravanshi | 73597bd | 2014-04-09 21:12:27 -0400 | [diff] [blame] | 1756 | if (!qla_ep) |
| 1757 | return -ENOTCONN; |
| 1758 | |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1759 | ha = to_qla_host(qla_ep->host); |
| 1760 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__, |
| 1761 | ha->host_no)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1762 | |
| 1763 | switch (param) { |
| 1764 | case ISCSI_PARAM_CONN_PORT: |
| 1765 | case ISCSI_PARAM_CONN_ADDRESS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1766 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 1767 | if (!dst_addr) |
| 1768 | return -ENOTCONN; |
| 1769 | |
| 1770 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 1771 | &qla_ep->dst_addr, param, buf); |
| 1772 | default: |
| 1773 | return -ENOSYS; |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 1778 | struct iscsi_stats *stats) |
| 1779 | { |
| 1780 | struct iscsi_session *sess; |
| 1781 | struct iscsi_cls_session *cls_sess; |
| 1782 | struct ddb_entry *ddb_entry; |
| 1783 | struct scsi_qla_host *ha; |
| 1784 | struct ql_iscsi_stats *ql_iscsi_stats; |
| 1785 | int stats_size; |
| 1786 | int ret; |
| 1787 | dma_addr_t iscsi_stats_dma; |
| 1788 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1789 | cls_sess = iscsi_conn_to_session(cls_conn); |
| 1790 | sess = cls_sess->dd_data; |
| 1791 | ddb_entry = sess->dd_data; |
| 1792 | ha = ddb_entry->ha; |
| 1793 | |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 1794 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__, |
| 1795 | ha->host_no)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1796 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 1797 | /* Allocate memory */ |
| 1798 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 1799 | &iscsi_stats_dma, GFP_KERNEL); |
| 1800 | if (!ql_iscsi_stats) { |
| 1801 | ql4_printk(KERN_ERR, ha, |
| 1802 | "Unable to allocate memory for iscsi stats\n"); |
| 1803 | goto exit_get_stats; |
| 1804 | } |
| 1805 | |
| 1806 | ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size, |
| 1807 | iscsi_stats_dma); |
| 1808 | if (ret != QLA_SUCCESS) { |
| 1809 | ql4_printk(KERN_ERR, ha, |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 1810 | "Unable to retrieve iscsi stats\n"); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1811 | goto free_stats; |
| 1812 | } |
| 1813 | |
| 1814 | /* octets */ |
| 1815 | stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets); |
| 1816 | stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets); |
| 1817 | /* xmit pdus */ |
| 1818 | stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus); |
| 1819 | stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus); |
| 1820 | stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus); |
| 1821 | stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus); |
| 1822 | stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus); |
| 1823 | stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus); |
| 1824 | stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus); |
| 1825 | stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus); |
| 1826 | /* recv pdus */ |
| 1827 | stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus); |
| 1828 | stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus); |
| 1829 | stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus); |
| 1830 | stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus); |
| 1831 | stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus); |
| 1832 | stats->logoutrsp_pdus = |
| 1833 | le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus); |
| 1834 | stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus); |
| 1835 | stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus); |
| 1836 | stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus); |
| 1837 | |
| 1838 | free_stats: |
| 1839 | dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats, |
| 1840 | iscsi_stats_dma); |
| 1841 | exit_get_stats: |
| 1842 | return; |
| 1843 | } |
| 1844 | |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1845 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| 1846 | { |
| 1847 | struct iscsi_cls_session *session; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1848 | struct iscsi_session *sess; |
| 1849 | unsigned long flags; |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 1850 | enum blk_eh_timer_return ret = BLK_EH_DONE; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1851 | |
| 1852 | session = starget_to_session(scsi_target(sc->device)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1853 | sess = session->dd_data; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1854 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1855 | spin_lock_irqsave(&session->lock, flags); |
| 1856 | if (session->state == ISCSI_SESSION_FAILED) |
| 1857 | ret = BLK_EH_RESET_TIMER; |
| 1858 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1859 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1860 | return ret; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1863 | static void qla4xxx_set_port_speed(struct Scsi_Host *shost) |
| 1864 | { |
| 1865 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 1866 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1867 | uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN; |
| 1868 | |
| 1869 | qla4xxx_get_firmware_state(ha); |
| 1870 | |
| 1871 | switch (ha->addl_fw_state & 0x0F00) { |
| 1872 | case FW_ADDSTATE_LINK_SPEED_10MBPS: |
| 1873 | speed = ISCSI_PORT_SPEED_10MBPS; |
| 1874 | break; |
| 1875 | case FW_ADDSTATE_LINK_SPEED_100MBPS: |
| 1876 | speed = ISCSI_PORT_SPEED_100MBPS; |
| 1877 | break; |
| 1878 | case FW_ADDSTATE_LINK_SPEED_1GBPS: |
| 1879 | speed = ISCSI_PORT_SPEED_1GBPS; |
| 1880 | break; |
| 1881 | case FW_ADDSTATE_LINK_SPEED_10GBPS: |
| 1882 | speed = ISCSI_PORT_SPEED_10GBPS; |
| 1883 | break; |
| 1884 | } |
| 1885 | ihost->port_speed = speed; |
| 1886 | } |
| 1887 | |
| 1888 | static void qla4xxx_set_port_state(struct Scsi_Host *shost) |
| 1889 | { |
| 1890 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 1891 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1892 | uint32_t state = ISCSI_PORT_STATE_DOWN; |
| 1893 | |
| 1894 | if (test_bit(AF_LINK_UP, &ha->flags)) |
| 1895 | state = ISCSI_PORT_STATE_UP; |
| 1896 | |
| 1897 | ihost->port_state = state; |
| 1898 | } |
| 1899 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1900 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 1901 | enum iscsi_host_param param, char *buf) |
| 1902 | { |
| 1903 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 1904 | int len; |
| 1905 | |
| 1906 | switch (param) { |
| 1907 | case ISCSI_HOST_PARAM_HWADDRESS: |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 1908 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1909 | break; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1910 | case ISCSI_HOST_PARAM_IPADDRESS: |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 1911 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1912 | break; |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1913 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1914 | len = sprintf(buf, "%s\n", ha->name_string); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1915 | break; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1916 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 1917 | qla4xxx_set_port_state(shost); |
| 1918 | len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost)); |
| 1919 | break; |
| 1920 | case ISCSI_HOST_PARAM_PORT_SPEED: |
| 1921 | qla4xxx_set_port_speed(shost); |
| 1922 | len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost)); |
| 1923 | break; |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1924 | default: |
| 1925 | return -ENOSYS; |
| 1926 | } |
| 1927 | |
| 1928 | return len; |
| 1929 | } |
| 1930 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1931 | static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
| 1932 | { |
| 1933 | if (ha->iface_ipv4) |
| 1934 | return; |
| 1935 | |
| 1936 | /* IPv4 */ |
| 1937 | ha->iface_ipv4 = iscsi_create_iface(ha->host, |
| 1938 | &qla4xxx_iscsi_transport, |
| 1939 | ISCSI_IFACE_TYPE_IPV4, 0, 0); |
| 1940 | if (!ha->iface_ipv4) |
| 1941 | ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " |
| 1942 | "iface0.\n"); |
| 1943 | } |
| 1944 | |
| 1945 | static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) |
| 1946 | { |
| 1947 | if (!ha->iface_ipv6_0) |
| 1948 | /* IPv6 iface-0 */ |
| 1949 | ha->iface_ipv6_0 = iscsi_create_iface(ha->host, |
| 1950 | &qla4xxx_iscsi_transport, |
| 1951 | ISCSI_IFACE_TYPE_IPV6, 0, |
| 1952 | 0); |
| 1953 | if (!ha->iface_ipv6_0) |
| 1954 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1955 | "iface0.\n"); |
| 1956 | |
| 1957 | if (!ha->iface_ipv6_1) |
| 1958 | /* IPv6 iface-1 */ |
| 1959 | ha->iface_ipv6_1 = iscsi_create_iface(ha->host, |
| 1960 | &qla4xxx_iscsi_transport, |
| 1961 | ISCSI_IFACE_TYPE_IPV6, 1, |
| 1962 | 0); |
| 1963 | if (!ha->iface_ipv6_1) |
| 1964 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1965 | "iface1.\n"); |
| 1966 | } |
| 1967 | |
| 1968 | static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) |
| 1969 | { |
| 1970 | if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) |
| 1971 | qla4xxx_create_ipv4_iface(ha); |
| 1972 | |
| 1973 | if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) |
| 1974 | qla4xxx_create_ipv6_iface(ha); |
| 1975 | } |
| 1976 | |
| 1977 | static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) |
| 1978 | { |
| 1979 | if (ha->iface_ipv4) { |
| 1980 | iscsi_destroy_iface(ha->iface_ipv4); |
| 1981 | ha->iface_ipv4 = NULL; |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) |
| 1986 | { |
| 1987 | if (ha->iface_ipv6_0) { |
| 1988 | iscsi_destroy_iface(ha->iface_ipv6_0); |
| 1989 | ha->iface_ipv6_0 = NULL; |
| 1990 | } |
| 1991 | if (ha->iface_ipv6_1) { |
| 1992 | iscsi_destroy_iface(ha->iface_ipv6_1); |
| 1993 | ha->iface_ipv6_1 = NULL; |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) |
| 1998 | { |
| 1999 | qla4xxx_destroy_ipv4_iface(ha); |
| 2000 | qla4xxx_destroy_ipv6_iface(ha); |
| 2001 | } |
| 2002 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2003 | static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
| 2004 | struct iscsi_iface_param_info *iface_param, |
| 2005 | struct addr_ctrl_blk *init_fw_cb) |
| 2006 | { |
| 2007 | /* |
| 2008 | * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. |
| 2009 | * iface_num 1 is valid only for IPv6 Addr. |
| 2010 | */ |
| 2011 | switch (iface_param->param) { |
| 2012 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 2013 | if (iface_param->iface_num & 0x1) |
| 2014 | /* IPv6 Addr 1 */ |
| 2015 | memcpy(init_fw_cb->ipv6_addr1, iface_param->value, |
| 2016 | sizeof(init_fw_cb->ipv6_addr1)); |
| 2017 | else |
| 2018 | /* IPv6 Addr 0 */ |
| 2019 | memcpy(init_fw_cb->ipv6_addr0, iface_param->value, |
| 2020 | sizeof(init_fw_cb->ipv6_addr0)); |
| 2021 | break; |
| 2022 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 2023 | if (iface_param->iface_num & 0x1) |
| 2024 | break; |
| 2025 | memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], |
| 2026 | sizeof(init_fw_cb->ipv6_if_id)); |
| 2027 | break; |
| 2028 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 2029 | if (iface_param->iface_num & 0x1) |
| 2030 | break; |
| 2031 | memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, |
| 2032 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 2033 | break; |
| 2034 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 2035 | /* Autocfg applies to even interface */ |
| 2036 | if (iface_param->iface_num & 0x1) |
| 2037 | break; |
| 2038 | |
| 2039 | if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) |
| 2040 | init_fw_cb->ipv6_addtl_opts &= |
| 2041 | cpu_to_le16( |
| 2042 | ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 2043 | else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) |
| 2044 | init_fw_cb->ipv6_addtl_opts |= |
| 2045 | cpu_to_le16( |
| 2046 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 2047 | else |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2048 | ql4_printk(KERN_ERR, ha, |
| 2049 | "Invalid autocfg setting for IPv6 addr\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2050 | break; |
| 2051 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 2052 | /* Autocfg applies to even interface */ |
| 2053 | if (iface_param->iface_num & 0x1) |
| 2054 | break; |
| 2055 | |
| 2056 | if (iface_param->value[0] == |
| 2057 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) |
| 2058 | init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( |
| 2059 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 2060 | else if (iface_param->value[0] == |
| 2061 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) |
| 2062 | init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( |
| 2063 | ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 2064 | else |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2065 | ql4_printk(KERN_ERR, ha, |
| 2066 | "Invalid autocfg setting for IPv6 linklocal addr\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2067 | break; |
| 2068 | case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: |
| 2069 | /* Autocfg applies to even interface */ |
| 2070 | if (iface_param->iface_num & 0x1) |
| 2071 | break; |
| 2072 | |
| 2073 | if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) |
| 2074 | memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, |
| 2075 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 2076 | break; |
| 2077 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2078 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2079 | init_fw_cb->ipv6_opts |= |
| 2080 | cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2081 | qla4xxx_create_ipv6_iface(ha); |
| 2082 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2083 | init_fw_cb->ipv6_opts &= |
| 2084 | cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & |
| 2085 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2086 | qla4xxx_destroy_ipv6_iface(ha); |
| 2087 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2088 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 2089 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2090 | if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) |
| 2091 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 2092 | init_fw_cb->ipv6_vlan_tag = |
| 2093 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 2094 | break; |
| 2095 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 2096 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 2097 | init_fw_cb->ipv6_opts |= |
| 2098 | cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE); |
| 2099 | else |
| 2100 | init_fw_cb->ipv6_opts &= |
| 2101 | cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2102 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 2103 | case ISCSI_NET_PARAM_MTU: |
| 2104 | init_fw_cb->eth_mtu_size = |
| 2105 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2106 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 2107 | case ISCSI_NET_PARAM_PORT: |
| 2108 | /* Autocfg applies to even interface */ |
| 2109 | if (iface_param->iface_num & 0x1) |
| 2110 | break; |
| 2111 | |
| 2112 | init_fw_cb->ipv6_port = |
| 2113 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2114 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2115 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 2116 | if (iface_param->iface_num & 0x1) |
| 2117 | break; |
| 2118 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2119 | init_fw_cb->ipv6_tcp_opts |= |
| 2120 | cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE); |
| 2121 | else |
| 2122 | init_fw_cb->ipv6_tcp_opts &= |
Vikas Chaudhary | 8f10872 | 2013-12-16 06:49:53 -0500 | [diff] [blame] | 2123 | cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE & |
| 2124 | 0xFFFF); |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2125 | break; |
| 2126 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 2127 | if (iface_param->iface_num & 0x1) |
| 2128 | break; |
| 2129 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2130 | init_fw_cb->ipv6_tcp_opts |= |
| 2131 | cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE); |
| 2132 | else |
| 2133 | init_fw_cb->ipv6_tcp_opts &= |
| 2134 | cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE); |
| 2135 | break; |
| 2136 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 2137 | if (iface_param->iface_num & 0x1) |
| 2138 | break; |
| 2139 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2140 | init_fw_cb->ipv6_tcp_opts |= |
| 2141 | cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE); |
| 2142 | else |
| 2143 | init_fw_cb->ipv6_tcp_opts &= |
| 2144 | cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE); |
| 2145 | break; |
| 2146 | case ISCSI_NET_PARAM_TCP_WSF: |
| 2147 | if (iface_param->iface_num & 0x1) |
| 2148 | break; |
| 2149 | init_fw_cb->ipv6_tcp_wsf = iface_param->value[0]; |
| 2150 | break; |
| 2151 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 2152 | if (iface_param->iface_num & 0x1) |
| 2153 | break; |
| 2154 | init_fw_cb->ipv6_tcp_opts &= |
| 2155 | cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE); |
| 2156 | init_fw_cb->ipv6_tcp_opts |= |
| 2157 | cpu_to_le16((iface_param->value[0] << 1) & |
| 2158 | IPV6_TCPOPT_TIMER_SCALE); |
| 2159 | break; |
| 2160 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 2161 | if (iface_param->iface_num & 0x1) |
| 2162 | break; |
| 2163 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2164 | init_fw_cb->ipv6_tcp_opts |= |
| 2165 | cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN); |
| 2166 | else |
| 2167 | init_fw_cb->ipv6_tcp_opts &= |
| 2168 | cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN); |
| 2169 | break; |
| 2170 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 2171 | if (iface_param->iface_num & 0x1) |
| 2172 | break; |
| 2173 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2174 | init_fw_cb->ipv6_opts |= |
| 2175 | cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN); |
| 2176 | else |
| 2177 | init_fw_cb->ipv6_opts &= |
| 2178 | cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN); |
| 2179 | break; |
| 2180 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 2181 | if (iface_param->iface_num & 0x1) |
| 2182 | break; |
| 2183 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2184 | init_fw_cb->ipv6_opts |= |
| 2185 | cpu_to_le16(IPV6_OPT_REDIRECT_EN); |
| 2186 | else |
| 2187 | init_fw_cb->ipv6_opts &= |
| 2188 | cpu_to_le16(~IPV6_OPT_REDIRECT_EN); |
| 2189 | break; |
| 2190 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 2191 | if (iface_param->iface_num & 0x1) |
| 2192 | break; |
| 2193 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2194 | init_fw_cb->ipv6_addtl_opts |= |
| 2195 | cpu_to_le16(IPV6_ADDOPT_MLD_EN); |
| 2196 | else |
| 2197 | init_fw_cb->ipv6_addtl_opts &= |
| 2198 | cpu_to_le16(~IPV6_ADDOPT_MLD_EN); |
| 2199 | break; |
| 2200 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 2201 | if (iface_param->iface_num & 0x1) |
| 2202 | break; |
| 2203 | init_fw_cb->ipv6_flow_lbl = |
| 2204 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2205 | break; |
| 2206 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
| 2207 | if (iface_param->iface_num & 0x1) |
| 2208 | break; |
| 2209 | init_fw_cb->ipv6_traffic_class = iface_param->value[0]; |
| 2210 | break; |
| 2211 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
| 2212 | if (iface_param->iface_num & 0x1) |
| 2213 | break; |
| 2214 | init_fw_cb->ipv6_hop_limit = iface_param->value[0]; |
| 2215 | break; |
| 2216 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
| 2217 | if (iface_param->iface_num & 0x1) |
| 2218 | break; |
| 2219 | init_fw_cb->ipv6_nd_reach_time = |
| 2220 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2221 | break; |
| 2222 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
| 2223 | if (iface_param->iface_num & 0x1) |
| 2224 | break; |
| 2225 | init_fw_cb->ipv6_nd_rexmit_timer = |
| 2226 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2227 | break; |
| 2228 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 2229 | if (iface_param->iface_num & 0x1) |
| 2230 | break; |
| 2231 | init_fw_cb->ipv6_nd_stale_timeout = |
| 2232 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2233 | break; |
| 2234 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 2235 | if (iface_param->iface_num & 0x1) |
| 2236 | break; |
| 2237 | init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0]; |
| 2238 | break; |
| 2239 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 2240 | if (iface_param->iface_num & 0x1) |
| 2241 | break; |
| 2242 | init_fw_cb->ipv6_gw_advrt_mtu = |
| 2243 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2244 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2245 | default: |
| 2246 | ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", |
| 2247 | iface_param->param); |
| 2248 | break; |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, |
| 2253 | struct iscsi_iface_param_info *iface_param, |
| 2254 | struct addr_ctrl_blk *init_fw_cb) |
| 2255 | { |
| 2256 | switch (iface_param->param) { |
| 2257 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 2258 | memcpy(init_fw_cb->ipv4_addr, iface_param->value, |
| 2259 | sizeof(init_fw_cb->ipv4_addr)); |
| 2260 | break; |
| 2261 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 2262 | memcpy(init_fw_cb->ipv4_subnet, iface_param->value, |
| 2263 | sizeof(init_fw_cb->ipv4_subnet)); |
| 2264 | break; |
| 2265 | case ISCSI_NET_PARAM_IPV4_GW: |
| 2266 | memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, |
| 2267 | sizeof(init_fw_cb->ipv4_gw_addr)); |
| 2268 | break; |
| 2269 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 2270 | if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) |
| 2271 | init_fw_cb->ipv4_tcp_opts |= |
| 2272 | cpu_to_le16(TCPOPT_DHCP_ENABLE); |
| 2273 | else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) |
| 2274 | init_fw_cb->ipv4_tcp_opts &= |
| 2275 | cpu_to_le16(~TCPOPT_DHCP_ENABLE); |
| 2276 | else |
| 2277 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); |
| 2278 | break; |
| 2279 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2280 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2281 | init_fw_cb->ipv4_ip_opts |= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 2282 | cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2283 | qla4xxx_create_ipv4_iface(ha); |
| 2284 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2285 | init_fw_cb->ipv4_ip_opts &= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 2286 | cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2287 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2288 | qla4xxx_destroy_ipv4_iface(ha); |
| 2289 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2290 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 2291 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2292 | if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) |
| 2293 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 2294 | init_fw_cb->ipv4_vlan_tag = |
| 2295 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 2296 | break; |
| 2297 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 2298 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 2299 | init_fw_cb->ipv4_ip_opts |= |
| 2300 | cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE); |
| 2301 | else |
| 2302 | init_fw_cb->ipv4_ip_opts &= |
| 2303 | cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2304 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 2305 | case ISCSI_NET_PARAM_MTU: |
| 2306 | init_fw_cb->eth_mtu_size = |
| 2307 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2308 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 2309 | case ISCSI_NET_PARAM_PORT: |
| 2310 | init_fw_cb->ipv4_port = |
| 2311 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2312 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2313 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 2314 | if (iface_param->iface_num & 0x1) |
| 2315 | break; |
| 2316 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2317 | init_fw_cb->ipv4_tcp_opts |= |
| 2318 | cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE); |
| 2319 | else |
| 2320 | init_fw_cb->ipv4_tcp_opts &= |
Vikas Chaudhary | 8f10872 | 2013-12-16 06:49:53 -0500 | [diff] [blame] | 2321 | cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE & |
| 2322 | 0xFFFF); |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2323 | break; |
| 2324 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 2325 | if (iface_param->iface_num & 0x1) |
| 2326 | break; |
| 2327 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2328 | init_fw_cb->ipv4_tcp_opts |= |
| 2329 | cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE); |
| 2330 | else |
| 2331 | init_fw_cb->ipv4_tcp_opts &= |
| 2332 | cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE); |
| 2333 | break; |
| 2334 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 2335 | if (iface_param->iface_num & 0x1) |
| 2336 | break; |
| 2337 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2338 | init_fw_cb->ipv4_tcp_opts |= |
| 2339 | cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE); |
| 2340 | else |
| 2341 | init_fw_cb->ipv4_tcp_opts &= |
| 2342 | cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE); |
| 2343 | break; |
| 2344 | case ISCSI_NET_PARAM_TCP_WSF: |
| 2345 | if (iface_param->iface_num & 0x1) |
| 2346 | break; |
| 2347 | init_fw_cb->ipv4_tcp_wsf = iface_param->value[0]; |
| 2348 | break; |
| 2349 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 2350 | if (iface_param->iface_num & 0x1) |
| 2351 | break; |
| 2352 | init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE); |
| 2353 | init_fw_cb->ipv4_tcp_opts |= |
| 2354 | cpu_to_le16((iface_param->value[0] << 1) & |
| 2355 | TCPOPT_TIMER_SCALE); |
| 2356 | break; |
| 2357 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 2358 | if (iface_param->iface_num & 0x1) |
| 2359 | break; |
| 2360 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2361 | init_fw_cb->ipv4_tcp_opts |= |
| 2362 | cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE); |
| 2363 | else |
| 2364 | init_fw_cb->ipv4_tcp_opts &= |
| 2365 | cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE); |
| 2366 | break; |
| 2367 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 2368 | if (iface_param->iface_num & 0x1) |
| 2369 | break; |
| 2370 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2371 | init_fw_cb->ipv4_tcp_opts |= |
| 2372 | cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN); |
| 2373 | else |
| 2374 | init_fw_cb->ipv4_tcp_opts &= |
| 2375 | cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN); |
| 2376 | break; |
| 2377 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 2378 | if (iface_param->iface_num & 0x1) |
| 2379 | break; |
| 2380 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2381 | init_fw_cb->ipv4_tcp_opts |= |
| 2382 | cpu_to_le16(TCPOPT_SLP_DA_INFO_EN); |
| 2383 | else |
| 2384 | init_fw_cb->ipv4_tcp_opts &= |
| 2385 | cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN); |
| 2386 | break; |
| 2387 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 2388 | if (iface_param->iface_num & 0x1) |
| 2389 | break; |
| 2390 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2391 | init_fw_cb->ipv4_ip_opts |= |
| 2392 | cpu_to_le16(IPOPT_IPV4_TOS_EN); |
| 2393 | else |
| 2394 | init_fw_cb->ipv4_ip_opts &= |
| 2395 | cpu_to_le16(~IPOPT_IPV4_TOS_EN); |
| 2396 | break; |
| 2397 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 2398 | if (iface_param->iface_num & 0x1) |
| 2399 | break; |
| 2400 | init_fw_cb->ipv4_tos = iface_param->value[0]; |
| 2401 | break; |
| 2402 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 2403 | if (iface_param->iface_num & 0x1) |
| 2404 | break; |
| 2405 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2406 | init_fw_cb->ipv4_ip_opts |= |
| 2407 | cpu_to_le16(IPOPT_GRAT_ARP_EN); |
| 2408 | else |
| 2409 | init_fw_cb->ipv4_ip_opts &= |
| 2410 | cpu_to_le16(~IPOPT_GRAT_ARP_EN); |
| 2411 | break; |
| 2412 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 2413 | if (iface_param->iface_num & 0x1) |
| 2414 | break; |
| 2415 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2416 | init_fw_cb->ipv4_ip_opts |= |
| 2417 | cpu_to_le16(IPOPT_ALT_CID_EN); |
| 2418 | else |
| 2419 | init_fw_cb->ipv4_ip_opts &= |
| 2420 | cpu_to_le16(~IPOPT_ALT_CID_EN); |
| 2421 | break; |
| 2422 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 2423 | if (iface_param->iface_num & 0x1) |
| 2424 | break; |
| 2425 | memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value, |
| 2426 | (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1)); |
| 2427 | init_fw_cb->ipv4_dhcp_alt_cid_len = |
| 2428 | strlen(init_fw_cb->ipv4_dhcp_alt_cid); |
| 2429 | break; |
| 2430 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 2431 | if (iface_param->iface_num & 0x1) |
| 2432 | break; |
| 2433 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2434 | init_fw_cb->ipv4_ip_opts |= |
| 2435 | cpu_to_le16(IPOPT_REQ_VID_EN); |
| 2436 | else |
| 2437 | init_fw_cb->ipv4_ip_opts &= |
| 2438 | cpu_to_le16(~IPOPT_REQ_VID_EN); |
| 2439 | break; |
| 2440 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 2441 | if (iface_param->iface_num & 0x1) |
| 2442 | break; |
| 2443 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2444 | init_fw_cb->ipv4_ip_opts |= |
| 2445 | cpu_to_le16(IPOPT_USE_VID_EN); |
| 2446 | else |
| 2447 | init_fw_cb->ipv4_ip_opts &= |
| 2448 | cpu_to_le16(~IPOPT_USE_VID_EN); |
| 2449 | break; |
| 2450 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 2451 | if (iface_param->iface_num & 0x1) |
| 2452 | break; |
| 2453 | memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value, |
| 2454 | (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1)); |
| 2455 | init_fw_cb->ipv4_dhcp_vid_len = |
| 2456 | strlen(init_fw_cb->ipv4_dhcp_vid); |
| 2457 | break; |
| 2458 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 2459 | if (iface_param->iface_num & 0x1) |
| 2460 | break; |
| 2461 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2462 | init_fw_cb->ipv4_ip_opts |= |
| 2463 | cpu_to_le16(IPOPT_LEARN_IQN_EN); |
| 2464 | else |
| 2465 | init_fw_cb->ipv4_ip_opts &= |
| 2466 | cpu_to_le16(~IPOPT_LEARN_IQN_EN); |
| 2467 | break; |
| 2468 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 2469 | if (iface_param->iface_num & 0x1) |
| 2470 | break; |
| 2471 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2472 | init_fw_cb->ipv4_ip_opts |= |
| 2473 | cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE); |
| 2474 | else |
| 2475 | init_fw_cb->ipv4_ip_opts &= |
| 2476 | cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE); |
| 2477 | break; |
| 2478 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 2479 | if (iface_param->iface_num & 0x1) |
| 2480 | break; |
| 2481 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2482 | init_fw_cb->ipv4_ip_opts |= |
| 2483 | cpu_to_le16(IPOPT_IN_FORWARD_EN); |
| 2484 | else |
| 2485 | init_fw_cb->ipv4_ip_opts &= |
| 2486 | cpu_to_le16(~IPOPT_IN_FORWARD_EN); |
| 2487 | break; |
| 2488 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 2489 | if (iface_param->iface_num & 0x1) |
| 2490 | break; |
| 2491 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2492 | init_fw_cb->ipv4_ip_opts |= |
| 2493 | cpu_to_le16(IPOPT_ARP_REDIRECT_EN); |
| 2494 | else |
| 2495 | init_fw_cb->ipv4_ip_opts &= |
| 2496 | cpu_to_le16(~IPOPT_ARP_REDIRECT_EN); |
| 2497 | break; |
| 2498 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 2499 | if (iface_param->iface_num & 0x1) |
| 2500 | break; |
| 2501 | init_fw_cb->ipv4_ttl = iface_param->value[0]; |
| 2502 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2503 | default: |
| 2504 | ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", |
| 2505 | iface_param->param); |
| 2506 | break; |
| 2507 | } |
| 2508 | } |
| 2509 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2510 | static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha, |
| 2511 | struct iscsi_iface_param_info *iface_param, |
| 2512 | struct addr_ctrl_blk *init_fw_cb) |
| 2513 | { |
| 2514 | switch (iface_param->param) { |
| 2515 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 2516 | if (iface_param->iface_num & 0x1) |
| 2517 | break; |
| 2518 | init_fw_cb->def_timeout = |
| 2519 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2520 | break; |
| 2521 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 2522 | if (iface_param->iface_num & 0x1) |
| 2523 | break; |
| 2524 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2525 | init_fw_cb->iscsi_opts |= |
| 2526 | cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN); |
| 2527 | else |
| 2528 | init_fw_cb->iscsi_opts &= |
| 2529 | cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN); |
| 2530 | break; |
| 2531 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 2532 | if (iface_param->iface_num & 0x1) |
| 2533 | break; |
| 2534 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2535 | init_fw_cb->iscsi_opts |= |
| 2536 | cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN); |
| 2537 | else |
| 2538 | init_fw_cb->iscsi_opts &= |
| 2539 | cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN); |
| 2540 | break; |
| 2541 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 2542 | if (iface_param->iface_num & 0x1) |
| 2543 | break; |
| 2544 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2545 | init_fw_cb->iscsi_opts |= |
| 2546 | cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN); |
| 2547 | else |
| 2548 | init_fw_cb->iscsi_opts &= |
| 2549 | cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN); |
| 2550 | break; |
| 2551 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 2552 | if (iface_param->iface_num & 0x1) |
| 2553 | break; |
| 2554 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2555 | init_fw_cb->iscsi_opts |= |
| 2556 | cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN); |
| 2557 | else |
| 2558 | init_fw_cb->iscsi_opts &= |
| 2559 | cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN); |
| 2560 | break; |
| 2561 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 2562 | if (iface_param->iface_num & 0x1) |
| 2563 | break; |
| 2564 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2565 | init_fw_cb->iscsi_opts |= |
| 2566 | cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN); |
| 2567 | else |
| 2568 | init_fw_cb->iscsi_opts &= |
| 2569 | cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN); |
| 2570 | break; |
| 2571 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 2572 | if (iface_param->iface_num & 0x1) |
| 2573 | break; |
| 2574 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2575 | init_fw_cb->iscsi_opts |= |
| 2576 | cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN); |
| 2577 | else |
| 2578 | init_fw_cb->iscsi_opts &= |
| 2579 | cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN); |
| 2580 | break; |
| 2581 | case ISCSI_IFACE_PARAM_ERL: |
| 2582 | if (iface_param->iface_num & 0x1) |
| 2583 | break; |
| 2584 | init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL); |
| 2585 | init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] & |
| 2586 | ISCSIOPTS_ERL); |
| 2587 | break; |
| 2588 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 2589 | if (iface_param->iface_num & 0x1) |
| 2590 | break; |
| 2591 | init_fw_cb->iscsi_max_pdu_size = |
| 2592 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2593 | BYTE_UNITS; |
| 2594 | break; |
| 2595 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 2596 | if (iface_param->iface_num & 0x1) |
| 2597 | break; |
| 2598 | init_fw_cb->iscsi_fburst_len = |
| 2599 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2600 | BYTE_UNITS; |
| 2601 | break; |
| 2602 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 2603 | if (iface_param->iface_num & 0x1) |
| 2604 | break; |
| 2605 | init_fw_cb->iscsi_max_outstnd_r2t = |
| 2606 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2607 | break; |
| 2608 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 2609 | if (iface_param->iface_num & 0x1) |
| 2610 | break; |
| 2611 | init_fw_cb->iscsi_max_burst_len = |
| 2612 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2613 | BYTE_UNITS; |
| 2614 | break; |
| 2615 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 2616 | if (iface_param->iface_num & 0x1) |
| 2617 | break; |
| 2618 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2619 | init_fw_cb->iscsi_opts |= |
| 2620 | cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN); |
| 2621 | else |
| 2622 | init_fw_cb->iscsi_opts &= |
| 2623 | cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN); |
| 2624 | break; |
| 2625 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 2626 | if (iface_param->iface_num & 0x1) |
| 2627 | break; |
| 2628 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2629 | init_fw_cb->iscsi_opts |= |
| 2630 | cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN); |
| 2631 | else |
| 2632 | init_fw_cb->iscsi_opts &= |
| 2633 | cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN); |
| 2634 | break; |
| 2635 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 2636 | if (iface_param->iface_num & 0x1) |
| 2637 | break; |
| 2638 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2639 | init_fw_cb->iscsi_opts |= |
| 2640 | cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN); |
| 2641 | else |
| 2642 | init_fw_cb->iscsi_opts &= |
| 2643 | cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN); |
| 2644 | break; |
| 2645 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 2646 | if (iface_param->iface_num & 0x1) |
| 2647 | break; |
| 2648 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2649 | init_fw_cb->iscsi_opts |= |
| 2650 | cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN); |
| 2651 | else |
| 2652 | init_fw_cb->iscsi_opts &= |
| 2653 | cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN); |
| 2654 | break; |
| 2655 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 2656 | if (iface_param->iface_num & 0x1) |
| 2657 | break; |
| 2658 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2659 | init_fw_cb->iscsi_opts |= |
| 2660 | cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN); |
| 2661 | else |
| 2662 | init_fw_cb->iscsi_opts &= |
| 2663 | cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN); |
| 2664 | break; |
| 2665 | default: |
| 2666 | ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n", |
| 2667 | iface_param->param); |
| 2668 | break; |
| 2669 | } |
| 2670 | } |
| 2671 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2672 | static void |
| 2673 | qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) |
| 2674 | { |
| 2675 | struct addr_ctrl_blk_def *acb; |
| 2676 | acb = (struct addr_ctrl_blk_def *)init_fw_cb; |
| 2677 | memset(acb->reserved1, 0, sizeof(acb->reserved1)); |
| 2678 | memset(acb->reserved2, 0, sizeof(acb->reserved2)); |
| 2679 | memset(acb->reserved3, 0, sizeof(acb->reserved3)); |
| 2680 | memset(acb->reserved4, 0, sizeof(acb->reserved4)); |
| 2681 | memset(acb->reserved5, 0, sizeof(acb->reserved5)); |
| 2682 | memset(acb->reserved6, 0, sizeof(acb->reserved6)); |
| 2683 | memset(acb->reserved7, 0, sizeof(acb->reserved7)); |
| 2684 | memset(acb->reserved8, 0, sizeof(acb->reserved8)); |
| 2685 | memset(acb->reserved9, 0, sizeof(acb->reserved9)); |
| 2686 | memset(acb->reserved10, 0, sizeof(acb->reserved10)); |
| 2687 | memset(acb->reserved11, 0, sizeof(acb->reserved11)); |
| 2688 | memset(acb->reserved12, 0, sizeof(acb->reserved12)); |
| 2689 | memset(acb->reserved13, 0, sizeof(acb->reserved13)); |
| 2690 | memset(acb->reserved14, 0, sizeof(acb->reserved14)); |
| 2691 | memset(acb->reserved15, 0, sizeof(acb->reserved15)); |
| 2692 | } |
| 2693 | |
| 2694 | static int |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2695 | 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] | 2696 | { |
| 2697 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 2698 | int rval = 0; |
| 2699 | struct iscsi_iface_param_info *iface_param = NULL; |
| 2700 | struct addr_ctrl_blk *init_fw_cb = NULL; |
| 2701 | dma_addr_t init_fw_cb_dma; |
| 2702 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2703 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2704 | uint32_t rem = len; |
| 2705 | struct nlattr *attr; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2706 | |
Himanshu Jha | d103adb | 2017-12-30 20:58:24 +0530 | [diff] [blame] | 2707 | init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev, |
| 2708 | sizeof(struct addr_ctrl_blk), |
| 2709 | &init_fw_cb_dma, GFP_KERNEL); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2710 | if (!init_fw_cb) { |
| 2711 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", |
| 2712 | __func__); |
| 2713 | return -ENOMEM; |
| 2714 | } |
| 2715 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2716 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2717 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2718 | |
| 2719 | if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { |
| 2720 | ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); |
| 2721 | rval = -EIO; |
| 2722 | goto exit_init_fw_cb; |
| 2723 | } |
| 2724 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2725 | nla_for_each_attr(attr, data, len, rem) { |
| 2726 | iface_param = nla_data(attr); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2727 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2728 | if (iface_param->param_type == ISCSI_NET_PARAM) { |
| 2729 | switch (iface_param->iface_type) { |
| 2730 | case ISCSI_IFACE_TYPE_IPV4: |
| 2731 | switch (iface_param->iface_num) { |
| 2732 | case 0: |
| 2733 | qla4xxx_set_ipv4(ha, iface_param, |
| 2734 | init_fw_cb); |
| 2735 | break; |
| 2736 | default: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2737 | /* Cannot have more than one IPv4 interface */ |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2738 | ql4_printk(KERN_ERR, ha, |
| 2739 | "Invalid IPv4 iface number = %d\n", |
| 2740 | iface_param->iface_num); |
| 2741 | break; |
| 2742 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2743 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2744 | case ISCSI_IFACE_TYPE_IPV6: |
| 2745 | switch (iface_param->iface_num) { |
| 2746 | case 0: |
| 2747 | case 1: |
| 2748 | qla4xxx_set_ipv6(ha, iface_param, |
| 2749 | init_fw_cb); |
| 2750 | break; |
| 2751 | default: |
| 2752 | /* Cannot have more than two IPv6 interface */ |
| 2753 | ql4_printk(KERN_ERR, ha, |
| 2754 | "Invalid IPv6 iface number = %d\n", |
| 2755 | iface_param->iface_num); |
| 2756 | break; |
| 2757 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2758 | break; |
| 2759 | default: |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2760 | ql4_printk(KERN_ERR, ha, |
| 2761 | "Invalid iface type\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2762 | break; |
| 2763 | } |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2764 | } else if (iface_param->param_type == ISCSI_IFACE_PARAM) { |
| 2765 | qla4xxx_set_iscsi_param(ha, iface_param, |
| 2766 | init_fw_cb); |
| 2767 | } else { |
| 2768 | continue; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2769 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); |
| 2773 | |
| 2774 | rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, |
| 2775 | sizeof(struct addr_ctrl_blk), |
| 2776 | FLASH_OPT_RMW_COMMIT); |
| 2777 | if (rval != QLA_SUCCESS) { |
| 2778 | ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", |
| 2779 | __func__); |
| 2780 | rval = -EIO; |
| 2781 | goto exit_init_fw_cb; |
| 2782 | } |
| 2783 | |
Vikas Chaudhary | ce505f9 | 2011-12-01 22:42:10 -0800 | [diff] [blame] | 2784 | rval = qla4xxx_disable_acb(ha); |
| 2785 | if (rval != QLA_SUCCESS) { |
| 2786 | ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n", |
| 2787 | __func__); |
| 2788 | rval = -EIO; |
| 2789 | goto exit_init_fw_cb; |
| 2790 | } |
| 2791 | |
| 2792 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 2793 | DISABLE_ACB_TOV * HZ); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2794 | |
| 2795 | qla4xxx_initcb_to_acb(init_fw_cb); |
| 2796 | |
| 2797 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); |
| 2798 | if (rval != QLA_SUCCESS) { |
| 2799 | ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", |
| 2800 | __func__); |
| 2801 | rval = -EIO; |
| 2802 | goto exit_init_fw_cb; |
| 2803 | } |
| 2804 | |
| 2805 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 2806 | qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, |
| 2807 | init_fw_cb_dma); |
| 2808 | |
| 2809 | exit_init_fw_cb: |
| 2810 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), |
| 2811 | init_fw_cb, init_fw_cb_dma); |
| 2812 | |
| 2813 | return rval; |
| 2814 | } |
| 2815 | |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2816 | static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess, |
| 2817 | enum iscsi_param param, char *buf) |
| 2818 | { |
| 2819 | struct iscsi_session *sess = cls_sess->dd_data; |
| 2820 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 2821 | struct scsi_qla_host *ha = ddb_entry->ha; |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2822 | struct iscsi_cls_conn *cls_conn = ddb_entry->conn; |
| 2823 | struct ql4_chap_table chap_tbl; |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2824 | int rval, len; |
| 2825 | uint16_t idx; |
| 2826 | |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2827 | memset(&chap_tbl, 0, sizeof(chap_tbl)); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2828 | switch (param) { |
| 2829 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 2830 | rval = qla4xxx_get_chap_index(ha, sess->username_in, |
| 2831 | sess->password_in, BIDI_CHAP, |
| 2832 | &idx); |
| 2833 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 2834 | len = sprintf(buf, "\n"); |
| 2835 | else |
| 2836 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2837 | break; |
| 2838 | case ISCSI_PARAM_CHAP_OUT_IDX: |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2839 | if (ddb_entry->ddb_type == FLASH_DDB) { |
| 2840 | if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) { |
| 2841 | idx = ddb_entry->chap_tbl_idx; |
| 2842 | rval = QLA_SUCCESS; |
| 2843 | } else { |
| 2844 | rval = QLA_ERROR; |
| 2845 | } |
| 2846 | } else { |
| 2847 | rval = qla4xxx_get_chap_index(ha, sess->username, |
| 2848 | sess->password, |
| 2849 | LOCAL_CHAP, &idx); |
| 2850 | } |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2851 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 2852 | len = sprintf(buf, "\n"); |
| 2853 | else |
| 2854 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2855 | break; |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2856 | case ISCSI_PARAM_USERNAME: |
| 2857 | case ISCSI_PARAM_PASSWORD: |
| 2858 | /* First, populate session username and password for FLASH DDB, |
| 2859 | * if not already done. This happens when session login fails |
| 2860 | * for a FLASH DDB. |
| 2861 | */ |
| 2862 | if (ddb_entry->ddb_type == FLASH_DDB && |
| 2863 | ddb_entry->chap_tbl_idx != INVALID_ENTRY && |
| 2864 | !sess->username && !sess->password) { |
| 2865 | idx = ddb_entry->chap_tbl_idx; |
| 2866 | rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name, |
| 2867 | chap_tbl.secret, |
| 2868 | idx); |
| 2869 | if (!rval) { |
| 2870 | iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME, |
| 2871 | (char *)chap_tbl.name, |
| 2872 | strlen((char *)chap_tbl.name)); |
| 2873 | iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD, |
| 2874 | (char *)chap_tbl.secret, |
| 2875 | chap_tbl.secret_len); |
| 2876 | } |
| 2877 | } |
| 2878 | /* allow fall-through */ |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2879 | default: |
| 2880 | return iscsi_session_get_param(cls_sess, param, buf); |
| 2881 | } |
| 2882 | |
| 2883 | return len; |
| 2884 | } |
| 2885 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2886 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2887 | enum iscsi_param param, char *buf) |
| 2888 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2889 | struct iscsi_conn *conn; |
| 2890 | struct qla_conn *qla_conn; |
| 2891 | struct sockaddr *dst_addr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2892 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2893 | conn = cls_conn->dd_data; |
| 2894 | qla_conn = conn->dd_data; |
Manish Rangankar | d46bdeb1 | 2012-08-07 07:57:13 -0400 | [diff] [blame] | 2895 | dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2896 | |
| 2897 | switch (param) { |
| 2898 | case ISCSI_PARAM_CONN_PORT: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2899 | case ISCSI_PARAM_CONN_ADDRESS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2900 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 2901 | dst_addr, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2902 | default: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2903 | return iscsi_conn_get_param(cls_conn, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2904 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2907 | int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index) |
| 2908 | { |
| 2909 | uint32_t mbx_sts = 0; |
| 2910 | uint16_t tmp_ddb_index; |
| 2911 | int ret; |
| 2912 | |
| 2913 | get_ddb_index: |
| 2914 | tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES); |
| 2915 | |
| 2916 | if (tmp_ddb_index >= MAX_DDB_ENTRIES) { |
| 2917 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2918 | "Free DDB index not available\n")); |
| 2919 | ret = QLA_ERROR; |
| 2920 | goto exit_get_ddb_index; |
| 2921 | } |
| 2922 | |
| 2923 | if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map)) |
| 2924 | goto get_ddb_index; |
| 2925 | |
| 2926 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2927 | "Found a free DDB index at %d\n", tmp_ddb_index)); |
| 2928 | ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts); |
| 2929 | if (ret == QLA_ERROR) { |
| 2930 | if (mbx_sts == MBOX_STS_COMMAND_ERROR) { |
| 2931 | ql4_printk(KERN_INFO, ha, |
| 2932 | "DDB index = %d not available trying next\n", |
| 2933 | tmp_ddb_index); |
| 2934 | goto get_ddb_index; |
| 2935 | } |
| 2936 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2937 | "Free FW DDB not available\n")); |
| 2938 | } |
| 2939 | |
| 2940 | *ddb_index = tmp_ddb_index; |
| 2941 | |
| 2942 | exit_get_ddb_index: |
| 2943 | return ret; |
| 2944 | } |
| 2945 | |
| 2946 | static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha, |
| 2947 | struct ddb_entry *ddb_entry, |
| 2948 | char *existing_ipaddr, |
| 2949 | char *user_ipaddr) |
| 2950 | { |
| 2951 | uint8_t dst_ipaddr[IPv6_ADDR_LEN]; |
| 2952 | char formatted_ipaddr[DDB_IPADDR_LEN]; |
| 2953 | int status = QLA_SUCCESS, ret = 0; |
| 2954 | |
| 2955 | if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) { |
| 2956 | ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 2957 | '\0', NULL); |
| 2958 | if (ret == 0) { |
| 2959 | status = QLA_ERROR; |
| 2960 | goto out_match; |
| 2961 | } |
| 2962 | ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr); |
| 2963 | } else { |
| 2964 | ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 2965 | '\0', NULL); |
| 2966 | if (ret == 0) { |
| 2967 | status = QLA_ERROR; |
| 2968 | goto out_match; |
| 2969 | } |
| 2970 | ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr); |
| 2971 | } |
| 2972 | |
| 2973 | if (strcmp(existing_ipaddr, formatted_ipaddr)) |
| 2974 | status = QLA_ERROR; |
| 2975 | |
| 2976 | out_match: |
| 2977 | return status; |
| 2978 | } |
| 2979 | |
| 2980 | static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha, |
| 2981 | struct iscsi_cls_conn *cls_conn) |
| 2982 | { |
| 2983 | int idx = 0, max_ddbs, rval; |
| 2984 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 2985 | struct iscsi_session *sess, *existing_sess; |
| 2986 | struct iscsi_conn *conn, *existing_conn; |
| 2987 | struct ddb_entry *ddb_entry; |
| 2988 | |
| 2989 | sess = cls_sess->dd_data; |
| 2990 | conn = cls_conn->dd_data; |
| 2991 | |
| 2992 | if (sess->targetname == NULL || |
| 2993 | conn->persistent_address == NULL || |
| 2994 | conn->persistent_port == 0) |
| 2995 | return QLA_ERROR; |
| 2996 | |
| 2997 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 2998 | MAX_DEV_DB_ENTRIES; |
| 2999 | |
| 3000 | for (idx = 0; idx < max_ddbs; idx++) { |
| 3001 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 3002 | if (ddb_entry == NULL) |
| 3003 | continue; |
| 3004 | |
| 3005 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 3006 | continue; |
| 3007 | |
| 3008 | existing_sess = ddb_entry->sess->dd_data; |
| 3009 | existing_conn = ddb_entry->conn->dd_data; |
| 3010 | |
| 3011 | if (existing_sess->targetname == NULL || |
| 3012 | existing_conn->persistent_address == NULL || |
| 3013 | existing_conn->persistent_port == 0) |
| 3014 | continue; |
| 3015 | |
| 3016 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3017 | "IQN = %s User IQN = %s\n", |
| 3018 | existing_sess->targetname, |
| 3019 | sess->targetname)); |
| 3020 | |
| 3021 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3022 | "IP = %s User IP = %s\n", |
| 3023 | existing_conn->persistent_address, |
| 3024 | conn->persistent_address)); |
| 3025 | |
| 3026 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3027 | "Port = %d User Port = %d\n", |
| 3028 | existing_conn->persistent_port, |
| 3029 | conn->persistent_port)); |
| 3030 | |
| 3031 | if (strcmp(existing_sess->targetname, sess->targetname)) |
| 3032 | continue; |
| 3033 | rval = qla4xxx_match_ipaddress(ha, ddb_entry, |
| 3034 | existing_conn->persistent_address, |
| 3035 | conn->persistent_address); |
| 3036 | if (rval == QLA_ERROR) |
| 3037 | continue; |
| 3038 | if (existing_conn->persistent_port != conn->persistent_port) |
| 3039 | continue; |
| 3040 | break; |
| 3041 | } |
| 3042 | |
| 3043 | if (idx == max_ddbs) |
| 3044 | return QLA_ERROR; |
| 3045 | |
| 3046 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3047 | "Match found in fwdb sessions\n")); |
| 3048 | return QLA_SUCCESS; |
| 3049 | } |
| 3050 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3051 | static struct iscsi_cls_session * |
| 3052 | qla4xxx_session_create(struct iscsi_endpoint *ep, |
| 3053 | uint16_t cmds_max, uint16_t qdepth, |
| 3054 | uint32_t initial_cmdsn) |
| 3055 | { |
| 3056 | struct iscsi_cls_session *cls_sess; |
| 3057 | struct scsi_qla_host *ha; |
| 3058 | struct qla_endpoint *qla_ep; |
| 3059 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3060 | uint16_t ddb_index; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3061 | struct iscsi_session *sess; |
| 3062 | struct sockaddr *dst_addr; |
| 3063 | int ret; |
| 3064 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3065 | if (!ep) { |
| 3066 | printk(KERN_ERR "qla4xxx: missing ep.\n"); |
| 3067 | return NULL; |
| 3068 | } |
| 3069 | |
| 3070 | qla_ep = ep->dd_data; |
| 3071 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 3072 | ha = to_qla_host(qla_ep->host); |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3073 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__, |
| 3074 | ha->host_no)); |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 3075 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3076 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 3077 | if (ret == QLA_ERROR) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3078 | return NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3079 | |
| 3080 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host, |
| 3081 | cmds_max, sizeof(struct ddb_entry), |
| 3082 | sizeof(struct ql4_task_data), |
| 3083 | initial_cmdsn, ddb_index); |
| 3084 | if (!cls_sess) |
| 3085 | return NULL; |
| 3086 | |
| 3087 | sess = cls_sess->dd_data; |
| 3088 | ddb_entry = sess->dd_data; |
| 3089 | ddb_entry->fw_ddb_index = ddb_index; |
| 3090 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 3091 | ddb_entry->ha = ha; |
| 3092 | ddb_entry->sess = cls_sess; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3093 | ddb_entry->unblock_sess = qla4xxx_unblock_ddb; |
| 3094 | ddb_entry->ddb_change = qla4xxx_ddb_change; |
Nilesh Javali | de2efea | 2013-12-16 06:49:40 -0500 | [diff] [blame] | 3095 | clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3096 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 3097 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| 3098 | ha->tot_ddbs++; |
| 3099 | |
| 3100 | return cls_sess; |
| 3101 | } |
| 3102 | |
| 3103 | static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess) |
| 3104 | { |
| 3105 | struct iscsi_session *sess; |
| 3106 | struct ddb_entry *ddb_entry; |
| 3107 | struct scsi_qla_host *ha; |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3108 | unsigned long flags, wtime; |
| 3109 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 3110 | dma_addr_t fw_ddb_entry_dma; |
| 3111 | uint32_t ddb_state; |
| 3112 | int ret; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3113 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3114 | sess = cls_sess->dd_data; |
| 3115 | ddb_entry = sess->dd_data; |
| 3116 | ha = ddb_entry->ha; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3117 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__, |
| 3118 | ha->host_no)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3119 | |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3120 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3121 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3122 | if (!fw_ddb_entry) { |
| 3123 | ql4_printk(KERN_ERR, ha, |
| 3124 | "%s: Unable to allocate dma buffer\n", __func__); |
| 3125 | goto destroy_session; |
| 3126 | } |
| 3127 | |
| 3128 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 3129 | do { |
| 3130 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 3131 | fw_ddb_entry, fw_ddb_entry_dma, |
| 3132 | NULL, NULL, &ddb_state, NULL, |
| 3133 | NULL, NULL); |
| 3134 | if (ret == QLA_ERROR) |
| 3135 | goto destroy_session; |
| 3136 | |
| 3137 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 3138 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 3139 | goto destroy_session; |
| 3140 | |
| 3141 | schedule_timeout_uninterruptible(HZ); |
| 3142 | } while ((time_after(wtime, jiffies))); |
| 3143 | |
| 3144 | destroy_session: |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 3145 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
Nilesh Javali | de2efea | 2013-12-16 06:49:40 -0500 | [diff] [blame] | 3146 | if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags)) |
| 3147 | clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3148 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3149 | qla4xxx_free_ddb(ha, ddb_entry); |
| 3150 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3151 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3152 | iscsi_session_teardown(cls_sess); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3153 | |
| 3154 | if (fw_ddb_entry) |
| 3155 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3156 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3157 | } |
| 3158 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3159 | static struct iscsi_cls_conn * |
| 3160 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx) |
| 3161 | { |
| 3162 | struct iscsi_cls_conn *cls_conn; |
| 3163 | struct iscsi_session *sess; |
| 3164 | struct ddb_entry *ddb_entry; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3165 | struct scsi_qla_host *ha; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3166 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3167 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), |
| 3168 | conn_idx); |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3169 | if (!cls_conn) { |
| 3170 | pr_info("%s: Can not create connection for conn_idx = %u\n", |
| 3171 | __func__, conn_idx); |
Mike Christie | ff1d031 | 2011-12-01 21:38:43 -0600 | [diff] [blame] | 3172 | return NULL; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3173 | } |
Mike Christie | ff1d031 | 2011-12-01 21:38:43 -0600 | [diff] [blame] | 3174 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3175 | sess = cls_sess->dd_data; |
| 3176 | ddb_entry = sess->dd_data; |
| 3177 | ddb_entry->conn = cls_conn; |
| 3178 | |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3179 | ha = ddb_entry->ha; |
| 3180 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__, |
| 3181 | conn_idx)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3182 | return cls_conn; |
| 3183 | } |
| 3184 | |
| 3185 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 3186 | struct iscsi_cls_conn *cls_conn, |
| 3187 | uint64_t transport_fd, int is_leading) |
| 3188 | { |
| 3189 | struct iscsi_conn *conn; |
| 3190 | struct qla_conn *qla_conn; |
| 3191 | struct iscsi_endpoint *ep; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3192 | struct ddb_entry *ddb_entry; |
| 3193 | struct scsi_qla_host *ha; |
| 3194 | struct iscsi_session *sess; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3195 | |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3196 | sess = cls_session->dd_data; |
| 3197 | ddb_entry = sess->dd_data; |
| 3198 | ha = ddb_entry->ha; |
| 3199 | |
| 3200 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__, |
| 3201 | cls_session->sid, cls_conn->cid)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3202 | |
| 3203 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
| 3204 | return -EINVAL; |
| 3205 | ep = iscsi_lookup_endpoint(transport_fd); |
| 3206 | conn = cls_conn->dd_data; |
| 3207 | qla_conn = conn->dd_data; |
| 3208 | qla_conn->qla_ep = ep->dd_data; |
| 3209 | return 0; |
| 3210 | } |
| 3211 | |
| 3212 | static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn) |
| 3213 | { |
| 3214 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 3215 | struct iscsi_session *sess; |
| 3216 | struct ddb_entry *ddb_entry; |
| 3217 | struct scsi_qla_host *ha; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3218 | struct dev_db_entry *fw_ddb_entry = NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3219 | dma_addr_t fw_ddb_entry_dma; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3220 | uint32_t mbx_sts = 0; |
| 3221 | int ret = 0; |
| 3222 | int status = QLA_SUCCESS; |
| 3223 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3224 | sess = cls_sess->dd_data; |
| 3225 | ddb_entry = sess->dd_data; |
| 3226 | ha = ddb_entry->ha; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3227 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__, |
| 3228 | cls_sess->sid, cls_conn->cid)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3229 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3230 | /* Check if we have matching FW DDB, if yes then do not |
| 3231 | * login to this target. This could cause target to logout previous |
| 3232 | * connection |
| 3233 | */ |
| 3234 | ret = qla4xxx_match_fwdb_session(ha, cls_conn); |
| 3235 | if (ret == QLA_SUCCESS) { |
| 3236 | ql4_printk(KERN_INFO, ha, |
| 3237 | "Session already exist in FW.\n"); |
| 3238 | ret = -EEXIST; |
| 3239 | goto exit_conn_start; |
| 3240 | } |
| 3241 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3242 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3243 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3244 | if (!fw_ddb_entry) { |
| 3245 | ql4_printk(KERN_ERR, ha, |
| 3246 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3247 | ret = -ENOMEM; |
| 3248 | goto exit_conn_start; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts); |
| 3252 | if (ret) { |
| 3253 | /* If iscsid is stopped and started then no need to do |
| 3254 | * set param again since ddb state will be already |
| 3255 | * active and FW does not allow set ddb to an |
| 3256 | * active session. |
| 3257 | */ |
| 3258 | if (mbx_sts) |
| 3259 | if (ddb_entry->fw_ddb_device_state == |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 3260 | DDB_DS_SESSION_ACTIVE) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3261 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3262 | goto exit_set_param; |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 3263 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3264 | |
| 3265 | ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n", |
| 3266 | __func__, ddb_entry->fw_ddb_index); |
| 3267 | goto exit_conn_start; |
| 3268 | } |
| 3269 | |
| 3270 | status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| 3271 | if (status == QLA_ERROR) { |
Manish Rangankar | 0e7e850 | 2011-07-25 13:48:54 -0500 | [diff] [blame] | 3272 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| 3273 | sess->targetname); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3274 | ret = -EINVAL; |
| 3275 | goto exit_conn_start; |
| 3276 | } |
| 3277 | |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 3278 | if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) |
| 3279 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| 3280 | |
| 3281 | DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__, |
| 3282 | ddb_entry->fw_ddb_device_state)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3283 | |
| 3284 | exit_set_param: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3285 | ret = 0; |
| 3286 | |
| 3287 | exit_conn_start: |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3288 | if (fw_ddb_entry) |
| 3289 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3290 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3291 | return ret; |
| 3292 | } |
| 3293 | |
| 3294 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| 3295 | { |
| 3296 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 3297 | struct iscsi_session *sess; |
| 3298 | struct scsi_qla_host *ha; |
| 3299 | struct ddb_entry *ddb_entry; |
| 3300 | int options; |
| 3301 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3302 | sess = cls_sess->dd_data; |
| 3303 | ddb_entry = sess->dd_data; |
| 3304 | ha = ddb_entry->ha; |
Vikas Chaudhary | c343c5e | 2013-12-16 06:49:48 -0500 | [diff] [blame] | 3305 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__, |
| 3306 | cls_conn->cid)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3307 | |
| 3308 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 3309 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) |
| 3310 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | static void qla4xxx_task_work(struct work_struct *wdata) |
| 3314 | { |
| 3315 | struct ql4_task_data *task_data; |
| 3316 | struct scsi_qla_host *ha; |
| 3317 | struct passthru_status *sts; |
| 3318 | struct iscsi_task *task; |
| 3319 | struct iscsi_hdr *hdr; |
| 3320 | uint8_t *data; |
| 3321 | uint32_t data_len; |
| 3322 | struct iscsi_conn *conn; |
| 3323 | int hdr_len; |
| 3324 | itt_t itt; |
| 3325 | |
| 3326 | task_data = container_of(wdata, struct ql4_task_data, task_work); |
| 3327 | ha = task_data->ha; |
| 3328 | task = task_data->task; |
| 3329 | sts = &task_data->sts; |
| 3330 | hdr_len = sizeof(struct iscsi_hdr); |
| 3331 | |
| 3332 | DEBUG3(printk(KERN_INFO "Status returned\n")); |
| 3333 | DEBUG3(qla4xxx_dump_buffer(sts, 64)); |
| 3334 | DEBUG3(printk(KERN_INFO "Response buffer")); |
| 3335 | DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64)); |
| 3336 | |
| 3337 | conn = task->conn; |
| 3338 | |
| 3339 | switch (sts->completionStatus) { |
| 3340 | case PASSTHRU_STATUS_COMPLETE: |
| 3341 | hdr = (struct iscsi_hdr *)task_data->resp_buffer; |
| 3342 | /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */ |
| 3343 | itt = sts->handle; |
| 3344 | hdr->itt = itt; |
| 3345 | data = task_data->resp_buffer + hdr_len; |
| 3346 | data_len = task_data->resp_len - hdr_len; |
| 3347 | iscsi_complete_pdu(conn, hdr, data, data_len); |
| 3348 | break; |
| 3349 | default: |
| 3350 | ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n", |
| 3351 | sts->completionStatus); |
| 3352 | break; |
| 3353 | } |
| 3354 | return; |
| 3355 | } |
| 3356 | |
| 3357 | static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 3358 | { |
| 3359 | struct ql4_task_data *task_data; |
| 3360 | struct iscsi_session *sess; |
| 3361 | struct ddb_entry *ddb_entry; |
| 3362 | struct scsi_qla_host *ha; |
| 3363 | int hdr_len; |
| 3364 | |
| 3365 | sess = task->conn->session; |
| 3366 | ddb_entry = sess->dd_data; |
| 3367 | ha = ddb_entry->ha; |
| 3368 | task_data = task->dd_data; |
| 3369 | memset(task_data, 0, sizeof(struct ql4_task_data)); |
| 3370 | |
| 3371 | if (task->sc) { |
| 3372 | ql4_printk(KERN_INFO, ha, |
| 3373 | "%s: SCSI Commands not implemented\n", __func__); |
| 3374 | return -EINVAL; |
| 3375 | } |
| 3376 | |
| 3377 | hdr_len = sizeof(struct iscsi_hdr); |
| 3378 | task_data->ha = ha; |
| 3379 | task_data->task = task; |
| 3380 | |
| 3381 | if (task->data_count) { |
| 3382 | task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data, |
| 3383 | task->data_count, |
Christoph Hellwig | ec44a67 | 2018-10-11 09:56:58 +0200 | [diff] [blame] | 3384 | DMA_TO_DEVICE); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 3388 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 3389 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3390 | task_data->resp_len = task->conn->max_recv_dlength + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3391 | task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| 3392 | task_data->resp_len, |
| 3393 | &task_data->resp_dma, |
| 3394 | GFP_ATOMIC); |
| 3395 | if (!task_data->resp_buffer) |
| 3396 | goto exit_alloc_pdu; |
| 3397 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3398 | task_data->req_len = task->data_count + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3399 | task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev, |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3400 | task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3401 | &task_data->req_dma, |
| 3402 | GFP_ATOMIC); |
| 3403 | if (!task_data->req_buffer) |
| 3404 | goto exit_alloc_pdu; |
| 3405 | |
| 3406 | task->hdr = task_data->req_buffer; |
| 3407 | |
| 3408 | INIT_WORK(&task_data->task_work, qla4xxx_task_work); |
| 3409 | |
| 3410 | return 0; |
| 3411 | |
| 3412 | exit_alloc_pdu: |
| 3413 | if (task_data->resp_buffer) |
| 3414 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 3415 | task_data->resp_buffer, task_data->resp_dma); |
| 3416 | |
| 3417 | if (task_data->req_buffer) |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3418 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3419 | task_data->req_buffer, task_data->req_dma); |
| 3420 | return -ENOMEM; |
| 3421 | } |
| 3422 | |
| 3423 | static void qla4xxx_task_cleanup(struct iscsi_task *task) |
| 3424 | { |
| 3425 | struct ql4_task_data *task_data; |
| 3426 | struct iscsi_session *sess; |
| 3427 | struct ddb_entry *ddb_entry; |
| 3428 | struct scsi_qla_host *ha; |
| 3429 | int hdr_len; |
| 3430 | |
| 3431 | hdr_len = sizeof(struct iscsi_hdr); |
| 3432 | sess = task->conn->session; |
| 3433 | ddb_entry = sess->dd_data; |
| 3434 | ha = ddb_entry->ha; |
| 3435 | task_data = task->dd_data; |
| 3436 | |
| 3437 | if (task->data_count) { |
| 3438 | dma_unmap_single(&ha->pdev->dev, task_data->data_dma, |
Christoph Hellwig | ec44a67 | 2018-10-11 09:56:58 +0200 | [diff] [blame] | 3439 | task->data_count, DMA_TO_DEVICE); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 3443 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 3444 | |
| 3445 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 3446 | task_data->resp_buffer, task_data->resp_dma); |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3447 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3448 | task_data->req_buffer, task_data->req_dma); |
| 3449 | return; |
| 3450 | } |
| 3451 | |
| 3452 | static int qla4xxx_task_xmit(struct iscsi_task *task) |
| 3453 | { |
| 3454 | struct scsi_cmnd *sc = task->sc; |
| 3455 | struct iscsi_session *sess = task->conn->session; |
| 3456 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 3457 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 3458 | |
| 3459 | if (!sc) |
| 3460 | return qla4xxx_send_passthru0(task); |
| 3461 | |
| 3462 | ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n", |
| 3463 | __func__); |
| 3464 | return -ENOSYS; |
| 3465 | } |
| 3466 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3467 | static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 3468 | struct iscsi_bus_flash_conn *conn, |
| 3469 | struct dev_db_entry *fw_ddb_entry) |
| 3470 | { |
| 3471 | unsigned long options = 0; |
| 3472 | int rc = 0; |
| 3473 | |
| 3474 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3475 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 3476 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3477 | rc = iscsi_switch_str_param(&sess->portal_type, |
| 3478 | PORTAL_TYPE_IPV6); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3479 | if (rc) |
| 3480 | goto exit_copy; |
| 3481 | } else { |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3482 | rc = iscsi_switch_str_param(&sess->portal_type, |
| 3483 | PORTAL_TYPE_IPV4); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3484 | if (rc) |
| 3485 | goto exit_copy; |
| 3486 | } |
| 3487 | |
| 3488 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 3489 | &options); |
| 3490 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 3491 | sess->entry_state = test_bit(OPT_ENTRY_STATE, &options); |
| 3492 | |
| 3493 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3494 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 3495 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 3496 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 3497 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 3498 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 3499 | &options); |
| 3500 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 3501 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 3502 | conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options); |
| 3503 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 3504 | &options); |
| 3505 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 3506 | sess->discovery_auth_optional = |
| 3507 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 3508 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 3509 | sess->erl |= BIT_1; |
| 3510 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 3511 | sess->erl |= BIT_0; |
| 3512 | |
| 3513 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3514 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 3515 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 3516 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 3517 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 3518 | conn->tcp_timer_scale |= BIT_3; |
| 3519 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 3520 | conn->tcp_timer_scale |= BIT_2; |
| 3521 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 3522 | conn->tcp_timer_scale |= BIT_1; |
| 3523 | |
| 3524 | conn->tcp_timer_scale >>= 1; |
| 3525 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 3526 | |
| 3527 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3528 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 3529 | |
| 3530 | conn->max_recv_dlength = BYTE_UNITS * |
| 3531 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 3532 | conn->max_xmit_dlength = BYTE_UNITS * |
| 3533 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 3534 | sess->first_burst = BYTE_UNITS * |
| 3535 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 3536 | sess->max_burst = BYTE_UNITS * |
| 3537 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 3538 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 3539 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3540 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 3541 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3542 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 3543 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 3544 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 3545 | conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl); |
| 3546 | conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 3547 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 3548 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 3549 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 3550 | sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 3551 | sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 3552 | sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3553 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 3554 | |
| 3555 | sess->default_taskmgmt_timeout = |
| 3556 | le16_to_cpu(fw_ddb_entry->def_timeout); |
| 3557 | conn->port = le16_to_cpu(fw_ddb_entry->port); |
| 3558 | |
| 3559 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3560 | conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3561 | if (!conn->ipaddress) { |
| 3562 | rc = -ENOMEM; |
| 3563 | goto exit_copy; |
| 3564 | } |
| 3565 | |
| 3566 | conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3567 | if (!conn->redirect_ipaddr) { |
| 3568 | rc = -ENOMEM; |
| 3569 | goto exit_copy; |
| 3570 | } |
| 3571 | |
| 3572 | memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 3573 | memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN); |
| 3574 | |
| 3575 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
| 3576 | conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos; |
| 3577 | |
Benoit Taine | 3d30b43 | 2014-05-26 17:21:13 +0200 | [diff] [blame] | 3578 | conn->link_local_ipv6_addr = kmemdup( |
| 3579 | fw_ddb_entry->link_local_ipv6_addr, |
| 3580 | IPv6_ADDR_LEN, GFP_KERNEL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3581 | if (!conn->link_local_ipv6_addr) { |
| 3582 | rc = -ENOMEM; |
| 3583 | goto exit_copy; |
| 3584 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3585 | } else { |
| 3586 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 3587 | } |
| 3588 | |
| 3589 | if (fw_ddb_entry->iscsi_name[0]) { |
| 3590 | rc = iscsi_switch_str_param(&sess->targetname, |
| 3591 | (char *)fw_ddb_entry->iscsi_name); |
| 3592 | if (rc) |
| 3593 | goto exit_copy; |
| 3594 | } |
| 3595 | |
| 3596 | if (fw_ddb_entry->iscsi_alias[0]) { |
| 3597 | rc = iscsi_switch_str_param(&sess->targetalias, |
| 3598 | (char *)fw_ddb_entry->iscsi_alias); |
| 3599 | if (rc) |
| 3600 | goto exit_copy; |
| 3601 | } |
| 3602 | |
| 3603 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 3604 | |
| 3605 | exit_copy: |
| 3606 | return rc; |
| 3607 | } |
| 3608 | |
| 3609 | static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 3610 | struct iscsi_bus_flash_conn *conn, |
| 3611 | struct dev_db_entry *fw_ddb_entry) |
| 3612 | { |
| 3613 | uint16_t options; |
| 3614 | int rc = 0; |
| 3615 | |
| 3616 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3617 | SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11); |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3618 | if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3619 | options |= BIT_8; |
| 3620 | else |
| 3621 | options &= ~BIT_8; |
| 3622 | |
| 3623 | SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6); |
| 3624 | SET_BITVAL(sess->discovery_sess, options, BIT_4); |
| 3625 | SET_BITVAL(sess->entry_state, options, BIT_3); |
| 3626 | fw_ddb_entry->options = cpu_to_le16(options); |
| 3627 | |
| 3628 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3629 | SET_BITVAL(conn->hdrdgst_en, options, BIT_13); |
| 3630 | SET_BITVAL(conn->datadgst_en, options, BIT_12); |
| 3631 | SET_BITVAL(sess->imm_data_en, options, BIT_11); |
| 3632 | SET_BITVAL(sess->initial_r2t_en, options, BIT_10); |
| 3633 | SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9); |
| 3634 | SET_BITVAL(sess->pdu_inorder_en, options, BIT_8); |
| 3635 | SET_BITVAL(sess->chap_auth_en, options, BIT_7); |
| 3636 | SET_BITVAL(conn->snack_req_en, options, BIT_6); |
| 3637 | SET_BITVAL(sess->discovery_logout_en, options, BIT_5); |
| 3638 | SET_BITVAL(sess->bidi_chap_en, options, BIT_4); |
| 3639 | SET_BITVAL(sess->discovery_auth_optional, options, BIT_3); |
| 3640 | SET_BITVAL(sess->erl & BIT_1, options, BIT_1); |
| 3641 | SET_BITVAL(sess->erl & BIT_0, options, BIT_0); |
| 3642 | fw_ddb_entry->iscsi_options = cpu_to_le16(options); |
| 3643 | |
| 3644 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3645 | SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6); |
| 3646 | SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5); |
| 3647 | SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4); |
| 3648 | SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3); |
| 3649 | SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2); |
| 3650 | SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1); |
| 3651 | SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0); |
| 3652 | fw_ddb_entry->tcp_options = cpu_to_le16(options); |
| 3653 | |
| 3654 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3655 | SET_BITVAL(conn->fragment_disable, options, BIT_4); |
| 3656 | fw_ddb_entry->ip_options = cpu_to_le16(options); |
| 3657 | |
| 3658 | fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t); |
| 3659 | fw_ddb_entry->iscsi_max_rcv_data_seg_len = |
| 3660 | cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS); |
| 3661 | fw_ddb_entry->iscsi_max_snd_data_seg_len = |
| 3662 | cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS); |
| 3663 | fw_ddb_entry->iscsi_first_burst_len = |
| 3664 | cpu_to_le16(sess->first_burst / BYTE_UNITS); |
| 3665 | fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst / |
| 3666 | BYTE_UNITS); |
| 3667 | fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait); |
| 3668 | fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain); |
| 3669 | fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt); |
| 3670 | fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size); |
Adheer Chandravanshi | fbcd483 | 2013-04-17 05:15:29 -0400 | [diff] [blame] | 3671 | fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf); |
| 3672 | fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3673 | fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label); |
| 3674 | fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout); |
| 3675 | fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port); |
Adheer Chandravanshi | fbcd483 | 2013-04-17 05:15:29 -0400 | [diff] [blame] | 3676 | fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn); |
| 3677 | fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn); |
Adheer Chandravanshi | 6556016 | 2013-07-08 08:33:06 -0400 | [diff] [blame] | 3678 | fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3679 | fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx); |
| 3680 | fw_ddb_entry->tsid = cpu_to_le16(sess->tsid); |
| 3681 | fw_ddb_entry->port = cpu_to_le16(conn->port); |
| 3682 | fw_ddb_entry->def_timeout = |
| 3683 | cpu_to_le16(sess->default_taskmgmt_timeout); |
| 3684 | |
Adheer Chandravanshi | 8459580 | 2013-07-08 08:33:07 -0400 | [diff] [blame] | 3685 | if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
| 3686 | fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class; |
| 3687 | else |
| 3688 | fw_ddb_entry->ipv4_tos = conn->ipv4_tos; |
| 3689 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3690 | if (conn->ipaddress) |
| 3691 | memcpy(fw_ddb_entry->ip_addr, conn->ipaddress, |
| 3692 | sizeof(fw_ddb_entry->ip_addr)); |
| 3693 | |
| 3694 | if (conn->redirect_ipaddr) |
| 3695 | memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr, |
| 3696 | sizeof(fw_ddb_entry->tgt_addr)); |
| 3697 | |
| 3698 | if (conn->link_local_ipv6_addr) |
| 3699 | memcpy(fw_ddb_entry->link_local_ipv6_addr, |
| 3700 | conn->link_local_ipv6_addr, |
| 3701 | sizeof(fw_ddb_entry->link_local_ipv6_addr)); |
| 3702 | |
| 3703 | if (sess->targetname) |
| 3704 | memcpy(fw_ddb_entry->iscsi_name, sess->targetname, |
| 3705 | sizeof(fw_ddb_entry->iscsi_name)); |
| 3706 | |
| 3707 | if (sess->targetalias) |
| 3708 | memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias, |
| 3709 | sizeof(fw_ddb_entry->iscsi_alias)); |
| 3710 | |
| 3711 | COPY_ISID(fw_ddb_entry->isid, sess->isid); |
| 3712 | |
| 3713 | return rc; |
| 3714 | } |
| 3715 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3716 | static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn, |
| 3717 | struct iscsi_session *sess, |
| 3718 | struct dev_db_entry *fw_ddb_entry) |
| 3719 | { |
| 3720 | unsigned long options = 0; |
| 3721 | uint16_t ddb_link; |
| 3722 | uint16_t disc_parent; |
Adheer Chandravanshi | fb734ee3 | 2013-11-22 05:28:22 -0500 | [diff] [blame] | 3723 | char ip_addr[DDB_IPADDR_LEN]; |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3724 | |
| 3725 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3726 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 3727 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 3728 | &options); |
| 3729 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 3730 | |
| 3731 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3732 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 3733 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 3734 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 3735 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 3736 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 3737 | &options); |
| 3738 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 3739 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 3740 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 3741 | &options); |
| 3742 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 3743 | sess->discovery_auth_optional = |
| 3744 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 3745 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 3746 | sess->erl |= BIT_1; |
| 3747 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 3748 | sess->erl |= BIT_0; |
| 3749 | |
| 3750 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3751 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 3752 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 3753 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 3754 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 3755 | conn->tcp_timer_scale |= BIT_3; |
| 3756 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 3757 | conn->tcp_timer_scale |= BIT_2; |
| 3758 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 3759 | conn->tcp_timer_scale |= BIT_1; |
| 3760 | |
| 3761 | conn->tcp_timer_scale >>= 1; |
| 3762 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 3763 | |
| 3764 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3765 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 3766 | |
| 3767 | conn->max_recv_dlength = BYTE_UNITS * |
| 3768 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 3769 | conn->max_xmit_dlength = BYTE_UNITS * |
| 3770 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 3771 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 3772 | sess->first_burst = BYTE_UNITS * |
| 3773 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 3774 | sess->max_burst = BYTE_UNITS * |
| 3775 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 3776 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3777 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 3778 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3779 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 3780 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 3781 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 3782 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 3783 | conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 3784 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 3785 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 3786 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 3787 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 3788 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 3789 | |
| 3790 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3791 | if (ddb_link == DDB_ISNS) |
| 3792 | disc_parent = ISCSI_DISC_PARENT_ISNS; |
| 3793 | else if (ddb_link == DDB_NO_LINK) |
| 3794 | disc_parent = ISCSI_DISC_PARENT_UNKNOWN; |
| 3795 | else if (ddb_link < MAX_DDB_ENTRIES) |
| 3796 | disc_parent = ISCSI_DISC_PARENT_SENDTGT; |
| 3797 | else |
| 3798 | disc_parent = ISCSI_DISC_PARENT_UNKNOWN; |
| 3799 | |
| 3800 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, |
| 3801 | iscsi_get_discovery_parent_name(disc_parent), 0); |
| 3802 | |
| 3803 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS, |
| 3804 | (char *)fw_ddb_entry->iscsi_alias, 0); |
Adheer Chandravanshi | fb734ee3 | 2013-11-22 05:28:22 -0500 | [diff] [blame] | 3805 | |
| 3806 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3807 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 3808 | memset(ip_addr, 0, sizeof(ip_addr)); |
| 3809 | sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr); |
| 3810 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR, |
| 3811 | (char *)ip_addr, 0); |
| 3812 | } |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3813 | } |
| 3814 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3815 | static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha, |
| 3816 | struct dev_db_entry *fw_ddb_entry, |
| 3817 | struct iscsi_cls_session *cls_sess, |
| 3818 | struct iscsi_cls_conn *cls_conn) |
| 3819 | { |
| 3820 | int buflen = 0; |
| 3821 | struct iscsi_session *sess; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3822 | struct ddb_entry *ddb_entry; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3823 | struct ql4_chap_table chap_tbl; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3824 | struct iscsi_conn *conn; |
| 3825 | char ip_addr[DDB_IPADDR_LEN]; |
| 3826 | uint16_t options = 0; |
| 3827 | |
| 3828 | sess = cls_sess->dd_data; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3829 | ddb_entry = sess->dd_data; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3830 | conn = cls_conn->dd_data; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3831 | memset(&chap_tbl, 0, sizeof(chap_tbl)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3832 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3833 | ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3834 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3835 | qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3836 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3837 | sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3838 | conn->persistent_port = le16_to_cpu(fw_ddb_entry->port); |
| 3839 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3840 | memset(ip_addr, 0, sizeof(ip_addr)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3841 | options = le16_to_cpu(fw_ddb_entry->options); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3842 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 3843 | iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3844 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3845 | memset(ip_addr, 0, sizeof(ip_addr)); |
| 3846 | sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 3847 | } else { |
| 3848 | iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4); |
| 3849 | sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 3850 | } |
| 3851 | |
| 3852 | iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS, |
| 3853 | (char *)ip_addr, buflen); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3854 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME, |
| 3855 | (char *)fw_ddb_entry->iscsi_name, buflen); |
| 3856 | iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME, |
| 3857 | (char *)ha->name_string, buflen); |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3858 | |
| 3859 | if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) { |
| 3860 | if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name, |
| 3861 | chap_tbl.secret, |
| 3862 | ddb_entry->chap_tbl_idx)) { |
| 3863 | iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME, |
| 3864 | (char *)chap_tbl.name, |
| 3865 | strlen((char *)chap_tbl.name)); |
| 3866 | iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD, |
| 3867 | (char *)chap_tbl.secret, |
| 3868 | chap_tbl.secret_len); |
| 3869 | } |
| 3870 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha, |
| 3874 | struct ddb_entry *ddb_entry) |
| 3875 | { |
| 3876 | struct iscsi_cls_session *cls_sess; |
| 3877 | struct iscsi_cls_conn *cls_conn; |
| 3878 | uint32_t ddb_state; |
| 3879 | dma_addr_t fw_ddb_entry_dma; |
| 3880 | struct dev_db_entry *fw_ddb_entry; |
| 3881 | |
| 3882 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3883 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3884 | if (!fw_ddb_entry) { |
| 3885 | ql4_printk(KERN_ERR, ha, |
| 3886 | "%s: Unable to allocate dma buffer\n", __func__); |
| 3887 | goto exit_session_conn_fwddb_param; |
| 3888 | } |
| 3889 | |
| 3890 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 3891 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 3892 | NULL, NULL, NULL) == QLA_ERROR) { |
| 3893 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 3894 | "get_ddb_entry for fw_ddb_index %d\n", |
| 3895 | ha->host_no, __func__, |
| 3896 | ddb_entry->fw_ddb_index)); |
| 3897 | goto exit_session_conn_fwddb_param; |
| 3898 | } |
| 3899 | |
| 3900 | cls_sess = ddb_entry->sess; |
| 3901 | |
| 3902 | cls_conn = ddb_entry->conn; |
| 3903 | |
| 3904 | /* Update params */ |
| 3905 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 3906 | |
| 3907 | exit_session_conn_fwddb_param: |
| 3908 | if (fw_ddb_entry) |
| 3909 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3910 | fw_ddb_entry, fw_ddb_entry_dma); |
| 3911 | } |
| 3912 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3913 | void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha, |
| 3914 | struct ddb_entry *ddb_entry) |
| 3915 | { |
| 3916 | struct iscsi_cls_session *cls_sess; |
| 3917 | struct iscsi_cls_conn *cls_conn; |
| 3918 | struct iscsi_session *sess; |
| 3919 | struct iscsi_conn *conn; |
| 3920 | uint32_t ddb_state; |
| 3921 | dma_addr_t fw_ddb_entry_dma; |
| 3922 | struct dev_db_entry *fw_ddb_entry; |
| 3923 | |
| 3924 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3925 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3926 | if (!fw_ddb_entry) { |
| 3927 | ql4_printk(KERN_ERR, ha, |
| 3928 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3929 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 3933 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 3934 | NULL, NULL, NULL) == QLA_ERROR) { |
| 3935 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 3936 | "get_ddb_entry for fw_ddb_index %d\n", |
| 3937 | ha->host_no, __func__, |
| 3938 | ddb_entry->fw_ddb_index)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3939 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | cls_sess = ddb_entry->sess; |
| 3943 | sess = cls_sess->dd_data; |
| 3944 | |
| 3945 | cls_conn = ddb_entry->conn; |
| 3946 | conn = cls_conn->dd_data; |
| 3947 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3948 | /* Update timers after login */ |
| 3949 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 3950 | (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) && |
| 3951 | (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ? |
| 3952 | le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3953 | ddb_entry->default_time2wait = |
| 3954 | le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3955 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3956 | /* Update params */ |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3957 | ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3958 | qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3959 | |
| 3960 | memcpy(sess->initiatorname, ha->name_string, |
| 3961 | min(sizeof(ha->name_string), sizeof(sess->initiatorname))); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3962 | |
| 3963 | exit_session_conn_param: |
| 3964 | if (fw_ddb_entry) |
| 3965 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3966 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3967 | } |
| 3968 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3969 | /* |
| 3970 | * Timer routines |
| 3971 | */ |
Kees Cook | d744644 | 2017-10-21 08:39:39 -0700 | [diff] [blame] | 3972 | static void qla4xxx_timer(struct timer_list *t); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3973 | |
Kees Cook | d744644 | 2017-10-21 08:39:39 -0700 | [diff] [blame] | 3974 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3975 | unsigned long interval) |
| 3976 | { |
| 3977 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| 3978 | __func__, ha->host->host_no)); |
Kees Cook | d744644 | 2017-10-21 08:39:39 -0700 | [diff] [blame] | 3979 | timer_setup(&ha->timer, qla4xxx_timer, 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3980 | ha->timer.expires = jiffies + interval * HZ; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3981 | add_timer(&ha->timer); |
| 3982 | ha->timer_active = 1; |
| 3983 | } |
| 3984 | |
| 3985 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| 3986 | { |
| 3987 | del_timer_sync(&ha->timer); |
| 3988 | ha->timer_active = 0; |
| 3989 | } |
| 3990 | |
| 3991 | /*** |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3992 | * qla4xxx_mark_device_missing - blocks the session |
| 3993 | * @cls_session: Pointer to the session to be blocked |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3994 | * @ddb_entry: Pointer to device database entry |
| 3995 | * |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3996 | * This routine marks a device missing and close connection. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3997 | **/ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3998 | void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3999 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4000 | iscsi_block_session(cls_session); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4003 | /** |
| 4004 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| 4005 | * @ha: Pointer to host adapter structure. |
| 4006 | * |
| 4007 | * This routine marks a device missing and resets the relogin retry count. |
| 4008 | **/ |
| 4009 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| 4010 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4011 | iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4012 | } |
| 4013 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4014 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| 4015 | struct ddb_entry *ddb_entry, |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4016 | struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4017 | { |
| 4018 | struct srb *srb; |
| 4019 | |
| 4020 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 4021 | if (!srb) |
| 4022 | return srb; |
| 4023 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4024 | kref_init(&srb->srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4025 | srb->ha = ha; |
| 4026 | srb->ddb = ddb_entry; |
| 4027 | srb->cmd = cmd; |
| 4028 | srb->flags = 0; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4029 | CMD_SP(cmd) = (void *)srb; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4030 | |
| 4031 | return srb; |
| 4032 | } |
| 4033 | |
| 4034 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| 4035 | { |
| 4036 | struct scsi_cmnd *cmd = srb->cmd; |
| 4037 | |
| 4038 | if (srb->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 4039 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4040 | srb->flags &= ~SRB_DMA_VALID; |
| 4041 | } |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4042 | CMD_SP(cmd) = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4043 | } |
| 4044 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4045 | void qla4xxx_srb_compl(struct kref *ref) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4046 | { |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4047 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4048 | struct scsi_cmnd *cmd = srb->cmd; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4049 | struct scsi_qla_host *ha = srb->ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4050 | |
| 4051 | qla4xxx_srb_free_dma(ha, srb); |
| 4052 | |
| 4053 | mempool_free(srb, ha->srb_mempool); |
| 4054 | |
| 4055 | cmd->scsi_done(cmd); |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4060 | * @host: scsi host |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4061 | * @cmd: Pointer to Linux's SCSI command structure |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4062 | * |
| 4063 | * Remarks: |
| 4064 | * This routine is invoked by Linux to send a SCSI command to the driver. |
| 4065 | * The mid-level driver tries to ensure that queuecommand never gets |
| 4066 | * invoked concurrently with itself or the interrupt handler (although |
| 4067 | * the interrupt handler may call this routine as part of request- |
| 4068 | * completion handling). Unfortunely, it sometimes calls the scheduler |
| 4069 | * in interrupt context which is a big NO! NO!. |
| 4070 | **/ |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4071 | static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4072 | { |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4073 | struct scsi_qla_host *ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4074 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 4075 | struct iscsi_cls_session *sess = ddb_entry->sess; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4076 | struct srb *srb; |
| 4077 | int rval; |
| 4078 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4079 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 4080 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 4081 | cmd->result = DID_NO_CONNECT << 16; |
| 4082 | else |
| 4083 | cmd->result = DID_REQUEUE << 16; |
| 4084 | goto qc_fail_command; |
| 4085 | } |
| 4086 | |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 4087 | if (!sess) { |
| 4088 | cmd->result = DID_IMM_RETRY << 16; |
| 4089 | goto qc_fail_command; |
| 4090 | } |
| 4091 | |
| 4092 | rval = iscsi_session_chkready(sess); |
| 4093 | if (rval) { |
| 4094 | cmd->result = rval; |
| 4095 | goto qc_fail_command; |
| 4096 | } |
| 4097 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4098 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 4099 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 4100 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 4101 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 4102 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| 4103 | !test_bit(AF_ONLINE, &ha->flags) || |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4104 | !test_bit(AF_LINK_UP, &ha->flags) || |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 4105 | test_bit(AF_LOOPBACK, &ha->flags) || |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 4106 | test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) || |
| 4107 | test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4108 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4109 | goto qc_host_busy; |
| 4110 | |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4111 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4112 | if (!srb) |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4113 | goto qc_host_busy; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4114 | |
| 4115 | rval = qla4xxx_send_command_to_isp(ha, srb); |
| 4116 | if (rval != QLA_SUCCESS) |
| 4117 | goto qc_host_busy_free_sp; |
| 4118 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4119 | return 0; |
| 4120 | |
| 4121 | qc_host_busy_free_sp: |
| 4122 | qla4xxx_srb_free_dma(ha, srb); |
| 4123 | mempool_free(srb, ha->srb_mempool); |
| 4124 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4125 | qc_host_busy: |
| 4126 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4127 | |
| 4128 | qc_fail_command: |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4129 | cmd->scsi_done(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4130 | |
| 4131 | return 0; |
| 4132 | } |
| 4133 | |
| 4134 | /** |
| 4135 | * qla4xxx_mem_free - frees memory allocated to adapter |
| 4136 | * @ha: Pointer to host adapter structure. |
| 4137 | * |
| 4138 | * Frees memory previously allocated by qla4xxx_mem_alloc |
| 4139 | **/ |
| 4140 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| 4141 | { |
| 4142 | if (ha->queues) |
| 4143 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| 4144 | ha->queues_dma); |
| 4145 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 4146 | if (ha->fw_dump) |
| 4147 | vfree(ha->fw_dump); |
| 4148 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4149 | ha->queues_len = 0; |
| 4150 | ha->queues = NULL; |
| 4151 | ha->queues_dma = 0; |
| 4152 | ha->request_ring = NULL; |
| 4153 | ha->request_dma = 0; |
| 4154 | ha->response_ring = NULL; |
| 4155 | ha->response_dma = 0; |
| 4156 | ha->shadow_regs = NULL; |
| 4157 | ha->shadow_regs_dma = 0; |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 4158 | ha->fw_dump = NULL; |
| 4159 | ha->fw_dump_size = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4160 | |
| 4161 | /* Free srb pool. */ |
Chengguang Xu | b03f3c3 | 2018-11-04 21:57:50 +0800 | [diff] [blame] | 4162 | mempool_destroy(ha->srb_mempool); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4163 | ha->srb_mempool = NULL; |
| 4164 | |
Chengguang Xu | 08cf8ab | 2018-11-04 21:57:49 +0800 | [diff] [blame] | 4165 | dma_pool_destroy(ha->chap_dma_pool); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4166 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 4167 | if (ha->chap_list) |
| 4168 | vfree(ha->chap_list); |
| 4169 | ha->chap_list = NULL; |
| 4170 | |
Chengguang Xu | 08cf8ab | 2018-11-04 21:57:49 +0800 | [diff] [blame] | 4171 | dma_pool_destroy(ha->fw_ddb_dma_pool); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4172 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4173 | /* release io space registers */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4174 | if (is_qla8022(ha)) { |
| 4175 | if (ha->nx_pcibase) |
| 4176 | iounmap( |
| 4177 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4178 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4179 | if (ha->nx_pcibase) |
| 4180 | iounmap( |
| 4181 | (struct device_reg_83xx __iomem *)ha->nx_pcibase); |
| 4182 | } else if (ha->reg) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4183 | iounmap(ha->reg); |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | if (ha->reset_tmplt.buff) |
| 4187 | vfree(ha->reset_tmplt.buff); |
| 4188 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4189 | pci_release_regions(ha->pdev); |
| 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| 4194 | * @ha: Pointer to host adapter structure |
| 4195 | * |
| 4196 | * Allocates DMA memory for request and response queues. Also allocates memory |
| 4197 | * for srbs. |
| 4198 | **/ |
| 4199 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| 4200 | { |
| 4201 | unsigned long align; |
| 4202 | |
| 4203 | /* Allocate contiguous block of DMA memory for queues. */ |
| 4204 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4205 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4206 | sizeof(struct shadow_regs) + |
| 4207 | MEM_ALIGN_VALUE + |
| 4208 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
Himanshu Jha | d103adb | 2017-12-30 20:58:24 +0530 | [diff] [blame] | 4209 | ha->queues = dma_zalloc_coherent(&ha->pdev->dev, ha->queues_len, |
| 4210 | &ha->queues_dma, GFP_KERNEL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4211 | if (ha->queues == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4212 | ql4_printk(KERN_WARNING, ha, |
| 4213 | "Memory Allocation failed - queues.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4214 | |
| 4215 | goto mem_alloc_error_exit; |
| 4216 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4217 | |
| 4218 | /* |
| 4219 | * As per RISC alignment requirements -- the bus-address must be a |
| 4220 | * multiple of the request-ring size (in bytes). |
| 4221 | */ |
| 4222 | align = 0; |
| 4223 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| 4224 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| 4225 | (MEM_ALIGN_VALUE - 1)); |
| 4226 | |
| 4227 | /* Update request and response queue pointers. */ |
| 4228 | ha->request_dma = ha->queues_dma + align; |
| 4229 | ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| 4230 | ha->response_dma = ha->queues_dma + align + |
| 4231 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| 4232 | ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| 4233 | (REQUEST_QUEUE_DEPTH * |
| 4234 | QUEUE_SIZE)); |
| 4235 | ha->shadow_regs_dma = ha->queues_dma + align + |
| 4236 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4237 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| 4238 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| 4239 | (REQUEST_QUEUE_DEPTH * |
| 4240 | QUEUE_SIZE) + |
| 4241 | (RESPONSE_QUEUE_DEPTH * |
| 4242 | QUEUE_SIZE)); |
| 4243 | |
| 4244 | /* Allocate memory for srb pool. */ |
| 4245 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 4246 | mempool_free_slab, srb_cachep); |
| 4247 | if (ha->srb_mempool == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4248 | ql4_printk(KERN_WARNING, ha, |
| 4249 | "Memory Allocation failed - SRB Pool.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4250 | |
| 4251 | goto mem_alloc_error_exit; |
| 4252 | } |
| 4253 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4254 | ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev, |
| 4255 | CHAP_DMA_BLOCK_SIZE, 8, 0); |
| 4256 | |
| 4257 | if (ha->chap_dma_pool == NULL) { |
| 4258 | ql4_printk(KERN_WARNING, ha, |
| 4259 | "%s: chap_dma_pool allocation failed..\n", __func__); |
| 4260 | goto mem_alloc_error_exit; |
| 4261 | } |
| 4262 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4263 | ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev, |
| 4264 | DDB_DMA_BLOCK_SIZE, 8, 0); |
| 4265 | |
| 4266 | if (ha->fw_ddb_dma_pool == NULL) { |
| 4267 | ql4_printk(KERN_WARNING, ha, |
| 4268 | "%s: fw_ddb_dma_pool allocation failed..\n", |
| 4269 | __func__); |
| 4270 | goto mem_alloc_error_exit; |
| 4271 | } |
| 4272 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4273 | return QLA_SUCCESS; |
| 4274 | |
| 4275 | mem_alloc_error_exit: |
| 4276 | qla4xxx_mem_free(ha); |
| 4277 | return QLA_ERROR; |
| 4278 | } |
| 4279 | |
| 4280 | /** |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4281 | * qla4_8xxx_check_temp - Check the ISP82XX temperature. |
| 4282 | * @ha: adapter block pointer. |
| 4283 | * |
| 4284 | * Note: The caller should not hold the idc lock. |
| 4285 | **/ |
| 4286 | static int qla4_8xxx_check_temp(struct scsi_qla_host *ha) |
| 4287 | { |
| 4288 | uint32_t temp, temp_state, temp_val; |
| 4289 | int status = QLA_SUCCESS; |
| 4290 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4291 | temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4292 | |
| 4293 | temp_state = qla82xx_get_temp_state(temp); |
| 4294 | temp_val = qla82xx_get_temp_val(temp); |
| 4295 | |
| 4296 | if (temp_state == QLA82XX_TEMP_PANIC) { |
| 4297 | ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C" |
| 4298 | " exceeds maximum allowed. Hardware has been shut" |
| 4299 | " down.\n", temp_val); |
| 4300 | status = QLA_ERROR; |
| 4301 | } else if (temp_state == QLA82XX_TEMP_WARN) { |
| 4302 | if (ha->temperature == QLA82XX_TEMP_NORMAL) |
| 4303 | ql4_printk(KERN_WARNING, ha, "Device temperature %d" |
| 4304 | " degrees C exceeds operating range." |
| 4305 | " Immediate action needed.\n", temp_val); |
| 4306 | } else { |
| 4307 | if (ha->temperature == QLA82XX_TEMP_WARN) |
| 4308 | ql4_printk(KERN_INFO, ha, "Device temperature is" |
| 4309 | " now %d degrees C in normal range.\n", |
| 4310 | temp_val); |
| 4311 | } |
| 4312 | ha->temperature = temp_state; |
| 4313 | return status; |
| 4314 | } |
| 4315 | |
| 4316 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4317 | * qla4_8xxx_check_fw_alive - Check firmware health |
| 4318 | * @ha: Pointer to host adapter structure. |
| 4319 | * |
| 4320 | * Context: Interrupt |
| 4321 | **/ |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4322 | static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4323 | { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4324 | uint32_t fw_heartbeat_counter; |
| 4325 | int status = QLA_SUCCESS; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4326 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4327 | fw_heartbeat_counter = qla4_8xxx_rd_direct(ha, |
| 4328 | QLA8XXX_PEG_ALIVE_COUNTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4329 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| 4330 | if (fw_heartbeat_counter == 0xffffffff) { |
| 4331 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| 4332 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| 4333 | ha->host_no, __func__)); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4334 | return status; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4335 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4336 | |
| 4337 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| 4338 | ha->seconds_since_last_heartbeat++; |
| 4339 | /* FW not alive after 2 seconds */ |
| 4340 | if (ha->seconds_since_last_heartbeat == 2) { |
| 4341 | ha->seconds_since_last_heartbeat = 0; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4342 | qla4_8xxx_dump_peg_reg(ha); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4343 | status = QLA_ERROR; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4344 | } |
Lalit Chandivade | 99457d7 | 2010-10-06 22:49:32 -0700 | [diff] [blame] | 4345 | } else |
| 4346 | ha->seconds_since_last_heartbeat = 0; |
| 4347 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4348 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4349 | return status; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4350 | } |
| 4351 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4352 | static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha) |
| 4353 | { |
| 4354 | uint32_t halt_status; |
| 4355 | int halt_status_unrecoverable = 0; |
| 4356 | |
| 4357 | halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1); |
| 4358 | |
| 4359 | if (is_qla8022(ha)) { |
| 4360 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 4361 | __func__); |
| 4362 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 4363 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 4364 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 4365 | |
| 4366 | if (QLA82XX_FWERROR_CODE(halt_status) == 0x67) |
| 4367 | ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n", |
| 4368 | __func__); |
| 4369 | if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| 4370 | halt_status_unrecoverable = 1; |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4371 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4372 | if (halt_status & QLA83XX_HALT_STATUS_FW_RESET) |
| 4373 | ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n", |
| 4374 | __func__); |
| 4375 | else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE) |
| 4376 | halt_status_unrecoverable = 1; |
| 4377 | } |
| 4378 | |
| 4379 | /* |
| 4380 | * Since we cannot change dev_state in interrupt context, |
| 4381 | * set appropriate DPC flag then wakeup DPC |
| 4382 | */ |
| 4383 | if (halt_status_unrecoverable) { |
| 4384 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 4385 | } else { |
| 4386 | ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n", |
| 4387 | __func__); |
| 4388 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4389 | } |
| 4390 | qla4xxx_mailbox_premature_completion(ha); |
| 4391 | qla4xxx_wake_dpc(ha); |
| 4392 | } |
| 4393 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4394 | /** |
| 4395 | * qla4_8xxx_watchdog - Poll dev state |
| 4396 | * @ha: Pointer to host adapter structure. |
| 4397 | * |
| 4398 | * Context: Interrupt |
| 4399 | **/ |
| 4400 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| 4401 | { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4402 | uint32_t dev_state; |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4403 | uint32_t idc_ctrl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4404 | |
Vikas Chaudhary | a083e8b | 2013-12-16 06:49:32 -0500 | [diff] [blame] | 4405 | if (is_qla8032(ha) && |
| 4406 | (qla4_83xx_is_detached(ha) == QLA_SUCCESS)) |
| 4407 | WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n", |
| 4408 | __func__, ha->func_num); |
| 4409 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4410 | /* don't poll if reset is going on */ |
Lalit Chandivade | d56a1f7 | 2010-12-02 22:12:45 -0800 | [diff] [blame] | 4411 | if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 4412 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
Vikas Chaudhary | 977f46a | 2011-05-17 23:17:08 -0700 | [diff] [blame] | 4413 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4414 | dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4415 | |
| 4416 | if (qla4_8xxx_check_temp(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4417 | if (is_qla8022(ha)) { |
| 4418 | ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n"); |
| 4419 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 4420 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 4421 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 4422 | } |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4423 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 4424 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4425 | } else if (dev_state == QLA8XXX_DEV_NEED_RESET && |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4426 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4427 | |
| 4428 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n", |
| 4429 | __func__); |
| 4430 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4431 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4432 | idc_ctrl = qla4_83xx_rd_reg(ha, |
| 4433 | QLA83XX_IDC_DRV_CTRL); |
| 4434 | if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) { |
| 4435 | ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n", |
| 4436 | __func__); |
| 4437 | qla4xxx_mailbox_premature_completion( |
| 4438 | ha); |
| 4439 | } |
| 4440 | } |
| 4441 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4442 | if ((is_qla8032(ha) || is_qla8042(ha)) || |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4443 | (is_qla8022(ha) && !ql4xdontresethba)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4444 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4445 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4446 | } |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4447 | } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4448 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4449 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
| 4450 | __func__); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4451 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| 4452 | qla4xxx_wake_dpc(ha); |
| 4453 | } else { |
| 4454 | /* Check firmware health */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4455 | if (qla4_8xxx_check_fw_alive(ha)) |
| 4456 | qla4_8xxx_process_fw_error(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4457 | } |
| 4458 | } |
| 4459 | } |
| 4460 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4461 | 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] | 4462 | { |
| 4463 | struct iscsi_session *sess; |
| 4464 | struct ddb_entry *ddb_entry; |
| 4465 | struct scsi_qla_host *ha; |
| 4466 | |
| 4467 | sess = cls_sess->dd_data; |
| 4468 | ddb_entry = sess->dd_data; |
| 4469 | ha = ddb_entry->ha; |
| 4470 | |
| 4471 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 4472 | return; |
| 4473 | |
| 4474 | if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 4475 | !iscsi_is_session_online(cls_sess)) { |
| 4476 | if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| 4477 | INVALID_ENTRY) { |
| 4478 | if (atomic_read(&ddb_entry->retry_relogin_timer) == |
| 4479 | 0) { |
| 4480 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 4481 | INVALID_ENTRY); |
| 4482 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4483 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 4484 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4485 | "%s: index [%d] login device\n", |
| 4486 | __func__, ddb_entry->fw_ddb_index)); |
| 4487 | } else |
| 4488 | atomic_dec(&ddb_entry->retry_relogin_timer); |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | /* Wait for relogin to timeout */ |
| 4493 | if (atomic_read(&ddb_entry->relogin_timer) && |
| 4494 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| 4495 | /* |
| 4496 | * If the relogin times out and the device is |
| 4497 | * still NOT ONLINE then try and relogin again. |
| 4498 | */ |
| 4499 | if (!iscsi_is_session_online(cls_sess)) { |
| 4500 | /* Reset retry relogin timer */ |
| 4501 | atomic_inc(&ddb_entry->relogin_retry_count); |
| 4502 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4503 | "%s: index[%d] relogin timed out-retrying" |
| 4504 | " relogin (%d), retry (%d)\n", __func__, |
| 4505 | ddb_entry->fw_ddb_index, |
| 4506 | atomic_read(&ddb_entry->relogin_retry_count), |
| 4507 | ddb_entry->default_time2wait + 4)); |
| 4508 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4509 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 4510 | ddb_entry->default_time2wait + 4); |
| 4511 | } |
| 4512 | } |
| 4513 | } |
| 4514 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4515 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4516 | * qla4xxx_timer - checks every second for work to do. |
| 4517 | * @ha: Pointer to host adapter structure. |
| 4518 | **/ |
Kees Cook | d744644 | 2017-10-21 08:39:39 -0700 | [diff] [blame] | 4519 | static void qla4xxx_timer(struct timer_list *t) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4520 | { |
Kees Cook | d744644 | 2017-10-21 08:39:39 -0700 | [diff] [blame] | 4521 | struct scsi_qla_host *ha = from_timer(ha, t, timer); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4522 | int start_dpc = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4523 | uint16_t w; |
| 4524 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4525 | iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb); |
| 4526 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4527 | /* If we are in the middle of AER/EEH processing |
| 4528 | * skip any processing and reschedule the timer |
| 4529 | */ |
| 4530 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 4531 | mod_timer(&ha->timer, jiffies + HZ); |
| 4532 | return; |
| 4533 | } |
| 4534 | |
| 4535 | /* Hardware read to trigger an EEH error during mailbox waits. */ |
| 4536 | if (!pci_channel_offline(ha->pdev)) |
| 4537 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4538 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4539 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4540 | qla4_8xxx_watchdog(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4541 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4542 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4543 | /* Check for heartbeat interval. */ |
| 4544 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| 4545 | ha->heartbeat_interval != 0) { |
| 4546 | ha->seconds_since_last_heartbeat++; |
| 4547 | if (ha->seconds_since_last_heartbeat > |
| 4548 | ha->heartbeat_interval + 2) |
| 4549 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4550 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 4553 | /* Process any deferred work. */ |
| 4554 | if (!list_empty(&ha->work_list)) |
| 4555 | start_dpc++; |
| 4556 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4557 | /* Wakeup the dpc routine for this adapter, if needed. */ |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 4558 | if (start_dpc || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4559 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 4560 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| 4561 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4562 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4563 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 4564 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 4565 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4566 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 4567 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
Nilesh Javali | 906cbf3 | 2014-04-09 21:12:25 -0400 | [diff] [blame] | 4568 | test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) || |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 4569 | test_bit(DPC_AEN, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4570 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| 4571 | " - dpc flags = 0x%lx\n", |
| 4572 | ha->host_no, __func__, ha->dpc_flags)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4573 | qla4xxx_wake_dpc(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | /* Reschedule timer thread to call us back in one second */ |
| 4577 | mod_timer(&ha->timer, jiffies + HZ); |
| 4578 | |
| 4579 | DEBUG2(ha->seconds_since_last_intr++); |
| 4580 | } |
| 4581 | |
| 4582 | /** |
| 4583 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| 4584 | * @ha: Pointer to host adapter structure. |
| 4585 | * |
| 4586 | * This routine stalls the driver until all outstanding commands are returned. |
| 4587 | * Caller must release the Hardware Lock prior to calling this routine. |
| 4588 | **/ |
| 4589 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| 4590 | { |
| 4591 | uint32_t index = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4592 | unsigned long flags; |
| 4593 | struct scsi_cmnd *cmd; |
Tej Parkash | 61d9a2b | 2013-12-16 06:49:43 -0500 | [diff] [blame] | 4594 | unsigned long wtime; |
| 4595 | uint32_t wtmo; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4596 | |
Tej Parkash | 61d9a2b | 2013-12-16 06:49:43 -0500 | [diff] [blame] | 4597 | if (is_qla40XX(ha)) |
| 4598 | wtmo = WAIT_CMD_TOV; |
| 4599 | else |
| 4600 | wtmo = ha->nx_reset_timeout / 2; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4601 | |
Tej Parkash | 61d9a2b | 2013-12-16 06:49:43 -0500 | [diff] [blame] | 4602 | wtime = jiffies + (wtmo * HZ); |
| 4603 | |
| 4604 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4605 | "Wait up to %u seconds for cmds to complete\n", |
| 4606 | wtmo)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4607 | |
| 4608 | while (!time_after_eq(jiffies, wtime)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4609 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4610 | /* Find a command that hasn't completed. */ |
| 4611 | for (index = 0; index < ha->host->can_queue; index++) { |
| 4612 | cmd = scsi_host_find_tag(ha->host, index); |
Mike Christie | a1e0063 | 2010-10-26 05:45:30 -0700 | [diff] [blame] | 4613 | /* |
| 4614 | * We cannot just check if the index is valid, |
| 4615 | * becase if we are run from the scsi eh, then |
| 4616 | * the scsi/block layer is going to prevent |
| 4617 | * the tag from being released. |
| 4618 | */ |
| 4619 | if (cmd != NULL && CMD_SP(cmd)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4620 | break; |
| 4621 | } |
| 4622 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4623 | |
| 4624 | /* If No Commands are pending, wait is complete */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4625 | if (index == ha->host->can_queue) |
| 4626 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4627 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4628 | msleep(1000); |
| 4629 | } |
| 4630 | /* If we timed out on waiting for commands to come back |
| 4631 | * return ERROR. */ |
| 4632 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4635 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4636 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4637 | uint32_t ctrl_status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4638 | unsigned long flags = 0; |
| 4639 | |
| 4640 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4641 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4642 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 4643 | return QLA_ERROR; |
| 4644 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4645 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4646 | |
| 4647 | /* |
| 4648 | * If the SCSI Reset Interrupt bit is set, clear it. |
| 4649 | * Otherwise, the Soft Reset won't work. |
| 4650 | */ |
| 4651 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4652 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| 4653 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 4654 | |
| 4655 | /* Issue Soft Reset */ |
| 4656 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| 4657 | readl(&ha->reg->ctrl_status); |
| 4658 | |
| 4659 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4660 | return QLA_SUCCESS; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | /** |
| 4664 | * qla4xxx_soft_reset - performs soft reset. |
| 4665 | * @ha: Pointer to host adapter structure. |
| 4666 | **/ |
| 4667 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| 4668 | { |
| 4669 | uint32_t max_wait_time; |
| 4670 | unsigned long flags = 0; |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4671 | int status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4672 | uint32_t ctrl_status; |
| 4673 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4674 | status = qla4xxx_hw_reset(ha); |
| 4675 | if (status != QLA_SUCCESS) |
| 4676 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4677 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4678 | status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4679 | /* Wait until the Network Reset Intr bit is cleared */ |
| 4680 | max_wait_time = RESET_INTR_TOV; |
| 4681 | do { |
| 4682 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4683 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4684 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4685 | |
| 4686 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| 4687 | break; |
| 4688 | |
| 4689 | msleep(1000); |
| 4690 | } while ((--max_wait_time)); |
| 4691 | |
| 4692 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| 4693 | DEBUG2(printk(KERN_WARNING |
| 4694 | "scsi%ld: Network Reset Intr not cleared by " |
| 4695 | "Network function, clearing it now!\n", |
| 4696 | ha->host_no)); |
| 4697 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4698 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| 4699 | readl(&ha->reg->ctrl_status); |
| 4700 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4701 | } |
| 4702 | |
| 4703 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 4704 | max_wait_time = SOFT_RESET_TOV; |
| 4705 | do { |
| 4706 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4707 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4708 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4709 | |
| 4710 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| 4711 | status = QLA_SUCCESS; |
| 4712 | break; |
| 4713 | } |
| 4714 | |
| 4715 | msleep(1000); |
| 4716 | } while ((--max_wait_time)); |
| 4717 | |
| 4718 | /* |
| 4719 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| 4720 | * after the soft reset has taken place. |
| 4721 | */ |
| 4722 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4723 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4724 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| 4725 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 4726 | readl(&ha->reg->ctrl_status); |
| 4727 | } |
| 4728 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4729 | |
| 4730 | /* If soft reset fails then most probably the bios on other |
| 4731 | * function is also enabled. |
| 4732 | * Since the initialization is sequential the other fn |
| 4733 | * wont be able to acknowledge the soft reset. |
| 4734 | * Issue a force soft reset to workaround this scenario. |
| 4735 | */ |
| 4736 | if (max_wait_time == 0) { |
| 4737 | /* Issue Force Soft Reset */ |
| 4738 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4739 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| 4740 | readl(&ha->reg->ctrl_status); |
| 4741 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4742 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 4743 | max_wait_time = SOFT_RESET_TOV; |
| 4744 | do { |
| 4745 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4746 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4747 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4748 | |
| 4749 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| 4750 | status = QLA_SUCCESS; |
| 4751 | break; |
| 4752 | } |
| 4753 | |
| 4754 | msleep(1000); |
| 4755 | } while ((--max_wait_time)); |
| 4756 | } |
| 4757 | |
| 4758 | return status; |
| 4759 | } |
| 4760 | |
| 4761 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4762 | * 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] | 4763 | * @ha: Pointer to host adapter structure. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4764 | * @res: returned scsi status |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4765 | * |
| 4766 | * This routine is called just prior to a HARD RESET to return all |
| 4767 | * outstanding commands back to the Operating System. |
| 4768 | * Caller should make sure that the following locks are released |
| 4769 | * before this calling routine: Hardware lock, and io_request_lock. |
| 4770 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4771 | 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] | 4772 | { |
| 4773 | struct srb *srb; |
| 4774 | int i; |
| 4775 | unsigned long flags; |
| 4776 | |
| 4777 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4778 | for (i = 0; i < ha->host->can_queue; i++) { |
| 4779 | srb = qla4xxx_del_from_active_array(ha, i); |
| 4780 | if (srb != NULL) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4781 | srb->cmd->result = res; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4782 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4788 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| 4789 | { |
| 4790 | clear_bit(AF_ONLINE, &ha->flags); |
| 4791 | |
| 4792 | /* Disable the board */ |
| 4793 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4794 | |
| 4795 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 4796 | qla4xxx_mark_all_devices_missing(ha); |
| 4797 | clear_bit(AF_INIT_DONE, &ha->flags); |
| 4798 | } |
| 4799 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4800 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session) |
| 4801 | { |
| 4802 | struct iscsi_session *sess; |
| 4803 | struct ddb_entry *ddb_entry; |
| 4804 | |
| 4805 | sess = cls_session->dd_data; |
| 4806 | ddb_entry = sess->dd_data; |
| 4807 | ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4808 | |
| 4809 | if (ddb_entry->ddb_type == FLASH_DDB) |
| 4810 | iscsi_block_session(ddb_entry->sess); |
| 4811 | else |
| 4812 | iscsi_session_failure(cls_session->dd_data, |
| 4813 | ISCSI_ERR_CONN_FAILED); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4814 | } |
| 4815 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4816 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4817 | * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| 4818 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4819 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4820 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4821 | { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4822 | int status = QLA_ERROR; |
| 4823 | uint8_t reset_chip = 0; |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4824 | uint32_t dev_state; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4825 | unsigned long wait; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4826 | |
| 4827 | /* Stall incoming I/O until we are done */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4828 | scsi_block_requests(ha->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4829 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4830 | clear_bit(AF_LINK_UP, &ha->flags); |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 4831 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4832 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4833 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4834 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4835 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4836 | if ((is_qla8032(ha) || is_qla8042(ha)) && |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 4837 | !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 4838 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 4839 | __func__); |
| 4840 | /* disable pause frame for ISP83xx */ |
| 4841 | qla4_83xx_disable_pause(ha); |
| 4842 | } |
| 4843 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4844 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
| 4845 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4846 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 4847 | reset_chip = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4848 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4849 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| 4850 | * do not reset adapter, jump to initialize_adapter */ |
| 4851 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| 4852 | status = QLA_SUCCESS; |
| 4853 | goto recover_ha_init_adapter; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4856 | /* For the ISP-8xxx adapter, issue a stop_firmware if invoked |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4857 | * from eh_host_reset or ioctl module */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4858 | if (is_qla80XX(ha) && !reset_chip && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4859 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 4860 | |
| 4861 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4862 | "scsi%ld: %s - Performing stop_firmware...\n", |
| 4863 | ha->host_no, __func__)); |
| 4864 | status = ha->isp_ops->reset_firmware(ha); |
| 4865 | if (status == QLA_SUCCESS) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4866 | ha->isp_ops->disable_intrs(ha); |
| 4867 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4868 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 4869 | } else { |
| 4870 | /* If the stop_firmware fails then |
| 4871 | * reset the entire chip */ |
| 4872 | reset_chip = 1; |
| 4873 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 4874 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4875 | } |
| 4876 | } |
| 4877 | |
| 4878 | /* Issue full chip reset if recovering from a catastrophic error, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4879 | * or if stop_firmware fails for ISP-8xxx. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4880 | * This is the default case for ISP-4xxx */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4881 | if (is_qla40XX(ha) || reset_chip) { |
| 4882 | if (is_qla40XX(ha)) |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4883 | goto chip_reset; |
| 4884 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4885 | /* Check if 8XXX firmware is alive or not |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4886 | * We may have arrived here from NEED_RESET |
| 4887 | * detection only */ |
| 4888 | if (test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4889 | goto chip_reset; |
| 4890 | |
| 4891 | wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ); |
| 4892 | while (time_before(jiffies, wait)) { |
| 4893 | if (qla4_8xxx_check_fw_alive(ha)) { |
| 4894 | qla4xxx_mailbox_premature_completion(ha); |
| 4895 | break; |
| 4896 | } |
| 4897 | |
| 4898 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 4899 | schedule_timeout(HZ); |
| 4900 | } |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 4901 | chip_reset: |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 4902 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4903 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 4904 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4905 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4906 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4907 | "scsi%ld: %s - Performing chip reset..\n", |
| 4908 | ha->host_no, __func__)); |
| 4909 | status = ha->isp_ops->reset_chip(ha); |
Tej Parkash | 61d9a2b | 2013-12-16 06:49:43 -0500 | [diff] [blame] | 4910 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | /* Flush any pending ddb changed AENs */ |
| 4914 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4915 | |
| 4916 | recover_ha_init_adapter: |
| 4917 | /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| 4918 | if (status == QLA_SUCCESS) { |
| 4919 | /* For ISP-4xxx, force function 1 to always initialize |
| 4920 | * before function 3 to prevent both funcions from |
| 4921 | * stepping on top of the other */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4922 | if (is_qla40XX(ha) && (ha->mac_index == 3)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4923 | ssleep(6); |
| 4924 | |
| 4925 | /* NOTE: AF_ONLINE flag set upon successful completion of |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 4926 | * qla4xxx_initialize_adapter */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4927 | status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 4928 | if (is_qla80XX(ha) && (status == QLA_ERROR)) { |
| 4929 | status = qla4_8xxx_check_init_adapter_retry(ha); |
| 4930 | if (status == QLA_ERROR) { |
| 4931 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n", |
| 4932 | ha->host_no, __func__); |
| 4933 | qla4xxx_dead_adapter_cleanup(ha); |
| 4934 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4935 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4936 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 4937 | &ha->dpc_flags); |
| 4938 | goto exit_recover; |
| 4939 | } |
| 4940 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | /* Retry failed adapter initialization, if necessary |
| 4944 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| 4945 | * case to prevent ping-pong resets between functions */ |
| 4946 | if (!test_bit(AF_ONLINE, &ha->flags) && |
| 4947 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4948 | /* Adapter initialization failed, see if we can retry |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4949 | * resetting the ha. |
| 4950 | * Since we don't want to block the DPC for too long |
| 4951 | * with multiple resets in the same thread, |
| 4952 | * utilize DPC to retry */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4953 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4954 | ha->isp_ops->idc_lock(ha); |
| 4955 | dev_state = qla4_8xxx_rd_direct(ha, |
| 4956 | QLA8XXX_CRB_DEV_STATE); |
| 4957 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4958 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4959 | ql4_printk(KERN_INFO, ha, "%s: don't retry " |
| 4960 | "recover adapter. H/W is in Failed " |
| 4961 | "state\n", __func__); |
| 4962 | qla4xxx_dead_adapter_cleanup(ha); |
| 4963 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4964 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4965 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 4966 | &ha->dpc_flags); |
| 4967 | status = QLA_ERROR; |
| 4968 | |
| 4969 | goto exit_recover; |
| 4970 | } |
| 4971 | } |
| 4972 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4973 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| 4974 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| 4975 | DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| 4976 | "(%d) more times\n", ha->host_no, |
| 4977 | ha->retry_reset_ha_cnt)); |
| 4978 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4979 | status = QLA_ERROR; |
| 4980 | } else { |
| 4981 | if (ha->retry_reset_ha_cnt > 0) { |
| 4982 | /* Schedule another Reset HA--DPC will retry */ |
| 4983 | ha->retry_reset_ha_cnt--; |
| 4984 | DEBUG2(printk("scsi%ld: recover adapter - " |
| 4985 | "retry remaining %d\n", |
| 4986 | ha->host_no, |
| 4987 | ha->retry_reset_ha_cnt)); |
| 4988 | status = QLA_ERROR; |
| 4989 | } |
| 4990 | |
| 4991 | if (ha->retry_reset_ha_cnt == 0) { |
| 4992 | /* Recover adapter retries have been exhausted. |
| 4993 | * Adapter DEAD */ |
| 4994 | DEBUG2(printk("scsi%ld: recover adapter " |
| 4995 | "failed - board disabled\n", |
| 4996 | ha->host_no)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4997 | qla4xxx_dead_adapter_cleanup(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4998 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4999 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5000 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5001 | &ha->dpc_flags); |
| 5002 | status = QLA_ERROR; |
| 5003 | } |
| 5004 | } |
| 5005 | } else { |
| 5006 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5007 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5008 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 5009 | } |
| 5010 | |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 5011 | exit_recover: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5012 | ha->adapter_error_count++; |
| 5013 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5014 | if (test_bit(AF_ONLINE, &ha->flags)) |
| 5015 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5016 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5017 | scsi_unblock_requests(ha->host); |
| 5018 | |
| 5019 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 5020 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5021 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5022 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5023 | return status; |
| 5024 | } |
| 5025 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5026 | static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session) |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5027 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5028 | struct iscsi_session *sess; |
| 5029 | struct ddb_entry *ddb_entry; |
| 5030 | struct scsi_qla_host *ha; |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5031 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5032 | sess = cls_session->dd_data; |
| 5033 | ddb_entry = sess->dd_data; |
| 5034 | ha = ddb_entry->ha; |
| 5035 | if (!iscsi_is_session_online(cls_session)) { |
| 5036 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| 5037 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5038 | " unblock session\n", ha->host_no, __func__, |
| 5039 | ddb_entry->fw_ddb_index); |
| 5040 | iscsi_unblock_session(ddb_entry->sess); |
| 5041 | } else { |
| 5042 | /* Trigger relogin */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5043 | if (ddb_entry->ddb_type == FLASH_DDB) { |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 5044 | if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) || |
| 5045 | test_bit(DF_DISABLE_RELOGIN, |
| 5046 | &ddb_entry->flags))) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5047 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 5048 | } else |
| 5049 | iscsi_session_failure(cls_session->dd_data, |
| 5050 | ISCSI_ERR_CONN_FAILED); |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5051 | } |
| 5052 | } |
| 5053 | } |
| 5054 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5055 | int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session) |
| 5056 | { |
| 5057 | struct iscsi_session *sess; |
| 5058 | struct ddb_entry *ddb_entry; |
| 5059 | struct scsi_qla_host *ha; |
| 5060 | |
| 5061 | sess = cls_session->dd_data; |
| 5062 | ddb_entry = sess->dd_data; |
| 5063 | ha = ddb_entry->ha; |
| 5064 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5065 | " unblock session\n", ha->host_no, __func__, |
| 5066 | ddb_entry->fw_ddb_index); |
| 5067 | |
| 5068 | iscsi_unblock_session(ddb_entry->sess); |
| 5069 | |
| 5070 | /* Start scan target */ |
| 5071 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 5072 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5073 | " start scan\n", ha->host_no, __func__, |
| 5074 | ddb_entry->fw_ddb_index); |
| 5075 | scsi_queue_work(ha->host, &ddb_entry->sess->scan_work); |
| 5076 | } |
| 5077 | return QLA_SUCCESS; |
| 5078 | } |
| 5079 | |
| 5080 | int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session) |
| 5081 | { |
| 5082 | struct iscsi_session *sess; |
| 5083 | struct ddb_entry *ddb_entry; |
| 5084 | struct scsi_qla_host *ha; |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 5085 | int status = QLA_SUCCESS; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5086 | |
| 5087 | sess = cls_session->dd_data; |
| 5088 | ddb_entry = sess->dd_data; |
| 5089 | ha = ddb_entry->ha; |
| 5090 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5091 | " unblock user space session\n", ha->host_no, __func__, |
| 5092 | ddb_entry->fw_ddb_index); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5093 | |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 5094 | if (!iscsi_is_session_online(cls_session)) { |
| 5095 | iscsi_conn_start(ddb_entry->conn); |
| 5096 | iscsi_conn_login_event(ddb_entry->conn, |
| 5097 | ISCSI_CONN_STATE_LOGGED_IN); |
| 5098 | } else { |
| 5099 | ql4_printk(KERN_INFO, ha, |
| 5100 | "scsi%ld: %s: ddb[%d] session [%d] already logged in\n", |
| 5101 | ha->host_no, __func__, ddb_entry->fw_ddb_index, |
| 5102 | cls_session->sid); |
| 5103 | status = QLA_ERROR; |
| 5104 | } |
| 5105 | |
| 5106 | return status; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5107 | } |
| 5108 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5109 | static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
| 5110 | { |
| 5111 | iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices); |
| 5112 | } |
| 5113 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5114 | static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| 5115 | { |
| 5116 | uint16_t relogin_timer; |
| 5117 | struct iscsi_session *sess; |
| 5118 | struct ddb_entry *ddb_entry; |
| 5119 | struct scsi_qla_host *ha; |
| 5120 | |
| 5121 | sess = cls_sess->dd_data; |
| 5122 | ddb_entry = sess->dd_data; |
| 5123 | ha = ddb_entry->ha; |
| 5124 | |
| 5125 | relogin_timer = max(ddb_entry->default_relogin_timeout, |
| 5126 | (uint16_t)RELOGIN_TOV); |
| 5127 | atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| 5128 | |
| 5129 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5130 | "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no, |
| 5131 | ddb_entry->fw_ddb_index, relogin_timer)); |
| 5132 | |
| 5133 | qla4xxx_login_flash_ddb(cls_sess); |
| 5134 | } |
| 5135 | |
| 5136 | static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess) |
| 5137 | { |
| 5138 | struct iscsi_session *sess; |
| 5139 | struct ddb_entry *ddb_entry; |
| 5140 | struct scsi_qla_host *ha; |
| 5141 | |
| 5142 | sess = cls_sess->dd_data; |
| 5143 | ddb_entry = sess->dd_data; |
| 5144 | ha = ddb_entry->ha; |
| 5145 | |
| 5146 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 5147 | return; |
| 5148 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 5149 | if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) |
| 5150 | return; |
| 5151 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5152 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 5153 | !iscsi_is_session_online(cls_sess)) { |
| 5154 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5155 | "relogin issued\n")); |
| 5156 | qla4xxx_relogin_flash_ddb(cls_sess); |
| 5157 | } |
| 5158 | } |
| 5159 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5160 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| 5161 | { |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5162 | if (ha->dpc_thread) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5163 | queue_work(ha->dpc_thread, &ha->dpc_work); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5164 | } |
| 5165 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5166 | static struct qla4_work_evt * |
| 5167 | qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size, |
| 5168 | enum qla4_work_type type) |
| 5169 | { |
| 5170 | struct qla4_work_evt *e; |
| 5171 | uint32_t size = sizeof(struct qla4_work_evt) + data_size; |
| 5172 | |
| 5173 | e = kzalloc(size, GFP_ATOMIC); |
| 5174 | if (!e) |
| 5175 | return NULL; |
| 5176 | |
| 5177 | INIT_LIST_HEAD(&e->list); |
| 5178 | e->type = type; |
| 5179 | return e; |
| 5180 | } |
| 5181 | |
| 5182 | static void qla4xxx_post_work(struct scsi_qla_host *ha, |
| 5183 | struct qla4_work_evt *e) |
| 5184 | { |
| 5185 | unsigned long flags; |
| 5186 | |
| 5187 | spin_lock_irqsave(&ha->work_lock, flags); |
| 5188 | list_add_tail(&e->list, &ha->work_list); |
| 5189 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 5190 | qla4xxx_wake_dpc(ha); |
| 5191 | } |
| 5192 | |
| 5193 | int qla4xxx_post_aen_work(struct scsi_qla_host *ha, |
| 5194 | enum iscsi_host_event_code aen_code, |
| 5195 | uint32_t data_size, uint8_t *data) |
| 5196 | { |
| 5197 | struct qla4_work_evt *e; |
| 5198 | |
| 5199 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN); |
| 5200 | if (!e) |
| 5201 | return QLA_ERROR; |
| 5202 | |
| 5203 | e->u.aen.code = aen_code; |
| 5204 | e->u.aen.data_size = data_size; |
| 5205 | memcpy(e->u.aen.data, data, data_size); |
| 5206 | |
| 5207 | qla4xxx_post_work(ha, e); |
| 5208 | |
| 5209 | return QLA_SUCCESS; |
| 5210 | } |
| 5211 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 5212 | int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha, |
| 5213 | uint32_t status, uint32_t pid, |
| 5214 | uint32_t data_size, uint8_t *data) |
| 5215 | { |
| 5216 | struct qla4_work_evt *e; |
| 5217 | |
| 5218 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS); |
| 5219 | if (!e) |
| 5220 | return QLA_ERROR; |
| 5221 | |
| 5222 | e->u.ping.status = status; |
| 5223 | e->u.ping.pid = pid; |
| 5224 | e->u.ping.data_size = data_size; |
| 5225 | memcpy(e->u.ping.data, data, data_size); |
| 5226 | |
| 5227 | qla4xxx_post_work(ha, e); |
| 5228 | |
| 5229 | return QLA_SUCCESS; |
| 5230 | } |
| 5231 | |
Vikas Chaudhary | a7380a6 | 2012-02-27 03:08:56 -0800 | [diff] [blame] | 5232 | static void qla4xxx_do_work(struct scsi_qla_host *ha) |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5233 | { |
| 5234 | struct qla4_work_evt *e, *tmp; |
| 5235 | unsigned long flags; |
| 5236 | LIST_HEAD(work); |
| 5237 | |
| 5238 | spin_lock_irqsave(&ha->work_lock, flags); |
| 5239 | list_splice_init(&ha->work_list, &work); |
| 5240 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 5241 | |
| 5242 | list_for_each_entry_safe(e, tmp, &work, list) { |
| 5243 | list_del_init(&e->list); |
| 5244 | |
| 5245 | switch (e->type) { |
| 5246 | case QLA4_EVENT_AEN: |
| 5247 | iscsi_post_host_event(ha->host_no, |
| 5248 | &qla4xxx_iscsi_transport, |
| 5249 | e->u.aen.code, |
| 5250 | e->u.aen.data_size, |
| 5251 | e->u.aen.data); |
| 5252 | break; |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 5253 | case QLA4_EVENT_PING_STATUS: |
| 5254 | iscsi_ping_comp_event(ha->host_no, |
| 5255 | &qla4xxx_iscsi_transport, |
| 5256 | e->u.ping.status, |
| 5257 | e->u.ping.pid, |
| 5258 | e->u.ping.data_size, |
| 5259 | e->u.ping.data); |
| 5260 | break; |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5261 | default: |
| 5262 | ql4_printk(KERN_WARNING, ha, "event type: 0x%x not " |
| 5263 | "supported", e->type); |
| 5264 | } |
| 5265 | kfree(e); |
| 5266 | } |
| 5267 | } |
| 5268 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5269 | /** |
| 5270 | * qla4xxx_do_dpc - dpc routine |
| 5271 | * @data: in our case pointer to adapter structure |
| 5272 | * |
| 5273 | * This routine is a task that is schedule by the interrupt handler |
| 5274 | * to perform the background processing for interrupts. We put it |
| 5275 | * on a task queue that is consumed whenever the scheduler runs; that's |
| 5276 | * so you can do anything (i.e. put the process to sleep etc). In fact, |
| 5277 | * the mid-level tries to sleep when it reaches the driver threshold |
| 5278 | * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| 5279 | **/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5280 | static void qla4xxx_do_dpc(struct work_struct *work) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5281 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5282 | struct scsi_qla_host *ha = |
| 5283 | container_of(work, struct scsi_qla_host, dpc_work); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5284 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5285 | |
Vikas Chaudhary | a7e5688 | 2013-12-16 06:49:51 -0500 | [diff] [blame] | 5286 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5287 | "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| 5288 | ha->host_no, __func__, ha->flags, ha->dpc_flags)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5289 | |
| 5290 | /* Initialization not yet finished. Don't do anything yet. */ |
| 5291 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5292 | return; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5293 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5294 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 5295 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| 5296 | ha->host_no, __func__, ha->flags)); |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5297 | return; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5298 | } |
| 5299 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5300 | /* post events to application */ |
| 5301 | qla4xxx_do_work(ha); |
| 5302 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5303 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5304 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5305 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 5306 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 5307 | __func__); |
| 5308 | /* disable pause frame for ISP83xx */ |
| 5309 | qla4_83xx_disable_pause(ha); |
| 5310 | } |
| 5311 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5312 | ha->isp_ops->idc_lock(ha); |
| 5313 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 5314 | QLA8XXX_DEV_FAILED); |
| 5315 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5316 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 5317 | qla4_8xxx_device_state_handler(ha); |
| 5318 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5319 | |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 5320 | if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) { |
| 5321 | if (is_qla8042(ha)) { |
| 5322 | if (ha->idc_info.info2 & |
| 5323 | ENABLE_INTERNAL_LOOPBACK) { |
| 5324 | ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n", |
| 5325 | __func__); |
| 5326 | status = qla4_84xx_config_acb(ha, |
| 5327 | ACB_CONFIG_DISABLE); |
| 5328 | if (status != QLA_SUCCESS) { |
| 5329 | ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n", |
| 5330 | __func__); |
| 5331 | } |
| 5332 | } |
| 5333 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5334 | qla4_83xx_post_idc_ack(ha); |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 5335 | clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags); |
| 5336 | } |
| 5337 | |
| 5338 | if (is_qla8042(ha) && |
| 5339 | test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) { |
| 5340 | ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n", |
| 5341 | __func__); |
| 5342 | if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) != |
| 5343 | QLA_SUCCESS) { |
| 5344 | ql4_printk(KERN_INFO, ha, "%s: ACB config failed ", |
| 5345 | __func__); |
| 5346 | } |
| 5347 | clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags); |
| 5348 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5349 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5350 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 5351 | qla4_8xxx_need_qsnt_handler(ha); |
| 5352 | } |
| 5353 | } |
| 5354 | |
| 5355 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| 5356 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5357 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5358 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5359 | if ((is_qla8022(ha) && ql4xdontresethba) || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5360 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 5361 | qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5362 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 5363 | ha->host_no, __func__)); |
| 5364 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 5365 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 5366 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 5367 | goto dpc_post_reset_ha; |
| 5368 | } |
| 5369 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| 5370 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 5371 | qla4xxx_recover_adapter(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5372 | |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5373 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5374 | uint8_t wait_time = RESET_INTR_TOV; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5375 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5376 | while ((readw(&ha->reg->ctrl_status) & |
| 5377 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| 5378 | if (--wait_time == 0) |
| 5379 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5380 | msleep(1000); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5381 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5382 | if (wait_time == 0) |
| 5383 | DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| 5384 | "bit not cleared-- resetting\n", |
| 5385 | ha->host_no, __func__)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5386 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5387 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| 5388 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5389 | status = qla4xxx_recover_adapter(ha); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5390 | } |
| 5391 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 5392 | if (status == QLA_SUCCESS) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5393 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5397 | dpc_post_reset_ha: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5398 | /* ---- process AEN? --- */ |
| 5399 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 5400 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| 5401 | |
| 5402 | /* ---- Get DHCP IP Address? --- */ |
| 5403 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 5404 | qla4xxx_get_dhcp_ip_address(ha); |
| 5405 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5406 | /* ---- relogin device? --- */ |
| 5407 | if (adapter_up(ha) && |
| 5408 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| 5409 | iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin); |
| 5410 | } |
| 5411 | |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5412 | /* ---- link change? --- */ |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 5413 | if (!test_bit(AF_LOOPBACK, &ha->flags) && |
| 5414 | test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5415 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 5416 | /* ---- link down? --- */ |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5417 | qla4xxx_mark_all_devices_missing(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5418 | } else { |
| 5419 | /* ---- link up? --- * |
| 5420 | * F/W will auto login to all devices ONLY ONCE after |
| 5421 | * link up during driver initialization and runtime |
| 5422 | * fatal error recovery. Therefore, the driver must |
| 5423 | * manually relogin to devices when recovering from |
| 5424 | * connection failures, logouts, expired KATO, etc. */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5425 | if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) { |
| 5426 | qla4xxx_build_ddb_list(ha, ha->is_reset); |
| 5427 | iscsi_host_for_each_session(ha->host, |
| 5428 | qla4xxx_login_flash_ddb); |
| 5429 | } else |
| 5430 | qla4xxx_relogin_all_devices(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5431 | } |
| 5432 | } |
Nilesh Javali | 906cbf3 | 2014-04-09 21:12:25 -0400 | [diff] [blame] | 5433 | if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) { |
| 5434 | if (qla4xxx_sysfs_ddb_export(ha)) |
| 5435 | ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n", |
| 5436 | __func__); |
| 5437 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | /** |
| 5441 | * qla4xxx_free_adapter - release the adapter |
| 5442 | * @ha: pointer to adapter structure |
| 5443 | **/ |
| 5444 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| 5445 | { |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 5446 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5447 | |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 5448 | /* Turn-off interrupts on the card. */ |
| 5449 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5450 | |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 5451 | if (is_qla40XX(ha)) { |
| 5452 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 5453 | &ha->reg->ctrl_status); |
| 5454 | readl(&ha->reg->ctrl_status); |
| 5455 | } else if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5456 | writel(0, &ha->qla4_82xx_reg->host_int); |
| 5457 | readl(&ha->qla4_82xx_reg->host_int); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5458 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | fbd8107 | 2012-09-20 07:35:03 -0400 | [diff] [blame] | 5459 | writel(0, &ha->qla4_83xx_reg->risc_intr); |
| 5460 | readl(&ha->qla4_83xx_reg->risc_intr); |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 5461 | } |
| 5462 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5463 | /* Remove timer thread, if present */ |
| 5464 | if (ha->timer_active) |
| 5465 | qla4xxx_stop_timer(ha); |
| 5466 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5467 | /* Kill the kernel thread for this host */ |
| 5468 | if (ha->dpc_thread) |
| 5469 | destroy_workqueue(ha->dpc_thread); |
| 5470 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5471 | /* Kill the kernel thread for this host */ |
| 5472 | if (ha->task_wq) |
| 5473 | destroy_workqueue(ha->task_wq); |
| 5474 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5475 | /* Put firmware in known state */ |
| 5476 | ha->isp_ops->reset_firmware(ha); |
| 5477 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5478 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5479 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5480 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5481 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5482 | } |
| 5483 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5484 | /* Detach interrupts */ |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 5485 | qla4xxx_free_irqs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5486 | |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 5487 | /* free extra memory */ |
| 5488 | qla4xxx_mem_free(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5489 | } |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 5490 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5491 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| 5492 | { |
| 5493 | int status = 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5494 | unsigned long mem_base, mem_len, db_base, db_len; |
| 5495 | struct pci_dev *pdev = ha->pdev; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5496 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5497 | status = pci_request_regions(pdev, DRIVER_NAME); |
| 5498 | if (status) { |
| 5499 | printk(KERN_WARNING |
| 5500 | "scsi(%ld) Failed to reserve PIO regions (%s) " |
| 5501 | "status=%d\n", ha->host_no, pci_name(pdev), status); |
| 5502 | goto iospace_error_exit; |
| 5503 | } |
| 5504 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5505 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
Sergei Shtylyov | 7d7311c | 2012-03-14 22:04:30 +0300 | [diff] [blame] | 5506 | __func__, pdev->revision)); |
| 5507 | ha->revision_id = pdev->revision; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5508 | |
| 5509 | /* remap phys address */ |
| 5510 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 5511 | mem_len = pci_resource_len(pdev, 0); |
| 5512 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| 5513 | __func__, mem_base, mem_len)); |
| 5514 | |
| 5515 | /* mapping of pcibase pointer */ |
| 5516 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| 5517 | if (!ha->nx_pcibase) { |
| 5518 | printk(KERN_ERR |
| 5519 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| 5520 | pci_release_regions(ha->pdev); |
| 5521 | goto iospace_error_exit; |
| 5522 | } |
| 5523 | |
| 5524 | /* Mapping of IO base pointer, door bell read and write pointer */ |
| 5525 | |
| 5526 | /* mapping of IO base pointer */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5527 | if (is_qla8022(ha)) { |
| 5528 | ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *) |
| 5529 | ((uint8_t *)ha->nx_pcibase + 0xbc000 + |
| 5530 | (ha->pdev->devfn << 11)); |
| 5531 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| 5532 | QLA82XX_CAM_RAM_DB2); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5533 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5534 | ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *) |
| 5535 | ((uint8_t *)ha->nx_pcibase); |
| 5536 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5537 | |
| 5538 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 5539 | db_len = pci_resource_len(pdev, 4); |
| 5540 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 5541 | return 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5542 | iospace_error_exit: |
| 5543 | return -ENOMEM; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | /*** |
| 5547 | * qla4xxx_iospace_config - maps registers |
| 5548 | * @ha: pointer to adapter structure |
| 5549 | * |
| 5550 | * This routines maps HBA's registers from the pci address space |
| 5551 | * into the kernel virtual address space for memory mapped i/o. |
| 5552 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5553 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5554 | { |
| 5555 | unsigned long pio, pio_len, pio_flags; |
| 5556 | unsigned long mmio, mmio_len, mmio_flags; |
| 5557 | |
| 5558 | pio = pci_resource_start(ha->pdev, 0); |
| 5559 | pio_len = pci_resource_len(ha->pdev, 0); |
| 5560 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 5561 | if (pio_flags & IORESOURCE_IO) { |
| 5562 | if (pio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5563 | ql4_printk(KERN_WARNING, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5564 | "Invalid PCI I/O region size\n"); |
| 5565 | pio = 0; |
| 5566 | } |
| 5567 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5568 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5569 | pio = 0; |
| 5570 | } |
| 5571 | |
| 5572 | /* Use MMIO operations for all accesses. */ |
| 5573 | mmio = pci_resource_start(ha->pdev, 1); |
| 5574 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 5575 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 5576 | |
| 5577 | if (!(mmio_flags & IORESOURCE_MEM)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5578 | ql4_printk(KERN_ERR, ha, |
| 5579 | "region #0 not an MMIO resource, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5580 | |
| 5581 | goto iospace_error_exit; |
| 5582 | } |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5583 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5584 | if (mmio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5585 | ql4_printk(KERN_ERR, ha, |
| 5586 | "Invalid PCI mem region size, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5587 | goto iospace_error_exit; |
| 5588 | } |
| 5589 | |
| 5590 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5591 | ql4_printk(KERN_WARNING, ha, |
| 5592 | "Failed to reserve PIO/MMIO regions\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5593 | |
| 5594 | goto iospace_error_exit; |
| 5595 | } |
| 5596 | |
| 5597 | ha->pio_address = pio; |
| 5598 | ha->pio_length = pio_len; |
| 5599 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| 5600 | if (!ha->reg) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5601 | ql4_printk(KERN_ERR, ha, |
| 5602 | "cannot remap MMIO, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5603 | |
| 5604 | goto iospace_error_exit; |
| 5605 | } |
| 5606 | |
| 5607 | return 0; |
| 5608 | |
| 5609 | iospace_error_exit: |
| 5610 | return -ENOMEM; |
| 5611 | } |
| 5612 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5613 | static struct isp_operations qla4xxx_isp_ops = { |
| 5614 | .iospace_config = qla4xxx_iospace_config, |
| 5615 | .pci_config = qla4xxx_pci_config, |
| 5616 | .disable_intrs = qla4xxx_disable_intrs, |
| 5617 | .enable_intrs = qla4xxx_enable_intrs, |
| 5618 | .start_firmware = qla4xxx_start_firmware, |
| 5619 | .intr_handler = qla4xxx_intr_handler, |
| 5620 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| 5621 | .reset_chip = qla4xxx_soft_reset, |
| 5622 | .reset_firmware = qla4xxx_hw_reset, |
| 5623 | .queue_iocb = qla4xxx_queue_iocb, |
| 5624 | .complete_iocb = qla4xxx_complete_iocb, |
| 5625 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 5626 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| 5627 | .get_sys_info = qla4xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5628 | .queue_mailbox_command = qla4xxx_queue_mbox_cmd, |
| 5629 | .process_mailbox_interrupt = qla4xxx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5630 | }; |
| 5631 | |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5632 | static struct isp_operations qla4_82xx_isp_ops = { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5633 | .iospace_config = qla4_8xxx_iospace_config, |
| 5634 | .pci_config = qla4_8xxx_pci_config, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5635 | .disable_intrs = qla4_82xx_disable_intrs, |
| 5636 | .enable_intrs = qla4_82xx_enable_intrs, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5637 | .start_firmware = qla4_8xxx_load_risc, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5638 | .restart_firmware = qla4_82xx_try_start_fw, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5639 | .intr_handler = qla4_82xx_intr_handler, |
| 5640 | .interrupt_service_routine = qla4_82xx_interrupt_service_routine, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5641 | .need_reset = qla4_8xxx_need_reset, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5642 | .reset_chip = qla4_82xx_isp_reset, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5643 | .reset_firmware = qla4_8xxx_stop_firmware, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5644 | .queue_iocb = qla4_82xx_queue_iocb, |
| 5645 | .complete_iocb = qla4_82xx_complete_iocb, |
| 5646 | .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out, |
| 5647 | .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5648 | .get_sys_info = qla4_8xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5649 | .rd_reg_direct = qla4_82xx_rd_32, |
| 5650 | .wr_reg_direct = qla4_82xx_wr_32, |
| 5651 | .rd_reg_indirect = qla4_82xx_md_rd_32, |
| 5652 | .wr_reg_indirect = qla4_82xx_md_wr_32, |
| 5653 | .idc_lock = qla4_82xx_idc_lock, |
| 5654 | .idc_unlock = qla4_82xx_idc_unlock, |
| 5655 | .rom_lock_recovery = qla4_82xx_rom_lock_recovery, |
| 5656 | .queue_mailbox_command = qla4_82xx_queue_mbox_cmd, |
| 5657 | .process_mailbox_interrupt = qla4_82xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5658 | }; |
| 5659 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5660 | static struct isp_operations qla4_83xx_isp_ops = { |
| 5661 | .iospace_config = qla4_8xxx_iospace_config, |
| 5662 | .pci_config = qla4_8xxx_pci_config, |
| 5663 | .disable_intrs = qla4_83xx_disable_intrs, |
| 5664 | .enable_intrs = qla4_83xx_enable_intrs, |
| 5665 | .start_firmware = qla4_8xxx_load_risc, |
| 5666 | .restart_firmware = qla4_83xx_start_firmware, |
| 5667 | .intr_handler = qla4_83xx_intr_handler, |
| 5668 | .interrupt_service_routine = qla4_83xx_interrupt_service_routine, |
| 5669 | .need_reset = qla4_8xxx_need_reset, |
| 5670 | .reset_chip = qla4_83xx_isp_reset, |
| 5671 | .reset_firmware = qla4_8xxx_stop_firmware, |
| 5672 | .queue_iocb = qla4_83xx_queue_iocb, |
| 5673 | .complete_iocb = qla4_83xx_complete_iocb, |
Tej Parkash | a24058f | 2013-03-07 05:43:13 -0500 | [diff] [blame] | 5674 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 5675 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5676 | .get_sys_info = qla4_8xxx_get_sys_info, |
| 5677 | .rd_reg_direct = qla4_83xx_rd_reg, |
| 5678 | .wr_reg_direct = qla4_83xx_wr_reg, |
| 5679 | .rd_reg_indirect = qla4_83xx_rd_reg_indirect, |
| 5680 | .wr_reg_indirect = qla4_83xx_wr_reg_indirect, |
| 5681 | .idc_lock = qla4_83xx_drv_lock, |
| 5682 | .idc_unlock = qla4_83xx_drv_unlock, |
| 5683 | .rom_lock_recovery = qla4_83xx_rom_lock_recovery, |
| 5684 | .queue_mailbox_command = qla4_83xx_queue_mbox_cmd, |
| 5685 | .process_mailbox_interrupt = qla4_83xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5686 | }; |
| 5687 | |
| 5688 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 5689 | { |
| 5690 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| 5691 | } |
| 5692 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5693 | 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] | 5694 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5695 | 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] | 5696 | } |
| 5697 | |
| 5698 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 5699 | { |
| 5700 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); |
| 5701 | } |
| 5702 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5703 | 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] | 5704 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5705 | 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] | 5706 | } |
| 5707 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5708 | static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf) |
| 5709 | { |
| 5710 | struct scsi_qla_host *ha = data; |
| 5711 | char *str = buf; |
| 5712 | int rc; |
| 5713 | |
| 5714 | switch (type) { |
| 5715 | case ISCSI_BOOT_ETH_FLAGS: |
| 5716 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 5717 | break; |
| 5718 | case ISCSI_BOOT_ETH_INDEX: |
| 5719 | rc = sprintf(str, "0\n"); |
| 5720 | break; |
| 5721 | case ISCSI_BOOT_ETH_MAC: |
| 5722 | rc = sysfs_format_mac(str, ha->my_mac, |
| 5723 | MAC_ADDR_LEN); |
| 5724 | break; |
| 5725 | default: |
| 5726 | rc = -ENOSYS; |
| 5727 | break; |
| 5728 | } |
| 5729 | return rc; |
| 5730 | } |
| 5731 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5732 | static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5733 | { |
| 5734 | int rc; |
| 5735 | |
| 5736 | switch (type) { |
| 5737 | case ISCSI_BOOT_ETH_FLAGS: |
| 5738 | case ISCSI_BOOT_ETH_MAC: |
| 5739 | case ISCSI_BOOT_ETH_INDEX: |
| 5740 | rc = S_IRUGO; |
| 5741 | break; |
| 5742 | default: |
| 5743 | rc = 0; |
| 5744 | break; |
| 5745 | } |
| 5746 | return rc; |
| 5747 | } |
| 5748 | |
| 5749 | static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf) |
| 5750 | { |
| 5751 | struct scsi_qla_host *ha = data; |
| 5752 | char *str = buf; |
| 5753 | int rc; |
| 5754 | |
| 5755 | switch (type) { |
| 5756 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5757 | rc = sprintf(str, "%s\n", ha->name_string); |
| 5758 | break; |
| 5759 | default: |
| 5760 | rc = -ENOSYS; |
| 5761 | break; |
| 5762 | } |
| 5763 | return rc; |
| 5764 | } |
| 5765 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5766 | static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5767 | { |
| 5768 | int rc; |
| 5769 | |
| 5770 | switch (type) { |
| 5771 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5772 | rc = S_IRUGO; |
| 5773 | break; |
| 5774 | default: |
| 5775 | rc = 0; |
| 5776 | break; |
| 5777 | } |
| 5778 | return rc; |
| 5779 | } |
| 5780 | |
| 5781 | static ssize_t |
| 5782 | qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type, |
| 5783 | char *buf) |
| 5784 | { |
| 5785 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 5786 | char *str = buf; |
| 5787 | int rc; |
| 5788 | |
| 5789 | switch (type) { |
| 5790 | case ISCSI_BOOT_TGT_NAME: |
| 5791 | rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name); |
| 5792 | break; |
| 5793 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5794 | if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1) |
| 5795 | rc = sprintf(buf, "%pI4\n", |
| 5796 | &boot_conn->dest_ipaddr.ip_address); |
| 5797 | else |
| 5798 | rc = sprintf(str, "%pI6\n", |
| 5799 | &boot_conn->dest_ipaddr.ip_address); |
| 5800 | break; |
| 5801 | case ISCSI_BOOT_TGT_PORT: |
| 5802 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 5803 | break; |
| 5804 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5805 | rc = sprintf(str, "%.*s\n", |
| 5806 | boot_conn->chap.target_chap_name_length, |
| 5807 | (char *)&boot_conn->chap.target_chap_name); |
| 5808 | break; |
| 5809 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5810 | rc = sprintf(str, "%.*s\n", |
| 5811 | boot_conn->chap.target_secret_length, |
| 5812 | (char *)&boot_conn->chap.target_secret); |
| 5813 | break; |
| 5814 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5815 | rc = sprintf(str, "%.*s\n", |
| 5816 | boot_conn->chap.intr_chap_name_length, |
| 5817 | (char *)&boot_conn->chap.intr_chap_name); |
| 5818 | break; |
| 5819 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5820 | rc = sprintf(str, "%.*s\n", |
| 5821 | boot_conn->chap.intr_secret_length, |
| 5822 | (char *)&boot_conn->chap.intr_secret); |
| 5823 | break; |
| 5824 | case ISCSI_BOOT_TGT_FLAGS: |
| 5825 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 5826 | break; |
| 5827 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5828 | rc = sprintf(str, "0\n"); |
| 5829 | break; |
| 5830 | default: |
| 5831 | rc = -ENOSYS; |
| 5832 | break; |
| 5833 | } |
| 5834 | return rc; |
| 5835 | } |
| 5836 | |
| 5837 | static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf) |
| 5838 | { |
| 5839 | struct scsi_qla_host *ha = data; |
| 5840 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess); |
| 5841 | |
| 5842 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 5843 | } |
| 5844 | |
| 5845 | static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf) |
| 5846 | { |
| 5847 | struct scsi_qla_host *ha = data; |
| 5848 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess); |
| 5849 | |
| 5850 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 5851 | } |
| 5852 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5853 | static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5854 | { |
| 5855 | int rc; |
| 5856 | |
| 5857 | switch (type) { |
| 5858 | case ISCSI_BOOT_TGT_NAME: |
| 5859 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5860 | case ISCSI_BOOT_TGT_PORT: |
| 5861 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5862 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5863 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5864 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5865 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5866 | case ISCSI_BOOT_TGT_FLAGS: |
| 5867 | rc = S_IRUGO; |
| 5868 | break; |
| 5869 | default: |
| 5870 | rc = 0; |
| 5871 | break; |
| 5872 | } |
| 5873 | return rc; |
| 5874 | } |
| 5875 | |
| 5876 | static void qla4xxx_boot_release(void *data) |
| 5877 | { |
| 5878 | struct scsi_qla_host *ha = data; |
| 5879 | |
| 5880 | scsi_host_put(ha->host); |
| 5881 | } |
| 5882 | |
| 5883 | static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) |
| 5884 | { |
| 5885 | dma_addr_t buf_dma; |
| 5886 | uint32_t addr, pri_addr, sec_addr; |
| 5887 | uint32_t offset; |
| 5888 | uint16_t func_num; |
| 5889 | uint8_t val; |
| 5890 | uint8_t *buf = NULL; |
| 5891 | size_t size = 13 * sizeof(uint8_t); |
| 5892 | int ret = QLA_SUCCESS; |
| 5893 | |
| 5894 | func_num = PCI_FUNC(ha->pdev->devfn); |
| 5895 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 5896 | ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n", |
| 5897 | __func__, ha->pdev->device, func_num); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5898 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 5899 | if (is_qla40XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5900 | if (func_num == 1) { |
| 5901 | addr = NVRAM_PORT0_BOOT_MODE; |
| 5902 | pri_addr = NVRAM_PORT0_BOOT_PRI_TGT; |
| 5903 | sec_addr = NVRAM_PORT0_BOOT_SEC_TGT; |
| 5904 | } else if (func_num == 3) { |
| 5905 | addr = NVRAM_PORT1_BOOT_MODE; |
| 5906 | pri_addr = NVRAM_PORT1_BOOT_PRI_TGT; |
| 5907 | sec_addr = NVRAM_PORT1_BOOT_SEC_TGT; |
| 5908 | } else { |
| 5909 | ret = QLA_ERROR; |
| 5910 | goto exit_boot_info; |
| 5911 | } |
| 5912 | |
| 5913 | /* Check Boot Mode */ |
| 5914 | val = rd_nvram_byte(ha, addr); |
| 5915 | if (!(val & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5916 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot " |
| 5917 | "options : 0x%x\n", __func__, val)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5918 | ret = QLA_ERROR; |
| 5919 | goto exit_boot_info; |
| 5920 | } |
| 5921 | |
| 5922 | /* get primary valid target index */ |
| 5923 | val = rd_nvram_byte(ha, pri_addr); |
| 5924 | if (val & BIT_7) |
| 5925 | ddb_index[0] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5926 | |
| 5927 | /* get secondary valid target index */ |
| 5928 | val = rd_nvram_byte(ha, sec_addr); |
| 5929 | if (val & BIT_7) |
| 5930 | ddb_index[1] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5931 | |
Vikas Chaudhary | 3e788fb | 2013-03-07 05:43:08 -0500 | [diff] [blame] | 5932 | } else if (is_qla80XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5933 | buf = dma_alloc_coherent(&ha->pdev->dev, size, |
| 5934 | &buf_dma, GFP_KERNEL); |
| 5935 | if (!buf) { |
| 5936 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5937 | "%s: Unable to allocate dma buffer\n", |
| 5938 | __func__)); |
| 5939 | ret = QLA_ERROR; |
| 5940 | goto exit_boot_info; |
| 5941 | } |
| 5942 | |
| 5943 | if (ha->port_num == 0) |
| 5944 | offset = BOOT_PARAM_OFFSET_PORT0; |
| 5945 | else if (ha->port_num == 1) |
| 5946 | offset = BOOT_PARAM_OFFSET_PORT1; |
| 5947 | else { |
| 5948 | ret = QLA_ERROR; |
| 5949 | goto exit_boot_info_free; |
| 5950 | } |
| 5951 | addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) + |
| 5952 | offset; |
| 5953 | if (qla4xxx_get_flash(ha, buf_dma, addr, |
| 5954 | 13 * sizeof(uint8_t)) != QLA_SUCCESS) { |
| 5955 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash" |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 5956 | " failed\n", ha->host_no, __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5957 | ret = QLA_ERROR; |
| 5958 | goto exit_boot_info_free; |
| 5959 | } |
| 5960 | /* Check Boot Mode */ |
| 5961 | if (!(buf[1] & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5962 | DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options" |
| 5963 | " : 0x%x\n", buf[1])); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5964 | ret = QLA_ERROR; |
| 5965 | goto exit_boot_info_free; |
| 5966 | } |
| 5967 | |
| 5968 | /* get primary valid target index */ |
| 5969 | if (buf[2] & BIT_7) |
| 5970 | ddb_index[0] = buf[2] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5971 | |
| 5972 | /* get secondary valid target index */ |
| 5973 | if (buf[11] & BIT_7) |
| 5974 | ddb_index[1] = buf[11] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5975 | } else { |
| 5976 | ret = QLA_ERROR; |
| 5977 | goto exit_boot_info; |
| 5978 | } |
| 5979 | |
| 5980 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary" |
| 5981 | " target ID %d\n", __func__, ddb_index[0], |
| 5982 | ddb_index[1])); |
| 5983 | |
| 5984 | exit_boot_info_free: |
| 5985 | dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma); |
| 5986 | exit_boot_info: |
Lalit Chandivade | 20e835b | 2012-02-13 18:30:42 +0530 | [diff] [blame] | 5987 | ha->pri_ddb_idx = ddb_index[0]; |
| 5988 | ha->sec_ddb_idx = ddb_index[1]; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5989 | return ret; |
| 5990 | } |
| 5991 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 5992 | /** |
| 5993 | * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password |
| 5994 | * @ha: pointer to adapter structure |
| 5995 | * @username: CHAP username to be returned |
| 5996 | * @password: CHAP password to be returned |
| 5997 | * |
| 5998 | * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP |
| 5999 | * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/. |
| 6000 | * So from the CHAP cache find the first BIDI CHAP entry and set it |
| 6001 | * to the boot record in sysfs. |
| 6002 | **/ |
| 6003 | static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username, |
| 6004 | char *password) |
| 6005 | { |
| 6006 | int i, ret = -EINVAL; |
| 6007 | int max_chap_entries = 0; |
| 6008 | struct ql4_chap_table *chap_table; |
| 6009 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 6010 | if (is_qla80XX(ha)) |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 6011 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 6012 | sizeof(struct ql4_chap_table); |
| 6013 | else |
| 6014 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 6015 | |
| 6016 | if (!ha->chap_list) { |
| 6017 | ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n"); |
| 6018 | return ret; |
| 6019 | } |
| 6020 | |
| 6021 | mutex_lock(&ha->chap_sem); |
| 6022 | for (i = 0; i < max_chap_entries; i++) { |
| 6023 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 6024 | if (chap_table->cookie != |
| 6025 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 6026 | continue; |
| 6027 | } |
| 6028 | |
| 6029 | if (chap_table->flags & BIT_7) /* local */ |
| 6030 | continue; |
| 6031 | |
| 6032 | if (!(chap_table->flags & BIT_6)) /* Not BIDI */ |
| 6033 | continue; |
| 6034 | |
Rickard Strandqvist | bdbb966 | 2014-07-26 16:49:32 +0200 | [diff] [blame] | 6035 | strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN); |
| 6036 | strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN); |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 6037 | ret = 0; |
| 6038 | break; |
| 6039 | } |
| 6040 | mutex_unlock(&ha->chap_sem); |
| 6041 | |
| 6042 | return ret; |
| 6043 | } |
| 6044 | |
| 6045 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6046 | static int qla4xxx_get_boot_target(struct scsi_qla_host *ha, |
| 6047 | struct ql4_boot_session_info *boot_sess, |
| 6048 | uint16_t ddb_index) |
| 6049 | { |
| 6050 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 6051 | struct dev_db_entry *fw_ddb_entry; |
| 6052 | dma_addr_t fw_ddb_entry_dma; |
| 6053 | uint16_t idx; |
| 6054 | uint16_t options; |
| 6055 | int ret = QLA_SUCCESS; |
| 6056 | |
| 6057 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6058 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 6059 | if (!fw_ddb_entry) { |
| 6060 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 6061 | "%s: Unable to allocate dma buffer.\n", |
| 6062 | __func__)); |
| 6063 | ret = QLA_ERROR; |
| 6064 | return ret; |
| 6065 | } |
| 6066 | |
| 6067 | if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry, |
| 6068 | fw_ddb_entry_dma, ddb_index)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6069 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at " |
| 6070 | "index [%d]\n", __func__, ddb_index)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6071 | ret = QLA_ERROR; |
| 6072 | goto exit_boot_target; |
| 6073 | } |
| 6074 | |
| 6075 | /* Update target name and IP from DDB */ |
| 6076 | memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name, |
| 6077 | min(sizeof(boot_sess->target_name), |
| 6078 | sizeof(fw_ddb_entry->iscsi_name))); |
| 6079 | |
| 6080 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6081 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 6082 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 6083 | &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN); |
| 6084 | } else { |
| 6085 | boot_conn->dest_ipaddr.ip_type = 0x1; |
| 6086 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 6087 | &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN); |
| 6088 | } |
| 6089 | |
| 6090 | boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port); |
| 6091 | |
| 6092 | /* update chap information */ |
| 6093 | idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 6094 | |
| 6095 | if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 6096 | |
| 6097 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n")); |
| 6098 | |
| 6099 | ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap. |
| 6100 | target_chap_name, |
| 6101 | (char *)&boot_conn->chap.target_secret, |
| 6102 | idx); |
| 6103 | if (ret) { |
| 6104 | ql4_printk(KERN_ERR, ha, "Failed to set chap\n"); |
| 6105 | ret = QLA_ERROR; |
| 6106 | goto exit_boot_target; |
| 6107 | } |
| 6108 | |
| 6109 | boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 6110 | boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 6111 | } |
| 6112 | |
| 6113 | if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 6114 | |
| 6115 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n")); |
| 6116 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 6117 | ret = qla4xxx_get_bidi_chap(ha, |
| 6118 | (char *)&boot_conn->chap.intr_chap_name, |
| 6119 | (char *)&boot_conn->chap.intr_secret); |
| 6120 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6121 | if (ret) { |
| 6122 | ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n"); |
| 6123 | ret = QLA_ERROR; |
| 6124 | goto exit_boot_target; |
| 6125 | } |
| 6126 | |
| 6127 | boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 6128 | boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 6129 | } |
| 6130 | |
| 6131 | exit_boot_target: |
| 6132 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6133 | fw_ddb_entry, fw_ddb_entry_dma); |
| 6134 | return ret; |
| 6135 | } |
| 6136 | |
| 6137 | static int qla4xxx_get_boot_info(struct scsi_qla_host *ha) |
| 6138 | { |
| 6139 | uint16_t ddb_index[2]; |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6140 | int ret = QLA_ERROR; |
| 6141 | int rval; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6142 | |
| 6143 | memset(ddb_index, 0, sizeof(ddb_index)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6144 | ddb_index[0] = 0xffff; |
| 6145 | ddb_index[1] = 0xffff; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6146 | ret = get_fw_boot_info(ha, ddb_index); |
| 6147 | if (ret != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6148 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6149 | "%s: No boot target configured.\n", __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6150 | return ret; |
| 6151 | } |
| 6152 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6153 | if (ql4xdisablesysfsboot) |
| 6154 | return QLA_SUCCESS; |
| 6155 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6156 | if (ddb_index[0] == 0xffff) |
| 6157 | goto sec_target; |
| 6158 | |
| 6159 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6160 | ddb_index[0]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6161 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6162 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not " |
| 6163 | "configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6164 | } else |
| 6165 | ret = QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6166 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6167 | sec_target: |
| 6168 | if (ddb_index[1] == 0xffff) |
| 6169 | goto exit_get_boot_info; |
| 6170 | |
| 6171 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6172 | ddb_index[1]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6173 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6174 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not" |
| 6175 | " configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6176 | } else |
| 6177 | ret = QLA_SUCCESS; |
| 6178 | |
| 6179 | exit_get_boot_info: |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6180 | return ret; |
| 6181 | } |
| 6182 | |
| 6183 | static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha) |
| 6184 | { |
| 6185 | struct iscsi_boot_kobj *boot_kobj; |
| 6186 | |
| 6187 | if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6188 | return QLA_ERROR; |
| 6189 | |
| 6190 | if (ql4xdisablesysfsboot) { |
| 6191 | ql4_printk(KERN_INFO, ha, |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 6192 | "%s: syfsboot disabled - driver will trigger login " |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6193 | "and publish session for discovery .\n", __func__); |
| 6194 | return QLA_SUCCESS; |
| 6195 | } |
| 6196 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6197 | |
| 6198 | ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no); |
| 6199 | if (!ha->boot_kset) |
| 6200 | goto kset_free; |
| 6201 | |
| 6202 | if (!scsi_host_get(ha->host)) |
| 6203 | goto kset_free; |
| 6204 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha, |
| 6205 | qla4xxx_show_boot_tgt_pri_info, |
| 6206 | qla4xxx_tgt_get_attr_visibility, |
| 6207 | qla4xxx_boot_release); |
| 6208 | if (!boot_kobj) |
| 6209 | goto put_host; |
| 6210 | |
| 6211 | if (!scsi_host_get(ha->host)) |
| 6212 | goto kset_free; |
| 6213 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha, |
| 6214 | qla4xxx_show_boot_tgt_sec_info, |
| 6215 | qla4xxx_tgt_get_attr_visibility, |
| 6216 | qla4xxx_boot_release); |
| 6217 | if (!boot_kobj) |
| 6218 | goto put_host; |
| 6219 | |
| 6220 | if (!scsi_host_get(ha->host)) |
| 6221 | goto kset_free; |
| 6222 | boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha, |
| 6223 | qla4xxx_show_boot_ini_info, |
| 6224 | qla4xxx_ini_get_attr_visibility, |
| 6225 | qla4xxx_boot_release); |
| 6226 | if (!boot_kobj) |
| 6227 | goto put_host; |
| 6228 | |
| 6229 | if (!scsi_host_get(ha->host)) |
| 6230 | goto kset_free; |
| 6231 | boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha, |
| 6232 | qla4xxx_show_boot_eth_info, |
| 6233 | qla4xxx_eth_get_attr_visibility, |
| 6234 | qla4xxx_boot_release); |
| 6235 | if (!boot_kobj) |
| 6236 | goto put_host; |
| 6237 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6238 | return QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6239 | |
| 6240 | put_host: |
| 6241 | scsi_host_put(ha->host); |
| 6242 | kset_free: |
| 6243 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 6244 | return -ENOMEM; |
| 6245 | } |
| 6246 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 6247 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6248 | static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry, |
| 6249 | struct ql4_tuple_ddb *tddb) |
| 6250 | { |
| 6251 | struct scsi_qla_host *ha; |
| 6252 | struct iscsi_cls_session *cls_sess; |
| 6253 | struct iscsi_cls_conn *cls_conn; |
| 6254 | struct iscsi_session *sess; |
| 6255 | struct iscsi_conn *conn; |
| 6256 | |
| 6257 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 6258 | ha = ddb_entry->ha; |
| 6259 | cls_sess = ddb_entry->sess; |
| 6260 | sess = cls_sess->dd_data; |
| 6261 | cls_conn = ddb_entry->conn; |
| 6262 | conn = cls_conn->dd_data; |
| 6263 | |
| 6264 | tddb->tpgt = sess->tpgt; |
| 6265 | tddb->port = conn->persistent_port; |
Rickard Strandqvist | bdbb966 | 2014-07-26 16:49:32 +0200 | [diff] [blame] | 6266 | strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE); |
| 6267 | strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6268 | } |
| 6269 | |
| 6270 | 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] | 6271 | struct ql4_tuple_ddb *tddb, |
| 6272 | uint8_t *flash_isid) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6273 | { |
| 6274 | uint16_t options = 0; |
| 6275 | |
| 6276 | tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 6277 | memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
| 6278 | min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name))); |
| 6279 | |
| 6280 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6281 | if (options & DDB_OPT_IPV6_DEVICE) |
| 6282 | sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 6283 | else |
| 6284 | sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 6285 | |
| 6286 | tddb->port = le16_to_cpu(fw_ddb_entry->port); |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6287 | |
| 6288 | if (flash_isid == NULL) |
| 6289 | memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0], |
| 6290 | sizeof(tddb->isid)); |
| 6291 | else |
| 6292 | memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha, |
| 6296 | struct ql4_tuple_ddb *old_tddb, |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6297 | struct ql4_tuple_ddb *new_tddb, |
| 6298 | uint8_t is_isid_compare) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6299 | { |
| 6300 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 6301 | return QLA_ERROR; |
| 6302 | |
| 6303 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr)) |
| 6304 | return QLA_ERROR; |
| 6305 | |
| 6306 | if (old_tddb->port != new_tddb->port) |
| 6307 | return QLA_ERROR; |
| 6308 | |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6309 | /* For multi sessions, driver generates the ISID, so do not compare |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 6310 | * ISID in reset path since it would be a comparison between the |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6311 | * driver generated ISID and firmware generated ISID. This could |
| 6312 | * lead to adding duplicated DDBs in the list as driver generated |
| 6313 | * ISID would not match firmware generated ISID. |
| 6314 | */ |
| 6315 | if (is_isid_compare) { |
Oleksandr Khoshaba | d1d81bd | 2016-10-22 20:32:28 +0300 | [diff] [blame] | 6316 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6317 | "%s: old ISID [%pmR] New ISID [%pmR]\n", |
| 6318 | __func__, old_tddb->isid, new_tddb->isid)); |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6319 | |
| 6320 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 6321 | sizeof(old_tddb->isid))) |
| 6322 | return QLA_ERROR; |
| 6323 | } |
| 6324 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6325 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6326 | "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]", |
| 6327 | old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr, |
| 6328 | old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt, |
| 6329 | new_tddb->ip_addr, new_tddb->iscsi_name)); |
| 6330 | |
| 6331 | return QLA_SUCCESS; |
| 6332 | } |
| 6333 | |
| 6334 | static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6335 | struct dev_db_entry *fw_ddb_entry, |
| 6336 | uint32_t *index) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6337 | { |
| 6338 | struct ddb_entry *ddb_entry; |
| 6339 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 6340 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 6341 | int idx; |
| 6342 | int ret = QLA_ERROR; |
| 6343 | |
| 6344 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 6345 | if (!fw_tddb) { |
| 6346 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6347 | "Memory Allocation failed.\n")); |
| 6348 | ret = QLA_SUCCESS; |
| 6349 | goto exit_check; |
| 6350 | } |
| 6351 | |
| 6352 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6353 | if (!tmp_tddb) { |
| 6354 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6355 | "Memory Allocation failed.\n")); |
| 6356 | ret = QLA_SUCCESS; |
| 6357 | goto exit_check; |
| 6358 | } |
| 6359 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6360 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6361 | |
| 6362 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 6363 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 6364 | if (ddb_entry == NULL) |
| 6365 | continue; |
| 6366 | |
| 6367 | qla4xxx_get_param_ddb(ddb_entry, tmp_tddb); |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6368 | if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6369 | ret = QLA_SUCCESS; /* found */ |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6370 | if (index != NULL) |
| 6371 | *index = idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6372 | goto exit_check; |
| 6373 | } |
| 6374 | } |
| 6375 | |
| 6376 | exit_check: |
| 6377 | if (fw_tddb) |
| 6378 | vfree(fw_tddb); |
| 6379 | if (tmp_tddb) |
| 6380 | vfree(tmp_tddb); |
| 6381 | return ret; |
| 6382 | } |
| 6383 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6384 | /** |
| 6385 | * qla4xxx_check_existing_isid - check if target with same isid exist |
| 6386 | * in target list |
| 6387 | * @list_nt: list of target |
| 6388 | * @isid: isid to check |
| 6389 | * |
| 6390 | * This routine return QLA_SUCCESS if target with same isid exist |
| 6391 | **/ |
| 6392 | static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid) |
| 6393 | { |
| 6394 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 6395 | struct dev_db_entry *fw_ddb_entry; |
| 6396 | |
| 6397 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 6398 | fw_ddb_entry = &nt_ddb_idx->fw_ddb; |
| 6399 | |
| 6400 | if (memcmp(&fw_ddb_entry->isid[0], &isid[0], |
| 6401 | sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) { |
| 6402 | return QLA_SUCCESS; |
| 6403 | } |
| 6404 | } |
| 6405 | return QLA_ERROR; |
| 6406 | } |
| 6407 | |
| 6408 | /** |
| 6409 | * qla4xxx_update_isid - compare ddbs and updated isid |
| 6410 | * @ha: Pointer to host adapter structure. |
| 6411 | * @list_nt: list of nt target |
| 6412 | * @fw_ddb_entry: firmware ddb entry |
| 6413 | * |
| 6414 | * This routine update isid if ddbs have same iqn, same isid and |
| 6415 | * different IP addr. |
| 6416 | * Return QLA_SUCCESS if isid is updated. |
| 6417 | **/ |
| 6418 | static int qla4xxx_update_isid(struct scsi_qla_host *ha, |
| 6419 | struct list_head *list_nt, |
| 6420 | struct dev_db_entry *fw_ddb_entry) |
| 6421 | { |
| 6422 | uint8_t base_value, i; |
| 6423 | |
| 6424 | base_value = fw_ddb_entry->isid[1] & 0x1f; |
| 6425 | for (i = 0; i < 8; i++) { |
| 6426 | fw_ddb_entry->isid[1] = (base_value | (i << 5)); |
| 6427 | if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 6428 | break; |
| 6429 | } |
| 6430 | |
| 6431 | if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 6432 | return QLA_ERROR; |
| 6433 | |
| 6434 | return QLA_SUCCESS; |
| 6435 | } |
| 6436 | |
| 6437 | /** |
| 6438 | * qla4xxx_should_update_isid - check if isid need to update |
| 6439 | * @ha: Pointer to host adapter structure. |
| 6440 | * @old_tddb: ddb tuple |
| 6441 | * @new_tddb: ddb tuple |
| 6442 | * |
| 6443 | * Return QLA_SUCCESS if different IP, different PORT, same iqn, |
| 6444 | * same isid |
| 6445 | **/ |
| 6446 | static int qla4xxx_should_update_isid(struct scsi_qla_host *ha, |
| 6447 | struct ql4_tuple_ddb *old_tddb, |
| 6448 | struct ql4_tuple_ddb *new_tddb) |
| 6449 | { |
| 6450 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) { |
| 6451 | /* Same ip */ |
| 6452 | if (old_tddb->port == new_tddb->port) |
| 6453 | return QLA_ERROR; |
| 6454 | } |
| 6455 | |
| 6456 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 6457 | /* different iqn */ |
| 6458 | return QLA_ERROR; |
| 6459 | |
| 6460 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 6461 | sizeof(old_tddb->isid))) |
| 6462 | /* different isid */ |
| 6463 | return QLA_ERROR; |
| 6464 | |
| 6465 | return QLA_SUCCESS; |
| 6466 | } |
| 6467 | |
| 6468 | /** |
| 6469 | * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt |
| 6470 | * @ha: Pointer to host adapter structure. |
| 6471 | * @list_nt: list of nt target. |
| 6472 | * @fw_ddb_entry: firmware ddb entry. |
| 6473 | * |
| 6474 | * This routine check if fw_ddb_entry already exists in list_nt to avoid |
| 6475 | * duplicate ddb in list_nt. |
| 6476 | * Return QLA_SUCCESS if duplicate ddb exit in list_nl. |
| 6477 | * Note: This function also update isid of DDB if required. |
| 6478 | **/ |
| 6479 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6480 | static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, |
| 6481 | struct list_head *list_nt, |
| 6482 | struct dev_db_entry *fw_ddb_entry) |
| 6483 | { |
| 6484 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 6485 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 6486 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6487 | int rval, ret = QLA_ERROR; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6488 | |
| 6489 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 6490 | if (!fw_tddb) { |
| 6491 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6492 | "Memory Allocation failed.\n")); |
| 6493 | ret = QLA_SUCCESS; |
| 6494 | goto exit_check; |
| 6495 | } |
| 6496 | |
| 6497 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6498 | if (!tmp_tddb) { |
| 6499 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6500 | "Memory Allocation failed.\n")); |
| 6501 | ret = QLA_SUCCESS; |
| 6502 | goto exit_check; |
| 6503 | } |
| 6504 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6505 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6506 | |
| 6507 | 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] | 6508 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, |
| 6509 | nt_ddb_idx->flash_isid); |
| 6510 | ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true); |
| 6511 | /* found duplicate ddb */ |
| 6512 | if (ret == QLA_SUCCESS) |
| 6513 | goto exit_check; |
| 6514 | } |
| 6515 | |
| 6516 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 6517 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL); |
| 6518 | |
| 6519 | ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb); |
| 6520 | if (ret == QLA_SUCCESS) { |
| 6521 | rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry); |
| 6522 | if (rval == QLA_SUCCESS) |
| 6523 | ret = QLA_ERROR; |
| 6524 | else |
| 6525 | ret = QLA_SUCCESS; |
| 6526 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6527 | goto exit_check; |
| 6528 | } |
| 6529 | } |
| 6530 | |
| 6531 | exit_check: |
| 6532 | if (fw_tddb) |
| 6533 | vfree(fw_tddb); |
| 6534 | if (tmp_tddb) |
| 6535 | vfree(tmp_tddb); |
| 6536 | return ret; |
| 6537 | } |
| 6538 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6539 | static void qla4xxx_free_ddb_list(struct list_head *list_ddb) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6540 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6541 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6542 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6543 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6544 | list_del_init(&ddb_idx->list); |
| 6545 | vfree(ddb_idx); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6546 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6547 | } |
| 6548 | |
| 6549 | static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha, |
| 6550 | struct dev_db_entry *fw_ddb_entry) |
| 6551 | { |
| 6552 | struct iscsi_endpoint *ep; |
| 6553 | struct sockaddr_in *addr; |
| 6554 | struct sockaddr_in6 *addr6; |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6555 | struct sockaddr *t_addr; |
| 6556 | struct sockaddr_storage *dst_addr; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6557 | char *ip; |
| 6558 | |
| 6559 | /* TODO: need to destroy on unload iscsi_endpoint*/ |
| 6560 | dst_addr = vmalloc(sizeof(*dst_addr)); |
| 6561 | if (!dst_addr) |
| 6562 | return NULL; |
| 6563 | |
| 6564 | if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6565 | t_addr = (struct sockaddr *)dst_addr; |
| 6566 | t_addr->sa_family = AF_INET6; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6567 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 6568 | ip = (char *)&addr6->sin6_addr; |
| 6569 | memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 6570 | addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 6571 | |
| 6572 | } else { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6573 | t_addr = (struct sockaddr *)dst_addr; |
| 6574 | t_addr->sa_family = AF_INET; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6575 | addr = (struct sockaddr_in *)dst_addr; |
| 6576 | ip = (char *)&addr->sin_addr; |
| 6577 | memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN); |
| 6578 | addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 6579 | } |
| 6580 | |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6581 | ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6582 | vfree(dst_addr); |
| 6583 | return ep; |
| 6584 | } |
| 6585 | |
| 6586 | static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx) |
| 6587 | { |
| 6588 | if (ql4xdisablesysfsboot) |
| 6589 | return QLA_SUCCESS; |
| 6590 | if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx) |
| 6591 | return QLA_ERROR; |
| 6592 | return QLA_SUCCESS; |
| 6593 | } |
| 6594 | |
| 6595 | static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6596 | struct ddb_entry *ddb_entry, |
| 6597 | uint16_t idx) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6598 | { |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6599 | uint16_t def_timeout; |
| 6600 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6601 | ddb_entry->ddb_type = FLASH_DDB; |
| 6602 | ddb_entry->fw_ddb_index = INVALID_ENTRY; |
| 6603 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 6604 | ddb_entry->ha = ha; |
| 6605 | ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb; |
| 6606 | ddb_entry->ddb_change = qla4xxx_flash_ddb_change; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 6607 | ddb_entry->chap_tbl_idx = INVALID_ENTRY; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6608 | |
| 6609 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 6610 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 6611 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6612 | def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6613 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6614 | (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ? |
| 6615 | def_timeout : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6616 | ddb_entry->default_time2wait = |
| 6617 | le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6618 | |
| 6619 | if (ql4xdisablesysfsboot && |
| 6620 | (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)) |
| 6621 | set_bit(DF_BOOT_TGT, &ddb_entry->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha) |
| 6625 | { |
| 6626 | uint32_t idx = 0; |
| 6627 | uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */ |
| 6628 | uint32_t sts[MBOX_REG_COUNT]; |
| 6629 | uint32_t ip_state; |
| 6630 | unsigned long wtime; |
| 6631 | int ret; |
| 6632 | |
| 6633 | wtime = jiffies + (HZ * IP_CONFIG_TOV); |
| 6634 | do { |
| 6635 | for (idx = 0; idx < IP_ADDR_COUNT; idx++) { |
| 6636 | if (ip_idx[idx] == -1) |
| 6637 | continue; |
| 6638 | |
| 6639 | ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts); |
| 6640 | |
| 6641 | if (ret == QLA_ERROR) { |
| 6642 | ip_idx[idx] = -1; |
| 6643 | continue; |
| 6644 | } |
| 6645 | |
| 6646 | ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT; |
| 6647 | |
| 6648 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6649 | "Waiting for IP state for idx = %d, state = 0x%x\n", |
| 6650 | ip_idx[idx], ip_state)); |
| 6651 | if (ip_state == IP_ADDRSTATE_UNCONFIGURED || |
| 6652 | ip_state == IP_ADDRSTATE_INVALID || |
| 6653 | ip_state == IP_ADDRSTATE_PREFERRED || |
| 6654 | ip_state == IP_ADDRSTATE_DEPRICATED || |
| 6655 | ip_state == IP_ADDRSTATE_DISABLING) |
| 6656 | ip_idx[idx] = -1; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | /* Break if all IP states checked */ |
| 6660 | if ((ip_idx[0] == -1) && |
| 6661 | (ip_idx[1] == -1) && |
| 6662 | (ip_idx[2] == -1) && |
| 6663 | (ip_idx[3] == -1)) |
| 6664 | break; |
| 6665 | schedule_timeout_uninterruptible(HZ); |
| 6666 | } while (time_after(wtime, jiffies)); |
| 6667 | } |
| 6668 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6669 | static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry, |
| 6670 | struct dev_db_entry *flash_ddb_entry) |
| 6671 | { |
| 6672 | uint16_t options = 0; |
| 6673 | size_t ip_len = IP_ADDR_LEN; |
| 6674 | |
| 6675 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6676 | if (options & DDB_OPT_IPV6_DEVICE) |
| 6677 | ip_len = IPv6_ADDR_LEN; |
| 6678 | |
| 6679 | if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len)) |
| 6680 | return QLA_ERROR; |
| 6681 | |
| 6682 | if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0], |
| 6683 | sizeof(fw_ddb_entry->isid))) |
| 6684 | return QLA_ERROR; |
| 6685 | |
| 6686 | if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port, |
| 6687 | sizeof(fw_ddb_entry->port))) |
| 6688 | return QLA_ERROR; |
| 6689 | |
| 6690 | return QLA_SUCCESS; |
| 6691 | } |
| 6692 | |
| 6693 | static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha, |
| 6694 | struct dev_db_entry *fw_ddb_entry, |
| 6695 | uint32_t fw_idx, uint32_t *flash_index) |
| 6696 | { |
| 6697 | struct dev_db_entry *flash_ddb_entry; |
| 6698 | dma_addr_t flash_ddb_entry_dma; |
| 6699 | uint32_t idx = 0; |
| 6700 | int max_ddbs; |
| 6701 | int ret = QLA_ERROR, status; |
| 6702 | |
| 6703 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6704 | MAX_DEV_DB_ENTRIES; |
| 6705 | |
| 6706 | flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6707 | &flash_ddb_entry_dma); |
| 6708 | if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) { |
| 6709 | ql4_printk(KERN_ERR, ha, "Out of memory\n"); |
| 6710 | goto exit_find_st_idx; |
| 6711 | } |
| 6712 | |
| 6713 | status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry, |
| 6714 | flash_ddb_entry_dma, fw_idx); |
| 6715 | if (status == QLA_SUCCESS) { |
| 6716 | status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry); |
| 6717 | if (status == QLA_SUCCESS) { |
| 6718 | *flash_index = fw_idx; |
| 6719 | ret = QLA_SUCCESS; |
| 6720 | goto exit_find_st_idx; |
| 6721 | } |
| 6722 | } |
| 6723 | |
| 6724 | for (idx = 0; idx < max_ddbs; idx++) { |
| 6725 | status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry, |
| 6726 | flash_ddb_entry_dma, idx); |
| 6727 | if (status == QLA_ERROR) |
| 6728 | continue; |
| 6729 | |
| 6730 | status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry); |
| 6731 | if (status == QLA_SUCCESS) { |
| 6732 | *flash_index = idx; |
| 6733 | ret = QLA_SUCCESS; |
| 6734 | goto exit_find_st_idx; |
| 6735 | } |
| 6736 | } |
| 6737 | |
| 6738 | if (idx == max_ddbs) |
| 6739 | ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n", |
| 6740 | fw_idx); |
| 6741 | |
| 6742 | exit_find_st_idx: |
| 6743 | if (flash_ddb_entry) |
| 6744 | dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry, |
| 6745 | flash_ddb_entry_dma); |
| 6746 | |
| 6747 | return ret; |
| 6748 | } |
| 6749 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6750 | static void qla4xxx_build_st_list(struct scsi_qla_host *ha, |
| 6751 | struct list_head *list_st) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6752 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6753 | struct qla_ddb_index *st_ddb_idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6754 | int max_ddbs; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6755 | int fw_idx_size; |
| 6756 | struct dev_db_entry *fw_ddb_entry; |
| 6757 | dma_addr_t fw_ddb_dma; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6758 | int ret; |
| 6759 | uint32_t idx = 0, next_idx = 0; |
| 6760 | uint32_t state = 0, conn_err = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6761 | uint32_t flash_index = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6762 | uint16_t conn_id = 0; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6763 | |
| 6764 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6765 | &fw_ddb_dma); |
| 6766 | if (fw_ddb_entry == NULL) { |
| 6767 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6768 | goto exit_st_list; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6769 | } |
| 6770 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6771 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6772 | MAX_DEV_DB_ENTRIES; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6773 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 6774 | |
| 6775 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6776 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 6777 | NULL, &next_idx, &state, |
| 6778 | &conn_err, NULL, &conn_id); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6779 | if (ret == QLA_ERROR) |
| 6780 | break; |
| 6781 | |
Lalit Chandivade | 981c982 | 2012-02-13 18:30:41 +0530 | [diff] [blame] | 6782 | /* Ignore DDB if invalid state (unassigned) */ |
| 6783 | if (state == DDB_DS_UNASSIGNED) |
| 6784 | goto continue_next_st; |
| 6785 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6786 | /* Check if ST, add to the list_st */ |
| 6787 | if (strlen((char *) fw_ddb_entry->iscsi_name) != 0) |
| 6788 | goto continue_next_st; |
| 6789 | |
| 6790 | st_ddb_idx = vzalloc(fw_idx_size); |
| 6791 | if (!st_ddb_idx) |
| 6792 | break; |
| 6793 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6794 | ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx, |
| 6795 | &flash_index); |
| 6796 | if (ret == QLA_ERROR) { |
| 6797 | ql4_printk(KERN_ERR, ha, |
| 6798 | "No flash entry for ST at idx [%d]\n", idx); |
| 6799 | st_ddb_idx->flash_ddb_idx = idx; |
| 6800 | } else { |
| 6801 | ql4_printk(KERN_INFO, ha, |
| 6802 | "ST at idx [%d] is stored at flash [%d]\n", |
| 6803 | idx, flash_index); |
| 6804 | st_ddb_idx->flash_ddb_idx = flash_index; |
| 6805 | } |
| 6806 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6807 | st_ddb_idx->fw_ddb_idx = idx; |
| 6808 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6809 | list_add_tail(&st_ddb_idx->list, list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6810 | continue_next_st: |
| 6811 | if (next_idx == 0) |
| 6812 | break; |
| 6813 | } |
| 6814 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6815 | exit_st_list: |
| 6816 | if (fw_ddb_entry) |
| 6817 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 6818 | } |
| 6819 | |
| 6820 | /** |
| 6821 | * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list |
| 6822 | * @ha: pointer to adapter structure |
| 6823 | * @list_ddb: List from which failed ddb to be removed |
| 6824 | * |
| 6825 | * Iterate over the list of DDBs and find and remove DDBs that are either in |
| 6826 | * no connection active state or failed state |
| 6827 | **/ |
| 6828 | static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha, |
| 6829 | struct list_head *list_ddb) |
| 6830 | { |
| 6831 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 6832 | uint32_t next_idx = 0; |
| 6833 | uint32_t state = 0, conn_err = 0; |
| 6834 | int ret; |
| 6835 | |
| 6836 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6837 | ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx, |
| 6838 | NULL, 0, NULL, &next_idx, &state, |
| 6839 | &conn_err, NULL, NULL); |
| 6840 | if (ret == QLA_ERROR) |
| 6841 | continue; |
| 6842 | |
| 6843 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 6844 | state == DDB_DS_SESSION_FAILED) { |
| 6845 | list_del_init(&ddb_idx->list); |
| 6846 | vfree(ddb_idx); |
| 6847 | } |
| 6848 | } |
| 6849 | } |
| 6850 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6851 | static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha, |
| 6852 | struct ddb_entry *ddb_entry, |
| 6853 | struct dev_db_entry *fw_ddb_entry) |
| 6854 | { |
| 6855 | struct iscsi_cls_session *cls_sess; |
| 6856 | struct iscsi_session *sess; |
| 6857 | uint32_t max_ddbs = 0; |
| 6858 | uint16_t ddb_link = -1; |
| 6859 | |
| 6860 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6861 | MAX_DEV_DB_ENTRIES; |
| 6862 | |
| 6863 | cls_sess = ddb_entry->sess; |
| 6864 | sess = cls_sess->dd_data; |
| 6865 | |
| 6866 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6867 | if (ddb_link < max_ddbs) |
| 6868 | sess->discovery_parent_idx = ddb_link; |
| 6869 | else |
| 6870 | sess->discovery_parent_idx = DDB_NO_LINK; |
| 6871 | } |
| 6872 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6873 | static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha, |
| 6874 | struct dev_db_entry *fw_ddb_entry, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6875 | int is_reset, uint16_t idx) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6876 | { |
| 6877 | struct iscsi_cls_session *cls_sess; |
| 6878 | struct iscsi_session *sess; |
| 6879 | struct iscsi_cls_conn *cls_conn; |
| 6880 | struct iscsi_endpoint *ep; |
| 6881 | uint16_t cmds_max = 32; |
| 6882 | uint16_t conn_id = 0; |
| 6883 | uint32_t initial_cmdsn = 0; |
| 6884 | int ret = QLA_SUCCESS; |
| 6885 | |
| 6886 | struct ddb_entry *ddb_entry = NULL; |
| 6887 | |
| 6888 | /* Create session object, with INVALID_ENTRY, |
| 6889 | * the targer_id would get set when we issue the login |
| 6890 | */ |
| 6891 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host, |
| 6892 | cmds_max, sizeof(struct ddb_entry), |
| 6893 | sizeof(struct ql4_task_data), |
| 6894 | initial_cmdsn, INVALID_ENTRY); |
| 6895 | if (!cls_sess) { |
| 6896 | ret = QLA_ERROR; |
| 6897 | goto exit_setup; |
| 6898 | } |
| 6899 | |
| 6900 | /* |
| 6901 | * so calling module_put function to decrement the |
| 6902 | * reference count. |
| 6903 | **/ |
| 6904 | module_put(qla4xxx_iscsi_transport.owner); |
| 6905 | sess = cls_sess->dd_data; |
| 6906 | ddb_entry = sess->dd_data; |
| 6907 | ddb_entry->sess = cls_sess; |
| 6908 | |
| 6909 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 6910 | memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry, |
| 6911 | sizeof(struct dev_db_entry)); |
| 6912 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6913 | qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6914 | |
| 6915 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id); |
| 6916 | |
| 6917 | if (!cls_conn) { |
| 6918 | ret = QLA_ERROR; |
| 6919 | goto exit_setup; |
| 6920 | } |
| 6921 | |
| 6922 | ddb_entry->conn = cls_conn; |
| 6923 | |
| 6924 | /* Setup ep, for displaying attributes in sysfs */ |
| 6925 | ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry); |
| 6926 | if (ep) { |
| 6927 | ep->conn = cls_conn; |
| 6928 | cls_conn->ep = ep; |
| 6929 | } else { |
| 6930 | DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n")); |
| 6931 | ret = QLA_ERROR; |
| 6932 | goto exit_setup; |
| 6933 | } |
| 6934 | |
| 6935 | /* Update sess/conn params */ |
| 6936 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6937 | qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6938 | |
| 6939 | if (is_reset == RESET_ADAPTER) { |
| 6940 | iscsi_block_session(cls_sess); |
| 6941 | /* Use the relogin path to discover new devices |
| 6942 | * by short-circuting the logic of setting |
| 6943 | * timer to relogin - instead set the flags |
| 6944 | * to initiate login right away. |
| 6945 | */ |
| 6946 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 6947 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 6948 | } |
| 6949 | |
| 6950 | exit_setup: |
| 6951 | return ret; |
| 6952 | } |
| 6953 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6954 | static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha, |
| 6955 | struct list_head *list_ddb, |
| 6956 | struct dev_db_entry *fw_ddb_entry) |
| 6957 | { |
| 6958 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 6959 | uint16_t ddb_link; |
| 6960 | |
| 6961 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6962 | |
| 6963 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6964 | if (ddb_idx->fw_ddb_idx == ddb_link) { |
| 6965 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6966 | "Updating NT parent idx from [%d] to [%d]\n", |
| 6967 | ddb_link, ddb_idx->flash_ddb_idx)); |
| 6968 | fw_ddb_entry->ddb_link = |
| 6969 | cpu_to_le16(ddb_idx->flash_ddb_idx); |
| 6970 | return; |
| 6971 | } |
| 6972 | } |
| 6973 | } |
| 6974 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6975 | static void qla4xxx_build_nt_list(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6976 | struct list_head *list_nt, |
| 6977 | struct list_head *list_st, |
| 6978 | int is_reset) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6979 | { |
| 6980 | struct dev_db_entry *fw_ddb_entry; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6981 | struct ddb_entry *ddb_entry = NULL; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6982 | dma_addr_t fw_ddb_dma; |
| 6983 | int max_ddbs; |
| 6984 | int fw_idx_size; |
| 6985 | int ret; |
| 6986 | uint32_t idx = 0, next_idx = 0; |
| 6987 | uint32_t state = 0, conn_err = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6988 | uint32_t ddb_idx = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6989 | uint16_t conn_id = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6990 | uint16_t ddb_link = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6991 | struct qla_ddb_index *nt_ddb_idx; |
| 6992 | |
| 6993 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6994 | &fw_ddb_dma); |
| 6995 | if (fw_ddb_entry == NULL) { |
| 6996 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 6997 | goto exit_nt_list; |
| 6998 | } |
| 6999 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 7000 | MAX_DEV_DB_ENTRIES; |
| 7001 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 7002 | |
| 7003 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 7004 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 7005 | NULL, &next_idx, &state, |
| 7006 | &conn_err, NULL, &conn_id); |
| 7007 | if (ret == QLA_ERROR) |
| 7008 | break; |
| 7009 | |
| 7010 | if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS) |
| 7011 | goto continue_next_nt; |
| 7012 | |
| 7013 | /* Check if NT, then add to list it */ |
| 7014 | if (strlen((char *) fw_ddb_entry->iscsi_name) == 0) |
| 7015 | goto continue_next_nt; |
| 7016 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7017 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 7018 | if (ddb_link < max_ddbs) |
| 7019 | qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry); |
| 7020 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7021 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE || |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7022 | state == DDB_DS_SESSION_FAILED) && |
| 7023 | (is_reset == INIT_ADAPTER)) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7024 | goto continue_next_nt; |
| 7025 | |
| 7026 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7027 | "Adding DDB to session = 0x%x\n", idx)); |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7028 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7029 | if (is_reset == INIT_ADAPTER) { |
| 7030 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 7031 | if (!nt_ddb_idx) |
| 7032 | break; |
| 7033 | |
| 7034 | nt_ddb_idx->fw_ddb_idx = idx; |
| 7035 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 7036 | /* Copy original isid as it may get updated in function |
| 7037 | * qla4xxx_update_isid(). We need original isid in |
| 7038 | * function qla4xxx_compare_tuple_ddb to find duplicate |
| 7039 | * target */ |
| 7040 | memcpy(&nt_ddb_idx->flash_isid[0], |
| 7041 | &fw_ddb_entry->isid[0], |
| 7042 | sizeof(nt_ddb_idx->flash_isid)); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7043 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 7044 | ret = qla4xxx_is_flash_ddb_exists(ha, list_nt, |
| 7045 | fw_ddb_entry); |
| 7046 | if (ret == QLA_SUCCESS) { |
| 7047 | /* free nt_ddb_idx and do not add to list_nt */ |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7048 | vfree(nt_ddb_idx); |
| 7049 | goto continue_next_nt; |
| 7050 | } |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 7051 | |
| 7052 | /* Copy updated isid */ |
| 7053 | memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry, |
| 7054 | sizeof(struct dev_db_entry)); |
| 7055 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7056 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 7057 | } else if (is_reset == RESET_ADAPTER) { |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7058 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, |
| 7059 | &ddb_idx); |
| 7060 | if (ret == QLA_SUCCESS) { |
| 7061 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, |
| 7062 | ddb_idx); |
| 7063 | if (ddb_entry != NULL) |
| 7064 | qla4xxx_update_sess_disc_idx(ha, |
| 7065 | ddb_entry, |
| 7066 | fw_ddb_entry); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7067 | goto continue_next_nt; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7068 | } |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7069 | } |
| 7070 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 7071 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7072 | if (ret == QLA_ERROR) |
| 7073 | goto exit_nt_list; |
| 7074 | |
| 7075 | continue_next_nt: |
| 7076 | if (next_idx == 0) |
| 7077 | break; |
| 7078 | } |
| 7079 | |
| 7080 | exit_nt_list: |
| 7081 | if (fw_ddb_entry) |
| 7082 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7083 | } |
| 7084 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7085 | static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7086 | struct list_head *list_nt, |
| 7087 | uint16_t target_id) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7088 | { |
| 7089 | struct dev_db_entry *fw_ddb_entry; |
| 7090 | dma_addr_t fw_ddb_dma; |
| 7091 | int max_ddbs; |
| 7092 | int fw_idx_size; |
| 7093 | int ret; |
| 7094 | uint32_t idx = 0, next_idx = 0; |
| 7095 | uint32_t state = 0, conn_err = 0; |
| 7096 | uint16_t conn_id = 0; |
| 7097 | struct qla_ddb_index *nt_ddb_idx; |
| 7098 | |
| 7099 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 7100 | &fw_ddb_dma); |
| 7101 | if (fw_ddb_entry == NULL) { |
| 7102 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 7103 | goto exit_new_nt_list; |
| 7104 | } |
| 7105 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 7106 | MAX_DEV_DB_ENTRIES; |
| 7107 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 7108 | |
| 7109 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 7110 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 7111 | NULL, &next_idx, &state, |
| 7112 | &conn_err, NULL, &conn_id); |
| 7113 | if (ret == QLA_ERROR) |
| 7114 | break; |
| 7115 | |
| 7116 | /* Check if NT, then add it to list */ |
| 7117 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
| 7118 | goto continue_next_new_nt; |
| 7119 | |
| 7120 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE)) |
| 7121 | goto continue_next_new_nt; |
| 7122 | |
| 7123 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7124 | "Adding DDB to session = 0x%x\n", idx)); |
| 7125 | |
| 7126 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 7127 | if (!nt_ddb_idx) |
| 7128 | break; |
| 7129 | |
| 7130 | nt_ddb_idx->fw_ddb_idx = idx; |
| 7131 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7132 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7133 | if (ret == QLA_SUCCESS) { |
| 7134 | /* free nt_ddb_idx and do not add to list_nt */ |
| 7135 | vfree(nt_ddb_idx); |
| 7136 | goto continue_next_new_nt; |
| 7137 | } |
| 7138 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7139 | if (target_id < max_ddbs) |
| 7140 | fw_ddb_entry->ddb_link = cpu_to_le16(target_id); |
| 7141 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7142 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 7143 | |
| 7144 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 7145 | idx); |
| 7146 | if (ret == QLA_ERROR) |
| 7147 | goto exit_new_nt_list; |
| 7148 | |
| 7149 | continue_next_new_nt: |
| 7150 | if (next_idx == 0) |
| 7151 | break; |
| 7152 | } |
| 7153 | |
| 7154 | exit_new_nt_list: |
| 7155 | if (fw_ddb_entry) |
| 7156 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7157 | } |
| 7158 | |
| 7159 | /** |
| 7160 | * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry |
| 7161 | * @dev: dev associated with the sysfs entry |
| 7162 | * @data: pointer to flashnode session object |
| 7163 | * |
| 7164 | * Returns: |
| 7165 | * 1: if flashnode entry is non-persistent |
| 7166 | * 0: if flashnode entry is persistent |
| 7167 | **/ |
| 7168 | static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data) |
| 7169 | { |
| 7170 | struct iscsi_bus_flash_session *fnode_sess; |
| 7171 | |
| 7172 | if (!iscsi_flashnode_bus_match(dev, NULL)) |
| 7173 | return 0; |
| 7174 | |
| 7175 | fnode_sess = iscsi_dev_to_flash_session(dev); |
| 7176 | |
| 7177 | return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT); |
| 7178 | } |
| 7179 | |
| 7180 | /** |
| 7181 | * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target |
| 7182 | * @ha: pointer to host |
| 7183 | * @fw_ddb_entry: flash ddb data |
| 7184 | * @idx: target index |
| 7185 | * @user: if set then this call is made from userland else from kernel |
| 7186 | * |
| 7187 | * Returns: |
| 7188 | * On sucess: QLA_SUCCESS |
| 7189 | * On failure: QLA_ERROR |
| 7190 | * |
| 7191 | * This create separate sysfs entries for session and connection attributes of |
| 7192 | * the given fw ddb entry. |
| 7193 | * If this is invoked as a result of a userspace call then the entry is marked |
| 7194 | * as nonpersistent using flash_state field. |
| 7195 | **/ |
Vikas Chaudhary | 28e02f1 | 2013-04-17 05:15:27 -0400 | [diff] [blame] | 7196 | static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha, |
| 7197 | struct dev_db_entry *fw_ddb_entry, |
| 7198 | uint16_t *idx, int user) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7199 | { |
| 7200 | struct iscsi_bus_flash_session *fnode_sess = NULL; |
| 7201 | struct iscsi_bus_flash_conn *fnode_conn = NULL; |
| 7202 | int rc = QLA_ERROR; |
| 7203 | |
| 7204 | fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx, |
| 7205 | &qla4xxx_iscsi_transport, 0); |
| 7206 | if (!fnode_sess) { |
| 7207 | ql4_printk(KERN_ERR, ha, |
| 7208 | "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n", |
| 7209 | __func__, *idx, ha->host_no); |
| 7210 | goto exit_tgt_create; |
| 7211 | } |
| 7212 | |
| 7213 | fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess, |
| 7214 | &qla4xxx_iscsi_transport, 0); |
| 7215 | if (!fnode_conn) { |
| 7216 | ql4_printk(KERN_ERR, ha, |
| 7217 | "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n", |
| 7218 | __func__, *idx, ha->host_no); |
| 7219 | goto free_sess; |
| 7220 | } |
| 7221 | |
| 7222 | if (user) { |
| 7223 | fnode_sess->flash_state = DEV_DB_NON_PERSISTENT; |
| 7224 | } else { |
| 7225 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 7226 | |
| 7227 | if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx) |
| 7228 | fnode_sess->is_boot_target = 1; |
| 7229 | else |
| 7230 | fnode_sess->is_boot_target = 0; |
| 7231 | } |
| 7232 | |
| 7233 | rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn, |
| 7234 | fw_ddb_entry); |
| 7235 | |
| 7236 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 7237 | __func__, fnode_sess->dev.kobj.name); |
| 7238 | |
| 7239 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 7240 | __func__, fnode_conn->dev.kobj.name); |
| 7241 | |
| 7242 | return QLA_SUCCESS; |
| 7243 | |
| 7244 | free_sess: |
| 7245 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 7246 | |
| 7247 | exit_tgt_create: |
| 7248 | return QLA_ERROR; |
| 7249 | } |
| 7250 | |
| 7251 | /** |
| 7252 | * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash |
| 7253 | * @shost: pointer to host |
| 7254 | * @buf: type of ddb entry (ipv4/ipv6) |
| 7255 | * @len: length of buf |
| 7256 | * |
| 7257 | * This creates new ddb entry in the flash by finding first free index and |
| 7258 | * storing default ddb there. And then create sysfs entry for the new ddb entry. |
| 7259 | **/ |
| 7260 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 7261 | int len) |
| 7262 | { |
| 7263 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7264 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7265 | dma_addr_t fw_ddb_entry_dma; |
| 7266 | struct device *dev; |
| 7267 | uint16_t idx = 0; |
| 7268 | uint16_t max_ddbs = 0; |
| 7269 | uint32_t options = 0; |
| 7270 | uint32_t rval = QLA_ERROR; |
| 7271 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7272 | if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) && |
| 7273 | strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) { |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7274 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n", |
| 7275 | __func__)); |
| 7276 | goto exit_ddb_add; |
| 7277 | } |
| 7278 | |
Adheer Chandravanshi | a957a7d | 2013-04-05 07:06:08 -0400 | [diff] [blame] | 7279 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7280 | MAX_DEV_DB_ENTRIES; |
| 7281 | |
| 7282 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7283 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7284 | if (!fw_ddb_entry) { |
| 7285 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7286 | "%s: Unable to allocate dma buffer\n", |
| 7287 | __func__)); |
| 7288 | goto exit_ddb_add; |
| 7289 | } |
| 7290 | |
| 7291 | dev = iscsi_find_flashnode_sess(ha->host, NULL, |
| 7292 | qla4xxx_sysfs_ddb_is_non_persistent); |
| 7293 | if (dev) { |
| 7294 | ql4_printk(KERN_ERR, ha, |
| 7295 | "%s: A non-persistent entry %s found\n", |
| 7296 | __func__, dev->kobj.name); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7297 | put_device(dev); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7298 | goto exit_ddb_add; |
| 7299 | } |
| 7300 | |
Adheer Chandravanshi | 9993757 | 2013-07-08 08:33:09 -0400 | [diff] [blame] | 7301 | /* Index 0 and 1 are reserved for boot target entries */ |
| 7302 | for (idx = 2; idx < max_ddbs; idx++) { |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7303 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, |
| 7304 | fw_ddb_entry_dma, idx)) |
| 7305 | break; |
| 7306 | } |
| 7307 | |
| 7308 | if (idx == max_ddbs) |
| 7309 | goto exit_ddb_add; |
| 7310 | |
| 7311 | if (!strncasecmp("ipv6", buf, 4)) |
| 7312 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7313 | |
| 7314 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7315 | if (rval == QLA_ERROR) |
| 7316 | goto exit_ddb_add; |
| 7317 | |
| 7318 | rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1); |
| 7319 | |
| 7320 | exit_ddb_add: |
| 7321 | if (fw_ddb_entry) |
| 7322 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7323 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7324 | if (rval == QLA_SUCCESS) |
| 7325 | return idx; |
| 7326 | else |
| 7327 | return -EIO; |
| 7328 | } |
| 7329 | |
| 7330 | /** |
| 7331 | * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash |
| 7332 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7333 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7334 | * |
| 7335 | * This writes the contents of target ddb buffer to Flash with a valid cookie |
| 7336 | * value in order to make the ddb entry persistent. |
| 7337 | **/ |
| 7338 | static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess, |
| 7339 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7340 | { |
| 7341 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7342 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7343 | uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
| 7344 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7345 | dma_addr_t fw_ddb_entry_dma; |
| 7346 | uint32_t options = 0; |
| 7347 | int rval = 0; |
| 7348 | |
| 7349 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7350 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7351 | if (!fw_ddb_entry) { |
| 7352 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7353 | "%s: Unable to allocate dma buffer\n", |
| 7354 | __func__)); |
| 7355 | rval = -ENOMEM; |
| 7356 | goto exit_ddb_apply; |
| 7357 | } |
| 7358 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7359 | if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7360 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7361 | |
| 7362 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7363 | if (rval == QLA_ERROR) |
| 7364 | goto exit_ddb_apply; |
| 7365 | |
| 7366 | dev_db_start_offset += (fnode_sess->target_id * |
| 7367 | sizeof(*fw_ddb_entry)); |
| 7368 | |
| 7369 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 7370 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 7371 | |
| 7372 | rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
| 7373 | sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT); |
| 7374 | |
| 7375 | if (rval == QLA_SUCCESS) { |
| 7376 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 7377 | ql4_printk(KERN_INFO, ha, |
| 7378 | "%s: flash node %u of host %lu written to flash\n", |
| 7379 | __func__, fnode_sess->target_id, ha->host_no); |
| 7380 | } else { |
| 7381 | rval = -EIO; |
| 7382 | ql4_printk(KERN_ERR, ha, |
| 7383 | "%s: Error while writing flash node %u of host %lu to flash\n", |
| 7384 | __func__, fnode_sess->target_id, ha->host_no); |
| 7385 | } |
| 7386 | |
| 7387 | exit_ddb_apply: |
| 7388 | if (fw_ddb_entry) |
| 7389 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7390 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7391 | return rval; |
| 7392 | } |
| 7393 | |
| 7394 | static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha, |
| 7395 | struct dev_db_entry *fw_ddb_entry, |
| 7396 | uint16_t idx) |
| 7397 | { |
| 7398 | struct dev_db_entry *ddb_entry = NULL; |
| 7399 | dma_addr_t ddb_entry_dma; |
| 7400 | unsigned long wtime; |
| 7401 | uint32_t mbx_sts = 0; |
| 7402 | uint32_t state = 0, conn_err = 0; |
| 7403 | uint16_t tmo = 0; |
| 7404 | int ret = 0; |
| 7405 | |
| 7406 | ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 7407 | &ddb_entry_dma, GFP_KERNEL); |
| 7408 | if (!ddb_entry) { |
| 7409 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7410 | "%s: Unable to allocate dma buffer\n", |
| 7411 | __func__)); |
| 7412 | return QLA_ERROR; |
| 7413 | } |
| 7414 | |
| 7415 | memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry)); |
| 7416 | |
| 7417 | ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts); |
| 7418 | if (ret != QLA_SUCCESS) { |
| 7419 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7420 | "%s: Unable to set ddb entry for index %d\n", |
| 7421 | __func__, idx)); |
| 7422 | goto exit_ddb_conn_open; |
| 7423 | } |
| 7424 | |
| 7425 | qla4xxx_conn_open(ha, idx); |
| 7426 | |
| 7427 | /* To ensure that sendtargets is done, wait for at least 12 secs */ |
| 7428 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 7429 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 7430 | ha->def_timeout : LOGIN_TOV); |
| 7431 | |
| 7432 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7433 | "Default time to wait for login to ddb %d\n", tmo)); |
| 7434 | |
| 7435 | wtime = jiffies + (HZ * tmo); |
| 7436 | do { |
| 7437 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, |
| 7438 | NULL, &state, &conn_err, NULL, |
| 7439 | NULL); |
| 7440 | if (ret == QLA_ERROR) |
| 7441 | continue; |
| 7442 | |
| 7443 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 7444 | state == DDB_DS_SESSION_FAILED) |
| 7445 | break; |
| 7446 | |
| 7447 | schedule_timeout_uninterruptible(HZ / 10); |
| 7448 | } while (time_after(wtime, jiffies)); |
| 7449 | |
| 7450 | exit_ddb_conn_open: |
| 7451 | if (ddb_entry) |
| 7452 | dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 7453 | ddb_entry, ddb_entry_dma); |
| 7454 | return ret; |
| 7455 | } |
| 7456 | |
| 7457 | static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7458 | struct dev_db_entry *fw_ddb_entry, |
| 7459 | uint16_t target_id) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7460 | { |
| 7461 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 7462 | struct list_head list_nt; |
| 7463 | uint16_t ddb_index; |
| 7464 | int ret = 0; |
| 7465 | |
| 7466 | if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) { |
| 7467 | ql4_printk(KERN_WARNING, ha, |
| 7468 | "%s: A discovery already in progress!\n", __func__); |
| 7469 | return QLA_ERROR; |
| 7470 | } |
| 7471 | |
| 7472 | INIT_LIST_HEAD(&list_nt); |
| 7473 | |
| 7474 | set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 7475 | |
| 7476 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 7477 | if (ret == QLA_ERROR) |
| 7478 | goto exit_login_st_clr_bit; |
| 7479 | |
| 7480 | ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index); |
| 7481 | if (ret == QLA_ERROR) |
| 7482 | goto exit_login_st; |
| 7483 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7484 | qla4xxx_build_new_nt_list(ha, &list_nt, target_id); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7485 | |
| 7486 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) { |
| 7487 | list_del_init(&ddb_idx->list); |
| 7488 | qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx); |
| 7489 | vfree(ddb_idx); |
| 7490 | } |
| 7491 | |
| 7492 | exit_login_st: |
| 7493 | if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) { |
| 7494 | ql4_printk(KERN_ERR, ha, |
| 7495 | "Unable to clear DDB index = 0x%x\n", ddb_index); |
| 7496 | } |
| 7497 | |
| 7498 | clear_bit(ddb_index, ha->ddb_idx_map); |
| 7499 | |
| 7500 | exit_login_st_clr_bit: |
| 7501 | clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 7502 | return ret; |
| 7503 | } |
| 7504 | |
| 7505 | static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha, |
| 7506 | struct dev_db_entry *fw_ddb_entry, |
| 7507 | uint16_t idx) |
| 7508 | { |
| 7509 | int ret = QLA_ERROR; |
| 7510 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7511 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7512 | if (ret != QLA_SUCCESS) |
| 7513 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 7514 | idx); |
| 7515 | else |
| 7516 | ret = -EPERM; |
| 7517 | |
| 7518 | return ret; |
| 7519 | } |
| 7520 | |
| 7521 | /** |
| 7522 | * qla4xxx_sysfs_ddb_login - Login to the specified target |
| 7523 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7524 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7525 | * |
| 7526 | * This logs in to the specified target |
| 7527 | **/ |
| 7528 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 7529 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7530 | { |
| 7531 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7532 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7533 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7534 | dma_addr_t fw_ddb_entry_dma; |
| 7535 | uint32_t options = 0; |
| 7536 | int ret = 0; |
| 7537 | |
| 7538 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) { |
| 7539 | ql4_printk(KERN_ERR, ha, |
| 7540 | "%s: Target info is not persistent\n", __func__); |
| 7541 | ret = -EIO; |
| 7542 | goto exit_ddb_login; |
| 7543 | } |
| 7544 | |
| 7545 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7546 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7547 | if (!fw_ddb_entry) { |
| 7548 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7549 | "%s: Unable to allocate dma buffer\n", |
| 7550 | __func__)); |
| 7551 | ret = -ENOMEM; |
| 7552 | goto exit_ddb_login; |
| 7553 | } |
| 7554 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7555 | if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7556 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7557 | |
| 7558 | ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7559 | if (ret == QLA_ERROR) |
| 7560 | goto exit_ddb_login; |
| 7561 | |
| 7562 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 7563 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 7564 | |
| 7565 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7566 | ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry, |
| 7567 | fnode_sess->target_id); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7568 | else |
| 7569 | ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry, |
| 7570 | fnode_sess->target_id); |
| 7571 | |
| 7572 | if (ret > 0) |
| 7573 | ret = -EIO; |
| 7574 | |
| 7575 | exit_ddb_login: |
| 7576 | if (fw_ddb_entry) |
| 7577 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7578 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7579 | return ret; |
| 7580 | } |
| 7581 | |
| 7582 | /** |
| 7583 | * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target |
| 7584 | * @cls_sess: pointer to session to be logged out |
| 7585 | * |
| 7586 | * This performs session log out from the specified target |
| 7587 | **/ |
| 7588 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess) |
| 7589 | { |
| 7590 | struct iscsi_session *sess; |
| 7591 | struct ddb_entry *ddb_entry = NULL; |
| 7592 | struct scsi_qla_host *ha; |
| 7593 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7594 | dma_addr_t fw_ddb_entry_dma; |
| 7595 | unsigned long flags; |
| 7596 | unsigned long wtime; |
| 7597 | uint32_t ddb_state; |
| 7598 | int options; |
| 7599 | int ret = 0; |
| 7600 | |
| 7601 | sess = cls_sess->dd_data; |
| 7602 | ddb_entry = sess->dd_data; |
| 7603 | ha = ddb_entry->ha; |
| 7604 | |
| 7605 | if (ddb_entry->ddb_type != FLASH_DDB) { |
| 7606 | ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n", |
| 7607 | __func__); |
| 7608 | ret = -ENXIO; |
| 7609 | goto exit_ddb_logout; |
| 7610 | } |
| 7611 | |
Adheer Chandravanshi | 37719c2 | 2013-04-05 07:06:07 -0400 | [diff] [blame] | 7612 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 7613 | ql4_printk(KERN_ERR, ha, |
| 7614 | "%s: Logout from boot target entry is not permitted.\n", |
| 7615 | __func__); |
| 7616 | ret = -EPERM; |
| 7617 | goto exit_ddb_logout; |
| 7618 | } |
| 7619 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7620 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7621 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7622 | if (!fw_ddb_entry) { |
| 7623 | ql4_printk(KERN_ERR, ha, |
| 7624 | "%s: Unable to allocate dma buffer\n", __func__); |
| 7625 | ret = -ENOMEM; |
| 7626 | goto exit_ddb_logout; |
| 7627 | } |
| 7628 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7629 | if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) |
| 7630 | goto ddb_logout_init; |
| 7631 | |
| 7632 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 7633 | fw_ddb_entry, fw_ddb_entry_dma, |
| 7634 | NULL, NULL, &ddb_state, NULL, |
| 7635 | NULL, NULL); |
| 7636 | if (ret == QLA_ERROR) |
| 7637 | goto ddb_logout_init; |
| 7638 | |
| 7639 | if (ddb_state == DDB_DS_SESSION_ACTIVE) |
| 7640 | goto ddb_logout_init; |
| 7641 | |
| 7642 | /* wait until next relogin is triggered using DF_RELOGIN and |
| 7643 | * clear DF_RELOGIN to avoid invocation of further relogin |
| 7644 | */ |
| 7645 | wtime = jiffies + (HZ * RELOGIN_TOV); |
| 7646 | do { |
| 7647 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 7648 | goto ddb_logout_init; |
| 7649 | |
| 7650 | schedule_timeout_uninterruptible(HZ); |
| 7651 | } while ((time_after(wtime, jiffies))); |
| 7652 | |
| 7653 | ddb_logout_init: |
| 7654 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 7655 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 7656 | |
| 7657 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 7658 | qla4xxx_session_logout_ddb(ha, ddb_entry, options); |
| 7659 | |
| 7660 | memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry)); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7661 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 7662 | do { |
| 7663 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 7664 | fw_ddb_entry, fw_ddb_entry_dma, |
| 7665 | NULL, NULL, &ddb_state, NULL, |
| 7666 | NULL, NULL); |
| 7667 | if (ret == QLA_ERROR) |
| 7668 | goto ddb_logout_clr_sess; |
| 7669 | |
| 7670 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 7671 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 7672 | goto ddb_logout_clr_sess; |
| 7673 | |
| 7674 | schedule_timeout_uninterruptible(HZ); |
| 7675 | } while ((time_after(wtime, jiffies))); |
| 7676 | |
| 7677 | ddb_logout_clr_sess: |
| 7678 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 7679 | /* |
| 7680 | * we have decremented the reference count of the driver |
| 7681 | * when we setup the session to have the driver unload |
| 7682 | * to be seamless without actually destroying the |
| 7683 | * session |
| 7684 | **/ |
| 7685 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 7686 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 7687 | |
| 7688 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 7689 | qla4xxx_free_ddb(ha, ddb_entry); |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7690 | clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7691 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 7692 | |
| 7693 | iscsi_session_teardown(ddb_entry->sess); |
| 7694 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7695 | clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7696 | ret = QLA_SUCCESS; |
| 7697 | |
| 7698 | exit_ddb_logout: |
| 7699 | if (fw_ddb_entry) |
| 7700 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7701 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7702 | return ret; |
| 7703 | } |
| 7704 | |
| 7705 | /** |
| 7706 | * qla4xxx_sysfs_ddb_logout - Logout from the specified target |
| 7707 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7708 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7709 | * |
| 7710 | * This performs log out from the specified target |
| 7711 | **/ |
| 7712 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 7713 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7714 | { |
| 7715 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7716 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7717 | struct ql4_tuple_ddb *flash_tddb = NULL; |
| 7718 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 7719 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7720 | struct ddb_entry *ddb_entry = NULL; |
| 7721 | dma_addr_t fw_ddb_dma; |
| 7722 | uint32_t next_idx = 0; |
| 7723 | uint32_t state = 0, conn_err = 0; |
| 7724 | uint16_t conn_id = 0; |
| 7725 | int idx, index; |
| 7726 | int status, ret = 0; |
| 7727 | |
| 7728 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 7729 | &fw_ddb_dma); |
| 7730 | if (fw_ddb_entry == NULL) { |
| 7731 | ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__); |
| 7732 | ret = -ENOMEM; |
| 7733 | goto exit_ddb_logout; |
| 7734 | } |
| 7735 | |
| 7736 | flash_tddb = vzalloc(sizeof(*flash_tddb)); |
| 7737 | if (!flash_tddb) { |
| 7738 | ql4_printk(KERN_WARNING, ha, |
| 7739 | "%s:Memory Allocation failed.\n", __func__); |
| 7740 | ret = -ENOMEM; |
| 7741 | goto exit_ddb_logout; |
| 7742 | } |
| 7743 | |
| 7744 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 7745 | if (!tmp_tddb) { |
| 7746 | ql4_printk(KERN_WARNING, ha, |
| 7747 | "%s:Memory Allocation failed.\n", __func__); |
| 7748 | ret = -ENOMEM; |
| 7749 | goto exit_ddb_logout; |
| 7750 | } |
| 7751 | |
| 7752 | if (!fnode_sess->targetname) { |
| 7753 | ql4_printk(KERN_ERR, ha, |
| 7754 | "%s:Cannot logout from SendTarget entry\n", |
| 7755 | __func__); |
| 7756 | ret = -EPERM; |
| 7757 | goto exit_ddb_logout; |
| 7758 | } |
| 7759 | |
| 7760 | if (fnode_sess->is_boot_target) { |
| 7761 | ql4_printk(KERN_ERR, ha, |
| 7762 | "%s: Logout from boot target entry is not permitted.\n", |
| 7763 | __func__); |
| 7764 | ret = -EPERM; |
| 7765 | goto exit_ddb_logout; |
| 7766 | } |
| 7767 | |
Rickard Strandqvist | bdbb966 | 2014-07-26 16:49:32 +0200 | [diff] [blame] | 7768 | strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname, |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7769 | ISCSI_NAME_SIZE); |
| 7770 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7771 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7772 | sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress); |
| 7773 | else |
| 7774 | sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress); |
| 7775 | |
| 7776 | flash_tddb->tpgt = fnode_sess->tpgt; |
| 7777 | flash_tddb->port = fnode_conn->port; |
| 7778 | |
| 7779 | COPY_ISID(flash_tddb->isid, fnode_sess->isid); |
| 7780 | |
| 7781 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 7782 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 7783 | if (ddb_entry == NULL) |
| 7784 | continue; |
| 7785 | |
| 7786 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 7787 | continue; |
| 7788 | |
| 7789 | index = ddb_entry->sess->target_id; |
| 7790 | status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry, |
| 7791 | fw_ddb_dma, NULL, &next_idx, |
| 7792 | &state, &conn_err, NULL, |
| 7793 | &conn_id); |
| 7794 | if (status == QLA_ERROR) { |
| 7795 | ret = -ENOMEM; |
| 7796 | break; |
| 7797 | } |
| 7798 | |
| 7799 | qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL); |
| 7800 | |
| 7801 | status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb, |
| 7802 | true); |
| 7803 | if (status == QLA_SUCCESS) { |
| 7804 | ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess); |
| 7805 | break; |
| 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | if (idx == MAX_DDB_ENTRIES) |
| 7810 | ret = -ESRCH; |
| 7811 | |
| 7812 | exit_ddb_logout: |
| 7813 | if (flash_tddb) |
| 7814 | vfree(flash_tddb); |
| 7815 | if (tmp_tddb) |
| 7816 | vfree(tmp_tddb); |
| 7817 | if (fw_ddb_entry) |
| 7818 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7819 | |
| 7820 | return ret; |
| 7821 | } |
| 7822 | |
| 7823 | static int |
| 7824 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 7825 | int param, char *buf) |
| 7826 | { |
| 7827 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7828 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7829 | struct iscsi_bus_flash_conn *fnode_conn; |
| 7830 | struct ql4_chap_table chap_tbl; |
| 7831 | struct device *dev; |
Adheer Chandravanshi | a2f7663 | 2013-07-08 08:33:08 -0400 | [diff] [blame] | 7832 | int parent_type; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7833 | int rc = 0; |
| 7834 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7835 | dev = iscsi_find_flashnode_conn(fnode_sess); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7836 | if (!dev) |
| 7837 | return -EIO; |
| 7838 | |
| 7839 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 7840 | |
| 7841 | switch (param) { |
| 7842 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 7843 | rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6); |
| 7844 | break; |
| 7845 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 7846 | rc = sprintf(buf, "%s\n", fnode_sess->portal_type); |
| 7847 | break; |
| 7848 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 7849 | rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable); |
| 7850 | break; |
| 7851 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 7852 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess); |
| 7853 | break; |
| 7854 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 7855 | rc = sprintf(buf, "%u\n", fnode_sess->entry_state); |
| 7856 | break; |
| 7857 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 7858 | rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en); |
| 7859 | break; |
| 7860 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 7861 | rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en); |
| 7862 | break; |
| 7863 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 7864 | rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en); |
| 7865 | break; |
| 7866 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 7867 | rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en); |
| 7868 | break; |
| 7869 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 7870 | rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en); |
| 7871 | break; |
| 7872 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 7873 | rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en); |
| 7874 | break; |
| 7875 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 7876 | rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en); |
| 7877 | break; |
| 7878 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 7879 | rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en); |
| 7880 | break; |
| 7881 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 7882 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en); |
| 7883 | break; |
| 7884 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 7885 | rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en); |
| 7886 | break; |
| 7887 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 7888 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional); |
| 7889 | break; |
| 7890 | case ISCSI_FLASHNODE_ERL: |
| 7891 | rc = sprintf(buf, "%u\n", fnode_sess->erl); |
| 7892 | break; |
| 7893 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 7894 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat); |
| 7895 | break; |
| 7896 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 7897 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable); |
| 7898 | break; |
| 7899 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 7900 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable); |
| 7901 | break; |
| 7902 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 7903 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale); |
| 7904 | break; |
| 7905 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 7906 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en); |
| 7907 | break; |
| 7908 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 7909 | rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable); |
| 7910 | break; |
| 7911 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 7912 | rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength); |
| 7913 | break; |
| 7914 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 7915 | rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength); |
| 7916 | break; |
| 7917 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 7918 | rc = sprintf(buf, "%u\n", fnode_sess->first_burst); |
| 7919 | break; |
| 7920 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 7921 | rc = sprintf(buf, "%u\n", fnode_sess->time2wait); |
| 7922 | break; |
| 7923 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 7924 | rc = sprintf(buf, "%u\n", fnode_sess->time2retain); |
| 7925 | break; |
| 7926 | case ISCSI_FLASHNODE_MAX_R2T: |
| 7927 | rc = sprintf(buf, "%u\n", fnode_sess->max_r2t); |
| 7928 | break; |
| 7929 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 7930 | rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout); |
| 7931 | break; |
| 7932 | case ISCSI_FLASHNODE_ISID: |
Oleksandr Khoshaba | d1d81bd | 2016-10-22 20:32:28 +0300 | [diff] [blame] | 7933 | rc = sprintf(buf, "%pm\n", fnode_sess->isid); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7934 | break; |
| 7935 | case ISCSI_FLASHNODE_TSID: |
| 7936 | rc = sprintf(buf, "%u\n", fnode_sess->tsid); |
| 7937 | break; |
| 7938 | case ISCSI_FLASHNODE_PORT: |
| 7939 | rc = sprintf(buf, "%d\n", fnode_conn->port); |
| 7940 | break; |
| 7941 | case ISCSI_FLASHNODE_MAX_BURST: |
| 7942 | rc = sprintf(buf, "%u\n", fnode_sess->max_burst); |
| 7943 | break; |
| 7944 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 7945 | rc = sprintf(buf, "%u\n", |
| 7946 | fnode_sess->default_taskmgmt_timeout); |
| 7947 | break; |
| 7948 | case ISCSI_FLASHNODE_IPADDR: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7949 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7950 | rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress); |
| 7951 | else |
| 7952 | rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress); |
| 7953 | break; |
| 7954 | case ISCSI_FLASHNODE_ALIAS: |
| 7955 | if (fnode_sess->targetalias) |
| 7956 | rc = sprintf(buf, "%s\n", fnode_sess->targetalias); |
| 7957 | else |
| 7958 | rc = sprintf(buf, "\n"); |
| 7959 | break; |
| 7960 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7961 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7962 | rc = sprintf(buf, "%pI6\n", |
| 7963 | fnode_conn->redirect_ipaddr); |
| 7964 | else |
| 7965 | rc = sprintf(buf, "%pI4\n", |
| 7966 | fnode_conn->redirect_ipaddr); |
| 7967 | break; |
| 7968 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 7969 | rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size); |
| 7970 | break; |
| 7971 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 7972 | rc = sprintf(buf, "%u\n", fnode_conn->local_port); |
| 7973 | break; |
| 7974 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 7975 | rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos); |
| 7976 | break; |
| 7977 | case ISCSI_FLASHNODE_IPV6_TC: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7978 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7979 | rc = sprintf(buf, "%u\n", |
| 7980 | fnode_conn->ipv6_traffic_class); |
| 7981 | else |
| 7982 | rc = sprintf(buf, "\n"); |
| 7983 | break; |
| 7984 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 7985 | rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label); |
| 7986 | break; |
| 7987 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7988 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7989 | rc = sprintf(buf, "%pI6\n", |
| 7990 | fnode_conn->link_local_ipv6_addr); |
| 7991 | else |
| 7992 | rc = sprintf(buf, "\n"); |
| 7993 | break; |
| 7994 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
Adheer Chandravanshi | a2f7663 | 2013-07-08 08:33:08 -0400 | [diff] [blame] | 7995 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7996 | break; |
| 7997 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 7998 | if (fnode_sess->discovery_parent_type == DDB_ISNS) |
| 7999 | parent_type = ISCSI_DISC_PARENT_ISNS; |
| 8000 | else if (fnode_sess->discovery_parent_type == DDB_NO_LINK) |
| 8001 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
Vikas Chaudhary | b6130ce | 2013-04-17 05:15:26 -0400 | [diff] [blame] | 8002 | else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8003 | parent_type = ISCSI_DISC_PARENT_SENDTGT; |
| 8004 | else |
| 8005 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
| 8006 | |
| 8007 | rc = sprintf(buf, "%s\n", |
| 8008 | iscsi_get_discovery_parent_name(parent_type)); |
| 8009 | break; |
| 8010 | case ISCSI_FLASHNODE_NAME: |
| 8011 | if (fnode_sess->targetname) |
| 8012 | rc = sprintf(buf, "%s\n", fnode_sess->targetname); |
| 8013 | else |
| 8014 | rc = sprintf(buf, "\n"); |
| 8015 | break; |
| 8016 | case ISCSI_FLASHNODE_TPGT: |
| 8017 | rc = sprintf(buf, "%u\n", fnode_sess->tpgt); |
| 8018 | break; |
| 8019 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 8020 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf); |
| 8021 | break; |
| 8022 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 8023 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf); |
| 8024 | break; |
| 8025 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 8026 | rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx); |
| 8027 | break; |
| 8028 | case ISCSI_FLASHNODE_USERNAME: |
| 8029 | if (fnode_sess->chap_auth_en) { |
| 8030 | qla4xxx_get_uni_chap_at_index(ha, |
| 8031 | chap_tbl.name, |
| 8032 | chap_tbl.secret, |
| 8033 | fnode_sess->chap_out_idx); |
| 8034 | rc = sprintf(buf, "%s\n", chap_tbl.name); |
| 8035 | } else { |
| 8036 | rc = sprintf(buf, "\n"); |
| 8037 | } |
| 8038 | break; |
| 8039 | case ISCSI_FLASHNODE_PASSWORD: |
| 8040 | if (fnode_sess->chap_auth_en) { |
| 8041 | qla4xxx_get_uni_chap_at_index(ha, |
| 8042 | chap_tbl.name, |
| 8043 | chap_tbl.secret, |
| 8044 | fnode_sess->chap_out_idx); |
| 8045 | rc = sprintf(buf, "%s\n", chap_tbl.secret); |
| 8046 | } else { |
| 8047 | rc = sprintf(buf, "\n"); |
| 8048 | } |
| 8049 | break; |
| 8050 | case ISCSI_FLASHNODE_STATSN: |
| 8051 | rc = sprintf(buf, "%u\n", fnode_conn->statsn); |
| 8052 | break; |
| 8053 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 8054 | rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn); |
| 8055 | break; |
| 8056 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 8057 | rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target); |
| 8058 | break; |
| 8059 | default: |
| 8060 | rc = -ENOSYS; |
| 8061 | break; |
| 8062 | } |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 8063 | |
| 8064 | put_device(dev); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8065 | return rc; |
| 8066 | } |
| 8067 | |
| 8068 | /** |
| 8069 | * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry |
| 8070 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 8071 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 8072 | * @data: Parameters and their values to update |
| 8073 | * @len: len of data |
| 8074 | * |
| 8075 | * This sets the parameter of flash ddb entry and writes them to flash |
| 8076 | **/ |
| 8077 | static int |
| 8078 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 8079 | struct iscsi_bus_flash_conn *fnode_conn, |
| 8080 | void *data, int len) |
| 8081 | { |
| 8082 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 8083 | struct scsi_qla_host *ha = to_qla_host(shost); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8084 | struct iscsi_flashnode_param_info *fnode_param; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8085 | struct ql4_chap_table chap_tbl; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8086 | struct nlattr *attr; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8087 | uint16_t chap_out_idx = INVALID_ENTRY; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8088 | int rc = QLA_ERROR; |
| 8089 | uint32_t rem = len; |
| 8090 | |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8091 | memset((void *)&chap_tbl, 0, sizeof(chap_tbl)); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8092 | nla_for_each_attr(attr, data, len, rem) { |
| 8093 | fnode_param = nla_data(attr); |
| 8094 | |
| 8095 | switch (fnode_param->param) { |
| 8096 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 8097 | fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0]; |
| 8098 | break; |
| 8099 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 8100 | memcpy(fnode_sess->portal_type, fnode_param->value, |
| 8101 | strlen(fnode_sess->portal_type)); |
| 8102 | break; |
| 8103 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 8104 | fnode_sess->auto_snd_tgt_disable = |
| 8105 | fnode_param->value[0]; |
| 8106 | break; |
| 8107 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 8108 | fnode_sess->discovery_sess = fnode_param->value[0]; |
| 8109 | break; |
| 8110 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 8111 | fnode_sess->entry_state = fnode_param->value[0]; |
| 8112 | break; |
| 8113 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 8114 | fnode_conn->hdrdgst_en = fnode_param->value[0]; |
| 8115 | break; |
| 8116 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 8117 | fnode_conn->datadgst_en = fnode_param->value[0]; |
| 8118 | break; |
| 8119 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 8120 | fnode_sess->imm_data_en = fnode_param->value[0]; |
| 8121 | break; |
| 8122 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 8123 | fnode_sess->initial_r2t_en = fnode_param->value[0]; |
| 8124 | break; |
| 8125 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 8126 | fnode_sess->dataseq_inorder_en = fnode_param->value[0]; |
| 8127 | break; |
| 8128 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 8129 | fnode_sess->pdu_inorder_en = fnode_param->value[0]; |
| 8130 | break; |
| 8131 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 8132 | fnode_sess->chap_auth_en = fnode_param->value[0]; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8133 | /* Invalidate chap index if chap auth is disabled */ |
| 8134 | if (!fnode_sess->chap_auth_en) |
| 8135 | fnode_sess->chap_out_idx = INVALID_ENTRY; |
| 8136 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8137 | break; |
| 8138 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 8139 | fnode_conn->snack_req_en = fnode_param->value[0]; |
| 8140 | break; |
| 8141 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 8142 | fnode_sess->discovery_logout_en = fnode_param->value[0]; |
| 8143 | break; |
| 8144 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 8145 | fnode_sess->bidi_chap_en = fnode_param->value[0]; |
| 8146 | break; |
| 8147 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 8148 | fnode_sess->discovery_auth_optional = |
| 8149 | fnode_param->value[0]; |
| 8150 | break; |
| 8151 | case ISCSI_FLASHNODE_ERL: |
| 8152 | fnode_sess->erl = fnode_param->value[0]; |
| 8153 | break; |
| 8154 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 8155 | fnode_conn->tcp_timestamp_stat = fnode_param->value[0]; |
| 8156 | break; |
| 8157 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 8158 | fnode_conn->tcp_nagle_disable = fnode_param->value[0]; |
| 8159 | break; |
| 8160 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 8161 | fnode_conn->tcp_wsf_disable = fnode_param->value[0]; |
| 8162 | break; |
| 8163 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 8164 | fnode_conn->tcp_timer_scale = fnode_param->value[0]; |
| 8165 | break; |
| 8166 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 8167 | fnode_conn->tcp_timestamp_en = fnode_param->value[0]; |
| 8168 | break; |
| 8169 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 8170 | fnode_conn->fragment_disable = fnode_param->value[0]; |
| 8171 | break; |
| 8172 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 8173 | fnode_conn->max_recv_dlength = |
| 8174 | *(unsigned *)fnode_param->value; |
| 8175 | break; |
| 8176 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 8177 | fnode_conn->max_xmit_dlength = |
| 8178 | *(unsigned *)fnode_param->value; |
| 8179 | break; |
| 8180 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 8181 | fnode_sess->first_burst = |
| 8182 | *(unsigned *)fnode_param->value; |
| 8183 | break; |
| 8184 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 8185 | fnode_sess->time2wait = *(uint16_t *)fnode_param->value; |
| 8186 | break; |
| 8187 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 8188 | fnode_sess->time2retain = |
| 8189 | *(uint16_t *)fnode_param->value; |
| 8190 | break; |
| 8191 | case ISCSI_FLASHNODE_MAX_R2T: |
| 8192 | fnode_sess->max_r2t = |
| 8193 | *(uint16_t *)fnode_param->value; |
| 8194 | break; |
| 8195 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 8196 | fnode_conn->keepalive_timeout = |
| 8197 | *(uint16_t *)fnode_param->value; |
| 8198 | break; |
| 8199 | case ISCSI_FLASHNODE_ISID: |
| 8200 | memcpy(fnode_sess->isid, fnode_param->value, |
| 8201 | sizeof(fnode_sess->isid)); |
| 8202 | break; |
| 8203 | case ISCSI_FLASHNODE_TSID: |
| 8204 | fnode_sess->tsid = *(uint16_t *)fnode_param->value; |
| 8205 | break; |
| 8206 | case ISCSI_FLASHNODE_PORT: |
| 8207 | fnode_conn->port = *(uint16_t *)fnode_param->value; |
| 8208 | break; |
| 8209 | case ISCSI_FLASHNODE_MAX_BURST: |
| 8210 | fnode_sess->max_burst = *(unsigned *)fnode_param->value; |
| 8211 | break; |
| 8212 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 8213 | fnode_sess->default_taskmgmt_timeout = |
| 8214 | *(uint16_t *)fnode_param->value; |
| 8215 | break; |
| 8216 | case ISCSI_FLASHNODE_IPADDR: |
| 8217 | memcpy(fnode_conn->ipaddress, fnode_param->value, |
| 8218 | IPv6_ADDR_LEN); |
| 8219 | break; |
| 8220 | case ISCSI_FLASHNODE_ALIAS: |
| 8221 | rc = iscsi_switch_str_param(&fnode_sess->targetalias, |
| 8222 | (char *)fnode_param->value); |
| 8223 | break; |
| 8224 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 8225 | memcpy(fnode_conn->redirect_ipaddr, fnode_param->value, |
| 8226 | IPv6_ADDR_LEN); |
| 8227 | break; |
| 8228 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 8229 | fnode_conn->max_segment_size = |
| 8230 | *(unsigned *)fnode_param->value; |
| 8231 | break; |
| 8232 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 8233 | fnode_conn->local_port = |
| 8234 | *(uint16_t *)fnode_param->value; |
| 8235 | break; |
| 8236 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 8237 | fnode_conn->ipv4_tos = fnode_param->value[0]; |
| 8238 | break; |
| 8239 | case ISCSI_FLASHNODE_IPV6_TC: |
| 8240 | fnode_conn->ipv6_traffic_class = fnode_param->value[0]; |
| 8241 | break; |
| 8242 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 8243 | fnode_conn->ipv6_flow_label = fnode_param->value[0]; |
| 8244 | break; |
| 8245 | case ISCSI_FLASHNODE_NAME: |
| 8246 | rc = iscsi_switch_str_param(&fnode_sess->targetname, |
| 8247 | (char *)fnode_param->value); |
| 8248 | break; |
| 8249 | case ISCSI_FLASHNODE_TPGT: |
| 8250 | fnode_sess->tpgt = *(uint16_t *)fnode_param->value; |
| 8251 | break; |
| 8252 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 8253 | memcpy(fnode_conn->link_local_ipv6_addr, |
| 8254 | fnode_param->value, IPv6_ADDR_LEN); |
| 8255 | break; |
Adheer Chandravanshi | 6556016 | 2013-07-08 08:33:06 -0400 | [diff] [blame] | 8256 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 8257 | fnode_sess->discovery_parent_idx = |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8258 | *(uint16_t *)fnode_param->value; |
| 8259 | break; |
| 8260 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 8261 | fnode_conn->tcp_xmit_wsf = |
| 8262 | *(uint8_t *)fnode_param->value; |
| 8263 | break; |
| 8264 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 8265 | fnode_conn->tcp_recv_wsf = |
| 8266 | *(uint8_t *)fnode_param->value; |
| 8267 | break; |
| 8268 | case ISCSI_FLASHNODE_STATSN: |
| 8269 | fnode_conn->statsn = *(uint32_t *)fnode_param->value; |
| 8270 | break; |
| 8271 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 8272 | fnode_conn->exp_statsn = |
| 8273 | *(uint32_t *)fnode_param->value; |
| 8274 | break; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8275 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 8276 | chap_out_idx = *(uint16_t *)fnode_param->value; |
| 8277 | if (!qla4xxx_get_uni_chap_at_index(ha, |
| 8278 | chap_tbl.name, |
| 8279 | chap_tbl.secret, |
| 8280 | chap_out_idx)) { |
| 8281 | fnode_sess->chap_out_idx = chap_out_idx; |
| 8282 | /* Enable chap auth if chap index is valid */ |
| 8283 | fnode_sess->chap_auth_en = QL4_PARAM_ENABLE; |
| 8284 | } |
| 8285 | break; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8286 | default: |
| 8287 | ql4_printk(KERN_ERR, ha, |
| 8288 | "%s: No such sysfs attribute\n", __func__); |
| 8289 | rc = -ENOSYS; |
| 8290 | goto exit_set_param; |
| 8291 | } |
| 8292 | } |
| 8293 | |
| 8294 | rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn); |
| 8295 | |
| 8296 | exit_set_param: |
| 8297 | return rc; |
| 8298 | } |
| 8299 | |
| 8300 | /** |
| 8301 | * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry |
| 8302 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 8303 | * |
| 8304 | * This invalidates the flash ddb entry at the given index |
| 8305 | **/ |
| 8306 | static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess) |
| 8307 | { |
| 8308 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 8309 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 8310 | uint32_t dev_db_start_offset; |
| 8311 | uint32_t dev_db_end_offset; |
| 8312 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8313 | dma_addr_t fw_ddb_entry_dma; |
| 8314 | uint16_t *ddb_cookie = NULL; |
Vikas Chaudhary | b6130ce | 2013-04-17 05:15:26 -0400 | [diff] [blame] | 8315 | size_t ddb_size = 0; |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8316 | void *pddb = NULL; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8317 | int target_id; |
| 8318 | int rc = 0; |
| 8319 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8320 | if (fnode_sess->is_boot_target) { |
| 8321 | rc = -EPERM; |
| 8322 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8323 | "%s: Deletion of boot target entry is not permitted.\n", |
| 8324 | __func__)); |
| 8325 | goto exit_ddb_del; |
| 8326 | } |
| 8327 | |
| 8328 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) |
| 8329 | goto sysfs_ddb_del; |
| 8330 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8331 | if (is_qla40XX(ha)) { |
| 8332 | dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8333 | dev_db_end_offset = FLASH_OFFSET_DB_END; |
| 8334 | dev_db_start_offset += (fnode_sess->target_id * |
| 8335 | sizeof(*fw_ddb_entry)); |
| 8336 | ddb_size = sizeof(*fw_ddb_entry); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8337 | } else { |
| 8338 | dev_db_start_offset = FLASH_RAW_ACCESS_ADDR + |
| 8339 | (ha->hw.flt_region_ddb << 2); |
| 8340 | /* flt_ddb_size is DDB table size for both ports |
| 8341 | * so divide it by 2 to calculate the offset for second port |
| 8342 | */ |
| 8343 | if (ha->port_num == 1) |
| 8344 | dev_db_start_offset += (ha->hw.flt_ddb_size / 2); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8345 | |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8346 | dev_db_end_offset = dev_db_start_offset + |
| 8347 | (ha->hw.flt_ddb_size / 2); |
| 8348 | |
| 8349 | dev_db_start_offset += (fnode_sess->target_id * |
| 8350 | sizeof(*fw_ddb_entry)); |
Adheer Chandravanshi | 1bcb561 | 2013-04-17 05:15:28 -0400 | [diff] [blame] | 8351 | dev_db_start_offset += offsetof(struct dev_db_entry, cookie); |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8352 | |
| 8353 | ddb_size = sizeof(*ddb_cookie); |
| 8354 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8355 | |
| 8356 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n", |
| 8357 | __func__, dev_db_start_offset, dev_db_end_offset)); |
| 8358 | |
| 8359 | if (dev_db_start_offset > dev_db_end_offset) { |
| 8360 | rc = -EIO; |
| 8361 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n", |
| 8362 | __func__, fnode_sess->target_id)); |
| 8363 | goto exit_ddb_del; |
| 8364 | } |
| 8365 | |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8366 | pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size, |
| 8367 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8368 | if (!pddb) { |
| 8369 | rc = -ENOMEM; |
| 8370 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8371 | "%s: Unable to allocate dma buffer\n", |
| 8372 | __func__)); |
| 8373 | goto exit_ddb_del; |
| 8374 | } |
| 8375 | |
| 8376 | if (is_qla40XX(ha)) { |
| 8377 | fw_ddb_entry = pddb; |
| 8378 | memset(fw_ddb_entry, 0, ddb_size); |
| 8379 | ddb_cookie = &fw_ddb_entry->cookie; |
| 8380 | } else { |
| 8381 | ddb_cookie = pddb; |
| 8382 | } |
| 8383 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8384 | /* invalidate the cookie */ |
| 8385 | *ddb_cookie = 0xFFEE; |
| 8386 | qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8387 | ddb_size, FLASH_OPT_RMW_COMMIT); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8388 | |
| 8389 | sysfs_ddb_del: |
| 8390 | target_id = fnode_sess->target_id; |
| 8391 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 8392 | ql4_printk(KERN_INFO, ha, |
| 8393 | "%s: session and conn entries for flashnode %u of host %lu deleted\n", |
| 8394 | __func__, target_id, ha->host_no); |
| 8395 | exit_ddb_del: |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8396 | if (pddb) |
| 8397 | dma_free_coherent(&ha->pdev->dev, ddb_size, pddb, |
| 8398 | fw_ddb_entry_dma); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8399 | return rc; |
| 8400 | } |
| 8401 | |
| 8402 | /** |
| 8403 | * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs |
| 8404 | * @ha: pointer to adapter structure |
| 8405 | * |
| 8406 | * Export the firmware DDB for all send targets and normal targets to sysfs. |
| 8407 | **/ |
Nilesh Javali | 906cbf3 | 2014-04-09 21:12:25 -0400 | [diff] [blame] | 8408 | int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8409 | { |
| 8410 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8411 | dma_addr_t fw_ddb_entry_dma; |
| 8412 | uint16_t max_ddbs; |
| 8413 | uint16_t idx = 0; |
| 8414 | int ret = QLA_SUCCESS; |
| 8415 | |
| 8416 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
| 8417 | sizeof(*fw_ddb_entry), |
| 8418 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8419 | if (!fw_ddb_entry) { |
| 8420 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8421 | "%s: Unable to allocate dma buffer\n", |
| 8422 | __func__)); |
| 8423 | return -ENOMEM; |
| 8424 | } |
| 8425 | |
Adheer Chandravanshi | a957a7d | 2013-04-05 07:06:08 -0400 | [diff] [blame] | 8426 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8427 | MAX_DEV_DB_ENTRIES; |
| 8428 | |
| 8429 | for (idx = 0; idx < max_ddbs; idx++) { |
| 8430 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma, |
| 8431 | idx)) |
| 8432 | continue; |
| 8433 | |
| 8434 | ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0); |
| 8435 | if (ret) { |
| 8436 | ret = -EIO; |
| 8437 | break; |
| 8438 | } |
| 8439 | } |
| 8440 | |
| 8441 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry, |
| 8442 | fw_ddb_entry_dma); |
| 8443 | |
| 8444 | return ret; |
| 8445 | } |
| 8446 | |
| 8447 | static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha) |
| 8448 | { |
| 8449 | iscsi_destroy_all_flashnode(ha->host); |
| 8450 | } |
| 8451 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8452 | /** |
| 8453 | * qla4xxx_build_ddb_list - Build ddb list and setup sessions |
| 8454 | * @ha: pointer to adapter structure |
| 8455 | * @is_reset: Is this init path or reset path |
| 8456 | * |
| 8457 | * Create a list of sendtargets (st) from firmware DDBs, issue send targets |
| 8458 | * using connection open, then create the list of normal targets (nt) |
| 8459 | * from firmware DDBs. Based on the list of nt setup session and connection |
| 8460 | * objects. |
| 8461 | **/ |
| 8462 | void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset) |
| 8463 | { |
| 8464 | uint16_t tmo = 0; |
| 8465 | struct list_head list_st, list_nt; |
| 8466 | struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp; |
| 8467 | unsigned long wtime; |
| 8468 | |
| 8469 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 8470 | set_bit(AF_BUILD_DDB_LIST, &ha->flags); |
| 8471 | ha->is_reset = is_reset; |
| 8472 | return; |
| 8473 | } |
| 8474 | |
| 8475 | INIT_LIST_HEAD(&list_st); |
| 8476 | INIT_LIST_HEAD(&list_nt); |
| 8477 | |
| 8478 | qla4xxx_build_st_list(ha, &list_st); |
| 8479 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8480 | /* Before issuing conn open mbox, ensure all IPs states are configured |
| 8481 | * Note, conn open fails if IPs are not configured |
| 8482 | */ |
| 8483 | qla4xxx_wait_for_ip_configuration(ha); |
| 8484 | |
| 8485 | /* Go thru the STs and fire the sendtargets by issuing conn open mbx */ |
| 8486 | list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) { |
| 8487 | qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx); |
| 8488 | } |
| 8489 | |
| 8490 | /* Wait to ensure all sendtargets are done for min 12 sec wait */ |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 8491 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 8492 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 8493 | ha->def_timeout : LOGIN_TOV); |
| 8494 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8495 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8496 | "Default time to wait for build ddb %d\n", tmo)); |
| 8497 | |
| 8498 | wtime = jiffies + (HZ * tmo); |
| 8499 | do { |
Nilesh Javali | f1f2e60 | 2011-12-16 01:58:57 -0800 | [diff] [blame] | 8500 | if (list_empty(&list_st)) |
| 8501 | break; |
| 8502 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8503 | qla4xxx_remove_failed_ddb(ha, &list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8504 | schedule_timeout_uninterruptible(HZ / 10); |
| 8505 | } while (time_after(wtime, jiffies)); |
| 8506 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 8507 | |
| 8508 | qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset); |
| 8509 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8510 | qla4xxx_free_ddb_list(&list_st); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8511 | qla4xxx_free_ddb_list(&list_nt); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8512 | |
| 8513 | qla4xxx_free_ddb_index(ha); |
| 8514 | } |
| 8515 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8516 | /** |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 8517 | * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login |
| 8518 | * response. |
| 8519 | * @ha: pointer to adapter structure |
| 8520 | * |
| 8521 | * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be |
| 8522 | * set in DDB and we will wait for login response of boot targets during |
| 8523 | * probe. |
| 8524 | **/ |
| 8525 | static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha) |
| 8526 | { |
| 8527 | struct ddb_entry *ddb_entry; |
| 8528 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8529 | dma_addr_t fw_ddb_entry_dma; |
| 8530 | unsigned long wtime; |
| 8531 | uint32_t ddb_state; |
| 8532 | int max_ddbs, idx, ret; |
| 8533 | |
| 8534 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 8535 | MAX_DEV_DB_ENTRIES; |
| 8536 | |
| 8537 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8538 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8539 | if (!fw_ddb_entry) { |
| 8540 | ql4_printk(KERN_ERR, ha, |
| 8541 | "%s: Unable to allocate dma buffer\n", __func__); |
| 8542 | goto exit_login_resp; |
| 8543 | } |
| 8544 | |
| 8545 | wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV); |
| 8546 | |
| 8547 | for (idx = 0; idx < max_ddbs; idx++) { |
| 8548 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 8549 | if (ddb_entry == NULL) |
| 8550 | continue; |
| 8551 | |
| 8552 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 8553 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8554 | "%s: DDB index [%d]\n", __func__, |
| 8555 | ddb_entry->fw_ddb_index)); |
| 8556 | do { |
| 8557 | ret = qla4xxx_get_fwddb_entry(ha, |
| 8558 | ddb_entry->fw_ddb_index, |
| 8559 | fw_ddb_entry, fw_ddb_entry_dma, |
| 8560 | NULL, NULL, &ddb_state, NULL, |
| 8561 | NULL, NULL); |
| 8562 | if (ret == QLA_ERROR) |
| 8563 | goto exit_login_resp; |
| 8564 | |
| 8565 | if ((ddb_state == DDB_DS_SESSION_ACTIVE) || |
| 8566 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 8567 | break; |
| 8568 | |
| 8569 | schedule_timeout_uninterruptible(HZ); |
| 8570 | |
| 8571 | } while ((time_after(wtime, jiffies))); |
| 8572 | |
| 8573 | if (!time_after(wtime, jiffies)) { |
| 8574 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8575 | "%s: Login response wait timer expired\n", |
| 8576 | __func__)); |
| 8577 | goto exit_login_resp; |
| 8578 | } |
| 8579 | } |
| 8580 | } |
| 8581 | |
| 8582 | exit_login_resp: |
| 8583 | if (fw_ddb_entry) |
| 8584 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8585 | fw_ddb_entry, fw_ddb_entry_dma); |
| 8586 | } |
| 8587 | |
| 8588 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8589 | * qla4xxx_probe_adapter - callback function to probe HBA |
| 8590 | * @pdev: pointer to pci_dev structure |
| 8591 | * @pci_device_id: pointer to pci_device entry |
| 8592 | * |
| 8593 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. |
| 8594 | * It returns zero if successful. It also initializes all data necessary for |
| 8595 | * the driver. |
| 8596 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8597 | static int qla4xxx_probe_adapter(struct pci_dev *pdev, |
| 8598 | const struct pci_device_id *ent) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8599 | { |
| 8600 | int ret = -ENODEV, status; |
| 8601 | struct Scsi_Host *host; |
| 8602 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8603 | uint8_t init_retry_count = 0; |
| 8604 | char buf[34]; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8605 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8606 | uint32_t dev_state; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8607 | |
| 8608 | if (pci_enable_device(pdev)) |
| 8609 | return -1; |
| 8610 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8611 | host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8612 | if (host == NULL) { |
| 8613 | printk(KERN_WARNING |
| 8614 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); |
| 8615 | goto probe_disable_device; |
| 8616 | } |
| 8617 | |
| 8618 | /* Clear our data area */ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8619 | ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8620 | memset(ha, 0, sizeof(*ha)); |
| 8621 | |
| 8622 | /* Save the information from PCI BIOS. */ |
| 8623 | ha->pdev = pdev; |
| 8624 | ha->host = host; |
| 8625 | ha->host_no = host->host_no; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8626 | ha->func_num = PCI_FUNC(ha->pdev->devfn); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8627 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8628 | pci_enable_pcie_error_reporting(pdev); |
| 8629 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8630 | /* Setup Runtime configurable options */ |
| 8631 | if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 8632 | ha->isp_ops = &qla4_82xx_isp_ops; |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8633 | ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8634 | ha->qdr_sn_window = -1; |
| 8635 | ha->ddr_mn_window = -1; |
| 8636 | ha->curr_window = 255; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8637 | nx_legacy_intr = &legacy_intr[ha->func_num]; |
| 8638 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; |
| 8639 | ha->nx_legacy_intr.tgt_status_reg = |
| 8640 | nx_legacy_intr->tgt_status_reg; |
| 8641 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; |
| 8642 | ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg; |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8643 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8644 | ha->isp_ops = &qla4_83xx_isp_ops; |
| 8645 | ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8646 | } else { |
| 8647 | ha->isp_ops = &qla4xxx_isp_ops; |
| 8648 | } |
| 8649 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8650 | if (is_qla80XX(ha)) { |
| 8651 | rwlock_init(&ha->hw_lock); |
| 8652 | ha->pf_bit = ha->func_num << 16; |
| 8653 | /* Set EEH reset type to fundamental if required by hba */ |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8654 | pdev->needs_freset = 1; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8655 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8656 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8657 | /* Configure PCI I/O space. */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8658 | ret = ha->isp_ops->iospace_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8659 | if (ret) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8660 | goto probe_failed_ioconfig; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8661 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8662 | 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] | 8663 | pdev->device, pdev->irq, ha->reg); |
| 8664 | |
| 8665 | qla4xxx_config_dma_addressing(ha); |
| 8666 | |
| 8667 | /* Initialize lists and spinlocks. */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8668 | INIT_LIST_HEAD(&ha->free_srb_q); |
| 8669 | |
| 8670 | mutex_init(&ha->mbox_sem); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 8671 | mutex_init(&ha->chap_sem); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8672 | init_completion(&ha->mbx_intr_comp); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 8673 | init_completion(&ha->disable_acb_comp); |
Vikas Chaudhary | df86f77 | 2013-11-22 05:28:17 -0500 | [diff] [blame] | 8674 | init_completion(&ha->idc_comp); |
| 8675 | init_completion(&ha->link_up_comp); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8676 | |
| 8677 | spin_lock_init(&ha->hardware_lock); |
Vikas Chaudhary | 8e9157c | 2012-08-22 07:45:24 -0400 | [diff] [blame] | 8678 | spin_lock_init(&ha->work_lock); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8679 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 8680 | /* Initialize work list */ |
| 8681 | INIT_LIST_HEAD(&ha->work_list); |
| 8682 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8683 | /* Allocate dma buffers */ |
| 8684 | if (qla4xxx_mem_alloc(ha)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8685 | ql4_printk(KERN_WARNING, ha, |
| 8686 | "[ERROR] Failed to allocate memory for adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8687 | |
| 8688 | ret = -ENOMEM; |
| 8689 | goto probe_failed; |
| 8690 | } |
| 8691 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8692 | host->cmd_per_lun = 3; |
| 8693 | host->max_channel = 0; |
| 8694 | host->max_lun = MAX_LUNS - 1; |
| 8695 | host->max_id = MAX_TARGETS; |
| 8696 | host->max_cmd_len = IOCB_MAX_CDB_LEN; |
| 8697 | host->can_queue = MAX_SRBS ; |
| 8698 | host->transportt = qla4xxx_scsi_transport; |
| 8699 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8700 | pci_set_drvdata(pdev, ha); |
| 8701 | |
| 8702 | ret = scsi_add_host(host, &pdev->dev); |
| 8703 | if (ret) |
| 8704 | goto probe_failed; |
| 8705 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8706 | if (is_qla80XX(ha)) |
| 8707 | qla4_8xxx_get_flash_info(ha); |
| 8708 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8709 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8710 | qla4_83xx_read_reset_template(ha); |
| 8711 | /* |
| 8712 | * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 8713 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 8714 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 8715 | * should honor the reset. |
| 8716 | */ |
| 8717 | if (ql4xdontresethba == 1) |
| 8718 | qla4_83xx_set_idc_dontreset(ha); |
| 8719 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8720 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8721 | /* |
| 8722 | * Initialize the Host adapter request/response queues and |
| 8723 | * firmware |
| 8724 | * NOTE: interrupts enabled upon successful completion |
| 8725 | */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8726 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8727 | |
| 8728 | /* Dont retry adapter initialization if IRQ allocation failed */ |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 8729 | if (is_qla80XX(ha) && (status == QLA_ERROR)) |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8730 | goto skip_retry_init; |
| 8731 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8732 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
| 8733 | init_retry_count++ < MAX_INIT_RETRIES) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8734 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8735 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8736 | ha->isp_ops->idc_lock(ha); |
| 8737 | dev_state = qla4_8xxx_rd_direct(ha, |
Vikas Chaudhary | e951aca | 2012-12-29 02:24:52 -0500 | [diff] [blame] | 8738 | QLA8XXX_CRB_DEV_STATE); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8739 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 8740 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8741 | ql4_printk(KERN_WARNING, ha, "%s: don't retry " |
| 8742 | "initialize adapter. H/W is in failed state\n", |
| 8743 | __func__); |
| 8744 | break; |
| 8745 | } |
| 8746 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8747 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
| 8748 | "(%d)\n", __func__, init_retry_count)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8749 | |
| 8750 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) |
| 8751 | continue; |
| 8752 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8753 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 8754 | if (is_qla80XX(ha) && (status == QLA_ERROR)) { |
| 8755 | if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR) |
| 8756 | goto skip_retry_init; |
| 8757 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8758 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8759 | |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8760 | skip_retry_init: |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8761 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8762 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8763 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8764 | if ((is_qla8022(ha) && ql4xdontresethba) || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8765 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 8766 | qla4_83xx_idc_dontreset(ha))) { |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 8767 | /* Put the device in failed state. */ |
| 8768 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8769 | ha->isp_ops->idc_lock(ha); |
| 8770 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 8771 | QLA8XXX_DEV_FAILED); |
| 8772 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 8773 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8774 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8775 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8776 | } |
| 8777 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8778 | /* Startup the kernel thread for this host adapter. */ |
| 8779 | DEBUG2(printk("scsi: %s: Starting kernel thread for " |
| 8780 | "qla4xxx_dpc\n", __func__)); |
| 8781 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); |
| 8782 | ha->dpc_thread = create_singlethread_workqueue(buf); |
| 8783 | if (!ha->dpc_thread) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8784 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8785 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8786 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8787 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 8788 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8789 | |
Kees Cook | d853754 | 2013-07-03 15:04:57 -0700 | [diff] [blame] | 8790 | ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1, |
| 8791 | ha->host_no); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8792 | if (!ha->task_wq) { |
| 8793 | ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n"); |
| 8794 | ret = -ENODEV; |
| 8795 | goto remove_host; |
| 8796 | } |
| 8797 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8798 | /* |
| 8799 | * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8800 | * (which is called indirectly by qla4xxx_initialize_adapter), |
| 8801 | * so that irqs will be registered after crbinit but before |
| 8802 | * mbx_intr_enable. |
| 8803 | */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 8804 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8805 | ret = qla4xxx_request_irqs(ha); |
| 8806 | if (ret) { |
| 8807 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " |
| 8808 | "interrupt %d already in use.\n", pdev->irq); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8809 | goto remove_host; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8810 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8811 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8812 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8813 | pci_save_state(ha->pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8814 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8815 | |
| 8816 | /* Start timer thread. */ |
Kees Cook | d744644 | 2017-10-21 08:39:39 -0700 | [diff] [blame] | 8817 | qla4xxx_start_timer(ha, 1); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8818 | |
| 8819 | set_bit(AF_INIT_DONE, &ha->flags); |
| 8820 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 8821 | qla4_8xxx_alloc_sysfs_attr(ha); |
| 8822 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8823 | printk(KERN_INFO |
| 8824 | " QLogic iSCSI HBA Driver version: %s\n" |
| 8825 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", |
| 8826 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), |
Adheer Chandravanshi | eee06a0 | 2013-07-08 08:33:10 -0400 | [diff] [blame] | 8827 | ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor, |
| 8828 | ha->fw_info.fw_patch, ha->fw_info.fw_build); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8829 | |
Manish Dusane | cfb2787 | 2012-09-20 07:35:01 -0400 | [diff] [blame] | 8830 | /* Set the driver version */ |
| 8831 | if (is_qla80XX(ha)) |
| 8832 | qla4_8xxx_set_param(ha, SET_DRVR_VERSION); |
| 8833 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8834 | if (qla4xxx_setup_boot_info(ha)) |
Vikas Chaudhary | 3573bfb | 2012-02-27 03:08:57 -0800 | [diff] [blame] | 8835 | ql4_printk(KERN_ERR, ha, |
| 8836 | "%s: No iSCSI boot target configured\n", __func__); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8837 | |
Nilesh Javali | 906cbf3 | 2014-04-09 21:12:25 -0400 | [diff] [blame] | 8838 | set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags); |
| 8839 | /* Perform the build ddb list and login to each */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8840 | qla4xxx_build_ddb_list(ha, INIT_ADAPTER); |
| 8841 | iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 8842 | qla4xxx_wait_login_resp_boot_tgt(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8843 | |
| 8844 | qla4xxx_create_chap_list(ha); |
| 8845 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8846 | qla4xxx_create_ifaces(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8847 | return 0; |
| 8848 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8849 | remove_host: |
| 8850 | scsi_remove_host(ha->host); |
| 8851 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8852 | probe_failed: |
| 8853 | qla4xxx_free_adapter(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8854 | |
| 8855 | probe_failed_ioconfig: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8856 | pci_disable_pcie_error_reporting(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8857 | scsi_host_put(ha->host); |
| 8858 | |
| 8859 | probe_disable_device: |
| 8860 | pci_disable_device(pdev); |
| 8861 | |
| 8862 | return ret; |
| 8863 | } |
| 8864 | |
| 8865 | /** |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8866 | * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize |
| 8867 | * @ha: pointer to adapter structure |
| 8868 | * |
| 8869 | * Mark the other ISP-4xxx port to indicate that the driver is being removed, |
| 8870 | * so that the other port will not re-initialize while in the process of |
| 8871 | * removing the ha due to driver unload or hba hotplug. |
| 8872 | **/ |
| 8873 | static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha) |
| 8874 | { |
| 8875 | struct scsi_qla_host *other_ha = NULL; |
| 8876 | struct pci_dev *other_pdev = NULL; |
| 8877 | int fn = ISP4XXX_PCI_FN_2; |
| 8878 | |
| 8879 | /*iscsi function numbers for ISP4xxx is 1 and 3*/ |
| 8880 | if (PCI_FUNC(ha->pdev->devfn) & BIT_1) |
| 8881 | fn = ISP4XXX_PCI_FN_1; |
| 8882 | |
| 8883 | other_pdev = |
| 8884 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 8885 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 8886 | fn)); |
| 8887 | |
| 8888 | /* Get other_ha if other_pdev is valid and state is enable*/ |
| 8889 | if (other_pdev) { |
| 8890 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 8891 | other_ha = pci_get_drvdata(other_pdev); |
| 8892 | if (other_ha) { |
| 8893 | set_bit(AF_HA_REMOVAL, &other_ha->flags); |
| 8894 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " |
| 8895 | "Prevent %s reinit\n", __func__, |
| 8896 | dev_name(&other_ha->pdev->dev))); |
| 8897 | } |
| 8898 | } |
| 8899 | pci_dev_put(other_pdev); |
| 8900 | } |
| 8901 | } |
| 8902 | |
Vikas Chaudhary | 28d958b | 2014-01-17 04:43:28 -0500 | [diff] [blame] | 8903 | static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha, |
| 8904 | struct ddb_entry *ddb_entry) |
| 8905 | { |
| 8906 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8907 | dma_addr_t fw_ddb_entry_dma; |
| 8908 | unsigned long wtime; |
| 8909 | uint32_t ddb_state; |
| 8910 | int options; |
| 8911 | int status; |
| 8912 | |
| 8913 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 8914 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) { |
| 8915 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
| 8916 | goto clear_ddb; |
| 8917 | } |
| 8918 | |
| 8919 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8920 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8921 | if (!fw_ddb_entry) { |
| 8922 | ql4_printk(KERN_ERR, ha, |
| 8923 | "%s: Unable to allocate dma buffer\n", __func__); |
| 8924 | goto clear_ddb; |
| 8925 | } |
| 8926 | |
| 8927 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 8928 | do { |
| 8929 | status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 8930 | fw_ddb_entry, fw_ddb_entry_dma, |
| 8931 | NULL, NULL, &ddb_state, NULL, |
| 8932 | NULL, NULL); |
| 8933 | if (status == QLA_ERROR) |
| 8934 | goto free_ddb; |
| 8935 | |
| 8936 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 8937 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 8938 | goto free_ddb; |
| 8939 | |
| 8940 | schedule_timeout_uninterruptible(HZ); |
| 8941 | } while ((time_after(wtime, jiffies))); |
| 8942 | |
| 8943 | free_ddb: |
| 8944 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8945 | fw_ddb_entry, fw_ddb_entry_dma); |
| 8946 | clear_ddb: |
| 8947 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 8948 | } |
| 8949 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8950 | static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha) |
| 8951 | { |
| 8952 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8953 | int idx; |
| 8954 | |
| 8955 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 8956 | |
| 8957 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 8958 | if ((ddb_entry != NULL) && |
| 8959 | (ddb_entry->ddb_type == FLASH_DDB)) { |
| 8960 | |
Vikas Chaudhary | 28d958b | 2014-01-17 04:43:28 -0500 | [diff] [blame] | 8961 | qla4xxx_destroy_ddb(ha, ddb_entry); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8962 | /* |
| 8963 | * we have decremented the reference count of the driver |
| 8964 | * when we setup the session to have the driver unload |
| 8965 | * to be seamless without actually destroying the |
| 8966 | * session |
| 8967 | **/ |
| 8968 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 8969 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 8970 | qla4xxx_free_ddb(ha, ddb_entry); |
| 8971 | iscsi_session_teardown(ddb_entry->sess); |
| 8972 | } |
| 8973 | } |
| 8974 | } |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8975 | /** |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 8976 | * qla4xxx_remove_adapter - callback function to remove adapter. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8977 | * @pci_dev: PCI device pointer |
| 8978 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8979 | static void qla4xxx_remove_adapter(struct pci_dev *pdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8980 | { |
| 8981 | struct scsi_qla_host *ha; |
| 8982 | |
Vikas Chaudhary | f8b0751 | 2012-09-20 07:35:08 -0400 | [diff] [blame] | 8983 | /* |
| 8984 | * If the PCI device is disabled then it means probe_adapter had |
| 8985 | * failed and resources already cleaned up on probe_adapter exit. |
| 8986 | */ |
| 8987 | if (!pci_is_enabled(pdev)) |
| 8988 | return; |
| 8989 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8990 | ha = pci_get_drvdata(pdev); |
| 8991 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 8992 | if (is_qla40XX(ha)) |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8993 | qla4xxx_prevent_other_port_reinit(ha); |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 8994 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8995 | /* destroy iface from sysfs */ |
| 8996 | qla4xxx_destroy_ifaces(ha); |
| 8997 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8998 | if ((!ql4xdisablesysfsboot) && ha->boot_kset) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8999 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 9000 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9001 | qla4xxx_destroy_fw_ddb_session(ha); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 9002 | qla4_8xxx_free_sysfs_attr(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9003 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 9004 | qla4xxx_sysfs_ddb_remove(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9005 | scsi_remove_host(ha->host); |
| 9006 | |
| 9007 | qla4xxx_free_adapter(ha); |
| 9008 | |
| 9009 | scsi_host_put(ha->host); |
| 9010 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9011 | pci_disable_pcie_error_reporting(pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9012 | pci_disable_device(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9013 | } |
| 9014 | |
| 9015 | /** |
| 9016 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. |
| 9017 | * @ha: HA context |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9018 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 9019 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9020 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9021 | /* Update our PCI device dma_mask for full 64 bit mask */ |
Christoph Hellwig | ec44a67 | 2018-10-11 09:56:58 +0200 | [diff] [blame] | 9022 | if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) { |
| 9023 | dev_dbg(&ha->pdev->dev, |
| 9024 | "Failed to set 64 bit PCI consistent mask; " |
| 9025 | "using 32 bit.\n"); |
| 9026 | dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32)); |
| 9027 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9028 | } |
| 9029 | |
| 9030 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) |
| 9031 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9032 | struct iscsi_cls_session *cls_sess; |
| 9033 | struct iscsi_session *sess; |
| 9034 | struct ddb_entry *ddb; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 9035 | int queue_depth = QL4_DEF_QDEPTH; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9036 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9037 | cls_sess = starget_to_session(sdev->sdev_target); |
| 9038 | sess = cls_sess->dd_data; |
| 9039 | ddb = sess->dd_data; |
| 9040 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9041 | sdev->hostdata = ddb; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 9042 | |
| 9043 | if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) |
| 9044 | queue_depth = ql4xmaxqdepth; |
| 9045 | |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 9046 | scsi_change_queue_depth(sdev, queue_depth); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9047 | return 0; |
| 9048 | } |
| 9049 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9050 | /** |
| 9051 | * qla4xxx_del_from_active_array - returns an active srb |
| 9052 | * @ha: Pointer to host adapter structure. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 9053 | * @index: index into the active_array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9054 | * |
| 9055 | * This routine removes and returns the srb at the specified index |
| 9056 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9057 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
| 9058 | uint32_t index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9059 | { |
| 9060 | struct srb *srb = NULL; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9061 | struct scsi_cmnd *cmd = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9062 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9063 | cmd = scsi_host_find_tag(ha->host, index); |
| 9064 | if (!cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9065 | return srb; |
| 9066 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9067 | srb = (struct srb *)CMD_SP(cmd); |
| 9068 | if (!srb) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9069 | return srb; |
| 9070 | |
| 9071 | /* update counters */ |
| 9072 | if (srb->flags & SRB_DMA_VALID) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9073 | ha->iocb_cnt -= srb->iocb_cnt; |
| 9074 | if (srb->cmd) |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9075 | srb->cmd->host_scribble = |
| 9076 | (unsigned char *)(unsigned long) MAX_SRBS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9077 | } |
| 9078 | return srb; |
| 9079 | } |
| 9080 | |
| 9081 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9082 | * 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] | 9083 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9084 | * @cmd: Scsi Command to wait on. |
| 9085 | * |
| 9086 | * This routine waits for the command to be returned by the Firmware |
| 9087 | * for some max time. |
| 9088 | **/ |
| 9089 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, |
| 9090 | struct scsi_cmnd *cmd) |
| 9091 | { |
| 9092 | int done = 0; |
| 9093 | struct srb *rp; |
| 9094 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9095 | int ret = SUCCESS; |
| 9096 | |
| 9097 | /* Dont wait on command if PCI error is being handled |
| 9098 | * by PCI AER driver |
| 9099 | */ |
| 9100 | if (unlikely(pci_channel_offline(ha->pdev)) || |
| 9101 | (test_bit(AF_EEH_BUSY, &ha->flags))) { |
| 9102 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", |
| 9103 | ha->host_no, __func__); |
| 9104 | return ret; |
| 9105 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9106 | |
| 9107 | do { |
| 9108 | /* Checking to see if its returned to OS */ |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9109 | rp = (struct srb *) CMD_SP(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9110 | if (rp == NULL) { |
| 9111 | done++; |
| 9112 | break; |
| 9113 | } |
| 9114 | |
| 9115 | msleep(2000); |
| 9116 | } while (max_wait_time--); |
| 9117 | |
| 9118 | return done; |
| 9119 | } |
| 9120 | |
| 9121 | /** |
| 9122 | * qla4xxx_wait_for_hba_online - waits for HBA to come online |
| 9123 | * @ha: Pointer to host adapter structure |
| 9124 | **/ |
| 9125 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) |
| 9126 | { |
| 9127 | unsigned long wait_online; |
| 9128 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 9129 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9130 | while (time_before(jiffies, wait_online)) { |
| 9131 | |
| 9132 | if (adapter_up(ha)) |
| 9133 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9134 | |
| 9135 | msleep(2000); |
| 9136 | } |
| 9137 | |
| 9138 | return QLA_ERROR; |
| 9139 | } |
| 9140 | |
| 9141 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9142 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 9143 | * @ha: pointer to HBA |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9144 | * @t: target id |
| 9145 | * @l: lun id |
| 9146 | * |
| 9147 | * This function waits for all outstanding commands to a lun to complete. It |
| 9148 | * returns 0 if all pending commands are returned and 1 otherwise. |
| 9149 | **/ |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9150 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
| 9151 | struct scsi_target *stgt, |
| 9152 | struct scsi_device *sdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9153 | { |
| 9154 | int cnt; |
| 9155 | int status = 0; |
| 9156 | struct scsi_cmnd *cmd; |
| 9157 | |
| 9158 | /* |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9159 | * Waiting for all commands for the designated target or dev |
| 9160 | * in the active array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9161 | */ |
| 9162 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { |
| 9163 | cmd = scsi_host_find_tag(ha->host, cnt); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9164 | if (cmd && stgt == scsi_target(cmd->device) && |
| 9165 | (!sdev || sdev == cmd->device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9166 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 9167 | status++; |
| 9168 | break; |
| 9169 | } |
| 9170 | } |
| 9171 | } |
| 9172 | return status; |
| 9173 | } |
| 9174 | |
| 9175 | /** |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9176 | * qla4xxx_eh_abort - callback for abort task. |
| 9177 | * @cmd: Pointer to Linux's SCSI command structure |
| 9178 | * |
| 9179 | * This routine is called by the Linux OS to abort the specified |
| 9180 | * command. |
| 9181 | **/ |
| 9182 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) |
| 9183 | { |
| 9184 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9185 | unsigned int id = cmd->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9186 | uint64_t lun = cmd->device->lun; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9187 | unsigned long flags; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9188 | struct srb *srb = NULL; |
| 9189 | int ret = SUCCESS; |
| 9190 | int wait = 0; |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9191 | int rval; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9192 | |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9193 | ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n", |
Vikas Chaudhary | 63c9e81 | 2013-12-16 06:49:50 -0500 | [diff] [blame] | 9194 | ha->host_no, id, lun, cmd, cmd->cmnd[0]); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9195 | |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9196 | rval = qla4xxx_isp_check_reg(ha); |
| 9197 | if (rval != QLA_SUCCESS) { |
| 9198 | ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n"); |
| 9199 | return FAILED; |
| 9200 | } |
| 9201 | |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9202 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9203 | srb = (struct srb *) CMD_SP(cmd); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9204 | if (!srb) { |
| 9205 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9206 | ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n", |
Vikas Chaudhary | 63c9e81 | 2013-12-16 06:49:50 -0500 | [diff] [blame] | 9207 | ha->host_no, id, lun); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9208 | return SUCCESS; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9209 | } |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9210 | kref_get(&srb->srb_ref); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9211 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9212 | |
| 9213 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9214 | DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n", |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9215 | ha->host_no, id, lun)); |
| 9216 | ret = FAILED; |
| 9217 | } else { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9218 | DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n", |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9219 | ha->host_no, id, lun)); |
| 9220 | wait = 1; |
| 9221 | } |
| 9222 | |
| 9223 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| 9224 | |
| 9225 | /* Wait for command to complete */ |
| 9226 | if (wait) { |
| 9227 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9228 | DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n", |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9229 | ha->host_no, id, lun)); |
| 9230 | ret = FAILED; |
| 9231 | } |
| 9232 | } |
| 9233 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9234 | ql4_printk(KERN_INFO, ha, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9235 | "scsi%ld:%d:%llu: Abort command - %s\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9236 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed"); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9237 | |
| 9238 | return ret; |
| 9239 | } |
| 9240 | |
| 9241 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9242 | * qla4xxx_eh_device_reset - callback for target reset. |
| 9243 | * @cmd: Pointer to Linux's SCSI command structure |
| 9244 | * |
| 9245 | * This routine is called by the Linux OS to reset all luns on the |
| 9246 | * specified target. |
| 9247 | **/ |
| 9248 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 9249 | { |
| 9250 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9251 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9252 | int ret = FAILED, stat; |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9253 | int rval; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9254 | |
Karen Higgins | 612f734 | 2009-07-15 15:03:01 -0500 | [diff] [blame] | 9255 | if (!ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9256 | return ret; |
| 9257 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9258 | ret = iscsi_block_scsi_eh(cmd); |
| 9259 | if (ret) |
| 9260 | return ret; |
| 9261 | ret = FAILED; |
| 9262 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9263 | ql4_printk(KERN_INFO, ha, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9264 | "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9265 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 9266 | |
| 9267 | DEBUG2(printk(KERN_INFO |
| 9268 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," |
| 9269 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 9270 | cmd, jiffies, cmd->request->timeout / HZ, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9271 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 9272 | |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9273 | rval = qla4xxx_isp_check_reg(ha); |
| 9274 | if (rval != QLA_SUCCESS) { |
| 9275 | ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n"); |
| 9276 | return FAILED; |
| 9277 | } |
| 9278 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9279 | /* FIXME: wait for hba to go online */ |
| 9280 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); |
| 9281 | if (stat != QLA_SUCCESS) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9282 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9283 | goto eh_dev_reset_done; |
| 9284 | } |
| 9285 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9286 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 9287 | cmd->device)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9288 | ql4_printk(KERN_INFO, ha, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9289 | "DEVICE RESET FAILED - waiting for " |
| 9290 | "commands.\n"); |
| 9291 | goto eh_dev_reset_done; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9292 | } |
| 9293 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 9294 | /* Send marker. */ |
| 9295 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 9296 | MM_LUN_RESET) != QLA_SUCCESS) |
| 9297 | goto eh_dev_reset_done; |
| 9298 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9299 | ql4_printk(KERN_INFO, ha, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9300 | "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n", |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9301 | ha->host_no, cmd->device->channel, cmd->device->id, |
| 9302 | cmd->device->lun); |
| 9303 | |
| 9304 | ret = SUCCESS; |
| 9305 | |
| 9306 | eh_dev_reset_done: |
| 9307 | |
| 9308 | return ret; |
| 9309 | } |
| 9310 | |
| 9311 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9312 | * qla4xxx_eh_target_reset - callback for target reset. |
| 9313 | * @cmd: Pointer to Linux's SCSI command structure |
| 9314 | * |
| 9315 | * This routine is called by the Linux OS to reset the target. |
| 9316 | **/ |
| 9317 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) |
| 9318 | { |
| 9319 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9320 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9321 | int stat, ret; |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9322 | int rval; |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9323 | |
| 9324 | if (!ddb_entry) |
| 9325 | return FAILED; |
| 9326 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9327 | ret = iscsi_block_scsi_eh(cmd); |
| 9328 | if (ret) |
| 9329 | return ret; |
| 9330 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9331 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9332 | "WARM TARGET RESET ISSUED.\n"); |
| 9333 | |
| 9334 | DEBUG2(printk(KERN_INFO |
| 9335 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " |
| 9336 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 9337 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9338 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 9339 | |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9340 | rval = qla4xxx_isp_check_reg(ha); |
| 9341 | if (rval != QLA_SUCCESS) { |
| 9342 | ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n"); |
| 9343 | return FAILED; |
| 9344 | } |
| 9345 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9346 | stat = qla4xxx_reset_target(ha, ddb_entry); |
| 9347 | if (stat != QLA_SUCCESS) { |
| 9348 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9349 | "WARM TARGET RESET FAILED.\n"); |
| 9350 | return FAILED; |
| 9351 | } |
| 9352 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9353 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 9354 | NULL)) { |
| 9355 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9356 | "WARM TARGET DEVICE RESET FAILED - " |
| 9357 | "waiting for commands.\n"); |
| 9358 | return FAILED; |
| 9359 | } |
| 9360 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 9361 | /* Send marker. */ |
| 9362 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 9363 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { |
| 9364 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9365 | "WARM TARGET DEVICE RESET FAILED - " |
| 9366 | "marker iocb failed.\n"); |
| 9367 | return FAILED; |
| 9368 | } |
| 9369 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9370 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9371 | "WARM TARGET RESET SUCCEEDED.\n"); |
| 9372 | return SUCCESS; |
| 9373 | } |
| 9374 | |
| 9375 | /** |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 9376 | * qla4xxx_is_eh_active - check if error handler is running |
| 9377 | * @shost: Pointer to SCSI Host struct |
| 9378 | * |
| 9379 | * This routine finds that if reset host is called in EH |
| 9380 | * scenario or from some application like sg_reset |
| 9381 | **/ |
| 9382 | static int qla4xxx_is_eh_active(struct Scsi_Host *shost) |
| 9383 | { |
| 9384 | if (shost->shost_state == SHOST_RECOVERY) |
| 9385 | return 1; |
| 9386 | return 0; |
| 9387 | } |
| 9388 | |
| 9389 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9390 | * qla4xxx_eh_host_reset - kernel callback |
| 9391 | * @cmd: Pointer to Linux's SCSI command structure |
| 9392 | * |
| 9393 | * This routine is invoked by the Linux kernel to perform fatal error |
| 9394 | * recovery on the specified adapter. |
| 9395 | **/ |
| 9396 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 9397 | { |
| 9398 | int return_status = FAILED; |
| 9399 | struct scsi_qla_host *ha; |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9400 | int rval; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9401 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9402 | ha = to_qla_host(cmd->device->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9403 | |
Manish Rangankar | 1bc5ad3 | 2018-02-11 22:48:41 -0800 | [diff] [blame] | 9404 | rval = qla4xxx_isp_check_reg(ha); |
| 9405 | if (rval != QLA_SUCCESS) { |
| 9406 | ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n"); |
| 9407 | return FAILED; |
| 9408 | } |
| 9409 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9410 | if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba) |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9411 | qla4_83xx_set_idc_dontreset(ha); |
| 9412 | |
| 9413 | /* |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9414 | * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other |
| 9415 | * protocol drivers, we should not set device_state to NEED_RESET |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9416 | */ |
| 9417 | if (ql4xdontresethba || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9418 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 9419 | qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9420 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 9421 | ha->host_no, __func__)); |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 9422 | |
| 9423 | /* Clear outstanding srb in queues */ |
| 9424 | if (qla4xxx_is_eh_active(cmd->device->host)) |
| 9425 | qla4xxx_abort_active_cmds(ha, DID_ABORT << 16); |
| 9426 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9427 | return FAILED; |
| 9428 | } |
| 9429 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9430 | ql4_printk(KERN_INFO, ha, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 9431 | "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9432 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 9433 | |
| 9434 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 9435 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " |
| 9436 | "DEAD.\n", ha->host_no, cmd->device->channel, |
| 9437 | __func__)); |
| 9438 | |
| 9439 | return FAILED; |
| 9440 | } |
| 9441 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9442 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9443 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9444 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 9445 | else |
| 9446 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 9447 | } |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 9448 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9449 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9450 | return_status = SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9451 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9452 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9453 | return_status == FAILED ? "FAILED" : "SUCCEEDED"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9454 | |
| 9455 | return return_status; |
| 9456 | } |
| 9457 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9458 | static int qla4xxx_context_reset(struct scsi_qla_host *ha) |
| 9459 | { |
| 9460 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 9461 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 9462 | struct addr_ctrl_blk_def *acb = NULL; |
| 9463 | uint32_t acb_len = sizeof(struct addr_ctrl_blk_def); |
| 9464 | int rval = QLA_SUCCESS; |
| 9465 | dma_addr_t acb_dma; |
| 9466 | |
| 9467 | acb = dma_alloc_coherent(&ha->pdev->dev, |
| 9468 | sizeof(struct addr_ctrl_blk_def), |
| 9469 | &acb_dma, GFP_KERNEL); |
| 9470 | if (!acb) { |
| 9471 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n", |
| 9472 | __func__); |
| 9473 | rval = -ENOMEM; |
| 9474 | goto exit_port_reset; |
| 9475 | } |
| 9476 | |
| 9477 | memset(acb, 0, acb_len); |
| 9478 | |
| 9479 | rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len); |
| 9480 | if (rval != QLA_SUCCESS) { |
| 9481 | rval = -EIO; |
| 9482 | goto exit_free_acb; |
| 9483 | } |
| 9484 | |
| 9485 | rval = qla4xxx_disable_acb(ha); |
| 9486 | if (rval != QLA_SUCCESS) { |
| 9487 | rval = -EIO; |
| 9488 | goto exit_free_acb; |
| 9489 | } |
| 9490 | |
| 9491 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 9492 | DISABLE_ACB_TOV * HZ); |
| 9493 | |
| 9494 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma); |
| 9495 | if (rval != QLA_SUCCESS) { |
| 9496 | rval = -EIO; |
| 9497 | goto exit_free_acb; |
| 9498 | } |
| 9499 | |
| 9500 | exit_free_acb: |
| 9501 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def), |
| 9502 | acb, acb_dma); |
| 9503 | exit_port_reset: |
| 9504 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__, |
| 9505 | rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED")); |
| 9506 | return rval; |
| 9507 | } |
| 9508 | |
| 9509 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type) |
| 9510 | { |
| 9511 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 9512 | int rval = QLA_SUCCESS; |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9513 | uint32_t idc_ctrl; |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9514 | |
| 9515 | if (ql4xdontresethba) { |
| 9516 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n", |
| 9517 | __func__)); |
| 9518 | rval = -EPERM; |
| 9519 | goto exit_host_reset; |
| 9520 | } |
| 9521 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9522 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 9523 | goto recover_adapter; |
| 9524 | |
| 9525 | switch (reset_type) { |
| 9526 | case SCSI_ADAPTER_RESET: |
| 9527 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 9528 | break; |
| 9529 | case SCSI_FIRMWARE_RESET: |
| 9530 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9531 | if (is_qla80XX(ha)) |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9532 | /* set firmware context reset */ |
| 9533 | set_bit(DPC_RESET_HA_FW_CONTEXT, |
| 9534 | &ha->dpc_flags); |
| 9535 | else { |
| 9536 | rval = qla4xxx_context_reset(ha); |
| 9537 | goto exit_host_reset; |
| 9538 | } |
| 9539 | } |
| 9540 | break; |
| 9541 | } |
| 9542 | |
| 9543 | recover_adapter: |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9544 | /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9545 | * reset is issued by application */ |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9546 | if ((is_qla8032(ha) || is_qla8042(ha)) && |
| 9547 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9548 | idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL); |
| 9549 | qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL, |
| 9550 | (idc_ctrl | GRACEFUL_RESET_BIT1)); |
| 9551 | } |
| 9552 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9553 | rval = qla4xxx_recover_adapter(ha); |
| 9554 | if (rval != QLA_SUCCESS) { |
| 9555 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n", |
| 9556 | __func__)); |
| 9557 | rval = -EIO; |
| 9558 | } |
| 9559 | |
| 9560 | exit_host_reset: |
| 9561 | return rval; |
| 9562 | } |
| 9563 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9564 | /* PCI AER driver recovers from all correctable errors w/o |
| 9565 | * driver intervention. For uncorrectable errors PCI AER |
| 9566 | * driver calls the following device driver's callbacks |
| 9567 | * |
| 9568 | * - Fatal Errors - link_reset |
Cao jin | 364757e | 2016-12-19 14:20:29 +0800 | [diff] [blame] | 9569 | * - Non-Fatal Errors - driver's error_detected() which |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9570 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. |
| 9571 | * |
| 9572 | * PCI AER driver calls |
Cao jin | 364757e | 2016-12-19 14:20:29 +0800 | [diff] [blame] | 9573 | * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled() |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9574 | * returns RECOVERED or NEED_RESET if fw_hung |
| 9575 | * NEED_RESET - driver's slot_reset() |
| 9576 | * DISCONNECT - device is dead & cannot recover |
Cao jin | 364757e | 2016-12-19 14:20:29 +0800 | [diff] [blame] | 9577 | * RECOVERED - driver's resume() |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9578 | */ |
| 9579 | static pci_ers_result_t |
| 9580 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 9581 | { |
| 9582 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9583 | |
| 9584 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", |
| 9585 | ha->host_no, __func__, state); |
| 9586 | |
| 9587 | if (!is_aer_supported(ha)) |
| 9588 | return PCI_ERS_RESULT_NONE; |
| 9589 | |
| 9590 | switch (state) { |
| 9591 | case pci_channel_io_normal: |
| 9592 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 9593 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9594 | case pci_channel_io_frozen: |
| 9595 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 9596 | qla4xxx_mailbox_premature_completion(ha); |
| 9597 | qla4xxx_free_irqs(ha); |
| 9598 | pci_disable_device(pdev); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9599 | /* Return back all IOs */ |
| 9600 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9601 | return PCI_ERS_RESULT_NEED_RESET; |
| 9602 | case pci_channel_io_perm_failure: |
| 9603 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 9604 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); |
| 9605 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 9606 | return PCI_ERS_RESULT_DISCONNECT; |
| 9607 | } |
| 9608 | return PCI_ERS_RESULT_NEED_RESET; |
| 9609 | } |
| 9610 | |
| 9611 | /** |
| 9612 | * qla4xxx_pci_mmio_enabled() gets called if |
| 9613 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER |
| 9614 | * and read/write to the device still works. |
| 9615 | **/ |
| 9616 | static pci_ers_result_t |
| 9617 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 9618 | { |
| 9619 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9620 | |
| 9621 | if (!is_aer_supported(ha)) |
| 9622 | return PCI_ERS_RESULT_NONE; |
| 9623 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9624 | return PCI_ERS_RESULT_RECOVERED; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9625 | } |
| 9626 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9627 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9628 | { |
| 9629 | uint32_t rval = QLA_ERROR; |
| 9630 | int fn; |
| 9631 | struct pci_dev *other_pdev = NULL; |
| 9632 | |
| 9633 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); |
| 9634 | |
| 9635 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 9636 | |
| 9637 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 9638 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9639 | clear_bit(AF_LINK_UP, &ha->flags); |
| 9640 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9641 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9642 | } |
| 9643 | |
| 9644 | fn = PCI_FUNC(ha->pdev->devfn); |
Tej Parkash | daa34eb | 2013-12-16 06:49:38 -0500 | [diff] [blame] | 9645 | if (is_qla8022(ha)) { |
| 9646 | while (fn > 0) { |
| 9647 | fn--; |
| 9648 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n", |
| 9649 | ha->host_no, __func__, fn); |
| 9650 | /* Get the pci device given the domain, bus, |
| 9651 | * slot/function number */ |
| 9652 | other_pdev = pci_get_domain_bus_and_slot( |
| 9653 | pci_domain_nr(ha->pdev->bus), |
| 9654 | ha->pdev->bus->number, |
| 9655 | PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 9656 | fn)); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9657 | |
Tej Parkash | daa34eb | 2013-12-16 06:49:38 -0500 | [diff] [blame] | 9658 | if (!other_pdev) |
| 9659 | continue; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9660 | |
Tej Parkash | daa34eb | 2013-12-16 06:49:38 -0500 | [diff] [blame] | 9661 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 9662 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n", |
| 9663 | ha->host_no, __func__, fn); |
| 9664 | pci_dev_put(other_pdev); |
| 9665 | break; |
| 9666 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9667 | pci_dev_put(other_pdev); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9668 | } |
Tej Parkash | daa34eb | 2013-12-16 06:49:38 -0500 | [diff] [blame] | 9669 | } else { |
| 9670 | /* this case is meant for ISP83xx/ISP84xx only */ |
| 9671 | if (qla4_83xx_can_perform_reset(ha)) { |
| 9672 | /* reset fn as iSCSI is going to perform the reset */ |
| 9673 | fn = 0; |
| 9674 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9675 | } |
| 9676 | |
| 9677 | /* The first function on the card, the reset owner will |
| 9678 | * start & initialize the firmware. The other functions |
| 9679 | * on the card will reset the firmware context |
| 9680 | */ |
| 9681 | if (!fn) { |
| 9682 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " |
| 9683 | "0x%x is the owner\n", ha->host_no, __func__, |
| 9684 | ha->pdev->devfn); |
| 9685 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9686 | ha->isp_ops->idc_lock(ha); |
| 9687 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9688 | QLA8XXX_DEV_COLD); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9689 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9690 | |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 9691 | rval = qla4_8xxx_update_idc_reg(ha); |
| 9692 | if (rval == QLA_ERROR) { |
| 9693 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n", |
| 9694 | ha->host_no, __func__); |
| 9695 | ha->isp_ops->idc_lock(ha); |
| 9696 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9697 | QLA8XXX_DEV_FAILED); |
| 9698 | ha->isp_ops->idc_unlock(ha); |
| 9699 | goto exit_error_recovery; |
| 9700 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9701 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9702 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9703 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9704 | |
| 9705 | if (rval != QLA_SUCCESS) { |
| 9706 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 9707 | "FAILED\n", ha->host_no, __func__); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 9708 | qla4xxx_free_irqs(ha); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9709 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9710 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9711 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9712 | QLA8XXX_DEV_FAILED); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9713 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9714 | } else { |
| 9715 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 9716 | "READY\n", ha->host_no, __func__); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9717 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9718 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9719 | QLA8XXX_DEV_READY); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9720 | /* Clear driver state register */ |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9721 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9722 | qla4_8xxx_set_drv_active(ha); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9723 | ha->isp_ops->idc_unlock(ha); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9724 | ha->isp_ops->enable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9725 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9726 | } else { |
| 9727 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " |
| 9728 | "the reset owner\n", ha->host_no, __func__, |
| 9729 | ha->pdev->devfn); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9730 | if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) == |
| 9731 | QLA8XXX_DEV_READY)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9732 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9733 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9734 | if (rval == QLA_SUCCESS) |
| 9735 | ha->isp_ops->enable_intrs(ha); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 9736 | else |
| 9737 | qla4xxx_free_irqs(ha); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9738 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9739 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9740 | qla4_8xxx_set_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9741 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9742 | } |
| 9743 | } |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 9744 | exit_error_recovery: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9745 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 9746 | return rval; |
| 9747 | } |
| 9748 | |
| 9749 | static pci_ers_result_t |
| 9750 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) |
| 9751 | { |
| 9752 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 9753 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9754 | int rc; |
| 9755 | |
| 9756 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", |
| 9757 | ha->host_no, __func__); |
| 9758 | |
| 9759 | if (!is_aer_supported(ha)) |
| 9760 | return PCI_ERS_RESULT_NONE; |
| 9761 | |
| 9762 | /* Restore the saved state of PCIe device - |
| 9763 | * BAR registers, PCI Config space, PCIX, MSI, |
| 9764 | * IOV states |
| 9765 | */ |
| 9766 | pci_restore_state(pdev); |
| 9767 | |
| 9768 | /* pci_restore_state() clears the saved_state flag of the device |
| 9769 | * save restored state which resets saved_state flag |
| 9770 | */ |
| 9771 | pci_save_state(pdev); |
| 9772 | |
| 9773 | /* Initialize device or resume if in suspended state */ |
| 9774 | rc = pci_enable_device(pdev); |
| 9775 | if (rc) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9776 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9777 | "device after reset\n", ha->host_no, __func__); |
| 9778 | goto exit_slot_reset; |
| 9779 | } |
| 9780 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9781 | ha->isp_ops->disable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9782 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9783 | if (is_qla80XX(ha)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9784 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { |
| 9785 | ret = PCI_ERS_RESULT_RECOVERED; |
| 9786 | goto exit_slot_reset; |
| 9787 | } else |
| 9788 | goto exit_slot_reset; |
| 9789 | } |
| 9790 | |
| 9791 | exit_slot_reset: |
| 9792 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" |
| 9793 | "device after reset\n", ha->host_no, __func__, ret); |
| 9794 | return ret; |
| 9795 | } |
| 9796 | |
| 9797 | static void |
| 9798 | qla4xxx_pci_resume(struct pci_dev *pdev) |
| 9799 | { |
| 9800 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9801 | int ret; |
| 9802 | |
| 9803 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", |
| 9804 | ha->host_no, __func__); |
| 9805 | |
| 9806 | ret = qla4xxx_wait_for_hba_online(ha); |
| 9807 | if (ret != QLA_SUCCESS) { |
| 9808 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " |
| 9809 | "resume I/O from slot/link_reset\n", ha->host_no, |
| 9810 | __func__); |
| 9811 | } |
| 9812 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9813 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 9814 | } |
| 9815 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 9816 | static const struct pci_error_handlers qla4xxx_err_handler = { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9817 | .error_detected = qla4xxx_pci_error_detected, |
| 9818 | .mmio_enabled = qla4xxx_pci_mmio_enabled, |
| 9819 | .slot_reset = qla4xxx_pci_slot_reset, |
| 9820 | .resume = qla4xxx_pci_resume, |
| 9821 | }; |
| 9822 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9823 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
| 9824 | { |
| 9825 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9826 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, |
| 9827 | .subvendor = PCI_ANY_ID, |
| 9828 | .subdevice = PCI_ANY_ID, |
| 9829 | }, |
| 9830 | { |
| 9831 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9832 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, |
| 9833 | .subvendor = PCI_ANY_ID, |
| 9834 | .subdevice = PCI_ANY_ID, |
| 9835 | }, |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 9836 | { |
| 9837 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9838 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, |
| 9839 | .subvendor = PCI_ANY_ID, |
| 9840 | .subdevice = PCI_ANY_ID, |
| 9841 | }, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9842 | { |
| 9843 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9844 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, |
| 9845 | .subvendor = PCI_ANY_ID, |
| 9846 | .subdevice = PCI_ANY_ID, |
| 9847 | }, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9848 | { |
| 9849 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9850 | .device = PCI_DEVICE_ID_QLOGIC_ISP8324, |
| 9851 | .subvendor = PCI_ANY_ID, |
| 9852 | .subdevice = PCI_ANY_ID, |
| 9853 | }, |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9854 | { |
| 9855 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9856 | .device = PCI_DEVICE_ID_QLOGIC_ISP8042, |
| 9857 | .subvendor = PCI_ANY_ID, |
| 9858 | .subdevice = PCI_ANY_ID, |
| 9859 | }, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9860 | {0, 0}, |
| 9861 | }; |
| 9862 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); |
| 9863 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 9864 | static struct pci_driver qla4xxx_pci_driver = { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9865 | .name = DRIVER_NAME, |
| 9866 | .id_table = qla4xxx_pci_tbl, |
| 9867 | .probe = qla4xxx_probe_adapter, |
| 9868 | .remove = qla4xxx_remove_adapter, |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9869 | .err_handler = &qla4xxx_err_handler, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9870 | }; |
| 9871 | |
| 9872 | static int __init qla4xxx_module_init(void) |
| 9873 | { |
| 9874 | int ret; |
| 9875 | |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 9876 | if (ql4xqfulltracking) |
| 9877 | qla4xxx_driver_template.track_queue_depth = 1; |
| 9878 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9879 | /* Allocate cache for SRBs. */ |
| 9880 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 9881 | SLAB_HWCACHE_ALIGN, NULL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9882 | if (srb_cachep == NULL) { |
| 9883 | printk(KERN_ERR |
| 9884 | "%s: Unable to allocate SRB cache..." |
| 9885 | "Failing load!\n", DRIVER_NAME); |
| 9886 | ret = -ENOMEM; |
| 9887 | goto no_srp_cache; |
| 9888 | } |
| 9889 | |
| 9890 | /* Derive version string. */ |
| 9891 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 9892 | if (ql4xextended_error_logging) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9893 | strcat(qla4xxx_version_str, "-debug"); |
| 9894 | |
| 9895 | qla4xxx_scsi_transport = |
| 9896 | iscsi_register_transport(&qla4xxx_iscsi_transport); |
| 9897 | if (!qla4xxx_scsi_transport){ |
| 9898 | ret = -ENODEV; |
| 9899 | goto release_srb_cache; |
| 9900 | } |
| 9901 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9902 | ret = pci_register_driver(&qla4xxx_pci_driver); |
| 9903 | if (ret) |
| 9904 | goto unregister_transport; |
| 9905 | |
| 9906 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); |
| 9907 | return 0; |
Doug Maxey | 5ae16db | 2006-10-05 23:50:07 -0500 | [diff] [blame] | 9908 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9909 | unregister_transport: |
| 9910 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 9911 | release_srb_cache: |
| 9912 | kmem_cache_destroy(srb_cachep); |
| 9913 | no_srp_cache: |
| 9914 | return ret; |
| 9915 | } |
| 9916 | |
| 9917 | static void __exit qla4xxx_module_exit(void) |
| 9918 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9919 | pci_unregister_driver(&qla4xxx_pci_driver); |
| 9920 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 9921 | kmem_cache_destroy(srb_cachep); |
| 9922 | } |
| 9923 | |
| 9924 | module_init(qla4xxx_module_init); |
| 9925 | module_exit(qla4xxx_module_exit); |
| 9926 | |
| 9927 | MODULE_AUTHOR("QLogic Corporation"); |
| 9928 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); |
| 9929 | MODULE_LICENSE("GPL"); |
| 9930 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |