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