David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic iSCSI HBA Driver |
Vikas Chaudhary | c68cdbf | 2012-08-22 07:55:09 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2012 QLogic Corporation |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4 | * |
| 5 | * See LICENSE.qla4xxx for copyright and licensing details. |
| 6 | */ |
| 7 | #include <linux/moduleparam.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 9 | #include <linux/blkdev.h> |
| 10 | #include <linux/iscsi_boot_sysfs.h> |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 11 | #include <linux/inet.h> |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 12 | |
| 13 | #include <scsi/scsi_tcq.h> |
| 14 | #include <scsi/scsicam.h> |
| 15 | |
| 16 | #include "ql4_def.h" |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 17 | #include "ql4_version.h" |
| 18 | #include "ql4_glbl.h" |
| 19 | #include "ql4_dbg.h" |
| 20 | #include "ql4_inline.h" |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 21 | #include "ql4_83xx.h" |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Driver version |
| 25 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 26 | static char qla4xxx_version_str[40]; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * SRB allocation cache |
| 30 | */ |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 31 | static struct kmem_cache *srb_cachep; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Module parameter information and variables |
| 35 | */ |
Vikas Chaudhary | a7380a6 | 2012-02-27 03:08:56 -0800 | [diff] [blame] | 36 | static int ql4xdisablesysfsboot = 1; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 37 | module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR); |
| 38 | MODULE_PARM_DESC(ql4xdisablesysfsboot, |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 39 | " Set to disable exporting boot targets to sysfs.\n" |
| 40 | "\t\t 0 - Export boot targets\n" |
| 41 | "\t\t 1 - Do not export boot targets (Default)"); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 42 | |
Vikas Chaudhary | 3573bfb | 2012-02-27 03:08:57 -0800 | [diff] [blame] | 43 | int ql4xdontresethba; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 44 | module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 45 | MODULE_PARM_DESC(ql4xdontresethba, |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 46 | " Don't reset the HBA for driver recovery.\n" |
| 47 | "\t\t 0 - It will reset HBA (Default)\n" |
| 48 | "\t\t 1 - It will NOT reset HBA"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 49 | |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 50 | int ql4xextended_error_logging; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 51 | module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 52 | MODULE_PARM_DESC(ql4xextended_error_logging, |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 53 | " Option to enable extended error logging.\n" |
| 54 | "\t\t 0 - no logging (Default)\n" |
| 55 | "\t\t 2 - debug logging"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 56 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 57 | int ql4xenablemsix = 1; |
| 58 | module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR); |
| 59 | MODULE_PARM_DESC(ql4xenablemsix, |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 60 | " Set to enable MSI or MSI-X interrupt mechanism.\n" |
| 61 | "\t\t 0 = enable INTx interrupt mechanism.\n" |
| 62 | "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n" |
| 63 | "\t\t 2 = enable MSI interrupt mechanism."); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 64 | |
Mike Christie | d510d96 | 2008-07-11 19:50:33 -0500 | [diff] [blame] | 65 | #define QL4_DEF_QDEPTH 32 |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 66 | static int ql4xmaxqdepth = QL4_DEF_QDEPTH; |
| 67 | module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR); |
| 68 | MODULE_PARM_DESC(ql4xmaxqdepth, |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 69 | " Maximum queue depth to report for target devices.\n" |
| 70 | "\t\t Default: 32."); |
Mike Christie | d510d96 | 2008-07-11 19:50:33 -0500 | [diff] [blame] | 71 | |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 72 | static int ql4xqfulltracking = 1; |
| 73 | module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR); |
| 74 | MODULE_PARM_DESC(ql4xqfulltracking, |
| 75 | " Enable or disable dynamic tracking and adjustment of\n" |
| 76 | "\t\t scsi device queue depth.\n" |
| 77 | "\t\t 0 - Disable.\n" |
| 78 | "\t\t 1 - Enable. (Default)"); |
| 79 | |
Vikas Chaudhary | 3038727 | 2011-03-21 03:34:32 -0700 | [diff] [blame] | 80 | static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO; |
| 81 | module_param(ql4xsess_recovery_tmo, int, S_IRUGO); |
| 82 | MODULE_PARM_DESC(ql4xsess_recovery_tmo, |
Vikas Chaudhary | 3573bfb | 2012-02-27 03:08:57 -0800 | [diff] [blame] | 83 | " Target Session Recovery Timeout.\n" |
Karen Higgins | a4e8a71 | 2012-01-11 02:44:20 -0800 | [diff] [blame] | 84 | "\t\t Default: 120 sec."); |
Vikas Chaudhary | 3038727 | 2011-03-21 03:34:32 -0700 | [diff] [blame] | 85 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 86 | int ql4xmdcapmask = 0x1F; |
| 87 | module_param(ql4xmdcapmask, int, S_IRUGO); |
| 88 | MODULE_PARM_DESC(ql4xmdcapmask, |
| 89 | " Set the Minidump driver capture mask level.\n" |
| 90 | "\t\t Default is 0x1F.\n" |
| 91 | "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F"); |
| 92 | |
| 93 | int ql4xenablemd = 1; |
| 94 | module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR); |
| 95 | MODULE_PARM_DESC(ql4xenablemd, |
| 96 | " Set to enable minidump.\n" |
| 97 | "\t\t 0 - disable minidump\n" |
| 98 | "\t\t 1 - enable minidump (Default)"); |
| 99 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 100 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 101 | /* |
| 102 | * SCSI host template entry points |
| 103 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 104 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * iSCSI template entry points |
| 108 | */ |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 109 | static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess, |
| 110 | enum iscsi_param param, char *buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 111 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
| 112 | enum iscsi_param param, char *buf); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 113 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 114 | enum iscsi_host_param param, char *buf); |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 115 | static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, |
| 116 | uint32_t len); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 117 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 118 | enum iscsi_param_type param_type, |
| 119 | int param, char *buf); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 120 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 121 | static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost, |
| 122 | struct sockaddr *dst_addr, |
| 123 | int non_blocking); |
| 124 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms); |
| 125 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep); |
| 126 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 127 | enum iscsi_param param, char *buf); |
| 128 | static int qla4xxx_conn_start(struct iscsi_cls_conn *conn); |
| 129 | static struct iscsi_cls_conn * |
| 130 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx); |
| 131 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 132 | struct iscsi_cls_conn *cls_conn, |
| 133 | uint64_t transport_fd, int is_leading); |
| 134 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn); |
| 135 | static struct iscsi_cls_session * |
| 136 | qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, |
| 137 | uint16_t qdepth, uint32_t initial_cmdsn); |
| 138 | static void qla4xxx_session_destroy(struct iscsi_cls_session *sess); |
| 139 | static void qla4xxx_task_work(struct work_struct *wdata); |
| 140 | static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t); |
| 141 | static int qla4xxx_task_xmit(struct iscsi_task *); |
| 142 | static void qla4xxx_task_cleanup(struct iscsi_task *); |
| 143 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session); |
| 144 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 145 | struct iscsi_stats *stats); |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 146 | static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num, |
| 147 | uint32_t iface_type, uint32_t payload_size, |
| 148 | uint32_t pid, struct sockaddr *dst_addr); |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 149 | static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx, |
| 150 | uint32_t *num_entries, char *buf); |
| 151 | static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx); |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 152 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 153 | /* |
| 154 | * SCSI host template entry points |
| 155 | */ |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 156 | static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 157 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 158 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 159 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 160 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); |
| 161 | static int qla4xxx_slave_alloc(struct scsi_device *device); |
| 162 | static int qla4xxx_slave_configure(struct scsi_device *device); |
| 163 | static void qla4xxx_slave_destroy(struct scsi_device *sdev); |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 164 | static umode_t qla4_attr_is_visible(int param_type, int param); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 165 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 166 | static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, |
| 167 | int reason); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 168 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 169 | /* |
| 170 | * iSCSI Flash DDB sysfs entry points |
| 171 | */ |
| 172 | static int |
| 173 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 174 | struct iscsi_bus_flash_conn *fnode_conn, |
| 175 | void *data, int len); |
| 176 | static int |
| 177 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 178 | int param, char *buf); |
| 179 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 180 | int len); |
| 181 | static int |
| 182 | qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess); |
| 183 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 184 | struct iscsi_bus_flash_conn *fnode_conn); |
| 185 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 186 | struct iscsi_bus_flash_conn *fnode_conn); |
| 187 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess); |
| 188 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 189 | static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
| 190 | QLA82XX_LEGACY_INTR_CONFIG; |
| 191 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 192 | static struct scsi_host_template qla4xxx_driver_template = { |
| 193 | .module = THIS_MODULE, |
| 194 | .name = DRIVER_NAME, |
| 195 | .proc_name = DRIVER_NAME, |
| 196 | .queuecommand = qla4xxx_queuecommand, |
| 197 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 198 | .eh_abort_handler = qla4xxx_eh_abort, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 199 | .eh_device_reset_handler = qla4xxx_eh_device_reset, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 200 | .eh_target_reset_handler = qla4xxx_eh_target_reset, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 201 | .eh_host_reset_handler = qla4xxx_eh_host_reset, |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 202 | .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 203 | |
| 204 | .slave_configure = qla4xxx_slave_configure, |
| 205 | .slave_alloc = qla4xxx_slave_alloc, |
| 206 | .slave_destroy = qla4xxx_slave_destroy, |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 207 | .change_queue_depth = qla4xxx_change_queue_depth, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 208 | |
| 209 | .this_id = -1, |
| 210 | .cmd_per_lun = 3, |
| 211 | .use_clustering = ENABLE_CLUSTERING, |
| 212 | .sg_tablesize = SG_ALL, |
| 213 | |
| 214 | .max_sectors = 0xFFFF, |
Harish Zunjarrao | 7ad633c | 2011-05-17 23:17:11 -0700 | [diff] [blame] | 215 | .shost_attrs = qla4xxx_host_attrs, |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 216 | .host_reset = qla4xxx_host_reset, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 217 | .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | static struct iscsi_transport qla4xxx_iscsi_transport = { |
| 221 | .owner = THIS_MODULE, |
| 222 | .name = DRIVER_NAME, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 223 | .caps = CAP_TEXT_NEGO | |
| 224 | CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST | |
| 225 | CAP_DATADGST | CAP_LOGIN_OFFLOAD | |
| 226 | CAP_MULTI_R2T, |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 227 | .attr_is_visible = qla4_attr_is_visible, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 228 | .create_session = qla4xxx_session_create, |
| 229 | .destroy_session = qla4xxx_session_destroy, |
| 230 | .start_conn = qla4xxx_conn_start, |
| 231 | .create_conn = qla4xxx_conn_create, |
| 232 | .bind_conn = qla4xxx_conn_bind, |
| 233 | .stop_conn = iscsi_conn_stop, |
| 234 | .destroy_conn = qla4xxx_conn_destroy, |
| 235 | .set_param = iscsi_set_param, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 236 | .get_conn_param = qla4xxx_conn_get_param, |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 237 | .get_session_param = qla4xxx_session_get_param, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 238 | .get_ep_param = qla4xxx_get_ep_param, |
| 239 | .ep_connect = qla4xxx_ep_connect, |
| 240 | .ep_poll = qla4xxx_ep_poll, |
| 241 | .ep_disconnect = qla4xxx_ep_disconnect, |
| 242 | .get_stats = qla4xxx_conn_get_stats, |
| 243 | .send_pdu = iscsi_conn_send_pdu, |
| 244 | .xmit_task = qla4xxx_task_xmit, |
| 245 | .cleanup_task = qla4xxx_task_cleanup, |
| 246 | .alloc_pdu = qla4xxx_alloc_pdu, |
| 247 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 248 | .get_host_param = qla4xxx_host_get_param, |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 249 | .set_iface_param = qla4xxx_iface_set_param, |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 250 | .get_iface_param = qla4xxx_get_iface_param, |
Vikas Chaudhary | a355943 | 2011-07-25 13:48:51 -0500 | [diff] [blame] | 251 | .bsg_request = qla4xxx_bsg_request, |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 252 | .send_ping = qla4xxx_send_ping, |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 253 | .get_chap = qla4xxx_get_chap_list, |
| 254 | .delete_chap = qla4xxx_delete_chap, |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 255 | .get_flashnode_param = qla4xxx_sysfs_ddb_get_param, |
| 256 | .set_flashnode_param = qla4xxx_sysfs_ddb_set_param, |
| 257 | .new_flashnode = qla4xxx_sysfs_ddb_add, |
| 258 | .del_flashnode = qla4xxx_sysfs_ddb_delete, |
| 259 | .login_flashnode = qla4xxx_sysfs_ddb_login, |
| 260 | .logout_flashnode = qla4xxx_sysfs_ddb_logout, |
| 261 | .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | static struct scsi_transport_template *qla4xxx_scsi_transport; |
| 265 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 266 | static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num, |
| 267 | uint32_t iface_type, uint32_t payload_size, |
| 268 | uint32_t pid, struct sockaddr *dst_addr) |
| 269 | { |
| 270 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 271 | struct sockaddr_in *addr; |
| 272 | struct sockaddr_in6 *addr6; |
| 273 | uint32_t options = 0; |
| 274 | uint8_t ipaddr[IPv6_ADDR_LEN]; |
| 275 | int rval; |
| 276 | |
| 277 | memset(ipaddr, 0, IPv6_ADDR_LEN); |
| 278 | /* IPv4 to IPv4 */ |
| 279 | if ((iface_type == ISCSI_IFACE_TYPE_IPV4) && |
| 280 | (dst_addr->sa_family == AF_INET)) { |
| 281 | addr = (struct sockaddr_in *)dst_addr; |
| 282 | memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN); |
| 283 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 " |
| 284 | "dest: %pI4\n", __func__, |
| 285 | &ha->ip_config.ip_address, ipaddr)); |
| 286 | rval = qla4xxx_ping_iocb(ha, options, payload_size, pid, |
| 287 | ipaddr); |
| 288 | if (rval) |
| 289 | rval = -EINVAL; |
| 290 | } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) && |
| 291 | (dst_addr->sa_family == AF_INET6)) { |
| 292 | /* IPv6 to IPv6 */ |
| 293 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 294 | memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN); |
| 295 | |
| 296 | options |= PING_IPV6_PROTOCOL_ENABLE; |
| 297 | |
| 298 | /* Ping using LinkLocal address */ |
| 299 | if ((iface_num == 0) || (iface_num == 1)) { |
| 300 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping " |
| 301 | "src: %pI6 dest: %pI6\n", __func__, |
| 302 | &ha->ip_config.ipv6_link_local_addr, |
| 303 | ipaddr)); |
| 304 | options |= PING_IPV6_LINKLOCAL_ADDR; |
| 305 | rval = qla4xxx_ping_iocb(ha, options, payload_size, |
| 306 | pid, ipaddr); |
| 307 | } else { |
| 308 | ql4_printk(KERN_WARNING, ha, "%s: iface num = %d " |
| 309 | "not supported\n", __func__, iface_num); |
| 310 | rval = -ENOSYS; |
| 311 | goto exit_send_ping; |
| 312 | } |
| 313 | |
| 314 | /* |
| 315 | * If ping using LinkLocal address fails, try ping using |
| 316 | * IPv6 address |
| 317 | */ |
| 318 | if (rval != QLA_SUCCESS) { |
| 319 | options &= ~PING_IPV6_LINKLOCAL_ADDR; |
| 320 | if (iface_num == 0) { |
| 321 | options |= PING_IPV6_ADDR0; |
| 322 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 " |
| 323 | "Ping src: %pI6 " |
| 324 | "dest: %pI6\n", __func__, |
| 325 | &ha->ip_config.ipv6_addr0, |
| 326 | ipaddr)); |
| 327 | } else if (iface_num == 1) { |
| 328 | options |= PING_IPV6_ADDR1; |
| 329 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 " |
| 330 | "Ping src: %pI6 " |
| 331 | "dest: %pI6\n", __func__, |
| 332 | &ha->ip_config.ipv6_addr1, |
| 333 | ipaddr)); |
| 334 | } |
| 335 | rval = qla4xxx_ping_iocb(ha, options, payload_size, |
| 336 | pid, ipaddr); |
| 337 | if (rval) |
| 338 | rval = -EINVAL; |
| 339 | } |
| 340 | } else |
| 341 | rval = -ENOSYS; |
| 342 | exit_send_ping: |
| 343 | return rval; |
| 344 | } |
| 345 | |
Vikas Chaudhary | 5e9bcec | 2012-08-22 07:55:01 -0400 | [diff] [blame] | 346 | static umode_t qla4_attr_is_visible(int param_type, int param) |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 347 | { |
| 348 | switch (param_type) { |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 349 | case ISCSI_HOST_PARAM: |
| 350 | switch (param) { |
| 351 | case ISCSI_HOST_PARAM_HWADDRESS: |
| 352 | case ISCSI_HOST_PARAM_IPADDRESS: |
| 353 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 354 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 355 | case ISCSI_HOST_PARAM_PORT_SPEED: |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 356 | return S_IRUGO; |
| 357 | default: |
| 358 | return 0; |
| 359 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 360 | case ISCSI_PARAM: |
| 361 | switch (param) { |
Mike Christie | 590134f | 2011-10-17 22:42:13 -0500 | [diff] [blame] | 362 | case ISCSI_PARAM_PERSISTENT_ADDRESS: |
| 363 | case ISCSI_PARAM_PERSISTENT_PORT: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 364 | case ISCSI_PARAM_CONN_ADDRESS: |
| 365 | case ISCSI_PARAM_CONN_PORT: |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 366 | case ISCSI_PARAM_TARGET_NAME: |
| 367 | case ISCSI_PARAM_TPGT: |
| 368 | case ISCSI_PARAM_TARGET_ALIAS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 369 | case ISCSI_PARAM_MAX_BURST: |
| 370 | case ISCSI_PARAM_MAX_R2T: |
| 371 | case ISCSI_PARAM_FIRST_BURST: |
| 372 | case ISCSI_PARAM_MAX_RECV_DLENGTH: |
| 373 | case ISCSI_PARAM_MAX_XMIT_DLENGTH: |
Mike Christie | de37920 | 2011-08-14 20:42:56 -0500 | [diff] [blame] | 374 | case ISCSI_PARAM_IFACE_NAME: |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 375 | case ISCSI_PARAM_CHAP_OUT_IDX: |
| 376 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 377 | case ISCSI_PARAM_USERNAME: |
| 378 | case ISCSI_PARAM_PASSWORD: |
| 379 | case ISCSI_PARAM_USERNAME_IN: |
| 380 | case ISCSI_PARAM_PASSWORD_IN: |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 381 | return S_IRUGO; |
| 382 | default: |
| 383 | return 0; |
| 384 | } |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 385 | case ISCSI_NET_PARAM: |
| 386 | switch (param) { |
| 387 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 388 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 389 | case ISCSI_NET_PARAM_IPV4_GW: |
| 390 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 391 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 392 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 393 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 394 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 395 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 396 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 397 | case ISCSI_NET_PARAM_VLAN_ID: |
| 398 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 399 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 400 | case ISCSI_NET_PARAM_MTU: |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 401 | case ISCSI_NET_PARAM_PORT: |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 402 | return S_IRUGO; |
| 403 | default: |
| 404 | return 0; |
| 405 | } |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 406 | case ISCSI_FLASHNODE_PARAM: |
| 407 | switch (param) { |
| 408 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 409 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 410 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 411 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 412 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 413 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 414 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 415 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 416 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 417 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 418 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 419 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 420 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 421 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 422 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 423 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 424 | case ISCSI_FLASHNODE_ERL: |
| 425 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 426 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 427 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 428 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 429 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 430 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 431 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 432 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 433 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 434 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 435 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 436 | case ISCSI_FLASHNODE_MAX_R2T: |
| 437 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 438 | case ISCSI_FLASHNODE_ISID: |
| 439 | case ISCSI_FLASHNODE_TSID: |
| 440 | case ISCSI_FLASHNODE_PORT: |
| 441 | case ISCSI_FLASHNODE_MAX_BURST: |
| 442 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 443 | case ISCSI_FLASHNODE_IPADDR: |
| 444 | case ISCSI_FLASHNODE_ALIAS: |
| 445 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 446 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 447 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 448 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 449 | case ISCSI_FLASHNODE_IPV6_TC: |
| 450 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 451 | case ISCSI_FLASHNODE_NAME: |
| 452 | case ISCSI_FLASHNODE_TPGT: |
| 453 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 454 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 455 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 456 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 457 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 458 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 459 | case ISCSI_FLASHNODE_USERNAME: |
| 460 | case ISCSI_FLASHNODE_PASSWORD: |
| 461 | case ISCSI_FLASHNODE_STATSN: |
| 462 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 463 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 464 | return S_IRUGO; |
| 465 | default: |
| 466 | return 0; |
| 467 | } |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 473 | static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx, |
| 474 | uint32_t *num_entries, char *buf) |
| 475 | { |
| 476 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 477 | struct ql4_chap_table *chap_table; |
| 478 | struct iscsi_chap_rec *chap_rec; |
| 479 | int max_chap_entries = 0; |
| 480 | int valid_chap_entries = 0; |
| 481 | int ret = 0, i; |
| 482 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 483 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 484 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 485 | sizeof(struct ql4_chap_table); |
| 486 | else |
| 487 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 488 | |
| 489 | ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n", |
| 490 | __func__, *num_entries, chap_tbl_idx); |
| 491 | |
| 492 | if (!buf) { |
| 493 | ret = -ENOMEM; |
| 494 | goto exit_get_chap_list; |
| 495 | } |
| 496 | |
| 497 | chap_rec = (struct iscsi_chap_rec *) buf; |
| 498 | mutex_lock(&ha->chap_sem); |
| 499 | for (i = chap_tbl_idx; i < max_chap_entries; i++) { |
| 500 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 501 | if (chap_table->cookie != |
| 502 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) |
| 503 | continue; |
| 504 | |
| 505 | chap_rec->chap_tbl_idx = i; |
| 506 | strncpy(chap_rec->username, chap_table->name, |
| 507 | ISCSI_CHAP_AUTH_NAME_MAX_LEN); |
| 508 | strncpy(chap_rec->password, chap_table->secret, |
| 509 | QL4_CHAP_MAX_SECRET_LEN); |
| 510 | chap_rec->password_length = chap_table->secret_len; |
| 511 | |
| 512 | if (chap_table->flags & BIT_7) /* local */ |
| 513 | chap_rec->chap_type = CHAP_TYPE_OUT; |
| 514 | |
| 515 | if (chap_table->flags & BIT_6) /* peer */ |
| 516 | chap_rec->chap_type = CHAP_TYPE_IN; |
| 517 | |
| 518 | chap_rec++; |
| 519 | |
| 520 | valid_chap_entries++; |
| 521 | if (valid_chap_entries == *num_entries) |
| 522 | break; |
| 523 | else |
| 524 | continue; |
| 525 | } |
| 526 | mutex_unlock(&ha->chap_sem); |
| 527 | |
| 528 | exit_get_chap_list: |
| 529 | ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n", |
| 530 | __func__, valid_chap_entries); |
| 531 | *num_entries = valid_chap_entries; |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | static int __qla4xxx_is_chap_active(struct device *dev, void *data) |
| 536 | { |
| 537 | int ret = 0; |
| 538 | uint16_t *chap_tbl_idx = (uint16_t *) data; |
| 539 | struct iscsi_cls_session *cls_session; |
| 540 | struct iscsi_session *sess; |
| 541 | struct ddb_entry *ddb_entry; |
| 542 | |
| 543 | if (!iscsi_is_session_dev(dev)) |
| 544 | goto exit_is_chap_active; |
| 545 | |
| 546 | cls_session = iscsi_dev_to_session(dev); |
| 547 | sess = cls_session->dd_data; |
| 548 | ddb_entry = sess->dd_data; |
| 549 | |
| 550 | if (iscsi_session_chkready(cls_session)) |
| 551 | goto exit_is_chap_active; |
| 552 | |
| 553 | if (ddb_entry->chap_tbl_idx == *chap_tbl_idx) |
| 554 | ret = 1; |
| 555 | |
| 556 | exit_is_chap_active: |
| 557 | return ret; |
| 558 | } |
| 559 | |
| 560 | static int qla4xxx_is_chap_active(struct Scsi_Host *shost, |
| 561 | uint16_t chap_tbl_idx) |
| 562 | { |
| 563 | int ret = 0; |
| 564 | |
| 565 | ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx, |
| 566 | __qla4xxx_is_chap_active); |
| 567 | |
| 568 | return ret; |
| 569 | } |
| 570 | |
| 571 | static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx) |
| 572 | { |
| 573 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 574 | struct ql4_chap_table *chap_table; |
| 575 | dma_addr_t chap_dma; |
| 576 | int max_chap_entries = 0; |
| 577 | uint32_t offset = 0; |
| 578 | uint32_t chap_size; |
| 579 | int ret = 0; |
| 580 | |
| 581 | chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma); |
| 582 | if (chap_table == NULL) |
| 583 | return -ENOMEM; |
| 584 | |
| 585 | memset(chap_table, 0, sizeof(struct ql4_chap_table)); |
| 586 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 587 | if (is_qla80XX(ha)) |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 588 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 589 | sizeof(struct ql4_chap_table); |
| 590 | else |
| 591 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 592 | |
| 593 | if (chap_tbl_idx > max_chap_entries) { |
| 594 | ret = -EINVAL; |
| 595 | goto exit_delete_chap; |
| 596 | } |
| 597 | |
| 598 | /* Check if chap index is in use. |
| 599 | * If chap is in use don't delet chap entry */ |
| 600 | ret = qla4xxx_is_chap_active(shost, chap_tbl_idx); |
| 601 | if (ret) { |
| 602 | ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot " |
| 603 | "delete from flash\n", chap_tbl_idx); |
| 604 | ret = -EBUSY; |
| 605 | goto exit_delete_chap; |
| 606 | } |
| 607 | |
| 608 | chap_size = sizeof(struct ql4_chap_table); |
| 609 | if (is_qla40XX(ha)) |
| 610 | offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size); |
| 611 | else { |
| 612 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 613 | /* flt_chap_size is CHAP table size for both ports |
| 614 | * so divide it by 2 to calculate the offset for second port |
| 615 | */ |
| 616 | if (ha->port_num == 1) |
| 617 | offset += (ha->hw.flt_chap_size / 2); |
| 618 | offset += (chap_tbl_idx * chap_size); |
| 619 | } |
| 620 | |
| 621 | ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 622 | if (ret != QLA_SUCCESS) { |
| 623 | ret = -EINVAL; |
| 624 | goto exit_delete_chap; |
| 625 | } |
| 626 | |
| 627 | DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n", |
| 628 | __le16_to_cpu(chap_table->cookie))); |
| 629 | |
| 630 | if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) { |
| 631 | ql4_printk(KERN_ERR, ha, "No valid chap entry found\n"); |
| 632 | goto exit_delete_chap; |
| 633 | } |
| 634 | |
| 635 | chap_table->cookie = __constant_cpu_to_le16(0xFFFF); |
| 636 | |
| 637 | offset = FLASH_CHAP_OFFSET | |
| 638 | (chap_tbl_idx * sizeof(struct ql4_chap_table)); |
| 639 | ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size, |
| 640 | FLASH_OPT_RMW_COMMIT); |
| 641 | if (ret == QLA_SUCCESS && ha->chap_list) { |
| 642 | mutex_lock(&ha->chap_sem); |
| 643 | /* Update ha chap_list cache */ |
| 644 | memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx, |
| 645 | chap_table, sizeof(struct ql4_chap_table)); |
| 646 | mutex_unlock(&ha->chap_sem); |
| 647 | } |
| 648 | if (ret != QLA_SUCCESS) |
| 649 | ret = -EINVAL; |
| 650 | |
| 651 | exit_delete_chap: |
| 652 | dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma); |
| 653 | return ret; |
| 654 | } |
| 655 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 656 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| 657 | enum iscsi_param_type param_type, |
| 658 | int param, char *buf) |
| 659 | { |
| 660 | struct Scsi_Host *shost = iscsi_iface_to_shost(iface); |
| 661 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 662 | int len = -ENOSYS; |
| 663 | |
| 664 | if (param_type != ISCSI_NET_PARAM) |
| 665 | return -ENOSYS; |
| 666 | |
| 667 | switch (param) { |
| 668 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 669 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| 670 | break; |
| 671 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 672 | len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask); |
| 673 | break; |
| 674 | case ISCSI_NET_PARAM_IPV4_GW: |
| 675 | len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); |
| 676 | break; |
| 677 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
| 678 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 679 | len = sprintf(buf, "%s\n", |
| 680 | (ha->ip_config.ipv4_options & |
| 681 | IPOPT_IPV4_PROTOCOL_ENABLE) ? |
| 682 | "enabled" : "disabled"); |
| 683 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 684 | len = sprintf(buf, "%s\n", |
| 685 | (ha->ip_config.ipv6_options & |
| 686 | IPV6_OPT_IPV6_PROTOCOL_ENABLE) ? |
| 687 | "enabled" : "disabled"); |
| 688 | break; |
| 689 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 690 | len = sprintf(buf, "%s\n", |
| 691 | (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ? |
| 692 | "dhcp" : "static"); |
| 693 | break; |
| 694 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 695 | if (iface->iface_num == 0) |
| 696 | len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0); |
| 697 | if (iface->iface_num == 1) |
| 698 | len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1); |
| 699 | break; |
| 700 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 701 | len = sprintf(buf, "%pI6\n", |
| 702 | &ha->ip_config.ipv6_link_local_addr); |
| 703 | break; |
| 704 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 705 | len = sprintf(buf, "%pI6\n", |
| 706 | &ha->ip_config.ipv6_default_router_addr); |
| 707 | break; |
| 708 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 709 | len = sprintf(buf, "%s\n", |
| 710 | (ha->ip_config.ipv6_addl_options & |
| 711 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? |
| 712 | "nd" : "static"); |
| 713 | break; |
| 714 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 715 | len = sprintf(buf, "%s\n", |
| 716 | (ha->ip_config.ipv6_addl_options & |
| 717 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? |
| 718 | "auto" : "static"); |
| 719 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 720 | case ISCSI_NET_PARAM_VLAN_ID: |
| 721 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 722 | len = sprintf(buf, "%d\n", |
| 723 | (ha->ip_config.ipv4_vlan_tag & |
| 724 | ISCSI_MAX_VLAN_ID)); |
| 725 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 726 | len = sprintf(buf, "%d\n", |
| 727 | (ha->ip_config.ipv6_vlan_tag & |
| 728 | ISCSI_MAX_VLAN_ID)); |
| 729 | break; |
| 730 | case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| 731 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 732 | len = sprintf(buf, "%d\n", |
| 733 | ((ha->ip_config.ipv4_vlan_tag >> 13) & |
| 734 | ISCSI_MAX_VLAN_PRIORITY)); |
| 735 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 736 | len = sprintf(buf, "%d\n", |
| 737 | ((ha->ip_config.ipv6_vlan_tag >> 13) & |
| 738 | ISCSI_MAX_VLAN_PRIORITY)); |
| 739 | break; |
| 740 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 741 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 742 | len = sprintf(buf, "%s\n", |
| 743 | (ha->ip_config.ipv4_options & |
| 744 | IPOPT_VLAN_TAGGING_ENABLE) ? |
| 745 | "enabled" : "disabled"); |
| 746 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 747 | len = sprintf(buf, "%s\n", |
| 748 | (ha->ip_config.ipv6_options & |
| 749 | IPV6_OPT_VLAN_TAGGING_ENABLE) ? |
| 750 | "enabled" : "disabled"); |
| 751 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 752 | case ISCSI_NET_PARAM_MTU: |
| 753 | len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size); |
| 754 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 755 | case ISCSI_NET_PARAM_PORT: |
| 756 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 757 | len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port); |
| 758 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| 759 | len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port); |
| 760 | break; |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 761 | default: |
| 762 | len = -ENOSYS; |
| 763 | } |
| 764 | |
| 765 | return len; |
| 766 | } |
| 767 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 768 | static struct iscsi_endpoint * |
| 769 | qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, |
| 770 | int non_blocking) |
| 771 | { |
| 772 | int ret; |
| 773 | struct iscsi_endpoint *ep; |
| 774 | struct qla_endpoint *qla_ep; |
| 775 | struct scsi_qla_host *ha; |
| 776 | struct sockaddr_in *addr; |
| 777 | struct sockaddr_in6 *addr6; |
| 778 | |
| 779 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 780 | if (!shost) { |
| 781 | ret = -ENXIO; |
| 782 | printk(KERN_ERR "%s: shost is NULL\n", |
| 783 | __func__); |
| 784 | return ERR_PTR(ret); |
| 785 | } |
| 786 | |
| 787 | ha = iscsi_host_priv(shost); |
| 788 | |
| 789 | ep = iscsi_create_endpoint(sizeof(struct qla_endpoint)); |
| 790 | if (!ep) { |
| 791 | ret = -ENOMEM; |
| 792 | return ERR_PTR(ret); |
| 793 | } |
| 794 | |
| 795 | qla_ep = ep->dd_data; |
| 796 | memset(qla_ep, 0, sizeof(struct qla_endpoint)); |
| 797 | if (dst_addr->sa_family == AF_INET) { |
| 798 | memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in)); |
| 799 | addr = (struct sockaddr_in *)&qla_ep->dst_addr; |
| 800 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__, |
| 801 | (char *)&addr->sin_addr)); |
| 802 | } else if (dst_addr->sa_family == AF_INET6) { |
| 803 | memcpy(&qla_ep->dst_addr, dst_addr, |
| 804 | sizeof(struct sockaddr_in6)); |
| 805 | addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr; |
| 806 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__, |
| 807 | (char *)&addr6->sin6_addr)); |
| 808 | } |
| 809 | |
| 810 | qla_ep->host = shost; |
| 811 | |
| 812 | return ep; |
| 813 | } |
| 814 | |
| 815 | static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) |
| 816 | { |
| 817 | struct qla_endpoint *qla_ep; |
| 818 | struct scsi_qla_host *ha; |
| 819 | int ret = 0; |
| 820 | |
| 821 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 822 | qla_ep = ep->dd_data; |
| 823 | ha = to_qla_host(qla_ep->host); |
| 824 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 825 | if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags)) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 826 | ret = 1; |
| 827 | |
| 828 | return ret; |
| 829 | } |
| 830 | |
| 831 | static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep) |
| 832 | { |
| 833 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 834 | iscsi_destroy_endpoint(ep); |
| 835 | } |
| 836 | |
| 837 | static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| 838 | enum iscsi_param param, |
| 839 | char *buf) |
| 840 | { |
| 841 | struct qla_endpoint *qla_ep = ep->dd_data; |
| 842 | struct sockaddr *dst_addr; |
| 843 | |
| 844 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 845 | |
| 846 | switch (param) { |
| 847 | case ISCSI_PARAM_CONN_PORT: |
| 848 | case ISCSI_PARAM_CONN_ADDRESS: |
| 849 | if (!qla_ep) |
| 850 | return -ENOTCONN; |
| 851 | |
| 852 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 853 | if (!dst_addr) |
| 854 | return -ENOTCONN; |
| 855 | |
| 856 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 857 | &qla_ep->dst_addr, param, buf); |
| 858 | default: |
| 859 | return -ENOSYS; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| 864 | struct iscsi_stats *stats) |
| 865 | { |
| 866 | struct iscsi_session *sess; |
| 867 | struct iscsi_cls_session *cls_sess; |
| 868 | struct ddb_entry *ddb_entry; |
| 869 | struct scsi_qla_host *ha; |
| 870 | struct ql_iscsi_stats *ql_iscsi_stats; |
| 871 | int stats_size; |
| 872 | int ret; |
| 873 | dma_addr_t iscsi_stats_dma; |
| 874 | |
| 875 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 876 | |
| 877 | cls_sess = iscsi_conn_to_session(cls_conn); |
| 878 | sess = cls_sess->dd_data; |
| 879 | ddb_entry = sess->dd_data; |
| 880 | ha = ddb_entry->ha; |
| 881 | |
| 882 | stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| 883 | /* Allocate memory */ |
| 884 | ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| 885 | &iscsi_stats_dma, GFP_KERNEL); |
| 886 | if (!ql_iscsi_stats) { |
| 887 | ql4_printk(KERN_ERR, ha, |
| 888 | "Unable to allocate memory for iscsi stats\n"); |
| 889 | goto exit_get_stats; |
| 890 | } |
| 891 | |
| 892 | ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size, |
| 893 | iscsi_stats_dma); |
| 894 | if (ret != QLA_SUCCESS) { |
| 895 | ql4_printk(KERN_ERR, ha, |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 896 | "Unable to retrieve iscsi stats\n"); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 897 | goto free_stats; |
| 898 | } |
| 899 | |
| 900 | /* octets */ |
| 901 | stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets); |
| 902 | stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets); |
| 903 | /* xmit pdus */ |
| 904 | stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus); |
| 905 | stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus); |
| 906 | stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus); |
| 907 | stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus); |
| 908 | stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus); |
| 909 | stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus); |
| 910 | stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus); |
| 911 | stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus); |
| 912 | /* recv pdus */ |
| 913 | stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus); |
| 914 | stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus); |
| 915 | stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus); |
| 916 | stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus); |
| 917 | stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus); |
| 918 | stats->logoutrsp_pdus = |
| 919 | le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus); |
| 920 | stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus); |
| 921 | stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus); |
| 922 | stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus); |
| 923 | |
| 924 | free_stats: |
| 925 | dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats, |
| 926 | iscsi_stats_dma); |
| 927 | exit_get_stats: |
| 928 | return; |
| 929 | } |
| 930 | |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 931 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| 932 | { |
| 933 | struct iscsi_cls_session *session; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 934 | struct iscsi_session *sess; |
| 935 | unsigned long flags; |
| 936 | enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 937 | |
| 938 | session = starget_to_session(scsi_target(sc->device)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 939 | sess = session->dd_data; |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 940 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 941 | spin_lock_irqsave(&session->lock, flags); |
| 942 | if (session->state == ISCSI_SESSION_FAILED) |
| 943 | ret = BLK_EH_RESET_TIMER; |
| 944 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 5c656af | 2009-07-15 15:02:59 -0500 | [diff] [blame] | 945 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 946 | return ret; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 949 | static void qla4xxx_set_port_speed(struct Scsi_Host *shost) |
| 950 | { |
| 951 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 952 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 953 | uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN; |
| 954 | |
| 955 | qla4xxx_get_firmware_state(ha); |
| 956 | |
| 957 | switch (ha->addl_fw_state & 0x0F00) { |
| 958 | case FW_ADDSTATE_LINK_SPEED_10MBPS: |
| 959 | speed = ISCSI_PORT_SPEED_10MBPS; |
| 960 | break; |
| 961 | case FW_ADDSTATE_LINK_SPEED_100MBPS: |
| 962 | speed = ISCSI_PORT_SPEED_100MBPS; |
| 963 | break; |
| 964 | case FW_ADDSTATE_LINK_SPEED_1GBPS: |
| 965 | speed = ISCSI_PORT_SPEED_1GBPS; |
| 966 | break; |
| 967 | case FW_ADDSTATE_LINK_SPEED_10GBPS: |
| 968 | speed = ISCSI_PORT_SPEED_10GBPS; |
| 969 | break; |
| 970 | } |
| 971 | ihost->port_speed = speed; |
| 972 | } |
| 973 | |
| 974 | static void qla4xxx_set_port_state(struct Scsi_Host *shost) |
| 975 | { |
| 976 | struct scsi_qla_host *ha = to_qla_host(shost); |
Vikas Chaudhary | e16d166 | 2012-03-02 01:55:31 -0800 | [diff] [blame] | 977 | struct iscsi_cls_host *ihost = shost->shost_data; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 978 | uint32_t state = ISCSI_PORT_STATE_DOWN; |
| 979 | |
| 980 | if (test_bit(AF_LINK_UP, &ha->flags)) |
| 981 | state = ISCSI_PORT_STATE_UP; |
| 982 | |
| 983 | ihost->port_state = state; |
| 984 | } |
| 985 | |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 986 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| 987 | enum iscsi_host_param param, char *buf) |
| 988 | { |
| 989 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 990 | int len; |
| 991 | |
| 992 | switch (param) { |
| 993 | case ISCSI_HOST_PARAM_HWADDRESS: |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 994 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 995 | break; |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 996 | case ISCSI_HOST_PARAM_IPADDRESS: |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 997 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 998 | break; |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 999 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
Mike Christie | 2223696 | 2007-05-30 12:57:24 -0500 | [diff] [blame] | 1000 | len = sprintf(buf, "%s\n", ha->name_string); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 1001 | break; |
Vikas Chaudhary | 3254dbe | 2012-01-19 03:06:56 -0800 | [diff] [blame] | 1002 | case ISCSI_HOST_PARAM_PORT_STATE: |
| 1003 | qla4xxx_set_port_state(shost); |
| 1004 | len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost)); |
| 1005 | break; |
| 1006 | case ISCSI_HOST_PARAM_PORT_SPEED: |
| 1007 | qla4xxx_set_port_speed(shost); |
| 1008 | len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost)); |
| 1009 | break; |
Mike Christie | aa1e93a | 2007-05-30 12:57:09 -0500 | [diff] [blame] | 1010 | default: |
| 1011 | return -ENOSYS; |
| 1012 | } |
| 1013 | |
| 1014 | return len; |
| 1015 | } |
| 1016 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1017 | static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
| 1018 | { |
| 1019 | if (ha->iface_ipv4) |
| 1020 | return; |
| 1021 | |
| 1022 | /* IPv4 */ |
| 1023 | ha->iface_ipv4 = iscsi_create_iface(ha->host, |
| 1024 | &qla4xxx_iscsi_transport, |
| 1025 | ISCSI_IFACE_TYPE_IPV4, 0, 0); |
| 1026 | if (!ha->iface_ipv4) |
| 1027 | ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " |
| 1028 | "iface0.\n"); |
| 1029 | } |
| 1030 | |
| 1031 | static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) |
| 1032 | { |
| 1033 | if (!ha->iface_ipv6_0) |
| 1034 | /* IPv6 iface-0 */ |
| 1035 | ha->iface_ipv6_0 = iscsi_create_iface(ha->host, |
| 1036 | &qla4xxx_iscsi_transport, |
| 1037 | ISCSI_IFACE_TYPE_IPV6, 0, |
| 1038 | 0); |
| 1039 | if (!ha->iface_ipv6_0) |
| 1040 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1041 | "iface0.\n"); |
| 1042 | |
| 1043 | if (!ha->iface_ipv6_1) |
| 1044 | /* IPv6 iface-1 */ |
| 1045 | ha->iface_ipv6_1 = iscsi_create_iface(ha->host, |
| 1046 | &qla4xxx_iscsi_transport, |
| 1047 | ISCSI_IFACE_TYPE_IPV6, 1, |
| 1048 | 0); |
| 1049 | if (!ha->iface_ipv6_1) |
| 1050 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| 1051 | "iface1.\n"); |
| 1052 | } |
| 1053 | |
| 1054 | static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) |
| 1055 | { |
| 1056 | if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) |
| 1057 | qla4xxx_create_ipv4_iface(ha); |
| 1058 | |
| 1059 | if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) |
| 1060 | qla4xxx_create_ipv6_iface(ha); |
| 1061 | } |
| 1062 | |
| 1063 | static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) |
| 1064 | { |
| 1065 | if (ha->iface_ipv4) { |
| 1066 | iscsi_destroy_iface(ha->iface_ipv4); |
| 1067 | ha->iface_ipv4 = NULL; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) |
| 1072 | { |
| 1073 | if (ha->iface_ipv6_0) { |
| 1074 | iscsi_destroy_iface(ha->iface_ipv6_0); |
| 1075 | ha->iface_ipv6_0 = NULL; |
| 1076 | } |
| 1077 | if (ha->iface_ipv6_1) { |
| 1078 | iscsi_destroy_iface(ha->iface_ipv6_1); |
| 1079 | ha->iface_ipv6_1 = NULL; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) |
| 1084 | { |
| 1085 | qla4xxx_destroy_ipv4_iface(ha); |
| 1086 | qla4xxx_destroy_ipv6_iface(ha); |
| 1087 | } |
| 1088 | |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1089 | static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
| 1090 | struct iscsi_iface_param_info *iface_param, |
| 1091 | struct addr_ctrl_blk *init_fw_cb) |
| 1092 | { |
| 1093 | /* |
| 1094 | * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. |
| 1095 | * iface_num 1 is valid only for IPv6 Addr. |
| 1096 | */ |
| 1097 | switch (iface_param->param) { |
| 1098 | case ISCSI_NET_PARAM_IPV6_ADDR: |
| 1099 | if (iface_param->iface_num & 0x1) |
| 1100 | /* IPv6 Addr 1 */ |
| 1101 | memcpy(init_fw_cb->ipv6_addr1, iface_param->value, |
| 1102 | sizeof(init_fw_cb->ipv6_addr1)); |
| 1103 | else |
| 1104 | /* IPv6 Addr 0 */ |
| 1105 | memcpy(init_fw_cb->ipv6_addr0, iface_param->value, |
| 1106 | sizeof(init_fw_cb->ipv6_addr0)); |
| 1107 | break; |
| 1108 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| 1109 | if (iface_param->iface_num & 0x1) |
| 1110 | break; |
| 1111 | memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], |
| 1112 | sizeof(init_fw_cb->ipv6_if_id)); |
| 1113 | break; |
| 1114 | case ISCSI_NET_PARAM_IPV6_ROUTER: |
| 1115 | if (iface_param->iface_num & 0x1) |
| 1116 | break; |
| 1117 | memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, |
| 1118 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 1119 | break; |
| 1120 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| 1121 | /* Autocfg applies to even interface */ |
| 1122 | if (iface_param->iface_num & 0x1) |
| 1123 | break; |
| 1124 | |
| 1125 | if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) |
| 1126 | init_fw_cb->ipv6_addtl_opts &= |
| 1127 | cpu_to_le16( |
| 1128 | ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 1129 | else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) |
| 1130 | init_fw_cb->ipv6_addtl_opts |= |
| 1131 | cpu_to_le16( |
| 1132 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| 1133 | else |
| 1134 | ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " |
| 1135 | "IPv6 addr\n"); |
| 1136 | break; |
| 1137 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| 1138 | /* Autocfg applies to even interface */ |
| 1139 | if (iface_param->iface_num & 0x1) |
| 1140 | break; |
| 1141 | |
| 1142 | if (iface_param->value[0] == |
| 1143 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) |
| 1144 | init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( |
| 1145 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 1146 | else if (iface_param->value[0] == |
| 1147 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) |
| 1148 | init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( |
| 1149 | ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| 1150 | else |
| 1151 | ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " |
| 1152 | "IPv6 linklocal addr\n"); |
| 1153 | break; |
| 1154 | case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: |
| 1155 | /* Autocfg applies to even interface */ |
| 1156 | if (iface_param->iface_num & 0x1) |
| 1157 | break; |
| 1158 | |
| 1159 | if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) |
| 1160 | memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, |
| 1161 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| 1162 | break; |
| 1163 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1164 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1165 | init_fw_cb->ipv6_opts |= |
| 1166 | cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1167 | qla4xxx_create_ipv6_iface(ha); |
| 1168 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1169 | init_fw_cb->ipv6_opts &= |
| 1170 | cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & |
| 1171 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1172 | qla4xxx_destroy_ipv6_iface(ha); |
| 1173 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1174 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 1175 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1176 | if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) |
| 1177 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1178 | init_fw_cb->ipv6_vlan_tag = |
| 1179 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 1180 | break; |
| 1181 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 1182 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 1183 | init_fw_cb->ipv6_opts |= |
| 1184 | cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE); |
| 1185 | else |
| 1186 | init_fw_cb->ipv6_opts &= |
| 1187 | cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1188 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 1189 | case ISCSI_NET_PARAM_MTU: |
| 1190 | init_fw_cb->eth_mtu_size = |
| 1191 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 1192 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 1193 | case ISCSI_NET_PARAM_PORT: |
| 1194 | /* Autocfg applies to even interface */ |
| 1195 | if (iface_param->iface_num & 0x1) |
| 1196 | break; |
| 1197 | |
| 1198 | init_fw_cb->ipv6_port = |
| 1199 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 1200 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1201 | default: |
| 1202 | ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", |
| 1203 | iface_param->param); |
| 1204 | break; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, |
| 1209 | struct iscsi_iface_param_info *iface_param, |
| 1210 | struct addr_ctrl_blk *init_fw_cb) |
| 1211 | { |
| 1212 | switch (iface_param->param) { |
| 1213 | case ISCSI_NET_PARAM_IPV4_ADDR: |
| 1214 | memcpy(init_fw_cb->ipv4_addr, iface_param->value, |
| 1215 | sizeof(init_fw_cb->ipv4_addr)); |
| 1216 | break; |
| 1217 | case ISCSI_NET_PARAM_IPV4_SUBNET: |
| 1218 | memcpy(init_fw_cb->ipv4_subnet, iface_param->value, |
| 1219 | sizeof(init_fw_cb->ipv4_subnet)); |
| 1220 | break; |
| 1221 | case ISCSI_NET_PARAM_IPV4_GW: |
| 1222 | memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, |
| 1223 | sizeof(init_fw_cb->ipv4_gw_addr)); |
| 1224 | break; |
| 1225 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| 1226 | if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) |
| 1227 | init_fw_cb->ipv4_tcp_opts |= |
| 1228 | cpu_to_le16(TCPOPT_DHCP_ENABLE); |
| 1229 | else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) |
| 1230 | init_fw_cb->ipv4_tcp_opts &= |
| 1231 | cpu_to_le16(~TCPOPT_DHCP_ENABLE); |
| 1232 | else |
| 1233 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); |
| 1234 | break; |
| 1235 | case ISCSI_NET_PARAM_IFACE_ENABLE: |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1236 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1237 | init_fw_cb->ipv4_ip_opts |= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 1238 | cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1239 | qla4xxx_create_ipv4_iface(ha); |
| 1240 | } else { |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1241 | init_fw_cb->ipv4_ip_opts &= |
Vikas Chaudhary | 2bab08f | 2011-07-25 13:48:39 -0500 | [diff] [blame] | 1242 | cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1243 | 0xFFFF); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 1244 | qla4xxx_destroy_ipv4_iface(ha); |
| 1245 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1246 | break; |
Mike Christie | 2d63673 | 2011-10-11 17:55:11 -0500 | [diff] [blame] | 1247 | case ISCSI_NET_PARAM_VLAN_TAG: |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1248 | if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) |
| 1249 | break; |
Vikas Chaudhary | 6ac73e8 | 2011-07-25 13:48:49 -0500 | [diff] [blame] | 1250 | init_fw_cb->ipv4_vlan_tag = |
| 1251 | cpu_to_be16(*(uint16_t *)iface_param->value); |
| 1252 | break; |
| 1253 | case ISCSI_NET_PARAM_VLAN_ENABLED: |
| 1254 | if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| 1255 | init_fw_cb->ipv4_ip_opts |= |
| 1256 | cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE); |
| 1257 | else |
| 1258 | init_fw_cb->ipv4_ip_opts &= |
| 1259 | cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1260 | break; |
Vikas Chaudhary | 943c157 | 2011-08-01 03:26:13 -0700 | [diff] [blame] | 1261 | case ISCSI_NET_PARAM_MTU: |
| 1262 | init_fw_cb->eth_mtu_size = |
| 1263 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 1264 | break; |
Vikas Chaudhary | 2ada7fc | 2011-08-01 03:26:19 -0700 | [diff] [blame] | 1265 | case ISCSI_NET_PARAM_PORT: |
| 1266 | init_fw_cb->ipv4_port = |
| 1267 | cpu_to_le16(*(uint16_t *)iface_param->value); |
| 1268 | break; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1269 | default: |
| 1270 | ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", |
| 1271 | iface_param->param); |
| 1272 | break; |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | static void |
| 1277 | qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) |
| 1278 | { |
| 1279 | struct addr_ctrl_blk_def *acb; |
| 1280 | acb = (struct addr_ctrl_blk_def *)init_fw_cb; |
| 1281 | memset(acb->reserved1, 0, sizeof(acb->reserved1)); |
| 1282 | memset(acb->reserved2, 0, sizeof(acb->reserved2)); |
| 1283 | memset(acb->reserved3, 0, sizeof(acb->reserved3)); |
| 1284 | memset(acb->reserved4, 0, sizeof(acb->reserved4)); |
| 1285 | memset(acb->reserved5, 0, sizeof(acb->reserved5)); |
| 1286 | memset(acb->reserved6, 0, sizeof(acb->reserved6)); |
| 1287 | memset(acb->reserved7, 0, sizeof(acb->reserved7)); |
| 1288 | memset(acb->reserved8, 0, sizeof(acb->reserved8)); |
| 1289 | memset(acb->reserved9, 0, sizeof(acb->reserved9)); |
| 1290 | memset(acb->reserved10, 0, sizeof(acb->reserved10)); |
| 1291 | memset(acb->reserved11, 0, sizeof(acb->reserved11)); |
| 1292 | memset(acb->reserved12, 0, sizeof(acb->reserved12)); |
| 1293 | memset(acb->reserved13, 0, sizeof(acb->reserved13)); |
| 1294 | memset(acb->reserved14, 0, sizeof(acb->reserved14)); |
| 1295 | memset(acb->reserved15, 0, sizeof(acb->reserved15)); |
| 1296 | } |
| 1297 | |
| 1298 | static int |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 1299 | 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] | 1300 | { |
| 1301 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 1302 | int rval = 0; |
| 1303 | struct iscsi_iface_param_info *iface_param = NULL; |
| 1304 | struct addr_ctrl_blk *init_fw_cb = NULL; |
| 1305 | dma_addr_t init_fw_cb_dma; |
| 1306 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 1307 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 1308 | uint32_t rem = len; |
| 1309 | struct nlattr *attr; |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1310 | |
| 1311 | init_fw_cb = dma_alloc_coherent(&ha->pdev->dev, |
| 1312 | sizeof(struct addr_ctrl_blk), |
| 1313 | &init_fw_cb_dma, GFP_KERNEL); |
| 1314 | if (!init_fw_cb) { |
| 1315 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", |
| 1316 | __func__); |
| 1317 | return -ENOMEM; |
| 1318 | } |
| 1319 | |
| 1320 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 1321 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| 1322 | memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| 1323 | |
| 1324 | if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { |
| 1325 | ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); |
| 1326 | rval = -EIO; |
| 1327 | goto exit_init_fw_cb; |
| 1328 | } |
| 1329 | |
Mike Christie | 00c3188 | 2011-10-06 03:56:59 -0500 | [diff] [blame] | 1330 | nla_for_each_attr(attr, data, len, rem) { |
| 1331 | iface_param = nla_data(attr); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1332 | |
| 1333 | if (iface_param->param_type != ISCSI_NET_PARAM) |
| 1334 | continue; |
| 1335 | |
| 1336 | switch (iface_param->iface_type) { |
| 1337 | case ISCSI_IFACE_TYPE_IPV4: |
| 1338 | switch (iface_param->iface_num) { |
| 1339 | case 0: |
| 1340 | qla4xxx_set_ipv4(ha, iface_param, init_fw_cb); |
| 1341 | break; |
| 1342 | default: |
| 1343 | /* Cannot have more than one IPv4 interface */ |
| 1344 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface " |
| 1345 | "number = %d\n", |
| 1346 | iface_param->iface_num); |
| 1347 | break; |
| 1348 | } |
| 1349 | break; |
| 1350 | case ISCSI_IFACE_TYPE_IPV6: |
| 1351 | switch (iface_param->iface_num) { |
| 1352 | case 0: |
| 1353 | case 1: |
| 1354 | qla4xxx_set_ipv6(ha, iface_param, init_fw_cb); |
| 1355 | break; |
| 1356 | default: |
| 1357 | /* Cannot have more than two IPv6 interface */ |
| 1358 | ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface " |
| 1359 | "number = %d\n", |
| 1360 | iface_param->iface_num); |
| 1361 | break; |
| 1362 | } |
| 1363 | break; |
| 1364 | default: |
| 1365 | ql4_printk(KERN_ERR, ha, "Invalid iface type\n"); |
| 1366 | break; |
| 1367 | } |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); |
| 1371 | |
| 1372 | rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, |
| 1373 | sizeof(struct addr_ctrl_blk), |
| 1374 | FLASH_OPT_RMW_COMMIT); |
| 1375 | if (rval != QLA_SUCCESS) { |
| 1376 | ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", |
| 1377 | __func__); |
| 1378 | rval = -EIO; |
| 1379 | goto exit_init_fw_cb; |
| 1380 | } |
| 1381 | |
Vikas Chaudhary | ce505f9 | 2011-12-01 22:42:10 -0800 | [diff] [blame] | 1382 | rval = qla4xxx_disable_acb(ha); |
| 1383 | if (rval != QLA_SUCCESS) { |
| 1384 | ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n", |
| 1385 | __func__); |
| 1386 | rval = -EIO; |
| 1387 | goto exit_init_fw_cb; |
| 1388 | } |
| 1389 | |
| 1390 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 1391 | DISABLE_ACB_TOV * HZ); |
Mike Christie | d00efe3 | 2011-07-25 13:48:38 -0500 | [diff] [blame] | 1392 | |
| 1393 | qla4xxx_initcb_to_acb(init_fw_cb); |
| 1394 | |
| 1395 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); |
| 1396 | if (rval != QLA_SUCCESS) { |
| 1397 | ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", |
| 1398 | __func__); |
| 1399 | rval = -EIO; |
| 1400 | goto exit_init_fw_cb; |
| 1401 | } |
| 1402 | |
| 1403 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| 1404 | qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, |
| 1405 | init_fw_cb_dma); |
| 1406 | |
| 1407 | exit_init_fw_cb: |
| 1408 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), |
| 1409 | init_fw_cb, init_fw_cb_dma); |
| 1410 | |
| 1411 | return rval; |
| 1412 | } |
| 1413 | |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 1414 | static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess, |
| 1415 | enum iscsi_param param, char *buf) |
| 1416 | { |
| 1417 | struct iscsi_session *sess = cls_sess->dd_data; |
| 1418 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 1419 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 1420 | int rval, len; |
| 1421 | uint16_t idx; |
| 1422 | |
| 1423 | switch (param) { |
| 1424 | case ISCSI_PARAM_CHAP_IN_IDX: |
| 1425 | rval = qla4xxx_get_chap_index(ha, sess->username_in, |
| 1426 | sess->password_in, BIDI_CHAP, |
| 1427 | &idx); |
| 1428 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 1429 | len = sprintf(buf, "\n"); |
| 1430 | else |
| 1431 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 1432 | break; |
| 1433 | case ISCSI_PARAM_CHAP_OUT_IDX: |
| 1434 | rval = qla4xxx_get_chap_index(ha, sess->username, |
| 1435 | sess->password, LOCAL_CHAP, |
| 1436 | &idx); |
| 1437 | if (rval) |
Manish Rangankar | c7a5e0d | 2013-01-20 23:51:04 -0500 | [diff] [blame] | 1438 | len = sprintf(buf, "\n"); |
| 1439 | else |
| 1440 | len = sprintf(buf, "%hu\n", idx); |
Mike Christie | fca9f04 | 2012-02-27 03:08:54 -0800 | [diff] [blame] | 1441 | break; |
| 1442 | default: |
| 1443 | return iscsi_session_get_param(cls_sess, param, buf); |
| 1444 | } |
| 1445 | |
| 1446 | return len; |
| 1447 | } |
| 1448 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1449 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1450 | enum iscsi_param param, char *buf) |
| 1451 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1452 | struct iscsi_conn *conn; |
| 1453 | struct qla_conn *qla_conn; |
| 1454 | struct sockaddr *dst_addr; |
| 1455 | int len = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1456 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1457 | conn = cls_conn->dd_data; |
| 1458 | qla_conn = conn->dd_data; |
Manish Rangankar | d46bdeb1 | 2012-08-07 07:57:13 -0400 | [diff] [blame] | 1459 | dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1460 | |
| 1461 | switch (param) { |
| 1462 | case ISCSI_PARAM_CONN_PORT: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1463 | case ISCSI_PARAM_CONN_ADDRESS: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1464 | return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| 1465 | dst_addr, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1466 | default: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1467 | return iscsi_conn_get_param(cls_conn, param, buf); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | return len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1471 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1474 | int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index) |
| 1475 | { |
| 1476 | uint32_t mbx_sts = 0; |
| 1477 | uint16_t tmp_ddb_index; |
| 1478 | int ret; |
| 1479 | |
| 1480 | get_ddb_index: |
| 1481 | tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES); |
| 1482 | |
| 1483 | if (tmp_ddb_index >= MAX_DDB_ENTRIES) { |
| 1484 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1485 | "Free DDB index not available\n")); |
| 1486 | ret = QLA_ERROR; |
| 1487 | goto exit_get_ddb_index; |
| 1488 | } |
| 1489 | |
| 1490 | if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map)) |
| 1491 | goto get_ddb_index; |
| 1492 | |
| 1493 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1494 | "Found a free DDB index at %d\n", tmp_ddb_index)); |
| 1495 | ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts); |
| 1496 | if (ret == QLA_ERROR) { |
| 1497 | if (mbx_sts == MBOX_STS_COMMAND_ERROR) { |
| 1498 | ql4_printk(KERN_INFO, ha, |
| 1499 | "DDB index = %d not available trying next\n", |
| 1500 | tmp_ddb_index); |
| 1501 | goto get_ddb_index; |
| 1502 | } |
| 1503 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1504 | "Free FW DDB not available\n")); |
| 1505 | } |
| 1506 | |
| 1507 | *ddb_index = tmp_ddb_index; |
| 1508 | |
| 1509 | exit_get_ddb_index: |
| 1510 | return ret; |
| 1511 | } |
| 1512 | |
| 1513 | static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha, |
| 1514 | struct ddb_entry *ddb_entry, |
| 1515 | char *existing_ipaddr, |
| 1516 | char *user_ipaddr) |
| 1517 | { |
| 1518 | uint8_t dst_ipaddr[IPv6_ADDR_LEN]; |
| 1519 | char formatted_ipaddr[DDB_IPADDR_LEN]; |
| 1520 | int status = QLA_SUCCESS, ret = 0; |
| 1521 | |
| 1522 | if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) { |
| 1523 | ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 1524 | '\0', NULL); |
| 1525 | if (ret == 0) { |
| 1526 | status = QLA_ERROR; |
| 1527 | goto out_match; |
| 1528 | } |
| 1529 | ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr); |
| 1530 | } else { |
| 1531 | ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| 1532 | '\0', NULL); |
| 1533 | if (ret == 0) { |
| 1534 | status = QLA_ERROR; |
| 1535 | goto out_match; |
| 1536 | } |
| 1537 | ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr); |
| 1538 | } |
| 1539 | |
| 1540 | if (strcmp(existing_ipaddr, formatted_ipaddr)) |
| 1541 | status = QLA_ERROR; |
| 1542 | |
| 1543 | out_match: |
| 1544 | return status; |
| 1545 | } |
| 1546 | |
| 1547 | static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha, |
| 1548 | struct iscsi_cls_conn *cls_conn) |
| 1549 | { |
| 1550 | int idx = 0, max_ddbs, rval; |
| 1551 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 1552 | struct iscsi_session *sess, *existing_sess; |
| 1553 | struct iscsi_conn *conn, *existing_conn; |
| 1554 | struct ddb_entry *ddb_entry; |
| 1555 | |
| 1556 | sess = cls_sess->dd_data; |
| 1557 | conn = cls_conn->dd_data; |
| 1558 | |
| 1559 | if (sess->targetname == NULL || |
| 1560 | conn->persistent_address == NULL || |
| 1561 | conn->persistent_port == 0) |
| 1562 | return QLA_ERROR; |
| 1563 | |
| 1564 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 1565 | MAX_DEV_DB_ENTRIES; |
| 1566 | |
| 1567 | for (idx = 0; idx < max_ddbs; idx++) { |
| 1568 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 1569 | if (ddb_entry == NULL) |
| 1570 | continue; |
| 1571 | |
| 1572 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 1573 | continue; |
| 1574 | |
| 1575 | existing_sess = ddb_entry->sess->dd_data; |
| 1576 | existing_conn = ddb_entry->conn->dd_data; |
| 1577 | |
| 1578 | if (existing_sess->targetname == NULL || |
| 1579 | existing_conn->persistent_address == NULL || |
| 1580 | existing_conn->persistent_port == 0) |
| 1581 | continue; |
| 1582 | |
| 1583 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1584 | "IQN = %s User IQN = %s\n", |
| 1585 | existing_sess->targetname, |
| 1586 | sess->targetname)); |
| 1587 | |
| 1588 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1589 | "IP = %s User IP = %s\n", |
| 1590 | existing_conn->persistent_address, |
| 1591 | conn->persistent_address)); |
| 1592 | |
| 1593 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1594 | "Port = %d User Port = %d\n", |
| 1595 | existing_conn->persistent_port, |
| 1596 | conn->persistent_port)); |
| 1597 | |
| 1598 | if (strcmp(existing_sess->targetname, sess->targetname)) |
| 1599 | continue; |
| 1600 | rval = qla4xxx_match_ipaddress(ha, ddb_entry, |
| 1601 | existing_conn->persistent_address, |
| 1602 | conn->persistent_address); |
| 1603 | if (rval == QLA_ERROR) |
| 1604 | continue; |
| 1605 | if (existing_conn->persistent_port != conn->persistent_port) |
| 1606 | continue; |
| 1607 | break; |
| 1608 | } |
| 1609 | |
| 1610 | if (idx == max_ddbs) |
| 1611 | return QLA_ERROR; |
| 1612 | |
| 1613 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 1614 | "Match found in fwdb sessions\n")); |
| 1615 | return QLA_SUCCESS; |
| 1616 | } |
| 1617 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1618 | static struct iscsi_cls_session * |
| 1619 | qla4xxx_session_create(struct iscsi_endpoint *ep, |
| 1620 | uint16_t cmds_max, uint16_t qdepth, |
| 1621 | uint32_t initial_cmdsn) |
| 1622 | { |
| 1623 | struct iscsi_cls_session *cls_sess; |
| 1624 | struct scsi_qla_host *ha; |
| 1625 | struct qla_endpoint *qla_ep; |
| 1626 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1627 | uint16_t ddb_index; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1628 | struct iscsi_session *sess; |
| 1629 | struct sockaddr *dst_addr; |
| 1630 | int ret; |
| 1631 | |
| 1632 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1633 | if (!ep) { |
| 1634 | printk(KERN_ERR "qla4xxx: missing ep.\n"); |
| 1635 | return NULL; |
| 1636 | } |
| 1637 | |
| 1638 | qla_ep = ep->dd_data; |
| 1639 | dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| 1640 | ha = to_qla_host(qla_ep->host); |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 1641 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1642 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 1643 | if (ret == QLA_ERROR) |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1644 | return NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1645 | |
| 1646 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host, |
| 1647 | cmds_max, sizeof(struct ddb_entry), |
| 1648 | sizeof(struct ql4_task_data), |
| 1649 | initial_cmdsn, ddb_index); |
| 1650 | if (!cls_sess) |
| 1651 | return NULL; |
| 1652 | |
| 1653 | sess = cls_sess->dd_data; |
| 1654 | ddb_entry = sess->dd_data; |
| 1655 | ddb_entry->fw_ddb_index = ddb_index; |
| 1656 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 1657 | ddb_entry->ha = ha; |
| 1658 | ddb_entry->sess = cls_sess; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1659 | ddb_entry->unblock_sess = qla4xxx_unblock_ddb; |
| 1660 | ddb_entry->ddb_change = qla4xxx_ddb_change; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1661 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 1662 | ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| 1663 | ha->tot_ddbs++; |
| 1664 | |
| 1665 | return cls_sess; |
| 1666 | } |
| 1667 | |
| 1668 | static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess) |
| 1669 | { |
| 1670 | struct iscsi_session *sess; |
| 1671 | struct ddb_entry *ddb_entry; |
| 1672 | struct scsi_qla_host *ha; |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 1673 | unsigned long flags, wtime; |
| 1674 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 1675 | dma_addr_t fw_ddb_entry_dma; |
| 1676 | uint32_t ddb_state; |
| 1677 | int ret; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1678 | |
| 1679 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1680 | sess = cls_sess->dd_data; |
| 1681 | ddb_entry = sess->dd_data; |
| 1682 | ha = ddb_entry->ha; |
| 1683 | |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 1684 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1685 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 1686 | if (!fw_ddb_entry) { |
| 1687 | ql4_printk(KERN_ERR, ha, |
| 1688 | "%s: Unable to allocate dma buffer\n", __func__); |
| 1689 | goto destroy_session; |
| 1690 | } |
| 1691 | |
| 1692 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 1693 | do { |
| 1694 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 1695 | fw_ddb_entry, fw_ddb_entry_dma, |
| 1696 | NULL, NULL, &ddb_state, NULL, |
| 1697 | NULL, NULL); |
| 1698 | if (ret == QLA_ERROR) |
| 1699 | goto destroy_session; |
| 1700 | |
| 1701 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 1702 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 1703 | goto destroy_session; |
| 1704 | |
| 1705 | schedule_timeout_uninterruptible(HZ); |
| 1706 | } while ((time_after(wtime, jiffies))); |
| 1707 | |
| 1708 | destroy_session: |
Manish Rangankar | 736cf36 | 2011-10-07 16:55:46 -0700 | [diff] [blame] | 1709 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 1710 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1711 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1712 | qla4xxx_free_ddb(ha, ddb_entry); |
| 1713 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 1714 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1715 | iscsi_session_teardown(cls_sess); |
Manish Rangankar | 90599b6 | 2012-04-23 22:32:34 -0700 | [diff] [blame] | 1716 | |
| 1717 | if (fw_ddb_entry) |
| 1718 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1719 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1720 | } |
| 1721 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1722 | static struct iscsi_cls_conn * |
| 1723 | qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx) |
| 1724 | { |
| 1725 | struct iscsi_cls_conn *cls_conn; |
| 1726 | struct iscsi_session *sess; |
| 1727 | struct ddb_entry *ddb_entry; |
| 1728 | |
| 1729 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1730 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), |
| 1731 | conn_idx); |
Mike Christie | ff1d031 | 2011-12-01 21:38:43 -0600 | [diff] [blame] | 1732 | if (!cls_conn) |
| 1733 | return NULL; |
| 1734 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1735 | sess = cls_sess->dd_data; |
| 1736 | ddb_entry = sess->dd_data; |
| 1737 | ddb_entry->conn = cls_conn; |
| 1738 | |
| 1739 | return cls_conn; |
| 1740 | } |
| 1741 | |
| 1742 | static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| 1743 | struct iscsi_cls_conn *cls_conn, |
| 1744 | uint64_t transport_fd, int is_leading) |
| 1745 | { |
| 1746 | struct iscsi_conn *conn; |
| 1747 | struct qla_conn *qla_conn; |
| 1748 | struct iscsi_endpoint *ep; |
| 1749 | |
| 1750 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1751 | |
| 1752 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
| 1753 | return -EINVAL; |
| 1754 | ep = iscsi_lookup_endpoint(transport_fd); |
| 1755 | conn = cls_conn->dd_data; |
| 1756 | qla_conn = conn->dd_data; |
| 1757 | qla_conn->qla_ep = ep->dd_data; |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
| 1761 | static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn) |
| 1762 | { |
| 1763 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 1764 | struct iscsi_session *sess; |
| 1765 | struct ddb_entry *ddb_entry; |
| 1766 | struct scsi_qla_host *ha; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1767 | struct dev_db_entry *fw_ddb_entry = NULL; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1768 | dma_addr_t fw_ddb_entry_dma; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1769 | uint32_t mbx_sts = 0; |
| 1770 | int ret = 0; |
| 1771 | int status = QLA_SUCCESS; |
| 1772 | |
| 1773 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1774 | sess = cls_sess->dd_data; |
| 1775 | ddb_entry = sess->dd_data; |
| 1776 | ha = ddb_entry->ha; |
| 1777 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1778 | /* Check if we have matching FW DDB, if yes then do not |
| 1779 | * login to this target. This could cause target to logout previous |
| 1780 | * connection |
| 1781 | */ |
| 1782 | ret = qla4xxx_match_fwdb_session(ha, cls_conn); |
| 1783 | if (ret == QLA_SUCCESS) { |
| 1784 | ql4_printk(KERN_INFO, ha, |
| 1785 | "Session already exist in FW.\n"); |
| 1786 | ret = -EEXIST; |
| 1787 | goto exit_conn_start; |
| 1788 | } |
| 1789 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1790 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1791 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 1792 | if (!fw_ddb_entry) { |
| 1793 | ql4_printk(KERN_ERR, ha, |
| 1794 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1795 | ret = -ENOMEM; |
| 1796 | goto exit_conn_start; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts); |
| 1800 | if (ret) { |
| 1801 | /* If iscsid is stopped and started then no need to do |
| 1802 | * set param again since ddb state will be already |
| 1803 | * active and FW does not allow set ddb to an |
| 1804 | * active session. |
| 1805 | */ |
| 1806 | if (mbx_sts) |
| 1807 | if (ddb_entry->fw_ddb_device_state == |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 1808 | DDB_DS_SESSION_ACTIVE) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1809 | ddb_entry->unblock_sess(ddb_entry->sess); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1810 | goto exit_set_param; |
Manish Rangankar | f922da7 | 2011-10-07 16:55:49 -0700 | [diff] [blame] | 1811 | } |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1812 | |
| 1813 | ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n", |
| 1814 | __func__, ddb_entry->fw_ddb_index); |
| 1815 | goto exit_conn_start; |
| 1816 | } |
| 1817 | |
| 1818 | status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| 1819 | if (status == QLA_ERROR) { |
Manish Rangankar | 0e7e850 | 2011-07-25 13:48:54 -0500 | [diff] [blame] | 1820 | ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| 1821 | sess->targetname); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1822 | ret = -EINVAL; |
| 1823 | goto exit_conn_start; |
| 1824 | } |
| 1825 | |
Manish Rangankar | 98270ab | 2011-10-07 16:55:47 -0700 | [diff] [blame] | 1826 | if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) |
| 1827 | ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| 1828 | |
| 1829 | DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__, |
| 1830 | ddb_entry->fw_ddb_device_state)); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1831 | |
| 1832 | exit_set_param: |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1833 | ret = 0; |
| 1834 | |
| 1835 | exit_conn_start: |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 1836 | if (fw_ddb_entry) |
| 1837 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 1838 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1839 | return ret; |
| 1840 | } |
| 1841 | |
| 1842 | static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| 1843 | { |
| 1844 | struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| 1845 | struct iscsi_session *sess; |
| 1846 | struct scsi_qla_host *ha; |
| 1847 | struct ddb_entry *ddb_entry; |
| 1848 | int options; |
| 1849 | |
| 1850 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 1851 | sess = cls_sess->dd_data; |
| 1852 | ddb_entry = sess->dd_data; |
| 1853 | ha = ddb_entry->ha; |
| 1854 | |
| 1855 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 1856 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) |
| 1857 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | static void qla4xxx_task_work(struct work_struct *wdata) |
| 1861 | { |
| 1862 | struct ql4_task_data *task_data; |
| 1863 | struct scsi_qla_host *ha; |
| 1864 | struct passthru_status *sts; |
| 1865 | struct iscsi_task *task; |
| 1866 | struct iscsi_hdr *hdr; |
| 1867 | uint8_t *data; |
| 1868 | uint32_t data_len; |
| 1869 | struct iscsi_conn *conn; |
| 1870 | int hdr_len; |
| 1871 | itt_t itt; |
| 1872 | |
| 1873 | task_data = container_of(wdata, struct ql4_task_data, task_work); |
| 1874 | ha = task_data->ha; |
| 1875 | task = task_data->task; |
| 1876 | sts = &task_data->sts; |
| 1877 | hdr_len = sizeof(struct iscsi_hdr); |
| 1878 | |
| 1879 | DEBUG3(printk(KERN_INFO "Status returned\n")); |
| 1880 | DEBUG3(qla4xxx_dump_buffer(sts, 64)); |
| 1881 | DEBUG3(printk(KERN_INFO "Response buffer")); |
| 1882 | DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64)); |
| 1883 | |
| 1884 | conn = task->conn; |
| 1885 | |
| 1886 | switch (sts->completionStatus) { |
| 1887 | case PASSTHRU_STATUS_COMPLETE: |
| 1888 | hdr = (struct iscsi_hdr *)task_data->resp_buffer; |
| 1889 | /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */ |
| 1890 | itt = sts->handle; |
| 1891 | hdr->itt = itt; |
| 1892 | data = task_data->resp_buffer + hdr_len; |
| 1893 | data_len = task_data->resp_len - hdr_len; |
| 1894 | iscsi_complete_pdu(conn, hdr, data, data_len); |
| 1895 | break; |
| 1896 | default: |
| 1897 | ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n", |
| 1898 | sts->completionStatus); |
| 1899 | break; |
| 1900 | } |
| 1901 | return; |
| 1902 | } |
| 1903 | |
| 1904 | static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 1905 | { |
| 1906 | struct ql4_task_data *task_data; |
| 1907 | struct iscsi_session *sess; |
| 1908 | struct ddb_entry *ddb_entry; |
| 1909 | struct scsi_qla_host *ha; |
| 1910 | int hdr_len; |
| 1911 | |
| 1912 | sess = task->conn->session; |
| 1913 | ddb_entry = sess->dd_data; |
| 1914 | ha = ddb_entry->ha; |
| 1915 | task_data = task->dd_data; |
| 1916 | memset(task_data, 0, sizeof(struct ql4_task_data)); |
| 1917 | |
| 1918 | if (task->sc) { |
| 1919 | ql4_printk(KERN_INFO, ha, |
| 1920 | "%s: SCSI Commands not implemented\n", __func__); |
| 1921 | return -EINVAL; |
| 1922 | } |
| 1923 | |
| 1924 | hdr_len = sizeof(struct iscsi_hdr); |
| 1925 | task_data->ha = ha; |
| 1926 | task_data->task = task; |
| 1927 | |
| 1928 | if (task->data_count) { |
| 1929 | task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data, |
| 1930 | task->data_count, |
| 1931 | PCI_DMA_TODEVICE); |
| 1932 | } |
| 1933 | |
| 1934 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 1935 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 1936 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1937 | task_data->resp_len = task->conn->max_recv_dlength + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1938 | task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| 1939 | task_data->resp_len, |
| 1940 | &task_data->resp_dma, |
| 1941 | GFP_ATOMIC); |
| 1942 | if (!task_data->resp_buffer) |
| 1943 | goto exit_alloc_pdu; |
| 1944 | |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1945 | task_data->req_len = task->data_count + hdr_len; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1946 | task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev, |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1947 | task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1948 | &task_data->req_dma, |
| 1949 | GFP_ATOMIC); |
| 1950 | if (!task_data->req_buffer) |
| 1951 | goto exit_alloc_pdu; |
| 1952 | |
| 1953 | task->hdr = task_data->req_buffer; |
| 1954 | |
| 1955 | INIT_WORK(&task_data->task_work, qla4xxx_task_work); |
| 1956 | |
| 1957 | return 0; |
| 1958 | |
| 1959 | exit_alloc_pdu: |
| 1960 | if (task_data->resp_buffer) |
| 1961 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 1962 | task_data->resp_buffer, task_data->resp_dma); |
| 1963 | |
| 1964 | if (task_data->req_buffer) |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1965 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1966 | task_data->req_buffer, task_data->req_dma); |
| 1967 | return -ENOMEM; |
| 1968 | } |
| 1969 | |
| 1970 | static void qla4xxx_task_cleanup(struct iscsi_task *task) |
| 1971 | { |
| 1972 | struct ql4_task_data *task_data; |
| 1973 | struct iscsi_session *sess; |
| 1974 | struct ddb_entry *ddb_entry; |
| 1975 | struct scsi_qla_host *ha; |
| 1976 | int hdr_len; |
| 1977 | |
| 1978 | hdr_len = sizeof(struct iscsi_hdr); |
| 1979 | sess = task->conn->session; |
| 1980 | ddb_entry = sess->dd_data; |
| 1981 | ha = ddb_entry->ha; |
| 1982 | task_data = task->dd_data; |
| 1983 | |
| 1984 | if (task->data_count) { |
| 1985 | dma_unmap_single(&ha->pdev->dev, task_data->data_dma, |
| 1986 | task->data_count, PCI_DMA_TODEVICE); |
| 1987 | } |
| 1988 | |
| 1989 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| 1990 | __func__, task->conn->max_recv_dlength, hdr_len)); |
| 1991 | |
| 1992 | dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| 1993 | task_data->resp_buffer, task_data->resp_dma); |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 1994 | dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 1995 | task_data->req_buffer, task_data->req_dma); |
| 1996 | return; |
| 1997 | } |
| 1998 | |
| 1999 | static int qla4xxx_task_xmit(struct iscsi_task *task) |
| 2000 | { |
| 2001 | struct scsi_cmnd *sc = task->sc; |
| 2002 | struct iscsi_session *sess = task->conn->session; |
| 2003 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 2004 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 2005 | |
| 2006 | if (!sc) |
| 2007 | return qla4xxx_send_passthru0(task); |
| 2008 | |
| 2009 | ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n", |
| 2010 | __func__); |
| 2011 | return -ENOSYS; |
| 2012 | } |
| 2013 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 2014 | static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 2015 | struct iscsi_bus_flash_conn *conn, |
| 2016 | struct dev_db_entry *fw_ddb_entry) |
| 2017 | { |
| 2018 | unsigned long options = 0; |
| 2019 | int rc = 0; |
| 2020 | |
| 2021 | options = le16_to_cpu(fw_ddb_entry->options); |
| 2022 | conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options); |
| 2023 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
| 2024 | rc = iscsi_switch_str_param(&sess->portal_type, DEV_TYPE_IPV6); |
| 2025 | if (rc) |
| 2026 | goto exit_copy; |
| 2027 | } else { |
| 2028 | rc = iscsi_switch_str_param(&sess->portal_type, DEV_TYPE_IPV4); |
| 2029 | if (rc) |
| 2030 | goto exit_copy; |
| 2031 | } |
| 2032 | |
| 2033 | sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE, |
| 2034 | &options); |
| 2035 | sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options); |
| 2036 | sess->entry_state = test_bit(OPT_ENTRY_STATE, &options); |
| 2037 | |
| 2038 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 2039 | conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options); |
| 2040 | conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options); |
| 2041 | sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options); |
| 2042 | sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options); |
| 2043 | sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER, |
| 2044 | &options); |
| 2045 | sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options); |
| 2046 | sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options); |
| 2047 | conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options); |
| 2048 | sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN, |
| 2049 | &options); |
| 2050 | sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options); |
| 2051 | sess->discovery_auth_optional = |
| 2052 | test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options); |
| 2053 | if (test_bit(ISCSIOPT_ERL1, &options)) |
| 2054 | sess->erl |= BIT_1; |
| 2055 | if (test_bit(ISCSIOPT_ERL0, &options)) |
| 2056 | sess->erl |= BIT_0; |
| 2057 | |
| 2058 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 2059 | conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options); |
| 2060 | conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options); |
| 2061 | conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options); |
| 2062 | if (test_bit(TCPOPT_TIMER_SCALE3, &options)) |
| 2063 | conn->tcp_timer_scale |= BIT_3; |
| 2064 | if (test_bit(TCPOPT_TIMER_SCALE2, &options)) |
| 2065 | conn->tcp_timer_scale |= BIT_2; |
| 2066 | if (test_bit(TCPOPT_TIMER_SCALE1, &options)) |
| 2067 | conn->tcp_timer_scale |= BIT_1; |
| 2068 | |
| 2069 | conn->tcp_timer_scale >>= 1; |
| 2070 | conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options); |
| 2071 | |
| 2072 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 2073 | conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options); |
| 2074 | |
| 2075 | conn->max_recv_dlength = BYTE_UNITS * |
| 2076 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 2077 | conn->max_xmit_dlength = BYTE_UNITS * |
| 2078 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 2079 | sess->first_burst = BYTE_UNITS * |
| 2080 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 2081 | sess->max_burst = BYTE_UNITS * |
| 2082 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 2083 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 2084 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 2085 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 2086 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 2087 | conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss); |
| 2088 | conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf; |
| 2089 | conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf; |
| 2090 | conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl); |
| 2091 | conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout); |
| 2092 | conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port); |
| 2093 | conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn); |
| 2094 | conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn); |
| 2095 | sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 2096 | sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link); |
| 2097 | sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 2098 | sess->tsid = le16_to_cpu(fw_ddb_entry->tsid); |
| 2099 | |
| 2100 | sess->default_taskmgmt_timeout = |
| 2101 | le16_to_cpu(fw_ddb_entry->def_timeout); |
| 2102 | conn->port = le16_to_cpu(fw_ddb_entry->port); |
| 2103 | |
| 2104 | options = le16_to_cpu(fw_ddb_entry->options); |
| 2105 | conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 2106 | if (!conn->ipaddress) { |
| 2107 | rc = -ENOMEM; |
| 2108 | goto exit_copy; |
| 2109 | } |
| 2110 | |
| 2111 | conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 2112 | if (!conn->redirect_ipaddr) { |
| 2113 | rc = -ENOMEM; |
| 2114 | goto exit_copy; |
| 2115 | } |
| 2116 | |
| 2117 | memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 2118 | memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN); |
| 2119 | |
| 2120 | if (test_bit(OPT_IPV6_DEVICE, &options)) { |
| 2121 | conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos; |
| 2122 | |
| 2123 | conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL); |
| 2124 | if (!conn->link_local_ipv6_addr) { |
| 2125 | rc = -ENOMEM; |
| 2126 | goto exit_copy; |
| 2127 | } |
| 2128 | |
| 2129 | memcpy(conn->link_local_ipv6_addr, |
| 2130 | fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN); |
| 2131 | } else { |
| 2132 | conn->ipv4_tos = fw_ddb_entry->ipv4_tos; |
| 2133 | } |
| 2134 | |
| 2135 | if (fw_ddb_entry->iscsi_name[0]) { |
| 2136 | rc = iscsi_switch_str_param(&sess->targetname, |
| 2137 | (char *)fw_ddb_entry->iscsi_name); |
| 2138 | if (rc) |
| 2139 | goto exit_copy; |
| 2140 | } |
| 2141 | |
| 2142 | if (fw_ddb_entry->iscsi_alias[0]) { |
| 2143 | rc = iscsi_switch_str_param(&sess->targetalias, |
| 2144 | (char *)fw_ddb_entry->iscsi_alias); |
| 2145 | if (rc) |
| 2146 | goto exit_copy; |
| 2147 | } |
| 2148 | |
| 2149 | COPY_ISID(sess->isid, fw_ddb_entry->isid); |
| 2150 | |
| 2151 | exit_copy: |
| 2152 | return rc; |
| 2153 | } |
| 2154 | |
| 2155 | static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess, |
| 2156 | struct iscsi_bus_flash_conn *conn, |
| 2157 | struct dev_db_entry *fw_ddb_entry) |
| 2158 | { |
| 2159 | uint16_t options; |
| 2160 | int rc = 0; |
| 2161 | |
| 2162 | options = le16_to_cpu(fw_ddb_entry->options); |
| 2163 | SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11); |
| 2164 | if (!strncmp(sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 2165 | options |= BIT_8; |
| 2166 | else |
| 2167 | options &= ~BIT_8; |
| 2168 | |
| 2169 | SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6); |
| 2170 | SET_BITVAL(sess->discovery_sess, options, BIT_4); |
| 2171 | SET_BITVAL(sess->entry_state, options, BIT_3); |
| 2172 | fw_ddb_entry->options = cpu_to_le16(options); |
| 2173 | |
| 2174 | options = le16_to_cpu(fw_ddb_entry->iscsi_options); |
| 2175 | SET_BITVAL(conn->hdrdgst_en, options, BIT_13); |
| 2176 | SET_BITVAL(conn->datadgst_en, options, BIT_12); |
| 2177 | SET_BITVAL(sess->imm_data_en, options, BIT_11); |
| 2178 | SET_BITVAL(sess->initial_r2t_en, options, BIT_10); |
| 2179 | SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9); |
| 2180 | SET_BITVAL(sess->pdu_inorder_en, options, BIT_8); |
| 2181 | SET_BITVAL(sess->chap_auth_en, options, BIT_7); |
| 2182 | SET_BITVAL(conn->snack_req_en, options, BIT_6); |
| 2183 | SET_BITVAL(sess->discovery_logout_en, options, BIT_5); |
| 2184 | SET_BITVAL(sess->bidi_chap_en, options, BIT_4); |
| 2185 | SET_BITVAL(sess->discovery_auth_optional, options, BIT_3); |
| 2186 | SET_BITVAL(sess->erl & BIT_1, options, BIT_1); |
| 2187 | SET_BITVAL(sess->erl & BIT_0, options, BIT_0); |
| 2188 | fw_ddb_entry->iscsi_options = cpu_to_le16(options); |
| 2189 | |
| 2190 | options = le16_to_cpu(fw_ddb_entry->tcp_options); |
| 2191 | SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6); |
| 2192 | SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5); |
| 2193 | SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4); |
| 2194 | SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3); |
| 2195 | SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2); |
| 2196 | SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1); |
| 2197 | SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0); |
| 2198 | fw_ddb_entry->tcp_options = cpu_to_le16(options); |
| 2199 | |
| 2200 | options = le16_to_cpu(fw_ddb_entry->ip_options); |
| 2201 | SET_BITVAL(conn->fragment_disable, options, BIT_4); |
| 2202 | fw_ddb_entry->ip_options = cpu_to_le16(options); |
| 2203 | |
| 2204 | fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t); |
| 2205 | fw_ddb_entry->iscsi_max_rcv_data_seg_len = |
| 2206 | cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS); |
| 2207 | fw_ddb_entry->iscsi_max_snd_data_seg_len = |
| 2208 | cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS); |
| 2209 | fw_ddb_entry->iscsi_first_burst_len = |
| 2210 | cpu_to_le16(sess->first_burst / BYTE_UNITS); |
| 2211 | fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst / |
| 2212 | BYTE_UNITS); |
| 2213 | fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait); |
| 2214 | fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain); |
| 2215 | fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt); |
| 2216 | fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size); |
| 2217 | fw_ddb_entry->tcp_xmt_wsf = cpu_to_le16(conn->tcp_xmit_wsf); |
| 2218 | fw_ddb_entry->tcp_rcv_wsf = cpu_to_le16(conn->tcp_recv_wsf); |
| 2219 | fw_ddb_entry->ipv4_tos = conn->ipv4_tos; |
| 2220 | fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label); |
| 2221 | fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout); |
| 2222 | fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port); |
| 2223 | fw_ddb_entry->stat_sn = cpu_to_le16(conn->statsn); |
| 2224 | fw_ddb_entry->exp_stat_sn = cpu_to_le16(conn->exp_statsn); |
| 2225 | fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_type); |
| 2226 | fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx); |
| 2227 | fw_ddb_entry->tsid = cpu_to_le16(sess->tsid); |
| 2228 | fw_ddb_entry->port = cpu_to_le16(conn->port); |
| 2229 | fw_ddb_entry->def_timeout = |
| 2230 | cpu_to_le16(sess->default_taskmgmt_timeout); |
| 2231 | |
| 2232 | if (conn->ipaddress) |
| 2233 | memcpy(fw_ddb_entry->ip_addr, conn->ipaddress, |
| 2234 | sizeof(fw_ddb_entry->ip_addr)); |
| 2235 | |
| 2236 | if (conn->redirect_ipaddr) |
| 2237 | memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr, |
| 2238 | sizeof(fw_ddb_entry->tgt_addr)); |
| 2239 | |
| 2240 | if (conn->link_local_ipv6_addr) |
| 2241 | memcpy(fw_ddb_entry->link_local_ipv6_addr, |
| 2242 | conn->link_local_ipv6_addr, |
| 2243 | sizeof(fw_ddb_entry->link_local_ipv6_addr)); |
| 2244 | |
| 2245 | if (sess->targetname) |
| 2246 | memcpy(fw_ddb_entry->iscsi_name, sess->targetname, |
| 2247 | sizeof(fw_ddb_entry->iscsi_name)); |
| 2248 | |
| 2249 | if (sess->targetalias) |
| 2250 | memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias, |
| 2251 | sizeof(fw_ddb_entry->iscsi_alias)); |
| 2252 | |
| 2253 | COPY_ISID(fw_ddb_entry->isid, sess->isid); |
| 2254 | |
| 2255 | return rc; |
| 2256 | } |
| 2257 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2258 | static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha, |
| 2259 | struct dev_db_entry *fw_ddb_entry, |
| 2260 | struct iscsi_cls_session *cls_sess, |
| 2261 | struct iscsi_cls_conn *cls_conn) |
| 2262 | { |
| 2263 | int buflen = 0; |
| 2264 | struct iscsi_session *sess; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 2265 | struct ddb_entry *ddb_entry; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2266 | struct iscsi_conn *conn; |
| 2267 | char ip_addr[DDB_IPADDR_LEN]; |
| 2268 | uint16_t options = 0; |
| 2269 | |
| 2270 | sess = cls_sess->dd_data; |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 2271 | ddb_entry = sess->dd_data; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2272 | conn = cls_conn->dd_data; |
| 2273 | |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 2274 | ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 2275 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2276 | conn->max_recv_dlength = BYTE_UNITS * |
| 2277 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 2278 | |
| 2279 | conn->max_xmit_dlength = BYTE_UNITS * |
| 2280 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 2281 | |
| 2282 | sess->initial_r2t_en = |
| 2283 | (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 2284 | |
| 2285 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 2286 | |
| 2287 | sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 2288 | |
| 2289 | sess->first_burst = BYTE_UNITS * |
| 2290 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 2291 | |
| 2292 | sess->max_burst = BYTE_UNITS * |
| 2293 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 2294 | |
| 2295 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 2296 | |
| 2297 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 2298 | |
| 2299 | conn->persistent_port = le16_to_cpu(fw_ddb_entry->port); |
| 2300 | |
| 2301 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 2302 | |
| 2303 | options = le16_to_cpu(fw_ddb_entry->options); |
| 2304 | if (options & DDB_OPT_IPV6_DEVICE) |
| 2305 | sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 2306 | else |
| 2307 | sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 2308 | |
| 2309 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME, |
| 2310 | (char *)fw_ddb_entry->iscsi_name, buflen); |
| 2311 | iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME, |
| 2312 | (char *)ha->name_string, buflen); |
| 2313 | iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS, |
| 2314 | (char *)ip_addr, buflen); |
Vikas Chaudhary | 6c1b878 | 2012-01-19 03:06:54 -0800 | [diff] [blame] | 2315 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS, |
| 2316 | (char *)fw_ddb_entry->iscsi_alias, buflen); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha, |
| 2320 | struct ddb_entry *ddb_entry) |
| 2321 | { |
| 2322 | struct iscsi_cls_session *cls_sess; |
| 2323 | struct iscsi_cls_conn *cls_conn; |
| 2324 | uint32_t ddb_state; |
| 2325 | dma_addr_t fw_ddb_entry_dma; |
| 2326 | struct dev_db_entry *fw_ddb_entry; |
| 2327 | |
| 2328 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 2329 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 2330 | if (!fw_ddb_entry) { |
| 2331 | ql4_printk(KERN_ERR, ha, |
| 2332 | "%s: Unable to allocate dma buffer\n", __func__); |
| 2333 | goto exit_session_conn_fwddb_param; |
| 2334 | } |
| 2335 | |
| 2336 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 2337 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 2338 | NULL, NULL, NULL) == QLA_ERROR) { |
| 2339 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 2340 | "get_ddb_entry for fw_ddb_index %d\n", |
| 2341 | ha->host_no, __func__, |
| 2342 | ddb_entry->fw_ddb_index)); |
| 2343 | goto exit_session_conn_fwddb_param; |
| 2344 | } |
| 2345 | |
| 2346 | cls_sess = ddb_entry->sess; |
| 2347 | |
| 2348 | cls_conn = ddb_entry->conn; |
| 2349 | |
| 2350 | /* Update params */ |
| 2351 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 2352 | |
| 2353 | exit_session_conn_fwddb_param: |
| 2354 | if (fw_ddb_entry) |
| 2355 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 2356 | fw_ddb_entry, fw_ddb_entry_dma); |
| 2357 | } |
| 2358 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2359 | void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha, |
| 2360 | struct ddb_entry *ddb_entry) |
| 2361 | { |
| 2362 | struct iscsi_cls_session *cls_sess; |
| 2363 | struct iscsi_cls_conn *cls_conn; |
| 2364 | struct iscsi_session *sess; |
| 2365 | struct iscsi_conn *conn; |
| 2366 | uint32_t ddb_state; |
| 2367 | dma_addr_t fw_ddb_entry_dma; |
| 2368 | struct dev_db_entry *fw_ddb_entry; |
| 2369 | |
| 2370 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 2371 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 2372 | if (!fw_ddb_entry) { |
| 2373 | ql4_printk(KERN_ERR, ha, |
| 2374 | "%s: Unable to allocate dma buffer\n", __func__); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2375 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| 2379 | fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| 2380 | NULL, NULL, NULL) == QLA_ERROR) { |
| 2381 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| 2382 | "get_ddb_entry for fw_ddb_index %d\n", |
| 2383 | ha->host_no, __func__, |
| 2384 | ddb_entry->fw_ddb_index)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2385 | goto exit_session_conn_param; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | cls_sess = ddb_entry->sess; |
| 2389 | sess = cls_sess->dd_data; |
| 2390 | |
| 2391 | cls_conn = ddb_entry->conn; |
| 2392 | conn = cls_conn->dd_data; |
| 2393 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2394 | /* Update timers after login */ |
| 2395 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 2396 | (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) && |
| 2397 | (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ? |
| 2398 | le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2399 | ddb_entry->default_time2wait = |
| 2400 | le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 2401 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2402 | /* Update params */ |
Nilesh Javali | 376738a | 2012-02-27 03:08:52 -0800 | [diff] [blame] | 2403 | ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2404 | conn->max_recv_dlength = BYTE_UNITS * |
| 2405 | le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| 2406 | |
| 2407 | conn->max_xmit_dlength = BYTE_UNITS * |
| 2408 | le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| 2409 | |
| 2410 | sess->initial_r2t_en = |
| 2411 | (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 2412 | |
| 2413 | sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| 2414 | |
| 2415 | sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| 2416 | |
| 2417 | sess->first_burst = BYTE_UNITS * |
| 2418 | le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| 2419 | |
| 2420 | sess->max_burst = BYTE_UNITS * |
| 2421 | le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| 2422 | |
| 2423 | sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| 2424 | |
| 2425 | sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| 2426 | |
| 2427 | sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 2428 | |
| 2429 | memcpy(sess->initiatorname, ha->name_string, |
| 2430 | min(sizeof(ha->name_string), sizeof(sess->initiatorname))); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2431 | |
Vikas Chaudhary | 6c1b878 | 2012-01-19 03:06:54 -0800 | [diff] [blame] | 2432 | iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_ALIAS, |
| 2433 | (char *)fw_ddb_entry->iscsi_alias, 0); |
| 2434 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2435 | exit_session_conn_param: |
| 2436 | if (fw_ddb_entry) |
| 2437 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 2438 | fw_ddb_entry, fw_ddb_entry_dma); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2439 | } |
| 2440 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2441 | /* |
| 2442 | * Timer routines |
| 2443 | */ |
| 2444 | |
| 2445 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, |
| 2446 | unsigned long interval) |
| 2447 | { |
| 2448 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| 2449 | __func__, ha->host->host_no)); |
| 2450 | init_timer(&ha->timer); |
| 2451 | ha->timer.expires = jiffies + interval * HZ; |
| 2452 | ha->timer.data = (unsigned long)ha; |
| 2453 | ha->timer.function = (void (*)(unsigned long))func; |
| 2454 | add_timer(&ha->timer); |
| 2455 | ha->timer_active = 1; |
| 2456 | } |
| 2457 | |
| 2458 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| 2459 | { |
| 2460 | del_timer_sync(&ha->timer); |
| 2461 | ha->timer_active = 0; |
| 2462 | } |
| 2463 | |
| 2464 | /*** |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2465 | * qla4xxx_mark_device_missing - blocks the session |
| 2466 | * @cls_session: Pointer to the session to be blocked |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2467 | * @ddb_entry: Pointer to device database entry |
| 2468 | * |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2469 | * This routine marks a device missing and close connection. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2470 | **/ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2471 | void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2472 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2473 | iscsi_block_session(cls_session); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2476 | /** |
| 2477 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| 2478 | * @ha: Pointer to host adapter structure. |
| 2479 | * |
| 2480 | * This routine marks a device missing and resets the relogin retry count. |
| 2481 | **/ |
| 2482 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| 2483 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2484 | iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2485 | } |
| 2486 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2487 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| 2488 | struct ddb_entry *ddb_entry, |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2489 | struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2490 | { |
| 2491 | struct srb *srb; |
| 2492 | |
| 2493 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| 2494 | if (!srb) |
| 2495 | return srb; |
| 2496 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2497 | kref_init(&srb->srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2498 | srb->ha = ha; |
| 2499 | srb->ddb = ddb_entry; |
| 2500 | srb->cmd = cmd; |
| 2501 | srb->flags = 0; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 2502 | CMD_SP(cmd) = (void *)srb; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2503 | |
| 2504 | return srb; |
| 2505 | } |
| 2506 | |
| 2507 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| 2508 | { |
| 2509 | struct scsi_cmnd *cmd = srb->cmd; |
| 2510 | |
| 2511 | if (srb->flags & SRB_DMA_VALID) { |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 2512 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2513 | srb->flags &= ~SRB_DMA_VALID; |
| 2514 | } |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 2515 | CMD_SP(cmd) = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2518 | void qla4xxx_srb_compl(struct kref *ref) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2519 | { |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2520 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2521 | struct scsi_cmnd *cmd = srb->cmd; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 2522 | struct scsi_qla_host *ha = srb->ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2523 | |
| 2524 | qla4xxx_srb_free_dma(ha, srb); |
| 2525 | |
| 2526 | mempool_free(srb, ha->srb_mempool); |
| 2527 | |
| 2528 | cmd->scsi_done(cmd); |
| 2529 | } |
| 2530 | |
| 2531 | /** |
| 2532 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2533 | * @host: scsi host |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2534 | * @cmd: Pointer to Linux's SCSI command structure |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2535 | * |
| 2536 | * Remarks: |
| 2537 | * This routine is invoked by Linux to send a SCSI command to the driver. |
| 2538 | * The mid-level driver tries to ensure that queuecommand never gets |
| 2539 | * invoked concurrently with itself or the interrupt handler (although |
| 2540 | * the interrupt handler may call this routine as part of request- |
| 2541 | * completion handling). Unfortunely, it sometimes calls the scheduler |
| 2542 | * in interrupt context which is a big NO! NO!. |
| 2543 | **/ |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2544 | static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2545 | { |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2546 | struct scsi_qla_host *ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2547 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 2548 | struct iscsi_cls_session *sess = ddb_entry->sess; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2549 | struct srb *srb; |
| 2550 | int rval; |
| 2551 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2552 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 2553 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| 2554 | cmd->result = DID_NO_CONNECT << 16; |
| 2555 | else |
| 2556 | cmd->result = DID_REQUEUE << 16; |
| 2557 | goto qc_fail_command; |
| 2558 | } |
| 2559 | |
Mike Christie | 7fb1921 | 2008-01-31 13:36:45 -0600 | [diff] [blame] | 2560 | if (!sess) { |
| 2561 | cmd->result = DID_IMM_RETRY << 16; |
| 2562 | goto qc_fail_command; |
| 2563 | } |
| 2564 | |
| 2565 | rval = iscsi_session_chkready(sess); |
| 2566 | if (rval) { |
| 2567 | cmd->result = rval; |
| 2568 | goto qc_fail_command; |
| 2569 | } |
| 2570 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2571 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 2572 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 2573 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 2574 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 2575 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| 2576 | !test_bit(AF_ONLINE, &ha->flags) || |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2577 | !test_bit(AF_LINK_UP, &ha->flags) || |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 2578 | test_bit(AF_LOOPBACK, &ha->flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2579 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 2580 | goto qc_host_busy; |
| 2581 | |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2582 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2583 | if (!srb) |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2584 | goto qc_host_busy; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2585 | |
| 2586 | rval = qla4xxx_send_command_to_isp(ha, srb); |
| 2587 | if (rval != QLA_SUCCESS) |
| 2588 | goto qc_host_busy_free_sp; |
| 2589 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2590 | return 0; |
| 2591 | |
| 2592 | qc_host_busy_free_sp: |
| 2593 | qla4xxx_srb_free_dma(ha, srb); |
| 2594 | mempool_free(srb, ha->srb_mempool); |
| 2595 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2596 | qc_host_busy: |
| 2597 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2598 | |
| 2599 | qc_fail_command: |
Vikas Chaudhary | 8f0722c | 2011-05-17 23:17:10 -0700 | [diff] [blame] | 2600 | cmd->scsi_done(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2601 | |
| 2602 | return 0; |
| 2603 | } |
| 2604 | |
| 2605 | /** |
| 2606 | * qla4xxx_mem_free - frees memory allocated to adapter |
| 2607 | * @ha: Pointer to host adapter structure. |
| 2608 | * |
| 2609 | * Frees memory previously allocated by qla4xxx_mem_alloc |
| 2610 | **/ |
| 2611 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| 2612 | { |
| 2613 | if (ha->queues) |
| 2614 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| 2615 | ha->queues_dma); |
| 2616 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 2617 | if (ha->fw_dump) |
| 2618 | vfree(ha->fw_dump); |
| 2619 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2620 | ha->queues_len = 0; |
| 2621 | ha->queues = NULL; |
| 2622 | ha->queues_dma = 0; |
| 2623 | ha->request_ring = NULL; |
| 2624 | ha->request_dma = 0; |
| 2625 | ha->response_ring = NULL; |
| 2626 | ha->response_dma = 0; |
| 2627 | ha->shadow_regs = NULL; |
| 2628 | ha->shadow_regs_dma = 0; |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 2629 | ha->fw_dump = NULL; |
| 2630 | ha->fw_dump_size = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2631 | |
| 2632 | /* Free srb pool. */ |
| 2633 | if (ha->srb_mempool) |
| 2634 | mempool_destroy(ha->srb_mempool); |
| 2635 | |
| 2636 | ha->srb_mempool = NULL; |
| 2637 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2638 | if (ha->chap_dma_pool) |
| 2639 | dma_pool_destroy(ha->chap_dma_pool); |
| 2640 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 2641 | if (ha->chap_list) |
| 2642 | vfree(ha->chap_list); |
| 2643 | ha->chap_list = NULL; |
| 2644 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2645 | if (ha->fw_ddb_dma_pool) |
| 2646 | dma_pool_destroy(ha->fw_ddb_dma_pool); |
| 2647 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2648 | /* release io space registers */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2649 | if (is_qla8022(ha)) { |
| 2650 | if (ha->nx_pcibase) |
| 2651 | iounmap( |
| 2652 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2653 | } else if (is_qla8032(ha)) { |
| 2654 | if (ha->nx_pcibase) |
| 2655 | iounmap( |
| 2656 | (struct device_reg_83xx __iomem *)ha->nx_pcibase); |
| 2657 | } else if (ha->reg) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2658 | iounmap(ha->reg); |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | if (ha->reset_tmplt.buff) |
| 2662 | vfree(ha->reset_tmplt.buff); |
| 2663 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2664 | pci_release_regions(ha->pdev); |
| 2665 | } |
| 2666 | |
| 2667 | /** |
| 2668 | * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| 2669 | * @ha: Pointer to host adapter structure |
| 2670 | * |
| 2671 | * Allocates DMA memory for request and response queues. Also allocates memory |
| 2672 | * for srbs. |
| 2673 | **/ |
| 2674 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| 2675 | { |
| 2676 | unsigned long align; |
| 2677 | |
| 2678 | /* Allocate contiguous block of DMA memory for queues. */ |
| 2679 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 2680 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| 2681 | sizeof(struct shadow_regs) + |
| 2682 | MEM_ALIGN_VALUE + |
| 2683 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| 2684 | ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, |
| 2685 | &ha->queues_dma, GFP_KERNEL); |
| 2686 | if (ha->queues == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2687 | ql4_printk(KERN_WARNING, ha, |
| 2688 | "Memory Allocation failed - queues.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2689 | |
| 2690 | goto mem_alloc_error_exit; |
| 2691 | } |
| 2692 | memset(ha->queues, 0, ha->queues_len); |
| 2693 | |
| 2694 | /* |
| 2695 | * As per RISC alignment requirements -- the bus-address must be a |
| 2696 | * multiple of the request-ring size (in bytes). |
| 2697 | */ |
| 2698 | align = 0; |
| 2699 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| 2700 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| 2701 | (MEM_ALIGN_VALUE - 1)); |
| 2702 | |
| 2703 | /* Update request and response queue pointers. */ |
| 2704 | ha->request_dma = ha->queues_dma + align; |
| 2705 | ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| 2706 | ha->response_dma = ha->queues_dma + align + |
| 2707 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| 2708 | ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| 2709 | (REQUEST_QUEUE_DEPTH * |
| 2710 | QUEUE_SIZE)); |
| 2711 | ha->shadow_regs_dma = ha->queues_dma + align + |
| 2712 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| 2713 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| 2714 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| 2715 | (REQUEST_QUEUE_DEPTH * |
| 2716 | QUEUE_SIZE) + |
| 2717 | (RESPONSE_QUEUE_DEPTH * |
| 2718 | QUEUE_SIZE)); |
| 2719 | |
| 2720 | /* Allocate memory for srb pool. */ |
| 2721 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| 2722 | mempool_free_slab, srb_cachep); |
| 2723 | if (ha->srb_mempool == NULL) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 2724 | ql4_printk(KERN_WARNING, ha, |
| 2725 | "Memory Allocation failed - SRB Pool.\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2726 | |
| 2727 | goto mem_alloc_error_exit; |
| 2728 | } |
| 2729 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 2730 | ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev, |
| 2731 | CHAP_DMA_BLOCK_SIZE, 8, 0); |
| 2732 | |
| 2733 | if (ha->chap_dma_pool == NULL) { |
| 2734 | ql4_printk(KERN_WARNING, ha, |
| 2735 | "%s: chap_dma_pool allocation failed..\n", __func__); |
| 2736 | goto mem_alloc_error_exit; |
| 2737 | } |
| 2738 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2739 | ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev, |
| 2740 | DDB_DMA_BLOCK_SIZE, 8, 0); |
| 2741 | |
| 2742 | if (ha->fw_ddb_dma_pool == NULL) { |
| 2743 | ql4_printk(KERN_WARNING, ha, |
| 2744 | "%s: fw_ddb_dma_pool allocation failed..\n", |
| 2745 | __func__); |
| 2746 | goto mem_alloc_error_exit; |
| 2747 | } |
| 2748 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2749 | return QLA_SUCCESS; |
| 2750 | |
| 2751 | mem_alloc_error_exit: |
| 2752 | qla4xxx_mem_free(ha); |
| 2753 | return QLA_ERROR; |
| 2754 | } |
| 2755 | |
| 2756 | /** |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 2757 | * qla4_8xxx_check_temp - Check the ISP82XX temperature. |
| 2758 | * @ha: adapter block pointer. |
| 2759 | * |
| 2760 | * Note: The caller should not hold the idc lock. |
| 2761 | **/ |
| 2762 | static int qla4_8xxx_check_temp(struct scsi_qla_host *ha) |
| 2763 | { |
| 2764 | uint32_t temp, temp_state, temp_val; |
| 2765 | int status = QLA_SUCCESS; |
| 2766 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 2767 | temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 2768 | |
| 2769 | temp_state = qla82xx_get_temp_state(temp); |
| 2770 | temp_val = qla82xx_get_temp_val(temp); |
| 2771 | |
| 2772 | if (temp_state == QLA82XX_TEMP_PANIC) { |
| 2773 | ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C" |
| 2774 | " exceeds maximum allowed. Hardware has been shut" |
| 2775 | " down.\n", temp_val); |
| 2776 | status = QLA_ERROR; |
| 2777 | } else if (temp_state == QLA82XX_TEMP_WARN) { |
| 2778 | if (ha->temperature == QLA82XX_TEMP_NORMAL) |
| 2779 | ql4_printk(KERN_WARNING, ha, "Device temperature %d" |
| 2780 | " degrees C exceeds operating range." |
| 2781 | " Immediate action needed.\n", temp_val); |
| 2782 | } else { |
| 2783 | if (ha->temperature == QLA82XX_TEMP_WARN) |
| 2784 | ql4_printk(KERN_INFO, ha, "Device temperature is" |
| 2785 | " now %d degrees C in normal range.\n", |
| 2786 | temp_val); |
| 2787 | } |
| 2788 | ha->temperature = temp_state; |
| 2789 | return status; |
| 2790 | } |
| 2791 | |
| 2792 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2793 | * qla4_8xxx_check_fw_alive - Check firmware health |
| 2794 | * @ha: Pointer to host adapter structure. |
| 2795 | * |
| 2796 | * Context: Interrupt |
| 2797 | **/ |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2798 | static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2799 | { |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2800 | uint32_t fw_heartbeat_counter; |
| 2801 | int status = QLA_SUCCESS; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2802 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 2803 | fw_heartbeat_counter = qla4_8xxx_rd_direct(ha, |
| 2804 | QLA8XXX_PEG_ALIVE_COUNTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2805 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| 2806 | if (fw_heartbeat_counter == 0xffffffff) { |
| 2807 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| 2808 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| 2809 | ha->host_no, __func__)); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2810 | return status; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2811 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2812 | |
| 2813 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| 2814 | ha->seconds_since_last_heartbeat++; |
| 2815 | /* FW not alive after 2 seconds */ |
| 2816 | if (ha->seconds_since_last_heartbeat == 2) { |
| 2817 | ha->seconds_since_last_heartbeat = 0; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2818 | qla4_8xxx_dump_peg_reg(ha); |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2819 | status = QLA_ERROR; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2820 | } |
Lalit Chandivade | 99457d7 | 2010-10-06 22:49:32 -0700 | [diff] [blame] | 2821 | } else |
| 2822 | ha->seconds_since_last_heartbeat = 0; |
| 2823 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2824 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 2825 | return status; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2826 | } |
| 2827 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2828 | static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha) |
| 2829 | { |
| 2830 | uint32_t halt_status; |
| 2831 | int halt_status_unrecoverable = 0; |
| 2832 | |
| 2833 | halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1); |
| 2834 | |
| 2835 | if (is_qla8022(ha)) { |
| 2836 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 2837 | __func__); |
| 2838 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 2839 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 2840 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 2841 | |
| 2842 | if (QLA82XX_FWERROR_CODE(halt_status) == 0x67) |
| 2843 | ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n", |
| 2844 | __func__); |
| 2845 | if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| 2846 | halt_status_unrecoverable = 1; |
| 2847 | } else if (is_qla8032(ha)) { |
| 2848 | if (halt_status & QLA83XX_HALT_STATUS_FW_RESET) |
| 2849 | ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n", |
| 2850 | __func__); |
| 2851 | else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE) |
| 2852 | halt_status_unrecoverable = 1; |
| 2853 | } |
| 2854 | |
| 2855 | /* |
| 2856 | * Since we cannot change dev_state in interrupt context, |
| 2857 | * set appropriate DPC flag then wakeup DPC |
| 2858 | */ |
| 2859 | if (halt_status_unrecoverable) { |
| 2860 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 2861 | } else { |
| 2862 | ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n", |
| 2863 | __func__); |
| 2864 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2865 | } |
| 2866 | qla4xxx_mailbox_premature_completion(ha); |
| 2867 | qla4xxx_wake_dpc(ha); |
| 2868 | } |
| 2869 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2870 | /** |
| 2871 | * qla4_8xxx_watchdog - Poll dev state |
| 2872 | * @ha: Pointer to host adapter structure. |
| 2873 | * |
| 2874 | * Context: Interrupt |
| 2875 | **/ |
| 2876 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| 2877 | { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2878 | uint32_t dev_state; |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 2879 | uint32_t idc_ctrl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2880 | |
| 2881 | /* don't poll if reset is going on */ |
Lalit Chandivade | d56a1f7 | 2010-12-02 22:12:45 -0800 | [diff] [blame] | 2882 | if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| 2883 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
Vikas Chaudhary | 977f46a | 2011-05-17 23:17:08 -0700 | [diff] [blame] | 2884 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 2885 | dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE); |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 2886 | |
| 2887 | if (qla4_8xxx_check_temp(ha)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2888 | if (is_qla8022(ha)) { |
| 2889 | ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n"); |
| 2890 | qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98, |
| 2891 | CRB_NIU_XG_PAUSE_CTL_P0 | |
| 2892 | CRB_NIU_XG_PAUSE_CTL_P1); |
| 2893 | } |
Mike Hernandez | 4f77083 | 2012-01-11 02:44:15 -0800 | [diff] [blame] | 2894 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| 2895 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 2896 | } else if (dev_state == QLA8XXX_DEV_NEED_RESET && |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2897 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6cf9412 | 2013-03-07 05:43:10 -0500 | [diff] [blame] | 2898 | |
| 2899 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n", |
| 2900 | __func__); |
| 2901 | |
| 2902 | if (is_qla8032(ha)) { |
| 2903 | idc_ctrl = qla4_83xx_rd_reg(ha, |
| 2904 | QLA83XX_IDC_DRV_CTRL); |
| 2905 | if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) { |
| 2906 | ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n", |
| 2907 | __func__); |
| 2908 | qla4xxx_mailbox_premature_completion( |
| 2909 | ha); |
| 2910 | } |
| 2911 | } |
| 2912 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2913 | if (is_qla8032(ha) || |
| 2914 | (is_qla8022(ha) && !ql4xdontresethba)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 2915 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 2916 | qla4xxx_wake_dpc(ha); |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 2917 | } |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 2918 | } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2919 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
Vikas Chaudhary | 3930b8c | 2010-12-02 22:12:47 -0800 | [diff] [blame] | 2920 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
| 2921 | __func__); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2922 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| 2923 | qla4xxx_wake_dpc(ha); |
| 2924 | } else { |
| 2925 | /* Check firmware health */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 2926 | if (qla4_8xxx_check_fw_alive(ha)) |
| 2927 | qla4_8xxx_process_fw_error(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2928 | } |
| 2929 | } |
| 2930 | } |
| 2931 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 2932 | 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] | 2933 | { |
| 2934 | struct iscsi_session *sess; |
| 2935 | struct ddb_entry *ddb_entry; |
| 2936 | struct scsi_qla_host *ha; |
| 2937 | |
| 2938 | sess = cls_sess->dd_data; |
| 2939 | ddb_entry = sess->dd_data; |
| 2940 | ha = ddb_entry->ha; |
| 2941 | |
| 2942 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 2943 | return; |
| 2944 | |
| 2945 | if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 2946 | !iscsi_is_session_online(cls_sess)) { |
| 2947 | if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| 2948 | INVALID_ENTRY) { |
| 2949 | if (atomic_read(&ddb_entry->retry_relogin_timer) == |
| 2950 | 0) { |
| 2951 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 2952 | INVALID_ENTRY); |
| 2953 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 2954 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 2955 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2956 | "%s: index [%d] login device\n", |
| 2957 | __func__, ddb_entry->fw_ddb_index)); |
| 2958 | } else |
| 2959 | atomic_dec(&ddb_entry->retry_relogin_timer); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | /* Wait for relogin to timeout */ |
| 2964 | if (atomic_read(&ddb_entry->relogin_timer) && |
| 2965 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| 2966 | /* |
| 2967 | * If the relogin times out and the device is |
| 2968 | * still NOT ONLINE then try and relogin again. |
| 2969 | */ |
| 2970 | if (!iscsi_is_session_online(cls_sess)) { |
| 2971 | /* Reset retry relogin timer */ |
| 2972 | atomic_inc(&ddb_entry->relogin_retry_count); |
| 2973 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 2974 | "%s: index[%d] relogin timed out-retrying" |
| 2975 | " relogin (%d), retry (%d)\n", __func__, |
| 2976 | ddb_entry->fw_ddb_index, |
| 2977 | atomic_read(&ddb_entry->relogin_retry_count), |
| 2978 | ddb_entry->default_time2wait + 4)); |
| 2979 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 2980 | atomic_set(&ddb_entry->retry_relogin_timer, |
| 2981 | ddb_entry->default_time2wait + 4); |
| 2982 | } |
| 2983 | } |
| 2984 | } |
| 2985 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 2986 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2987 | * qla4xxx_timer - checks every second for work to do. |
| 2988 | * @ha: Pointer to host adapter structure. |
| 2989 | **/ |
| 2990 | static void qla4xxx_timer(struct scsi_qla_host *ha) |
| 2991 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2992 | int start_dpc = 0; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2993 | uint16_t w; |
| 2994 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 2995 | iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb); |
| 2996 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 2997 | /* If we are in the middle of AER/EEH processing |
| 2998 | * skip any processing and reschedule the timer |
| 2999 | */ |
| 3000 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 3001 | mod_timer(&ha->timer, jiffies + HZ); |
| 3002 | return; |
| 3003 | } |
| 3004 | |
| 3005 | /* Hardware read to trigger an EEH error during mailbox waits. */ |
| 3006 | if (!pci_channel_offline(ha->pdev)) |
| 3007 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3008 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3009 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3010 | qla4_8xxx_watchdog(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3011 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 3012 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3013 | /* Check for heartbeat interval. */ |
| 3014 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| 3015 | ha->heartbeat_interval != 0) { |
| 3016 | ha->seconds_since_last_heartbeat++; |
| 3017 | if (ha->seconds_since_last_heartbeat > |
| 3018 | ha->heartbeat_interval + 2) |
| 3019 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 3020 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 3023 | /* Process any deferred work. */ |
| 3024 | if (!list_empty(&ha->work_list)) |
| 3025 | start_dpc++; |
| 3026 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3027 | /* Wakeup the dpc routine for this adapter, if needed. */ |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 3028 | if (start_dpc || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3029 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| 3030 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| 3031 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3032 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3033 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| 3034 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 3035 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3036 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| 3037 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 3038 | test_bit(DPC_AEN, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3039 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| 3040 | " - dpc flags = 0x%lx\n", |
| 3041 | ha->host_no, __func__, ha->dpc_flags)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3042 | qla4xxx_wake_dpc(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | /* Reschedule timer thread to call us back in one second */ |
| 3046 | mod_timer(&ha->timer, jiffies + HZ); |
| 3047 | |
| 3048 | DEBUG2(ha->seconds_since_last_intr++); |
| 3049 | } |
| 3050 | |
| 3051 | /** |
| 3052 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| 3053 | * @ha: Pointer to host adapter structure. |
| 3054 | * |
| 3055 | * This routine stalls the driver until all outstanding commands are returned. |
| 3056 | * Caller must release the Hardware Lock prior to calling this routine. |
| 3057 | **/ |
| 3058 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| 3059 | { |
| 3060 | uint32_t index = 0; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3061 | unsigned long flags; |
| 3062 | struct scsi_cmnd *cmd; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3063 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3064 | unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
| 3065 | |
| 3066 | DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " |
| 3067 | "complete\n", WAIT_CMD_TOV)); |
| 3068 | |
| 3069 | while (!time_after_eq(jiffies, wtime)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3070 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3071 | /* Find a command that hasn't completed. */ |
| 3072 | for (index = 0; index < ha->host->can_queue; index++) { |
| 3073 | cmd = scsi_host_find_tag(ha->host, index); |
Mike Christie | a1e0063 | 2010-10-26 05:45:30 -0700 | [diff] [blame] | 3074 | /* |
| 3075 | * We cannot just check if the index is valid, |
| 3076 | * becase if we are run from the scsi eh, then |
| 3077 | * the scsi/block layer is going to prevent |
| 3078 | * the tag from being released. |
| 3079 | */ |
| 3080 | if (cmd != NULL && CMD_SP(cmd)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3081 | break; |
| 3082 | } |
| 3083 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3084 | |
| 3085 | /* If No Commands are pending, wait is complete */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3086 | if (index == ha->host->can_queue) |
| 3087 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3088 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3089 | msleep(1000); |
| 3090 | } |
| 3091 | /* If we timed out on waiting for commands to come back |
| 3092 | * return ERROR. */ |
| 3093 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3094 | } |
| 3095 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3096 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3097 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3098 | uint32_t ctrl_status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3099 | unsigned long flags = 0; |
| 3100 | |
| 3101 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3102 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3103 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| 3104 | return QLA_ERROR; |
| 3105 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3106 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3107 | |
| 3108 | /* |
| 3109 | * If the SCSI Reset Interrupt bit is set, clear it. |
| 3110 | * Otherwise, the Soft Reset won't work. |
| 3111 | */ |
| 3112 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 3113 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| 3114 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 3115 | |
| 3116 | /* Issue Soft Reset */ |
| 3117 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| 3118 | readl(&ha->reg->ctrl_status); |
| 3119 | |
| 3120 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3121 | return QLA_SUCCESS; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | /** |
| 3125 | * qla4xxx_soft_reset - performs soft reset. |
| 3126 | * @ha: Pointer to host adapter structure. |
| 3127 | **/ |
| 3128 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| 3129 | { |
| 3130 | uint32_t max_wait_time; |
| 3131 | unsigned long flags = 0; |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 3132 | int status; |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3133 | uint32_t ctrl_status; |
| 3134 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 3135 | status = qla4xxx_hw_reset(ha); |
| 3136 | if (status != QLA_SUCCESS) |
| 3137 | return status; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3138 | |
Vikas Chaudhary | f931c53 | 2010-10-06 22:48:07 -0700 | [diff] [blame] | 3139 | status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3140 | /* Wait until the Network Reset Intr bit is cleared */ |
| 3141 | max_wait_time = RESET_INTR_TOV; |
| 3142 | do { |
| 3143 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3144 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 3145 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3146 | |
| 3147 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| 3148 | break; |
| 3149 | |
| 3150 | msleep(1000); |
| 3151 | } while ((--max_wait_time)); |
| 3152 | |
| 3153 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| 3154 | DEBUG2(printk(KERN_WARNING |
| 3155 | "scsi%ld: Network Reset Intr not cleared by " |
| 3156 | "Network function, clearing it now!\n", |
| 3157 | ha->host_no)); |
| 3158 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3159 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| 3160 | readl(&ha->reg->ctrl_status); |
| 3161 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3162 | } |
| 3163 | |
| 3164 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 3165 | max_wait_time = SOFT_RESET_TOV; |
| 3166 | do { |
| 3167 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3168 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 3169 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3170 | |
| 3171 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| 3172 | status = QLA_SUCCESS; |
| 3173 | break; |
| 3174 | } |
| 3175 | |
| 3176 | msleep(1000); |
| 3177 | } while ((--max_wait_time)); |
| 3178 | |
| 3179 | /* |
| 3180 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| 3181 | * after the soft reset has taken place. |
| 3182 | */ |
| 3183 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3184 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 3185 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| 3186 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| 3187 | readl(&ha->reg->ctrl_status); |
| 3188 | } |
| 3189 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3190 | |
| 3191 | /* If soft reset fails then most probably the bios on other |
| 3192 | * function is also enabled. |
| 3193 | * Since the initialization is sequential the other fn |
| 3194 | * wont be able to acknowledge the soft reset. |
| 3195 | * Issue a force soft reset to workaround this scenario. |
| 3196 | */ |
| 3197 | if (max_wait_time == 0) { |
| 3198 | /* Issue Force Soft Reset */ |
| 3199 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3200 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| 3201 | readl(&ha->reg->ctrl_status); |
| 3202 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3203 | /* Wait until the firmware tells us the Soft Reset is done */ |
| 3204 | max_wait_time = SOFT_RESET_TOV; |
| 3205 | do { |
| 3206 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3207 | ctrl_status = readw(&ha->reg->ctrl_status); |
| 3208 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3209 | |
| 3210 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| 3211 | status = QLA_SUCCESS; |
| 3212 | break; |
| 3213 | } |
| 3214 | |
| 3215 | msleep(1000); |
| 3216 | } while ((--max_wait_time)); |
| 3217 | } |
| 3218 | |
| 3219 | return status; |
| 3220 | } |
| 3221 | |
| 3222 | /** |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3223 | * 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] | 3224 | * @ha: Pointer to host adapter structure. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3225 | * @res: returned scsi status |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3226 | * |
| 3227 | * This routine is called just prior to a HARD RESET to return all |
| 3228 | * outstanding commands back to the Operating System. |
| 3229 | * Caller should make sure that the following locks are released |
| 3230 | * before this calling routine: Hardware lock, and io_request_lock. |
| 3231 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3232 | 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] | 3233 | { |
| 3234 | struct srb *srb; |
| 3235 | int i; |
| 3236 | unsigned long flags; |
| 3237 | |
| 3238 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3239 | for (i = 0; i < ha->host->can_queue; i++) { |
| 3240 | srb = qla4xxx_del_from_active_array(ha, i); |
| 3241 | if (srb != NULL) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3242 | srb->cmd->result = res; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 3243 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3249 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| 3250 | { |
| 3251 | clear_bit(AF_ONLINE, &ha->flags); |
| 3252 | |
| 3253 | /* Disable the board */ |
| 3254 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3255 | |
| 3256 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 3257 | qla4xxx_mark_all_devices_missing(ha); |
| 3258 | clear_bit(AF_INIT_DONE, &ha->flags); |
| 3259 | } |
| 3260 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3261 | static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session) |
| 3262 | { |
| 3263 | struct iscsi_session *sess; |
| 3264 | struct ddb_entry *ddb_entry; |
| 3265 | |
| 3266 | sess = cls_session->dd_data; |
| 3267 | ddb_entry = sess->dd_data; |
| 3268 | ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3269 | |
| 3270 | if (ddb_entry->ddb_type == FLASH_DDB) |
| 3271 | iscsi_block_session(ddb_entry->sess); |
| 3272 | else |
| 3273 | iscsi_session_failure(cls_session->dd_data, |
| 3274 | ISCSI_ERR_CONN_FAILED); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3275 | } |
| 3276 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3277 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3278 | * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| 3279 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3280 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3281 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3282 | { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3283 | int status = QLA_ERROR; |
| 3284 | uint8_t reset_chip = 0; |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 3285 | uint32_t dev_state; |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 3286 | unsigned long wait; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3287 | |
| 3288 | /* Stall incoming I/O until we are done */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3289 | scsi_block_requests(ha->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3290 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3291 | clear_bit(AF_LINK_UP, &ha->flags); |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 3292 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3293 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3294 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3295 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3296 | |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 3297 | if (is_qla8032(ha) && |
| 3298 | !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 3299 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 3300 | __func__); |
| 3301 | /* disable pause frame for ISP83xx */ |
| 3302 | qla4_83xx_disable_pause(ha); |
| 3303 | } |
| 3304 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3305 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
| 3306 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3307 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 3308 | reset_chip = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3309 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3310 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| 3311 | * do not reset adapter, jump to initialize_adapter */ |
| 3312 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| 3313 | status = QLA_SUCCESS; |
| 3314 | goto recover_ha_init_adapter; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3317 | /* For the ISP-8xxx adapter, issue a stop_firmware if invoked |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3318 | * from eh_host_reset or ioctl module */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3319 | if (is_qla80XX(ha) && !reset_chip && |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3320 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| 3321 | |
| 3322 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3323 | "scsi%ld: %s - Performing stop_firmware...\n", |
| 3324 | ha->host_no, __func__)); |
| 3325 | status = ha->isp_ops->reset_firmware(ha); |
| 3326 | if (status == QLA_SUCCESS) { |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 3327 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 3328 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 3329 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3330 | ha->isp_ops->disable_intrs(ha); |
| 3331 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 3332 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 3333 | } else { |
| 3334 | /* If the stop_firmware fails then |
| 3335 | * reset the entire chip */ |
| 3336 | reset_chip = 1; |
| 3337 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 3338 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | /* Issue full chip reset if recovering from a catastrophic error, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3343 | * or if stop_firmware fails for ISP-8xxx. |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3344 | * This is the default case for ISP-4xxx */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 3345 | if (is_qla40XX(ha) || reset_chip) { |
| 3346 | if (is_qla40XX(ha)) |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 3347 | goto chip_reset; |
| 3348 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3349 | /* Check if 8XXX firmware is alive or not |
Shyam Sunder | 9ee91a3 | 2011-12-01 22:42:13 -0800 | [diff] [blame] | 3350 | * We may have arrived here from NEED_RESET |
| 3351 | * detection only */ |
| 3352 | if (test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 3353 | goto chip_reset; |
| 3354 | |
| 3355 | wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ); |
| 3356 | while (time_before(jiffies, wait)) { |
| 3357 | if (qla4_8xxx_check_fw_alive(ha)) { |
| 3358 | qla4xxx_mailbox_premature_completion(ha); |
| 3359 | break; |
| 3360 | } |
| 3361 | |
| 3362 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 3363 | schedule_timeout(HZ); |
| 3364 | } |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 3365 | chip_reset: |
Nilesh Javali | 2bd1e2b | 2010-10-06 22:49:20 -0700 | [diff] [blame] | 3366 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| 3367 | qla4xxx_cmd_wait(ha); |
Vikas Chaudhary | da10621 | 2012-08-22 07:45:26 -0400 | [diff] [blame] | 3368 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3369 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 3370 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| 3371 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3372 | "scsi%ld: %s - Performing chip reset..\n", |
| 3373 | ha->host_no, __func__)); |
| 3374 | status = ha->isp_ops->reset_chip(ha); |
| 3375 | } |
| 3376 | |
| 3377 | /* Flush any pending ddb changed AENs */ |
| 3378 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| 3379 | |
| 3380 | recover_ha_init_adapter: |
| 3381 | /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| 3382 | if (status == QLA_SUCCESS) { |
| 3383 | /* For ISP-4xxx, force function 1 to always initialize |
| 3384 | * before function 3 to prevent both funcions from |
| 3385 | * stepping on top of the other */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 3386 | if (is_qla40XX(ha) && (ha->mac_index == 3)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3387 | ssleep(6); |
| 3388 | |
| 3389 | /* NOTE: AF_ONLINE flag set upon successful completion of |
| 3390 | * qla4xxx_initialize_adapter */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3391 | status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | /* Retry failed adapter initialization, if necessary |
| 3395 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| 3396 | * case to prevent ping-pong resets between functions */ |
| 3397 | if (!test_bit(AF_ONLINE, &ha->flags) && |
| 3398 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3399 | /* Adapter initialization failed, see if we can retry |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3400 | * resetting the ha. |
| 3401 | * Since we don't want to block the DPC for too long |
| 3402 | * with multiple resets in the same thread, |
| 3403 | * utilize DPC to retry */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3404 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 3405 | ha->isp_ops->idc_lock(ha); |
| 3406 | dev_state = qla4_8xxx_rd_direct(ha, |
| 3407 | QLA8XXX_CRB_DEV_STATE); |
| 3408 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 3409 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 3410 | ql4_printk(KERN_INFO, ha, "%s: don't retry " |
| 3411 | "recover adapter. H/W is in Failed " |
| 3412 | "state\n", __func__); |
| 3413 | qla4xxx_dead_adapter_cleanup(ha); |
| 3414 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 3415 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 3416 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| 3417 | &ha->dpc_flags); |
| 3418 | status = QLA_ERROR; |
| 3419 | |
| 3420 | goto exit_recover; |
| 3421 | } |
| 3422 | } |
| 3423 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3424 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| 3425 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| 3426 | DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| 3427 | "(%d) more times\n", ha->host_no, |
| 3428 | ha->retry_reset_ha_cnt)); |
| 3429 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 3430 | status = QLA_ERROR; |
| 3431 | } else { |
| 3432 | if (ha->retry_reset_ha_cnt > 0) { |
| 3433 | /* Schedule another Reset HA--DPC will retry */ |
| 3434 | ha->retry_reset_ha_cnt--; |
| 3435 | DEBUG2(printk("scsi%ld: recover adapter - " |
| 3436 | "retry remaining %d\n", |
| 3437 | ha->host_no, |
| 3438 | ha->retry_reset_ha_cnt)); |
| 3439 | status = QLA_ERROR; |
| 3440 | } |
| 3441 | |
| 3442 | if (ha->retry_reset_ha_cnt == 0) { |
| 3443 | /* Recover adapter retries have been exhausted. |
| 3444 | * Adapter DEAD */ |
| 3445 | DEBUG2(printk("scsi%ld: recover adapter " |
| 3446 | "failed - board disabled\n", |
| 3447 | ha->host_no)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3448 | qla4xxx_dead_adapter_cleanup(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3449 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 3450 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3451 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3452 | &ha->dpc_flags); |
| 3453 | status = QLA_ERROR; |
| 3454 | } |
| 3455 | } |
| 3456 | } else { |
| 3457 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3458 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3459 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| 3460 | } |
| 3461 | |
Sarang Radke | 8e0f3a6 | 2011-12-01 22:42:09 -0800 | [diff] [blame] | 3462 | exit_recover: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3463 | ha->adapter_error_count++; |
| 3464 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3465 | if (test_bit(AF_ONLINE, &ha->flags)) |
| 3466 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3467 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3468 | scsi_unblock_requests(ha->host); |
| 3469 | |
| 3470 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 3471 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3472 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3473 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3474 | return status; |
| 3475 | } |
| 3476 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3477 | static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session) |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 3478 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3479 | struct iscsi_session *sess; |
| 3480 | struct ddb_entry *ddb_entry; |
| 3481 | struct scsi_qla_host *ha; |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 3482 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3483 | sess = cls_session->dd_data; |
| 3484 | ddb_entry = sess->dd_data; |
| 3485 | ha = ddb_entry->ha; |
| 3486 | if (!iscsi_is_session_online(cls_session)) { |
| 3487 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| 3488 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 3489 | " unblock session\n", ha->host_no, __func__, |
| 3490 | ddb_entry->fw_ddb_index); |
| 3491 | iscsi_unblock_session(ddb_entry->sess); |
| 3492 | } else { |
| 3493 | /* Trigger relogin */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3494 | if (ddb_entry->ddb_type == FLASH_DDB) { |
| 3495 | if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) |
| 3496 | qla4xxx_arm_relogin_timer(ddb_entry); |
| 3497 | } else |
| 3498 | iscsi_session_failure(cls_session->dd_data, |
| 3499 | ISCSI_ERR_CONN_FAILED); |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | } |
| 3503 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3504 | int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session) |
| 3505 | { |
| 3506 | struct iscsi_session *sess; |
| 3507 | struct ddb_entry *ddb_entry; |
| 3508 | struct scsi_qla_host *ha; |
| 3509 | |
| 3510 | sess = cls_session->dd_data; |
| 3511 | ddb_entry = sess->dd_data; |
| 3512 | ha = ddb_entry->ha; |
| 3513 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 3514 | " unblock session\n", ha->host_no, __func__, |
| 3515 | ddb_entry->fw_ddb_index); |
| 3516 | |
| 3517 | iscsi_unblock_session(ddb_entry->sess); |
| 3518 | |
| 3519 | /* Start scan target */ |
| 3520 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 3521 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 3522 | " start scan\n", ha->host_no, __func__, |
| 3523 | ddb_entry->fw_ddb_index); |
| 3524 | scsi_queue_work(ha->host, &ddb_entry->sess->scan_work); |
| 3525 | } |
| 3526 | return QLA_SUCCESS; |
| 3527 | } |
| 3528 | |
| 3529 | int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session) |
| 3530 | { |
| 3531 | struct iscsi_session *sess; |
| 3532 | struct ddb_entry *ddb_entry; |
| 3533 | struct scsi_qla_host *ha; |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 3534 | int status = QLA_SUCCESS; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3535 | |
| 3536 | sess = cls_session->dd_data; |
| 3537 | ddb_entry = sess->dd_data; |
| 3538 | ha = ddb_entry->ha; |
| 3539 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| 3540 | " unblock user space session\n", ha->host_no, __func__, |
| 3541 | ddb_entry->fw_ddb_index); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3542 | |
Manish Rangankar | 80c53e6 | 2012-08-07 07:57:15 -0400 | [diff] [blame] | 3543 | if (!iscsi_is_session_online(cls_session)) { |
| 3544 | iscsi_conn_start(ddb_entry->conn); |
| 3545 | iscsi_conn_login_event(ddb_entry->conn, |
| 3546 | ISCSI_CONN_STATE_LOGGED_IN); |
| 3547 | } else { |
| 3548 | ql4_printk(KERN_INFO, ha, |
| 3549 | "scsi%ld: %s: ddb[%d] session [%d] already logged in\n", |
| 3550 | ha->host_no, __func__, ddb_entry->fw_ddb_index, |
| 3551 | cls_session->sid); |
| 3552 | status = QLA_ERROR; |
| 3553 | } |
| 3554 | |
| 3555 | return status; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3556 | } |
| 3557 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3558 | static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
| 3559 | { |
| 3560 | iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices); |
| 3561 | } |
| 3562 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3563 | static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| 3564 | { |
| 3565 | uint16_t relogin_timer; |
| 3566 | struct iscsi_session *sess; |
| 3567 | struct ddb_entry *ddb_entry; |
| 3568 | struct scsi_qla_host *ha; |
| 3569 | |
| 3570 | sess = cls_sess->dd_data; |
| 3571 | ddb_entry = sess->dd_data; |
| 3572 | ha = ddb_entry->ha; |
| 3573 | |
| 3574 | relogin_timer = max(ddb_entry->default_relogin_timeout, |
| 3575 | (uint16_t)RELOGIN_TOV); |
| 3576 | atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| 3577 | |
| 3578 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3579 | "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no, |
| 3580 | ddb_entry->fw_ddb_index, relogin_timer)); |
| 3581 | |
| 3582 | qla4xxx_login_flash_ddb(cls_sess); |
| 3583 | } |
| 3584 | |
| 3585 | static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess) |
| 3586 | { |
| 3587 | struct iscsi_session *sess; |
| 3588 | struct ddb_entry *ddb_entry; |
| 3589 | struct scsi_qla_host *ha; |
| 3590 | |
| 3591 | sess = cls_sess->dd_data; |
| 3592 | ddb_entry = sess->dd_data; |
| 3593 | ha = ddb_entry->ha; |
| 3594 | |
| 3595 | if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| 3596 | return; |
| 3597 | |
| 3598 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| 3599 | !iscsi_is_session_online(cls_sess)) { |
| 3600 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 3601 | "relogin issued\n")); |
| 3602 | qla4xxx_relogin_flash_ddb(cls_sess); |
| 3603 | } |
| 3604 | } |
| 3605 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3606 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| 3607 | { |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 3608 | if (ha->dpc_thread) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3609 | queue_work(ha->dpc_thread, &ha->dpc_work); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3610 | } |
| 3611 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 3612 | static struct qla4_work_evt * |
| 3613 | qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size, |
| 3614 | enum qla4_work_type type) |
| 3615 | { |
| 3616 | struct qla4_work_evt *e; |
| 3617 | uint32_t size = sizeof(struct qla4_work_evt) + data_size; |
| 3618 | |
| 3619 | e = kzalloc(size, GFP_ATOMIC); |
| 3620 | if (!e) |
| 3621 | return NULL; |
| 3622 | |
| 3623 | INIT_LIST_HEAD(&e->list); |
| 3624 | e->type = type; |
| 3625 | return e; |
| 3626 | } |
| 3627 | |
| 3628 | static void qla4xxx_post_work(struct scsi_qla_host *ha, |
| 3629 | struct qla4_work_evt *e) |
| 3630 | { |
| 3631 | unsigned long flags; |
| 3632 | |
| 3633 | spin_lock_irqsave(&ha->work_lock, flags); |
| 3634 | list_add_tail(&e->list, &ha->work_list); |
| 3635 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 3636 | qla4xxx_wake_dpc(ha); |
| 3637 | } |
| 3638 | |
| 3639 | int qla4xxx_post_aen_work(struct scsi_qla_host *ha, |
| 3640 | enum iscsi_host_event_code aen_code, |
| 3641 | uint32_t data_size, uint8_t *data) |
| 3642 | { |
| 3643 | struct qla4_work_evt *e; |
| 3644 | |
| 3645 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN); |
| 3646 | if (!e) |
| 3647 | return QLA_ERROR; |
| 3648 | |
| 3649 | e->u.aen.code = aen_code; |
| 3650 | e->u.aen.data_size = data_size; |
| 3651 | memcpy(e->u.aen.data, data, data_size); |
| 3652 | |
| 3653 | qla4xxx_post_work(ha, e); |
| 3654 | |
| 3655 | return QLA_SUCCESS; |
| 3656 | } |
| 3657 | |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 3658 | int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha, |
| 3659 | uint32_t status, uint32_t pid, |
| 3660 | uint32_t data_size, uint8_t *data) |
| 3661 | { |
| 3662 | struct qla4_work_evt *e; |
| 3663 | |
| 3664 | e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS); |
| 3665 | if (!e) |
| 3666 | return QLA_ERROR; |
| 3667 | |
| 3668 | e->u.ping.status = status; |
| 3669 | e->u.ping.pid = pid; |
| 3670 | e->u.ping.data_size = data_size; |
| 3671 | memcpy(e->u.ping.data, data, data_size); |
| 3672 | |
| 3673 | qla4xxx_post_work(ha, e); |
| 3674 | |
| 3675 | return QLA_SUCCESS; |
| 3676 | } |
| 3677 | |
Vikas Chaudhary | a7380a6 | 2012-02-27 03:08:56 -0800 | [diff] [blame] | 3678 | static void qla4xxx_do_work(struct scsi_qla_host *ha) |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 3679 | { |
| 3680 | struct qla4_work_evt *e, *tmp; |
| 3681 | unsigned long flags; |
| 3682 | LIST_HEAD(work); |
| 3683 | |
| 3684 | spin_lock_irqsave(&ha->work_lock, flags); |
| 3685 | list_splice_init(&ha->work_list, &work); |
| 3686 | spin_unlock_irqrestore(&ha->work_lock, flags); |
| 3687 | |
| 3688 | list_for_each_entry_safe(e, tmp, &work, list) { |
| 3689 | list_del_init(&e->list); |
| 3690 | |
| 3691 | switch (e->type) { |
| 3692 | case QLA4_EVENT_AEN: |
| 3693 | iscsi_post_host_event(ha->host_no, |
| 3694 | &qla4xxx_iscsi_transport, |
| 3695 | e->u.aen.code, |
| 3696 | e->u.aen.data_size, |
| 3697 | e->u.aen.data); |
| 3698 | break; |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 3699 | case QLA4_EVENT_PING_STATUS: |
| 3700 | iscsi_ping_comp_event(ha->host_no, |
| 3701 | &qla4xxx_iscsi_transport, |
| 3702 | e->u.ping.status, |
| 3703 | e->u.ping.pid, |
| 3704 | e->u.ping.data_size, |
| 3705 | e->u.ping.data); |
| 3706 | break; |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 3707 | default: |
| 3708 | ql4_printk(KERN_WARNING, ha, "event type: 0x%x not " |
| 3709 | "supported", e->type); |
| 3710 | } |
| 3711 | kfree(e); |
| 3712 | } |
| 3713 | } |
| 3714 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3715 | /** |
| 3716 | * qla4xxx_do_dpc - dpc routine |
| 3717 | * @data: in our case pointer to adapter structure |
| 3718 | * |
| 3719 | * This routine is a task that is schedule by the interrupt handler |
| 3720 | * to perform the background processing for interrupts. We put it |
| 3721 | * on a task queue that is consumed whenever the scheduler runs; that's |
| 3722 | * so you can do anything (i.e. put the process to sleep etc). In fact, |
| 3723 | * the mid-level tries to sleep when it reaches the driver threshold |
| 3724 | * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| 3725 | **/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3726 | static void qla4xxx_do_dpc(struct work_struct *work) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3727 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3728 | struct scsi_qla_host *ha = |
| 3729 | container_of(work, struct scsi_qla_host, dpc_work); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3730 | int status = QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3731 | |
David C Somayajulu | f26b904 | 2006-11-15 16:41:09 -0800 | [diff] [blame] | 3732 | DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3733 | "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| 3734 | ha->host_no, __func__, ha->flags, ha->dpc_flags)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3735 | |
| 3736 | /* Initialization not yet finished. Don't do anything yet. */ |
| 3737 | if (!test_bit(AF_INIT_DONE, &ha->flags)) |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 3738 | return; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3739 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 3740 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| 3741 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| 3742 | ha->host_no, __func__, ha->flags)); |
Lalit Chandivade | 1b46807 | 2011-05-17 23:17:09 -0700 | [diff] [blame] | 3743 | return; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 3744 | } |
| 3745 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 3746 | /* post events to application */ |
| 3747 | qla4xxx_do_work(ha); |
| 3748 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3749 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3750 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
Tej Parkash | 546fef2 | 2012-09-20 07:35:12 -0400 | [diff] [blame] | 3751 | if (is_qla8032(ha)) { |
| 3752 | ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n", |
| 3753 | __func__); |
| 3754 | /* disable pause frame for ISP83xx */ |
| 3755 | qla4_83xx_disable_pause(ha); |
| 3756 | } |
| 3757 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 3758 | ha->isp_ops->idc_lock(ha); |
| 3759 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 3760 | QLA8XXX_DEV_FAILED); |
| 3761 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3762 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| 3763 | qla4_8xxx_device_state_handler(ha); |
| 3764 | } |
Nilesh Javali | 320a61d | 2012-09-20 07:35:10 -0400 | [diff] [blame] | 3765 | |
| 3766 | if (test_and_clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) |
| 3767 | qla4_83xx_post_idc_ack(ha); |
| 3768 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3769 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| 3770 | qla4_8xxx_need_qsnt_handler(ha); |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| 3775 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3776 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3777 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3778 | if ((is_qla8022(ha) && ql4xdontresethba) || |
| 3779 | (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3780 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 3781 | ha->host_no, __func__)); |
| 3782 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 3783 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 3784 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 3785 | goto dpc_post_reset_ha; |
| 3786 | } |
| 3787 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| 3788 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 3789 | qla4xxx_recover_adapter(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3790 | |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3791 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3792 | uint8_t wait_time = RESET_INTR_TOV; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3793 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3794 | while ((readw(&ha->reg->ctrl_status) & |
| 3795 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| 3796 | if (--wait_time == 0) |
| 3797 | break; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3798 | msleep(1000); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3799 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3800 | if (wait_time == 0) |
| 3801 | DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| 3802 | "bit not cleared-- resetting\n", |
| 3803 | ha->host_no, __func__)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3804 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3805 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| 3806 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3807 | status = qla4xxx_recover_adapter(ha); |
David C Somayajulu | 477ffb9 | 2007-01-22 12:26:11 -0800 | [diff] [blame] | 3808 | } |
| 3809 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| 3810 | if (status == QLA_SUCCESS) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3811 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3812 | } |
| 3813 | } |
| 3814 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3815 | dpc_post_reset_ha: |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3816 | /* ---- process AEN? --- */ |
| 3817 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| 3818 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| 3819 | |
| 3820 | /* ---- Get DHCP IP Address? --- */ |
| 3821 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| 3822 | qla4xxx_get_dhcp_ip_address(ha); |
| 3823 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3824 | /* ---- relogin device? --- */ |
| 3825 | if (adapter_up(ha) && |
| 3826 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| 3827 | iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin); |
| 3828 | } |
| 3829 | |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 3830 | /* ---- link change? --- */ |
Nilesh Javali | 026fbd3 | 2013-01-20 23:50:58 -0500 | [diff] [blame] | 3831 | if (!test_bit(AF_LOOPBACK, &ha->flags) && |
| 3832 | test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 3833 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 3834 | /* ---- link down? --- */ |
Vikas Chaudhary | 2d7924e | 2011-03-21 03:34:33 -0700 | [diff] [blame] | 3835 | qla4xxx_mark_all_devices_missing(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 3836 | } else { |
| 3837 | /* ---- link up? --- * |
| 3838 | * F/W will auto login to all devices ONLY ONCE after |
| 3839 | * link up during driver initialization and runtime |
| 3840 | * fatal error recovery. Therefore, the driver must |
| 3841 | * manually relogin to devices when recovering from |
| 3842 | * connection failures, logouts, expired KATO, etc. */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 3843 | if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) { |
| 3844 | qla4xxx_build_ddb_list(ha, ha->is_reset); |
| 3845 | iscsi_host_for_each_session(ha->host, |
| 3846 | qla4xxx_login_flash_ddb); |
| 3847 | } else |
| 3848 | qla4xxx_relogin_all_devices(ha); |
Vikas Chaudhary | 065aa1b | 2010-04-28 11:38:11 +0530 | [diff] [blame] | 3849 | } |
| 3850 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | /** |
| 3854 | * qla4xxx_free_adapter - release the adapter |
| 3855 | * @ha: pointer to adapter structure |
| 3856 | **/ |
| 3857 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| 3858 | { |
Sarang Radke | 8a28896 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 3859 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3860 | |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 3861 | /* Turn-off interrupts on the card. */ |
| 3862 | ha->isp_ops->disable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3863 | |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 3864 | if (is_qla40XX(ha)) { |
| 3865 | writel(set_rmask(CSR_SCSI_PROCESSOR_INTR), |
| 3866 | &ha->reg->ctrl_status); |
| 3867 | readl(&ha->reg->ctrl_status); |
| 3868 | } else if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 3869 | writel(0, &ha->qla4_82xx_reg->host_int); |
| 3870 | readl(&ha->qla4_82xx_reg->host_int); |
Vikas Chaudhary | fbd8107 | 2012-09-20 07:35:03 -0400 | [diff] [blame] | 3871 | } else if (is_qla8032(ha)) { |
| 3872 | writel(0, &ha->qla4_83xx_reg->risc_intr); |
| 3873 | readl(&ha->qla4_83xx_reg->risc_intr); |
Vikas Chaudhary | d9e62e5 | 2012-08-22 07:45:25 -0400 | [diff] [blame] | 3874 | } |
| 3875 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3876 | /* Remove timer thread, if present */ |
| 3877 | if (ha->timer_active) |
| 3878 | qla4xxx_stop_timer(ha); |
| 3879 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3880 | /* Kill the kernel thread for this host */ |
| 3881 | if (ha->dpc_thread) |
| 3882 | destroy_workqueue(ha->dpc_thread); |
| 3883 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 3884 | /* Kill the kernel thread for this host */ |
| 3885 | if (ha->task_wq) |
| 3886 | destroy_workqueue(ha->task_wq); |
| 3887 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3888 | /* Put firmware in known state */ |
| 3889 | ha->isp_ops->reset_firmware(ha); |
| 3890 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3891 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 3892 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3893 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 3894 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3895 | } |
| 3896 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3897 | /* Detach interrupts */ |
Vikas Chaudhary | 5c19b92 | 2012-11-23 06:58:38 -0500 | [diff] [blame] | 3898 | qla4xxx_free_irqs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3899 | |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 3900 | /* free extra memory */ |
| 3901 | qla4xxx_mem_free(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3902 | } |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 3903 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3904 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| 3905 | { |
| 3906 | int status = 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3907 | unsigned long mem_base, mem_len, db_base, db_len; |
| 3908 | struct pci_dev *pdev = ha->pdev; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3909 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3910 | status = pci_request_regions(pdev, DRIVER_NAME); |
| 3911 | if (status) { |
| 3912 | printk(KERN_WARNING |
| 3913 | "scsi(%ld) Failed to reserve PIO regions (%s) " |
| 3914 | "status=%d\n", ha->host_no, pci_name(pdev), status); |
| 3915 | goto iospace_error_exit; |
| 3916 | } |
| 3917 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3918 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
Sergei Shtylyov | 7d7311c | 2012-03-14 22:04:30 +0300 | [diff] [blame] | 3919 | __func__, pdev->revision)); |
| 3920 | ha->revision_id = pdev->revision; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3921 | |
| 3922 | /* remap phys address */ |
| 3923 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| 3924 | mem_len = pci_resource_len(pdev, 0); |
| 3925 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| 3926 | __func__, mem_base, mem_len)); |
| 3927 | |
| 3928 | /* mapping of pcibase pointer */ |
| 3929 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| 3930 | if (!ha->nx_pcibase) { |
| 3931 | printk(KERN_ERR |
| 3932 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| 3933 | pci_release_regions(ha->pdev); |
| 3934 | goto iospace_error_exit; |
| 3935 | } |
| 3936 | |
| 3937 | /* Mapping of IO base pointer, door bell read and write pointer */ |
| 3938 | |
| 3939 | /* mapping of IO base pointer */ |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 3940 | if (is_qla8022(ha)) { |
| 3941 | ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *) |
| 3942 | ((uint8_t *)ha->nx_pcibase + 0xbc000 + |
| 3943 | (ha->pdev->devfn << 11)); |
| 3944 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| 3945 | QLA82XX_CAM_RAM_DB2); |
| 3946 | } else if (is_qla8032(ha)) { |
| 3947 | ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *) |
| 3948 | ((uint8_t *)ha->nx_pcibase); |
| 3949 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3950 | |
| 3951 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| 3952 | db_len = pci_resource_len(pdev, 4); |
| 3953 | |
Shyam Sundar | 2657c80 | 2010-10-06 22:50:29 -0700 | [diff] [blame] | 3954 | return 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3955 | iospace_error_exit: |
| 3956 | return -ENOMEM; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | /*** |
| 3960 | * qla4xxx_iospace_config - maps registers |
| 3961 | * @ha: pointer to adapter structure |
| 3962 | * |
| 3963 | * This routines maps HBA's registers from the pci address space |
| 3964 | * into the kernel virtual address space for memory mapped i/o. |
| 3965 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 3966 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3967 | { |
| 3968 | unsigned long pio, pio_len, pio_flags; |
| 3969 | unsigned long mmio, mmio_len, mmio_flags; |
| 3970 | |
| 3971 | pio = pci_resource_start(ha->pdev, 0); |
| 3972 | pio_len = pci_resource_len(ha->pdev, 0); |
| 3973 | pio_flags = pci_resource_flags(ha->pdev, 0); |
| 3974 | if (pio_flags & IORESOURCE_IO) { |
| 3975 | if (pio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3976 | ql4_printk(KERN_WARNING, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3977 | "Invalid PCI I/O region size\n"); |
| 3978 | pio = 0; |
| 3979 | } |
| 3980 | } else { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3981 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3982 | pio = 0; |
| 3983 | } |
| 3984 | |
| 3985 | /* Use MMIO operations for all accesses. */ |
| 3986 | mmio = pci_resource_start(ha->pdev, 1); |
| 3987 | mmio_len = pci_resource_len(ha->pdev, 1); |
| 3988 | mmio_flags = pci_resource_flags(ha->pdev, 1); |
| 3989 | |
| 3990 | if (!(mmio_flags & IORESOURCE_MEM)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3991 | ql4_printk(KERN_ERR, ha, |
| 3992 | "region #0 not an MMIO resource, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3993 | |
| 3994 | goto iospace_error_exit; |
| 3995 | } |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3996 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 3997 | if (mmio_len < MIN_IOBASE_LEN) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 3998 | ql4_printk(KERN_ERR, ha, |
| 3999 | "Invalid PCI mem region size, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4000 | goto iospace_error_exit; |
| 4001 | } |
| 4002 | |
| 4003 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4004 | ql4_printk(KERN_WARNING, ha, |
| 4005 | "Failed to reserve PIO/MMIO regions\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4006 | |
| 4007 | goto iospace_error_exit; |
| 4008 | } |
| 4009 | |
| 4010 | ha->pio_address = pio; |
| 4011 | ha->pio_length = pio_len; |
| 4012 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| 4013 | if (!ha->reg) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 4014 | ql4_printk(KERN_ERR, ha, |
| 4015 | "cannot remap MMIO, aborting\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 4016 | |
| 4017 | goto iospace_error_exit; |
| 4018 | } |
| 4019 | |
| 4020 | return 0; |
| 4021 | |
| 4022 | iospace_error_exit: |
| 4023 | return -ENOMEM; |
| 4024 | } |
| 4025 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4026 | static struct isp_operations qla4xxx_isp_ops = { |
| 4027 | .iospace_config = qla4xxx_iospace_config, |
| 4028 | .pci_config = qla4xxx_pci_config, |
| 4029 | .disable_intrs = qla4xxx_disable_intrs, |
| 4030 | .enable_intrs = qla4xxx_enable_intrs, |
| 4031 | .start_firmware = qla4xxx_start_firmware, |
| 4032 | .intr_handler = qla4xxx_intr_handler, |
| 4033 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| 4034 | .reset_chip = qla4xxx_soft_reset, |
| 4035 | .reset_firmware = qla4xxx_hw_reset, |
| 4036 | .queue_iocb = qla4xxx_queue_iocb, |
| 4037 | .complete_iocb = qla4xxx_complete_iocb, |
| 4038 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 4039 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| 4040 | .get_sys_info = qla4xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4041 | .queue_mailbox_command = qla4xxx_queue_mbox_cmd, |
| 4042 | .process_mailbox_interrupt = qla4xxx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4043 | }; |
| 4044 | |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 4045 | static struct isp_operations qla4_82xx_isp_ops = { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4046 | .iospace_config = qla4_8xxx_iospace_config, |
| 4047 | .pci_config = qla4_8xxx_pci_config, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 4048 | .disable_intrs = qla4_82xx_disable_intrs, |
| 4049 | .enable_intrs = qla4_82xx_enable_intrs, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4050 | .start_firmware = qla4_8xxx_load_risc, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4051 | .restart_firmware = qla4_82xx_try_start_fw, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 4052 | .intr_handler = qla4_82xx_intr_handler, |
| 4053 | .interrupt_service_routine = qla4_82xx_interrupt_service_routine, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4054 | .need_reset = qla4_8xxx_need_reset, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 4055 | .reset_chip = qla4_82xx_isp_reset, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4056 | .reset_firmware = qla4_8xxx_stop_firmware, |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 4057 | .queue_iocb = qla4_82xx_queue_iocb, |
| 4058 | .complete_iocb = qla4_82xx_complete_iocb, |
| 4059 | .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out, |
| 4060 | .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4061 | .get_sys_info = qla4_8xxx_get_sys_info, |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 4062 | .rd_reg_direct = qla4_82xx_rd_32, |
| 4063 | .wr_reg_direct = qla4_82xx_wr_32, |
| 4064 | .rd_reg_indirect = qla4_82xx_md_rd_32, |
| 4065 | .wr_reg_indirect = qla4_82xx_md_wr_32, |
| 4066 | .idc_lock = qla4_82xx_idc_lock, |
| 4067 | .idc_unlock = qla4_82xx_idc_unlock, |
| 4068 | .rom_lock_recovery = qla4_82xx_rom_lock_recovery, |
| 4069 | .queue_mailbox_command = qla4_82xx_queue_mbox_cmd, |
| 4070 | .process_mailbox_interrupt = qla4_82xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4071 | }; |
| 4072 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4073 | static struct isp_operations qla4_83xx_isp_ops = { |
| 4074 | .iospace_config = qla4_8xxx_iospace_config, |
| 4075 | .pci_config = qla4_8xxx_pci_config, |
| 4076 | .disable_intrs = qla4_83xx_disable_intrs, |
| 4077 | .enable_intrs = qla4_83xx_enable_intrs, |
| 4078 | .start_firmware = qla4_8xxx_load_risc, |
| 4079 | .restart_firmware = qla4_83xx_start_firmware, |
| 4080 | .intr_handler = qla4_83xx_intr_handler, |
| 4081 | .interrupt_service_routine = qla4_83xx_interrupt_service_routine, |
| 4082 | .need_reset = qla4_8xxx_need_reset, |
| 4083 | .reset_chip = qla4_83xx_isp_reset, |
| 4084 | .reset_firmware = qla4_8xxx_stop_firmware, |
| 4085 | .queue_iocb = qla4_83xx_queue_iocb, |
| 4086 | .complete_iocb = qla4_83xx_complete_iocb, |
Tej Parkash | a24058f | 2013-03-07 05:43:13 -0500 | [diff] [blame] | 4087 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| 4088 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 4089 | .get_sys_info = qla4_8xxx_get_sys_info, |
| 4090 | .rd_reg_direct = qla4_83xx_rd_reg, |
| 4091 | .wr_reg_direct = qla4_83xx_wr_reg, |
| 4092 | .rd_reg_indirect = qla4_83xx_rd_reg_indirect, |
| 4093 | .wr_reg_indirect = qla4_83xx_wr_reg_indirect, |
| 4094 | .idc_lock = qla4_83xx_drv_lock, |
| 4095 | .idc_unlock = qla4_83xx_drv_unlock, |
| 4096 | .rom_lock_recovery = qla4_83xx_rom_lock_recovery, |
| 4097 | .queue_mailbox_command = qla4_83xx_queue_mbox_cmd, |
| 4098 | .process_mailbox_interrupt = qla4_83xx_process_mbox_intr, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 4099 | }; |
| 4100 | |
| 4101 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| 4102 | { |
| 4103 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| 4104 | } |
| 4105 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 4106 | 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] | 4107 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 4108 | 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] | 4109 | } |
| 4110 | |
| 4111 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) |
| 4112 | { |
| 4113 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); |
| 4114 | } |
| 4115 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 4116 | 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] | 4117 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 4118 | 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] | 4119 | } |
| 4120 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4121 | static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf) |
| 4122 | { |
| 4123 | struct scsi_qla_host *ha = data; |
| 4124 | char *str = buf; |
| 4125 | int rc; |
| 4126 | |
| 4127 | switch (type) { |
| 4128 | case ISCSI_BOOT_ETH_FLAGS: |
| 4129 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 4130 | break; |
| 4131 | case ISCSI_BOOT_ETH_INDEX: |
| 4132 | rc = sprintf(str, "0\n"); |
| 4133 | break; |
| 4134 | case ISCSI_BOOT_ETH_MAC: |
| 4135 | rc = sysfs_format_mac(str, ha->my_mac, |
| 4136 | MAC_ADDR_LEN); |
| 4137 | break; |
| 4138 | default: |
| 4139 | rc = -ENOSYS; |
| 4140 | break; |
| 4141 | } |
| 4142 | return rc; |
| 4143 | } |
| 4144 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 4145 | static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4146 | { |
| 4147 | int rc; |
| 4148 | |
| 4149 | switch (type) { |
| 4150 | case ISCSI_BOOT_ETH_FLAGS: |
| 4151 | case ISCSI_BOOT_ETH_MAC: |
| 4152 | case ISCSI_BOOT_ETH_INDEX: |
| 4153 | rc = S_IRUGO; |
| 4154 | break; |
| 4155 | default: |
| 4156 | rc = 0; |
| 4157 | break; |
| 4158 | } |
| 4159 | return rc; |
| 4160 | } |
| 4161 | |
| 4162 | static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf) |
| 4163 | { |
| 4164 | struct scsi_qla_host *ha = data; |
| 4165 | char *str = buf; |
| 4166 | int rc; |
| 4167 | |
| 4168 | switch (type) { |
| 4169 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 4170 | rc = sprintf(str, "%s\n", ha->name_string); |
| 4171 | break; |
| 4172 | default: |
| 4173 | rc = -ENOSYS; |
| 4174 | break; |
| 4175 | } |
| 4176 | return rc; |
| 4177 | } |
| 4178 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 4179 | static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4180 | { |
| 4181 | int rc; |
| 4182 | |
| 4183 | switch (type) { |
| 4184 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 4185 | rc = S_IRUGO; |
| 4186 | break; |
| 4187 | default: |
| 4188 | rc = 0; |
| 4189 | break; |
| 4190 | } |
| 4191 | return rc; |
| 4192 | } |
| 4193 | |
| 4194 | static ssize_t |
| 4195 | qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type, |
| 4196 | char *buf) |
| 4197 | { |
| 4198 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 4199 | char *str = buf; |
| 4200 | int rc; |
| 4201 | |
| 4202 | switch (type) { |
| 4203 | case ISCSI_BOOT_TGT_NAME: |
| 4204 | rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name); |
| 4205 | break; |
| 4206 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 4207 | if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1) |
| 4208 | rc = sprintf(buf, "%pI4\n", |
| 4209 | &boot_conn->dest_ipaddr.ip_address); |
| 4210 | else |
| 4211 | rc = sprintf(str, "%pI6\n", |
| 4212 | &boot_conn->dest_ipaddr.ip_address); |
| 4213 | break; |
| 4214 | case ISCSI_BOOT_TGT_PORT: |
| 4215 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 4216 | break; |
| 4217 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 4218 | rc = sprintf(str, "%.*s\n", |
| 4219 | boot_conn->chap.target_chap_name_length, |
| 4220 | (char *)&boot_conn->chap.target_chap_name); |
| 4221 | break; |
| 4222 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 4223 | rc = sprintf(str, "%.*s\n", |
| 4224 | boot_conn->chap.target_secret_length, |
| 4225 | (char *)&boot_conn->chap.target_secret); |
| 4226 | break; |
| 4227 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 4228 | rc = sprintf(str, "%.*s\n", |
| 4229 | boot_conn->chap.intr_chap_name_length, |
| 4230 | (char *)&boot_conn->chap.intr_chap_name); |
| 4231 | break; |
| 4232 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 4233 | rc = sprintf(str, "%.*s\n", |
| 4234 | boot_conn->chap.intr_secret_length, |
| 4235 | (char *)&boot_conn->chap.intr_secret); |
| 4236 | break; |
| 4237 | case ISCSI_BOOT_TGT_FLAGS: |
| 4238 | rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT); |
| 4239 | break; |
| 4240 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 4241 | rc = sprintf(str, "0\n"); |
| 4242 | break; |
| 4243 | default: |
| 4244 | rc = -ENOSYS; |
| 4245 | break; |
| 4246 | } |
| 4247 | return rc; |
| 4248 | } |
| 4249 | |
| 4250 | static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf) |
| 4251 | { |
| 4252 | struct scsi_qla_host *ha = data; |
| 4253 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess); |
| 4254 | |
| 4255 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 4256 | } |
| 4257 | |
| 4258 | static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf) |
| 4259 | { |
| 4260 | struct scsi_qla_host *ha = data; |
| 4261 | struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess); |
| 4262 | |
| 4263 | return qla4xxx_show_boot_tgt_info(boot_sess, type, buf); |
| 4264 | } |
| 4265 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 4266 | static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4267 | { |
| 4268 | int rc; |
| 4269 | |
| 4270 | switch (type) { |
| 4271 | case ISCSI_BOOT_TGT_NAME: |
| 4272 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 4273 | case ISCSI_BOOT_TGT_PORT: |
| 4274 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 4275 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 4276 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 4277 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 4278 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 4279 | case ISCSI_BOOT_TGT_FLAGS: |
| 4280 | rc = S_IRUGO; |
| 4281 | break; |
| 4282 | default: |
| 4283 | rc = 0; |
| 4284 | break; |
| 4285 | } |
| 4286 | return rc; |
| 4287 | } |
| 4288 | |
| 4289 | static void qla4xxx_boot_release(void *data) |
| 4290 | { |
| 4291 | struct scsi_qla_host *ha = data; |
| 4292 | |
| 4293 | scsi_host_put(ha->host); |
| 4294 | } |
| 4295 | |
| 4296 | static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[]) |
| 4297 | { |
| 4298 | dma_addr_t buf_dma; |
| 4299 | uint32_t addr, pri_addr, sec_addr; |
| 4300 | uint32_t offset; |
| 4301 | uint16_t func_num; |
| 4302 | uint8_t val; |
| 4303 | uint8_t *buf = NULL; |
| 4304 | size_t size = 13 * sizeof(uint8_t); |
| 4305 | int ret = QLA_SUCCESS; |
| 4306 | |
| 4307 | func_num = PCI_FUNC(ha->pdev->devfn); |
| 4308 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 4309 | ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n", |
| 4310 | __func__, ha->pdev->device, func_num); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4311 | |
Manish Rangankar | 0d5b36b | 2011-10-07 16:55:51 -0700 | [diff] [blame] | 4312 | if (is_qla40XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4313 | if (func_num == 1) { |
| 4314 | addr = NVRAM_PORT0_BOOT_MODE; |
| 4315 | pri_addr = NVRAM_PORT0_BOOT_PRI_TGT; |
| 4316 | sec_addr = NVRAM_PORT0_BOOT_SEC_TGT; |
| 4317 | } else if (func_num == 3) { |
| 4318 | addr = NVRAM_PORT1_BOOT_MODE; |
| 4319 | pri_addr = NVRAM_PORT1_BOOT_PRI_TGT; |
| 4320 | sec_addr = NVRAM_PORT1_BOOT_SEC_TGT; |
| 4321 | } else { |
| 4322 | ret = QLA_ERROR; |
| 4323 | goto exit_boot_info; |
| 4324 | } |
| 4325 | |
| 4326 | /* Check Boot Mode */ |
| 4327 | val = rd_nvram_byte(ha, addr); |
| 4328 | if (!(val & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 4329 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot " |
| 4330 | "options : 0x%x\n", __func__, val)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4331 | ret = QLA_ERROR; |
| 4332 | goto exit_boot_info; |
| 4333 | } |
| 4334 | |
| 4335 | /* get primary valid target index */ |
| 4336 | val = rd_nvram_byte(ha, pri_addr); |
| 4337 | if (val & BIT_7) |
| 4338 | ddb_index[0] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4339 | |
| 4340 | /* get secondary valid target index */ |
| 4341 | val = rd_nvram_byte(ha, sec_addr); |
| 4342 | if (val & BIT_7) |
| 4343 | ddb_index[1] = (val & 0x7f); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4344 | |
Vikas Chaudhary | 3e788fb | 2013-03-07 05:43:08 -0500 | [diff] [blame] | 4345 | } else if (is_qla80XX(ha)) { |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4346 | buf = dma_alloc_coherent(&ha->pdev->dev, size, |
| 4347 | &buf_dma, GFP_KERNEL); |
| 4348 | if (!buf) { |
| 4349 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 4350 | "%s: Unable to allocate dma buffer\n", |
| 4351 | __func__)); |
| 4352 | ret = QLA_ERROR; |
| 4353 | goto exit_boot_info; |
| 4354 | } |
| 4355 | |
| 4356 | if (ha->port_num == 0) |
| 4357 | offset = BOOT_PARAM_OFFSET_PORT0; |
| 4358 | else if (ha->port_num == 1) |
| 4359 | offset = BOOT_PARAM_OFFSET_PORT1; |
| 4360 | else { |
| 4361 | ret = QLA_ERROR; |
| 4362 | goto exit_boot_info_free; |
| 4363 | } |
| 4364 | addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) + |
| 4365 | offset; |
| 4366 | if (qla4xxx_get_flash(ha, buf_dma, addr, |
| 4367 | 13 * sizeof(uint8_t)) != QLA_SUCCESS) { |
| 4368 | DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash" |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 4369 | " failed\n", ha->host_no, __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4370 | ret = QLA_ERROR; |
| 4371 | goto exit_boot_info_free; |
| 4372 | } |
| 4373 | /* Check Boot Mode */ |
| 4374 | if (!(buf[1] & 0x07)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 4375 | DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options" |
| 4376 | " : 0x%x\n", buf[1])); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4377 | ret = QLA_ERROR; |
| 4378 | goto exit_boot_info_free; |
| 4379 | } |
| 4380 | |
| 4381 | /* get primary valid target index */ |
| 4382 | if (buf[2] & BIT_7) |
| 4383 | ddb_index[0] = buf[2] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4384 | |
| 4385 | /* get secondary valid target index */ |
| 4386 | if (buf[11] & BIT_7) |
| 4387 | ddb_index[1] = buf[11] & 0x7f; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4388 | } else { |
| 4389 | ret = QLA_ERROR; |
| 4390 | goto exit_boot_info; |
| 4391 | } |
| 4392 | |
| 4393 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary" |
| 4394 | " target ID %d\n", __func__, ddb_index[0], |
| 4395 | ddb_index[1])); |
| 4396 | |
| 4397 | exit_boot_info_free: |
| 4398 | dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma); |
| 4399 | exit_boot_info: |
Lalit Chandivade | 20e835b | 2012-02-13 18:30:42 +0530 | [diff] [blame] | 4400 | ha->pri_ddb_idx = ddb_index[0]; |
| 4401 | ha->sec_ddb_idx = ddb_index[1]; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4402 | return ret; |
| 4403 | } |
| 4404 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 4405 | /** |
| 4406 | * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password |
| 4407 | * @ha: pointer to adapter structure |
| 4408 | * @username: CHAP username to be returned |
| 4409 | * @password: CHAP password to be returned |
| 4410 | * |
| 4411 | * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP |
| 4412 | * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/. |
| 4413 | * So from the CHAP cache find the first BIDI CHAP entry and set it |
| 4414 | * to the boot record in sysfs. |
| 4415 | **/ |
| 4416 | static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username, |
| 4417 | char *password) |
| 4418 | { |
| 4419 | int i, ret = -EINVAL; |
| 4420 | int max_chap_entries = 0; |
| 4421 | struct ql4_chap_table *chap_table; |
| 4422 | |
Vikas Chaudhary | d11b0ca | 2013-03-22 07:08:31 -0400 | [diff] [blame] | 4423 | if (is_qla80XX(ha)) |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 4424 | max_chap_entries = (ha->hw.flt_chap_size / 2) / |
| 4425 | sizeof(struct ql4_chap_table); |
| 4426 | else |
| 4427 | max_chap_entries = MAX_CHAP_ENTRIES_40XX; |
| 4428 | |
| 4429 | if (!ha->chap_list) { |
| 4430 | ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n"); |
| 4431 | return ret; |
| 4432 | } |
| 4433 | |
| 4434 | mutex_lock(&ha->chap_sem); |
| 4435 | for (i = 0; i < max_chap_entries; i++) { |
| 4436 | chap_table = (struct ql4_chap_table *)ha->chap_list + i; |
| 4437 | if (chap_table->cookie != |
| 4438 | __constant_cpu_to_le16(CHAP_VALID_COOKIE)) { |
| 4439 | continue; |
| 4440 | } |
| 4441 | |
| 4442 | if (chap_table->flags & BIT_7) /* local */ |
| 4443 | continue; |
| 4444 | |
| 4445 | if (!(chap_table->flags & BIT_6)) /* Not BIDI */ |
| 4446 | continue; |
| 4447 | |
| 4448 | strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN); |
| 4449 | strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN); |
| 4450 | ret = 0; |
| 4451 | break; |
| 4452 | } |
| 4453 | mutex_unlock(&ha->chap_sem); |
| 4454 | |
| 4455 | return ret; |
| 4456 | } |
| 4457 | |
| 4458 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4459 | static int qla4xxx_get_boot_target(struct scsi_qla_host *ha, |
| 4460 | struct ql4_boot_session_info *boot_sess, |
| 4461 | uint16_t ddb_index) |
| 4462 | { |
| 4463 | struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 4464 | struct dev_db_entry *fw_ddb_entry; |
| 4465 | dma_addr_t fw_ddb_entry_dma; |
| 4466 | uint16_t idx; |
| 4467 | uint16_t options; |
| 4468 | int ret = QLA_SUCCESS; |
| 4469 | |
| 4470 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 4471 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 4472 | if (!fw_ddb_entry) { |
| 4473 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 4474 | "%s: Unable to allocate dma buffer.\n", |
| 4475 | __func__)); |
| 4476 | ret = QLA_ERROR; |
| 4477 | return ret; |
| 4478 | } |
| 4479 | |
| 4480 | if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry, |
| 4481 | fw_ddb_entry_dma, ddb_index)) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 4482 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at " |
| 4483 | "index [%d]\n", __func__, ddb_index)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4484 | ret = QLA_ERROR; |
| 4485 | goto exit_boot_target; |
| 4486 | } |
| 4487 | |
| 4488 | /* Update target name and IP from DDB */ |
| 4489 | memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name, |
| 4490 | min(sizeof(boot_sess->target_name), |
| 4491 | sizeof(fw_ddb_entry->iscsi_name))); |
| 4492 | |
| 4493 | options = le16_to_cpu(fw_ddb_entry->options); |
| 4494 | if (options & DDB_OPT_IPV6_DEVICE) { |
| 4495 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 4496 | &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN); |
| 4497 | } else { |
| 4498 | boot_conn->dest_ipaddr.ip_type = 0x1; |
| 4499 | memcpy(&boot_conn->dest_ipaddr.ip_address, |
| 4500 | &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN); |
| 4501 | } |
| 4502 | |
| 4503 | boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port); |
| 4504 | |
| 4505 | /* update chap information */ |
| 4506 | idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx); |
| 4507 | |
| 4508 | if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 4509 | |
| 4510 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n")); |
| 4511 | |
| 4512 | ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap. |
| 4513 | target_chap_name, |
| 4514 | (char *)&boot_conn->chap.target_secret, |
| 4515 | idx); |
| 4516 | if (ret) { |
| 4517 | ql4_printk(KERN_ERR, ha, "Failed to set chap\n"); |
| 4518 | ret = QLA_ERROR; |
| 4519 | goto exit_boot_target; |
| 4520 | } |
| 4521 | |
| 4522 | boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 4523 | boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 4524 | } |
| 4525 | |
| 4526 | if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) { |
| 4527 | |
| 4528 | DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n")); |
| 4529 | |
Lalit Chandivade | 28deb45 | 2011-10-07 16:55:44 -0700 | [diff] [blame] | 4530 | ret = qla4xxx_get_bidi_chap(ha, |
| 4531 | (char *)&boot_conn->chap.intr_chap_name, |
| 4532 | (char *)&boot_conn->chap.intr_secret); |
| 4533 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4534 | if (ret) { |
| 4535 | ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n"); |
| 4536 | ret = QLA_ERROR; |
| 4537 | goto exit_boot_target; |
| 4538 | } |
| 4539 | |
| 4540 | boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN; |
| 4541 | boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN; |
| 4542 | } |
| 4543 | |
| 4544 | exit_boot_target: |
| 4545 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 4546 | fw_ddb_entry, fw_ddb_entry_dma); |
| 4547 | return ret; |
| 4548 | } |
| 4549 | |
| 4550 | static int qla4xxx_get_boot_info(struct scsi_qla_host *ha) |
| 4551 | { |
| 4552 | uint16_t ddb_index[2]; |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4553 | int ret = QLA_ERROR; |
| 4554 | int rval; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4555 | |
| 4556 | memset(ddb_index, 0, sizeof(ddb_index)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4557 | ddb_index[0] = 0xffff; |
| 4558 | ddb_index[1] = 0xffff; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4559 | ret = get_fw_boot_info(ha, ddb_index); |
| 4560 | if (ret != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 4561 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4562 | "%s: No boot target configured.\n", __func__)); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4563 | return ret; |
| 4564 | } |
| 4565 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4566 | if (ql4xdisablesysfsboot) |
| 4567 | return QLA_SUCCESS; |
| 4568 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4569 | if (ddb_index[0] == 0xffff) |
| 4570 | goto sec_target; |
| 4571 | |
| 4572 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4573 | ddb_index[0]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4574 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 4575 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not " |
| 4576 | "configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4577 | } else |
| 4578 | ret = QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4579 | |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4580 | sec_target: |
| 4581 | if (ddb_index[1] == 0xffff) |
| 4582 | goto exit_get_boot_info; |
| 4583 | |
| 4584 | rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess), |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4585 | ddb_index[1]); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4586 | if (rval != QLA_SUCCESS) { |
Manish Rangankar | e8fb00e | 2012-02-13 18:30:43 +0530 | [diff] [blame] | 4587 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not" |
| 4588 | " configured\n", __func__)); |
Lalit Chandivade | 8de5b95 | 2011-10-07 16:55:43 -0700 | [diff] [blame] | 4589 | } else |
| 4590 | ret = QLA_SUCCESS; |
| 4591 | |
| 4592 | exit_get_boot_info: |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4593 | return ret; |
| 4594 | } |
| 4595 | |
| 4596 | static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha) |
| 4597 | { |
| 4598 | struct iscsi_boot_kobj *boot_kobj; |
| 4599 | |
| 4600 | if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4601 | return QLA_ERROR; |
| 4602 | |
| 4603 | if (ql4xdisablesysfsboot) { |
| 4604 | ql4_printk(KERN_INFO, ha, |
Petr Uzel | 0bd7f84 | 2012-02-24 16:32:59 +0100 | [diff] [blame] | 4605 | "%s: syfsboot disabled - driver will trigger login " |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4606 | "and publish session for discovery .\n", __func__); |
| 4607 | return QLA_SUCCESS; |
| 4608 | } |
| 4609 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4610 | |
| 4611 | ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no); |
| 4612 | if (!ha->boot_kset) |
| 4613 | goto kset_free; |
| 4614 | |
| 4615 | if (!scsi_host_get(ha->host)) |
| 4616 | goto kset_free; |
| 4617 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha, |
| 4618 | qla4xxx_show_boot_tgt_pri_info, |
| 4619 | qla4xxx_tgt_get_attr_visibility, |
| 4620 | qla4xxx_boot_release); |
| 4621 | if (!boot_kobj) |
| 4622 | goto put_host; |
| 4623 | |
| 4624 | if (!scsi_host_get(ha->host)) |
| 4625 | goto kset_free; |
| 4626 | boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha, |
| 4627 | qla4xxx_show_boot_tgt_sec_info, |
| 4628 | qla4xxx_tgt_get_attr_visibility, |
| 4629 | qla4xxx_boot_release); |
| 4630 | if (!boot_kobj) |
| 4631 | goto put_host; |
| 4632 | |
| 4633 | if (!scsi_host_get(ha->host)) |
| 4634 | goto kset_free; |
| 4635 | boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha, |
| 4636 | qla4xxx_show_boot_ini_info, |
| 4637 | qla4xxx_ini_get_attr_visibility, |
| 4638 | qla4xxx_boot_release); |
| 4639 | if (!boot_kobj) |
| 4640 | goto put_host; |
| 4641 | |
| 4642 | if (!scsi_host_get(ha->host)) |
| 4643 | goto kset_free; |
| 4644 | boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha, |
| 4645 | qla4xxx_show_boot_eth_info, |
| 4646 | qla4xxx_eth_get_attr_visibility, |
| 4647 | qla4xxx_boot_release); |
| 4648 | if (!boot_kobj) |
| 4649 | goto put_host; |
| 4650 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4651 | return QLA_SUCCESS; |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 4652 | |
| 4653 | put_host: |
| 4654 | scsi_host_put(ha->host); |
| 4655 | kset_free: |
| 4656 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 4657 | return -ENOMEM; |
| 4658 | } |
| 4659 | |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 4660 | |
| 4661 | /** |
| 4662 | * qla4xxx_create chap_list - Create CHAP list from FLASH |
| 4663 | * @ha: pointer to adapter structure |
| 4664 | * |
| 4665 | * Read flash and make a list of CHAP entries, during login when a CHAP entry |
| 4666 | * is received, it will be checked in this list. If entry exist then the CHAP |
| 4667 | * entry index is set in the DDB. If CHAP entry does not exist in this list |
| 4668 | * then a new entry is added in FLASH in CHAP table and the index obtained is |
| 4669 | * used in the DDB. |
| 4670 | **/ |
| 4671 | static void qla4xxx_create_chap_list(struct scsi_qla_host *ha) |
| 4672 | { |
| 4673 | int rval = 0; |
| 4674 | uint8_t *chap_flash_data = NULL; |
| 4675 | uint32_t offset; |
| 4676 | dma_addr_t chap_dma; |
| 4677 | uint32_t chap_size = 0; |
| 4678 | |
| 4679 | if (is_qla40XX(ha)) |
| 4680 | chap_size = MAX_CHAP_ENTRIES_40XX * |
| 4681 | sizeof(struct ql4_chap_table); |
| 4682 | else /* Single region contains CHAP info for both |
| 4683 | * ports which is divided into half for each port. |
| 4684 | */ |
| 4685 | chap_size = ha->hw.flt_chap_size / 2; |
| 4686 | |
| 4687 | chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size, |
| 4688 | &chap_dma, GFP_KERNEL); |
| 4689 | if (!chap_flash_data) { |
| 4690 | ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n"); |
| 4691 | return; |
| 4692 | } |
| 4693 | if (is_qla40XX(ha)) |
| 4694 | offset = FLASH_CHAP_OFFSET; |
| 4695 | else { |
| 4696 | offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); |
| 4697 | if (ha->port_num == 1) |
| 4698 | offset += chap_size; |
| 4699 | } |
| 4700 | |
| 4701 | rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); |
| 4702 | if (rval != QLA_SUCCESS) |
| 4703 | goto exit_chap_list; |
| 4704 | |
| 4705 | if (ha->chap_list == NULL) |
| 4706 | ha->chap_list = vmalloc(chap_size); |
| 4707 | if (ha->chap_list == NULL) { |
| 4708 | ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n"); |
| 4709 | goto exit_chap_list; |
| 4710 | } |
| 4711 | |
| 4712 | memcpy(ha->chap_list, chap_flash_data, chap_size); |
| 4713 | |
| 4714 | exit_chap_list: |
| 4715 | dma_free_coherent(&ha->pdev->dev, chap_size, |
| 4716 | chap_flash_data, chap_dma); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 4717 | } |
| 4718 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4719 | static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry, |
| 4720 | struct ql4_tuple_ddb *tddb) |
| 4721 | { |
| 4722 | struct scsi_qla_host *ha; |
| 4723 | struct iscsi_cls_session *cls_sess; |
| 4724 | struct iscsi_cls_conn *cls_conn; |
| 4725 | struct iscsi_session *sess; |
| 4726 | struct iscsi_conn *conn; |
| 4727 | |
| 4728 | DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| 4729 | ha = ddb_entry->ha; |
| 4730 | cls_sess = ddb_entry->sess; |
| 4731 | sess = cls_sess->dd_data; |
| 4732 | cls_conn = ddb_entry->conn; |
| 4733 | conn = cls_conn->dd_data; |
| 4734 | |
| 4735 | tddb->tpgt = sess->tpgt; |
| 4736 | tddb->port = conn->persistent_port; |
| 4737 | strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE); |
| 4738 | strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN); |
| 4739 | } |
| 4740 | |
| 4741 | 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] | 4742 | struct ql4_tuple_ddb *tddb, |
| 4743 | uint8_t *flash_isid) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4744 | { |
| 4745 | uint16_t options = 0; |
| 4746 | |
| 4747 | tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| 4748 | memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0], |
| 4749 | min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name))); |
| 4750 | |
| 4751 | options = le16_to_cpu(fw_ddb_entry->options); |
| 4752 | if (options & DDB_OPT_IPV6_DEVICE) |
| 4753 | sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| 4754 | else |
| 4755 | sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| 4756 | |
| 4757 | tddb->port = le16_to_cpu(fw_ddb_entry->port); |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 4758 | |
| 4759 | if (flash_isid == NULL) |
| 4760 | memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0], |
| 4761 | sizeof(tddb->isid)); |
| 4762 | else |
| 4763 | memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid)); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha, |
| 4767 | struct ql4_tuple_ddb *old_tddb, |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 4768 | struct ql4_tuple_ddb *new_tddb, |
| 4769 | uint8_t is_isid_compare) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4770 | { |
| 4771 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 4772 | return QLA_ERROR; |
| 4773 | |
| 4774 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr)) |
| 4775 | return QLA_ERROR; |
| 4776 | |
| 4777 | if (old_tddb->port != new_tddb->port) |
| 4778 | return QLA_ERROR; |
| 4779 | |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 4780 | /* For multi sessions, driver generates the ISID, so do not compare |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 4781 | * ISID in reset path since it would be a comparison between the |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 4782 | * driver generated ISID and firmware generated ISID. This could |
| 4783 | * lead to adding duplicated DDBs in the list as driver generated |
| 4784 | * ISID would not match firmware generated ISID. |
| 4785 | */ |
| 4786 | if (is_isid_compare) { |
| 4787 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x" |
| 4788 | "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n", |
| 4789 | __func__, old_tddb->isid[5], old_tddb->isid[4], |
| 4790 | old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1], |
| 4791 | old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4], |
| 4792 | new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1], |
| 4793 | new_tddb->isid[0])); |
| 4794 | |
| 4795 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 4796 | sizeof(old_tddb->isid))) |
| 4797 | return QLA_ERROR; |
| 4798 | } |
| 4799 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4800 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 4801 | "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]", |
| 4802 | old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr, |
| 4803 | old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt, |
| 4804 | new_tddb->ip_addr, new_tddb->iscsi_name)); |
| 4805 | |
| 4806 | return QLA_SUCCESS; |
| 4807 | } |
| 4808 | |
| 4809 | static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, |
| 4810 | struct dev_db_entry *fw_ddb_entry) |
| 4811 | { |
| 4812 | struct ddb_entry *ddb_entry; |
| 4813 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 4814 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 4815 | int idx; |
| 4816 | int ret = QLA_ERROR; |
| 4817 | |
| 4818 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 4819 | if (!fw_tddb) { |
| 4820 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 4821 | "Memory Allocation failed.\n")); |
| 4822 | ret = QLA_SUCCESS; |
| 4823 | goto exit_check; |
| 4824 | } |
| 4825 | |
| 4826 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 4827 | if (!tmp_tddb) { |
| 4828 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 4829 | "Memory Allocation failed.\n")); |
| 4830 | ret = QLA_SUCCESS; |
| 4831 | goto exit_check; |
| 4832 | } |
| 4833 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 4834 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4835 | |
| 4836 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 4837 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 4838 | if (ddb_entry == NULL) |
| 4839 | continue; |
| 4840 | |
| 4841 | qla4xxx_get_param_ddb(ddb_entry, tmp_tddb); |
Manish Rangankar | 173269e | 2012-02-27 03:08:55 -0800 | [diff] [blame] | 4842 | if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) { |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4843 | ret = QLA_SUCCESS; /* found */ |
| 4844 | goto exit_check; |
| 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | exit_check: |
| 4849 | if (fw_tddb) |
| 4850 | vfree(fw_tddb); |
| 4851 | if (tmp_tddb) |
| 4852 | vfree(tmp_tddb); |
| 4853 | return ret; |
| 4854 | } |
| 4855 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 4856 | /** |
| 4857 | * qla4xxx_check_existing_isid - check if target with same isid exist |
| 4858 | * in target list |
| 4859 | * @list_nt: list of target |
| 4860 | * @isid: isid to check |
| 4861 | * |
| 4862 | * This routine return QLA_SUCCESS if target with same isid exist |
| 4863 | **/ |
| 4864 | static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid) |
| 4865 | { |
| 4866 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 4867 | struct dev_db_entry *fw_ddb_entry; |
| 4868 | |
| 4869 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 4870 | fw_ddb_entry = &nt_ddb_idx->fw_ddb; |
| 4871 | |
| 4872 | if (memcmp(&fw_ddb_entry->isid[0], &isid[0], |
| 4873 | sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) { |
| 4874 | return QLA_SUCCESS; |
| 4875 | } |
| 4876 | } |
| 4877 | return QLA_ERROR; |
| 4878 | } |
| 4879 | |
| 4880 | /** |
| 4881 | * qla4xxx_update_isid - compare ddbs and updated isid |
| 4882 | * @ha: Pointer to host adapter structure. |
| 4883 | * @list_nt: list of nt target |
| 4884 | * @fw_ddb_entry: firmware ddb entry |
| 4885 | * |
| 4886 | * This routine update isid if ddbs have same iqn, same isid and |
| 4887 | * different IP addr. |
| 4888 | * Return QLA_SUCCESS if isid is updated. |
| 4889 | **/ |
| 4890 | static int qla4xxx_update_isid(struct scsi_qla_host *ha, |
| 4891 | struct list_head *list_nt, |
| 4892 | struct dev_db_entry *fw_ddb_entry) |
| 4893 | { |
| 4894 | uint8_t base_value, i; |
| 4895 | |
| 4896 | base_value = fw_ddb_entry->isid[1] & 0x1f; |
| 4897 | for (i = 0; i < 8; i++) { |
| 4898 | fw_ddb_entry->isid[1] = (base_value | (i << 5)); |
| 4899 | if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 4900 | break; |
| 4901 | } |
| 4902 | |
| 4903 | if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) |
| 4904 | return QLA_ERROR; |
| 4905 | |
| 4906 | return QLA_SUCCESS; |
| 4907 | } |
| 4908 | |
| 4909 | /** |
| 4910 | * qla4xxx_should_update_isid - check if isid need to update |
| 4911 | * @ha: Pointer to host adapter structure. |
| 4912 | * @old_tddb: ddb tuple |
| 4913 | * @new_tddb: ddb tuple |
| 4914 | * |
| 4915 | * Return QLA_SUCCESS if different IP, different PORT, same iqn, |
| 4916 | * same isid |
| 4917 | **/ |
| 4918 | static int qla4xxx_should_update_isid(struct scsi_qla_host *ha, |
| 4919 | struct ql4_tuple_ddb *old_tddb, |
| 4920 | struct ql4_tuple_ddb *new_tddb) |
| 4921 | { |
| 4922 | if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) { |
| 4923 | /* Same ip */ |
| 4924 | if (old_tddb->port == new_tddb->port) |
| 4925 | return QLA_ERROR; |
| 4926 | } |
| 4927 | |
| 4928 | if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) |
| 4929 | /* different iqn */ |
| 4930 | return QLA_ERROR; |
| 4931 | |
| 4932 | if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], |
| 4933 | sizeof(old_tddb->isid))) |
| 4934 | /* different isid */ |
| 4935 | return QLA_ERROR; |
| 4936 | |
| 4937 | return QLA_SUCCESS; |
| 4938 | } |
| 4939 | |
| 4940 | /** |
| 4941 | * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt |
| 4942 | * @ha: Pointer to host adapter structure. |
| 4943 | * @list_nt: list of nt target. |
| 4944 | * @fw_ddb_entry: firmware ddb entry. |
| 4945 | * |
| 4946 | * This routine check if fw_ddb_entry already exists in list_nt to avoid |
| 4947 | * duplicate ddb in list_nt. |
| 4948 | * Return QLA_SUCCESS if duplicate ddb exit in list_nl. |
| 4949 | * Note: This function also update isid of DDB if required. |
| 4950 | **/ |
| 4951 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4952 | static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha, |
| 4953 | struct list_head *list_nt, |
| 4954 | struct dev_db_entry *fw_ddb_entry) |
| 4955 | { |
| 4956 | struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; |
| 4957 | struct ql4_tuple_ddb *fw_tddb = NULL; |
| 4958 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 4959 | int rval, ret = QLA_ERROR; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4960 | |
| 4961 | fw_tddb = vzalloc(sizeof(*fw_tddb)); |
| 4962 | if (!fw_tddb) { |
| 4963 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 4964 | "Memory Allocation failed.\n")); |
| 4965 | ret = QLA_SUCCESS; |
| 4966 | goto exit_check; |
| 4967 | } |
| 4968 | |
| 4969 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 4970 | if (!tmp_tddb) { |
| 4971 | DEBUG2(ql4_printk(KERN_WARNING, ha, |
| 4972 | "Memory Allocation failed.\n")); |
| 4973 | ret = QLA_SUCCESS; |
| 4974 | goto exit_check; |
| 4975 | } |
| 4976 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 4977 | qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4978 | |
| 4979 | 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] | 4980 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, |
| 4981 | nt_ddb_idx->flash_isid); |
| 4982 | ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true); |
| 4983 | /* found duplicate ddb */ |
| 4984 | if (ret == QLA_SUCCESS) |
| 4985 | goto exit_check; |
| 4986 | } |
| 4987 | |
| 4988 | list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) { |
| 4989 | qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL); |
| 4990 | |
| 4991 | ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb); |
| 4992 | if (ret == QLA_SUCCESS) { |
| 4993 | rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry); |
| 4994 | if (rval == QLA_SUCCESS) |
| 4995 | ret = QLA_ERROR; |
| 4996 | else |
| 4997 | ret = QLA_SUCCESS; |
| 4998 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 4999 | goto exit_check; |
| 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | exit_check: |
| 5004 | if (fw_tddb) |
| 5005 | vfree(fw_tddb); |
| 5006 | if (tmp_tddb) |
| 5007 | vfree(tmp_tddb); |
| 5008 | return ret; |
| 5009 | } |
| 5010 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5011 | static void qla4xxx_free_ddb_list(struct list_head *list_ddb) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5012 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5013 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5014 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5015 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 5016 | list_del_init(&ddb_idx->list); |
| 5017 | vfree(ddb_idx); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5018 | } |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha, |
| 5022 | struct dev_db_entry *fw_ddb_entry) |
| 5023 | { |
| 5024 | struct iscsi_endpoint *ep; |
| 5025 | struct sockaddr_in *addr; |
| 5026 | struct sockaddr_in6 *addr6; |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 5027 | struct sockaddr *t_addr; |
| 5028 | struct sockaddr_storage *dst_addr; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5029 | char *ip; |
| 5030 | |
| 5031 | /* TODO: need to destroy on unload iscsi_endpoint*/ |
| 5032 | dst_addr = vmalloc(sizeof(*dst_addr)); |
| 5033 | if (!dst_addr) |
| 5034 | return NULL; |
| 5035 | |
| 5036 | if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 5037 | t_addr = (struct sockaddr *)dst_addr; |
| 5038 | t_addr->sa_family = AF_INET6; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5039 | addr6 = (struct sockaddr_in6 *)dst_addr; |
| 5040 | ip = (char *)&addr6->sin6_addr; |
| 5041 | memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN); |
| 5042 | addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 5043 | |
| 5044 | } else { |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 5045 | t_addr = (struct sockaddr *)dst_addr; |
| 5046 | t_addr->sa_family = AF_INET; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5047 | addr = (struct sockaddr_in *)dst_addr; |
| 5048 | ip = (char *)&addr->sin_addr; |
| 5049 | memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN); |
| 5050 | addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port)); |
| 5051 | } |
| 5052 | |
Manish Rangankar | 3dd4849 | 2012-11-23 06:58:40 -0500 | [diff] [blame] | 5053 | ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5054 | vfree(dst_addr); |
| 5055 | return ep; |
| 5056 | } |
| 5057 | |
| 5058 | static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx) |
| 5059 | { |
| 5060 | if (ql4xdisablesysfsboot) |
| 5061 | return QLA_SUCCESS; |
| 5062 | if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx) |
| 5063 | return QLA_ERROR; |
| 5064 | return QLA_SUCCESS; |
| 5065 | } |
| 5066 | |
| 5067 | static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 5068 | struct ddb_entry *ddb_entry, |
| 5069 | uint16_t idx) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5070 | { |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 5071 | uint16_t def_timeout; |
| 5072 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5073 | ddb_entry->ddb_type = FLASH_DDB; |
| 5074 | ddb_entry->fw_ddb_index = INVALID_ENTRY; |
| 5075 | ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| 5076 | ddb_entry->ha = ha; |
| 5077 | ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb; |
| 5078 | ddb_entry->ddb_change = qla4xxx_flash_ddb_change; |
| 5079 | |
| 5080 | atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); |
| 5081 | atomic_set(&ddb_entry->relogin_timer, 0); |
| 5082 | atomic_set(&ddb_entry->relogin_retry_count, 0); |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 5083 | def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5084 | ddb_entry->default_relogin_timeout = |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 5085 | (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ? |
| 5086 | def_timeout : LOGIN_TOV; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5087 | ddb_entry->default_time2wait = |
| 5088 | le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 5089 | |
| 5090 | if (ql4xdisablesysfsboot && |
| 5091 | (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)) |
| 5092 | set_bit(DF_BOOT_TGT, &ddb_entry->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha) |
| 5096 | { |
| 5097 | uint32_t idx = 0; |
| 5098 | uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */ |
| 5099 | uint32_t sts[MBOX_REG_COUNT]; |
| 5100 | uint32_t ip_state; |
| 5101 | unsigned long wtime; |
| 5102 | int ret; |
| 5103 | |
| 5104 | wtime = jiffies + (HZ * IP_CONFIG_TOV); |
| 5105 | do { |
| 5106 | for (idx = 0; idx < IP_ADDR_COUNT; idx++) { |
| 5107 | if (ip_idx[idx] == -1) |
| 5108 | continue; |
| 5109 | |
| 5110 | ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts); |
| 5111 | |
| 5112 | if (ret == QLA_ERROR) { |
| 5113 | ip_idx[idx] = -1; |
| 5114 | continue; |
| 5115 | } |
| 5116 | |
| 5117 | ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT; |
| 5118 | |
| 5119 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5120 | "Waiting for IP state for idx = %d, state = 0x%x\n", |
| 5121 | ip_idx[idx], ip_state)); |
| 5122 | if (ip_state == IP_ADDRSTATE_UNCONFIGURED || |
| 5123 | ip_state == IP_ADDRSTATE_INVALID || |
| 5124 | ip_state == IP_ADDRSTATE_PREFERRED || |
| 5125 | ip_state == IP_ADDRSTATE_DEPRICATED || |
| 5126 | ip_state == IP_ADDRSTATE_DISABLING) |
| 5127 | ip_idx[idx] = -1; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | /* Break if all IP states checked */ |
| 5131 | if ((ip_idx[0] == -1) && |
| 5132 | (ip_idx[1] == -1) && |
| 5133 | (ip_idx[2] == -1) && |
| 5134 | (ip_idx[3] == -1)) |
| 5135 | break; |
| 5136 | schedule_timeout_uninterruptible(HZ); |
| 5137 | } while (time_after(wtime, jiffies)); |
| 5138 | } |
| 5139 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5140 | static void qla4xxx_build_st_list(struct scsi_qla_host *ha, |
| 5141 | struct list_head *list_st) |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5142 | { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5143 | struct qla_ddb_index *st_ddb_idx; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5144 | int max_ddbs; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5145 | int fw_idx_size; |
| 5146 | struct dev_db_entry *fw_ddb_entry; |
| 5147 | dma_addr_t fw_ddb_dma; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5148 | int ret; |
| 5149 | uint32_t idx = 0, next_idx = 0; |
| 5150 | uint32_t state = 0, conn_err = 0; |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5151 | uint16_t conn_id = 0; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5152 | |
| 5153 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 5154 | &fw_ddb_dma); |
| 5155 | if (fw_ddb_entry == NULL) { |
| 5156 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5157 | goto exit_st_list; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5158 | } |
| 5159 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5160 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 5161 | MAX_DEV_DB_ENTRIES; |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5162 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 5163 | |
| 5164 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5165 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 5166 | NULL, &next_idx, &state, |
| 5167 | &conn_err, NULL, &conn_id); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5168 | if (ret == QLA_ERROR) |
| 5169 | break; |
| 5170 | |
Lalit Chandivade | 981c982 | 2012-02-13 18:30:41 +0530 | [diff] [blame] | 5171 | /* Ignore DDB if invalid state (unassigned) */ |
| 5172 | if (state == DDB_DS_UNASSIGNED) |
| 5173 | goto continue_next_st; |
| 5174 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5175 | /* Check if ST, add to the list_st */ |
| 5176 | if (strlen((char *) fw_ddb_entry->iscsi_name) != 0) |
| 5177 | goto continue_next_st; |
| 5178 | |
| 5179 | st_ddb_idx = vzalloc(fw_idx_size); |
| 5180 | if (!st_ddb_idx) |
| 5181 | break; |
| 5182 | |
| 5183 | st_ddb_idx->fw_ddb_idx = idx; |
| 5184 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5185 | list_add_tail(&st_ddb_idx->list, list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 5186 | continue_next_st: |
| 5187 | if (next_idx == 0) |
| 5188 | break; |
| 5189 | } |
| 5190 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5191 | exit_st_list: |
| 5192 | if (fw_ddb_entry) |
| 5193 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 5194 | } |
| 5195 | |
| 5196 | /** |
| 5197 | * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list |
| 5198 | * @ha: pointer to adapter structure |
| 5199 | * @list_ddb: List from which failed ddb to be removed |
| 5200 | * |
| 5201 | * Iterate over the list of DDBs and find and remove DDBs that are either in |
| 5202 | * no connection active state or failed state |
| 5203 | **/ |
| 5204 | static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha, |
| 5205 | struct list_head *list_ddb) |
| 5206 | { |
| 5207 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 5208 | uint32_t next_idx = 0; |
| 5209 | uint32_t state = 0, conn_err = 0; |
| 5210 | int ret; |
| 5211 | |
| 5212 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) { |
| 5213 | ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx, |
| 5214 | NULL, 0, NULL, &next_idx, &state, |
| 5215 | &conn_err, NULL, NULL); |
| 5216 | if (ret == QLA_ERROR) |
| 5217 | continue; |
| 5218 | |
| 5219 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 5220 | state == DDB_DS_SESSION_FAILED) { |
| 5221 | list_del_init(&ddb_idx->list); |
| 5222 | vfree(ddb_idx); |
| 5223 | } |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha, |
| 5228 | struct dev_db_entry *fw_ddb_entry, |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 5229 | int is_reset, uint16_t idx) |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5230 | { |
| 5231 | struct iscsi_cls_session *cls_sess; |
| 5232 | struct iscsi_session *sess; |
| 5233 | struct iscsi_cls_conn *cls_conn; |
| 5234 | struct iscsi_endpoint *ep; |
| 5235 | uint16_t cmds_max = 32; |
| 5236 | uint16_t conn_id = 0; |
| 5237 | uint32_t initial_cmdsn = 0; |
| 5238 | int ret = QLA_SUCCESS; |
| 5239 | |
| 5240 | struct ddb_entry *ddb_entry = NULL; |
| 5241 | |
| 5242 | /* Create session object, with INVALID_ENTRY, |
| 5243 | * the targer_id would get set when we issue the login |
| 5244 | */ |
| 5245 | cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host, |
| 5246 | cmds_max, sizeof(struct ddb_entry), |
| 5247 | sizeof(struct ql4_task_data), |
| 5248 | initial_cmdsn, INVALID_ENTRY); |
| 5249 | if (!cls_sess) { |
| 5250 | ret = QLA_ERROR; |
| 5251 | goto exit_setup; |
| 5252 | } |
| 5253 | |
| 5254 | /* |
| 5255 | * so calling module_put function to decrement the |
| 5256 | * reference count. |
| 5257 | **/ |
| 5258 | module_put(qla4xxx_iscsi_transport.owner); |
| 5259 | sess = cls_sess->dd_data; |
| 5260 | ddb_entry = sess->dd_data; |
| 5261 | ddb_entry->sess = cls_sess; |
| 5262 | |
| 5263 | cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| 5264 | memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry, |
| 5265 | sizeof(struct dev_db_entry)); |
| 5266 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 5267 | qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5268 | |
| 5269 | cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id); |
| 5270 | |
| 5271 | if (!cls_conn) { |
| 5272 | ret = QLA_ERROR; |
| 5273 | goto exit_setup; |
| 5274 | } |
| 5275 | |
| 5276 | ddb_entry->conn = cls_conn; |
| 5277 | |
| 5278 | /* Setup ep, for displaying attributes in sysfs */ |
| 5279 | ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry); |
| 5280 | if (ep) { |
| 5281 | ep->conn = cls_conn; |
| 5282 | cls_conn->ep = ep; |
| 5283 | } else { |
| 5284 | DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n")); |
| 5285 | ret = QLA_ERROR; |
| 5286 | goto exit_setup; |
| 5287 | } |
| 5288 | |
| 5289 | /* Update sess/conn params */ |
| 5290 | qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| 5291 | |
| 5292 | if (is_reset == RESET_ADAPTER) { |
| 5293 | iscsi_block_session(cls_sess); |
| 5294 | /* Use the relogin path to discover new devices |
| 5295 | * by short-circuting the logic of setting |
| 5296 | * timer to relogin - instead set the flags |
| 5297 | * to initiate login right away. |
| 5298 | */ |
| 5299 | set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| 5300 | set_bit(DF_RELOGIN, &ddb_entry->flags); |
| 5301 | } |
| 5302 | |
| 5303 | exit_setup: |
| 5304 | return ret; |
| 5305 | } |
| 5306 | |
| 5307 | static void qla4xxx_build_nt_list(struct scsi_qla_host *ha, |
| 5308 | struct list_head *list_nt, int is_reset) |
| 5309 | { |
| 5310 | struct dev_db_entry *fw_ddb_entry; |
| 5311 | dma_addr_t fw_ddb_dma; |
| 5312 | int max_ddbs; |
| 5313 | int fw_idx_size; |
| 5314 | int ret; |
| 5315 | uint32_t idx = 0, next_idx = 0; |
| 5316 | uint32_t state = 0, conn_err = 0; |
| 5317 | uint16_t conn_id = 0; |
| 5318 | struct qla_ddb_index *nt_ddb_idx; |
| 5319 | |
| 5320 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 5321 | &fw_ddb_dma); |
| 5322 | if (fw_ddb_entry == NULL) { |
| 5323 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 5324 | goto exit_nt_list; |
| 5325 | } |
| 5326 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 5327 | MAX_DEV_DB_ENTRIES; |
| 5328 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 5329 | |
| 5330 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 5331 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 5332 | NULL, &next_idx, &state, |
| 5333 | &conn_err, NULL, &conn_id); |
| 5334 | if (ret == QLA_ERROR) |
| 5335 | break; |
| 5336 | |
| 5337 | if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS) |
| 5338 | goto continue_next_nt; |
| 5339 | |
| 5340 | /* Check if NT, then add to list it */ |
| 5341 | if (strlen((char *) fw_ddb_entry->iscsi_name) == 0) |
| 5342 | goto continue_next_nt; |
| 5343 | |
| 5344 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 5345 | state == DDB_DS_SESSION_FAILED)) |
| 5346 | goto continue_next_nt; |
| 5347 | |
| 5348 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5349 | "Adding DDB to session = 0x%x\n", idx)); |
| 5350 | if (is_reset == INIT_ADAPTER) { |
| 5351 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 5352 | if (!nt_ddb_idx) |
| 5353 | break; |
| 5354 | |
| 5355 | nt_ddb_idx->fw_ddb_idx = idx; |
| 5356 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 5357 | /* Copy original isid as it may get updated in function |
| 5358 | * qla4xxx_update_isid(). We need original isid in |
| 5359 | * function qla4xxx_compare_tuple_ddb to find duplicate |
| 5360 | * target */ |
| 5361 | memcpy(&nt_ddb_idx->flash_isid[0], |
| 5362 | &fw_ddb_entry->isid[0], |
| 5363 | sizeof(nt_ddb_idx->flash_isid)); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5364 | |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 5365 | ret = qla4xxx_is_flash_ddb_exists(ha, list_nt, |
| 5366 | fw_ddb_entry); |
| 5367 | if (ret == QLA_SUCCESS) { |
| 5368 | /* free nt_ddb_idx and do not add to list_nt */ |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5369 | vfree(nt_ddb_idx); |
| 5370 | goto continue_next_nt; |
| 5371 | } |
Vikas Chaudhary | 1cb78d7 | 2012-06-14 06:35:48 -0400 | [diff] [blame] | 5372 | |
| 5373 | /* Copy updated isid */ |
| 5374 | memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry, |
| 5375 | sizeof(struct dev_db_entry)); |
| 5376 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5377 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 5378 | } else if (is_reset == RESET_ADAPTER) { |
| 5379 | if (qla4xxx_is_session_exists(ha, fw_ddb_entry) == |
| 5380 | QLA_SUCCESS) |
| 5381 | goto continue_next_nt; |
| 5382 | } |
| 5383 | |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 5384 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx); |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 5385 | if (ret == QLA_ERROR) |
| 5386 | goto exit_nt_list; |
| 5387 | |
| 5388 | continue_next_nt: |
| 5389 | if (next_idx == 0) |
| 5390 | break; |
| 5391 | } |
| 5392 | |
| 5393 | exit_nt_list: |
| 5394 | if (fw_ddb_entry) |
| 5395 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 5396 | } |
| 5397 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 5398 | static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha, |
| 5399 | struct list_head *list_nt) |
| 5400 | { |
| 5401 | struct dev_db_entry *fw_ddb_entry; |
| 5402 | dma_addr_t fw_ddb_dma; |
| 5403 | int max_ddbs; |
| 5404 | int fw_idx_size; |
| 5405 | int ret; |
| 5406 | uint32_t idx = 0, next_idx = 0; |
| 5407 | uint32_t state = 0, conn_err = 0; |
| 5408 | uint16_t conn_id = 0; |
| 5409 | struct qla_ddb_index *nt_ddb_idx; |
| 5410 | |
| 5411 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 5412 | &fw_ddb_dma); |
| 5413 | if (fw_ddb_entry == NULL) { |
| 5414 | DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); |
| 5415 | goto exit_new_nt_list; |
| 5416 | } |
| 5417 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 5418 | MAX_DEV_DB_ENTRIES; |
| 5419 | fw_idx_size = sizeof(struct qla_ddb_index); |
| 5420 | |
| 5421 | for (idx = 0; idx < max_ddbs; idx = next_idx) { |
| 5422 | ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma, |
| 5423 | NULL, &next_idx, &state, |
| 5424 | &conn_err, NULL, &conn_id); |
| 5425 | if (ret == QLA_ERROR) |
| 5426 | break; |
| 5427 | |
| 5428 | /* Check if NT, then add it to list */ |
| 5429 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
| 5430 | goto continue_next_new_nt; |
| 5431 | |
| 5432 | if (!(state == DDB_DS_NO_CONNECTION_ACTIVE)) |
| 5433 | goto continue_next_new_nt; |
| 5434 | |
| 5435 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5436 | "Adding DDB to session = 0x%x\n", idx)); |
| 5437 | |
| 5438 | nt_ddb_idx = vmalloc(fw_idx_size); |
| 5439 | if (!nt_ddb_idx) |
| 5440 | break; |
| 5441 | |
| 5442 | nt_ddb_idx->fw_ddb_idx = idx; |
| 5443 | |
| 5444 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry); |
| 5445 | if (ret == QLA_SUCCESS) { |
| 5446 | /* free nt_ddb_idx and do not add to list_nt */ |
| 5447 | vfree(nt_ddb_idx); |
| 5448 | goto continue_next_new_nt; |
| 5449 | } |
| 5450 | |
| 5451 | list_add_tail(&nt_ddb_idx->list, list_nt); |
| 5452 | |
| 5453 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 5454 | idx); |
| 5455 | if (ret == QLA_ERROR) |
| 5456 | goto exit_new_nt_list; |
| 5457 | |
| 5458 | continue_next_new_nt: |
| 5459 | if (next_idx == 0) |
| 5460 | break; |
| 5461 | } |
| 5462 | |
| 5463 | exit_new_nt_list: |
| 5464 | if (fw_ddb_entry) |
| 5465 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 5466 | } |
| 5467 | |
| 5468 | /** |
| 5469 | * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry |
| 5470 | * @dev: dev associated with the sysfs entry |
| 5471 | * @data: pointer to flashnode session object |
| 5472 | * |
| 5473 | * Returns: |
| 5474 | * 1: if flashnode entry is non-persistent |
| 5475 | * 0: if flashnode entry is persistent |
| 5476 | **/ |
| 5477 | static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data) |
| 5478 | { |
| 5479 | struct iscsi_bus_flash_session *fnode_sess; |
| 5480 | |
| 5481 | if (!iscsi_flashnode_bus_match(dev, NULL)) |
| 5482 | return 0; |
| 5483 | |
| 5484 | fnode_sess = iscsi_dev_to_flash_session(dev); |
| 5485 | |
| 5486 | return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT); |
| 5487 | } |
| 5488 | |
| 5489 | /** |
| 5490 | * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target |
| 5491 | * @ha: pointer to host |
| 5492 | * @fw_ddb_entry: flash ddb data |
| 5493 | * @idx: target index |
| 5494 | * @user: if set then this call is made from userland else from kernel |
| 5495 | * |
| 5496 | * Returns: |
| 5497 | * On sucess: QLA_SUCCESS |
| 5498 | * On failure: QLA_ERROR |
| 5499 | * |
| 5500 | * This create separate sysfs entries for session and connection attributes of |
| 5501 | * the given fw ddb entry. |
| 5502 | * If this is invoked as a result of a userspace call then the entry is marked |
| 5503 | * as nonpersistent using flash_state field. |
| 5504 | **/ |
| 5505 | int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha, |
| 5506 | struct dev_db_entry *fw_ddb_entry, |
| 5507 | uint16_t *idx, int user) |
| 5508 | { |
| 5509 | struct iscsi_bus_flash_session *fnode_sess = NULL; |
| 5510 | struct iscsi_bus_flash_conn *fnode_conn = NULL; |
| 5511 | int rc = QLA_ERROR; |
| 5512 | |
| 5513 | fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx, |
| 5514 | &qla4xxx_iscsi_transport, 0); |
| 5515 | if (!fnode_sess) { |
| 5516 | ql4_printk(KERN_ERR, ha, |
| 5517 | "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n", |
| 5518 | __func__, *idx, ha->host_no); |
| 5519 | goto exit_tgt_create; |
| 5520 | } |
| 5521 | |
| 5522 | fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess, |
| 5523 | &qla4xxx_iscsi_transport, 0); |
| 5524 | if (!fnode_conn) { |
| 5525 | ql4_printk(KERN_ERR, ha, |
| 5526 | "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n", |
| 5527 | __func__, *idx, ha->host_no); |
| 5528 | goto free_sess; |
| 5529 | } |
| 5530 | |
| 5531 | if (user) { |
| 5532 | fnode_sess->flash_state = DEV_DB_NON_PERSISTENT; |
| 5533 | } else { |
| 5534 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 5535 | |
| 5536 | if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx) |
| 5537 | fnode_sess->is_boot_target = 1; |
| 5538 | else |
| 5539 | fnode_sess->is_boot_target = 0; |
| 5540 | } |
| 5541 | |
| 5542 | rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn, |
| 5543 | fw_ddb_entry); |
| 5544 | |
| 5545 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 5546 | __func__, fnode_sess->dev.kobj.name); |
| 5547 | |
| 5548 | ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n", |
| 5549 | __func__, fnode_conn->dev.kobj.name); |
| 5550 | |
| 5551 | return QLA_SUCCESS; |
| 5552 | |
| 5553 | free_sess: |
| 5554 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 5555 | |
| 5556 | exit_tgt_create: |
| 5557 | return QLA_ERROR; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
| 5561 | * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash |
| 5562 | * @shost: pointer to host |
| 5563 | * @buf: type of ddb entry (ipv4/ipv6) |
| 5564 | * @len: length of buf |
| 5565 | * |
| 5566 | * This creates new ddb entry in the flash by finding first free index and |
| 5567 | * storing default ddb there. And then create sysfs entry for the new ddb entry. |
| 5568 | **/ |
| 5569 | static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf, |
| 5570 | int len) |
| 5571 | { |
| 5572 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 5573 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 5574 | dma_addr_t fw_ddb_entry_dma; |
| 5575 | struct device *dev; |
| 5576 | uint16_t idx = 0; |
| 5577 | uint16_t max_ddbs = 0; |
| 5578 | uint32_t options = 0; |
| 5579 | uint32_t rval = QLA_ERROR; |
| 5580 | |
| 5581 | if (strncasecmp(DEV_TYPE_IPV4, buf, 4) && |
| 5582 | strncasecmp(DEV_TYPE_IPV6, buf, 4)) { |
| 5583 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n", |
| 5584 | __func__)); |
| 5585 | goto exit_ddb_add; |
| 5586 | } |
| 5587 | |
| 5588 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 5589 | MAX_DEV_DB_ENTRIES; |
| 5590 | |
| 5591 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5592 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 5593 | if (!fw_ddb_entry) { |
| 5594 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5595 | "%s: Unable to allocate dma buffer\n", |
| 5596 | __func__)); |
| 5597 | goto exit_ddb_add; |
| 5598 | } |
| 5599 | |
| 5600 | dev = iscsi_find_flashnode_sess(ha->host, NULL, |
| 5601 | qla4xxx_sysfs_ddb_is_non_persistent); |
| 5602 | if (dev) { |
| 5603 | ql4_printk(KERN_ERR, ha, |
| 5604 | "%s: A non-persistent entry %s found\n", |
| 5605 | __func__, dev->kobj.name); |
| 5606 | goto exit_ddb_add; |
| 5607 | } |
| 5608 | |
| 5609 | for (idx = 0; idx < max_ddbs; idx++) { |
| 5610 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, |
| 5611 | fw_ddb_entry_dma, idx)) |
| 5612 | break; |
| 5613 | } |
| 5614 | |
| 5615 | if (idx == max_ddbs) |
| 5616 | goto exit_ddb_add; |
| 5617 | |
| 5618 | if (!strncasecmp("ipv6", buf, 4)) |
| 5619 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 5620 | |
| 5621 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 5622 | if (rval == QLA_ERROR) |
| 5623 | goto exit_ddb_add; |
| 5624 | |
| 5625 | rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1); |
| 5626 | |
| 5627 | exit_ddb_add: |
| 5628 | if (fw_ddb_entry) |
| 5629 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5630 | fw_ddb_entry, fw_ddb_entry_dma); |
| 5631 | if (rval == QLA_SUCCESS) |
| 5632 | return idx; |
| 5633 | else |
| 5634 | return -EIO; |
| 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash |
| 5639 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 5640 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 5641 | * |
| 5642 | * This writes the contents of target ddb buffer to Flash with a valid cookie |
| 5643 | * value in order to make the ddb entry persistent. |
| 5644 | **/ |
| 5645 | static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess, |
| 5646 | struct iscsi_bus_flash_conn *fnode_conn) |
| 5647 | { |
| 5648 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 5649 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 5650 | uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
| 5651 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 5652 | dma_addr_t fw_ddb_entry_dma; |
| 5653 | uint32_t options = 0; |
| 5654 | int rval = 0; |
| 5655 | |
| 5656 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5657 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 5658 | if (!fw_ddb_entry) { |
| 5659 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5660 | "%s: Unable to allocate dma buffer\n", |
| 5661 | __func__)); |
| 5662 | rval = -ENOMEM; |
| 5663 | goto exit_ddb_apply; |
| 5664 | } |
| 5665 | |
| 5666 | if (!strncasecmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 5667 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 5668 | |
| 5669 | rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 5670 | if (rval == QLA_ERROR) |
| 5671 | goto exit_ddb_apply; |
| 5672 | |
| 5673 | dev_db_start_offset += (fnode_sess->target_id * |
| 5674 | sizeof(*fw_ddb_entry)); |
| 5675 | |
| 5676 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 5677 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 5678 | |
| 5679 | rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
| 5680 | sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT); |
| 5681 | |
| 5682 | if (rval == QLA_SUCCESS) { |
| 5683 | fnode_sess->flash_state = DEV_DB_PERSISTENT; |
| 5684 | ql4_printk(KERN_INFO, ha, |
| 5685 | "%s: flash node %u of host %lu written to flash\n", |
| 5686 | __func__, fnode_sess->target_id, ha->host_no); |
| 5687 | } else { |
| 5688 | rval = -EIO; |
| 5689 | ql4_printk(KERN_ERR, ha, |
| 5690 | "%s: Error while writing flash node %u of host %lu to flash\n", |
| 5691 | __func__, fnode_sess->target_id, ha->host_no); |
| 5692 | } |
| 5693 | |
| 5694 | exit_ddb_apply: |
| 5695 | if (fw_ddb_entry) |
| 5696 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5697 | fw_ddb_entry, fw_ddb_entry_dma); |
| 5698 | return rval; |
| 5699 | } |
| 5700 | |
| 5701 | static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha, |
| 5702 | struct dev_db_entry *fw_ddb_entry, |
| 5703 | uint16_t idx) |
| 5704 | { |
| 5705 | struct dev_db_entry *ddb_entry = NULL; |
| 5706 | dma_addr_t ddb_entry_dma; |
| 5707 | unsigned long wtime; |
| 5708 | uint32_t mbx_sts = 0; |
| 5709 | uint32_t state = 0, conn_err = 0; |
| 5710 | uint16_t tmo = 0; |
| 5711 | int ret = 0; |
| 5712 | |
| 5713 | ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 5714 | &ddb_entry_dma, GFP_KERNEL); |
| 5715 | if (!ddb_entry) { |
| 5716 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5717 | "%s: Unable to allocate dma buffer\n", |
| 5718 | __func__)); |
| 5719 | return QLA_ERROR; |
| 5720 | } |
| 5721 | |
| 5722 | memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry)); |
| 5723 | |
| 5724 | ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts); |
| 5725 | if (ret != QLA_SUCCESS) { |
| 5726 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5727 | "%s: Unable to set ddb entry for index %d\n", |
| 5728 | __func__, idx)); |
| 5729 | goto exit_ddb_conn_open; |
| 5730 | } |
| 5731 | |
| 5732 | qla4xxx_conn_open(ha, idx); |
| 5733 | |
| 5734 | /* To ensure that sendtargets is done, wait for at least 12 secs */ |
| 5735 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 5736 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 5737 | ha->def_timeout : LOGIN_TOV); |
| 5738 | |
| 5739 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 5740 | "Default time to wait for login to ddb %d\n", tmo)); |
| 5741 | |
| 5742 | wtime = jiffies + (HZ * tmo); |
| 5743 | do { |
| 5744 | ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL, |
| 5745 | NULL, &state, &conn_err, NULL, |
| 5746 | NULL); |
| 5747 | if (ret == QLA_ERROR) |
| 5748 | continue; |
| 5749 | |
| 5750 | if (state == DDB_DS_NO_CONNECTION_ACTIVE || |
| 5751 | state == DDB_DS_SESSION_FAILED) |
| 5752 | break; |
| 5753 | |
| 5754 | schedule_timeout_uninterruptible(HZ / 10); |
| 5755 | } while (time_after(wtime, jiffies)); |
| 5756 | |
| 5757 | exit_ddb_conn_open: |
| 5758 | if (ddb_entry) |
| 5759 | dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry), |
| 5760 | ddb_entry, ddb_entry_dma); |
| 5761 | return ret; |
| 5762 | } |
| 5763 | |
| 5764 | static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha, |
| 5765 | struct dev_db_entry *fw_ddb_entry) |
| 5766 | { |
| 5767 | struct qla_ddb_index *ddb_idx, *ddb_idx_tmp; |
| 5768 | struct list_head list_nt; |
| 5769 | uint16_t ddb_index; |
| 5770 | int ret = 0; |
| 5771 | |
| 5772 | if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) { |
| 5773 | ql4_printk(KERN_WARNING, ha, |
| 5774 | "%s: A discovery already in progress!\n", __func__); |
| 5775 | return QLA_ERROR; |
| 5776 | } |
| 5777 | |
| 5778 | INIT_LIST_HEAD(&list_nt); |
| 5779 | |
| 5780 | set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 5781 | |
| 5782 | ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| 5783 | if (ret == QLA_ERROR) |
| 5784 | goto exit_login_st_clr_bit; |
| 5785 | |
| 5786 | ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index); |
| 5787 | if (ret == QLA_ERROR) |
| 5788 | goto exit_login_st; |
| 5789 | |
| 5790 | qla4xxx_build_new_nt_list(ha, &list_nt); |
| 5791 | |
| 5792 | list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) { |
| 5793 | list_del_init(&ddb_idx->list); |
| 5794 | qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx); |
| 5795 | vfree(ddb_idx); |
| 5796 | } |
| 5797 | |
| 5798 | exit_login_st: |
| 5799 | if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) { |
| 5800 | ql4_printk(KERN_ERR, ha, |
| 5801 | "Unable to clear DDB index = 0x%x\n", ddb_index); |
| 5802 | } |
| 5803 | |
| 5804 | clear_bit(ddb_index, ha->ddb_idx_map); |
| 5805 | |
| 5806 | exit_login_st_clr_bit: |
| 5807 | clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags); |
| 5808 | return ret; |
| 5809 | } |
| 5810 | |
| 5811 | static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha, |
| 5812 | struct dev_db_entry *fw_ddb_entry, |
| 5813 | uint16_t idx) |
| 5814 | { |
| 5815 | int ret = QLA_ERROR; |
| 5816 | |
| 5817 | ret = qla4xxx_is_session_exists(ha, fw_ddb_entry); |
| 5818 | if (ret != QLA_SUCCESS) |
| 5819 | ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER, |
| 5820 | idx); |
| 5821 | else |
| 5822 | ret = -EPERM; |
| 5823 | |
| 5824 | return ret; |
| 5825 | } |
| 5826 | |
| 5827 | /** |
| 5828 | * qla4xxx_sysfs_ddb_login - Login to the specified target |
| 5829 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 5830 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 5831 | * |
| 5832 | * This logs in to the specified target |
| 5833 | **/ |
| 5834 | static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, |
| 5835 | struct iscsi_bus_flash_conn *fnode_conn) |
| 5836 | { |
| 5837 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 5838 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 5839 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 5840 | dma_addr_t fw_ddb_entry_dma; |
| 5841 | uint32_t options = 0; |
| 5842 | int ret = 0; |
| 5843 | |
| 5844 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) { |
| 5845 | ql4_printk(KERN_ERR, ha, |
| 5846 | "%s: Target info is not persistent\n", __func__); |
| 5847 | ret = -EIO; |
| 5848 | goto exit_ddb_login; |
| 5849 | } |
| 5850 | |
| 5851 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5852 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 5853 | if (!fw_ddb_entry) { |
| 5854 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 5855 | "%s: Unable to allocate dma buffer\n", |
| 5856 | __func__)); |
| 5857 | ret = -ENOMEM; |
| 5858 | goto exit_ddb_login; |
| 5859 | } |
| 5860 | |
| 5861 | if (!strncasecmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 5862 | options |= IPV6_DEFAULT_DDB_ENTRY; |
| 5863 | |
| 5864 | ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); |
| 5865 | if (ret == QLA_ERROR) |
| 5866 | goto exit_ddb_login; |
| 5867 | |
| 5868 | qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry); |
| 5869 | fw_ddb_entry->cookie = DDB_VALID_COOKIE; |
| 5870 | |
| 5871 | if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) |
| 5872 | ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry); |
| 5873 | else |
| 5874 | ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry, |
| 5875 | fnode_sess->target_id); |
| 5876 | |
| 5877 | if (ret > 0) |
| 5878 | ret = -EIO; |
| 5879 | |
| 5880 | exit_ddb_login: |
| 5881 | if (fw_ddb_entry) |
| 5882 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5883 | fw_ddb_entry, fw_ddb_entry_dma); |
| 5884 | return ret; |
| 5885 | } |
| 5886 | |
| 5887 | /** |
| 5888 | * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target |
| 5889 | * @cls_sess: pointer to session to be logged out |
| 5890 | * |
| 5891 | * This performs session log out from the specified target |
| 5892 | **/ |
| 5893 | static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess) |
| 5894 | { |
| 5895 | struct iscsi_session *sess; |
| 5896 | struct ddb_entry *ddb_entry = NULL; |
| 5897 | struct scsi_qla_host *ha; |
| 5898 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 5899 | dma_addr_t fw_ddb_entry_dma; |
| 5900 | unsigned long flags; |
| 5901 | unsigned long wtime; |
| 5902 | uint32_t ddb_state; |
| 5903 | int options; |
| 5904 | int ret = 0; |
| 5905 | |
| 5906 | sess = cls_sess->dd_data; |
| 5907 | ddb_entry = sess->dd_data; |
| 5908 | ha = ddb_entry->ha; |
| 5909 | |
| 5910 | if (ddb_entry->ddb_type != FLASH_DDB) { |
| 5911 | ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n", |
| 5912 | __func__); |
| 5913 | ret = -ENXIO; |
| 5914 | goto exit_ddb_logout; |
| 5915 | } |
| 5916 | |
| 5917 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 5918 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) { |
| 5919 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
| 5920 | ret = -EIO; |
| 5921 | goto exit_ddb_logout; |
| 5922 | } |
| 5923 | |
| 5924 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5925 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 5926 | if (!fw_ddb_entry) { |
| 5927 | ql4_printk(KERN_ERR, ha, |
| 5928 | "%s: Unable to allocate dma buffer\n", __func__); |
| 5929 | ret = -ENOMEM; |
| 5930 | goto exit_ddb_logout; |
| 5931 | } |
| 5932 | |
| 5933 | wtime = jiffies + (HZ * LOGOUT_TOV); |
| 5934 | do { |
| 5935 | ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, |
| 5936 | fw_ddb_entry, fw_ddb_entry_dma, |
| 5937 | NULL, NULL, &ddb_state, NULL, |
| 5938 | NULL, NULL); |
| 5939 | if (ret == QLA_ERROR) |
| 5940 | goto ddb_logout_clr_sess; |
| 5941 | |
| 5942 | if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) || |
| 5943 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 5944 | goto ddb_logout_clr_sess; |
| 5945 | |
| 5946 | schedule_timeout_uninterruptible(HZ); |
| 5947 | } while ((time_after(wtime, jiffies))); |
| 5948 | |
| 5949 | ddb_logout_clr_sess: |
| 5950 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 5951 | /* |
| 5952 | * we have decremented the reference count of the driver |
| 5953 | * when we setup the session to have the driver unload |
| 5954 | * to be seamless without actually destroying the |
| 5955 | * session |
| 5956 | **/ |
| 5957 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 5958 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 5959 | |
| 5960 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5961 | qla4xxx_free_ddb(ha, ddb_entry); |
| 5962 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5963 | |
| 5964 | iscsi_session_teardown(ddb_entry->sess); |
| 5965 | |
| 5966 | ret = QLA_SUCCESS; |
| 5967 | |
| 5968 | exit_ddb_logout: |
| 5969 | if (fw_ddb_entry) |
| 5970 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 5971 | fw_ddb_entry, fw_ddb_entry_dma); |
| 5972 | return ret; |
| 5973 | } |
| 5974 | |
| 5975 | /** |
| 5976 | * qla4xxx_sysfs_ddb_logout - Logout from the specified target |
| 5977 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 5978 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 5979 | * |
| 5980 | * This performs log out from the specified target |
| 5981 | **/ |
| 5982 | static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, |
| 5983 | struct iscsi_bus_flash_conn *fnode_conn) |
| 5984 | { |
| 5985 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 5986 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 5987 | struct ql4_tuple_ddb *flash_tddb = NULL; |
| 5988 | struct ql4_tuple_ddb *tmp_tddb = NULL; |
| 5989 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 5990 | struct ddb_entry *ddb_entry = NULL; |
| 5991 | dma_addr_t fw_ddb_dma; |
| 5992 | uint32_t next_idx = 0; |
| 5993 | uint32_t state = 0, conn_err = 0; |
| 5994 | uint16_t conn_id = 0; |
| 5995 | int idx, index; |
| 5996 | int status, ret = 0; |
| 5997 | |
| 5998 | fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL, |
| 5999 | &fw_ddb_dma); |
| 6000 | if (fw_ddb_entry == NULL) { |
| 6001 | ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__); |
| 6002 | ret = -ENOMEM; |
| 6003 | goto exit_ddb_logout; |
| 6004 | } |
| 6005 | |
| 6006 | flash_tddb = vzalloc(sizeof(*flash_tddb)); |
| 6007 | if (!flash_tddb) { |
| 6008 | ql4_printk(KERN_WARNING, ha, |
| 6009 | "%s:Memory Allocation failed.\n", __func__); |
| 6010 | ret = -ENOMEM; |
| 6011 | goto exit_ddb_logout; |
| 6012 | } |
| 6013 | |
| 6014 | tmp_tddb = vzalloc(sizeof(*tmp_tddb)); |
| 6015 | if (!tmp_tddb) { |
| 6016 | ql4_printk(KERN_WARNING, ha, |
| 6017 | "%s:Memory Allocation failed.\n", __func__); |
| 6018 | ret = -ENOMEM; |
| 6019 | goto exit_ddb_logout; |
| 6020 | } |
| 6021 | |
| 6022 | if (!fnode_sess->targetname) { |
| 6023 | ql4_printk(KERN_ERR, ha, |
| 6024 | "%s:Cannot logout from SendTarget entry\n", |
| 6025 | __func__); |
| 6026 | ret = -EPERM; |
| 6027 | goto exit_ddb_logout; |
| 6028 | } |
| 6029 | |
| 6030 | if (fnode_sess->is_boot_target) { |
| 6031 | ql4_printk(KERN_ERR, ha, |
| 6032 | "%s: Logout from boot target entry is not permitted.\n", |
| 6033 | __func__); |
| 6034 | ret = -EPERM; |
| 6035 | goto exit_ddb_logout; |
| 6036 | } |
| 6037 | |
| 6038 | strncpy(flash_tddb->iscsi_name, fnode_sess->targetname, |
| 6039 | ISCSI_NAME_SIZE); |
| 6040 | |
| 6041 | if (!strncmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 6042 | sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress); |
| 6043 | else |
| 6044 | sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress); |
| 6045 | |
| 6046 | flash_tddb->tpgt = fnode_sess->tpgt; |
| 6047 | flash_tddb->port = fnode_conn->port; |
| 6048 | |
| 6049 | COPY_ISID(flash_tddb->isid, fnode_sess->isid); |
| 6050 | |
| 6051 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 6052 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 6053 | if (ddb_entry == NULL) |
| 6054 | continue; |
| 6055 | |
| 6056 | if (ddb_entry->ddb_type != FLASH_DDB) |
| 6057 | continue; |
| 6058 | |
| 6059 | index = ddb_entry->sess->target_id; |
| 6060 | status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry, |
| 6061 | fw_ddb_dma, NULL, &next_idx, |
| 6062 | &state, &conn_err, NULL, |
| 6063 | &conn_id); |
| 6064 | if (status == QLA_ERROR) { |
| 6065 | ret = -ENOMEM; |
| 6066 | break; |
| 6067 | } |
| 6068 | |
| 6069 | qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL); |
| 6070 | |
| 6071 | status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb, |
| 6072 | true); |
| 6073 | if (status == QLA_SUCCESS) { |
| 6074 | ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess); |
| 6075 | break; |
| 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | if (idx == MAX_DDB_ENTRIES) |
| 6080 | ret = -ESRCH; |
| 6081 | |
| 6082 | exit_ddb_logout: |
| 6083 | if (flash_tddb) |
| 6084 | vfree(flash_tddb); |
| 6085 | if (tmp_tddb) |
| 6086 | vfree(tmp_tddb); |
| 6087 | if (fw_ddb_entry) |
| 6088 | dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma); |
| 6089 | |
| 6090 | return ret; |
| 6091 | } |
| 6092 | |
| 6093 | static int |
| 6094 | qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess, |
| 6095 | int param, char *buf) |
| 6096 | { |
| 6097 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 6098 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 6099 | struct iscsi_bus_flash_conn *fnode_conn; |
| 6100 | struct ql4_chap_table chap_tbl; |
| 6101 | struct device *dev; |
| 6102 | int parent_type, parent_index = 0xffff; |
| 6103 | int rc = 0; |
| 6104 | |
| 6105 | dev = iscsi_find_flashnode_conn(fnode_sess, NULL, |
| 6106 | iscsi_is_flashnode_conn_dev); |
| 6107 | if (!dev) |
| 6108 | return -EIO; |
| 6109 | |
| 6110 | fnode_conn = iscsi_dev_to_flash_conn(dev); |
| 6111 | |
| 6112 | switch (param) { |
| 6113 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 6114 | rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6); |
| 6115 | break; |
| 6116 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 6117 | rc = sprintf(buf, "%s\n", fnode_sess->portal_type); |
| 6118 | break; |
| 6119 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 6120 | rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable); |
| 6121 | break; |
| 6122 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 6123 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess); |
| 6124 | break; |
| 6125 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 6126 | rc = sprintf(buf, "%u\n", fnode_sess->entry_state); |
| 6127 | break; |
| 6128 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 6129 | rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en); |
| 6130 | break; |
| 6131 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 6132 | rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en); |
| 6133 | break; |
| 6134 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 6135 | rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en); |
| 6136 | break; |
| 6137 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 6138 | rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en); |
| 6139 | break; |
| 6140 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 6141 | rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en); |
| 6142 | break; |
| 6143 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 6144 | rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en); |
| 6145 | break; |
| 6146 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 6147 | rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en); |
| 6148 | break; |
| 6149 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 6150 | rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en); |
| 6151 | break; |
| 6152 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 6153 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en); |
| 6154 | break; |
| 6155 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 6156 | rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en); |
| 6157 | break; |
| 6158 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 6159 | rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional); |
| 6160 | break; |
| 6161 | case ISCSI_FLASHNODE_ERL: |
| 6162 | rc = sprintf(buf, "%u\n", fnode_sess->erl); |
| 6163 | break; |
| 6164 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 6165 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat); |
| 6166 | break; |
| 6167 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 6168 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable); |
| 6169 | break; |
| 6170 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 6171 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable); |
| 6172 | break; |
| 6173 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 6174 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale); |
| 6175 | break; |
| 6176 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 6177 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en); |
| 6178 | break; |
| 6179 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 6180 | rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable); |
| 6181 | break; |
| 6182 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 6183 | rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength); |
| 6184 | break; |
| 6185 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 6186 | rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength); |
| 6187 | break; |
| 6188 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 6189 | rc = sprintf(buf, "%u\n", fnode_sess->first_burst); |
| 6190 | break; |
| 6191 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 6192 | rc = sprintf(buf, "%u\n", fnode_sess->time2wait); |
| 6193 | break; |
| 6194 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 6195 | rc = sprintf(buf, "%u\n", fnode_sess->time2retain); |
| 6196 | break; |
| 6197 | case ISCSI_FLASHNODE_MAX_R2T: |
| 6198 | rc = sprintf(buf, "%u\n", fnode_sess->max_r2t); |
| 6199 | break; |
| 6200 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 6201 | rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout); |
| 6202 | break; |
| 6203 | case ISCSI_FLASHNODE_ISID: |
| 6204 | rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n", |
| 6205 | fnode_sess->isid[0], fnode_sess->isid[1], |
| 6206 | fnode_sess->isid[2], fnode_sess->isid[3], |
| 6207 | fnode_sess->isid[4], fnode_sess->isid[5]); |
| 6208 | break; |
| 6209 | case ISCSI_FLASHNODE_TSID: |
| 6210 | rc = sprintf(buf, "%u\n", fnode_sess->tsid); |
| 6211 | break; |
| 6212 | case ISCSI_FLASHNODE_PORT: |
| 6213 | rc = sprintf(buf, "%d\n", fnode_conn->port); |
| 6214 | break; |
| 6215 | case ISCSI_FLASHNODE_MAX_BURST: |
| 6216 | rc = sprintf(buf, "%u\n", fnode_sess->max_burst); |
| 6217 | break; |
| 6218 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 6219 | rc = sprintf(buf, "%u\n", |
| 6220 | fnode_sess->default_taskmgmt_timeout); |
| 6221 | break; |
| 6222 | case ISCSI_FLASHNODE_IPADDR: |
| 6223 | if (!strncmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 6224 | rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress); |
| 6225 | else |
| 6226 | rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress); |
| 6227 | break; |
| 6228 | case ISCSI_FLASHNODE_ALIAS: |
| 6229 | if (fnode_sess->targetalias) |
| 6230 | rc = sprintf(buf, "%s\n", fnode_sess->targetalias); |
| 6231 | else |
| 6232 | rc = sprintf(buf, "\n"); |
| 6233 | break; |
| 6234 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 6235 | if (!strncmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 6236 | rc = sprintf(buf, "%pI6\n", |
| 6237 | fnode_conn->redirect_ipaddr); |
| 6238 | else |
| 6239 | rc = sprintf(buf, "%pI4\n", |
| 6240 | fnode_conn->redirect_ipaddr); |
| 6241 | break; |
| 6242 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 6243 | rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size); |
| 6244 | break; |
| 6245 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 6246 | rc = sprintf(buf, "%u\n", fnode_conn->local_port); |
| 6247 | break; |
| 6248 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 6249 | rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos); |
| 6250 | break; |
| 6251 | case ISCSI_FLASHNODE_IPV6_TC: |
| 6252 | if (!strncmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 6253 | rc = sprintf(buf, "%u\n", |
| 6254 | fnode_conn->ipv6_traffic_class); |
| 6255 | else |
| 6256 | rc = sprintf(buf, "\n"); |
| 6257 | break; |
| 6258 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 6259 | rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label); |
| 6260 | break; |
| 6261 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 6262 | if (!strncmp(fnode_sess->portal_type, DEV_TYPE_IPV6, 4)) |
| 6263 | rc = sprintf(buf, "%pI6\n", |
| 6264 | fnode_conn->link_local_ipv6_addr); |
| 6265 | else |
| 6266 | rc = sprintf(buf, "\n"); |
| 6267 | break; |
| 6268 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: |
| 6269 | if ((fnode_sess->discovery_parent_idx) >= 0 && |
| 6270 | (fnode_sess->discovery_parent_idx < MAX_DDB_ENTRIES)) |
| 6271 | parent_index = fnode_sess->discovery_parent_idx; |
| 6272 | |
| 6273 | rc = sprintf(buf, "%u\n", parent_index); |
| 6274 | break; |
| 6275 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 6276 | if (fnode_sess->discovery_parent_type == DDB_ISNS) |
| 6277 | parent_type = ISCSI_DISC_PARENT_ISNS; |
| 6278 | else if (fnode_sess->discovery_parent_type == DDB_NO_LINK) |
| 6279 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
| 6280 | else if (fnode_sess->discovery_parent_type >= 0 && |
| 6281 | fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES) |
| 6282 | parent_type = ISCSI_DISC_PARENT_SENDTGT; |
| 6283 | else |
| 6284 | parent_type = ISCSI_DISC_PARENT_UNKNOWN; |
| 6285 | |
| 6286 | rc = sprintf(buf, "%s\n", |
| 6287 | iscsi_get_discovery_parent_name(parent_type)); |
| 6288 | break; |
| 6289 | case ISCSI_FLASHNODE_NAME: |
| 6290 | if (fnode_sess->targetname) |
| 6291 | rc = sprintf(buf, "%s\n", fnode_sess->targetname); |
| 6292 | else |
| 6293 | rc = sprintf(buf, "\n"); |
| 6294 | break; |
| 6295 | case ISCSI_FLASHNODE_TPGT: |
| 6296 | rc = sprintf(buf, "%u\n", fnode_sess->tpgt); |
| 6297 | break; |
| 6298 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 6299 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf); |
| 6300 | break; |
| 6301 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 6302 | rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf); |
| 6303 | break; |
| 6304 | case ISCSI_FLASHNODE_CHAP_OUT_IDX: |
| 6305 | rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx); |
| 6306 | break; |
| 6307 | case ISCSI_FLASHNODE_USERNAME: |
| 6308 | if (fnode_sess->chap_auth_en) { |
| 6309 | qla4xxx_get_uni_chap_at_index(ha, |
| 6310 | chap_tbl.name, |
| 6311 | chap_tbl.secret, |
| 6312 | fnode_sess->chap_out_idx); |
| 6313 | rc = sprintf(buf, "%s\n", chap_tbl.name); |
| 6314 | } else { |
| 6315 | rc = sprintf(buf, "\n"); |
| 6316 | } |
| 6317 | break; |
| 6318 | case ISCSI_FLASHNODE_PASSWORD: |
| 6319 | if (fnode_sess->chap_auth_en) { |
| 6320 | qla4xxx_get_uni_chap_at_index(ha, |
| 6321 | chap_tbl.name, |
| 6322 | chap_tbl.secret, |
| 6323 | fnode_sess->chap_out_idx); |
| 6324 | rc = sprintf(buf, "%s\n", chap_tbl.secret); |
| 6325 | } else { |
| 6326 | rc = sprintf(buf, "\n"); |
| 6327 | } |
| 6328 | break; |
| 6329 | case ISCSI_FLASHNODE_STATSN: |
| 6330 | rc = sprintf(buf, "%u\n", fnode_conn->statsn); |
| 6331 | break; |
| 6332 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 6333 | rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn); |
| 6334 | break; |
| 6335 | case ISCSI_FLASHNODE_IS_BOOT_TGT: |
| 6336 | rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target); |
| 6337 | break; |
| 6338 | default: |
| 6339 | rc = -ENOSYS; |
| 6340 | break; |
| 6341 | } |
| 6342 | return rc; |
| 6343 | } |
| 6344 | |
| 6345 | /** |
| 6346 | * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry |
| 6347 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 6348 | * @fnode_conn: pointer to connection attrs of flash ddb entry |
| 6349 | * @data: Parameters and their values to update |
| 6350 | * @len: len of data |
| 6351 | * |
| 6352 | * This sets the parameter of flash ddb entry and writes them to flash |
| 6353 | **/ |
| 6354 | static int |
| 6355 | qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, |
| 6356 | struct iscsi_bus_flash_conn *fnode_conn, |
| 6357 | void *data, int len) |
| 6358 | { |
| 6359 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 6360 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 6361 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 6362 | struct iscsi_flashnode_param_info *fnode_param; |
| 6363 | struct nlattr *attr; |
| 6364 | int rc = QLA_ERROR; |
| 6365 | uint32_t rem = len; |
| 6366 | |
| 6367 | fw_ddb_entry = kzalloc(sizeof(*fw_ddb_entry), GFP_KERNEL); |
| 6368 | if (!fw_ddb_entry) { |
| 6369 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 6370 | "%s: Unable to allocate ddb buffer\n", |
| 6371 | __func__)); |
| 6372 | return -ENOMEM; |
| 6373 | } |
| 6374 | |
| 6375 | nla_for_each_attr(attr, data, len, rem) { |
| 6376 | fnode_param = nla_data(attr); |
| 6377 | |
| 6378 | switch (fnode_param->param) { |
| 6379 | case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: |
| 6380 | fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0]; |
| 6381 | break; |
| 6382 | case ISCSI_FLASHNODE_PORTAL_TYPE: |
| 6383 | memcpy(fnode_sess->portal_type, fnode_param->value, |
| 6384 | strlen(fnode_sess->portal_type)); |
| 6385 | break; |
| 6386 | case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: |
| 6387 | fnode_sess->auto_snd_tgt_disable = |
| 6388 | fnode_param->value[0]; |
| 6389 | break; |
| 6390 | case ISCSI_FLASHNODE_DISCOVERY_SESS: |
| 6391 | fnode_sess->discovery_sess = fnode_param->value[0]; |
| 6392 | break; |
| 6393 | case ISCSI_FLASHNODE_ENTRY_EN: |
| 6394 | fnode_sess->entry_state = fnode_param->value[0]; |
| 6395 | break; |
| 6396 | case ISCSI_FLASHNODE_HDR_DGST_EN: |
| 6397 | fnode_conn->hdrdgst_en = fnode_param->value[0]; |
| 6398 | break; |
| 6399 | case ISCSI_FLASHNODE_DATA_DGST_EN: |
| 6400 | fnode_conn->datadgst_en = fnode_param->value[0]; |
| 6401 | break; |
| 6402 | case ISCSI_FLASHNODE_IMM_DATA_EN: |
| 6403 | fnode_sess->imm_data_en = fnode_param->value[0]; |
| 6404 | break; |
| 6405 | case ISCSI_FLASHNODE_INITIAL_R2T_EN: |
| 6406 | fnode_sess->initial_r2t_en = fnode_param->value[0]; |
| 6407 | break; |
| 6408 | case ISCSI_FLASHNODE_DATASEQ_INORDER: |
| 6409 | fnode_sess->dataseq_inorder_en = fnode_param->value[0]; |
| 6410 | break; |
| 6411 | case ISCSI_FLASHNODE_PDU_INORDER: |
| 6412 | fnode_sess->pdu_inorder_en = fnode_param->value[0]; |
| 6413 | break; |
| 6414 | case ISCSI_FLASHNODE_CHAP_AUTH_EN: |
| 6415 | fnode_sess->chap_auth_en = fnode_param->value[0]; |
| 6416 | break; |
| 6417 | case ISCSI_FLASHNODE_SNACK_REQ_EN: |
| 6418 | fnode_conn->snack_req_en = fnode_param->value[0]; |
| 6419 | break; |
| 6420 | case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: |
| 6421 | fnode_sess->discovery_logout_en = fnode_param->value[0]; |
| 6422 | break; |
| 6423 | case ISCSI_FLASHNODE_BIDI_CHAP_EN: |
| 6424 | fnode_sess->bidi_chap_en = fnode_param->value[0]; |
| 6425 | break; |
| 6426 | case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: |
| 6427 | fnode_sess->discovery_auth_optional = |
| 6428 | fnode_param->value[0]; |
| 6429 | break; |
| 6430 | case ISCSI_FLASHNODE_ERL: |
| 6431 | fnode_sess->erl = fnode_param->value[0]; |
| 6432 | break; |
| 6433 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: |
| 6434 | fnode_conn->tcp_timestamp_stat = fnode_param->value[0]; |
| 6435 | break; |
| 6436 | case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: |
| 6437 | fnode_conn->tcp_nagle_disable = fnode_param->value[0]; |
| 6438 | break; |
| 6439 | case ISCSI_FLASHNODE_TCP_WSF_DISABLE: |
| 6440 | fnode_conn->tcp_wsf_disable = fnode_param->value[0]; |
| 6441 | break; |
| 6442 | case ISCSI_FLASHNODE_TCP_TIMER_SCALE: |
| 6443 | fnode_conn->tcp_timer_scale = fnode_param->value[0]; |
| 6444 | break; |
| 6445 | case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: |
| 6446 | fnode_conn->tcp_timestamp_en = fnode_param->value[0]; |
| 6447 | break; |
| 6448 | case ISCSI_FLASHNODE_IP_FRAG_DISABLE: |
| 6449 | fnode_conn->fragment_disable = fnode_param->value[0]; |
| 6450 | break; |
| 6451 | case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: |
| 6452 | fnode_conn->max_recv_dlength = |
| 6453 | *(unsigned *)fnode_param->value; |
| 6454 | break; |
| 6455 | case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: |
| 6456 | fnode_conn->max_xmit_dlength = |
| 6457 | *(unsigned *)fnode_param->value; |
| 6458 | break; |
| 6459 | case ISCSI_FLASHNODE_FIRST_BURST: |
| 6460 | fnode_sess->first_burst = |
| 6461 | *(unsigned *)fnode_param->value; |
| 6462 | break; |
| 6463 | case ISCSI_FLASHNODE_DEF_TIME2WAIT: |
| 6464 | fnode_sess->time2wait = *(uint16_t *)fnode_param->value; |
| 6465 | break; |
| 6466 | case ISCSI_FLASHNODE_DEF_TIME2RETAIN: |
| 6467 | fnode_sess->time2retain = |
| 6468 | *(uint16_t *)fnode_param->value; |
| 6469 | break; |
| 6470 | case ISCSI_FLASHNODE_MAX_R2T: |
| 6471 | fnode_sess->max_r2t = |
| 6472 | *(uint16_t *)fnode_param->value; |
| 6473 | break; |
| 6474 | case ISCSI_FLASHNODE_KEEPALIVE_TMO: |
| 6475 | fnode_conn->keepalive_timeout = |
| 6476 | *(uint16_t *)fnode_param->value; |
| 6477 | break; |
| 6478 | case ISCSI_FLASHNODE_ISID: |
| 6479 | memcpy(fnode_sess->isid, fnode_param->value, |
| 6480 | sizeof(fnode_sess->isid)); |
| 6481 | break; |
| 6482 | case ISCSI_FLASHNODE_TSID: |
| 6483 | fnode_sess->tsid = *(uint16_t *)fnode_param->value; |
| 6484 | break; |
| 6485 | case ISCSI_FLASHNODE_PORT: |
| 6486 | fnode_conn->port = *(uint16_t *)fnode_param->value; |
| 6487 | break; |
| 6488 | case ISCSI_FLASHNODE_MAX_BURST: |
| 6489 | fnode_sess->max_burst = *(unsigned *)fnode_param->value; |
| 6490 | break; |
| 6491 | case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: |
| 6492 | fnode_sess->default_taskmgmt_timeout = |
| 6493 | *(uint16_t *)fnode_param->value; |
| 6494 | break; |
| 6495 | case ISCSI_FLASHNODE_IPADDR: |
| 6496 | memcpy(fnode_conn->ipaddress, fnode_param->value, |
| 6497 | IPv6_ADDR_LEN); |
| 6498 | break; |
| 6499 | case ISCSI_FLASHNODE_ALIAS: |
| 6500 | rc = iscsi_switch_str_param(&fnode_sess->targetalias, |
| 6501 | (char *)fnode_param->value); |
| 6502 | break; |
| 6503 | case ISCSI_FLASHNODE_REDIRECT_IPADDR: |
| 6504 | memcpy(fnode_conn->redirect_ipaddr, fnode_param->value, |
| 6505 | IPv6_ADDR_LEN); |
| 6506 | break; |
| 6507 | case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: |
| 6508 | fnode_conn->max_segment_size = |
| 6509 | *(unsigned *)fnode_param->value; |
| 6510 | break; |
| 6511 | case ISCSI_FLASHNODE_LOCAL_PORT: |
| 6512 | fnode_conn->local_port = |
| 6513 | *(uint16_t *)fnode_param->value; |
| 6514 | break; |
| 6515 | case ISCSI_FLASHNODE_IPV4_TOS: |
| 6516 | fnode_conn->ipv4_tos = fnode_param->value[0]; |
| 6517 | break; |
| 6518 | case ISCSI_FLASHNODE_IPV6_TC: |
| 6519 | fnode_conn->ipv6_traffic_class = fnode_param->value[0]; |
| 6520 | break; |
| 6521 | case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: |
| 6522 | fnode_conn->ipv6_flow_label = fnode_param->value[0]; |
| 6523 | break; |
| 6524 | case ISCSI_FLASHNODE_NAME: |
| 6525 | rc = iscsi_switch_str_param(&fnode_sess->targetname, |
| 6526 | (char *)fnode_param->value); |
| 6527 | break; |
| 6528 | case ISCSI_FLASHNODE_TPGT: |
| 6529 | fnode_sess->tpgt = *(uint16_t *)fnode_param->value; |
| 6530 | break; |
| 6531 | case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: |
| 6532 | memcpy(fnode_conn->link_local_ipv6_addr, |
| 6533 | fnode_param->value, IPv6_ADDR_LEN); |
| 6534 | break; |
| 6535 | case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: |
| 6536 | fnode_sess->discovery_parent_type = |
| 6537 | *(uint16_t *)fnode_param->value; |
| 6538 | break; |
| 6539 | case ISCSI_FLASHNODE_TCP_XMIT_WSF: |
| 6540 | fnode_conn->tcp_xmit_wsf = |
| 6541 | *(uint8_t *)fnode_param->value; |
| 6542 | break; |
| 6543 | case ISCSI_FLASHNODE_TCP_RECV_WSF: |
| 6544 | fnode_conn->tcp_recv_wsf = |
| 6545 | *(uint8_t *)fnode_param->value; |
| 6546 | break; |
| 6547 | case ISCSI_FLASHNODE_STATSN: |
| 6548 | fnode_conn->statsn = *(uint32_t *)fnode_param->value; |
| 6549 | break; |
| 6550 | case ISCSI_FLASHNODE_EXP_STATSN: |
| 6551 | fnode_conn->exp_statsn = |
| 6552 | *(uint32_t *)fnode_param->value; |
| 6553 | break; |
| 6554 | default: |
| 6555 | ql4_printk(KERN_ERR, ha, |
| 6556 | "%s: No such sysfs attribute\n", __func__); |
| 6557 | rc = -ENOSYS; |
| 6558 | goto exit_set_param; |
| 6559 | } |
| 6560 | } |
| 6561 | |
| 6562 | rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn); |
| 6563 | |
| 6564 | exit_set_param: |
| 6565 | return rc; |
| 6566 | } |
| 6567 | |
| 6568 | /** |
| 6569 | * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry |
| 6570 | * @fnode_sess: pointer to session attrs of flash ddb entry |
| 6571 | * |
| 6572 | * This invalidates the flash ddb entry at the given index |
| 6573 | **/ |
| 6574 | static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess) |
| 6575 | { |
| 6576 | struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); |
| 6577 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 6578 | uint32_t dev_db_start_offset; |
| 6579 | uint32_t dev_db_end_offset; |
| 6580 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 6581 | dma_addr_t fw_ddb_entry_dma; |
| 6582 | uint16_t *ddb_cookie = NULL; |
| 6583 | int target_id; |
| 6584 | int rc = 0; |
| 6585 | |
| 6586 | if (!fnode_sess) { |
| 6587 | rc = -EINVAL; |
| 6588 | goto exit_ddb_del; |
| 6589 | } |
| 6590 | |
| 6591 | if (fnode_sess->is_boot_target) { |
| 6592 | rc = -EPERM; |
| 6593 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 6594 | "%s: Deletion of boot target entry is not permitted.\n", |
| 6595 | __func__)); |
| 6596 | goto exit_ddb_del; |
| 6597 | } |
| 6598 | |
| 6599 | if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) |
| 6600 | goto sysfs_ddb_del; |
| 6601 | |
| 6602 | ddb_cookie = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_cookie), |
| 6603 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 6604 | if (!ddb_cookie) { |
| 6605 | rc = -ENOMEM; |
| 6606 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 6607 | "%s: Unable to allocate dma buffer\n", |
| 6608 | __func__)); |
| 6609 | goto exit_ddb_del; |
| 6610 | } |
| 6611 | |
| 6612 | if (is_qla40XX(ha)) { |
| 6613 | dev_db_start_offset = FLASH_OFFSET_DB_INFO; |
| 6614 | } else { |
| 6615 | dev_db_start_offset = FLASH_RAW_ACCESS_ADDR + |
| 6616 | (ha->hw.flt_region_ddb << 2); |
| 6617 | /* flt_ddb_size is DDB table size for both ports |
| 6618 | * so divide it by 2 to calculate the offset for second port |
| 6619 | */ |
| 6620 | if (ha->port_num == 1) |
| 6621 | dev_db_start_offset += (ha->hw.flt_ddb_size / 2); |
| 6622 | } |
| 6623 | |
| 6624 | dev_db_end_offset = dev_db_start_offset + (ha->hw.flt_ddb_size / 2); |
| 6625 | dev_db_start_offset += (fnode_sess->target_id * sizeof(*fw_ddb_entry)); |
| 6626 | dev_db_start_offset += (void *)&(fw_ddb_entry->cookie) - |
| 6627 | (void *)fw_ddb_entry; |
| 6628 | |
| 6629 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n", |
| 6630 | __func__, dev_db_start_offset, dev_db_end_offset)); |
| 6631 | |
| 6632 | if (dev_db_start_offset > dev_db_end_offset) { |
| 6633 | rc = -EIO; |
| 6634 | DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n", |
| 6635 | __func__, fnode_sess->target_id)); |
| 6636 | goto exit_ddb_del; |
| 6637 | } |
| 6638 | |
| 6639 | /* invalidate the cookie */ |
| 6640 | *ddb_cookie = 0xFFEE; |
| 6641 | qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset, |
| 6642 | sizeof(*ddb_cookie), FLASH_OPT_RMW_COMMIT); |
| 6643 | |
| 6644 | sysfs_ddb_del: |
| 6645 | target_id = fnode_sess->target_id; |
| 6646 | iscsi_destroy_flashnode_sess(fnode_sess); |
| 6647 | ql4_printk(KERN_INFO, ha, |
| 6648 | "%s: session and conn entries for flashnode %u of host %lu deleted\n", |
| 6649 | __func__, target_id, ha->host_no); |
| 6650 | exit_ddb_del: |
| 6651 | if (ddb_cookie) |
| 6652 | dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_cookie), |
| 6653 | ddb_cookie, fw_ddb_entry_dma); |
| 6654 | return rc; |
| 6655 | } |
| 6656 | |
| 6657 | /** |
| 6658 | * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs |
| 6659 | * @ha: pointer to adapter structure |
| 6660 | * |
| 6661 | * Export the firmware DDB for all send targets and normal targets to sysfs. |
| 6662 | **/ |
| 6663 | static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha) |
| 6664 | { |
| 6665 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 6666 | dma_addr_t fw_ddb_entry_dma; |
| 6667 | uint16_t max_ddbs; |
| 6668 | uint16_t idx = 0; |
| 6669 | int ret = QLA_SUCCESS; |
| 6670 | |
| 6671 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, |
| 6672 | sizeof(*fw_ddb_entry), |
| 6673 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 6674 | if (!fw_ddb_entry) { |
| 6675 | DEBUG2(ql4_printk(KERN_ERR, ha, |
| 6676 | "%s: Unable to allocate dma buffer\n", |
| 6677 | __func__)); |
| 6678 | return -ENOMEM; |
| 6679 | } |
| 6680 | |
| 6681 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6682 | MAX_DEV_DB_ENTRIES; |
| 6683 | |
| 6684 | for (idx = 0; idx < max_ddbs; idx++) { |
| 6685 | if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma, |
| 6686 | idx)) |
| 6687 | continue; |
| 6688 | |
| 6689 | ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0); |
| 6690 | if (ret) { |
| 6691 | ret = -EIO; |
| 6692 | break; |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry, |
| 6697 | fw_ddb_entry_dma); |
| 6698 | |
| 6699 | return ret; |
| 6700 | } |
| 6701 | |
| 6702 | static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha) |
| 6703 | { |
| 6704 | iscsi_destroy_all_flashnode(ha->host); |
| 6705 | } |
| 6706 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6707 | /** |
| 6708 | * qla4xxx_build_ddb_list - Build ddb list and setup sessions |
| 6709 | * @ha: pointer to adapter structure |
| 6710 | * @is_reset: Is this init path or reset path |
| 6711 | * |
| 6712 | * Create a list of sendtargets (st) from firmware DDBs, issue send targets |
| 6713 | * using connection open, then create the list of normal targets (nt) |
| 6714 | * from firmware DDBs. Based on the list of nt setup session and connection |
| 6715 | * objects. |
| 6716 | **/ |
| 6717 | void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset) |
| 6718 | { |
| 6719 | uint16_t tmo = 0; |
| 6720 | struct list_head list_st, list_nt; |
| 6721 | struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp; |
| 6722 | unsigned long wtime; |
| 6723 | |
| 6724 | if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| 6725 | set_bit(AF_BUILD_DDB_LIST, &ha->flags); |
| 6726 | ha->is_reset = is_reset; |
| 6727 | return; |
| 6728 | } |
| 6729 | |
| 6730 | INIT_LIST_HEAD(&list_st); |
| 6731 | INIT_LIST_HEAD(&list_nt); |
| 6732 | |
| 6733 | qla4xxx_build_st_list(ha, &list_st); |
| 6734 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6735 | /* Before issuing conn open mbox, ensure all IPs states are configured |
| 6736 | * Note, conn open fails if IPs are not configured |
| 6737 | */ |
| 6738 | qla4xxx_wait_for_ip_configuration(ha); |
| 6739 | |
| 6740 | /* Go thru the STs and fire the sendtargets by issuing conn open mbx */ |
| 6741 | list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) { |
| 6742 | qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx); |
| 6743 | } |
| 6744 | |
| 6745 | /* Wait to ensure all sendtargets are done for min 12 sec wait */ |
Nilesh Javali | c28eaac | 2011-12-18 21:40:44 -0800 | [diff] [blame] | 6746 | tmo = ((ha->def_timeout > LOGIN_TOV) && |
| 6747 | (ha->def_timeout < LOGIN_TOV * 10) ? |
| 6748 | ha->def_timeout : LOGIN_TOV); |
| 6749 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6750 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6751 | "Default time to wait for build ddb %d\n", tmo)); |
| 6752 | |
| 6753 | wtime = jiffies + (HZ * tmo); |
| 6754 | do { |
Nilesh Javali | f1f2e60 | 2011-12-16 01:58:57 -0800 | [diff] [blame] | 6755 | if (list_empty(&list_st)) |
| 6756 | break; |
| 6757 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6758 | qla4xxx_remove_failed_ddb(ha, &list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6759 | schedule_timeout_uninterruptible(HZ / 10); |
| 6760 | } while (time_after(wtime, jiffies)); |
| 6761 | |
| 6762 | /* Free up the sendtargets list */ |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6763 | qla4xxx_free_ddb_list(&list_st); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6764 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6765 | qla4xxx_build_nt_list(ha, &list_nt, is_reset); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6766 | |
Lalit Chandivade | 4a4bc2e | 2011-12-16 01:58:55 -0800 | [diff] [blame] | 6767 | qla4xxx_free_ddb_list(&list_nt); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6768 | |
| 6769 | qla4xxx_free_ddb_index(ha); |
| 6770 | } |
| 6771 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6772 | /** |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 6773 | * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login |
| 6774 | * response. |
| 6775 | * @ha: pointer to adapter structure |
| 6776 | * |
| 6777 | * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be |
| 6778 | * set in DDB and we will wait for login response of boot targets during |
| 6779 | * probe. |
| 6780 | **/ |
| 6781 | static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha) |
| 6782 | { |
| 6783 | struct ddb_entry *ddb_entry; |
| 6784 | struct dev_db_entry *fw_ddb_entry = NULL; |
| 6785 | dma_addr_t fw_ddb_entry_dma; |
| 6786 | unsigned long wtime; |
| 6787 | uint32_t ddb_state; |
| 6788 | int max_ddbs, idx, ret; |
| 6789 | |
| 6790 | max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| 6791 | MAX_DEV_DB_ENTRIES; |
| 6792 | |
| 6793 | fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6794 | &fw_ddb_entry_dma, GFP_KERNEL); |
| 6795 | if (!fw_ddb_entry) { |
| 6796 | ql4_printk(KERN_ERR, ha, |
| 6797 | "%s: Unable to allocate dma buffer\n", __func__); |
| 6798 | goto exit_login_resp; |
| 6799 | } |
| 6800 | |
| 6801 | wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV); |
| 6802 | |
| 6803 | for (idx = 0; idx < max_ddbs; idx++) { |
| 6804 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 6805 | if (ddb_entry == NULL) |
| 6806 | continue; |
| 6807 | |
| 6808 | if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) { |
| 6809 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6810 | "%s: DDB index [%d]\n", __func__, |
| 6811 | ddb_entry->fw_ddb_index)); |
| 6812 | do { |
| 6813 | ret = qla4xxx_get_fwddb_entry(ha, |
| 6814 | ddb_entry->fw_ddb_index, |
| 6815 | fw_ddb_entry, fw_ddb_entry_dma, |
| 6816 | NULL, NULL, &ddb_state, NULL, |
| 6817 | NULL, NULL); |
| 6818 | if (ret == QLA_ERROR) |
| 6819 | goto exit_login_resp; |
| 6820 | |
| 6821 | if ((ddb_state == DDB_DS_SESSION_ACTIVE) || |
| 6822 | (ddb_state == DDB_DS_SESSION_FAILED)) |
| 6823 | break; |
| 6824 | |
| 6825 | schedule_timeout_uninterruptible(HZ); |
| 6826 | |
| 6827 | } while ((time_after(wtime, jiffies))); |
| 6828 | |
| 6829 | if (!time_after(wtime, jiffies)) { |
| 6830 | DEBUG2(ql4_printk(KERN_INFO, ha, |
| 6831 | "%s: Login response wait timer expired\n", |
| 6832 | __func__)); |
| 6833 | goto exit_login_resp; |
| 6834 | } |
| 6835 | } |
| 6836 | } |
| 6837 | |
| 6838 | exit_login_resp: |
| 6839 | if (fw_ddb_entry) |
| 6840 | dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| 6841 | fw_ddb_entry, fw_ddb_entry_dma); |
| 6842 | } |
| 6843 | |
| 6844 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6845 | * qla4xxx_probe_adapter - callback function to probe HBA |
| 6846 | * @pdev: pointer to pci_dev structure |
| 6847 | * @pci_device_id: pointer to pci_device entry |
| 6848 | * |
| 6849 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. |
| 6850 | * It returns zero if successful. It also initializes all data necessary for |
| 6851 | * the driver. |
| 6852 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6853 | static int qla4xxx_probe_adapter(struct pci_dev *pdev, |
| 6854 | const struct pci_device_id *ent) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6855 | { |
| 6856 | int ret = -ENODEV, status; |
| 6857 | struct Scsi_Host *host; |
| 6858 | struct scsi_qla_host *ha; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6859 | uint8_t init_retry_count = 0; |
| 6860 | char buf[34]; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6861 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 6862 | uint32_t dev_state; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6863 | |
| 6864 | if (pci_enable_device(pdev)) |
| 6865 | return -1; |
| 6866 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 6867 | host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6868 | if (host == NULL) { |
| 6869 | printk(KERN_WARNING |
| 6870 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); |
| 6871 | goto probe_disable_device; |
| 6872 | } |
| 6873 | |
| 6874 | /* Clear our data area */ |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 6875 | ha = to_qla_host(host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6876 | memset(ha, 0, sizeof(*ha)); |
| 6877 | |
| 6878 | /* Save the information from PCI BIOS. */ |
| 6879 | ha->pdev = pdev; |
| 6880 | ha->host = host; |
| 6881 | ha->host_no = host->host_no; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 6882 | ha->func_num = PCI_FUNC(ha->pdev->devfn); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6883 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 6884 | pci_enable_pcie_error_reporting(pdev); |
| 6885 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6886 | /* Setup Runtime configurable options */ |
| 6887 | if (is_qla8022(ha)) { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 6888 | ha->isp_ops = &qla4_82xx_isp_ops; |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 6889 | ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6890 | ha->qdr_sn_window = -1; |
| 6891 | ha->ddr_mn_window = -1; |
| 6892 | ha->curr_window = 255; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6893 | nx_legacy_intr = &legacy_intr[ha->func_num]; |
| 6894 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; |
| 6895 | ha->nx_legacy_intr.tgt_status_reg = |
| 6896 | nx_legacy_intr->tgt_status_reg; |
| 6897 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; |
| 6898 | ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 6899 | } else if (is_qla8032(ha)) { |
| 6900 | ha->isp_ops = &qla4_83xx_isp_ops; |
| 6901 | ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6902 | } else { |
| 6903 | ha->isp_ops = &qla4xxx_isp_ops; |
| 6904 | } |
| 6905 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 6906 | if (is_qla80XX(ha)) { |
| 6907 | rwlock_init(&ha->hw_lock); |
| 6908 | ha->pf_bit = ha->func_num << 16; |
| 6909 | /* Set EEH reset type to fundamental if required by hba */ |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 6910 | pdev->needs_freset = 1; |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 6911 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 6912 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6913 | /* Configure PCI I/O space. */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6914 | ret = ha->isp_ops->iospace_config(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6915 | if (ret) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6916 | goto probe_failed_ioconfig; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6917 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 6918 | 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] | 6919 | pdev->device, pdev->irq, ha->reg); |
| 6920 | |
| 6921 | qla4xxx_config_dma_addressing(ha); |
| 6922 | |
| 6923 | /* Initialize lists and spinlocks. */ |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6924 | INIT_LIST_HEAD(&ha->free_srb_q); |
| 6925 | |
| 6926 | mutex_init(&ha->mbox_sem); |
Lalit Chandivade | 4549415 | 2011-10-07 16:55:42 -0700 | [diff] [blame] | 6927 | mutex_init(&ha->chap_sem); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6928 | init_completion(&ha->mbx_intr_comp); |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 6929 | init_completion(&ha->disable_acb_comp); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6930 | |
| 6931 | spin_lock_init(&ha->hardware_lock); |
Vikas Chaudhary | 8e9157c | 2012-08-22 07:45:24 -0400 | [diff] [blame] | 6932 | spin_lock_init(&ha->work_lock); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6933 | |
Vikas Chaudhary | ff88443 | 2011-08-29 23:43:02 +0530 | [diff] [blame] | 6934 | /* Initialize work list */ |
| 6935 | INIT_LIST_HEAD(&ha->work_list); |
| 6936 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6937 | /* Allocate dma buffers */ |
| 6938 | if (qla4xxx_mem_alloc(ha)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 6939 | ql4_printk(KERN_WARNING, ha, |
| 6940 | "[ERROR] Failed to allocate memory for adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6941 | |
| 6942 | ret = -ENOMEM; |
| 6943 | goto probe_failed; |
| 6944 | } |
| 6945 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 6946 | host->cmd_per_lun = 3; |
| 6947 | host->max_channel = 0; |
| 6948 | host->max_lun = MAX_LUNS - 1; |
| 6949 | host->max_id = MAX_TARGETS; |
| 6950 | host->max_cmd_len = IOCB_MAX_CDB_LEN; |
| 6951 | host->can_queue = MAX_SRBS ; |
| 6952 | host->transportt = qla4xxx_scsi_transport; |
| 6953 | |
| 6954 | ret = scsi_init_shared_tag_map(host, MAX_SRBS); |
| 6955 | if (ret) { |
| 6956 | ql4_printk(KERN_WARNING, ha, |
| 6957 | "%s: scsi_init_shared_tag_map failed\n", __func__); |
| 6958 | goto probe_failed; |
| 6959 | } |
| 6960 | |
| 6961 | pci_set_drvdata(pdev, ha); |
| 6962 | |
| 6963 | ret = scsi_add_host(host, &pdev->dev); |
| 6964 | if (ret) |
| 6965 | goto probe_failed; |
| 6966 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 6967 | if (is_qla80XX(ha)) |
| 6968 | qla4_8xxx_get_flash_info(ha); |
| 6969 | |
| 6970 | if (is_qla8032(ha)) { |
| 6971 | qla4_83xx_read_reset_template(ha); |
| 6972 | /* |
| 6973 | * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 6974 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 6975 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 6976 | * should honor the reset. |
| 6977 | */ |
| 6978 | if (ql4xdontresethba == 1) |
| 6979 | qla4_83xx_set_idc_dontreset(ha); |
| 6980 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6981 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 6982 | /* |
| 6983 | * Initialize the Host adapter request/response queues and |
| 6984 | * firmware |
| 6985 | * NOTE: interrupts enabled upon successful completion |
| 6986 | */ |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 6987 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 6988 | |
| 6989 | /* Dont retry adapter initialization if IRQ allocation failed */ |
Nilesh Javali | 17801c9 | 2013-03-22 07:22:42 -0400 | [diff] [blame] | 6990 | if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) { |
| 6991 | ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n", |
| 6992 | __func__); |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 6993 | goto skip_retry_init; |
Nilesh Javali | 17801c9 | 2013-03-22 07:22:42 -0400 | [diff] [blame] | 6994 | } |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 6995 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 6996 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
| 6997 | init_retry_count++ < MAX_INIT_RETRIES) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 6998 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 6999 | if (is_qla80XX(ha)) { |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7000 | ha->isp_ops->idc_lock(ha); |
| 7001 | dev_state = qla4_8xxx_rd_direct(ha, |
Vikas Chaudhary | e951aca | 2012-12-29 02:24:52 -0500 | [diff] [blame] | 7002 | QLA8XXX_CRB_DEV_STATE); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7003 | ha->isp_ops->idc_unlock(ha); |
Vikas Chaudhary | de8c72d | 2012-08-22 09:14:24 -0400 | [diff] [blame] | 7004 | if (dev_state == QLA8XXX_DEV_FAILED) { |
Prasanna Mumbai | f9880e7 | 2011-03-21 03:34:26 -0700 | [diff] [blame] | 7005 | ql4_printk(KERN_WARNING, ha, "%s: don't retry " |
| 7006 | "initialize adapter. H/W is in failed state\n", |
| 7007 | __func__); |
| 7008 | break; |
| 7009 | } |
| 7010 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7011 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
| 7012 | "(%d)\n", __func__, init_retry_count)); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7013 | |
| 7014 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) |
| 7015 | continue; |
| 7016 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7017 | status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7018 | } |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7019 | |
Poornima Vonti | 7977f82 | 2012-09-20 07:35:07 -0400 | [diff] [blame] | 7020 | skip_retry_init: |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7021 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7022 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7023 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 7024 | if ((is_qla8022(ha) && ql4xdontresethba) || |
| 7025 | (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) { |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 7026 | /* Put the device in failed state. */ |
| 7027 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7028 | ha->isp_ops->idc_lock(ha); |
| 7029 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 7030 | QLA8XXX_DEV_FAILED); |
| 7031 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | fe99852 | 2010-12-02 22:12:36 -0800 | [diff] [blame] | 7032 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7033 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7034 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7035 | } |
| 7036 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7037 | /* Startup the kernel thread for this host adapter. */ |
| 7038 | DEBUG2(printk("scsi: %s: Starting kernel thread for " |
| 7039 | "qla4xxx_dpc\n", __func__)); |
| 7040 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); |
| 7041 | ha->dpc_thread = create_singlethread_workqueue(buf); |
| 7042 | if (!ha->dpc_thread) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7043 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7044 | ret = -ENODEV; |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7045 | goto remove_host; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7046 | } |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7047 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7048 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7049 | sprintf(buf, "qla4xxx_%lu_task", ha->host_no); |
| 7050 | ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1); |
| 7051 | if (!ha->task_wq) { |
| 7052 | ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n"); |
| 7053 | ret = -ENODEV; |
| 7054 | goto remove_host; |
| 7055 | } |
| 7056 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 7057 | /* |
| 7058 | * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7059 | * (which is called indirectly by qla4xxx_initialize_adapter), |
| 7060 | * so that irqs will be registered after crbinit but before |
| 7061 | * mbx_intr_enable. |
| 7062 | */ |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 7063 | if (is_qla40XX(ha)) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7064 | ret = qla4xxx_request_irqs(ha); |
| 7065 | if (ret) { |
| 7066 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " |
| 7067 | "interrupt %d already in use.\n", pdev->irq); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7068 | goto remove_host; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7069 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7070 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7071 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7072 | pci_save_state(ha->pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7073 | ha->isp_ops->enable_intrs(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7074 | |
| 7075 | /* Start timer thread. */ |
| 7076 | qla4xxx_start_timer(ha, qla4xxx_timer, 1); |
| 7077 | |
| 7078 | set_bit(AF_INIT_DONE, &ha->flags); |
| 7079 | |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 7080 | qla4_8xxx_alloc_sysfs_attr(ha); |
| 7081 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7082 | printk(KERN_INFO |
| 7083 | " QLogic iSCSI HBA Driver version: %s\n" |
| 7084 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", |
| 7085 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), |
| 7086 | ha->host_no, ha->firmware_version[0], ha->firmware_version[1], |
| 7087 | ha->patch_number, ha->build_number); |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 7088 | |
Manish Dusane | cfb2787 | 2012-09-20 07:35:01 -0400 | [diff] [blame] | 7089 | /* Set the driver version */ |
| 7090 | if (is_qla80XX(ha)) |
| 7091 | qla4_8xxx_set_param(ha, SET_DRVR_VERSION); |
| 7092 | |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 7093 | if (qla4xxx_setup_boot_info(ha)) |
Vikas Chaudhary | 3573bfb | 2012-02-27 03:08:57 -0800 | [diff] [blame] | 7094 | ql4_printk(KERN_ERR, ha, |
| 7095 | "%s: No iSCSI boot target configured\n", __func__); |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 7096 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7097 | if (qla4xxx_sysfs_ddb_export(ha)) |
| 7098 | ql4_printk(KERN_ERR, ha, |
| 7099 | "%s: Error exporting ddb to sysfs\n", __func__); |
| 7100 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7101 | /* Perform the build ddb list and login to each */ |
| 7102 | qla4xxx_build_ddb_list(ha, INIT_ADAPTER); |
| 7103 | iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb); |
Manish Rangankar | 1dc8ed5 | 2013-01-20 23:51:03 -0500 | [diff] [blame] | 7104 | qla4xxx_wait_login_resp_boot_tgt(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7105 | |
| 7106 | qla4xxx_create_chap_list(ha); |
| 7107 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 7108 | qla4xxx_create_ifaces(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7109 | return 0; |
| 7110 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7111 | remove_host: |
| 7112 | scsi_remove_host(ha->host); |
| 7113 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7114 | probe_failed: |
| 7115 | qla4xxx_free_adapter(ha); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7116 | |
| 7117 | probe_failed_ioconfig: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7118 | pci_disable_pcie_error_reporting(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7119 | scsi_host_put(ha->host); |
| 7120 | |
| 7121 | probe_disable_device: |
| 7122 | pci_disable_device(pdev); |
| 7123 | |
| 7124 | return ret; |
| 7125 | } |
| 7126 | |
| 7127 | /** |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 7128 | * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize |
| 7129 | * @ha: pointer to adapter structure |
| 7130 | * |
| 7131 | * Mark the other ISP-4xxx port to indicate that the driver is being removed, |
| 7132 | * so that the other port will not re-initialize while in the process of |
| 7133 | * removing the ha due to driver unload or hba hotplug. |
| 7134 | **/ |
| 7135 | static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha) |
| 7136 | { |
| 7137 | struct scsi_qla_host *other_ha = NULL; |
| 7138 | struct pci_dev *other_pdev = NULL; |
| 7139 | int fn = ISP4XXX_PCI_FN_2; |
| 7140 | |
| 7141 | /*iscsi function numbers for ISP4xxx is 1 and 3*/ |
| 7142 | if (PCI_FUNC(ha->pdev->devfn) & BIT_1) |
| 7143 | fn = ISP4XXX_PCI_FN_1; |
| 7144 | |
| 7145 | other_pdev = |
| 7146 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 7147 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 7148 | fn)); |
| 7149 | |
| 7150 | /* Get other_ha if other_pdev is valid and state is enable*/ |
| 7151 | if (other_pdev) { |
| 7152 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 7153 | other_ha = pci_get_drvdata(other_pdev); |
| 7154 | if (other_ha) { |
| 7155 | set_bit(AF_HA_REMOVAL, &other_ha->flags); |
| 7156 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " |
| 7157 | "Prevent %s reinit\n", __func__, |
| 7158 | dev_name(&other_ha->pdev->dev))); |
| 7159 | } |
| 7160 | } |
| 7161 | pci_dev_put(other_pdev); |
| 7162 | } |
| 7163 | } |
| 7164 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7165 | static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha) |
| 7166 | { |
| 7167 | struct ddb_entry *ddb_entry; |
| 7168 | int options; |
| 7169 | int idx; |
| 7170 | |
| 7171 | for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) { |
| 7172 | |
| 7173 | ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| 7174 | if ((ddb_entry != NULL) && |
| 7175 | (ddb_entry->ddb_type == FLASH_DDB)) { |
| 7176 | |
| 7177 | options = LOGOUT_OPTION_CLOSE_SESSION; |
| 7178 | if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) |
| 7179 | == QLA_ERROR) |
| 7180 | ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", |
| 7181 | __func__); |
| 7182 | |
| 7183 | qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| 7184 | /* |
| 7185 | * we have decremented the reference count of the driver |
| 7186 | * when we setup the session to have the driver unload |
| 7187 | * to be seamless without actually destroying the |
| 7188 | * session |
| 7189 | **/ |
| 7190 | try_module_get(qla4xxx_iscsi_transport.owner); |
| 7191 | iscsi_destroy_endpoint(ddb_entry->conn->ep); |
| 7192 | qla4xxx_free_ddb(ha, ddb_entry); |
| 7193 | iscsi_session_teardown(ddb_entry->sess); |
| 7194 | } |
| 7195 | } |
| 7196 | } |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 7197 | /** |
Masanari Iida | 59e13d4 | 2012-04-25 00:24:16 +0900 | [diff] [blame] | 7198 | * qla4xxx_remove_adapter - callback function to remove adapter. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7199 | * @pci_dev: PCI device pointer |
| 7200 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7201 | static void qla4xxx_remove_adapter(struct pci_dev *pdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7202 | { |
| 7203 | struct scsi_qla_host *ha; |
| 7204 | |
Vikas Chaudhary | f8b0751 | 2012-09-20 07:35:08 -0400 | [diff] [blame] | 7205 | /* |
| 7206 | * If the PCI device is disabled then it means probe_adapter had |
| 7207 | * failed and resources already cleaned up on probe_adapter exit. |
| 7208 | */ |
| 7209 | if (!pci_is_enabled(pdev)) |
| 7210 | return; |
| 7211 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7212 | ha = pci_get_drvdata(pdev); |
| 7213 | |
Vikas Chaudhary | ee996a6 | 2012-08-22 07:55:05 -0400 | [diff] [blame] | 7214 | if (is_qla40XX(ha)) |
Karen Higgins | 7eece5a | 2011-03-21 03:34:29 -0700 | [diff] [blame] | 7215 | qla4xxx_prevent_other_port_reinit(ha); |
David C Somayajulu | bee4fe8 | 2007-05-23 18:03:32 -0700 | [diff] [blame] | 7216 | |
Vikas Chaudhary | ed1086e | 2011-07-25 13:48:41 -0500 | [diff] [blame] | 7217 | /* destroy iface from sysfs */ |
| 7218 | qla4xxx_destroy_ifaces(ha); |
| 7219 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7220 | if ((!ql4xdisablesysfsboot) && ha->boot_kset) |
Manish Rangankar | 2a991c2 | 2011-07-25 13:48:55 -0500 | [diff] [blame] | 7221 | iscsi_boot_destroy_kset(ha->boot_kset); |
| 7222 | |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7223 | qla4xxx_destroy_fw_ddb_session(ha); |
Tej Parkash | 068237c8 | 2012-05-18 04:41:44 -0400 | [diff] [blame] | 7224 | qla4_8xxx_free_sysfs_attr(ha); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7225 | |
Adheer Chandravanshi | 1e9e2be | 2013-03-22 07:41:31 -0400 | [diff] [blame] | 7226 | qla4xxx_sysfs_ddb_remove(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7227 | scsi_remove_host(ha->host); |
| 7228 | |
| 7229 | qla4xxx_free_adapter(ha); |
| 7230 | |
| 7231 | scsi_host_put(ha->host); |
| 7232 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7233 | pci_disable_pcie_error_reporting(pdev); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7234 | pci_disable_device(pdev); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7235 | pci_set_drvdata(pdev, NULL); |
| 7236 | } |
| 7237 | |
| 7238 | /** |
| 7239 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. |
| 7240 | * @ha: HA context |
| 7241 | * |
| 7242 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated |
| 7243 | * supported addressing method. |
| 7244 | */ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 7245 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7246 | { |
| 7247 | int retval; |
| 7248 | |
| 7249 | /* Update our PCI device dma_mask for full 64 bit mask */ |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 7250 | if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) { |
| 7251 | if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7252 | dev_dbg(&ha->pdev->dev, |
| 7253 | "Failed to set 64 bit PCI consistent mask; " |
| 7254 | "using 32 bit.\n"); |
| 7255 | retval = pci_set_consistent_dma_mask(ha->pdev, |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 7256 | DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7257 | } |
| 7258 | } else |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 7259 | retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7260 | } |
| 7261 | |
| 7262 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) |
| 7263 | { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7264 | struct iscsi_cls_session *cls_sess; |
| 7265 | struct iscsi_session *sess; |
| 7266 | struct ddb_entry *ddb; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 7267 | int queue_depth = QL4_DEF_QDEPTH; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7268 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7269 | cls_sess = starget_to_session(sdev->sdev_target); |
| 7270 | sess = cls_sess->dd_data; |
| 7271 | ddb = sess->dd_data; |
| 7272 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7273 | sdev->hostdata = ddb; |
| 7274 | sdev->tagged_supported = 1; |
Vikas Chaudhary | 8bb4033 | 2011-03-21 03:34:31 -0700 | [diff] [blame] | 7275 | |
| 7276 | if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) |
| 7277 | queue_depth = ql4xmaxqdepth; |
| 7278 | |
| 7279 | scsi_activate_tcq(sdev, queue_depth); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7280 | return 0; |
| 7281 | } |
| 7282 | |
| 7283 | static int qla4xxx_slave_configure(struct scsi_device *sdev) |
| 7284 | { |
| 7285 | sdev->tagged_supported = 1; |
| 7286 | return 0; |
| 7287 | } |
| 7288 | |
| 7289 | static void qla4xxx_slave_destroy(struct scsi_device *sdev) |
| 7290 | { |
| 7291 | scsi_deactivate_tcq(sdev, 1); |
| 7292 | } |
| 7293 | |
Tej Parkash | f7b4aa6 | 2012-04-30 04:12:19 -0700 | [diff] [blame] | 7294 | static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth, |
| 7295 | int reason) |
| 7296 | { |
| 7297 | if (!ql4xqfulltracking) |
| 7298 | return -EOPNOTSUPP; |
| 7299 | |
| 7300 | return iscsi_change_queue_depth(sdev, qdepth, reason); |
| 7301 | } |
| 7302 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7303 | /** |
| 7304 | * qla4xxx_del_from_active_array - returns an active srb |
| 7305 | * @ha: Pointer to host adapter structure. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 7306 | * @index: index into the active_array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7307 | * |
| 7308 | * This routine removes and returns the srb at the specified index |
| 7309 | **/ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7310 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
| 7311 | uint32_t index) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7312 | { |
| 7313 | struct srb *srb = NULL; |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 7314 | struct scsi_cmnd *cmd = NULL; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7315 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 7316 | cmd = scsi_host_find_tag(ha->host, index); |
| 7317 | if (!cmd) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7318 | return srb; |
| 7319 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 7320 | srb = (struct srb *)CMD_SP(cmd); |
| 7321 | if (!srb) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7322 | return srb; |
| 7323 | |
| 7324 | /* update counters */ |
| 7325 | if (srb->flags & SRB_DMA_VALID) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7326 | ha->iocb_cnt -= srb->iocb_cnt; |
| 7327 | if (srb->cmd) |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 7328 | srb->cmd->host_scribble = |
| 7329 | (unsigned char *)(unsigned long) MAX_SRBS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7330 | } |
| 7331 | return srb; |
| 7332 | } |
| 7333 | |
| 7334 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7335 | * 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] | 7336 | * @ha: Pointer to host adapter structure. |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7337 | * @cmd: Scsi Command to wait on. |
| 7338 | * |
| 7339 | * This routine waits for the command to be returned by the Firmware |
| 7340 | * for some max time. |
| 7341 | **/ |
| 7342 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, |
| 7343 | struct scsi_cmnd *cmd) |
| 7344 | { |
| 7345 | int done = 0; |
| 7346 | struct srb *rp; |
| 7347 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7348 | int ret = SUCCESS; |
| 7349 | |
| 7350 | /* Dont wait on command if PCI error is being handled |
| 7351 | * by PCI AER driver |
| 7352 | */ |
| 7353 | if (unlikely(pci_channel_offline(ha->pdev)) || |
| 7354 | (test_bit(AF_EEH_BUSY, &ha->flags))) { |
| 7355 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", |
| 7356 | ha->host_no, __func__); |
| 7357 | return ret; |
| 7358 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7359 | |
| 7360 | do { |
| 7361 | /* Checking to see if its returned to OS */ |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 7362 | rp = (struct srb *) CMD_SP(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7363 | if (rp == NULL) { |
| 7364 | done++; |
| 7365 | break; |
| 7366 | } |
| 7367 | |
| 7368 | msleep(2000); |
| 7369 | } while (max_wait_time--); |
| 7370 | |
| 7371 | return done; |
| 7372 | } |
| 7373 | |
| 7374 | /** |
| 7375 | * qla4xxx_wait_for_hba_online - waits for HBA to come online |
| 7376 | * @ha: Pointer to host adapter structure |
| 7377 | **/ |
| 7378 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) |
| 7379 | { |
| 7380 | unsigned long wait_online; |
| 7381 | |
Vikas Chaudhary | f581a3f | 2010-10-06 22:47:48 -0700 | [diff] [blame] | 7382 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7383 | while (time_before(jiffies, wait_online)) { |
| 7384 | |
| 7385 | if (adapter_up(ha)) |
| 7386 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7387 | |
| 7388 | msleep(2000); |
| 7389 | } |
| 7390 | |
| 7391 | return QLA_ERROR; |
| 7392 | } |
| 7393 | |
| 7394 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7395 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 7396 | * @ha: pointer to HBA |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7397 | * @t: target id |
| 7398 | * @l: lun id |
| 7399 | * |
| 7400 | * This function waits for all outstanding commands to a lun to complete. It |
| 7401 | * returns 0 if all pending commands are returned and 1 otherwise. |
| 7402 | **/ |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7403 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
| 7404 | struct scsi_target *stgt, |
| 7405 | struct scsi_device *sdev) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7406 | { |
| 7407 | int cnt; |
| 7408 | int status = 0; |
| 7409 | struct scsi_cmnd *cmd; |
| 7410 | |
| 7411 | /* |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7412 | * Waiting for all commands for the designated target or dev |
| 7413 | * in the active array |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7414 | */ |
| 7415 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { |
| 7416 | cmd = scsi_host_find_tag(ha->host, cnt); |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7417 | if (cmd && stgt == scsi_target(cmd->device) && |
| 7418 | (!sdev || sdev == cmd->device)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7419 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 7420 | status++; |
| 7421 | break; |
| 7422 | } |
| 7423 | } |
| 7424 | } |
| 7425 | return status; |
| 7426 | } |
| 7427 | |
| 7428 | /** |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7429 | * qla4xxx_eh_abort - callback for abort task. |
| 7430 | * @cmd: Pointer to Linux's SCSI command structure |
| 7431 | * |
| 7432 | * This routine is called by the Linux OS to abort the specified |
| 7433 | * command. |
| 7434 | **/ |
| 7435 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) |
| 7436 | { |
| 7437 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 7438 | unsigned int id = cmd->device->id; |
| 7439 | unsigned int lun = cmd->device->lun; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 7440 | unsigned long flags; |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7441 | struct srb *srb = NULL; |
| 7442 | int ret = SUCCESS; |
| 7443 | int wait = 0; |
| 7444 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7445 | ql4_printk(KERN_INFO, ha, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 7446 | "scsi%ld:%d:%d: Abort command issued cmd=%p\n", |
| 7447 | ha->host_no, id, lun, cmd); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7448 | |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 7449 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7450 | srb = (struct srb *) CMD_SP(cmd); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 7451 | if (!srb) { |
| 7452 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7453 | return SUCCESS; |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 7454 | } |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7455 | kref_get(&srb->srb_ref); |
Mike Christie | 92b3e5b | 2010-10-06 22:51:17 -0700 | [diff] [blame] | 7456 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7457 | |
| 7458 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { |
| 7459 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", |
| 7460 | ha->host_no, id, lun)); |
| 7461 | ret = FAILED; |
| 7462 | } else { |
| 7463 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n", |
| 7464 | ha->host_no, id, lun)); |
| 7465 | wait = 1; |
| 7466 | } |
| 7467 | |
| 7468 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| 7469 | |
| 7470 | /* Wait for command to complete */ |
| 7471 | if (wait) { |
| 7472 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
| 7473 | DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n", |
| 7474 | ha->host_no, id, lun)); |
| 7475 | ret = FAILED; |
| 7476 | } |
| 7477 | } |
| 7478 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7479 | ql4_printk(KERN_INFO, ha, |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7480 | "scsi%ld:%d:%d: Abort command - %s\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7481 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed"); |
Vikas Chaudhary | 09a0f71 | 2010-04-28 11:42:24 +0530 | [diff] [blame] | 7482 | |
| 7483 | return ret; |
| 7484 | } |
| 7485 | |
| 7486 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7487 | * qla4xxx_eh_device_reset - callback for target reset. |
| 7488 | * @cmd: Pointer to Linux's SCSI command structure |
| 7489 | * |
| 7490 | * This routine is called by the Linux OS to reset all luns on the |
| 7491 | * specified target. |
| 7492 | **/ |
| 7493 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) |
| 7494 | { |
| 7495 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 7496 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7497 | int ret = FAILED, stat; |
| 7498 | |
Karen Higgins | 612f734 | 2009-07-15 15:03:01 -0500 | [diff] [blame] | 7499 | if (!ddb_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7500 | return ret; |
| 7501 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 7502 | ret = iscsi_block_scsi_eh(cmd); |
| 7503 | if (ret) |
| 7504 | return ret; |
| 7505 | ret = FAILED; |
| 7506 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7507 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7508 | "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no, |
| 7509 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 7510 | |
| 7511 | DEBUG2(printk(KERN_INFO |
| 7512 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," |
| 7513 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 7514 | cmd, jiffies, cmd->request->timeout / HZ, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7515 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 7516 | |
| 7517 | /* FIXME: wait for hba to go online */ |
| 7518 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); |
| 7519 | if (stat != QLA_SUCCESS) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7520 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7521 | goto eh_dev_reset_done; |
| 7522 | } |
| 7523 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7524 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 7525 | cmd->device)) { |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7526 | ql4_printk(KERN_INFO, ha, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7527 | "DEVICE RESET FAILED - waiting for " |
| 7528 | "commands.\n"); |
| 7529 | goto eh_dev_reset_done; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7530 | } |
| 7531 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 7532 | /* Send marker. */ |
| 7533 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 7534 | MM_LUN_RESET) != QLA_SUCCESS) |
| 7535 | goto eh_dev_reset_done; |
| 7536 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7537 | ql4_printk(KERN_INFO, ha, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7538 | "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n", |
| 7539 | ha->host_no, cmd->device->channel, cmd->device->id, |
| 7540 | cmd->device->lun); |
| 7541 | |
| 7542 | ret = SUCCESS; |
| 7543 | |
| 7544 | eh_dev_reset_done: |
| 7545 | |
| 7546 | return ret; |
| 7547 | } |
| 7548 | |
| 7549 | /** |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7550 | * qla4xxx_eh_target_reset - callback for target reset. |
| 7551 | * @cmd: Pointer to Linux's SCSI command structure |
| 7552 | * |
| 7553 | * This routine is called by the Linux OS to reset the target. |
| 7554 | **/ |
| 7555 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) |
| 7556 | { |
| 7557 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); |
| 7558 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 7559 | int stat, ret; |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7560 | |
| 7561 | if (!ddb_entry) |
| 7562 | return FAILED; |
| 7563 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 7564 | ret = iscsi_block_scsi_eh(cmd); |
| 7565 | if (ret) |
| 7566 | return ret; |
| 7567 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7568 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 7569 | "WARM TARGET RESET ISSUED.\n"); |
| 7570 | |
| 7571 | DEBUG2(printk(KERN_INFO |
| 7572 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " |
| 7573 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 7574 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7575 | ha->dpc_flags, cmd->result, cmd->allowed)); |
| 7576 | |
| 7577 | stat = qla4xxx_reset_target(ha, ddb_entry); |
| 7578 | if (stat != QLA_SUCCESS) { |
| 7579 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 7580 | "WARM TARGET RESET FAILED.\n"); |
| 7581 | return FAILED; |
| 7582 | } |
| 7583 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7584 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
| 7585 | NULL)) { |
| 7586 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 7587 | "WARM TARGET DEVICE RESET FAILED - " |
| 7588 | "waiting for commands.\n"); |
| 7589 | return FAILED; |
| 7590 | } |
| 7591 | |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 7592 | /* Send marker. */ |
| 7593 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, |
| 7594 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { |
| 7595 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 7596 | "WARM TARGET DEVICE RESET FAILED - " |
| 7597 | "marker iocb failed.\n"); |
| 7598 | return FAILED; |
| 7599 | } |
| 7600 | |
Mike Christie | ce54503 | 2008-02-29 18:25:20 -0600 | [diff] [blame] | 7601 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
| 7602 | "WARM TARGET RESET SUCCEEDED.\n"); |
| 7603 | return SUCCESS; |
| 7604 | } |
| 7605 | |
| 7606 | /** |
Sarang Radke | 8a28896 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 7607 | * qla4xxx_is_eh_active - check if error handler is running |
| 7608 | * @shost: Pointer to SCSI Host struct |
| 7609 | * |
| 7610 | * This routine finds that if reset host is called in EH |
| 7611 | * scenario or from some application like sg_reset |
| 7612 | **/ |
| 7613 | static int qla4xxx_is_eh_active(struct Scsi_Host *shost) |
| 7614 | { |
| 7615 | if (shost->shost_state == SHOST_RECOVERY) |
| 7616 | return 1; |
| 7617 | return 0; |
| 7618 | } |
| 7619 | |
| 7620 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7621 | * qla4xxx_eh_host_reset - kernel callback |
| 7622 | * @cmd: Pointer to Linux's SCSI command structure |
| 7623 | * |
| 7624 | * This routine is invoked by the Linux kernel to perform fatal error |
| 7625 | * recovery on the specified adapter. |
| 7626 | **/ |
| 7627 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) |
| 7628 | { |
| 7629 | int return_status = FAILED; |
| 7630 | struct scsi_qla_host *ha; |
| 7631 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7632 | ha = to_qla_host(cmd->device->host); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7633 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 7634 | if (is_qla8032(ha) && ql4xdontresethba) |
| 7635 | qla4_83xx_set_idc_dontreset(ha); |
| 7636 | |
| 7637 | /* |
| 7638 | * For ISP8324, if IDC_CTRL DONTRESET_BIT0 is set by other |
| 7639 | * protocol drivers, we should not set device_state to |
| 7640 | * NEED_RESET |
| 7641 | */ |
| 7642 | if (ql4xdontresethba || |
| 7643 | (is_qla8032(ha) && qla4_83xx_idc_dontreset(ha))) { |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7644 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| 7645 | ha->host_no, __func__)); |
Sarang Radke | 8a28896 | 2011-12-06 02:34:10 -0800 | [diff] [blame] | 7646 | |
| 7647 | /* Clear outstanding srb in queues */ |
| 7648 | if (qla4xxx_is_eh_active(cmd->device->host)) |
| 7649 | qla4xxx_abort_active_cmds(ha, DID_ABORT << 16); |
| 7650 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7651 | return FAILED; |
| 7652 | } |
| 7653 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7654 | ql4_printk(KERN_INFO, ha, |
Karen Higgins | dca05c4 | 2009-07-15 15:03:00 -0500 | [diff] [blame] | 7655 | "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7656 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
| 7657 | |
| 7658 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { |
| 7659 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " |
| 7660 | "DEAD.\n", ha->host_no, cmd->device->channel, |
| 7661 | __func__)); |
| 7662 | |
| 7663 | return FAILED; |
| 7664 | } |
| 7665 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7666 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 7667 | if (is_qla80XX(ha)) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7668 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| 7669 | else |
| 7670 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 7671 | } |
Mike Christie | 50a29ae | 2008-03-04 13:26:53 -0600 | [diff] [blame] | 7672 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 7673 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7674 | return_status = SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7675 | |
Vikas Chaudhary | c2660df | 2010-07-10 14:51:02 +0530 | [diff] [blame] | 7676 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7677 | return_status == FAILED ? "FAILED" : "SUCCEEDED"); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 7678 | |
| 7679 | return return_status; |
| 7680 | } |
| 7681 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 7682 | static int qla4xxx_context_reset(struct scsi_qla_host *ha) |
| 7683 | { |
| 7684 | uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| 7685 | uint32_t mbox_sts[MBOX_REG_COUNT]; |
| 7686 | struct addr_ctrl_blk_def *acb = NULL; |
| 7687 | uint32_t acb_len = sizeof(struct addr_ctrl_blk_def); |
| 7688 | int rval = QLA_SUCCESS; |
| 7689 | dma_addr_t acb_dma; |
| 7690 | |
| 7691 | acb = dma_alloc_coherent(&ha->pdev->dev, |
| 7692 | sizeof(struct addr_ctrl_blk_def), |
| 7693 | &acb_dma, GFP_KERNEL); |
| 7694 | if (!acb) { |
| 7695 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n", |
| 7696 | __func__); |
| 7697 | rval = -ENOMEM; |
| 7698 | goto exit_port_reset; |
| 7699 | } |
| 7700 | |
| 7701 | memset(acb, 0, acb_len); |
| 7702 | |
| 7703 | rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len); |
| 7704 | if (rval != QLA_SUCCESS) { |
| 7705 | rval = -EIO; |
| 7706 | goto exit_free_acb; |
| 7707 | } |
| 7708 | |
| 7709 | rval = qla4xxx_disable_acb(ha); |
| 7710 | if (rval != QLA_SUCCESS) { |
| 7711 | rval = -EIO; |
| 7712 | goto exit_free_acb; |
| 7713 | } |
| 7714 | |
| 7715 | wait_for_completion_timeout(&ha->disable_acb_comp, |
| 7716 | DISABLE_ACB_TOV * HZ); |
| 7717 | |
| 7718 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma); |
| 7719 | if (rval != QLA_SUCCESS) { |
| 7720 | rval = -EIO; |
| 7721 | goto exit_free_acb; |
| 7722 | } |
| 7723 | |
| 7724 | exit_free_acb: |
| 7725 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def), |
| 7726 | acb, acb_dma); |
| 7727 | exit_port_reset: |
| 7728 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__, |
| 7729 | rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED")); |
| 7730 | return rval; |
| 7731 | } |
| 7732 | |
| 7733 | static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type) |
| 7734 | { |
| 7735 | struct scsi_qla_host *ha = to_qla_host(shost); |
| 7736 | int rval = QLA_SUCCESS; |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 7737 | uint32_t idc_ctrl; |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 7738 | |
| 7739 | if (ql4xdontresethba) { |
| 7740 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n", |
| 7741 | __func__)); |
| 7742 | rval = -EPERM; |
| 7743 | goto exit_host_reset; |
| 7744 | } |
| 7745 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 7746 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| 7747 | goto recover_adapter; |
| 7748 | |
| 7749 | switch (reset_type) { |
| 7750 | case SCSI_ADAPTER_RESET: |
| 7751 | set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| 7752 | break; |
| 7753 | case SCSI_FIRMWARE_RESET: |
| 7754 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 7755 | if (is_qla80XX(ha)) |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 7756 | /* set firmware context reset */ |
| 7757 | set_bit(DPC_RESET_HA_FW_CONTEXT, |
| 7758 | &ha->dpc_flags); |
| 7759 | else { |
| 7760 | rval = qla4xxx_context_reset(ha); |
| 7761 | goto exit_host_reset; |
| 7762 | } |
| 7763 | } |
| 7764 | break; |
| 7765 | } |
| 7766 | |
| 7767 | recover_adapter: |
Vikas Chaudhary | ebd777d | 2013-03-07 05:43:09 -0500 | [diff] [blame] | 7768 | /* For ISP83XX set graceful reset bit in IDC_DRV_CTRL if |
| 7769 | * reset is issued by application */ |
| 7770 | if (is_qla8032(ha) && test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| 7771 | idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL); |
| 7772 | qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL, |
| 7773 | (idc_ctrl | GRACEFUL_RESET_BIT1)); |
| 7774 | } |
| 7775 | |
Vikas Chaudhary | 95d3126 | 2011-08-12 02:51:29 -0700 | [diff] [blame] | 7776 | rval = qla4xxx_recover_adapter(ha); |
| 7777 | if (rval != QLA_SUCCESS) { |
| 7778 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n", |
| 7779 | __func__)); |
| 7780 | rval = -EIO; |
| 7781 | } |
| 7782 | |
| 7783 | exit_host_reset: |
| 7784 | return rval; |
| 7785 | } |
| 7786 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7787 | /* PCI AER driver recovers from all correctable errors w/o |
| 7788 | * driver intervention. For uncorrectable errors PCI AER |
| 7789 | * driver calls the following device driver's callbacks |
| 7790 | * |
| 7791 | * - Fatal Errors - link_reset |
| 7792 | * - Non-Fatal Errors - driver's pci_error_detected() which |
| 7793 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. |
| 7794 | * |
| 7795 | * PCI AER driver calls |
| 7796 | * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled |
| 7797 | * returns RECOVERED or NEED_RESET if fw_hung |
| 7798 | * NEED_RESET - driver's slot_reset() |
| 7799 | * DISCONNECT - device is dead & cannot recover |
| 7800 | * RECOVERED - driver's pci_resume() |
| 7801 | */ |
| 7802 | static pci_ers_result_t |
| 7803 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 7804 | { |
| 7805 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 7806 | |
| 7807 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", |
| 7808 | ha->host_no, __func__, state); |
| 7809 | |
| 7810 | if (!is_aer_supported(ha)) |
| 7811 | return PCI_ERS_RESULT_NONE; |
| 7812 | |
| 7813 | switch (state) { |
| 7814 | case pci_channel_io_normal: |
| 7815 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 7816 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 7817 | case pci_channel_io_frozen: |
| 7818 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 7819 | qla4xxx_mailbox_premature_completion(ha); |
| 7820 | qla4xxx_free_irqs(ha); |
| 7821 | pci_disable_device(pdev); |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 7822 | /* Return back all IOs */ |
| 7823 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7824 | return PCI_ERS_RESULT_NEED_RESET; |
| 7825 | case pci_channel_io_perm_failure: |
| 7826 | set_bit(AF_EEH_BUSY, &ha->flags); |
| 7827 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); |
| 7828 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| 7829 | return PCI_ERS_RESULT_DISCONNECT; |
| 7830 | } |
| 7831 | return PCI_ERS_RESULT_NEED_RESET; |
| 7832 | } |
| 7833 | |
| 7834 | /** |
| 7835 | * qla4xxx_pci_mmio_enabled() gets called if |
| 7836 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER |
| 7837 | * and read/write to the device still works. |
| 7838 | **/ |
| 7839 | static pci_ers_result_t |
| 7840 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) |
| 7841 | { |
| 7842 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 7843 | |
| 7844 | if (!is_aer_supported(ha)) |
| 7845 | return PCI_ERS_RESULT_NONE; |
| 7846 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 7847 | return PCI_ERS_RESULT_RECOVERED; |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7848 | } |
| 7849 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 7850 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7851 | { |
| 7852 | uint32_t rval = QLA_ERROR; |
| 7853 | int fn; |
| 7854 | struct pci_dev *other_pdev = NULL; |
| 7855 | |
| 7856 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); |
| 7857 | |
| 7858 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 7859 | |
| 7860 | if (test_bit(AF_ONLINE, &ha->flags)) { |
| 7861 | clear_bit(AF_ONLINE, &ha->flags); |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 7862 | clear_bit(AF_LINK_UP, &ha->flags); |
| 7863 | iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7864 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7865 | } |
| 7866 | |
| 7867 | fn = PCI_FUNC(ha->pdev->devfn); |
| 7868 | while (fn > 0) { |
| 7869 | fn--; |
| 7870 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at " |
| 7871 | "func %x\n", ha->host_no, __func__, fn); |
| 7872 | /* Get the pci device given the domain, bus, |
| 7873 | * slot/function number */ |
| 7874 | other_pdev = |
| 7875 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), |
| 7876 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), |
| 7877 | fn)); |
| 7878 | |
| 7879 | if (!other_pdev) |
| 7880 | continue; |
| 7881 | |
| 7882 | if (atomic_read(&other_pdev->enable_cnt)) { |
| 7883 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI " |
| 7884 | "func in enabled state%x\n", ha->host_no, |
| 7885 | __func__, fn); |
| 7886 | pci_dev_put(other_pdev); |
| 7887 | break; |
| 7888 | } |
| 7889 | pci_dev_put(other_pdev); |
| 7890 | } |
| 7891 | |
| 7892 | /* The first function on the card, the reset owner will |
| 7893 | * start & initialize the firmware. The other functions |
| 7894 | * on the card will reset the firmware context |
| 7895 | */ |
| 7896 | if (!fn) { |
| 7897 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " |
| 7898 | "0x%x is the owner\n", ha->host_no, __func__, |
| 7899 | ha->pdev->devfn); |
| 7900 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7901 | ha->isp_ops->idc_lock(ha); |
| 7902 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 7903 | QLA8XXX_DEV_COLD); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7904 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7905 | |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 7906 | rval = qla4_8xxx_update_idc_reg(ha); |
| 7907 | if (rval == QLA_ERROR) { |
| 7908 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n", |
| 7909 | ha->host_no, __func__); |
| 7910 | ha->isp_ops->idc_lock(ha); |
| 7911 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 7912 | QLA8XXX_DEV_FAILED); |
| 7913 | ha->isp_ops->idc_unlock(ha); |
| 7914 | goto exit_error_recovery; |
| 7915 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7916 | |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7917 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7918 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7919 | |
| 7920 | if (rval != QLA_SUCCESS) { |
| 7921 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 7922 | "FAILED\n", ha->host_no, __func__); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 7923 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7924 | qla4_8xxx_clear_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7925 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 7926 | QLA8XXX_DEV_FAILED); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 7927 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7928 | } else { |
| 7929 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " |
| 7930 | "READY\n", ha->host_no, __func__); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 7931 | ha->isp_ops->idc_lock(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7932 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, |
| 7933 | QLA8XXX_DEV_READY); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7934 | /* Clear driver state register */ |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7935 | qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7936 | qla4_8xxx_set_drv_active(ha); |
Poornima Vonti | 8276190 | 2012-09-20 07:35:04 -0400 | [diff] [blame] | 7937 | ha->isp_ops->idc_unlock(ha); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 7938 | ha->isp_ops->enable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7939 | } |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7940 | } else { |
| 7941 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " |
| 7942 | "the reset owner\n", ha->host_no, __func__, |
| 7943 | ha->pdev->devfn); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7944 | if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) == |
| 7945 | QLA8XXX_DEV_READY)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7946 | clear_bit(AF_FW_RECOVERY, &ha->flags); |
Mike Christie | 1348373 | 2011-12-01 21:38:41 -0600 | [diff] [blame] | 7947 | rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
Poornima Vonti | 137257d | 2013-01-20 23:51:01 -0500 | [diff] [blame] | 7948 | if (rval == QLA_SUCCESS) |
| 7949 | ha->isp_ops->enable_intrs(ha); |
| 7950 | |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7951 | ha->isp_ops->idc_lock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7952 | qla4_8xxx_set_drv_active(ha); |
Vikas Chaudhary | 33693c7 | 2012-08-22 07:55:04 -0400 | [diff] [blame] | 7953 | ha->isp_ops->idc_unlock(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7954 | } |
| 7955 | } |
Vikas Chaudhary | 39c9582 | 2012-09-20 07:35:05 -0400 | [diff] [blame] | 7956 | exit_error_recovery: |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7957 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| 7958 | return rval; |
| 7959 | } |
| 7960 | |
| 7961 | static pci_ers_result_t |
| 7962 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) |
| 7963 | { |
| 7964 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; |
| 7965 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 7966 | int rc; |
| 7967 | |
| 7968 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", |
| 7969 | ha->host_no, __func__); |
| 7970 | |
| 7971 | if (!is_aer_supported(ha)) |
| 7972 | return PCI_ERS_RESULT_NONE; |
| 7973 | |
| 7974 | /* Restore the saved state of PCIe device - |
| 7975 | * BAR registers, PCI Config space, PCIX, MSI, |
| 7976 | * IOV states |
| 7977 | */ |
| 7978 | pci_restore_state(pdev); |
| 7979 | |
| 7980 | /* pci_restore_state() clears the saved_state flag of the device |
| 7981 | * save restored state which resets saved_state flag |
| 7982 | */ |
| 7983 | pci_save_state(pdev); |
| 7984 | |
| 7985 | /* Initialize device or resume if in suspended state */ |
| 7986 | rc = pci_enable_device(pdev); |
| 7987 | if (rc) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7988 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7989 | "device after reset\n", ha->host_no, __func__); |
| 7990 | goto exit_slot_reset; |
| 7991 | } |
| 7992 | |
Vikas Chaudhary | 7b3595d | 2010-10-06 22:50:56 -0700 | [diff] [blame] | 7993 | ha->isp_ops->disable_intrs(ha); |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7994 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 7995 | if (is_qla80XX(ha)) { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 7996 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { |
| 7997 | ret = PCI_ERS_RESULT_RECOVERED; |
| 7998 | goto exit_slot_reset; |
| 7999 | } else |
| 8000 | goto exit_slot_reset; |
| 8001 | } |
| 8002 | |
| 8003 | exit_slot_reset: |
| 8004 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" |
| 8005 | "device after reset\n", ha->host_no, __func__, ret); |
| 8006 | return ret; |
| 8007 | } |
| 8008 | |
| 8009 | static void |
| 8010 | qla4xxx_pci_resume(struct pci_dev *pdev) |
| 8011 | { |
| 8012 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); |
| 8013 | int ret; |
| 8014 | |
| 8015 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", |
| 8016 | ha->host_no, __func__); |
| 8017 | |
| 8018 | ret = qla4xxx_wait_for_hba_online(ha); |
| 8019 | if (ret != QLA_SUCCESS) { |
| 8020 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " |
| 8021 | "resume I/O from slot/link_reset\n", ha->host_no, |
| 8022 | __func__); |
| 8023 | } |
| 8024 | |
| 8025 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8026 | clear_bit(AF_EEH_BUSY, &ha->flags); |
| 8027 | } |
| 8028 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 8029 | static const struct pci_error_handlers qla4xxx_err_handler = { |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8030 | .error_detected = qla4xxx_pci_error_detected, |
| 8031 | .mmio_enabled = qla4xxx_pci_mmio_enabled, |
| 8032 | .slot_reset = qla4xxx_pci_slot_reset, |
| 8033 | .resume = qla4xxx_pci_resume, |
| 8034 | }; |
| 8035 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8036 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
| 8037 | { |
| 8038 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 8039 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, |
| 8040 | .subvendor = PCI_ANY_ID, |
| 8041 | .subdevice = PCI_ANY_ID, |
| 8042 | }, |
| 8043 | { |
| 8044 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 8045 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, |
| 8046 | .subvendor = PCI_ANY_ID, |
| 8047 | .subdevice = PCI_ANY_ID, |
| 8048 | }, |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 8049 | { |
| 8050 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 8051 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, |
| 8052 | .subvendor = PCI_ANY_ID, |
| 8053 | .subdevice = PCI_ANY_ID, |
| 8054 | }, |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 8055 | { |
| 8056 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 8057 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, |
| 8058 | .subvendor = PCI_ANY_ID, |
| 8059 | .subdevice = PCI_ANY_ID, |
| 8060 | }, |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 8061 | { |
| 8062 | .vendor = PCI_VENDOR_ID_QLOGIC, |
| 8063 | .device = PCI_DEVICE_ID_QLOGIC_ISP8324, |
| 8064 | .subvendor = PCI_ANY_ID, |
| 8065 | .subdevice = PCI_ANY_ID, |
| 8066 | }, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8067 | {0, 0}, |
| 8068 | }; |
| 8069 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); |
| 8070 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 8071 | static struct pci_driver qla4xxx_pci_driver = { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8072 | .name = DRIVER_NAME, |
| 8073 | .id_table = qla4xxx_pci_tbl, |
| 8074 | .probe = qla4xxx_probe_adapter, |
| 8075 | .remove = qla4xxx_remove_adapter, |
Lalit Chandivade | 2232be0 | 2010-07-30 14:38:47 +0530 | [diff] [blame] | 8076 | .err_handler = &qla4xxx_err_handler, |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8077 | }; |
| 8078 | |
| 8079 | static int __init qla4xxx_module_init(void) |
| 8080 | { |
| 8081 | int ret; |
| 8082 | |
| 8083 | /* Allocate cache for SRBs. */ |
| 8084 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 8085 | SLAB_HWCACHE_ALIGN, NULL); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8086 | if (srb_cachep == NULL) { |
| 8087 | printk(KERN_ERR |
| 8088 | "%s: Unable to allocate SRB cache..." |
| 8089 | "Failing load!\n", DRIVER_NAME); |
| 8090 | ret = -ENOMEM; |
| 8091 | goto no_srp_cache; |
| 8092 | } |
| 8093 | |
| 8094 | /* Derive version string. */ |
| 8095 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 8096 | if (ql4xextended_error_logging) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8097 | strcat(qla4xxx_version_str, "-debug"); |
| 8098 | |
| 8099 | qla4xxx_scsi_transport = |
| 8100 | iscsi_register_transport(&qla4xxx_iscsi_transport); |
| 8101 | if (!qla4xxx_scsi_transport){ |
| 8102 | ret = -ENODEV; |
| 8103 | goto release_srb_cache; |
| 8104 | } |
| 8105 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8106 | ret = pci_register_driver(&qla4xxx_pci_driver); |
| 8107 | if (ret) |
| 8108 | goto unregister_transport; |
| 8109 | |
| 8110 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); |
| 8111 | return 0; |
Doug Maxey | 5ae16db | 2006-10-05 23:50:07 -0500 | [diff] [blame] | 8112 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8113 | unregister_transport: |
| 8114 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 8115 | release_srb_cache: |
| 8116 | kmem_cache_destroy(srb_cachep); |
| 8117 | no_srp_cache: |
| 8118 | return ret; |
| 8119 | } |
| 8120 | |
| 8121 | static void __exit qla4xxx_module_exit(void) |
| 8122 | { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 8123 | pci_unregister_driver(&qla4xxx_pci_driver); |
| 8124 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); |
| 8125 | kmem_cache_destroy(srb_cachep); |
| 8126 | } |
| 8127 | |
| 8128 | module_init(qla4xxx_module_init); |
| 8129 | module_exit(qla4xxx_module_exit); |
| 8130 | |
| 8131 | MODULE_AUTHOR("QLogic Corporation"); |
| 8132 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); |
| 8133 | MODULE_LICENSE("GPL"); |
| 8134 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |