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 | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 86 | int ql4xmdcapmask = 0x1F; |
| 87 | module_param(ql4xmdcapmask, int, S_IRUGO); |
| 88 | MODULE_PARM_DESC(ql4xmdcapmask, |
| 89 | " Set the Minidump driver capture mask level.\n" |
| 90 | "\t\t Default is 0x1F.\n" |
| 91 | "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F"); |
| 92 | |
| 93 | int ql4xenablemd = 1; |
| 94 | module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR); |
| 95 | MODULE_PARM_DESC(ql4xenablemd, |
| 96 | " Set to enable minidump.\n" |
| 97 | "\t\t 0 - disable minidump\n" |
| 98 | "\t\t 1 - enable minidump (Default)"); |
| 99 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 100 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 101 | /* |
| 102 | * SCSI host template entry points |
| 103 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 104 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * iSCSI template entry points |
| 108 | */ |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 109 | static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess, |
| 110 | enum iscsi_param param, char *buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 111 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
| 112 | enum iscsi_param param, char *buf); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 113 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 114 | enum iscsi_host_param param, char *buf); |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 115 | static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, |
| 116 | uint32_t len); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 117 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 118 | enum iscsi_param_type param_type, |
| 119 | int param, char *buf); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 120 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 121 | static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost, |
| 122 | struct sockaddr *dst_addr, |
| 123 | int non_blocking); |
| 124 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms); |
| 125 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep); |
| 126 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 127 | enum iscsi_param param, char *buf); |
| 128 | static int qla4xxx_conn_start(struct iscsi_cls_conn *conn); |
| 129 | static struct iscsi_cls_conn * |
| 130 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx); |
| 131 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 132 | struct iscsi_cls_conn *cls_conn, |
| 133 | uint64_t transport_fd, int is_leading); |
| 134 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn); |
| 135 | static struct iscsi_cls_session * |
| 136 | qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, |
| 137 | uint16_t qdepth, uint32_t initial_cmdsn); |
| 138 | static void qla4xxx_session_destroy(struct iscsi_cls_session *sess); |
| 139 | static void qla4xxx_task_work(struct work_struct *wdata); |
| 140 | static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t); |
| 141 | static int qla4xxx_task_xmit(struct iscsi_task *); |
| 142 | static void qla4xxx_task_cleanup(struct iscsi_task *); |
| 143 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session); |
| 144 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 145 | struct iscsi_stats *stats); |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 146 | static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num, |
| 147 | uint32_t iface_type, uint32_t payload_size, |
| 148 | uint32_t pid, struct sockaddr *dst_addr); |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 149 | static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx, |
| 150 | uint32_t *num_entries, char *buf); |
| 151 | static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx); |
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); |
| 165 | static int qla4xxx_slave_configure(struct scsi_device *device); |
| 166 | static void qla4xxx_slave_destroy(struct scsi_device *sdev); |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 167 | static umode_t qla4_attr_is_visible(int param_type, int param); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 168 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 169 | static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, |
| 170 | int reason); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 171 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 172 | /* |
| 173 | * iSCSI Flash DDB sysfs entry points |
| 174 | */ |
| 175 | static int |
| 176 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 177 | struct iscsi_bus_flash_conn *fnode_conn, |
| 178 | void *data, int len); |
| 179 | static int |
| 180 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 181 | int param, char *buf); |
| 182 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 183 | int len); |
| 184 | static int |
| 185 | qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess); |
| 186 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 187 | struct iscsi_bus_flash_conn *fnode_conn); |
| 188 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 189 | struct iscsi_bus_flash_conn *fnode_conn); |
| 190 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess); |
| 191 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 192 | static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
| 193 | QLA82XX_LEGACY_INTR_CONFIG; |
| 194 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 195 | static struct scsi_host_template qla4xxx_driver_template = { |
| 196 | .module = THIS_MODULE, |
| 197 | .name = DRIVER_NAME, |
| 198 | .proc_name = DRIVER_NAME, |
| 199 | .queuecommand = qla4xxx_queuecommand, |
| 200 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 201 | .eh_abort_handler = qla4xxx_eh_abort, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 202 | .eh_device_reset_handler = qla4xxx_eh_device_reset, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 203 | .eh_target_reset_handler = qla4xxx_eh_target_reset, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 204 | .eh_host_reset_handler = qla4xxx_eh_host_reset, |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 205 | .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 206 | |
| 207 | .slave_configure = qla4xxx_slave_configure, |
| 208 | .slave_alloc = qla4xxx_slave_alloc, |
| 209 | .slave_destroy = qla4xxx_slave_destroy, |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 210 | .change_queue_depth = qla4xxx_change_queue_depth, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 211 | |
| 212 | .this_id = -1, |
| 213 | .cmd_per_lun = 3, |
| 214 | .use_clustering = ENABLE_CLUSTERING, |
| 215 | .sg_tablesize = SG_ALL, |
| 216 | |
| 217 | .max_sectors = 0xFFFF, |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 218 | .shost_attrs = qla4xxx_host_attrs, |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 219 | .host_reset = qla4xxx_host_reset, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 220 | .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | static struct iscsi_transport qla4xxx_iscsi_transport = { |
| 224 | .owner = THIS_MODULE, |
| 225 | .name = DRIVER_NAME, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 226 | .caps = CAP_TEXT_NEGO | |
| 227 | CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST | |
| 228 | CAP_DATADGST | CAP_LOGIN_OFFLOAD | |
| 229 | CAP_MULTI_R2T, |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 230 | .attr_is_visible = qla4_attr_is_visible, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 231 | .create_session = qla4xxx_session_create, |
| 232 | .destroy_session = qla4xxx_session_destroy, |
| 233 | .start_conn = qla4xxx_conn_start, |
| 234 | .create_conn = qla4xxx_conn_create, |
| 235 | .bind_conn = qla4xxx_conn_bind, |
| 236 | .stop_conn = iscsi_conn_stop, |
| 237 | .destroy_conn = qla4xxx_conn_destroy, |
| 238 | .set_param = iscsi_set_param, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 239 | .get_conn_param = qla4xxx_conn_get_param, |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 240 | .get_session_param = qla4xxx_session_get_param, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 241 | .get_ep_param = qla4xxx_get_ep_param, |
| 242 | .ep_connect = qla4xxx_ep_connect, |
| 243 | .ep_poll = qla4xxx_ep_poll, |
| 244 | .ep_disconnect = qla4xxx_ep_disconnect, |
| 245 | .get_stats = qla4xxx_conn_get_stats, |
| 246 | .send_pdu = iscsi_conn_send_pdu, |
| 247 | .xmit_task = qla4xxx_task_xmit, |
| 248 | .cleanup_task = qla4xxx_task_cleanup, |
| 249 | .alloc_pdu = qla4xxx_alloc_pdu, |
| 250 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 251 | .get_host_param = qla4xxx_host_get_param, |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 252 | .set_iface_param = qla4xxx_iface_set_param, |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 253 | .get_iface_param = qla4xxx_get_iface_param, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 254 | .bsg_request = qla4xxx_bsg_request, |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 255 | .send_ping = qla4xxx_send_ping, |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 256 | .get_chap = qla4xxx_get_chap_list, |
| 257 | .delete_chap = qla4xxx_delete_chap, |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 258 | .set_chap = qla4xxx_set_chap_entry, |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 259 | .get_flashnode_param = qla4xxx_sysfs_ddb_get_param, |
| 260 | .set_flashnode_param = qla4xxx_sysfs_ddb_set_param, |
| 261 | .new_flashnode = qla4xxx_sysfs_ddb_add, |
| 262 | .del_flashnode = qla4xxx_sysfs_ddb_delete, |
| 263 | .login_flashnode = qla4xxx_sysfs_ddb_login, |
| 264 | .logout_flashnode = qla4xxx_sysfs_ddb_logout, |
| 265 | .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid, |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 266 | .get_host_stats = qla4xxx_get_host_stats, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | static struct scsi_transport_template *qla4xxx_scsi_transport; |
| 270 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 271 | static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num, |
| 272 | uint32_t iface_type, uint32_t payload_size, |
| 273 | uint32_t pid, struct sockaddr *dst_addr) |
| 274 | { |
| 275 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 276 | struct sockaddr_in *addr; |
| 277 | struct sockaddr_in6 *addr6; |
| 278 | uint32_t options = 0; |
| 279 | uint8_t ipaddr[IPv6_ADDR_LEN]; |
| 280 | int rval; |
| 281 | |
| 282 | memset(ipaddr, 0, IPv6_ADDR_LEN); |
| 283 | /* IPv4 to IPv4 */ |
| 284 | if ((iface_type == ISCSI_IFACE_TYPE_IPV4) && |
| 285 | (dst_addr->sa_family == AF_INET)) { |
| 286 | addr = (struct sockaddr_in *)dst_addr; |
| 287 | memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN); |
| 288 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 " |
| 289 | "dest: %pI4\n", __func__, |
| 290 | &ha->ip_config.ip_address, ipaddr)); |
| 291 | rval = qla4xxx_ping_iocb(ha, options, payload_size, pid, |
| 292 | ipaddr); |
| 293 | if (rval) |
| 294 | rval = -EINVAL; |
| 295 | } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) && |
| 296 | (dst_addr->sa_family == AF_INET6)) { |
| 297 | /* IPv6 to IPv6 */ |
| 298 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 299 | memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN); |
| 300 | |
| 301 | options |= PING_IPV6_PROTOCOL_ENABLE; |
| 302 | |
| 303 | /* Ping using LinkLocal address */ |
| 304 | if ((iface_num == 0) || (iface_num == 1)) { |
| 305 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping " |
| 306 | "src: %pI6 dest: %pI6\n", __func__, |
| 307 | &ha->ip_config.ipv6_link_local_addr, |
| 308 | ipaddr)); |
| 309 | options |= PING_IPV6_LINKLOCAL_ADDR; |
| 310 | rval = qla4xxx_ping_iocb(ha, options, payload_size, |
| 311 | pid, ipaddr); |
| 312 | } else { |
| 313 | ql4_printk(KERN_WARNING, ha, "%s: iface num = %d " |
| 314 | "not supported\n", __func__, iface_num); |
| 315 | rval = -ENOSYS; |
| 316 | goto exit_send_ping; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * If ping using LinkLocal address fails, try ping using |
| 321 | * IPv6 address |
| 322 | */ |
| 323 | if (rval != QLA_SUCCESS) { |
| 324 | options &= ~PING_IPV6_LINKLOCAL_ADDR; |
| 325 | if (iface_num == 0) { |
| 326 | options |= PING_IPV6_ADDR0; |
| 327 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 " |
| 328 | "Ping src: %pI6 " |
| 329 | "dest: %pI6\n", __func__, |
| 330 | &ha->ip_config.ipv6_addr0, |
| 331 | ipaddr)); |
| 332 | } else if (iface_num == 1) { |
| 333 | options |= PING_IPV6_ADDR1; |
| 334 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 " |
| 335 | "Ping src: %pI6 " |
| 336 | "dest: %pI6\n", __func__, |
| 337 | &ha->ip_config.ipv6_addr1, |
| 338 | ipaddr)); |
| 339 | } |
| 340 | rval = qla4xxx_ping_iocb(ha, options, payload_size, |
| 341 | pid, ipaddr); |
| 342 | if (rval) |
| 343 | rval = -EINVAL; |
| 344 | } |
| 345 | } else |
| 346 | rval = -ENOSYS; |
| 347 | exit_send_ping: |
| 348 | return rval; |
| 349 | } |
| 350 | |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 351 | static umode_t qla4_attr_is_visible(int param_type, int param) |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 352 | { |
| 353 | switch (param_type) { |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 354 | case ISCSI_HOST_PARAM: |
| 355 | switch (param) { |
| 356 | case ISCSI_HOST_PARAM_HWADDRESS: |
| 357 | case ISCSI_HOST_PARAM_IPADDRESS: |
| 358 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 359 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 360 | case ISCSI_HOST_PARAM_PORT_SPEED: |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 361 | return S_IRUGO; |
| 362 | default: |
| 363 | return 0; |
| 364 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 365 | case ISCSI_PARAM: |
| 366 | switch (param) { |
Mike Christie | 590134f | 2011-10-17 22:42:13 -0500 | [diff] [blame] | 367 | case ISCSI_PARAM_PERSISTENT_ADDRESS: |
| 368 | case ISCSI_PARAM_PERSISTENT_PORT: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 369 | case ISCSI_PARAM_CONN_ADDRESS: |
| 370 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 371 | case ISCSI_PARAM_TARGET_NAME: |
| 372 | case ISCSI_PARAM_TPGT: |
| 373 | case ISCSI_PARAM_TARGET_ALIAS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 374 | case ISCSI_PARAM_MAX_BURST: |
| 375 | case ISCSI_PARAM_MAX_R2T: |
| 376 | case ISCSI_PARAM_FIRST_BURST: |
| 377 | case ISCSI_PARAM_MAX_RECV_DLENGTH: |
| 378 | case ISCSI_PARAM_MAX_XMIT_DLENGTH: |
Mike Christie | de37920 | 2011-08-14 20:42:56 -0500 | [diff] [blame] | 379 | case ISCSI_PARAM_IFACE_NAME: |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 380 | case ISCSI_PARAM_CHAP_OUT_IDX: |
| 381 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 382 | case ISCSI_PARAM_USERNAME: |
| 383 | case ISCSI_PARAM_PASSWORD: |
| 384 | case ISCSI_PARAM_USERNAME_IN: |
| 385 | case ISCSI_PARAM_PASSWORD_IN: |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 386 | case ISCSI_PARAM_AUTO_SND_TGT_DISABLE: |
| 387 | case ISCSI_PARAM_DISCOVERY_SESS: |
| 388 | case ISCSI_PARAM_PORTAL_TYPE: |
| 389 | case ISCSI_PARAM_CHAP_AUTH_EN: |
| 390 | case ISCSI_PARAM_DISCOVERY_LOGOUT_EN: |
| 391 | case ISCSI_PARAM_BIDI_CHAP_EN: |
| 392 | case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 393 | case ISCSI_PARAM_DEF_TIME2WAIT: |
| 394 | case ISCSI_PARAM_DEF_TIME2RETAIN: |
| 395 | case ISCSI_PARAM_HDRDGST_EN: |
| 396 | case ISCSI_PARAM_DATADGST_EN: |
| 397 | case ISCSI_PARAM_INITIAL_R2T_EN: |
| 398 | case ISCSI_PARAM_IMM_DATA_EN: |
| 399 | case ISCSI_PARAM_PDU_INORDER_EN: |
| 400 | case ISCSI_PARAM_DATASEQ_INORDER_EN: |
| 401 | case ISCSI_PARAM_MAX_SEGMENT_SIZE: |
| 402 | case ISCSI_PARAM_TCP_TIMESTAMP_STAT: |
| 403 | case ISCSI_PARAM_TCP_WSF_DISABLE: |
| 404 | case ISCSI_PARAM_TCP_NAGLE_DISABLE: |
| 405 | case ISCSI_PARAM_TCP_TIMER_SCALE: |
| 406 | case ISCSI_PARAM_TCP_TIMESTAMP_EN: |
| 407 | case ISCSI_PARAM_TCP_XMIT_WSF: |
| 408 | case ISCSI_PARAM_TCP_RECV_WSF: |
| 409 | case ISCSI_PARAM_IP_FRAGMENT_DISABLE: |
| 410 | case ISCSI_PARAM_IPV4_TOS: |
| 411 | case ISCSI_PARAM_IPV6_TC: |
| 412 | case ISCSI_PARAM_IPV6_FLOW_LABEL: |
| 413 | case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6: |
| 414 | case ISCSI_PARAM_KEEPALIVE_TMO: |
| 415 | case ISCSI_PARAM_LOCAL_PORT: |
| 416 | case ISCSI_PARAM_ISID: |
| 417 | case ISCSI_PARAM_TSID: |
| 418 | case ISCSI_PARAM_DEF_TASKMGMT_TMO: |
| 419 | case ISCSI_PARAM_ERL: |
| 420 | case ISCSI_PARAM_STATSN: |
| 421 | case ISCSI_PARAM_EXP_STATSN: |
| 422 | case ISCSI_PARAM_DISCOVERY_PARENT_IDX: |
| 423 | case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: |
Adheer Chandravanshi | fb734ee3 | 2013-11-22 05:28:22 -0500 | [diff] [blame] | 424 | case ISCSI_PARAM_LOCAL_IPADDR: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 425 | return S_IRUGO; |
| 426 | default: |
| 427 | return 0; |
| 428 | } |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 429 | case ISCSI_NET_PARAM: |
| 430 | switch (param) { |
| 431 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 432 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 433 | case ISCSI_NET_PARAM_IPV4_GW: |
| 434 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 435 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 436 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 437 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 438 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 439 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 440 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 441 | case ISCSI_NET_PARAM_VLAN_ID: |
| 442 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 443 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 444 | case ISCSI_NET_PARAM_MTU: |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 445 | case ISCSI_NET_PARAM_PORT: |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 446 | case ISCSI_NET_PARAM_IPADDR_STATE: |
| 447 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: |
| 448 | case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: |
| 449 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 450 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 451 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 452 | case ISCSI_NET_PARAM_TCP_WSF: |
| 453 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 454 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 455 | case ISCSI_NET_PARAM_CACHE_ID: |
| 456 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 457 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 458 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 459 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 460 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 461 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 462 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 463 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 464 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 465 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 466 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 467 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 468 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 469 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 470 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 471 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 472 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 473 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 474 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
| 475 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
| 476 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
| 477 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
| 478 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 479 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 480 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 481 | return S_IRUGO; |
| 482 | default: |
| 483 | return 0; |
| 484 | } |
| 485 | case ISCSI_IFACE_PARAM: |
| 486 | switch (param) { |
| 487 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 488 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 489 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 490 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 491 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 492 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 493 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 494 | case ISCSI_IFACE_PARAM_ERL: |
| 495 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 496 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 497 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 498 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 499 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 500 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 501 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 502 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 503 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 504 | case ISCSI_IFACE_PARAM_INITIATOR_NAME: |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 505 | return S_IRUGO; |
| 506 | default: |
| 507 | return 0; |
| 508 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 509 | case ISCSI_FLASHNODE_PARAM: |
| 510 | switch (param) { |
| 511 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 512 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 513 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 514 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 515 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 516 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 517 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 518 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 519 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 520 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 521 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 522 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 523 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 524 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 525 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 526 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 527 | case ISCSI_FLASHNODE_ERL: |
| 528 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 529 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 530 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 531 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 532 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 533 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 534 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 535 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 536 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 537 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 538 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 539 | case ISCSI_FLASHNODE_MAX_R2T: |
| 540 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 541 | case ISCSI_FLASHNODE_ISID: |
| 542 | case ISCSI_FLASHNODE_TSID: |
| 543 | case ISCSI_FLASHNODE_PORT: |
| 544 | case ISCSI_FLASHNODE_MAX_BURST: |
| 545 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 546 | case ISCSI_FLASHNODE_IPADDR: |
| 547 | case ISCSI_FLASHNODE_ALIAS: |
| 548 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 549 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 550 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 551 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 552 | case ISCSI_FLASHNODE_IPV6_TC: |
| 553 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 554 | case ISCSI_FLASHNODE_NAME: |
| 555 | case ISCSI_FLASHNODE_TPGT: |
| 556 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 557 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 558 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 559 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 560 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 561 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 562 | case ISCSI_FLASHNODE_USERNAME: |
| 563 | case ISCSI_FLASHNODE_PASSWORD: |
| 564 | case ISCSI_FLASHNODE_STATSN: |
| 565 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 566 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 567 | return S_IRUGO; |
| 568 | default: |
| 569 | return 0; |
| 570 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Adheer Chandravanshi | ea507a2 | 2013-11-22 05:28:23 -0500 | [diff] [blame] | 576 | /** |
| 577 | * qla4xxx_create chap_list - Create CHAP list from FLASH |
| 578 | * @ha: pointer to adapter structure |
| 579 | * |
| 580 | * Read flash and make a list of CHAP entries, during login when a CHAP entry |
| 581 | * is received, it will be checked in this list. If entry exist then the CHAP |
| 582 | * entry index is set in the DDB. If CHAP entry does not exist in this list |
| 583 | * then a new entry is added in FLASH in CHAP table and the index obtained is |
| 584 | * used in the DDB. |
| 585 | **/ |
| 586 | static void qla4xxx_create_chap_list(struct scsi_qla_host *ha) |
| 587 | { |
| 588 | int rval = 0; |
| 589 | uint8_t *chap_flash_data = NULL; |
| 590 | uint32_t offset; |
| 591 | dma_addr_t chap_dma; |
| 592 | uint32_t chap_size = 0; |
| 593 | |
| 594 | if (is_qla40XX(ha)) |
| 595 | chap_size = MAX_CHAP_ENTRIES_40XX * |
| 596 | sizeof(struct ql4_chap_table); |
| 597 | else /* Single region contains CHAP info for both |
| 598 | * ports which is divided into half for each port. |
| 599 | */ |
| 600 | chap_size = ha->hw.flt_chap_size / 2; |
| 601 | |
| 602 | chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size, |
| 603 | &chap_dma, GFP_KERNEL); |
| 604 | if (!chap_flash_data) { |
| 605 | ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n"); |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | if (is_qla40XX(ha)) { |
| 610 | offset = FLASH_CHAP_OFFSET; |
| 611 | } else { |
| 612 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 613 | if (ha->port_num == 1) |
| 614 | offset += chap_size; |
| 615 | } |
| 616 | |
| 617 | rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 618 | if (rval != QLA_SUCCESS) |
| 619 | goto exit_chap_list; |
| 620 | |
| 621 | if (ha->chap_list == NULL) |
| 622 | ha->chap_list = vmalloc(chap_size); |
| 623 | if (ha->chap_list == NULL) { |
| 624 | ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n"); |
| 625 | goto exit_chap_list; |
| 626 | } |
| 627 | |
| 628 | memset(ha->chap_list, 0, chap_size); |
| 629 | memcpy(ha->chap_list, chap_flash_data, chap_size); |
| 630 | |
| 631 | exit_chap_list: |
| 632 | dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma); |
| 633 | } |
| 634 | |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 635 | static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha, |
| 636 | int16_t chap_index, |
| 637 | struct ql4_chap_table **chap_entry) |
| 638 | { |
| 639 | int rval = QLA_ERROR; |
| 640 | int max_chap_entries; |
| 641 | |
| 642 | if (!ha->chap_list) { |
| 643 | ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n"); |
| 644 | rval = QLA_ERROR; |
| 645 | goto exit_get_chap; |
| 646 | } |
| 647 | |
| 648 | if (is_qla80XX(ha)) |
| 649 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 650 | sizeof(struct ql4_chap_table); |
| 651 | else |
| 652 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 653 | |
| 654 | if (chap_index > max_chap_entries) { |
| 655 | ql4_printk(KERN_ERR, ha, "Invalid Chap index\n"); |
| 656 | rval = QLA_ERROR; |
| 657 | goto exit_get_chap; |
| 658 | } |
| 659 | |
| 660 | *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index; |
| 661 | if ((*chap_entry)->cookie != |
| 662 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 663 | rval = QLA_ERROR; |
| 664 | *chap_entry = NULL; |
| 665 | } else { |
| 666 | rval = QLA_SUCCESS; |
| 667 | } |
| 668 | |
| 669 | exit_get_chap: |
| 670 | return rval; |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * qla4xxx_find_free_chap_index - Find the first free chap index |
| 675 | * @ha: pointer to adapter structure |
| 676 | * @chap_index: CHAP index to be returned |
| 677 | * |
| 678 | * Find the first free chap index available in the chap table |
| 679 | * |
| 680 | * Note: Caller should acquire the chap lock before getting here. |
| 681 | **/ |
| 682 | static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha, |
| 683 | uint16_t *chap_index) |
| 684 | { |
| 685 | int i, rval; |
| 686 | int free_index = -1; |
| 687 | int max_chap_entries = 0; |
| 688 | struct ql4_chap_table *chap_table; |
| 689 | |
| 690 | if (is_qla80XX(ha)) |
| 691 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 692 | sizeof(struct ql4_chap_table); |
| 693 | else |
| 694 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 695 | |
| 696 | if (!ha->chap_list) { |
| 697 | ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n"); |
| 698 | rval = QLA_ERROR; |
| 699 | goto exit_find_chap; |
| 700 | } |
| 701 | |
| 702 | for (i = 0; i < max_chap_entries; i++) { |
| 703 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 704 | |
| 705 | if ((chap_table->cookie != |
| 706 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) && |
| 707 | (i > MAX_RESRV_CHAP_IDX)) { |
| 708 | free_index = i; |
| 709 | break; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | if (free_index != -1) { |
| 714 | *chap_index = free_index; |
| 715 | rval = QLA_SUCCESS; |
| 716 | } else { |
| 717 | rval = QLA_ERROR; |
| 718 | } |
| 719 | |
| 720 | exit_find_chap: |
| 721 | return rval; |
| 722 | } |
| 723 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 724 | static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx, |
| 725 | uint32_t *num_entries, char *buf) |
| 726 | { |
| 727 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 728 | struct ql4_chap_table *chap_table; |
| 729 | struct iscsi_chap_rec *chap_rec; |
| 730 | int max_chap_entries = 0; |
| 731 | int valid_chap_entries = 0; |
| 732 | int ret = 0, i; |
| 733 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 734 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 735 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 736 | sizeof(struct ql4_chap_table); |
| 737 | else |
| 738 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 739 | |
| 740 | ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n", |
| 741 | __func__, *num_entries, chap_tbl_idx); |
| 742 | |
| 743 | if (!buf) { |
| 744 | ret = -ENOMEM; |
| 745 | goto exit_get_chap_list; |
| 746 | } |
| 747 | |
Adheer Chandravanshi | ea507a2 | 2013-11-22 05:28:23 -0500 | [diff] [blame] | 748 | qla4xxx_create_chap_list(ha); |
| 749 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 750 | chap_rec = (struct iscsi_chap_rec *) buf; |
| 751 | mutex_lock(&ha->chap_sem); |
| 752 | for (i = chap_tbl_idx; i < max_chap_entries; i++) { |
| 753 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 754 | if (chap_table->cookie != |
| 755 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) |
| 756 | continue; |
| 757 | |
| 758 | chap_rec->chap_tbl_idx = i; |
| 759 | strncpy(chap_rec->username, chap_table->name, |
| 760 | ISCSI_CHAP_AUTH_NAME_MAX_LEN); |
| 761 | strncpy(chap_rec->password, chap_table->secret, |
| 762 | QL4_CHAP_MAX_SECRET_LEN); |
| 763 | chap_rec->password_length = chap_table->secret_len; |
| 764 | |
| 765 | if (chap_table->flags & BIT_7) /* local */ |
| 766 | chap_rec->chap_type = CHAP_TYPE_OUT; |
| 767 | |
| 768 | if (chap_table->flags & BIT_6) /* peer */ |
| 769 | chap_rec->chap_type = CHAP_TYPE_IN; |
| 770 | |
| 771 | chap_rec++; |
| 772 | |
| 773 | valid_chap_entries++; |
| 774 | if (valid_chap_entries == *num_entries) |
| 775 | break; |
| 776 | else |
| 777 | continue; |
| 778 | } |
| 779 | mutex_unlock(&ha->chap_sem); |
| 780 | |
| 781 | exit_get_chap_list: |
| 782 | ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n", |
| 783 | __func__, valid_chap_entries); |
| 784 | *num_entries = valid_chap_entries; |
| 785 | return ret; |
| 786 | } |
| 787 | |
| 788 | static int __qla4xxx_is_chap_active(struct device *dev, void *data) |
| 789 | { |
| 790 | int ret = 0; |
| 791 | uint16_t *chap_tbl_idx = (uint16_t *) data; |
| 792 | struct iscsi_cls_session *cls_session; |
| 793 | struct iscsi_session *sess; |
| 794 | struct ddb_entry *ddb_entry; |
| 795 | |
| 796 | if (!iscsi_is_session_dev(dev)) |
| 797 | goto exit_is_chap_active; |
| 798 | |
| 799 | cls_session = iscsi_dev_to_session(dev); |
| 800 | sess = cls_session->dd_data; |
| 801 | ddb_entry = sess->dd_data; |
| 802 | |
| 803 | if (iscsi_session_chkready(cls_session)) |
| 804 | goto exit_is_chap_active; |
| 805 | |
| 806 | if (ddb_entry->chap_tbl_idx == *chap_tbl_idx) |
| 807 | ret = 1; |
| 808 | |
| 809 | exit_is_chap_active: |
| 810 | return ret; |
| 811 | } |
| 812 | |
| 813 | static int qla4xxx_is_chap_active(struct Scsi_Host *shost, |
| 814 | uint16_t chap_tbl_idx) |
| 815 | { |
| 816 | int ret = 0; |
| 817 | |
| 818 | ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx, |
| 819 | __qla4xxx_is_chap_active); |
| 820 | |
| 821 | return ret; |
| 822 | } |
| 823 | |
| 824 | static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx) |
| 825 | { |
| 826 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 827 | struct ql4_chap_table *chap_table; |
| 828 | dma_addr_t chap_dma; |
| 829 | int max_chap_entries = 0; |
| 830 | uint32_t offset = 0; |
| 831 | uint32_t chap_size; |
| 832 | int ret = 0; |
| 833 | |
| 834 | chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma); |
| 835 | if (chap_table == NULL) |
| 836 | return -ENOMEM; |
| 837 | |
| 838 | memset(chap_table, 0, sizeof(struct ql4_chap_table)); |
| 839 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 840 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 841 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 842 | sizeof(struct ql4_chap_table); |
| 843 | else |
| 844 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 845 | |
| 846 | if (chap_tbl_idx > max_chap_entries) { |
| 847 | ret = -EINVAL; |
| 848 | goto exit_delete_chap; |
| 849 | } |
| 850 | |
| 851 | /* Check if chap index is in use. |
| 852 | * If chap is in use don't delet chap entry */ |
| 853 | ret = qla4xxx_is_chap_active(shost, chap_tbl_idx); |
| 854 | if (ret) { |
| 855 | ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot " |
| 856 | "delete from flash\n", chap_tbl_idx); |
| 857 | ret = -EBUSY; |
| 858 | goto exit_delete_chap; |
| 859 | } |
| 860 | |
| 861 | chap_size = sizeof(struct ql4_chap_table); |
| 862 | if (is_qla40XX(ha)) |
| 863 | offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size); |
| 864 | else { |
| 865 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 866 | /* flt_chap_size is CHAP table size for both ports |
| 867 | * so divide it by 2 to calculate the offset for second port |
| 868 | */ |
| 869 | if (ha->port_num == 1) |
| 870 | offset += (ha->hw.flt_chap_size / 2); |
| 871 | offset += (chap_tbl_idx * chap_size); |
| 872 | } |
| 873 | |
| 874 | ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 875 | if (ret != QLA_SUCCESS) { |
| 876 | ret = -EINVAL; |
| 877 | goto exit_delete_chap; |
| 878 | } |
| 879 | |
| 880 | DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n", |
| 881 | __le16_to_cpu(chap_table->cookie))); |
| 882 | |
| 883 | if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) { |
| 884 | ql4_printk(KERN_ERR, ha, "No valid chap entry found\n"); |
| 885 | goto exit_delete_chap; |
| 886 | } |
| 887 | |
| 888 | chap_table->cookie = __constant_cpu_to_le16(0xFFFF); |
| 889 | |
| 890 | offset = FLASH_CHAP_OFFSET | |
| 891 | (chap_tbl_idx * sizeof(struct ql4_chap_table)); |
| 892 | ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size, |
| 893 | FLASH_OPT_RMW_COMMIT); |
| 894 | if (ret == QLA_SUCCESS && ha->chap_list) { |
| 895 | mutex_lock(&ha->chap_sem); |
| 896 | /* Update ha chap_list cache */ |
| 897 | memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx, |
| 898 | chap_table, sizeof(struct ql4_chap_table)); |
| 899 | mutex_unlock(&ha->chap_sem); |
| 900 | } |
| 901 | if (ret != QLA_SUCCESS) |
| 902 | ret = -EINVAL; |
| 903 | |
| 904 | exit_delete_chap: |
| 905 | dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma); |
| 906 | return ret; |
| 907 | } |
| 908 | |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 909 | /** |
| 910 | * qla4xxx_set_chap_entry - Make chap entry with given information |
| 911 | * @shost: pointer to host |
| 912 | * @data: chap info - credentials, index and type to make chap entry |
| 913 | * @len: length of data |
| 914 | * |
| 915 | * Add or update chap entry with the given information |
| 916 | **/ |
| 917 | static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len) |
| 918 | { |
| 919 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 920 | struct iscsi_chap_rec chap_rec; |
| 921 | struct ql4_chap_table *chap_entry = NULL; |
| 922 | struct iscsi_param_info *param_info; |
| 923 | struct nlattr *attr; |
| 924 | int max_chap_entries = 0; |
| 925 | int type; |
| 926 | int rem = len; |
| 927 | int rc = 0; |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 928 | int size; |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 929 | |
| 930 | memset(&chap_rec, 0, sizeof(chap_rec)); |
| 931 | |
| 932 | nla_for_each_attr(attr, data, len, rem) { |
| 933 | param_info = nla_data(attr); |
| 934 | |
| 935 | switch (param_info->param) { |
| 936 | case ISCSI_CHAP_PARAM_INDEX: |
| 937 | chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value; |
| 938 | break; |
| 939 | case ISCSI_CHAP_PARAM_CHAP_TYPE: |
| 940 | chap_rec.chap_type = param_info->value[0]; |
| 941 | break; |
| 942 | case ISCSI_CHAP_PARAM_USERNAME: |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 943 | size = min_t(size_t, sizeof(chap_rec.username), |
| 944 | param_info->len); |
| 945 | memcpy(chap_rec.username, param_info->value, size); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 946 | break; |
| 947 | case ISCSI_CHAP_PARAM_PASSWORD: |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 948 | size = min_t(size_t, sizeof(chap_rec.password), |
| 949 | param_info->len); |
| 950 | memcpy(chap_rec.password, param_info->value, size); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 951 | break; |
| 952 | case ISCSI_CHAP_PARAM_PASSWORD_LEN: |
| 953 | chap_rec.password_length = param_info->value[0]; |
| 954 | break; |
| 955 | default: |
| 956 | ql4_printk(KERN_ERR, ha, |
| 957 | "%s: No such sysfs attribute\n", __func__); |
| 958 | rc = -ENOSYS; |
| 959 | goto exit_set_chap; |
| 960 | }; |
| 961 | } |
| 962 | |
| 963 | if (chap_rec.chap_type == CHAP_TYPE_IN) |
| 964 | type = BIDI_CHAP; |
| 965 | else |
| 966 | type = LOCAL_CHAP; |
| 967 | |
| 968 | if (is_qla80XX(ha)) |
| 969 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 970 | sizeof(struct ql4_chap_table); |
| 971 | else |
| 972 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 973 | |
| 974 | mutex_lock(&ha->chap_sem); |
| 975 | if (chap_rec.chap_tbl_idx < max_chap_entries) { |
| 976 | rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx, |
| 977 | &chap_entry); |
| 978 | if (!rc) { |
| 979 | if (!(type == qla4xxx_get_chap_type(chap_entry))) { |
| 980 | ql4_printk(KERN_INFO, ha, |
| 981 | "Type mismatch for CHAP entry %d\n", |
| 982 | chap_rec.chap_tbl_idx); |
| 983 | rc = -EINVAL; |
| 984 | goto exit_unlock_chap; |
| 985 | } |
| 986 | |
| 987 | /* If chap index is in use then don't modify it */ |
| 988 | rc = qla4xxx_is_chap_active(shost, |
| 989 | chap_rec.chap_tbl_idx); |
| 990 | if (rc) { |
| 991 | ql4_printk(KERN_INFO, ha, |
| 992 | "CHAP entry %d is in use\n", |
| 993 | chap_rec.chap_tbl_idx); |
| 994 | rc = -EBUSY; |
| 995 | goto exit_unlock_chap; |
| 996 | } |
| 997 | } |
| 998 | } else { |
| 999 | rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx); |
| 1000 | if (rc) { |
| 1001 | ql4_printk(KERN_INFO, ha, "CHAP entry not available\n"); |
| 1002 | rc = -EBUSY; |
| 1003 | goto exit_unlock_chap; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password, |
| 1008 | chap_rec.chap_tbl_idx, type); |
| 1009 | |
| 1010 | exit_unlock_chap: |
| 1011 | mutex_unlock(&ha->chap_sem); |
| 1012 | |
| 1013 | exit_set_chap: |
| 1014 | return rc; |
| 1015 | } |
| 1016 | |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame] | 1017 | |
| 1018 | static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len) |
| 1019 | { |
| 1020 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 1021 | struct iscsi_offload_host_stats *host_stats = NULL; |
| 1022 | int host_stats_size; |
| 1023 | int ret = 0; |
| 1024 | int ddb_idx = 0; |
| 1025 | struct ql_iscsi_stats *ql_iscsi_stats = NULL; |
| 1026 | int stats_size; |
| 1027 | dma_addr_t iscsi_stats_dma; |
| 1028 | |
| 1029 | DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__)); |
| 1030 | |
| 1031 | host_stats_size = sizeof(struct iscsi_offload_host_stats); |
| 1032 | |
| 1033 | if (host_stats_size != len) { |
| 1034 | ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n", |
| 1035 | __func__, len, host_stats_size); |
| 1036 | ret = -EINVAL; |
| 1037 | goto exit_host_stats; |
| 1038 | } |
| 1039 | host_stats = (struct iscsi_offload_host_stats *)buf; |
| 1040 | |
| 1041 | if (!buf) { |
| 1042 | ret = -ENOMEM; |
| 1043 | goto exit_host_stats; |
| 1044 | } |
| 1045 | |
| 1046 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 1047 | |
| 1048 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 1049 | &iscsi_stats_dma, GFP_KERNEL); |
| 1050 | if (!ql_iscsi_stats) { |
| 1051 | ql4_printk(KERN_ERR, ha, |
| 1052 | "Unable to allocate memory for iscsi stats\n"); |
| 1053 | goto exit_host_stats; |
| 1054 | } |
| 1055 | |
| 1056 | ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size, |
| 1057 | iscsi_stats_dma); |
| 1058 | if (ret != QLA_SUCCESS) { |
| 1059 | ql4_printk(KERN_ERR, ha, |
| 1060 | "Unable to retrieve iscsi stats\n"); |
| 1061 | goto exit_host_stats; |
| 1062 | } |
| 1063 | host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames); |
| 1064 | host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes); |
| 1065 | host_stats->mactx_multicast_frames = |
| 1066 | le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames); |
| 1067 | host_stats->mactx_broadcast_frames = |
| 1068 | le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames); |
| 1069 | host_stats->mactx_pause_frames = |
| 1070 | le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames); |
| 1071 | host_stats->mactx_control_frames = |
| 1072 | le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames); |
| 1073 | host_stats->mactx_deferral = |
| 1074 | le64_to_cpu(ql_iscsi_stats->mac_tx_deferral); |
| 1075 | host_stats->mactx_excess_deferral = |
| 1076 | le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral); |
| 1077 | host_stats->mactx_late_collision = |
| 1078 | le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision); |
| 1079 | host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort); |
| 1080 | host_stats->mactx_single_collision = |
| 1081 | le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision); |
| 1082 | host_stats->mactx_multiple_collision = |
| 1083 | le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision); |
| 1084 | host_stats->mactx_collision = |
| 1085 | le64_to_cpu(ql_iscsi_stats->mac_tx_collision); |
| 1086 | host_stats->mactx_frames_dropped = |
| 1087 | le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped); |
| 1088 | host_stats->mactx_jumbo_frames = |
| 1089 | le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames); |
| 1090 | host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames); |
| 1091 | host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes); |
| 1092 | host_stats->macrx_unknown_control_frames = |
| 1093 | le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames); |
| 1094 | host_stats->macrx_pause_frames = |
| 1095 | le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames); |
| 1096 | host_stats->macrx_control_frames = |
| 1097 | le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames); |
| 1098 | host_stats->macrx_dribble = |
| 1099 | le64_to_cpu(ql_iscsi_stats->mac_rx_dribble); |
| 1100 | host_stats->macrx_frame_length_error = |
| 1101 | le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error); |
| 1102 | host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber); |
| 1103 | host_stats->macrx_carrier_sense_error = |
| 1104 | le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error); |
| 1105 | host_stats->macrx_frame_discarded = |
| 1106 | le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded); |
| 1107 | host_stats->macrx_frames_dropped = |
| 1108 | le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped); |
| 1109 | host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error); |
| 1110 | host_stats->mac_encoding_error = |
| 1111 | le64_to_cpu(ql_iscsi_stats->mac_encoding_error); |
| 1112 | host_stats->macrx_length_error_large = |
| 1113 | le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large); |
| 1114 | host_stats->macrx_length_error_small = |
| 1115 | le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small); |
| 1116 | host_stats->macrx_multicast_frames = |
| 1117 | le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames); |
| 1118 | host_stats->macrx_broadcast_frames = |
| 1119 | le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames); |
| 1120 | host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets); |
| 1121 | host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes); |
| 1122 | host_stats->iptx_fragments = |
| 1123 | le64_to_cpu(ql_iscsi_stats->ip_tx_fragments); |
| 1124 | host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets); |
| 1125 | host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes); |
| 1126 | host_stats->iprx_fragments = |
| 1127 | le64_to_cpu(ql_iscsi_stats->ip_rx_fragments); |
| 1128 | host_stats->ip_datagram_reassembly = |
| 1129 | le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly); |
| 1130 | host_stats->ip_invalid_address_error = |
| 1131 | le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error); |
| 1132 | host_stats->ip_error_packets = |
| 1133 | le64_to_cpu(ql_iscsi_stats->ip_error_packets); |
| 1134 | host_stats->ip_fragrx_overlap = |
| 1135 | le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap); |
| 1136 | host_stats->ip_fragrx_outoforder = |
| 1137 | le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder); |
| 1138 | host_stats->ip_datagram_reassembly_timeout = |
| 1139 | le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout); |
| 1140 | host_stats->ipv6tx_packets = |
| 1141 | le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets); |
| 1142 | host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes); |
| 1143 | host_stats->ipv6tx_fragments = |
| 1144 | le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments); |
| 1145 | host_stats->ipv6rx_packets = |
| 1146 | le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets); |
| 1147 | host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes); |
| 1148 | host_stats->ipv6rx_fragments = |
| 1149 | le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments); |
| 1150 | host_stats->ipv6_datagram_reassembly = |
| 1151 | le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly); |
| 1152 | host_stats->ipv6_invalid_address_error = |
| 1153 | le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error); |
| 1154 | host_stats->ipv6_error_packets = |
| 1155 | le64_to_cpu(ql_iscsi_stats->ipv6_error_packets); |
| 1156 | host_stats->ipv6_fragrx_overlap = |
| 1157 | le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap); |
| 1158 | host_stats->ipv6_fragrx_outoforder = |
| 1159 | le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder); |
| 1160 | host_stats->ipv6_datagram_reassembly_timeout = |
| 1161 | le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout); |
| 1162 | host_stats->tcptx_segments = |
| 1163 | le64_to_cpu(ql_iscsi_stats->tcp_tx_segments); |
| 1164 | host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes); |
| 1165 | host_stats->tcprx_segments = |
| 1166 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segments); |
| 1167 | host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte); |
| 1168 | host_stats->tcp_duplicate_ack_retx = |
| 1169 | le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx); |
| 1170 | host_stats->tcp_retx_timer_expired = |
| 1171 | le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired); |
| 1172 | host_stats->tcprx_duplicate_ack = |
| 1173 | le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack); |
| 1174 | host_stats->tcprx_pure_ackr = |
| 1175 | le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr); |
| 1176 | host_stats->tcptx_delayed_ack = |
| 1177 | le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack); |
| 1178 | host_stats->tcptx_pure_ack = |
| 1179 | le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack); |
| 1180 | host_stats->tcprx_segment_error = |
| 1181 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error); |
| 1182 | host_stats->tcprx_segment_outoforder = |
| 1183 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder); |
| 1184 | host_stats->tcprx_window_probe = |
| 1185 | le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe); |
| 1186 | host_stats->tcprx_window_update = |
| 1187 | le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update); |
| 1188 | host_stats->tcptx_window_probe_persist = |
| 1189 | le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist); |
| 1190 | host_stats->ecc_error_correction = |
| 1191 | le64_to_cpu(ql_iscsi_stats->ecc_error_correction); |
| 1192 | host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx); |
| 1193 | host_stats->iscsi_data_bytes_tx = |
| 1194 | le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx); |
| 1195 | host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx); |
| 1196 | host_stats->iscsi_data_bytes_rx = |
| 1197 | le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx); |
| 1198 | host_stats->iscsi_io_completed = |
| 1199 | le64_to_cpu(ql_iscsi_stats->iscsi_io_completed); |
| 1200 | host_stats->iscsi_unexpected_io_rx = |
| 1201 | le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx); |
| 1202 | host_stats->iscsi_format_error = |
| 1203 | le64_to_cpu(ql_iscsi_stats->iscsi_format_error); |
| 1204 | host_stats->iscsi_hdr_digest_error = |
| 1205 | le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error); |
| 1206 | host_stats->iscsi_data_digest_error = |
| 1207 | le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error); |
| 1208 | host_stats->iscsi_sequence_error = |
| 1209 | le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error); |
| 1210 | exit_host_stats: |
| 1211 | if (ql_iscsi_stats) |
| 1212 | dma_free_coherent(&ha->pdev->dev, host_stats_size, |
| 1213 | ql_iscsi_stats, iscsi_stats_dma); |
| 1214 | |
| 1215 | ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n", |
| 1216 | __func__); |
| 1217 | return ret; |
| 1218 | } |
| 1219 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1220 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 1221 | enum iscsi_param_type param_type, |
| 1222 | int param, char *buf) |
| 1223 | { |
| 1224 | struct Scsi_Host *shost = iscsi_iface_to_shost(iface); |
| 1225 | struct scsi_qla_host *ha = to_qla_host(shost); |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1226 | int ival; |
| 1227 | char *pval = NULL; |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1228 | int len = -ENOSYS; |
| 1229 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1230 | if (param_type == ISCSI_NET_PARAM) { |
| 1231 | switch (param) { |
| 1232 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 1233 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| 1234 | break; |
| 1235 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 1236 | len = sprintf(buf, "%pI4\n", |
| 1237 | &ha->ip_config.subnet_mask); |
| 1238 | break; |
| 1239 | case ISCSI_NET_PARAM_IPV4_GW: |
| 1240 | len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); |
| 1241 | break; |
| 1242 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 1243 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1244 | OP_STATE(ha->ip_config.ipv4_options, |
| 1245 | IPOPT_IPV4_PROTOCOL_ENABLE, pval); |
| 1246 | } else { |
| 1247 | OP_STATE(ha->ip_config.ipv6_options, |
| 1248 | IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval); |
| 1249 | } |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1250 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1251 | len = sprintf(buf, "%s\n", pval); |
| 1252 | break; |
| 1253 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1254 | len = sprintf(buf, "%s\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1255 | (ha->ip_config.tcp_options & |
| 1256 | TCPOPT_DHCP_ENABLE) ? |
| 1257 | "dhcp" : "static"); |
| 1258 | break; |
| 1259 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 1260 | if (iface->iface_num == 0) |
| 1261 | len = sprintf(buf, "%pI6\n", |
| 1262 | &ha->ip_config.ipv6_addr0); |
| 1263 | if (iface->iface_num == 1) |
| 1264 | len = sprintf(buf, "%pI6\n", |
| 1265 | &ha->ip_config.ipv6_addr1); |
| 1266 | break; |
| 1267 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 1268 | len = sprintf(buf, "%pI6\n", |
| 1269 | &ha->ip_config.ipv6_link_local_addr); |
| 1270 | break; |
| 1271 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 1272 | len = sprintf(buf, "%pI6\n", |
| 1273 | &ha->ip_config.ipv6_default_router_addr); |
| 1274 | break; |
| 1275 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 1276 | pval = (ha->ip_config.ipv6_addl_options & |
| 1277 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? |
| 1278 | "nd" : "static"; |
| 1279 | |
| 1280 | len = sprintf(buf, "%s\n", pval); |
| 1281 | break; |
| 1282 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 1283 | pval = (ha->ip_config.ipv6_addl_options & |
| 1284 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? |
| 1285 | "auto" : "static"; |
| 1286 | |
| 1287 | len = sprintf(buf, "%s\n", pval); |
| 1288 | break; |
| 1289 | case ISCSI_NET_PARAM_VLAN_ID: |
| 1290 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1291 | ival = ha->ip_config.ipv4_vlan_tag & |
| 1292 | ISCSI_MAX_VLAN_ID; |
| 1293 | else |
| 1294 | ival = ha->ip_config.ipv6_vlan_tag & |
| 1295 | ISCSI_MAX_VLAN_ID; |
| 1296 | |
| 1297 | len = sprintf(buf, "%d\n", ival); |
| 1298 | break; |
| 1299 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 1300 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1301 | ival = (ha->ip_config.ipv4_vlan_tag >> 13) & |
| 1302 | ISCSI_MAX_VLAN_PRIORITY; |
| 1303 | else |
| 1304 | ival = (ha->ip_config.ipv6_vlan_tag >> 13) & |
| 1305 | ISCSI_MAX_VLAN_PRIORITY; |
| 1306 | |
| 1307 | len = sprintf(buf, "%d\n", ival); |
| 1308 | break; |
| 1309 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 1310 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1311 | OP_STATE(ha->ip_config.ipv4_options, |
| 1312 | IPOPT_VLAN_TAGGING_ENABLE, pval); |
| 1313 | } else { |
| 1314 | OP_STATE(ha->ip_config.ipv6_options, |
| 1315 | IPV6_OPT_VLAN_TAGGING_ENABLE, pval); |
| 1316 | } |
| 1317 | len = sprintf(buf, "%s\n", pval); |
| 1318 | break; |
| 1319 | case ISCSI_NET_PARAM_MTU: |
| 1320 | len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size); |
| 1321 | break; |
| 1322 | case ISCSI_NET_PARAM_PORT: |
| 1323 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1324 | len = sprintf(buf, "%d\n", |
| 1325 | ha->ip_config.ipv4_port); |
| 1326 | else |
| 1327 | len = sprintf(buf, "%d\n", |
| 1328 | ha->ip_config.ipv6_port); |
| 1329 | break; |
| 1330 | case ISCSI_NET_PARAM_IPADDR_STATE: |
| 1331 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1332 | pval = iscsi_get_ipaddress_state_name( |
| 1333 | ha->ip_config.ipv4_addr_state); |
| 1334 | } else { |
| 1335 | if (iface->iface_num == 0) |
| 1336 | pval = iscsi_get_ipaddress_state_name( |
| 1337 | ha->ip_config.ipv6_addr0_state); |
| 1338 | else if (iface->iface_num == 1) |
| 1339 | pval = iscsi_get_ipaddress_state_name( |
| 1340 | ha->ip_config.ipv6_addr1_state); |
| 1341 | } |
| 1342 | |
| 1343 | len = sprintf(buf, "%s\n", pval); |
| 1344 | break; |
| 1345 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: |
| 1346 | pval = iscsi_get_ipaddress_state_name( |
| 1347 | ha->ip_config.ipv6_link_local_state); |
| 1348 | len = sprintf(buf, "%s\n", pval); |
| 1349 | break; |
| 1350 | case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: |
| 1351 | pval = iscsi_get_router_state_name( |
| 1352 | ha->ip_config.ipv6_default_router_state); |
| 1353 | len = sprintf(buf, "%s\n", pval); |
| 1354 | break; |
| 1355 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 1356 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1357 | OP_STATE(~ha->ip_config.tcp_options, |
| 1358 | TCPOPT_DELAYED_ACK_DISABLE, pval); |
| 1359 | } else { |
| 1360 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1361 | IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval); |
| 1362 | } |
| 1363 | len = sprintf(buf, "%s\n", pval); |
| 1364 | break; |
| 1365 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 1366 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1367 | OP_STATE(~ha->ip_config.tcp_options, |
| 1368 | TCPOPT_NAGLE_ALGO_DISABLE, pval); |
| 1369 | } else { |
| 1370 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1371 | IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval); |
| 1372 | } |
| 1373 | len = sprintf(buf, "%s\n", pval); |
| 1374 | break; |
| 1375 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 1376 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1377 | OP_STATE(~ha->ip_config.tcp_options, |
| 1378 | TCPOPT_WINDOW_SCALE_DISABLE, pval); |
| 1379 | } else { |
| 1380 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1381 | IPV6_TCPOPT_WINDOW_SCALE_DISABLE, |
| 1382 | pval); |
| 1383 | } |
| 1384 | len = sprintf(buf, "%s\n", pval); |
| 1385 | break; |
| 1386 | case ISCSI_NET_PARAM_TCP_WSF: |
| 1387 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1388 | len = sprintf(buf, "%d\n", |
| 1389 | ha->ip_config.tcp_wsf); |
| 1390 | else |
| 1391 | len = sprintf(buf, "%d\n", |
| 1392 | ha->ip_config.ipv6_tcp_wsf); |
| 1393 | break; |
| 1394 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 1395 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1396 | ival = (ha->ip_config.tcp_options & |
| 1397 | TCPOPT_TIMER_SCALE) >> 1; |
| 1398 | else |
| 1399 | ival = (ha->ip_config.ipv6_tcp_options & |
| 1400 | IPV6_TCPOPT_TIMER_SCALE) >> 1; |
| 1401 | |
| 1402 | len = sprintf(buf, "%d\n", ival); |
| 1403 | break; |
| 1404 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 1405 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1406 | OP_STATE(ha->ip_config.tcp_options, |
| 1407 | TCPOPT_TIMESTAMP_ENABLE, pval); |
| 1408 | } else { |
| 1409 | OP_STATE(ha->ip_config.ipv6_tcp_options, |
| 1410 | IPV6_TCPOPT_TIMESTAMP_EN, pval); |
| 1411 | } |
| 1412 | len = sprintf(buf, "%s\n", pval); |
| 1413 | break; |
| 1414 | case ISCSI_NET_PARAM_CACHE_ID: |
| 1415 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1416 | len = sprintf(buf, "%d\n", |
| 1417 | ha->ip_config.ipv4_cache_id); |
| 1418 | else |
| 1419 | len = sprintf(buf, "%d\n", |
| 1420 | ha->ip_config.ipv6_cache_id); |
| 1421 | break; |
| 1422 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 1423 | OP_STATE(ha->ip_config.tcp_options, |
| 1424 | TCPOPT_DNS_SERVER_IP_EN, pval); |
| 1425 | |
| 1426 | len = sprintf(buf, "%s\n", pval); |
| 1427 | break; |
| 1428 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 1429 | OP_STATE(ha->ip_config.tcp_options, |
| 1430 | TCPOPT_SLP_DA_INFO_EN, pval); |
| 1431 | |
| 1432 | len = sprintf(buf, "%s\n", pval); |
| 1433 | break; |
| 1434 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 1435 | OP_STATE(ha->ip_config.ipv4_options, |
| 1436 | IPOPT_IPV4_TOS_EN, pval); |
| 1437 | |
| 1438 | len = sprintf(buf, "%s\n", pval); |
| 1439 | break; |
| 1440 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 1441 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos); |
| 1442 | break; |
| 1443 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 1444 | OP_STATE(ha->ip_config.ipv4_options, |
| 1445 | IPOPT_GRAT_ARP_EN, pval); |
| 1446 | |
| 1447 | len = sprintf(buf, "%s\n", pval); |
| 1448 | break; |
| 1449 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 1450 | OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN, |
| 1451 | pval); |
| 1452 | |
| 1453 | len = sprintf(buf, "%s\n", pval); |
| 1454 | break; |
| 1455 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 1456 | pval = (ha->ip_config.ipv4_alt_cid_len) ? |
| 1457 | (char *)ha->ip_config.ipv4_alt_cid : ""; |
| 1458 | |
| 1459 | len = sprintf(buf, "%s\n", pval); |
| 1460 | break; |
| 1461 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 1462 | OP_STATE(ha->ip_config.ipv4_options, |
| 1463 | IPOPT_REQ_VID_EN, pval); |
| 1464 | |
| 1465 | len = sprintf(buf, "%s\n", pval); |
| 1466 | break; |
| 1467 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 1468 | OP_STATE(ha->ip_config.ipv4_options, |
| 1469 | IPOPT_USE_VID_EN, pval); |
| 1470 | |
| 1471 | len = sprintf(buf, "%s\n", pval); |
| 1472 | break; |
| 1473 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 1474 | pval = (ha->ip_config.ipv4_vid_len) ? |
| 1475 | (char *)ha->ip_config.ipv4_vid : ""; |
| 1476 | |
| 1477 | len = sprintf(buf, "%s\n", pval); |
| 1478 | break; |
| 1479 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 1480 | OP_STATE(ha->ip_config.ipv4_options, |
| 1481 | IPOPT_LEARN_IQN_EN, pval); |
| 1482 | |
| 1483 | len = sprintf(buf, "%s\n", pval); |
| 1484 | break; |
| 1485 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 1486 | OP_STATE(~ha->ip_config.ipv4_options, |
| 1487 | IPOPT_FRAGMENTATION_DISABLE, pval); |
| 1488 | |
| 1489 | len = sprintf(buf, "%s\n", pval); |
| 1490 | break; |
| 1491 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 1492 | OP_STATE(ha->ip_config.ipv4_options, |
| 1493 | IPOPT_IN_FORWARD_EN, pval); |
| 1494 | |
| 1495 | len = sprintf(buf, "%s\n", pval); |
| 1496 | break; |
| 1497 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 1498 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1499 | OP_STATE(ha->ip_config.ipv4_options, |
| 1500 | IPOPT_ARP_REDIRECT_EN, pval); |
| 1501 | } else { |
| 1502 | OP_STATE(ha->ip_config.ipv6_options, |
| 1503 | IPV6_OPT_REDIRECT_EN, pval); |
| 1504 | } |
| 1505 | len = sprintf(buf, "%s\n", pval); |
| 1506 | break; |
| 1507 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 1508 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl); |
| 1509 | break; |
| 1510 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 1511 | OP_STATE(ha->ip_config.ipv6_options, |
| 1512 | IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval); |
| 1513 | |
| 1514 | len = sprintf(buf, "%s\n", pval); |
| 1515 | break; |
| 1516 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 1517 | OP_STATE(ha->ip_config.ipv6_addl_options, |
| 1518 | IPV6_ADDOPT_MLD_EN, pval); |
| 1519 | |
| 1520 | len = sprintf(buf, "%s\n", pval); |
| 1521 | break; |
| 1522 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 1523 | len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl); |
| 1524 | break; |
| 1525 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1526 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1527 | ha->ip_config.ipv6_traffic_class); |
| 1528 | break; |
| 1529 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1530 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1531 | ha->ip_config.ipv6_hop_limit); |
| 1532 | break; |
| 1533 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1534 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1535 | ha->ip_config.ipv6_nd_reach_time); |
| 1536 | break; |
| 1537 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1538 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1539 | ha->ip_config.ipv6_nd_rexmit_timer); |
| 1540 | break; |
| 1541 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 1542 | len = sprintf(buf, "%d\n", |
| 1543 | ha->ip_config.ipv6_nd_stale_timeout); |
| 1544 | break; |
| 1545 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 1546 | len = sprintf(buf, "%d\n", |
| 1547 | ha->ip_config.ipv6_dup_addr_detect_count); |
| 1548 | break; |
| 1549 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 1550 | len = sprintf(buf, "%d\n", |
| 1551 | ha->ip_config.ipv6_gw_advrt_mtu); |
| 1552 | break; |
| 1553 | default: |
| 1554 | len = -ENOSYS; |
| 1555 | } |
| 1556 | } else if (param_type == ISCSI_IFACE_PARAM) { |
| 1557 | switch (param) { |
| 1558 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 1559 | len = sprintf(buf, "%d\n", ha->ip_config.def_timeout); |
| 1560 | break; |
| 1561 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 1562 | OP_STATE(ha->ip_config.iscsi_options, |
| 1563 | ISCSIOPTS_HEADER_DIGEST_EN, pval); |
| 1564 | |
| 1565 | len = sprintf(buf, "%s\n", pval); |
| 1566 | break; |
| 1567 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 1568 | OP_STATE(ha->ip_config.iscsi_options, |
| 1569 | ISCSIOPTS_DATA_DIGEST_EN, pval); |
| 1570 | |
| 1571 | len = sprintf(buf, "%s\n", pval); |
| 1572 | break; |
| 1573 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 1574 | OP_STATE(ha->ip_config.iscsi_options, |
| 1575 | ISCSIOPTS_IMMEDIATE_DATA_EN, pval); |
| 1576 | |
| 1577 | len = sprintf(buf, "%s\n", pval); |
| 1578 | break; |
| 1579 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 1580 | OP_STATE(ha->ip_config.iscsi_options, |
| 1581 | ISCSIOPTS_INITIAL_R2T_EN, pval); |
| 1582 | |
| 1583 | len = sprintf(buf, "%s\n", pval); |
| 1584 | break; |
| 1585 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 1586 | OP_STATE(ha->ip_config.iscsi_options, |
| 1587 | ISCSIOPTS_DATA_SEQ_INORDER_EN, pval); |
| 1588 | |
| 1589 | len = sprintf(buf, "%s\n", pval); |
| 1590 | break; |
| 1591 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 1592 | OP_STATE(ha->ip_config.iscsi_options, |
| 1593 | ISCSIOPTS_DATA_PDU_INORDER_EN, pval); |
| 1594 | |
| 1595 | len = sprintf(buf, "%s\n", pval); |
| 1596 | break; |
| 1597 | case ISCSI_IFACE_PARAM_ERL: |
| 1598 | len = sprintf(buf, "%d\n", |
| 1599 | (ha->ip_config.iscsi_options & |
| 1600 | ISCSIOPTS_ERL)); |
| 1601 | break; |
| 1602 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 1603 | len = sprintf(buf, "%u\n", |
| 1604 | ha->ip_config.iscsi_max_pdu_size * |
| 1605 | BYTE_UNITS); |
| 1606 | break; |
| 1607 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 1608 | len = sprintf(buf, "%u\n", |
| 1609 | ha->ip_config.iscsi_first_burst_len * |
| 1610 | BYTE_UNITS); |
| 1611 | break; |
| 1612 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 1613 | len = sprintf(buf, "%d\n", |
| 1614 | ha->ip_config.iscsi_max_outstnd_r2t); |
| 1615 | break; |
| 1616 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 1617 | len = sprintf(buf, "%u\n", |
| 1618 | ha->ip_config.iscsi_max_burst_len * |
| 1619 | BYTE_UNITS); |
| 1620 | break; |
| 1621 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 1622 | OP_STATE(ha->ip_config.iscsi_options, |
| 1623 | ISCSIOPTS_CHAP_AUTH_EN, pval); |
| 1624 | |
| 1625 | len = sprintf(buf, "%s\n", pval); |
| 1626 | break; |
| 1627 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 1628 | OP_STATE(ha->ip_config.iscsi_options, |
| 1629 | ISCSIOPTS_BIDI_CHAP_EN, pval); |
| 1630 | |
| 1631 | len = sprintf(buf, "%s\n", pval); |
| 1632 | break; |
| 1633 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 1634 | OP_STATE(ha->ip_config.iscsi_options, |
| 1635 | ISCSIOPTS_DISCOVERY_AUTH_EN, pval); |
| 1636 | |
| 1637 | len = sprintf(buf, "%s\n", pval); |
| 1638 | break; |
| 1639 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 1640 | OP_STATE(ha->ip_config.iscsi_options, |
| 1641 | ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval); |
| 1642 | |
| 1643 | len = sprintf(buf, "%s\n", pval); |
| 1644 | break; |
| 1645 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 1646 | OP_STATE(ha->ip_config.iscsi_options, |
| 1647 | ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval); |
| 1648 | |
| 1649 | len = sprintf(buf, "%s\n", pval); |
| 1650 | break; |
| 1651 | case ISCSI_IFACE_PARAM_INITIATOR_NAME: |
| 1652 | len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name); |
| 1653 | break; |
| 1654 | default: |
| 1655 | len = -ENOSYS; |
| 1656 | } |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | return len; |
| 1660 | } |
| 1661 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1662 | static struct iscsi_endpoint * |
| 1663 | qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, |
| 1664 | int non_blocking) |
| 1665 | { |
| 1666 | int ret; |
| 1667 | struct iscsi_endpoint *ep; |
| 1668 | struct qla_endpoint *qla_ep; |
| 1669 | struct scsi_qla_host *ha; |
| 1670 | struct sockaddr_in *addr; |
| 1671 | struct sockaddr_in6 *addr6; |
| 1672 | |
| 1673 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1674 | if (!shost) { |
| 1675 | ret = -ENXIO; |
| 1676 | printk(KERN_ERR "%s: shost is NULL\n", |
| 1677 | __func__); |
| 1678 | return ERR_PTR(ret); |
| 1679 | } |
| 1680 | |
| 1681 | ha = iscsi_host_priv(shost); |
| 1682 | |
| 1683 | ep = iscsi_create_endpoint(sizeof(struct qla_endpoint)); |
| 1684 | if (!ep) { |
| 1685 | ret = -ENOMEM; |
| 1686 | return ERR_PTR(ret); |
| 1687 | } |
| 1688 | |
| 1689 | qla_ep = ep->dd_data; |
| 1690 | memset(qla_ep, 0, sizeof(struct qla_endpoint)); |
| 1691 | if (dst_addr->sa_family == AF_INET) { |
| 1692 | memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in)); |
| 1693 | addr = (struct sockaddr_in *)&qla_ep->dst_addr; |
| 1694 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__, |
| 1695 | (char *)&addr->sin_addr)); |
| 1696 | } else if (dst_addr->sa_family == AF_INET6) { |
| 1697 | memcpy(&qla_ep->dst_addr, dst_addr, |
| 1698 | sizeof(struct sockaddr_in6)); |
| 1699 | addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr; |
| 1700 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__, |
| 1701 | (char *)&addr6->sin6_addr)); |
| 1702 | } |
| 1703 | |
| 1704 | qla_ep->host = shost; |
| 1705 | |
| 1706 | return ep; |
| 1707 | } |
| 1708 | |
| 1709 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) |
| 1710 | { |
| 1711 | struct qla_endpoint *qla_ep; |
| 1712 | struct scsi_qla_host *ha; |
| 1713 | int ret = 0; |
| 1714 | |
| 1715 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1716 | qla_ep = ep->dd_data; |
| 1717 | ha = to_qla_host(qla_ep->host); |
| 1718 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1719 | if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags)) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1720 | ret = 1; |
| 1721 | |
| 1722 | return ret; |
| 1723 | } |
| 1724 | |
| 1725 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep) |
| 1726 | { |
| 1727 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1728 | iscsi_destroy_endpoint(ep); |
| 1729 | } |
| 1730 | |
| 1731 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 1732 | enum iscsi_param param, |
| 1733 | char *buf) |
| 1734 | { |
| 1735 | struct qla_endpoint *qla_ep = ep->dd_data; |
| 1736 | struct sockaddr *dst_addr; |
| 1737 | |
| 1738 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1739 | |
| 1740 | switch (param) { |
| 1741 | case ISCSI_PARAM_CONN_PORT: |
| 1742 | case ISCSI_PARAM_CONN_ADDRESS: |
| 1743 | if (!qla_ep) |
| 1744 | return -ENOTCONN; |
| 1745 | |
| 1746 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 1747 | if (!dst_addr) |
| 1748 | return -ENOTCONN; |
| 1749 | |
| 1750 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 1751 | &qla_ep->dst_addr, param, buf); |
| 1752 | default: |
| 1753 | return -ENOSYS; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 1758 | struct iscsi_stats *stats) |
| 1759 | { |
| 1760 | struct iscsi_session *sess; |
| 1761 | struct iscsi_cls_session *cls_sess; |
| 1762 | struct ddb_entry *ddb_entry; |
| 1763 | struct scsi_qla_host *ha; |
| 1764 | struct ql_iscsi_stats *ql_iscsi_stats; |
| 1765 | int stats_size; |
| 1766 | int ret; |
| 1767 | dma_addr_t iscsi_stats_dma; |
| 1768 | |
| 1769 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1770 | |
| 1771 | cls_sess = iscsi_conn_to_session(cls_conn); |
| 1772 | sess = cls_sess->dd_data; |
| 1773 | ddb_entry = sess->dd_data; |
| 1774 | ha = ddb_entry->ha; |
| 1775 | |
| 1776 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 1777 | /* Allocate memory */ |
| 1778 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 1779 | &iscsi_stats_dma, GFP_KERNEL); |
| 1780 | if (!ql_iscsi_stats) { |
| 1781 | ql4_printk(KERN_ERR, ha, |
| 1782 | "Unable to allocate memory for iscsi stats\n"); |
| 1783 | goto exit_get_stats; |
| 1784 | } |
| 1785 | |
| 1786 | ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size, |
| 1787 | iscsi_stats_dma); |
| 1788 | if (ret != QLA_SUCCESS) { |
| 1789 | ql4_printk(KERN_ERR, ha, |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 1790 | "Unable to retrieve iscsi stats\n"); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1791 | goto free_stats; |
| 1792 | } |
| 1793 | |
| 1794 | /* octets */ |
| 1795 | stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets); |
| 1796 | stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets); |
| 1797 | /* xmit pdus */ |
| 1798 | stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus); |
| 1799 | stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus); |
| 1800 | stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus); |
| 1801 | stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus); |
| 1802 | stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus); |
| 1803 | stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus); |
| 1804 | stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus); |
| 1805 | stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus); |
| 1806 | /* recv pdus */ |
| 1807 | stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus); |
| 1808 | stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus); |
| 1809 | stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus); |
| 1810 | stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus); |
| 1811 | stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus); |
| 1812 | stats->logoutrsp_pdus = |
| 1813 | le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus); |
| 1814 | stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus); |
| 1815 | stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus); |
| 1816 | stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus); |
| 1817 | |
| 1818 | free_stats: |
| 1819 | dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats, |
| 1820 | iscsi_stats_dma); |
| 1821 | exit_get_stats: |
| 1822 | return; |
| 1823 | } |
| 1824 | |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1825 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| 1826 | { |
| 1827 | struct iscsi_cls_session *session; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1828 | struct iscsi_session *sess; |
| 1829 | unsigned long flags; |
| 1830 | enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1831 | |
| 1832 | session = starget_to_session(scsi_target(sc->device)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1833 | sess = session->dd_data; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1834 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1835 | spin_lock_irqsave(&session->lock, flags); |
| 1836 | if (session->state == ISCSI_SESSION_FAILED) |
| 1837 | ret = BLK_EH_RESET_TIMER; |
| 1838 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1839 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1840 | return ret; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1843 | static void qla4xxx_set_port_speed(struct Scsi_Host *shost) |
| 1844 | { |
| 1845 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 1846 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1847 | uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN; |
| 1848 | |
| 1849 | qla4xxx_get_firmware_state(ha); |
| 1850 | |
| 1851 | switch (ha->addl_fw_state & 0x0F00) { |
| 1852 | case FW_ADDSTATE_LINK_SPEED_10MBPS: |
| 1853 | speed = ISCSI_PORT_SPEED_10MBPS; |
| 1854 | break; |
| 1855 | case FW_ADDSTATE_LINK_SPEED_100MBPS: |
| 1856 | speed = ISCSI_PORT_SPEED_100MBPS; |
| 1857 | break; |
| 1858 | case FW_ADDSTATE_LINK_SPEED_1GBPS: |
| 1859 | speed = ISCSI_PORT_SPEED_1GBPS; |
| 1860 | break; |
| 1861 | case FW_ADDSTATE_LINK_SPEED_10GBPS: |
| 1862 | speed = ISCSI_PORT_SPEED_10GBPS; |
| 1863 | break; |
| 1864 | } |
| 1865 | ihost->port_speed = speed; |
| 1866 | } |
| 1867 | |
| 1868 | static void qla4xxx_set_port_state(struct Scsi_Host *shost) |
| 1869 | { |
| 1870 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 1871 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1872 | uint32_t state = ISCSI_PORT_STATE_DOWN; |
| 1873 | |
| 1874 | if (test_bit(AF_LINK_UP, &ha->flags)) |
| 1875 | state = ISCSI_PORT_STATE_UP; |
| 1876 | |
| 1877 | ihost->port_state = state; |
| 1878 | } |
| 1879 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1880 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 1881 | enum iscsi_host_param param, char *buf) |
| 1882 | { |
| 1883 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 1884 | int len; |
| 1885 | |
| 1886 | switch (param) { |
| 1887 | case ISCSI_HOST_PARAM_HWADDRESS: |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 1888 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1889 | break; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1890 | case ISCSI_HOST_PARAM_IPADDRESS: |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 1891 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1892 | break; |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1893 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1894 | len = sprintf(buf, "%s\n", ha->name_string); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1895 | break; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1896 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 1897 | qla4xxx_set_port_state(shost); |
| 1898 | len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost)); |
| 1899 | break; |
| 1900 | case ISCSI_HOST_PARAM_PORT_SPEED: |
| 1901 | qla4xxx_set_port_speed(shost); |
| 1902 | len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost)); |
| 1903 | break; |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1904 | default: |
| 1905 | return -ENOSYS; |
| 1906 | } |
| 1907 | |
| 1908 | return len; |
| 1909 | } |
| 1910 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1911 | static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
| 1912 | { |
| 1913 | if (ha->iface_ipv4) |
| 1914 | return; |
| 1915 | |
| 1916 | /* IPv4 */ |
| 1917 | ha->iface_ipv4 = iscsi_create_iface(ha->host, |
| 1918 | &qla4xxx_iscsi_transport, |
| 1919 | ISCSI_IFACE_TYPE_IPV4, 0, 0); |
| 1920 | if (!ha->iface_ipv4) |
| 1921 | ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " |
| 1922 | "iface0.\n"); |
| 1923 | } |
| 1924 | |
| 1925 | static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) |
| 1926 | { |
| 1927 | if (!ha->iface_ipv6_0) |
| 1928 | /* IPv6 iface-0 */ |
| 1929 | ha->iface_ipv6_0 = iscsi_create_iface(ha->host, |
| 1930 | &qla4xxx_iscsi_transport, |
| 1931 | ISCSI_IFACE_TYPE_IPV6, 0, |
| 1932 | 0); |
| 1933 | if (!ha->iface_ipv6_0) |
| 1934 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1935 | "iface0.\n"); |
| 1936 | |
| 1937 | if (!ha->iface_ipv6_1) |
| 1938 | /* IPv6 iface-1 */ |
| 1939 | ha->iface_ipv6_1 = iscsi_create_iface(ha->host, |
| 1940 | &qla4xxx_iscsi_transport, |
| 1941 | ISCSI_IFACE_TYPE_IPV6, 1, |
| 1942 | 0); |
| 1943 | if (!ha->iface_ipv6_1) |
| 1944 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1945 | "iface1.\n"); |
| 1946 | } |
| 1947 | |
| 1948 | static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) |
| 1949 | { |
| 1950 | if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) |
| 1951 | qla4xxx_create_ipv4_iface(ha); |
| 1952 | |
| 1953 | if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) |
| 1954 | qla4xxx_create_ipv6_iface(ha); |
| 1955 | } |
| 1956 | |
| 1957 | static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) |
| 1958 | { |
| 1959 | if (ha->iface_ipv4) { |
| 1960 | iscsi_destroy_iface(ha->iface_ipv4); |
| 1961 | ha->iface_ipv4 = NULL; |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) |
| 1966 | { |
| 1967 | if (ha->iface_ipv6_0) { |
| 1968 | iscsi_destroy_iface(ha->iface_ipv6_0); |
| 1969 | ha->iface_ipv6_0 = NULL; |
| 1970 | } |
| 1971 | if (ha->iface_ipv6_1) { |
| 1972 | iscsi_destroy_iface(ha->iface_ipv6_1); |
| 1973 | ha->iface_ipv6_1 = NULL; |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) |
| 1978 | { |
| 1979 | qla4xxx_destroy_ipv4_iface(ha); |
| 1980 | qla4xxx_destroy_ipv6_iface(ha); |
| 1981 | } |
| 1982 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1983 | static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
| 1984 | struct iscsi_iface_param_info *iface_param, |
| 1985 | struct addr_ctrl_blk *init_fw_cb) |
| 1986 | { |
| 1987 | /* |
| 1988 | * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. |
| 1989 | * iface_num 1 is valid only for IPv6 Addr. |
| 1990 | */ |
| 1991 | switch (iface_param->param) { |
| 1992 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 1993 | if (iface_param->iface_num & 0x1) |
| 1994 | /* IPv6 Addr 1 */ |
| 1995 | memcpy(init_fw_cb->ipv6_addr1, iface_param->value, |
| 1996 | sizeof(init_fw_cb->ipv6_addr1)); |
| 1997 | else |
| 1998 | /* IPv6 Addr 0 */ |
| 1999 | memcpy(init_fw_cb->ipv6_addr0, iface_param->value, |
| 2000 | sizeof(init_fw_cb->ipv6_addr0)); |
| 2001 | break; |
| 2002 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 2003 | if (iface_param->iface_num & 0x1) |
| 2004 | break; |
| 2005 | memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], |
| 2006 | sizeof(init_fw_cb->ipv6_if_id)); |
| 2007 | break; |
| 2008 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 2009 | if (iface_param->iface_num & 0x1) |
| 2010 | break; |
| 2011 | memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, |
| 2012 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 2013 | break; |
| 2014 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 2015 | /* Autocfg applies to even interface */ |
| 2016 | if (iface_param->iface_num & 0x1) |
| 2017 | break; |
| 2018 | |
| 2019 | if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) |
| 2020 | init_fw_cb->ipv6_addtl_opts &= |
| 2021 | cpu_to_le16( |
| 2022 | ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 2023 | else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) |
| 2024 | init_fw_cb->ipv6_addtl_opts |= |
| 2025 | cpu_to_le16( |
| 2026 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 2027 | else |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2028 | ql4_printk(KERN_ERR, ha, |
| 2029 | "Invalid autocfg setting for IPv6 addr\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2030 | break; |
| 2031 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 2032 | /* Autocfg applies to even interface */ |
| 2033 | if (iface_param->iface_num & 0x1) |
| 2034 | break; |
| 2035 | |
| 2036 | if (iface_param->value[0] == |
| 2037 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) |
| 2038 | init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( |
| 2039 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 2040 | else if (iface_param->value[0] == |
| 2041 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) |
| 2042 | init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( |
| 2043 | ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 2044 | else |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2045 | ql4_printk(KERN_ERR, ha, |
| 2046 | "Invalid autocfg setting for IPv6 linklocal addr\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2047 | break; |
| 2048 | case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: |
| 2049 | /* Autocfg applies to even interface */ |
| 2050 | if (iface_param->iface_num & 0x1) |
| 2051 | break; |
| 2052 | |
| 2053 | if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) |
| 2054 | memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, |
| 2055 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 2056 | break; |
| 2057 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2058 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2059 | init_fw_cb->ipv6_opts |= |
| 2060 | cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2061 | qla4xxx_create_ipv6_iface(ha); |
| 2062 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2063 | init_fw_cb->ipv6_opts &= |
| 2064 | cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & |
| 2065 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2066 | qla4xxx_destroy_ipv6_iface(ha); |
| 2067 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2068 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 2069 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2070 | if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) |
| 2071 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 2072 | init_fw_cb->ipv6_vlan_tag = |
| 2073 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 2074 | break; |
| 2075 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 2076 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 2077 | init_fw_cb->ipv6_opts |= |
| 2078 | cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE); |
| 2079 | else |
| 2080 | init_fw_cb->ipv6_opts &= |
| 2081 | cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2082 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 2083 | case ISCSI_NET_PARAM_MTU: |
| 2084 | init_fw_cb->eth_mtu_size = |
| 2085 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2086 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 2087 | case ISCSI_NET_PARAM_PORT: |
| 2088 | /* Autocfg applies to even interface */ |
| 2089 | if (iface_param->iface_num & 0x1) |
| 2090 | break; |
| 2091 | |
| 2092 | init_fw_cb->ipv6_port = |
| 2093 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2094 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2095 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 2096 | if (iface_param->iface_num & 0x1) |
| 2097 | break; |
| 2098 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2099 | init_fw_cb->ipv6_tcp_opts |= |
| 2100 | cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE); |
| 2101 | else |
| 2102 | init_fw_cb->ipv6_tcp_opts &= |
| 2103 | cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE); |
| 2104 | break; |
| 2105 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 2106 | if (iface_param->iface_num & 0x1) |
| 2107 | break; |
| 2108 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2109 | init_fw_cb->ipv6_tcp_opts |= |
| 2110 | cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE); |
| 2111 | else |
| 2112 | init_fw_cb->ipv6_tcp_opts &= |
| 2113 | cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE); |
| 2114 | break; |
| 2115 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 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_WINDOW_SCALE_DISABLE); |
| 2121 | else |
| 2122 | init_fw_cb->ipv6_tcp_opts &= |
| 2123 | cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE); |
| 2124 | break; |
| 2125 | case ISCSI_NET_PARAM_TCP_WSF: |
| 2126 | if (iface_param->iface_num & 0x1) |
| 2127 | break; |
| 2128 | init_fw_cb->ipv6_tcp_wsf = iface_param->value[0]; |
| 2129 | break; |
| 2130 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 2131 | if (iface_param->iface_num & 0x1) |
| 2132 | break; |
| 2133 | init_fw_cb->ipv6_tcp_opts &= |
| 2134 | cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE); |
| 2135 | init_fw_cb->ipv6_tcp_opts |= |
| 2136 | cpu_to_le16((iface_param->value[0] << 1) & |
| 2137 | IPV6_TCPOPT_TIMER_SCALE); |
| 2138 | break; |
| 2139 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 2140 | if (iface_param->iface_num & 0x1) |
| 2141 | break; |
| 2142 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2143 | init_fw_cb->ipv6_tcp_opts |= |
| 2144 | cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN); |
| 2145 | else |
| 2146 | init_fw_cb->ipv6_tcp_opts &= |
| 2147 | cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN); |
| 2148 | break; |
| 2149 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 2150 | if (iface_param->iface_num & 0x1) |
| 2151 | break; |
| 2152 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2153 | init_fw_cb->ipv6_opts |= |
| 2154 | cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN); |
| 2155 | else |
| 2156 | init_fw_cb->ipv6_opts &= |
| 2157 | cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN); |
| 2158 | break; |
| 2159 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 2160 | if (iface_param->iface_num & 0x1) |
| 2161 | break; |
| 2162 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2163 | init_fw_cb->ipv6_opts |= |
| 2164 | cpu_to_le16(IPV6_OPT_REDIRECT_EN); |
| 2165 | else |
| 2166 | init_fw_cb->ipv6_opts &= |
| 2167 | cpu_to_le16(~IPV6_OPT_REDIRECT_EN); |
| 2168 | break; |
| 2169 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 2170 | if (iface_param->iface_num & 0x1) |
| 2171 | break; |
| 2172 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2173 | init_fw_cb->ipv6_addtl_opts |= |
| 2174 | cpu_to_le16(IPV6_ADDOPT_MLD_EN); |
| 2175 | else |
| 2176 | init_fw_cb->ipv6_addtl_opts &= |
| 2177 | cpu_to_le16(~IPV6_ADDOPT_MLD_EN); |
| 2178 | break; |
| 2179 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 2180 | if (iface_param->iface_num & 0x1) |
| 2181 | break; |
| 2182 | init_fw_cb->ipv6_flow_lbl = |
| 2183 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2184 | break; |
| 2185 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
| 2186 | if (iface_param->iface_num & 0x1) |
| 2187 | break; |
| 2188 | init_fw_cb->ipv6_traffic_class = iface_param->value[0]; |
| 2189 | break; |
| 2190 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
| 2191 | if (iface_param->iface_num & 0x1) |
| 2192 | break; |
| 2193 | init_fw_cb->ipv6_hop_limit = iface_param->value[0]; |
| 2194 | break; |
| 2195 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
| 2196 | if (iface_param->iface_num & 0x1) |
| 2197 | break; |
| 2198 | init_fw_cb->ipv6_nd_reach_time = |
| 2199 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2200 | break; |
| 2201 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
| 2202 | if (iface_param->iface_num & 0x1) |
| 2203 | break; |
| 2204 | init_fw_cb->ipv6_nd_rexmit_timer = |
| 2205 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2206 | break; |
| 2207 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 2208 | if (iface_param->iface_num & 0x1) |
| 2209 | break; |
| 2210 | init_fw_cb->ipv6_nd_stale_timeout = |
| 2211 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2212 | break; |
| 2213 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 2214 | if (iface_param->iface_num & 0x1) |
| 2215 | break; |
| 2216 | init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0]; |
| 2217 | break; |
| 2218 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 2219 | if (iface_param->iface_num & 0x1) |
| 2220 | break; |
| 2221 | init_fw_cb->ipv6_gw_advrt_mtu = |
| 2222 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2223 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2224 | default: |
| 2225 | ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", |
| 2226 | iface_param->param); |
| 2227 | break; |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, |
| 2232 | struct iscsi_iface_param_info *iface_param, |
| 2233 | struct addr_ctrl_blk *init_fw_cb) |
| 2234 | { |
| 2235 | switch (iface_param->param) { |
| 2236 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 2237 | memcpy(init_fw_cb->ipv4_addr, iface_param->value, |
| 2238 | sizeof(init_fw_cb->ipv4_addr)); |
| 2239 | break; |
| 2240 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 2241 | memcpy(init_fw_cb->ipv4_subnet, iface_param->value, |
| 2242 | sizeof(init_fw_cb->ipv4_subnet)); |
| 2243 | break; |
| 2244 | case ISCSI_NET_PARAM_IPV4_GW: |
| 2245 | memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, |
| 2246 | sizeof(init_fw_cb->ipv4_gw_addr)); |
| 2247 | break; |
| 2248 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 2249 | if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) |
| 2250 | init_fw_cb->ipv4_tcp_opts |= |
| 2251 | cpu_to_le16(TCPOPT_DHCP_ENABLE); |
| 2252 | else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) |
| 2253 | init_fw_cb->ipv4_tcp_opts &= |
| 2254 | cpu_to_le16(~TCPOPT_DHCP_ENABLE); |
| 2255 | else |
| 2256 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); |
| 2257 | break; |
| 2258 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2259 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2260 | init_fw_cb->ipv4_ip_opts |= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 2261 | cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2262 | qla4xxx_create_ipv4_iface(ha); |
| 2263 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2264 | init_fw_cb->ipv4_ip_opts &= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 2265 | cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2266 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2267 | qla4xxx_destroy_ipv4_iface(ha); |
| 2268 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2269 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 2270 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2271 | if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) |
| 2272 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 2273 | init_fw_cb->ipv4_vlan_tag = |
| 2274 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 2275 | break; |
| 2276 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 2277 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 2278 | init_fw_cb->ipv4_ip_opts |= |
| 2279 | cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE); |
| 2280 | else |
| 2281 | init_fw_cb->ipv4_ip_opts &= |
| 2282 | cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2283 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 2284 | case ISCSI_NET_PARAM_MTU: |
| 2285 | init_fw_cb->eth_mtu_size = |
| 2286 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2287 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 2288 | case ISCSI_NET_PARAM_PORT: |
| 2289 | init_fw_cb->ipv4_port = |
| 2290 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2291 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2292 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 2293 | if (iface_param->iface_num & 0x1) |
| 2294 | break; |
| 2295 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2296 | init_fw_cb->ipv4_tcp_opts |= |
| 2297 | cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE); |
| 2298 | else |
| 2299 | init_fw_cb->ipv4_tcp_opts &= |
| 2300 | cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE); |
| 2301 | break; |
| 2302 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 2303 | if (iface_param->iface_num & 0x1) |
| 2304 | break; |
| 2305 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2306 | init_fw_cb->ipv4_tcp_opts |= |
| 2307 | cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE); |
| 2308 | else |
| 2309 | init_fw_cb->ipv4_tcp_opts &= |
| 2310 | cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE); |
| 2311 | break; |
| 2312 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 2313 | if (iface_param->iface_num & 0x1) |
| 2314 | break; |
| 2315 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2316 | init_fw_cb->ipv4_tcp_opts |= |
| 2317 | cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE); |
| 2318 | else |
| 2319 | init_fw_cb->ipv4_tcp_opts &= |
| 2320 | cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE); |
| 2321 | break; |
| 2322 | case ISCSI_NET_PARAM_TCP_WSF: |
| 2323 | if (iface_param->iface_num & 0x1) |
| 2324 | break; |
| 2325 | init_fw_cb->ipv4_tcp_wsf = iface_param->value[0]; |
| 2326 | break; |
| 2327 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 2328 | if (iface_param->iface_num & 0x1) |
| 2329 | break; |
| 2330 | init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE); |
| 2331 | init_fw_cb->ipv4_tcp_opts |= |
| 2332 | cpu_to_le16((iface_param->value[0] << 1) & |
| 2333 | TCPOPT_TIMER_SCALE); |
| 2334 | break; |
| 2335 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 2336 | if (iface_param->iface_num & 0x1) |
| 2337 | break; |
| 2338 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2339 | init_fw_cb->ipv4_tcp_opts |= |
| 2340 | cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE); |
| 2341 | else |
| 2342 | init_fw_cb->ipv4_tcp_opts &= |
| 2343 | cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE); |
| 2344 | break; |
| 2345 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 2346 | if (iface_param->iface_num & 0x1) |
| 2347 | break; |
| 2348 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2349 | init_fw_cb->ipv4_tcp_opts |= |
| 2350 | cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN); |
| 2351 | else |
| 2352 | init_fw_cb->ipv4_tcp_opts &= |
| 2353 | cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN); |
| 2354 | break; |
| 2355 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 2356 | if (iface_param->iface_num & 0x1) |
| 2357 | break; |
| 2358 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2359 | init_fw_cb->ipv4_tcp_opts |= |
| 2360 | cpu_to_le16(TCPOPT_SLP_DA_INFO_EN); |
| 2361 | else |
| 2362 | init_fw_cb->ipv4_tcp_opts &= |
| 2363 | cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN); |
| 2364 | break; |
| 2365 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 2366 | if (iface_param->iface_num & 0x1) |
| 2367 | break; |
| 2368 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2369 | init_fw_cb->ipv4_ip_opts |= |
| 2370 | cpu_to_le16(IPOPT_IPV4_TOS_EN); |
| 2371 | else |
| 2372 | init_fw_cb->ipv4_ip_opts &= |
| 2373 | cpu_to_le16(~IPOPT_IPV4_TOS_EN); |
| 2374 | break; |
| 2375 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 2376 | if (iface_param->iface_num & 0x1) |
| 2377 | break; |
| 2378 | init_fw_cb->ipv4_tos = iface_param->value[0]; |
| 2379 | break; |
| 2380 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 2381 | if (iface_param->iface_num & 0x1) |
| 2382 | break; |
| 2383 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2384 | init_fw_cb->ipv4_ip_opts |= |
| 2385 | cpu_to_le16(IPOPT_GRAT_ARP_EN); |
| 2386 | else |
| 2387 | init_fw_cb->ipv4_ip_opts &= |
| 2388 | cpu_to_le16(~IPOPT_GRAT_ARP_EN); |
| 2389 | break; |
| 2390 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 2391 | if (iface_param->iface_num & 0x1) |
| 2392 | break; |
| 2393 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2394 | init_fw_cb->ipv4_ip_opts |= |
| 2395 | cpu_to_le16(IPOPT_ALT_CID_EN); |
| 2396 | else |
| 2397 | init_fw_cb->ipv4_ip_opts &= |
| 2398 | cpu_to_le16(~IPOPT_ALT_CID_EN); |
| 2399 | break; |
| 2400 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 2401 | if (iface_param->iface_num & 0x1) |
| 2402 | break; |
| 2403 | memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value, |
| 2404 | (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1)); |
| 2405 | init_fw_cb->ipv4_dhcp_alt_cid_len = |
| 2406 | strlen(init_fw_cb->ipv4_dhcp_alt_cid); |
| 2407 | break; |
| 2408 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 2409 | if (iface_param->iface_num & 0x1) |
| 2410 | break; |
| 2411 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2412 | init_fw_cb->ipv4_ip_opts |= |
| 2413 | cpu_to_le16(IPOPT_REQ_VID_EN); |
| 2414 | else |
| 2415 | init_fw_cb->ipv4_ip_opts &= |
| 2416 | cpu_to_le16(~IPOPT_REQ_VID_EN); |
| 2417 | break; |
| 2418 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 2419 | if (iface_param->iface_num & 0x1) |
| 2420 | break; |
| 2421 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2422 | init_fw_cb->ipv4_ip_opts |= |
| 2423 | cpu_to_le16(IPOPT_USE_VID_EN); |
| 2424 | else |
| 2425 | init_fw_cb->ipv4_ip_opts &= |
| 2426 | cpu_to_le16(~IPOPT_USE_VID_EN); |
| 2427 | break; |
| 2428 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 2429 | if (iface_param->iface_num & 0x1) |
| 2430 | break; |
| 2431 | memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value, |
| 2432 | (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1)); |
| 2433 | init_fw_cb->ipv4_dhcp_vid_len = |
| 2434 | strlen(init_fw_cb->ipv4_dhcp_vid); |
| 2435 | break; |
| 2436 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 2437 | if (iface_param->iface_num & 0x1) |
| 2438 | break; |
| 2439 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2440 | init_fw_cb->ipv4_ip_opts |= |
| 2441 | cpu_to_le16(IPOPT_LEARN_IQN_EN); |
| 2442 | else |
| 2443 | init_fw_cb->ipv4_ip_opts &= |
| 2444 | cpu_to_le16(~IPOPT_LEARN_IQN_EN); |
| 2445 | break; |
| 2446 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 2447 | if (iface_param->iface_num & 0x1) |
| 2448 | break; |
| 2449 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2450 | init_fw_cb->ipv4_ip_opts |= |
| 2451 | cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE); |
| 2452 | else |
| 2453 | init_fw_cb->ipv4_ip_opts &= |
| 2454 | cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE); |
| 2455 | break; |
| 2456 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 2457 | if (iface_param->iface_num & 0x1) |
| 2458 | break; |
| 2459 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2460 | init_fw_cb->ipv4_ip_opts |= |
| 2461 | cpu_to_le16(IPOPT_IN_FORWARD_EN); |
| 2462 | else |
| 2463 | init_fw_cb->ipv4_ip_opts &= |
| 2464 | cpu_to_le16(~IPOPT_IN_FORWARD_EN); |
| 2465 | break; |
| 2466 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 2467 | if (iface_param->iface_num & 0x1) |
| 2468 | break; |
| 2469 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2470 | init_fw_cb->ipv4_ip_opts |= |
| 2471 | cpu_to_le16(IPOPT_ARP_REDIRECT_EN); |
| 2472 | else |
| 2473 | init_fw_cb->ipv4_ip_opts &= |
| 2474 | cpu_to_le16(~IPOPT_ARP_REDIRECT_EN); |
| 2475 | break; |
| 2476 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 2477 | if (iface_param->iface_num & 0x1) |
| 2478 | break; |
| 2479 | init_fw_cb->ipv4_ttl = iface_param->value[0]; |
| 2480 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2481 | default: |
| 2482 | ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", |
| 2483 | iface_param->param); |
| 2484 | break; |
| 2485 | } |
| 2486 | } |
| 2487 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2488 | static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha, |
| 2489 | struct iscsi_iface_param_info *iface_param, |
| 2490 | struct addr_ctrl_blk *init_fw_cb) |
| 2491 | { |
| 2492 | switch (iface_param->param) { |
| 2493 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 2494 | if (iface_param->iface_num & 0x1) |
| 2495 | break; |
| 2496 | init_fw_cb->def_timeout = |
| 2497 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2498 | break; |
| 2499 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 2500 | if (iface_param->iface_num & 0x1) |
| 2501 | break; |
| 2502 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2503 | init_fw_cb->iscsi_opts |= |
| 2504 | cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN); |
| 2505 | else |
| 2506 | init_fw_cb->iscsi_opts &= |
| 2507 | cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN); |
| 2508 | break; |
| 2509 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 2510 | if (iface_param->iface_num & 0x1) |
| 2511 | break; |
| 2512 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2513 | init_fw_cb->iscsi_opts |= |
| 2514 | cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN); |
| 2515 | else |
| 2516 | init_fw_cb->iscsi_opts &= |
| 2517 | cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN); |
| 2518 | break; |
| 2519 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 2520 | if (iface_param->iface_num & 0x1) |
| 2521 | break; |
| 2522 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2523 | init_fw_cb->iscsi_opts |= |
| 2524 | cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN); |
| 2525 | else |
| 2526 | init_fw_cb->iscsi_opts &= |
| 2527 | cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN); |
| 2528 | break; |
| 2529 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 2530 | if (iface_param->iface_num & 0x1) |
| 2531 | break; |
| 2532 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2533 | init_fw_cb->iscsi_opts |= |
| 2534 | cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN); |
| 2535 | else |
| 2536 | init_fw_cb->iscsi_opts &= |
| 2537 | cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN); |
| 2538 | break; |
| 2539 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 2540 | if (iface_param->iface_num & 0x1) |
| 2541 | break; |
| 2542 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2543 | init_fw_cb->iscsi_opts |= |
| 2544 | cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN); |
| 2545 | else |
| 2546 | init_fw_cb->iscsi_opts &= |
| 2547 | cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN); |
| 2548 | break; |
| 2549 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 2550 | if (iface_param->iface_num & 0x1) |
| 2551 | break; |
| 2552 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2553 | init_fw_cb->iscsi_opts |= |
| 2554 | cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN); |
| 2555 | else |
| 2556 | init_fw_cb->iscsi_opts &= |
| 2557 | cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN); |
| 2558 | break; |
| 2559 | case ISCSI_IFACE_PARAM_ERL: |
| 2560 | if (iface_param->iface_num & 0x1) |
| 2561 | break; |
| 2562 | init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL); |
| 2563 | init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] & |
| 2564 | ISCSIOPTS_ERL); |
| 2565 | break; |
| 2566 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 2567 | if (iface_param->iface_num & 0x1) |
| 2568 | break; |
| 2569 | init_fw_cb->iscsi_max_pdu_size = |
| 2570 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2571 | BYTE_UNITS; |
| 2572 | break; |
| 2573 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 2574 | if (iface_param->iface_num & 0x1) |
| 2575 | break; |
| 2576 | init_fw_cb->iscsi_fburst_len = |
| 2577 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2578 | BYTE_UNITS; |
| 2579 | break; |
| 2580 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 2581 | if (iface_param->iface_num & 0x1) |
| 2582 | break; |
| 2583 | init_fw_cb->iscsi_max_outstnd_r2t = |
| 2584 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2585 | break; |
| 2586 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 2587 | if (iface_param->iface_num & 0x1) |
| 2588 | break; |
| 2589 | init_fw_cb->iscsi_max_burst_len = |
| 2590 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2591 | BYTE_UNITS; |
| 2592 | break; |
| 2593 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 2594 | if (iface_param->iface_num & 0x1) |
| 2595 | break; |
| 2596 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2597 | init_fw_cb->iscsi_opts |= |
| 2598 | cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN); |
| 2599 | else |
| 2600 | init_fw_cb->iscsi_opts &= |
| 2601 | cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN); |
| 2602 | break; |
| 2603 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 2604 | if (iface_param->iface_num & 0x1) |
| 2605 | break; |
| 2606 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2607 | init_fw_cb->iscsi_opts |= |
| 2608 | cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN); |
| 2609 | else |
| 2610 | init_fw_cb->iscsi_opts &= |
| 2611 | cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN); |
| 2612 | break; |
| 2613 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 2614 | if (iface_param->iface_num & 0x1) |
| 2615 | break; |
| 2616 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2617 | init_fw_cb->iscsi_opts |= |
| 2618 | cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN); |
| 2619 | else |
| 2620 | init_fw_cb->iscsi_opts &= |
| 2621 | cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN); |
| 2622 | break; |
| 2623 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 2624 | if (iface_param->iface_num & 0x1) |
| 2625 | break; |
| 2626 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2627 | init_fw_cb->iscsi_opts |= |
| 2628 | cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN); |
| 2629 | else |
| 2630 | init_fw_cb->iscsi_opts &= |
| 2631 | cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN); |
| 2632 | break; |
| 2633 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 2634 | if (iface_param->iface_num & 0x1) |
| 2635 | break; |
| 2636 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2637 | init_fw_cb->iscsi_opts |= |
| 2638 | cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN); |
| 2639 | else |
| 2640 | init_fw_cb->iscsi_opts &= |
| 2641 | cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN); |
| 2642 | break; |
| 2643 | default: |
| 2644 | ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n", |
| 2645 | iface_param->param); |
| 2646 | break; |
| 2647 | } |
| 2648 | } |
| 2649 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2650 | static void |
| 2651 | qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) |
| 2652 | { |
| 2653 | struct addr_ctrl_blk_def *acb; |
| 2654 | acb = (struct addr_ctrl_blk_def *)init_fw_cb; |
| 2655 | memset(acb->reserved1, 0, sizeof(acb->reserved1)); |
| 2656 | memset(acb->reserved2, 0, sizeof(acb->reserved2)); |
| 2657 | memset(acb->reserved3, 0, sizeof(acb->reserved3)); |
| 2658 | memset(acb->reserved4, 0, sizeof(acb->reserved4)); |
| 2659 | memset(acb->reserved5, 0, sizeof(acb->reserved5)); |
| 2660 | memset(acb->reserved6, 0, sizeof(acb->reserved6)); |
| 2661 | memset(acb->reserved7, 0, sizeof(acb->reserved7)); |
| 2662 | memset(acb->reserved8, 0, sizeof(acb->reserved8)); |
| 2663 | memset(acb->reserved9, 0, sizeof(acb->reserved9)); |
| 2664 | memset(acb->reserved10, 0, sizeof(acb->reserved10)); |
| 2665 | memset(acb->reserved11, 0, sizeof(acb->reserved11)); |
| 2666 | memset(acb->reserved12, 0, sizeof(acb->reserved12)); |
| 2667 | memset(acb->reserved13, 0, sizeof(acb->reserved13)); |
| 2668 | memset(acb->reserved14, 0, sizeof(acb->reserved14)); |
| 2669 | memset(acb->reserved15, 0, sizeof(acb->reserved15)); |
| 2670 | } |
| 2671 | |
| 2672 | static int |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2673 | 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] | 2674 | { |
| 2675 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 2676 | int rval = 0; |
| 2677 | struct iscsi_iface_param_info *iface_param = NULL; |
| 2678 | struct addr_ctrl_blk *init_fw_cb = NULL; |
| 2679 | dma_addr_t init_fw_cb_dma; |
| 2680 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2681 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2682 | uint32_t rem = len; |
| 2683 | struct nlattr *attr; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2684 | |
| 2685 | init_fw_cb = dma_alloc_coherent(&ha->pdev->dev, |
| 2686 | sizeof(struct addr_ctrl_blk), |
| 2687 | &init_fw_cb_dma, GFP_KERNEL); |
| 2688 | if (!init_fw_cb) { |
| 2689 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", |
| 2690 | __func__); |
| 2691 | return -ENOMEM; |
| 2692 | } |
| 2693 | |
| 2694 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 2695 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2696 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2697 | |
| 2698 | if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { |
| 2699 | ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); |
| 2700 | rval = -EIO; |
| 2701 | goto exit_init_fw_cb; |
| 2702 | } |
| 2703 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2704 | nla_for_each_attr(attr, data, len, rem) { |
| 2705 | iface_param = nla_data(attr); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2706 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2707 | if (iface_param->param_type == ISCSI_NET_PARAM) { |
| 2708 | switch (iface_param->iface_type) { |
| 2709 | case ISCSI_IFACE_TYPE_IPV4: |
| 2710 | switch (iface_param->iface_num) { |
| 2711 | case 0: |
| 2712 | qla4xxx_set_ipv4(ha, iface_param, |
| 2713 | init_fw_cb); |
| 2714 | break; |
| 2715 | default: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2716 | /* Cannot have more than one IPv4 interface */ |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2717 | ql4_printk(KERN_ERR, ha, |
| 2718 | "Invalid IPv4 iface number = %d\n", |
| 2719 | iface_param->iface_num); |
| 2720 | break; |
| 2721 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2722 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2723 | case ISCSI_IFACE_TYPE_IPV6: |
| 2724 | switch (iface_param->iface_num) { |
| 2725 | case 0: |
| 2726 | case 1: |
| 2727 | qla4xxx_set_ipv6(ha, iface_param, |
| 2728 | init_fw_cb); |
| 2729 | break; |
| 2730 | default: |
| 2731 | /* Cannot have more than two IPv6 interface */ |
| 2732 | ql4_printk(KERN_ERR, ha, |
| 2733 | "Invalid IPv6 iface number = %d\n", |
| 2734 | iface_param->iface_num); |
| 2735 | break; |
| 2736 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2737 | break; |
| 2738 | default: |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2739 | ql4_printk(KERN_ERR, ha, |
| 2740 | "Invalid iface type\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2741 | break; |
| 2742 | } |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2743 | } else if (iface_param->param_type == ISCSI_IFACE_PARAM) { |
| 2744 | qla4xxx_set_iscsi_param(ha, iface_param, |
| 2745 | init_fw_cb); |
| 2746 | } else { |
| 2747 | continue; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2748 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); |
| 2752 | |
| 2753 | rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, |
| 2754 | sizeof(struct addr_ctrl_blk), |
| 2755 | FLASH_OPT_RMW_COMMIT); |
| 2756 | if (rval != QLA_SUCCESS) { |
| 2757 | ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", |
| 2758 | __func__); |
| 2759 | rval = -EIO; |
| 2760 | goto exit_init_fw_cb; |
| 2761 | } |
| 2762 | |
Vikas Chaudhary | ce505f9 | 2011-12-01 22:42:10 -0800 | [diff] [blame] | 2763 | rval = qla4xxx_disable_acb(ha); |
| 2764 | if (rval != QLA_SUCCESS) { |
| 2765 | ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n", |
| 2766 | __func__); |
| 2767 | rval = -EIO; |
| 2768 | goto exit_init_fw_cb; |
| 2769 | } |
| 2770 | |
| 2771 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 2772 | DISABLE_ACB_TOV * HZ); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2773 | |
| 2774 | qla4xxx_initcb_to_acb(init_fw_cb); |
| 2775 | |
| 2776 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); |
| 2777 | if (rval != QLA_SUCCESS) { |
| 2778 | ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", |
| 2779 | __func__); |
| 2780 | rval = -EIO; |
| 2781 | goto exit_init_fw_cb; |
| 2782 | } |
| 2783 | |
| 2784 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 2785 | qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, |
| 2786 | init_fw_cb_dma); |
| 2787 | |
| 2788 | exit_init_fw_cb: |
| 2789 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), |
| 2790 | init_fw_cb, init_fw_cb_dma); |
| 2791 | |
| 2792 | return rval; |
| 2793 | } |
| 2794 | |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2795 | static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess, |
| 2796 | enum iscsi_param param, char *buf) |
| 2797 | { |
| 2798 | struct iscsi_session *sess = cls_sess->dd_data; |
| 2799 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 2800 | struct scsi_qla_host *ha = ddb_entry->ha; |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2801 | struct iscsi_cls_conn *cls_conn = ddb_entry->conn; |
| 2802 | struct ql4_chap_table chap_tbl; |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2803 | int rval, len; |
| 2804 | uint16_t idx; |
| 2805 | |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2806 | memset(&chap_tbl, 0, sizeof(chap_tbl)); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2807 | switch (param) { |
| 2808 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 2809 | rval = qla4xxx_get_chap_index(ha, sess->username_in, |
| 2810 | sess->password_in, BIDI_CHAP, |
| 2811 | &idx); |
| 2812 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 2813 | len = sprintf(buf, "\n"); |
| 2814 | else |
| 2815 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2816 | break; |
| 2817 | case ISCSI_PARAM_CHAP_OUT_IDX: |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2818 | if (ddb_entry->ddb_type == FLASH_DDB) { |
| 2819 | if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) { |
| 2820 | idx = ddb_entry->chap_tbl_idx; |
| 2821 | rval = QLA_SUCCESS; |
| 2822 | } else { |
| 2823 | rval = QLA_ERROR; |
| 2824 | } |
| 2825 | } else { |
| 2826 | rval = qla4xxx_get_chap_index(ha, sess->username, |
| 2827 | sess->password, |
| 2828 | LOCAL_CHAP, &idx); |
| 2829 | } |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2830 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 2831 | len = sprintf(buf, "\n"); |
| 2832 | else |
| 2833 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2834 | break; |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2835 | case ISCSI_PARAM_USERNAME: |
| 2836 | case ISCSI_PARAM_PASSWORD: |
| 2837 | /* First, populate session username and password for FLASH DDB, |
| 2838 | * if not already done. This happens when session login fails |
| 2839 | * for a FLASH DDB. |
| 2840 | */ |
| 2841 | if (ddb_entry->ddb_type == FLASH_DDB && |
| 2842 | ddb_entry->chap_tbl_idx != INVALID_ENTRY && |
| 2843 | !sess->username && !sess->password) { |
| 2844 | idx = ddb_entry->chap_tbl_idx; |
| 2845 | rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name, |
| 2846 | chap_tbl.secret, |
| 2847 | idx); |
| 2848 | if (!rval) { |
| 2849 | iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME, |
| 2850 | (char *)chap_tbl.name, |
| 2851 | strlen((char *)chap_tbl.name)); |
| 2852 | iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD, |
| 2853 | (char *)chap_tbl.secret, |
| 2854 | chap_tbl.secret_len); |
| 2855 | } |
| 2856 | } |
| 2857 | /* allow fall-through */ |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2858 | default: |
| 2859 | return iscsi_session_get_param(cls_sess, param, buf); |
| 2860 | } |
| 2861 | |
| 2862 | return len; |
| 2863 | } |
| 2864 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2865 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2866 | enum iscsi_param param, char *buf) |
| 2867 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2868 | struct iscsi_conn *conn; |
| 2869 | struct qla_conn *qla_conn; |
| 2870 | struct sockaddr *dst_addr; |
| 2871 | int len = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2872 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2873 | conn = cls_conn->dd_data; |
| 2874 | qla_conn = conn->dd_data; |
Manish Rangankar | d46bdeb1 | 2012-08-07 07:57:13 -0400 | [diff] [blame] | 2875 | dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2876 | |
| 2877 | switch (param) { |
| 2878 | case ISCSI_PARAM_CONN_PORT: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2879 | case ISCSI_PARAM_CONN_ADDRESS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2880 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 2881 | dst_addr, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2882 | default: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2883 | return iscsi_conn_get_param(cls_conn, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | return len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2887 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2890 | int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index) |
| 2891 | { |
| 2892 | uint32_t mbx_sts = 0; |
| 2893 | uint16_t tmp_ddb_index; |
| 2894 | int ret; |
| 2895 | |
| 2896 | get_ddb_index: |
| 2897 | tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES); |
| 2898 | |
| 2899 | if (tmp_ddb_index >= MAX_DDB_ENTRIES) { |
| 2900 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2901 | "Free DDB index not available\n")); |
| 2902 | ret = QLA_ERROR; |
| 2903 | goto exit_get_ddb_index; |
| 2904 | } |
| 2905 | |
| 2906 | if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map)) |
| 2907 | goto get_ddb_index; |
| 2908 | |
| 2909 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2910 | "Found a free DDB index at %d\n", tmp_ddb_index)); |
| 2911 | ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts); |
| 2912 | if (ret == QLA_ERROR) { |
| 2913 | if (mbx_sts == MBOX_STS_COMMAND_ERROR) { |
| 2914 | ql4_printk(KERN_INFO, ha, |
| 2915 | "DDB index = %d not available trying next\n", |
| 2916 | tmp_ddb_index); |
| 2917 | goto get_ddb_index; |
| 2918 | } |
| 2919 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2920 | "Free FW DDB not available\n")); |
| 2921 | } |
| 2922 | |
| 2923 | *ddb_index = tmp_ddb_index; |
| 2924 | |
| 2925 | exit_get_ddb_index: |
| 2926 | return ret; |
| 2927 | } |
| 2928 | |
| 2929 | static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha, |
| 2930 | struct ddb_entry *ddb_entry, |
| 2931 | char *existing_ipaddr, |
| 2932 | char *user_ipaddr) |
| 2933 | { |
| 2934 | uint8_t dst_ipaddr[IPv6_ADDR_LEN]; |
| 2935 | char formatted_ipaddr[DDB_IPADDR_LEN]; |
| 2936 | int status = QLA_SUCCESS, ret = 0; |
| 2937 | |
| 2938 | if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) { |
| 2939 | ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 2940 | '\0', NULL); |
| 2941 | if (ret == 0) { |
| 2942 | status = QLA_ERROR; |
| 2943 | goto out_match; |
| 2944 | } |
| 2945 | ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr); |
| 2946 | } else { |
| 2947 | ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 2948 | '\0', NULL); |
| 2949 | if (ret == 0) { |
| 2950 | status = QLA_ERROR; |
| 2951 | goto out_match; |
| 2952 | } |
| 2953 | ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr); |
| 2954 | } |
| 2955 | |
| 2956 | if (strcmp(existing_ipaddr, formatted_ipaddr)) |
| 2957 | status = QLA_ERROR; |
| 2958 | |
| 2959 | out_match: |
| 2960 | return status; |
| 2961 | } |
| 2962 | |
| 2963 | static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha, |
| 2964 | struct iscsi_cls_conn *cls_conn) |
| 2965 | { |
| 2966 | int idx = 0, max_ddbs, rval; |
| 2967 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 2968 | struct iscsi_session *sess, *existing_sess; |
| 2969 | struct iscsi_conn *conn, *existing_conn; |
| 2970 | struct ddb_entry *ddb_entry; |
| 2971 | |
| 2972 | sess = cls_sess->dd_data; |
| 2973 | conn = cls_conn->dd_data; |
| 2974 | |
| 2975 | if (sess->targetname == NULL || |
| 2976 | conn->persistent_address == NULL || |
| 2977 | conn->persistent_port == 0) |
| 2978 | return QLA_ERROR; |
| 2979 | |
| 2980 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 2981 | MAX_DEV_DB_ENTRIES; |
| 2982 | |
| 2983 | for (idx = 0; idx < max_ddbs; idx++) { |
| 2984 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 2985 | if (ddb_entry == NULL) |
| 2986 | continue; |
| 2987 | |
| 2988 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 2989 | continue; |
| 2990 | |
| 2991 | existing_sess = ddb_entry->sess->dd_data; |
| 2992 | existing_conn = ddb_entry->conn->dd_data; |
| 2993 | |
| 2994 | if (existing_sess->targetname == NULL || |
| 2995 | existing_conn->persistent_address == NULL || |
| 2996 | existing_conn->persistent_port == 0) |
| 2997 | continue; |
| 2998 | |
| 2999 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3000 | "IQN = %s User IQN = %s\n", |
| 3001 | existing_sess->targetname, |
| 3002 | sess->targetname)); |
| 3003 | |
| 3004 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3005 | "IP = %s User IP = %s\n", |
| 3006 | existing_conn->persistent_address, |
| 3007 | conn->persistent_address)); |
| 3008 | |
| 3009 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3010 | "Port = %d User Port = %d\n", |
| 3011 | existing_conn->persistent_port, |
| 3012 | conn->persistent_port)); |
| 3013 | |
| 3014 | if (strcmp(existing_sess->targetname, sess->targetname)) |
| 3015 | continue; |
| 3016 | rval = qla4xxx_match_ipaddress(ha, ddb_entry, |
| 3017 | existing_conn->persistent_address, |
| 3018 | conn->persistent_address); |
| 3019 | if (rval == QLA_ERROR) |
| 3020 | continue; |
| 3021 | if (existing_conn->persistent_port != conn->persistent_port) |
| 3022 | continue; |
| 3023 | break; |
| 3024 | } |
| 3025 | |
| 3026 | if (idx == max_ddbs) |
| 3027 | return QLA_ERROR; |
| 3028 | |
| 3029 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3030 | "Match found in fwdb sessions\n")); |
| 3031 | return QLA_SUCCESS; |
| 3032 | } |
| 3033 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3034 | static struct iscsi_cls_session * |
| 3035 | qla4xxx_session_create(struct iscsi_endpoint *ep, |
| 3036 | uint16_t cmds_max, uint16_t qdepth, |
| 3037 | uint32_t initial_cmdsn) |
| 3038 | { |
| 3039 | struct iscsi_cls_session *cls_sess; |
| 3040 | struct scsi_qla_host *ha; |
| 3041 | struct qla_endpoint *qla_ep; |
| 3042 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3043 | uint16_t ddb_index; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3044 | struct iscsi_session *sess; |
| 3045 | struct sockaddr *dst_addr; |
| 3046 | int ret; |
| 3047 | |
| 3048 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3049 | if (!ep) { |
| 3050 | printk(KERN_ERR "qla4xxx: missing ep.\n"); |
| 3051 | return NULL; |
| 3052 | } |
| 3053 | |
| 3054 | qla_ep = ep->dd_data; |
| 3055 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 3056 | ha = to_qla_host(qla_ep->host); |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 3057 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3058 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 3059 | if (ret == QLA_ERROR) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3060 | return NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3061 | |
| 3062 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host, |
| 3063 | cmds_max, sizeof(struct ddb_entry), |
| 3064 | sizeof(struct ql4_task_data), |
| 3065 | initial_cmdsn, ddb_index); |
| 3066 | if (!cls_sess) |
| 3067 | return NULL; |
| 3068 | |
| 3069 | sess = cls_sess->dd_data; |
| 3070 | ddb_entry = sess->dd_data; |
| 3071 | ddb_entry->fw_ddb_index = ddb_index; |
| 3072 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 3073 | ddb_entry->ha = ha; |
| 3074 | ddb_entry->sess = cls_sess; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3075 | ddb_entry->unblock_sess = qla4xxx_unblock_ddb; |
| 3076 | ddb_entry->ddb_change = qla4xxx_ddb_change; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3077 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 3078 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| 3079 | ha->tot_ddbs++; |
| 3080 | |
| 3081 | return cls_sess; |
| 3082 | } |
| 3083 | |
| 3084 | static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess) |
| 3085 | { |
| 3086 | struct iscsi_session *sess; |
| 3087 | struct ddb_entry *ddb_entry; |
| 3088 | struct scsi_qla_host *ha; |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3089 | unsigned long flags, wtime; |
| 3090 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 3091 | dma_addr_t fw_ddb_entry_dma; |
| 3092 | uint32_t ddb_state; |
| 3093 | int ret; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3094 | |
| 3095 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3096 | sess = cls_sess->dd_data; |
| 3097 | ddb_entry = sess->dd_data; |
| 3098 | ha = ddb_entry->ha; |
| 3099 | |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3100 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3101 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3102 | if (!fw_ddb_entry) { |
| 3103 | ql4_printk(KERN_ERR, ha, |
| 3104 | "%s: Unable to allocate dma buffer\n", __func__); |
| 3105 | goto destroy_session; |
| 3106 | } |
| 3107 | |
| 3108 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 3109 | do { |
| 3110 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 3111 | fw_ddb_entry, fw_ddb_entry_dma, |
| 3112 | NULL, NULL, &ddb_state, NULL, |
| 3113 | NULL, NULL); |
| 3114 | if (ret == QLA_ERROR) |
| 3115 | goto destroy_session; |
| 3116 | |
| 3117 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 3118 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 3119 | goto destroy_session; |
| 3120 | |
| 3121 | schedule_timeout_uninterruptible(HZ); |
| 3122 | } while ((time_after(wtime, jiffies))); |
| 3123 | |
| 3124 | destroy_session: |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 3125 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 3126 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3127 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3128 | qla4xxx_free_ddb(ha, ddb_entry); |
| 3129 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3130 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3131 | iscsi_session_teardown(cls_sess); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3132 | |
| 3133 | if (fw_ddb_entry) |
| 3134 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3135 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3136 | } |
| 3137 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3138 | static struct iscsi_cls_conn * |
| 3139 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx) |
| 3140 | { |
| 3141 | struct iscsi_cls_conn *cls_conn; |
| 3142 | struct iscsi_session *sess; |
| 3143 | struct ddb_entry *ddb_entry; |
| 3144 | |
| 3145 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3146 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), |
| 3147 | conn_idx); |
Mike Christie | ff1d031 | 2011-12-01 21:38:43 -0600 | [diff] [blame] | 3148 | if (!cls_conn) |
| 3149 | return NULL; |
| 3150 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3151 | sess = cls_sess->dd_data; |
| 3152 | ddb_entry = sess->dd_data; |
| 3153 | ddb_entry->conn = cls_conn; |
| 3154 | |
| 3155 | return cls_conn; |
| 3156 | } |
| 3157 | |
| 3158 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 3159 | struct iscsi_cls_conn *cls_conn, |
| 3160 | uint64_t transport_fd, int is_leading) |
| 3161 | { |
| 3162 | struct iscsi_conn *conn; |
| 3163 | struct qla_conn *qla_conn; |
| 3164 | struct iscsi_endpoint *ep; |
| 3165 | |
| 3166 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3167 | |
| 3168 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
| 3169 | return -EINVAL; |
| 3170 | ep = iscsi_lookup_endpoint(transport_fd); |
| 3171 | conn = cls_conn->dd_data; |
| 3172 | qla_conn = conn->dd_data; |
| 3173 | qla_conn->qla_ep = ep->dd_data; |
| 3174 | return 0; |
| 3175 | } |
| 3176 | |
| 3177 | static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn) |
| 3178 | { |
| 3179 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 3180 | struct iscsi_session *sess; |
| 3181 | struct ddb_entry *ddb_entry; |
| 3182 | struct scsi_qla_host *ha; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3183 | struct dev_db_entry *fw_ddb_entry = NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3184 | dma_addr_t fw_ddb_entry_dma; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3185 | uint32_t mbx_sts = 0; |
| 3186 | int ret = 0; |
| 3187 | int status = QLA_SUCCESS; |
| 3188 | |
| 3189 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3190 | sess = cls_sess->dd_data; |
| 3191 | ddb_entry = sess->dd_data; |
| 3192 | ha = ddb_entry->ha; |
| 3193 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3194 | /* Check if we have matching FW DDB, if yes then do not |
| 3195 | * login to this target. This could cause target to logout previous |
| 3196 | * connection |
| 3197 | */ |
| 3198 | ret = qla4xxx_match_fwdb_session(ha, cls_conn); |
| 3199 | if (ret == QLA_SUCCESS) { |
| 3200 | ql4_printk(KERN_INFO, ha, |
| 3201 | "Session already exist in FW.\n"); |
| 3202 | ret = -EEXIST; |
| 3203 | goto exit_conn_start; |
| 3204 | } |
| 3205 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3206 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3207 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3208 | if (!fw_ddb_entry) { |
| 3209 | ql4_printk(KERN_ERR, ha, |
| 3210 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3211 | ret = -ENOMEM; |
| 3212 | goto exit_conn_start; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts); |
| 3216 | if (ret) { |
| 3217 | /* If iscsid is stopped and started then no need to do |
| 3218 | * set param again since ddb state will be already |
| 3219 | * active and FW does not allow set ddb to an |
| 3220 | * active session. |
| 3221 | */ |
| 3222 | if (mbx_sts) |
| 3223 | if (ddb_entry->fw_ddb_device_state == |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 3224 | DDB_DS_SESSION_ACTIVE) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3225 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3226 | goto exit_set_param; |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 3227 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3228 | |
| 3229 | ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n", |
| 3230 | __func__, ddb_entry->fw_ddb_index); |
| 3231 | goto exit_conn_start; |
| 3232 | } |
| 3233 | |
| 3234 | status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| 3235 | if (status == QLA_ERROR) { |
Manish Rangankar | 0e7e850 | 2011-07-25 13:48:54 -0500 | [diff] [blame] | 3236 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| 3237 | sess->targetname); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3238 | ret = -EINVAL; |
| 3239 | goto exit_conn_start; |
| 3240 | } |
| 3241 | |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 3242 | if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) |
| 3243 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| 3244 | |
| 3245 | DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__, |
| 3246 | ddb_entry->fw_ddb_device_state)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3247 | |
| 3248 | exit_set_param: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3249 | ret = 0; |
| 3250 | |
| 3251 | exit_conn_start: |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3252 | if (fw_ddb_entry) |
| 3253 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3254 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3255 | return ret; |
| 3256 | } |
| 3257 | |
| 3258 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| 3259 | { |
| 3260 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 3261 | struct iscsi_session *sess; |
| 3262 | struct scsi_qla_host *ha; |
| 3263 | struct ddb_entry *ddb_entry; |
| 3264 | int options; |
| 3265 | |
| 3266 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3267 | sess = cls_sess->dd_data; |
| 3268 | ddb_entry = sess->dd_data; |
| 3269 | ha = ddb_entry->ha; |
| 3270 | |
| 3271 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 3272 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) |
| 3273 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | static void qla4xxx_task_work(struct work_struct *wdata) |
| 3277 | { |
| 3278 | struct ql4_task_data *task_data; |
| 3279 | struct scsi_qla_host *ha; |
| 3280 | struct passthru_status *sts; |
| 3281 | struct iscsi_task *task; |
| 3282 | struct iscsi_hdr *hdr; |
| 3283 | uint8_t *data; |
| 3284 | uint32_t data_len; |
| 3285 | struct iscsi_conn *conn; |
| 3286 | int hdr_len; |
| 3287 | itt_t itt; |
| 3288 | |
| 3289 | task_data = container_of(wdata, struct ql4_task_data, task_work); |
| 3290 | ha = task_data->ha; |
| 3291 | task = task_data->task; |
| 3292 | sts = &task_data->sts; |
| 3293 | hdr_len = sizeof(struct iscsi_hdr); |
| 3294 | |
| 3295 | DEBUG3(printk(KERN_INFO "Status returned\n")); |
| 3296 | DEBUG3(qla4xxx_dump_buffer(sts, 64)); |
| 3297 | DEBUG3(printk(KERN_INFO "Response buffer")); |
| 3298 | DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64)); |
| 3299 | |
| 3300 | conn = task->conn; |
| 3301 | |
| 3302 | switch (sts->completionStatus) { |
| 3303 | case PASSTHRU_STATUS_COMPLETE: |
| 3304 | hdr = (struct iscsi_hdr *)task_data->resp_buffer; |
| 3305 | /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */ |
| 3306 | itt = sts->handle; |
| 3307 | hdr->itt = itt; |
| 3308 | data = task_data->resp_buffer + hdr_len; |
| 3309 | data_len = task_data->resp_len - hdr_len; |
| 3310 | iscsi_complete_pdu(conn, hdr, data, data_len); |
| 3311 | break; |
| 3312 | default: |
| 3313 | ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n", |
| 3314 | sts->completionStatus); |
| 3315 | break; |
| 3316 | } |
| 3317 | return; |
| 3318 | } |
| 3319 | |
| 3320 | static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 3321 | { |
| 3322 | struct ql4_task_data *task_data; |
| 3323 | struct iscsi_session *sess; |
| 3324 | struct ddb_entry *ddb_entry; |
| 3325 | struct scsi_qla_host *ha; |
| 3326 | int hdr_len; |
| 3327 | |
| 3328 | sess = task->conn->session; |
| 3329 | ddb_entry = sess->dd_data; |
| 3330 | ha = ddb_entry->ha; |
| 3331 | task_data = task->dd_data; |
| 3332 | memset(task_data, 0, sizeof(struct ql4_task_data)); |
| 3333 | |
| 3334 | if (task->sc) { |
| 3335 | ql4_printk(KERN_INFO, ha, |
| 3336 | "%s: SCSI Commands not implemented\n", __func__); |
| 3337 | return -EINVAL; |
| 3338 | } |
| 3339 | |
| 3340 | hdr_len = sizeof(struct iscsi_hdr); |
| 3341 | task_data->ha = ha; |
| 3342 | task_data->task = task; |
| 3343 | |
| 3344 | if (task->data_count) { |
| 3345 | task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data, |
| 3346 | task->data_count, |
| 3347 | PCI_DMA_TODEVICE); |
| 3348 | } |
| 3349 | |
| 3350 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 3351 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 3352 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3353 | task_data->resp_len = task->conn->max_recv_dlength + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3354 | task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| 3355 | task_data->resp_len, |
| 3356 | &task_data->resp_dma, |
| 3357 | GFP_ATOMIC); |
| 3358 | if (!task_data->resp_buffer) |
| 3359 | goto exit_alloc_pdu; |
| 3360 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3361 | task_data->req_len = task->data_count + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3362 | task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev, |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3363 | task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3364 | &task_data->req_dma, |
| 3365 | GFP_ATOMIC); |
| 3366 | if (!task_data->req_buffer) |
| 3367 | goto exit_alloc_pdu; |
| 3368 | |
| 3369 | task->hdr = task_data->req_buffer; |
| 3370 | |
| 3371 | INIT_WORK(&task_data->task_work, qla4xxx_task_work); |
| 3372 | |
| 3373 | return 0; |
| 3374 | |
| 3375 | exit_alloc_pdu: |
| 3376 | if (task_data->resp_buffer) |
| 3377 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 3378 | task_data->resp_buffer, task_data->resp_dma); |
| 3379 | |
| 3380 | if (task_data->req_buffer) |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3381 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3382 | task_data->req_buffer, task_data->req_dma); |
| 3383 | return -ENOMEM; |
| 3384 | } |
| 3385 | |
| 3386 | static void qla4xxx_task_cleanup(struct iscsi_task *task) |
| 3387 | { |
| 3388 | struct ql4_task_data *task_data; |
| 3389 | struct iscsi_session *sess; |
| 3390 | struct ddb_entry *ddb_entry; |
| 3391 | struct scsi_qla_host *ha; |
| 3392 | int hdr_len; |
| 3393 | |
| 3394 | hdr_len = sizeof(struct iscsi_hdr); |
| 3395 | sess = task->conn->session; |
| 3396 | ddb_entry = sess->dd_data; |
| 3397 | ha = ddb_entry->ha; |
| 3398 | task_data = task->dd_data; |
| 3399 | |
| 3400 | if (task->data_count) { |
| 3401 | dma_unmap_single(&ha->pdev->dev, task_data->data_dma, |
| 3402 | task->data_count, PCI_DMA_TODEVICE); |
| 3403 | } |
| 3404 | |
| 3405 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 3406 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 3407 | |
| 3408 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 3409 | task_data->resp_buffer, task_data->resp_dma); |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3410 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3411 | task_data->req_buffer, task_data->req_dma); |
| 3412 | return; |
| 3413 | } |
| 3414 | |
| 3415 | static int qla4xxx_task_xmit(struct iscsi_task *task) |
| 3416 | { |
| 3417 | struct scsi_cmnd *sc = task->sc; |
| 3418 | struct iscsi_session *sess = task->conn->session; |
| 3419 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 3420 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 3421 | |
| 3422 | if (!sc) |
| 3423 | return qla4xxx_send_passthru0(task); |
| 3424 | |
| 3425 | ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n", |
| 3426 | __func__); |
| 3427 | return -ENOSYS; |
| 3428 | } |
| 3429 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3430 | static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 3431 | struct iscsi_bus_flash_conn *conn, |
| 3432 | struct dev_db_entry *fw_ddb_entry) |
| 3433 | { |
| 3434 | unsigned long options = 0; |
| 3435 | int rc = 0; |
| 3436 | |
| 3437 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3438 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 3439 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3440 | rc = iscsi_switch_str_param(&sess->portal_type, |
| 3441 | PORTAL_TYPE_IPV6); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3442 | if (rc) |
| 3443 | goto exit_copy; |
| 3444 | } else { |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3445 | rc = iscsi_switch_str_param(&sess->portal_type, |
| 3446 | PORTAL_TYPE_IPV4); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3447 | if (rc) |
| 3448 | goto exit_copy; |
| 3449 | } |
| 3450 | |
| 3451 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 3452 | &options); |
| 3453 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 3454 | sess->entry_state = test_bit(OPT_ENTRY_STATE, &options); |
| 3455 | |
| 3456 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3457 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 3458 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 3459 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 3460 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 3461 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 3462 | &options); |
| 3463 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 3464 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 3465 | conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options); |
| 3466 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 3467 | &options); |
| 3468 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 3469 | sess->discovery_auth_optional = |
| 3470 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 3471 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 3472 | sess->erl |= BIT_1; |
| 3473 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 3474 | sess->erl |= BIT_0; |
| 3475 | |
| 3476 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3477 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 3478 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 3479 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 3480 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 3481 | conn->tcp_timer_scale |= BIT_3; |
| 3482 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 3483 | conn->tcp_timer_scale |= BIT_2; |
| 3484 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 3485 | conn->tcp_timer_scale |= BIT_1; |
| 3486 | |
| 3487 | conn->tcp_timer_scale >>= 1; |
| 3488 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 3489 | |
| 3490 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3491 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 3492 | |
| 3493 | conn->max_recv_dlength = BYTE_UNITS * |
| 3494 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 3495 | conn->max_xmit_dlength = BYTE_UNITS * |
| 3496 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 3497 | sess->first_burst = BYTE_UNITS * |
| 3498 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 3499 | sess->max_burst = BYTE_UNITS * |
| 3500 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 3501 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 3502 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3503 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 3504 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3505 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 3506 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 3507 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 3508 | conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl); |
| 3509 | conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 3510 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 3511 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 3512 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 3513 | sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 3514 | sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 3515 | sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3516 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 3517 | |
| 3518 | sess->default_taskmgmt_timeout = |
| 3519 | le16_to_cpu(fw_ddb_entry->def_timeout); |
| 3520 | conn->port = le16_to_cpu(fw_ddb_entry->port); |
| 3521 | |
| 3522 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3523 | conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3524 | if (!conn->ipaddress) { |
| 3525 | rc = -ENOMEM; |
| 3526 | goto exit_copy; |
| 3527 | } |
| 3528 | |
| 3529 | conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3530 | if (!conn->redirect_ipaddr) { |
| 3531 | rc = -ENOMEM; |
| 3532 | goto exit_copy; |
| 3533 | } |
| 3534 | |
| 3535 | memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 3536 | memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN); |
| 3537 | |
| 3538 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
| 3539 | conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos; |
| 3540 | |
| 3541 | conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3542 | if (!conn->link_local_ipv6_addr) { |
| 3543 | rc = -ENOMEM; |
| 3544 | goto exit_copy; |
| 3545 | } |
| 3546 | |
| 3547 | memcpy(conn->link_local_ipv6_addr, |
| 3548 | fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN); |
| 3549 | } else { |
| 3550 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 3551 | } |
| 3552 | |
| 3553 | if (fw_ddb_entry->iscsi_name[0]) { |
| 3554 | rc = iscsi_switch_str_param(&sess->targetname, |
| 3555 | (char *)fw_ddb_entry->iscsi_name); |
| 3556 | if (rc) |
| 3557 | goto exit_copy; |
| 3558 | } |
| 3559 | |
| 3560 | if (fw_ddb_entry->iscsi_alias[0]) { |
| 3561 | rc = iscsi_switch_str_param(&sess->targetalias, |
| 3562 | (char *)fw_ddb_entry->iscsi_alias); |
| 3563 | if (rc) |
| 3564 | goto exit_copy; |
| 3565 | } |
| 3566 | |
| 3567 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 3568 | |
| 3569 | exit_copy: |
| 3570 | return rc; |
| 3571 | } |
| 3572 | |
| 3573 | static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 3574 | struct iscsi_bus_flash_conn *conn, |
| 3575 | struct dev_db_entry *fw_ddb_entry) |
| 3576 | { |
| 3577 | uint16_t options; |
| 3578 | int rc = 0; |
| 3579 | |
| 3580 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3581 | SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11); |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3582 | if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3583 | options |= BIT_8; |
| 3584 | else |
| 3585 | options &= ~BIT_8; |
| 3586 | |
| 3587 | SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6); |
| 3588 | SET_BITVAL(sess->discovery_sess, options, BIT_4); |
| 3589 | SET_BITVAL(sess->entry_state, options, BIT_3); |
| 3590 | fw_ddb_entry->options = cpu_to_le16(options); |
| 3591 | |
| 3592 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3593 | SET_BITVAL(conn->hdrdgst_en, options, BIT_13); |
| 3594 | SET_BITVAL(conn->datadgst_en, options, BIT_12); |
| 3595 | SET_BITVAL(sess->imm_data_en, options, BIT_11); |
| 3596 | SET_BITVAL(sess->initial_r2t_en, options, BIT_10); |
| 3597 | SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9); |
| 3598 | SET_BITVAL(sess->pdu_inorder_en, options, BIT_8); |
| 3599 | SET_BITVAL(sess->chap_auth_en, options, BIT_7); |
| 3600 | SET_BITVAL(conn->snack_req_en, options, BIT_6); |
| 3601 | SET_BITVAL(sess->discovery_logout_en, options, BIT_5); |
| 3602 | SET_BITVAL(sess->bidi_chap_en, options, BIT_4); |
| 3603 | SET_BITVAL(sess->discovery_auth_optional, options, BIT_3); |
| 3604 | SET_BITVAL(sess->erl & BIT_1, options, BIT_1); |
| 3605 | SET_BITVAL(sess->erl & BIT_0, options, BIT_0); |
| 3606 | fw_ddb_entry->iscsi_options = cpu_to_le16(options); |
| 3607 | |
| 3608 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3609 | SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6); |
| 3610 | SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5); |
| 3611 | SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4); |
| 3612 | SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3); |
| 3613 | SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2); |
| 3614 | SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1); |
| 3615 | SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0); |
| 3616 | fw_ddb_entry->tcp_options = cpu_to_le16(options); |
| 3617 | |
| 3618 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3619 | SET_BITVAL(conn->fragment_disable, options, BIT_4); |
| 3620 | fw_ddb_entry->ip_options = cpu_to_le16(options); |
| 3621 | |
| 3622 | fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t); |
| 3623 | fw_ddb_entry->iscsi_max_rcv_data_seg_len = |
| 3624 | cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS); |
| 3625 | fw_ddb_entry->iscsi_max_snd_data_seg_len = |
| 3626 | cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS); |
| 3627 | fw_ddb_entry->iscsi_first_burst_len = |
| 3628 | cpu_to_le16(sess->first_burst / BYTE_UNITS); |
| 3629 | fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst / |
| 3630 | BYTE_UNITS); |
| 3631 | fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait); |
| 3632 | fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain); |
| 3633 | fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt); |
| 3634 | fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size); |
Adheer Chandravanshi | fbcd483 | 2013-04-17 05:15:29 -0400 | [diff] [blame] | 3635 | fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf); |
| 3636 | 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] | 3637 | fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label); |
| 3638 | fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout); |
| 3639 | fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port); |
Adheer Chandravanshi | fbcd483 | 2013-04-17 05:15:29 -0400 | [diff] [blame] | 3640 | fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn); |
| 3641 | fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn); |
Adheer Chandravanshi | 6556016 | 2013-07-08 08:33:06 -0400 | [diff] [blame] | 3642 | fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3643 | fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx); |
| 3644 | fw_ddb_entry->tsid = cpu_to_le16(sess->tsid); |
| 3645 | fw_ddb_entry->port = cpu_to_le16(conn->port); |
| 3646 | fw_ddb_entry->def_timeout = |
| 3647 | cpu_to_le16(sess->default_taskmgmt_timeout); |
| 3648 | |
Adheer Chandravanshi | 8459580 | 2013-07-08 08:33:07 -0400 | [diff] [blame] | 3649 | if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
| 3650 | fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class; |
| 3651 | else |
| 3652 | fw_ddb_entry->ipv4_tos = conn->ipv4_tos; |
| 3653 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3654 | if (conn->ipaddress) |
| 3655 | memcpy(fw_ddb_entry->ip_addr, conn->ipaddress, |
| 3656 | sizeof(fw_ddb_entry->ip_addr)); |
| 3657 | |
| 3658 | if (conn->redirect_ipaddr) |
| 3659 | memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr, |
| 3660 | sizeof(fw_ddb_entry->tgt_addr)); |
| 3661 | |
| 3662 | if (conn->link_local_ipv6_addr) |
| 3663 | memcpy(fw_ddb_entry->link_local_ipv6_addr, |
| 3664 | conn->link_local_ipv6_addr, |
| 3665 | sizeof(fw_ddb_entry->link_local_ipv6_addr)); |
| 3666 | |
| 3667 | if (sess->targetname) |
| 3668 | memcpy(fw_ddb_entry->iscsi_name, sess->targetname, |
| 3669 | sizeof(fw_ddb_entry->iscsi_name)); |
| 3670 | |
| 3671 | if (sess->targetalias) |
| 3672 | memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias, |
| 3673 | sizeof(fw_ddb_entry->iscsi_alias)); |
| 3674 | |
| 3675 | COPY_ISID(fw_ddb_entry->isid, sess->isid); |
| 3676 | |
| 3677 | return rc; |
| 3678 | } |
| 3679 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3680 | static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn, |
| 3681 | struct iscsi_session *sess, |
| 3682 | struct dev_db_entry *fw_ddb_entry) |
| 3683 | { |
| 3684 | unsigned long options = 0; |
| 3685 | uint16_t ddb_link; |
| 3686 | uint16_t disc_parent; |
Adheer Chandravanshi | fb734ee3 | 2013-11-22 05:28:22 -0500 | [diff] [blame] | 3687 | char ip_addr[DDB_IPADDR_LEN]; |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3688 | |
| 3689 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3690 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 3691 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 3692 | &options); |
| 3693 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 3694 | |
| 3695 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3696 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 3697 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 3698 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 3699 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 3700 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 3701 | &options); |
| 3702 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 3703 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 3704 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 3705 | &options); |
| 3706 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 3707 | sess->discovery_auth_optional = |
| 3708 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 3709 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 3710 | sess->erl |= BIT_1; |
| 3711 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 3712 | sess->erl |= BIT_0; |
| 3713 | |
| 3714 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3715 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 3716 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 3717 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 3718 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 3719 | conn->tcp_timer_scale |= BIT_3; |
| 3720 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 3721 | conn->tcp_timer_scale |= BIT_2; |
| 3722 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 3723 | conn->tcp_timer_scale |= BIT_1; |
| 3724 | |
| 3725 | conn->tcp_timer_scale >>= 1; |
| 3726 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 3727 | |
| 3728 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3729 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 3730 | |
| 3731 | conn->max_recv_dlength = BYTE_UNITS * |
| 3732 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 3733 | conn->max_xmit_dlength = BYTE_UNITS * |
| 3734 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 3735 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 3736 | sess->first_burst = BYTE_UNITS * |
| 3737 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 3738 | sess->max_burst = BYTE_UNITS * |
| 3739 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 3740 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3741 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 3742 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3743 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 3744 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 3745 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 3746 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 3747 | conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 3748 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 3749 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 3750 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 3751 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 3752 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 3753 | |
| 3754 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3755 | if (ddb_link == DDB_ISNS) |
| 3756 | disc_parent = ISCSI_DISC_PARENT_ISNS; |
| 3757 | else if (ddb_link == DDB_NO_LINK) |
| 3758 | disc_parent = ISCSI_DISC_PARENT_UNKNOWN; |
| 3759 | else if (ddb_link < MAX_DDB_ENTRIES) |
| 3760 | disc_parent = ISCSI_DISC_PARENT_SENDTGT; |
| 3761 | else |
| 3762 | disc_parent = ISCSI_DISC_PARENT_UNKNOWN; |
| 3763 | |
| 3764 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, |
| 3765 | iscsi_get_discovery_parent_name(disc_parent), 0); |
| 3766 | |
| 3767 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS, |
| 3768 | (char *)fw_ddb_entry->iscsi_alias, 0); |
Adheer Chandravanshi | fb734ee3 | 2013-11-22 05:28:22 -0500 | [diff] [blame] | 3769 | |
| 3770 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3771 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 3772 | memset(ip_addr, 0, sizeof(ip_addr)); |
| 3773 | sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr); |
| 3774 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR, |
| 3775 | (char *)ip_addr, 0); |
| 3776 | } |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3777 | } |
| 3778 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3779 | static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha, |
| 3780 | struct dev_db_entry *fw_ddb_entry, |
| 3781 | struct iscsi_cls_session *cls_sess, |
| 3782 | struct iscsi_cls_conn *cls_conn) |
| 3783 | { |
| 3784 | int buflen = 0; |
| 3785 | struct iscsi_session *sess; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3786 | struct ddb_entry *ddb_entry; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3787 | struct ql4_chap_table chap_tbl; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3788 | struct iscsi_conn *conn; |
| 3789 | char ip_addr[DDB_IPADDR_LEN]; |
| 3790 | uint16_t options = 0; |
| 3791 | |
| 3792 | sess = cls_sess->dd_data; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3793 | ddb_entry = sess->dd_data; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3794 | conn = cls_conn->dd_data; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3795 | memset(&chap_tbl, 0, sizeof(chap_tbl)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3796 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3797 | ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3798 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3799 | qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3800 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3801 | sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3802 | conn->persistent_port = le16_to_cpu(fw_ddb_entry->port); |
| 3803 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3804 | memset(ip_addr, 0, sizeof(ip_addr)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3805 | options = le16_to_cpu(fw_ddb_entry->options); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3806 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 3807 | iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3808 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3809 | memset(ip_addr, 0, sizeof(ip_addr)); |
| 3810 | sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 3811 | } else { |
| 3812 | iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4); |
| 3813 | sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 3814 | } |
| 3815 | |
| 3816 | iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS, |
| 3817 | (char *)ip_addr, buflen); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3818 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME, |
| 3819 | (char *)fw_ddb_entry->iscsi_name, buflen); |
| 3820 | iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME, |
| 3821 | (char *)ha->name_string, buflen); |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3822 | |
| 3823 | if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) { |
| 3824 | if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name, |
| 3825 | chap_tbl.secret, |
| 3826 | ddb_entry->chap_tbl_idx)) { |
| 3827 | iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME, |
| 3828 | (char *)chap_tbl.name, |
| 3829 | strlen((char *)chap_tbl.name)); |
| 3830 | iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD, |
| 3831 | (char *)chap_tbl.secret, |
| 3832 | chap_tbl.secret_len); |
| 3833 | } |
| 3834 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha, |
| 3838 | struct ddb_entry *ddb_entry) |
| 3839 | { |
| 3840 | struct iscsi_cls_session *cls_sess; |
| 3841 | struct iscsi_cls_conn *cls_conn; |
| 3842 | uint32_t ddb_state; |
| 3843 | dma_addr_t fw_ddb_entry_dma; |
| 3844 | struct dev_db_entry *fw_ddb_entry; |
| 3845 | |
| 3846 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3847 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3848 | if (!fw_ddb_entry) { |
| 3849 | ql4_printk(KERN_ERR, ha, |
| 3850 | "%s: Unable to allocate dma buffer\n", __func__); |
| 3851 | goto exit_session_conn_fwddb_param; |
| 3852 | } |
| 3853 | |
| 3854 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 3855 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 3856 | NULL, NULL, NULL) == QLA_ERROR) { |
| 3857 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 3858 | "get_ddb_entry for fw_ddb_index %d\n", |
| 3859 | ha->host_no, __func__, |
| 3860 | ddb_entry->fw_ddb_index)); |
| 3861 | goto exit_session_conn_fwddb_param; |
| 3862 | } |
| 3863 | |
| 3864 | cls_sess = ddb_entry->sess; |
| 3865 | |
| 3866 | cls_conn = ddb_entry->conn; |
| 3867 | |
| 3868 | /* Update params */ |
| 3869 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 3870 | |
| 3871 | exit_session_conn_fwddb_param: |
| 3872 | if (fw_ddb_entry) |
| 3873 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3874 | fw_ddb_entry, fw_ddb_entry_dma); |
| 3875 | } |
| 3876 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3877 | void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha, |
| 3878 | struct ddb_entry *ddb_entry) |
| 3879 | { |
| 3880 | struct iscsi_cls_session *cls_sess; |
| 3881 | struct iscsi_cls_conn *cls_conn; |
| 3882 | struct iscsi_session *sess; |
| 3883 | struct iscsi_conn *conn; |
| 3884 | uint32_t ddb_state; |
| 3885 | dma_addr_t fw_ddb_entry_dma; |
| 3886 | struct dev_db_entry *fw_ddb_entry; |
| 3887 | |
| 3888 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3889 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3890 | if (!fw_ddb_entry) { |
| 3891 | ql4_printk(KERN_ERR, ha, |
| 3892 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3893 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 3897 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 3898 | NULL, NULL, NULL) == QLA_ERROR) { |
| 3899 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 3900 | "get_ddb_entry for fw_ddb_index %d\n", |
| 3901 | ha->host_no, __func__, |
| 3902 | ddb_entry->fw_ddb_index)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3903 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | cls_sess = ddb_entry->sess; |
| 3907 | sess = cls_sess->dd_data; |
| 3908 | |
| 3909 | cls_conn = ddb_entry->conn; |
| 3910 | conn = cls_conn->dd_data; |
| 3911 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3912 | /* Update timers after login */ |
| 3913 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 3914 | (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) && |
| 3915 | (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ? |
| 3916 | le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3917 | ddb_entry->default_time2wait = |
| 3918 | le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3919 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3920 | /* Update params */ |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3921 | 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] | 3922 | qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3923 | |
| 3924 | memcpy(sess->initiatorname, ha->name_string, |
| 3925 | min(sizeof(ha->name_string), sizeof(sess->initiatorname))); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3926 | |
| 3927 | exit_session_conn_param: |
| 3928 | if (fw_ddb_entry) |
| 3929 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3930 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3931 | } |
| 3932 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3933 | /* |
| 3934 | * Timer routines |
| 3935 | */ |
| 3936 | |
| 3937 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, |
| 3938 | unsigned long interval) |
| 3939 | { |
| 3940 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| 3941 | __func__, ha->host->host_no)); |
| 3942 | init_timer(&ha->timer); |
| 3943 | ha->timer.expires = jiffies + interval * HZ; |
| 3944 | ha->timer.data = (unsigned long)ha; |
| 3945 | ha->timer.function = (void (*)(unsigned long))func; |
| 3946 | add_timer(&ha->timer); |
| 3947 | ha->timer_active = 1; |
| 3948 | } |
| 3949 | |
| 3950 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| 3951 | { |
| 3952 | del_timer_sync(&ha->timer); |
| 3953 | ha->timer_active = 0; |
| 3954 | } |
| 3955 | |
| 3956 | /*** |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3957 | * qla4xxx_mark_device_missing - blocks the session |
| 3958 | * @cls_session: Pointer to the session to be blocked |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3959 | * @ddb_entry: Pointer to device database entry |
| 3960 | * |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3961 | * This routine marks a device missing and close connection. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3962 | **/ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3963 | void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3964 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3965 | iscsi_block_session(cls_session); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3968 | /** |
| 3969 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| 3970 | * @ha: Pointer to host adapter structure. |
| 3971 | * |
| 3972 | * This routine marks a device missing and resets the relogin retry count. |
| 3973 | **/ |
| 3974 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| 3975 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3976 | iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3977 | } |
| 3978 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3979 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| 3980 | struct ddb_entry *ddb_entry, |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 3981 | struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3982 | { |
| 3983 | struct srb *srb; |
| 3984 | |
| 3985 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 3986 | if (!srb) |
| 3987 | return srb; |
| 3988 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 3989 | kref_init(&srb->srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3990 | srb->ha = ha; |
| 3991 | srb->ddb = ddb_entry; |
| 3992 | srb->cmd = cmd; |
| 3993 | srb->flags = 0; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 3994 | CMD_SP(cmd) = (void *)srb; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3995 | |
| 3996 | return srb; |
| 3997 | } |
| 3998 | |
| 3999 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| 4000 | { |
| 4001 | struct scsi_cmnd *cmd = srb->cmd; |
| 4002 | |
| 4003 | if (srb->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 4004 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4005 | srb->flags &= ~SRB_DMA_VALID; |
| 4006 | } |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 4007 | CMD_SP(cmd) = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4010 | void qla4xxx_srb_compl(struct kref *ref) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4011 | { |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4012 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4013 | struct scsi_cmnd *cmd = srb->cmd; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4014 | struct scsi_qla_host *ha = srb->ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4015 | |
| 4016 | qla4xxx_srb_free_dma(ha, srb); |
| 4017 | |
| 4018 | mempool_free(srb, ha->srb_mempool); |
| 4019 | |
| 4020 | cmd->scsi_done(cmd); |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4025 | * @host: scsi host |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4026 | * @cmd: Pointer to Linux's SCSI command structure |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4027 | * |
| 4028 | * Remarks: |
| 4029 | * This routine is invoked by Linux to send a SCSI command to the driver. |
| 4030 | * The mid-level driver tries to ensure that queuecommand never gets |
| 4031 | * invoked concurrently with itself or the interrupt handler (although |
| 4032 | * the interrupt handler may call this routine as part of request- |
| 4033 | * completion handling). Unfortunely, it sometimes calls the scheduler |
| 4034 | * in interrupt context which is a big NO! NO!. |
| 4035 | **/ |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4036 | static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4037 | { |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4038 | struct scsi_qla_host *ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4039 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 4040 | struct iscsi_cls_session *sess = ddb_entry->sess; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4041 | struct srb *srb; |
| 4042 | int rval; |
| 4043 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4044 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 4045 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 4046 | cmd->result = DID_NO_CONNECT << 16; |
| 4047 | else |
| 4048 | cmd->result = DID_REQUEUE << 16; |
| 4049 | goto qc_fail_command; |
| 4050 | } |
| 4051 | |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 4052 | if (!sess) { |
| 4053 | cmd->result = DID_IMM_RETRY << 16; |
| 4054 | goto qc_fail_command; |
| 4055 | } |
| 4056 | |
| 4057 | rval = iscsi_session_chkready(sess); |
| 4058 | if (rval) { |
| 4059 | cmd->result = rval; |
| 4060 | goto qc_fail_command; |
| 4061 | } |
| 4062 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4063 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 4064 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 4065 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 4066 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 4067 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| 4068 | !test_bit(AF_ONLINE, &ha->flags) || |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4069 | !test_bit(AF_LINK_UP, &ha->flags) || |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 4070 | test_bit(AF_LOOPBACK, &ha->flags) || |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 4071 | test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) || |
| 4072 | test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4073 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4074 | goto qc_host_busy; |
| 4075 | |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4076 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4077 | if (!srb) |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4078 | goto qc_host_busy; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4079 | |
| 4080 | rval = qla4xxx_send_command_to_isp(ha, srb); |
| 4081 | if (rval != QLA_SUCCESS) |
| 4082 | goto qc_host_busy_free_sp; |
| 4083 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4084 | return 0; |
| 4085 | |
| 4086 | qc_host_busy_free_sp: |
| 4087 | qla4xxx_srb_free_dma(ha, srb); |
| 4088 | mempool_free(srb, ha->srb_mempool); |
| 4089 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4090 | qc_host_busy: |
| 4091 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4092 | |
| 4093 | qc_fail_command: |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4094 | cmd->scsi_done(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4095 | |
| 4096 | return 0; |
| 4097 | } |
| 4098 | |
| 4099 | /** |
| 4100 | * qla4xxx_mem_free - frees memory allocated to adapter |
| 4101 | * @ha: Pointer to host adapter structure. |
| 4102 | * |
| 4103 | * Frees memory previously allocated by qla4xxx_mem_alloc |
| 4104 | **/ |
| 4105 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| 4106 | { |
| 4107 | if (ha->queues) |
| 4108 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| 4109 | ha->queues_dma); |
| 4110 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 4111 | if (ha->fw_dump) |
| 4112 | vfree(ha->fw_dump); |
| 4113 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4114 | ha->queues_len = 0; |
| 4115 | ha->queues = NULL; |
| 4116 | ha->queues_dma = 0; |
| 4117 | ha->request_ring = NULL; |
| 4118 | ha->request_dma = 0; |
| 4119 | ha->response_ring = NULL; |
| 4120 | ha->response_dma = 0; |
| 4121 | ha->shadow_regs = NULL; |
| 4122 | ha->shadow_regs_dma = 0; |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 4123 | ha->fw_dump = NULL; |
| 4124 | ha->fw_dump_size = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4125 | |
| 4126 | /* Free srb pool. */ |
| 4127 | if (ha->srb_mempool) |
| 4128 | mempool_destroy(ha->srb_mempool); |
| 4129 | |
| 4130 | ha->srb_mempool = NULL; |
| 4131 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4132 | if (ha->chap_dma_pool) |
| 4133 | dma_pool_destroy(ha->chap_dma_pool); |
| 4134 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 4135 | if (ha->chap_list) |
| 4136 | vfree(ha->chap_list); |
| 4137 | ha->chap_list = NULL; |
| 4138 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4139 | if (ha->fw_ddb_dma_pool) |
| 4140 | dma_pool_destroy(ha->fw_ddb_dma_pool); |
| 4141 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4142 | /* release io space registers */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4143 | if (is_qla8022(ha)) { |
| 4144 | if (ha->nx_pcibase) |
| 4145 | iounmap( |
| 4146 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4147 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4148 | if (ha->nx_pcibase) |
| 4149 | iounmap( |
| 4150 | (struct device_reg_83xx __iomem *)ha->nx_pcibase); |
| 4151 | } else if (ha->reg) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4152 | iounmap(ha->reg); |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | if (ha->reset_tmplt.buff) |
| 4156 | vfree(ha->reset_tmplt.buff); |
| 4157 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4158 | pci_release_regions(ha->pdev); |
| 4159 | } |
| 4160 | |
| 4161 | /** |
| 4162 | * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| 4163 | * @ha: Pointer to host adapter structure |
| 4164 | * |
| 4165 | * Allocates DMA memory for request and response queues. Also allocates memory |
| 4166 | * for srbs. |
| 4167 | **/ |
| 4168 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| 4169 | { |
| 4170 | unsigned long align; |
| 4171 | |
| 4172 | /* Allocate contiguous block of DMA memory for queues. */ |
| 4173 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4174 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4175 | sizeof(struct shadow_regs) + |
| 4176 | MEM_ALIGN_VALUE + |
| 4177 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 4178 | ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, |
| 4179 | &ha->queues_dma, GFP_KERNEL); |
| 4180 | if (ha->queues == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4181 | ql4_printk(KERN_WARNING, ha, |
| 4182 | "Memory Allocation failed - queues.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4183 | |
| 4184 | goto mem_alloc_error_exit; |
| 4185 | } |
| 4186 | memset(ha->queues, 0, ha->queues_len); |
| 4187 | |
| 4188 | /* |
| 4189 | * As per RISC alignment requirements -- the bus-address must be a |
| 4190 | * multiple of the request-ring size (in bytes). |
| 4191 | */ |
| 4192 | align = 0; |
| 4193 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| 4194 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| 4195 | (MEM_ALIGN_VALUE - 1)); |
| 4196 | |
| 4197 | /* Update request and response queue pointers. */ |
| 4198 | ha->request_dma = ha->queues_dma + align; |
| 4199 | ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| 4200 | ha->response_dma = ha->queues_dma + align + |
| 4201 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| 4202 | ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| 4203 | (REQUEST_QUEUE_DEPTH * |
| 4204 | QUEUE_SIZE)); |
| 4205 | ha->shadow_regs_dma = ha->queues_dma + align + |
| 4206 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4207 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| 4208 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| 4209 | (REQUEST_QUEUE_DEPTH * |
| 4210 | QUEUE_SIZE) + |
| 4211 | (RESPONSE_QUEUE_DEPTH * |
| 4212 | QUEUE_SIZE)); |
| 4213 | |
| 4214 | /* Allocate memory for srb pool. */ |
| 4215 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 4216 | mempool_free_slab, srb_cachep); |
| 4217 | if (ha->srb_mempool == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4218 | ql4_printk(KERN_WARNING, ha, |
| 4219 | "Memory Allocation failed - SRB Pool.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4220 | |
| 4221 | goto mem_alloc_error_exit; |
| 4222 | } |
| 4223 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4224 | ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev, |
| 4225 | CHAP_DMA_BLOCK_SIZE, 8, 0); |
| 4226 | |
| 4227 | if (ha->chap_dma_pool == NULL) { |
| 4228 | ql4_printk(KERN_WARNING, ha, |
| 4229 | "%s: chap_dma_pool allocation failed..\n", __func__); |
| 4230 | goto mem_alloc_error_exit; |
| 4231 | } |
| 4232 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4233 | ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev, |
| 4234 | DDB_DMA_BLOCK_SIZE, 8, 0); |
| 4235 | |
| 4236 | if (ha->fw_ddb_dma_pool == NULL) { |
| 4237 | ql4_printk(KERN_WARNING, ha, |
| 4238 | "%s: fw_ddb_dma_pool allocation failed..\n", |
| 4239 | __func__); |
| 4240 | goto mem_alloc_error_exit; |
| 4241 | } |
| 4242 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4243 | return QLA_SUCCESS; |
| 4244 | |
| 4245 | mem_alloc_error_exit: |
| 4246 | qla4xxx_mem_free(ha); |
| 4247 | return QLA_ERROR; |
| 4248 | } |
| 4249 | |
| 4250 | /** |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4251 | * qla4_8xxx_check_temp - Check the ISP82XX temperature. |
| 4252 | * @ha: adapter block pointer. |
| 4253 | * |
| 4254 | * Note: The caller should not hold the idc lock. |
| 4255 | **/ |
| 4256 | static int qla4_8xxx_check_temp(struct scsi_qla_host *ha) |
| 4257 | { |
| 4258 | uint32_t temp, temp_state, temp_val; |
| 4259 | int status = QLA_SUCCESS; |
| 4260 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4261 | temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4262 | |
| 4263 | temp_state = qla82xx_get_temp_state(temp); |
| 4264 | temp_val = qla82xx_get_temp_val(temp); |
| 4265 | |
| 4266 | if (temp_state == QLA82XX_TEMP_PANIC) { |
| 4267 | ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C" |
| 4268 | " exceeds maximum allowed. Hardware has been shut" |
| 4269 | " down.\n", temp_val); |
| 4270 | status = QLA_ERROR; |
| 4271 | } else if (temp_state == QLA82XX_TEMP_WARN) { |
| 4272 | if (ha->temperature == QLA82XX_TEMP_NORMAL) |
| 4273 | ql4_printk(KERN_WARNING, ha, "Device temperature %d" |
| 4274 | " degrees C exceeds operating range." |
| 4275 | " Immediate action needed.\n", temp_val); |
| 4276 | } else { |
| 4277 | if (ha->temperature == QLA82XX_TEMP_WARN) |
| 4278 | ql4_printk(KERN_INFO, ha, "Device temperature is" |
| 4279 | " now %d degrees C in normal range.\n", |
| 4280 | temp_val); |
| 4281 | } |
| 4282 | ha->temperature = temp_state; |
| 4283 | return status; |
| 4284 | } |
| 4285 | |
| 4286 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4287 | * qla4_8xxx_check_fw_alive - Check firmware health |
| 4288 | * @ha: Pointer to host adapter structure. |
| 4289 | * |
| 4290 | * Context: Interrupt |
| 4291 | **/ |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4292 | static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4293 | { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4294 | uint32_t fw_heartbeat_counter; |
| 4295 | int status = QLA_SUCCESS; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4296 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4297 | fw_heartbeat_counter = qla4_8xxx_rd_direct(ha, |
| 4298 | QLA8XXX_PEG_ALIVE_COUNTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4299 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| 4300 | if (fw_heartbeat_counter == 0xffffffff) { |
| 4301 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| 4302 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| 4303 | ha->host_no, __func__)); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4304 | return status; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4305 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4306 | |
| 4307 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| 4308 | ha->seconds_since_last_heartbeat++; |
| 4309 | /* FW not alive after 2 seconds */ |
| 4310 | if (ha->seconds_since_last_heartbeat == 2) { |
| 4311 | ha->seconds_since_last_heartbeat = 0; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4312 | qla4_8xxx_dump_peg_reg(ha); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4313 | status = QLA_ERROR; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4314 | } |
Lalit Chandivade | 99457d7 | 2010-10-06 22:49:32 -0700 | [diff] [blame] | 4315 | } else |
| 4316 | ha->seconds_since_last_heartbeat = 0; |
| 4317 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4318 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4319 | return status; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4320 | } |
| 4321 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4322 | static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha) |
| 4323 | { |
| 4324 | uint32_t halt_status; |
| 4325 | int halt_status_unrecoverable = 0; |
| 4326 | |
| 4327 | halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1); |
| 4328 | |
| 4329 | if (is_qla8022(ha)) { |
| 4330 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 4331 | __func__); |
| 4332 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 4333 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 4334 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 4335 | |
| 4336 | if (QLA82XX_FWERROR_CODE(halt_status) == 0x67) |
| 4337 | ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n", |
| 4338 | __func__); |
| 4339 | if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| 4340 | halt_status_unrecoverable = 1; |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4341 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4342 | if (halt_status & QLA83XX_HALT_STATUS_FW_RESET) |
| 4343 | ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n", |
| 4344 | __func__); |
| 4345 | else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE) |
| 4346 | halt_status_unrecoverable = 1; |
| 4347 | } |
| 4348 | |
| 4349 | /* |
| 4350 | * Since we cannot change dev_state in interrupt context, |
| 4351 | * set appropriate DPC flag then wakeup DPC |
| 4352 | */ |
| 4353 | if (halt_status_unrecoverable) { |
| 4354 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 4355 | } else { |
| 4356 | ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n", |
| 4357 | __func__); |
| 4358 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4359 | } |
| 4360 | qla4xxx_mailbox_premature_completion(ha); |
| 4361 | qla4xxx_wake_dpc(ha); |
| 4362 | } |
| 4363 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4364 | /** |
| 4365 | * qla4_8xxx_watchdog - Poll dev state |
| 4366 | * @ha: Pointer to host adapter structure. |
| 4367 | * |
| 4368 | * Context: Interrupt |
| 4369 | **/ |
| 4370 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| 4371 | { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4372 | uint32_t dev_state; |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4373 | uint32_t idc_ctrl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4374 | |
Vikas Chaudhary | a083e8b | 2013-12-16 06:49:32 -0500 | [diff] [blame] | 4375 | if (is_qla8032(ha) && |
| 4376 | (qla4_83xx_is_detached(ha) == QLA_SUCCESS)) |
| 4377 | WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n", |
| 4378 | __func__, ha->func_num); |
| 4379 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4380 | /* don't poll if reset is going on */ |
Lalit Chandivade | d56a1f7 | 2010-12-02 22:12:45 -0800 | [diff] [blame] | 4381 | if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 4382 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
Vikas Chaudhary | 977f46a | 2011-05-17 23:17:08 -0700 | [diff] [blame] | 4383 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4384 | dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4385 | |
| 4386 | if (qla4_8xxx_check_temp(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4387 | if (is_qla8022(ha)) { |
| 4388 | ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n"); |
| 4389 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 4390 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 4391 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 4392 | } |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4393 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 4394 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4395 | } else if (dev_state == QLA8XXX_DEV_NEED_RESET && |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4396 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4397 | |
| 4398 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n", |
| 4399 | __func__); |
| 4400 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4401 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4402 | idc_ctrl = qla4_83xx_rd_reg(ha, |
| 4403 | QLA83XX_IDC_DRV_CTRL); |
| 4404 | if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) { |
| 4405 | ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n", |
| 4406 | __func__); |
| 4407 | qla4xxx_mailbox_premature_completion( |
| 4408 | ha); |
| 4409 | } |
| 4410 | } |
| 4411 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4412 | if ((is_qla8032(ha) || is_qla8042(ha)) || |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4413 | (is_qla8022(ha) && !ql4xdontresethba)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4414 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4415 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4416 | } |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4417 | } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4418 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4419 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
| 4420 | __func__); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4421 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| 4422 | qla4xxx_wake_dpc(ha); |
| 4423 | } else { |
| 4424 | /* Check firmware health */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4425 | if (qla4_8xxx_check_fw_alive(ha)) |
| 4426 | qla4_8xxx_process_fw_error(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4427 | } |
| 4428 | } |
| 4429 | } |
| 4430 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4431 | 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] | 4432 | { |
| 4433 | struct iscsi_session *sess; |
| 4434 | struct ddb_entry *ddb_entry; |
| 4435 | struct scsi_qla_host *ha; |
| 4436 | |
| 4437 | sess = cls_sess->dd_data; |
| 4438 | ddb_entry = sess->dd_data; |
| 4439 | ha = ddb_entry->ha; |
| 4440 | |
| 4441 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 4442 | return; |
| 4443 | |
| 4444 | if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 4445 | !iscsi_is_session_online(cls_sess)) { |
| 4446 | if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| 4447 | INVALID_ENTRY) { |
| 4448 | if (atomic_read(&ddb_entry->retry_relogin_timer) == |
| 4449 | 0) { |
| 4450 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 4451 | INVALID_ENTRY); |
| 4452 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4453 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 4454 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4455 | "%s: index [%d] login device\n", |
| 4456 | __func__, ddb_entry->fw_ddb_index)); |
| 4457 | } else |
| 4458 | atomic_dec(&ddb_entry->retry_relogin_timer); |
| 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | /* Wait for relogin to timeout */ |
| 4463 | if (atomic_read(&ddb_entry->relogin_timer) && |
| 4464 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| 4465 | /* |
| 4466 | * If the relogin times out and the device is |
| 4467 | * still NOT ONLINE then try and relogin again. |
| 4468 | */ |
| 4469 | if (!iscsi_is_session_online(cls_sess)) { |
| 4470 | /* Reset retry relogin timer */ |
| 4471 | atomic_inc(&ddb_entry->relogin_retry_count); |
| 4472 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4473 | "%s: index[%d] relogin timed out-retrying" |
| 4474 | " relogin (%d), retry (%d)\n", __func__, |
| 4475 | ddb_entry->fw_ddb_index, |
| 4476 | atomic_read(&ddb_entry->relogin_retry_count), |
| 4477 | ddb_entry->default_time2wait + 4)); |
| 4478 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4479 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 4480 | ddb_entry->default_time2wait + 4); |
| 4481 | } |
| 4482 | } |
| 4483 | } |
| 4484 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4485 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4486 | * qla4xxx_timer - checks every second for work to do. |
| 4487 | * @ha: Pointer to host adapter structure. |
| 4488 | **/ |
| 4489 | static void qla4xxx_timer(struct scsi_qla_host *ha) |
| 4490 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4491 | int start_dpc = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4492 | uint16_t w; |
| 4493 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4494 | iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb); |
| 4495 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4496 | /* If we are in the middle of AER/EEH processing |
| 4497 | * skip any processing and reschedule the timer |
| 4498 | */ |
| 4499 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 4500 | mod_timer(&ha->timer, jiffies + HZ); |
| 4501 | return; |
| 4502 | } |
| 4503 | |
| 4504 | /* Hardware read to trigger an EEH error during mailbox waits. */ |
| 4505 | if (!pci_channel_offline(ha->pdev)) |
| 4506 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4507 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4508 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4509 | qla4_8xxx_watchdog(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4510 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4511 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4512 | /* Check for heartbeat interval. */ |
| 4513 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| 4514 | ha->heartbeat_interval != 0) { |
| 4515 | ha->seconds_since_last_heartbeat++; |
| 4516 | if (ha->seconds_since_last_heartbeat > |
| 4517 | ha->heartbeat_interval + 2) |
| 4518 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4519 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 4522 | /* Process any deferred work. */ |
| 4523 | if (!list_empty(&ha->work_list)) |
| 4524 | start_dpc++; |
| 4525 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4526 | /* Wakeup the dpc routine for this adapter, if needed. */ |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 4527 | if (start_dpc || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4528 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 4529 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| 4530 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4531 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4532 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 4533 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 4534 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4535 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 4536 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 4537 | test_bit(DPC_AEN, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4538 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| 4539 | " - dpc flags = 0x%lx\n", |
| 4540 | ha->host_no, __func__, ha->dpc_flags)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4541 | qla4xxx_wake_dpc(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | /* Reschedule timer thread to call us back in one second */ |
| 4545 | mod_timer(&ha->timer, jiffies + HZ); |
| 4546 | |
| 4547 | DEBUG2(ha->seconds_since_last_intr++); |
| 4548 | } |
| 4549 | |
| 4550 | /** |
| 4551 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| 4552 | * @ha: Pointer to host adapter structure. |
| 4553 | * |
| 4554 | * This routine stalls the driver until all outstanding commands are returned. |
| 4555 | * Caller must release the Hardware Lock prior to calling this routine. |
| 4556 | **/ |
| 4557 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| 4558 | { |
| 4559 | uint32_t index = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4560 | unsigned long flags; |
| 4561 | struct scsi_cmnd *cmd; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4562 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4563 | unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
| 4564 | |
| 4565 | DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " |
| 4566 | "complete\n", WAIT_CMD_TOV)); |
| 4567 | |
| 4568 | while (!time_after_eq(jiffies, wtime)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4569 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4570 | /* Find a command that hasn't completed. */ |
| 4571 | for (index = 0; index < ha->host->can_queue; index++) { |
| 4572 | cmd = scsi_host_find_tag(ha->host, index); |
Mike Christie | a1e0063 | 2010-10-26 05:45:30 -0700 | [diff] [blame] | 4573 | /* |
| 4574 | * We cannot just check if the index is valid, |
| 4575 | * becase if we are run from the scsi eh, then |
| 4576 | * the scsi/block layer is going to prevent |
| 4577 | * the tag from being released. |
| 4578 | */ |
| 4579 | if (cmd != NULL && CMD_SP(cmd)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4580 | break; |
| 4581 | } |
| 4582 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4583 | |
| 4584 | /* If No Commands are pending, wait is complete */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4585 | if (index == ha->host->can_queue) |
| 4586 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4587 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4588 | msleep(1000); |
| 4589 | } |
| 4590 | /* If we timed out on waiting for commands to come back |
| 4591 | * return ERROR. */ |
| 4592 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4593 | } |
| 4594 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4595 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4596 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4597 | uint32_t ctrl_status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4598 | unsigned long flags = 0; |
| 4599 | |
| 4600 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4601 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4602 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 4603 | return QLA_ERROR; |
| 4604 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4605 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4606 | |
| 4607 | /* |
| 4608 | * If the SCSI Reset Interrupt bit is set, clear it. |
| 4609 | * Otherwise, the Soft Reset won't work. |
| 4610 | */ |
| 4611 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4612 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| 4613 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 4614 | |
| 4615 | /* Issue Soft Reset */ |
| 4616 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| 4617 | readl(&ha->reg->ctrl_status); |
| 4618 | |
| 4619 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4620 | return QLA_SUCCESS; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | /** |
| 4624 | * qla4xxx_soft_reset - performs soft reset. |
| 4625 | * @ha: Pointer to host adapter structure. |
| 4626 | **/ |
| 4627 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| 4628 | { |
| 4629 | uint32_t max_wait_time; |
| 4630 | unsigned long flags = 0; |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4631 | int status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4632 | uint32_t ctrl_status; |
| 4633 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4634 | status = qla4xxx_hw_reset(ha); |
| 4635 | if (status != QLA_SUCCESS) |
| 4636 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4637 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4638 | status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4639 | /* Wait until the Network Reset Intr bit is cleared */ |
| 4640 | max_wait_time = RESET_INTR_TOV; |
| 4641 | do { |
| 4642 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4643 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4644 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4645 | |
| 4646 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| 4647 | break; |
| 4648 | |
| 4649 | msleep(1000); |
| 4650 | } while ((--max_wait_time)); |
| 4651 | |
| 4652 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| 4653 | DEBUG2(printk(KERN_WARNING |
| 4654 | "scsi%ld: Network Reset Intr not cleared by " |
| 4655 | "Network function, clearing it now!\n", |
| 4656 | ha->host_no)); |
| 4657 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4658 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| 4659 | readl(&ha->reg->ctrl_status); |
| 4660 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4661 | } |
| 4662 | |
| 4663 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 4664 | max_wait_time = SOFT_RESET_TOV; |
| 4665 | do { |
| 4666 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4667 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4668 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4669 | |
| 4670 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| 4671 | status = QLA_SUCCESS; |
| 4672 | break; |
| 4673 | } |
| 4674 | |
| 4675 | msleep(1000); |
| 4676 | } while ((--max_wait_time)); |
| 4677 | |
| 4678 | /* |
| 4679 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| 4680 | * after the soft reset has taken place. |
| 4681 | */ |
| 4682 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4683 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4684 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| 4685 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 4686 | readl(&ha->reg->ctrl_status); |
| 4687 | } |
| 4688 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4689 | |
| 4690 | /* If soft reset fails then most probably the bios on other |
| 4691 | * function is also enabled. |
| 4692 | * Since the initialization is sequential the other fn |
| 4693 | * wont be able to acknowledge the soft reset. |
| 4694 | * Issue a force soft reset to workaround this scenario. |
| 4695 | */ |
| 4696 | if (max_wait_time == 0) { |
| 4697 | /* Issue Force Soft Reset */ |
| 4698 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4699 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| 4700 | readl(&ha->reg->ctrl_status); |
| 4701 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4702 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 4703 | max_wait_time = SOFT_RESET_TOV; |
| 4704 | do { |
| 4705 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4706 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4707 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4708 | |
| 4709 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| 4710 | status = QLA_SUCCESS; |
| 4711 | break; |
| 4712 | } |
| 4713 | |
| 4714 | msleep(1000); |
| 4715 | } while ((--max_wait_time)); |
| 4716 | } |
| 4717 | |
| 4718 | return status; |
| 4719 | } |
| 4720 | |
| 4721 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4722 | * 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] | 4723 | * @ha: Pointer to host adapter structure. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4724 | * @res: returned scsi status |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4725 | * |
| 4726 | * This routine is called just prior to a HARD RESET to return all |
| 4727 | * outstanding commands back to the Operating System. |
| 4728 | * Caller should make sure that the following locks are released |
| 4729 | * before this calling routine: Hardware lock, and io_request_lock. |
| 4730 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4731 | 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] | 4732 | { |
| 4733 | struct srb *srb; |
| 4734 | int i; |
| 4735 | unsigned long flags; |
| 4736 | |
| 4737 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4738 | for (i = 0; i < ha->host->can_queue; i++) { |
| 4739 | srb = qla4xxx_del_from_active_array(ha, i); |
| 4740 | if (srb != NULL) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4741 | srb->cmd->result = res; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4742 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4743 | } |
| 4744 | } |
| 4745 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4748 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| 4749 | { |
| 4750 | clear_bit(AF_ONLINE, &ha->flags); |
| 4751 | |
| 4752 | /* Disable the board */ |
| 4753 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4754 | |
| 4755 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 4756 | qla4xxx_mark_all_devices_missing(ha); |
| 4757 | clear_bit(AF_INIT_DONE, &ha->flags); |
| 4758 | } |
| 4759 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4760 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session) |
| 4761 | { |
| 4762 | struct iscsi_session *sess; |
| 4763 | struct ddb_entry *ddb_entry; |
| 4764 | |
| 4765 | sess = cls_session->dd_data; |
| 4766 | ddb_entry = sess->dd_data; |
| 4767 | ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4768 | |
| 4769 | if (ddb_entry->ddb_type == FLASH_DDB) |
| 4770 | iscsi_block_session(ddb_entry->sess); |
| 4771 | else |
| 4772 | iscsi_session_failure(cls_session->dd_data, |
| 4773 | ISCSI_ERR_CONN_FAILED); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4774 | } |
| 4775 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4776 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4777 | * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| 4778 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4779 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4780 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4781 | { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4782 | int status = QLA_ERROR; |
| 4783 | uint8_t reset_chip = 0; |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4784 | uint32_t dev_state; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4785 | unsigned long wait; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4786 | |
| 4787 | /* Stall incoming I/O until we are done */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4788 | scsi_block_requests(ha->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4789 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4790 | clear_bit(AF_LINK_UP, &ha->flags); |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 4791 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4792 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4793 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4794 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4795 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4796 | if ((is_qla8032(ha) || is_qla8042(ha)) && |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 4797 | !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 4798 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 4799 | __func__); |
| 4800 | /* disable pause frame for ISP83xx */ |
| 4801 | qla4_83xx_disable_pause(ha); |
| 4802 | } |
| 4803 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4804 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
| 4805 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4806 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 4807 | reset_chip = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4808 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4809 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| 4810 | * do not reset adapter, jump to initialize_adapter */ |
| 4811 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| 4812 | status = QLA_SUCCESS; |
| 4813 | goto recover_ha_init_adapter; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4816 | /* For the ISP-8xxx adapter, issue a stop_firmware if invoked |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4817 | * from eh_host_reset or ioctl module */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4818 | if (is_qla80XX(ha) && !reset_chip && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4819 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 4820 | |
| 4821 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4822 | "scsi%ld: %s - Performing stop_firmware...\n", |
| 4823 | ha->host_no, __func__)); |
| 4824 | status = ha->isp_ops->reset_firmware(ha); |
| 4825 | if (status == QLA_SUCCESS) { |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 4826 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4827 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 4828 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4829 | ha->isp_ops->disable_intrs(ha); |
| 4830 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4831 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 4832 | } else { |
| 4833 | /* If the stop_firmware fails then |
| 4834 | * reset the entire chip */ |
| 4835 | reset_chip = 1; |
| 4836 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 4837 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | /* Issue full chip reset if recovering from a catastrophic error, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4842 | * or if stop_firmware fails for ISP-8xxx. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4843 | * This is the default case for ISP-4xxx */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4844 | if (is_qla40XX(ha) || reset_chip) { |
| 4845 | if (is_qla40XX(ha)) |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4846 | goto chip_reset; |
| 4847 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4848 | /* Check if 8XXX firmware is alive or not |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4849 | * We may have arrived here from NEED_RESET |
| 4850 | * detection only */ |
| 4851 | if (test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4852 | goto chip_reset; |
| 4853 | |
| 4854 | wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ); |
| 4855 | while (time_before(jiffies, wait)) { |
| 4856 | if (qla4_8xxx_check_fw_alive(ha)) { |
| 4857 | qla4xxx_mailbox_premature_completion(ha); |
| 4858 | break; |
| 4859 | } |
| 4860 | |
| 4861 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 4862 | schedule_timeout(HZ); |
| 4863 | } |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 4864 | chip_reset: |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 4865 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4866 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 4867 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4868 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4869 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 4870 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4871 | "scsi%ld: %s - Performing chip reset..\n", |
| 4872 | ha->host_no, __func__)); |
| 4873 | status = ha->isp_ops->reset_chip(ha); |
| 4874 | } |
| 4875 | |
| 4876 | /* Flush any pending ddb changed AENs */ |
| 4877 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4878 | |
| 4879 | recover_ha_init_adapter: |
| 4880 | /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| 4881 | if (status == QLA_SUCCESS) { |
| 4882 | /* For ISP-4xxx, force function 1 to always initialize |
| 4883 | * before function 3 to prevent both funcions from |
| 4884 | * stepping on top of the other */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4885 | if (is_qla40XX(ha) && (ha->mac_index == 3)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4886 | ssleep(6); |
| 4887 | |
| 4888 | /* NOTE: AF_ONLINE flag set upon successful completion of |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 4889 | * qla4xxx_initialize_adapter */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4890 | status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 4891 | if (is_qla80XX(ha) && (status == QLA_ERROR)) { |
| 4892 | status = qla4_8xxx_check_init_adapter_retry(ha); |
| 4893 | if (status == QLA_ERROR) { |
| 4894 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n", |
| 4895 | ha->host_no, __func__); |
| 4896 | qla4xxx_dead_adapter_cleanup(ha); |
| 4897 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4898 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4899 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 4900 | &ha->dpc_flags); |
| 4901 | goto exit_recover; |
| 4902 | } |
| 4903 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | /* Retry failed adapter initialization, if necessary |
| 4907 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| 4908 | * case to prevent ping-pong resets between functions */ |
| 4909 | if (!test_bit(AF_ONLINE, &ha->flags) && |
| 4910 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4911 | /* Adapter initialization failed, see if we can retry |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4912 | * resetting the ha. |
| 4913 | * Since we don't want to block the DPC for too long |
| 4914 | * with multiple resets in the same thread, |
| 4915 | * utilize DPC to retry */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4916 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4917 | ha->isp_ops->idc_lock(ha); |
| 4918 | dev_state = qla4_8xxx_rd_direct(ha, |
| 4919 | QLA8XXX_CRB_DEV_STATE); |
| 4920 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4921 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4922 | ql4_printk(KERN_INFO, ha, "%s: don't retry " |
| 4923 | "recover adapter. H/W is in Failed " |
| 4924 | "state\n", __func__); |
| 4925 | qla4xxx_dead_adapter_cleanup(ha); |
| 4926 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4927 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4928 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 4929 | &ha->dpc_flags); |
| 4930 | status = QLA_ERROR; |
| 4931 | |
| 4932 | goto exit_recover; |
| 4933 | } |
| 4934 | } |
| 4935 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4936 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| 4937 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| 4938 | DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| 4939 | "(%d) more times\n", ha->host_no, |
| 4940 | ha->retry_reset_ha_cnt)); |
| 4941 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4942 | status = QLA_ERROR; |
| 4943 | } else { |
| 4944 | if (ha->retry_reset_ha_cnt > 0) { |
| 4945 | /* Schedule another Reset HA--DPC will retry */ |
| 4946 | ha->retry_reset_ha_cnt--; |
| 4947 | DEBUG2(printk("scsi%ld: recover adapter - " |
| 4948 | "retry remaining %d\n", |
| 4949 | ha->host_no, |
| 4950 | ha->retry_reset_ha_cnt)); |
| 4951 | status = QLA_ERROR; |
| 4952 | } |
| 4953 | |
| 4954 | if (ha->retry_reset_ha_cnt == 0) { |
| 4955 | /* Recover adapter retries have been exhausted. |
| 4956 | * Adapter DEAD */ |
| 4957 | DEBUG2(printk("scsi%ld: recover adapter " |
| 4958 | "failed - board disabled\n", |
| 4959 | ha->host_no)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4960 | qla4xxx_dead_adapter_cleanup(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4961 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4962 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4963 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4964 | &ha->dpc_flags); |
| 4965 | status = QLA_ERROR; |
| 4966 | } |
| 4967 | } |
| 4968 | } else { |
| 4969 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4970 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4971 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4972 | } |
| 4973 | |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4974 | exit_recover: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4975 | ha->adapter_error_count++; |
| 4976 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4977 | if (test_bit(AF_ONLINE, &ha->flags)) |
| 4978 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4979 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4980 | scsi_unblock_requests(ha->host); |
| 4981 | |
| 4982 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 4983 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4984 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4985 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4986 | return status; |
| 4987 | } |
| 4988 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4989 | static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session) |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 4990 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4991 | struct iscsi_session *sess; |
| 4992 | struct ddb_entry *ddb_entry; |
| 4993 | struct scsi_qla_host *ha; |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 4994 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4995 | sess = cls_session->dd_data; |
| 4996 | ddb_entry = sess->dd_data; |
| 4997 | ha = ddb_entry->ha; |
| 4998 | if (!iscsi_is_session_online(cls_session)) { |
| 4999 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| 5000 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5001 | " unblock session\n", ha->host_no, __func__, |
| 5002 | ddb_entry->fw_ddb_index); |
| 5003 | iscsi_unblock_session(ddb_entry->sess); |
| 5004 | } else { |
| 5005 | /* Trigger relogin */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5006 | if (ddb_entry->ddb_type == FLASH_DDB) { |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 5007 | if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) || |
| 5008 | test_bit(DF_DISABLE_RELOGIN, |
| 5009 | &ddb_entry->flags))) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5010 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 5011 | } else |
| 5012 | iscsi_session_failure(cls_session->dd_data, |
| 5013 | ISCSI_ERR_CONN_FAILED); |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5014 | } |
| 5015 | } |
| 5016 | } |
| 5017 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5018 | int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session) |
| 5019 | { |
| 5020 | struct iscsi_session *sess; |
| 5021 | struct ddb_entry *ddb_entry; |
| 5022 | struct scsi_qla_host *ha; |
| 5023 | |
| 5024 | sess = cls_session->dd_data; |
| 5025 | ddb_entry = sess->dd_data; |
| 5026 | ha = ddb_entry->ha; |
| 5027 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5028 | " unblock session\n", ha->host_no, __func__, |
| 5029 | ddb_entry->fw_ddb_index); |
| 5030 | |
| 5031 | iscsi_unblock_session(ddb_entry->sess); |
| 5032 | |
| 5033 | /* Start scan target */ |
| 5034 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 5035 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5036 | " start scan\n", ha->host_no, __func__, |
| 5037 | ddb_entry->fw_ddb_index); |
| 5038 | scsi_queue_work(ha->host, &ddb_entry->sess->scan_work); |
| 5039 | } |
| 5040 | return QLA_SUCCESS; |
| 5041 | } |
| 5042 | |
| 5043 | int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session) |
| 5044 | { |
| 5045 | struct iscsi_session *sess; |
| 5046 | struct ddb_entry *ddb_entry; |
| 5047 | struct scsi_qla_host *ha; |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 5048 | int status = QLA_SUCCESS; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5049 | |
| 5050 | sess = cls_session->dd_data; |
| 5051 | ddb_entry = sess->dd_data; |
| 5052 | ha = ddb_entry->ha; |
| 5053 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 5054 | " unblock user space session\n", ha->host_no, __func__, |
| 5055 | ddb_entry->fw_ddb_index); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5056 | |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 5057 | if (!iscsi_is_session_online(cls_session)) { |
| 5058 | iscsi_conn_start(ddb_entry->conn); |
| 5059 | iscsi_conn_login_event(ddb_entry->conn, |
| 5060 | ISCSI_CONN_STATE_LOGGED_IN); |
| 5061 | } else { |
| 5062 | ql4_printk(KERN_INFO, ha, |
| 5063 | "scsi%ld: %s: ddb[%d] session [%d] already logged in\n", |
| 5064 | ha->host_no, __func__, ddb_entry->fw_ddb_index, |
| 5065 | cls_session->sid); |
| 5066 | status = QLA_ERROR; |
| 5067 | } |
| 5068 | |
| 5069 | return status; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5070 | } |
| 5071 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5072 | static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
| 5073 | { |
| 5074 | iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices); |
| 5075 | } |
| 5076 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5077 | static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| 5078 | { |
| 5079 | uint16_t relogin_timer; |
| 5080 | struct iscsi_session *sess; |
| 5081 | struct ddb_entry *ddb_entry; |
| 5082 | struct scsi_qla_host *ha; |
| 5083 | |
| 5084 | sess = cls_sess->dd_data; |
| 5085 | ddb_entry = sess->dd_data; |
| 5086 | ha = ddb_entry->ha; |
| 5087 | |
| 5088 | relogin_timer = max(ddb_entry->default_relogin_timeout, |
| 5089 | (uint16_t)RELOGIN_TOV); |
| 5090 | atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| 5091 | |
| 5092 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5093 | "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no, |
| 5094 | ddb_entry->fw_ddb_index, relogin_timer)); |
| 5095 | |
| 5096 | qla4xxx_login_flash_ddb(cls_sess); |
| 5097 | } |
| 5098 | |
| 5099 | static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess) |
| 5100 | { |
| 5101 | struct iscsi_session *sess; |
| 5102 | struct ddb_entry *ddb_entry; |
| 5103 | struct scsi_qla_host *ha; |
| 5104 | |
| 5105 | sess = cls_sess->dd_data; |
| 5106 | ddb_entry = sess->dd_data; |
| 5107 | ha = ddb_entry->ha; |
| 5108 | |
| 5109 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 5110 | return; |
| 5111 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 5112 | if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) |
| 5113 | return; |
| 5114 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5115 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 5116 | !iscsi_is_session_online(cls_sess)) { |
| 5117 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5118 | "relogin issued\n")); |
| 5119 | qla4xxx_relogin_flash_ddb(cls_sess); |
| 5120 | } |
| 5121 | } |
| 5122 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5123 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| 5124 | { |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5125 | if (ha->dpc_thread) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5126 | queue_work(ha->dpc_thread, &ha->dpc_work); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5127 | } |
| 5128 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5129 | static struct qla4_work_evt * |
| 5130 | qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size, |
| 5131 | enum qla4_work_type type) |
| 5132 | { |
| 5133 | struct qla4_work_evt *e; |
| 5134 | uint32_t size = sizeof(struct qla4_work_evt) + data_size; |
| 5135 | |
| 5136 | e = kzalloc(size, GFP_ATOMIC); |
| 5137 | if (!e) |
| 5138 | return NULL; |
| 5139 | |
| 5140 | INIT_LIST_HEAD(&e->list); |
| 5141 | e->type = type; |
| 5142 | return e; |
| 5143 | } |
| 5144 | |
| 5145 | static void qla4xxx_post_work(struct scsi_qla_host *ha, |
| 5146 | struct qla4_work_evt *e) |
| 5147 | { |
| 5148 | unsigned long flags; |
| 5149 | |
| 5150 | spin_lock_irqsave(&ha->work_lock, flags); |
| 5151 | list_add_tail(&e->list, &ha->work_list); |
| 5152 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 5153 | qla4xxx_wake_dpc(ha); |
| 5154 | } |
| 5155 | |
| 5156 | int qla4xxx_post_aen_work(struct scsi_qla_host *ha, |
| 5157 | enum iscsi_host_event_code aen_code, |
| 5158 | uint32_t data_size, uint8_t *data) |
| 5159 | { |
| 5160 | struct qla4_work_evt *e; |
| 5161 | |
| 5162 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN); |
| 5163 | if (!e) |
| 5164 | return QLA_ERROR; |
| 5165 | |
| 5166 | e->u.aen.code = aen_code; |
| 5167 | e->u.aen.data_size = data_size; |
| 5168 | memcpy(e->u.aen.data, data, data_size); |
| 5169 | |
| 5170 | qla4xxx_post_work(ha, e); |
| 5171 | |
| 5172 | return QLA_SUCCESS; |
| 5173 | } |
| 5174 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 5175 | int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha, |
| 5176 | uint32_t status, uint32_t pid, |
| 5177 | uint32_t data_size, uint8_t *data) |
| 5178 | { |
| 5179 | struct qla4_work_evt *e; |
| 5180 | |
| 5181 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS); |
| 5182 | if (!e) |
| 5183 | return QLA_ERROR; |
| 5184 | |
| 5185 | e->u.ping.status = status; |
| 5186 | e->u.ping.pid = pid; |
| 5187 | e->u.ping.data_size = data_size; |
| 5188 | memcpy(e->u.ping.data, data, data_size); |
| 5189 | |
| 5190 | qla4xxx_post_work(ha, e); |
| 5191 | |
| 5192 | return QLA_SUCCESS; |
| 5193 | } |
| 5194 | |
Vikas Chaudhary | a7380a6 | 2012-02-27 03:08:56 -0800 | [diff] [blame] | 5195 | static void qla4xxx_do_work(struct scsi_qla_host *ha) |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5196 | { |
| 5197 | struct qla4_work_evt *e, *tmp; |
| 5198 | unsigned long flags; |
| 5199 | LIST_HEAD(work); |
| 5200 | |
| 5201 | spin_lock_irqsave(&ha->work_lock, flags); |
| 5202 | list_splice_init(&ha->work_list, &work); |
| 5203 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 5204 | |
| 5205 | list_for_each_entry_safe(e, tmp, &work, list) { |
| 5206 | list_del_init(&e->list); |
| 5207 | |
| 5208 | switch (e->type) { |
| 5209 | case QLA4_EVENT_AEN: |
| 5210 | iscsi_post_host_event(ha->host_no, |
| 5211 | &qla4xxx_iscsi_transport, |
| 5212 | e->u.aen.code, |
| 5213 | e->u.aen.data_size, |
| 5214 | e->u.aen.data); |
| 5215 | break; |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 5216 | case QLA4_EVENT_PING_STATUS: |
| 5217 | iscsi_ping_comp_event(ha->host_no, |
| 5218 | &qla4xxx_iscsi_transport, |
| 5219 | e->u.ping.status, |
| 5220 | e->u.ping.pid, |
| 5221 | e->u.ping.data_size, |
| 5222 | e->u.ping.data); |
| 5223 | break; |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5224 | default: |
| 5225 | ql4_printk(KERN_WARNING, ha, "event type: 0x%x not " |
| 5226 | "supported", e->type); |
| 5227 | } |
| 5228 | kfree(e); |
| 5229 | } |
| 5230 | } |
| 5231 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5232 | /** |
| 5233 | * qla4xxx_do_dpc - dpc routine |
| 5234 | * @data: in our case pointer to adapter structure |
| 5235 | * |
| 5236 | * This routine is a task that is schedule by the interrupt handler |
| 5237 | * to perform the background processing for interrupts. We put it |
| 5238 | * on a task queue that is consumed whenever the scheduler runs; that's |
| 5239 | * so you can do anything (i.e. put the process to sleep etc). In fact, |
| 5240 | * the mid-level tries to sleep when it reaches the driver threshold |
| 5241 | * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| 5242 | **/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5243 | static void qla4xxx_do_dpc(struct work_struct *work) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5244 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5245 | struct scsi_qla_host *ha = |
| 5246 | container_of(work, struct scsi_qla_host, dpc_work); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5247 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5248 | |
David C Somayajulu | f26b904 | 2006-11-15 16:41:09 -0800 | [diff] [blame] | 5249 | DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5250 | "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| 5251 | ha->host_no, __func__, ha->flags, ha->dpc_flags)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5252 | |
| 5253 | /* Initialization not yet finished. Don't do anything yet. */ |
| 5254 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5255 | return; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5256 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5257 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 5258 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| 5259 | ha->host_no, __func__, ha->flags)); |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5260 | return; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5261 | } |
| 5262 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5263 | /* post events to application */ |
| 5264 | qla4xxx_do_work(ha); |
| 5265 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5266 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5267 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5268 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 5269 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 5270 | __func__); |
| 5271 | /* disable pause frame for ISP83xx */ |
| 5272 | qla4_83xx_disable_pause(ha); |
| 5273 | } |
| 5274 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5275 | ha->isp_ops->idc_lock(ha); |
| 5276 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 5277 | QLA8XXX_DEV_FAILED); |
| 5278 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5279 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 5280 | qla4_8xxx_device_state_handler(ha); |
| 5281 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5282 | |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 5283 | if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) { |
| 5284 | if (is_qla8042(ha)) { |
| 5285 | if (ha->idc_info.info2 & |
| 5286 | ENABLE_INTERNAL_LOOPBACK) { |
| 5287 | ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n", |
| 5288 | __func__); |
| 5289 | status = qla4_84xx_config_acb(ha, |
| 5290 | ACB_CONFIG_DISABLE); |
| 5291 | if (status != QLA_SUCCESS) { |
| 5292 | ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n", |
| 5293 | __func__); |
| 5294 | } |
| 5295 | } |
| 5296 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5297 | qla4_83xx_post_idc_ack(ha); |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 5298 | clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags); |
| 5299 | } |
| 5300 | |
| 5301 | if (is_qla8042(ha) && |
| 5302 | test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) { |
| 5303 | ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n", |
| 5304 | __func__); |
| 5305 | if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) != |
| 5306 | QLA_SUCCESS) { |
| 5307 | ql4_printk(KERN_INFO, ha, "%s: ACB config failed ", |
| 5308 | __func__); |
| 5309 | } |
| 5310 | clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags); |
| 5311 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5312 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5313 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 5314 | qla4_8xxx_need_qsnt_handler(ha); |
| 5315 | } |
| 5316 | } |
| 5317 | |
| 5318 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| 5319 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5320 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5321 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5322 | if ((is_qla8022(ha) && ql4xdontresethba) || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5323 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 5324 | qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5325 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 5326 | ha->host_no, __func__)); |
| 5327 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 5328 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 5329 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 5330 | goto dpc_post_reset_ha; |
| 5331 | } |
| 5332 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| 5333 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 5334 | qla4xxx_recover_adapter(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5335 | |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5336 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5337 | uint8_t wait_time = RESET_INTR_TOV; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5338 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5339 | while ((readw(&ha->reg->ctrl_status) & |
| 5340 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| 5341 | if (--wait_time == 0) |
| 5342 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5343 | msleep(1000); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5344 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5345 | if (wait_time == 0) |
| 5346 | DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| 5347 | "bit not cleared-- resetting\n", |
| 5348 | ha->host_no, __func__)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5349 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5350 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| 5351 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5352 | status = qla4xxx_recover_adapter(ha); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5353 | } |
| 5354 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 5355 | if (status == QLA_SUCCESS) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5356 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5360 | dpc_post_reset_ha: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5361 | /* ---- process AEN? --- */ |
| 5362 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 5363 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| 5364 | |
| 5365 | /* ---- Get DHCP IP Address? --- */ |
| 5366 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 5367 | qla4xxx_get_dhcp_ip_address(ha); |
| 5368 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5369 | /* ---- relogin device? --- */ |
| 5370 | if (adapter_up(ha) && |
| 5371 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| 5372 | iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin); |
| 5373 | } |
| 5374 | |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5375 | /* ---- link change? --- */ |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 5376 | if (!test_bit(AF_LOOPBACK, &ha->flags) && |
| 5377 | test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5378 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 5379 | /* ---- link down? --- */ |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5380 | qla4xxx_mark_all_devices_missing(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5381 | } else { |
| 5382 | /* ---- link up? --- * |
| 5383 | * F/W will auto login to all devices ONLY ONCE after |
| 5384 | * link up during driver initialization and runtime |
| 5385 | * fatal error recovery. Therefore, the driver must |
| 5386 | * manually relogin to devices when recovering from |
| 5387 | * connection failures, logouts, expired KATO, etc. */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5388 | if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) { |
| 5389 | qla4xxx_build_ddb_list(ha, ha->is_reset); |
| 5390 | iscsi_host_for_each_session(ha->host, |
| 5391 | qla4xxx_login_flash_ddb); |
| 5392 | } else |
| 5393 | qla4xxx_relogin_all_devices(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5394 | } |
| 5395 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | /** |
| 5399 | * qla4xxx_free_adapter - release the adapter |
| 5400 | * @ha: pointer to adapter structure |
| 5401 | **/ |
| 5402 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| 5403 | { |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 5404 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5405 | |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 5406 | /* Turn-off interrupts on the card. */ |
| 5407 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5408 | |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 5409 | if (is_qla40XX(ha)) { |
| 5410 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 5411 | &ha->reg->ctrl_status); |
| 5412 | readl(&ha->reg->ctrl_status); |
| 5413 | } else if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5414 | writel(0, &ha->qla4_82xx_reg->host_int); |
| 5415 | readl(&ha->qla4_82xx_reg->host_int); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5416 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | fbd8107 | 2012-09-20 07:35:03 -0400 | [diff] [blame] | 5417 | writel(0, &ha->qla4_83xx_reg->risc_intr); |
| 5418 | readl(&ha->qla4_83xx_reg->risc_intr); |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 5419 | } |
| 5420 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5421 | /* Remove timer thread, if present */ |
| 5422 | if (ha->timer_active) |
| 5423 | qla4xxx_stop_timer(ha); |
| 5424 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5425 | /* Kill the kernel thread for this host */ |
| 5426 | if (ha->dpc_thread) |
| 5427 | destroy_workqueue(ha->dpc_thread); |
| 5428 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5429 | /* Kill the kernel thread for this host */ |
| 5430 | if (ha->task_wq) |
| 5431 | destroy_workqueue(ha->task_wq); |
| 5432 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5433 | /* Put firmware in known state */ |
| 5434 | ha->isp_ops->reset_firmware(ha); |
| 5435 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5436 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5437 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5438 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5439 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5440 | } |
| 5441 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5442 | /* Detach interrupts */ |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 5443 | qla4xxx_free_irqs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5444 | |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 5445 | /* free extra memory */ |
| 5446 | qla4xxx_mem_free(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5447 | } |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 5448 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5449 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| 5450 | { |
| 5451 | int status = 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5452 | unsigned long mem_base, mem_len, db_base, db_len; |
| 5453 | struct pci_dev *pdev = ha->pdev; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5454 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5455 | status = pci_request_regions(pdev, DRIVER_NAME); |
| 5456 | if (status) { |
| 5457 | printk(KERN_WARNING |
| 5458 | "scsi(%ld) Failed to reserve PIO regions (%s) " |
| 5459 | "status=%d\n", ha->host_no, pci_name(pdev), status); |
| 5460 | goto iospace_error_exit; |
| 5461 | } |
| 5462 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5463 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
Sergei Shtylyov | 7d7311c | 2012-03-14 22:04:30 +0300 | [diff] [blame] | 5464 | __func__, pdev->revision)); |
| 5465 | ha->revision_id = pdev->revision; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5466 | |
| 5467 | /* remap phys address */ |
| 5468 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 5469 | mem_len = pci_resource_len(pdev, 0); |
| 5470 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| 5471 | __func__, mem_base, mem_len)); |
| 5472 | |
| 5473 | /* mapping of pcibase pointer */ |
| 5474 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| 5475 | if (!ha->nx_pcibase) { |
| 5476 | printk(KERN_ERR |
| 5477 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| 5478 | pci_release_regions(ha->pdev); |
| 5479 | goto iospace_error_exit; |
| 5480 | } |
| 5481 | |
| 5482 | /* Mapping of IO base pointer, door bell read and write pointer */ |
| 5483 | |
| 5484 | /* mapping of IO base pointer */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5485 | if (is_qla8022(ha)) { |
| 5486 | ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *) |
| 5487 | ((uint8_t *)ha->nx_pcibase + 0xbc000 + |
| 5488 | (ha->pdev->devfn << 11)); |
| 5489 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| 5490 | QLA82XX_CAM_RAM_DB2); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5491 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5492 | ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *) |
| 5493 | ((uint8_t *)ha->nx_pcibase); |
| 5494 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5495 | |
| 5496 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 5497 | db_len = pci_resource_len(pdev, 4); |
| 5498 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 5499 | return 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5500 | iospace_error_exit: |
| 5501 | return -ENOMEM; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | /*** |
| 5505 | * qla4xxx_iospace_config - maps registers |
| 5506 | * @ha: pointer to adapter structure |
| 5507 | * |
| 5508 | * This routines maps HBA's registers from the pci address space |
| 5509 | * into the kernel virtual address space for memory mapped i/o. |
| 5510 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5511 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5512 | { |
| 5513 | unsigned long pio, pio_len, pio_flags; |
| 5514 | unsigned long mmio, mmio_len, mmio_flags; |
| 5515 | |
| 5516 | pio = pci_resource_start(ha->pdev, 0); |
| 5517 | pio_len = pci_resource_len(ha->pdev, 0); |
| 5518 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 5519 | if (pio_flags & IORESOURCE_IO) { |
| 5520 | if (pio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5521 | ql4_printk(KERN_WARNING, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5522 | "Invalid PCI I/O region size\n"); |
| 5523 | pio = 0; |
| 5524 | } |
| 5525 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5526 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5527 | pio = 0; |
| 5528 | } |
| 5529 | |
| 5530 | /* Use MMIO operations for all accesses. */ |
| 5531 | mmio = pci_resource_start(ha->pdev, 1); |
| 5532 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 5533 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 5534 | |
| 5535 | if (!(mmio_flags & IORESOURCE_MEM)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5536 | ql4_printk(KERN_ERR, ha, |
| 5537 | "region #0 not an MMIO resource, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5538 | |
| 5539 | goto iospace_error_exit; |
| 5540 | } |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5541 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5542 | if (mmio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5543 | ql4_printk(KERN_ERR, ha, |
| 5544 | "Invalid PCI mem region size, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5545 | goto iospace_error_exit; |
| 5546 | } |
| 5547 | |
| 5548 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5549 | ql4_printk(KERN_WARNING, ha, |
| 5550 | "Failed to reserve PIO/MMIO regions\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5551 | |
| 5552 | goto iospace_error_exit; |
| 5553 | } |
| 5554 | |
| 5555 | ha->pio_address = pio; |
| 5556 | ha->pio_length = pio_len; |
| 5557 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| 5558 | if (!ha->reg) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5559 | ql4_printk(KERN_ERR, ha, |
| 5560 | "cannot remap MMIO, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5561 | |
| 5562 | goto iospace_error_exit; |
| 5563 | } |
| 5564 | |
| 5565 | return 0; |
| 5566 | |
| 5567 | iospace_error_exit: |
| 5568 | return -ENOMEM; |
| 5569 | } |
| 5570 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5571 | static struct isp_operations qla4xxx_isp_ops = { |
| 5572 | .iospace_config = qla4xxx_iospace_config, |
| 5573 | .pci_config = qla4xxx_pci_config, |
| 5574 | .disable_intrs = qla4xxx_disable_intrs, |
| 5575 | .enable_intrs = qla4xxx_enable_intrs, |
| 5576 | .start_firmware = qla4xxx_start_firmware, |
| 5577 | .intr_handler = qla4xxx_intr_handler, |
| 5578 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| 5579 | .reset_chip = qla4xxx_soft_reset, |
| 5580 | .reset_firmware = qla4xxx_hw_reset, |
| 5581 | .queue_iocb = qla4xxx_queue_iocb, |
| 5582 | .complete_iocb = qla4xxx_complete_iocb, |
| 5583 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 5584 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| 5585 | .get_sys_info = qla4xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5586 | .queue_mailbox_command = qla4xxx_queue_mbox_cmd, |
| 5587 | .process_mailbox_interrupt = qla4xxx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5588 | }; |
| 5589 | |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5590 | static struct isp_operations qla4_82xx_isp_ops = { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5591 | .iospace_config = qla4_8xxx_iospace_config, |
| 5592 | .pci_config = qla4_8xxx_pci_config, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5593 | .disable_intrs = qla4_82xx_disable_intrs, |
| 5594 | .enable_intrs = qla4_82xx_enable_intrs, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5595 | .start_firmware = qla4_8xxx_load_risc, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5596 | .restart_firmware = qla4_82xx_try_start_fw, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5597 | .intr_handler = qla4_82xx_intr_handler, |
| 5598 | .interrupt_service_routine = qla4_82xx_interrupt_service_routine, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5599 | .need_reset = qla4_8xxx_need_reset, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5600 | .reset_chip = qla4_82xx_isp_reset, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5601 | .reset_firmware = qla4_8xxx_stop_firmware, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5602 | .queue_iocb = qla4_82xx_queue_iocb, |
| 5603 | .complete_iocb = qla4_82xx_complete_iocb, |
| 5604 | .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out, |
| 5605 | .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5606 | .get_sys_info = qla4_8xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5607 | .rd_reg_direct = qla4_82xx_rd_32, |
| 5608 | .wr_reg_direct = qla4_82xx_wr_32, |
| 5609 | .rd_reg_indirect = qla4_82xx_md_rd_32, |
| 5610 | .wr_reg_indirect = qla4_82xx_md_wr_32, |
| 5611 | .idc_lock = qla4_82xx_idc_lock, |
| 5612 | .idc_unlock = qla4_82xx_idc_unlock, |
| 5613 | .rom_lock_recovery = qla4_82xx_rom_lock_recovery, |
| 5614 | .queue_mailbox_command = qla4_82xx_queue_mbox_cmd, |
| 5615 | .process_mailbox_interrupt = qla4_82xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5616 | }; |
| 5617 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5618 | static struct isp_operations qla4_83xx_isp_ops = { |
| 5619 | .iospace_config = qla4_8xxx_iospace_config, |
| 5620 | .pci_config = qla4_8xxx_pci_config, |
| 5621 | .disable_intrs = qla4_83xx_disable_intrs, |
| 5622 | .enable_intrs = qla4_83xx_enable_intrs, |
| 5623 | .start_firmware = qla4_8xxx_load_risc, |
| 5624 | .restart_firmware = qla4_83xx_start_firmware, |
| 5625 | .intr_handler = qla4_83xx_intr_handler, |
| 5626 | .interrupt_service_routine = qla4_83xx_interrupt_service_routine, |
| 5627 | .need_reset = qla4_8xxx_need_reset, |
| 5628 | .reset_chip = qla4_83xx_isp_reset, |
| 5629 | .reset_firmware = qla4_8xxx_stop_firmware, |
| 5630 | .queue_iocb = qla4_83xx_queue_iocb, |
| 5631 | .complete_iocb = qla4_83xx_complete_iocb, |
Tej Parkash | a24058f | 2013-03-07 05:43:13 -0500 | [diff] [blame] | 5632 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 5633 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5634 | .get_sys_info = qla4_8xxx_get_sys_info, |
| 5635 | .rd_reg_direct = qla4_83xx_rd_reg, |
| 5636 | .wr_reg_direct = qla4_83xx_wr_reg, |
| 5637 | .rd_reg_indirect = qla4_83xx_rd_reg_indirect, |
| 5638 | .wr_reg_indirect = qla4_83xx_wr_reg_indirect, |
| 5639 | .idc_lock = qla4_83xx_drv_lock, |
| 5640 | .idc_unlock = qla4_83xx_drv_unlock, |
| 5641 | .rom_lock_recovery = qla4_83xx_rom_lock_recovery, |
| 5642 | .queue_mailbox_command = qla4_83xx_queue_mbox_cmd, |
| 5643 | .process_mailbox_interrupt = qla4_83xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5644 | }; |
| 5645 | |
| 5646 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 5647 | { |
| 5648 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| 5649 | } |
| 5650 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5651 | 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] | 5652 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5653 | 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] | 5654 | } |
| 5655 | |
| 5656 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 5657 | { |
| 5658 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); |
| 5659 | } |
| 5660 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5661 | 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] | 5662 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5663 | 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] | 5664 | } |
| 5665 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5666 | static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf) |
| 5667 | { |
| 5668 | struct scsi_qla_host *ha = data; |
| 5669 | char *str = buf; |
| 5670 | int rc; |
| 5671 | |
| 5672 | switch (type) { |
| 5673 | case ISCSI_BOOT_ETH_FLAGS: |
| 5674 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 5675 | break; |
| 5676 | case ISCSI_BOOT_ETH_INDEX: |
| 5677 | rc = sprintf(str, "0\n"); |
| 5678 | break; |
| 5679 | case ISCSI_BOOT_ETH_MAC: |
| 5680 | rc = sysfs_format_mac(str, ha->my_mac, |
| 5681 | MAC_ADDR_LEN); |
| 5682 | break; |
| 5683 | default: |
| 5684 | rc = -ENOSYS; |
| 5685 | break; |
| 5686 | } |
| 5687 | return rc; |
| 5688 | } |
| 5689 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5690 | static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5691 | { |
| 5692 | int rc; |
| 5693 | |
| 5694 | switch (type) { |
| 5695 | case ISCSI_BOOT_ETH_FLAGS: |
| 5696 | case ISCSI_BOOT_ETH_MAC: |
| 5697 | case ISCSI_BOOT_ETH_INDEX: |
| 5698 | rc = S_IRUGO; |
| 5699 | break; |
| 5700 | default: |
| 5701 | rc = 0; |
| 5702 | break; |
| 5703 | } |
| 5704 | return rc; |
| 5705 | } |
| 5706 | |
| 5707 | static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf) |
| 5708 | { |
| 5709 | struct scsi_qla_host *ha = data; |
| 5710 | char *str = buf; |
| 5711 | int rc; |
| 5712 | |
| 5713 | switch (type) { |
| 5714 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5715 | rc = sprintf(str, "%s\n", ha->name_string); |
| 5716 | break; |
| 5717 | default: |
| 5718 | rc = -ENOSYS; |
| 5719 | break; |
| 5720 | } |
| 5721 | return rc; |
| 5722 | } |
| 5723 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5724 | static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5725 | { |
| 5726 | int rc; |
| 5727 | |
| 5728 | switch (type) { |
| 5729 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5730 | rc = S_IRUGO; |
| 5731 | break; |
| 5732 | default: |
| 5733 | rc = 0; |
| 5734 | break; |
| 5735 | } |
| 5736 | return rc; |
| 5737 | } |
| 5738 | |
| 5739 | static ssize_t |
| 5740 | qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type, |
| 5741 | char *buf) |
| 5742 | { |
| 5743 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 5744 | char *str = buf; |
| 5745 | int rc; |
| 5746 | |
| 5747 | switch (type) { |
| 5748 | case ISCSI_BOOT_TGT_NAME: |
| 5749 | rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name); |
| 5750 | break; |
| 5751 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5752 | if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1) |
| 5753 | rc = sprintf(buf, "%pI4\n", |
| 5754 | &boot_conn->dest_ipaddr.ip_address); |
| 5755 | else |
| 5756 | rc = sprintf(str, "%pI6\n", |
| 5757 | &boot_conn->dest_ipaddr.ip_address); |
| 5758 | break; |
| 5759 | case ISCSI_BOOT_TGT_PORT: |
| 5760 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 5761 | break; |
| 5762 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5763 | rc = sprintf(str, "%.*s\n", |
| 5764 | boot_conn->chap.target_chap_name_length, |
| 5765 | (char *)&boot_conn->chap.target_chap_name); |
| 5766 | break; |
| 5767 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5768 | rc = sprintf(str, "%.*s\n", |
| 5769 | boot_conn->chap.target_secret_length, |
| 5770 | (char *)&boot_conn->chap.target_secret); |
| 5771 | break; |
| 5772 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5773 | rc = sprintf(str, "%.*s\n", |
| 5774 | boot_conn->chap.intr_chap_name_length, |
| 5775 | (char *)&boot_conn->chap.intr_chap_name); |
| 5776 | break; |
| 5777 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5778 | rc = sprintf(str, "%.*s\n", |
| 5779 | boot_conn->chap.intr_secret_length, |
| 5780 | (char *)&boot_conn->chap.intr_secret); |
| 5781 | break; |
| 5782 | case ISCSI_BOOT_TGT_FLAGS: |
| 5783 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 5784 | break; |
| 5785 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5786 | rc = sprintf(str, "0\n"); |
| 5787 | break; |
| 5788 | default: |
| 5789 | rc = -ENOSYS; |
| 5790 | break; |
| 5791 | } |
| 5792 | return rc; |
| 5793 | } |
| 5794 | |
| 5795 | static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf) |
| 5796 | { |
| 5797 | struct scsi_qla_host *ha = data; |
| 5798 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess); |
| 5799 | |
| 5800 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 5801 | } |
| 5802 | |
| 5803 | static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf) |
| 5804 | { |
| 5805 | struct scsi_qla_host *ha = data; |
| 5806 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess); |
| 5807 | |
| 5808 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 5809 | } |
| 5810 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5811 | static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5812 | { |
| 5813 | int rc; |
| 5814 | |
| 5815 | switch (type) { |
| 5816 | case ISCSI_BOOT_TGT_NAME: |
| 5817 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5818 | case ISCSI_BOOT_TGT_PORT: |
| 5819 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5820 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5821 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5822 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5823 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5824 | case ISCSI_BOOT_TGT_FLAGS: |
| 5825 | rc = S_IRUGO; |
| 5826 | break; |
| 5827 | default: |
| 5828 | rc = 0; |
| 5829 | break; |
| 5830 | } |
| 5831 | return rc; |
| 5832 | } |
| 5833 | |
| 5834 | static void qla4xxx_boot_release(void *data) |
| 5835 | { |
| 5836 | struct scsi_qla_host *ha = data; |
| 5837 | |
| 5838 | scsi_host_put(ha->host); |
| 5839 | } |
| 5840 | |
| 5841 | static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) |
| 5842 | { |
| 5843 | dma_addr_t buf_dma; |
| 5844 | uint32_t addr, pri_addr, sec_addr; |
| 5845 | uint32_t offset; |
| 5846 | uint16_t func_num; |
| 5847 | uint8_t val; |
| 5848 | uint8_t *buf = NULL; |
| 5849 | size_t size = 13 * sizeof(uint8_t); |
| 5850 | int ret = QLA_SUCCESS; |
| 5851 | |
| 5852 | func_num = PCI_FUNC(ha->pdev->devfn); |
| 5853 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 5854 | ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n", |
| 5855 | __func__, ha->pdev->device, func_num); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5856 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 5857 | if (is_qla40XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5858 | if (func_num == 1) { |
| 5859 | addr = NVRAM_PORT0_BOOT_MODE; |
| 5860 | pri_addr = NVRAM_PORT0_BOOT_PRI_TGT; |
| 5861 | sec_addr = NVRAM_PORT0_BOOT_SEC_TGT; |
| 5862 | } else if (func_num == 3) { |
| 5863 | addr = NVRAM_PORT1_BOOT_MODE; |
| 5864 | pri_addr = NVRAM_PORT1_BOOT_PRI_TGT; |
| 5865 | sec_addr = NVRAM_PORT1_BOOT_SEC_TGT; |
| 5866 | } else { |
| 5867 | ret = QLA_ERROR; |
| 5868 | goto exit_boot_info; |
| 5869 | } |
| 5870 | |
| 5871 | /* Check Boot Mode */ |
| 5872 | val = rd_nvram_byte(ha, addr); |
| 5873 | if (!(val & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5874 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot " |
| 5875 | "options : 0x%x\n", __func__, val)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5876 | ret = QLA_ERROR; |
| 5877 | goto exit_boot_info; |
| 5878 | } |
| 5879 | |
| 5880 | /* get primary valid target index */ |
| 5881 | val = rd_nvram_byte(ha, pri_addr); |
| 5882 | if (val & BIT_7) |
| 5883 | ddb_index[0] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5884 | |
| 5885 | /* get secondary valid target index */ |
| 5886 | val = rd_nvram_byte(ha, sec_addr); |
| 5887 | if (val & BIT_7) |
| 5888 | ddb_index[1] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5889 | |
Vikas Chaudhary | 3e788fb | 2013-03-07 05:43:08 -0500 | [diff] [blame] | 5890 | } else if (is_qla80XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5891 | buf = dma_alloc_coherent(&ha->pdev->dev, size, |
| 5892 | &buf_dma, GFP_KERNEL); |
| 5893 | if (!buf) { |
| 5894 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5895 | "%s: Unable to allocate dma buffer\n", |
| 5896 | __func__)); |
| 5897 | ret = QLA_ERROR; |
| 5898 | goto exit_boot_info; |
| 5899 | } |
| 5900 | |
| 5901 | if (ha->port_num == 0) |
| 5902 | offset = BOOT_PARAM_OFFSET_PORT0; |
| 5903 | else if (ha->port_num == 1) |
| 5904 | offset = BOOT_PARAM_OFFSET_PORT1; |
| 5905 | else { |
| 5906 | ret = QLA_ERROR; |
| 5907 | goto exit_boot_info_free; |
| 5908 | } |
| 5909 | addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) + |
| 5910 | offset; |
| 5911 | if (qla4xxx_get_flash(ha, buf_dma, addr, |
| 5912 | 13 * sizeof(uint8_t)) != QLA_SUCCESS) { |
| 5913 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash" |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 5914 | " failed\n", ha->host_no, __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5915 | ret = QLA_ERROR; |
| 5916 | goto exit_boot_info_free; |
| 5917 | } |
| 5918 | /* Check Boot Mode */ |
| 5919 | if (!(buf[1] & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5920 | DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options" |
| 5921 | " : 0x%x\n", buf[1])); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5922 | ret = QLA_ERROR; |
| 5923 | goto exit_boot_info_free; |
| 5924 | } |
| 5925 | |
| 5926 | /* get primary valid target index */ |
| 5927 | if (buf[2] & BIT_7) |
| 5928 | ddb_index[0] = buf[2] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5929 | |
| 5930 | /* get secondary valid target index */ |
| 5931 | if (buf[11] & BIT_7) |
| 5932 | ddb_index[1] = buf[11] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5933 | } else { |
| 5934 | ret = QLA_ERROR; |
| 5935 | goto exit_boot_info; |
| 5936 | } |
| 5937 | |
| 5938 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary" |
| 5939 | " target ID %d\n", __func__, ddb_index[0], |
| 5940 | ddb_index[1])); |
| 5941 | |
| 5942 | exit_boot_info_free: |
| 5943 | dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma); |
| 5944 | exit_boot_info: |
Lalit Chandivade | 20e835b | 2012-02-13 18:30:42 +0530 | [diff] [blame] | 5945 | ha->pri_ddb_idx = ddb_index[0]; |
| 5946 | ha->sec_ddb_idx = ddb_index[1]; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5947 | return ret; |
| 5948 | } |
| 5949 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 5950 | /** |
| 5951 | * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password |
| 5952 | * @ha: pointer to adapter structure |
| 5953 | * @username: CHAP username to be returned |
| 5954 | * @password: CHAP password to be returned |
| 5955 | * |
| 5956 | * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP |
| 5957 | * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/. |
| 5958 | * So from the CHAP cache find the first BIDI CHAP entry and set it |
| 5959 | * to the boot record in sysfs. |
| 5960 | **/ |
| 5961 | static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username, |
| 5962 | char *password) |
| 5963 | { |
| 5964 | int i, ret = -EINVAL; |
| 5965 | int max_chap_entries = 0; |
| 5966 | struct ql4_chap_table *chap_table; |
| 5967 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 5968 | if (is_qla80XX(ha)) |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 5969 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 5970 | sizeof(struct ql4_chap_table); |
| 5971 | else |
| 5972 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 5973 | |
| 5974 | if (!ha->chap_list) { |
| 5975 | ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n"); |
| 5976 | return ret; |
| 5977 | } |
| 5978 | |
| 5979 | mutex_lock(&ha->chap_sem); |
| 5980 | for (i = 0; i < max_chap_entries; i++) { |
| 5981 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 5982 | if (chap_table->cookie != |
| 5983 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 5984 | continue; |
| 5985 | } |
| 5986 | |
| 5987 | if (chap_table->flags & BIT_7) /* local */ |
| 5988 | continue; |
| 5989 | |
| 5990 | if (!(chap_table->flags & BIT_6)) /* Not BIDI */ |
| 5991 | continue; |
| 5992 | |
| 5993 | strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN); |
| 5994 | strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN); |
| 5995 | ret = 0; |
| 5996 | break; |
| 5997 | } |
| 5998 | mutex_unlock(&ha->chap_sem); |
| 5999 | |
| 6000 | return ret; |
| 6001 | } |
| 6002 | |
| 6003 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6004 | static int qla4xxx_get_boot_target(struct scsi_qla_host *ha, |
| 6005 | struct ql4_boot_session_info *boot_sess, |
| 6006 | uint16_t ddb_index) |
| 6007 | { |
| 6008 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 6009 | struct dev_db_entry *fw_ddb_entry; |
| 6010 | dma_addr_t fw_ddb_entry_dma; |
| 6011 | uint16_t idx; |
| 6012 | uint16_t options; |
| 6013 | int ret = QLA_SUCCESS; |
| 6014 | |
| 6015 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6016 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 6017 | if (!fw_ddb_entry) { |
| 6018 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 6019 | "%s: Unable to allocate dma buffer.\n", |
| 6020 | __func__)); |
| 6021 | ret = QLA_ERROR; |
| 6022 | return ret; |
| 6023 | } |
| 6024 | |
| 6025 | if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry, |
| 6026 | fw_ddb_entry_dma, ddb_index)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6027 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at " |
| 6028 | "index [%d]\n", __func__, ddb_index)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6029 | ret = QLA_ERROR; |
| 6030 | goto exit_boot_target; |
| 6031 | } |
| 6032 | |
| 6033 | /* Update target name and IP from DDB */ |
| 6034 | memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name, |
| 6035 | min(sizeof(boot_sess->target_name), |
| 6036 | sizeof(fw_ddb_entry->iscsi_name))); |
| 6037 | |
| 6038 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6039 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 6040 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 6041 | &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN); |
| 6042 | } else { |
| 6043 | boot_conn->dest_ipaddr.ip_type = 0x1; |
| 6044 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 6045 | &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN); |
| 6046 | } |
| 6047 | |
| 6048 | boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port); |
| 6049 | |
| 6050 | /* update chap information */ |
| 6051 | idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 6052 | |
| 6053 | if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 6054 | |
| 6055 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n")); |
| 6056 | |
| 6057 | ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap. |
| 6058 | target_chap_name, |
| 6059 | (char *)&boot_conn->chap.target_secret, |
| 6060 | idx); |
| 6061 | if (ret) { |
| 6062 | ql4_printk(KERN_ERR, ha, "Failed to set chap\n"); |
| 6063 | ret = QLA_ERROR; |
| 6064 | goto exit_boot_target; |
| 6065 | } |
| 6066 | |
| 6067 | boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 6068 | boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 6069 | } |
| 6070 | |
| 6071 | if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 6072 | |
| 6073 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n")); |
| 6074 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 6075 | ret = qla4xxx_get_bidi_chap(ha, |
| 6076 | (char *)&boot_conn->chap.intr_chap_name, |
| 6077 | (char *)&boot_conn->chap.intr_secret); |
| 6078 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6079 | if (ret) { |
| 6080 | ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n"); |
| 6081 | ret = QLA_ERROR; |
| 6082 | goto exit_boot_target; |
| 6083 | } |
| 6084 | |
| 6085 | boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 6086 | boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 6087 | } |
| 6088 | |
| 6089 | exit_boot_target: |
| 6090 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6091 | fw_ddb_entry, fw_ddb_entry_dma); |
| 6092 | return ret; |
| 6093 | } |
| 6094 | |
| 6095 | static int qla4xxx_get_boot_info(struct scsi_qla_host *ha) |
| 6096 | { |
| 6097 | uint16_t ddb_index[2]; |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6098 | int ret = QLA_ERROR; |
| 6099 | int rval; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6100 | |
| 6101 | memset(ddb_index, 0, sizeof(ddb_index)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6102 | ddb_index[0] = 0xffff; |
| 6103 | ddb_index[1] = 0xffff; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6104 | ret = get_fw_boot_info(ha, ddb_index); |
| 6105 | if (ret != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6106 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6107 | "%s: No boot target configured.\n", __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6108 | return ret; |
| 6109 | } |
| 6110 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6111 | if (ql4xdisablesysfsboot) |
| 6112 | return QLA_SUCCESS; |
| 6113 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6114 | if (ddb_index[0] == 0xffff) |
| 6115 | goto sec_target; |
| 6116 | |
| 6117 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6118 | ddb_index[0]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6119 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6120 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not " |
| 6121 | "configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6122 | } else |
| 6123 | ret = QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6124 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6125 | sec_target: |
| 6126 | if (ddb_index[1] == 0xffff) |
| 6127 | goto exit_get_boot_info; |
| 6128 | |
| 6129 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6130 | ddb_index[1]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6131 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6132 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not" |
| 6133 | " configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6134 | } else |
| 6135 | ret = QLA_SUCCESS; |
| 6136 | |
| 6137 | exit_get_boot_info: |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6138 | return ret; |
| 6139 | } |
| 6140 | |
| 6141 | static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha) |
| 6142 | { |
| 6143 | struct iscsi_boot_kobj *boot_kobj; |
| 6144 | |
| 6145 | if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6146 | return QLA_ERROR; |
| 6147 | |
| 6148 | if (ql4xdisablesysfsboot) { |
| 6149 | ql4_printk(KERN_INFO, ha, |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 6150 | "%s: syfsboot disabled - driver will trigger login " |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6151 | "and publish session for discovery .\n", __func__); |
| 6152 | return QLA_SUCCESS; |
| 6153 | } |
| 6154 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6155 | |
| 6156 | ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no); |
| 6157 | if (!ha->boot_kset) |
| 6158 | goto kset_free; |
| 6159 | |
| 6160 | if (!scsi_host_get(ha->host)) |
| 6161 | goto kset_free; |
| 6162 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha, |
| 6163 | qla4xxx_show_boot_tgt_pri_info, |
| 6164 | qla4xxx_tgt_get_attr_visibility, |
| 6165 | qla4xxx_boot_release); |
| 6166 | if (!boot_kobj) |
| 6167 | goto put_host; |
| 6168 | |
| 6169 | if (!scsi_host_get(ha->host)) |
| 6170 | goto kset_free; |
| 6171 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha, |
| 6172 | qla4xxx_show_boot_tgt_sec_info, |
| 6173 | qla4xxx_tgt_get_attr_visibility, |
| 6174 | qla4xxx_boot_release); |
| 6175 | if (!boot_kobj) |
| 6176 | goto put_host; |
| 6177 | |
| 6178 | if (!scsi_host_get(ha->host)) |
| 6179 | goto kset_free; |
| 6180 | boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha, |
| 6181 | qla4xxx_show_boot_ini_info, |
| 6182 | qla4xxx_ini_get_attr_visibility, |
| 6183 | qla4xxx_boot_release); |
| 6184 | if (!boot_kobj) |
| 6185 | goto put_host; |
| 6186 | |
| 6187 | if (!scsi_host_get(ha->host)) |
| 6188 | goto kset_free; |
| 6189 | boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha, |
| 6190 | qla4xxx_show_boot_eth_info, |
| 6191 | qla4xxx_eth_get_attr_visibility, |
| 6192 | qla4xxx_boot_release); |
| 6193 | if (!boot_kobj) |
| 6194 | goto put_host; |
| 6195 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6196 | return QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6197 | |
| 6198 | put_host: |
| 6199 | scsi_host_put(ha->host); |
| 6200 | kset_free: |
| 6201 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 6202 | return -ENOMEM; |
| 6203 | } |
| 6204 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 6205 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6206 | static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry, |
| 6207 | struct ql4_tuple_ddb *tddb) |
| 6208 | { |
| 6209 | struct scsi_qla_host *ha; |
| 6210 | struct iscsi_cls_session *cls_sess; |
| 6211 | struct iscsi_cls_conn *cls_conn; |
| 6212 | struct iscsi_session *sess; |
| 6213 | struct iscsi_conn *conn; |
| 6214 | |
| 6215 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 6216 | ha = ddb_entry->ha; |
| 6217 | cls_sess = ddb_entry->sess; |
| 6218 | sess = cls_sess->dd_data; |
| 6219 | cls_conn = ddb_entry->conn; |
| 6220 | conn = cls_conn->dd_data; |
| 6221 | |
| 6222 | tddb->tpgt = sess->tpgt; |
| 6223 | tddb->port = conn->persistent_port; |
| 6224 | strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE); |
| 6225 | strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN); |
| 6226 | } |
| 6227 | |
| 6228 | 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] | 6229 | struct ql4_tuple_ddb *tddb, |
| 6230 | uint8_t *flash_isid) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6231 | { |
| 6232 | uint16_t options = 0; |
| 6233 | |
| 6234 | tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 6235 | memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
| 6236 | min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name))); |
| 6237 | |
| 6238 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6239 | if (options & DDB_OPT_IPV6_DEVICE) |
| 6240 | sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 6241 | else |
| 6242 | sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 6243 | |
| 6244 | tddb->port = le16_to_cpu(fw_ddb_entry->port); |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6245 | |
| 6246 | if (flash_isid == NULL) |
| 6247 | memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0], |
| 6248 | sizeof(tddb->isid)); |
| 6249 | else |
| 6250 | memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha, |
| 6254 | struct ql4_tuple_ddb *old_tddb, |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6255 | struct ql4_tuple_ddb *new_tddb, |
| 6256 | uint8_t is_isid_compare) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6257 | { |
| 6258 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 6259 | return QLA_ERROR; |
| 6260 | |
| 6261 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr)) |
| 6262 | return QLA_ERROR; |
| 6263 | |
| 6264 | if (old_tddb->port != new_tddb->port) |
| 6265 | return QLA_ERROR; |
| 6266 | |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6267 | /* For multi sessions, driver generates the ISID, so do not compare |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 6268 | * ISID in reset path since it would be a comparison between the |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6269 | * driver generated ISID and firmware generated ISID. This could |
| 6270 | * lead to adding duplicated DDBs in the list as driver generated |
| 6271 | * ISID would not match firmware generated ISID. |
| 6272 | */ |
| 6273 | if (is_isid_compare) { |
| 6274 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x" |
| 6275 | "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n", |
| 6276 | __func__, old_tddb->isid[5], old_tddb->isid[4], |
| 6277 | old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1], |
| 6278 | old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4], |
| 6279 | new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1], |
| 6280 | new_tddb->isid[0])); |
| 6281 | |
| 6282 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 6283 | sizeof(old_tddb->isid))) |
| 6284 | return QLA_ERROR; |
| 6285 | } |
| 6286 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6287 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6288 | "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]", |
| 6289 | old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr, |
| 6290 | old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt, |
| 6291 | new_tddb->ip_addr, new_tddb->iscsi_name)); |
| 6292 | |
| 6293 | return QLA_SUCCESS; |
| 6294 | } |
| 6295 | |
| 6296 | static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6297 | struct dev_db_entry *fw_ddb_entry, |
| 6298 | uint32_t *index) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6299 | { |
| 6300 | struct ddb_entry *ddb_entry; |
| 6301 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 6302 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 6303 | int idx; |
| 6304 | int ret = QLA_ERROR; |
| 6305 | |
| 6306 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 6307 | if (!fw_tddb) { |
| 6308 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6309 | "Memory Allocation failed.\n")); |
| 6310 | ret = QLA_SUCCESS; |
| 6311 | goto exit_check; |
| 6312 | } |
| 6313 | |
| 6314 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6315 | if (!tmp_tddb) { |
| 6316 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6317 | "Memory Allocation failed.\n")); |
| 6318 | ret = QLA_SUCCESS; |
| 6319 | goto exit_check; |
| 6320 | } |
| 6321 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6322 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6323 | |
| 6324 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 6325 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 6326 | if (ddb_entry == NULL) |
| 6327 | continue; |
| 6328 | |
| 6329 | qla4xxx_get_param_ddb(ddb_entry, tmp_tddb); |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6330 | if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6331 | ret = QLA_SUCCESS; /* found */ |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6332 | if (index != NULL) |
| 6333 | *index = idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6334 | goto exit_check; |
| 6335 | } |
| 6336 | } |
| 6337 | |
| 6338 | exit_check: |
| 6339 | if (fw_tddb) |
| 6340 | vfree(fw_tddb); |
| 6341 | if (tmp_tddb) |
| 6342 | vfree(tmp_tddb); |
| 6343 | return ret; |
| 6344 | } |
| 6345 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6346 | /** |
| 6347 | * qla4xxx_check_existing_isid - check if target with same isid exist |
| 6348 | * in target list |
| 6349 | * @list_nt: list of target |
| 6350 | * @isid: isid to check |
| 6351 | * |
| 6352 | * This routine return QLA_SUCCESS if target with same isid exist |
| 6353 | **/ |
| 6354 | static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid) |
| 6355 | { |
| 6356 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 6357 | struct dev_db_entry *fw_ddb_entry; |
| 6358 | |
| 6359 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 6360 | fw_ddb_entry = &nt_ddb_idx->fw_ddb; |
| 6361 | |
| 6362 | if (memcmp(&fw_ddb_entry->isid[0], &isid[0], |
| 6363 | sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) { |
| 6364 | return QLA_SUCCESS; |
| 6365 | } |
| 6366 | } |
| 6367 | return QLA_ERROR; |
| 6368 | } |
| 6369 | |
| 6370 | /** |
| 6371 | * qla4xxx_update_isid - compare ddbs and updated isid |
| 6372 | * @ha: Pointer to host adapter structure. |
| 6373 | * @list_nt: list of nt target |
| 6374 | * @fw_ddb_entry: firmware ddb entry |
| 6375 | * |
| 6376 | * This routine update isid if ddbs have same iqn, same isid and |
| 6377 | * different IP addr. |
| 6378 | * Return QLA_SUCCESS if isid is updated. |
| 6379 | **/ |
| 6380 | static int qla4xxx_update_isid(struct scsi_qla_host *ha, |
| 6381 | struct list_head *list_nt, |
| 6382 | struct dev_db_entry *fw_ddb_entry) |
| 6383 | { |
| 6384 | uint8_t base_value, i; |
| 6385 | |
| 6386 | base_value = fw_ddb_entry->isid[1] & 0x1f; |
| 6387 | for (i = 0; i < 8; i++) { |
| 6388 | fw_ddb_entry->isid[1] = (base_value | (i << 5)); |
| 6389 | if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 6390 | break; |
| 6391 | } |
| 6392 | |
| 6393 | if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 6394 | return QLA_ERROR; |
| 6395 | |
| 6396 | return QLA_SUCCESS; |
| 6397 | } |
| 6398 | |
| 6399 | /** |
| 6400 | * qla4xxx_should_update_isid - check if isid need to update |
| 6401 | * @ha: Pointer to host adapter structure. |
| 6402 | * @old_tddb: ddb tuple |
| 6403 | * @new_tddb: ddb tuple |
| 6404 | * |
| 6405 | * Return QLA_SUCCESS if different IP, different PORT, same iqn, |
| 6406 | * same isid |
| 6407 | **/ |
| 6408 | static int qla4xxx_should_update_isid(struct scsi_qla_host *ha, |
| 6409 | struct ql4_tuple_ddb *old_tddb, |
| 6410 | struct ql4_tuple_ddb *new_tddb) |
| 6411 | { |
| 6412 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) { |
| 6413 | /* Same ip */ |
| 6414 | if (old_tddb->port == new_tddb->port) |
| 6415 | return QLA_ERROR; |
| 6416 | } |
| 6417 | |
| 6418 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 6419 | /* different iqn */ |
| 6420 | return QLA_ERROR; |
| 6421 | |
| 6422 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 6423 | sizeof(old_tddb->isid))) |
| 6424 | /* different isid */ |
| 6425 | return QLA_ERROR; |
| 6426 | |
| 6427 | return QLA_SUCCESS; |
| 6428 | } |
| 6429 | |
| 6430 | /** |
| 6431 | * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt |
| 6432 | * @ha: Pointer to host adapter structure. |
| 6433 | * @list_nt: list of nt target. |
| 6434 | * @fw_ddb_entry: firmware ddb entry. |
| 6435 | * |
| 6436 | * This routine check if fw_ddb_entry already exists in list_nt to avoid |
| 6437 | * duplicate ddb in list_nt. |
| 6438 | * Return QLA_SUCCESS if duplicate ddb exit in list_nl. |
| 6439 | * Note: This function also update isid of DDB if required. |
| 6440 | **/ |
| 6441 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6442 | static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, |
| 6443 | struct list_head *list_nt, |
| 6444 | struct dev_db_entry *fw_ddb_entry) |
| 6445 | { |
| 6446 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 6447 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 6448 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6449 | int rval, ret = QLA_ERROR; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6450 | |
| 6451 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 6452 | if (!fw_tddb) { |
| 6453 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6454 | "Memory Allocation failed.\n")); |
| 6455 | ret = QLA_SUCCESS; |
| 6456 | goto exit_check; |
| 6457 | } |
| 6458 | |
| 6459 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6460 | if (!tmp_tddb) { |
| 6461 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6462 | "Memory Allocation failed.\n")); |
| 6463 | ret = QLA_SUCCESS; |
| 6464 | goto exit_check; |
| 6465 | } |
| 6466 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6467 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6468 | |
| 6469 | 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] | 6470 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, |
| 6471 | nt_ddb_idx->flash_isid); |
| 6472 | ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true); |
| 6473 | /* found duplicate ddb */ |
| 6474 | if (ret == QLA_SUCCESS) |
| 6475 | goto exit_check; |
| 6476 | } |
| 6477 | |
| 6478 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 6479 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL); |
| 6480 | |
| 6481 | ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb); |
| 6482 | if (ret == QLA_SUCCESS) { |
| 6483 | rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry); |
| 6484 | if (rval == QLA_SUCCESS) |
| 6485 | ret = QLA_ERROR; |
| 6486 | else |
| 6487 | ret = QLA_SUCCESS; |
| 6488 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6489 | goto exit_check; |
| 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | exit_check: |
| 6494 | if (fw_tddb) |
| 6495 | vfree(fw_tddb); |
| 6496 | if (tmp_tddb) |
| 6497 | vfree(tmp_tddb); |
| 6498 | return ret; |
| 6499 | } |
| 6500 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6501 | static void qla4xxx_free_ddb_list(struct list_head *list_ddb) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6502 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6503 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6504 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6505 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6506 | list_del_init(&ddb_idx->list); |
| 6507 | vfree(ddb_idx); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6508 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6509 | } |
| 6510 | |
| 6511 | static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha, |
| 6512 | struct dev_db_entry *fw_ddb_entry) |
| 6513 | { |
| 6514 | struct iscsi_endpoint *ep; |
| 6515 | struct sockaddr_in *addr; |
| 6516 | struct sockaddr_in6 *addr6; |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6517 | struct sockaddr *t_addr; |
| 6518 | struct sockaddr_storage *dst_addr; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6519 | char *ip; |
| 6520 | |
| 6521 | /* TODO: need to destroy on unload iscsi_endpoint*/ |
| 6522 | dst_addr = vmalloc(sizeof(*dst_addr)); |
| 6523 | if (!dst_addr) |
| 6524 | return NULL; |
| 6525 | |
| 6526 | if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6527 | t_addr = (struct sockaddr *)dst_addr; |
| 6528 | t_addr->sa_family = AF_INET6; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6529 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 6530 | ip = (char *)&addr6->sin6_addr; |
| 6531 | memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 6532 | addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 6533 | |
| 6534 | } else { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6535 | t_addr = (struct sockaddr *)dst_addr; |
| 6536 | t_addr->sa_family = AF_INET; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6537 | addr = (struct sockaddr_in *)dst_addr; |
| 6538 | ip = (char *)&addr->sin_addr; |
| 6539 | memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN); |
| 6540 | addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 6541 | } |
| 6542 | |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6543 | ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6544 | vfree(dst_addr); |
| 6545 | return ep; |
| 6546 | } |
| 6547 | |
| 6548 | static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx) |
| 6549 | { |
| 6550 | if (ql4xdisablesysfsboot) |
| 6551 | return QLA_SUCCESS; |
| 6552 | if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx) |
| 6553 | return QLA_ERROR; |
| 6554 | return QLA_SUCCESS; |
| 6555 | } |
| 6556 | |
| 6557 | static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6558 | struct ddb_entry *ddb_entry, |
| 6559 | uint16_t idx) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6560 | { |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6561 | uint16_t def_timeout; |
| 6562 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6563 | ddb_entry->ddb_type = FLASH_DDB; |
| 6564 | ddb_entry->fw_ddb_index = INVALID_ENTRY; |
| 6565 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 6566 | ddb_entry->ha = ha; |
| 6567 | ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb; |
| 6568 | ddb_entry->ddb_change = qla4xxx_flash_ddb_change; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 6569 | ddb_entry->chap_tbl_idx = INVALID_ENTRY; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6570 | |
| 6571 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 6572 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 6573 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6574 | def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6575 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6576 | (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ? |
| 6577 | def_timeout : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6578 | ddb_entry->default_time2wait = |
| 6579 | le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6580 | |
| 6581 | if (ql4xdisablesysfsboot && |
| 6582 | (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)) |
| 6583 | set_bit(DF_BOOT_TGT, &ddb_entry->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha) |
| 6587 | { |
| 6588 | uint32_t idx = 0; |
| 6589 | uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */ |
| 6590 | uint32_t sts[MBOX_REG_COUNT]; |
| 6591 | uint32_t ip_state; |
| 6592 | unsigned long wtime; |
| 6593 | int ret; |
| 6594 | |
| 6595 | wtime = jiffies + (HZ * IP_CONFIG_TOV); |
| 6596 | do { |
| 6597 | for (idx = 0; idx < IP_ADDR_COUNT; idx++) { |
| 6598 | if (ip_idx[idx] == -1) |
| 6599 | continue; |
| 6600 | |
| 6601 | ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts); |
| 6602 | |
| 6603 | if (ret == QLA_ERROR) { |
| 6604 | ip_idx[idx] = -1; |
| 6605 | continue; |
| 6606 | } |
| 6607 | |
| 6608 | ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT; |
| 6609 | |
| 6610 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6611 | "Waiting for IP state for idx = %d, state = 0x%x\n", |
| 6612 | ip_idx[idx], ip_state)); |
| 6613 | if (ip_state == IP_ADDRSTATE_UNCONFIGURED || |
| 6614 | ip_state == IP_ADDRSTATE_INVALID || |
| 6615 | ip_state == IP_ADDRSTATE_PREFERRED || |
| 6616 | ip_state == IP_ADDRSTATE_DEPRICATED || |
| 6617 | ip_state == IP_ADDRSTATE_DISABLING) |
| 6618 | ip_idx[idx] = -1; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | /* Break if all IP states checked */ |
| 6622 | if ((ip_idx[0] == -1) && |
| 6623 | (ip_idx[1] == -1) && |
| 6624 | (ip_idx[2] == -1) && |
| 6625 | (ip_idx[3] == -1)) |
| 6626 | break; |
| 6627 | schedule_timeout_uninterruptible(HZ); |
| 6628 | } while (time_after(wtime, jiffies)); |
| 6629 | } |
| 6630 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6631 | static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry, |
| 6632 | struct dev_db_entry *flash_ddb_entry) |
| 6633 | { |
| 6634 | uint16_t options = 0; |
| 6635 | size_t ip_len = IP_ADDR_LEN; |
| 6636 | |
| 6637 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6638 | if (options & DDB_OPT_IPV6_DEVICE) |
| 6639 | ip_len = IPv6_ADDR_LEN; |
| 6640 | |
| 6641 | if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len)) |
| 6642 | return QLA_ERROR; |
| 6643 | |
| 6644 | if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0], |
| 6645 | sizeof(fw_ddb_entry->isid))) |
| 6646 | return QLA_ERROR; |
| 6647 | |
| 6648 | if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port, |
| 6649 | sizeof(fw_ddb_entry->port))) |
| 6650 | return QLA_ERROR; |
| 6651 | |
| 6652 | return QLA_SUCCESS; |
| 6653 | } |
| 6654 | |
| 6655 | static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha, |
| 6656 | struct dev_db_entry *fw_ddb_entry, |
| 6657 | uint32_t fw_idx, uint32_t *flash_index) |
| 6658 | { |
| 6659 | struct dev_db_entry *flash_ddb_entry; |
| 6660 | dma_addr_t flash_ddb_entry_dma; |
| 6661 | uint32_t idx = 0; |
| 6662 | int max_ddbs; |
| 6663 | int ret = QLA_ERROR, status; |
| 6664 | |
| 6665 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6666 | MAX_DEV_DB_ENTRIES; |
| 6667 | |
| 6668 | flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6669 | &flash_ddb_entry_dma); |
| 6670 | if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) { |
| 6671 | ql4_printk(KERN_ERR, ha, "Out of memory\n"); |
| 6672 | goto exit_find_st_idx; |
| 6673 | } |
| 6674 | |
| 6675 | status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry, |
| 6676 | flash_ddb_entry_dma, fw_idx); |
| 6677 | if (status == QLA_SUCCESS) { |
| 6678 | status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry); |
| 6679 | if (status == QLA_SUCCESS) { |
| 6680 | *flash_index = fw_idx; |
| 6681 | ret = QLA_SUCCESS; |
| 6682 | goto exit_find_st_idx; |
| 6683 | } |
| 6684 | } |
| 6685 | |
| 6686 | for (idx = 0; idx < max_ddbs; idx++) { |
| 6687 | status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry, |
| 6688 | flash_ddb_entry_dma, idx); |
| 6689 | if (status == QLA_ERROR) |
| 6690 | continue; |
| 6691 | |
| 6692 | status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry); |
| 6693 | if (status == QLA_SUCCESS) { |
| 6694 | *flash_index = idx; |
| 6695 | ret = QLA_SUCCESS; |
| 6696 | goto exit_find_st_idx; |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | if (idx == max_ddbs) |
| 6701 | ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n", |
| 6702 | fw_idx); |
| 6703 | |
| 6704 | exit_find_st_idx: |
| 6705 | if (flash_ddb_entry) |
| 6706 | dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry, |
| 6707 | flash_ddb_entry_dma); |
| 6708 | |
| 6709 | return ret; |
| 6710 | } |
| 6711 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6712 | static void qla4xxx_build_st_list(struct scsi_qla_host *ha, |
| 6713 | struct list_head *list_st) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6714 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6715 | struct qla_ddb_index *st_ddb_idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6716 | int max_ddbs; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6717 | int fw_idx_size; |
| 6718 | struct dev_db_entry *fw_ddb_entry; |
| 6719 | dma_addr_t fw_ddb_dma; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6720 | int ret; |
| 6721 | uint32_t idx = 0, next_idx = 0; |
| 6722 | uint32_t state = 0, conn_err = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6723 | uint32_t flash_index = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6724 | uint16_t conn_id = 0; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6725 | |
| 6726 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6727 | &fw_ddb_dma); |
| 6728 | if (fw_ddb_entry == NULL) { |
| 6729 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6730 | goto exit_st_list; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6731 | } |
| 6732 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6733 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6734 | MAX_DEV_DB_ENTRIES; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6735 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 6736 | |
| 6737 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6738 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 6739 | NULL, &next_idx, &state, |
| 6740 | &conn_err, NULL, &conn_id); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6741 | if (ret == QLA_ERROR) |
| 6742 | break; |
| 6743 | |
Lalit Chandivade | 981c982 | 2012-02-13 18:30:41 +0530 | [diff] [blame] | 6744 | /* Ignore DDB if invalid state (unassigned) */ |
| 6745 | if (state == DDB_DS_UNASSIGNED) |
| 6746 | goto continue_next_st; |
| 6747 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6748 | /* Check if ST, add to the list_st */ |
| 6749 | if (strlen((char *) fw_ddb_entry->iscsi_name) != 0) |
| 6750 | goto continue_next_st; |
| 6751 | |
| 6752 | st_ddb_idx = vzalloc(fw_idx_size); |
| 6753 | if (!st_ddb_idx) |
| 6754 | break; |
| 6755 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6756 | ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx, |
| 6757 | &flash_index); |
| 6758 | if (ret == QLA_ERROR) { |
| 6759 | ql4_printk(KERN_ERR, ha, |
| 6760 | "No flash entry for ST at idx [%d]\n", idx); |
| 6761 | st_ddb_idx->flash_ddb_idx = idx; |
| 6762 | } else { |
| 6763 | ql4_printk(KERN_INFO, ha, |
| 6764 | "ST at idx [%d] is stored at flash [%d]\n", |
| 6765 | idx, flash_index); |
| 6766 | st_ddb_idx->flash_ddb_idx = flash_index; |
| 6767 | } |
| 6768 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6769 | st_ddb_idx->fw_ddb_idx = idx; |
| 6770 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6771 | list_add_tail(&st_ddb_idx->list, list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6772 | continue_next_st: |
| 6773 | if (next_idx == 0) |
| 6774 | break; |
| 6775 | } |
| 6776 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6777 | exit_st_list: |
| 6778 | if (fw_ddb_entry) |
| 6779 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 6780 | } |
| 6781 | |
| 6782 | /** |
| 6783 | * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list |
| 6784 | * @ha: pointer to adapter structure |
| 6785 | * @list_ddb: List from which failed ddb to be removed |
| 6786 | * |
| 6787 | * Iterate over the list of DDBs and find and remove DDBs that are either in |
| 6788 | * no connection active state or failed state |
| 6789 | **/ |
| 6790 | static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha, |
| 6791 | struct list_head *list_ddb) |
| 6792 | { |
| 6793 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 6794 | uint32_t next_idx = 0; |
| 6795 | uint32_t state = 0, conn_err = 0; |
| 6796 | int ret; |
| 6797 | |
| 6798 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6799 | ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx, |
| 6800 | NULL, 0, NULL, &next_idx, &state, |
| 6801 | &conn_err, NULL, NULL); |
| 6802 | if (ret == QLA_ERROR) |
| 6803 | continue; |
| 6804 | |
| 6805 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 6806 | state == DDB_DS_SESSION_FAILED) { |
| 6807 | list_del_init(&ddb_idx->list); |
| 6808 | vfree(ddb_idx); |
| 6809 | } |
| 6810 | } |
| 6811 | } |
| 6812 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6813 | static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha, |
| 6814 | struct ddb_entry *ddb_entry, |
| 6815 | struct dev_db_entry *fw_ddb_entry) |
| 6816 | { |
| 6817 | struct iscsi_cls_session *cls_sess; |
| 6818 | struct iscsi_session *sess; |
| 6819 | uint32_t max_ddbs = 0; |
| 6820 | uint16_t ddb_link = -1; |
| 6821 | |
| 6822 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6823 | MAX_DEV_DB_ENTRIES; |
| 6824 | |
| 6825 | cls_sess = ddb_entry->sess; |
| 6826 | sess = cls_sess->dd_data; |
| 6827 | |
| 6828 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6829 | if (ddb_link < max_ddbs) |
| 6830 | sess->discovery_parent_idx = ddb_link; |
| 6831 | else |
| 6832 | sess->discovery_parent_idx = DDB_NO_LINK; |
| 6833 | } |
| 6834 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6835 | static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha, |
| 6836 | struct dev_db_entry *fw_ddb_entry, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6837 | int is_reset, uint16_t idx) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6838 | { |
| 6839 | struct iscsi_cls_session *cls_sess; |
| 6840 | struct iscsi_session *sess; |
| 6841 | struct iscsi_cls_conn *cls_conn; |
| 6842 | struct iscsi_endpoint *ep; |
| 6843 | uint16_t cmds_max = 32; |
| 6844 | uint16_t conn_id = 0; |
| 6845 | uint32_t initial_cmdsn = 0; |
| 6846 | int ret = QLA_SUCCESS; |
| 6847 | |
| 6848 | struct ddb_entry *ddb_entry = NULL; |
| 6849 | |
| 6850 | /* Create session object, with INVALID_ENTRY, |
| 6851 | * the targer_id would get set when we issue the login |
| 6852 | */ |
| 6853 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host, |
| 6854 | cmds_max, sizeof(struct ddb_entry), |
| 6855 | sizeof(struct ql4_task_data), |
| 6856 | initial_cmdsn, INVALID_ENTRY); |
| 6857 | if (!cls_sess) { |
| 6858 | ret = QLA_ERROR; |
| 6859 | goto exit_setup; |
| 6860 | } |
| 6861 | |
| 6862 | /* |
| 6863 | * so calling module_put function to decrement the |
| 6864 | * reference count. |
| 6865 | **/ |
| 6866 | module_put(qla4xxx_iscsi_transport.owner); |
| 6867 | sess = cls_sess->dd_data; |
| 6868 | ddb_entry = sess->dd_data; |
| 6869 | ddb_entry->sess = cls_sess; |
| 6870 | |
| 6871 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 6872 | memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry, |
| 6873 | sizeof(struct dev_db_entry)); |
| 6874 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6875 | qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6876 | |
| 6877 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id); |
| 6878 | |
| 6879 | if (!cls_conn) { |
| 6880 | ret = QLA_ERROR; |
| 6881 | goto exit_setup; |
| 6882 | } |
| 6883 | |
| 6884 | ddb_entry->conn = cls_conn; |
| 6885 | |
| 6886 | /* Setup ep, for displaying attributes in sysfs */ |
| 6887 | ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry); |
| 6888 | if (ep) { |
| 6889 | ep->conn = cls_conn; |
| 6890 | cls_conn->ep = ep; |
| 6891 | } else { |
| 6892 | DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n")); |
| 6893 | ret = QLA_ERROR; |
| 6894 | goto exit_setup; |
| 6895 | } |
| 6896 | |
| 6897 | /* Update sess/conn params */ |
| 6898 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6899 | qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6900 | |
| 6901 | if (is_reset == RESET_ADAPTER) { |
| 6902 | iscsi_block_session(cls_sess); |
| 6903 | /* Use the relogin path to discover new devices |
| 6904 | * by short-circuting the logic of setting |
| 6905 | * timer to relogin - instead set the flags |
| 6906 | * to initiate login right away. |
| 6907 | */ |
| 6908 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 6909 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 6910 | } |
| 6911 | |
| 6912 | exit_setup: |
| 6913 | return ret; |
| 6914 | } |
| 6915 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6916 | static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha, |
| 6917 | struct list_head *list_ddb, |
| 6918 | struct dev_db_entry *fw_ddb_entry) |
| 6919 | { |
| 6920 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 6921 | uint16_t ddb_link; |
| 6922 | |
| 6923 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6924 | |
| 6925 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6926 | if (ddb_idx->fw_ddb_idx == ddb_link) { |
| 6927 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6928 | "Updating NT parent idx from [%d] to [%d]\n", |
| 6929 | ddb_link, ddb_idx->flash_ddb_idx)); |
| 6930 | fw_ddb_entry->ddb_link = |
| 6931 | cpu_to_le16(ddb_idx->flash_ddb_idx); |
| 6932 | return; |
| 6933 | } |
| 6934 | } |
| 6935 | } |
| 6936 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6937 | static void qla4xxx_build_nt_list(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6938 | struct list_head *list_nt, |
| 6939 | struct list_head *list_st, |
| 6940 | int is_reset) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6941 | { |
| 6942 | struct dev_db_entry *fw_ddb_entry; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6943 | struct ddb_entry *ddb_entry = NULL; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6944 | dma_addr_t fw_ddb_dma; |
| 6945 | int max_ddbs; |
| 6946 | int fw_idx_size; |
| 6947 | int ret; |
| 6948 | uint32_t idx = 0, next_idx = 0; |
| 6949 | uint32_t state = 0, conn_err = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6950 | uint32_t ddb_idx = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6951 | uint16_t conn_id = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6952 | uint16_t ddb_link = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6953 | struct qla_ddb_index *nt_ddb_idx; |
| 6954 | |
| 6955 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6956 | &fw_ddb_dma); |
| 6957 | if (fw_ddb_entry == NULL) { |
| 6958 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 6959 | goto exit_nt_list; |
| 6960 | } |
| 6961 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6962 | MAX_DEV_DB_ENTRIES; |
| 6963 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 6964 | |
| 6965 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 6966 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 6967 | NULL, &next_idx, &state, |
| 6968 | &conn_err, NULL, &conn_id); |
| 6969 | if (ret == QLA_ERROR) |
| 6970 | break; |
| 6971 | |
| 6972 | if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS) |
| 6973 | goto continue_next_nt; |
| 6974 | |
| 6975 | /* Check if NT, then add to list it */ |
| 6976 | if (strlen((char *) fw_ddb_entry->iscsi_name) == 0) |
| 6977 | goto continue_next_nt; |
| 6978 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6979 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6980 | if (ddb_link < max_ddbs) |
| 6981 | qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry); |
| 6982 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6983 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE || |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6984 | state == DDB_DS_SESSION_FAILED) && |
| 6985 | (is_reset == INIT_ADAPTER)) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6986 | goto continue_next_nt; |
| 6987 | |
| 6988 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6989 | "Adding DDB to session = 0x%x\n", idx)); |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6990 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6991 | if (is_reset == INIT_ADAPTER) { |
| 6992 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 6993 | if (!nt_ddb_idx) |
| 6994 | break; |
| 6995 | |
| 6996 | nt_ddb_idx->fw_ddb_idx = idx; |
| 6997 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6998 | /* Copy original isid as it may get updated in function |
| 6999 | * qla4xxx_update_isid(). We need original isid in |
| 7000 | * function qla4xxx_compare_tuple_ddb to find duplicate |
| 7001 | * target */ |
| 7002 | memcpy(&nt_ddb_idx->flash_isid[0], |
| 7003 | &fw_ddb_entry->isid[0], |
| 7004 | sizeof(nt_ddb_idx->flash_isid)); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7005 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 7006 | ret = qla4xxx_is_flash_ddb_exists(ha, list_nt, |
| 7007 | fw_ddb_entry); |
| 7008 | if (ret == QLA_SUCCESS) { |
| 7009 | /* free nt_ddb_idx and do not add to list_nt */ |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7010 | vfree(nt_ddb_idx); |
| 7011 | goto continue_next_nt; |
| 7012 | } |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 7013 | |
| 7014 | /* Copy updated isid */ |
| 7015 | memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry, |
| 7016 | sizeof(struct dev_db_entry)); |
| 7017 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7018 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 7019 | } else if (is_reset == RESET_ADAPTER) { |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7020 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, |
| 7021 | &ddb_idx); |
| 7022 | if (ret == QLA_SUCCESS) { |
| 7023 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, |
| 7024 | ddb_idx); |
| 7025 | if (ddb_entry != NULL) |
| 7026 | qla4xxx_update_sess_disc_idx(ha, |
| 7027 | ddb_entry, |
| 7028 | fw_ddb_entry); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7029 | goto continue_next_nt; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7030 | } |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7031 | } |
| 7032 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 7033 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7034 | if (ret == QLA_ERROR) |
| 7035 | goto exit_nt_list; |
| 7036 | |
| 7037 | continue_next_nt: |
| 7038 | if (next_idx == 0) |
| 7039 | break; |
| 7040 | } |
| 7041 | |
| 7042 | exit_nt_list: |
| 7043 | if (fw_ddb_entry) |
| 7044 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7045 | } |
| 7046 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7047 | static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7048 | struct list_head *list_nt, |
| 7049 | uint16_t target_id) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7050 | { |
| 7051 | struct dev_db_entry *fw_ddb_entry; |
| 7052 | dma_addr_t fw_ddb_dma; |
| 7053 | int max_ddbs; |
| 7054 | int fw_idx_size; |
| 7055 | int ret; |
| 7056 | uint32_t idx = 0, next_idx = 0; |
| 7057 | uint32_t state = 0, conn_err = 0; |
| 7058 | uint16_t conn_id = 0; |
| 7059 | struct qla_ddb_index *nt_ddb_idx; |
| 7060 | |
| 7061 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 7062 | &fw_ddb_dma); |
| 7063 | if (fw_ddb_entry == NULL) { |
| 7064 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 7065 | goto exit_new_nt_list; |
| 7066 | } |
| 7067 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 7068 | MAX_DEV_DB_ENTRIES; |
| 7069 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 7070 | |
| 7071 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 7072 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 7073 | NULL, &next_idx, &state, |
| 7074 | &conn_err, NULL, &conn_id); |
| 7075 | if (ret == QLA_ERROR) |
| 7076 | break; |
| 7077 | |
| 7078 | /* Check if NT, then add it to list */ |
| 7079 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
| 7080 | goto continue_next_new_nt; |
| 7081 | |
| 7082 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE)) |
| 7083 | goto continue_next_new_nt; |
| 7084 | |
| 7085 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7086 | "Adding DDB to session = 0x%x\n", idx)); |
| 7087 | |
| 7088 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 7089 | if (!nt_ddb_idx) |
| 7090 | break; |
| 7091 | |
| 7092 | nt_ddb_idx->fw_ddb_idx = idx; |
| 7093 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7094 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7095 | if (ret == QLA_SUCCESS) { |
| 7096 | /* free nt_ddb_idx and do not add to list_nt */ |
| 7097 | vfree(nt_ddb_idx); |
| 7098 | goto continue_next_new_nt; |
| 7099 | } |
| 7100 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7101 | if (target_id < max_ddbs) |
| 7102 | fw_ddb_entry->ddb_link = cpu_to_le16(target_id); |
| 7103 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7104 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 7105 | |
| 7106 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 7107 | idx); |
| 7108 | if (ret == QLA_ERROR) |
| 7109 | goto exit_new_nt_list; |
| 7110 | |
| 7111 | continue_next_new_nt: |
| 7112 | if (next_idx == 0) |
| 7113 | break; |
| 7114 | } |
| 7115 | |
| 7116 | exit_new_nt_list: |
| 7117 | if (fw_ddb_entry) |
| 7118 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7119 | } |
| 7120 | |
| 7121 | /** |
| 7122 | * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry |
| 7123 | * @dev: dev associated with the sysfs entry |
| 7124 | * @data: pointer to flashnode session object |
| 7125 | * |
| 7126 | * Returns: |
| 7127 | * 1: if flashnode entry is non-persistent |
| 7128 | * 0: if flashnode entry is persistent |
| 7129 | **/ |
| 7130 | static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data) |
| 7131 | { |
| 7132 | struct iscsi_bus_flash_session *fnode_sess; |
| 7133 | |
| 7134 | if (!iscsi_flashnode_bus_match(dev, NULL)) |
| 7135 | return 0; |
| 7136 | |
| 7137 | fnode_sess = iscsi_dev_to_flash_session(dev); |
| 7138 | |
| 7139 | return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT); |
| 7140 | } |
| 7141 | |
| 7142 | /** |
| 7143 | * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target |
| 7144 | * @ha: pointer to host |
| 7145 | * @fw_ddb_entry: flash ddb data |
| 7146 | * @idx: target index |
| 7147 | * @user: if set then this call is made from userland else from kernel |
| 7148 | * |
| 7149 | * Returns: |
| 7150 | * On sucess: QLA_SUCCESS |
| 7151 | * On failure: QLA_ERROR |
| 7152 | * |
| 7153 | * This create separate sysfs entries for session and connection attributes of |
| 7154 | * the given fw ddb entry. |
| 7155 | * If this is invoked as a result of a userspace call then the entry is marked |
| 7156 | * as nonpersistent using flash_state field. |
| 7157 | **/ |
Vikas Chaudhary | 28e02f1 | 2013-04-17 05:15:27 -0400 | [diff] [blame] | 7158 | static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha, |
| 7159 | struct dev_db_entry *fw_ddb_entry, |
| 7160 | uint16_t *idx, int user) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7161 | { |
| 7162 | struct iscsi_bus_flash_session *fnode_sess = NULL; |
| 7163 | struct iscsi_bus_flash_conn *fnode_conn = NULL; |
| 7164 | int rc = QLA_ERROR; |
| 7165 | |
| 7166 | fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx, |
| 7167 | &qla4xxx_iscsi_transport, 0); |
| 7168 | if (!fnode_sess) { |
| 7169 | ql4_printk(KERN_ERR, ha, |
| 7170 | "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n", |
| 7171 | __func__, *idx, ha->host_no); |
| 7172 | goto exit_tgt_create; |
| 7173 | } |
| 7174 | |
| 7175 | fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess, |
| 7176 | &qla4xxx_iscsi_transport, 0); |
| 7177 | if (!fnode_conn) { |
| 7178 | ql4_printk(KERN_ERR, ha, |
| 7179 | "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n", |
| 7180 | __func__, *idx, ha->host_no); |
| 7181 | goto free_sess; |
| 7182 | } |
| 7183 | |
| 7184 | if (user) { |
| 7185 | fnode_sess->flash_state = DEV_DB_NON_PERSISTENT; |
| 7186 | } else { |
| 7187 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 7188 | |
| 7189 | if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx) |
| 7190 | fnode_sess->is_boot_target = 1; |
| 7191 | else |
| 7192 | fnode_sess->is_boot_target = 0; |
| 7193 | } |
| 7194 | |
| 7195 | rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn, |
| 7196 | fw_ddb_entry); |
| 7197 | |
| 7198 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 7199 | __func__, fnode_sess->dev.kobj.name); |
| 7200 | |
| 7201 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 7202 | __func__, fnode_conn->dev.kobj.name); |
| 7203 | |
| 7204 | return QLA_SUCCESS; |
| 7205 | |
| 7206 | free_sess: |
| 7207 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 7208 | |
| 7209 | exit_tgt_create: |
| 7210 | return QLA_ERROR; |
| 7211 | } |
| 7212 | |
| 7213 | /** |
| 7214 | * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash |
| 7215 | * @shost: pointer to host |
| 7216 | * @buf: type of ddb entry (ipv4/ipv6) |
| 7217 | * @len: length of buf |
| 7218 | * |
| 7219 | * This creates new ddb entry in the flash by finding first free index and |
| 7220 | * storing default ddb there. And then create sysfs entry for the new ddb entry. |
| 7221 | **/ |
| 7222 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 7223 | int len) |
| 7224 | { |
| 7225 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7226 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7227 | dma_addr_t fw_ddb_entry_dma; |
| 7228 | struct device *dev; |
| 7229 | uint16_t idx = 0; |
| 7230 | uint16_t max_ddbs = 0; |
| 7231 | uint32_t options = 0; |
| 7232 | uint32_t rval = QLA_ERROR; |
| 7233 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7234 | if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) && |
| 7235 | strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) { |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7236 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n", |
| 7237 | __func__)); |
| 7238 | goto exit_ddb_add; |
| 7239 | } |
| 7240 | |
Adheer Chandravanshi | a957a7d | 2013-04-05 07:06:08 -0400 | [diff] [blame] | 7241 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7242 | MAX_DEV_DB_ENTRIES; |
| 7243 | |
| 7244 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7245 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7246 | if (!fw_ddb_entry) { |
| 7247 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7248 | "%s: Unable to allocate dma buffer\n", |
| 7249 | __func__)); |
| 7250 | goto exit_ddb_add; |
| 7251 | } |
| 7252 | |
| 7253 | dev = iscsi_find_flashnode_sess(ha->host, NULL, |
| 7254 | qla4xxx_sysfs_ddb_is_non_persistent); |
| 7255 | if (dev) { |
| 7256 | ql4_printk(KERN_ERR, ha, |
| 7257 | "%s: A non-persistent entry %s found\n", |
| 7258 | __func__, dev->kobj.name); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7259 | put_device(dev); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7260 | goto exit_ddb_add; |
| 7261 | } |
| 7262 | |
Adheer Chandravanshi | 9993757 | 2013-07-08 08:33:09 -0400 | [diff] [blame] | 7263 | /* Index 0 and 1 are reserved for boot target entries */ |
| 7264 | for (idx = 2; idx < max_ddbs; idx++) { |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7265 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, |
| 7266 | fw_ddb_entry_dma, idx)) |
| 7267 | break; |
| 7268 | } |
| 7269 | |
| 7270 | if (idx == max_ddbs) |
| 7271 | goto exit_ddb_add; |
| 7272 | |
| 7273 | if (!strncasecmp("ipv6", buf, 4)) |
| 7274 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7275 | |
| 7276 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7277 | if (rval == QLA_ERROR) |
| 7278 | goto exit_ddb_add; |
| 7279 | |
| 7280 | rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1); |
| 7281 | |
| 7282 | exit_ddb_add: |
| 7283 | if (fw_ddb_entry) |
| 7284 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7285 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7286 | if (rval == QLA_SUCCESS) |
| 7287 | return idx; |
| 7288 | else |
| 7289 | return -EIO; |
| 7290 | } |
| 7291 | |
| 7292 | /** |
| 7293 | * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash |
| 7294 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7295 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7296 | * |
| 7297 | * This writes the contents of target ddb buffer to Flash with a valid cookie |
| 7298 | * value in order to make the ddb entry persistent. |
| 7299 | **/ |
| 7300 | static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess, |
| 7301 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7302 | { |
| 7303 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7304 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7305 | uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
| 7306 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7307 | dma_addr_t fw_ddb_entry_dma; |
| 7308 | uint32_t options = 0; |
| 7309 | int rval = 0; |
| 7310 | |
| 7311 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7312 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7313 | if (!fw_ddb_entry) { |
| 7314 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7315 | "%s: Unable to allocate dma buffer\n", |
| 7316 | __func__)); |
| 7317 | rval = -ENOMEM; |
| 7318 | goto exit_ddb_apply; |
| 7319 | } |
| 7320 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7321 | if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7322 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7323 | |
| 7324 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7325 | if (rval == QLA_ERROR) |
| 7326 | goto exit_ddb_apply; |
| 7327 | |
| 7328 | dev_db_start_offset += (fnode_sess->target_id * |
| 7329 | sizeof(*fw_ddb_entry)); |
| 7330 | |
| 7331 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 7332 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 7333 | |
| 7334 | rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
| 7335 | sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT); |
| 7336 | |
| 7337 | if (rval == QLA_SUCCESS) { |
| 7338 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 7339 | ql4_printk(KERN_INFO, ha, |
| 7340 | "%s: flash node %u of host %lu written to flash\n", |
| 7341 | __func__, fnode_sess->target_id, ha->host_no); |
| 7342 | } else { |
| 7343 | rval = -EIO; |
| 7344 | ql4_printk(KERN_ERR, ha, |
| 7345 | "%s: Error while writing flash node %u of host %lu to flash\n", |
| 7346 | __func__, fnode_sess->target_id, ha->host_no); |
| 7347 | } |
| 7348 | |
| 7349 | exit_ddb_apply: |
| 7350 | if (fw_ddb_entry) |
| 7351 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7352 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7353 | return rval; |
| 7354 | } |
| 7355 | |
| 7356 | static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha, |
| 7357 | struct dev_db_entry *fw_ddb_entry, |
| 7358 | uint16_t idx) |
| 7359 | { |
| 7360 | struct dev_db_entry *ddb_entry = NULL; |
| 7361 | dma_addr_t ddb_entry_dma; |
| 7362 | unsigned long wtime; |
| 7363 | uint32_t mbx_sts = 0; |
| 7364 | uint32_t state = 0, conn_err = 0; |
| 7365 | uint16_t tmo = 0; |
| 7366 | int ret = 0; |
| 7367 | |
| 7368 | ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 7369 | &ddb_entry_dma, GFP_KERNEL); |
| 7370 | if (!ddb_entry) { |
| 7371 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7372 | "%s: Unable to allocate dma buffer\n", |
| 7373 | __func__)); |
| 7374 | return QLA_ERROR; |
| 7375 | } |
| 7376 | |
| 7377 | memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry)); |
| 7378 | |
| 7379 | ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts); |
| 7380 | if (ret != QLA_SUCCESS) { |
| 7381 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7382 | "%s: Unable to set ddb entry for index %d\n", |
| 7383 | __func__, idx)); |
| 7384 | goto exit_ddb_conn_open; |
| 7385 | } |
| 7386 | |
| 7387 | qla4xxx_conn_open(ha, idx); |
| 7388 | |
| 7389 | /* To ensure that sendtargets is done, wait for at least 12 secs */ |
| 7390 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 7391 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 7392 | ha->def_timeout : LOGIN_TOV); |
| 7393 | |
| 7394 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7395 | "Default time to wait for login to ddb %d\n", tmo)); |
| 7396 | |
| 7397 | wtime = jiffies + (HZ * tmo); |
| 7398 | do { |
| 7399 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, |
| 7400 | NULL, &state, &conn_err, NULL, |
| 7401 | NULL); |
| 7402 | if (ret == QLA_ERROR) |
| 7403 | continue; |
| 7404 | |
| 7405 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 7406 | state == DDB_DS_SESSION_FAILED) |
| 7407 | break; |
| 7408 | |
| 7409 | schedule_timeout_uninterruptible(HZ / 10); |
| 7410 | } while (time_after(wtime, jiffies)); |
| 7411 | |
| 7412 | exit_ddb_conn_open: |
| 7413 | if (ddb_entry) |
| 7414 | dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 7415 | ddb_entry, ddb_entry_dma); |
| 7416 | return ret; |
| 7417 | } |
| 7418 | |
| 7419 | static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7420 | struct dev_db_entry *fw_ddb_entry, |
| 7421 | uint16_t target_id) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7422 | { |
| 7423 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 7424 | struct list_head list_nt; |
| 7425 | uint16_t ddb_index; |
| 7426 | int ret = 0; |
| 7427 | |
| 7428 | if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) { |
| 7429 | ql4_printk(KERN_WARNING, ha, |
| 7430 | "%s: A discovery already in progress!\n", __func__); |
| 7431 | return QLA_ERROR; |
| 7432 | } |
| 7433 | |
| 7434 | INIT_LIST_HEAD(&list_nt); |
| 7435 | |
| 7436 | set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 7437 | |
| 7438 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 7439 | if (ret == QLA_ERROR) |
| 7440 | goto exit_login_st_clr_bit; |
| 7441 | |
| 7442 | ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index); |
| 7443 | if (ret == QLA_ERROR) |
| 7444 | goto exit_login_st; |
| 7445 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7446 | qla4xxx_build_new_nt_list(ha, &list_nt, target_id); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7447 | |
| 7448 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) { |
| 7449 | list_del_init(&ddb_idx->list); |
| 7450 | qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx); |
| 7451 | vfree(ddb_idx); |
| 7452 | } |
| 7453 | |
| 7454 | exit_login_st: |
| 7455 | if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) { |
| 7456 | ql4_printk(KERN_ERR, ha, |
| 7457 | "Unable to clear DDB index = 0x%x\n", ddb_index); |
| 7458 | } |
| 7459 | |
| 7460 | clear_bit(ddb_index, ha->ddb_idx_map); |
| 7461 | |
| 7462 | exit_login_st_clr_bit: |
| 7463 | clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 7464 | return ret; |
| 7465 | } |
| 7466 | |
| 7467 | static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha, |
| 7468 | struct dev_db_entry *fw_ddb_entry, |
| 7469 | uint16_t idx) |
| 7470 | { |
| 7471 | int ret = QLA_ERROR; |
| 7472 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7473 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7474 | if (ret != QLA_SUCCESS) |
| 7475 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 7476 | idx); |
| 7477 | else |
| 7478 | ret = -EPERM; |
| 7479 | |
| 7480 | return ret; |
| 7481 | } |
| 7482 | |
| 7483 | /** |
| 7484 | * qla4xxx_sysfs_ddb_login - Login to the specified target |
| 7485 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7486 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7487 | * |
| 7488 | * This logs in to the specified target |
| 7489 | **/ |
| 7490 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 7491 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7492 | { |
| 7493 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7494 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7495 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7496 | dma_addr_t fw_ddb_entry_dma; |
| 7497 | uint32_t options = 0; |
| 7498 | int ret = 0; |
| 7499 | |
| 7500 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) { |
| 7501 | ql4_printk(KERN_ERR, ha, |
| 7502 | "%s: Target info is not persistent\n", __func__); |
| 7503 | ret = -EIO; |
| 7504 | goto exit_ddb_login; |
| 7505 | } |
| 7506 | |
| 7507 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7508 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7509 | if (!fw_ddb_entry) { |
| 7510 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7511 | "%s: Unable to allocate dma buffer\n", |
| 7512 | __func__)); |
| 7513 | ret = -ENOMEM; |
| 7514 | goto exit_ddb_login; |
| 7515 | } |
| 7516 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7517 | if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7518 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7519 | |
| 7520 | ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7521 | if (ret == QLA_ERROR) |
| 7522 | goto exit_ddb_login; |
| 7523 | |
| 7524 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 7525 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 7526 | |
| 7527 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7528 | ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry, |
| 7529 | fnode_sess->target_id); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7530 | else |
| 7531 | ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry, |
| 7532 | fnode_sess->target_id); |
| 7533 | |
| 7534 | if (ret > 0) |
| 7535 | ret = -EIO; |
| 7536 | |
| 7537 | exit_ddb_login: |
| 7538 | if (fw_ddb_entry) |
| 7539 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7540 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7541 | return ret; |
| 7542 | } |
| 7543 | |
| 7544 | /** |
| 7545 | * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target |
| 7546 | * @cls_sess: pointer to session to be logged out |
| 7547 | * |
| 7548 | * This performs session log out from the specified target |
| 7549 | **/ |
| 7550 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess) |
| 7551 | { |
| 7552 | struct iscsi_session *sess; |
| 7553 | struct ddb_entry *ddb_entry = NULL; |
| 7554 | struct scsi_qla_host *ha; |
| 7555 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7556 | dma_addr_t fw_ddb_entry_dma; |
| 7557 | unsigned long flags; |
| 7558 | unsigned long wtime; |
| 7559 | uint32_t ddb_state; |
| 7560 | int options; |
| 7561 | int ret = 0; |
| 7562 | |
| 7563 | sess = cls_sess->dd_data; |
| 7564 | ddb_entry = sess->dd_data; |
| 7565 | ha = ddb_entry->ha; |
| 7566 | |
| 7567 | if (ddb_entry->ddb_type != FLASH_DDB) { |
| 7568 | ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n", |
| 7569 | __func__); |
| 7570 | ret = -ENXIO; |
| 7571 | goto exit_ddb_logout; |
| 7572 | } |
| 7573 | |
Adheer Chandravanshi | 37719c2 | 2013-04-05 07:06:07 -0400 | [diff] [blame] | 7574 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 7575 | ql4_printk(KERN_ERR, ha, |
| 7576 | "%s: Logout from boot target entry is not permitted.\n", |
| 7577 | __func__); |
| 7578 | ret = -EPERM; |
| 7579 | goto exit_ddb_logout; |
| 7580 | } |
| 7581 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7582 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7583 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7584 | if (!fw_ddb_entry) { |
| 7585 | ql4_printk(KERN_ERR, ha, |
| 7586 | "%s: Unable to allocate dma buffer\n", __func__); |
| 7587 | ret = -ENOMEM; |
| 7588 | goto exit_ddb_logout; |
| 7589 | } |
| 7590 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7591 | if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) |
| 7592 | goto ddb_logout_init; |
| 7593 | |
| 7594 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 7595 | fw_ddb_entry, fw_ddb_entry_dma, |
| 7596 | NULL, NULL, &ddb_state, NULL, |
| 7597 | NULL, NULL); |
| 7598 | if (ret == QLA_ERROR) |
| 7599 | goto ddb_logout_init; |
| 7600 | |
| 7601 | if (ddb_state == DDB_DS_SESSION_ACTIVE) |
| 7602 | goto ddb_logout_init; |
| 7603 | |
| 7604 | /* wait until next relogin is triggered using DF_RELOGIN and |
| 7605 | * clear DF_RELOGIN to avoid invocation of further relogin |
| 7606 | */ |
| 7607 | wtime = jiffies + (HZ * RELOGIN_TOV); |
| 7608 | do { |
| 7609 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 7610 | goto ddb_logout_init; |
| 7611 | |
| 7612 | schedule_timeout_uninterruptible(HZ); |
| 7613 | } while ((time_after(wtime, jiffies))); |
| 7614 | |
| 7615 | ddb_logout_init: |
| 7616 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 7617 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 7618 | |
| 7619 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 7620 | qla4xxx_session_logout_ddb(ha, ddb_entry, options); |
| 7621 | |
| 7622 | memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry)); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7623 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 7624 | do { |
| 7625 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 7626 | fw_ddb_entry, fw_ddb_entry_dma, |
| 7627 | NULL, NULL, &ddb_state, NULL, |
| 7628 | NULL, NULL); |
| 7629 | if (ret == QLA_ERROR) |
| 7630 | goto ddb_logout_clr_sess; |
| 7631 | |
| 7632 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 7633 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 7634 | goto ddb_logout_clr_sess; |
| 7635 | |
| 7636 | schedule_timeout_uninterruptible(HZ); |
| 7637 | } while ((time_after(wtime, jiffies))); |
| 7638 | |
| 7639 | ddb_logout_clr_sess: |
| 7640 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 7641 | /* |
| 7642 | * we have decremented the reference count of the driver |
| 7643 | * when we setup the session to have the driver unload |
| 7644 | * to be seamless without actually destroying the |
| 7645 | * session |
| 7646 | **/ |
| 7647 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 7648 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 7649 | |
| 7650 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 7651 | qla4xxx_free_ddb(ha, ddb_entry); |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7652 | clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7653 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 7654 | |
| 7655 | iscsi_session_teardown(ddb_entry->sess); |
| 7656 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7657 | clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7658 | ret = QLA_SUCCESS; |
| 7659 | |
| 7660 | exit_ddb_logout: |
| 7661 | if (fw_ddb_entry) |
| 7662 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7663 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7664 | return ret; |
| 7665 | } |
| 7666 | |
| 7667 | /** |
| 7668 | * qla4xxx_sysfs_ddb_logout - Logout from the specified target |
| 7669 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7670 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7671 | * |
| 7672 | * This performs log out from the specified target |
| 7673 | **/ |
| 7674 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 7675 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7676 | { |
| 7677 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7678 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7679 | struct ql4_tuple_ddb *flash_tddb = NULL; |
| 7680 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 7681 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7682 | struct ddb_entry *ddb_entry = NULL; |
| 7683 | dma_addr_t fw_ddb_dma; |
| 7684 | uint32_t next_idx = 0; |
| 7685 | uint32_t state = 0, conn_err = 0; |
| 7686 | uint16_t conn_id = 0; |
| 7687 | int idx, index; |
| 7688 | int status, ret = 0; |
| 7689 | |
| 7690 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 7691 | &fw_ddb_dma); |
| 7692 | if (fw_ddb_entry == NULL) { |
| 7693 | ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__); |
| 7694 | ret = -ENOMEM; |
| 7695 | goto exit_ddb_logout; |
| 7696 | } |
| 7697 | |
| 7698 | flash_tddb = vzalloc(sizeof(*flash_tddb)); |
| 7699 | if (!flash_tddb) { |
| 7700 | ql4_printk(KERN_WARNING, ha, |
| 7701 | "%s:Memory Allocation failed.\n", __func__); |
| 7702 | ret = -ENOMEM; |
| 7703 | goto exit_ddb_logout; |
| 7704 | } |
| 7705 | |
| 7706 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 7707 | if (!tmp_tddb) { |
| 7708 | ql4_printk(KERN_WARNING, ha, |
| 7709 | "%s:Memory Allocation failed.\n", __func__); |
| 7710 | ret = -ENOMEM; |
| 7711 | goto exit_ddb_logout; |
| 7712 | } |
| 7713 | |
| 7714 | if (!fnode_sess->targetname) { |
| 7715 | ql4_printk(KERN_ERR, ha, |
| 7716 | "%s:Cannot logout from SendTarget entry\n", |
| 7717 | __func__); |
| 7718 | ret = -EPERM; |
| 7719 | goto exit_ddb_logout; |
| 7720 | } |
| 7721 | |
| 7722 | if (fnode_sess->is_boot_target) { |
| 7723 | ql4_printk(KERN_ERR, ha, |
| 7724 | "%s: Logout from boot target entry is not permitted.\n", |
| 7725 | __func__); |
| 7726 | ret = -EPERM; |
| 7727 | goto exit_ddb_logout; |
| 7728 | } |
| 7729 | |
| 7730 | strncpy(flash_tddb->iscsi_name, fnode_sess->targetname, |
| 7731 | ISCSI_NAME_SIZE); |
| 7732 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7733 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7734 | sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress); |
| 7735 | else |
| 7736 | sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress); |
| 7737 | |
| 7738 | flash_tddb->tpgt = fnode_sess->tpgt; |
| 7739 | flash_tddb->port = fnode_conn->port; |
| 7740 | |
| 7741 | COPY_ISID(flash_tddb->isid, fnode_sess->isid); |
| 7742 | |
| 7743 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 7744 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 7745 | if (ddb_entry == NULL) |
| 7746 | continue; |
| 7747 | |
| 7748 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 7749 | continue; |
| 7750 | |
| 7751 | index = ddb_entry->sess->target_id; |
| 7752 | status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry, |
| 7753 | fw_ddb_dma, NULL, &next_idx, |
| 7754 | &state, &conn_err, NULL, |
| 7755 | &conn_id); |
| 7756 | if (status == QLA_ERROR) { |
| 7757 | ret = -ENOMEM; |
| 7758 | break; |
| 7759 | } |
| 7760 | |
| 7761 | qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL); |
| 7762 | |
| 7763 | status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb, |
| 7764 | true); |
| 7765 | if (status == QLA_SUCCESS) { |
| 7766 | ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess); |
| 7767 | break; |
| 7768 | } |
| 7769 | } |
| 7770 | |
| 7771 | if (idx == MAX_DDB_ENTRIES) |
| 7772 | ret = -ESRCH; |
| 7773 | |
| 7774 | exit_ddb_logout: |
| 7775 | if (flash_tddb) |
| 7776 | vfree(flash_tddb); |
| 7777 | if (tmp_tddb) |
| 7778 | vfree(tmp_tddb); |
| 7779 | if (fw_ddb_entry) |
| 7780 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7781 | |
| 7782 | return ret; |
| 7783 | } |
| 7784 | |
| 7785 | static int |
| 7786 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 7787 | int param, char *buf) |
| 7788 | { |
| 7789 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7790 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7791 | struct iscsi_bus_flash_conn *fnode_conn; |
| 7792 | struct ql4_chap_table chap_tbl; |
| 7793 | struct device *dev; |
Adheer Chandravanshi | a2f7663 | 2013-07-08 08:33:08 -0400 | [diff] [blame] | 7794 | int parent_type; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7795 | int rc = 0; |
| 7796 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7797 | dev = iscsi_find_flashnode_conn(fnode_sess); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7798 | if (!dev) |
| 7799 | return -EIO; |
| 7800 | |
| 7801 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 7802 | |
| 7803 | switch (param) { |
| 7804 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 7805 | rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6); |
| 7806 | break; |
| 7807 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 7808 | rc = sprintf(buf, "%s\n", fnode_sess->portal_type); |
| 7809 | break; |
| 7810 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 7811 | rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable); |
| 7812 | break; |
| 7813 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 7814 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess); |
| 7815 | break; |
| 7816 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 7817 | rc = sprintf(buf, "%u\n", fnode_sess->entry_state); |
| 7818 | break; |
| 7819 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 7820 | rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en); |
| 7821 | break; |
| 7822 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 7823 | rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en); |
| 7824 | break; |
| 7825 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 7826 | rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en); |
| 7827 | break; |
| 7828 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 7829 | rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en); |
| 7830 | break; |
| 7831 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 7832 | rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en); |
| 7833 | break; |
| 7834 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 7835 | rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en); |
| 7836 | break; |
| 7837 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 7838 | rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en); |
| 7839 | break; |
| 7840 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 7841 | rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en); |
| 7842 | break; |
| 7843 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 7844 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en); |
| 7845 | break; |
| 7846 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 7847 | rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en); |
| 7848 | break; |
| 7849 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 7850 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional); |
| 7851 | break; |
| 7852 | case ISCSI_FLASHNODE_ERL: |
| 7853 | rc = sprintf(buf, "%u\n", fnode_sess->erl); |
| 7854 | break; |
| 7855 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 7856 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat); |
| 7857 | break; |
| 7858 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 7859 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable); |
| 7860 | break; |
| 7861 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 7862 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable); |
| 7863 | break; |
| 7864 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 7865 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale); |
| 7866 | break; |
| 7867 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 7868 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en); |
| 7869 | break; |
| 7870 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 7871 | rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable); |
| 7872 | break; |
| 7873 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 7874 | rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength); |
| 7875 | break; |
| 7876 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 7877 | rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength); |
| 7878 | break; |
| 7879 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 7880 | rc = sprintf(buf, "%u\n", fnode_sess->first_burst); |
| 7881 | break; |
| 7882 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 7883 | rc = sprintf(buf, "%u\n", fnode_sess->time2wait); |
| 7884 | break; |
| 7885 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 7886 | rc = sprintf(buf, "%u\n", fnode_sess->time2retain); |
| 7887 | break; |
| 7888 | case ISCSI_FLASHNODE_MAX_R2T: |
| 7889 | rc = sprintf(buf, "%u\n", fnode_sess->max_r2t); |
| 7890 | break; |
| 7891 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 7892 | rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout); |
| 7893 | break; |
| 7894 | case ISCSI_FLASHNODE_ISID: |
| 7895 | rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n", |
| 7896 | fnode_sess->isid[0], fnode_sess->isid[1], |
| 7897 | fnode_sess->isid[2], fnode_sess->isid[3], |
| 7898 | fnode_sess->isid[4], fnode_sess->isid[5]); |
| 7899 | break; |
| 7900 | case ISCSI_FLASHNODE_TSID: |
| 7901 | rc = sprintf(buf, "%u\n", fnode_sess->tsid); |
| 7902 | break; |
| 7903 | case ISCSI_FLASHNODE_PORT: |
| 7904 | rc = sprintf(buf, "%d\n", fnode_conn->port); |
| 7905 | break; |
| 7906 | case ISCSI_FLASHNODE_MAX_BURST: |
| 7907 | rc = sprintf(buf, "%u\n", fnode_sess->max_burst); |
| 7908 | break; |
| 7909 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 7910 | rc = sprintf(buf, "%u\n", |
| 7911 | fnode_sess->default_taskmgmt_timeout); |
| 7912 | break; |
| 7913 | case ISCSI_FLASHNODE_IPADDR: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7914 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7915 | rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress); |
| 7916 | else |
| 7917 | rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress); |
| 7918 | break; |
| 7919 | case ISCSI_FLASHNODE_ALIAS: |
| 7920 | if (fnode_sess->targetalias) |
| 7921 | rc = sprintf(buf, "%s\n", fnode_sess->targetalias); |
| 7922 | else |
| 7923 | rc = sprintf(buf, "\n"); |
| 7924 | break; |
| 7925 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7926 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7927 | rc = sprintf(buf, "%pI6\n", |
| 7928 | fnode_conn->redirect_ipaddr); |
| 7929 | else |
| 7930 | rc = sprintf(buf, "%pI4\n", |
| 7931 | fnode_conn->redirect_ipaddr); |
| 7932 | break; |
| 7933 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 7934 | rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size); |
| 7935 | break; |
| 7936 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 7937 | rc = sprintf(buf, "%u\n", fnode_conn->local_port); |
| 7938 | break; |
| 7939 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 7940 | rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos); |
| 7941 | break; |
| 7942 | case ISCSI_FLASHNODE_IPV6_TC: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7943 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7944 | rc = sprintf(buf, "%u\n", |
| 7945 | fnode_conn->ipv6_traffic_class); |
| 7946 | else |
| 7947 | rc = sprintf(buf, "\n"); |
| 7948 | break; |
| 7949 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 7950 | rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label); |
| 7951 | break; |
| 7952 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7953 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7954 | rc = sprintf(buf, "%pI6\n", |
| 7955 | fnode_conn->link_local_ipv6_addr); |
| 7956 | else |
| 7957 | rc = sprintf(buf, "\n"); |
| 7958 | break; |
| 7959 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
Adheer Chandravanshi | a2f7663 | 2013-07-08 08:33:08 -0400 | [diff] [blame] | 7960 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7961 | break; |
| 7962 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 7963 | if (fnode_sess->discovery_parent_type == DDB_ISNS) |
| 7964 | parent_type = ISCSI_DISC_PARENT_ISNS; |
| 7965 | else if (fnode_sess->discovery_parent_type == DDB_NO_LINK) |
| 7966 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
Vikas Chaudhary | b6130ce | 2013-04-17 05:15:26 -0400 | [diff] [blame] | 7967 | else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7968 | parent_type = ISCSI_DISC_PARENT_SENDTGT; |
| 7969 | else |
| 7970 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
| 7971 | |
| 7972 | rc = sprintf(buf, "%s\n", |
| 7973 | iscsi_get_discovery_parent_name(parent_type)); |
| 7974 | break; |
| 7975 | case ISCSI_FLASHNODE_NAME: |
| 7976 | if (fnode_sess->targetname) |
| 7977 | rc = sprintf(buf, "%s\n", fnode_sess->targetname); |
| 7978 | else |
| 7979 | rc = sprintf(buf, "\n"); |
| 7980 | break; |
| 7981 | case ISCSI_FLASHNODE_TPGT: |
| 7982 | rc = sprintf(buf, "%u\n", fnode_sess->tpgt); |
| 7983 | break; |
| 7984 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 7985 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf); |
| 7986 | break; |
| 7987 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 7988 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf); |
| 7989 | break; |
| 7990 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 7991 | rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx); |
| 7992 | break; |
| 7993 | case ISCSI_FLASHNODE_USERNAME: |
| 7994 | if (fnode_sess->chap_auth_en) { |
| 7995 | qla4xxx_get_uni_chap_at_index(ha, |
| 7996 | chap_tbl.name, |
| 7997 | chap_tbl.secret, |
| 7998 | fnode_sess->chap_out_idx); |
| 7999 | rc = sprintf(buf, "%s\n", chap_tbl.name); |
| 8000 | } else { |
| 8001 | rc = sprintf(buf, "\n"); |
| 8002 | } |
| 8003 | break; |
| 8004 | case ISCSI_FLASHNODE_PASSWORD: |
| 8005 | if (fnode_sess->chap_auth_en) { |
| 8006 | qla4xxx_get_uni_chap_at_index(ha, |
| 8007 | chap_tbl.name, |
| 8008 | chap_tbl.secret, |
| 8009 | fnode_sess->chap_out_idx); |
| 8010 | rc = sprintf(buf, "%s\n", chap_tbl.secret); |
| 8011 | } else { |
| 8012 | rc = sprintf(buf, "\n"); |
| 8013 | } |
| 8014 | break; |
| 8015 | case ISCSI_FLASHNODE_STATSN: |
| 8016 | rc = sprintf(buf, "%u\n", fnode_conn->statsn); |
| 8017 | break; |
| 8018 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 8019 | rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn); |
| 8020 | break; |
| 8021 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 8022 | rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target); |
| 8023 | break; |
| 8024 | default: |
| 8025 | rc = -ENOSYS; |
| 8026 | break; |
| 8027 | } |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 8028 | |
| 8029 | put_device(dev); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8030 | return rc; |
| 8031 | } |
| 8032 | |
| 8033 | /** |
| 8034 | * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry |
| 8035 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 8036 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 8037 | * @data: Parameters and their values to update |
| 8038 | * @len: len of data |
| 8039 | * |
| 8040 | * This sets the parameter of flash ddb entry and writes them to flash |
| 8041 | **/ |
| 8042 | static int |
| 8043 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 8044 | struct iscsi_bus_flash_conn *fnode_conn, |
| 8045 | void *data, int len) |
| 8046 | { |
| 8047 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 8048 | struct scsi_qla_host *ha = to_qla_host(shost); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8049 | struct iscsi_flashnode_param_info *fnode_param; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8050 | struct ql4_chap_table chap_tbl; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8051 | struct nlattr *attr; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8052 | uint16_t chap_out_idx = INVALID_ENTRY; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8053 | int rc = QLA_ERROR; |
| 8054 | uint32_t rem = len; |
| 8055 | |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8056 | memset((void *)&chap_tbl, 0, sizeof(chap_tbl)); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8057 | nla_for_each_attr(attr, data, len, rem) { |
| 8058 | fnode_param = nla_data(attr); |
| 8059 | |
| 8060 | switch (fnode_param->param) { |
| 8061 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 8062 | fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0]; |
| 8063 | break; |
| 8064 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 8065 | memcpy(fnode_sess->portal_type, fnode_param->value, |
| 8066 | strlen(fnode_sess->portal_type)); |
| 8067 | break; |
| 8068 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 8069 | fnode_sess->auto_snd_tgt_disable = |
| 8070 | fnode_param->value[0]; |
| 8071 | break; |
| 8072 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 8073 | fnode_sess->discovery_sess = fnode_param->value[0]; |
| 8074 | break; |
| 8075 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 8076 | fnode_sess->entry_state = fnode_param->value[0]; |
| 8077 | break; |
| 8078 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 8079 | fnode_conn->hdrdgst_en = fnode_param->value[0]; |
| 8080 | break; |
| 8081 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 8082 | fnode_conn->datadgst_en = fnode_param->value[0]; |
| 8083 | break; |
| 8084 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 8085 | fnode_sess->imm_data_en = fnode_param->value[0]; |
| 8086 | break; |
| 8087 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 8088 | fnode_sess->initial_r2t_en = fnode_param->value[0]; |
| 8089 | break; |
| 8090 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 8091 | fnode_sess->dataseq_inorder_en = fnode_param->value[0]; |
| 8092 | break; |
| 8093 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 8094 | fnode_sess->pdu_inorder_en = fnode_param->value[0]; |
| 8095 | break; |
| 8096 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 8097 | fnode_sess->chap_auth_en = fnode_param->value[0]; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8098 | /* Invalidate chap index if chap auth is disabled */ |
| 8099 | if (!fnode_sess->chap_auth_en) |
| 8100 | fnode_sess->chap_out_idx = INVALID_ENTRY; |
| 8101 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8102 | break; |
| 8103 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 8104 | fnode_conn->snack_req_en = fnode_param->value[0]; |
| 8105 | break; |
| 8106 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 8107 | fnode_sess->discovery_logout_en = fnode_param->value[0]; |
| 8108 | break; |
| 8109 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 8110 | fnode_sess->bidi_chap_en = fnode_param->value[0]; |
| 8111 | break; |
| 8112 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 8113 | fnode_sess->discovery_auth_optional = |
| 8114 | fnode_param->value[0]; |
| 8115 | break; |
| 8116 | case ISCSI_FLASHNODE_ERL: |
| 8117 | fnode_sess->erl = fnode_param->value[0]; |
| 8118 | break; |
| 8119 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 8120 | fnode_conn->tcp_timestamp_stat = fnode_param->value[0]; |
| 8121 | break; |
| 8122 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 8123 | fnode_conn->tcp_nagle_disable = fnode_param->value[0]; |
| 8124 | break; |
| 8125 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 8126 | fnode_conn->tcp_wsf_disable = fnode_param->value[0]; |
| 8127 | break; |
| 8128 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 8129 | fnode_conn->tcp_timer_scale = fnode_param->value[0]; |
| 8130 | break; |
| 8131 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 8132 | fnode_conn->tcp_timestamp_en = fnode_param->value[0]; |
| 8133 | break; |
| 8134 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 8135 | fnode_conn->fragment_disable = fnode_param->value[0]; |
| 8136 | break; |
| 8137 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 8138 | fnode_conn->max_recv_dlength = |
| 8139 | *(unsigned *)fnode_param->value; |
| 8140 | break; |
| 8141 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 8142 | fnode_conn->max_xmit_dlength = |
| 8143 | *(unsigned *)fnode_param->value; |
| 8144 | break; |
| 8145 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 8146 | fnode_sess->first_burst = |
| 8147 | *(unsigned *)fnode_param->value; |
| 8148 | break; |
| 8149 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 8150 | fnode_sess->time2wait = *(uint16_t *)fnode_param->value; |
| 8151 | break; |
| 8152 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 8153 | fnode_sess->time2retain = |
| 8154 | *(uint16_t *)fnode_param->value; |
| 8155 | break; |
| 8156 | case ISCSI_FLASHNODE_MAX_R2T: |
| 8157 | fnode_sess->max_r2t = |
| 8158 | *(uint16_t *)fnode_param->value; |
| 8159 | break; |
| 8160 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 8161 | fnode_conn->keepalive_timeout = |
| 8162 | *(uint16_t *)fnode_param->value; |
| 8163 | break; |
| 8164 | case ISCSI_FLASHNODE_ISID: |
| 8165 | memcpy(fnode_sess->isid, fnode_param->value, |
| 8166 | sizeof(fnode_sess->isid)); |
| 8167 | break; |
| 8168 | case ISCSI_FLASHNODE_TSID: |
| 8169 | fnode_sess->tsid = *(uint16_t *)fnode_param->value; |
| 8170 | break; |
| 8171 | case ISCSI_FLASHNODE_PORT: |
| 8172 | fnode_conn->port = *(uint16_t *)fnode_param->value; |
| 8173 | break; |
| 8174 | case ISCSI_FLASHNODE_MAX_BURST: |
| 8175 | fnode_sess->max_burst = *(unsigned *)fnode_param->value; |
| 8176 | break; |
| 8177 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 8178 | fnode_sess->default_taskmgmt_timeout = |
| 8179 | *(uint16_t *)fnode_param->value; |
| 8180 | break; |
| 8181 | case ISCSI_FLASHNODE_IPADDR: |
| 8182 | memcpy(fnode_conn->ipaddress, fnode_param->value, |
| 8183 | IPv6_ADDR_LEN); |
| 8184 | break; |
| 8185 | case ISCSI_FLASHNODE_ALIAS: |
| 8186 | rc = iscsi_switch_str_param(&fnode_sess->targetalias, |
| 8187 | (char *)fnode_param->value); |
| 8188 | break; |
| 8189 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 8190 | memcpy(fnode_conn->redirect_ipaddr, fnode_param->value, |
| 8191 | IPv6_ADDR_LEN); |
| 8192 | break; |
| 8193 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 8194 | fnode_conn->max_segment_size = |
| 8195 | *(unsigned *)fnode_param->value; |
| 8196 | break; |
| 8197 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 8198 | fnode_conn->local_port = |
| 8199 | *(uint16_t *)fnode_param->value; |
| 8200 | break; |
| 8201 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 8202 | fnode_conn->ipv4_tos = fnode_param->value[0]; |
| 8203 | break; |
| 8204 | case ISCSI_FLASHNODE_IPV6_TC: |
| 8205 | fnode_conn->ipv6_traffic_class = fnode_param->value[0]; |
| 8206 | break; |
| 8207 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 8208 | fnode_conn->ipv6_flow_label = fnode_param->value[0]; |
| 8209 | break; |
| 8210 | case ISCSI_FLASHNODE_NAME: |
| 8211 | rc = iscsi_switch_str_param(&fnode_sess->targetname, |
| 8212 | (char *)fnode_param->value); |
| 8213 | break; |
| 8214 | case ISCSI_FLASHNODE_TPGT: |
| 8215 | fnode_sess->tpgt = *(uint16_t *)fnode_param->value; |
| 8216 | break; |
| 8217 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 8218 | memcpy(fnode_conn->link_local_ipv6_addr, |
| 8219 | fnode_param->value, IPv6_ADDR_LEN); |
| 8220 | break; |
Adheer Chandravanshi | 6556016 | 2013-07-08 08:33:06 -0400 | [diff] [blame] | 8221 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 8222 | fnode_sess->discovery_parent_idx = |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8223 | *(uint16_t *)fnode_param->value; |
| 8224 | break; |
| 8225 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 8226 | fnode_conn->tcp_xmit_wsf = |
| 8227 | *(uint8_t *)fnode_param->value; |
| 8228 | break; |
| 8229 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 8230 | fnode_conn->tcp_recv_wsf = |
| 8231 | *(uint8_t *)fnode_param->value; |
| 8232 | break; |
| 8233 | case ISCSI_FLASHNODE_STATSN: |
| 8234 | fnode_conn->statsn = *(uint32_t *)fnode_param->value; |
| 8235 | break; |
| 8236 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 8237 | fnode_conn->exp_statsn = |
| 8238 | *(uint32_t *)fnode_param->value; |
| 8239 | break; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8240 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 8241 | chap_out_idx = *(uint16_t *)fnode_param->value; |
| 8242 | if (!qla4xxx_get_uni_chap_at_index(ha, |
| 8243 | chap_tbl.name, |
| 8244 | chap_tbl.secret, |
| 8245 | chap_out_idx)) { |
| 8246 | fnode_sess->chap_out_idx = chap_out_idx; |
| 8247 | /* Enable chap auth if chap index is valid */ |
| 8248 | fnode_sess->chap_auth_en = QL4_PARAM_ENABLE; |
| 8249 | } |
| 8250 | break; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8251 | default: |
| 8252 | ql4_printk(KERN_ERR, ha, |
| 8253 | "%s: No such sysfs attribute\n", __func__); |
| 8254 | rc = -ENOSYS; |
| 8255 | goto exit_set_param; |
| 8256 | } |
| 8257 | } |
| 8258 | |
| 8259 | rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn); |
| 8260 | |
| 8261 | exit_set_param: |
| 8262 | return rc; |
| 8263 | } |
| 8264 | |
| 8265 | /** |
| 8266 | * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry |
| 8267 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 8268 | * |
| 8269 | * This invalidates the flash ddb entry at the given index |
| 8270 | **/ |
| 8271 | static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess) |
| 8272 | { |
| 8273 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 8274 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 8275 | uint32_t dev_db_start_offset; |
| 8276 | uint32_t dev_db_end_offset; |
| 8277 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8278 | dma_addr_t fw_ddb_entry_dma; |
| 8279 | uint16_t *ddb_cookie = NULL; |
Vikas Chaudhary | b6130ce | 2013-04-17 05:15:26 -0400 | [diff] [blame] | 8280 | size_t ddb_size = 0; |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8281 | void *pddb = NULL; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8282 | int target_id; |
| 8283 | int rc = 0; |
| 8284 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8285 | if (fnode_sess->is_boot_target) { |
| 8286 | rc = -EPERM; |
| 8287 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8288 | "%s: Deletion of boot target entry is not permitted.\n", |
| 8289 | __func__)); |
| 8290 | goto exit_ddb_del; |
| 8291 | } |
| 8292 | |
| 8293 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) |
| 8294 | goto sysfs_ddb_del; |
| 8295 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8296 | if (is_qla40XX(ha)) { |
| 8297 | dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8298 | dev_db_end_offset = FLASH_OFFSET_DB_END; |
| 8299 | dev_db_start_offset += (fnode_sess->target_id * |
| 8300 | sizeof(*fw_ddb_entry)); |
| 8301 | ddb_size = sizeof(*fw_ddb_entry); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8302 | } else { |
| 8303 | dev_db_start_offset = FLASH_RAW_ACCESS_ADDR + |
| 8304 | (ha->hw.flt_region_ddb << 2); |
| 8305 | /* flt_ddb_size is DDB table size for both ports |
| 8306 | * so divide it by 2 to calculate the offset for second port |
| 8307 | */ |
| 8308 | if (ha->port_num == 1) |
| 8309 | dev_db_start_offset += (ha->hw.flt_ddb_size / 2); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8310 | |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8311 | dev_db_end_offset = dev_db_start_offset + |
| 8312 | (ha->hw.flt_ddb_size / 2); |
| 8313 | |
| 8314 | dev_db_start_offset += (fnode_sess->target_id * |
| 8315 | sizeof(*fw_ddb_entry)); |
Adheer Chandravanshi | 1bcb561 | 2013-04-17 05:15:28 -0400 | [diff] [blame] | 8316 | dev_db_start_offset += offsetof(struct dev_db_entry, cookie); |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8317 | |
| 8318 | ddb_size = sizeof(*ddb_cookie); |
| 8319 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8320 | |
| 8321 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n", |
| 8322 | __func__, dev_db_start_offset, dev_db_end_offset)); |
| 8323 | |
| 8324 | if (dev_db_start_offset > dev_db_end_offset) { |
| 8325 | rc = -EIO; |
| 8326 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n", |
| 8327 | __func__, fnode_sess->target_id)); |
| 8328 | goto exit_ddb_del; |
| 8329 | } |
| 8330 | |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8331 | pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size, |
| 8332 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8333 | if (!pddb) { |
| 8334 | rc = -ENOMEM; |
| 8335 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8336 | "%s: Unable to allocate dma buffer\n", |
| 8337 | __func__)); |
| 8338 | goto exit_ddb_del; |
| 8339 | } |
| 8340 | |
| 8341 | if (is_qla40XX(ha)) { |
| 8342 | fw_ddb_entry = pddb; |
| 8343 | memset(fw_ddb_entry, 0, ddb_size); |
| 8344 | ddb_cookie = &fw_ddb_entry->cookie; |
| 8345 | } else { |
| 8346 | ddb_cookie = pddb; |
| 8347 | } |
| 8348 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8349 | /* invalidate the cookie */ |
| 8350 | *ddb_cookie = 0xFFEE; |
| 8351 | qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8352 | ddb_size, FLASH_OPT_RMW_COMMIT); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8353 | |
| 8354 | sysfs_ddb_del: |
| 8355 | target_id = fnode_sess->target_id; |
| 8356 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 8357 | ql4_printk(KERN_INFO, ha, |
| 8358 | "%s: session and conn entries for flashnode %u of host %lu deleted\n", |
| 8359 | __func__, target_id, ha->host_no); |
| 8360 | exit_ddb_del: |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8361 | if (pddb) |
| 8362 | dma_free_coherent(&ha->pdev->dev, ddb_size, pddb, |
| 8363 | fw_ddb_entry_dma); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8364 | return rc; |
| 8365 | } |
| 8366 | |
| 8367 | /** |
| 8368 | * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs |
| 8369 | * @ha: pointer to adapter structure |
| 8370 | * |
| 8371 | * Export the firmware DDB for all send targets and normal targets to sysfs. |
| 8372 | **/ |
| 8373 | static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha) |
| 8374 | { |
| 8375 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8376 | dma_addr_t fw_ddb_entry_dma; |
| 8377 | uint16_t max_ddbs; |
| 8378 | uint16_t idx = 0; |
| 8379 | int ret = QLA_SUCCESS; |
| 8380 | |
| 8381 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
| 8382 | sizeof(*fw_ddb_entry), |
| 8383 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8384 | if (!fw_ddb_entry) { |
| 8385 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8386 | "%s: Unable to allocate dma buffer\n", |
| 8387 | __func__)); |
| 8388 | return -ENOMEM; |
| 8389 | } |
| 8390 | |
Adheer Chandravanshi | a957a7d | 2013-04-05 07:06:08 -0400 | [diff] [blame] | 8391 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8392 | MAX_DEV_DB_ENTRIES; |
| 8393 | |
| 8394 | for (idx = 0; idx < max_ddbs; idx++) { |
| 8395 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma, |
| 8396 | idx)) |
| 8397 | continue; |
| 8398 | |
| 8399 | ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0); |
| 8400 | if (ret) { |
| 8401 | ret = -EIO; |
| 8402 | break; |
| 8403 | } |
| 8404 | } |
| 8405 | |
| 8406 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry, |
| 8407 | fw_ddb_entry_dma); |
| 8408 | |
| 8409 | return ret; |
| 8410 | } |
| 8411 | |
| 8412 | static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha) |
| 8413 | { |
| 8414 | iscsi_destroy_all_flashnode(ha->host); |
| 8415 | } |
| 8416 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8417 | /** |
| 8418 | * qla4xxx_build_ddb_list - Build ddb list and setup sessions |
| 8419 | * @ha: pointer to adapter structure |
| 8420 | * @is_reset: Is this init path or reset path |
| 8421 | * |
| 8422 | * Create a list of sendtargets (st) from firmware DDBs, issue send targets |
| 8423 | * using connection open, then create the list of normal targets (nt) |
| 8424 | * from firmware DDBs. Based on the list of nt setup session and connection |
| 8425 | * objects. |
| 8426 | **/ |
| 8427 | void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset) |
| 8428 | { |
| 8429 | uint16_t tmo = 0; |
| 8430 | struct list_head list_st, list_nt; |
| 8431 | struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp; |
| 8432 | unsigned long wtime; |
| 8433 | |
| 8434 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 8435 | set_bit(AF_BUILD_DDB_LIST, &ha->flags); |
| 8436 | ha->is_reset = is_reset; |
| 8437 | return; |
| 8438 | } |
| 8439 | |
| 8440 | INIT_LIST_HEAD(&list_st); |
| 8441 | INIT_LIST_HEAD(&list_nt); |
| 8442 | |
| 8443 | qla4xxx_build_st_list(ha, &list_st); |
| 8444 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8445 | /* Before issuing conn open mbox, ensure all IPs states are configured |
| 8446 | * Note, conn open fails if IPs are not configured |
| 8447 | */ |
| 8448 | qla4xxx_wait_for_ip_configuration(ha); |
| 8449 | |
| 8450 | /* Go thru the STs and fire the sendtargets by issuing conn open mbx */ |
| 8451 | list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) { |
| 8452 | qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx); |
| 8453 | } |
| 8454 | |
| 8455 | /* Wait to ensure all sendtargets are done for min 12 sec wait */ |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 8456 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 8457 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 8458 | ha->def_timeout : LOGIN_TOV); |
| 8459 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8460 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8461 | "Default time to wait for build ddb %d\n", tmo)); |
| 8462 | |
| 8463 | wtime = jiffies + (HZ * tmo); |
| 8464 | do { |
Nilesh Javali | f1f2e60 | 2011-12-16 01:58:57 -0800 | [diff] [blame] | 8465 | if (list_empty(&list_st)) |
| 8466 | break; |
| 8467 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8468 | qla4xxx_remove_failed_ddb(ha, &list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8469 | schedule_timeout_uninterruptible(HZ / 10); |
| 8470 | } while (time_after(wtime, jiffies)); |
| 8471 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 8472 | |
| 8473 | qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset); |
| 8474 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8475 | qla4xxx_free_ddb_list(&list_st); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8476 | qla4xxx_free_ddb_list(&list_nt); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8477 | |
| 8478 | qla4xxx_free_ddb_index(ha); |
| 8479 | } |
| 8480 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8481 | /** |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 8482 | * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login |
| 8483 | * response. |
| 8484 | * @ha: pointer to adapter structure |
| 8485 | * |
| 8486 | * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be |
| 8487 | * set in DDB and we will wait for login response of boot targets during |
| 8488 | * probe. |
| 8489 | **/ |
| 8490 | static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha) |
| 8491 | { |
| 8492 | struct ddb_entry *ddb_entry; |
| 8493 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8494 | dma_addr_t fw_ddb_entry_dma; |
| 8495 | unsigned long wtime; |
| 8496 | uint32_t ddb_state; |
| 8497 | int max_ddbs, idx, ret; |
| 8498 | |
| 8499 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 8500 | MAX_DEV_DB_ENTRIES; |
| 8501 | |
| 8502 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8503 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8504 | if (!fw_ddb_entry) { |
| 8505 | ql4_printk(KERN_ERR, ha, |
| 8506 | "%s: Unable to allocate dma buffer\n", __func__); |
| 8507 | goto exit_login_resp; |
| 8508 | } |
| 8509 | |
| 8510 | wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV); |
| 8511 | |
| 8512 | for (idx = 0; idx < max_ddbs; idx++) { |
| 8513 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 8514 | if (ddb_entry == NULL) |
| 8515 | continue; |
| 8516 | |
| 8517 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 8518 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8519 | "%s: DDB index [%d]\n", __func__, |
| 8520 | ddb_entry->fw_ddb_index)); |
| 8521 | do { |
| 8522 | ret = qla4xxx_get_fwddb_entry(ha, |
| 8523 | ddb_entry->fw_ddb_index, |
| 8524 | fw_ddb_entry, fw_ddb_entry_dma, |
| 8525 | NULL, NULL, &ddb_state, NULL, |
| 8526 | NULL, NULL); |
| 8527 | if (ret == QLA_ERROR) |
| 8528 | goto exit_login_resp; |
| 8529 | |
| 8530 | if ((ddb_state == DDB_DS_SESSION_ACTIVE) || |
| 8531 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 8532 | break; |
| 8533 | |
| 8534 | schedule_timeout_uninterruptible(HZ); |
| 8535 | |
| 8536 | } while ((time_after(wtime, jiffies))); |
| 8537 | |
| 8538 | if (!time_after(wtime, jiffies)) { |
| 8539 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8540 | "%s: Login response wait timer expired\n", |
| 8541 | __func__)); |
| 8542 | goto exit_login_resp; |
| 8543 | } |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | exit_login_resp: |
| 8548 | if (fw_ddb_entry) |
| 8549 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8550 | fw_ddb_entry, fw_ddb_entry_dma); |
| 8551 | } |
| 8552 | |
| 8553 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8554 | * qla4xxx_probe_adapter - callback function to probe HBA |
| 8555 | * @pdev: pointer to pci_dev structure |
| 8556 | * @pci_device_id: pointer to pci_device entry |
| 8557 | * |
| 8558 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. |
| 8559 | * It returns zero if successful. It also initializes all data necessary for |
| 8560 | * the driver. |
| 8561 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8562 | static int qla4xxx_probe_adapter(struct pci_dev *pdev, |
| 8563 | const struct pci_device_id *ent) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8564 | { |
| 8565 | int ret = -ENODEV, status; |
| 8566 | struct Scsi_Host *host; |
| 8567 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8568 | uint8_t init_retry_count = 0; |
| 8569 | char buf[34]; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8570 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8571 | uint32_t dev_state; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8572 | |
| 8573 | if (pci_enable_device(pdev)) |
| 8574 | return -1; |
| 8575 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8576 | host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8577 | if (host == NULL) { |
| 8578 | printk(KERN_WARNING |
| 8579 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); |
| 8580 | goto probe_disable_device; |
| 8581 | } |
| 8582 | |
| 8583 | /* Clear our data area */ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8584 | ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8585 | memset(ha, 0, sizeof(*ha)); |
| 8586 | |
| 8587 | /* Save the information from PCI BIOS. */ |
| 8588 | ha->pdev = pdev; |
| 8589 | ha->host = host; |
| 8590 | ha->host_no = host->host_no; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8591 | ha->func_num = PCI_FUNC(ha->pdev->devfn); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8592 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8593 | pci_enable_pcie_error_reporting(pdev); |
| 8594 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8595 | /* Setup Runtime configurable options */ |
| 8596 | if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 8597 | ha->isp_ops = &qla4_82xx_isp_ops; |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8598 | ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8599 | ha->qdr_sn_window = -1; |
| 8600 | ha->ddr_mn_window = -1; |
| 8601 | ha->curr_window = 255; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8602 | nx_legacy_intr = &legacy_intr[ha->func_num]; |
| 8603 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; |
| 8604 | ha->nx_legacy_intr.tgt_status_reg = |
| 8605 | nx_legacy_intr->tgt_status_reg; |
| 8606 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; |
| 8607 | 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] | 8608 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8609 | ha->isp_ops = &qla4_83xx_isp_ops; |
| 8610 | ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8611 | } else { |
| 8612 | ha->isp_ops = &qla4xxx_isp_ops; |
| 8613 | } |
| 8614 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8615 | if (is_qla80XX(ha)) { |
| 8616 | rwlock_init(&ha->hw_lock); |
| 8617 | ha->pf_bit = ha->func_num << 16; |
| 8618 | /* Set EEH reset type to fundamental if required by hba */ |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8619 | pdev->needs_freset = 1; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8620 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8621 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8622 | /* Configure PCI I/O space. */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8623 | ret = ha->isp_ops->iospace_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8624 | if (ret) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8625 | goto probe_failed_ioconfig; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8626 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8627 | 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] | 8628 | pdev->device, pdev->irq, ha->reg); |
| 8629 | |
| 8630 | qla4xxx_config_dma_addressing(ha); |
| 8631 | |
| 8632 | /* Initialize lists and spinlocks. */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8633 | INIT_LIST_HEAD(&ha->free_srb_q); |
| 8634 | |
| 8635 | mutex_init(&ha->mbox_sem); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 8636 | mutex_init(&ha->chap_sem); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8637 | init_completion(&ha->mbx_intr_comp); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 8638 | init_completion(&ha->disable_acb_comp); |
Vikas Chaudhary | df86f77 | 2013-11-22 05:28:17 -0500 | [diff] [blame] | 8639 | init_completion(&ha->idc_comp); |
| 8640 | init_completion(&ha->link_up_comp); |
| 8641 | init_completion(&ha->disable_acb_comp); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8642 | |
| 8643 | spin_lock_init(&ha->hardware_lock); |
Vikas Chaudhary | 8e9157c | 2012-08-22 07:45:24 -0400 | [diff] [blame] | 8644 | spin_lock_init(&ha->work_lock); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8645 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 8646 | /* Initialize work list */ |
| 8647 | INIT_LIST_HEAD(&ha->work_list); |
| 8648 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8649 | /* Allocate dma buffers */ |
| 8650 | if (qla4xxx_mem_alloc(ha)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8651 | ql4_printk(KERN_WARNING, ha, |
| 8652 | "[ERROR] Failed to allocate memory for adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8653 | |
| 8654 | ret = -ENOMEM; |
| 8655 | goto probe_failed; |
| 8656 | } |
| 8657 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8658 | host->cmd_per_lun = 3; |
| 8659 | host->max_channel = 0; |
| 8660 | host->max_lun = MAX_LUNS - 1; |
| 8661 | host->max_id = MAX_TARGETS; |
| 8662 | host->max_cmd_len = IOCB_MAX_CDB_LEN; |
| 8663 | host->can_queue = MAX_SRBS ; |
| 8664 | host->transportt = qla4xxx_scsi_transport; |
| 8665 | |
| 8666 | ret = scsi_init_shared_tag_map(host, MAX_SRBS); |
| 8667 | if (ret) { |
| 8668 | ql4_printk(KERN_WARNING, ha, |
| 8669 | "%s: scsi_init_shared_tag_map failed\n", __func__); |
| 8670 | goto probe_failed; |
| 8671 | } |
| 8672 | |
| 8673 | pci_set_drvdata(pdev, ha); |
| 8674 | |
| 8675 | ret = scsi_add_host(host, &pdev->dev); |
| 8676 | if (ret) |
| 8677 | goto probe_failed; |
| 8678 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8679 | if (is_qla80XX(ha)) |
| 8680 | qla4_8xxx_get_flash_info(ha); |
| 8681 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8682 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8683 | qla4_83xx_read_reset_template(ha); |
| 8684 | /* |
| 8685 | * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 8686 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 8687 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 8688 | * should honor the reset. |
| 8689 | */ |
| 8690 | if (ql4xdontresethba == 1) |
| 8691 | qla4_83xx_set_idc_dontreset(ha); |
| 8692 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8693 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8694 | /* |
| 8695 | * Initialize the Host adapter request/response queues and |
| 8696 | * firmware |
| 8697 | * NOTE: interrupts enabled upon successful completion |
| 8698 | */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8699 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8700 | |
| 8701 | /* Dont retry adapter initialization if IRQ allocation failed */ |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 8702 | if (is_qla80XX(ha) && (status == QLA_ERROR)) |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8703 | goto skip_retry_init; |
| 8704 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8705 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
| 8706 | init_retry_count++ < MAX_INIT_RETRIES) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8707 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8708 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8709 | ha->isp_ops->idc_lock(ha); |
| 8710 | dev_state = qla4_8xxx_rd_direct(ha, |
Vikas Chaudhary | e951aca | 2012-12-29 02:24:52 -0500 | [diff] [blame] | 8711 | QLA8XXX_CRB_DEV_STATE); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8712 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 8713 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8714 | ql4_printk(KERN_WARNING, ha, "%s: don't retry " |
| 8715 | "initialize adapter. H/W is in failed state\n", |
| 8716 | __func__); |
| 8717 | break; |
| 8718 | } |
| 8719 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8720 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
| 8721 | "(%d)\n", __func__, init_retry_count)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8722 | |
| 8723 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) |
| 8724 | continue; |
| 8725 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8726 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 8727 | if (is_qla80XX(ha) && (status == QLA_ERROR)) { |
| 8728 | if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR) |
| 8729 | goto skip_retry_init; |
| 8730 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8731 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8732 | |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8733 | skip_retry_init: |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8734 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8735 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8736 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8737 | if ((is_qla8022(ha) && ql4xdontresethba) || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8738 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 8739 | qla4_83xx_idc_dontreset(ha))) { |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 8740 | /* Put the device in failed state. */ |
| 8741 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8742 | ha->isp_ops->idc_lock(ha); |
| 8743 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 8744 | QLA8XXX_DEV_FAILED); |
| 8745 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 8746 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8747 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8748 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8749 | } |
| 8750 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8751 | /* Startup the kernel thread for this host adapter. */ |
| 8752 | DEBUG2(printk("scsi: %s: Starting kernel thread for " |
| 8753 | "qla4xxx_dpc\n", __func__)); |
| 8754 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); |
| 8755 | ha->dpc_thread = create_singlethread_workqueue(buf); |
| 8756 | if (!ha->dpc_thread) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8757 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8758 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8759 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8760 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 8761 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8762 | |
Kees Cook | d853754 | 2013-07-03 15:04:57 -0700 | [diff] [blame] | 8763 | ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1, |
| 8764 | ha->host_no); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8765 | if (!ha->task_wq) { |
| 8766 | ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n"); |
| 8767 | ret = -ENODEV; |
| 8768 | goto remove_host; |
| 8769 | } |
| 8770 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8771 | /* |
| 8772 | * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8773 | * (which is called indirectly by qla4xxx_initialize_adapter), |
| 8774 | * so that irqs will be registered after crbinit but before |
| 8775 | * mbx_intr_enable. |
| 8776 | */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 8777 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8778 | ret = qla4xxx_request_irqs(ha); |
| 8779 | if (ret) { |
| 8780 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " |
| 8781 | "interrupt %d already in use.\n", pdev->irq); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8782 | goto remove_host; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8783 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8784 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8785 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8786 | pci_save_state(ha->pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8787 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8788 | |
| 8789 | /* Start timer thread. */ |
| 8790 | qla4xxx_start_timer(ha, qla4xxx_timer, 1); |
| 8791 | |
| 8792 | set_bit(AF_INIT_DONE, &ha->flags); |
| 8793 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 8794 | qla4_8xxx_alloc_sysfs_attr(ha); |
| 8795 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8796 | printk(KERN_INFO |
| 8797 | " QLogic iSCSI HBA Driver version: %s\n" |
| 8798 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", |
| 8799 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), |
Adheer Chandravanshi | eee06a0 | 2013-07-08 08:33:10 -0400 | [diff] [blame] | 8800 | ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor, |
| 8801 | ha->fw_info.fw_patch, ha->fw_info.fw_build); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8802 | |
Manish Dusane | cfb2787 | 2012-09-20 07:35:01 -0400 | [diff] [blame] | 8803 | /* Set the driver version */ |
| 8804 | if (is_qla80XX(ha)) |
| 8805 | qla4_8xxx_set_param(ha, SET_DRVR_VERSION); |
| 8806 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8807 | if (qla4xxx_setup_boot_info(ha)) |
Vikas Chaudhary | 3573bfb | 2012-02-27 03:08:57 -0800 | [diff] [blame] | 8808 | ql4_printk(KERN_ERR, ha, |
| 8809 | "%s: No iSCSI boot target configured\n", __func__); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8810 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8811 | if (qla4xxx_sysfs_ddb_export(ha)) |
| 8812 | ql4_printk(KERN_ERR, ha, |
| 8813 | "%s: Error exporting ddb to sysfs\n", __func__); |
| 8814 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8815 | /* Perform the build ddb list and login to each */ |
| 8816 | qla4xxx_build_ddb_list(ha, INIT_ADAPTER); |
| 8817 | iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 8818 | qla4xxx_wait_login_resp_boot_tgt(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8819 | |
| 8820 | qla4xxx_create_chap_list(ha); |
| 8821 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8822 | qla4xxx_create_ifaces(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8823 | return 0; |
| 8824 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8825 | remove_host: |
| 8826 | scsi_remove_host(ha->host); |
| 8827 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8828 | probe_failed: |
| 8829 | qla4xxx_free_adapter(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8830 | |
| 8831 | probe_failed_ioconfig: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8832 | pci_disable_pcie_error_reporting(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8833 | scsi_host_put(ha->host); |
| 8834 | |
| 8835 | probe_disable_device: |
| 8836 | pci_disable_device(pdev); |
| 8837 | |
| 8838 | return ret; |
| 8839 | } |
| 8840 | |
| 8841 | /** |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8842 | * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize |
| 8843 | * @ha: pointer to adapter structure |
| 8844 | * |
| 8845 | * Mark the other ISP-4xxx port to indicate that the driver is being removed, |
| 8846 | * so that the other port will not re-initialize while in the process of |
| 8847 | * removing the ha due to driver unload or hba hotplug. |
| 8848 | **/ |
| 8849 | static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha) |
| 8850 | { |
| 8851 | struct scsi_qla_host *other_ha = NULL; |
| 8852 | struct pci_dev *other_pdev = NULL; |
| 8853 | int fn = ISP4XXX_PCI_FN_2; |
| 8854 | |
| 8855 | /*iscsi function numbers for ISP4xxx is 1 and 3*/ |
| 8856 | if (PCI_FUNC(ha->pdev->devfn) & BIT_1) |
| 8857 | fn = ISP4XXX_PCI_FN_1; |
| 8858 | |
| 8859 | other_pdev = |
| 8860 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 8861 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 8862 | fn)); |
| 8863 | |
| 8864 | /* Get other_ha if other_pdev is valid and state is enable*/ |
| 8865 | if (other_pdev) { |
| 8866 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 8867 | other_ha = pci_get_drvdata(other_pdev); |
| 8868 | if (other_ha) { |
| 8869 | set_bit(AF_HA_REMOVAL, &other_ha->flags); |
| 8870 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " |
| 8871 | "Prevent %s reinit\n", __func__, |
| 8872 | dev_name(&other_ha->pdev->dev))); |
| 8873 | } |
| 8874 | } |
| 8875 | pci_dev_put(other_pdev); |
| 8876 | } |
| 8877 | } |
| 8878 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8879 | static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha) |
| 8880 | { |
| 8881 | struct ddb_entry *ddb_entry; |
| 8882 | int options; |
| 8883 | int idx; |
| 8884 | |
| 8885 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 8886 | |
| 8887 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 8888 | if ((ddb_entry != NULL) && |
| 8889 | (ddb_entry->ddb_type == FLASH_DDB)) { |
| 8890 | |
| 8891 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 8892 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) |
| 8893 | == QLA_ERROR) |
| 8894 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", |
| 8895 | __func__); |
| 8896 | |
| 8897 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 8898 | /* |
| 8899 | * we have decremented the reference count of the driver |
| 8900 | * when we setup the session to have the driver unload |
| 8901 | * to be seamless without actually destroying the |
| 8902 | * session |
| 8903 | **/ |
| 8904 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 8905 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 8906 | qla4xxx_free_ddb(ha, ddb_entry); |
| 8907 | iscsi_session_teardown(ddb_entry->sess); |
| 8908 | } |
| 8909 | } |
| 8910 | } |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8911 | /** |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 8912 | * qla4xxx_remove_adapter - callback function to remove adapter. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8913 | * @pci_dev: PCI device pointer |
| 8914 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8915 | static void qla4xxx_remove_adapter(struct pci_dev *pdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8916 | { |
| 8917 | struct scsi_qla_host *ha; |
| 8918 | |
Vikas Chaudhary | f8b0751 | 2012-09-20 07:35:08 -0400 | [diff] [blame] | 8919 | /* |
| 8920 | * If the PCI device is disabled then it means probe_adapter had |
| 8921 | * failed and resources already cleaned up on probe_adapter exit. |
| 8922 | */ |
| 8923 | if (!pci_is_enabled(pdev)) |
| 8924 | return; |
| 8925 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8926 | ha = pci_get_drvdata(pdev); |
| 8927 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 8928 | if (is_qla40XX(ha)) |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8929 | qla4xxx_prevent_other_port_reinit(ha); |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 8930 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8931 | /* destroy iface from sysfs */ |
| 8932 | qla4xxx_destroy_ifaces(ha); |
| 8933 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8934 | if ((!ql4xdisablesysfsboot) && ha->boot_kset) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8935 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 8936 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8937 | qla4xxx_destroy_fw_ddb_session(ha); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 8938 | qla4_8xxx_free_sysfs_attr(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8939 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8940 | qla4xxx_sysfs_ddb_remove(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8941 | scsi_remove_host(ha->host); |
| 8942 | |
| 8943 | qla4xxx_free_adapter(ha); |
| 8944 | |
| 8945 | scsi_host_put(ha->host); |
| 8946 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8947 | pci_disable_pcie_error_reporting(pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8948 | pci_disable_device(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8949 | } |
| 8950 | |
| 8951 | /** |
| 8952 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. |
| 8953 | * @ha: HA context |
| 8954 | * |
| 8955 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 8956 | * supported addressing method. |
| 8957 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 8958 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8959 | { |
| 8960 | int retval; |
| 8961 | |
| 8962 | /* Update our PCI device dma_mask for full 64 bit mask */ |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 8963 | if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) { |
| 8964 | if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8965 | dev_dbg(&ha->pdev->dev, |
| 8966 | "Failed to set 64 bit PCI consistent mask; " |
| 8967 | "using 32 bit.\n"); |
| 8968 | retval = pci_set_consistent_dma_mask(ha->pdev, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 8969 | DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8970 | } |
| 8971 | } else |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 8972 | retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8973 | } |
| 8974 | |
| 8975 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) |
| 8976 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8977 | struct iscsi_cls_session *cls_sess; |
| 8978 | struct iscsi_session *sess; |
| 8979 | struct ddb_entry *ddb; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 8980 | int queue_depth = QL4_DEF_QDEPTH; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8981 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8982 | cls_sess = starget_to_session(sdev->sdev_target); |
| 8983 | sess = cls_sess->dd_data; |
| 8984 | ddb = sess->dd_data; |
| 8985 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8986 | sdev->hostdata = ddb; |
| 8987 | sdev->tagged_supported = 1; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 8988 | |
| 8989 | if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) |
| 8990 | queue_depth = ql4xmaxqdepth; |
| 8991 | |
| 8992 | scsi_activate_tcq(sdev, queue_depth); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8993 | return 0; |
| 8994 | } |
| 8995 | |
| 8996 | static int qla4xxx_slave_configure(struct scsi_device *sdev) |
| 8997 | { |
| 8998 | sdev->tagged_supported = 1; |
| 8999 | return 0; |
| 9000 | } |
| 9001 | |
| 9002 | static void qla4xxx_slave_destroy(struct scsi_device *sdev) |
| 9003 | { |
| 9004 | scsi_deactivate_tcq(sdev, 1); |
| 9005 | } |
| 9006 | |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 9007 | static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, |
| 9008 | int reason) |
| 9009 | { |
| 9010 | if (!ql4xqfulltracking) |
| 9011 | return -EOPNOTSUPP; |
| 9012 | |
| 9013 | return iscsi_change_queue_depth(sdev, qdepth, reason); |
| 9014 | } |
| 9015 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9016 | /** |
| 9017 | * qla4xxx_del_from_active_array - returns an active srb |
| 9018 | * @ha: Pointer to host adapter structure. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 9019 | * @index: index into the active_array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9020 | * |
| 9021 | * This routine removes and returns the srb at the specified index |
| 9022 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9023 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
| 9024 | uint32_t index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9025 | { |
| 9026 | struct srb *srb = NULL; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9027 | struct scsi_cmnd *cmd = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9028 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9029 | cmd = scsi_host_find_tag(ha->host, index); |
| 9030 | if (!cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9031 | return srb; |
| 9032 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9033 | srb = (struct srb *)CMD_SP(cmd); |
| 9034 | if (!srb) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9035 | return srb; |
| 9036 | |
| 9037 | /* update counters */ |
| 9038 | if (srb->flags & SRB_DMA_VALID) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9039 | ha->iocb_cnt -= srb->iocb_cnt; |
| 9040 | if (srb->cmd) |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9041 | srb->cmd->host_scribble = |
| 9042 | (unsigned char *)(unsigned long) MAX_SRBS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9043 | } |
| 9044 | return srb; |
| 9045 | } |
| 9046 | |
| 9047 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9048 | * 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] | 9049 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9050 | * @cmd: Scsi Command to wait on. |
| 9051 | * |
| 9052 | * This routine waits for the command to be returned by the Firmware |
| 9053 | * for some max time. |
| 9054 | **/ |
| 9055 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, |
| 9056 | struct scsi_cmnd *cmd) |
| 9057 | { |
| 9058 | int done = 0; |
| 9059 | struct srb *rp; |
| 9060 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9061 | int ret = SUCCESS; |
| 9062 | |
| 9063 | /* Dont wait on command if PCI error is being handled |
| 9064 | * by PCI AER driver |
| 9065 | */ |
| 9066 | if (unlikely(pci_channel_offline(ha->pdev)) || |
| 9067 | (test_bit(AF_EEH_BUSY, &ha->flags))) { |
| 9068 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", |
| 9069 | ha->host_no, __func__); |
| 9070 | return ret; |
| 9071 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9072 | |
| 9073 | do { |
| 9074 | /* Checking to see if its returned to OS */ |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9075 | rp = (struct srb *) CMD_SP(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9076 | if (rp == NULL) { |
| 9077 | done++; |
| 9078 | break; |
| 9079 | } |
| 9080 | |
| 9081 | msleep(2000); |
| 9082 | } while (max_wait_time--); |
| 9083 | |
| 9084 | return done; |
| 9085 | } |
| 9086 | |
| 9087 | /** |
| 9088 | * qla4xxx_wait_for_hba_online - waits for HBA to come online |
| 9089 | * @ha: Pointer to host adapter structure |
| 9090 | **/ |
| 9091 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) |
| 9092 | { |
| 9093 | unsigned long wait_online; |
| 9094 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 9095 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9096 | while (time_before(jiffies, wait_online)) { |
| 9097 | |
| 9098 | if (adapter_up(ha)) |
| 9099 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9100 | |
| 9101 | msleep(2000); |
| 9102 | } |
| 9103 | |
| 9104 | return QLA_ERROR; |
| 9105 | } |
| 9106 | |
| 9107 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9108 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 9109 | * @ha: pointer to HBA |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9110 | * @t: target id |
| 9111 | * @l: lun id |
| 9112 | * |
| 9113 | * This function waits for all outstanding commands to a lun to complete. It |
| 9114 | * returns 0 if all pending commands are returned and 1 otherwise. |
| 9115 | **/ |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9116 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
| 9117 | struct scsi_target *stgt, |
| 9118 | struct scsi_device *sdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9119 | { |
| 9120 | int cnt; |
| 9121 | int status = 0; |
| 9122 | struct scsi_cmnd *cmd; |
| 9123 | |
| 9124 | /* |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9125 | * Waiting for all commands for the designated target or dev |
| 9126 | * in the active array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9127 | */ |
| 9128 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { |
| 9129 | cmd = scsi_host_find_tag(ha->host, cnt); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9130 | if (cmd && stgt == scsi_target(cmd->device) && |
| 9131 | (!sdev || sdev == cmd->device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9132 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 9133 | status++; |
| 9134 | break; |
| 9135 | } |
| 9136 | } |
| 9137 | } |
| 9138 | return status; |
| 9139 | } |
| 9140 | |
| 9141 | /** |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9142 | * qla4xxx_eh_abort - callback for abort task. |
| 9143 | * @cmd: Pointer to Linux's SCSI command structure |
| 9144 | * |
| 9145 | * This routine is called by the Linux OS to abort the specified |
| 9146 | * command. |
| 9147 | **/ |
| 9148 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) |
| 9149 | { |
| 9150 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9151 | unsigned int id = cmd->device->id; |
| 9152 | unsigned int lun = cmd->device->lun; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9153 | unsigned long flags; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9154 | struct srb *srb = NULL; |
| 9155 | int ret = SUCCESS; |
| 9156 | int wait = 0; |
| 9157 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9158 | ql4_printk(KERN_INFO, ha, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 9159 | "scsi%ld:%d:%d: Abort command issued cmd=%p\n", |
| 9160 | ha->host_no, id, lun, cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9161 | |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9162 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9163 | srb = (struct srb *) CMD_SP(cmd); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9164 | if (!srb) { |
| 9165 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9166 | return SUCCESS; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9167 | } |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9168 | kref_get(&srb->srb_ref); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9169 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9170 | |
| 9171 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { |
| 9172 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", |
| 9173 | ha->host_no, id, lun)); |
| 9174 | ret = FAILED; |
| 9175 | } else { |
| 9176 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n", |
| 9177 | ha->host_no, id, lun)); |
| 9178 | wait = 1; |
| 9179 | } |
| 9180 | |
| 9181 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| 9182 | |
| 9183 | /* Wait for command to complete */ |
| 9184 | if (wait) { |
| 9185 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 9186 | DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n", |
| 9187 | ha->host_no, id, lun)); |
| 9188 | ret = FAILED; |
| 9189 | } |
| 9190 | } |
| 9191 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9192 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9193 | "scsi%ld:%d:%d: Abort command - %s\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9194 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed"); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9195 | |
| 9196 | return ret; |
| 9197 | } |
| 9198 | |
| 9199 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9200 | * qla4xxx_eh_device_reset - callback for target reset. |
| 9201 | * @cmd: Pointer to Linux's SCSI command structure |
| 9202 | * |
| 9203 | * This routine is called by the Linux OS to reset all luns on the |
| 9204 | * specified target. |
| 9205 | **/ |
| 9206 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 9207 | { |
| 9208 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9209 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9210 | int ret = FAILED, stat; |
| 9211 | |
Karen Higgins | 612f734 | 2009-07-15 15:03:01 -0500 | [diff] [blame] | 9212 | if (!ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9213 | return ret; |
| 9214 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9215 | ret = iscsi_block_scsi_eh(cmd); |
| 9216 | if (ret) |
| 9217 | return ret; |
| 9218 | ret = FAILED; |
| 9219 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9220 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9221 | "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no, |
| 9222 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 9223 | |
| 9224 | DEBUG2(printk(KERN_INFO |
| 9225 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," |
| 9226 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 9227 | cmd, jiffies, cmd->request->timeout / HZ, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9228 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 9229 | |
| 9230 | /* FIXME: wait for hba to go online */ |
| 9231 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); |
| 9232 | if (stat != QLA_SUCCESS) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9233 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9234 | goto eh_dev_reset_done; |
| 9235 | } |
| 9236 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9237 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 9238 | cmd->device)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9239 | ql4_printk(KERN_INFO, ha, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9240 | "DEVICE RESET FAILED - waiting for " |
| 9241 | "commands.\n"); |
| 9242 | goto eh_dev_reset_done; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9243 | } |
| 9244 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 9245 | /* Send marker. */ |
| 9246 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 9247 | MM_LUN_RESET) != QLA_SUCCESS) |
| 9248 | goto eh_dev_reset_done; |
| 9249 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9250 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9251 | "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n", |
| 9252 | ha->host_no, cmd->device->channel, cmd->device->id, |
| 9253 | cmd->device->lun); |
| 9254 | |
| 9255 | ret = SUCCESS; |
| 9256 | |
| 9257 | eh_dev_reset_done: |
| 9258 | |
| 9259 | return ret; |
| 9260 | } |
| 9261 | |
| 9262 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9263 | * qla4xxx_eh_target_reset - callback for target reset. |
| 9264 | * @cmd: Pointer to Linux's SCSI command structure |
| 9265 | * |
| 9266 | * This routine is called by the Linux OS to reset the target. |
| 9267 | **/ |
| 9268 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) |
| 9269 | { |
| 9270 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9271 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9272 | int stat, ret; |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9273 | |
| 9274 | if (!ddb_entry) |
| 9275 | return FAILED; |
| 9276 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9277 | ret = iscsi_block_scsi_eh(cmd); |
| 9278 | if (ret) |
| 9279 | return ret; |
| 9280 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9281 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9282 | "WARM TARGET RESET ISSUED.\n"); |
| 9283 | |
| 9284 | DEBUG2(printk(KERN_INFO |
| 9285 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " |
| 9286 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 9287 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9288 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 9289 | |
| 9290 | stat = qla4xxx_reset_target(ha, ddb_entry); |
| 9291 | if (stat != QLA_SUCCESS) { |
| 9292 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9293 | "WARM TARGET RESET FAILED.\n"); |
| 9294 | return FAILED; |
| 9295 | } |
| 9296 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9297 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 9298 | NULL)) { |
| 9299 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9300 | "WARM TARGET DEVICE RESET FAILED - " |
| 9301 | "waiting for commands.\n"); |
| 9302 | return FAILED; |
| 9303 | } |
| 9304 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 9305 | /* Send marker. */ |
| 9306 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 9307 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { |
| 9308 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9309 | "WARM TARGET DEVICE RESET FAILED - " |
| 9310 | "marker iocb failed.\n"); |
| 9311 | return FAILED; |
| 9312 | } |
| 9313 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9314 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9315 | "WARM TARGET RESET SUCCEEDED.\n"); |
| 9316 | return SUCCESS; |
| 9317 | } |
| 9318 | |
| 9319 | /** |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 9320 | * qla4xxx_is_eh_active - check if error handler is running |
| 9321 | * @shost: Pointer to SCSI Host struct |
| 9322 | * |
| 9323 | * This routine finds that if reset host is called in EH |
| 9324 | * scenario or from some application like sg_reset |
| 9325 | **/ |
| 9326 | static int qla4xxx_is_eh_active(struct Scsi_Host *shost) |
| 9327 | { |
| 9328 | if (shost->shost_state == SHOST_RECOVERY) |
| 9329 | return 1; |
| 9330 | return 0; |
| 9331 | } |
| 9332 | |
| 9333 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9334 | * qla4xxx_eh_host_reset - kernel callback |
| 9335 | * @cmd: Pointer to Linux's SCSI command structure |
| 9336 | * |
| 9337 | * This routine is invoked by the Linux kernel to perform fatal error |
| 9338 | * recovery on the specified adapter. |
| 9339 | **/ |
| 9340 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 9341 | { |
| 9342 | int return_status = FAILED; |
| 9343 | struct scsi_qla_host *ha; |
| 9344 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9345 | ha = to_qla_host(cmd->device->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9346 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9347 | if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba) |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9348 | qla4_83xx_set_idc_dontreset(ha); |
| 9349 | |
| 9350 | /* |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9351 | * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other |
| 9352 | * protocol drivers, we should not set device_state to NEED_RESET |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9353 | */ |
| 9354 | if (ql4xdontresethba || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9355 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 9356 | qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9357 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 9358 | ha->host_no, __func__)); |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 9359 | |
| 9360 | /* Clear outstanding srb in queues */ |
| 9361 | if (qla4xxx_is_eh_active(cmd->device->host)) |
| 9362 | qla4xxx_abort_active_cmds(ha, DID_ABORT << 16); |
| 9363 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9364 | return FAILED; |
| 9365 | } |
| 9366 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9367 | ql4_printk(KERN_INFO, ha, |
Karen Higgins | dca05c4 | 2009-07-15 15:03:00 -0500 | [diff] [blame] | 9368 | "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9369 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 9370 | |
| 9371 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 9372 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " |
| 9373 | "DEAD.\n", ha->host_no, cmd->device->channel, |
| 9374 | __func__)); |
| 9375 | |
| 9376 | return FAILED; |
| 9377 | } |
| 9378 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9379 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9380 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9381 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 9382 | else |
| 9383 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 9384 | } |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 9385 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9386 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9387 | return_status = SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9388 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9389 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9390 | return_status == FAILED ? "FAILED" : "SUCCEEDED"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9391 | |
| 9392 | return return_status; |
| 9393 | } |
| 9394 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9395 | static int qla4xxx_context_reset(struct scsi_qla_host *ha) |
| 9396 | { |
| 9397 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 9398 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 9399 | struct addr_ctrl_blk_def *acb = NULL; |
| 9400 | uint32_t acb_len = sizeof(struct addr_ctrl_blk_def); |
| 9401 | int rval = QLA_SUCCESS; |
| 9402 | dma_addr_t acb_dma; |
| 9403 | |
| 9404 | acb = dma_alloc_coherent(&ha->pdev->dev, |
| 9405 | sizeof(struct addr_ctrl_blk_def), |
| 9406 | &acb_dma, GFP_KERNEL); |
| 9407 | if (!acb) { |
| 9408 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n", |
| 9409 | __func__); |
| 9410 | rval = -ENOMEM; |
| 9411 | goto exit_port_reset; |
| 9412 | } |
| 9413 | |
| 9414 | memset(acb, 0, acb_len); |
| 9415 | |
| 9416 | rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len); |
| 9417 | if (rval != QLA_SUCCESS) { |
| 9418 | rval = -EIO; |
| 9419 | goto exit_free_acb; |
| 9420 | } |
| 9421 | |
| 9422 | rval = qla4xxx_disable_acb(ha); |
| 9423 | if (rval != QLA_SUCCESS) { |
| 9424 | rval = -EIO; |
| 9425 | goto exit_free_acb; |
| 9426 | } |
| 9427 | |
| 9428 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 9429 | DISABLE_ACB_TOV * HZ); |
| 9430 | |
| 9431 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma); |
| 9432 | if (rval != QLA_SUCCESS) { |
| 9433 | rval = -EIO; |
| 9434 | goto exit_free_acb; |
| 9435 | } |
| 9436 | |
| 9437 | exit_free_acb: |
| 9438 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def), |
| 9439 | acb, acb_dma); |
| 9440 | exit_port_reset: |
| 9441 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__, |
| 9442 | rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED")); |
| 9443 | return rval; |
| 9444 | } |
| 9445 | |
| 9446 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type) |
| 9447 | { |
| 9448 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 9449 | int rval = QLA_SUCCESS; |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9450 | uint32_t idc_ctrl; |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9451 | |
| 9452 | if (ql4xdontresethba) { |
| 9453 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n", |
| 9454 | __func__)); |
| 9455 | rval = -EPERM; |
| 9456 | goto exit_host_reset; |
| 9457 | } |
| 9458 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9459 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 9460 | goto recover_adapter; |
| 9461 | |
| 9462 | switch (reset_type) { |
| 9463 | case SCSI_ADAPTER_RESET: |
| 9464 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 9465 | break; |
| 9466 | case SCSI_FIRMWARE_RESET: |
| 9467 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9468 | if (is_qla80XX(ha)) |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9469 | /* set firmware context reset */ |
| 9470 | set_bit(DPC_RESET_HA_FW_CONTEXT, |
| 9471 | &ha->dpc_flags); |
| 9472 | else { |
| 9473 | rval = qla4xxx_context_reset(ha); |
| 9474 | goto exit_host_reset; |
| 9475 | } |
| 9476 | } |
| 9477 | break; |
| 9478 | } |
| 9479 | |
| 9480 | recover_adapter: |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9481 | /* 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] | 9482 | * reset is issued by application */ |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9483 | if ((is_qla8032(ha) || is_qla8042(ha)) && |
| 9484 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9485 | idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL); |
| 9486 | qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL, |
| 9487 | (idc_ctrl | GRACEFUL_RESET_BIT1)); |
| 9488 | } |
| 9489 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9490 | rval = qla4xxx_recover_adapter(ha); |
| 9491 | if (rval != QLA_SUCCESS) { |
| 9492 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n", |
| 9493 | __func__)); |
| 9494 | rval = -EIO; |
| 9495 | } |
| 9496 | |
| 9497 | exit_host_reset: |
| 9498 | return rval; |
| 9499 | } |
| 9500 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9501 | /* PCI AER driver recovers from all correctable errors w/o |
| 9502 | * driver intervention. For uncorrectable errors PCI AER |
| 9503 | * driver calls the following device driver's callbacks |
| 9504 | * |
| 9505 | * - Fatal Errors - link_reset |
| 9506 | * - Non-Fatal Errors - driver's pci_error_detected() which |
| 9507 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. |
| 9508 | * |
| 9509 | * PCI AER driver calls |
| 9510 | * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled |
| 9511 | * returns RECOVERED or NEED_RESET if fw_hung |
| 9512 | * NEED_RESET - driver's slot_reset() |
| 9513 | * DISCONNECT - device is dead & cannot recover |
| 9514 | * RECOVERED - driver's pci_resume() |
| 9515 | */ |
| 9516 | static pci_ers_result_t |
| 9517 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 9518 | { |
| 9519 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9520 | |
| 9521 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", |
| 9522 | ha->host_no, __func__, state); |
| 9523 | |
| 9524 | if (!is_aer_supported(ha)) |
| 9525 | return PCI_ERS_RESULT_NONE; |
| 9526 | |
| 9527 | switch (state) { |
| 9528 | case pci_channel_io_normal: |
| 9529 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 9530 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9531 | case pci_channel_io_frozen: |
| 9532 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 9533 | qla4xxx_mailbox_premature_completion(ha); |
| 9534 | qla4xxx_free_irqs(ha); |
| 9535 | pci_disable_device(pdev); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9536 | /* Return back all IOs */ |
| 9537 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9538 | return PCI_ERS_RESULT_NEED_RESET; |
| 9539 | case pci_channel_io_perm_failure: |
| 9540 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 9541 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); |
| 9542 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 9543 | return PCI_ERS_RESULT_DISCONNECT; |
| 9544 | } |
| 9545 | return PCI_ERS_RESULT_NEED_RESET; |
| 9546 | } |
| 9547 | |
| 9548 | /** |
| 9549 | * qla4xxx_pci_mmio_enabled() gets called if |
| 9550 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER |
| 9551 | * and read/write to the device still works. |
| 9552 | **/ |
| 9553 | static pci_ers_result_t |
| 9554 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 9555 | { |
| 9556 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9557 | |
| 9558 | if (!is_aer_supported(ha)) |
| 9559 | return PCI_ERS_RESULT_NONE; |
| 9560 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9561 | return PCI_ERS_RESULT_RECOVERED; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9562 | } |
| 9563 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9564 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9565 | { |
| 9566 | uint32_t rval = QLA_ERROR; |
| 9567 | int fn; |
| 9568 | struct pci_dev *other_pdev = NULL; |
| 9569 | |
| 9570 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); |
| 9571 | |
| 9572 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 9573 | |
| 9574 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 9575 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9576 | clear_bit(AF_LINK_UP, &ha->flags); |
| 9577 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9578 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9579 | } |
| 9580 | |
| 9581 | fn = PCI_FUNC(ha->pdev->devfn); |
| 9582 | while (fn > 0) { |
| 9583 | fn--; |
| 9584 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at " |
| 9585 | "func %x\n", ha->host_no, __func__, fn); |
| 9586 | /* Get the pci device given the domain, bus, |
| 9587 | * slot/function number */ |
| 9588 | other_pdev = |
| 9589 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 9590 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 9591 | fn)); |
| 9592 | |
| 9593 | if (!other_pdev) |
| 9594 | continue; |
| 9595 | |
| 9596 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 9597 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI " |
| 9598 | "func in enabled state%x\n", ha->host_no, |
| 9599 | __func__, fn); |
| 9600 | pci_dev_put(other_pdev); |
| 9601 | break; |
| 9602 | } |
| 9603 | pci_dev_put(other_pdev); |
| 9604 | } |
| 9605 | |
| 9606 | /* The first function on the card, the reset owner will |
| 9607 | * start & initialize the firmware. The other functions |
| 9608 | * on the card will reset the firmware context |
| 9609 | */ |
| 9610 | if (!fn) { |
| 9611 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " |
| 9612 | "0x%x is the owner\n", ha->host_no, __func__, |
| 9613 | ha->pdev->devfn); |
| 9614 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9615 | ha->isp_ops->idc_lock(ha); |
| 9616 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9617 | QLA8XXX_DEV_COLD); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9618 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9619 | |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 9620 | rval = qla4_8xxx_update_idc_reg(ha); |
| 9621 | if (rval == QLA_ERROR) { |
| 9622 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n", |
| 9623 | ha->host_no, __func__); |
| 9624 | ha->isp_ops->idc_lock(ha); |
| 9625 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9626 | QLA8XXX_DEV_FAILED); |
| 9627 | ha->isp_ops->idc_unlock(ha); |
| 9628 | goto exit_error_recovery; |
| 9629 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9630 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9631 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9632 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9633 | |
| 9634 | if (rval != QLA_SUCCESS) { |
| 9635 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 9636 | "FAILED\n", ha->host_no, __func__); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 9637 | qla4xxx_free_irqs(ha); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9638 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9639 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9640 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9641 | QLA8XXX_DEV_FAILED); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9642 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9643 | } else { |
| 9644 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 9645 | "READY\n", ha->host_no, __func__); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9646 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9647 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9648 | QLA8XXX_DEV_READY); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9649 | /* Clear driver state register */ |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9650 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9651 | qla4_8xxx_set_drv_active(ha); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9652 | ha->isp_ops->idc_unlock(ha); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9653 | ha->isp_ops->enable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9654 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9655 | } else { |
| 9656 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " |
| 9657 | "the reset owner\n", ha->host_no, __func__, |
| 9658 | ha->pdev->devfn); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9659 | if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) == |
| 9660 | QLA8XXX_DEV_READY)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9661 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9662 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9663 | if (rval == QLA_SUCCESS) |
| 9664 | ha->isp_ops->enable_intrs(ha); |
Nilesh Javali | 37418cc | 2013-12-16 06:49:31 -0500 | [diff] [blame] | 9665 | else |
| 9666 | qla4xxx_free_irqs(ha); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9667 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9668 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9669 | qla4_8xxx_set_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9670 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9671 | } |
| 9672 | } |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 9673 | exit_error_recovery: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9674 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 9675 | return rval; |
| 9676 | } |
| 9677 | |
| 9678 | static pci_ers_result_t |
| 9679 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) |
| 9680 | { |
| 9681 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 9682 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9683 | int rc; |
| 9684 | |
| 9685 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", |
| 9686 | ha->host_no, __func__); |
| 9687 | |
| 9688 | if (!is_aer_supported(ha)) |
| 9689 | return PCI_ERS_RESULT_NONE; |
| 9690 | |
| 9691 | /* Restore the saved state of PCIe device - |
| 9692 | * BAR registers, PCI Config space, PCIX, MSI, |
| 9693 | * IOV states |
| 9694 | */ |
| 9695 | pci_restore_state(pdev); |
| 9696 | |
| 9697 | /* pci_restore_state() clears the saved_state flag of the device |
| 9698 | * save restored state which resets saved_state flag |
| 9699 | */ |
| 9700 | pci_save_state(pdev); |
| 9701 | |
| 9702 | /* Initialize device or resume if in suspended state */ |
| 9703 | rc = pci_enable_device(pdev); |
| 9704 | if (rc) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9705 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9706 | "device after reset\n", ha->host_no, __func__); |
| 9707 | goto exit_slot_reset; |
| 9708 | } |
| 9709 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9710 | ha->isp_ops->disable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9711 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9712 | if (is_qla80XX(ha)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9713 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { |
| 9714 | ret = PCI_ERS_RESULT_RECOVERED; |
| 9715 | goto exit_slot_reset; |
| 9716 | } else |
| 9717 | goto exit_slot_reset; |
| 9718 | } |
| 9719 | |
| 9720 | exit_slot_reset: |
| 9721 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" |
| 9722 | "device after reset\n", ha->host_no, __func__, ret); |
| 9723 | return ret; |
| 9724 | } |
| 9725 | |
| 9726 | static void |
| 9727 | qla4xxx_pci_resume(struct pci_dev *pdev) |
| 9728 | { |
| 9729 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9730 | int ret; |
| 9731 | |
| 9732 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", |
| 9733 | ha->host_no, __func__); |
| 9734 | |
| 9735 | ret = qla4xxx_wait_for_hba_online(ha); |
| 9736 | if (ret != QLA_SUCCESS) { |
| 9737 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " |
| 9738 | "resume I/O from slot/link_reset\n", ha->host_no, |
| 9739 | __func__); |
| 9740 | } |
| 9741 | |
| 9742 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9743 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 9744 | } |
| 9745 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 9746 | static const struct pci_error_handlers qla4xxx_err_handler = { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9747 | .error_detected = qla4xxx_pci_error_detected, |
| 9748 | .mmio_enabled = qla4xxx_pci_mmio_enabled, |
| 9749 | .slot_reset = qla4xxx_pci_slot_reset, |
| 9750 | .resume = qla4xxx_pci_resume, |
| 9751 | }; |
| 9752 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9753 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
| 9754 | { |
| 9755 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9756 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, |
| 9757 | .subvendor = PCI_ANY_ID, |
| 9758 | .subdevice = PCI_ANY_ID, |
| 9759 | }, |
| 9760 | { |
| 9761 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9762 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, |
| 9763 | .subvendor = PCI_ANY_ID, |
| 9764 | .subdevice = PCI_ANY_ID, |
| 9765 | }, |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 9766 | { |
| 9767 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9768 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, |
| 9769 | .subvendor = PCI_ANY_ID, |
| 9770 | .subdevice = PCI_ANY_ID, |
| 9771 | }, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9772 | { |
| 9773 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9774 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, |
| 9775 | .subvendor = PCI_ANY_ID, |
| 9776 | .subdevice = PCI_ANY_ID, |
| 9777 | }, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9778 | { |
| 9779 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9780 | .device = PCI_DEVICE_ID_QLOGIC_ISP8324, |
| 9781 | .subvendor = PCI_ANY_ID, |
| 9782 | .subdevice = PCI_ANY_ID, |
| 9783 | }, |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9784 | { |
| 9785 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9786 | .device = PCI_DEVICE_ID_QLOGIC_ISP8042, |
| 9787 | .subvendor = PCI_ANY_ID, |
| 9788 | .subdevice = PCI_ANY_ID, |
| 9789 | }, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9790 | {0, 0}, |
| 9791 | }; |
| 9792 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); |
| 9793 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 9794 | static struct pci_driver qla4xxx_pci_driver = { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9795 | .name = DRIVER_NAME, |
| 9796 | .id_table = qla4xxx_pci_tbl, |
| 9797 | .probe = qla4xxx_probe_adapter, |
| 9798 | .remove = qla4xxx_remove_adapter, |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9799 | .err_handler = &qla4xxx_err_handler, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9800 | }; |
| 9801 | |
| 9802 | static int __init qla4xxx_module_init(void) |
| 9803 | { |
| 9804 | int ret; |
| 9805 | |
| 9806 | /* Allocate cache for SRBs. */ |
| 9807 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 9808 | SLAB_HWCACHE_ALIGN, NULL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9809 | if (srb_cachep == NULL) { |
| 9810 | printk(KERN_ERR |
| 9811 | "%s: Unable to allocate SRB cache..." |
| 9812 | "Failing load!\n", DRIVER_NAME); |
| 9813 | ret = -ENOMEM; |
| 9814 | goto no_srp_cache; |
| 9815 | } |
| 9816 | |
| 9817 | /* Derive version string. */ |
| 9818 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 9819 | if (ql4xextended_error_logging) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9820 | strcat(qla4xxx_version_str, "-debug"); |
| 9821 | |
| 9822 | qla4xxx_scsi_transport = |
| 9823 | iscsi_register_transport(&qla4xxx_iscsi_transport); |
| 9824 | if (!qla4xxx_scsi_transport){ |
| 9825 | ret = -ENODEV; |
| 9826 | goto release_srb_cache; |
| 9827 | } |
| 9828 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9829 | ret = pci_register_driver(&qla4xxx_pci_driver); |
| 9830 | if (ret) |
| 9831 | goto unregister_transport; |
| 9832 | |
| 9833 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); |
| 9834 | return 0; |
Doug Maxey | 5ae16db | 2006-10-05 23:50:07 -0500 | [diff] [blame] | 9835 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9836 | unregister_transport: |
| 9837 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 9838 | release_srb_cache: |
| 9839 | kmem_cache_destroy(srb_cachep); |
| 9840 | no_srp_cache: |
| 9841 | return ret; |
| 9842 | } |
| 9843 | |
| 9844 | static void __exit qla4xxx_module_exit(void) |
| 9845 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9846 | pci_unregister_driver(&qla4xxx_pci_driver); |
| 9847 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 9848 | kmem_cache_destroy(srb_cachep); |
| 9849 | } |
| 9850 | |
| 9851 | module_init(qla4xxx_module_init); |
| 9852 | module_exit(qla4xxx_module_exit); |
| 9853 | |
| 9854 | MODULE_AUTHOR("QLogic Corporation"); |
| 9855 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); |
| 9856 | MODULE_LICENSE("GPL"); |
| 9857 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |