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: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 424 | return S_IRUGO; |
| 425 | default: |
| 426 | return 0; |
| 427 | } |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 428 | case ISCSI_NET_PARAM: |
| 429 | switch (param) { |
| 430 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 431 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 432 | case ISCSI_NET_PARAM_IPV4_GW: |
| 433 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 434 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 435 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 436 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 437 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 438 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 439 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 440 | case ISCSI_NET_PARAM_VLAN_ID: |
| 441 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 442 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 443 | case ISCSI_NET_PARAM_MTU: |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 444 | case ISCSI_NET_PARAM_PORT: |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 445 | case ISCSI_NET_PARAM_IPADDR_STATE: |
| 446 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: |
| 447 | case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: |
| 448 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 449 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 450 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 451 | case ISCSI_NET_PARAM_TCP_WSF: |
| 452 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 453 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 454 | case ISCSI_NET_PARAM_CACHE_ID: |
| 455 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 456 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 457 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 458 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 459 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 460 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 461 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 462 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 463 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 464 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 465 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 466 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 467 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 468 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 469 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 470 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 471 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 472 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 473 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
| 474 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
| 475 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
| 476 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
| 477 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 478 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 479 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 480 | return S_IRUGO; |
| 481 | default: |
| 482 | return 0; |
| 483 | } |
| 484 | case ISCSI_IFACE_PARAM: |
| 485 | switch (param) { |
| 486 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 487 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 488 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 489 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 490 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 491 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 492 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 493 | case ISCSI_IFACE_PARAM_ERL: |
| 494 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 495 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 496 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 497 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 498 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 499 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 500 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 501 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 502 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 503 | case ISCSI_IFACE_PARAM_INITIATOR_NAME: |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 504 | return S_IRUGO; |
| 505 | default: |
| 506 | return 0; |
| 507 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 508 | case ISCSI_FLASHNODE_PARAM: |
| 509 | switch (param) { |
| 510 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 511 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 512 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 513 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 514 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 515 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 516 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 517 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 518 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 519 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 520 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 521 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 522 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 523 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 524 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 525 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 526 | case ISCSI_FLASHNODE_ERL: |
| 527 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 528 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 529 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 530 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 531 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 532 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 533 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 534 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 535 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 536 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 537 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 538 | case ISCSI_FLASHNODE_MAX_R2T: |
| 539 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 540 | case ISCSI_FLASHNODE_ISID: |
| 541 | case ISCSI_FLASHNODE_TSID: |
| 542 | case ISCSI_FLASHNODE_PORT: |
| 543 | case ISCSI_FLASHNODE_MAX_BURST: |
| 544 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 545 | case ISCSI_FLASHNODE_IPADDR: |
| 546 | case ISCSI_FLASHNODE_ALIAS: |
| 547 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 548 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 549 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 550 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 551 | case ISCSI_FLASHNODE_IPV6_TC: |
| 552 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 553 | case ISCSI_FLASHNODE_NAME: |
| 554 | case ISCSI_FLASHNODE_TPGT: |
| 555 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 556 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 557 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 558 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 559 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 560 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 561 | case ISCSI_FLASHNODE_USERNAME: |
| 562 | case ISCSI_FLASHNODE_PASSWORD: |
| 563 | case ISCSI_FLASHNODE_STATSN: |
| 564 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 565 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 566 | return S_IRUGO; |
| 567 | default: |
| 568 | return 0; |
| 569 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 575 | static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha, |
| 576 | int16_t chap_index, |
| 577 | struct ql4_chap_table **chap_entry) |
| 578 | { |
| 579 | int rval = QLA_ERROR; |
| 580 | int max_chap_entries; |
| 581 | |
| 582 | if (!ha->chap_list) { |
| 583 | ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n"); |
| 584 | rval = QLA_ERROR; |
| 585 | goto exit_get_chap; |
| 586 | } |
| 587 | |
| 588 | if (is_qla80XX(ha)) |
| 589 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 590 | sizeof(struct ql4_chap_table); |
| 591 | else |
| 592 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 593 | |
| 594 | if (chap_index > max_chap_entries) { |
| 595 | ql4_printk(KERN_ERR, ha, "Invalid Chap index\n"); |
| 596 | rval = QLA_ERROR; |
| 597 | goto exit_get_chap; |
| 598 | } |
| 599 | |
| 600 | *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index; |
| 601 | if ((*chap_entry)->cookie != |
| 602 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 603 | rval = QLA_ERROR; |
| 604 | *chap_entry = NULL; |
| 605 | } else { |
| 606 | rval = QLA_SUCCESS; |
| 607 | } |
| 608 | |
| 609 | exit_get_chap: |
| 610 | return rval; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * qla4xxx_find_free_chap_index - Find the first free chap index |
| 615 | * @ha: pointer to adapter structure |
| 616 | * @chap_index: CHAP index to be returned |
| 617 | * |
| 618 | * Find the first free chap index available in the chap table |
| 619 | * |
| 620 | * Note: Caller should acquire the chap lock before getting here. |
| 621 | **/ |
| 622 | static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha, |
| 623 | uint16_t *chap_index) |
| 624 | { |
| 625 | int i, rval; |
| 626 | int free_index = -1; |
| 627 | int max_chap_entries = 0; |
| 628 | struct ql4_chap_table *chap_table; |
| 629 | |
| 630 | if (is_qla80XX(ha)) |
| 631 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 632 | sizeof(struct ql4_chap_table); |
| 633 | else |
| 634 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 635 | |
| 636 | if (!ha->chap_list) { |
| 637 | ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n"); |
| 638 | rval = QLA_ERROR; |
| 639 | goto exit_find_chap; |
| 640 | } |
| 641 | |
| 642 | for (i = 0; i < max_chap_entries; i++) { |
| 643 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 644 | |
| 645 | if ((chap_table->cookie != |
| 646 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) && |
| 647 | (i > MAX_RESRV_CHAP_IDX)) { |
| 648 | free_index = i; |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if (free_index != -1) { |
| 654 | *chap_index = free_index; |
| 655 | rval = QLA_SUCCESS; |
| 656 | } else { |
| 657 | rval = QLA_ERROR; |
| 658 | } |
| 659 | |
| 660 | exit_find_chap: |
| 661 | return rval; |
| 662 | } |
| 663 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 664 | static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx, |
| 665 | uint32_t *num_entries, char *buf) |
| 666 | { |
| 667 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 668 | struct ql4_chap_table *chap_table; |
| 669 | struct iscsi_chap_rec *chap_rec; |
| 670 | int max_chap_entries = 0; |
| 671 | int valid_chap_entries = 0; |
| 672 | int ret = 0, i; |
| 673 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 674 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 675 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 676 | sizeof(struct ql4_chap_table); |
| 677 | else |
| 678 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 679 | |
| 680 | ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n", |
| 681 | __func__, *num_entries, chap_tbl_idx); |
| 682 | |
| 683 | if (!buf) { |
| 684 | ret = -ENOMEM; |
| 685 | goto exit_get_chap_list; |
| 686 | } |
| 687 | |
| 688 | chap_rec = (struct iscsi_chap_rec *) buf; |
| 689 | mutex_lock(&ha->chap_sem); |
| 690 | for (i = chap_tbl_idx; i < max_chap_entries; i++) { |
| 691 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 692 | if (chap_table->cookie != |
| 693 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) |
| 694 | continue; |
| 695 | |
| 696 | chap_rec->chap_tbl_idx = i; |
| 697 | strncpy(chap_rec->username, chap_table->name, |
| 698 | ISCSI_CHAP_AUTH_NAME_MAX_LEN); |
| 699 | strncpy(chap_rec->password, chap_table->secret, |
| 700 | QL4_CHAP_MAX_SECRET_LEN); |
| 701 | chap_rec->password_length = chap_table->secret_len; |
| 702 | |
| 703 | if (chap_table->flags & BIT_7) /* local */ |
| 704 | chap_rec->chap_type = CHAP_TYPE_OUT; |
| 705 | |
| 706 | if (chap_table->flags & BIT_6) /* peer */ |
| 707 | chap_rec->chap_type = CHAP_TYPE_IN; |
| 708 | |
| 709 | chap_rec++; |
| 710 | |
| 711 | valid_chap_entries++; |
| 712 | if (valid_chap_entries == *num_entries) |
| 713 | break; |
| 714 | else |
| 715 | continue; |
| 716 | } |
| 717 | mutex_unlock(&ha->chap_sem); |
| 718 | |
| 719 | exit_get_chap_list: |
| 720 | ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n", |
| 721 | __func__, valid_chap_entries); |
| 722 | *num_entries = valid_chap_entries; |
| 723 | return ret; |
| 724 | } |
| 725 | |
| 726 | static int __qla4xxx_is_chap_active(struct device *dev, void *data) |
| 727 | { |
| 728 | int ret = 0; |
| 729 | uint16_t *chap_tbl_idx = (uint16_t *) data; |
| 730 | struct iscsi_cls_session *cls_session; |
| 731 | struct iscsi_session *sess; |
| 732 | struct ddb_entry *ddb_entry; |
| 733 | |
| 734 | if (!iscsi_is_session_dev(dev)) |
| 735 | goto exit_is_chap_active; |
| 736 | |
| 737 | cls_session = iscsi_dev_to_session(dev); |
| 738 | sess = cls_session->dd_data; |
| 739 | ddb_entry = sess->dd_data; |
| 740 | |
| 741 | if (iscsi_session_chkready(cls_session)) |
| 742 | goto exit_is_chap_active; |
| 743 | |
| 744 | if (ddb_entry->chap_tbl_idx == *chap_tbl_idx) |
| 745 | ret = 1; |
| 746 | |
| 747 | exit_is_chap_active: |
| 748 | return ret; |
| 749 | } |
| 750 | |
| 751 | static int qla4xxx_is_chap_active(struct Scsi_Host *shost, |
| 752 | uint16_t chap_tbl_idx) |
| 753 | { |
| 754 | int ret = 0; |
| 755 | |
| 756 | ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx, |
| 757 | __qla4xxx_is_chap_active); |
| 758 | |
| 759 | return ret; |
| 760 | } |
| 761 | |
| 762 | static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx) |
| 763 | { |
| 764 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 765 | struct ql4_chap_table *chap_table; |
| 766 | dma_addr_t chap_dma; |
| 767 | int max_chap_entries = 0; |
| 768 | uint32_t offset = 0; |
| 769 | uint32_t chap_size; |
| 770 | int ret = 0; |
| 771 | |
| 772 | chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma); |
| 773 | if (chap_table == NULL) |
| 774 | return -ENOMEM; |
| 775 | |
| 776 | memset(chap_table, 0, sizeof(struct ql4_chap_table)); |
| 777 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 778 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 779 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 780 | sizeof(struct ql4_chap_table); |
| 781 | else |
| 782 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 783 | |
| 784 | if (chap_tbl_idx > max_chap_entries) { |
| 785 | ret = -EINVAL; |
| 786 | goto exit_delete_chap; |
| 787 | } |
| 788 | |
| 789 | /* Check if chap index is in use. |
| 790 | * If chap is in use don't delet chap entry */ |
| 791 | ret = qla4xxx_is_chap_active(shost, chap_tbl_idx); |
| 792 | if (ret) { |
| 793 | ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot " |
| 794 | "delete from flash\n", chap_tbl_idx); |
| 795 | ret = -EBUSY; |
| 796 | goto exit_delete_chap; |
| 797 | } |
| 798 | |
| 799 | chap_size = sizeof(struct ql4_chap_table); |
| 800 | if (is_qla40XX(ha)) |
| 801 | offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size); |
| 802 | else { |
| 803 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 804 | /* flt_chap_size is CHAP table size for both ports |
| 805 | * so divide it by 2 to calculate the offset for second port |
| 806 | */ |
| 807 | if (ha->port_num == 1) |
| 808 | offset += (ha->hw.flt_chap_size / 2); |
| 809 | offset += (chap_tbl_idx * chap_size); |
| 810 | } |
| 811 | |
| 812 | ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 813 | if (ret != QLA_SUCCESS) { |
| 814 | ret = -EINVAL; |
| 815 | goto exit_delete_chap; |
| 816 | } |
| 817 | |
| 818 | DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n", |
| 819 | __le16_to_cpu(chap_table->cookie))); |
| 820 | |
| 821 | if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) { |
| 822 | ql4_printk(KERN_ERR, ha, "No valid chap entry found\n"); |
| 823 | goto exit_delete_chap; |
| 824 | } |
| 825 | |
| 826 | chap_table->cookie = __constant_cpu_to_le16(0xFFFF); |
| 827 | |
| 828 | offset = FLASH_CHAP_OFFSET | |
| 829 | (chap_tbl_idx * sizeof(struct ql4_chap_table)); |
| 830 | ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size, |
| 831 | FLASH_OPT_RMW_COMMIT); |
| 832 | if (ret == QLA_SUCCESS && ha->chap_list) { |
| 833 | mutex_lock(&ha->chap_sem); |
| 834 | /* Update ha chap_list cache */ |
| 835 | memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx, |
| 836 | chap_table, sizeof(struct ql4_chap_table)); |
| 837 | mutex_unlock(&ha->chap_sem); |
| 838 | } |
| 839 | if (ret != QLA_SUCCESS) |
| 840 | ret = -EINVAL; |
| 841 | |
| 842 | exit_delete_chap: |
| 843 | dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma); |
| 844 | return ret; |
| 845 | } |
| 846 | |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 847 | /** |
| 848 | * qla4xxx_set_chap_entry - Make chap entry with given information |
| 849 | * @shost: pointer to host |
| 850 | * @data: chap info - credentials, index and type to make chap entry |
| 851 | * @len: length of data |
| 852 | * |
| 853 | * Add or update chap entry with the given information |
| 854 | **/ |
| 855 | static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len) |
| 856 | { |
| 857 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 858 | struct iscsi_chap_rec chap_rec; |
| 859 | struct ql4_chap_table *chap_entry = NULL; |
| 860 | struct iscsi_param_info *param_info; |
| 861 | struct nlattr *attr; |
| 862 | int max_chap_entries = 0; |
| 863 | int type; |
| 864 | int rem = len; |
| 865 | int rc = 0; |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 866 | int size; |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 867 | |
| 868 | memset(&chap_rec, 0, sizeof(chap_rec)); |
| 869 | |
| 870 | nla_for_each_attr(attr, data, len, rem) { |
| 871 | param_info = nla_data(attr); |
| 872 | |
| 873 | switch (param_info->param) { |
| 874 | case ISCSI_CHAP_PARAM_INDEX: |
| 875 | chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value; |
| 876 | break; |
| 877 | case ISCSI_CHAP_PARAM_CHAP_TYPE: |
| 878 | chap_rec.chap_type = param_info->value[0]; |
| 879 | break; |
| 880 | case ISCSI_CHAP_PARAM_USERNAME: |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 881 | size = min_t(size_t, sizeof(chap_rec.username), |
| 882 | param_info->len); |
| 883 | memcpy(chap_rec.username, param_info->value, size); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 884 | break; |
| 885 | case ISCSI_CHAP_PARAM_PASSWORD: |
Dan Carpenter | 3c60cfd | 2013-11-13 10:48:11 +0300 | [diff] [blame] | 886 | size = min_t(size_t, sizeof(chap_rec.password), |
| 887 | param_info->len); |
| 888 | memcpy(chap_rec.password, param_info->value, size); |
Adheer Chandravanshi | 26ffd7b | 2013-09-17 07:54:49 -0400 | [diff] [blame] | 889 | break; |
| 890 | case ISCSI_CHAP_PARAM_PASSWORD_LEN: |
| 891 | chap_rec.password_length = param_info->value[0]; |
| 892 | break; |
| 893 | default: |
| 894 | ql4_printk(KERN_ERR, ha, |
| 895 | "%s: No such sysfs attribute\n", __func__); |
| 896 | rc = -ENOSYS; |
| 897 | goto exit_set_chap; |
| 898 | }; |
| 899 | } |
| 900 | |
| 901 | if (chap_rec.chap_type == CHAP_TYPE_IN) |
| 902 | type = BIDI_CHAP; |
| 903 | else |
| 904 | type = LOCAL_CHAP; |
| 905 | |
| 906 | if (is_qla80XX(ha)) |
| 907 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 908 | sizeof(struct ql4_chap_table); |
| 909 | else |
| 910 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 911 | |
| 912 | mutex_lock(&ha->chap_sem); |
| 913 | if (chap_rec.chap_tbl_idx < max_chap_entries) { |
| 914 | rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx, |
| 915 | &chap_entry); |
| 916 | if (!rc) { |
| 917 | if (!(type == qla4xxx_get_chap_type(chap_entry))) { |
| 918 | ql4_printk(KERN_INFO, ha, |
| 919 | "Type mismatch for CHAP entry %d\n", |
| 920 | chap_rec.chap_tbl_idx); |
| 921 | rc = -EINVAL; |
| 922 | goto exit_unlock_chap; |
| 923 | } |
| 924 | |
| 925 | /* If chap index is in use then don't modify it */ |
| 926 | rc = qla4xxx_is_chap_active(shost, |
| 927 | chap_rec.chap_tbl_idx); |
| 928 | if (rc) { |
| 929 | ql4_printk(KERN_INFO, ha, |
| 930 | "CHAP entry %d is in use\n", |
| 931 | chap_rec.chap_tbl_idx); |
| 932 | rc = -EBUSY; |
| 933 | goto exit_unlock_chap; |
| 934 | } |
| 935 | } |
| 936 | } else { |
| 937 | rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx); |
| 938 | if (rc) { |
| 939 | ql4_printk(KERN_INFO, ha, "CHAP entry not available\n"); |
| 940 | rc = -EBUSY; |
| 941 | goto exit_unlock_chap; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password, |
| 946 | chap_rec.chap_tbl_idx, type); |
| 947 | |
| 948 | exit_unlock_chap: |
| 949 | mutex_unlock(&ha->chap_sem); |
| 950 | |
| 951 | exit_set_chap: |
| 952 | return rc; |
| 953 | } |
| 954 | |
Lalit Chandivade | 4161cee | 2013-11-22 05:28:19 -0500 | [diff] [blame^] | 955 | |
| 956 | static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len) |
| 957 | { |
| 958 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 959 | struct iscsi_offload_host_stats *host_stats = NULL; |
| 960 | int host_stats_size; |
| 961 | int ret = 0; |
| 962 | int ddb_idx = 0; |
| 963 | struct ql_iscsi_stats *ql_iscsi_stats = NULL; |
| 964 | int stats_size; |
| 965 | dma_addr_t iscsi_stats_dma; |
| 966 | |
| 967 | DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__)); |
| 968 | |
| 969 | host_stats_size = sizeof(struct iscsi_offload_host_stats); |
| 970 | |
| 971 | if (host_stats_size != len) { |
| 972 | ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n", |
| 973 | __func__, len, host_stats_size); |
| 974 | ret = -EINVAL; |
| 975 | goto exit_host_stats; |
| 976 | } |
| 977 | host_stats = (struct iscsi_offload_host_stats *)buf; |
| 978 | |
| 979 | if (!buf) { |
| 980 | ret = -ENOMEM; |
| 981 | goto exit_host_stats; |
| 982 | } |
| 983 | |
| 984 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 985 | |
| 986 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 987 | &iscsi_stats_dma, GFP_KERNEL); |
| 988 | if (!ql_iscsi_stats) { |
| 989 | ql4_printk(KERN_ERR, ha, |
| 990 | "Unable to allocate memory for iscsi stats\n"); |
| 991 | goto exit_host_stats; |
| 992 | } |
| 993 | |
| 994 | ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size, |
| 995 | iscsi_stats_dma); |
| 996 | if (ret != QLA_SUCCESS) { |
| 997 | ql4_printk(KERN_ERR, ha, |
| 998 | "Unable to retrieve iscsi stats\n"); |
| 999 | goto exit_host_stats; |
| 1000 | } |
| 1001 | host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames); |
| 1002 | host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes); |
| 1003 | host_stats->mactx_multicast_frames = |
| 1004 | le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames); |
| 1005 | host_stats->mactx_broadcast_frames = |
| 1006 | le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames); |
| 1007 | host_stats->mactx_pause_frames = |
| 1008 | le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames); |
| 1009 | host_stats->mactx_control_frames = |
| 1010 | le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames); |
| 1011 | host_stats->mactx_deferral = |
| 1012 | le64_to_cpu(ql_iscsi_stats->mac_tx_deferral); |
| 1013 | host_stats->mactx_excess_deferral = |
| 1014 | le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral); |
| 1015 | host_stats->mactx_late_collision = |
| 1016 | le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision); |
| 1017 | host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort); |
| 1018 | host_stats->mactx_single_collision = |
| 1019 | le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision); |
| 1020 | host_stats->mactx_multiple_collision = |
| 1021 | le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision); |
| 1022 | host_stats->mactx_collision = |
| 1023 | le64_to_cpu(ql_iscsi_stats->mac_tx_collision); |
| 1024 | host_stats->mactx_frames_dropped = |
| 1025 | le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped); |
| 1026 | host_stats->mactx_jumbo_frames = |
| 1027 | le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames); |
| 1028 | host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames); |
| 1029 | host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes); |
| 1030 | host_stats->macrx_unknown_control_frames = |
| 1031 | le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames); |
| 1032 | host_stats->macrx_pause_frames = |
| 1033 | le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames); |
| 1034 | host_stats->macrx_control_frames = |
| 1035 | le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames); |
| 1036 | host_stats->macrx_dribble = |
| 1037 | le64_to_cpu(ql_iscsi_stats->mac_rx_dribble); |
| 1038 | host_stats->macrx_frame_length_error = |
| 1039 | le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error); |
| 1040 | host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber); |
| 1041 | host_stats->macrx_carrier_sense_error = |
| 1042 | le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error); |
| 1043 | host_stats->macrx_frame_discarded = |
| 1044 | le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded); |
| 1045 | host_stats->macrx_frames_dropped = |
| 1046 | le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped); |
| 1047 | host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error); |
| 1048 | host_stats->mac_encoding_error = |
| 1049 | le64_to_cpu(ql_iscsi_stats->mac_encoding_error); |
| 1050 | host_stats->macrx_length_error_large = |
| 1051 | le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large); |
| 1052 | host_stats->macrx_length_error_small = |
| 1053 | le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small); |
| 1054 | host_stats->macrx_multicast_frames = |
| 1055 | le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames); |
| 1056 | host_stats->macrx_broadcast_frames = |
| 1057 | le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames); |
| 1058 | host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets); |
| 1059 | host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes); |
| 1060 | host_stats->iptx_fragments = |
| 1061 | le64_to_cpu(ql_iscsi_stats->ip_tx_fragments); |
| 1062 | host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets); |
| 1063 | host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes); |
| 1064 | host_stats->iprx_fragments = |
| 1065 | le64_to_cpu(ql_iscsi_stats->ip_rx_fragments); |
| 1066 | host_stats->ip_datagram_reassembly = |
| 1067 | le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly); |
| 1068 | host_stats->ip_invalid_address_error = |
| 1069 | le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error); |
| 1070 | host_stats->ip_error_packets = |
| 1071 | le64_to_cpu(ql_iscsi_stats->ip_error_packets); |
| 1072 | host_stats->ip_fragrx_overlap = |
| 1073 | le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap); |
| 1074 | host_stats->ip_fragrx_outoforder = |
| 1075 | le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder); |
| 1076 | host_stats->ip_datagram_reassembly_timeout = |
| 1077 | le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout); |
| 1078 | host_stats->ipv6tx_packets = |
| 1079 | le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets); |
| 1080 | host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes); |
| 1081 | host_stats->ipv6tx_fragments = |
| 1082 | le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments); |
| 1083 | host_stats->ipv6rx_packets = |
| 1084 | le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets); |
| 1085 | host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes); |
| 1086 | host_stats->ipv6rx_fragments = |
| 1087 | le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments); |
| 1088 | host_stats->ipv6_datagram_reassembly = |
| 1089 | le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly); |
| 1090 | host_stats->ipv6_invalid_address_error = |
| 1091 | le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error); |
| 1092 | host_stats->ipv6_error_packets = |
| 1093 | le64_to_cpu(ql_iscsi_stats->ipv6_error_packets); |
| 1094 | host_stats->ipv6_fragrx_overlap = |
| 1095 | le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap); |
| 1096 | host_stats->ipv6_fragrx_outoforder = |
| 1097 | le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder); |
| 1098 | host_stats->ipv6_datagram_reassembly_timeout = |
| 1099 | le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout); |
| 1100 | host_stats->tcptx_segments = |
| 1101 | le64_to_cpu(ql_iscsi_stats->tcp_tx_segments); |
| 1102 | host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes); |
| 1103 | host_stats->tcprx_segments = |
| 1104 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segments); |
| 1105 | host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte); |
| 1106 | host_stats->tcp_duplicate_ack_retx = |
| 1107 | le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx); |
| 1108 | host_stats->tcp_retx_timer_expired = |
| 1109 | le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired); |
| 1110 | host_stats->tcprx_duplicate_ack = |
| 1111 | le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack); |
| 1112 | host_stats->tcprx_pure_ackr = |
| 1113 | le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr); |
| 1114 | host_stats->tcptx_delayed_ack = |
| 1115 | le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack); |
| 1116 | host_stats->tcptx_pure_ack = |
| 1117 | le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack); |
| 1118 | host_stats->tcprx_segment_error = |
| 1119 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error); |
| 1120 | host_stats->tcprx_segment_outoforder = |
| 1121 | le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder); |
| 1122 | host_stats->tcprx_window_probe = |
| 1123 | le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe); |
| 1124 | host_stats->tcprx_window_update = |
| 1125 | le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update); |
| 1126 | host_stats->tcptx_window_probe_persist = |
| 1127 | le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist); |
| 1128 | host_stats->ecc_error_correction = |
| 1129 | le64_to_cpu(ql_iscsi_stats->ecc_error_correction); |
| 1130 | host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx); |
| 1131 | host_stats->iscsi_data_bytes_tx = |
| 1132 | le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx); |
| 1133 | host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx); |
| 1134 | host_stats->iscsi_data_bytes_rx = |
| 1135 | le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx); |
| 1136 | host_stats->iscsi_io_completed = |
| 1137 | le64_to_cpu(ql_iscsi_stats->iscsi_io_completed); |
| 1138 | host_stats->iscsi_unexpected_io_rx = |
| 1139 | le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx); |
| 1140 | host_stats->iscsi_format_error = |
| 1141 | le64_to_cpu(ql_iscsi_stats->iscsi_format_error); |
| 1142 | host_stats->iscsi_hdr_digest_error = |
| 1143 | le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error); |
| 1144 | host_stats->iscsi_data_digest_error = |
| 1145 | le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error); |
| 1146 | host_stats->iscsi_sequence_error = |
| 1147 | le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error); |
| 1148 | exit_host_stats: |
| 1149 | if (ql_iscsi_stats) |
| 1150 | dma_free_coherent(&ha->pdev->dev, host_stats_size, |
| 1151 | ql_iscsi_stats, iscsi_stats_dma); |
| 1152 | |
| 1153 | ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n", |
| 1154 | __func__); |
| 1155 | return ret; |
| 1156 | } |
| 1157 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1158 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 1159 | enum iscsi_param_type param_type, |
| 1160 | int param, char *buf) |
| 1161 | { |
| 1162 | struct Scsi_Host *shost = iscsi_iface_to_shost(iface); |
| 1163 | struct scsi_qla_host *ha = to_qla_host(shost); |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1164 | int ival; |
| 1165 | char *pval = NULL; |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1166 | int len = -ENOSYS; |
| 1167 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1168 | if (param_type == ISCSI_NET_PARAM) { |
| 1169 | switch (param) { |
| 1170 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 1171 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| 1172 | break; |
| 1173 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 1174 | len = sprintf(buf, "%pI4\n", |
| 1175 | &ha->ip_config.subnet_mask); |
| 1176 | break; |
| 1177 | case ISCSI_NET_PARAM_IPV4_GW: |
| 1178 | len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); |
| 1179 | break; |
| 1180 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 1181 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1182 | OP_STATE(ha->ip_config.ipv4_options, |
| 1183 | IPOPT_IPV4_PROTOCOL_ENABLE, pval); |
| 1184 | } else { |
| 1185 | OP_STATE(ha->ip_config.ipv6_options, |
| 1186 | IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval); |
| 1187 | } |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1188 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1189 | len = sprintf(buf, "%s\n", pval); |
| 1190 | break; |
| 1191 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1192 | len = sprintf(buf, "%s\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1193 | (ha->ip_config.tcp_options & |
| 1194 | TCPOPT_DHCP_ENABLE) ? |
| 1195 | "dhcp" : "static"); |
| 1196 | break; |
| 1197 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 1198 | if (iface->iface_num == 0) |
| 1199 | len = sprintf(buf, "%pI6\n", |
| 1200 | &ha->ip_config.ipv6_addr0); |
| 1201 | if (iface->iface_num == 1) |
| 1202 | len = sprintf(buf, "%pI6\n", |
| 1203 | &ha->ip_config.ipv6_addr1); |
| 1204 | break; |
| 1205 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 1206 | len = sprintf(buf, "%pI6\n", |
| 1207 | &ha->ip_config.ipv6_link_local_addr); |
| 1208 | break; |
| 1209 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 1210 | len = sprintf(buf, "%pI6\n", |
| 1211 | &ha->ip_config.ipv6_default_router_addr); |
| 1212 | break; |
| 1213 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 1214 | pval = (ha->ip_config.ipv6_addl_options & |
| 1215 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? |
| 1216 | "nd" : "static"; |
| 1217 | |
| 1218 | len = sprintf(buf, "%s\n", pval); |
| 1219 | break; |
| 1220 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 1221 | pval = (ha->ip_config.ipv6_addl_options & |
| 1222 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? |
| 1223 | "auto" : "static"; |
| 1224 | |
| 1225 | len = sprintf(buf, "%s\n", pval); |
| 1226 | break; |
| 1227 | case ISCSI_NET_PARAM_VLAN_ID: |
| 1228 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1229 | ival = ha->ip_config.ipv4_vlan_tag & |
| 1230 | ISCSI_MAX_VLAN_ID; |
| 1231 | else |
| 1232 | ival = ha->ip_config.ipv6_vlan_tag & |
| 1233 | ISCSI_MAX_VLAN_ID; |
| 1234 | |
| 1235 | len = sprintf(buf, "%d\n", ival); |
| 1236 | break; |
| 1237 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 1238 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1239 | ival = (ha->ip_config.ipv4_vlan_tag >> 13) & |
| 1240 | ISCSI_MAX_VLAN_PRIORITY; |
| 1241 | else |
| 1242 | ival = (ha->ip_config.ipv6_vlan_tag >> 13) & |
| 1243 | ISCSI_MAX_VLAN_PRIORITY; |
| 1244 | |
| 1245 | len = sprintf(buf, "%d\n", ival); |
| 1246 | break; |
| 1247 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 1248 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1249 | OP_STATE(ha->ip_config.ipv4_options, |
| 1250 | IPOPT_VLAN_TAGGING_ENABLE, pval); |
| 1251 | } else { |
| 1252 | OP_STATE(ha->ip_config.ipv6_options, |
| 1253 | IPV6_OPT_VLAN_TAGGING_ENABLE, pval); |
| 1254 | } |
| 1255 | len = sprintf(buf, "%s\n", pval); |
| 1256 | break; |
| 1257 | case ISCSI_NET_PARAM_MTU: |
| 1258 | len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size); |
| 1259 | break; |
| 1260 | case ISCSI_NET_PARAM_PORT: |
| 1261 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1262 | len = sprintf(buf, "%d\n", |
| 1263 | ha->ip_config.ipv4_port); |
| 1264 | else |
| 1265 | len = sprintf(buf, "%d\n", |
| 1266 | ha->ip_config.ipv6_port); |
| 1267 | break; |
| 1268 | case ISCSI_NET_PARAM_IPADDR_STATE: |
| 1269 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1270 | pval = iscsi_get_ipaddress_state_name( |
| 1271 | ha->ip_config.ipv4_addr_state); |
| 1272 | } else { |
| 1273 | if (iface->iface_num == 0) |
| 1274 | pval = iscsi_get_ipaddress_state_name( |
| 1275 | ha->ip_config.ipv6_addr0_state); |
| 1276 | else if (iface->iface_num == 1) |
| 1277 | pval = iscsi_get_ipaddress_state_name( |
| 1278 | ha->ip_config.ipv6_addr1_state); |
| 1279 | } |
| 1280 | |
| 1281 | len = sprintf(buf, "%s\n", pval); |
| 1282 | break; |
| 1283 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: |
| 1284 | pval = iscsi_get_ipaddress_state_name( |
| 1285 | ha->ip_config.ipv6_link_local_state); |
| 1286 | len = sprintf(buf, "%s\n", pval); |
| 1287 | break; |
| 1288 | case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: |
| 1289 | pval = iscsi_get_router_state_name( |
| 1290 | ha->ip_config.ipv6_default_router_state); |
| 1291 | len = sprintf(buf, "%s\n", pval); |
| 1292 | break; |
| 1293 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 1294 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1295 | OP_STATE(~ha->ip_config.tcp_options, |
| 1296 | TCPOPT_DELAYED_ACK_DISABLE, pval); |
| 1297 | } else { |
| 1298 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1299 | IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval); |
| 1300 | } |
| 1301 | len = sprintf(buf, "%s\n", pval); |
| 1302 | break; |
| 1303 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 1304 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1305 | OP_STATE(~ha->ip_config.tcp_options, |
| 1306 | TCPOPT_NAGLE_ALGO_DISABLE, pval); |
| 1307 | } else { |
| 1308 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1309 | IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval); |
| 1310 | } |
| 1311 | len = sprintf(buf, "%s\n", pval); |
| 1312 | break; |
| 1313 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 1314 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1315 | OP_STATE(~ha->ip_config.tcp_options, |
| 1316 | TCPOPT_WINDOW_SCALE_DISABLE, pval); |
| 1317 | } else { |
| 1318 | OP_STATE(~ha->ip_config.ipv6_tcp_options, |
| 1319 | IPV6_TCPOPT_WINDOW_SCALE_DISABLE, |
| 1320 | pval); |
| 1321 | } |
| 1322 | len = sprintf(buf, "%s\n", pval); |
| 1323 | break; |
| 1324 | case ISCSI_NET_PARAM_TCP_WSF: |
| 1325 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1326 | len = sprintf(buf, "%d\n", |
| 1327 | ha->ip_config.tcp_wsf); |
| 1328 | else |
| 1329 | len = sprintf(buf, "%d\n", |
| 1330 | ha->ip_config.ipv6_tcp_wsf); |
| 1331 | break; |
| 1332 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 1333 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1334 | ival = (ha->ip_config.tcp_options & |
| 1335 | TCPOPT_TIMER_SCALE) >> 1; |
| 1336 | else |
| 1337 | ival = (ha->ip_config.ipv6_tcp_options & |
| 1338 | IPV6_TCPOPT_TIMER_SCALE) >> 1; |
| 1339 | |
| 1340 | len = sprintf(buf, "%d\n", ival); |
| 1341 | break; |
| 1342 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 1343 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1344 | OP_STATE(ha->ip_config.tcp_options, |
| 1345 | TCPOPT_TIMESTAMP_ENABLE, pval); |
| 1346 | } else { |
| 1347 | OP_STATE(ha->ip_config.ipv6_tcp_options, |
| 1348 | IPV6_TCPOPT_TIMESTAMP_EN, pval); |
| 1349 | } |
| 1350 | len = sprintf(buf, "%s\n", pval); |
| 1351 | break; |
| 1352 | case ISCSI_NET_PARAM_CACHE_ID: |
| 1353 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 1354 | len = sprintf(buf, "%d\n", |
| 1355 | ha->ip_config.ipv4_cache_id); |
| 1356 | else |
| 1357 | len = sprintf(buf, "%d\n", |
| 1358 | ha->ip_config.ipv6_cache_id); |
| 1359 | break; |
| 1360 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 1361 | OP_STATE(ha->ip_config.tcp_options, |
| 1362 | TCPOPT_DNS_SERVER_IP_EN, pval); |
| 1363 | |
| 1364 | len = sprintf(buf, "%s\n", pval); |
| 1365 | break; |
| 1366 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 1367 | OP_STATE(ha->ip_config.tcp_options, |
| 1368 | TCPOPT_SLP_DA_INFO_EN, pval); |
| 1369 | |
| 1370 | len = sprintf(buf, "%s\n", pval); |
| 1371 | break; |
| 1372 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 1373 | OP_STATE(ha->ip_config.ipv4_options, |
| 1374 | IPOPT_IPV4_TOS_EN, pval); |
| 1375 | |
| 1376 | len = sprintf(buf, "%s\n", pval); |
| 1377 | break; |
| 1378 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 1379 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos); |
| 1380 | break; |
| 1381 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 1382 | OP_STATE(ha->ip_config.ipv4_options, |
| 1383 | IPOPT_GRAT_ARP_EN, pval); |
| 1384 | |
| 1385 | len = sprintf(buf, "%s\n", pval); |
| 1386 | break; |
| 1387 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 1388 | OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN, |
| 1389 | pval); |
| 1390 | |
| 1391 | len = sprintf(buf, "%s\n", pval); |
| 1392 | break; |
| 1393 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 1394 | pval = (ha->ip_config.ipv4_alt_cid_len) ? |
| 1395 | (char *)ha->ip_config.ipv4_alt_cid : ""; |
| 1396 | |
| 1397 | len = sprintf(buf, "%s\n", pval); |
| 1398 | break; |
| 1399 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 1400 | OP_STATE(ha->ip_config.ipv4_options, |
| 1401 | IPOPT_REQ_VID_EN, pval); |
| 1402 | |
| 1403 | len = sprintf(buf, "%s\n", pval); |
| 1404 | break; |
| 1405 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 1406 | OP_STATE(ha->ip_config.ipv4_options, |
| 1407 | IPOPT_USE_VID_EN, pval); |
| 1408 | |
| 1409 | len = sprintf(buf, "%s\n", pval); |
| 1410 | break; |
| 1411 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 1412 | pval = (ha->ip_config.ipv4_vid_len) ? |
| 1413 | (char *)ha->ip_config.ipv4_vid : ""; |
| 1414 | |
| 1415 | len = sprintf(buf, "%s\n", pval); |
| 1416 | break; |
| 1417 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 1418 | OP_STATE(ha->ip_config.ipv4_options, |
| 1419 | IPOPT_LEARN_IQN_EN, pval); |
| 1420 | |
| 1421 | len = sprintf(buf, "%s\n", pval); |
| 1422 | break; |
| 1423 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 1424 | OP_STATE(~ha->ip_config.ipv4_options, |
| 1425 | IPOPT_FRAGMENTATION_DISABLE, pval); |
| 1426 | |
| 1427 | len = sprintf(buf, "%s\n", pval); |
| 1428 | break; |
| 1429 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 1430 | OP_STATE(ha->ip_config.ipv4_options, |
| 1431 | IPOPT_IN_FORWARD_EN, pval); |
| 1432 | |
| 1433 | len = sprintf(buf, "%s\n", pval); |
| 1434 | break; |
| 1435 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 1436 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
| 1437 | OP_STATE(ha->ip_config.ipv4_options, |
| 1438 | IPOPT_ARP_REDIRECT_EN, pval); |
| 1439 | } else { |
| 1440 | OP_STATE(ha->ip_config.ipv6_options, |
| 1441 | IPV6_OPT_REDIRECT_EN, pval); |
| 1442 | } |
| 1443 | len = sprintf(buf, "%s\n", pval); |
| 1444 | break; |
| 1445 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 1446 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl); |
| 1447 | break; |
| 1448 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 1449 | OP_STATE(ha->ip_config.ipv6_options, |
| 1450 | IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval); |
| 1451 | |
| 1452 | len = sprintf(buf, "%s\n", pval); |
| 1453 | break; |
| 1454 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 1455 | OP_STATE(ha->ip_config.ipv6_addl_options, |
| 1456 | IPV6_ADDOPT_MLD_EN, pval); |
| 1457 | |
| 1458 | len = sprintf(buf, "%s\n", pval); |
| 1459 | break; |
| 1460 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 1461 | len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl); |
| 1462 | break; |
| 1463 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1464 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1465 | ha->ip_config.ipv6_traffic_class); |
| 1466 | break; |
| 1467 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1468 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1469 | ha->ip_config.ipv6_hop_limit); |
| 1470 | break; |
| 1471 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1472 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1473 | ha->ip_config.ipv6_nd_reach_time); |
| 1474 | break; |
| 1475 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1476 | len = sprintf(buf, "%d\n", |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1477 | ha->ip_config.ipv6_nd_rexmit_timer); |
| 1478 | break; |
| 1479 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 1480 | len = sprintf(buf, "%d\n", |
| 1481 | ha->ip_config.ipv6_nd_stale_timeout); |
| 1482 | break; |
| 1483 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 1484 | len = sprintf(buf, "%d\n", |
| 1485 | ha->ip_config.ipv6_dup_addr_detect_count); |
| 1486 | break; |
| 1487 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 1488 | len = sprintf(buf, "%d\n", |
| 1489 | ha->ip_config.ipv6_gw_advrt_mtu); |
| 1490 | break; |
| 1491 | default: |
| 1492 | len = -ENOSYS; |
| 1493 | } |
| 1494 | } else if (param_type == ISCSI_IFACE_PARAM) { |
| 1495 | switch (param) { |
| 1496 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 1497 | len = sprintf(buf, "%d\n", ha->ip_config.def_timeout); |
| 1498 | break; |
| 1499 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 1500 | OP_STATE(ha->ip_config.iscsi_options, |
| 1501 | ISCSIOPTS_HEADER_DIGEST_EN, pval); |
| 1502 | |
| 1503 | len = sprintf(buf, "%s\n", pval); |
| 1504 | break; |
| 1505 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 1506 | OP_STATE(ha->ip_config.iscsi_options, |
| 1507 | ISCSIOPTS_DATA_DIGEST_EN, pval); |
| 1508 | |
| 1509 | len = sprintf(buf, "%s\n", pval); |
| 1510 | break; |
| 1511 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 1512 | OP_STATE(ha->ip_config.iscsi_options, |
| 1513 | ISCSIOPTS_IMMEDIATE_DATA_EN, pval); |
| 1514 | |
| 1515 | len = sprintf(buf, "%s\n", pval); |
| 1516 | break; |
| 1517 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 1518 | OP_STATE(ha->ip_config.iscsi_options, |
| 1519 | ISCSIOPTS_INITIAL_R2T_EN, pval); |
| 1520 | |
| 1521 | len = sprintf(buf, "%s\n", pval); |
| 1522 | break; |
| 1523 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 1524 | OP_STATE(ha->ip_config.iscsi_options, |
| 1525 | ISCSIOPTS_DATA_SEQ_INORDER_EN, pval); |
| 1526 | |
| 1527 | len = sprintf(buf, "%s\n", pval); |
| 1528 | break; |
| 1529 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 1530 | OP_STATE(ha->ip_config.iscsi_options, |
| 1531 | ISCSIOPTS_DATA_PDU_INORDER_EN, pval); |
| 1532 | |
| 1533 | len = sprintf(buf, "%s\n", pval); |
| 1534 | break; |
| 1535 | case ISCSI_IFACE_PARAM_ERL: |
| 1536 | len = sprintf(buf, "%d\n", |
| 1537 | (ha->ip_config.iscsi_options & |
| 1538 | ISCSIOPTS_ERL)); |
| 1539 | break; |
| 1540 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 1541 | len = sprintf(buf, "%u\n", |
| 1542 | ha->ip_config.iscsi_max_pdu_size * |
| 1543 | BYTE_UNITS); |
| 1544 | break; |
| 1545 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 1546 | len = sprintf(buf, "%u\n", |
| 1547 | ha->ip_config.iscsi_first_burst_len * |
| 1548 | BYTE_UNITS); |
| 1549 | break; |
| 1550 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 1551 | len = sprintf(buf, "%d\n", |
| 1552 | ha->ip_config.iscsi_max_outstnd_r2t); |
| 1553 | break; |
| 1554 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 1555 | len = sprintf(buf, "%u\n", |
| 1556 | ha->ip_config.iscsi_max_burst_len * |
| 1557 | BYTE_UNITS); |
| 1558 | break; |
| 1559 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 1560 | OP_STATE(ha->ip_config.iscsi_options, |
| 1561 | ISCSIOPTS_CHAP_AUTH_EN, pval); |
| 1562 | |
| 1563 | len = sprintf(buf, "%s\n", pval); |
| 1564 | break; |
| 1565 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 1566 | OP_STATE(ha->ip_config.iscsi_options, |
| 1567 | ISCSIOPTS_BIDI_CHAP_EN, pval); |
| 1568 | |
| 1569 | len = sprintf(buf, "%s\n", pval); |
| 1570 | break; |
| 1571 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 1572 | OP_STATE(ha->ip_config.iscsi_options, |
| 1573 | ISCSIOPTS_DISCOVERY_AUTH_EN, pval); |
| 1574 | |
| 1575 | len = sprintf(buf, "%s\n", pval); |
| 1576 | break; |
| 1577 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 1578 | OP_STATE(ha->ip_config.iscsi_options, |
| 1579 | ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval); |
| 1580 | |
| 1581 | len = sprintf(buf, "%s\n", pval); |
| 1582 | break; |
| 1583 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 1584 | OP_STATE(ha->ip_config.iscsi_options, |
| 1585 | ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval); |
| 1586 | |
| 1587 | len = sprintf(buf, "%s\n", pval); |
| 1588 | break; |
| 1589 | case ISCSI_IFACE_PARAM_INITIATOR_NAME: |
| 1590 | len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name); |
| 1591 | break; |
| 1592 | default: |
| 1593 | len = -ENOSYS; |
| 1594 | } |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | return len; |
| 1598 | } |
| 1599 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1600 | static struct iscsi_endpoint * |
| 1601 | qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, |
| 1602 | int non_blocking) |
| 1603 | { |
| 1604 | int ret; |
| 1605 | struct iscsi_endpoint *ep; |
| 1606 | struct qla_endpoint *qla_ep; |
| 1607 | struct scsi_qla_host *ha; |
| 1608 | struct sockaddr_in *addr; |
| 1609 | struct sockaddr_in6 *addr6; |
| 1610 | |
| 1611 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1612 | if (!shost) { |
| 1613 | ret = -ENXIO; |
| 1614 | printk(KERN_ERR "%s: shost is NULL\n", |
| 1615 | __func__); |
| 1616 | return ERR_PTR(ret); |
| 1617 | } |
| 1618 | |
| 1619 | ha = iscsi_host_priv(shost); |
| 1620 | |
| 1621 | ep = iscsi_create_endpoint(sizeof(struct qla_endpoint)); |
| 1622 | if (!ep) { |
| 1623 | ret = -ENOMEM; |
| 1624 | return ERR_PTR(ret); |
| 1625 | } |
| 1626 | |
| 1627 | qla_ep = ep->dd_data; |
| 1628 | memset(qla_ep, 0, sizeof(struct qla_endpoint)); |
| 1629 | if (dst_addr->sa_family == AF_INET) { |
| 1630 | memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in)); |
| 1631 | addr = (struct sockaddr_in *)&qla_ep->dst_addr; |
| 1632 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__, |
| 1633 | (char *)&addr->sin_addr)); |
| 1634 | } else if (dst_addr->sa_family == AF_INET6) { |
| 1635 | memcpy(&qla_ep->dst_addr, dst_addr, |
| 1636 | sizeof(struct sockaddr_in6)); |
| 1637 | addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr; |
| 1638 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__, |
| 1639 | (char *)&addr6->sin6_addr)); |
| 1640 | } |
| 1641 | |
| 1642 | qla_ep->host = shost; |
| 1643 | |
| 1644 | return ep; |
| 1645 | } |
| 1646 | |
| 1647 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) |
| 1648 | { |
| 1649 | struct qla_endpoint *qla_ep; |
| 1650 | struct scsi_qla_host *ha; |
| 1651 | int ret = 0; |
| 1652 | |
| 1653 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1654 | qla_ep = ep->dd_data; |
| 1655 | ha = to_qla_host(qla_ep->host); |
| 1656 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1657 | if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags)) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1658 | ret = 1; |
| 1659 | |
| 1660 | return ret; |
| 1661 | } |
| 1662 | |
| 1663 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep) |
| 1664 | { |
| 1665 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1666 | iscsi_destroy_endpoint(ep); |
| 1667 | } |
| 1668 | |
| 1669 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 1670 | enum iscsi_param param, |
| 1671 | char *buf) |
| 1672 | { |
| 1673 | struct qla_endpoint *qla_ep = ep->dd_data; |
| 1674 | struct sockaddr *dst_addr; |
| 1675 | |
| 1676 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1677 | |
| 1678 | switch (param) { |
| 1679 | case ISCSI_PARAM_CONN_PORT: |
| 1680 | case ISCSI_PARAM_CONN_ADDRESS: |
| 1681 | if (!qla_ep) |
| 1682 | return -ENOTCONN; |
| 1683 | |
| 1684 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 1685 | if (!dst_addr) |
| 1686 | return -ENOTCONN; |
| 1687 | |
| 1688 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 1689 | &qla_ep->dst_addr, param, buf); |
| 1690 | default: |
| 1691 | return -ENOSYS; |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 1696 | struct iscsi_stats *stats) |
| 1697 | { |
| 1698 | struct iscsi_session *sess; |
| 1699 | struct iscsi_cls_session *cls_sess; |
| 1700 | struct ddb_entry *ddb_entry; |
| 1701 | struct scsi_qla_host *ha; |
| 1702 | struct ql_iscsi_stats *ql_iscsi_stats; |
| 1703 | int stats_size; |
| 1704 | int ret; |
| 1705 | dma_addr_t iscsi_stats_dma; |
| 1706 | |
| 1707 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1708 | |
| 1709 | cls_sess = iscsi_conn_to_session(cls_conn); |
| 1710 | sess = cls_sess->dd_data; |
| 1711 | ddb_entry = sess->dd_data; |
| 1712 | ha = ddb_entry->ha; |
| 1713 | |
| 1714 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 1715 | /* Allocate memory */ |
| 1716 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 1717 | &iscsi_stats_dma, GFP_KERNEL); |
| 1718 | if (!ql_iscsi_stats) { |
| 1719 | ql4_printk(KERN_ERR, ha, |
| 1720 | "Unable to allocate memory for iscsi stats\n"); |
| 1721 | goto exit_get_stats; |
| 1722 | } |
| 1723 | |
| 1724 | ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size, |
| 1725 | iscsi_stats_dma); |
| 1726 | if (ret != QLA_SUCCESS) { |
| 1727 | ql4_printk(KERN_ERR, ha, |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 1728 | "Unable to retrieve iscsi stats\n"); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1729 | goto free_stats; |
| 1730 | } |
| 1731 | |
| 1732 | /* octets */ |
| 1733 | stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets); |
| 1734 | stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets); |
| 1735 | /* xmit pdus */ |
| 1736 | stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus); |
| 1737 | stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus); |
| 1738 | stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus); |
| 1739 | stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus); |
| 1740 | stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus); |
| 1741 | stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus); |
| 1742 | stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus); |
| 1743 | stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus); |
| 1744 | /* recv pdus */ |
| 1745 | stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus); |
| 1746 | stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus); |
| 1747 | stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus); |
| 1748 | stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus); |
| 1749 | stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus); |
| 1750 | stats->logoutrsp_pdus = |
| 1751 | le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus); |
| 1752 | stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus); |
| 1753 | stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus); |
| 1754 | stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus); |
| 1755 | |
| 1756 | free_stats: |
| 1757 | dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats, |
| 1758 | iscsi_stats_dma); |
| 1759 | exit_get_stats: |
| 1760 | return; |
| 1761 | } |
| 1762 | |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1763 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| 1764 | { |
| 1765 | struct iscsi_cls_session *session; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1766 | struct iscsi_session *sess; |
| 1767 | unsigned long flags; |
| 1768 | enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1769 | |
| 1770 | session = starget_to_session(scsi_target(sc->device)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1771 | sess = session->dd_data; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1772 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1773 | spin_lock_irqsave(&session->lock, flags); |
| 1774 | if (session->state == ISCSI_SESSION_FAILED) |
| 1775 | ret = BLK_EH_RESET_TIMER; |
| 1776 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 1777 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1778 | return ret; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1781 | static void qla4xxx_set_port_speed(struct Scsi_Host *shost) |
| 1782 | { |
| 1783 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 1784 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1785 | uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN; |
| 1786 | |
| 1787 | qla4xxx_get_firmware_state(ha); |
| 1788 | |
| 1789 | switch (ha->addl_fw_state & 0x0F00) { |
| 1790 | case FW_ADDSTATE_LINK_SPEED_10MBPS: |
| 1791 | speed = ISCSI_PORT_SPEED_10MBPS; |
| 1792 | break; |
| 1793 | case FW_ADDSTATE_LINK_SPEED_100MBPS: |
| 1794 | speed = ISCSI_PORT_SPEED_100MBPS; |
| 1795 | break; |
| 1796 | case FW_ADDSTATE_LINK_SPEED_1GBPS: |
| 1797 | speed = ISCSI_PORT_SPEED_1GBPS; |
| 1798 | break; |
| 1799 | case FW_ADDSTATE_LINK_SPEED_10GBPS: |
| 1800 | speed = ISCSI_PORT_SPEED_10GBPS; |
| 1801 | break; |
| 1802 | } |
| 1803 | ihost->port_speed = speed; |
| 1804 | } |
| 1805 | |
| 1806 | static void qla4xxx_set_port_state(struct Scsi_Host *shost) |
| 1807 | { |
| 1808 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 1809 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1810 | uint32_t state = ISCSI_PORT_STATE_DOWN; |
| 1811 | |
| 1812 | if (test_bit(AF_LINK_UP, &ha->flags)) |
| 1813 | state = ISCSI_PORT_STATE_UP; |
| 1814 | |
| 1815 | ihost->port_state = state; |
| 1816 | } |
| 1817 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1818 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 1819 | enum iscsi_host_param param, char *buf) |
| 1820 | { |
| 1821 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 1822 | int len; |
| 1823 | |
| 1824 | switch (param) { |
| 1825 | case ISCSI_HOST_PARAM_HWADDRESS: |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 1826 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1827 | break; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1828 | case ISCSI_HOST_PARAM_IPADDRESS: |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 1829 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1830 | break; |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1831 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1832 | len = sprintf(buf, "%s\n", ha->name_string); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1833 | break; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1834 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 1835 | qla4xxx_set_port_state(shost); |
| 1836 | len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost)); |
| 1837 | break; |
| 1838 | case ISCSI_HOST_PARAM_PORT_SPEED: |
| 1839 | qla4xxx_set_port_speed(shost); |
| 1840 | len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost)); |
| 1841 | break; |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1842 | default: |
| 1843 | return -ENOSYS; |
| 1844 | } |
| 1845 | |
| 1846 | return len; |
| 1847 | } |
| 1848 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1849 | static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
| 1850 | { |
| 1851 | if (ha->iface_ipv4) |
| 1852 | return; |
| 1853 | |
| 1854 | /* IPv4 */ |
| 1855 | ha->iface_ipv4 = iscsi_create_iface(ha->host, |
| 1856 | &qla4xxx_iscsi_transport, |
| 1857 | ISCSI_IFACE_TYPE_IPV4, 0, 0); |
| 1858 | if (!ha->iface_ipv4) |
| 1859 | ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " |
| 1860 | "iface0.\n"); |
| 1861 | } |
| 1862 | |
| 1863 | static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) |
| 1864 | { |
| 1865 | if (!ha->iface_ipv6_0) |
| 1866 | /* IPv6 iface-0 */ |
| 1867 | ha->iface_ipv6_0 = iscsi_create_iface(ha->host, |
| 1868 | &qla4xxx_iscsi_transport, |
| 1869 | ISCSI_IFACE_TYPE_IPV6, 0, |
| 1870 | 0); |
| 1871 | if (!ha->iface_ipv6_0) |
| 1872 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1873 | "iface0.\n"); |
| 1874 | |
| 1875 | if (!ha->iface_ipv6_1) |
| 1876 | /* IPv6 iface-1 */ |
| 1877 | ha->iface_ipv6_1 = iscsi_create_iface(ha->host, |
| 1878 | &qla4xxx_iscsi_transport, |
| 1879 | ISCSI_IFACE_TYPE_IPV6, 1, |
| 1880 | 0); |
| 1881 | if (!ha->iface_ipv6_1) |
| 1882 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1883 | "iface1.\n"); |
| 1884 | } |
| 1885 | |
| 1886 | static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) |
| 1887 | { |
| 1888 | if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) |
| 1889 | qla4xxx_create_ipv4_iface(ha); |
| 1890 | |
| 1891 | if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) |
| 1892 | qla4xxx_create_ipv6_iface(ha); |
| 1893 | } |
| 1894 | |
| 1895 | static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) |
| 1896 | { |
| 1897 | if (ha->iface_ipv4) { |
| 1898 | iscsi_destroy_iface(ha->iface_ipv4); |
| 1899 | ha->iface_ipv4 = NULL; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) |
| 1904 | { |
| 1905 | if (ha->iface_ipv6_0) { |
| 1906 | iscsi_destroy_iface(ha->iface_ipv6_0); |
| 1907 | ha->iface_ipv6_0 = NULL; |
| 1908 | } |
| 1909 | if (ha->iface_ipv6_1) { |
| 1910 | iscsi_destroy_iface(ha->iface_ipv6_1); |
| 1911 | ha->iface_ipv6_1 = NULL; |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) |
| 1916 | { |
| 1917 | qla4xxx_destroy_ipv4_iface(ha); |
| 1918 | qla4xxx_destroy_ipv6_iface(ha); |
| 1919 | } |
| 1920 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1921 | static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
| 1922 | struct iscsi_iface_param_info *iface_param, |
| 1923 | struct addr_ctrl_blk *init_fw_cb) |
| 1924 | { |
| 1925 | /* |
| 1926 | * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. |
| 1927 | * iface_num 1 is valid only for IPv6 Addr. |
| 1928 | */ |
| 1929 | switch (iface_param->param) { |
| 1930 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 1931 | if (iface_param->iface_num & 0x1) |
| 1932 | /* IPv6 Addr 1 */ |
| 1933 | memcpy(init_fw_cb->ipv6_addr1, iface_param->value, |
| 1934 | sizeof(init_fw_cb->ipv6_addr1)); |
| 1935 | else |
| 1936 | /* IPv6 Addr 0 */ |
| 1937 | memcpy(init_fw_cb->ipv6_addr0, iface_param->value, |
| 1938 | sizeof(init_fw_cb->ipv6_addr0)); |
| 1939 | break; |
| 1940 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 1941 | if (iface_param->iface_num & 0x1) |
| 1942 | break; |
| 1943 | memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], |
| 1944 | sizeof(init_fw_cb->ipv6_if_id)); |
| 1945 | break; |
| 1946 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 1947 | if (iface_param->iface_num & 0x1) |
| 1948 | break; |
| 1949 | memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, |
| 1950 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 1951 | break; |
| 1952 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 1953 | /* Autocfg applies to even interface */ |
| 1954 | if (iface_param->iface_num & 0x1) |
| 1955 | break; |
| 1956 | |
| 1957 | if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) |
| 1958 | init_fw_cb->ipv6_addtl_opts &= |
| 1959 | cpu_to_le16( |
| 1960 | ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 1961 | else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) |
| 1962 | init_fw_cb->ipv6_addtl_opts |= |
| 1963 | cpu_to_le16( |
| 1964 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 1965 | else |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1966 | ql4_printk(KERN_ERR, ha, |
| 1967 | "Invalid autocfg setting for IPv6 addr\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1968 | break; |
| 1969 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 1970 | /* Autocfg applies to even interface */ |
| 1971 | if (iface_param->iface_num & 0x1) |
| 1972 | break; |
| 1973 | |
| 1974 | if (iface_param->value[0] == |
| 1975 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) |
| 1976 | init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( |
| 1977 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 1978 | else if (iface_param->value[0] == |
| 1979 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) |
| 1980 | init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( |
| 1981 | ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 1982 | else |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 1983 | ql4_printk(KERN_ERR, ha, |
| 1984 | "Invalid autocfg setting for IPv6 linklocal addr\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1985 | break; |
| 1986 | case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: |
| 1987 | /* Autocfg applies to even interface */ |
| 1988 | if (iface_param->iface_num & 0x1) |
| 1989 | break; |
| 1990 | |
| 1991 | if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) |
| 1992 | memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, |
| 1993 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 1994 | break; |
| 1995 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1996 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1997 | init_fw_cb->ipv6_opts |= |
| 1998 | cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1999 | qla4xxx_create_ipv6_iface(ha); |
| 2000 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2001 | init_fw_cb->ipv6_opts &= |
| 2002 | cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & |
| 2003 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2004 | qla4xxx_destroy_ipv6_iface(ha); |
| 2005 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2006 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 2007 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2008 | if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) |
| 2009 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 2010 | init_fw_cb->ipv6_vlan_tag = |
| 2011 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 2012 | break; |
| 2013 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 2014 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 2015 | init_fw_cb->ipv6_opts |= |
| 2016 | cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE); |
| 2017 | else |
| 2018 | init_fw_cb->ipv6_opts &= |
| 2019 | cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2020 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 2021 | case ISCSI_NET_PARAM_MTU: |
| 2022 | init_fw_cb->eth_mtu_size = |
| 2023 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2024 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 2025 | case ISCSI_NET_PARAM_PORT: |
| 2026 | /* Autocfg applies to even interface */ |
| 2027 | if (iface_param->iface_num & 0x1) |
| 2028 | break; |
| 2029 | |
| 2030 | init_fw_cb->ipv6_port = |
| 2031 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2032 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2033 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 2034 | if (iface_param->iface_num & 0x1) |
| 2035 | break; |
| 2036 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2037 | init_fw_cb->ipv6_tcp_opts |= |
| 2038 | cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE); |
| 2039 | else |
| 2040 | init_fw_cb->ipv6_tcp_opts &= |
| 2041 | cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE); |
| 2042 | break; |
| 2043 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 2044 | if (iface_param->iface_num & 0x1) |
| 2045 | break; |
| 2046 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2047 | init_fw_cb->ipv6_tcp_opts |= |
| 2048 | cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE); |
| 2049 | else |
| 2050 | init_fw_cb->ipv6_tcp_opts &= |
| 2051 | cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE); |
| 2052 | break; |
| 2053 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 2054 | if (iface_param->iface_num & 0x1) |
| 2055 | break; |
| 2056 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2057 | init_fw_cb->ipv6_tcp_opts |= |
| 2058 | cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE); |
| 2059 | else |
| 2060 | init_fw_cb->ipv6_tcp_opts &= |
| 2061 | cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE); |
| 2062 | break; |
| 2063 | case ISCSI_NET_PARAM_TCP_WSF: |
| 2064 | if (iface_param->iface_num & 0x1) |
| 2065 | break; |
| 2066 | init_fw_cb->ipv6_tcp_wsf = iface_param->value[0]; |
| 2067 | break; |
| 2068 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 2069 | if (iface_param->iface_num & 0x1) |
| 2070 | break; |
| 2071 | init_fw_cb->ipv6_tcp_opts &= |
| 2072 | cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE); |
| 2073 | init_fw_cb->ipv6_tcp_opts |= |
| 2074 | cpu_to_le16((iface_param->value[0] << 1) & |
| 2075 | IPV6_TCPOPT_TIMER_SCALE); |
| 2076 | break; |
| 2077 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 2078 | if (iface_param->iface_num & 0x1) |
| 2079 | break; |
| 2080 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2081 | init_fw_cb->ipv6_tcp_opts |= |
| 2082 | cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN); |
| 2083 | else |
| 2084 | init_fw_cb->ipv6_tcp_opts &= |
| 2085 | cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN); |
| 2086 | break; |
| 2087 | case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: |
| 2088 | if (iface_param->iface_num & 0x1) |
| 2089 | break; |
| 2090 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2091 | init_fw_cb->ipv6_opts |= |
| 2092 | cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN); |
| 2093 | else |
| 2094 | init_fw_cb->ipv6_opts &= |
| 2095 | cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN); |
| 2096 | break; |
| 2097 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 2098 | if (iface_param->iface_num & 0x1) |
| 2099 | break; |
| 2100 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2101 | init_fw_cb->ipv6_opts |= |
| 2102 | cpu_to_le16(IPV6_OPT_REDIRECT_EN); |
| 2103 | else |
| 2104 | init_fw_cb->ipv6_opts &= |
| 2105 | cpu_to_le16(~IPV6_OPT_REDIRECT_EN); |
| 2106 | break; |
| 2107 | case ISCSI_NET_PARAM_IPV6_MLD_EN: |
| 2108 | if (iface_param->iface_num & 0x1) |
| 2109 | break; |
| 2110 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2111 | init_fw_cb->ipv6_addtl_opts |= |
| 2112 | cpu_to_le16(IPV6_ADDOPT_MLD_EN); |
| 2113 | else |
| 2114 | init_fw_cb->ipv6_addtl_opts &= |
| 2115 | cpu_to_le16(~IPV6_ADDOPT_MLD_EN); |
| 2116 | break; |
| 2117 | case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: |
| 2118 | if (iface_param->iface_num & 0x1) |
| 2119 | break; |
| 2120 | init_fw_cb->ipv6_flow_lbl = |
| 2121 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2122 | break; |
| 2123 | case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: |
| 2124 | if (iface_param->iface_num & 0x1) |
| 2125 | break; |
| 2126 | init_fw_cb->ipv6_traffic_class = iface_param->value[0]; |
| 2127 | break; |
| 2128 | case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: |
| 2129 | if (iface_param->iface_num & 0x1) |
| 2130 | break; |
| 2131 | init_fw_cb->ipv6_hop_limit = iface_param->value[0]; |
| 2132 | break; |
| 2133 | case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: |
| 2134 | if (iface_param->iface_num & 0x1) |
| 2135 | break; |
| 2136 | init_fw_cb->ipv6_nd_reach_time = |
| 2137 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2138 | break; |
| 2139 | case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: |
| 2140 | if (iface_param->iface_num & 0x1) |
| 2141 | break; |
| 2142 | init_fw_cb->ipv6_nd_rexmit_timer = |
| 2143 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2144 | break; |
| 2145 | case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: |
| 2146 | if (iface_param->iface_num & 0x1) |
| 2147 | break; |
| 2148 | init_fw_cb->ipv6_nd_stale_timeout = |
| 2149 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2150 | break; |
| 2151 | case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: |
| 2152 | if (iface_param->iface_num & 0x1) |
| 2153 | break; |
| 2154 | init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0]; |
| 2155 | break; |
| 2156 | case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: |
| 2157 | if (iface_param->iface_num & 0x1) |
| 2158 | break; |
| 2159 | init_fw_cb->ipv6_gw_advrt_mtu = |
| 2160 | cpu_to_le32(*(uint32_t *)iface_param->value); |
| 2161 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2162 | default: |
| 2163 | ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", |
| 2164 | iface_param->param); |
| 2165 | break; |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, |
| 2170 | struct iscsi_iface_param_info *iface_param, |
| 2171 | struct addr_ctrl_blk *init_fw_cb) |
| 2172 | { |
| 2173 | switch (iface_param->param) { |
| 2174 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 2175 | memcpy(init_fw_cb->ipv4_addr, iface_param->value, |
| 2176 | sizeof(init_fw_cb->ipv4_addr)); |
| 2177 | break; |
| 2178 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 2179 | memcpy(init_fw_cb->ipv4_subnet, iface_param->value, |
| 2180 | sizeof(init_fw_cb->ipv4_subnet)); |
| 2181 | break; |
| 2182 | case ISCSI_NET_PARAM_IPV4_GW: |
| 2183 | memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, |
| 2184 | sizeof(init_fw_cb->ipv4_gw_addr)); |
| 2185 | break; |
| 2186 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 2187 | if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) |
| 2188 | init_fw_cb->ipv4_tcp_opts |= |
| 2189 | cpu_to_le16(TCPOPT_DHCP_ENABLE); |
| 2190 | else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) |
| 2191 | init_fw_cb->ipv4_tcp_opts &= |
| 2192 | cpu_to_le16(~TCPOPT_DHCP_ENABLE); |
| 2193 | else |
| 2194 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); |
| 2195 | break; |
| 2196 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2197 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2198 | init_fw_cb->ipv4_ip_opts |= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 2199 | cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2200 | qla4xxx_create_ipv4_iface(ha); |
| 2201 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2202 | init_fw_cb->ipv4_ip_opts &= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 2203 | cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2204 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 2205 | qla4xxx_destroy_ipv4_iface(ha); |
| 2206 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2207 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 2208 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2209 | if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) |
| 2210 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 2211 | init_fw_cb->ipv4_vlan_tag = |
| 2212 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 2213 | break; |
| 2214 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 2215 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 2216 | init_fw_cb->ipv4_ip_opts |= |
| 2217 | cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE); |
| 2218 | else |
| 2219 | init_fw_cb->ipv4_ip_opts &= |
| 2220 | cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2221 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 2222 | case ISCSI_NET_PARAM_MTU: |
| 2223 | init_fw_cb->eth_mtu_size = |
| 2224 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2225 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 2226 | case ISCSI_NET_PARAM_PORT: |
| 2227 | init_fw_cb->ipv4_port = |
| 2228 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2229 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2230 | case ISCSI_NET_PARAM_DELAYED_ACK_EN: |
| 2231 | if (iface_param->iface_num & 0x1) |
| 2232 | break; |
| 2233 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2234 | init_fw_cb->ipv4_tcp_opts |= |
| 2235 | cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE); |
| 2236 | else |
| 2237 | init_fw_cb->ipv4_tcp_opts &= |
| 2238 | cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE); |
| 2239 | break; |
| 2240 | case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: |
| 2241 | if (iface_param->iface_num & 0x1) |
| 2242 | break; |
| 2243 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2244 | init_fw_cb->ipv4_tcp_opts |= |
| 2245 | cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE); |
| 2246 | else |
| 2247 | init_fw_cb->ipv4_tcp_opts &= |
| 2248 | cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE); |
| 2249 | break; |
| 2250 | case ISCSI_NET_PARAM_TCP_WSF_DISABLE: |
| 2251 | if (iface_param->iface_num & 0x1) |
| 2252 | break; |
| 2253 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2254 | init_fw_cb->ipv4_tcp_opts |= |
| 2255 | cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE); |
| 2256 | else |
| 2257 | init_fw_cb->ipv4_tcp_opts &= |
| 2258 | cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE); |
| 2259 | break; |
| 2260 | case ISCSI_NET_PARAM_TCP_WSF: |
| 2261 | if (iface_param->iface_num & 0x1) |
| 2262 | break; |
| 2263 | init_fw_cb->ipv4_tcp_wsf = iface_param->value[0]; |
| 2264 | break; |
| 2265 | case ISCSI_NET_PARAM_TCP_TIMER_SCALE: |
| 2266 | if (iface_param->iface_num & 0x1) |
| 2267 | break; |
| 2268 | init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE); |
| 2269 | init_fw_cb->ipv4_tcp_opts |= |
| 2270 | cpu_to_le16((iface_param->value[0] << 1) & |
| 2271 | TCPOPT_TIMER_SCALE); |
| 2272 | break; |
| 2273 | case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: |
| 2274 | if (iface_param->iface_num & 0x1) |
| 2275 | break; |
| 2276 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2277 | init_fw_cb->ipv4_tcp_opts |= |
| 2278 | cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE); |
| 2279 | else |
| 2280 | init_fw_cb->ipv4_tcp_opts &= |
| 2281 | cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE); |
| 2282 | break; |
| 2283 | case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: |
| 2284 | if (iface_param->iface_num & 0x1) |
| 2285 | break; |
| 2286 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2287 | init_fw_cb->ipv4_tcp_opts |= |
| 2288 | cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN); |
| 2289 | else |
| 2290 | init_fw_cb->ipv4_tcp_opts &= |
| 2291 | cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN); |
| 2292 | break; |
| 2293 | case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: |
| 2294 | if (iface_param->iface_num & 0x1) |
| 2295 | break; |
| 2296 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2297 | init_fw_cb->ipv4_tcp_opts |= |
| 2298 | cpu_to_le16(TCPOPT_SLP_DA_INFO_EN); |
| 2299 | else |
| 2300 | init_fw_cb->ipv4_tcp_opts &= |
| 2301 | cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN); |
| 2302 | break; |
| 2303 | case ISCSI_NET_PARAM_IPV4_TOS_EN: |
| 2304 | if (iface_param->iface_num & 0x1) |
| 2305 | break; |
| 2306 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2307 | init_fw_cb->ipv4_ip_opts |= |
| 2308 | cpu_to_le16(IPOPT_IPV4_TOS_EN); |
| 2309 | else |
| 2310 | init_fw_cb->ipv4_ip_opts &= |
| 2311 | cpu_to_le16(~IPOPT_IPV4_TOS_EN); |
| 2312 | break; |
| 2313 | case ISCSI_NET_PARAM_IPV4_TOS: |
| 2314 | if (iface_param->iface_num & 0x1) |
| 2315 | break; |
| 2316 | init_fw_cb->ipv4_tos = iface_param->value[0]; |
| 2317 | break; |
| 2318 | case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: |
| 2319 | if (iface_param->iface_num & 0x1) |
| 2320 | break; |
| 2321 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2322 | init_fw_cb->ipv4_ip_opts |= |
| 2323 | cpu_to_le16(IPOPT_GRAT_ARP_EN); |
| 2324 | else |
| 2325 | init_fw_cb->ipv4_ip_opts &= |
| 2326 | cpu_to_le16(~IPOPT_GRAT_ARP_EN); |
| 2327 | break; |
| 2328 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: |
| 2329 | if (iface_param->iface_num & 0x1) |
| 2330 | break; |
| 2331 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2332 | init_fw_cb->ipv4_ip_opts |= |
| 2333 | cpu_to_le16(IPOPT_ALT_CID_EN); |
| 2334 | else |
| 2335 | init_fw_cb->ipv4_ip_opts &= |
| 2336 | cpu_to_le16(~IPOPT_ALT_CID_EN); |
| 2337 | break; |
| 2338 | case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: |
| 2339 | if (iface_param->iface_num & 0x1) |
| 2340 | break; |
| 2341 | memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value, |
| 2342 | (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1)); |
| 2343 | init_fw_cb->ipv4_dhcp_alt_cid_len = |
| 2344 | strlen(init_fw_cb->ipv4_dhcp_alt_cid); |
| 2345 | break; |
| 2346 | case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: |
| 2347 | if (iface_param->iface_num & 0x1) |
| 2348 | break; |
| 2349 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2350 | init_fw_cb->ipv4_ip_opts |= |
| 2351 | cpu_to_le16(IPOPT_REQ_VID_EN); |
| 2352 | else |
| 2353 | init_fw_cb->ipv4_ip_opts &= |
| 2354 | cpu_to_le16(~IPOPT_REQ_VID_EN); |
| 2355 | break; |
| 2356 | case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: |
| 2357 | if (iface_param->iface_num & 0x1) |
| 2358 | break; |
| 2359 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2360 | init_fw_cb->ipv4_ip_opts |= |
| 2361 | cpu_to_le16(IPOPT_USE_VID_EN); |
| 2362 | else |
| 2363 | init_fw_cb->ipv4_ip_opts &= |
| 2364 | cpu_to_le16(~IPOPT_USE_VID_EN); |
| 2365 | break; |
| 2366 | case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: |
| 2367 | if (iface_param->iface_num & 0x1) |
| 2368 | break; |
| 2369 | memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value, |
| 2370 | (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1)); |
| 2371 | init_fw_cb->ipv4_dhcp_vid_len = |
| 2372 | strlen(init_fw_cb->ipv4_dhcp_vid); |
| 2373 | break; |
| 2374 | case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: |
| 2375 | if (iface_param->iface_num & 0x1) |
| 2376 | break; |
| 2377 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2378 | init_fw_cb->ipv4_ip_opts |= |
| 2379 | cpu_to_le16(IPOPT_LEARN_IQN_EN); |
| 2380 | else |
| 2381 | init_fw_cb->ipv4_ip_opts &= |
| 2382 | cpu_to_le16(~IPOPT_LEARN_IQN_EN); |
| 2383 | break; |
| 2384 | case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: |
| 2385 | if (iface_param->iface_num & 0x1) |
| 2386 | break; |
| 2387 | if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE) |
| 2388 | init_fw_cb->ipv4_ip_opts |= |
| 2389 | cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE); |
| 2390 | else |
| 2391 | init_fw_cb->ipv4_ip_opts &= |
| 2392 | cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE); |
| 2393 | break; |
| 2394 | case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: |
| 2395 | if (iface_param->iface_num & 0x1) |
| 2396 | break; |
| 2397 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2398 | init_fw_cb->ipv4_ip_opts |= |
| 2399 | cpu_to_le16(IPOPT_IN_FORWARD_EN); |
| 2400 | else |
| 2401 | init_fw_cb->ipv4_ip_opts &= |
| 2402 | cpu_to_le16(~IPOPT_IN_FORWARD_EN); |
| 2403 | break; |
| 2404 | case ISCSI_NET_PARAM_REDIRECT_EN: |
| 2405 | if (iface_param->iface_num & 0x1) |
| 2406 | break; |
| 2407 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2408 | init_fw_cb->ipv4_ip_opts |= |
| 2409 | cpu_to_le16(IPOPT_ARP_REDIRECT_EN); |
| 2410 | else |
| 2411 | init_fw_cb->ipv4_ip_opts &= |
| 2412 | cpu_to_le16(~IPOPT_ARP_REDIRECT_EN); |
| 2413 | break; |
| 2414 | case ISCSI_NET_PARAM_IPV4_TTL: |
| 2415 | if (iface_param->iface_num & 0x1) |
| 2416 | break; |
| 2417 | init_fw_cb->ipv4_ttl = iface_param->value[0]; |
| 2418 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2419 | default: |
| 2420 | ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", |
| 2421 | iface_param->param); |
| 2422 | break; |
| 2423 | } |
| 2424 | } |
| 2425 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2426 | static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha, |
| 2427 | struct iscsi_iface_param_info *iface_param, |
| 2428 | struct addr_ctrl_blk *init_fw_cb) |
| 2429 | { |
| 2430 | switch (iface_param->param) { |
| 2431 | case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: |
| 2432 | if (iface_param->iface_num & 0x1) |
| 2433 | break; |
| 2434 | init_fw_cb->def_timeout = |
| 2435 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2436 | break; |
| 2437 | case ISCSI_IFACE_PARAM_HDRDGST_EN: |
| 2438 | if (iface_param->iface_num & 0x1) |
| 2439 | break; |
| 2440 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2441 | init_fw_cb->iscsi_opts |= |
| 2442 | cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN); |
| 2443 | else |
| 2444 | init_fw_cb->iscsi_opts &= |
| 2445 | cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN); |
| 2446 | break; |
| 2447 | case ISCSI_IFACE_PARAM_DATADGST_EN: |
| 2448 | if (iface_param->iface_num & 0x1) |
| 2449 | break; |
| 2450 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2451 | init_fw_cb->iscsi_opts |= |
| 2452 | cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN); |
| 2453 | else |
| 2454 | init_fw_cb->iscsi_opts &= |
| 2455 | cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN); |
| 2456 | break; |
| 2457 | case ISCSI_IFACE_PARAM_IMM_DATA_EN: |
| 2458 | if (iface_param->iface_num & 0x1) |
| 2459 | break; |
| 2460 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2461 | init_fw_cb->iscsi_opts |= |
| 2462 | cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN); |
| 2463 | else |
| 2464 | init_fw_cb->iscsi_opts &= |
| 2465 | cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN); |
| 2466 | break; |
| 2467 | case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: |
| 2468 | if (iface_param->iface_num & 0x1) |
| 2469 | break; |
| 2470 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2471 | init_fw_cb->iscsi_opts |= |
| 2472 | cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN); |
| 2473 | else |
| 2474 | init_fw_cb->iscsi_opts &= |
| 2475 | cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN); |
| 2476 | break; |
| 2477 | case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: |
| 2478 | if (iface_param->iface_num & 0x1) |
| 2479 | break; |
| 2480 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2481 | init_fw_cb->iscsi_opts |= |
| 2482 | cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN); |
| 2483 | else |
| 2484 | init_fw_cb->iscsi_opts &= |
| 2485 | cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN); |
| 2486 | break; |
| 2487 | case ISCSI_IFACE_PARAM_PDU_INORDER_EN: |
| 2488 | if (iface_param->iface_num & 0x1) |
| 2489 | break; |
| 2490 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2491 | init_fw_cb->iscsi_opts |= |
| 2492 | cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN); |
| 2493 | else |
| 2494 | init_fw_cb->iscsi_opts &= |
| 2495 | cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN); |
| 2496 | break; |
| 2497 | case ISCSI_IFACE_PARAM_ERL: |
| 2498 | if (iface_param->iface_num & 0x1) |
| 2499 | break; |
| 2500 | init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL); |
| 2501 | init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] & |
| 2502 | ISCSIOPTS_ERL); |
| 2503 | break; |
| 2504 | case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: |
| 2505 | if (iface_param->iface_num & 0x1) |
| 2506 | break; |
| 2507 | init_fw_cb->iscsi_max_pdu_size = |
| 2508 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2509 | BYTE_UNITS; |
| 2510 | break; |
| 2511 | case ISCSI_IFACE_PARAM_FIRST_BURST: |
| 2512 | if (iface_param->iface_num & 0x1) |
| 2513 | break; |
| 2514 | init_fw_cb->iscsi_fburst_len = |
| 2515 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2516 | BYTE_UNITS; |
| 2517 | break; |
| 2518 | case ISCSI_IFACE_PARAM_MAX_R2T: |
| 2519 | if (iface_param->iface_num & 0x1) |
| 2520 | break; |
| 2521 | init_fw_cb->iscsi_max_outstnd_r2t = |
| 2522 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 2523 | break; |
| 2524 | case ISCSI_IFACE_PARAM_MAX_BURST: |
| 2525 | if (iface_param->iface_num & 0x1) |
| 2526 | break; |
| 2527 | init_fw_cb->iscsi_max_burst_len = |
| 2528 | cpu_to_le32(*(uint32_t *)iface_param->value) / |
| 2529 | BYTE_UNITS; |
| 2530 | break; |
| 2531 | case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: |
| 2532 | if (iface_param->iface_num & 0x1) |
| 2533 | break; |
| 2534 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2535 | init_fw_cb->iscsi_opts |= |
| 2536 | cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN); |
| 2537 | else |
| 2538 | init_fw_cb->iscsi_opts &= |
| 2539 | cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN); |
| 2540 | break; |
| 2541 | case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: |
| 2542 | if (iface_param->iface_num & 0x1) |
| 2543 | break; |
| 2544 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2545 | init_fw_cb->iscsi_opts |= |
| 2546 | cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN); |
| 2547 | else |
| 2548 | init_fw_cb->iscsi_opts &= |
| 2549 | cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN); |
| 2550 | break; |
| 2551 | case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: |
| 2552 | if (iface_param->iface_num & 0x1) |
| 2553 | break; |
| 2554 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2555 | init_fw_cb->iscsi_opts |= |
| 2556 | cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN); |
| 2557 | else |
| 2558 | init_fw_cb->iscsi_opts &= |
| 2559 | cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN); |
| 2560 | break; |
| 2561 | case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: |
| 2562 | if (iface_param->iface_num & 0x1) |
| 2563 | break; |
| 2564 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2565 | init_fw_cb->iscsi_opts |= |
| 2566 | cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN); |
| 2567 | else |
| 2568 | init_fw_cb->iscsi_opts &= |
| 2569 | cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN); |
| 2570 | break; |
| 2571 | case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: |
| 2572 | if (iface_param->iface_num & 0x1) |
| 2573 | break; |
| 2574 | if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE) |
| 2575 | init_fw_cb->iscsi_opts |= |
| 2576 | cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN); |
| 2577 | else |
| 2578 | init_fw_cb->iscsi_opts &= |
| 2579 | cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN); |
| 2580 | break; |
| 2581 | default: |
| 2582 | ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n", |
| 2583 | iface_param->param); |
| 2584 | break; |
| 2585 | } |
| 2586 | } |
| 2587 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2588 | static void |
| 2589 | qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) |
| 2590 | { |
| 2591 | struct addr_ctrl_blk_def *acb; |
| 2592 | acb = (struct addr_ctrl_blk_def *)init_fw_cb; |
| 2593 | memset(acb->reserved1, 0, sizeof(acb->reserved1)); |
| 2594 | memset(acb->reserved2, 0, sizeof(acb->reserved2)); |
| 2595 | memset(acb->reserved3, 0, sizeof(acb->reserved3)); |
| 2596 | memset(acb->reserved4, 0, sizeof(acb->reserved4)); |
| 2597 | memset(acb->reserved5, 0, sizeof(acb->reserved5)); |
| 2598 | memset(acb->reserved6, 0, sizeof(acb->reserved6)); |
| 2599 | memset(acb->reserved7, 0, sizeof(acb->reserved7)); |
| 2600 | memset(acb->reserved8, 0, sizeof(acb->reserved8)); |
| 2601 | memset(acb->reserved9, 0, sizeof(acb->reserved9)); |
| 2602 | memset(acb->reserved10, 0, sizeof(acb->reserved10)); |
| 2603 | memset(acb->reserved11, 0, sizeof(acb->reserved11)); |
| 2604 | memset(acb->reserved12, 0, sizeof(acb->reserved12)); |
| 2605 | memset(acb->reserved13, 0, sizeof(acb->reserved13)); |
| 2606 | memset(acb->reserved14, 0, sizeof(acb->reserved14)); |
| 2607 | memset(acb->reserved15, 0, sizeof(acb->reserved15)); |
| 2608 | } |
| 2609 | |
| 2610 | static int |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2611 | 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] | 2612 | { |
| 2613 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 2614 | int rval = 0; |
| 2615 | struct iscsi_iface_param_info *iface_param = NULL; |
| 2616 | struct addr_ctrl_blk *init_fw_cb = NULL; |
| 2617 | dma_addr_t init_fw_cb_dma; |
| 2618 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 2619 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2620 | uint32_t rem = len; |
| 2621 | struct nlattr *attr; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2622 | |
| 2623 | init_fw_cb = dma_alloc_coherent(&ha->pdev->dev, |
| 2624 | sizeof(struct addr_ctrl_blk), |
| 2625 | &init_fw_cb_dma, GFP_KERNEL); |
| 2626 | if (!init_fw_cb) { |
| 2627 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", |
| 2628 | __func__); |
| 2629 | return -ENOMEM; |
| 2630 | } |
| 2631 | |
| 2632 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 2633 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 2634 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 2635 | |
| 2636 | if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { |
| 2637 | ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); |
| 2638 | rval = -EIO; |
| 2639 | goto exit_init_fw_cb; |
| 2640 | } |
| 2641 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 2642 | nla_for_each_attr(attr, data, len, rem) { |
| 2643 | iface_param = nla_data(attr); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2644 | |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2645 | if (iface_param->param_type == ISCSI_NET_PARAM) { |
| 2646 | switch (iface_param->iface_type) { |
| 2647 | case ISCSI_IFACE_TYPE_IPV4: |
| 2648 | switch (iface_param->iface_num) { |
| 2649 | case 0: |
| 2650 | qla4xxx_set_ipv4(ha, iface_param, |
| 2651 | init_fw_cb); |
| 2652 | break; |
| 2653 | default: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2654 | /* Cannot have more than one IPv4 interface */ |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2655 | ql4_printk(KERN_ERR, ha, |
| 2656 | "Invalid IPv4 iface number = %d\n", |
| 2657 | iface_param->iface_num); |
| 2658 | break; |
| 2659 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2660 | break; |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2661 | case ISCSI_IFACE_TYPE_IPV6: |
| 2662 | switch (iface_param->iface_num) { |
| 2663 | case 0: |
| 2664 | case 1: |
| 2665 | qla4xxx_set_ipv6(ha, iface_param, |
| 2666 | init_fw_cb); |
| 2667 | break; |
| 2668 | default: |
| 2669 | /* Cannot have more than two IPv6 interface */ |
| 2670 | ql4_printk(KERN_ERR, ha, |
| 2671 | "Invalid IPv6 iface number = %d\n", |
| 2672 | iface_param->iface_num); |
| 2673 | break; |
| 2674 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2675 | break; |
| 2676 | default: |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2677 | ql4_printk(KERN_ERR, ha, |
| 2678 | "Invalid iface type\n"); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2679 | break; |
| 2680 | } |
Harish Zunjarrao | f8e9341 | 2013-10-18 09:01:42 -0400 | [diff] [blame] | 2681 | } else if (iface_param->param_type == ISCSI_IFACE_PARAM) { |
| 2682 | qla4xxx_set_iscsi_param(ha, iface_param, |
| 2683 | init_fw_cb); |
| 2684 | } else { |
| 2685 | continue; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2686 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); |
| 2690 | |
| 2691 | rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, |
| 2692 | sizeof(struct addr_ctrl_blk), |
| 2693 | FLASH_OPT_RMW_COMMIT); |
| 2694 | if (rval != QLA_SUCCESS) { |
| 2695 | ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", |
| 2696 | __func__); |
| 2697 | rval = -EIO; |
| 2698 | goto exit_init_fw_cb; |
| 2699 | } |
| 2700 | |
Vikas Chaudhary | ce505f9 | 2011-12-01 22:42:10 -0800 | [diff] [blame] | 2701 | rval = qla4xxx_disable_acb(ha); |
| 2702 | if (rval != QLA_SUCCESS) { |
| 2703 | ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n", |
| 2704 | __func__); |
| 2705 | rval = -EIO; |
| 2706 | goto exit_init_fw_cb; |
| 2707 | } |
| 2708 | |
| 2709 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 2710 | DISABLE_ACB_TOV * HZ); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 2711 | |
| 2712 | qla4xxx_initcb_to_acb(init_fw_cb); |
| 2713 | |
| 2714 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); |
| 2715 | if (rval != QLA_SUCCESS) { |
| 2716 | ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", |
| 2717 | __func__); |
| 2718 | rval = -EIO; |
| 2719 | goto exit_init_fw_cb; |
| 2720 | } |
| 2721 | |
| 2722 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 2723 | qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, |
| 2724 | init_fw_cb_dma); |
| 2725 | |
| 2726 | exit_init_fw_cb: |
| 2727 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), |
| 2728 | init_fw_cb, init_fw_cb_dma); |
| 2729 | |
| 2730 | return rval; |
| 2731 | } |
| 2732 | |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2733 | static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess, |
| 2734 | enum iscsi_param param, char *buf) |
| 2735 | { |
| 2736 | struct iscsi_session *sess = cls_sess->dd_data; |
| 2737 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 2738 | struct scsi_qla_host *ha = ddb_entry->ha; |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2739 | struct iscsi_cls_conn *cls_conn = ddb_entry->conn; |
| 2740 | struct ql4_chap_table chap_tbl; |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2741 | int rval, len; |
| 2742 | uint16_t idx; |
| 2743 | |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2744 | memset(&chap_tbl, 0, sizeof(chap_tbl)); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2745 | switch (param) { |
| 2746 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 2747 | rval = qla4xxx_get_chap_index(ha, sess->username_in, |
| 2748 | sess->password_in, BIDI_CHAP, |
| 2749 | &idx); |
| 2750 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 2751 | len = sprintf(buf, "\n"); |
| 2752 | else |
| 2753 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2754 | break; |
| 2755 | case ISCSI_PARAM_CHAP_OUT_IDX: |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2756 | if (ddb_entry->ddb_type == FLASH_DDB) { |
| 2757 | if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) { |
| 2758 | idx = ddb_entry->chap_tbl_idx; |
| 2759 | rval = QLA_SUCCESS; |
| 2760 | } else { |
| 2761 | rval = QLA_ERROR; |
| 2762 | } |
| 2763 | } else { |
| 2764 | rval = qla4xxx_get_chap_index(ha, sess->username, |
| 2765 | sess->password, |
| 2766 | LOCAL_CHAP, &idx); |
| 2767 | } |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2768 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 2769 | len = sprintf(buf, "\n"); |
| 2770 | else |
| 2771 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2772 | break; |
Adheer Chandravanshi | 97c2730 | 2013-09-17 07:54:50 -0400 | [diff] [blame] | 2773 | case ISCSI_PARAM_USERNAME: |
| 2774 | case ISCSI_PARAM_PASSWORD: |
| 2775 | /* First, populate session username and password for FLASH DDB, |
| 2776 | * if not already done. This happens when session login fails |
| 2777 | * for a FLASH DDB. |
| 2778 | */ |
| 2779 | if (ddb_entry->ddb_type == FLASH_DDB && |
| 2780 | ddb_entry->chap_tbl_idx != INVALID_ENTRY && |
| 2781 | !sess->username && !sess->password) { |
| 2782 | idx = ddb_entry->chap_tbl_idx; |
| 2783 | rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name, |
| 2784 | chap_tbl.secret, |
| 2785 | idx); |
| 2786 | if (!rval) { |
| 2787 | iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME, |
| 2788 | (char *)chap_tbl.name, |
| 2789 | strlen((char *)chap_tbl.name)); |
| 2790 | iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD, |
| 2791 | (char *)chap_tbl.secret, |
| 2792 | chap_tbl.secret_len); |
| 2793 | } |
| 2794 | } |
| 2795 | /* allow fall-through */ |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 2796 | default: |
| 2797 | return iscsi_session_get_param(cls_sess, param, buf); |
| 2798 | } |
| 2799 | |
| 2800 | return len; |
| 2801 | } |
| 2802 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2803 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2804 | enum iscsi_param param, char *buf) |
| 2805 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2806 | struct iscsi_conn *conn; |
| 2807 | struct qla_conn *qla_conn; |
| 2808 | struct sockaddr *dst_addr; |
| 2809 | int len = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2810 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2811 | conn = cls_conn->dd_data; |
| 2812 | qla_conn = conn->dd_data; |
Manish Rangankar | d46bdeb1 | 2012-08-07 07:57:13 -0400 | [diff] [blame] | 2813 | dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2814 | |
| 2815 | switch (param) { |
| 2816 | case ISCSI_PARAM_CONN_PORT: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2817 | case ISCSI_PARAM_CONN_ADDRESS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2818 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 2819 | dst_addr, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2820 | default: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2821 | return iscsi_conn_get_param(cls_conn, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | return len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2825 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2828 | int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index) |
| 2829 | { |
| 2830 | uint32_t mbx_sts = 0; |
| 2831 | uint16_t tmp_ddb_index; |
| 2832 | int ret; |
| 2833 | |
| 2834 | get_ddb_index: |
| 2835 | tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES); |
| 2836 | |
| 2837 | if (tmp_ddb_index >= MAX_DDB_ENTRIES) { |
| 2838 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2839 | "Free DDB index not available\n")); |
| 2840 | ret = QLA_ERROR; |
| 2841 | goto exit_get_ddb_index; |
| 2842 | } |
| 2843 | |
| 2844 | if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map)) |
| 2845 | goto get_ddb_index; |
| 2846 | |
| 2847 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2848 | "Found a free DDB index at %d\n", tmp_ddb_index)); |
| 2849 | ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts); |
| 2850 | if (ret == QLA_ERROR) { |
| 2851 | if (mbx_sts == MBOX_STS_COMMAND_ERROR) { |
| 2852 | ql4_printk(KERN_INFO, ha, |
| 2853 | "DDB index = %d not available trying next\n", |
| 2854 | tmp_ddb_index); |
| 2855 | goto get_ddb_index; |
| 2856 | } |
| 2857 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2858 | "Free FW DDB not available\n")); |
| 2859 | } |
| 2860 | |
| 2861 | *ddb_index = tmp_ddb_index; |
| 2862 | |
| 2863 | exit_get_ddb_index: |
| 2864 | return ret; |
| 2865 | } |
| 2866 | |
| 2867 | static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha, |
| 2868 | struct ddb_entry *ddb_entry, |
| 2869 | char *existing_ipaddr, |
| 2870 | char *user_ipaddr) |
| 2871 | { |
| 2872 | uint8_t dst_ipaddr[IPv6_ADDR_LEN]; |
| 2873 | char formatted_ipaddr[DDB_IPADDR_LEN]; |
| 2874 | int status = QLA_SUCCESS, ret = 0; |
| 2875 | |
| 2876 | if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) { |
| 2877 | ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 2878 | '\0', NULL); |
| 2879 | if (ret == 0) { |
| 2880 | status = QLA_ERROR; |
| 2881 | goto out_match; |
| 2882 | } |
| 2883 | ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr); |
| 2884 | } else { |
| 2885 | ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 2886 | '\0', NULL); |
| 2887 | if (ret == 0) { |
| 2888 | status = QLA_ERROR; |
| 2889 | goto out_match; |
| 2890 | } |
| 2891 | ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr); |
| 2892 | } |
| 2893 | |
| 2894 | if (strcmp(existing_ipaddr, formatted_ipaddr)) |
| 2895 | status = QLA_ERROR; |
| 2896 | |
| 2897 | out_match: |
| 2898 | return status; |
| 2899 | } |
| 2900 | |
| 2901 | static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha, |
| 2902 | struct iscsi_cls_conn *cls_conn) |
| 2903 | { |
| 2904 | int idx = 0, max_ddbs, rval; |
| 2905 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 2906 | struct iscsi_session *sess, *existing_sess; |
| 2907 | struct iscsi_conn *conn, *existing_conn; |
| 2908 | struct ddb_entry *ddb_entry; |
| 2909 | |
| 2910 | sess = cls_sess->dd_data; |
| 2911 | conn = cls_conn->dd_data; |
| 2912 | |
| 2913 | if (sess->targetname == NULL || |
| 2914 | conn->persistent_address == NULL || |
| 2915 | conn->persistent_port == 0) |
| 2916 | return QLA_ERROR; |
| 2917 | |
| 2918 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 2919 | MAX_DEV_DB_ENTRIES; |
| 2920 | |
| 2921 | for (idx = 0; idx < max_ddbs; idx++) { |
| 2922 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 2923 | if (ddb_entry == NULL) |
| 2924 | continue; |
| 2925 | |
| 2926 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 2927 | continue; |
| 2928 | |
| 2929 | existing_sess = ddb_entry->sess->dd_data; |
| 2930 | existing_conn = ddb_entry->conn->dd_data; |
| 2931 | |
| 2932 | if (existing_sess->targetname == NULL || |
| 2933 | existing_conn->persistent_address == NULL || |
| 2934 | existing_conn->persistent_port == 0) |
| 2935 | continue; |
| 2936 | |
| 2937 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2938 | "IQN = %s User IQN = %s\n", |
| 2939 | existing_sess->targetname, |
| 2940 | sess->targetname)); |
| 2941 | |
| 2942 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2943 | "IP = %s User IP = %s\n", |
| 2944 | existing_conn->persistent_address, |
| 2945 | conn->persistent_address)); |
| 2946 | |
| 2947 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2948 | "Port = %d User Port = %d\n", |
| 2949 | existing_conn->persistent_port, |
| 2950 | conn->persistent_port)); |
| 2951 | |
| 2952 | if (strcmp(existing_sess->targetname, sess->targetname)) |
| 2953 | continue; |
| 2954 | rval = qla4xxx_match_ipaddress(ha, ddb_entry, |
| 2955 | existing_conn->persistent_address, |
| 2956 | conn->persistent_address); |
| 2957 | if (rval == QLA_ERROR) |
| 2958 | continue; |
| 2959 | if (existing_conn->persistent_port != conn->persistent_port) |
| 2960 | continue; |
| 2961 | break; |
| 2962 | } |
| 2963 | |
| 2964 | if (idx == max_ddbs) |
| 2965 | return QLA_ERROR; |
| 2966 | |
| 2967 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2968 | "Match found in fwdb sessions\n")); |
| 2969 | return QLA_SUCCESS; |
| 2970 | } |
| 2971 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2972 | static struct iscsi_cls_session * |
| 2973 | qla4xxx_session_create(struct iscsi_endpoint *ep, |
| 2974 | uint16_t cmds_max, uint16_t qdepth, |
| 2975 | uint32_t initial_cmdsn) |
| 2976 | { |
| 2977 | struct iscsi_cls_session *cls_sess; |
| 2978 | struct scsi_qla_host *ha; |
| 2979 | struct qla_endpoint *qla_ep; |
| 2980 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2981 | uint16_t ddb_index; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2982 | struct iscsi_session *sess; |
| 2983 | struct sockaddr *dst_addr; |
| 2984 | int ret; |
| 2985 | |
| 2986 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 2987 | if (!ep) { |
| 2988 | printk(KERN_ERR "qla4xxx: missing ep.\n"); |
| 2989 | return NULL; |
| 2990 | } |
| 2991 | |
| 2992 | qla_ep = ep->dd_data; |
| 2993 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 2994 | ha = to_qla_host(qla_ep->host); |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 2995 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2996 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 2997 | if (ret == QLA_ERROR) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2998 | return NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2999 | |
| 3000 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host, |
| 3001 | cmds_max, sizeof(struct ddb_entry), |
| 3002 | sizeof(struct ql4_task_data), |
| 3003 | initial_cmdsn, ddb_index); |
| 3004 | if (!cls_sess) |
| 3005 | return NULL; |
| 3006 | |
| 3007 | sess = cls_sess->dd_data; |
| 3008 | ddb_entry = sess->dd_data; |
| 3009 | ddb_entry->fw_ddb_index = ddb_index; |
| 3010 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 3011 | ddb_entry->ha = ha; |
| 3012 | ddb_entry->sess = cls_sess; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3013 | ddb_entry->unblock_sess = qla4xxx_unblock_ddb; |
| 3014 | ddb_entry->ddb_change = qla4xxx_ddb_change; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3015 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 3016 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| 3017 | ha->tot_ddbs++; |
| 3018 | |
| 3019 | return cls_sess; |
| 3020 | } |
| 3021 | |
| 3022 | static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess) |
| 3023 | { |
| 3024 | struct iscsi_session *sess; |
| 3025 | struct ddb_entry *ddb_entry; |
| 3026 | struct scsi_qla_host *ha; |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3027 | unsigned long flags, wtime; |
| 3028 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 3029 | dma_addr_t fw_ddb_entry_dma; |
| 3030 | uint32_t ddb_state; |
| 3031 | int ret; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3032 | |
| 3033 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3034 | sess = cls_sess->dd_data; |
| 3035 | ddb_entry = sess->dd_data; |
| 3036 | ha = ddb_entry->ha; |
| 3037 | |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3038 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3039 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3040 | if (!fw_ddb_entry) { |
| 3041 | ql4_printk(KERN_ERR, ha, |
| 3042 | "%s: Unable to allocate dma buffer\n", __func__); |
| 3043 | goto destroy_session; |
| 3044 | } |
| 3045 | |
| 3046 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 3047 | do { |
| 3048 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 3049 | fw_ddb_entry, fw_ddb_entry_dma, |
| 3050 | NULL, NULL, &ddb_state, NULL, |
| 3051 | NULL, NULL); |
| 3052 | if (ret == QLA_ERROR) |
| 3053 | goto destroy_session; |
| 3054 | |
| 3055 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 3056 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 3057 | goto destroy_session; |
| 3058 | |
| 3059 | schedule_timeout_uninterruptible(HZ); |
| 3060 | } while ((time_after(wtime, jiffies))); |
| 3061 | |
| 3062 | destroy_session: |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 3063 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 3064 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3065 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3066 | qla4xxx_free_ddb(ha, ddb_entry); |
| 3067 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3068 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3069 | iscsi_session_teardown(cls_sess); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 3070 | |
| 3071 | if (fw_ddb_entry) |
| 3072 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3073 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3074 | } |
| 3075 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3076 | static struct iscsi_cls_conn * |
| 3077 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx) |
| 3078 | { |
| 3079 | struct iscsi_cls_conn *cls_conn; |
| 3080 | struct iscsi_session *sess; |
| 3081 | struct ddb_entry *ddb_entry; |
| 3082 | |
| 3083 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3084 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), |
| 3085 | conn_idx); |
Mike Christie | ff1d031 | 2011-12-01 21:38:43 -0600 | [diff] [blame] | 3086 | if (!cls_conn) |
| 3087 | return NULL; |
| 3088 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3089 | sess = cls_sess->dd_data; |
| 3090 | ddb_entry = sess->dd_data; |
| 3091 | ddb_entry->conn = cls_conn; |
| 3092 | |
| 3093 | return cls_conn; |
| 3094 | } |
| 3095 | |
| 3096 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 3097 | struct iscsi_cls_conn *cls_conn, |
| 3098 | uint64_t transport_fd, int is_leading) |
| 3099 | { |
| 3100 | struct iscsi_conn *conn; |
| 3101 | struct qla_conn *qla_conn; |
| 3102 | struct iscsi_endpoint *ep; |
| 3103 | |
| 3104 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3105 | |
| 3106 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
| 3107 | return -EINVAL; |
| 3108 | ep = iscsi_lookup_endpoint(transport_fd); |
| 3109 | conn = cls_conn->dd_data; |
| 3110 | qla_conn = conn->dd_data; |
| 3111 | qla_conn->qla_ep = ep->dd_data; |
| 3112 | return 0; |
| 3113 | } |
| 3114 | |
| 3115 | static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn) |
| 3116 | { |
| 3117 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 3118 | struct iscsi_session *sess; |
| 3119 | struct ddb_entry *ddb_entry; |
| 3120 | struct scsi_qla_host *ha; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3121 | struct dev_db_entry *fw_ddb_entry = NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3122 | dma_addr_t fw_ddb_entry_dma; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3123 | uint32_t mbx_sts = 0; |
| 3124 | int ret = 0; |
| 3125 | int status = QLA_SUCCESS; |
| 3126 | |
| 3127 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3128 | sess = cls_sess->dd_data; |
| 3129 | ddb_entry = sess->dd_data; |
| 3130 | ha = ddb_entry->ha; |
| 3131 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3132 | /* Check if we have matching FW DDB, if yes then do not |
| 3133 | * login to this target. This could cause target to logout previous |
| 3134 | * connection |
| 3135 | */ |
| 3136 | ret = qla4xxx_match_fwdb_session(ha, cls_conn); |
| 3137 | if (ret == QLA_SUCCESS) { |
| 3138 | ql4_printk(KERN_INFO, ha, |
| 3139 | "Session already exist in FW.\n"); |
| 3140 | ret = -EEXIST; |
| 3141 | goto exit_conn_start; |
| 3142 | } |
| 3143 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3144 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3145 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3146 | if (!fw_ddb_entry) { |
| 3147 | ql4_printk(KERN_ERR, ha, |
| 3148 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3149 | ret = -ENOMEM; |
| 3150 | goto exit_conn_start; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts); |
| 3154 | if (ret) { |
| 3155 | /* If iscsid is stopped and started then no need to do |
| 3156 | * set param again since ddb state will be already |
| 3157 | * active and FW does not allow set ddb to an |
| 3158 | * active session. |
| 3159 | */ |
| 3160 | if (mbx_sts) |
| 3161 | if (ddb_entry->fw_ddb_device_state == |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 3162 | DDB_DS_SESSION_ACTIVE) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3163 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3164 | goto exit_set_param; |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 3165 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3166 | |
| 3167 | ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n", |
| 3168 | __func__, ddb_entry->fw_ddb_index); |
| 3169 | goto exit_conn_start; |
| 3170 | } |
| 3171 | |
| 3172 | status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| 3173 | if (status == QLA_ERROR) { |
Manish Rangankar | 0e7e850 | 2011-07-25 13:48:54 -0500 | [diff] [blame] | 3174 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| 3175 | sess->targetname); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3176 | ret = -EINVAL; |
| 3177 | goto exit_conn_start; |
| 3178 | } |
| 3179 | |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 3180 | if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) |
| 3181 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| 3182 | |
| 3183 | DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__, |
| 3184 | ddb_entry->fw_ddb_device_state)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3185 | |
| 3186 | exit_set_param: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3187 | ret = 0; |
| 3188 | |
| 3189 | exit_conn_start: |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3190 | if (fw_ddb_entry) |
| 3191 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3192 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3193 | return ret; |
| 3194 | } |
| 3195 | |
| 3196 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| 3197 | { |
| 3198 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 3199 | struct iscsi_session *sess; |
| 3200 | struct scsi_qla_host *ha; |
| 3201 | struct ddb_entry *ddb_entry; |
| 3202 | int options; |
| 3203 | |
| 3204 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 3205 | sess = cls_sess->dd_data; |
| 3206 | ddb_entry = sess->dd_data; |
| 3207 | ha = ddb_entry->ha; |
| 3208 | |
| 3209 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 3210 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) |
| 3211 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | static void qla4xxx_task_work(struct work_struct *wdata) |
| 3215 | { |
| 3216 | struct ql4_task_data *task_data; |
| 3217 | struct scsi_qla_host *ha; |
| 3218 | struct passthru_status *sts; |
| 3219 | struct iscsi_task *task; |
| 3220 | struct iscsi_hdr *hdr; |
| 3221 | uint8_t *data; |
| 3222 | uint32_t data_len; |
| 3223 | struct iscsi_conn *conn; |
| 3224 | int hdr_len; |
| 3225 | itt_t itt; |
| 3226 | |
| 3227 | task_data = container_of(wdata, struct ql4_task_data, task_work); |
| 3228 | ha = task_data->ha; |
| 3229 | task = task_data->task; |
| 3230 | sts = &task_data->sts; |
| 3231 | hdr_len = sizeof(struct iscsi_hdr); |
| 3232 | |
| 3233 | DEBUG3(printk(KERN_INFO "Status returned\n")); |
| 3234 | DEBUG3(qla4xxx_dump_buffer(sts, 64)); |
| 3235 | DEBUG3(printk(KERN_INFO "Response buffer")); |
| 3236 | DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64)); |
| 3237 | |
| 3238 | conn = task->conn; |
| 3239 | |
| 3240 | switch (sts->completionStatus) { |
| 3241 | case PASSTHRU_STATUS_COMPLETE: |
| 3242 | hdr = (struct iscsi_hdr *)task_data->resp_buffer; |
| 3243 | /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */ |
| 3244 | itt = sts->handle; |
| 3245 | hdr->itt = itt; |
| 3246 | data = task_data->resp_buffer + hdr_len; |
| 3247 | data_len = task_data->resp_len - hdr_len; |
| 3248 | iscsi_complete_pdu(conn, hdr, data, data_len); |
| 3249 | break; |
| 3250 | default: |
| 3251 | ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n", |
| 3252 | sts->completionStatus); |
| 3253 | break; |
| 3254 | } |
| 3255 | return; |
| 3256 | } |
| 3257 | |
| 3258 | static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 3259 | { |
| 3260 | struct ql4_task_data *task_data; |
| 3261 | struct iscsi_session *sess; |
| 3262 | struct ddb_entry *ddb_entry; |
| 3263 | struct scsi_qla_host *ha; |
| 3264 | int hdr_len; |
| 3265 | |
| 3266 | sess = task->conn->session; |
| 3267 | ddb_entry = sess->dd_data; |
| 3268 | ha = ddb_entry->ha; |
| 3269 | task_data = task->dd_data; |
| 3270 | memset(task_data, 0, sizeof(struct ql4_task_data)); |
| 3271 | |
| 3272 | if (task->sc) { |
| 3273 | ql4_printk(KERN_INFO, ha, |
| 3274 | "%s: SCSI Commands not implemented\n", __func__); |
| 3275 | return -EINVAL; |
| 3276 | } |
| 3277 | |
| 3278 | hdr_len = sizeof(struct iscsi_hdr); |
| 3279 | task_data->ha = ha; |
| 3280 | task_data->task = task; |
| 3281 | |
| 3282 | if (task->data_count) { |
| 3283 | task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data, |
| 3284 | task->data_count, |
| 3285 | PCI_DMA_TODEVICE); |
| 3286 | } |
| 3287 | |
| 3288 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 3289 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 3290 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3291 | task_data->resp_len = task->conn->max_recv_dlength + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3292 | task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| 3293 | task_data->resp_len, |
| 3294 | &task_data->resp_dma, |
| 3295 | GFP_ATOMIC); |
| 3296 | if (!task_data->resp_buffer) |
| 3297 | goto exit_alloc_pdu; |
| 3298 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3299 | task_data->req_len = task->data_count + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3300 | task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev, |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3301 | task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3302 | &task_data->req_dma, |
| 3303 | GFP_ATOMIC); |
| 3304 | if (!task_data->req_buffer) |
| 3305 | goto exit_alloc_pdu; |
| 3306 | |
| 3307 | task->hdr = task_data->req_buffer; |
| 3308 | |
| 3309 | INIT_WORK(&task_data->task_work, qla4xxx_task_work); |
| 3310 | |
| 3311 | return 0; |
| 3312 | |
| 3313 | exit_alloc_pdu: |
| 3314 | if (task_data->resp_buffer) |
| 3315 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 3316 | task_data->resp_buffer, task_data->resp_dma); |
| 3317 | |
| 3318 | if (task_data->req_buffer) |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3319 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3320 | task_data->req_buffer, task_data->req_dma); |
| 3321 | return -ENOMEM; |
| 3322 | } |
| 3323 | |
| 3324 | static void qla4xxx_task_cleanup(struct iscsi_task *task) |
| 3325 | { |
| 3326 | struct ql4_task_data *task_data; |
| 3327 | struct iscsi_session *sess; |
| 3328 | struct ddb_entry *ddb_entry; |
| 3329 | struct scsi_qla_host *ha; |
| 3330 | int hdr_len; |
| 3331 | |
| 3332 | hdr_len = sizeof(struct iscsi_hdr); |
| 3333 | sess = task->conn->session; |
| 3334 | ddb_entry = sess->dd_data; |
| 3335 | ha = ddb_entry->ha; |
| 3336 | task_data = task->dd_data; |
| 3337 | |
| 3338 | if (task->data_count) { |
| 3339 | dma_unmap_single(&ha->pdev->dev, task_data->data_dma, |
| 3340 | task->data_count, PCI_DMA_TODEVICE); |
| 3341 | } |
| 3342 | |
| 3343 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 3344 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 3345 | |
| 3346 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 3347 | task_data->resp_buffer, task_data->resp_dma); |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 3348 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3349 | task_data->req_buffer, task_data->req_dma); |
| 3350 | return; |
| 3351 | } |
| 3352 | |
| 3353 | static int qla4xxx_task_xmit(struct iscsi_task *task) |
| 3354 | { |
| 3355 | struct scsi_cmnd *sc = task->sc; |
| 3356 | struct iscsi_session *sess = task->conn->session; |
| 3357 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 3358 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 3359 | |
| 3360 | if (!sc) |
| 3361 | return qla4xxx_send_passthru0(task); |
| 3362 | |
| 3363 | ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n", |
| 3364 | __func__); |
| 3365 | return -ENOSYS; |
| 3366 | } |
| 3367 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3368 | static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 3369 | struct iscsi_bus_flash_conn *conn, |
| 3370 | struct dev_db_entry *fw_ddb_entry) |
| 3371 | { |
| 3372 | unsigned long options = 0; |
| 3373 | int rc = 0; |
| 3374 | |
| 3375 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3376 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 3377 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3378 | rc = iscsi_switch_str_param(&sess->portal_type, |
| 3379 | PORTAL_TYPE_IPV6); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3380 | if (rc) |
| 3381 | goto exit_copy; |
| 3382 | } else { |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3383 | rc = iscsi_switch_str_param(&sess->portal_type, |
| 3384 | PORTAL_TYPE_IPV4); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3385 | if (rc) |
| 3386 | goto exit_copy; |
| 3387 | } |
| 3388 | |
| 3389 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 3390 | &options); |
| 3391 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 3392 | sess->entry_state = test_bit(OPT_ENTRY_STATE, &options); |
| 3393 | |
| 3394 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3395 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 3396 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 3397 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 3398 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 3399 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 3400 | &options); |
| 3401 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 3402 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 3403 | conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options); |
| 3404 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 3405 | &options); |
| 3406 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 3407 | sess->discovery_auth_optional = |
| 3408 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 3409 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 3410 | sess->erl |= BIT_1; |
| 3411 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 3412 | sess->erl |= BIT_0; |
| 3413 | |
| 3414 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3415 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 3416 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 3417 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 3418 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 3419 | conn->tcp_timer_scale |= BIT_3; |
| 3420 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 3421 | conn->tcp_timer_scale |= BIT_2; |
| 3422 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 3423 | conn->tcp_timer_scale |= BIT_1; |
| 3424 | |
| 3425 | conn->tcp_timer_scale >>= 1; |
| 3426 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 3427 | |
| 3428 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3429 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 3430 | |
| 3431 | conn->max_recv_dlength = BYTE_UNITS * |
| 3432 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 3433 | conn->max_xmit_dlength = BYTE_UNITS * |
| 3434 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 3435 | sess->first_burst = BYTE_UNITS * |
| 3436 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 3437 | sess->max_burst = BYTE_UNITS * |
| 3438 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 3439 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 3440 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3441 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 3442 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3443 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 3444 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 3445 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 3446 | conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl); |
| 3447 | conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 3448 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 3449 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 3450 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 3451 | sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 3452 | sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 3453 | sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3454 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 3455 | |
| 3456 | sess->default_taskmgmt_timeout = |
| 3457 | le16_to_cpu(fw_ddb_entry->def_timeout); |
| 3458 | conn->port = le16_to_cpu(fw_ddb_entry->port); |
| 3459 | |
| 3460 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3461 | conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3462 | if (!conn->ipaddress) { |
| 3463 | rc = -ENOMEM; |
| 3464 | goto exit_copy; |
| 3465 | } |
| 3466 | |
| 3467 | conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3468 | if (!conn->redirect_ipaddr) { |
| 3469 | rc = -ENOMEM; |
| 3470 | goto exit_copy; |
| 3471 | } |
| 3472 | |
| 3473 | memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 3474 | memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN); |
| 3475 | |
| 3476 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
| 3477 | conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos; |
| 3478 | |
| 3479 | conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 3480 | if (!conn->link_local_ipv6_addr) { |
| 3481 | rc = -ENOMEM; |
| 3482 | goto exit_copy; |
| 3483 | } |
| 3484 | |
| 3485 | memcpy(conn->link_local_ipv6_addr, |
| 3486 | fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN); |
| 3487 | } else { |
| 3488 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 3489 | } |
| 3490 | |
| 3491 | if (fw_ddb_entry->iscsi_name[0]) { |
| 3492 | rc = iscsi_switch_str_param(&sess->targetname, |
| 3493 | (char *)fw_ddb_entry->iscsi_name); |
| 3494 | if (rc) |
| 3495 | goto exit_copy; |
| 3496 | } |
| 3497 | |
| 3498 | if (fw_ddb_entry->iscsi_alias[0]) { |
| 3499 | rc = iscsi_switch_str_param(&sess->targetalias, |
| 3500 | (char *)fw_ddb_entry->iscsi_alias); |
| 3501 | if (rc) |
| 3502 | goto exit_copy; |
| 3503 | } |
| 3504 | |
| 3505 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 3506 | |
| 3507 | exit_copy: |
| 3508 | return rc; |
| 3509 | } |
| 3510 | |
| 3511 | static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 3512 | struct iscsi_bus_flash_conn *conn, |
| 3513 | struct dev_db_entry *fw_ddb_entry) |
| 3514 | { |
| 3515 | uint16_t options; |
| 3516 | int rc = 0; |
| 3517 | |
| 3518 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3519 | SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11); |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 3520 | if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3521 | options |= BIT_8; |
| 3522 | else |
| 3523 | options &= ~BIT_8; |
| 3524 | |
| 3525 | SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6); |
| 3526 | SET_BITVAL(sess->discovery_sess, options, BIT_4); |
| 3527 | SET_BITVAL(sess->entry_state, options, BIT_3); |
| 3528 | fw_ddb_entry->options = cpu_to_le16(options); |
| 3529 | |
| 3530 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3531 | SET_BITVAL(conn->hdrdgst_en, options, BIT_13); |
| 3532 | SET_BITVAL(conn->datadgst_en, options, BIT_12); |
| 3533 | SET_BITVAL(sess->imm_data_en, options, BIT_11); |
| 3534 | SET_BITVAL(sess->initial_r2t_en, options, BIT_10); |
| 3535 | SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9); |
| 3536 | SET_BITVAL(sess->pdu_inorder_en, options, BIT_8); |
| 3537 | SET_BITVAL(sess->chap_auth_en, options, BIT_7); |
| 3538 | SET_BITVAL(conn->snack_req_en, options, BIT_6); |
| 3539 | SET_BITVAL(sess->discovery_logout_en, options, BIT_5); |
| 3540 | SET_BITVAL(sess->bidi_chap_en, options, BIT_4); |
| 3541 | SET_BITVAL(sess->discovery_auth_optional, options, BIT_3); |
| 3542 | SET_BITVAL(sess->erl & BIT_1, options, BIT_1); |
| 3543 | SET_BITVAL(sess->erl & BIT_0, options, BIT_0); |
| 3544 | fw_ddb_entry->iscsi_options = cpu_to_le16(options); |
| 3545 | |
| 3546 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3547 | SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6); |
| 3548 | SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5); |
| 3549 | SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4); |
| 3550 | SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3); |
| 3551 | SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2); |
| 3552 | SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1); |
| 3553 | SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0); |
| 3554 | fw_ddb_entry->tcp_options = cpu_to_le16(options); |
| 3555 | |
| 3556 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3557 | SET_BITVAL(conn->fragment_disable, options, BIT_4); |
| 3558 | fw_ddb_entry->ip_options = cpu_to_le16(options); |
| 3559 | |
| 3560 | fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t); |
| 3561 | fw_ddb_entry->iscsi_max_rcv_data_seg_len = |
| 3562 | cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS); |
| 3563 | fw_ddb_entry->iscsi_max_snd_data_seg_len = |
| 3564 | cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS); |
| 3565 | fw_ddb_entry->iscsi_first_burst_len = |
| 3566 | cpu_to_le16(sess->first_burst / BYTE_UNITS); |
| 3567 | fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst / |
| 3568 | BYTE_UNITS); |
| 3569 | fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait); |
| 3570 | fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain); |
| 3571 | fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt); |
| 3572 | fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size); |
Adheer Chandravanshi | fbcd483 | 2013-04-17 05:15:29 -0400 | [diff] [blame] | 3573 | fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf); |
| 3574 | 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] | 3575 | fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label); |
| 3576 | fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout); |
| 3577 | fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port); |
Adheer Chandravanshi | fbcd483 | 2013-04-17 05:15:29 -0400 | [diff] [blame] | 3578 | fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn); |
| 3579 | fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn); |
Adheer Chandravanshi | 6556016 | 2013-07-08 08:33:06 -0400 | [diff] [blame] | 3580 | fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3581 | fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx); |
| 3582 | fw_ddb_entry->tsid = cpu_to_le16(sess->tsid); |
| 3583 | fw_ddb_entry->port = cpu_to_le16(conn->port); |
| 3584 | fw_ddb_entry->def_timeout = |
| 3585 | cpu_to_le16(sess->default_taskmgmt_timeout); |
| 3586 | |
Adheer Chandravanshi | 8459580 | 2013-07-08 08:33:07 -0400 | [diff] [blame] | 3587 | if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
| 3588 | fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class; |
| 3589 | else |
| 3590 | fw_ddb_entry->ipv4_tos = conn->ipv4_tos; |
| 3591 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 3592 | if (conn->ipaddress) |
| 3593 | memcpy(fw_ddb_entry->ip_addr, conn->ipaddress, |
| 3594 | sizeof(fw_ddb_entry->ip_addr)); |
| 3595 | |
| 3596 | if (conn->redirect_ipaddr) |
| 3597 | memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr, |
| 3598 | sizeof(fw_ddb_entry->tgt_addr)); |
| 3599 | |
| 3600 | if (conn->link_local_ipv6_addr) |
| 3601 | memcpy(fw_ddb_entry->link_local_ipv6_addr, |
| 3602 | conn->link_local_ipv6_addr, |
| 3603 | sizeof(fw_ddb_entry->link_local_ipv6_addr)); |
| 3604 | |
| 3605 | if (sess->targetname) |
| 3606 | memcpy(fw_ddb_entry->iscsi_name, sess->targetname, |
| 3607 | sizeof(fw_ddb_entry->iscsi_name)); |
| 3608 | |
| 3609 | if (sess->targetalias) |
| 3610 | memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias, |
| 3611 | sizeof(fw_ddb_entry->iscsi_alias)); |
| 3612 | |
| 3613 | COPY_ISID(fw_ddb_entry->isid, sess->isid); |
| 3614 | |
| 3615 | return rc; |
| 3616 | } |
| 3617 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3618 | static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn, |
| 3619 | struct iscsi_session *sess, |
| 3620 | struct dev_db_entry *fw_ddb_entry) |
| 3621 | { |
| 3622 | unsigned long options = 0; |
| 3623 | uint16_t ddb_link; |
| 3624 | uint16_t disc_parent; |
| 3625 | |
| 3626 | options = le16_to_cpu(fw_ddb_entry->options); |
| 3627 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 3628 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 3629 | &options); |
| 3630 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 3631 | |
| 3632 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 3633 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 3634 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 3635 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 3636 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 3637 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 3638 | &options); |
| 3639 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 3640 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 3641 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 3642 | &options); |
| 3643 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 3644 | sess->discovery_auth_optional = |
| 3645 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 3646 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 3647 | sess->erl |= BIT_1; |
| 3648 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 3649 | sess->erl |= BIT_0; |
| 3650 | |
| 3651 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 3652 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 3653 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 3654 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 3655 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 3656 | conn->tcp_timer_scale |= BIT_3; |
| 3657 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 3658 | conn->tcp_timer_scale |= BIT_2; |
| 3659 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 3660 | conn->tcp_timer_scale |= BIT_1; |
| 3661 | |
| 3662 | conn->tcp_timer_scale >>= 1; |
| 3663 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 3664 | |
| 3665 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 3666 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 3667 | |
| 3668 | conn->max_recv_dlength = BYTE_UNITS * |
| 3669 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 3670 | conn->max_xmit_dlength = BYTE_UNITS * |
| 3671 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 3672 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 3673 | sess->first_burst = BYTE_UNITS * |
| 3674 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 3675 | sess->max_burst = BYTE_UNITS * |
| 3676 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 3677 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3678 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 3679 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 3680 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 3681 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 3682 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 3683 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 3684 | conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 3685 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 3686 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 3687 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 3688 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 3689 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 3690 | |
| 3691 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3692 | if (ddb_link == DDB_ISNS) |
| 3693 | disc_parent = ISCSI_DISC_PARENT_ISNS; |
| 3694 | else if (ddb_link == DDB_NO_LINK) |
| 3695 | disc_parent = ISCSI_DISC_PARENT_UNKNOWN; |
| 3696 | else if (ddb_link < MAX_DDB_ENTRIES) |
| 3697 | disc_parent = ISCSI_DISC_PARENT_SENDTGT; |
| 3698 | else |
| 3699 | disc_parent = ISCSI_DISC_PARENT_UNKNOWN; |
| 3700 | |
| 3701 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, |
| 3702 | iscsi_get_discovery_parent_name(disc_parent), 0); |
| 3703 | |
| 3704 | iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS, |
| 3705 | (char *)fw_ddb_entry->iscsi_alias, 0); |
| 3706 | } |
| 3707 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3708 | static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha, |
| 3709 | struct dev_db_entry *fw_ddb_entry, |
| 3710 | struct iscsi_cls_session *cls_sess, |
| 3711 | struct iscsi_cls_conn *cls_conn) |
| 3712 | { |
| 3713 | int buflen = 0; |
| 3714 | struct iscsi_session *sess; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3715 | struct ddb_entry *ddb_entry; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3716 | struct ql4_chap_table chap_tbl; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3717 | struct iscsi_conn *conn; |
| 3718 | char ip_addr[DDB_IPADDR_LEN]; |
| 3719 | uint16_t options = 0; |
| 3720 | |
| 3721 | sess = cls_sess->dd_data; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3722 | ddb_entry = sess->dd_data; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3723 | conn = cls_conn->dd_data; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3724 | memset(&chap_tbl, 0, sizeof(chap_tbl)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3725 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3726 | ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 3727 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3728 | qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3729 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3730 | sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3731 | conn->persistent_port = le16_to_cpu(fw_ddb_entry->port); |
| 3732 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3733 | memset(ip_addr, 0, sizeof(ip_addr)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3734 | options = le16_to_cpu(fw_ddb_entry->options); |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3735 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 3736 | iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3737 | |
Adheer Chandravanshi | 8cc91d4 | 2013-07-01 05:54:13 -0400 | [diff] [blame] | 3738 | memset(ip_addr, 0, sizeof(ip_addr)); |
| 3739 | sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 3740 | } else { |
| 3741 | iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4); |
| 3742 | sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 3743 | } |
| 3744 | |
| 3745 | iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS, |
| 3746 | (char *)ip_addr, buflen); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3747 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME, |
| 3748 | (char *)fw_ddb_entry->iscsi_name, buflen); |
| 3749 | iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME, |
| 3750 | (char *)ha->name_string, buflen); |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 3751 | |
| 3752 | if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) { |
| 3753 | if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name, |
| 3754 | chap_tbl.secret, |
| 3755 | ddb_entry->chap_tbl_idx)) { |
| 3756 | iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME, |
| 3757 | (char *)chap_tbl.name, |
| 3758 | strlen((char *)chap_tbl.name)); |
| 3759 | iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD, |
| 3760 | (char *)chap_tbl.secret, |
| 3761 | chap_tbl.secret_len); |
| 3762 | } |
| 3763 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha, |
| 3767 | struct ddb_entry *ddb_entry) |
| 3768 | { |
| 3769 | struct iscsi_cls_session *cls_sess; |
| 3770 | struct iscsi_cls_conn *cls_conn; |
| 3771 | uint32_t ddb_state; |
| 3772 | dma_addr_t fw_ddb_entry_dma; |
| 3773 | struct dev_db_entry *fw_ddb_entry; |
| 3774 | |
| 3775 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3776 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3777 | if (!fw_ddb_entry) { |
| 3778 | ql4_printk(KERN_ERR, ha, |
| 3779 | "%s: Unable to allocate dma buffer\n", __func__); |
| 3780 | goto exit_session_conn_fwddb_param; |
| 3781 | } |
| 3782 | |
| 3783 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 3784 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 3785 | NULL, NULL, NULL) == QLA_ERROR) { |
| 3786 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 3787 | "get_ddb_entry for fw_ddb_index %d\n", |
| 3788 | ha->host_no, __func__, |
| 3789 | ddb_entry->fw_ddb_index)); |
| 3790 | goto exit_session_conn_fwddb_param; |
| 3791 | } |
| 3792 | |
| 3793 | cls_sess = ddb_entry->sess; |
| 3794 | |
| 3795 | cls_conn = ddb_entry->conn; |
| 3796 | |
| 3797 | /* Update params */ |
| 3798 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 3799 | |
| 3800 | exit_session_conn_fwddb_param: |
| 3801 | if (fw_ddb_entry) |
| 3802 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3803 | fw_ddb_entry, fw_ddb_entry_dma); |
| 3804 | } |
| 3805 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3806 | void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha, |
| 3807 | struct ddb_entry *ddb_entry) |
| 3808 | { |
| 3809 | struct iscsi_cls_session *cls_sess; |
| 3810 | struct iscsi_cls_conn *cls_conn; |
| 3811 | struct iscsi_session *sess; |
| 3812 | struct iscsi_conn *conn; |
| 3813 | uint32_t ddb_state; |
| 3814 | dma_addr_t fw_ddb_entry_dma; |
| 3815 | struct dev_db_entry *fw_ddb_entry; |
| 3816 | |
| 3817 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3818 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 3819 | if (!fw_ddb_entry) { |
| 3820 | ql4_printk(KERN_ERR, ha, |
| 3821 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3822 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 3826 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 3827 | NULL, NULL, NULL) == QLA_ERROR) { |
| 3828 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 3829 | "get_ddb_entry for fw_ddb_index %d\n", |
| 3830 | ha->host_no, __func__, |
| 3831 | ddb_entry->fw_ddb_index)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3832 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | cls_sess = ddb_entry->sess; |
| 3836 | sess = cls_sess->dd_data; |
| 3837 | |
| 3838 | cls_conn = ddb_entry->conn; |
| 3839 | conn = cls_conn->dd_data; |
| 3840 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3841 | /* Update timers after login */ |
| 3842 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 3843 | (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) && |
| 3844 | (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ? |
| 3845 | le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3846 | ddb_entry->default_time2wait = |
| 3847 | le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 3848 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3849 | /* Update params */ |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 3850 | 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] | 3851 | qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3852 | |
| 3853 | memcpy(sess->initiatorname, ha->name_string, |
| 3854 | min(sizeof(ha->name_string), sizeof(sess->initiatorname))); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3855 | |
| 3856 | exit_session_conn_param: |
| 3857 | if (fw_ddb_entry) |
| 3858 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 3859 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3862 | /* |
| 3863 | * Timer routines |
| 3864 | */ |
| 3865 | |
| 3866 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, |
| 3867 | unsigned long interval) |
| 3868 | { |
| 3869 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| 3870 | __func__, ha->host->host_no)); |
| 3871 | init_timer(&ha->timer); |
| 3872 | ha->timer.expires = jiffies + interval * HZ; |
| 3873 | ha->timer.data = (unsigned long)ha; |
| 3874 | ha->timer.function = (void (*)(unsigned long))func; |
| 3875 | add_timer(&ha->timer); |
| 3876 | ha->timer_active = 1; |
| 3877 | } |
| 3878 | |
| 3879 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| 3880 | { |
| 3881 | del_timer_sync(&ha->timer); |
| 3882 | ha->timer_active = 0; |
| 3883 | } |
| 3884 | |
| 3885 | /*** |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3886 | * qla4xxx_mark_device_missing - blocks the session |
| 3887 | * @cls_session: Pointer to the session to be blocked |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3888 | * @ddb_entry: Pointer to device database entry |
| 3889 | * |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3890 | * This routine marks a device missing and close connection. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3891 | **/ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3892 | void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3893 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3894 | iscsi_block_session(cls_session); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3897 | /** |
| 3898 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| 3899 | * @ha: Pointer to host adapter structure. |
| 3900 | * |
| 3901 | * This routine marks a device missing and resets the relogin retry count. |
| 3902 | **/ |
| 3903 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| 3904 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3905 | iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3906 | } |
| 3907 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3908 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| 3909 | struct ddb_entry *ddb_entry, |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 3910 | struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3911 | { |
| 3912 | struct srb *srb; |
| 3913 | |
| 3914 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 3915 | if (!srb) |
| 3916 | return srb; |
| 3917 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 3918 | kref_init(&srb->srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3919 | srb->ha = ha; |
| 3920 | srb->ddb = ddb_entry; |
| 3921 | srb->cmd = cmd; |
| 3922 | srb->flags = 0; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 3923 | CMD_SP(cmd) = (void *)srb; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3924 | |
| 3925 | return srb; |
| 3926 | } |
| 3927 | |
| 3928 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| 3929 | { |
| 3930 | struct scsi_cmnd *cmd = srb->cmd; |
| 3931 | |
| 3932 | if (srb->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 3933 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3934 | srb->flags &= ~SRB_DMA_VALID; |
| 3935 | } |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 3936 | CMD_SP(cmd) = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 3939 | void qla4xxx_srb_compl(struct kref *ref) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3940 | { |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 3941 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3942 | struct scsi_cmnd *cmd = srb->cmd; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 3943 | struct scsi_qla_host *ha = srb->ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3944 | |
| 3945 | qla4xxx_srb_free_dma(ha, srb); |
| 3946 | |
| 3947 | mempool_free(srb, ha->srb_mempool); |
| 3948 | |
| 3949 | cmd->scsi_done(cmd); |
| 3950 | } |
| 3951 | |
| 3952 | /** |
| 3953 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 3954 | * @host: scsi host |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3955 | * @cmd: Pointer to Linux's SCSI command structure |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3956 | * |
| 3957 | * Remarks: |
| 3958 | * This routine is invoked by Linux to send a SCSI command to the driver. |
| 3959 | * The mid-level driver tries to ensure that queuecommand never gets |
| 3960 | * invoked concurrently with itself or the interrupt handler (although |
| 3961 | * the interrupt handler may call this routine as part of request- |
| 3962 | * completion handling). Unfortunely, it sometimes calls the scheduler |
| 3963 | * in interrupt context which is a big NO! NO!. |
| 3964 | **/ |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 3965 | static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3966 | { |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 3967 | struct scsi_qla_host *ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3968 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 3969 | struct iscsi_cls_session *sess = ddb_entry->sess; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3970 | struct srb *srb; |
| 3971 | int rval; |
| 3972 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 3973 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 3974 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 3975 | cmd->result = DID_NO_CONNECT << 16; |
| 3976 | else |
| 3977 | cmd->result = DID_REQUEUE << 16; |
| 3978 | goto qc_fail_command; |
| 3979 | } |
| 3980 | |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 3981 | if (!sess) { |
| 3982 | cmd->result = DID_IMM_RETRY << 16; |
| 3983 | goto qc_fail_command; |
| 3984 | } |
| 3985 | |
| 3986 | rval = iscsi_session_chkready(sess); |
| 3987 | if (rval) { |
| 3988 | cmd->result = rval; |
| 3989 | goto qc_fail_command; |
| 3990 | } |
| 3991 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3992 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 3993 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 3994 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 3995 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 3996 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| 3997 | !test_bit(AF_ONLINE, &ha->flags) || |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3998 | !test_bit(AF_LINK_UP, &ha->flags) || |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 3999 | test_bit(AF_LOOPBACK, &ha->flags) || |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 4000 | test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) || |
| 4001 | test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4002 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4003 | goto qc_host_busy; |
| 4004 | |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4005 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4006 | if (!srb) |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4007 | goto qc_host_busy; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4008 | |
| 4009 | rval = qla4xxx_send_command_to_isp(ha, srb); |
| 4010 | if (rval != QLA_SUCCESS) |
| 4011 | goto qc_host_busy_free_sp; |
| 4012 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4013 | return 0; |
| 4014 | |
| 4015 | qc_host_busy_free_sp: |
| 4016 | qla4xxx_srb_free_dma(ha, srb); |
| 4017 | mempool_free(srb, ha->srb_mempool); |
| 4018 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4019 | qc_host_busy: |
| 4020 | return SCSI_MLQUEUE_HOST_BUSY; |
| 4021 | |
| 4022 | qc_fail_command: |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 4023 | cmd->scsi_done(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4024 | |
| 4025 | return 0; |
| 4026 | } |
| 4027 | |
| 4028 | /** |
| 4029 | * qla4xxx_mem_free - frees memory allocated to adapter |
| 4030 | * @ha: Pointer to host adapter structure. |
| 4031 | * |
| 4032 | * Frees memory previously allocated by qla4xxx_mem_alloc |
| 4033 | **/ |
| 4034 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| 4035 | { |
| 4036 | if (ha->queues) |
| 4037 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| 4038 | ha->queues_dma); |
| 4039 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 4040 | if (ha->fw_dump) |
| 4041 | vfree(ha->fw_dump); |
| 4042 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4043 | ha->queues_len = 0; |
| 4044 | ha->queues = NULL; |
| 4045 | ha->queues_dma = 0; |
| 4046 | ha->request_ring = NULL; |
| 4047 | ha->request_dma = 0; |
| 4048 | ha->response_ring = NULL; |
| 4049 | ha->response_dma = 0; |
| 4050 | ha->shadow_regs = NULL; |
| 4051 | ha->shadow_regs_dma = 0; |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 4052 | ha->fw_dump = NULL; |
| 4053 | ha->fw_dump_size = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4054 | |
| 4055 | /* Free srb pool. */ |
| 4056 | if (ha->srb_mempool) |
| 4057 | mempool_destroy(ha->srb_mempool); |
| 4058 | |
| 4059 | ha->srb_mempool = NULL; |
| 4060 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4061 | if (ha->chap_dma_pool) |
| 4062 | dma_pool_destroy(ha->chap_dma_pool); |
| 4063 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 4064 | if (ha->chap_list) |
| 4065 | vfree(ha->chap_list); |
| 4066 | ha->chap_list = NULL; |
| 4067 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4068 | if (ha->fw_ddb_dma_pool) |
| 4069 | dma_pool_destroy(ha->fw_ddb_dma_pool); |
| 4070 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4071 | /* release io space registers */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4072 | if (is_qla8022(ha)) { |
| 4073 | if (ha->nx_pcibase) |
| 4074 | iounmap( |
| 4075 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4076 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4077 | if (ha->nx_pcibase) |
| 4078 | iounmap( |
| 4079 | (struct device_reg_83xx __iomem *)ha->nx_pcibase); |
| 4080 | } else if (ha->reg) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4081 | iounmap(ha->reg); |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | if (ha->reset_tmplt.buff) |
| 4085 | vfree(ha->reset_tmplt.buff); |
| 4086 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4087 | pci_release_regions(ha->pdev); |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| 4092 | * @ha: Pointer to host adapter structure |
| 4093 | * |
| 4094 | * Allocates DMA memory for request and response queues. Also allocates memory |
| 4095 | * for srbs. |
| 4096 | **/ |
| 4097 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| 4098 | { |
| 4099 | unsigned long align; |
| 4100 | |
| 4101 | /* Allocate contiguous block of DMA memory for queues. */ |
| 4102 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4103 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4104 | sizeof(struct shadow_regs) + |
| 4105 | MEM_ALIGN_VALUE + |
| 4106 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 4107 | ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, |
| 4108 | &ha->queues_dma, GFP_KERNEL); |
| 4109 | if (ha->queues == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4110 | ql4_printk(KERN_WARNING, ha, |
| 4111 | "Memory Allocation failed - queues.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4112 | |
| 4113 | goto mem_alloc_error_exit; |
| 4114 | } |
| 4115 | memset(ha->queues, 0, ha->queues_len); |
| 4116 | |
| 4117 | /* |
| 4118 | * As per RISC alignment requirements -- the bus-address must be a |
| 4119 | * multiple of the request-ring size (in bytes). |
| 4120 | */ |
| 4121 | align = 0; |
| 4122 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| 4123 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| 4124 | (MEM_ALIGN_VALUE - 1)); |
| 4125 | |
| 4126 | /* Update request and response queue pointers. */ |
| 4127 | ha->request_dma = ha->queues_dma + align; |
| 4128 | ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| 4129 | ha->response_dma = ha->queues_dma + align + |
| 4130 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| 4131 | ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| 4132 | (REQUEST_QUEUE_DEPTH * |
| 4133 | QUEUE_SIZE)); |
| 4134 | ha->shadow_regs_dma = ha->queues_dma + align + |
| 4135 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 4136 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| 4137 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| 4138 | (REQUEST_QUEUE_DEPTH * |
| 4139 | QUEUE_SIZE) + |
| 4140 | (RESPONSE_QUEUE_DEPTH * |
| 4141 | QUEUE_SIZE)); |
| 4142 | |
| 4143 | /* Allocate memory for srb pool. */ |
| 4144 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 4145 | mempool_free_slab, srb_cachep); |
| 4146 | if (ha->srb_mempool == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4147 | ql4_printk(KERN_WARNING, ha, |
| 4148 | "Memory Allocation failed - SRB Pool.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4149 | |
| 4150 | goto mem_alloc_error_exit; |
| 4151 | } |
| 4152 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4153 | ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev, |
| 4154 | CHAP_DMA_BLOCK_SIZE, 8, 0); |
| 4155 | |
| 4156 | if (ha->chap_dma_pool == NULL) { |
| 4157 | ql4_printk(KERN_WARNING, ha, |
| 4158 | "%s: chap_dma_pool allocation failed..\n", __func__); |
| 4159 | goto mem_alloc_error_exit; |
| 4160 | } |
| 4161 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4162 | ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev, |
| 4163 | DDB_DMA_BLOCK_SIZE, 8, 0); |
| 4164 | |
| 4165 | if (ha->fw_ddb_dma_pool == NULL) { |
| 4166 | ql4_printk(KERN_WARNING, ha, |
| 4167 | "%s: fw_ddb_dma_pool allocation failed..\n", |
| 4168 | __func__); |
| 4169 | goto mem_alloc_error_exit; |
| 4170 | } |
| 4171 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4172 | return QLA_SUCCESS; |
| 4173 | |
| 4174 | mem_alloc_error_exit: |
| 4175 | qla4xxx_mem_free(ha); |
| 4176 | return QLA_ERROR; |
| 4177 | } |
| 4178 | |
| 4179 | /** |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4180 | * qla4_8xxx_check_temp - Check the ISP82XX temperature. |
| 4181 | * @ha: adapter block pointer. |
| 4182 | * |
| 4183 | * Note: The caller should not hold the idc lock. |
| 4184 | **/ |
| 4185 | static int qla4_8xxx_check_temp(struct scsi_qla_host *ha) |
| 4186 | { |
| 4187 | uint32_t temp, temp_state, temp_val; |
| 4188 | int status = QLA_SUCCESS; |
| 4189 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4190 | temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4191 | |
| 4192 | temp_state = qla82xx_get_temp_state(temp); |
| 4193 | temp_val = qla82xx_get_temp_val(temp); |
| 4194 | |
| 4195 | if (temp_state == QLA82XX_TEMP_PANIC) { |
| 4196 | ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C" |
| 4197 | " exceeds maximum allowed. Hardware has been shut" |
| 4198 | " down.\n", temp_val); |
| 4199 | status = QLA_ERROR; |
| 4200 | } else if (temp_state == QLA82XX_TEMP_WARN) { |
| 4201 | if (ha->temperature == QLA82XX_TEMP_NORMAL) |
| 4202 | ql4_printk(KERN_WARNING, ha, "Device temperature %d" |
| 4203 | " degrees C exceeds operating range." |
| 4204 | " Immediate action needed.\n", temp_val); |
| 4205 | } else { |
| 4206 | if (ha->temperature == QLA82XX_TEMP_WARN) |
| 4207 | ql4_printk(KERN_INFO, ha, "Device temperature is" |
| 4208 | " now %d degrees C in normal range.\n", |
| 4209 | temp_val); |
| 4210 | } |
| 4211 | ha->temperature = temp_state; |
| 4212 | return status; |
| 4213 | } |
| 4214 | |
| 4215 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4216 | * qla4_8xxx_check_fw_alive - Check firmware health |
| 4217 | * @ha: Pointer to host adapter structure. |
| 4218 | * |
| 4219 | * Context: Interrupt |
| 4220 | **/ |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4221 | static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4222 | { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4223 | uint32_t fw_heartbeat_counter; |
| 4224 | int status = QLA_SUCCESS; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4225 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4226 | fw_heartbeat_counter = qla4_8xxx_rd_direct(ha, |
| 4227 | QLA8XXX_PEG_ALIVE_COUNTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4228 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| 4229 | if (fw_heartbeat_counter == 0xffffffff) { |
| 4230 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| 4231 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| 4232 | ha->host_no, __func__)); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4233 | return status; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4234 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4235 | |
| 4236 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| 4237 | ha->seconds_since_last_heartbeat++; |
| 4238 | /* FW not alive after 2 seconds */ |
| 4239 | if (ha->seconds_since_last_heartbeat == 2) { |
| 4240 | ha->seconds_since_last_heartbeat = 0; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4241 | qla4_8xxx_dump_peg_reg(ha); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4242 | status = QLA_ERROR; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4243 | } |
Lalit Chandivade | 99457d7 | 2010-10-06 22:49:32 -0700 | [diff] [blame] | 4244 | } else |
| 4245 | ha->seconds_since_last_heartbeat = 0; |
| 4246 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4247 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4248 | return status; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4249 | } |
| 4250 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4251 | static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha) |
| 4252 | { |
| 4253 | uint32_t halt_status; |
| 4254 | int halt_status_unrecoverable = 0; |
| 4255 | |
| 4256 | halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1); |
| 4257 | |
| 4258 | if (is_qla8022(ha)) { |
| 4259 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 4260 | __func__); |
| 4261 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 4262 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 4263 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 4264 | |
| 4265 | if (QLA82XX_FWERROR_CODE(halt_status) == 0x67) |
| 4266 | ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n", |
| 4267 | __func__); |
| 4268 | if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| 4269 | halt_status_unrecoverable = 1; |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4270 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4271 | if (halt_status & QLA83XX_HALT_STATUS_FW_RESET) |
| 4272 | ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n", |
| 4273 | __func__); |
| 4274 | else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE) |
| 4275 | halt_status_unrecoverable = 1; |
| 4276 | } |
| 4277 | |
| 4278 | /* |
| 4279 | * Since we cannot change dev_state in interrupt context, |
| 4280 | * set appropriate DPC flag then wakeup DPC |
| 4281 | */ |
| 4282 | if (halt_status_unrecoverable) { |
| 4283 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 4284 | } else { |
| 4285 | ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n", |
| 4286 | __func__); |
| 4287 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4288 | } |
| 4289 | qla4xxx_mailbox_premature_completion(ha); |
| 4290 | qla4xxx_wake_dpc(ha); |
| 4291 | } |
| 4292 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4293 | /** |
| 4294 | * qla4_8xxx_watchdog - Poll dev state |
| 4295 | * @ha: Pointer to host adapter structure. |
| 4296 | * |
| 4297 | * Context: Interrupt |
| 4298 | **/ |
| 4299 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| 4300 | { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4301 | uint32_t dev_state; |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4302 | uint32_t idc_ctrl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4303 | |
| 4304 | /* don't poll if reset is going on */ |
Lalit Chandivade | d56a1f7 | 2010-12-02 22:12:45 -0800 | [diff] [blame] | 4305 | if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 4306 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
Vikas Chaudhary | 977f46a | 2011-05-17 23:17:08 -0700 | [diff] [blame] | 4307 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4308 | dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4309 | |
| 4310 | if (qla4_8xxx_check_temp(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4311 | if (is_qla8022(ha)) { |
| 4312 | ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n"); |
| 4313 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 4314 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 4315 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 4316 | } |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 4317 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 4318 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4319 | } else if (dev_state == QLA8XXX_DEV_NEED_RESET && |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4320 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4321 | |
| 4322 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n", |
| 4323 | __func__); |
| 4324 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4325 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 4326 | idc_ctrl = qla4_83xx_rd_reg(ha, |
| 4327 | QLA83XX_IDC_DRV_CTRL); |
| 4328 | if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) { |
| 4329 | ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n", |
| 4330 | __func__); |
| 4331 | qla4xxx_mailbox_premature_completion( |
| 4332 | ha); |
| 4333 | } |
| 4334 | } |
| 4335 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4336 | if ((is_qla8032(ha) || is_qla8042(ha)) || |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4337 | (is_qla8022(ha) && !ql4xdontresethba)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4338 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4339 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4340 | } |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4341 | } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4342 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 4343 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
| 4344 | __func__); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4345 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| 4346 | qla4xxx_wake_dpc(ha); |
| 4347 | } else { |
| 4348 | /* Check firmware health */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4349 | if (qla4_8xxx_check_fw_alive(ha)) |
| 4350 | qla4_8xxx_process_fw_error(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4351 | } |
| 4352 | } |
| 4353 | } |
| 4354 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 4355 | 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] | 4356 | { |
| 4357 | struct iscsi_session *sess; |
| 4358 | struct ddb_entry *ddb_entry; |
| 4359 | struct scsi_qla_host *ha; |
| 4360 | |
| 4361 | sess = cls_sess->dd_data; |
| 4362 | ddb_entry = sess->dd_data; |
| 4363 | ha = ddb_entry->ha; |
| 4364 | |
| 4365 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 4366 | return; |
| 4367 | |
| 4368 | if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 4369 | !iscsi_is_session_online(cls_sess)) { |
| 4370 | if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| 4371 | INVALID_ENTRY) { |
| 4372 | if (atomic_read(&ddb_entry->retry_relogin_timer) == |
| 4373 | 0) { |
| 4374 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 4375 | INVALID_ENTRY); |
| 4376 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4377 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 4378 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4379 | "%s: index [%d] login device\n", |
| 4380 | __func__, ddb_entry->fw_ddb_index)); |
| 4381 | } else |
| 4382 | atomic_dec(&ddb_entry->retry_relogin_timer); |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | /* Wait for relogin to timeout */ |
| 4387 | if (atomic_read(&ddb_entry->relogin_timer) && |
| 4388 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| 4389 | /* |
| 4390 | * If the relogin times out and the device is |
| 4391 | * still NOT ONLINE then try and relogin again. |
| 4392 | */ |
| 4393 | if (!iscsi_is_session_online(cls_sess)) { |
| 4394 | /* Reset retry relogin timer */ |
| 4395 | atomic_inc(&ddb_entry->relogin_retry_count); |
| 4396 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4397 | "%s: index[%d] relogin timed out-retrying" |
| 4398 | " relogin (%d), retry (%d)\n", __func__, |
| 4399 | ddb_entry->fw_ddb_index, |
| 4400 | atomic_read(&ddb_entry->relogin_retry_count), |
| 4401 | ddb_entry->default_time2wait + 4)); |
| 4402 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 4403 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 4404 | ddb_entry->default_time2wait + 4); |
| 4405 | } |
| 4406 | } |
| 4407 | } |
| 4408 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4409 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4410 | * qla4xxx_timer - checks every second for work to do. |
| 4411 | * @ha: Pointer to host adapter structure. |
| 4412 | **/ |
| 4413 | static void qla4xxx_timer(struct scsi_qla_host *ha) |
| 4414 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4415 | int start_dpc = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4416 | uint16_t w; |
| 4417 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4418 | iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb); |
| 4419 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 4420 | /* If we are in the middle of AER/EEH processing |
| 4421 | * skip any processing and reschedule the timer |
| 4422 | */ |
| 4423 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 4424 | mod_timer(&ha->timer, jiffies + HZ); |
| 4425 | return; |
| 4426 | } |
| 4427 | |
| 4428 | /* Hardware read to trigger an EEH error during mailbox waits. */ |
| 4429 | if (!pci_channel_offline(ha->pdev)) |
| 4430 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4431 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4432 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4433 | qla4_8xxx_watchdog(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4434 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4435 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4436 | /* Check for heartbeat interval. */ |
| 4437 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| 4438 | ha->heartbeat_interval != 0) { |
| 4439 | ha->seconds_since_last_heartbeat++; |
| 4440 | if (ha->seconds_since_last_heartbeat > |
| 4441 | ha->heartbeat_interval + 2) |
| 4442 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4443 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 4446 | /* Process any deferred work. */ |
| 4447 | if (!list_empty(&ha->work_list)) |
| 4448 | start_dpc++; |
| 4449 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4450 | /* Wakeup the dpc routine for this adapter, if needed. */ |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 4451 | if (start_dpc || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4452 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 4453 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| 4454 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4455 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4456 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 4457 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 4458 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4459 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 4460 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 4461 | test_bit(DPC_AEN, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4462 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| 4463 | " - dpc flags = 0x%lx\n", |
| 4464 | ha->host_no, __func__, ha->dpc_flags)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4465 | qla4xxx_wake_dpc(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | /* Reschedule timer thread to call us back in one second */ |
| 4469 | mod_timer(&ha->timer, jiffies + HZ); |
| 4470 | |
| 4471 | DEBUG2(ha->seconds_since_last_intr++); |
| 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| 4476 | * @ha: Pointer to host adapter structure. |
| 4477 | * |
| 4478 | * This routine stalls the driver until all outstanding commands are returned. |
| 4479 | * Caller must release the Hardware Lock prior to calling this routine. |
| 4480 | **/ |
| 4481 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| 4482 | { |
| 4483 | uint32_t index = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4484 | unsigned long flags; |
| 4485 | struct scsi_cmnd *cmd; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4486 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4487 | unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
| 4488 | |
| 4489 | DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " |
| 4490 | "complete\n", WAIT_CMD_TOV)); |
| 4491 | |
| 4492 | while (!time_after_eq(jiffies, wtime)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4493 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4494 | /* Find a command that hasn't completed. */ |
| 4495 | for (index = 0; index < ha->host->can_queue; index++) { |
| 4496 | cmd = scsi_host_find_tag(ha->host, index); |
Mike Christie | a1e0063 | 2010-10-26 05:45:30 -0700 | [diff] [blame] | 4497 | /* |
| 4498 | * We cannot just check if the index is valid, |
| 4499 | * becase if we are run from the scsi eh, then |
| 4500 | * the scsi/block layer is going to prevent |
| 4501 | * the tag from being released. |
| 4502 | */ |
| 4503 | if (cmd != NULL && CMD_SP(cmd)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4504 | break; |
| 4505 | } |
| 4506 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4507 | |
| 4508 | /* If No Commands are pending, wait is complete */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4509 | if (index == ha->host->can_queue) |
| 4510 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4511 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4512 | msleep(1000); |
| 4513 | } |
| 4514 | /* If we timed out on waiting for commands to come back |
| 4515 | * return ERROR. */ |
| 4516 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4519 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4520 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4521 | uint32_t ctrl_status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4522 | unsigned long flags = 0; |
| 4523 | |
| 4524 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4525 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4526 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 4527 | return QLA_ERROR; |
| 4528 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4529 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4530 | |
| 4531 | /* |
| 4532 | * If the SCSI Reset Interrupt bit is set, clear it. |
| 4533 | * Otherwise, the Soft Reset won't work. |
| 4534 | */ |
| 4535 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4536 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| 4537 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 4538 | |
| 4539 | /* Issue Soft Reset */ |
| 4540 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| 4541 | readl(&ha->reg->ctrl_status); |
| 4542 | |
| 4543 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4544 | return QLA_SUCCESS; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | /** |
| 4548 | * qla4xxx_soft_reset - performs soft reset. |
| 4549 | * @ha: Pointer to host adapter structure. |
| 4550 | **/ |
| 4551 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| 4552 | { |
| 4553 | uint32_t max_wait_time; |
| 4554 | unsigned long flags = 0; |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4555 | int status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 4556 | uint32_t ctrl_status; |
| 4557 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4558 | status = qla4xxx_hw_reset(ha); |
| 4559 | if (status != QLA_SUCCESS) |
| 4560 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4561 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 4562 | status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4563 | /* Wait until the Network Reset Intr bit is cleared */ |
| 4564 | max_wait_time = RESET_INTR_TOV; |
| 4565 | do { |
| 4566 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4567 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4568 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4569 | |
| 4570 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| 4571 | break; |
| 4572 | |
| 4573 | msleep(1000); |
| 4574 | } while ((--max_wait_time)); |
| 4575 | |
| 4576 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| 4577 | DEBUG2(printk(KERN_WARNING |
| 4578 | "scsi%ld: Network Reset Intr not cleared by " |
| 4579 | "Network function, clearing it now!\n", |
| 4580 | ha->host_no)); |
| 4581 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4582 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| 4583 | readl(&ha->reg->ctrl_status); |
| 4584 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4585 | } |
| 4586 | |
| 4587 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 4588 | max_wait_time = SOFT_RESET_TOV; |
| 4589 | do { |
| 4590 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4591 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4592 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4593 | |
| 4594 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| 4595 | status = QLA_SUCCESS; |
| 4596 | break; |
| 4597 | } |
| 4598 | |
| 4599 | msleep(1000); |
| 4600 | } while ((--max_wait_time)); |
| 4601 | |
| 4602 | /* |
| 4603 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| 4604 | * after the soft reset has taken place. |
| 4605 | */ |
| 4606 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4607 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4608 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| 4609 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 4610 | readl(&ha->reg->ctrl_status); |
| 4611 | } |
| 4612 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4613 | |
| 4614 | /* If soft reset fails then most probably the bios on other |
| 4615 | * function is also enabled. |
| 4616 | * Since the initialization is sequential the other fn |
| 4617 | * wont be able to acknowledge the soft reset. |
| 4618 | * Issue a force soft reset to workaround this scenario. |
| 4619 | */ |
| 4620 | if (max_wait_time == 0) { |
| 4621 | /* Issue Force Soft Reset */ |
| 4622 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4623 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| 4624 | readl(&ha->reg->ctrl_status); |
| 4625 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4626 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 4627 | max_wait_time = SOFT_RESET_TOV; |
| 4628 | do { |
| 4629 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4630 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 4631 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4632 | |
| 4633 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| 4634 | status = QLA_SUCCESS; |
| 4635 | break; |
| 4636 | } |
| 4637 | |
| 4638 | msleep(1000); |
| 4639 | } while ((--max_wait_time)); |
| 4640 | } |
| 4641 | |
| 4642 | return status; |
| 4643 | } |
| 4644 | |
| 4645 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4646 | * 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] | 4647 | * @ha: Pointer to host adapter structure. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4648 | * @res: returned scsi status |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4649 | * |
| 4650 | * This routine is called just prior to a HARD RESET to return all |
| 4651 | * outstanding commands back to the Operating System. |
| 4652 | * Caller should make sure that the following locks are released |
| 4653 | * before this calling routine: Hardware lock, and io_request_lock. |
| 4654 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4655 | 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] | 4656 | { |
| 4657 | struct srb *srb; |
| 4658 | int i; |
| 4659 | unsigned long flags; |
| 4660 | |
| 4661 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4662 | for (i = 0; i < ha->host->can_queue; i++) { |
| 4663 | srb = qla4xxx_del_from_active_array(ha, i); |
| 4664 | if (srb != NULL) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4665 | srb->cmd->result = res; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 4666 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4667 | } |
| 4668 | } |
| 4669 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4672 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| 4673 | { |
| 4674 | clear_bit(AF_ONLINE, &ha->flags); |
| 4675 | |
| 4676 | /* Disable the board */ |
| 4677 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4678 | |
| 4679 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 4680 | qla4xxx_mark_all_devices_missing(ha); |
| 4681 | clear_bit(AF_INIT_DONE, &ha->flags); |
| 4682 | } |
| 4683 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4684 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session) |
| 4685 | { |
| 4686 | struct iscsi_session *sess; |
| 4687 | struct ddb_entry *ddb_entry; |
| 4688 | |
| 4689 | sess = cls_session->dd_data; |
| 4690 | ddb_entry = sess->dd_data; |
| 4691 | ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4692 | |
| 4693 | if (ddb_entry->ddb_type == FLASH_DDB) |
| 4694 | iscsi_block_session(ddb_entry->sess); |
| 4695 | else |
| 4696 | iscsi_session_failure(cls_session->dd_data, |
| 4697 | ISCSI_ERR_CONN_FAILED); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4698 | } |
| 4699 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4700 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4701 | * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| 4702 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4703 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4704 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4705 | { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4706 | int status = QLA_ERROR; |
| 4707 | uint8_t reset_chip = 0; |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4708 | uint32_t dev_state; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4709 | unsigned long wait; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4710 | |
| 4711 | /* Stall incoming I/O until we are done */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4712 | scsi_block_requests(ha->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4713 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4714 | clear_bit(AF_LINK_UP, &ha->flags); |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 4715 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4716 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4717 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4718 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4719 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 4720 | if ((is_qla8032(ha) || is_qla8042(ha)) && |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 4721 | !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 4722 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 4723 | __func__); |
| 4724 | /* disable pause frame for ISP83xx */ |
| 4725 | qla4_83xx_disable_pause(ha); |
| 4726 | } |
| 4727 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4728 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
| 4729 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4730 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 4731 | reset_chip = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4732 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4733 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| 4734 | * do not reset adapter, jump to initialize_adapter */ |
| 4735 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| 4736 | status = QLA_SUCCESS; |
| 4737 | goto recover_ha_init_adapter; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4738 | } |
| 4739 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4740 | /* For the ISP-8xxx adapter, issue a stop_firmware if invoked |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4741 | * from eh_host_reset or ioctl module */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4742 | if (is_qla80XX(ha) && !reset_chip && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4743 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 4744 | |
| 4745 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4746 | "scsi%ld: %s - Performing stop_firmware...\n", |
| 4747 | ha->host_no, __func__)); |
| 4748 | status = ha->isp_ops->reset_firmware(ha); |
| 4749 | if (status == QLA_SUCCESS) { |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 4750 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4751 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 4752 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4753 | ha->isp_ops->disable_intrs(ha); |
| 4754 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4755 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 4756 | } else { |
| 4757 | /* If the stop_firmware fails then |
| 4758 | * reset the entire chip */ |
| 4759 | reset_chip = 1; |
| 4760 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 4761 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | /* Issue full chip reset if recovering from a catastrophic error, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4766 | * or if stop_firmware fails for ISP-8xxx. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4767 | * This is the default case for ISP-4xxx */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4768 | if (is_qla40XX(ha) || reset_chip) { |
| 4769 | if (is_qla40XX(ha)) |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4770 | goto chip_reset; |
| 4771 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4772 | /* Check if 8XXX firmware is alive or not |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 4773 | * We may have arrived here from NEED_RESET |
| 4774 | * detection only */ |
| 4775 | if (test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4776 | goto chip_reset; |
| 4777 | |
| 4778 | wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ); |
| 4779 | while (time_before(jiffies, wait)) { |
| 4780 | if (qla4_8xxx_check_fw_alive(ha)) { |
| 4781 | qla4xxx_mailbox_premature_completion(ha); |
| 4782 | break; |
| 4783 | } |
| 4784 | |
| 4785 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 4786 | schedule_timeout(HZ); |
| 4787 | } |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 4788 | chip_reset: |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 4789 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 4790 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 4791 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4792 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4793 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 4794 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4795 | "scsi%ld: %s - Performing chip reset..\n", |
| 4796 | ha->host_no, __func__)); |
| 4797 | status = ha->isp_ops->reset_chip(ha); |
| 4798 | } |
| 4799 | |
| 4800 | /* Flush any pending ddb changed AENs */ |
| 4801 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 4802 | |
| 4803 | recover_ha_init_adapter: |
| 4804 | /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| 4805 | if (status == QLA_SUCCESS) { |
| 4806 | /* For ISP-4xxx, force function 1 to always initialize |
| 4807 | * before function 3 to prevent both funcions from |
| 4808 | * stepping on top of the other */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 4809 | if (is_qla40XX(ha) && (ha->mac_index == 3)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4810 | ssleep(6); |
| 4811 | |
| 4812 | /* NOTE: AF_ONLINE flag set upon successful completion of |
| 4813 | * qla4xxx_initialize_adapter */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4814 | status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | /* Retry failed adapter initialization, if necessary |
| 4818 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| 4819 | * case to prevent ping-pong resets between functions */ |
| 4820 | if (!test_bit(AF_ONLINE, &ha->flags) && |
| 4821 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4822 | /* Adapter initialization failed, see if we can retry |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4823 | * resetting the ha. |
| 4824 | * Since we don't want to block the DPC for too long |
| 4825 | * with multiple resets in the same thread, |
| 4826 | * utilize DPC to retry */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4827 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4828 | ha->isp_ops->idc_lock(ha); |
| 4829 | dev_state = qla4_8xxx_rd_direct(ha, |
| 4830 | QLA8XXX_CRB_DEV_STATE); |
| 4831 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 4832 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4833 | ql4_printk(KERN_INFO, ha, "%s: don't retry " |
| 4834 | "recover adapter. H/W is in Failed " |
| 4835 | "state\n", __func__); |
| 4836 | qla4xxx_dead_adapter_cleanup(ha); |
| 4837 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4838 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 4839 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 4840 | &ha->dpc_flags); |
| 4841 | status = QLA_ERROR; |
| 4842 | |
| 4843 | goto exit_recover; |
| 4844 | } |
| 4845 | } |
| 4846 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4847 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| 4848 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| 4849 | DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| 4850 | "(%d) more times\n", ha->host_no, |
| 4851 | ha->retry_reset_ha_cnt)); |
| 4852 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4853 | status = QLA_ERROR; |
| 4854 | } else { |
| 4855 | if (ha->retry_reset_ha_cnt > 0) { |
| 4856 | /* Schedule another Reset HA--DPC will retry */ |
| 4857 | ha->retry_reset_ha_cnt--; |
| 4858 | DEBUG2(printk("scsi%ld: recover adapter - " |
| 4859 | "retry remaining %d\n", |
| 4860 | ha->host_no, |
| 4861 | ha->retry_reset_ha_cnt)); |
| 4862 | status = QLA_ERROR; |
| 4863 | } |
| 4864 | |
| 4865 | if (ha->retry_reset_ha_cnt == 0) { |
| 4866 | /* Recover adapter retries have been exhausted. |
| 4867 | * Adapter DEAD */ |
| 4868 | DEBUG2(printk("scsi%ld: recover adapter " |
| 4869 | "failed - board disabled\n", |
| 4870 | ha->host_no)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4871 | qla4xxx_dead_adapter_cleanup(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4872 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4873 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4874 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4875 | &ha->dpc_flags); |
| 4876 | status = QLA_ERROR; |
| 4877 | } |
| 4878 | } |
| 4879 | } else { |
| 4880 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4881 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4882 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 4883 | } |
| 4884 | |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 4885 | exit_recover: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4886 | ha->adapter_error_count++; |
| 4887 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4888 | if (test_bit(AF_ONLINE, &ha->flags)) |
| 4889 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4890 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4891 | scsi_unblock_requests(ha->host); |
| 4892 | |
| 4893 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 4894 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4895 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4896 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4897 | return status; |
| 4898 | } |
| 4899 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4900 | static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session) |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 4901 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4902 | struct iscsi_session *sess; |
| 4903 | struct ddb_entry *ddb_entry; |
| 4904 | struct scsi_qla_host *ha; |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 4905 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4906 | sess = cls_session->dd_data; |
| 4907 | ddb_entry = sess->dd_data; |
| 4908 | ha = ddb_entry->ha; |
| 4909 | if (!iscsi_is_session_online(cls_session)) { |
| 4910 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| 4911 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 4912 | " unblock session\n", ha->host_no, __func__, |
| 4913 | ddb_entry->fw_ddb_index); |
| 4914 | iscsi_unblock_session(ddb_entry->sess); |
| 4915 | } else { |
| 4916 | /* Trigger relogin */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4917 | if (ddb_entry->ddb_type == FLASH_DDB) { |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 4918 | if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) || |
| 4919 | test_bit(DF_DISABLE_RELOGIN, |
| 4920 | &ddb_entry->flags))) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4921 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 4922 | } else |
| 4923 | iscsi_session_failure(cls_session->dd_data, |
| 4924 | ISCSI_ERR_CONN_FAILED); |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 4925 | } |
| 4926 | } |
| 4927 | } |
| 4928 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4929 | int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session) |
| 4930 | { |
| 4931 | struct iscsi_session *sess; |
| 4932 | struct ddb_entry *ddb_entry; |
| 4933 | struct scsi_qla_host *ha; |
| 4934 | |
| 4935 | sess = cls_session->dd_data; |
| 4936 | ddb_entry = sess->dd_data; |
| 4937 | ha = ddb_entry->ha; |
| 4938 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 4939 | " unblock session\n", ha->host_no, __func__, |
| 4940 | ddb_entry->fw_ddb_index); |
| 4941 | |
| 4942 | iscsi_unblock_session(ddb_entry->sess); |
| 4943 | |
| 4944 | /* Start scan target */ |
| 4945 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 4946 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 4947 | " start scan\n", ha->host_no, __func__, |
| 4948 | ddb_entry->fw_ddb_index); |
| 4949 | scsi_queue_work(ha->host, &ddb_entry->sess->scan_work); |
| 4950 | } |
| 4951 | return QLA_SUCCESS; |
| 4952 | } |
| 4953 | |
| 4954 | int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session) |
| 4955 | { |
| 4956 | struct iscsi_session *sess; |
| 4957 | struct ddb_entry *ddb_entry; |
| 4958 | struct scsi_qla_host *ha; |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 4959 | int status = QLA_SUCCESS; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4960 | |
| 4961 | sess = cls_session->dd_data; |
| 4962 | ddb_entry = sess->dd_data; |
| 4963 | ha = ddb_entry->ha; |
| 4964 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 4965 | " unblock user space session\n", ha->host_no, __func__, |
| 4966 | ddb_entry->fw_ddb_index); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4967 | |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 4968 | if (!iscsi_is_session_online(cls_session)) { |
| 4969 | iscsi_conn_start(ddb_entry->conn); |
| 4970 | iscsi_conn_login_event(ddb_entry->conn, |
| 4971 | ISCSI_CONN_STATE_LOGGED_IN); |
| 4972 | } else { |
| 4973 | ql4_printk(KERN_INFO, ha, |
| 4974 | "scsi%ld: %s: ddb[%d] session [%d] already logged in\n", |
| 4975 | ha->host_no, __func__, ddb_entry->fw_ddb_index, |
| 4976 | cls_session->sid); |
| 4977 | status = QLA_ERROR; |
| 4978 | } |
| 4979 | |
| 4980 | return status; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4981 | } |
| 4982 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 4983 | static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
| 4984 | { |
| 4985 | iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices); |
| 4986 | } |
| 4987 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4988 | static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| 4989 | { |
| 4990 | uint16_t relogin_timer; |
| 4991 | struct iscsi_session *sess; |
| 4992 | struct ddb_entry *ddb_entry; |
| 4993 | struct scsi_qla_host *ha; |
| 4994 | |
| 4995 | sess = cls_sess->dd_data; |
| 4996 | ddb_entry = sess->dd_data; |
| 4997 | ha = ddb_entry->ha; |
| 4998 | |
| 4999 | relogin_timer = max(ddb_entry->default_relogin_timeout, |
| 5000 | (uint16_t)RELOGIN_TOV); |
| 5001 | atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| 5002 | |
| 5003 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5004 | "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no, |
| 5005 | ddb_entry->fw_ddb_index, relogin_timer)); |
| 5006 | |
| 5007 | qla4xxx_login_flash_ddb(cls_sess); |
| 5008 | } |
| 5009 | |
| 5010 | static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess) |
| 5011 | { |
| 5012 | struct iscsi_session *sess; |
| 5013 | struct ddb_entry *ddb_entry; |
| 5014 | struct scsi_qla_host *ha; |
| 5015 | |
| 5016 | sess = cls_sess->dd_data; |
| 5017 | ddb_entry = sess->dd_data; |
| 5018 | ha = ddb_entry->ha; |
| 5019 | |
| 5020 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 5021 | return; |
| 5022 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 5023 | if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) |
| 5024 | return; |
| 5025 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5026 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 5027 | !iscsi_is_session_online(cls_sess)) { |
| 5028 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5029 | "relogin issued\n")); |
| 5030 | qla4xxx_relogin_flash_ddb(cls_sess); |
| 5031 | } |
| 5032 | } |
| 5033 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5034 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| 5035 | { |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5036 | if (ha->dpc_thread) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5037 | queue_work(ha->dpc_thread, &ha->dpc_work); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5038 | } |
| 5039 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5040 | static struct qla4_work_evt * |
| 5041 | qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size, |
| 5042 | enum qla4_work_type type) |
| 5043 | { |
| 5044 | struct qla4_work_evt *e; |
| 5045 | uint32_t size = sizeof(struct qla4_work_evt) + data_size; |
| 5046 | |
| 5047 | e = kzalloc(size, GFP_ATOMIC); |
| 5048 | if (!e) |
| 5049 | return NULL; |
| 5050 | |
| 5051 | INIT_LIST_HEAD(&e->list); |
| 5052 | e->type = type; |
| 5053 | return e; |
| 5054 | } |
| 5055 | |
| 5056 | static void qla4xxx_post_work(struct scsi_qla_host *ha, |
| 5057 | struct qla4_work_evt *e) |
| 5058 | { |
| 5059 | unsigned long flags; |
| 5060 | |
| 5061 | spin_lock_irqsave(&ha->work_lock, flags); |
| 5062 | list_add_tail(&e->list, &ha->work_list); |
| 5063 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 5064 | qla4xxx_wake_dpc(ha); |
| 5065 | } |
| 5066 | |
| 5067 | int qla4xxx_post_aen_work(struct scsi_qla_host *ha, |
| 5068 | enum iscsi_host_event_code aen_code, |
| 5069 | uint32_t data_size, uint8_t *data) |
| 5070 | { |
| 5071 | struct qla4_work_evt *e; |
| 5072 | |
| 5073 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN); |
| 5074 | if (!e) |
| 5075 | return QLA_ERROR; |
| 5076 | |
| 5077 | e->u.aen.code = aen_code; |
| 5078 | e->u.aen.data_size = data_size; |
| 5079 | memcpy(e->u.aen.data, data, data_size); |
| 5080 | |
| 5081 | qla4xxx_post_work(ha, e); |
| 5082 | |
| 5083 | return QLA_SUCCESS; |
| 5084 | } |
| 5085 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 5086 | int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha, |
| 5087 | uint32_t status, uint32_t pid, |
| 5088 | uint32_t data_size, uint8_t *data) |
| 5089 | { |
| 5090 | struct qla4_work_evt *e; |
| 5091 | |
| 5092 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS); |
| 5093 | if (!e) |
| 5094 | return QLA_ERROR; |
| 5095 | |
| 5096 | e->u.ping.status = status; |
| 5097 | e->u.ping.pid = pid; |
| 5098 | e->u.ping.data_size = data_size; |
| 5099 | memcpy(e->u.ping.data, data, data_size); |
| 5100 | |
| 5101 | qla4xxx_post_work(ha, e); |
| 5102 | |
| 5103 | return QLA_SUCCESS; |
| 5104 | } |
| 5105 | |
Vikas Chaudhary | a7380a6 | 2012-02-27 03:08:56 -0800 | [diff] [blame] | 5106 | static void qla4xxx_do_work(struct scsi_qla_host *ha) |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5107 | { |
| 5108 | struct qla4_work_evt *e, *tmp; |
| 5109 | unsigned long flags; |
| 5110 | LIST_HEAD(work); |
| 5111 | |
| 5112 | spin_lock_irqsave(&ha->work_lock, flags); |
| 5113 | list_splice_init(&ha->work_list, &work); |
| 5114 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 5115 | |
| 5116 | list_for_each_entry_safe(e, tmp, &work, list) { |
| 5117 | list_del_init(&e->list); |
| 5118 | |
| 5119 | switch (e->type) { |
| 5120 | case QLA4_EVENT_AEN: |
| 5121 | iscsi_post_host_event(ha->host_no, |
| 5122 | &qla4xxx_iscsi_transport, |
| 5123 | e->u.aen.code, |
| 5124 | e->u.aen.data_size, |
| 5125 | e->u.aen.data); |
| 5126 | break; |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 5127 | case QLA4_EVENT_PING_STATUS: |
| 5128 | iscsi_ping_comp_event(ha->host_no, |
| 5129 | &qla4xxx_iscsi_transport, |
| 5130 | e->u.ping.status, |
| 5131 | e->u.ping.pid, |
| 5132 | e->u.ping.data_size, |
| 5133 | e->u.ping.data); |
| 5134 | break; |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5135 | default: |
| 5136 | ql4_printk(KERN_WARNING, ha, "event type: 0x%x not " |
| 5137 | "supported", e->type); |
| 5138 | } |
| 5139 | kfree(e); |
| 5140 | } |
| 5141 | } |
| 5142 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5143 | /** |
| 5144 | * qla4xxx_do_dpc - dpc routine |
| 5145 | * @data: in our case pointer to adapter structure |
| 5146 | * |
| 5147 | * This routine is a task that is schedule by the interrupt handler |
| 5148 | * to perform the background processing for interrupts. We put it |
| 5149 | * on a task queue that is consumed whenever the scheduler runs; that's |
| 5150 | * so you can do anything (i.e. put the process to sleep etc). In fact, |
| 5151 | * the mid-level tries to sleep when it reaches the driver threshold |
| 5152 | * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| 5153 | **/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5154 | static void qla4xxx_do_dpc(struct work_struct *work) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5155 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5156 | struct scsi_qla_host *ha = |
| 5157 | container_of(work, struct scsi_qla_host, dpc_work); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5158 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5159 | |
David C Somayajulu | f26b904 | 2006-11-15 16:41:09 -0800 | [diff] [blame] | 5160 | DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5161 | "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| 5162 | ha->host_no, __func__, ha->flags, ha->dpc_flags)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5163 | |
| 5164 | /* Initialization not yet finished. Don't do anything yet. */ |
| 5165 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5166 | return; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5167 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5168 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 5169 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| 5170 | ha->host_no, __func__, ha->flags)); |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 5171 | return; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 5172 | } |
| 5173 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 5174 | /* post events to application */ |
| 5175 | qla4xxx_do_work(ha); |
| 5176 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5177 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5178 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5179 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 5180 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 5181 | __func__); |
| 5182 | /* disable pause frame for ISP83xx */ |
| 5183 | qla4_83xx_disable_pause(ha); |
| 5184 | } |
| 5185 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5186 | ha->isp_ops->idc_lock(ha); |
| 5187 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 5188 | QLA8XXX_DEV_FAILED); |
| 5189 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5190 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 5191 | qla4_8xxx_device_state_handler(ha); |
| 5192 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5193 | |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 5194 | if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) { |
| 5195 | if (is_qla8042(ha)) { |
| 5196 | if (ha->idc_info.info2 & |
| 5197 | ENABLE_INTERNAL_LOOPBACK) { |
| 5198 | ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n", |
| 5199 | __func__); |
| 5200 | status = qla4_84xx_config_acb(ha, |
| 5201 | ACB_CONFIG_DISABLE); |
| 5202 | if (status != QLA_SUCCESS) { |
| 5203 | ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n", |
| 5204 | __func__); |
| 5205 | } |
| 5206 | } |
| 5207 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5208 | qla4_83xx_post_idc_ack(ha); |
Nilesh Javali | 7ab284c | 2013-08-16 07:03:03 -0400 | [diff] [blame] | 5209 | clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags); |
| 5210 | } |
| 5211 | |
| 5212 | if (is_qla8042(ha) && |
| 5213 | test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) { |
| 5214 | ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n", |
| 5215 | __func__); |
| 5216 | if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) != |
| 5217 | QLA_SUCCESS) { |
| 5218 | ql4_printk(KERN_INFO, ha, "%s: ACB config failed ", |
| 5219 | __func__); |
| 5220 | } |
| 5221 | clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags); |
| 5222 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 5223 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5224 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 5225 | qla4_8xxx_need_qsnt_handler(ha); |
| 5226 | } |
| 5227 | } |
| 5228 | |
| 5229 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| 5230 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5231 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5232 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5233 | if ((is_qla8022(ha) && ql4xdontresethba) || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5234 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 5235 | qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5236 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 5237 | ha->host_no, __func__)); |
| 5238 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 5239 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 5240 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 5241 | goto dpc_post_reset_ha; |
| 5242 | } |
| 5243 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| 5244 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 5245 | qla4xxx_recover_adapter(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5246 | |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5247 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5248 | uint8_t wait_time = RESET_INTR_TOV; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5249 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5250 | while ((readw(&ha->reg->ctrl_status) & |
| 5251 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| 5252 | if (--wait_time == 0) |
| 5253 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5254 | msleep(1000); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5255 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5256 | if (wait_time == 0) |
| 5257 | DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| 5258 | "bit not cleared-- resetting\n", |
| 5259 | ha->host_no, __func__)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5260 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5261 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| 5262 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5263 | status = qla4xxx_recover_adapter(ha); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 5264 | } |
| 5265 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 5266 | if (status == QLA_SUCCESS) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5267 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5271 | dpc_post_reset_ha: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5272 | /* ---- process AEN? --- */ |
| 5273 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 5274 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| 5275 | |
| 5276 | /* ---- Get DHCP IP Address? --- */ |
| 5277 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 5278 | qla4xxx_get_dhcp_ip_address(ha); |
| 5279 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5280 | /* ---- relogin device? --- */ |
| 5281 | if (adapter_up(ha) && |
| 5282 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| 5283 | iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin); |
| 5284 | } |
| 5285 | |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5286 | /* ---- link change? --- */ |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 5287 | if (!test_bit(AF_LOOPBACK, &ha->flags) && |
| 5288 | test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5289 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 5290 | /* ---- link down? --- */ |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 5291 | qla4xxx_mark_all_devices_missing(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5292 | } else { |
| 5293 | /* ---- link up? --- * |
| 5294 | * F/W will auto login to all devices ONLY ONCE after |
| 5295 | * link up during driver initialization and runtime |
| 5296 | * fatal error recovery. Therefore, the driver must |
| 5297 | * manually relogin to devices when recovering from |
| 5298 | * connection failures, logouts, expired KATO, etc. */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5299 | if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) { |
| 5300 | qla4xxx_build_ddb_list(ha, ha->is_reset); |
| 5301 | iscsi_host_for_each_session(ha->host, |
| 5302 | qla4xxx_login_flash_ddb); |
| 5303 | } else |
| 5304 | qla4xxx_relogin_all_devices(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 5305 | } |
| 5306 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | /** |
| 5310 | * qla4xxx_free_adapter - release the adapter |
| 5311 | * @ha: pointer to adapter structure |
| 5312 | **/ |
| 5313 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| 5314 | { |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 5315 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5316 | |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 5317 | /* Turn-off interrupts on the card. */ |
| 5318 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5319 | |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 5320 | if (is_qla40XX(ha)) { |
| 5321 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 5322 | &ha->reg->ctrl_status); |
| 5323 | readl(&ha->reg->ctrl_status); |
| 5324 | } else if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5325 | writel(0, &ha->qla4_82xx_reg->host_int); |
| 5326 | readl(&ha->qla4_82xx_reg->host_int); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5327 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | fbd8107 | 2012-09-20 07:35:03 -0400 | [diff] [blame] | 5328 | writel(0, &ha->qla4_83xx_reg->risc_intr); |
| 5329 | readl(&ha->qla4_83xx_reg->risc_intr); |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 5330 | } |
| 5331 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5332 | /* Remove timer thread, if present */ |
| 5333 | if (ha->timer_active) |
| 5334 | qla4xxx_stop_timer(ha); |
| 5335 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5336 | /* Kill the kernel thread for this host */ |
| 5337 | if (ha->dpc_thread) |
| 5338 | destroy_workqueue(ha->dpc_thread); |
| 5339 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 5340 | /* Kill the kernel thread for this host */ |
| 5341 | if (ha->task_wq) |
| 5342 | destroy_workqueue(ha->task_wq); |
| 5343 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5344 | /* Put firmware in known state */ |
| 5345 | ha->isp_ops->reset_firmware(ha); |
| 5346 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5347 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5348 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5349 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5350 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5351 | } |
| 5352 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5353 | /* Detach interrupts */ |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 5354 | qla4xxx_free_irqs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5355 | |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 5356 | /* free extra memory */ |
| 5357 | qla4xxx_mem_free(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5358 | } |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 5359 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5360 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| 5361 | { |
| 5362 | int status = 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5363 | unsigned long mem_base, mem_len, db_base, db_len; |
| 5364 | struct pci_dev *pdev = ha->pdev; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5365 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5366 | status = pci_request_regions(pdev, DRIVER_NAME); |
| 5367 | if (status) { |
| 5368 | printk(KERN_WARNING |
| 5369 | "scsi(%ld) Failed to reserve PIO regions (%s) " |
| 5370 | "status=%d\n", ha->host_no, pci_name(pdev), status); |
| 5371 | goto iospace_error_exit; |
| 5372 | } |
| 5373 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5374 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
Sergei Shtylyov | 7d7311c | 2012-03-14 22:04:30 +0300 | [diff] [blame] | 5375 | __func__, pdev->revision)); |
| 5376 | ha->revision_id = pdev->revision; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5377 | |
| 5378 | /* remap phys address */ |
| 5379 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 5380 | mem_len = pci_resource_len(pdev, 0); |
| 5381 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| 5382 | __func__, mem_base, mem_len)); |
| 5383 | |
| 5384 | /* mapping of pcibase pointer */ |
| 5385 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| 5386 | if (!ha->nx_pcibase) { |
| 5387 | printk(KERN_ERR |
| 5388 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| 5389 | pci_release_regions(ha->pdev); |
| 5390 | goto iospace_error_exit; |
| 5391 | } |
| 5392 | |
| 5393 | /* Mapping of IO base pointer, door bell read and write pointer */ |
| 5394 | |
| 5395 | /* mapping of IO base pointer */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5396 | if (is_qla8022(ha)) { |
| 5397 | ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *) |
| 5398 | ((uint8_t *)ha->nx_pcibase + 0xbc000 + |
| 5399 | (ha->pdev->devfn << 11)); |
| 5400 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| 5401 | QLA82XX_CAM_RAM_DB2); |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 5402 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5403 | ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *) |
| 5404 | ((uint8_t *)ha->nx_pcibase); |
| 5405 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5406 | |
| 5407 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 5408 | db_len = pci_resource_len(pdev, 4); |
| 5409 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 5410 | return 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5411 | iospace_error_exit: |
| 5412 | return -ENOMEM; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | /*** |
| 5416 | * qla4xxx_iospace_config - maps registers |
| 5417 | * @ha: pointer to adapter structure |
| 5418 | * |
| 5419 | * This routines maps HBA's registers from the pci address space |
| 5420 | * into the kernel virtual address space for memory mapped i/o. |
| 5421 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5422 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5423 | { |
| 5424 | unsigned long pio, pio_len, pio_flags; |
| 5425 | unsigned long mmio, mmio_len, mmio_flags; |
| 5426 | |
| 5427 | pio = pci_resource_start(ha->pdev, 0); |
| 5428 | pio_len = pci_resource_len(ha->pdev, 0); |
| 5429 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 5430 | if (pio_flags & IORESOURCE_IO) { |
| 5431 | if (pio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5432 | ql4_printk(KERN_WARNING, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5433 | "Invalid PCI I/O region size\n"); |
| 5434 | pio = 0; |
| 5435 | } |
| 5436 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5437 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5438 | pio = 0; |
| 5439 | } |
| 5440 | |
| 5441 | /* Use MMIO operations for all accesses. */ |
| 5442 | mmio = pci_resource_start(ha->pdev, 1); |
| 5443 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 5444 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 5445 | |
| 5446 | if (!(mmio_flags & IORESOURCE_MEM)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5447 | ql4_printk(KERN_ERR, ha, |
| 5448 | "region #0 not an MMIO resource, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5449 | |
| 5450 | goto iospace_error_exit; |
| 5451 | } |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5452 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5453 | if (mmio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5454 | ql4_printk(KERN_ERR, ha, |
| 5455 | "Invalid PCI mem region size, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5456 | goto iospace_error_exit; |
| 5457 | } |
| 5458 | |
| 5459 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5460 | ql4_printk(KERN_WARNING, ha, |
| 5461 | "Failed to reserve PIO/MMIO regions\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5462 | |
| 5463 | goto iospace_error_exit; |
| 5464 | } |
| 5465 | |
| 5466 | ha->pio_address = pio; |
| 5467 | ha->pio_length = pio_len; |
| 5468 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| 5469 | if (!ha->reg) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 5470 | ql4_printk(KERN_ERR, ha, |
| 5471 | "cannot remap MMIO, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5472 | |
| 5473 | goto iospace_error_exit; |
| 5474 | } |
| 5475 | |
| 5476 | return 0; |
| 5477 | |
| 5478 | iospace_error_exit: |
| 5479 | return -ENOMEM; |
| 5480 | } |
| 5481 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5482 | static struct isp_operations qla4xxx_isp_ops = { |
| 5483 | .iospace_config = qla4xxx_iospace_config, |
| 5484 | .pci_config = qla4xxx_pci_config, |
| 5485 | .disable_intrs = qla4xxx_disable_intrs, |
| 5486 | .enable_intrs = qla4xxx_enable_intrs, |
| 5487 | .start_firmware = qla4xxx_start_firmware, |
| 5488 | .intr_handler = qla4xxx_intr_handler, |
| 5489 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| 5490 | .reset_chip = qla4xxx_soft_reset, |
| 5491 | .reset_firmware = qla4xxx_hw_reset, |
| 5492 | .queue_iocb = qla4xxx_queue_iocb, |
| 5493 | .complete_iocb = qla4xxx_complete_iocb, |
| 5494 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 5495 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| 5496 | .get_sys_info = qla4xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5497 | .queue_mailbox_command = qla4xxx_queue_mbox_cmd, |
| 5498 | .process_mailbox_interrupt = qla4xxx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5499 | }; |
| 5500 | |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5501 | static struct isp_operations qla4_82xx_isp_ops = { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5502 | .iospace_config = qla4_8xxx_iospace_config, |
| 5503 | .pci_config = qla4_8xxx_pci_config, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5504 | .disable_intrs = qla4_82xx_disable_intrs, |
| 5505 | .enable_intrs = qla4_82xx_enable_intrs, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5506 | .start_firmware = qla4_8xxx_load_risc, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5507 | .restart_firmware = qla4_82xx_try_start_fw, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5508 | .intr_handler = qla4_82xx_intr_handler, |
| 5509 | .interrupt_service_routine = qla4_82xx_interrupt_service_routine, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5510 | .need_reset = qla4_8xxx_need_reset, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5511 | .reset_chip = qla4_82xx_isp_reset, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5512 | .reset_firmware = qla4_8xxx_stop_firmware, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5513 | .queue_iocb = qla4_82xx_queue_iocb, |
| 5514 | .complete_iocb = qla4_82xx_complete_iocb, |
| 5515 | .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out, |
| 5516 | .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5517 | .get_sys_info = qla4_8xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 5518 | .rd_reg_direct = qla4_82xx_rd_32, |
| 5519 | .wr_reg_direct = qla4_82xx_wr_32, |
| 5520 | .rd_reg_indirect = qla4_82xx_md_rd_32, |
| 5521 | .wr_reg_indirect = qla4_82xx_md_wr_32, |
| 5522 | .idc_lock = qla4_82xx_idc_lock, |
| 5523 | .idc_unlock = qla4_82xx_idc_unlock, |
| 5524 | .rom_lock_recovery = qla4_82xx_rom_lock_recovery, |
| 5525 | .queue_mailbox_command = qla4_82xx_queue_mbox_cmd, |
| 5526 | .process_mailbox_interrupt = qla4_82xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5527 | }; |
| 5528 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5529 | static struct isp_operations qla4_83xx_isp_ops = { |
| 5530 | .iospace_config = qla4_8xxx_iospace_config, |
| 5531 | .pci_config = qla4_8xxx_pci_config, |
| 5532 | .disable_intrs = qla4_83xx_disable_intrs, |
| 5533 | .enable_intrs = qla4_83xx_enable_intrs, |
| 5534 | .start_firmware = qla4_8xxx_load_risc, |
| 5535 | .restart_firmware = qla4_83xx_start_firmware, |
| 5536 | .intr_handler = qla4_83xx_intr_handler, |
| 5537 | .interrupt_service_routine = qla4_83xx_interrupt_service_routine, |
| 5538 | .need_reset = qla4_8xxx_need_reset, |
| 5539 | .reset_chip = qla4_83xx_isp_reset, |
| 5540 | .reset_firmware = qla4_8xxx_stop_firmware, |
| 5541 | .queue_iocb = qla4_83xx_queue_iocb, |
| 5542 | .complete_iocb = qla4_83xx_complete_iocb, |
Tej Parkash | a24058f | 2013-03-07 05:43:13 -0500 | [diff] [blame] | 5543 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 5544 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 5545 | .get_sys_info = qla4_8xxx_get_sys_info, |
| 5546 | .rd_reg_direct = qla4_83xx_rd_reg, |
| 5547 | .wr_reg_direct = qla4_83xx_wr_reg, |
| 5548 | .rd_reg_indirect = qla4_83xx_rd_reg_indirect, |
| 5549 | .wr_reg_indirect = qla4_83xx_wr_reg_indirect, |
| 5550 | .idc_lock = qla4_83xx_drv_lock, |
| 5551 | .idc_unlock = qla4_83xx_drv_unlock, |
| 5552 | .rom_lock_recovery = qla4_83xx_rom_lock_recovery, |
| 5553 | .queue_mailbox_command = qla4_83xx_queue_mbox_cmd, |
| 5554 | .process_mailbox_interrupt = qla4_83xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 5555 | }; |
| 5556 | |
| 5557 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 5558 | { |
| 5559 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| 5560 | } |
| 5561 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5562 | 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] | 5563 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5564 | 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] | 5565 | } |
| 5566 | |
| 5567 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 5568 | { |
| 5569 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); |
| 5570 | } |
| 5571 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 5572 | 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] | 5573 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 5574 | 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] | 5575 | } |
| 5576 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5577 | static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf) |
| 5578 | { |
| 5579 | struct scsi_qla_host *ha = data; |
| 5580 | char *str = buf; |
| 5581 | int rc; |
| 5582 | |
| 5583 | switch (type) { |
| 5584 | case ISCSI_BOOT_ETH_FLAGS: |
| 5585 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 5586 | break; |
| 5587 | case ISCSI_BOOT_ETH_INDEX: |
| 5588 | rc = sprintf(str, "0\n"); |
| 5589 | break; |
| 5590 | case ISCSI_BOOT_ETH_MAC: |
| 5591 | rc = sysfs_format_mac(str, ha->my_mac, |
| 5592 | MAC_ADDR_LEN); |
| 5593 | break; |
| 5594 | default: |
| 5595 | rc = -ENOSYS; |
| 5596 | break; |
| 5597 | } |
| 5598 | return rc; |
| 5599 | } |
| 5600 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5601 | static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5602 | { |
| 5603 | int rc; |
| 5604 | |
| 5605 | switch (type) { |
| 5606 | case ISCSI_BOOT_ETH_FLAGS: |
| 5607 | case ISCSI_BOOT_ETH_MAC: |
| 5608 | case ISCSI_BOOT_ETH_INDEX: |
| 5609 | rc = S_IRUGO; |
| 5610 | break; |
| 5611 | default: |
| 5612 | rc = 0; |
| 5613 | break; |
| 5614 | } |
| 5615 | return rc; |
| 5616 | } |
| 5617 | |
| 5618 | static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf) |
| 5619 | { |
| 5620 | struct scsi_qla_host *ha = data; |
| 5621 | char *str = buf; |
| 5622 | int rc; |
| 5623 | |
| 5624 | switch (type) { |
| 5625 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5626 | rc = sprintf(str, "%s\n", ha->name_string); |
| 5627 | break; |
| 5628 | default: |
| 5629 | rc = -ENOSYS; |
| 5630 | break; |
| 5631 | } |
| 5632 | return rc; |
| 5633 | } |
| 5634 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5635 | static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5636 | { |
| 5637 | int rc; |
| 5638 | |
| 5639 | switch (type) { |
| 5640 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5641 | rc = S_IRUGO; |
| 5642 | break; |
| 5643 | default: |
| 5644 | rc = 0; |
| 5645 | break; |
| 5646 | } |
| 5647 | return rc; |
| 5648 | } |
| 5649 | |
| 5650 | static ssize_t |
| 5651 | qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type, |
| 5652 | char *buf) |
| 5653 | { |
| 5654 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 5655 | char *str = buf; |
| 5656 | int rc; |
| 5657 | |
| 5658 | switch (type) { |
| 5659 | case ISCSI_BOOT_TGT_NAME: |
| 5660 | rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name); |
| 5661 | break; |
| 5662 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5663 | if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1) |
| 5664 | rc = sprintf(buf, "%pI4\n", |
| 5665 | &boot_conn->dest_ipaddr.ip_address); |
| 5666 | else |
| 5667 | rc = sprintf(str, "%pI6\n", |
| 5668 | &boot_conn->dest_ipaddr.ip_address); |
| 5669 | break; |
| 5670 | case ISCSI_BOOT_TGT_PORT: |
| 5671 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 5672 | break; |
| 5673 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5674 | rc = sprintf(str, "%.*s\n", |
| 5675 | boot_conn->chap.target_chap_name_length, |
| 5676 | (char *)&boot_conn->chap.target_chap_name); |
| 5677 | break; |
| 5678 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5679 | rc = sprintf(str, "%.*s\n", |
| 5680 | boot_conn->chap.target_secret_length, |
| 5681 | (char *)&boot_conn->chap.target_secret); |
| 5682 | break; |
| 5683 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5684 | rc = sprintf(str, "%.*s\n", |
| 5685 | boot_conn->chap.intr_chap_name_length, |
| 5686 | (char *)&boot_conn->chap.intr_chap_name); |
| 5687 | break; |
| 5688 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5689 | rc = sprintf(str, "%.*s\n", |
| 5690 | boot_conn->chap.intr_secret_length, |
| 5691 | (char *)&boot_conn->chap.intr_secret); |
| 5692 | break; |
| 5693 | case ISCSI_BOOT_TGT_FLAGS: |
| 5694 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 5695 | break; |
| 5696 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5697 | rc = sprintf(str, "0\n"); |
| 5698 | break; |
| 5699 | default: |
| 5700 | rc = -ENOSYS; |
| 5701 | break; |
| 5702 | } |
| 5703 | return rc; |
| 5704 | } |
| 5705 | |
| 5706 | static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf) |
| 5707 | { |
| 5708 | struct scsi_qla_host *ha = data; |
| 5709 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess); |
| 5710 | |
| 5711 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 5712 | } |
| 5713 | |
| 5714 | static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf) |
| 5715 | { |
| 5716 | struct scsi_qla_host *ha = data; |
| 5717 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess); |
| 5718 | |
| 5719 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 5720 | } |
| 5721 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 5722 | static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5723 | { |
| 5724 | int rc; |
| 5725 | |
| 5726 | switch (type) { |
| 5727 | case ISCSI_BOOT_TGT_NAME: |
| 5728 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5729 | case ISCSI_BOOT_TGT_PORT: |
| 5730 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5731 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5732 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5733 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5734 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5735 | case ISCSI_BOOT_TGT_FLAGS: |
| 5736 | rc = S_IRUGO; |
| 5737 | break; |
| 5738 | default: |
| 5739 | rc = 0; |
| 5740 | break; |
| 5741 | } |
| 5742 | return rc; |
| 5743 | } |
| 5744 | |
| 5745 | static void qla4xxx_boot_release(void *data) |
| 5746 | { |
| 5747 | struct scsi_qla_host *ha = data; |
| 5748 | |
| 5749 | scsi_host_put(ha->host); |
| 5750 | } |
| 5751 | |
| 5752 | static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) |
| 5753 | { |
| 5754 | dma_addr_t buf_dma; |
| 5755 | uint32_t addr, pri_addr, sec_addr; |
| 5756 | uint32_t offset; |
| 5757 | uint16_t func_num; |
| 5758 | uint8_t val; |
| 5759 | uint8_t *buf = NULL; |
| 5760 | size_t size = 13 * sizeof(uint8_t); |
| 5761 | int ret = QLA_SUCCESS; |
| 5762 | |
| 5763 | func_num = PCI_FUNC(ha->pdev->devfn); |
| 5764 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 5765 | ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n", |
| 5766 | __func__, ha->pdev->device, func_num); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5767 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 5768 | if (is_qla40XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5769 | if (func_num == 1) { |
| 5770 | addr = NVRAM_PORT0_BOOT_MODE; |
| 5771 | pri_addr = NVRAM_PORT0_BOOT_PRI_TGT; |
| 5772 | sec_addr = NVRAM_PORT0_BOOT_SEC_TGT; |
| 5773 | } else if (func_num == 3) { |
| 5774 | addr = NVRAM_PORT1_BOOT_MODE; |
| 5775 | pri_addr = NVRAM_PORT1_BOOT_PRI_TGT; |
| 5776 | sec_addr = NVRAM_PORT1_BOOT_SEC_TGT; |
| 5777 | } else { |
| 5778 | ret = QLA_ERROR; |
| 5779 | goto exit_boot_info; |
| 5780 | } |
| 5781 | |
| 5782 | /* Check Boot Mode */ |
| 5783 | val = rd_nvram_byte(ha, addr); |
| 5784 | if (!(val & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5785 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot " |
| 5786 | "options : 0x%x\n", __func__, val)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5787 | ret = QLA_ERROR; |
| 5788 | goto exit_boot_info; |
| 5789 | } |
| 5790 | |
| 5791 | /* get primary valid target index */ |
| 5792 | val = rd_nvram_byte(ha, pri_addr); |
| 5793 | if (val & BIT_7) |
| 5794 | ddb_index[0] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5795 | |
| 5796 | /* get secondary valid target index */ |
| 5797 | val = rd_nvram_byte(ha, sec_addr); |
| 5798 | if (val & BIT_7) |
| 5799 | ddb_index[1] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5800 | |
Vikas Chaudhary | 3e788fb | 2013-03-07 05:43:08 -0500 | [diff] [blame] | 5801 | } else if (is_qla80XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5802 | buf = dma_alloc_coherent(&ha->pdev->dev, size, |
| 5803 | &buf_dma, GFP_KERNEL); |
| 5804 | if (!buf) { |
| 5805 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5806 | "%s: Unable to allocate dma buffer\n", |
| 5807 | __func__)); |
| 5808 | ret = QLA_ERROR; |
| 5809 | goto exit_boot_info; |
| 5810 | } |
| 5811 | |
| 5812 | if (ha->port_num == 0) |
| 5813 | offset = BOOT_PARAM_OFFSET_PORT0; |
| 5814 | else if (ha->port_num == 1) |
| 5815 | offset = BOOT_PARAM_OFFSET_PORT1; |
| 5816 | else { |
| 5817 | ret = QLA_ERROR; |
| 5818 | goto exit_boot_info_free; |
| 5819 | } |
| 5820 | addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) + |
| 5821 | offset; |
| 5822 | if (qla4xxx_get_flash(ha, buf_dma, addr, |
| 5823 | 13 * sizeof(uint8_t)) != QLA_SUCCESS) { |
| 5824 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash" |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 5825 | " failed\n", ha->host_no, __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5826 | ret = QLA_ERROR; |
| 5827 | goto exit_boot_info_free; |
| 5828 | } |
| 5829 | /* Check Boot Mode */ |
| 5830 | if (!(buf[1] & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5831 | DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options" |
| 5832 | " : 0x%x\n", buf[1])); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5833 | ret = QLA_ERROR; |
| 5834 | goto exit_boot_info_free; |
| 5835 | } |
| 5836 | |
| 5837 | /* get primary valid target index */ |
| 5838 | if (buf[2] & BIT_7) |
| 5839 | ddb_index[0] = buf[2] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5840 | |
| 5841 | /* get secondary valid target index */ |
| 5842 | if (buf[11] & BIT_7) |
| 5843 | ddb_index[1] = buf[11] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5844 | } else { |
| 5845 | ret = QLA_ERROR; |
| 5846 | goto exit_boot_info; |
| 5847 | } |
| 5848 | |
| 5849 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary" |
| 5850 | " target ID %d\n", __func__, ddb_index[0], |
| 5851 | ddb_index[1])); |
| 5852 | |
| 5853 | exit_boot_info_free: |
| 5854 | dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma); |
| 5855 | exit_boot_info: |
Lalit Chandivade | 20e835b | 2012-02-13 18:30:42 +0530 | [diff] [blame] | 5856 | ha->pri_ddb_idx = ddb_index[0]; |
| 5857 | ha->sec_ddb_idx = ddb_index[1]; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5858 | return ret; |
| 5859 | } |
| 5860 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 5861 | /** |
| 5862 | * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password |
| 5863 | * @ha: pointer to adapter structure |
| 5864 | * @username: CHAP username to be returned |
| 5865 | * @password: CHAP password to be returned |
| 5866 | * |
| 5867 | * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP |
| 5868 | * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/. |
| 5869 | * So from the CHAP cache find the first BIDI CHAP entry and set it |
| 5870 | * to the boot record in sysfs. |
| 5871 | **/ |
| 5872 | static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username, |
| 5873 | char *password) |
| 5874 | { |
| 5875 | int i, ret = -EINVAL; |
| 5876 | int max_chap_entries = 0; |
| 5877 | struct ql4_chap_table *chap_table; |
| 5878 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 5879 | if (is_qla80XX(ha)) |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 5880 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 5881 | sizeof(struct ql4_chap_table); |
| 5882 | else |
| 5883 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 5884 | |
| 5885 | if (!ha->chap_list) { |
| 5886 | ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n"); |
| 5887 | return ret; |
| 5888 | } |
| 5889 | |
| 5890 | mutex_lock(&ha->chap_sem); |
| 5891 | for (i = 0; i < max_chap_entries; i++) { |
| 5892 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 5893 | if (chap_table->cookie != |
| 5894 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 5895 | continue; |
| 5896 | } |
| 5897 | |
| 5898 | if (chap_table->flags & BIT_7) /* local */ |
| 5899 | continue; |
| 5900 | |
| 5901 | if (!(chap_table->flags & BIT_6)) /* Not BIDI */ |
| 5902 | continue; |
| 5903 | |
| 5904 | strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN); |
| 5905 | strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN); |
| 5906 | ret = 0; |
| 5907 | break; |
| 5908 | } |
| 5909 | mutex_unlock(&ha->chap_sem); |
| 5910 | |
| 5911 | return ret; |
| 5912 | } |
| 5913 | |
| 5914 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5915 | static int qla4xxx_get_boot_target(struct scsi_qla_host *ha, |
| 5916 | struct ql4_boot_session_info *boot_sess, |
| 5917 | uint16_t ddb_index) |
| 5918 | { |
| 5919 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 5920 | struct dev_db_entry *fw_ddb_entry; |
| 5921 | dma_addr_t fw_ddb_entry_dma; |
| 5922 | uint16_t idx; |
| 5923 | uint16_t options; |
| 5924 | int ret = QLA_SUCCESS; |
| 5925 | |
| 5926 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5927 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 5928 | if (!fw_ddb_entry) { |
| 5929 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5930 | "%s: Unable to allocate dma buffer.\n", |
| 5931 | __func__)); |
| 5932 | ret = QLA_ERROR; |
| 5933 | return ret; |
| 5934 | } |
| 5935 | |
| 5936 | if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry, |
| 5937 | fw_ddb_entry_dma, ddb_index)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 5938 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at " |
| 5939 | "index [%d]\n", __func__, ddb_index)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5940 | ret = QLA_ERROR; |
| 5941 | goto exit_boot_target; |
| 5942 | } |
| 5943 | |
| 5944 | /* Update target name and IP from DDB */ |
| 5945 | memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name, |
| 5946 | min(sizeof(boot_sess->target_name), |
| 5947 | sizeof(fw_ddb_entry->iscsi_name))); |
| 5948 | |
| 5949 | options = le16_to_cpu(fw_ddb_entry->options); |
| 5950 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 5951 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 5952 | &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN); |
| 5953 | } else { |
| 5954 | boot_conn->dest_ipaddr.ip_type = 0x1; |
| 5955 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 5956 | &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN); |
| 5957 | } |
| 5958 | |
| 5959 | boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port); |
| 5960 | |
| 5961 | /* update chap information */ |
| 5962 | idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 5963 | |
| 5964 | if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 5965 | |
| 5966 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n")); |
| 5967 | |
| 5968 | ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap. |
| 5969 | target_chap_name, |
| 5970 | (char *)&boot_conn->chap.target_secret, |
| 5971 | idx); |
| 5972 | if (ret) { |
| 5973 | ql4_printk(KERN_ERR, ha, "Failed to set chap\n"); |
| 5974 | ret = QLA_ERROR; |
| 5975 | goto exit_boot_target; |
| 5976 | } |
| 5977 | |
| 5978 | boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 5979 | boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 5980 | } |
| 5981 | |
| 5982 | if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 5983 | |
| 5984 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n")); |
| 5985 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 5986 | ret = qla4xxx_get_bidi_chap(ha, |
| 5987 | (char *)&boot_conn->chap.intr_chap_name, |
| 5988 | (char *)&boot_conn->chap.intr_secret); |
| 5989 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 5990 | if (ret) { |
| 5991 | ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n"); |
| 5992 | ret = QLA_ERROR; |
| 5993 | goto exit_boot_target; |
| 5994 | } |
| 5995 | |
| 5996 | boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 5997 | boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 5998 | } |
| 5999 | |
| 6000 | exit_boot_target: |
| 6001 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6002 | fw_ddb_entry, fw_ddb_entry_dma); |
| 6003 | return ret; |
| 6004 | } |
| 6005 | |
| 6006 | static int qla4xxx_get_boot_info(struct scsi_qla_host *ha) |
| 6007 | { |
| 6008 | uint16_t ddb_index[2]; |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6009 | int ret = QLA_ERROR; |
| 6010 | int rval; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6011 | |
| 6012 | memset(ddb_index, 0, sizeof(ddb_index)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6013 | ddb_index[0] = 0xffff; |
| 6014 | ddb_index[1] = 0xffff; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6015 | ret = get_fw_boot_info(ha, ddb_index); |
| 6016 | if (ret != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6017 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6018 | "%s: No boot target configured.\n", __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6019 | return ret; |
| 6020 | } |
| 6021 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6022 | if (ql4xdisablesysfsboot) |
| 6023 | return QLA_SUCCESS; |
| 6024 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6025 | if (ddb_index[0] == 0xffff) |
| 6026 | goto sec_target; |
| 6027 | |
| 6028 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6029 | ddb_index[0]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6030 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6031 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not " |
| 6032 | "configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6033 | } else |
| 6034 | ret = QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6035 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6036 | sec_target: |
| 6037 | if (ddb_index[1] == 0xffff) |
| 6038 | goto exit_get_boot_info; |
| 6039 | |
| 6040 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6041 | ddb_index[1]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6042 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 6043 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not" |
| 6044 | " configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 6045 | } else |
| 6046 | ret = QLA_SUCCESS; |
| 6047 | |
| 6048 | exit_get_boot_info: |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6049 | return ret; |
| 6050 | } |
| 6051 | |
| 6052 | static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha) |
| 6053 | { |
| 6054 | struct iscsi_boot_kobj *boot_kobj; |
| 6055 | |
| 6056 | if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6057 | return QLA_ERROR; |
| 6058 | |
| 6059 | if (ql4xdisablesysfsboot) { |
| 6060 | ql4_printk(KERN_INFO, ha, |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 6061 | "%s: syfsboot disabled - driver will trigger login " |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6062 | "and publish session for discovery .\n", __func__); |
| 6063 | return QLA_SUCCESS; |
| 6064 | } |
| 6065 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6066 | |
| 6067 | ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no); |
| 6068 | if (!ha->boot_kset) |
| 6069 | goto kset_free; |
| 6070 | |
| 6071 | if (!scsi_host_get(ha->host)) |
| 6072 | goto kset_free; |
| 6073 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha, |
| 6074 | qla4xxx_show_boot_tgt_pri_info, |
| 6075 | qla4xxx_tgt_get_attr_visibility, |
| 6076 | qla4xxx_boot_release); |
| 6077 | if (!boot_kobj) |
| 6078 | goto put_host; |
| 6079 | |
| 6080 | if (!scsi_host_get(ha->host)) |
| 6081 | goto kset_free; |
| 6082 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha, |
| 6083 | qla4xxx_show_boot_tgt_sec_info, |
| 6084 | qla4xxx_tgt_get_attr_visibility, |
| 6085 | qla4xxx_boot_release); |
| 6086 | if (!boot_kobj) |
| 6087 | goto put_host; |
| 6088 | |
| 6089 | if (!scsi_host_get(ha->host)) |
| 6090 | goto kset_free; |
| 6091 | boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha, |
| 6092 | qla4xxx_show_boot_ini_info, |
| 6093 | qla4xxx_ini_get_attr_visibility, |
| 6094 | qla4xxx_boot_release); |
| 6095 | if (!boot_kobj) |
| 6096 | goto put_host; |
| 6097 | |
| 6098 | if (!scsi_host_get(ha->host)) |
| 6099 | goto kset_free; |
| 6100 | boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha, |
| 6101 | qla4xxx_show_boot_eth_info, |
| 6102 | qla4xxx_eth_get_attr_visibility, |
| 6103 | qla4xxx_boot_release); |
| 6104 | if (!boot_kobj) |
| 6105 | goto put_host; |
| 6106 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6107 | return QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 6108 | |
| 6109 | put_host: |
| 6110 | scsi_host_put(ha->host); |
| 6111 | kset_free: |
| 6112 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 6113 | return -ENOMEM; |
| 6114 | } |
| 6115 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 6116 | |
| 6117 | /** |
| 6118 | * qla4xxx_create chap_list - Create CHAP list from FLASH |
| 6119 | * @ha: pointer to adapter structure |
| 6120 | * |
| 6121 | * Read flash and make a list of CHAP entries, during login when a CHAP entry |
| 6122 | * is received, it will be checked in this list. If entry exist then the CHAP |
| 6123 | * entry index is set in the DDB. If CHAP entry does not exist in this list |
| 6124 | * then a new entry is added in FLASH in CHAP table and the index obtained is |
| 6125 | * used in the DDB. |
| 6126 | **/ |
| 6127 | static void qla4xxx_create_chap_list(struct scsi_qla_host *ha) |
| 6128 | { |
| 6129 | int rval = 0; |
| 6130 | uint8_t *chap_flash_data = NULL; |
| 6131 | uint32_t offset; |
| 6132 | dma_addr_t chap_dma; |
| 6133 | uint32_t chap_size = 0; |
| 6134 | |
| 6135 | if (is_qla40XX(ha)) |
| 6136 | chap_size = MAX_CHAP_ENTRIES_40XX * |
| 6137 | sizeof(struct ql4_chap_table); |
| 6138 | else /* Single region contains CHAP info for both |
| 6139 | * ports which is divided into half for each port. |
| 6140 | */ |
| 6141 | chap_size = ha->hw.flt_chap_size / 2; |
| 6142 | |
| 6143 | chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size, |
| 6144 | &chap_dma, GFP_KERNEL); |
| 6145 | if (!chap_flash_data) { |
| 6146 | ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n"); |
| 6147 | return; |
| 6148 | } |
| 6149 | if (is_qla40XX(ha)) |
| 6150 | offset = FLASH_CHAP_OFFSET; |
| 6151 | else { |
| 6152 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 6153 | if (ha->port_num == 1) |
| 6154 | offset += chap_size; |
| 6155 | } |
| 6156 | |
| 6157 | rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 6158 | if (rval != QLA_SUCCESS) |
| 6159 | goto exit_chap_list; |
| 6160 | |
| 6161 | if (ha->chap_list == NULL) |
| 6162 | ha->chap_list = vmalloc(chap_size); |
| 6163 | if (ha->chap_list == NULL) { |
| 6164 | ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n"); |
| 6165 | goto exit_chap_list; |
| 6166 | } |
| 6167 | |
| 6168 | memcpy(ha->chap_list, chap_flash_data, chap_size); |
| 6169 | |
| 6170 | exit_chap_list: |
| 6171 | dma_free_coherent(&ha->pdev->dev, chap_size, |
| 6172 | chap_flash_data, chap_dma); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 6173 | } |
| 6174 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6175 | static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry, |
| 6176 | struct ql4_tuple_ddb *tddb) |
| 6177 | { |
| 6178 | struct scsi_qla_host *ha; |
| 6179 | struct iscsi_cls_session *cls_sess; |
| 6180 | struct iscsi_cls_conn *cls_conn; |
| 6181 | struct iscsi_session *sess; |
| 6182 | struct iscsi_conn *conn; |
| 6183 | |
| 6184 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 6185 | ha = ddb_entry->ha; |
| 6186 | cls_sess = ddb_entry->sess; |
| 6187 | sess = cls_sess->dd_data; |
| 6188 | cls_conn = ddb_entry->conn; |
| 6189 | conn = cls_conn->dd_data; |
| 6190 | |
| 6191 | tddb->tpgt = sess->tpgt; |
| 6192 | tddb->port = conn->persistent_port; |
| 6193 | strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE); |
| 6194 | strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN); |
| 6195 | } |
| 6196 | |
| 6197 | 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] | 6198 | struct ql4_tuple_ddb *tddb, |
| 6199 | uint8_t *flash_isid) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6200 | { |
| 6201 | uint16_t options = 0; |
| 6202 | |
| 6203 | tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 6204 | memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
| 6205 | min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name))); |
| 6206 | |
| 6207 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6208 | if (options & DDB_OPT_IPV6_DEVICE) |
| 6209 | sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 6210 | else |
| 6211 | sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 6212 | |
| 6213 | tddb->port = le16_to_cpu(fw_ddb_entry->port); |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6214 | |
| 6215 | if (flash_isid == NULL) |
| 6216 | memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0], |
| 6217 | sizeof(tddb->isid)); |
| 6218 | else |
| 6219 | memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6220 | } |
| 6221 | |
| 6222 | static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha, |
| 6223 | struct ql4_tuple_ddb *old_tddb, |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6224 | struct ql4_tuple_ddb *new_tddb, |
| 6225 | uint8_t is_isid_compare) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6226 | { |
| 6227 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 6228 | return QLA_ERROR; |
| 6229 | |
| 6230 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr)) |
| 6231 | return QLA_ERROR; |
| 6232 | |
| 6233 | if (old_tddb->port != new_tddb->port) |
| 6234 | return QLA_ERROR; |
| 6235 | |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6236 | /* For multi sessions, driver generates the ISID, so do not compare |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 6237 | * ISID in reset path since it would be a comparison between the |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6238 | * driver generated ISID and firmware generated ISID. This could |
| 6239 | * lead to adding duplicated DDBs in the list as driver generated |
| 6240 | * ISID would not match firmware generated ISID. |
| 6241 | */ |
| 6242 | if (is_isid_compare) { |
| 6243 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x" |
| 6244 | "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n", |
| 6245 | __func__, old_tddb->isid[5], old_tddb->isid[4], |
| 6246 | old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1], |
| 6247 | old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4], |
| 6248 | new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1], |
| 6249 | new_tddb->isid[0])); |
| 6250 | |
| 6251 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 6252 | sizeof(old_tddb->isid))) |
| 6253 | return QLA_ERROR; |
| 6254 | } |
| 6255 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6256 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6257 | "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]", |
| 6258 | old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr, |
| 6259 | old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt, |
| 6260 | new_tddb->ip_addr, new_tddb->iscsi_name)); |
| 6261 | |
| 6262 | return QLA_SUCCESS; |
| 6263 | } |
| 6264 | |
| 6265 | static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6266 | struct dev_db_entry *fw_ddb_entry, |
| 6267 | uint32_t *index) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6268 | { |
| 6269 | struct ddb_entry *ddb_entry; |
| 6270 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 6271 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 6272 | int idx; |
| 6273 | int ret = QLA_ERROR; |
| 6274 | |
| 6275 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 6276 | if (!fw_tddb) { |
| 6277 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6278 | "Memory Allocation failed.\n")); |
| 6279 | ret = QLA_SUCCESS; |
| 6280 | goto exit_check; |
| 6281 | } |
| 6282 | |
| 6283 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6284 | if (!tmp_tddb) { |
| 6285 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6286 | "Memory Allocation failed.\n")); |
| 6287 | ret = QLA_SUCCESS; |
| 6288 | goto exit_check; |
| 6289 | } |
| 6290 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6291 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6292 | |
| 6293 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 6294 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 6295 | if (ddb_entry == NULL) |
| 6296 | continue; |
| 6297 | |
| 6298 | qla4xxx_get_param_ddb(ddb_entry, tmp_tddb); |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 6299 | if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6300 | ret = QLA_SUCCESS; /* found */ |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6301 | if (index != NULL) |
| 6302 | *index = idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6303 | goto exit_check; |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | exit_check: |
| 6308 | if (fw_tddb) |
| 6309 | vfree(fw_tddb); |
| 6310 | if (tmp_tddb) |
| 6311 | vfree(tmp_tddb); |
| 6312 | return ret; |
| 6313 | } |
| 6314 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6315 | /** |
| 6316 | * qla4xxx_check_existing_isid - check if target with same isid exist |
| 6317 | * in target list |
| 6318 | * @list_nt: list of target |
| 6319 | * @isid: isid to check |
| 6320 | * |
| 6321 | * This routine return QLA_SUCCESS if target with same isid exist |
| 6322 | **/ |
| 6323 | static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid) |
| 6324 | { |
| 6325 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 6326 | struct dev_db_entry *fw_ddb_entry; |
| 6327 | |
| 6328 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 6329 | fw_ddb_entry = &nt_ddb_idx->fw_ddb; |
| 6330 | |
| 6331 | if (memcmp(&fw_ddb_entry->isid[0], &isid[0], |
| 6332 | sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) { |
| 6333 | return QLA_SUCCESS; |
| 6334 | } |
| 6335 | } |
| 6336 | return QLA_ERROR; |
| 6337 | } |
| 6338 | |
| 6339 | /** |
| 6340 | * qla4xxx_update_isid - compare ddbs and updated isid |
| 6341 | * @ha: Pointer to host adapter structure. |
| 6342 | * @list_nt: list of nt target |
| 6343 | * @fw_ddb_entry: firmware ddb entry |
| 6344 | * |
| 6345 | * This routine update isid if ddbs have same iqn, same isid and |
| 6346 | * different IP addr. |
| 6347 | * Return QLA_SUCCESS if isid is updated. |
| 6348 | **/ |
| 6349 | static int qla4xxx_update_isid(struct scsi_qla_host *ha, |
| 6350 | struct list_head *list_nt, |
| 6351 | struct dev_db_entry *fw_ddb_entry) |
| 6352 | { |
| 6353 | uint8_t base_value, i; |
| 6354 | |
| 6355 | base_value = fw_ddb_entry->isid[1] & 0x1f; |
| 6356 | for (i = 0; i < 8; i++) { |
| 6357 | fw_ddb_entry->isid[1] = (base_value | (i << 5)); |
| 6358 | if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 6359 | break; |
| 6360 | } |
| 6361 | |
| 6362 | if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 6363 | return QLA_ERROR; |
| 6364 | |
| 6365 | return QLA_SUCCESS; |
| 6366 | } |
| 6367 | |
| 6368 | /** |
| 6369 | * qla4xxx_should_update_isid - check if isid need to update |
| 6370 | * @ha: Pointer to host adapter structure. |
| 6371 | * @old_tddb: ddb tuple |
| 6372 | * @new_tddb: ddb tuple |
| 6373 | * |
| 6374 | * Return QLA_SUCCESS if different IP, different PORT, same iqn, |
| 6375 | * same isid |
| 6376 | **/ |
| 6377 | static int qla4xxx_should_update_isid(struct scsi_qla_host *ha, |
| 6378 | struct ql4_tuple_ddb *old_tddb, |
| 6379 | struct ql4_tuple_ddb *new_tddb) |
| 6380 | { |
| 6381 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) { |
| 6382 | /* Same ip */ |
| 6383 | if (old_tddb->port == new_tddb->port) |
| 6384 | return QLA_ERROR; |
| 6385 | } |
| 6386 | |
| 6387 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 6388 | /* different iqn */ |
| 6389 | return QLA_ERROR; |
| 6390 | |
| 6391 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 6392 | sizeof(old_tddb->isid))) |
| 6393 | /* different isid */ |
| 6394 | return QLA_ERROR; |
| 6395 | |
| 6396 | return QLA_SUCCESS; |
| 6397 | } |
| 6398 | |
| 6399 | /** |
| 6400 | * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt |
| 6401 | * @ha: Pointer to host adapter structure. |
| 6402 | * @list_nt: list of nt target. |
| 6403 | * @fw_ddb_entry: firmware ddb entry. |
| 6404 | * |
| 6405 | * This routine check if fw_ddb_entry already exists in list_nt to avoid |
| 6406 | * duplicate ddb in list_nt. |
| 6407 | * Return QLA_SUCCESS if duplicate ddb exit in list_nl. |
| 6408 | * Note: This function also update isid of DDB if required. |
| 6409 | **/ |
| 6410 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6411 | static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, |
| 6412 | struct list_head *list_nt, |
| 6413 | struct dev_db_entry *fw_ddb_entry) |
| 6414 | { |
| 6415 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 6416 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 6417 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6418 | int rval, ret = QLA_ERROR; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6419 | |
| 6420 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 6421 | if (!fw_tddb) { |
| 6422 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6423 | "Memory Allocation failed.\n")); |
| 6424 | ret = QLA_SUCCESS; |
| 6425 | goto exit_check; |
| 6426 | } |
| 6427 | |
| 6428 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6429 | if (!tmp_tddb) { |
| 6430 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 6431 | "Memory Allocation failed.\n")); |
| 6432 | ret = QLA_SUCCESS; |
| 6433 | goto exit_check; |
| 6434 | } |
| 6435 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6436 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6437 | |
| 6438 | 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] | 6439 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, |
| 6440 | nt_ddb_idx->flash_isid); |
| 6441 | ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true); |
| 6442 | /* found duplicate ddb */ |
| 6443 | if (ret == QLA_SUCCESS) |
| 6444 | goto exit_check; |
| 6445 | } |
| 6446 | |
| 6447 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 6448 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL); |
| 6449 | |
| 6450 | ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb); |
| 6451 | if (ret == QLA_SUCCESS) { |
| 6452 | rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry); |
| 6453 | if (rval == QLA_SUCCESS) |
| 6454 | ret = QLA_ERROR; |
| 6455 | else |
| 6456 | ret = QLA_SUCCESS; |
| 6457 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6458 | goto exit_check; |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | exit_check: |
| 6463 | if (fw_tddb) |
| 6464 | vfree(fw_tddb); |
| 6465 | if (tmp_tddb) |
| 6466 | vfree(tmp_tddb); |
| 6467 | return ret; |
| 6468 | } |
| 6469 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6470 | static void qla4xxx_free_ddb_list(struct list_head *list_ddb) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6471 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6472 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6473 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6474 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6475 | list_del_init(&ddb_idx->list); |
| 6476 | vfree(ddb_idx); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6477 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha, |
| 6481 | struct dev_db_entry *fw_ddb_entry) |
| 6482 | { |
| 6483 | struct iscsi_endpoint *ep; |
| 6484 | struct sockaddr_in *addr; |
| 6485 | struct sockaddr_in6 *addr6; |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6486 | struct sockaddr *t_addr; |
| 6487 | struct sockaddr_storage *dst_addr; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6488 | char *ip; |
| 6489 | |
| 6490 | /* TODO: need to destroy on unload iscsi_endpoint*/ |
| 6491 | dst_addr = vmalloc(sizeof(*dst_addr)); |
| 6492 | if (!dst_addr) |
| 6493 | return NULL; |
| 6494 | |
| 6495 | if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6496 | t_addr = (struct sockaddr *)dst_addr; |
| 6497 | t_addr->sa_family = AF_INET6; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6498 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 6499 | ip = (char *)&addr6->sin6_addr; |
| 6500 | memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 6501 | addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 6502 | |
| 6503 | } else { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6504 | t_addr = (struct sockaddr *)dst_addr; |
| 6505 | t_addr->sa_family = AF_INET; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6506 | addr = (struct sockaddr_in *)dst_addr; |
| 6507 | ip = (char *)&addr->sin_addr; |
| 6508 | memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN); |
| 6509 | addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 6510 | } |
| 6511 | |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 6512 | ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6513 | vfree(dst_addr); |
| 6514 | return ep; |
| 6515 | } |
| 6516 | |
| 6517 | static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx) |
| 6518 | { |
| 6519 | if (ql4xdisablesysfsboot) |
| 6520 | return QLA_SUCCESS; |
| 6521 | if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx) |
| 6522 | return QLA_ERROR; |
| 6523 | return QLA_SUCCESS; |
| 6524 | } |
| 6525 | |
| 6526 | static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6527 | struct ddb_entry *ddb_entry, |
| 6528 | uint16_t idx) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6529 | { |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6530 | uint16_t def_timeout; |
| 6531 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6532 | ddb_entry->ddb_type = FLASH_DDB; |
| 6533 | ddb_entry->fw_ddb_index = INVALID_ENTRY; |
| 6534 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 6535 | ddb_entry->ha = ha; |
| 6536 | ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb; |
| 6537 | ddb_entry->ddb_change = qla4xxx_flash_ddb_change; |
Adheer Chandravanshi | 946ac57 | 2013-09-17 07:54:46 -0400 | [diff] [blame] | 6538 | ddb_entry->chap_tbl_idx = INVALID_ENTRY; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6539 | |
| 6540 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 6541 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 6542 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6543 | def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6544 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6545 | (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ? |
| 6546 | def_timeout : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6547 | ddb_entry->default_time2wait = |
| 6548 | le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6549 | |
| 6550 | if (ql4xdisablesysfsboot && |
| 6551 | (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)) |
| 6552 | set_bit(DF_BOOT_TGT, &ddb_entry->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha) |
| 6556 | { |
| 6557 | uint32_t idx = 0; |
| 6558 | uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */ |
| 6559 | uint32_t sts[MBOX_REG_COUNT]; |
| 6560 | uint32_t ip_state; |
| 6561 | unsigned long wtime; |
| 6562 | int ret; |
| 6563 | |
| 6564 | wtime = jiffies + (HZ * IP_CONFIG_TOV); |
| 6565 | do { |
| 6566 | for (idx = 0; idx < IP_ADDR_COUNT; idx++) { |
| 6567 | if (ip_idx[idx] == -1) |
| 6568 | continue; |
| 6569 | |
| 6570 | ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts); |
| 6571 | |
| 6572 | if (ret == QLA_ERROR) { |
| 6573 | ip_idx[idx] = -1; |
| 6574 | continue; |
| 6575 | } |
| 6576 | |
| 6577 | ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT; |
| 6578 | |
| 6579 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6580 | "Waiting for IP state for idx = %d, state = 0x%x\n", |
| 6581 | ip_idx[idx], ip_state)); |
| 6582 | if (ip_state == IP_ADDRSTATE_UNCONFIGURED || |
| 6583 | ip_state == IP_ADDRSTATE_INVALID || |
| 6584 | ip_state == IP_ADDRSTATE_PREFERRED || |
| 6585 | ip_state == IP_ADDRSTATE_DEPRICATED || |
| 6586 | ip_state == IP_ADDRSTATE_DISABLING) |
| 6587 | ip_idx[idx] = -1; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6588 | } |
| 6589 | |
| 6590 | /* Break if all IP states checked */ |
| 6591 | if ((ip_idx[0] == -1) && |
| 6592 | (ip_idx[1] == -1) && |
| 6593 | (ip_idx[2] == -1) && |
| 6594 | (ip_idx[3] == -1)) |
| 6595 | break; |
| 6596 | schedule_timeout_uninterruptible(HZ); |
| 6597 | } while (time_after(wtime, jiffies)); |
| 6598 | } |
| 6599 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6600 | static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry, |
| 6601 | struct dev_db_entry *flash_ddb_entry) |
| 6602 | { |
| 6603 | uint16_t options = 0; |
| 6604 | size_t ip_len = IP_ADDR_LEN; |
| 6605 | |
| 6606 | options = le16_to_cpu(fw_ddb_entry->options); |
| 6607 | if (options & DDB_OPT_IPV6_DEVICE) |
| 6608 | ip_len = IPv6_ADDR_LEN; |
| 6609 | |
| 6610 | if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len)) |
| 6611 | return QLA_ERROR; |
| 6612 | |
| 6613 | if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0], |
| 6614 | sizeof(fw_ddb_entry->isid))) |
| 6615 | return QLA_ERROR; |
| 6616 | |
| 6617 | if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port, |
| 6618 | sizeof(fw_ddb_entry->port))) |
| 6619 | return QLA_ERROR; |
| 6620 | |
| 6621 | return QLA_SUCCESS; |
| 6622 | } |
| 6623 | |
| 6624 | static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha, |
| 6625 | struct dev_db_entry *fw_ddb_entry, |
| 6626 | uint32_t fw_idx, uint32_t *flash_index) |
| 6627 | { |
| 6628 | struct dev_db_entry *flash_ddb_entry; |
| 6629 | dma_addr_t flash_ddb_entry_dma; |
| 6630 | uint32_t idx = 0; |
| 6631 | int max_ddbs; |
| 6632 | int ret = QLA_ERROR, status; |
| 6633 | |
| 6634 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6635 | MAX_DEV_DB_ENTRIES; |
| 6636 | |
| 6637 | flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6638 | &flash_ddb_entry_dma); |
| 6639 | if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) { |
| 6640 | ql4_printk(KERN_ERR, ha, "Out of memory\n"); |
| 6641 | goto exit_find_st_idx; |
| 6642 | } |
| 6643 | |
| 6644 | status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry, |
| 6645 | flash_ddb_entry_dma, fw_idx); |
| 6646 | if (status == QLA_SUCCESS) { |
| 6647 | status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry); |
| 6648 | if (status == QLA_SUCCESS) { |
| 6649 | *flash_index = fw_idx; |
| 6650 | ret = QLA_SUCCESS; |
| 6651 | goto exit_find_st_idx; |
| 6652 | } |
| 6653 | } |
| 6654 | |
| 6655 | for (idx = 0; idx < max_ddbs; idx++) { |
| 6656 | status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry, |
| 6657 | flash_ddb_entry_dma, idx); |
| 6658 | if (status == QLA_ERROR) |
| 6659 | continue; |
| 6660 | |
| 6661 | status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry); |
| 6662 | if (status == QLA_SUCCESS) { |
| 6663 | *flash_index = idx; |
| 6664 | ret = QLA_SUCCESS; |
| 6665 | goto exit_find_st_idx; |
| 6666 | } |
| 6667 | } |
| 6668 | |
| 6669 | if (idx == max_ddbs) |
| 6670 | ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n", |
| 6671 | fw_idx); |
| 6672 | |
| 6673 | exit_find_st_idx: |
| 6674 | if (flash_ddb_entry) |
| 6675 | dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry, |
| 6676 | flash_ddb_entry_dma); |
| 6677 | |
| 6678 | return ret; |
| 6679 | } |
| 6680 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6681 | static void qla4xxx_build_st_list(struct scsi_qla_host *ha, |
| 6682 | struct list_head *list_st) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6683 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6684 | struct qla_ddb_index *st_ddb_idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6685 | int max_ddbs; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6686 | int fw_idx_size; |
| 6687 | struct dev_db_entry *fw_ddb_entry; |
| 6688 | dma_addr_t fw_ddb_dma; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6689 | int ret; |
| 6690 | uint32_t idx = 0, next_idx = 0; |
| 6691 | uint32_t state = 0, conn_err = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6692 | uint32_t flash_index = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6693 | uint16_t conn_id = 0; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6694 | |
| 6695 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6696 | &fw_ddb_dma); |
| 6697 | if (fw_ddb_entry == NULL) { |
| 6698 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6699 | goto exit_st_list; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6700 | } |
| 6701 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6702 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6703 | MAX_DEV_DB_ENTRIES; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6704 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 6705 | |
| 6706 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6707 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 6708 | NULL, &next_idx, &state, |
| 6709 | &conn_err, NULL, &conn_id); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6710 | if (ret == QLA_ERROR) |
| 6711 | break; |
| 6712 | |
Lalit Chandivade | 981c982 | 2012-02-13 18:30:41 +0530 | [diff] [blame] | 6713 | /* Ignore DDB if invalid state (unassigned) */ |
| 6714 | if (state == DDB_DS_UNASSIGNED) |
| 6715 | goto continue_next_st; |
| 6716 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6717 | /* Check if ST, add to the list_st */ |
| 6718 | if (strlen((char *) fw_ddb_entry->iscsi_name) != 0) |
| 6719 | goto continue_next_st; |
| 6720 | |
| 6721 | st_ddb_idx = vzalloc(fw_idx_size); |
| 6722 | if (!st_ddb_idx) |
| 6723 | break; |
| 6724 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6725 | ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx, |
| 6726 | &flash_index); |
| 6727 | if (ret == QLA_ERROR) { |
| 6728 | ql4_printk(KERN_ERR, ha, |
| 6729 | "No flash entry for ST at idx [%d]\n", idx); |
| 6730 | st_ddb_idx->flash_ddb_idx = idx; |
| 6731 | } else { |
| 6732 | ql4_printk(KERN_INFO, ha, |
| 6733 | "ST at idx [%d] is stored at flash [%d]\n", |
| 6734 | idx, flash_index); |
| 6735 | st_ddb_idx->flash_ddb_idx = flash_index; |
| 6736 | } |
| 6737 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6738 | st_ddb_idx->fw_ddb_idx = idx; |
| 6739 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6740 | list_add_tail(&st_ddb_idx->list, list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6741 | continue_next_st: |
| 6742 | if (next_idx == 0) |
| 6743 | break; |
| 6744 | } |
| 6745 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6746 | exit_st_list: |
| 6747 | if (fw_ddb_entry) |
| 6748 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 6749 | } |
| 6750 | |
| 6751 | /** |
| 6752 | * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list |
| 6753 | * @ha: pointer to adapter structure |
| 6754 | * @list_ddb: List from which failed ddb to be removed |
| 6755 | * |
| 6756 | * Iterate over the list of DDBs and find and remove DDBs that are either in |
| 6757 | * no connection active state or failed state |
| 6758 | **/ |
| 6759 | static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha, |
| 6760 | struct list_head *list_ddb) |
| 6761 | { |
| 6762 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 6763 | uint32_t next_idx = 0; |
| 6764 | uint32_t state = 0, conn_err = 0; |
| 6765 | int ret; |
| 6766 | |
| 6767 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6768 | ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx, |
| 6769 | NULL, 0, NULL, &next_idx, &state, |
| 6770 | &conn_err, NULL, NULL); |
| 6771 | if (ret == QLA_ERROR) |
| 6772 | continue; |
| 6773 | |
| 6774 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 6775 | state == DDB_DS_SESSION_FAILED) { |
| 6776 | list_del_init(&ddb_idx->list); |
| 6777 | vfree(ddb_idx); |
| 6778 | } |
| 6779 | } |
| 6780 | } |
| 6781 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6782 | static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha, |
| 6783 | struct ddb_entry *ddb_entry, |
| 6784 | struct dev_db_entry *fw_ddb_entry) |
| 6785 | { |
| 6786 | struct iscsi_cls_session *cls_sess; |
| 6787 | struct iscsi_session *sess; |
| 6788 | uint32_t max_ddbs = 0; |
| 6789 | uint16_t ddb_link = -1; |
| 6790 | |
| 6791 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6792 | MAX_DEV_DB_ENTRIES; |
| 6793 | |
| 6794 | cls_sess = ddb_entry->sess; |
| 6795 | sess = cls_sess->dd_data; |
| 6796 | |
| 6797 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6798 | if (ddb_link < max_ddbs) |
| 6799 | sess->discovery_parent_idx = ddb_link; |
| 6800 | else |
| 6801 | sess->discovery_parent_idx = DDB_NO_LINK; |
| 6802 | } |
| 6803 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6804 | static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha, |
| 6805 | struct dev_db_entry *fw_ddb_entry, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6806 | int is_reset, uint16_t idx) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6807 | { |
| 6808 | struct iscsi_cls_session *cls_sess; |
| 6809 | struct iscsi_session *sess; |
| 6810 | struct iscsi_cls_conn *cls_conn; |
| 6811 | struct iscsi_endpoint *ep; |
| 6812 | uint16_t cmds_max = 32; |
| 6813 | uint16_t conn_id = 0; |
| 6814 | uint32_t initial_cmdsn = 0; |
| 6815 | int ret = QLA_SUCCESS; |
| 6816 | |
| 6817 | struct ddb_entry *ddb_entry = NULL; |
| 6818 | |
| 6819 | /* Create session object, with INVALID_ENTRY, |
| 6820 | * the targer_id would get set when we issue the login |
| 6821 | */ |
| 6822 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host, |
| 6823 | cmds_max, sizeof(struct ddb_entry), |
| 6824 | sizeof(struct ql4_task_data), |
| 6825 | initial_cmdsn, INVALID_ENTRY); |
| 6826 | if (!cls_sess) { |
| 6827 | ret = QLA_ERROR; |
| 6828 | goto exit_setup; |
| 6829 | } |
| 6830 | |
| 6831 | /* |
| 6832 | * so calling module_put function to decrement the |
| 6833 | * reference count. |
| 6834 | **/ |
| 6835 | module_put(qla4xxx_iscsi_transport.owner); |
| 6836 | sess = cls_sess->dd_data; |
| 6837 | ddb_entry = sess->dd_data; |
| 6838 | ddb_entry->sess = cls_sess; |
| 6839 | |
| 6840 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 6841 | memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry, |
| 6842 | sizeof(struct dev_db_entry)); |
| 6843 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6844 | qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6845 | |
| 6846 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id); |
| 6847 | |
| 6848 | if (!cls_conn) { |
| 6849 | ret = QLA_ERROR; |
| 6850 | goto exit_setup; |
| 6851 | } |
| 6852 | |
| 6853 | ddb_entry->conn = cls_conn; |
| 6854 | |
| 6855 | /* Setup ep, for displaying attributes in sysfs */ |
| 6856 | ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry); |
| 6857 | if (ep) { |
| 6858 | ep->conn = cls_conn; |
| 6859 | cls_conn->ep = ep; |
| 6860 | } else { |
| 6861 | DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n")); |
| 6862 | ret = QLA_ERROR; |
| 6863 | goto exit_setup; |
| 6864 | } |
| 6865 | |
| 6866 | /* Update sess/conn params */ |
| 6867 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6868 | qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6869 | |
| 6870 | if (is_reset == RESET_ADAPTER) { |
| 6871 | iscsi_block_session(cls_sess); |
| 6872 | /* Use the relogin path to discover new devices |
| 6873 | * by short-circuting the logic of setting |
| 6874 | * timer to relogin - instead set the flags |
| 6875 | * to initiate login right away. |
| 6876 | */ |
| 6877 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 6878 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 6879 | } |
| 6880 | |
| 6881 | exit_setup: |
| 6882 | return ret; |
| 6883 | } |
| 6884 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6885 | static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha, |
| 6886 | struct list_head *list_ddb, |
| 6887 | struct dev_db_entry *fw_ddb_entry) |
| 6888 | { |
| 6889 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 6890 | uint16_t ddb_link; |
| 6891 | |
| 6892 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6893 | |
| 6894 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 6895 | if (ddb_idx->fw_ddb_idx == ddb_link) { |
| 6896 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6897 | "Updating NT parent idx from [%d] to [%d]\n", |
| 6898 | ddb_link, ddb_idx->flash_ddb_idx)); |
| 6899 | fw_ddb_entry->ddb_link = |
| 6900 | cpu_to_le16(ddb_idx->flash_ddb_idx); |
| 6901 | return; |
| 6902 | } |
| 6903 | } |
| 6904 | } |
| 6905 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6906 | static void qla4xxx_build_nt_list(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6907 | struct list_head *list_nt, |
| 6908 | struct list_head *list_st, |
| 6909 | int is_reset) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6910 | { |
| 6911 | struct dev_db_entry *fw_ddb_entry; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6912 | struct ddb_entry *ddb_entry = NULL; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6913 | dma_addr_t fw_ddb_dma; |
| 6914 | int max_ddbs; |
| 6915 | int fw_idx_size; |
| 6916 | int ret; |
| 6917 | uint32_t idx = 0, next_idx = 0; |
| 6918 | uint32_t state = 0, conn_err = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6919 | uint32_t ddb_idx = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6920 | uint16_t conn_id = 0; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6921 | uint16_t ddb_link = -1; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6922 | struct qla_ddb_index *nt_ddb_idx; |
| 6923 | |
| 6924 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 6925 | &fw_ddb_dma); |
| 6926 | if (fw_ddb_entry == NULL) { |
| 6927 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 6928 | goto exit_nt_list; |
| 6929 | } |
| 6930 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6931 | MAX_DEV_DB_ENTRIES; |
| 6932 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 6933 | |
| 6934 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 6935 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 6936 | NULL, &next_idx, &state, |
| 6937 | &conn_err, NULL, &conn_id); |
| 6938 | if (ret == QLA_ERROR) |
| 6939 | break; |
| 6940 | |
| 6941 | if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS) |
| 6942 | goto continue_next_nt; |
| 6943 | |
| 6944 | /* Check if NT, then add to list it */ |
| 6945 | if (strlen((char *) fw_ddb_entry->iscsi_name) == 0) |
| 6946 | goto continue_next_nt; |
| 6947 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6948 | ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 6949 | if (ddb_link < max_ddbs) |
| 6950 | qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry); |
| 6951 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6952 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE || |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6953 | state == DDB_DS_SESSION_FAILED) && |
| 6954 | (is_reset == INIT_ADAPTER)) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6955 | goto continue_next_nt; |
| 6956 | |
| 6957 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6958 | "Adding DDB to session = 0x%x\n", idx)); |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6959 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6960 | if (is_reset == INIT_ADAPTER) { |
| 6961 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 6962 | if (!nt_ddb_idx) |
| 6963 | break; |
| 6964 | |
| 6965 | nt_ddb_idx->fw_ddb_idx = idx; |
| 6966 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6967 | /* Copy original isid as it may get updated in function |
| 6968 | * qla4xxx_update_isid(). We need original isid in |
| 6969 | * function qla4xxx_compare_tuple_ddb to find duplicate |
| 6970 | * target */ |
| 6971 | memcpy(&nt_ddb_idx->flash_isid[0], |
| 6972 | &fw_ddb_entry->isid[0], |
| 6973 | sizeof(nt_ddb_idx->flash_isid)); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6974 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6975 | ret = qla4xxx_is_flash_ddb_exists(ha, list_nt, |
| 6976 | fw_ddb_entry); |
| 6977 | if (ret == QLA_SUCCESS) { |
| 6978 | /* free nt_ddb_idx and do not add to list_nt */ |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6979 | vfree(nt_ddb_idx); |
| 6980 | goto continue_next_nt; |
| 6981 | } |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 6982 | |
| 6983 | /* Copy updated isid */ |
| 6984 | memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry, |
| 6985 | sizeof(struct dev_db_entry)); |
| 6986 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6987 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 6988 | } else if (is_reset == RESET_ADAPTER) { |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6989 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, |
| 6990 | &ddb_idx); |
| 6991 | if (ret == QLA_SUCCESS) { |
| 6992 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, |
| 6993 | ddb_idx); |
| 6994 | if (ddb_entry != NULL) |
| 6995 | qla4xxx_update_sess_disc_idx(ha, |
| 6996 | ddb_entry, |
| 6997 | fw_ddb_entry); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6998 | goto continue_next_nt; |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 6999 | } |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7000 | } |
| 7001 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 7002 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 7003 | if (ret == QLA_ERROR) |
| 7004 | goto exit_nt_list; |
| 7005 | |
| 7006 | continue_next_nt: |
| 7007 | if (next_idx == 0) |
| 7008 | break; |
| 7009 | } |
| 7010 | |
| 7011 | exit_nt_list: |
| 7012 | if (fw_ddb_entry) |
| 7013 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7014 | } |
| 7015 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7016 | static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7017 | struct list_head *list_nt, |
| 7018 | uint16_t target_id) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7019 | { |
| 7020 | struct dev_db_entry *fw_ddb_entry; |
| 7021 | dma_addr_t fw_ddb_dma; |
| 7022 | int max_ddbs; |
| 7023 | int fw_idx_size; |
| 7024 | int ret; |
| 7025 | uint32_t idx = 0, next_idx = 0; |
| 7026 | uint32_t state = 0, conn_err = 0; |
| 7027 | uint16_t conn_id = 0; |
| 7028 | struct qla_ddb_index *nt_ddb_idx; |
| 7029 | |
| 7030 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 7031 | &fw_ddb_dma); |
| 7032 | if (fw_ddb_entry == NULL) { |
| 7033 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 7034 | goto exit_new_nt_list; |
| 7035 | } |
| 7036 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 7037 | MAX_DEV_DB_ENTRIES; |
| 7038 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 7039 | |
| 7040 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 7041 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 7042 | NULL, &next_idx, &state, |
| 7043 | &conn_err, NULL, &conn_id); |
| 7044 | if (ret == QLA_ERROR) |
| 7045 | break; |
| 7046 | |
| 7047 | /* Check if NT, then add it to list */ |
| 7048 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
| 7049 | goto continue_next_new_nt; |
| 7050 | |
| 7051 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE)) |
| 7052 | goto continue_next_new_nt; |
| 7053 | |
| 7054 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7055 | "Adding DDB to session = 0x%x\n", idx)); |
| 7056 | |
| 7057 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 7058 | if (!nt_ddb_idx) |
| 7059 | break; |
| 7060 | |
| 7061 | nt_ddb_idx->fw_ddb_idx = idx; |
| 7062 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7063 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7064 | if (ret == QLA_SUCCESS) { |
| 7065 | /* free nt_ddb_idx and do not add to list_nt */ |
| 7066 | vfree(nt_ddb_idx); |
| 7067 | goto continue_next_new_nt; |
| 7068 | } |
| 7069 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7070 | if (target_id < max_ddbs) |
| 7071 | fw_ddb_entry->ddb_link = cpu_to_le16(target_id); |
| 7072 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7073 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 7074 | |
| 7075 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 7076 | idx); |
| 7077 | if (ret == QLA_ERROR) |
| 7078 | goto exit_new_nt_list; |
| 7079 | |
| 7080 | continue_next_new_nt: |
| 7081 | if (next_idx == 0) |
| 7082 | break; |
| 7083 | } |
| 7084 | |
| 7085 | exit_new_nt_list: |
| 7086 | if (fw_ddb_entry) |
| 7087 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7088 | } |
| 7089 | |
| 7090 | /** |
| 7091 | * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry |
| 7092 | * @dev: dev associated with the sysfs entry |
| 7093 | * @data: pointer to flashnode session object |
| 7094 | * |
| 7095 | * Returns: |
| 7096 | * 1: if flashnode entry is non-persistent |
| 7097 | * 0: if flashnode entry is persistent |
| 7098 | **/ |
| 7099 | static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data) |
| 7100 | { |
| 7101 | struct iscsi_bus_flash_session *fnode_sess; |
| 7102 | |
| 7103 | if (!iscsi_flashnode_bus_match(dev, NULL)) |
| 7104 | return 0; |
| 7105 | |
| 7106 | fnode_sess = iscsi_dev_to_flash_session(dev); |
| 7107 | |
| 7108 | return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT); |
| 7109 | } |
| 7110 | |
| 7111 | /** |
| 7112 | * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target |
| 7113 | * @ha: pointer to host |
| 7114 | * @fw_ddb_entry: flash ddb data |
| 7115 | * @idx: target index |
| 7116 | * @user: if set then this call is made from userland else from kernel |
| 7117 | * |
| 7118 | * Returns: |
| 7119 | * On sucess: QLA_SUCCESS |
| 7120 | * On failure: QLA_ERROR |
| 7121 | * |
| 7122 | * This create separate sysfs entries for session and connection attributes of |
| 7123 | * the given fw ddb entry. |
| 7124 | * If this is invoked as a result of a userspace call then the entry is marked |
| 7125 | * as nonpersistent using flash_state field. |
| 7126 | **/ |
Vikas Chaudhary | 28e02f1 | 2013-04-17 05:15:27 -0400 | [diff] [blame] | 7127 | static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha, |
| 7128 | struct dev_db_entry *fw_ddb_entry, |
| 7129 | uint16_t *idx, int user) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7130 | { |
| 7131 | struct iscsi_bus_flash_session *fnode_sess = NULL; |
| 7132 | struct iscsi_bus_flash_conn *fnode_conn = NULL; |
| 7133 | int rc = QLA_ERROR; |
| 7134 | |
| 7135 | fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx, |
| 7136 | &qla4xxx_iscsi_transport, 0); |
| 7137 | if (!fnode_sess) { |
| 7138 | ql4_printk(KERN_ERR, ha, |
| 7139 | "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n", |
| 7140 | __func__, *idx, ha->host_no); |
| 7141 | goto exit_tgt_create; |
| 7142 | } |
| 7143 | |
| 7144 | fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess, |
| 7145 | &qla4xxx_iscsi_transport, 0); |
| 7146 | if (!fnode_conn) { |
| 7147 | ql4_printk(KERN_ERR, ha, |
| 7148 | "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n", |
| 7149 | __func__, *idx, ha->host_no); |
| 7150 | goto free_sess; |
| 7151 | } |
| 7152 | |
| 7153 | if (user) { |
| 7154 | fnode_sess->flash_state = DEV_DB_NON_PERSISTENT; |
| 7155 | } else { |
| 7156 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 7157 | |
| 7158 | if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx) |
| 7159 | fnode_sess->is_boot_target = 1; |
| 7160 | else |
| 7161 | fnode_sess->is_boot_target = 0; |
| 7162 | } |
| 7163 | |
| 7164 | rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn, |
| 7165 | fw_ddb_entry); |
| 7166 | |
| 7167 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 7168 | __func__, fnode_sess->dev.kobj.name); |
| 7169 | |
| 7170 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 7171 | __func__, fnode_conn->dev.kobj.name); |
| 7172 | |
| 7173 | return QLA_SUCCESS; |
| 7174 | |
| 7175 | free_sess: |
| 7176 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 7177 | |
| 7178 | exit_tgt_create: |
| 7179 | return QLA_ERROR; |
| 7180 | } |
| 7181 | |
| 7182 | /** |
| 7183 | * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash |
| 7184 | * @shost: pointer to host |
| 7185 | * @buf: type of ddb entry (ipv4/ipv6) |
| 7186 | * @len: length of buf |
| 7187 | * |
| 7188 | * This creates new ddb entry in the flash by finding first free index and |
| 7189 | * storing default ddb there. And then create sysfs entry for the new ddb entry. |
| 7190 | **/ |
| 7191 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 7192 | int len) |
| 7193 | { |
| 7194 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7195 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7196 | dma_addr_t fw_ddb_entry_dma; |
| 7197 | struct device *dev; |
| 7198 | uint16_t idx = 0; |
| 7199 | uint16_t max_ddbs = 0; |
| 7200 | uint32_t options = 0; |
| 7201 | uint32_t rval = QLA_ERROR; |
| 7202 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7203 | if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) && |
| 7204 | strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) { |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7205 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n", |
| 7206 | __func__)); |
| 7207 | goto exit_ddb_add; |
| 7208 | } |
| 7209 | |
Adheer Chandravanshi | a957a7d | 2013-04-05 07:06:08 -0400 | [diff] [blame] | 7210 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7211 | MAX_DEV_DB_ENTRIES; |
| 7212 | |
| 7213 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7214 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7215 | if (!fw_ddb_entry) { |
| 7216 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7217 | "%s: Unable to allocate dma buffer\n", |
| 7218 | __func__)); |
| 7219 | goto exit_ddb_add; |
| 7220 | } |
| 7221 | |
| 7222 | dev = iscsi_find_flashnode_sess(ha->host, NULL, |
| 7223 | qla4xxx_sysfs_ddb_is_non_persistent); |
| 7224 | if (dev) { |
| 7225 | ql4_printk(KERN_ERR, ha, |
| 7226 | "%s: A non-persistent entry %s found\n", |
| 7227 | __func__, dev->kobj.name); |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7228 | put_device(dev); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7229 | goto exit_ddb_add; |
| 7230 | } |
| 7231 | |
Adheer Chandravanshi | 9993757 | 2013-07-08 08:33:09 -0400 | [diff] [blame] | 7232 | /* Index 0 and 1 are reserved for boot target entries */ |
| 7233 | for (idx = 2; idx < max_ddbs; idx++) { |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7234 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, |
| 7235 | fw_ddb_entry_dma, idx)) |
| 7236 | break; |
| 7237 | } |
| 7238 | |
| 7239 | if (idx == max_ddbs) |
| 7240 | goto exit_ddb_add; |
| 7241 | |
| 7242 | if (!strncasecmp("ipv6", buf, 4)) |
| 7243 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7244 | |
| 7245 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7246 | if (rval == QLA_ERROR) |
| 7247 | goto exit_ddb_add; |
| 7248 | |
| 7249 | rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1); |
| 7250 | |
| 7251 | exit_ddb_add: |
| 7252 | if (fw_ddb_entry) |
| 7253 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7254 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7255 | if (rval == QLA_SUCCESS) |
| 7256 | return idx; |
| 7257 | else |
| 7258 | return -EIO; |
| 7259 | } |
| 7260 | |
| 7261 | /** |
| 7262 | * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash |
| 7263 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7264 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7265 | * |
| 7266 | * This writes the contents of target ddb buffer to Flash with a valid cookie |
| 7267 | * value in order to make the ddb entry persistent. |
| 7268 | **/ |
| 7269 | static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess, |
| 7270 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7271 | { |
| 7272 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7273 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7274 | uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
| 7275 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7276 | dma_addr_t fw_ddb_entry_dma; |
| 7277 | uint32_t options = 0; |
| 7278 | int rval = 0; |
| 7279 | |
| 7280 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7281 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7282 | if (!fw_ddb_entry) { |
| 7283 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7284 | "%s: Unable to allocate dma buffer\n", |
| 7285 | __func__)); |
| 7286 | rval = -ENOMEM; |
| 7287 | goto exit_ddb_apply; |
| 7288 | } |
| 7289 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7290 | if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7291 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7292 | |
| 7293 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7294 | if (rval == QLA_ERROR) |
| 7295 | goto exit_ddb_apply; |
| 7296 | |
| 7297 | dev_db_start_offset += (fnode_sess->target_id * |
| 7298 | sizeof(*fw_ddb_entry)); |
| 7299 | |
| 7300 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 7301 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 7302 | |
| 7303 | rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
| 7304 | sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT); |
| 7305 | |
| 7306 | if (rval == QLA_SUCCESS) { |
| 7307 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 7308 | ql4_printk(KERN_INFO, ha, |
| 7309 | "%s: flash node %u of host %lu written to flash\n", |
| 7310 | __func__, fnode_sess->target_id, ha->host_no); |
| 7311 | } else { |
| 7312 | rval = -EIO; |
| 7313 | ql4_printk(KERN_ERR, ha, |
| 7314 | "%s: Error while writing flash node %u of host %lu to flash\n", |
| 7315 | __func__, fnode_sess->target_id, ha->host_no); |
| 7316 | } |
| 7317 | |
| 7318 | exit_ddb_apply: |
| 7319 | if (fw_ddb_entry) |
| 7320 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7321 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7322 | return rval; |
| 7323 | } |
| 7324 | |
| 7325 | static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha, |
| 7326 | struct dev_db_entry *fw_ddb_entry, |
| 7327 | uint16_t idx) |
| 7328 | { |
| 7329 | struct dev_db_entry *ddb_entry = NULL; |
| 7330 | dma_addr_t ddb_entry_dma; |
| 7331 | unsigned long wtime; |
| 7332 | uint32_t mbx_sts = 0; |
| 7333 | uint32_t state = 0, conn_err = 0; |
| 7334 | uint16_t tmo = 0; |
| 7335 | int ret = 0; |
| 7336 | |
| 7337 | ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 7338 | &ddb_entry_dma, GFP_KERNEL); |
| 7339 | if (!ddb_entry) { |
| 7340 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7341 | "%s: Unable to allocate dma buffer\n", |
| 7342 | __func__)); |
| 7343 | return QLA_ERROR; |
| 7344 | } |
| 7345 | |
| 7346 | memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry)); |
| 7347 | |
| 7348 | ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts); |
| 7349 | if (ret != QLA_SUCCESS) { |
| 7350 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7351 | "%s: Unable to set ddb entry for index %d\n", |
| 7352 | __func__, idx)); |
| 7353 | goto exit_ddb_conn_open; |
| 7354 | } |
| 7355 | |
| 7356 | qla4xxx_conn_open(ha, idx); |
| 7357 | |
| 7358 | /* To ensure that sendtargets is done, wait for at least 12 secs */ |
| 7359 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 7360 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 7361 | ha->def_timeout : LOGIN_TOV); |
| 7362 | |
| 7363 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 7364 | "Default time to wait for login to ddb %d\n", tmo)); |
| 7365 | |
| 7366 | wtime = jiffies + (HZ * tmo); |
| 7367 | do { |
| 7368 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, |
| 7369 | NULL, &state, &conn_err, NULL, |
| 7370 | NULL); |
| 7371 | if (ret == QLA_ERROR) |
| 7372 | continue; |
| 7373 | |
| 7374 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 7375 | state == DDB_DS_SESSION_FAILED) |
| 7376 | break; |
| 7377 | |
| 7378 | schedule_timeout_uninterruptible(HZ / 10); |
| 7379 | } while (time_after(wtime, jiffies)); |
| 7380 | |
| 7381 | exit_ddb_conn_open: |
| 7382 | if (ddb_entry) |
| 7383 | dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 7384 | ddb_entry, ddb_entry_dma); |
| 7385 | return ret; |
| 7386 | } |
| 7387 | |
| 7388 | static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha, |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7389 | struct dev_db_entry *fw_ddb_entry, |
| 7390 | uint16_t target_id) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7391 | { |
| 7392 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 7393 | struct list_head list_nt; |
| 7394 | uint16_t ddb_index; |
| 7395 | int ret = 0; |
| 7396 | |
| 7397 | if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) { |
| 7398 | ql4_printk(KERN_WARNING, ha, |
| 7399 | "%s: A discovery already in progress!\n", __func__); |
| 7400 | return QLA_ERROR; |
| 7401 | } |
| 7402 | |
| 7403 | INIT_LIST_HEAD(&list_nt); |
| 7404 | |
| 7405 | set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 7406 | |
| 7407 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 7408 | if (ret == QLA_ERROR) |
| 7409 | goto exit_login_st_clr_bit; |
| 7410 | |
| 7411 | ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index); |
| 7412 | if (ret == QLA_ERROR) |
| 7413 | goto exit_login_st; |
| 7414 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7415 | qla4xxx_build_new_nt_list(ha, &list_nt, target_id); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7416 | |
| 7417 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) { |
| 7418 | list_del_init(&ddb_idx->list); |
| 7419 | qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx); |
| 7420 | vfree(ddb_idx); |
| 7421 | } |
| 7422 | |
| 7423 | exit_login_st: |
| 7424 | if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) { |
| 7425 | ql4_printk(KERN_ERR, ha, |
| 7426 | "Unable to clear DDB index = 0x%x\n", ddb_index); |
| 7427 | } |
| 7428 | |
| 7429 | clear_bit(ddb_index, ha->ddb_idx_map); |
| 7430 | |
| 7431 | exit_login_st_clr_bit: |
| 7432 | clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 7433 | return ret; |
| 7434 | } |
| 7435 | |
| 7436 | static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha, |
| 7437 | struct dev_db_entry *fw_ddb_entry, |
| 7438 | uint16_t idx) |
| 7439 | { |
| 7440 | int ret = QLA_ERROR; |
| 7441 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7442 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7443 | if (ret != QLA_SUCCESS) |
| 7444 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 7445 | idx); |
| 7446 | else |
| 7447 | ret = -EPERM; |
| 7448 | |
| 7449 | return ret; |
| 7450 | } |
| 7451 | |
| 7452 | /** |
| 7453 | * qla4xxx_sysfs_ddb_login - Login to the specified target |
| 7454 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7455 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7456 | * |
| 7457 | * This logs in to the specified target |
| 7458 | **/ |
| 7459 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 7460 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7461 | { |
| 7462 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7463 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7464 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7465 | dma_addr_t fw_ddb_entry_dma; |
| 7466 | uint32_t options = 0; |
| 7467 | int ret = 0; |
| 7468 | |
| 7469 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) { |
| 7470 | ql4_printk(KERN_ERR, ha, |
| 7471 | "%s: Target info is not persistent\n", __func__); |
| 7472 | ret = -EIO; |
| 7473 | goto exit_ddb_login; |
| 7474 | } |
| 7475 | |
| 7476 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7477 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7478 | if (!fw_ddb_entry) { |
| 7479 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 7480 | "%s: Unable to allocate dma buffer\n", |
| 7481 | __func__)); |
| 7482 | ret = -ENOMEM; |
| 7483 | goto exit_ddb_login; |
| 7484 | } |
| 7485 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7486 | if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7487 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 7488 | |
| 7489 | ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 7490 | if (ret == QLA_ERROR) |
| 7491 | goto exit_ddb_login; |
| 7492 | |
| 7493 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 7494 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 7495 | |
| 7496 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 7497 | ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry, |
| 7498 | fnode_sess->target_id); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7499 | else |
| 7500 | ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry, |
| 7501 | fnode_sess->target_id); |
| 7502 | |
| 7503 | if (ret > 0) |
| 7504 | ret = -EIO; |
| 7505 | |
| 7506 | exit_ddb_login: |
| 7507 | if (fw_ddb_entry) |
| 7508 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7509 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7510 | return ret; |
| 7511 | } |
| 7512 | |
| 7513 | /** |
| 7514 | * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target |
| 7515 | * @cls_sess: pointer to session to be logged out |
| 7516 | * |
| 7517 | * This performs session log out from the specified target |
| 7518 | **/ |
| 7519 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess) |
| 7520 | { |
| 7521 | struct iscsi_session *sess; |
| 7522 | struct ddb_entry *ddb_entry = NULL; |
| 7523 | struct scsi_qla_host *ha; |
| 7524 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7525 | dma_addr_t fw_ddb_entry_dma; |
| 7526 | unsigned long flags; |
| 7527 | unsigned long wtime; |
| 7528 | uint32_t ddb_state; |
| 7529 | int options; |
| 7530 | int ret = 0; |
| 7531 | |
| 7532 | sess = cls_sess->dd_data; |
| 7533 | ddb_entry = sess->dd_data; |
| 7534 | ha = ddb_entry->ha; |
| 7535 | |
| 7536 | if (ddb_entry->ddb_type != FLASH_DDB) { |
| 7537 | ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n", |
| 7538 | __func__); |
| 7539 | ret = -ENXIO; |
| 7540 | goto exit_ddb_logout; |
| 7541 | } |
| 7542 | |
Adheer Chandravanshi | 37719c2 | 2013-04-05 07:06:07 -0400 | [diff] [blame] | 7543 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 7544 | ql4_printk(KERN_ERR, ha, |
| 7545 | "%s: Logout from boot target entry is not permitted.\n", |
| 7546 | __func__); |
| 7547 | ret = -EPERM; |
| 7548 | goto exit_ddb_logout; |
| 7549 | } |
| 7550 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7551 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7552 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 7553 | if (!fw_ddb_entry) { |
| 7554 | ql4_printk(KERN_ERR, ha, |
| 7555 | "%s: Unable to allocate dma buffer\n", __func__); |
| 7556 | ret = -ENOMEM; |
| 7557 | goto exit_ddb_logout; |
| 7558 | } |
| 7559 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7560 | if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) |
| 7561 | goto ddb_logout_init; |
| 7562 | |
| 7563 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 7564 | fw_ddb_entry, fw_ddb_entry_dma, |
| 7565 | NULL, NULL, &ddb_state, NULL, |
| 7566 | NULL, NULL); |
| 7567 | if (ret == QLA_ERROR) |
| 7568 | goto ddb_logout_init; |
| 7569 | |
| 7570 | if (ddb_state == DDB_DS_SESSION_ACTIVE) |
| 7571 | goto ddb_logout_init; |
| 7572 | |
| 7573 | /* wait until next relogin is triggered using DF_RELOGIN and |
| 7574 | * clear DF_RELOGIN to avoid invocation of further relogin |
| 7575 | */ |
| 7576 | wtime = jiffies + (HZ * RELOGIN_TOV); |
| 7577 | do { |
| 7578 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 7579 | goto ddb_logout_init; |
| 7580 | |
| 7581 | schedule_timeout_uninterruptible(HZ); |
| 7582 | } while ((time_after(wtime, jiffies))); |
| 7583 | |
| 7584 | ddb_logout_init: |
| 7585 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 7586 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 7587 | |
| 7588 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 7589 | qla4xxx_session_logout_ddb(ha, ddb_entry, options); |
| 7590 | |
| 7591 | memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry)); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7592 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 7593 | do { |
| 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_clr_sess; |
| 7600 | |
| 7601 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 7602 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 7603 | goto ddb_logout_clr_sess; |
| 7604 | |
| 7605 | schedule_timeout_uninterruptible(HZ); |
| 7606 | } while ((time_after(wtime, jiffies))); |
| 7607 | |
| 7608 | ddb_logout_clr_sess: |
| 7609 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 7610 | /* |
| 7611 | * we have decremented the reference count of the driver |
| 7612 | * when we setup the session to have the driver unload |
| 7613 | * to be seamless without actually destroying the |
| 7614 | * session |
| 7615 | **/ |
| 7616 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 7617 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 7618 | |
| 7619 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 7620 | qla4xxx_free_ddb(ha, ddb_entry); |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7621 | clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7622 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 7623 | |
| 7624 | iscsi_session_teardown(ddb_entry->sess); |
| 7625 | |
Adheer Chandravanshi | 99c6a33 | 2013-07-08 08:33:05 -0400 | [diff] [blame] | 7626 | clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7627 | ret = QLA_SUCCESS; |
| 7628 | |
| 7629 | exit_ddb_logout: |
| 7630 | if (fw_ddb_entry) |
| 7631 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 7632 | fw_ddb_entry, fw_ddb_entry_dma); |
| 7633 | return ret; |
| 7634 | } |
| 7635 | |
| 7636 | /** |
| 7637 | * qla4xxx_sysfs_ddb_logout - Logout from the specified target |
| 7638 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 7639 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 7640 | * |
| 7641 | * This performs log out from the specified target |
| 7642 | **/ |
| 7643 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 7644 | struct iscsi_bus_flash_conn *fnode_conn) |
| 7645 | { |
| 7646 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7647 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7648 | struct ql4_tuple_ddb *flash_tddb = NULL; |
| 7649 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 7650 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 7651 | struct ddb_entry *ddb_entry = NULL; |
| 7652 | dma_addr_t fw_ddb_dma; |
| 7653 | uint32_t next_idx = 0; |
| 7654 | uint32_t state = 0, conn_err = 0; |
| 7655 | uint16_t conn_id = 0; |
| 7656 | int idx, index; |
| 7657 | int status, ret = 0; |
| 7658 | |
| 7659 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 7660 | &fw_ddb_dma); |
| 7661 | if (fw_ddb_entry == NULL) { |
| 7662 | ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__); |
| 7663 | ret = -ENOMEM; |
| 7664 | goto exit_ddb_logout; |
| 7665 | } |
| 7666 | |
| 7667 | flash_tddb = vzalloc(sizeof(*flash_tddb)); |
| 7668 | if (!flash_tddb) { |
| 7669 | ql4_printk(KERN_WARNING, ha, |
| 7670 | "%s:Memory Allocation failed.\n", __func__); |
| 7671 | ret = -ENOMEM; |
| 7672 | goto exit_ddb_logout; |
| 7673 | } |
| 7674 | |
| 7675 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 7676 | if (!tmp_tddb) { |
| 7677 | ql4_printk(KERN_WARNING, ha, |
| 7678 | "%s:Memory Allocation failed.\n", __func__); |
| 7679 | ret = -ENOMEM; |
| 7680 | goto exit_ddb_logout; |
| 7681 | } |
| 7682 | |
| 7683 | if (!fnode_sess->targetname) { |
| 7684 | ql4_printk(KERN_ERR, ha, |
| 7685 | "%s:Cannot logout from SendTarget entry\n", |
| 7686 | __func__); |
| 7687 | ret = -EPERM; |
| 7688 | goto exit_ddb_logout; |
| 7689 | } |
| 7690 | |
| 7691 | if (fnode_sess->is_boot_target) { |
| 7692 | ql4_printk(KERN_ERR, ha, |
| 7693 | "%s: Logout from boot target entry is not permitted.\n", |
| 7694 | __func__); |
| 7695 | ret = -EPERM; |
| 7696 | goto exit_ddb_logout; |
| 7697 | } |
| 7698 | |
| 7699 | strncpy(flash_tddb->iscsi_name, fnode_sess->targetname, |
| 7700 | ISCSI_NAME_SIZE); |
| 7701 | |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7702 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7703 | sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress); |
| 7704 | else |
| 7705 | sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress); |
| 7706 | |
| 7707 | flash_tddb->tpgt = fnode_sess->tpgt; |
| 7708 | flash_tddb->port = fnode_conn->port; |
| 7709 | |
| 7710 | COPY_ISID(flash_tddb->isid, fnode_sess->isid); |
| 7711 | |
| 7712 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 7713 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 7714 | if (ddb_entry == NULL) |
| 7715 | continue; |
| 7716 | |
| 7717 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 7718 | continue; |
| 7719 | |
| 7720 | index = ddb_entry->sess->target_id; |
| 7721 | status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry, |
| 7722 | fw_ddb_dma, NULL, &next_idx, |
| 7723 | &state, &conn_err, NULL, |
| 7724 | &conn_id); |
| 7725 | if (status == QLA_ERROR) { |
| 7726 | ret = -ENOMEM; |
| 7727 | break; |
| 7728 | } |
| 7729 | |
| 7730 | qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL); |
| 7731 | |
| 7732 | status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb, |
| 7733 | true); |
| 7734 | if (status == QLA_SUCCESS) { |
| 7735 | ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess); |
| 7736 | break; |
| 7737 | } |
| 7738 | } |
| 7739 | |
| 7740 | if (idx == MAX_DDB_ENTRIES) |
| 7741 | ret = -ESRCH; |
| 7742 | |
| 7743 | exit_ddb_logout: |
| 7744 | if (flash_tddb) |
| 7745 | vfree(flash_tddb); |
| 7746 | if (tmp_tddb) |
| 7747 | vfree(tmp_tddb); |
| 7748 | if (fw_ddb_entry) |
| 7749 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 7750 | |
| 7751 | return ret; |
| 7752 | } |
| 7753 | |
| 7754 | static int |
| 7755 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 7756 | int param, char *buf) |
| 7757 | { |
| 7758 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 7759 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7760 | struct iscsi_bus_flash_conn *fnode_conn; |
| 7761 | struct ql4_chap_table chap_tbl; |
| 7762 | struct device *dev; |
Adheer Chandravanshi | a2f7663 | 2013-07-08 08:33:08 -0400 | [diff] [blame] | 7763 | int parent_type; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7764 | int rc = 0; |
| 7765 | |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7766 | dev = iscsi_find_flashnode_conn(fnode_sess); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7767 | if (!dev) |
| 7768 | return -EIO; |
| 7769 | |
| 7770 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 7771 | |
| 7772 | switch (param) { |
| 7773 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 7774 | rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6); |
| 7775 | break; |
| 7776 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 7777 | rc = sprintf(buf, "%s\n", fnode_sess->portal_type); |
| 7778 | break; |
| 7779 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 7780 | rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable); |
| 7781 | break; |
| 7782 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 7783 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess); |
| 7784 | break; |
| 7785 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 7786 | rc = sprintf(buf, "%u\n", fnode_sess->entry_state); |
| 7787 | break; |
| 7788 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 7789 | rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en); |
| 7790 | break; |
| 7791 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 7792 | rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en); |
| 7793 | break; |
| 7794 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 7795 | rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en); |
| 7796 | break; |
| 7797 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 7798 | rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en); |
| 7799 | break; |
| 7800 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 7801 | rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en); |
| 7802 | break; |
| 7803 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 7804 | rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en); |
| 7805 | break; |
| 7806 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 7807 | rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en); |
| 7808 | break; |
| 7809 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 7810 | rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en); |
| 7811 | break; |
| 7812 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 7813 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en); |
| 7814 | break; |
| 7815 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 7816 | rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en); |
| 7817 | break; |
| 7818 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 7819 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional); |
| 7820 | break; |
| 7821 | case ISCSI_FLASHNODE_ERL: |
| 7822 | rc = sprintf(buf, "%u\n", fnode_sess->erl); |
| 7823 | break; |
| 7824 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 7825 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat); |
| 7826 | break; |
| 7827 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 7828 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable); |
| 7829 | break; |
| 7830 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 7831 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable); |
| 7832 | break; |
| 7833 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 7834 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale); |
| 7835 | break; |
| 7836 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 7837 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en); |
| 7838 | break; |
| 7839 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 7840 | rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable); |
| 7841 | break; |
| 7842 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 7843 | rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength); |
| 7844 | break; |
| 7845 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 7846 | rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength); |
| 7847 | break; |
| 7848 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 7849 | rc = sprintf(buf, "%u\n", fnode_sess->first_burst); |
| 7850 | break; |
| 7851 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 7852 | rc = sprintf(buf, "%u\n", fnode_sess->time2wait); |
| 7853 | break; |
| 7854 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 7855 | rc = sprintf(buf, "%u\n", fnode_sess->time2retain); |
| 7856 | break; |
| 7857 | case ISCSI_FLASHNODE_MAX_R2T: |
| 7858 | rc = sprintf(buf, "%u\n", fnode_sess->max_r2t); |
| 7859 | break; |
| 7860 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 7861 | rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout); |
| 7862 | break; |
| 7863 | case ISCSI_FLASHNODE_ISID: |
| 7864 | rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n", |
| 7865 | fnode_sess->isid[0], fnode_sess->isid[1], |
| 7866 | fnode_sess->isid[2], fnode_sess->isid[3], |
| 7867 | fnode_sess->isid[4], fnode_sess->isid[5]); |
| 7868 | break; |
| 7869 | case ISCSI_FLASHNODE_TSID: |
| 7870 | rc = sprintf(buf, "%u\n", fnode_sess->tsid); |
| 7871 | break; |
| 7872 | case ISCSI_FLASHNODE_PORT: |
| 7873 | rc = sprintf(buf, "%d\n", fnode_conn->port); |
| 7874 | break; |
| 7875 | case ISCSI_FLASHNODE_MAX_BURST: |
| 7876 | rc = sprintf(buf, "%u\n", fnode_sess->max_burst); |
| 7877 | break; |
| 7878 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 7879 | rc = sprintf(buf, "%u\n", |
| 7880 | fnode_sess->default_taskmgmt_timeout); |
| 7881 | break; |
| 7882 | case ISCSI_FLASHNODE_IPADDR: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7883 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7884 | rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress); |
| 7885 | else |
| 7886 | rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress); |
| 7887 | break; |
| 7888 | case ISCSI_FLASHNODE_ALIAS: |
| 7889 | if (fnode_sess->targetalias) |
| 7890 | rc = sprintf(buf, "%s\n", fnode_sess->targetalias); |
| 7891 | else |
| 7892 | rc = sprintf(buf, "\n"); |
| 7893 | break; |
| 7894 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7895 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7896 | rc = sprintf(buf, "%pI6\n", |
| 7897 | fnode_conn->redirect_ipaddr); |
| 7898 | else |
| 7899 | rc = sprintf(buf, "%pI4\n", |
| 7900 | fnode_conn->redirect_ipaddr); |
| 7901 | break; |
| 7902 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 7903 | rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size); |
| 7904 | break; |
| 7905 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 7906 | rc = sprintf(buf, "%u\n", fnode_conn->local_port); |
| 7907 | break; |
| 7908 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 7909 | rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos); |
| 7910 | break; |
| 7911 | case ISCSI_FLASHNODE_IPV6_TC: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7912 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7913 | rc = sprintf(buf, "%u\n", |
| 7914 | fnode_conn->ipv6_traffic_class); |
| 7915 | else |
| 7916 | rc = sprintf(buf, "\n"); |
| 7917 | break; |
| 7918 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 7919 | rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label); |
| 7920 | break; |
| 7921 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
Adheer Chandravanshi | c962c18 | 2013-03-25 08:08:32 -0400 | [diff] [blame] | 7922 | if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4)) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7923 | rc = sprintf(buf, "%pI6\n", |
| 7924 | fnode_conn->link_local_ipv6_addr); |
| 7925 | else |
| 7926 | rc = sprintf(buf, "\n"); |
| 7927 | break; |
| 7928 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
Adheer Chandravanshi | a2f7663 | 2013-07-08 08:33:08 -0400 | [diff] [blame] | 7929 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7930 | break; |
| 7931 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 7932 | if (fnode_sess->discovery_parent_type == DDB_ISNS) |
| 7933 | parent_type = ISCSI_DISC_PARENT_ISNS; |
| 7934 | else if (fnode_sess->discovery_parent_type == DDB_NO_LINK) |
| 7935 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
Vikas Chaudhary | b6130ce | 2013-04-17 05:15:26 -0400 | [diff] [blame] | 7936 | else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES) |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7937 | parent_type = ISCSI_DISC_PARENT_SENDTGT; |
| 7938 | else |
| 7939 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
| 7940 | |
| 7941 | rc = sprintf(buf, "%s\n", |
| 7942 | iscsi_get_discovery_parent_name(parent_type)); |
| 7943 | break; |
| 7944 | case ISCSI_FLASHNODE_NAME: |
| 7945 | if (fnode_sess->targetname) |
| 7946 | rc = sprintf(buf, "%s\n", fnode_sess->targetname); |
| 7947 | else |
| 7948 | rc = sprintf(buf, "\n"); |
| 7949 | break; |
| 7950 | case ISCSI_FLASHNODE_TPGT: |
| 7951 | rc = sprintf(buf, "%u\n", fnode_sess->tpgt); |
| 7952 | break; |
| 7953 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 7954 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf); |
| 7955 | break; |
| 7956 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 7957 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf); |
| 7958 | break; |
| 7959 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 7960 | rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx); |
| 7961 | break; |
| 7962 | case ISCSI_FLASHNODE_USERNAME: |
| 7963 | if (fnode_sess->chap_auth_en) { |
| 7964 | qla4xxx_get_uni_chap_at_index(ha, |
| 7965 | chap_tbl.name, |
| 7966 | chap_tbl.secret, |
| 7967 | fnode_sess->chap_out_idx); |
| 7968 | rc = sprintf(buf, "%s\n", chap_tbl.name); |
| 7969 | } else { |
| 7970 | rc = sprintf(buf, "\n"); |
| 7971 | } |
| 7972 | break; |
| 7973 | case ISCSI_FLASHNODE_PASSWORD: |
| 7974 | if (fnode_sess->chap_auth_en) { |
| 7975 | qla4xxx_get_uni_chap_at_index(ha, |
| 7976 | chap_tbl.name, |
| 7977 | chap_tbl.secret, |
| 7978 | fnode_sess->chap_out_idx); |
| 7979 | rc = sprintf(buf, "%s\n", chap_tbl.secret); |
| 7980 | } else { |
| 7981 | rc = sprintf(buf, "\n"); |
| 7982 | } |
| 7983 | break; |
| 7984 | case ISCSI_FLASHNODE_STATSN: |
| 7985 | rc = sprintf(buf, "%u\n", fnode_conn->statsn); |
| 7986 | break; |
| 7987 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 7988 | rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn); |
| 7989 | break; |
| 7990 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 7991 | rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target); |
| 7992 | break; |
| 7993 | default: |
| 7994 | rc = -ENOSYS; |
| 7995 | break; |
| 7996 | } |
Mike Christie | 8526cb1 | 2013-05-06 12:06:56 -0500 | [diff] [blame] | 7997 | |
| 7998 | put_device(dev); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7999 | return rc; |
| 8000 | } |
| 8001 | |
| 8002 | /** |
| 8003 | * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry |
| 8004 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 8005 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 8006 | * @data: Parameters and their values to update |
| 8007 | * @len: len of data |
| 8008 | * |
| 8009 | * This sets the parameter of flash ddb entry and writes them to flash |
| 8010 | **/ |
| 8011 | static int |
| 8012 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 8013 | struct iscsi_bus_flash_conn *fnode_conn, |
| 8014 | void *data, int len) |
| 8015 | { |
| 8016 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 8017 | struct scsi_qla_host *ha = to_qla_host(shost); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8018 | struct iscsi_flashnode_param_info *fnode_param; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8019 | struct ql4_chap_table chap_tbl; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8020 | struct nlattr *attr; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8021 | uint16_t chap_out_idx = INVALID_ENTRY; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8022 | int rc = QLA_ERROR; |
| 8023 | uint32_t rem = len; |
| 8024 | |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8025 | memset((void *)&chap_tbl, 0, sizeof(chap_tbl)); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8026 | nla_for_each_attr(attr, data, len, rem) { |
| 8027 | fnode_param = nla_data(attr); |
| 8028 | |
| 8029 | switch (fnode_param->param) { |
| 8030 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 8031 | fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0]; |
| 8032 | break; |
| 8033 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 8034 | memcpy(fnode_sess->portal_type, fnode_param->value, |
| 8035 | strlen(fnode_sess->portal_type)); |
| 8036 | break; |
| 8037 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 8038 | fnode_sess->auto_snd_tgt_disable = |
| 8039 | fnode_param->value[0]; |
| 8040 | break; |
| 8041 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 8042 | fnode_sess->discovery_sess = fnode_param->value[0]; |
| 8043 | break; |
| 8044 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 8045 | fnode_sess->entry_state = fnode_param->value[0]; |
| 8046 | break; |
| 8047 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 8048 | fnode_conn->hdrdgst_en = fnode_param->value[0]; |
| 8049 | break; |
| 8050 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 8051 | fnode_conn->datadgst_en = fnode_param->value[0]; |
| 8052 | break; |
| 8053 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 8054 | fnode_sess->imm_data_en = fnode_param->value[0]; |
| 8055 | break; |
| 8056 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 8057 | fnode_sess->initial_r2t_en = fnode_param->value[0]; |
| 8058 | break; |
| 8059 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 8060 | fnode_sess->dataseq_inorder_en = fnode_param->value[0]; |
| 8061 | break; |
| 8062 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 8063 | fnode_sess->pdu_inorder_en = fnode_param->value[0]; |
| 8064 | break; |
| 8065 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 8066 | fnode_sess->chap_auth_en = fnode_param->value[0]; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8067 | /* Invalidate chap index if chap auth is disabled */ |
| 8068 | if (!fnode_sess->chap_auth_en) |
| 8069 | fnode_sess->chap_out_idx = INVALID_ENTRY; |
| 8070 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8071 | break; |
| 8072 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 8073 | fnode_conn->snack_req_en = fnode_param->value[0]; |
| 8074 | break; |
| 8075 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 8076 | fnode_sess->discovery_logout_en = fnode_param->value[0]; |
| 8077 | break; |
| 8078 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 8079 | fnode_sess->bidi_chap_en = fnode_param->value[0]; |
| 8080 | break; |
| 8081 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 8082 | fnode_sess->discovery_auth_optional = |
| 8083 | fnode_param->value[0]; |
| 8084 | break; |
| 8085 | case ISCSI_FLASHNODE_ERL: |
| 8086 | fnode_sess->erl = fnode_param->value[0]; |
| 8087 | break; |
| 8088 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 8089 | fnode_conn->tcp_timestamp_stat = fnode_param->value[0]; |
| 8090 | break; |
| 8091 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 8092 | fnode_conn->tcp_nagle_disable = fnode_param->value[0]; |
| 8093 | break; |
| 8094 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 8095 | fnode_conn->tcp_wsf_disable = fnode_param->value[0]; |
| 8096 | break; |
| 8097 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 8098 | fnode_conn->tcp_timer_scale = fnode_param->value[0]; |
| 8099 | break; |
| 8100 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 8101 | fnode_conn->tcp_timestamp_en = fnode_param->value[0]; |
| 8102 | break; |
| 8103 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 8104 | fnode_conn->fragment_disable = fnode_param->value[0]; |
| 8105 | break; |
| 8106 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 8107 | fnode_conn->max_recv_dlength = |
| 8108 | *(unsigned *)fnode_param->value; |
| 8109 | break; |
| 8110 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 8111 | fnode_conn->max_xmit_dlength = |
| 8112 | *(unsigned *)fnode_param->value; |
| 8113 | break; |
| 8114 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 8115 | fnode_sess->first_burst = |
| 8116 | *(unsigned *)fnode_param->value; |
| 8117 | break; |
| 8118 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 8119 | fnode_sess->time2wait = *(uint16_t *)fnode_param->value; |
| 8120 | break; |
| 8121 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 8122 | fnode_sess->time2retain = |
| 8123 | *(uint16_t *)fnode_param->value; |
| 8124 | break; |
| 8125 | case ISCSI_FLASHNODE_MAX_R2T: |
| 8126 | fnode_sess->max_r2t = |
| 8127 | *(uint16_t *)fnode_param->value; |
| 8128 | break; |
| 8129 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 8130 | fnode_conn->keepalive_timeout = |
| 8131 | *(uint16_t *)fnode_param->value; |
| 8132 | break; |
| 8133 | case ISCSI_FLASHNODE_ISID: |
| 8134 | memcpy(fnode_sess->isid, fnode_param->value, |
| 8135 | sizeof(fnode_sess->isid)); |
| 8136 | break; |
| 8137 | case ISCSI_FLASHNODE_TSID: |
| 8138 | fnode_sess->tsid = *(uint16_t *)fnode_param->value; |
| 8139 | break; |
| 8140 | case ISCSI_FLASHNODE_PORT: |
| 8141 | fnode_conn->port = *(uint16_t *)fnode_param->value; |
| 8142 | break; |
| 8143 | case ISCSI_FLASHNODE_MAX_BURST: |
| 8144 | fnode_sess->max_burst = *(unsigned *)fnode_param->value; |
| 8145 | break; |
| 8146 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 8147 | fnode_sess->default_taskmgmt_timeout = |
| 8148 | *(uint16_t *)fnode_param->value; |
| 8149 | break; |
| 8150 | case ISCSI_FLASHNODE_IPADDR: |
| 8151 | memcpy(fnode_conn->ipaddress, fnode_param->value, |
| 8152 | IPv6_ADDR_LEN); |
| 8153 | break; |
| 8154 | case ISCSI_FLASHNODE_ALIAS: |
| 8155 | rc = iscsi_switch_str_param(&fnode_sess->targetalias, |
| 8156 | (char *)fnode_param->value); |
| 8157 | break; |
| 8158 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 8159 | memcpy(fnode_conn->redirect_ipaddr, fnode_param->value, |
| 8160 | IPv6_ADDR_LEN); |
| 8161 | break; |
| 8162 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 8163 | fnode_conn->max_segment_size = |
| 8164 | *(unsigned *)fnode_param->value; |
| 8165 | break; |
| 8166 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 8167 | fnode_conn->local_port = |
| 8168 | *(uint16_t *)fnode_param->value; |
| 8169 | break; |
| 8170 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 8171 | fnode_conn->ipv4_tos = fnode_param->value[0]; |
| 8172 | break; |
| 8173 | case ISCSI_FLASHNODE_IPV6_TC: |
| 8174 | fnode_conn->ipv6_traffic_class = fnode_param->value[0]; |
| 8175 | break; |
| 8176 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 8177 | fnode_conn->ipv6_flow_label = fnode_param->value[0]; |
| 8178 | break; |
| 8179 | case ISCSI_FLASHNODE_NAME: |
| 8180 | rc = iscsi_switch_str_param(&fnode_sess->targetname, |
| 8181 | (char *)fnode_param->value); |
| 8182 | break; |
| 8183 | case ISCSI_FLASHNODE_TPGT: |
| 8184 | fnode_sess->tpgt = *(uint16_t *)fnode_param->value; |
| 8185 | break; |
| 8186 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 8187 | memcpy(fnode_conn->link_local_ipv6_addr, |
| 8188 | fnode_param->value, IPv6_ADDR_LEN); |
| 8189 | break; |
Adheer Chandravanshi | 6556016 | 2013-07-08 08:33:06 -0400 | [diff] [blame] | 8190 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 8191 | fnode_sess->discovery_parent_idx = |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8192 | *(uint16_t *)fnode_param->value; |
| 8193 | break; |
| 8194 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 8195 | fnode_conn->tcp_xmit_wsf = |
| 8196 | *(uint8_t *)fnode_param->value; |
| 8197 | break; |
| 8198 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 8199 | fnode_conn->tcp_recv_wsf = |
| 8200 | *(uint8_t *)fnode_param->value; |
| 8201 | break; |
| 8202 | case ISCSI_FLASHNODE_STATSN: |
| 8203 | fnode_conn->statsn = *(uint32_t *)fnode_param->value; |
| 8204 | break; |
| 8205 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 8206 | fnode_conn->exp_statsn = |
| 8207 | *(uint32_t *)fnode_param->value; |
| 8208 | break; |
Adheer Chandravanshi | 244c079 | 2013-09-17 07:54:45 -0400 | [diff] [blame] | 8209 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 8210 | chap_out_idx = *(uint16_t *)fnode_param->value; |
| 8211 | if (!qla4xxx_get_uni_chap_at_index(ha, |
| 8212 | chap_tbl.name, |
| 8213 | chap_tbl.secret, |
| 8214 | chap_out_idx)) { |
| 8215 | fnode_sess->chap_out_idx = chap_out_idx; |
| 8216 | /* Enable chap auth if chap index is valid */ |
| 8217 | fnode_sess->chap_auth_en = QL4_PARAM_ENABLE; |
| 8218 | } |
| 8219 | break; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8220 | default: |
| 8221 | ql4_printk(KERN_ERR, ha, |
| 8222 | "%s: No such sysfs attribute\n", __func__); |
| 8223 | rc = -ENOSYS; |
| 8224 | goto exit_set_param; |
| 8225 | } |
| 8226 | } |
| 8227 | |
| 8228 | rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn); |
| 8229 | |
| 8230 | exit_set_param: |
| 8231 | return rc; |
| 8232 | } |
| 8233 | |
| 8234 | /** |
| 8235 | * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry |
| 8236 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 8237 | * |
| 8238 | * This invalidates the flash ddb entry at the given index |
| 8239 | **/ |
| 8240 | static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess) |
| 8241 | { |
| 8242 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 8243 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 8244 | uint32_t dev_db_start_offset; |
| 8245 | uint32_t dev_db_end_offset; |
| 8246 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8247 | dma_addr_t fw_ddb_entry_dma; |
| 8248 | uint16_t *ddb_cookie = NULL; |
Vikas Chaudhary | b6130ce | 2013-04-17 05:15:26 -0400 | [diff] [blame] | 8249 | size_t ddb_size = 0; |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8250 | void *pddb = NULL; |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8251 | int target_id; |
| 8252 | int rc = 0; |
| 8253 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8254 | if (fnode_sess->is_boot_target) { |
| 8255 | rc = -EPERM; |
| 8256 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8257 | "%s: Deletion of boot target entry is not permitted.\n", |
| 8258 | __func__)); |
| 8259 | goto exit_ddb_del; |
| 8260 | } |
| 8261 | |
| 8262 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) |
| 8263 | goto sysfs_ddb_del; |
| 8264 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8265 | if (is_qla40XX(ha)) { |
| 8266 | dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8267 | dev_db_end_offset = FLASH_OFFSET_DB_END; |
| 8268 | dev_db_start_offset += (fnode_sess->target_id * |
| 8269 | sizeof(*fw_ddb_entry)); |
| 8270 | ddb_size = sizeof(*fw_ddb_entry); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8271 | } else { |
| 8272 | dev_db_start_offset = FLASH_RAW_ACCESS_ADDR + |
| 8273 | (ha->hw.flt_region_ddb << 2); |
| 8274 | /* flt_ddb_size is DDB table size for both ports |
| 8275 | * so divide it by 2 to calculate the offset for second port |
| 8276 | */ |
| 8277 | if (ha->port_num == 1) |
| 8278 | dev_db_start_offset += (ha->hw.flt_ddb_size / 2); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8279 | |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8280 | dev_db_end_offset = dev_db_start_offset + |
| 8281 | (ha->hw.flt_ddb_size / 2); |
| 8282 | |
| 8283 | dev_db_start_offset += (fnode_sess->target_id * |
| 8284 | sizeof(*fw_ddb_entry)); |
Adheer Chandravanshi | 1bcb561 | 2013-04-17 05:15:28 -0400 | [diff] [blame] | 8285 | dev_db_start_offset += offsetof(struct dev_db_entry, cookie); |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8286 | |
| 8287 | ddb_size = sizeof(*ddb_cookie); |
| 8288 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8289 | |
| 8290 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n", |
| 8291 | __func__, dev_db_start_offset, dev_db_end_offset)); |
| 8292 | |
| 8293 | if (dev_db_start_offset > dev_db_end_offset) { |
| 8294 | rc = -EIO; |
| 8295 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n", |
| 8296 | __func__, fnode_sess->target_id)); |
| 8297 | goto exit_ddb_del; |
| 8298 | } |
| 8299 | |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8300 | pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size, |
| 8301 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8302 | if (!pddb) { |
| 8303 | rc = -ENOMEM; |
| 8304 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8305 | "%s: Unable to allocate dma buffer\n", |
| 8306 | __func__)); |
| 8307 | goto exit_ddb_del; |
| 8308 | } |
| 8309 | |
| 8310 | if (is_qla40XX(ha)) { |
| 8311 | fw_ddb_entry = pddb; |
| 8312 | memset(fw_ddb_entry, 0, ddb_size); |
| 8313 | ddb_cookie = &fw_ddb_entry->cookie; |
| 8314 | } else { |
| 8315 | ddb_cookie = pddb; |
| 8316 | } |
| 8317 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8318 | /* invalidate the cookie */ |
| 8319 | *ddb_cookie = 0xFFEE; |
| 8320 | qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8321 | ddb_size, FLASH_OPT_RMW_COMMIT); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8322 | |
| 8323 | sysfs_ddb_del: |
| 8324 | target_id = fnode_sess->target_id; |
| 8325 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 8326 | ql4_printk(KERN_INFO, ha, |
| 8327 | "%s: session and conn entries for flashnode %u of host %lu deleted\n", |
| 8328 | __func__, target_id, ha->host_no); |
| 8329 | exit_ddb_del: |
Adheer Chandravanshi | 039acc1 | 2013-04-05 07:06:06 -0400 | [diff] [blame] | 8330 | if (pddb) |
| 8331 | dma_free_coherent(&ha->pdev->dev, ddb_size, pddb, |
| 8332 | fw_ddb_entry_dma); |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8333 | return rc; |
| 8334 | } |
| 8335 | |
| 8336 | /** |
| 8337 | * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs |
| 8338 | * @ha: pointer to adapter structure |
| 8339 | * |
| 8340 | * Export the firmware DDB for all send targets and normal targets to sysfs. |
| 8341 | **/ |
| 8342 | static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha) |
| 8343 | { |
| 8344 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8345 | dma_addr_t fw_ddb_entry_dma; |
| 8346 | uint16_t max_ddbs; |
| 8347 | uint16_t idx = 0; |
| 8348 | int ret = QLA_SUCCESS; |
| 8349 | |
| 8350 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
| 8351 | sizeof(*fw_ddb_entry), |
| 8352 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8353 | if (!fw_ddb_entry) { |
| 8354 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 8355 | "%s: Unable to allocate dma buffer\n", |
| 8356 | __func__)); |
| 8357 | return -ENOMEM; |
| 8358 | } |
| 8359 | |
Adheer Chandravanshi | a957a7d | 2013-04-05 07:06:08 -0400 | [diff] [blame] | 8360 | max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES : |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8361 | MAX_DEV_DB_ENTRIES; |
| 8362 | |
| 8363 | for (idx = 0; idx < max_ddbs; idx++) { |
| 8364 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma, |
| 8365 | idx)) |
| 8366 | continue; |
| 8367 | |
| 8368 | ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0); |
| 8369 | if (ret) { |
| 8370 | ret = -EIO; |
| 8371 | break; |
| 8372 | } |
| 8373 | } |
| 8374 | |
| 8375 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry, |
| 8376 | fw_ddb_entry_dma); |
| 8377 | |
| 8378 | return ret; |
| 8379 | } |
| 8380 | |
| 8381 | static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha) |
| 8382 | { |
| 8383 | iscsi_destroy_all_flashnode(ha->host); |
| 8384 | } |
| 8385 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8386 | /** |
| 8387 | * qla4xxx_build_ddb_list - Build ddb list and setup sessions |
| 8388 | * @ha: pointer to adapter structure |
| 8389 | * @is_reset: Is this init path or reset path |
| 8390 | * |
| 8391 | * Create a list of sendtargets (st) from firmware DDBs, issue send targets |
| 8392 | * using connection open, then create the list of normal targets (nt) |
| 8393 | * from firmware DDBs. Based on the list of nt setup session and connection |
| 8394 | * objects. |
| 8395 | **/ |
| 8396 | void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset) |
| 8397 | { |
| 8398 | uint16_t tmo = 0; |
| 8399 | struct list_head list_st, list_nt; |
| 8400 | struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp; |
| 8401 | unsigned long wtime; |
| 8402 | |
| 8403 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 8404 | set_bit(AF_BUILD_DDB_LIST, &ha->flags); |
| 8405 | ha->is_reset = is_reset; |
| 8406 | return; |
| 8407 | } |
| 8408 | |
| 8409 | INIT_LIST_HEAD(&list_st); |
| 8410 | INIT_LIST_HEAD(&list_nt); |
| 8411 | |
| 8412 | qla4xxx_build_st_list(ha, &list_st); |
| 8413 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8414 | /* Before issuing conn open mbox, ensure all IPs states are configured |
| 8415 | * Note, conn open fails if IPs are not configured |
| 8416 | */ |
| 8417 | qla4xxx_wait_for_ip_configuration(ha); |
| 8418 | |
| 8419 | /* Go thru the STs and fire the sendtargets by issuing conn open mbx */ |
| 8420 | list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) { |
| 8421 | qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx); |
| 8422 | } |
| 8423 | |
| 8424 | /* Wait to ensure all sendtargets are done for min 12 sec wait */ |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 8425 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 8426 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 8427 | ha->def_timeout : LOGIN_TOV); |
| 8428 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8429 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8430 | "Default time to wait for build ddb %d\n", tmo)); |
| 8431 | |
| 8432 | wtime = jiffies + (HZ * tmo); |
| 8433 | do { |
Nilesh Javali | f1f2e60 | 2011-12-16 01:58:57 -0800 | [diff] [blame] | 8434 | if (list_empty(&list_st)) |
| 8435 | break; |
| 8436 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8437 | qla4xxx_remove_failed_ddb(ha, &list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8438 | schedule_timeout_uninterruptible(HZ / 10); |
| 8439 | } while (time_after(wtime, jiffies)); |
| 8440 | |
Manish Rangankar | ad8bd45 | 2013-09-17 07:30:02 -0400 | [diff] [blame] | 8441 | |
| 8442 | qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset); |
| 8443 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8444 | qla4xxx_free_ddb_list(&list_st); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 8445 | qla4xxx_free_ddb_list(&list_nt); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8446 | |
| 8447 | qla4xxx_free_ddb_index(ha); |
| 8448 | } |
| 8449 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8450 | /** |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 8451 | * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login |
| 8452 | * response. |
| 8453 | * @ha: pointer to adapter structure |
| 8454 | * |
| 8455 | * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be |
| 8456 | * set in DDB and we will wait for login response of boot targets during |
| 8457 | * probe. |
| 8458 | **/ |
| 8459 | static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha) |
| 8460 | { |
| 8461 | struct ddb_entry *ddb_entry; |
| 8462 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 8463 | dma_addr_t fw_ddb_entry_dma; |
| 8464 | unsigned long wtime; |
| 8465 | uint32_t ddb_state; |
| 8466 | int max_ddbs, idx, ret; |
| 8467 | |
| 8468 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 8469 | MAX_DEV_DB_ENTRIES; |
| 8470 | |
| 8471 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8472 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 8473 | if (!fw_ddb_entry) { |
| 8474 | ql4_printk(KERN_ERR, ha, |
| 8475 | "%s: Unable to allocate dma buffer\n", __func__); |
| 8476 | goto exit_login_resp; |
| 8477 | } |
| 8478 | |
| 8479 | wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV); |
| 8480 | |
| 8481 | for (idx = 0; idx < max_ddbs; idx++) { |
| 8482 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 8483 | if (ddb_entry == NULL) |
| 8484 | continue; |
| 8485 | |
| 8486 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 8487 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8488 | "%s: DDB index [%d]\n", __func__, |
| 8489 | ddb_entry->fw_ddb_index)); |
| 8490 | do { |
| 8491 | ret = qla4xxx_get_fwddb_entry(ha, |
| 8492 | ddb_entry->fw_ddb_index, |
| 8493 | fw_ddb_entry, fw_ddb_entry_dma, |
| 8494 | NULL, NULL, &ddb_state, NULL, |
| 8495 | NULL, NULL); |
| 8496 | if (ret == QLA_ERROR) |
| 8497 | goto exit_login_resp; |
| 8498 | |
| 8499 | if ((ddb_state == DDB_DS_SESSION_ACTIVE) || |
| 8500 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 8501 | break; |
| 8502 | |
| 8503 | schedule_timeout_uninterruptible(HZ); |
| 8504 | |
| 8505 | } while ((time_after(wtime, jiffies))); |
| 8506 | |
| 8507 | if (!time_after(wtime, jiffies)) { |
| 8508 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 8509 | "%s: Login response wait timer expired\n", |
| 8510 | __func__)); |
| 8511 | goto exit_login_resp; |
| 8512 | } |
| 8513 | } |
| 8514 | } |
| 8515 | |
| 8516 | exit_login_resp: |
| 8517 | if (fw_ddb_entry) |
| 8518 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 8519 | fw_ddb_entry, fw_ddb_entry_dma); |
| 8520 | } |
| 8521 | |
| 8522 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8523 | * qla4xxx_probe_adapter - callback function to probe HBA |
| 8524 | * @pdev: pointer to pci_dev structure |
| 8525 | * @pci_device_id: pointer to pci_device entry |
| 8526 | * |
| 8527 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. |
| 8528 | * It returns zero if successful. It also initializes all data necessary for |
| 8529 | * the driver. |
| 8530 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8531 | static int qla4xxx_probe_adapter(struct pci_dev *pdev, |
| 8532 | const struct pci_device_id *ent) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8533 | { |
| 8534 | int ret = -ENODEV, status; |
| 8535 | struct Scsi_Host *host; |
| 8536 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8537 | uint8_t init_retry_count = 0; |
| 8538 | char buf[34]; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8539 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8540 | uint32_t dev_state; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8541 | |
| 8542 | if (pci_enable_device(pdev)) |
| 8543 | return -1; |
| 8544 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8545 | host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8546 | if (host == NULL) { |
| 8547 | printk(KERN_WARNING |
| 8548 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); |
| 8549 | goto probe_disable_device; |
| 8550 | } |
| 8551 | |
| 8552 | /* Clear our data area */ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8553 | ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8554 | memset(ha, 0, sizeof(*ha)); |
| 8555 | |
| 8556 | /* Save the information from PCI BIOS. */ |
| 8557 | ha->pdev = pdev; |
| 8558 | ha->host = host; |
| 8559 | ha->host_no = host->host_no; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8560 | ha->func_num = PCI_FUNC(ha->pdev->devfn); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8561 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8562 | pci_enable_pcie_error_reporting(pdev); |
| 8563 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8564 | /* Setup Runtime configurable options */ |
| 8565 | if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 8566 | ha->isp_ops = &qla4_82xx_isp_ops; |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8567 | ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8568 | ha->qdr_sn_window = -1; |
| 8569 | ha->ddr_mn_window = -1; |
| 8570 | ha->curr_window = 255; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8571 | nx_legacy_intr = &legacy_intr[ha->func_num]; |
| 8572 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; |
| 8573 | ha->nx_legacy_intr.tgt_status_reg = |
| 8574 | nx_legacy_intr->tgt_status_reg; |
| 8575 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; |
| 8576 | 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] | 8577 | } else if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8578 | ha->isp_ops = &qla4_83xx_isp_ops; |
| 8579 | ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8580 | } else { |
| 8581 | ha->isp_ops = &qla4xxx_isp_ops; |
| 8582 | } |
| 8583 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8584 | if (is_qla80XX(ha)) { |
| 8585 | rwlock_init(&ha->hw_lock); |
| 8586 | ha->pf_bit = ha->func_num << 16; |
| 8587 | /* Set EEH reset type to fundamental if required by hba */ |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8588 | pdev->needs_freset = 1; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8589 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8590 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8591 | /* Configure PCI I/O space. */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8592 | ret = ha->isp_ops->iospace_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8593 | if (ret) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8594 | goto probe_failed_ioconfig; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8595 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8596 | 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] | 8597 | pdev->device, pdev->irq, ha->reg); |
| 8598 | |
| 8599 | qla4xxx_config_dma_addressing(ha); |
| 8600 | |
| 8601 | /* Initialize lists and spinlocks. */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8602 | INIT_LIST_HEAD(&ha->free_srb_q); |
| 8603 | |
| 8604 | mutex_init(&ha->mbox_sem); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 8605 | mutex_init(&ha->chap_sem); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8606 | init_completion(&ha->mbx_intr_comp); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 8607 | init_completion(&ha->disable_acb_comp); |
Vikas Chaudhary | df86f77 | 2013-11-22 05:28:17 -0500 | [diff] [blame] | 8608 | init_completion(&ha->idc_comp); |
| 8609 | init_completion(&ha->link_up_comp); |
| 8610 | init_completion(&ha->disable_acb_comp); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8611 | |
| 8612 | spin_lock_init(&ha->hardware_lock); |
Vikas Chaudhary | 8e9157c | 2012-08-22 07:45:24 -0400 | [diff] [blame] | 8613 | spin_lock_init(&ha->work_lock); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8614 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 8615 | /* Initialize work list */ |
| 8616 | INIT_LIST_HEAD(&ha->work_list); |
| 8617 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8618 | /* Allocate dma buffers */ |
| 8619 | if (qla4xxx_mem_alloc(ha)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8620 | ql4_printk(KERN_WARNING, ha, |
| 8621 | "[ERROR] Failed to allocate memory for adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8622 | |
| 8623 | ret = -ENOMEM; |
| 8624 | goto probe_failed; |
| 8625 | } |
| 8626 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8627 | host->cmd_per_lun = 3; |
| 8628 | host->max_channel = 0; |
| 8629 | host->max_lun = MAX_LUNS - 1; |
| 8630 | host->max_id = MAX_TARGETS; |
| 8631 | host->max_cmd_len = IOCB_MAX_CDB_LEN; |
| 8632 | host->can_queue = MAX_SRBS ; |
| 8633 | host->transportt = qla4xxx_scsi_transport; |
| 8634 | |
| 8635 | ret = scsi_init_shared_tag_map(host, MAX_SRBS); |
| 8636 | if (ret) { |
| 8637 | ql4_printk(KERN_WARNING, ha, |
| 8638 | "%s: scsi_init_shared_tag_map failed\n", __func__); |
| 8639 | goto probe_failed; |
| 8640 | } |
| 8641 | |
| 8642 | pci_set_drvdata(pdev, ha); |
| 8643 | |
| 8644 | ret = scsi_add_host(host, &pdev->dev); |
| 8645 | if (ret) |
| 8646 | goto probe_failed; |
| 8647 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8648 | if (is_qla80XX(ha)) |
| 8649 | qla4_8xxx_get_flash_info(ha); |
| 8650 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8651 | if (is_qla8032(ha) || is_qla8042(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8652 | qla4_83xx_read_reset_template(ha); |
| 8653 | /* |
| 8654 | * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 8655 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 8656 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 8657 | * should honor the reset. |
| 8658 | */ |
| 8659 | if (ql4xdontresethba == 1) |
| 8660 | qla4_83xx_set_idc_dontreset(ha); |
| 8661 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8662 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8663 | /* |
| 8664 | * Initialize the Host adapter request/response queues and |
| 8665 | * firmware |
| 8666 | * NOTE: interrupts enabled upon successful completion |
| 8667 | */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8668 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8669 | |
| 8670 | /* Dont retry adapter initialization if IRQ allocation failed */ |
Nilesh Javali | 17801c9 | 2013-03-22 07:22:42 -0400 | [diff] [blame] | 8671 | if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) { |
| 8672 | ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n", |
| 8673 | __func__); |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8674 | goto skip_retry_init; |
Nilesh Javali | 17801c9 | 2013-03-22 07:22:42 -0400 | [diff] [blame] | 8675 | } |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8676 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8677 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
| 8678 | init_retry_count++ < MAX_INIT_RETRIES) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8679 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8680 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8681 | ha->isp_ops->idc_lock(ha); |
| 8682 | dev_state = qla4_8xxx_rd_direct(ha, |
Vikas Chaudhary | e951aca | 2012-12-29 02:24:52 -0500 | [diff] [blame] | 8683 | QLA8XXX_CRB_DEV_STATE); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8684 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 8685 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 8686 | ql4_printk(KERN_WARNING, ha, "%s: don't retry " |
| 8687 | "initialize adapter. H/W is in failed state\n", |
| 8688 | __func__); |
| 8689 | break; |
| 8690 | } |
| 8691 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8692 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
| 8693 | "(%d)\n", __func__, init_retry_count)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8694 | |
| 8695 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) |
| 8696 | continue; |
| 8697 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8698 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8699 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8700 | |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 8701 | skip_retry_init: |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8702 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8703 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8704 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8705 | if ((is_qla8022(ha) && ql4xdontresethba) || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 8706 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 8707 | qla4_83xx_idc_dontreset(ha))) { |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 8708 | /* Put the device in failed state. */ |
| 8709 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 8710 | ha->isp_ops->idc_lock(ha); |
| 8711 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 8712 | QLA8XXX_DEV_FAILED); |
| 8713 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 8714 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8715 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8716 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8717 | } |
| 8718 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8719 | /* Startup the kernel thread for this host adapter. */ |
| 8720 | DEBUG2(printk("scsi: %s: Starting kernel thread for " |
| 8721 | "qla4xxx_dpc\n", __func__)); |
| 8722 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); |
| 8723 | ha->dpc_thread = create_singlethread_workqueue(buf); |
| 8724 | if (!ha->dpc_thread) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 8725 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8726 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8727 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8728 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 8729 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8730 | |
Kees Cook | d853754 | 2013-07-03 15:04:57 -0700 | [diff] [blame] | 8731 | ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1, |
| 8732 | ha->host_no); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8733 | if (!ha->task_wq) { |
| 8734 | ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n"); |
| 8735 | ret = -ENODEV; |
| 8736 | goto remove_host; |
| 8737 | } |
| 8738 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8739 | /* |
| 8740 | * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8741 | * (which is called indirectly by qla4xxx_initialize_adapter), |
| 8742 | * so that irqs will be registered after crbinit but before |
| 8743 | * mbx_intr_enable. |
| 8744 | */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 8745 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8746 | ret = qla4xxx_request_irqs(ha); |
| 8747 | if (ret) { |
| 8748 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " |
| 8749 | "interrupt %d already in use.\n", pdev->irq); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8750 | goto remove_host; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8751 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8752 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8753 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8754 | pci_save_state(ha->pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8755 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8756 | |
| 8757 | /* Start timer thread. */ |
| 8758 | qla4xxx_start_timer(ha, qla4xxx_timer, 1); |
| 8759 | |
| 8760 | set_bit(AF_INIT_DONE, &ha->flags); |
| 8761 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 8762 | qla4_8xxx_alloc_sysfs_attr(ha); |
| 8763 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8764 | printk(KERN_INFO |
| 8765 | " QLogic iSCSI HBA Driver version: %s\n" |
| 8766 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", |
| 8767 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), |
Adheer Chandravanshi | eee06a0 | 2013-07-08 08:33:10 -0400 | [diff] [blame] | 8768 | ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor, |
| 8769 | ha->fw_info.fw_patch, ha->fw_info.fw_build); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8770 | |
Manish Dusane | cfb2787 | 2012-09-20 07:35:01 -0400 | [diff] [blame] | 8771 | /* Set the driver version */ |
| 8772 | if (is_qla80XX(ha)) |
| 8773 | qla4_8xxx_set_param(ha, SET_DRVR_VERSION); |
| 8774 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8775 | if (qla4xxx_setup_boot_info(ha)) |
Vikas Chaudhary | 3573bfb | 2012-02-27 03:08:57 -0800 | [diff] [blame] | 8776 | ql4_printk(KERN_ERR, ha, |
| 8777 | "%s: No iSCSI boot target configured\n", __func__); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8778 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8779 | if (qla4xxx_sysfs_ddb_export(ha)) |
| 8780 | ql4_printk(KERN_ERR, ha, |
| 8781 | "%s: Error exporting ddb to sysfs\n", __func__); |
| 8782 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8783 | /* Perform the build ddb list and login to each */ |
| 8784 | qla4xxx_build_ddb_list(ha, INIT_ADAPTER); |
| 8785 | iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 8786 | qla4xxx_wait_login_resp_boot_tgt(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8787 | |
| 8788 | qla4xxx_create_chap_list(ha); |
| 8789 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8790 | qla4xxx_create_ifaces(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8791 | return 0; |
| 8792 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8793 | remove_host: |
| 8794 | scsi_remove_host(ha->host); |
| 8795 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8796 | probe_failed: |
| 8797 | qla4xxx_free_adapter(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8798 | |
| 8799 | probe_failed_ioconfig: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8800 | pci_disable_pcie_error_reporting(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8801 | scsi_host_put(ha->host); |
| 8802 | |
| 8803 | probe_disable_device: |
| 8804 | pci_disable_device(pdev); |
| 8805 | |
| 8806 | return ret; |
| 8807 | } |
| 8808 | |
| 8809 | /** |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8810 | * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize |
| 8811 | * @ha: pointer to adapter structure |
| 8812 | * |
| 8813 | * Mark the other ISP-4xxx port to indicate that the driver is being removed, |
| 8814 | * so that the other port will not re-initialize while in the process of |
| 8815 | * removing the ha due to driver unload or hba hotplug. |
| 8816 | **/ |
| 8817 | static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha) |
| 8818 | { |
| 8819 | struct scsi_qla_host *other_ha = NULL; |
| 8820 | struct pci_dev *other_pdev = NULL; |
| 8821 | int fn = ISP4XXX_PCI_FN_2; |
| 8822 | |
| 8823 | /*iscsi function numbers for ISP4xxx is 1 and 3*/ |
| 8824 | if (PCI_FUNC(ha->pdev->devfn) & BIT_1) |
| 8825 | fn = ISP4XXX_PCI_FN_1; |
| 8826 | |
| 8827 | other_pdev = |
| 8828 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 8829 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 8830 | fn)); |
| 8831 | |
| 8832 | /* Get other_ha if other_pdev is valid and state is enable*/ |
| 8833 | if (other_pdev) { |
| 8834 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 8835 | other_ha = pci_get_drvdata(other_pdev); |
| 8836 | if (other_ha) { |
| 8837 | set_bit(AF_HA_REMOVAL, &other_ha->flags); |
| 8838 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " |
| 8839 | "Prevent %s reinit\n", __func__, |
| 8840 | dev_name(&other_ha->pdev->dev))); |
| 8841 | } |
| 8842 | } |
| 8843 | pci_dev_put(other_pdev); |
| 8844 | } |
| 8845 | } |
| 8846 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8847 | static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha) |
| 8848 | { |
| 8849 | struct ddb_entry *ddb_entry; |
| 8850 | int options; |
| 8851 | int idx; |
| 8852 | |
| 8853 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 8854 | |
| 8855 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 8856 | if ((ddb_entry != NULL) && |
| 8857 | (ddb_entry->ddb_type == FLASH_DDB)) { |
| 8858 | |
| 8859 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 8860 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) |
| 8861 | == QLA_ERROR) |
| 8862 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", |
| 8863 | __func__); |
| 8864 | |
| 8865 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 8866 | /* |
| 8867 | * we have decremented the reference count of the driver |
| 8868 | * when we setup the session to have the driver unload |
| 8869 | * to be seamless without actually destroying the |
| 8870 | * session |
| 8871 | **/ |
| 8872 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 8873 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 8874 | qla4xxx_free_ddb(ha, ddb_entry); |
| 8875 | iscsi_session_teardown(ddb_entry->sess); |
| 8876 | } |
| 8877 | } |
| 8878 | } |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8879 | /** |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 8880 | * qla4xxx_remove_adapter - callback function to remove adapter. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8881 | * @pci_dev: PCI device pointer |
| 8882 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8883 | static void qla4xxx_remove_adapter(struct pci_dev *pdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8884 | { |
| 8885 | struct scsi_qla_host *ha; |
| 8886 | |
Vikas Chaudhary | f8b0751 | 2012-09-20 07:35:08 -0400 | [diff] [blame] | 8887 | /* |
| 8888 | * If the PCI device is disabled then it means probe_adapter had |
| 8889 | * failed and resources already cleaned up on probe_adapter exit. |
| 8890 | */ |
| 8891 | if (!pci_is_enabled(pdev)) |
| 8892 | return; |
| 8893 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8894 | ha = pci_get_drvdata(pdev); |
| 8895 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 8896 | if (is_qla40XX(ha)) |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 8897 | qla4xxx_prevent_other_port_reinit(ha); |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 8898 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 8899 | /* destroy iface from sysfs */ |
| 8900 | qla4xxx_destroy_ifaces(ha); |
| 8901 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8902 | if ((!ql4xdisablesysfsboot) && ha->boot_kset) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 8903 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 8904 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8905 | qla4xxx_destroy_fw_ddb_session(ha); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 8906 | qla4_8xxx_free_sysfs_attr(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 8907 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 8908 | qla4xxx_sysfs_ddb_remove(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8909 | scsi_remove_host(ha->host); |
| 8910 | |
| 8911 | qla4xxx_free_adapter(ha); |
| 8912 | |
| 8913 | scsi_host_put(ha->host); |
| 8914 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8915 | pci_disable_pcie_error_reporting(pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8916 | pci_disable_device(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8917 | } |
| 8918 | |
| 8919 | /** |
| 8920 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. |
| 8921 | * @ha: HA context |
| 8922 | * |
| 8923 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 8924 | * supported addressing method. |
| 8925 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 8926 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8927 | { |
| 8928 | int retval; |
| 8929 | |
| 8930 | /* Update our PCI device dma_mask for full 64 bit mask */ |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 8931 | if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) { |
| 8932 | if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8933 | dev_dbg(&ha->pdev->dev, |
| 8934 | "Failed to set 64 bit PCI consistent mask; " |
| 8935 | "using 32 bit.\n"); |
| 8936 | retval = pci_set_consistent_dma_mask(ha->pdev, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 8937 | DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8938 | } |
| 8939 | } else |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 8940 | retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8941 | } |
| 8942 | |
| 8943 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) |
| 8944 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8945 | struct iscsi_cls_session *cls_sess; |
| 8946 | struct iscsi_session *sess; |
| 8947 | struct ddb_entry *ddb; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 8948 | int queue_depth = QL4_DEF_QDEPTH; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8949 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 8950 | cls_sess = starget_to_session(sdev->sdev_target); |
| 8951 | sess = cls_sess->dd_data; |
| 8952 | ddb = sess->dd_data; |
| 8953 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8954 | sdev->hostdata = ddb; |
| 8955 | sdev->tagged_supported = 1; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 8956 | |
| 8957 | if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) |
| 8958 | queue_depth = ql4xmaxqdepth; |
| 8959 | |
| 8960 | scsi_activate_tcq(sdev, queue_depth); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8961 | return 0; |
| 8962 | } |
| 8963 | |
| 8964 | static int qla4xxx_slave_configure(struct scsi_device *sdev) |
| 8965 | { |
| 8966 | sdev->tagged_supported = 1; |
| 8967 | return 0; |
| 8968 | } |
| 8969 | |
| 8970 | static void qla4xxx_slave_destroy(struct scsi_device *sdev) |
| 8971 | { |
| 8972 | scsi_deactivate_tcq(sdev, 1); |
| 8973 | } |
| 8974 | |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 8975 | static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, |
| 8976 | int reason) |
| 8977 | { |
| 8978 | if (!ql4xqfulltracking) |
| 8979 | return -EOPNOTSUPP; |
| 8980 | |
| 8981 | return iscsi_change_queue_depth(sdev, qdepth, reason); |
| 8982 | } |
| 8983 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8984 | /** |
| 8985 | * qla4xxx_del_from_active_array - returns an active srb |
| 8986 | * @ha: Pointer to host adapter structure. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 8987 | * @index: index into the active_array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8988 | * |
| 8989 | * This routine removes and returns the srb at the specified index |
| 8990 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8991 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
| 8992 | uint32_t index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8993 | { |
| 8994 | struct srb *srb = NULL; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 8995 | struct scsi_cmnd *cmd = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8996 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 8997 | cmd = scsi_host_find_tag(ha->host, index); |
| 8998 | if (!cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8999 | return srb; |
| 9000 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9001 | srb = (struct srb *)CMD_SP(cmd); |
| 9002 | if (!srb) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9003 | return srb; |
| 9004 | |
| 9005 | /* update counters */ |
| 9006 | if (srb->flags & SRB_DMA_VALID) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9007 | ha->iocb_cnt -= srb->iocb_cnt; |
| 9008 | if (srb->cmd) |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9009 | srb->cmd->host_scribble = |
| 9010 | (unsigned char *)(unsigned long) MAX_SRBS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9011 | } |
| 9012 | return srb; |
| 9013 | } |
| 9014 | |
| 9015 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9016 | * 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] | 9017 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9018 | * @cmd: Scsi Command to wait on. |
| 9019 | * |
| 9020 | * This routine waits for the command to be returned by the Firmware |
| 9021 | * for some max time. |
| 9022 | **/ |
| 9023 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, |
| 9024 | struct scsi_cmnd *cmd) |
| 9025 | { |
| 9026 | int done = 0; |
| 9027 | struct srb *rp; |
| 9028 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9029 | int ret = SUCCESS; |
| 9030 | |
| 9031 | /* Dont wait on command if PCI error is being handled |
| 9032 | * by PCI AER driver |
| 9033 | */ |
| 9034 | if (unlikely(pci_channel_offline(ha->pdev)) || |
| 9035 | (test_bit(AF_EEH_BUSY, &ha->flags))) { |
| 9036 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", |
| 9037 | ha->host_no, __func__); |
| 9038 | return ret; |
| 9039 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9040 | |
| 9041 | do { |
| 9042 | /* Checking to see if its returned to OS */ |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 9043 | rp = (struct srb *) CMD_SP(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9044 | if (rp == NULL) { |
| 9045 | done++; |
| 9046 | break; |
| 9047 | } |
| 9048 | |
| 9049 | msleep(2000); |
| 9050 | } while (max_wait_time--); |
| 9051 | |
| 9052 | return done; |
| 9053 | } |
| 9054 | |
| 9055 | /** |
| 9056 | * qla4xxx_wait_for_hba_online - waits for HBA to come online |
| 9057 | * @ha: Pointer to host adapter structure |
| 9058 | **/ |
| 9059 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) |
| 9060 | { |
| 9061 | unsigned long wait_online; |
| 9062 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 9063 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9064 | while (time_before(jiffies, wait_online)) { |
| 9065 | |
| 9066 | if (adapter_up(ha)) |
| 9067 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9068 | |
| 9069 | msleep(2000); |
| 9070 | } |
| 9071 | |
| 9072 | return QLA_ERROR; |
| 9073 | } |
| 9074 | |
| 9075 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9076 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 9077 | * @ha: pointer to HBA |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9078 | * @t: target id |
| 9079 | * @l: lun id |
| 9080 | * |
| 9081 | * This function waits for all outstanding commands to a lun to complete. It |
| 9082 | * returns 0 if all pending commands are returned and 1 otherwise. |
| 9083 | **/ |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9084 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
| 9085 | struct scsi_target *stgt, |
| 9086 | struct scsi_device *sdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9087 | { |
| 9088 | int cnt; |
| 9089 | int status = 0; |
| 9090 | struct scsi_cmnd *cmd; |
| 9091 | |
| 9092 | /* |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9093 | * Waiting for all commands for the designated target or dev |
| 9094 | * in the active array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9095 | */ |
| 9096 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { |
| 9097 | cmd = scsi_host_find_tag(ha->host, cnt); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9098 | if (cmd && stgt == scsi_target(cmd->device) && |
| 9099 | (!sdev || sdev == cmd->device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9100 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 9101 | status++; |
| 9102 | break; |
| 9103 | } |
| 9104 | } |
| 9105 | } |
| 9106 | return status; |
| 9107 | } |
| 9108 | |
| 9109 | /** |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9110 | * qla4xxx_eh_abort - callback for abort task. |
| 9111 | * @cmd: Pointer to Linux's SCSI command structure |
| 9112 | * |
| 9113 | * This routine is called by the Linux OS to abort the specified |
| 9114 | * command. |
| 9115 | **/ |
| 9116 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) |
| 9117 | { |
| 9118 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9119 | unsigned int id = cmd->device->id; |
| 9120 | unsigned int lun = cmd->device->lun; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9121 | unsigned long flags; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9122 | struct srb *srb = NULL; |
| 9123 | int ret = SUCCESS; |
| 9124 | int wait = 0; |
| 9125 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9126 | ql4_printk(KERN_INFO, ha, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 9127 | "scsi%ld:%d:%d: Abort command issued cmd=%p\n", |
| 9128 | ha->host_no, id, lun, cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9129 | |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9130 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9131 | srb = (struct srb *) CMD_SP(cmd); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9132 | if (!srb) { |
| 9133 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9134 | return SUCCESS; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9135 | } |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9136 | kref_get(&srb->srb_ref); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 9137 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9138 | |
| 9139 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { |
| 9140 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", |
| 9141 | ha->host_no, id, lun)); |
| 9142 | ret = FAILED; |
| 9143 | } else { |
| 9144 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n", |
| 9145 | ha->host_no, id, lun)); |
| 9146 | wait = 1; |
| 9147 | } |
| 9148 | |
| 9149 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| 9150 | |
| 9151 | /* Wait for command to complete */ |
| 9152 | if (wait) { |
| 9153 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 9154 | DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n", |
| 9155 | ha->host_no, id, lun)); |
| 9156 | ret = FAILED; |
| 9157 | } |
| 9158 | } |
| 9159 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9160 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9161 | "scsi%ld:%d:%d: Abort command - %s\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9162 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed"); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 9163 | |
| 9164 | return ret; |
| 9165 | } |
| 9166 | |
| 9167 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9168 | * qla4xxx_eh_device_reset - callback for target reset. |
| 9169 | * @cmd: Pointer to Linux's SCSI command structure |
| 9170 | * |
| 9171 | * This routine is called by the Linux OS to reset all luns on the |
| 9172 | * specified target. |
| 9173 | **/ |
| 9174 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 9175 | { |
| 9176 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9177 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9178 | int ret = FAILED, stat; |
| 9179 | |
Karen Higgins | 612f734 | 2009-07-15 15:03:01 -0500 | [diff] [blame] | 9180 | if (!ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9181 | return ret; |
| 9182 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9183 | ret = iscsi_block_scsi_eh(cmd); |
| 9184 | if (ret) |
| 9185 | return ret; |
| 9186 | ret = FAILED; |
| 9187 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9188 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9189 | "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no, |
| 9190 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 9191 | |
| 9192 | DEBUG2(printk(KERN_INFO |
| 9193 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," |
| 9194 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 9195 | cmd, jiffies, cmd->request->timeout / HZ, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9196 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 9197 | |
| 9198 | /* FIXME: wait for hba to go online */ |
| 9199 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); |
| 9200 | if (stat != QLA_SUCCESS) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9201 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9202 | goto eh_dev_reset_done; |
| 9203 | } |
| 9204 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9205 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 9206 | cmd->device)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9207 | ql4_printk(KERN_INFO, ha, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9208 | "DEVICE RESET FAILED - waiting for " |
| 9209 | "commands.\n"); |
| 9210 | goto eh_dev_reset_done; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9211 | } |
| 9212 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 9213 | /* Send marker. */ |
| 9214 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 9215 | MM_LUN_RESET) != QLA_SUCCESS) |
| 9216 | goto eh_dev_reset_done; |
| 9217 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9218 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9219 | "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n", |
| 9220 | ha->host_no, cmd->device->channel, cmd->device->id, |
| 9221 | cmd->device->lun); |
| 9222 | |
| 9223 | ret = SUCCESS; |
| 9224 | |
| 9225 | eh_dev_reset_done: |
| 9226 | |
| 9227 | return ret; |
| 9228 | } |
| 9229 | |
| 9230 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9231 | * qla4xxx_eh_target_reset - callback for target reset. |
| 9232 | * @cmd: Pointer to Linux's SCSI command structure |
| 9233 | * |
| 9234 | * This routine is called by the Linux OS to reset the target. |
| 9235 | **/ |
| 9236 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) |
| 9237 | { |
| 9238 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 9239 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9240 | int stat, ret; |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9241 | |
| 9242 | if (!ddb_entry) |
| 9243 | return FAILED; |
| 9244 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 9245 | ret = iscsi_block_scsi_eh(cmd); |
| 9246 | if (ret) |
| 9247 | return ret; |
| 9248 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9249 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9250 | "WARM TARGET RESET ISSUED.\n"); |
| 9251 | |
| 9252 | DEBUG2(printk(KERN_INFO |
| 9253 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " |
| 9254 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 9255 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9256 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 9257 | |
| 9258 | stat = qla4xxx_reset_target(ha, ddb_entry); |
| 9259 | if (stat != QLA_SUCCESS) { |
| 9260 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9261 | "WARM TARGET RESET FAILED.\n"); |
| 9262 | return FAILED; |
| 9263 | } |
| 9264 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9265 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 9266 | NULL)) { |
| 9267 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9268 | "WARM TARGET DEVICE RESET FAILED - " |
| 9269 | "waiting for commands.\n"); |
| 9270 | return FAILED; |
| 9271 | } |
| 9272 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 9273 | /* Send marker. */ |
| 9274 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 9275 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { |
| 9276 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9277 | "WARM TARGET DEVICE RESET FAILED - " |
| 9278 | "marker iocb failed.\n"); |
| 9279 | return FAILED; |
| 9280 | } |
| 9281 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 9282 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 9283 | "WARM TARGET RESET SUCCEEDED.\n"); |
| 9284 | return SUCCESS; |
| 9285 | } |
| 9286 | |
| 9287 | /** |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 9288 | * qla4xxx_is_eh_active - check if error handler is running |
| 9289 | * @shost: Pointer to SCSI Host struct |
| 9290 | * |
| 9291 | * This routine finds that if reset host is called in EH |
| 9292 | * scenario or from some application like sg_reset |
| 9293 | **/ |
| 9294 | static int qla4xxx_is_eh_active(struct Scsi_Host *shost) |
| 9295 | { |
| 9296 | if (shost->shost_state == SHOST_RECOVERY) |
| 9297 | return 1; |
| 9298 | return 0; |
| 9299 | } |
| 9300 | |
| 9301 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9302 | * qla4xxx_eh_host_reset - kernel callback |
| 9303 | * @cmd: Pointer to Linux's SCSI command structure |
| 9304 | * |
| 9305 | * This routine is invoked by the Linux kernel to perform fatal error |
| 9306 | * recovery on the specified adapter. |
| 9307 | **/ |
| 9308 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 9309 | { |
| 9310 | int return_status = FAILED; |
| 9311 | struct scsi_qla_host *ha; |
| 9312 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9313 | ha = to_qla_host(cmd->device->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9314 | |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9315 | if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba) |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9316 | qla4_83xx_set_idc_dontreset(ha); |
| 9317 | |
| 9318 | /* |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9319 | * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other |
| 9320 | * protocol drivers, we should not set device_state to NEED_RESET |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9321 | */ |
| 9322 | if (ql4xdontresethba || |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9323 | ((is_qla8032(ha) || is_qla8042(ha)) && |
| 9324 | qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9325 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 9326 | ha->host_no, __func__)); |
Sarang Radke | 8a2889601 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 9327 | |
| 9328 | /* Clear outstanding srb in queues */ |
| 9329 | if (qla4xxx_is_eh_active(cmd->device->host)) |
| 9330 | qla4xxx_abort_active_cmds(ha, DID_ABORT << 16); |
| 9331 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9332 | return FAILED; |
| 9333 | } |
| 9334 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9335 | ql4_printk(KERN_INFO, ha, |
Karen Higgins | dca05c4 | 2009-07-15 15:03:00 -0500 | [diff] [blame] | 9336 | "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9337 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 9338 | |
| 9339 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 9340 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " |
| 9341 | "DEAD.\n", ha->host_no, cmd->device->channel, |
| 9342 | __func__)); |
| 9343 | |
| 9344 | return FAILED; |
| 9345 | } |
| 9346 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9347 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9348 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9349 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 9350 | else |
| 9351 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 9352 | } |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 9353 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9354 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9355 | return_status = SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9356 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 9357 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9358 | return_status == FAILED ? "FAILED" : "SUCCEEDED"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9359 | |
| 9360 | return return_status; |
| 9361 | } |
| 9362 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9363 | static int qla4xxx_context_reset(struct scsi_qla_host *ha) |
| 9364 | { |
| 9365 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 9366 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 9367 | struct addr_ctrl_blk_def *acb = NULL; |
| 9368 | uint32_t acb_len = sizeof(struct addr_ctrl_blk_def); |
| 9369 | int rval = QLA_SUCCESS; |
| 9370 | dma_addr_t acb_dma; |
| 9371 | |
| 9372 | acb = dma_alloc_coherent(&ha->pdev->dev, |
| 9373 | sizeof(struct addr_ctrl_blk_def), |
| 9374 | &acb_dma, GFP_KERNEL); |
| 9375 | if (!acb) { |
| 9376 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n", |
| 9377 | __func__); |
| 9378 | rval = -ENOMEM; |
| 9379 | goto exit_port_reset; |
| 9380 | } |
| 9381 | |
| 9382 | memset(acb, 0, acb_len); |
| 9383 | |
| 9384 | rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len); |
| 9385 | if (rval != QLA_SUCCESS) { |
| 9386 | rval = -EIO; |
| 9387 | goto exit_free_acb; |
| 9388 | } |
| 9389 | |
| 9390 | rval = qla4xxx_disable_acb(ha); |
| 9391 | if (rval != QLA_SUCCESS) { |
| 9392 | rval = -EIO; |
| 9393 | goto exit_free_acb; |
| 9394 | } |
| 9395 | |
| 9396 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 9397 | DISABLE_ACB_TOV * HZ); |
| 9398 | |
| 9399 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma); |
| 9400 | if (rval != QLA_SUCCESS) { |
| 9401 | rval = -EIO; |
| 9402 | goto exit_free_acb; |
| 9403 | } |
| 9404 | |
| 9405 | exit_free_acb: |
| 9406 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def), |
| 9407 | acb, acb_dma); |
| 9408 | exit_port_reset: |
| 9409 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__, |
| 9410 | rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED")); |
| 9411 | return rval; |
| 9412 | } |
| 9413 | |
| 9414 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type) |
| 9415 | { |
| 9416 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 9417 | int rval = QLA_SUCCESS; |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9418 | uint32_t idc_ctrl; |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9419 | |
| 9420 | if (ql4xdontresethba) { |
| 9421 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n", |
| 9422 | __func__)); |
| 9423 | rval = -EPERM; |
| 9424 | goto exit_host_reset; |
| 9425 | } |
| 9426 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9427 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 9428 | goto recover_adapter; |
| 9429 | |
| 9430 | switch (reset_type) { |
| 9431 | case SCSI_ADAPTER_RESET: |
| 9432 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 9433 | break; |
| 9434 | case SCSI_FIRMWARE_RESET: |
| 9435 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9436 | if (is_qla80XX(ha)) |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9437 | /* set firmware context reset */ |
| 9438 | set_bit(DPC_RESET_HA_FW_CONTEXT, |
| 9439 | &ha->dpc_flags); |
| 9440 | else { |
| 9441 | rval = qla4xxx_context_reset(ha); |
| 9442 | goto exit_host_reset; |
| 9443 | } |
| 9444 | } |
| 9445 | break; |
| 9446 | } |
| 9447 | |
| 9448 | recover_adapter: |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9449 | /* 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] | 9450 | * reset is issued by application */ |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9451 | if ((is_qla8032(ha) || is_qla8042(ha)) && |
| 9452 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 9453 | idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL); |
| 9454 | qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL, |
| 9455 | (idc_ctrl | GRACEFUL_RESET_BIT1)); |
| 9456 | } |
| 9457 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 9458 | rval = qla4xxx_recover_adapter(ha); |
| 9459 | if (rval != QLA_SUCCESS) { |
| 9460 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n", |
| 9461 | __func__)); |
| 9462 | rval = -EIO; |
| 9463 | } |
| 9464 | |
| 9465 | exit_host_reset: |
| 9466 | return rval; |
| 9467 | } |
| 9468 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9469 | /* PCI AER driver recovers from all correctable errors w/o |
| 9470 | * driver intervention. For uncorrectable errors PCI AER |
| 9471 | * driver calls the following device driver's callbacks |
| 9472 | * |
| 9473 | * - Fatal Errors - link_reset |
| 9474 | * - Non-Fatal Errors - driver's pci_error_detected() which |
| 9475 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. |
| 9476 | * |
| 9477 | * PCI AER driver calls |
| 9478 | * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled |
| 9479 | * returns RECOVERED or NEED_RESET if fw_hung |
| 9480 | * NEED_RESET - driver's slot_reset() |
| 9481 | * DISCONNECT - device is dead & cannot recover |
| 9482 | * RECOVERED - driver's pci_resume() |
| 9483 | */ |
| 9484 | static pci_ers_result_t |
| 9485 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 9486 | { |
| 9487 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9488 | |
| 9489 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", |
| 9490 | ha->host_no, __func__, state); |
| 9491 | |
| 9492 | if (!is_aer_supported(ha)) |
| 9493 | return PCI_ERS_RESULT_NONE; |
| 9494 | |
| 9495 | switch (state) { |
| 9496 | case pci_channel_io_normal: |
| 9497 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 9498 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 9499 | case pci_channel_io_frozen: |
| 9500 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 9501 | qla4xxx_mailbox_premature_completion(ha); |
| 9502 | qla4xxx_free_irqs(ha); |
| 9503 | pci_disable_device(pdev); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9504 | /* Return back all IOs */ |
| 9505 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9506 | return PCI_ERS_RESULT_NEED_RESET; |
| 9507 | case pci_channel_io_perm_failure: |
| 9508 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 9509 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); |
| 9510 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 9511 | return PCI_ERS_RESULT_DISCONNECT; |
| 9512 | } |
| 9513 | return PCI_ERS_RESULT_NEED_RESET; |
| 9514 | } |
| 9515 | |
| 9516 | /** |
| 9517 | * qla4xxx_pci_mmio_enabled() gets called if |
| 9518 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER |
| 9519 | * and read/write to the device still works. |
| 9520 | **/ |
| 9521 | static pci_ers_result_t |
| 9522 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 9523 | { |
| 9524 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9525 | |
| 9526 | if (!is_aer_supported(ha)) |
| 9527 | return PCI_ERS_RESULT_NONE; |
| 9528 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9529 | return PCI_ERS_RESULT_RECOVERED; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9530 | } |
| 9531 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9532 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9533 | { |
| 9534 | uint32_t rval = QLA_ERROR; |
| 9535 | int fn; |
| 9536 | struct pci_dev *other_pdev = NULL; |
| 9537 | |
| 9538 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); |
| 9539 | |
| 9540 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 9541 | |
| 9542 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 9543 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 9544 | clear_bit(AF_LINK_UP, &ha->flags); |
| 9545 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9546 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9547 | } |
| 9548 | |
| 9549 | fn = PCI_FUNC(ha->pdev->devfn); |
| 9550 | while (fn > 0) { |
| 9551 | fn--; |
| 9552 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at " |
| 9553 | "func %x\n", ha->host_no, __func__, fn); |
| 9554 | /* Get the pci device given the domain, bus, |
| 9555 | * slot/function number */ |
| 9556 | other_pdev = |
| 9557 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 9558 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 9559 | fn)); |
| 9560 | |
| 9561 | if (!other_pdev) |
| 9562 | continue; |
| 9563 | |
| 9564 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 9565 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI " |
| 9566 | "func in enabled state%x\n", ha->host_no, |
| 9567 | __func__, fn); |
| 9568 | pci_dev_put(other_pdev); |
| 9569 | break; |
| 9570 | } |
| 9571 | pci_dev_put(other_pdev); |
| 9572 | } |
| 9573 | |
| 9574 | /* The first function on the card, the reset owner will |
| 9575 | * start & initialize the firmware. The other functions |
| 9576 | * on the card will reset the firmware context |
| 9577 | */ |
| 9578 | if (!fn) { |
| 9579 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " |
| 9580 | "0x%x is the owner\n", ha->host_no, __func__, |
| 9581 | ha->pdev->devfn); |
| 9582 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9583 | ha->isp_ops->idc_lock(ha); |
| 9584 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9585 | QLA8XXX_DEV_COLD); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9586 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9587 | |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 9588 | rval = qla4_8xxx_update_idc_reg(ha); |
| 9589 | if (rval == QLA_ERROR) { |
| 9590 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n", |
| 9591 | ha->host_no, __func__); |
| 9592 | ha->isp_ops->idc_lock(ha); |
| 9593 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9594 | QLA8XXX_DEV_FAILED); |
| 9595 | ha->isp_ops->idc_unlock(ha); |
| 9596 | goto exit_error_recovery; |
| 9597 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9598 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9599 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9600 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9601 | |
| 9602 | if (rval != QLA_SUCCESS) { |
| 9603 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 9604 | "FAILED\n", ha->host_no, __func__); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9605 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9606 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9607 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9608 | QLA8XXX_DEV_FAILED); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9609 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9610 | } else { |
| 9611 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 9612 | "READY\n", ha->host_no, __func__); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9613 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9614 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 9615 | QLA8XXX_DEV_READY); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9616 | /* Clear driver state register */ |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9617 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9618 | qla4_8xxx_set_drv_active(ha); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 9619 | ha->isp_ops->idc_unlock(ha); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9620 | ha->isp_ops->enable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9621 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9622 | } else { |
| 9623 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " |
| 9624 | "the reset owner\n", ha->host_no, __func__, |
| 9625 | ha->pdev->devfn); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9626 | if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) == |
| 9627 | QLA8XXX_DEV_READY)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9628 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 9629 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 9630 | if (rval == QLA_SUCCESS) |
| 9631 | ha->isp_ops->enable_intrs(ha); |
| 9632 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9633 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9634 | qla4_8xxx_set_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 9635 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9636 | } |
| 9637 | } |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 9638 | exit_error_recovery: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9639 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 9640 | return rval; |
| 9641 | } |
| 9642 | |
| 9643 | static pci_ers_result_t |
| 9644 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) |
| 9645 | { |
| 9646 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 9647 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9648 | int rc; |
| 9649 | |
| 9650 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", |
| 9651 | ha->host_no, __func__); |
| 9652 | |
| 9653 | if (!is_aer_supported(ha)) |
| 9654 | return PCI_ERS_RESULT_NONE; |
| 9655 | |
| 9656 | /* Restore the saved state of PCIe device - |
| 9657 | * BAR registers, PCI Config space, PCIX, MSI, |
| 9658 | * IOV states |
| 9659 | */ |
| 9660 | pci_restore_state(pdev); |
| 9661 | |
| 9662 | /* pci_restore_state() clears the saved_state flag of the device |
| 9663 | * save restored state which resets saved_state flag |
| 9664 | */ |
| 9665 | pci_save_state(pdev); |
| 9666 | |
| 9667 | /* Initialize device or resume if in suspended state */ |
| 9668 | rc = pci_enable_device(pdev); |
| 9669 | if (rc) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9670 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9671 | "device after reset\n", ha->host_no, __func__); |
| 9672 | goto exit_slot_reset; |
| 9673 | } |
| 9674 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 9675 | ha->isp_ops->disable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9676 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9677 | if (is_qla80XX(ha)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9678 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { |
| 9679 | ret = PCI_ERS_RESULT_RECOVERED; |
| 9680 | goto exit_slot_reset; |
| 9681 | } else |
| 9682 | goto exit_slot_reset; |
| 9683 | } |
| 9684 | |
| 9685 | exit_slot_reset: |
| 9686 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" |
| 9687 | "device after reset\n", ha->host_no, __func__, ret); |
| 9688 | return ret; |
| 9689 | } |
| 9690 | |
| 9691 | static void |
| 9692 | qla4xxx_pci_resume(struct pci_dev *pdev) |
| 9693 | { |
| 9694 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 9695 | int ret; |
| 9696 | |
| 9697 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", |
| 9698 | ha->host_no, __func__); |
| 9699 | |
| 9700 | ret = qla4xxx_wait_for_hba_online(ha); |
| 9701 | if (ret != QLA_SUCCESS) { |
| 9702 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " |
| 9703 | "resume I/O from slot/link_reset\n", ha->host_no, |
| 9704 | __func__); |
| 9705 | } |
| 9706 | |
| 9707 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9708 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 9709 | } |
| 9710 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 9711 | static const struct pci_error_handlers qla4xxx_err_handler = { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9712 | .error_detected = qla4xxx_pci_error_detected, |
| 9713 | .mmio_enabled = qla4xxx_pci_mmio_enabled, |
| 9714 | .slot_reset = qla4xxx_pci_slot_reset, |
| 9715 | .resume = qla4xxx_pci_resume, |
| 9716 | }; |
| 9717 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9718 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
| 9719 | { |
| 9720 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9721 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, |
| 9722 | .subvendor = PCI_ANY_ID, |
| 9723 | .subdevice = PCI_ANY_ID, |
| 9724 | }, |
| 9725 | { |
| 9726 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9727 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, |
| 9728 | .subvendor = PCI_ANY_ID, |
| 9729 | .subdevice = PCI_ANY_ID, |
| 9730 | }, |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 9731 | { |
| 9732 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9733 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, |
| 9734 | .subvendor = PCI_ANY_ID, |
| 9735 | .subdevice = PCI_ANY_ID, |
| 9736 | }, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 9737 | { |
| 9738 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9739 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, |
| 9740 | .subvendor = PCI_ANY_ID, |
| 9741 | .subdevice = PCI_ANY_ID, |
| 9742 | }, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 9743 | { |
| 9744 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9745 | .device = PCI_DEVICE_ID_QLOGIC_ISP8324, |
| 9746 | .subvendor = PCI_ANY_ID, |
| 9747 | .subdevice = PCI_ANY_ID, |
| 9748 | }, |
Vikas Chaudhary | b37ca41 | 2013-08-16 07:03:02 -0400 | [diff] [blame] | 9749 | { |
| 9750 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 9751 | .device = PCI_DEVICE_ID_QLOGIC_ISP8042, |
| 9752 | .subvendor = PCI_ANY_ID, |
| 9753 | .subdevice = PCI_ANY_ID, |
| 9754 | }, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9755 | {0, 0}, |
| 9756 | }; |
| 9757 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); |
| 9758 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 9759 | static struct pci_driver qla4xxx_pci_driver = { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9760 | .name = DRIVER_NAME, |
| 9761 | .id_table = qla4xxx_pci_tbl, |
| 9762 | .probe = qla4xxx_probe_adapter, |
| 9763 | .remove = qla4xxx_remove_adapter, |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 9764 | .err_handler = &qla4xxx_err_handler, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9765 | }; |
| 9766 | |
| 9767 | static int __init qla4xxx_module_init(void) |
| 9768 | { |
| 9769 | int ret; |
| 9770 | |
| 9771 | /* Allocate cache for SRBs. */ |
| 9772 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 9773 | SLAB_HWCACHE_ALIGN, NULL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9774 | if (srb_cachep == NULL) { |
| 9775 | printk(KERN_ERR |
| 9776 | "%s: Unable to allocate SRB cache..." |
| 9777 | "Failing load!\n", DRIVER_NAME); |
| 9778 | ret = -ENOMEM; |
| 9779 | goto no_srp_cache; |
| 9780 | } |
| 9781 | |
| 9782 | /* Derive version string. */ |
| 9783 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 9784 | if (ql4xextended_error_logging) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9785 | strcat(qla4xxx_version_str, "-debug"); |
| 9786 | |
| 9787 | qla4xxx_scsi_transport = |
| 9788 | iscsi_register_transport(&qla4xxx_iscsi_transport); |
| 9789 | if (!qla4xxx_scsi_transport){ |
| 9790 | ret = -ENODEV; |
| 9791 | goto release_srb_cache; |
| 9792 | } |
| 9793 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9794 | ret = pci_register_driver(&qla4xxx_pci_driver); |
| 9795 | if (ret) |
| 9796 | goto unregister_transport; |
| 9797 | |
| 9798 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); |
| 9799 | return 0; |
Doug Maxey | 5ae16db | 2006-10-05 23:50:07 -0500 | [diff] [blame] | 9800 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9801 | unregister_transport: |
| 9802 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 9803 | release_srb_cache: |
| 9804 | kmem_cache_destroy(srb_cachep); |
| 9805 | no_srp_cache: |
| 9806 | return ret; |
| 9807 | } |
| 9808 | |
| 9809 | static void __exit qla4xxx_module_exit(void) |
| 9810 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 9811 | pci_unregister_driver(&qla4xxx_pci_driver); |
| 9812 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 9813 | kmem_cache_destroy(srb_cachep); |
| 9814 | } |
| 9815 | |
| 9816 | module_init(qla4xxx_module_init); |
| 9817 | module_exit(qla4xxx_module_exit); |
| 9818 | |
| 9819 | MODULE_AUTHOR("QLogic Corporation"); |
| 9820 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); |
| 9821 | MODULE_LICENSE("GPL"); |
| 9822 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |