blob: c5d9564d455ce6ddadd759c884fa13212f09d543 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary4a4f51e2013-08-16 07:03:04 -04003 * Copyright (c) 2003-2013 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7#include <linux/moduleparam.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Manish Rangankar2a991c22011-07-25 13:48:55 -05009#include <linux/blkdev.h>
10#include <linux/iscsi_boot_sysfs.h>
Mike Christie13483732011-12-01 21:38:41 -060011#include <linux/inet.h>
David Somayajuluafaf5a22006-09-19 10:28:00 -070012
13#include <scsi/scsi_tcq.h>
14#include <scsi/scsicam.h>
15
16#include "ql4_def.h"
David C Somayajulubee4fe82007-05-23 18:03:32 -070017#include "ql4_version.h"
18#include "ql4_glbl.h"
19#include "ql4_dbg.h"
20#include "ql4_inline.h"
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -040021#include "ql4_83xx.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070022
23/*
24 * Driver version
25 */
Adrian Bunk47975472007-04-26 00:35:16 -070026static char qla4xxx_version_str[40];
David Somayajuluafaf5a22006-09-19 10:28:00 -070027
28/*
29 * SRB allocation cache
30 */
Christoph Lametere18b8902006-12-06 20:33:20 -080031static struct kmem_cache *srb_cachep;
David Somayajuluafaf5a22006-09-19 10:28:00 -070032
33/*
34 * Module parameter information and variables
35 */
Vikas Chaudharya7380a62012-02-27 03:08:56 -080036static int ql4xdisablesysfsboot = 1;
Mike Christie13483732011-12-01 21:38:41 -060037module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
38MODULE_PARM_DESC(ql4xdisablesysfsboot,
Karen Higginsa4e8a712012-01-11 02:44:20 -080039 " Set to disable exporting boot targets to sysfs.\n"
40 "\t\t 0 - Export boot targets\n"
41 "\t\t 1 - Do not export boot targets (Default)");
Mike Christie13483732011-12-01 21:38:41 -060042
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -080043int ql4xdontresethba;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053044module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
David Somayajuluafaf5a22006-09-19 10:28:00 -070045MODULE_PARM_DESC(ql4xdontresethba,
Karen Higginsa4e8a712012-01-11 02:44:20 -080046 " Don't reset the HBA for driver recovery.\n"
47 "\t\t 0 - It will reset HBA (Default)\n"
48 "\t\t 1 - It will NOT reset HBA");
David Somayajuluafaf5a22006-09-19 10:28:00 -070049
Karen Higginsa4e8a712012-01-11 02:44:20 -080050int ql4xextended_error_logging;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053051module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070052MODULE_PARM_DESC(ql4xextended_error_logging,
Karen Higginsa4e8a712012-01-11 02:44:20 -080053 " Option to enable extended error logging.\n"
54 "\t\t 0 - no logging (Default)\n"
55 "\t\t 2 - debug logging");
David Somayajuluafaf5a22006-09-19 10:28:00 -070056
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053057int ql4xenablemsix = 1;
58module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
59MODULE_PARM_DESC(ql4xenablemsix,
Karen Higginsa4e8a712012-01-11 02:44:20 -080060 " Set to enable MSI or MSI-X interrupt mechanism.\n"
61 "\t\t 0 = enable INTx interrupt mechanism.\n"
62 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
63 "\t\t 2 = enable MSI interrupt mechanism.");
David C Somayajulu477ffb92007-01-22 12:26:11 -080064
Mike Christied510d962008-07-11 19:50:33 -050065#define QL4_DEF_QDEPTH 32
Vikas Chaudhary8bb40332011-03-21 03:34:31 -070066static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
67module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
68MODULE_PARM_DESC(ql4xmaxqdepth,
Karen Higginsa4e8a712012-01-11 02:44:20 -080069 " Maximum queue depth to report for target devices.\n"
70 "\t\t Default: 32.");
Mike Christied510d962008-07-11 19:50:33 -050071
Tej Parkashf7b4aa62012-04-30 04:12:19 -070072static int ql4xqfulltracking = 1;
73module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
74MODULE_PARM_DESC(ql4xqfulltracking,
75 " Enable or disable dynamic tracking and adjustment of\n"
76 "\t\t scsi device queue depth.\n"
77 "\t\t 0 - Disable.\n"
78 "\t\t 1 - Enable. (Default)");
79
Vikas Chaudhary30387272011-03-21 03:34:32 -070080static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
81module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
82MODULE_PARM_DESC(ql4xsess_recovery_tmo,
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -080083 " Target Session Recovery Timeout.\n"
Karen Higginsa4e8a712012-01-11 02:44:20 -080084 "\t\t Default: 120 sec.");
Vikas Chaudhary30387272011-03-21 03:34:32 -070085
Tej Parkasha511b4a2014-02-24 22:06:57 -050086int ql4xmdcapmask = 0;
Tej Parkash068237c82012-05-18 04:41:44 -040087module_param(ql4xmdcapmask, int, S_IRUGO);
88MODULE_PARM_DESC(ql4xmdcapmask,
89 " Set the Minidump driver capture mask level.\n"
Tej Parkasha511b4a2014-02-24 22:06:57 -050090 "\t\t Default is 0 (firmware default capture mask)\n"
Tej Parkashb4109822014-02-24 22:06:58 -050091 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
Tej Parkash068237c82012-05-18 04:41:44 -040092
93int ql4xenablemd = 1;
94module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
95MODULE_PARM_DESC(ql4xenablemd,
96 " Set to enable minidump.\n"
97 "\t\t 0 - disable minidump\n"
98 "\t\t 1 - enable minidump (Default)");
99
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500100static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700101/*
102 * SCSI host template entry points
103 */
Adrian Bunk47975472007-04-26 00:35:16 -0700104static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700105
106/*
107 * iSCSI template entry points
108 */
Mike Christiefca9f042012-02-27 03:08:54 -0800109static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
110 enum iscsi_param param, char *buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700111static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
112 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500113static int qla4xxx_host_get_param(struct Scsi_Host *shost,
114 enum iscsi_host_param param, char *buf);
Mike Christie00c31882011-10-06 03:56:59 -0500115static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
116 uint32_t len);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500117static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
118 enum iscsi_param_type param_type,
119 int param, char *buf);
Mike Christie5c656af2009-07-15 15:02:59 -0500120static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500121static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
122 struct sockaddr *dst_addr,
123 int non_blocking);
124static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
125static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
126static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
127 enum iscsi_param param, char *buf);
128static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
129static struct iscsi_cls_conn *
130qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
131static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
132 struct iscsi_cls_conn *cls_conn,
133 uint64_t transport_fd, int is_leading);
134static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
135static struct iscsi_cls_session *
136qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
137 uint16_t qdepth, uint32_t initial_cmdsn);
138static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
139static void qla4xxx_task_work(struct work_struct *wdata);
140static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
141static int qla4xxx_task_xmit(struct iscsi_task *);
142static void qla4xxx_task_cleanup(struct iscsi_task *);
143static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
144static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
145 struct iscsi_stats *stats);
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530146static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
147 uint32_t iface_type, uint32_t payload_size,
148 uint32_t pid, struct sockaddr *dst_addr);
Nilesh Javali376738a2012-02-27 03:08:52 -0800149static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
150 uint32_t *num_entries, char *buf);
151static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400152static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
153 int len);
Lalit Chandivade4161cee2013-11-22 05:28:19 -0500154static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530155
David Somayajuluafaf5a22006-09-19 10:28:00 -0700156/*
157 * SCSI host template entry points
158 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500159static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530160static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700161static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -0600162static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700163static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164static int qla4xxx_slave_alloc(struct scsi_device *device);
165static int qla4xxx_slave_configure(struct scsi_device *device);
166static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400167static umode_t qla4_attr_is_visible(int param_type, int param);
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700168static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
Tej Parkashf7b4aa62012-04-30 04:12:19 -0700169static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
170 int reason);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700171
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400172/*
173 * iSCSI Flash DDB sysfs entry points
174 */
175static int
176qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
177 struct iscsi_bus_flash_conn *fnode_conn,
178 void *data, int len);
179static int
180qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
181 int param, char *buf);
182static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
183 int len);
184static int
185qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
186static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
187 struct iscsi_bus_flash_conn *fnode_conn);
188static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
189 struct iscsi_bus_flash_conn *fnode_conn);
190static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
191
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530192static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
193 QLA82XX_LEGACY_INTR_CONFIG;
194
David Somayajuluafaf5a22006-09-19 10:28:00 -0700195static struct scsi_host_template qla4xxx_driver_template = {
196 .module = THIS_MODULE,
197 .name = DRIVER_NAME,
198 .proc_name = DRIVER_NAME,
199 .queuecommand = qla4xxx_queuecommand,
200
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530201 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700202 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600203 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700204 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500205 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700206
207 .slave_configure = qla4xxx_slave_configure,
208 .slave_alloc = qla4xxx_slave_alloc,
209 .slave_destroy = qla4xxx_slave_destroy,
Tej Parkashf7b4aa62012-04-30 04:12:19 -0700210 .change_queue_depth = qla4xxx_change_queue_depth,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700211
212 .this_id = -1,
213 .cmd_per_lun = 3,
214 .use_clustering = ENABLE_CLUSTERING,
215 .sg_tablesize = SG_ALL,
216
217 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700218 .shost_attrs = qla4xxx_host_attrs,
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700219 .host_reset = qla4xxx_host_reset,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500220 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700221};
222
223static struct iscsi_transport qla4xxx_iscsi_transport = {
224 .owner = THIS_MODULE,
225 .name = DRIVER_NAME,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500226 .caps = CAP_TEXT_NEGO |
227 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
228 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
229 CAP_MULTI_R2T,
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400230 .attr_is_visible = qla4_attr_is_visible,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500231 .create_session = qla4xxx_session_create,
232 .destroy_session = qla4xxx_session_destroy,
233 .start_conn = qla4xxx_conn_start,
234 .create_conn = qla4xxx_conn_create,
235 .bind_conn = qla4xxx_conn_bind,
236 .stop_conn = iscsi_conn_stop,
237 .destroy_conn = qla4xxx_conn_destroy,
238 .set_param = iscsi_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700239 .get_conn_param = qla4xxx_conn_get_param,
Mike Christiefca9f042012-02-27 03:08:54 -0800240 .get_session_param = qla4xxx_session_get_param,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500241 .get_ep_param = qla4xxx_get_ep_param,
242 .ep_connect = qla4xxx_ep_connect,
243 .ep_poll = qla4xxx_ep_poll,
244 .ep_disconnect = qla4xxx_ep_disconnect,
245 .get_stats = qla4xxx_conn_get_stats,
246 .send_pdu = iscsi_conn_send_pdu,
247 .xmit_task = qla4xxx_task_xmit,
248 .cleanup_task = qla4xxx_task_cleanup,
249 .alloc_pdu = qla4xxx_alloc_pdu,
250
Mike Christieaa1e93a2007-05-30 12:57:09 -0500251 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500252 .set_iface_param = qla4xxx_iface_set_param,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500253 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500254 .bsg_request = qla4xxx_bsg_request,
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530255 .send_ping = qla4xxx_send_ping,
Nilesh Javali376738a2012-02-27 03:08:52 -0800256 .get_chap = qla4xxx_get_chap_list,
257 .delete_chap = qla4xxx_delete_chap,
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400258 .set_chap = qla4xxx_set_chap_entry,
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400259 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
260 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
261 .new_flashnode = qla4xxx_sysfs_ddb_add,
262 .del_flashnode = qla4xxx_sysfs_ddb_delete,
263 .login_flashnode = qla4xxx_sysfs_ddb_login,
264 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
265 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
Lalit Chandivade4161cee2013-11-22 05:28:19 -0500266 .get_host_stats = qla4xxx_get_host_stats,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700267};
268
269static struct scsi_transport_template *qla4xxx_scsi_transport;
270
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530271static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
272 uint32_t iface_type, uint32_t payload_size,
273 uint32_t pid, struct sockaddr *dst_addr)
274{
275 struct scsi_qla_host *ha = to_qla_host(shost);
276 struct sockaddr_in *addr;
277 struct sockaddr_in6 *addr6;
278 uint32_t options = 0;
279 uint8_t ipaddr[IPv6_ADDR_LEN];
280 int rval;
281
282 memset(ipaddr, 0, IPv6_ADDR_LEN);
283 /* IPv4 to IPv4 */
284 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
285 (dst_addr->sa_family == AF_INET)) {
286 addr = (struct sockaddr_in *)dst_addr;
287 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
288 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
289 "dest: %pI4\n", __func__,
290 &ha->ip_config.ip_address, ipaddr));
291 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
292 ipaddr);
293 if (rval)
294 rval = -EINVAL;
295 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
296 (dst_addr->sa_family == AF_INET6)) {
297 /* IPv6 to IPv6 */
298 addr6 = (struct sockaddr_in6 *)dst_addr;
299 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
300
301 options |= PING_IPV6_PROTOCOL_ENABLE;
302
303 /* Ping using LinkLocal address */
304 if ((iface_num == 0) || (iface_num == 1)) {
305 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
306 "src: %pI6 dest: %pI6\n", __func__,
307 &ha->ip_config.ipv6_link_local_addr,
308 ipaddr));
309 options |= PING_IPV6_LINKLOCAL_ADDR;
310 rval = qla4xxx_ping_iocb(ha, options, payload_size,
311 pid, ipaddr);
312 } else {
313 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
314 "not supported\n", __func__, iface_num);
315 rval = -ENOSYS;
316 goto exit_send_ping;
317 }
318
319 /*
320 * If ping using LinkLocal address fails, try ping using
321 * IPv6 address
322 */
323 if (rval != QLA_SUCCESS) {
324 options &= ~PING_IPV6_LINKLOCAL_ADDR;
325 if (iface_num == 0) {
326 options |= PING_IPV6_ADDR0;
327 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
328 "Ping src: %pI6 "
329 "dest: %pI6\n", __func__,
330 &ha->ip_config.ipv6_addr0,
331 ipaddr));
332 } else if (iface_num == 1) {
333 options |= PING_IPV6_ADDR1;
334 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
335 "Ping src: %pI6 "
336 "dest: %pI6\n", __func__,
337 &ha->ip_config.ipv6_addr1,
338 ipaddr));
339 }
340 rval = qla4xxx_ping_iocb(ha, options, payload_size,
341 pid, ipaddr);
342 if (rval)
343 rval = -EINVAL;
344 }
345 } else
346 rval = -ENOSYS;
347exit_send_ping:
348 return rval;
349}
350
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400351static umode_t qla4_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -0500352{
353 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500354 case ISCSI_HOST_PARAM:
355 switch (param) {
356 case ISCSI_HOST_PARAM_HWADDRESS:
357 case ISCSI_HOST_PARAM_IPADDRESS:
358 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -0800359 case ISCSI_HOST_PARAM_PORT_STATE:
360 case ISCSI_HOST_PARAM_PORT_SPEED:
Mike Christief27fb2e2011-07-25 13:48:45 -0500361 return S_IRUGO;
362 default:
363 return 0;
364 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500365 case ISCSI_PARAM:
366 switch (param) {
Mike Christie590134f2011-10-17 22:42:13 -0500367 case ISCSI_PARAM_PERSISTENT_ADDRESS:
368 case ISCSI_PARAM_PERSISTENT_PORT:
Mike Christie3128c6c2011-07-25 13:48:42 -0500369 case ISCSI_PARAM_CONN_ADDRESS:
370 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500371 case ISCSI_PARAM_TARGET_NAME:
372 case ISCSI_PARAM_TPGT:
373 case ISCSI_PARAM_TARGET_ALIAS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500374 case ISCSI_PARAM_MAX_BURST:
375 case ISCSI_PARAM_MAX_R2T:
376 case ISCSI_PARAM_FIRST_BURST:
377 case ISCSI_PARAM_MAX_RECV_DLENGTH:
378 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Mike Christiede379202011-08-14 20:42:56 -0500379 case ISCSI_PARAM_IFACE_NAME:
Mike Christiefca9f042012-02-27 03:08:54 -0800380 case ISCSI_PARAM_CHAP_OUT_IDX:
381 case ISCSI_PARAM_CHAP_IN_IDX:
382 case ISCSI_PARAM_USERNAME:
383 case ISCSI_PARAM_PASSWORD:
384 case ISCSI_PARAM_USERNAME_IN:
385 case ISCSI_PARAM_PASSWORD_IN:
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -0400386 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
387 case ISCSI_PARAM_DISCOVERY_SESS:
388 case ISCSI_PARAM_PORTAL_TYPE:
389 case ISCSI_PARAM_CHAP_AUTH_EN:
390 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
391 case ISCSI_PARAM_BIDI_CHAP_EN:
392 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
393 case ISCSI_PARAM_DEF_TIME2WAIT:
394 case ISCSI_PARAM_DEF_TIME2RETAIN:
395 case ISCSI_PARAM_HDRDGST_EN:
396 case ISCSI_PARAM_DATADGST_EN:
397 case ISCSI_PARAM_INITIAL_R2T_EN:
398 case ISCSI_PARAM_IMM_DATA_EN:
399 case ISCSI_PARAM_PDU_INORDER_EN:
400 case ISCSI_PARAM_DATASEQ_INORDER_EN:
401 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
402 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
403 case ISCSI_PARAM_TCP_WSF_DISABLE:
404 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
405 case ISCSI_PARAM_TCP_TIMER_SCALE:
406 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
407 case ISCSI_PARAM_TCP_XMIT_WSF:
408 case ISCSI_PARAM_TCP_RECV_WSF:
409 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
410 case ISCSI_PARAM_IPV4_TOS:
411 case ISCSI_PARAM_IPV6_TC:
412 case ISCSI_PARAM_IPV6_FLOW_LABEL:
413 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
414 case ISCSI_PARAM_KEEPALIVE_TMO:
415 case ISCSI_PARAM_LOCAL_PORT:
416 case ISCSI_PARAM_ISID:
417 case ISCSI_PARAM_TSID:
418 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
419 case ISCSI_PARAM_ERL:
420 case ISCSI_PARAM_STATSN:
421 case ISCSI_PARAM_EXP_STATSN:
422 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
423 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
Adheer Chandravanshifb734ee32013-11-22 05:28:22 -0500424 case ISCSI_PARAM_LOCAL_IPADDR:
Mike Christie3128c6c2011-07-25 13:48:42 -0500425 return S_IRUGO;
426 default:
427 return 0;
428 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500429 case ISCSI_NET_PARAM:
430 switch (param) {
431 case ISCSI_NET_PARAM_IPV4_ADDR:
432 case ISCSI_NET_PARAM_IPV4_SUBNET:
433 case ISCSI_NET_PARAM_IPV4_GW:
434 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
435 case ISCSI_NET_PARAM_IFACE_ENABLE:
436 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
437 case ISCSI_NET_PARAM_IPV6_ADDR:
438 case ISCSI_NET_PARAM_IPV6_ROUTER:
439 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
440 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500441 case ISCSI_NET_PARAM_VLAN_ID:
442 case ISCSI_NET_PARAM_VLAN_PRIORITY:
443 case ISCSI_NET_PARAM_VLAN_ENABLED:
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700444 case ISCSI_NET_PARAM_MTU:
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700445 case ISCSI_NET_PARAM_PORT:
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400446 case ISCSI_NET_PARAM_IPADDR_STATE:
447 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
448 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
449 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
450 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
451 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
452 case ISCSI_NET_PARAM_TCP_WSF:
453 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
454 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
455 case ISCSI_NET_PARAM_CACHE_ID:
456 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
457 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
458 case ISCSI_NET_PARAM_IPV4_TOS_EN:
459 case ISCSI_NET_PARAM_IPV4_TOS:
460 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
461 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
462 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
463 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
464 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
465 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
466 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
467 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
468 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
469 case ISCSI_NET_PARAM_REDIRECT_EN:
470 case ISCSI_NET_PARAM_IPV4_TTL:
471 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
472 case ISCSI_NET_PARAM_IPV6_MLD_EN:
473 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
474 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
475 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
476 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
477 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
478 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
479 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
480 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
481 return S_IRUGO;
482 default:
483 return 0;
484 }
485 case ISCSI_IFACE_PARAM:
486 switch (param) {
487 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
488 case ISCSI_IFACE_PARAM_HDRDGST_EN:
489 case ISCSI_IFACE_PARAM_DATADGST_EN:
490 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
491 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
492 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
493 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
494 case ISCSI_IFACE_PARAM_ERL:
495 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
496 case ISCSI_IFACE_PARAM_FIRST_BURST:
497 case ISCSI_IFACE_PARAM_MAX_R2T:
498 case ISCSI_IFACE_PARAM_MAX_BURST:
499 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
500 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
501 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
502 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
503 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
504 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
Mike Christieb78dbba2011-07-25 13:48:44 -0500505 return S_IRUGO;
506 default:
507 return 0;
508 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400509 case ISCSI_FLASHNODE_PARAM:
510 switch (param) {
511 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
512 case ISCSI_FLASHNODE_PORTAL_TYPE:
513 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
514 case ISCSI_FLASHNODE_DISCOVERY_SESS:
515 case ISCSI_FLASHNODE_ENTRY_EN:
516 case ISCSI_FLASHNODE_HDR_DGST_EN:
517 case ISCSI_FLASHNODE_DATA_DGST_EN:
518 case ISCSI_FLASHNODE_IMM_DATA_EN:
519 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
520 case ISCSI_FLASHNODE_DATASEQ_INORDER:
521 case ISCSI_FLASHNODE_PDU_INORDER:
522 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
523 case ISCSI_FLASHNODE_SNACK_REQ_EN:
524 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
525 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
526 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
527 case ISCSI_FLASHNODE_ERL:
528 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
529 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
530 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
531 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
532 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
533 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
534 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
535 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
536 case ISCSI_FLASHNODE_FIRST_BURST:
537 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
538 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
539 case ISCSI_FLASHNODE_MAX_R2T:
540 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
541 case ISCSI_FLASHNODE_ISID:
542 case ISCSI_FLASHNODE_TSID:
543 case ISCSI_FLASHNODE_PORT:
544 case ISCSI_FLASHNODE_MAX_BURST:
545 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
546 case ISCSI_FLASHNODE_IPADDR:
547 case ISCSI_FLASHNODE_ALIAS:
548 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
549 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
550 case ISCSI_FLASHNODE_LOCAL_PORT:
551 case ISCSI_FLASHNODE_IPV4_TOS:
552 case ISCSI_FLASHNODE_IPV6_TC:
553 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
554 case ISCSI_FLASHNODE_NAME:
555 case ISCSI_FLASHNODE_TPGT:
556 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
557 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
558 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
559 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
560 case ISCSI_FLASHNODE_TCP_RECV_WSF:
561 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
562 case ISCSI_FLASHNODE_USERNAME:
563 case ISCSI_FLASHNODE_PASSWORD:
564 case ISCSI_FLASHNODE_STATSN:
565 case ISCSI_FLASHNODE_EXP_STATSN:
566 case ISCSI_FLASHNODE_IS_BOOT_TGT:
567 return S_IRUGO;
568 default:
569 return 0;
570 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500571 }
572
573 return 0;
574}
575
Adheer Chandravanshiea507a22013-11-22 05:28:23 -0500576/**
577 * qla4xxx_create chap_list - Create CHAP list from FLASH
578 * @ha: pointer to adapter structure
579 *
580 * Read flash and make a list of CHAP entries, during login when a CHAP entry
581 * is received, it will be checked in this list. If entry exist then the CHAP
582 * entry index is set in the DDB. If CHAP entry does not exist in this list
583 * then a new entry is added in FLASH in CHAP table and the index obtained is
584 * used in the DDB.
585 **/
586static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
587{
588 int rval = 0;
589 uint8_t *chap_flash_data = NULL;
590 uint32_t offset;
591 dma_addr_t chap_dma;
592 uint32_t chap_size = 0;
593
594 if (is_qla40XX(ha))
595 chap_size = MAX_CHAP_ENTRIES_40XX *
596 sizeof(struct ql4_chap_table);
597 else /* Single region contains CHAP info for both
598 * ports which is divided into half for each port.
599 */
600 chap_size = ha->hw.flt_chap_size / 2;
601
602 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
603 &chap_dma, GFP_KERNEL);
604 if (!chap_flash_data) {
605 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
606 return;
607 }
608
609 if (is_qla40XX(ha)) {
610 offset = FLASH_CHAP_OFFSET;
611 } else {
612 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
613 if (ha->port_num == 1)
614 offset += chap_size;
615 }
616
617 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
618 if (rval != QLA_SUCCESS)
619 goto exit_chap_list;
620
621 if (ha->chap_list == NULL)
622 ha->chap_list = vmalloc(chap_size);
623 if (ha->chap_list == NULL) {
624 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
625 goto exit_chap_list;
626 }
627
628 memset(ha->chap_list, 0, chap_size);
629 memcpy(ha->chap_list, chap_flash_data, chap_size);
630
631exit_chap_list:
632 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
633}
634
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400635static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
636 int16_t chap_index,
637 struct ql4_chap_table **chap_entry)
638{
639 int rval = QLA_ERROR;
640 int max_chap_entries;
641
642 if (!ha->chap_list) {
643 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
644 rval = QLA_ERROR;
645 goto exit_get_chap;
646 }
647
648 if (is_qla80XX(ha))
649 max_chap_entries = (ha->hw.flt_chap_size / 2) /
650 sizeof(struct ql4_chap_table);
651 else
652 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
653
654 if (chap_index > max_chap_entries) {
655 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
656 rval = QLA_ERROR;
657 goto exit_get_chap;
658 }
659
660 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
661 if ((*chap_entry)->cookie !=
662 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
663 rval = QLA_ERROR;
664 *chap_entry = NULL;
665 } else {
666 rval = QLA_SUCCESS;
667 }
668
669exit_get_chap:
670 return rval;
671}
672
673/**
674 * qla4xxx_find_free_chap_index - Find the first free chap index
675 * @ha: pointer to adapter structure
676 * @chap_index: CHAP index to be returned
677 *
678 * Find the first free chap index available in the chap table
679 *
680 * Note: Caller should acquire the chap lock before getting here.
681 **/
682static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
683 uint16_t *chap_index)
684{
685 int i, rval;
686 int free_index = -1;
687 int max_chap_entries = 0;
688 struct ql4_chap_table *chap_table;
689
690 if (is_qla80XX(ha))
691 max_chap_entries = (ha->hw.flt_chap_size / 2) /
692 sizeof(struct ql4_chap_table);
693 else
694 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
695
696 if (!ha->chap_list) {
697 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
698 rval = QLA_ERROR;
699 goto exit_find_chap;
700 }
701
702 for (i = 0; i < max_chap_entries; i++) {
703 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
704
705 if ((chap_table->cookie !=
706 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
707 (i > MAX_RESRV_CHAP_IDX)) {
708 free_index = i;
709 break;
710 }
711 }
712
713 if (free_index != -1) {
714 *chap_index = free_index;
715 rval = QLA_SUCCESS;
716 } else {
717 rval = QLA_ERROR;
718 }
719
720exit_find_chap:
721 return rval;
722}
723
Nilesh Javali376738a2012-02-27 03:08:52 -0800724static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
725 uint32_t *num_entries, char *buf)
726{
727 struct scsi_qla_host *ha = to_qla_host(shost);
728 struct ql4_chap_table *chap_table;
729 struct iscsi_chap_rec *chap_rec;
730 int max_chap_entries = 0;
731 int valid_chap_entries = 0;
732 int ret = 0, i;
733
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400734 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800735 max_chap_entries = (ha->hw.flt_chap_size / 2) /
736 sizeof(struct ql4_chap_table);
737 else
738 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
739
740 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
741 __func__, *num_entries, chap_tbl_idx);
742
743 if (!buf) {
744 ret = -ENOMEM;
745 goto exit_get_chap_list;
746 }
747
Adheer Chandravanshiea507a22013-11-22 05:28:23 -0500748 qla4xxx_create_chap_list(ha);
749
Nilesh Javali376738a2012-02-27 03:08:52 -0800750 chap_rec = (struct iscsi_chap_rec *) buf;
751 mutex_lock(&ha->chap_sem);
752 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
753 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
754 if (chap_table->cookie !=
755 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
756 continue;
757
758 chap_rec->chap_tbl_idx = i;
759 strncpy(chap_rec->username, chap_table->name,
760 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
761 strncpy(chap_rec->password, chap_table->secret,
762 QL4_CHAP_MAX_SECRET_LEN);
763 chap_rec->password_length = chap_table->secret_len;
764
765 if (chap_table->flags & BIT_7) /* local */
766 chap_rec->chap_type = CHAP_TYPE_OUT;
767
768 if (chap_table->flags & BIT_6) /* peer */
769 chap_rec->chap_type = CHAP_TYPE_IN;
770
771 chap_rec++;
772
773 valid_chap_entries++;
774 if (valid_chap_entries == *num_entries)
775 break;
776 else
777 continue;
778 }
779 mutex_unlock(&ha->chap_sem);
780
781exit_get_chap_list:
782 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
783 __func__, valid_chap_entries);
784 *num_entries = valid_chap_entries;
785 return ret;
786}
787
788static int __qla4xxx_is_chap_active(struct device *dev, void *data)
789{
790 int ret = 0;
791 uint16_t *chap_tbl_idx = (uint16_t *) data;
792 struct iscsi_cls_session *cls_session;
793 struct iscsi_session *sess;
794 struct ddb_entry *ddb_entry;
795
796 if (!iscsi_is_session_dev(dev))
797 goto exit_is_chap_active;
798
799 cls_session = iscsi_dev_to_session(dev);
800 sess = cls_session->dd_data;
801 ddb_entry = sess->dd_data;
802
803 if (iscsi_session_chkready(cls_session))
804 goto exit_is_chap_active;
805
806 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
807 ret = 1;
808
809exit_is_chap_active:
810 return ret;
811}
812
813static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
814 uint16_t chap_tbl_idx)
815{
816 int ret = 0;
817
818 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
819 __qla4xxx_is_chap_active);
820
821 return ret;
822}
823
824static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
825{
826 struct scsi_qla_host *ha = to_qla_host(shost);
827 struct ql4_chap_table *chap_table;
828 dma_addr_t chap_dma;
829 int max_chap_entries = 0;
830 uint32_t offset = 0;
831 uint32_t chap_size;
832 int ret = 0;
833
834 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
835 if (chap_table == NULL)
836 return -ENOMEM;
837
838 memset(chap_table, 0, sizeof(struct ql4_chap_table));
839
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400840 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800841 max_chap_entries = (ha->hw.flt_chap_size / 2) /
842 sizeof(struct ql4_chap_table);
843 else
844 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
845
846 if (chap_tbl_idx > max_chap_entries) {
847 ret = -EINVAL;
848 goto exit_delete_chap;
849 }
850
851 /* Check if chap index is in use.
852 * If chap is in use don't delet chap entry */
853 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
854 if (ret) {
855 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
856 "delete from flash\n", chap_tbl_idx);
857 ret = -EBUSY;
858 goto exit_delete_chap;
859 }
860
861 chap_size = sizeof(struct ql4_chap_table);
862 if (is_qla40XX(ha))
863 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
864 else {
865 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
866 /* flt_chap_size is CHAP table size for both ports
867 * so divide it by 2 to calculate the offset for second port
868 */
869 if (ha->port_num == 1)
870 offset += (ha->hw.flt_chap_size / 2);
871 offset += (chap_tbl_idx * chap_size);
872 }
873
874 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
875 if (ret != QLA_SUCCESS) {
876 ret = -EINVAL;
877 goto exit_delete_chap;
878 }
879
880 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
881 __le16_to_cpu(chap_table->cookie)));
882
883 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
884 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
885 goto exit_delete_chap;
886 }
887
888 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
889
890 offset = FLASH_CHAP_OFFSET |
891 (chap_tbl_idx * sizeof(struct ql4_chap_table));
892 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
893 FLASH_OPT_RMW_COMMIT);
894 if (ret == QLA_SUCCESS && ha->chap_list) {
895 mutex_lock(&ha->chap_sem);
896 /* Update ha chap_list cache */
897 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
898 chap_table, sizeof(struct ql4_chap_table));
899 mutex_unlock(&ha->chap_sem);
900 }
901 if (ret != QLA_SUCCESS)
902 ret = -EINVAL;
903
904exit_delete_chap:
905 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
906 return ret;
907}
908
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400909/**
910 * qla4xxx_set_chap_entry - Make chap entry with given information
911 * @shost: pointer to host
912 * @data: chap info - credentials, index and type to make chap entry
913 * @len: length of data
914 *
915 * Add or update chap entry with the given information
916 **/
917static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
918{
919 struct scsi_qla_host *ha = to_qla_host(shost);
920 struct iscsi_chap_rec chap_rec;
921 struct ql4_chap_table *chap_entry = NULL;
922 struct iscsi_param_info *param_info;
923 struct nlattr *attr;
924 int max_chap_entries = 0;
925 int type;
926 int rem = len;
927 int rc = 0;
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300928 int size;
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400929
930 memset(&chap_rec, 0, sizeof(chap_rec));
931
932 nla_for_each_attr(attr, data, len, rem) {
933 param_info = nla_data(attr);
934
935 switch (param_info->param) {
936 case ISCSI_CHAP_PARAM_INDEX:
937 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
938 break;
939 case ISCSI_CHAP_PARAM_CHAP_TYPE:
940 chap_rec.chap_type = param_info->value[0];
941 break;
942 case ISCSI_CHAP_PARAM_USERNAME:
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300943 size = min_t(size_t, sizeof(chap_rec.username),
944 param_info->len);
945 memcpy(chap_rec.username, param_info->value, size);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400946 break;
947 case ISCSI_CHAP_PARAM_PASSWORD:
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300948 size = min_t(size_t, sizeof(chap_rec.password),
949 param_info->len);
950 memcpy(chap_rec.password, param_info->value, size);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400951 break;
952 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
953 chap_rec.password_length = param_info->value[0];
954 break;
955 default:
956 ql4_printk(KERN_ERR, ha,
957 "%s: No such sysfs attribute\n", __func__);
958 rc = -ENOSYS;
959 goto exit_set_chap;
960 };
961 }
962
963 if (chap_rec.chap_type == CHAP_TYPE_IN)
964 type = BIDI_CHAP;
965 else
966 type = LOCAL_CHAP;
967
968 if (is_qla80XX(ha))
969 max_chap_entries = (ha->hw.flt_chap_size / 2) /
970 sizeof(struct ql4_chap_table);
971 else
972 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
973
974 mutex_lock(&ha->chap_sem);
975 if (chap_rec.chap_tbl_idx < max_chap_entries) {
976 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
977 &chap_entry);
978 if (!rc) {
979 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
980 ql4_printk(KERN_INFO, ha,
981 "Type mismatch for CHAP entry %d\n",
982 chap_rec.chap_tbl_idx);
983 rc = -EINVAL;
984 goto exit_unlock_chap;
985 }
986
987 /* If chap index is in use then don't modify it */
988 rc = qla4xxx_is_chap_active(shost,
989 chap_rec.chap_tbl_idx);
990 if (rc) {
991 ql4_printk(KERN_INFO, ha,
992 "CHAP entry %d is in use\n",
993 chap_rec.chap_tbl_idx);
994 rc = -EBUSY;
995 goto exit_unlock_chap;
996 }
997 }
998 } else {
999 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1000 if (rc) {
1001 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1002 rc = -EBUSY;
1003 goto exit_unlock_chap;
1004 }
1005 }
1006
1007 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1008 chap_rec.chap_tbl_idx, type);
1009
1010exit_unlock_chap:
1011 mutex_unlock(&ha->chap_sem);
1012
1013exit_set_chap:
1014 return rc;
1015}
1016
Lalit Chandivade4161cee2013-11-22 05:28:19 -05001017
1018static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1019{
1020 struct scsi_qla_host *ha = to_qla_host(shost);
1021 struct iscsi_offload_host_stats *host_stats = NULL;
1022 int host_stats_size;
1023 int ret = 0;
1024 int ddb_idx = 0;
1025 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1026 int stats_size;
1027 dma_addr_t iscsi_stats_dma;
1028
1029 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1030
1031 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1032
1033 if (host_stats_size != len) {
1034 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1035 __func__, len, host_stats_size);
1036 ret = -EINVAL;
1037 goto exit_host_stats;
1038 }
1039 host_stats = (struct iscsi_offload_host_stats *)buf;
1040
1041 if (!buf) {
1042 ret = -ENOMEM;
1043 goto exit_host_stats;
1044 }
1045
1046 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1047
1048 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1049 &iscsi_stats_dma, GFP_KERNEL);
1050 if (!ql_iscsi_stats) {
1051 ql4_printk(KERN_ERR, ha,
1052 "Unable to allocate memory for iscsi stats\n");
1053 goto exit_host_stats;
1054 }
1055
1056 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1057 iscsi_stats_dma);
1058 if (ret != QLA_SUCCESS) {
1059 ql4_printk(KERN_ERR, ha,
1060 "Unable to retrieve iscsi stats\n");
1061 goto exit_host_stats;
1062 }
1063 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1064 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1065 host_stats->mactx_multicast_frames =
1066 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1067 host_stats->mactx_broadcast_frames =
1068 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1069 host_stats->mactx_pause_frames =
1070 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1071 host_stats->mactx_control_frames =
1072 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1073 host_stats->mactx_deferral =
1074 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1075 host_stats->mactx_excess_deferral =
1076 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1077 host_stats->mactx_late_collision =
1078 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1079 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1080 host_stats->mactx_single_collision =
1081 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1082 host_stats->mactx_multiple_collision =
1083 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1084 host_stats->mactx_collision =
1085 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1086 host_stats->mactx_frames_dropped =
1087 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1088 host_stats->mactx_jumbo_frames =
1089 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1090 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1091 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1092 host_stats->macrx_unknown_control_frames =
1093 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1094 host_stats->macrx_pause_frames =
1095 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1096 host_stats->macrx_control_frames =
1097 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1098 host_stats->macrx_dribble =
1099 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1100 host_stats->macrx_frame_length_error =
1101 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1102 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1103 host_stats->macrx_carrier_sense_error =
1104 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1105 host_stats->macrx_frame_discarded =
1106 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1107 host_stats->macrx_frames_dropped =
1108 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1109 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1110 host_stats->mac_encoding_error =
1111 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1112 host_stats->macrx_length_error_large =
1113 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1114 host_stats->macrx_length_error_small =
1115 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1116 host_stats->macrx_multicast_frames =
1117 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1118 host_stats->macrx_broadcast_frames =
1119 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1120 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1121 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1122 host_stats->iptx_fragments =
1123 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1124 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1125 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1126 host_stats->iprx_fragments =
1127 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1128 host_stats->ip_datagram_reassembly =
1129 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1130 host_stats->ip_invalid_address_error =
1131 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1132 host_stats->ip_error_packets =
1133 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1134 host_stats->ip_fragrx_overlap =
1135 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1136 host_stats->ip_fragrx_outoforder =
1137 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1138 host_stats->ip_datagram_reassembly_timeout =
1139 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1140 host_stats->ipv6tx_packets =
1141 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1142 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1143 host_stats->ipv6tx_fragments =
1144 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1145 host_stats->ipv6rx_packets =
1146 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1147 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1148 host_stats->ipv6rx_fragments =
1149 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1150 host_stats->ipv6_datagram_reassembly =
1151 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1152 host_stats->ipv6_invalid_address_error =
1153 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1154 host_stats->ipv6_error_packets =
1155 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1156 host_stats->ipv6_fragrx_overlap =
1157 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1158 host_stats->ipv6_fragrx_outoforder =
1159 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1160 host_stats->ipv6_datagram_reassembly_timeout =
1161 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1162 host_stats->tcptx_segments =
1163 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1164 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1165 host_stats->tcprx_segments =
1166 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1167 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1168 host_stats->tcp_duplicate_ack_retx =
1169 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1170 host_stats->tcp_retx_timer_expired =
1171 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1172 host_stats->tcprx_duplicate_ack =
1173 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1174 host_stats->tcprx_pure_ackr =
1175 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1176 host_stats->tcptx_delayed_ack =
1177 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1178 host_stats->tcptx_pure_ack =
1179 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1180 host_stats->tcprx_segment_error =
1181 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1182 host_stats->tcprx_segment_outoforder =
1183 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1184 host_stats->tcprx_window_probe =
1185 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1186 host_stats->tcprx_window_update =
1187 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1188 host_stats->tcptx_window_probe_persist =
1189 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1190 host_stats->ecc_error_correction =
1191 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1192 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1193 host_stats->iscsi_data_bytes_tx =
1194 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1195 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1196 host_stats->iscsi_data_bytes_rx =
1197 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1198 host_stats->iscsi_io_completed =
1199 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1200 host_stats->iscsi_unexpected_io_rx =
1201 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1202 host_stats->iscsi_format_error =
1203 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1204 host_stats->iscsi_hdr_digest_error =
1205 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1206 host_stats->iscsi_data_digest_error =
1207 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1208 host_stats->iscsi_sequence_error =
1209 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1210exit_host_stats:
1211 if (ql_iscsi_stats)
1212 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1213 ql_iscsi_stats, iscsi_stats_dma);
1214
1215 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1216 __func__);
1217 return ret;
1218}
1219
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001220static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1221 enum iscsi_param_type param_type,
1222 int param, char *buf)
1223{
1224 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1225 struct scsi_qla_host *ha = to_qla_host(shost);
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001226 int ival;
1227 char *pval = NULL;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001228 int len = -ENOSYS;
1229
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001230 if (param_type == ISCSI_NET_PARAM) {
1231 switch (param) {
1232 case ISCSI_NET_PARAM_IPV4_ADDR:
1233 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1234 break;
1235 case ISCSI_NET_PARAM_IPV4_SUBNET:
1236 len = sprintf(buf, "%pI4\n",
1237 &ha->ip_config.subnet_mask);
1238 break;
1239 case ISCSI_NET_PARAM_IPV4_GW:
1240 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1241 break;
1242 case ISCSI_NET_PARAM_IFACE_ENABLE:
1243 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1244 OP_STATE(ha->ip_config.ipv4_options,
1245 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1246 } else {
1247 OP_STATE(ha->ip_config.ipv6_options,
1248 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1249 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001250
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001251 len = sprintf(buf, "%s\n", pval);
1252 break;
1253 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001254 len = sprintf(buf, "%s\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001255 (ha->ip_config.tcp_options &
1256 TCPOPT_DHCP_ENABLE) ?
1257 "dhcp" : "static");
1258 break;
1259 case ISCSI_NET_PARAM_IPV6_ADDR:
1260 if (iface->iface_num == 0)
1261 len = sprintf(buf, "%pI6\n",
1262 &ha->ip_config.ipv6_addr0);
1263 if (iface->iface_num == 1)
1264 len = sprintf(buf, "%pI6\n",
1265 &ha->ip_config.ipv6_addr1);
1266 break;
1267 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1268 len = sprintf(buf, "%pI6\n",
1269 &ha->ip_config.ipv6_link_local_addr);
1270 break;
1271 case ISCSI_NET_PARAM_IPV6_ROUTER:
1272 len = sprintf(buf, "%pI6\n",
1273 &ha->ip_config.ipv6_default_router_addr);
1274 break;
1275 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1276 pval = (ha->ip_config.ipv6_addl_options &
1277 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1278 "nd" : "static";
1279
1280 len = sprintf(buf, "%s\n", pval);
1281 break;
1282 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1283 pval = (ha->ip_config.ipv6_addl_options &
1284 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1285 "auto" : "static";
1286
1287 len = sprintf(buf, "%s\n", pval);
1288 break;
1289 case ISCSI_NET_PARAM_VLAN_ID:
1290 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1291 ival = ha->ip_config.ipv4_vlan_tag &
1292 ISCSI_MAX_VLAN_ID;
1293 else
1294 ival = ha->ip_config.ipv6_vlan_tag &
1295 ISCSI_MAX_VLAN_ID;
1296
1297 len = sprintf(buf, "%d\n", ival);
1298 break;
1299 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1300 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1301 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1302 ISCSI_MAX_VLAN_PRIORITY;
1303 else
1304 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1305 ISCSI_MAX_VLAN_PRIORITY;
1306
1307 len = sprintf(buf, "%d\n", ival);
1308 break;
1309 case ISCSI_NET_PARAM_VLAN_ENABLED:
1310 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1311 OP_STATE(ha->ip_config.ipv4_options,
1312 IPOPT_VLAN_TAGGING_ENABLE, pval);
1313 } else {
1314 OP_STATE(ha->ip_config.ipv6_options,
1315 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1316 }
1317 len = sprintf(buf, "%s\n", pval);
1318 break;
1319 case ISCSI_NET_PARAM_MTU:
1320 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1321 break;
1322 case ISCSI_NET_PARAM_PORT:
1323 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1324 len = sprintf(buf, "%d\n",
1325 ha->ip_config.ipv4_port);
1326 else
1327 len = sprintf(buf, "%d\n",
1328 ha->ip_config.ipv6_port);
1329 break;
1330 case ISCSI_NET_PARAM_IPADDR_STATE:
1331 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1332 pval = iscsi_get_ipaddress_state_name(
1333 ha->ip_config.ipv4_addr_state);
1334 } else {
1335 if (iface->iface_num == 0)
1336 pval = iscsi_get_ipaddress_state_name(
1337 ha->ip_config.ipv6_addr0_state);
1338 else if (iface->iface_num == 1)
1339 pval = iscsi_get_ipaddress_state_name(
1340 ha->ip_config.ipv6_addr1_state);
1341 }
1342
1343 len = sprintf(buf, "%s\n", pval);
1344 break;
1345 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1346 pval = iscsi_get_ipaddress_state_name(
1347 ha->ip_config.ipv6_link_local_state);
1348 len = sprintf(buf, "%s\n", pval);
1349 break;
1350 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1351 pval = iscsi_get_router_state_name(
1352 ha->ip_config.ipv6_default_router_state);
1353 len = sprintf(buf, "%s\n", pval);
1354 break;
1355 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1356 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1357 OP_STATE(~ha->ip_config.tcp_options,
1358 TCPOPT_DELAYED_ACK_DISABLE, pval);
1359 } else {
1360 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1361 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1362 }
1363 len = sprintf(buf, "%s\n", pval);
1364 break;
1365 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1366 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1367 OP_STATE(~ha->ip_config.tcp_options,
1368 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1369 } else {
1370 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1371 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1372 }
1373 len = sprintf(buf, "%s\n", pval);
1374 break;
1375 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1376 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1377 OP_STATE(~ha->ip_config.tcp_options,
1378 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1379 } else {
1380 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1381 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1382 pval);
1383 }
1384 len = sprintf(buf, "%s\n", pval);
1385 break;
1386 case ISCSI_NET_PARAM_TCP_WSF:
1387 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1388 len = sprintf(buf, "%d\n",
1389 ha->ip_config.tcp_wsf);
1390 else
1391 len = sprintf(buf, "%d\n",
1392 ha->ip_config.ipv6_tcp_wsf);
1393 break;
1394 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1395 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1396 ival = (ha->ip_config.tcp_options &
1397 TCPOPT_TIMER_SCALE) >> 1;
1398 else
1399 ival = (ha->ip_config.ipv6_tcp_options &
1400 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1401
1402 len = sprintf(buf, "%d\n", ival);
1403 break;
1404 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1405 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1406 OP_STATE(ha->ip_config.tcp_options,
1407 TCPOPT_TIMESTAMP_ENABLE, pval);
1408 } else {
1409 OP_STATE(ha->ip_config.ipv6_tcp_options,
1410 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1411 }
1412 len = sprintf(buf, "%s\n", pval);
1413 break;
1414 case ISCSI_NET_PARAM_CACHE_ID:
1415 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1416 len = sprintf(buf, "%d\n",
1417 ha->ip_config.ipv4_cache_id);
1418 else
1419 len = sprintf(buf, "%d\n",
1420 ha->ip_config.ipv6_cache_id);
1421 break;
1422 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1423 OP_STATE(ha->ip_config.tcp_options,
1424 TCPOPT_DNS_SERVER_IP_EN, pval);
1425
1426 len = sprintf(buf, "%s\n", pval);
1427 break;
1428 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1429 OP_STATE(ha->ip_config.tcp_options,
1430 TCPOPT_SLP_DA_INFO_EN, pval);
1431
1432 len = sprintf(buf, "%s\n", pval);
1433 break;
1434 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1435 OP_STATE(ha->ip_config.ipv4_options,
1436 IPOPT_IPV4_TOS_EN, pval);
1437
1438 len = sprintf(buf, "%s\n", pval);
1439 break;
1440 case ISCSI_NET_PARAM_IPV4_TOS:
1441 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1442 break;
1443 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1444 OP_STATE(ha->ip_config.ipv4_options,
1445 IPOPT_GRAT_ARP_EN, pval);
1446
1447 len = sprintf(buf, "%s\n", pval);
1448 break;
1449 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1450 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1451 pval);
1452
1453 len = sprintf(buf, "%s\n", pval);
1454 break;
1455 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1456 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1457 (char *)ha->ip_config.ipv4_alt_cid : "";
1458
1459 len = sprintf(buf, "%s\n", pval);
1460 break;
1461 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1462 OP_STATE(ha->ip_config.ipv4_options,
1463 IPOPT_REQ_VID_EN, pval);
1464
1465 len = sprintf(buf, "%s\n", pval);
1466 break;
1467 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1468 OP_STATE(ha->ip_config.ipv4_options,
1469 IPOPT_USE_VID_EN, pval);
1470
1471 len = sprintf(buf, "%s\n", pval);
1472 break;
1473 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1474 pval = (ha->ip_config.ipv4_vid_len) ?
1475 (char *)ha->ip_config.ipv4_vid : "";
1476
1477 len = sprintf(buf, "%s\n", pval);
1478 break;
1479 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1480 OP_STATE(ha->ip_config.ipv4_options,
1481 IPOPT_LEARN_IQN_EN, pval);
1482
1483 len = sprintf(buf, "%s\n", pval);
1484 break;
1485 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1486 OP_STATE(~ha->ip_config.ipv4_options,
1487 IPOPT_FRAGMENTATION_DISABLE, pval);
1488
1489 len = sprintf(buf, "%s\n", pval);
1490 break;
1491 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1492 OP_STATE(ha->ip_config.ipv4_options,
1493 IPOPT_IN_FORWARD_EN, pval);
1494
1495 len = sprintf(buf, "%s\n", pval);
1496 break;
1497 case ISCSI_NET_PARAM_REDIRECT_EN:
1498 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1499 OP_STATE(ha->ip_config.ipv4_options,
1500 IPOPT_ARP_REDIRECT_EN, pval);
1501 } else {
1502 OP_STATE(ha->ip_config.ipv6_options,
1503 IPV6_OPT_REDIRECT_EN, pval);
1504 }
1505 len = sprintf(buf, "%s\n", pval);
1506 break;
1507 case ISCSI_NET_PARAM_IPV4_TTL:
1508 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1509 break;
1510 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1511 OP_STATE(ha->ip_config.ipv6_options,
1512 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1513
1514 len = sprintf(buf, "%s\n", pval);
1515 break;
1516 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1517 OP_STATE(ha->ip_config.ipv6_addl_options,
1518 IPV6_ADDOPT_MLD_EN, pval);
1519
1520 len = sprintf(buf, "%s\n", pval);
1521 break;
1522 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1523 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1524 break;
1525 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001526 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001527 ha->ip_config.ipv6_traffic_class);
1528 break;
1529 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001530 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001531 ha->ip_config.ipv6_hop_limit);
1532 break;
1533 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001534 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001535 ha->ip_config.ipv6_nd_reach_time);
1536 break;
1537 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001538 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001539 ha->ip_config.ipv6_nd_rexmit_timer);
1540 break;
1541 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1542 len = sprintf(buf, "%d\n",
1543 ha->ip_config.ipv6_nd_stale_timeout);
1544 break;
1545 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1546 len = sprintf(buf, "%d\n",
1547 ha->ip_config.ipv6_dup_addr_detect_count);
1548 break;
1549 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1550 len = sprintf(buf, "%d\n",
1551 ha->ip_config.ipv6_gw_advrt_mtu);
1552 break;
1553 default:
1554 len = -ENOSYS;
1555 }
1556 } else if (param_type == ISCSI_IFACE_PARAM) {
1557 switch (param) {
1558 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1559 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1560 break;
1561 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1562 OP_STATE(ha->ip_config.iscsi_options,
1563 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1564
1565 len = sprintf(buf, "%s\n", pval);
1566 break;
1567 case ISCSI_IFACE_PARAM_DATADGST_EN:
1568 OP_STATE(ha->ip_config.iscsi_options,
1569 ISCSIOPTS_DATA_DIGEST_EN, pval);
1570
1571 len = sprintf(buf, "%s\n", pval);
1572 break;
1573 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1574 OP_STATE(ha->ip_config.iscsi_options,
1575 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1576
1577 len = sprintf(buf, "%s\n", pval);
1578 break;
1579 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1580 OP_STATE(ha->ip_config.iscsi_options,
1581 ISCSIOPTS_INITIAL_R2T_EN, pval);
1582
1583 len = sprintf(buf, "%s\n", pval);
1584 break;
1585 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1586 OP_STATE(ha->ip_config.iscsi_options,
1587 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1588
1589 len = sprintf(buf, "%s\n", pval);
1590 break;
1591 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1592 OP_STATE(ha->ip_config.iscsi_options,
1593 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1594
1595 len = sprintf(buf, "%s\n", pval);
1596 break;
1597 case ISCSI_IFACE_PARAM_ERL:
1598 len = sprintf(buf, "%d\n",
1599 (ha->ip_config.iscsi_options &
1600 ISCSIOPTS_ERL));
1601 break;
1602 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1603 len = sprintf(buf, "%u\n",
1604 ha->ip_config.iscsi_max_pdu_size *
1605 BYTE_UNITS);
1606 break;
1607 case ISCSI_IFACE_PARAM_FIRST_BURST:
1608 len = sprintf(buf, "%u\n",
1609 ha->ip_config.iscsi_first_burst_len *
1610 BYTE_UNITS);
1611 break;
1612 case ISCSI_IFACE_PARAM_MAX_R2T:
1613 len = sprintf(buf, "%d\n",
1614 ha->ip_config.iscsi_max_outstnd_r2t);
1615 break;
1616 case ISCSI_IFACE_PARAM_MAX_BURST:
1617 len = sprintf(buf, "%u\n",
1618 ha->ip_config.iscsi_max_burst_len *
1619 BYTE_UNITS);
1620 break;
1621 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1622 OP_STATE(ha->ip_config.iscsi_options,
1623 ISCSIOPTS_CHAP_AUTH_EN, pval);
1624
1625 len = sprintf(buf, "%s\n", pval);
1626 break;
1627 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1628 OP_STATE(ha->ip_config.iscsi_options,
1629 ISCSIOPTS_BIDI_CHAP_EN, pval);
1630
1631 len = sprintf(buf, "%s\n", pval);
1632 break;
1633 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1634 OP_STATE(ha->ip_config.iscsi_options,
1635 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1636
1637 len = sprintf(buf, "%s\n", pval);
1638 break;
1639 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1640 OP_STATE(ha->ip_config.iscsi_options,
1641 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1642
1643 len = sprintf(buf, "%s\n", pval);
1644 break;
1645 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1646 OP_STATE(ha->ip_config.iscsi_options,
1647 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1648
1649 len = sprintf(buf, "%s\n", pval);
1650 break;
1651 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1652 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1653 break;
1654 default:
1655 len = -ENOSYS;
1656 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001657 }
1658
1659 return len;
1660}
1661
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001662static struct iscsi_endpoint *
1663qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1664 int non_blocking)
1665{
1666 int ret;
1667 struct iscsi_endpoint *ep;
1668 struct qla_endpoint *qla_ep;
1669 struct scsi_qla_host *ha;
1670 struct sockaddr_in *addr;
1671 struct sockaddr_in6 *addr6;
1672
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001673 if (!shost) {
1674 ret = -ENXIO;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001675 pr_err("%s: shost is NULL\n", __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001676 return ERR_PTR(ret);
1677 }
1678
1679 ha = iscsi_host_priv(shost);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001680 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1681 if (!ep) {
1682 ret = -ENOMEM;
1683 return ERR_PTR(ret);
1684 }
1685
1686 qla_ep = ep->dd_data;
1687 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1688 if (dst_addr->sa_family == AF_INET) {
1689 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1690 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1691 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1692 (char *)&addr->sin_addr));
1693 } else if (dst_addr->sa_family == AF_INET6) {
1694 memcpy(&qla_ep->dst_addr, dst_addr,
1695 sizeof(struct sockaddr_in6));
1696 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1697 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1698 (char *)&addr6->sin6_addr));
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001699 } else {
1700 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1701 __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001702 }
1703
1704 qla_ep->host = shost;
1705
1706 return ep;
1707}
1708
1709static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1710{
1711 struct qla_endpoint *qla_ep;
1712 struct scsi_qla_host *ha;
1713 int ret = 0;
1714
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001715 qla_ep = ep->dd_data;
1716 ha = to_qla_host(qla_ep->host);
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001717 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001718
Mike Christie13483732011-12-01 21:38:41 -06001719 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001720 ret = 1;
1721
1722 return ret;
1723}
1724
1725static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1726{
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001727 struct qla_endpoint *qla_ep;
1728 struct scsi_qla_host *ha;
1729
1730 qla_ep = ep->dd_data;
1731 ha = to_qla_host(qla_ep->host);
1732 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1733 ha->host_no));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001734 iscsi_destroy_endpoint(ep);
1735}
1736
1737static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1738 enum iscsi_param param,
1739 char *buf)
1740{
1741 struct qla_endpoint *qla_ep = ep->dd_data;
1742 struct sockaddr *dst_addr;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001743 struct scsi_qla_host *ha;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001744
Adheer Chandravanshi73597bd2014-04-09 21:12:27 -04001745 if (!qla_ep)
1746 return -ENOTCONN;
1747
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001748 ha = to_qla_host(qla_ep->host);
1749 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1750 ha->host_no));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001751
1752 switch (param) {
1753 case ISCSI_PARAM_CONN_PORT:
1754 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001755 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1756 if (!dst_addr)
1757 return -ENOTCONN;
1758
1759 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1760 &qla_ep->dst_addr, param, buf);
1761 default:
1762 return -ENOSYS;
1763 }
1764}
1765
1766static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1767 struct iscsi_stats *stats)
1768{
1769 struct iscsi_session *sess;
1770 struct iscsi_cls_session *cls_sess;
1771 struct ddb_entry *ddb_entry;
1772 struct scsi_qla_host *ha;
1773 struct ql_iscsi_stats *ql_iscsi_stats;
1774 int stats_size;
1775 int ret;
1776 dma_addr_t iscsi_stats_dma;
1777
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001778 cls_sess = iscsi_conn_to_session(cls_conn);
1779 sess = cls_sess->dd_data;
1780 ddb_entry = sess->dd_data;
1781 ha = ddb_entry->ha;
1782
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05001783 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1784 ha->host_no));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001785 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1786 /* Allocate memory */
1787 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1788 &iscsi_stats_dma, GFP_KERNEL);
1789 if (!ql_iscsi_stats) {
1790 ql4_printk(KERN_ERR, ha,
1791 "Unable to allocate memory for iscsi stats\n");
1792 goto exit_get_stats;
1793 }
1794
1795 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1796 iscsi_stats_dma);
1797 if (ret != QLA_SUCCESS) {
1798 ql4_printk(KERN_ERR, ha,
Masanari Iida59e13d42012-04-25 00:24:16 +09001799 "Unable to retrieve iscsi stats\n");
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001800 goto free_stats;
1801 }
1802
1803 /* octets */
1804 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1805 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1806 /* xmit pdus */
1807 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1808 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1809 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1810 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1811 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1812 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1813 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1814 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1815 /* recv pdus */
1816 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1817 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1818 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1819 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1820 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1821 stats->logoutrsp_pdus =
1822 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1823 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1824 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1825 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1826
1827free_stats:
1828 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1829 iscsi_stats_dma);
1830exit_get_stats:
1831 return;
1832}
1833
Mike Christie5c656af2009-07-15 15:02:59 -05001834static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1835{
1836 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001837 struct iscsi_session *sess;
1838 unsigned long flags;
1839 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -05001840
1841 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001842 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -05001843
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001844 spin_lock_irqsave(&session->lock, flags);
1845 if (session->state == ISCSI_SESSION_FAILED)
1846 ret = BLK_EH_RESET_TIMER;
1847 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -05001848
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001849 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001850}
1851
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001852static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1853{
1854 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001855 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001856 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1857
1858 qla4xxx_get_firmware_state(ha);
1859
1860 switch (ha->addl_fw_state & 0x0F00) {
1861 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1862 speed = ISCSI_PORT_SPEED_10MBPS;
1863 break;
1864 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1865 speed = ISCSI_PORT_SPEED_100MBPS;
1866 break;
1867 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1868 speed = ISCSI_PORT_SPEED_1GBPS;
1869 break;
1870 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1871 speed = ISCSI_PORT_SPEED_10GBPS;
1872 break;
1873 }
1874 ihost->port_speed = speed;
1875}
1876
1877static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1878{
1879 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001880 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001881 uint32_t state = ISCSI_PORT_STATE_DOWN;
1882
1883 if (test_bit(AF_LINK_UP, &ha->flags))
1884 state = ISCSI_PORT_STATE_UP;
1885
1886 ihost->port_state = state;
1887}
1888
Mike Christieaa1e93a2007-05-30 12:57:09 -05001889static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1890 enum iscsi_host_param param, char *buf)
1891{
1892 struct scsi_qla_host *ha = to_qla_host(shost);
1893 int len;
1894
1895 switch (param) {
1896 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -08001897 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -05001898 break;
Mike Christie22236962007-05-30 12:57:24 -05001899 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05001900 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -05001901 break;
Mike Christie8ad57812007-05-30 12:57:13 -05001902 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -05001903 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -05001904 break;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001905 case ISCSI_HOST_PARAM_PORT_STATE:
1906 qla4xxx_set_port_state(shost);
1907 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1908 break;
1909 case ISCSI_HOST_PARAM_PORT_SPEED:
1910 qla4xxx_set_port_speed(shost);
1911 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1912 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -05001913 default:
1914 return -ENOSYS;
1915 }
1916
1917 return len;
1918}
1919
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001920static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1921{
1922 if (ha->iface_ipv4)
1923 return;
1924
1925 /* IPv4 */
1926 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1927 &qla4xxx_iscsi_transport,
1928 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1929 if (!ha->iface_ipv4)
1930 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1931 "iface0.\n");
1932}
1933
1934static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1935{
1936 if (!ha->iface_ipv6_0)
1937 /* IPv6 iface-0 */
1938 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1939 &qla4xxx_iscsi_transport,
1940 ISCSI_IFACE_TYPE_IPV6, 0,
1941 0);
1942 if (!ha->iface_ipv6_0)
1943 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1944 "iface0.\n");
1945
1946 if (!ha->iface_ipv6_1)
1947 /* IPv6 iface-1 */
1948 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1949 &qla4xxx_iscsi_transport,
1950 ISCSI_IFACE_TYPE_IPV6, 1,
1951 0);
1952 if (!ha->iface_ipv6_1)
1953 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1954 "iface1.\n");
1955}
1956
1957static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1958{
1959 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1960 qla4xxx_create_ipv4_iface(ha);
1961
1962 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1963 qla4xxx_create_ipv6_iface(ha);
1964}
1965
1966static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1967{
1968 if (ha->iface_ipv4) {
1969 iscsi_destroy_iface(ha->iface_ipv4);
1970 ha->iface_ipv4 = NULL;
1971 }
1972}
1973
1974static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1975{
1976 if (ha->iface_ipv6_0) {
1977 iscsi_destroy_iface(ha->iface_ipv6_0);
1978 ha->iface_ipv6_0 = NULL;
1979 }
1980 if (ha->iface_ipv6_1) {
1981 iscsi_destroy_iface(ha->iface_ipv6_1);
1982 ha->iface_ipv6_1 = NULL;
1983 }
1984}
1985
1986static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1987{
1988 qla4xxx_destroy_ipv4_iface(ha);
1989 qla4xxx_destroy_ipv6_iface(ha);
1990}
1991
Mike Christied00efe32011-07-25 13:48:38 -05001992static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1993 struct iscsi_iface_param_info *iface_param,
1994 struct addr_ctrl_blk *init_fw_cb)
1995{
1996 /*
1997 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1998 * iface_num 1 is valid only for IPv6 Addr.
1999 */
2000 switch (iface_param->param) {
2001 case ISCSI_NET_PARAM_IPV6_ADDR:
2002 if (iface_param->iface_num & 0x1)
2003 /* IPv6 Addr 1 */
2004 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2005 sizeof(init_fw_cb->ipv6_addr1));
2006 else
2007 /* IPv6 Addr 0 */
2008 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2009 sizeof(init_fw_cb->ipv6_addr0));
2010 break;
2011 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2012 if (iface_param->iface_num & 0x1)
2013 break;
2014 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2015 sizeof(init_fw_cb->ipv6_if_id));
2016 break;
2017 case ISCSI_NET_PARAM_IPV6_ROUTER:
2018 if (iface_param->iface_num & 0x1)
2019 break;
2020 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2021 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2022 break;
2023 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2024 /* Autocfg applies to even interface */
2025 if (iface_param->iface_num & 0x1)
2026 break;
2027
2028 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2029 init_fw_cb->ipv6_addtl_opts &=
2030 cpu_to_le16(
2031 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2032 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2033 init_fw_cb->ipv6_addtl_opts |=
2034 cpu_to_le16(
2035 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2036 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002037 ql4_printk(KERN_ERR, ha,
2038 "Invalid autocfg setting for IPv6 addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05002039 break;
2040 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2041 /* Autocfg applies to even interface */
2042 if (iface_param->iface_num & 0x1)
2043 break;
2044
2045 if (iface_param->value[0] ==
2046 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2047 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2048 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2049 else if (iface_param->value[0] ==
2050 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2051 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2052 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2053 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002054 ql4_printk(KERN_ERR, ha,
2055 "Invalid autocfg setting for IPv6 linklocal addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05002056 break;
2057 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2058 /* Autocfg applies to even interface */
2059 if (iface_param->iface_num & 0x1)
2060 break;
2061
2062 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2063 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2064 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2065 break;
2066 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002067 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05002068 init_fw_cb->ipv6_opts |=
2069 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002070 qla4xxx_create_ipv6_iface(ha);
2071 } else {
Mike Christied00efe32011-07-25 13:48:38 -05002072 init_fw_cb->ipv6_opts &=
2073 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2074 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002075 qla4xxx_destroy_ipv6_iface(ha);
2076 }
Mike Christied00efe32011-07-25 13:48:38 -05002077 break;
Mike Christie2d636732011-10-11 17:55:11 -05002078 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002079 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2080 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002081 init_fw_cb->ipv6_vlan_tag =
2082 cpu_to_be16(*(uint16_t *)iface_param->value);
2083 break;
2084 case ISCSI_NET_PARAM_VLAN_ENABLED:
2085 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2086 init_fw_cb->ipv6_opts |=
2087 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2088 else
2089 init_fw_cb->ipv6_opts &=
2090 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002091 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002092 case ISCSI_NET_PARAM_MTU:
2093 init_fw_cb->eth_mtu_size =
2094 cpu_to_le16(*(uint16_t *)iface_param->value);
2095 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002096 case ISCSI_NET_PARAM_PORT:
2097 /* Autocfg applies to even interface */
2098 if (iface_param->iface_num & 0x1)
2099 break;
2100
2101 init_fw_cb->ipv6_port =
2102 cpu_to_le16(*(uint16_t *)iface_param->value);
2103 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002104 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2105 if (iface_param->iface_num & 0x1)
2106 break;
2107 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2108 init_fw_cb->ipv6_tcp_opts |=
2109 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2110 else
2111 init_fw_cb->ipv6_tcp_opts &=
Vikas Chaudhary8f108722013-12-16 06:49:53 -05002112 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2113 0xFFFF);
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002114 break;
2115 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2116 if (iface_param->iface_num & 0x1)
2117 break;
2118 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2119 init_fw_cb->ipv6_tcp_opts |=
2120 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2121 else
2122 init_fw_cb->ipv6_tcp_opts &=
2123 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2124 break;
2125 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2126 if (iface_param->iface_num & 0x1)
2127 break;
2128 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2129 init_fw_cb->ipv6_tcp_opts |=
2130 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2131 else
2132 init_fw_cb->ipv6_tcp_opts &=
2133 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2134 break;
2135 case ISCSI_NET_PARAM_TCP_WSF:
2136 if (iface_param->iface_num & 0x1)
2137 break;
2138 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2139 break;
2140 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2141 if (iface_param->iface_num & 0x1)
2142 break;
2143 init_fw_cb->ipv6_tcp_opts &=
2144 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2145 init_fw_cb->ipv6_tcp_opts |=
2146 cpu_to_le16((iface_param->value[0] << 1) &
2147 IPV6_TCPOPT_TIMER_SCALE);
2148 break;
2149 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2150 if (iface_param->iface_num & 0x1)
2151 break;
2152 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2153 init_fw_cb->ipv6_tcp_opts |=
2154 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2155 else
2156 init_fw_cb->ipv6_tcp_opts &=
2157 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2158 break;
2159 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2160 if (iface_param->iface_num & 0x1)
2161 break;
2162 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2163 init_fw_cb->ipv6_opts |=
2164 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2165 else
2166 init_fw_cb->ipv6_opts &=
2167 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2168 break;
2169 case ISCSI_NET_PARAM_REDIRECT_EN:
2170 if (iface_param->iface_num & 0x1)
2171 break;
2172 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2173 init_fw_cb->ipv6_opts |=
2174 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2175 else
2176 init_fw_cb->ipv6_opts &=
2177 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2178 break;
2179 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2180 if (iface_param->iface_num & 0x1)
2181 break;
2182 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2183 init_fw_cb->ipv6_addtl_opts |=
2184 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2185 else
2186 init_fw_cb->ipv6_addtl_opts &=
2187 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2188 break;
2189 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2190 if (iface_param->iface_num & 0x1)
2191 break;
2192 init_fw_cb->ipv6_flow_lbl =
2193 cpu_to_le16(*(uint16_t *)iface_param->value);
2194 break;
2195 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2196 if (iface_param->iface_num & 0x1)
2197 break;
2198 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2199 break;
2200 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2201 if (iface_param->iface_num & 0x1)
2202 break;
2203 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2204 break;
2205 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2206 if (iface_param->iface_num & 0x1)
2207 break;
2208 init_fw_cb->ipv6_nd_reach_time =
2209 cpu_to_le32(*(uint32_t *)iface_param->value);
2210 break;
2211 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2212 if (iface_param->iface_num & 0x1)
2213 break;
2214 init_fw_cb->ipv6_nd_rexmit_timer =
2215 cpu_to_le32(*(uint32_t *)iface_param->value);
2216 break;
2217 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2218 if (iface_param->iface_num & 0x1)
2219 break;
2220 init_fw_cb->ipv6_nd_stale_timeout =
2221 cpu_to_le32(*(uint32_t *)iface_param->value);
2222 break;
2223 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2224 if (iface_param->iface_num & 0x1)
2225 break;
2226 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2227 break;
2228 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2229 if (iface_param->iface_num & 0x1)
2230 break;
2231 init_fw_cb->ipv6_gw_advrt_mtu =
2232 cpu_to_le32(*(uint32_t *)iface_param->value);
2233 break;
Mike Christied00efe32011-07-25 13:48:38 -05002234 default:
2235 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2236 iface_param->param);
2237 break;
2238 }
2239}
2240
2241static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2242 struct iscsi_iface_param_info *iface_param,
2243 struct addr_ctrl_blk *init_fw_cb)
2244{
2245 switch (iface_param->param) {
2246 case ISCSI_NET_PARAM_IPV4_ADDR:
2247 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2248 sizeof(init_fw_cb->ipv4_addr));
2249 break;
2250 case ISCSI_NET_PARAM_IPV4_SUBNET:
2251 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2252 sizeof(init_fw_cb->ipv4_subnet));
2253 break;
2254 case ISCSI_NET_PARAM_IPV4_GW:
2255 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2256 sizeof(init_fw_cb->ipv4_gw_addr));
2257 break;
2258 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2259 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2260 init_fw_cb->ipv4_tcp_opts |=
2261 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2262 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2263 init_fw_cb->ipv4_tcp_opts &=
2264 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2265 else
2266 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2267 break;
2268 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002269 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05002270 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05002271 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002272 qla4xxx_create_ipv4_iface(ha);
2273 } else {
Mike Christied00efe32011-07-25 13:48:38 -05002274 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05002275 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -05002276 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002277 qla4xxx_destroy_ipv4_iface(ha);
2278 }
Mike Christied00efe32011-07-25 13:48:38 -05002279 break;
Mike Christie2d636732011-10-11 17:55:11 -05002280 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002281 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2282 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002283 init_fw_cb->ipv4_vlan_tag =
2284 cpu_to_be16(*(uint16_t *)iface_param->value);
2285 break;
2286 case ISCSI_NET_PARAM_VLAN_ENABLED:
2287 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2288 init_fw_cb->ipv4_ip_opts |=
2289 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2290 else
2291 init_fw_cb->ipv4_ip_opts &=
2292 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002293 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002294 case ISCSI_NET_PARAM_MTU:
2295 init_fw_cb->eth_mtu_size =
2296 cpu_to_le16(*(uint16_t *)iface_param->value);
2297 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002298 case ISCSI_NET_PARAM_PORT:
2299 init_fw_cb->ipv4_port =
2300 cpu_to_le16(*(uint16_t *)iface_param->value);
2301 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002302 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2303 if (iface_param->iface_num & 0x1)
2304 break;
2305 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2306 init_fw_cb->ipv4_tcp_opts |=
2307 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2308 else
2309 init_fw_cb->ipv4_tcp_opts &=
Vikas Chaudhary8f108722013-12-16 06:49:53 -05002310 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2311 0xFFFF);
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002312 break;
2313 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2314 if (iface_param->iface_num & 0x1)
2315 break;
2316 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2317 init_fw_cb->ipv4_tcp_opts |=
2318 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2319 else
2320 init_fw_cb->ipv4_tcp_opts &=
2321 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2322 break;
2323 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2324 if (iface_param->iface_num & 0x1)
2325 break;
2326 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2327 init_fw_cb->ipv4_tcp_opts |=
2328 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2329 else
2330 init_fw_cb->ipv4_tcp_opts &=
2331 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2332 break;
2333 case ISCSI_NET_PARAM_TCP_WSF:
2334 if (iface_param->iface_num & 0x1)
2335 break;
2336 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2337 break;
2338 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2339 if (iface_param->iface_num & 0x1)
2340 break;
2341 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2342 init_fw_cb->ipv4_tcp_opts |=
2343 cpu_to_le16((iface_param->value[0] << 1) &
2344 TCPOPT_TIMER_SCALE);
2345 break;
2346 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2347 if (iface_param->iface_num & 0x1)
2348 break;
2349 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2350 init_fw_cb->ipv4_tcp_opts |=
2351 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2352 else
2353 init_fw_cb->ipv4_tcp_opts &=
2354 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2355 break;
2356 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2357 if (iface_param->iface_num & 0x1)
2358 break;
2359 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2360 init_fw_cb->ipv4_tcp_opts |=
2361 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2362 else
2363 init_fw_cb->ipv4_tcp_opts &=
2364 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2365 break;
2366 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2367 if (iface_param->iface_num & 0x1)
2368 break;
2369 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2370 init_fw_cb->ipv4_tcp_opts |=
2371 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2372 else
2373 init_fw_cb->ipv4_tcp_opts &=
2374 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2375 break;
2376 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2377 if (iface_param->iface_num & 0x1)
2378 break;
2379 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2380 init_fw_cb->ipv4_ip_opts |=
2381 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2382 else
2383 init_fw_cb->ipv4_ip_opts &=
2384 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2385 break;
2386 case ISCSI_NET_PARAM_IPV4_TOS:
2387 if (iface_param->iface_num & 0x1)
2388 break;
2389 init_fw_cb->ipv4_tos = iface_param->value[0];
2390 break;
2391 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2392 if (iface_param->iface_num & 0x1)
2393 break;
2394 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2395 init_fw_cb->ipv4_ip_opts |=
2396 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2397 else
2398 init_fw_cb->ipv4_ip_opts &=
2399 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2400 break;
2401 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2402 if (iface_param->iface_num & 0x1)
2403 break;
2404 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2405 init_fw_cb->ipv4_ip_opts |=
2406 cpu_to_le16(IPOPT_ALT_CID_EN);
2407 else
2408 init_fw_cb->ipv4_ip_opts &=
2409 cpu_to_le16(~IPOPT_ALT_CID_EN);
2410 break;
2411 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2412 if (iface_param->iface_num & 0x1)
2413 break;
2414 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2415 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2416 init_fw_cb->ipv4_dhcp_alt_cid_len =
2417 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2418 break;
2419 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2420 if (iface_param->iface_num & 0x1)
2421 break;
2422 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2423 init_fw_cb->ipv4_ip_opts |=
2424 cpu_to_le16(IPOPT_REQ_VID_EN);
2425 else
2426 init_fw_cb->ipv4_ip_opts &=
2427 cpu_to_le16(~IPOPT_REQ_VID_EN);
2428 break;
2429 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2430 if (iface_param->iface_num & 0x1)
2431 break;
2432 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2433 init_fw_cb->ipv4_ip_opts |=
2434 cpu_to_le16(IPOPT_USE_VID_EN);
2435 else
2436 init_fw_cb->ipv4_ip_opts &=
2437 cpu_to_le16(~IPOPT_USE_VID_EN);
2438 break;
2439 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2440 if (iface_param->iface_num & 0x1)
2441 break;
2442 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2443 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2444 init_fw_cb->ipv4_dhcp_vid_len =
2445 strlen(init_fw_cb->ipv4_dhcp_vid);
2446 break;
2447 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2448 if (iface_param->iface_num & 0x1)
2449 break;
2450 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2451 init_fw_cb->ipv4_ip_opts |=
2452 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2453 else
2454 init_fw_cb->ipv4_ip_opts &=
2455 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2456 break;
2457 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2458 if (iface_param->iface_num & 0x1)
2459 break;
2460 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2461 init_fw_cb->ipv4_ip_opts |=
2462 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2463 else
2464 init_fw_cb->ipv4_ip_opts &=
2465 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2466 break;
2467 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2468 if (iface_param->iface_num & 0x1)
2469 break;
2470 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2471 init_fw_cb->ipv4_ip_opts |=
2472 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2473 else
2474 init_fw_cb->ipv4_ip_opts &=
2475 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2476 break;
2477 case ISCSI_NET_PARAM_REDIRECT_EN:
2478 if (iface_param->iface_num & 0x1)
2479 break;
2480 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2481 init_fw_cb->ipv4_ip_opts |=
2482 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2483 else
2484 init_fw_cb->ipv4_ip_opts &=
2485 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2486 break;
2487 case ISCSI_NET_PARAM_IPV4_TTL:
2488 if (iface_param->iface_num & 0x1)
2489 break;
2490 init_fw_cb->ipv4_ttl = iface_param->value[0];
2491 break;
Mike Christied00efe32011-07-25 13:48:38 -05002492 default:
2493 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2494 iface_param->param);
2495 break;
2496 }
2497}
2498
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002499static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2500 struct iscsi_iface_param_info *iface_param,
2501 struct addr_ctrl_blk *init_fw_cb)
2502{
2503 switch (iface_param->param) {
2504 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2505 if (iface_param->iface_num & 0x1)
2506 break;
2507 init_fw_cb->def_timeout =
2508 cpu_to_le16(*(uint16_t *)iface_param->value);
2509 break;
2510 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2511 if (iface_param->iface_num & 0x1)
2512 break;
2513 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2514 init_fw_cb->iscsi_opts |=
2515 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2516 else
2517 init_fw_cb->iscsi_opts &=
2518 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2519 break;
2520 case ISCSI_IFACE_PARAM_DATADGST_EN:
2521 if (iface_param->iface_num & 0x1)
2522 break;
2523 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2524 init_fw_cb->iscsi_opts |=
2525 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2526 else
2527 init_fw_cb->iscsi_opts &=
2528 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2529 break;
2530 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2531 if (iface_param->iface_num & 0x1)
2532 break;
2533 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2534 init_fw_cb->iscsi_opts |=
2535 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2536 else
2537 init_fw_cb->iscsi_opts &=
2538 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2539 break;
2540 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2541 if (iface_param->iface_num & 0x1)
2542 break;
2543 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2544 init_fw_cb->iscsi_opts |=
2545 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2546 else
2547 init_fw_cb->iscsi_opts &=
2548 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2549 break;
2550 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2551 if (iface_param->iface_num & 0x1)
2552 break;
2553 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2554 init_fw_cb->iscsi_opts |=
2555 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2556 else
2557 init_fw_cb->iscsi_opts &=
2558 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2559 break;
2560 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2561 if (iface_param->iface_num & 0x1)
2562 break;
2563 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2564 init_fw_cb->iscsi_opts |=
2565 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2566 else
2567 init_fw_cb->iscsi_opts &=
2568 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2569 break;
2570 case ISCSI_IFACE_PARAM_ERL:
2571 if (iface_param->iface_num & 0x1)
2572 break;
2573 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2574 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2575 ISCSIOPTS_ERL);
2576 break;
2577 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2578 if (iface_param->iface_num & 0x1)
2579 break;
2580 init_fw_cb->iscsi_max_pdu_size =
2581 cpu_to_le32(*(uint32_t *)iface_param->value) /
2582 BYTE_UNITS;
2583 break;
2584 case ISCSI_IFACE_PARAM_FIRST_BURST:
2585 if (iface_param->iface_num & 0x1)
2586 break;
2587 init_fw_cb->iscsi_fburst_len =
2588 cpu_to_le32(*(uint32_t *)iface_param->value) /
2589 BYTE_UNITS;
2590 break;
2591 case ISCSI_IFACE_PARAM_MAX_R2T:
2592 if (iface_param->iface_num & 0x1)
2593 break;
2594 init_fw_cb->iscsi_max_outstnd_r2t =
2595 cpu_to_le16(*(uint16_t *)iface_param->value);
2596 break;
2597 case ISCSI_IFACE_PARAM_MAX_BURST:
2598 if (iface_param->iface_num & 0x1)
2599 break;
2600 init_fw_cb->iscsi_max_burst_len =
2601 cpu_to_le32(*(uint32_t *)iface_param->value) /
2602 BYTE_UNITS;
2603 break;
2604 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2605 if (iface_param->iface_num & 0x1)
2606 break;
2607 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2608 init_fw_cb->iscsi_opts |=
2609 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2610 else
2611 init_fw_cb->iscsi_opts &=
2612 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2613 break;
2614 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2615 if (iface_param->iface_num & 0x1)
2616 break;
2617 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2618 init_fw_cb->iscsi_opts |=
2619 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2620 else
2621 init_fw_cb->iscsi_opts &=
2622 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2623 break;
2624 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2625 if (iface_param->iface_num & 0x1)
2626 break;
2627 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2628 init_fw_cb->iscsi_opts |=
2629 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2630 else
2631 init_fw_cb->iscsi_opts &=
2632 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2633 break;
2634 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2635 if (iface_param->iface_num & 0x1)
2636 break;
2637 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2638 init_fw_cb->iscsi_opts |=
2639 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2640 else
2641 init_fw_cb->iscsi_opts &=
2642 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2643 break;
2644 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2645 if (iface_param->iface_num & 0x1)
2646 break;
2647 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2648 init_fw_cb->iscsi_opts |=
2649 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2650 else
2651 init_fw_cb->iscsi_opts &=
2652 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2653 break;
2654 default:
2655 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2656 iface_param->param);
2657 break;
2658 }
2659}
2660
Mike Christied00efe32011-07-25 13:48:38 -05002661static void
2662qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2663{
2664 struct addr_ctrl_blk_def *acb;
2665 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2666 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2667 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2668 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2669 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2670 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2671 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2672 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2673 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2674 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2675 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2676 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2677 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2678 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2679 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2680 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2681}
2682
2683static int
Mike Christie00c31882011-10-06 03:56:59 -05002684qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05002685{
2686 struct scsi_qla_host *ha = to_qla_host(shost);
2687 int rval = 0;
2688 struct iscsi_iface_param_info *iface_param = NULL;
2689 struct addr_ctrl_blk *init_fw_cb = NULL;
2690 dma_addr_t init_fw_cb_dma;
2691 uint32_t mbox_cmd[MBOX_REG_COUNT];
2692 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christie00c31882011-10-06 03:56:59 -05002693 uint32_t rem = len;
2694 struct nlattr *attr;
Mike Christied00efe32011-07-25 13:48:38 -05002695
2696 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2697 sizeof(struct addr_ctrl_blk),
2698 &init_fw_cb_dma, GFP_KERNEL);
2699 if (!init_fw_cb) {
2700 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2701 __func__);
2702 return -ENOMEM;
2703 }
2704
2705 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2706 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2707 memset(&mbox_sts, 0, sizeof(mbox_sts));
2708
2709 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2710 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2711 rval = -EIO;
2712 goto exit_init_fw_cb;
2713 }
2714
Mike Christie00c31882011-10-06 03:56:59 -05002715 nla_for_each_attr(attr, data, len, rem) {
2716 iface_param = nla_data(attr);
Mike Christied00efe32011-07-25 13:48:38 -05002717
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002718 if (iface_param->param_type == ISCSI_NET_PARAM) {
2719 switch (iface_param->iface_type) {
2720 case ISCSI_IFACE_TYPE_IPV4:
2721 switch (iface_param->iface_num) {
2722 case 0:
2723 qla4xxx_set_ipv4(ha, iface_param,
2724 init_fw_cb);
2725 break;
2726 default:
Mike Christied00efe32011-07-25 13:48:38 -05002727 /* Cannot have more than one IPv4 interface */
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002728 ql4_printk(KERN_ERR, ha,
2729 "Invalid IPv4 iface number = %d\n",
2730 iface_param->iface_num);
2731 break;
2732 }
Mike Christied00efe32011-07-25 13:48:38 -05002733 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002734 case ISCSI_IFACE_TYPE_IPV6:
2735 switch (iface_param->iface_num) {
2736 case 0:
2737 case 1:
2738 qla4xxx_set_ipv6(ha, iface_param,
2739 init_fw_cb);
2740 break;
2741 default:
2742 /* Cannot have more than two IPv6 interface */
2743 ql4_printk(KERN_ERR, ha,
2744 "Invalid IPv6 iface number = %d\n",
2745 iface_param->iface_num);
2746 break;
2747 }
Mike Christied00efe32011-07-25 13:48:38 -05002748 break;
2749 default:
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002750 ql4_printk(KERN_ERR, ha,
2751 "Invalid iface type\n");
Mike Christied00efe32011-07-25 13:48:38 -05002752 break;
2753 }
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002754 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2755 qla4xxx_set_iscsi_param(ha, iface_param,
2756 init_fw_cb);
2757 } else {
2758 continue;
Mike Christied00efe32011-07-25 13:48:38 -05002759 }
Mike Christied00efe32011-07-25 13:48:38 -05002760 }
2761
2762 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2763
2764 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2765 sizeof(struct addr_ctrl_blk),
2766 FLASH_OPT_RMW_COMMIT);
2767 if (rval != QLA_SUCCESS) {
2768 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2769 __func__);
2770 rval = -EIO;
2771 goto exit_init_fw_cb;
2772 }
2773
Vikas Chaudharyce505f92011-12-01 22:42:10 -08002774 rval = qla4xxx_disable_acb(ha);
2775 if (rval != QLA_SUCCESS) {
2776 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2777 __func__);
2778 rval = -EIO;
2779 goto exit_init_fw_cb;
2780 }
2781
2782 wait_for_completion_timeout(&ha->disable_acb_comp,
2783 DISABLE_ACB_TOV * HZ);
Mike Christied00efe32011-07-25 13:48:38 -05002784
2785 qla4xxx_initcb_to_acb(init_fw_cb);
2786
2787 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2788 if (rval != QLA_SUCCESS) {
2789 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2790 __func__);
2791 rval = -EIO;
2792 goto exit_init_fw_cb;
2793 }
2794
2795 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2796 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2797 init_fw_cb_dma);
2798
2799exit_init_fw_cb:
2800 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2801 init_fw_cb, init_fw_cb_dma);
2802
2803 return rval;
2804}
2805
Mike Christiefca9f042012-02-27 03:08:54 -08002806static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2807 enum iscsi_param param, char *buf)
2808{
2809 struct iscsi_session *sess = cls_sess->dd_data;
2810 struct ddb_entry *ddb_entry = sess->dd_data;
2811 struct scsi_qla_host *ha = ddb_entry->ha;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002812 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2813 struct ql4_chap_table chap_tbl;
Mike Christiefca9f042012-02-27 03:08:54 -08002814 int rval, len;
2815 uint16_t idx;
2816
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002817 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christiefca9f042012-02-27 03:08:54 -08002818 switch (param) {
2819 case ISCSI_PARAM_CHAP_IN_IDX:
2820 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2821 sess->password_in, BIDI_CHAP,
2822 &idx);
2823 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002824 len = sprintf(buf, "\n");
2825 else
2826 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002827 break;
2828 case ISCSI_PARAM_CHAP_OUT_IDX:
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002829 if (ddb_entry->ddb_type == FLASH_DDB) {
2830 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2831 idx = ddb_entry->chap_tbl_idx;
2832 rval = QLA_SUCCESS;
2833 } else {
2834 rval = QLA_ERROR;
2835 }
2836 } else {
2837 rval = qla4xxx_get_chap_index(ha, sess->username,
2838 sess->password,
2839 LOCAL_CHAP, &idx);
2840 }
Mike Christiefca9f042012-02-27 03:08:54 -08002841 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002842 len = sprintf(buf, "\n");
2843 else
2844 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002845 break;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002846 case ISCSI_PARAM_USERNAME:
2847 case ISCSI_PARAM_PASSWORD:
2848 /* First, populate session username and password for FLASH DDB,
2849 * if not already done. This happens when session login fails
2850 * for a FLASH DDB.
2851 */
2852 if (ddb_entry->ddb_type == FLASH_DDB &&
2853 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2854 !sess->username && !sess->password) {
2855 idx = ddb_entry->chap_tbl_idx;
2856 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2857 chap_tbl.secret,
2858 idx);
2859 if (!rval) {
2860 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2861 (char *)chap_tbl.name,
2862 strlen((char *)chap_tbl.name));
2863 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2864 (char *)chap_tbl.secret,
2865 chap_tbl.secret_len);
2866 }
2867 }
2868 /* allow fall-through */
Mike Christiefca9f042012-02-27 03:08:54 -08002869 default:
2870 return iscsi_session_get_param(cls_sess, param, buf);
2871 }
2872
2873 return len;
2874}
2875
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002876static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002877 enum iscsi_param param, char *buf)
2878{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002879 struct iscsi_conn *conn;
2880 struct qla_conn *qla_conn;
2881 struct sockaddr *dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002882
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002883 conn = cls_conn->dd_data;
2884 qla_conn = conn->dd_data;
Manish Rangankard46bdeb12012-08-07 07:57:13 -04002885 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002886
2887 switch (param) {
2888 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002889 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002890 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2891 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002892 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002893 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002894 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002895}
2896
Mike Christie13483732011-12-01 21:38:41 -06002897int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2898{
2899 uint32_t mbx_sts = 0;
2900 uint16_t tmp_ddb_index;
2901 int ret;
2902
2903get_ddb_index:
2904 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2905
2906 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2907 DEBUG2(ql4_printk(KERN_INFO, ha,
2908 "Free DDB index not available\n"));
2909 ret = QLA_ERROR;
2910 goto exit_get_ddb_index;
2911 }
2912
2913 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2914 goto get_ddb_index;
2915
2916 DEBUG2(ql4_printk(KERN_INFO, ha,
2917 "Found a free DDB index at %d\n", tmp_ddb_index));
2918 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2919 if (ret == QLA_ERROR) {
2920 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2921 ql4_printk(KERN_INFO, ha,
2922 "DDB index = %d not available trying next\n",
2923 tmp_ddb_index);
2924 goto get_ddb_index;
2925 }
2926 DEBUG2(ql4_printk(KERN_INFO, ha,
2927 "Free FW DDB not available\n"));
2928 }
2929
2930 *ddb_index = tmp_ddb_index;
2931
2932exit_get_ddb_index:
2933 return ret;
2934}
2935
2936static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2937 struct ddb_entry *ddb_entry,
2938 char *existing_ipaddr,
2939 char *user_ipaddr)
2940{
2941 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2942 char formatted_ipaddr[DDB_IPADDR_LEN];
2943 int status = QLA_SUCCESS, ret = 0;
2944
2945 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2946 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2947 '\0', NULL);
2948 if (ret == 0) {
2949 status = QLA_ERROR;
2950 goto out_match;
2951 }
2952 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2953 } else {
2954 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2955 '\0', NULL);
2956 if (ret == 0) {
2957 status = QLA_ERROR;
2958 goto out_match;
2959 }
2960 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2961 }
2962
2963 if (strcmp(existing_ipaddr, formatted_ipaddr))
2964 status = QLA_ERROR;
2965
2966out_match:
2967 return status;
2968}
2969
2970static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2971 struct iscsi_cls_conn *cls_conn)
2972{
2973 int idx = 0, max_ddbs, rval;
2974 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2975 struct iscsi_session *sess, *existing_sess;
2976 struct iscsi_conn *conn, *existing_conn;
2977 struct ddb_entry *ddb_entry;
2978
2979 sess = cls_sess->dd_data;
2980 conn = cls_conn->dd_data;
2981
2982 if (sess->targetname == NULL ||
2983 conn->persistent_address == NULL ||
2984 conn->persistent_port == 0)
2985 return QLA_ERROR;
2986
2987 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
2988 MAX_DEV_DB_ENTRIES;
2989
2990 for (idx = 0; idx < max_ddbs; idx++) {
2991 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
2992 if (ddb_entry == NULL)
2993 continue;
2994
2995 if (ddb_entry->ddb_type != FLASH_DDB)
2996 continue;
2997
2998 existing_sess = ddb_entry->sess->dd_data;
2999 existing_conn = ddb_entry->conn->dd_data;
3000
3001 if (existing_sess->targetname == NULL ||
3002 existing_conn->persistent_address == NULL ||
3003 existing_conn->persistent_port == 0)
3004 continue;
3005
3006 DEBUG2(ql4_printk(KERN_INFO, ha,
3007 "IQN = %s User IQN = %s\n",
3008 existing_sess->targetname,
3009 sess->targetname));
3010
3011 DEBUG2(ql4_printk(KERN_INFO, ha,
3012 "IP = %s User IP = %s\n",
3013 existing_conn->persistent_address,
3014 conn->persistent_address));
3015
3016 DEBUG2(ql4_printk(KERN_INFO, ha,
3017 "Port = %d User Port = %d\n",
3018 existing_conn->persistent_port,
3019 conn->persistent_port));
3020
3021 if (strcmp(existing_sess->targetname, sess->targetname))
3022 continue;
3023 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3024 existing_conn->persistent_address,
3025 conn->persistent_address);
3026 if (rval == QLA_ERROR)
3027 continue;
3028 if (existing_conn->persistent_port != conn->persistent_port)
3029 continue;
3030 break;
3031 }
3032
3033 if (idx == max_ddbs)
3034 return QLA_ERROR;
3035
3036 DEBUG2(ql4_printk(KERN_INFO, ha,
3037 "Match found in fwdb sessions\n"));
3038 return QLA_SUCCESS;
3039}
3040
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003041static struct iscsi_cls_session *
3042qla4xxx_session_create(struct iscsi_endpoint *ep,
3043 uint16_t cmds_max, uint16_t qdepth,
3044 uint32_t initial_cmdsn)
3045{
3046 struct iscsi_cls_session *cls_sess;
3047 struct scsi_qla_host *ha;
3048 struct qla_endpoint *qla_ep;
3049 struct ddb_entry *ddb_entry;
Mike Christie13483732011-12-01 21:38:41 -06003050 uint16_t ddb_index;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003051 struct iscsi_session *sess;
3052 struct sockaddr *dst_addr;
3053 int ret;
3054
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003055 if (!ep) {
3056 printk(KERN_ERR "qla4xxx: missing ep.\n");
3057 return NULL;
3058 }
3059
3060 qla_ep = ep->dd_data;
3061 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3062 ha = to_qla_host(qla_ep->host);
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003063 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3064 ha->host_no));
Manish Rangankar736cf362011-10-07 16:55:46 -07003065
Mike Christie13483732011-12-01 21:38:41 -06003066 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3067 if (ret == QLA_ERROR)
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003068 return NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003069
3070 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3071 cmds_max, sizeof(struct ddb_entry),
3072 sizeof(struct ql4_task_data),
3073 initial_cmdsn, ddb_index);
3074 if (!cls_sess)
3075 return NULL;
3076
3077 sess = cls_sess->dd_data;
3078 ddb_entry = sess->dd_data;
3079 ddb_entry->fw_ddb_index = ddb_index;
3080 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3081 ddb_entry->ha = ha;
3082 ddb_entry->sess = cls_sess;
Mike Christie13483732011-12-01 21:38:41 -06003083 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3084 ddb_entry->ddb_change = qla4xxx_ddb_change;
Nilesh Javalide2efea2013-12-16 06:49:40 -05003085 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003086 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3087 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3088 ha->tot_ddbs++;
3089
3090 return cls_sess;
3091}
3092
3093static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3094{
3095 struct iscsi_session *sess;
3096 struct ddb_entry *ddb_entry;
3097 struct scsi_qla_host *ha;
Manish Rangankar90599b62012-04-23 22:32:34 -07003098 unsigned long flags, wtime;
3099 struct dev_db_entry *fw_ddb_entry = NULL;
3100 dma_addr_t fw_ddb_entry_dma;
3101 uint32_t ddb_state;
3102 int ret;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003103
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003104 sess = cls_sess->dd_data;
3105 ddb_entry = sess->dd_data;
3106 ha = ddb_entry->ha;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003107 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3108 ha->host_no));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003109
Manish Rangankar90599b62012-04-23 22:32:34 -07003110 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3111 &fw_ddb_entry_dma, GFP_KERNEL);
3112 if (!fw_ddb_entry) {
3113 ql4_printk(KERN_ERR, ha,
3114 "%s: Unable to allocate dma buffer\n", __func__);
3115 goto destroy_session;
3116 }
3117
3118 wtime = jiffies + (HZ * LOGOUT_TOV);
3119 do {
3120 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3121 fw_ddb_entry, fw_ddb_entry_dma,
3122 NULL, NULL, &ddb_state, NULL,
3123 NULL, NULL);
3124 if (ret == QLA_ERROR)
3125 goto destroy_session;
3126
3127 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3128 (ddb_state == DDB_DS_SESSION_FAILED))
3129 goto destroy_session;
3130
3131 schedule_timeout_uninterruptible(HZ);
3132 } while ((time_after(wtime, jiffies)));
3133
3134destroy_session:
Manish Rangankar736cf362011-10-07 16:55:46 -07003135 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
Nilesh Javalide2efea2013-12-16 06:49:40 -05003136 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3137 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003138 spin_lock_irqsave(&ha->hardware_lock, flags);
3139 qla4xxx_free_ddb(ha, ddb_entry);
3140 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Manish Rangankar90599b62012-04-23 22:32:34 -07003141
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003142 iscsi_session_teardown(cls_sess);
Manish Rangankar90599b62012-04-23 22:32:34 -07003143
3144 if (fw_ddb_entry)
3145 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3146 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003147}
3148
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003149static struct iscsi_cls_conn *
3150qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3151{
3152 struct iscsi_cls_conn *cls_conn;
3153 struct iscsi_session *sess;
3154 struct ddb_entry *ddb_entry;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003155 struct scsi_qla_host *ha;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003156
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003157 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3158 conn_idx);
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003159 if (!cls_conn) {
3160 pr_info("%s: Can not create connection for conn_idx = %u\n",
3161 __func__, conn_idx);
Mike Christieff1d0312011-12-01 21:38:43 -06003162 return NULL;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003163 }
Mike Christieff1d0312011-12-01 21:38:43 -06003164
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003165 sess = cls_sess->dd_data;
3166 ddb_entry = sess->dd_data;
3167 ddb_entry->conn = cls_conn;
3168
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003169 ha = ddb_entry->ha;
3170 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3171 conn_idx));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003172 return cls_conn;
3173}
3174
3175static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3176 struct iscsi_cls_conn *cls_conn,
3177 uint64_t transport_fd, int is_leading)
3178{
3179 struct iscsi_conn *conn;
3180 struct qla_conn *qla_conn;
3181 struct iscsi_endpoint *ep;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003182 struct ddb_entry *ddb_entry;
3183 struct scsi_qla_host *ha;
3184 struct iscsi_session *sess;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003185
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003186 sess = cls_session->dd_data;
3187 ddb_entry = sess->dd_data;
3188 ha = ddb_entry->ha;
3189
3190 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3191 cls_session->sid, cls_conn->cid));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003192
3193 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3194 return -EINVAL;
3195 ep = iscsi_lookup_endpoint(transport_fd);
3196 conn = cls_conn->dd_data;
3197 qla_conn = conn->dd_data;
3198 qla_conn->qla_ep = ep->dd_data;
3199 return 0;
3200}
3201
3202static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3203{
3204 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3205 struct iscsi_session *sess;
3206 struct ddb_entry *ddb_entry;
3207 struct scsi_qla_host *ha;
Mike Christie13483732011-12-01 21:38:41 -06003208 struct dev_db_entry *fw_ddb_entry = NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003209 dma_addr_t fw_ddb_entry_dma;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003210 uint32_t mbx_sts = 0;
3211 int ret = 0;
3212 int status = QLA_SUCCESS;
3213
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003214 sess = cls_sess->dd_data;
3215 ddb_entry = sess->dd_data;
3216 ha = ddb_entry->ha;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003217 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3218 cls_sess->sid, cls_conn->cid));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003219
Mike Christie13483732011-12-01 21:38:41 -06003220 /* Check if we have matching FW DDB, if yes then do not
3221 * login to this target. This could cause target to logout previous
3222 * connection
3223 */
3224 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3225 if (ret == QLA_SUCCESS) {
3226 ql4_printk(KERN_INFO, ha,
3227 "Session already exist in FW.\n");
3228 ret = -EEXIST;
3229 goto exit_conn_start;
3230 }
3231
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003232 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3233 &fw_ddb_entry_dma, GFP_KERNEL);
3234 if (!fw_ddb_entry) {
3235 ql4_printk(KERN_ERR, ha,
3236 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003237 ret = -ENOMEM;
3238 goto exit_conn_start;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003239 }
3240
3241 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3242 if (ret) {
3243 /* If iscsid is stopped and started then no need to do
3244 * set param again since ddb state will be already
3245 * active and FW does not allow set ddb to an
3246 * active session.
3247 */
3248 if (mbx_sts)
3249 if (ddb_entry->fw_ddb_device_state ==
Manish Rangankarf922da72011-10-07 16:55:49 -07003250 DDB_DS_SESSION_ACTIVE) {
Mike Christie13483732011-12-01 21:38:41 -06003251 ddb_entry->unblock_sess(ddb_entry->sess);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003252 goto exit_set_param;
Manish Rangankarf922da72011-10-07 16:55:49 -07003253 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003254
3255 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3256 __func__, ddb_entry->fw_ddb_index);
3257 goto exit_conn_start;
3258 }
3259
3260 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3261 if (status == QLA_ERROR) {
Manish Rangankar0e7e8502011-07-25 13:48:54 -05003262 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3263 sess->targetname);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003264 ret = -EINVAL;
3265 goto exit_conn_start;
3266 }
3267
Manish Rangankar98270ab2011-10-07 16:55:47 -07003268 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3269 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3270
3271 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3272 ddb_entry->fw_ddb_device_state));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003273
3274exit_set_param:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003275 ret = 0;
3276
3277exit_conn_start:
Mike Christie13483732011-12-01 21:38:41 -06003278 if (fw_ddb_entry)
3279 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3280 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003281 return ret;
3282}
3283
3284static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3285{
3286 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3287 struct iscsi_session *sess;
3288 struct scsi_qla_host *ha;
3289 struct ddb_entry *ddb_entry;
3290 int options;
3291
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003292 sess = cls_sess->dd_data;
3293 ddb_entry = sess->dd_data;
3294 ha = ddb_entry->ha;
Vikas Chaudharyc343c5e2013-12-16 06:49:48 -05003295 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3296 cls_conn->cid));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003297
3298 options = LOGOUT_OPTION_CLOSE_SESSION;
3299 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3300 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003301}
3302
3303static void qla4xxx_task_work(struct work_struct *wdata)
3304{
3305 struct ql4_task_data *task_data;
3306 struct scsi_qla_host *ha;
3307 struct passthru_status *sts;
3308 struct iscsi_task *task;
3309 struct iscsi_hdr *hdr;
3310 uint8_t *data;
3311 uint32_t data_len;
3312 struct iscsi_conn *conn;
3313 int hdr_len;
3314 itt_t itt;
3315
3316 task_data = container_of(wdata, struct ql4_task_data, task_work);
3317 ha = task_data->ha;
3318 task = task_data->task;
3319 sts = &task_data->sts;
3320 hdr_len = sizeof(struct iscsi_hdr);
3321
3322 DEBUG3(printk(KERN_INFO "Status returned\n"));
3323 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3324 DEBUG3(printk(KERN_INFO "Response buffer"));
3325 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3326
3327 conn = task->conn;
3328
3329 switch (sts->completionStatus) {
3330 case PASSTHRU_STATUS_COMPLETE:
3331 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3332 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3333 itt = sts->handle;
3334 hdr->itt = itt;
3335 data = task_data->resp_buffer + hdr_len;
3336 data_len = task_data->resp_len - hdr_len;
3337 iscsi_complete_pdu(conn, hdr, data, data_len);
3338 break;
3339 default:
3340 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3341 sts->completionStatus);
3342 break;
3343 }
3344 return;
3345}
3346
3347static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3348{
3349 struct ql4_task_data *task_data;
3350 struct iscsi_session *sess;
3351 struct ddb_entry *ddb_entry;
3352 struct scsi_qla_host *ha;
3353 int hdr_len;
3354
3355 sess = task->conn->session;
3356 ddb_entry = sess->dd_data;
3357 ha = ddb_entry->ha;
3358 task_data = task->dd_data;
3359 memset(task_data, 0, sizeof(struct ql4_task_data));
3360
3361 if (task->sc) {
3362 ql4_printk(KERN_INFO, ha,
3363 "%s: SCSI Commands not implemented\n", __func__);
3364 return -EINVAL;
3365 }
3366
3367 hdr_len = sizeof(struct iscsi_hdr);
3368 task_data->ha = ha;
3369 task_data->task = task;
3370
3371 if (task->data_count) {
3372 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3373 task->data_count,
3374 PCI_DMA_TODEVICE);
3375 }
3376
3377 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3378 __func__, task->conn->max_recv_dlength, hdr_len));
3379
Manish Rangankar69ca2162011-10-07 16:55:50 -07003380 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003381 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3382 task_data->resp_len,
3383 &task_data->resp_dma,
3384 GFP_ATOMIC);
3385 if (!task_data->resp_buffer)
3386 goto exit_alloc_pdu;
3387
Manish Rangankar69ca2162011-10-07 16:55:50 -07003388 task_data->req_len = task->data_count + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003389 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
Manish Rangankar69ca2162011-10-07 16:55:50 -07003390 task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003391 &task_data->req_dma,
3392 GFP_ATOMIC);
3393 if (!task_data->req_buffer)
3394 goto exit_alloc_pdu;
3395
3396 task->hdr = task_data->req_buffer;
3397
3398 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3399
3400 return 0;
3401
3402exit_alloc_pdu:
3403 if (task_data->resp_buffer)
3404 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3405 task_data->resp_buffer, task_data->resp_dma);
3406
3407 if (task_data->req_buffer)
Manish Rangankar69ca2162011-10-07 16:55:50 -07003408 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003409 task_data->req_buffer, task_data->req_dma);
3410 return -ENOMEM;
3411}
3412
3413static void qla4xxx_task_cleanup(struct iscsi_task *task)
3414{
3415 struct ql4_task_data *task_data;
3416 struct iscsi_session *sess;
3417 struct ddb_entry *ddb_entry;
3418 struct scsi_qla_host *ha;
3419 int hdr_len;
3420
3421 hdr_len = sizeof(struct iscsi_hdr);
3422 sess = task->conn->session;
3423 ddb_entry = sess->dd_data;
3424 ha = ddb_entry->ha;
3425 task_data = task->dd_data;
3426
3427 if (task->data_count) {
3428 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3429 task->data_count, PCI_DMA_TODEVICE);
3430 }
3431
3432 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3433 __func__, task->conn->max_recv_dlength, hdr_len));
3434
3435 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3436 task_data->resp_buffer, task_data->resp_dma);
Manish Rangankar69ca2162011-10-07 16:55:50 -07003437 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003438 task_data->req_buffer, task_data->req_dma);
3439 return;
3440}
3441
3442static int qla4xxx_task_xmit(struct iscsi_task *task)
3443{
3444 struct scsi_cmnd *sc = task->sc;
3445 struct iscsi_session *sess = task->conn->session;
3446 struct ddb_entry *ddb_entry = sess->dd_data;
3447 struct scsi_qla_host *ha = ddb_entry->ha;
3448
3449 if (!sc)
3450 return qla4xxx_send_passthru0(task);
3451
3452 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3453 __func__);
3454 return -ENOSYS;
3455}
3456
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003457static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3458 struct iscsi_bus_flash_conn *conn,
3459 struct dev_db_entry *fw_ddb_entry)
3460{
3461 unsigned long options = 0;
3462 int rc = 0;
3463
3464 options = le16_to_cpu(fw_ddb_entry->options);
3465 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3466 if (test_bit(OPT_IPV6_DEVICE, &options)) {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003467 rc = iscsi_switch_str_param(&sess->portal_type,
3468 PORTAL_TYPE_IPV6);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003469 if (rc)
3470 goto exit_copy;
3471 } else {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003472 rc = iscsi_switch_str_param(&sess->portal_type,
3473 PORTAL_TYPE_IPV4);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003474 if (rc)
3475 goto exit_copy;
3476 }
3477
3478 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3479 &options);
3480 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3481 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3482
3483 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3484 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3485 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3486 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3487 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3488 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3489 &options);
3490 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3491 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3492 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3493 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3494 &options);
3495 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3496 sess->discovery_auth_optional =
3497 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3498 if (test_bit(ISCSIOPT_ERL1, &options))
3499 sess->erl |= BIT_1;
3500 if (test_bit(ISCSIOPT_ERL0, &options))
3501 sess->erl |= BIT_0;
3502
3503 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3504 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3505 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3506 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3507 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3508 conn->tcp_timer_scale |= BIT_3;
3509 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3510 conn->tcp_timer_scale |= BIT_2;
3511 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3512 conn->tcp_timer_scale |= BIT_1;
3513
3514 conn->tcp_timer_scale >>= 1;
3515 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3516
3517 options = le16_to_cpu(fw_ddb_entry->ip_options);
3518 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3519
3520 conn->max_recv_dlength = BYTE_UNITS *
3521 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3522 conn->max_xmit_dlength = BYTE_UNITS *
3523 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3524 sess->first_burst = BYTE_UNITS *
3525 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3526 sess->max_burst = BYTE_UNITS *
3527 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3528 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3529 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3530 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3531 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3532 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3533 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3534 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3535 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3536 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3537 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3538 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3539 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3540 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3541 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3542 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3543 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3544
3545 sess->default_taskmgmt_timeout =
3546 le16_to_cpu(fw_ddb_entry->def_timeout);
3547 conn->port = le16_to_cpu(fw_ddb_entry->port);
3548
3549 options = le16_to_cpu(fw_ddb_entry->options);
3550 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3551 if (!conn->ipaddress) {
3552 rc = -ENOMEM;
3553 goto exit_copy;
3554 }
3555
3556 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3557 if (!conn->redirect_ipaddr) {
3558 rc = -ENOMEM;
3559 goto exit_copy;
3560 }
3561
3562 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3563 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3564
3565 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3566 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3567
Benoit Taine3d30b432014-05-26 17:21:13 +02003568 conn->link_local_ipv6_addr = kmemdup(
3569 fw_ddb_entry->link_local_ipv6_addr,
3570 IPv6_ADDR_LEN, GFP_KERNEL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003571 if (!conn->link_local_ipv6_addr) {
3572 rc = -ENOMEM;
3573 goto exit_copy;
3574 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003575 } else {
3576 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3577 }
3578
3579 if (fw_ddb_entry->iscsi_name[0]) {
3580 rc = iscsi_switch_str_param(&sess->targetname,
3581 (char *)fw_ddb_entry->iscsi_name);
3582 if (rc)
3583 goto exit_copy;
3584 }
3585
3586 if (fw_ddb_entry->iscsi_alias[0]) {
3587 rc = iscsi_switch_str_param(&sess->targetalias,
3588 (char *)fw_ddb_entry->iscsi_alias);
3589 if (rc)
3590 goto exit_copy;
3591 }
3592
3593 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3594
3595exit_copy:
3596 return rc;
3597}
3598
3599static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3600 struct iscsi_bus_flash_conn *conn,
3601 struct dev_db_entry *fw_ddb_entry)
3602{
3603 uint16_t options;
3604 int rc = 0;
3605
3606 options = le16_to_cpu(fw_ddb_entry->options);
3607 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003608 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003609 options |= BIT_8;
3610 else
3611 options &= ~BIT_8;
3612
3613 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3614 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3615 SET_BITVAL(sess->entry_state, options, BIT_3);
3616 fw_ddb_entry->options = cpu_to_le16(options);
3617
3618 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3619 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3620 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3621 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3622 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3623 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3624 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3625 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3626 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3627 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3628 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3629 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3630 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3631 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3632 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3633
3634 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3635 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3636 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3637 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3638 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3639 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3640 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3641 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3642 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3643
3644 options = le16_to_cpu(fw_ddb_entry->ip_options);
3645 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3646 fw_ddb_entry->ip_options = cpu_to_le16(options);
3647
3648 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3649 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3650 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3651 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3652 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3653 fw_ddb_entry->iscsi_first_burst_len =
3654 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3655 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3656 BYTE_UNITS);
3657 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3658 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3659 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3660 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003661 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3662 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003663 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3664 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3665 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003666 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3667 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
Adheer Chandravanshi65560162013-07-08 08:33:06 -04003668 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003669 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3670 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3671 fw_ddb_entry->port = cpu_to_le16(conn->port);
3672 fw_ddb_entry->def_timeout =
3673 cpu_to_le16(sess->default_taskmgmt_timeout);
3674
Adheer Chandravanshi84595802013-07-08 08:33:07 -04003675 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3676 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3677 else
3678 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3679
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003680 if (conn->ipaddress)
3681 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3682 sizeof(fw_ddb_entry->ip_addr));
3683
3684 if (conn->redirect_ipaddr)
3685 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3686 sizeof(fw_ddb_entry->tgt_addr));
3687
3688 if (conn->link_local_ipv6_addr)
3689 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3690 conn->link_local_ipv6_addr,
3691 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3692
3693 if (sess->targetname)
3694 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3695 sizeof(fw_ddb_entry->iscsi_name));
3696
3697 if (sess->targetalias)
3698 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3699 sizeof(fw_ddb_entry->iscsi_alias));
3700
3701 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3702
3703 return rc;
3704}
3705
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003706static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3707 struct iscsi_session *sess,
3708 struct dev_db_entry *fw_ddb_entry)
3709{
3710 unsigned long options = 0;
3711 uint16_t ddb_link;
3712 uint16_t disc_parent;
Adheer Chandravanshifb734ee32013-11-22 05:28:22 -05003713 char ip_addr[DDB_IPADDR_LEN];
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003714
3715 options = le16_to_cpu(fw_ddb_entry->options);
3716 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3717 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3718 &options);
3719 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3720
3721 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3722 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3723 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3724 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3725 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3726 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3727 &options);
3728 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3729 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3730 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3731 &options);
3732 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3733 sess->discovery_auth_optional =
3734 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3735 if (test_bit(ISCSIOPT_ERL1, &options))
3736 sess->erl |= BIT_1;
3737 if (test_bit(ISCSIOPT_ERL0, &options))
3738 sess->erl |= BIT_0;
3739
3740 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3741 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3742 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3743 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3744 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3745 conn->tcp_timer_scale |= BIT_3;
3746 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3747 conn->tcp_timer_scale |= BIT_2;
3748 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3749 conn->tcp_timer_scale |= BIT_1;
3750
3751 conn->tcp_timer_scale >>= 1;
3752 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3753
3754 options = le16_to_cpu(fw_ddb_entry->ip_options);
3755 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3756
3757 conn->max_recv_dlength = BYTE_UNITS *
3758 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3759 conn->max_xmit_dlength = BYTE_UNITS *
3760 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3761 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3762 sess->first_burst = BYTE_UNITS *
3763 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3764 sess->max_burst = BYTE_UNITS *
3765 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3766 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3767 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3768 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3769 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3770 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3771 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3772 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3773 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3774 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3775 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3776 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3777 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3778 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3779
3780 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003781 if (ddb_link == DDB_ISNS)
3782 disc_parent = ISCSI_DISC_PARENT_ISNS;
3783 else if (ddb_link == DDB_NO_LINK)
3784 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3785 else if (ddb_link < MAX_DDB_ENTRIES)
3786 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3787 else
3788 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3789
3790 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3791 iscsi_get_discovery_parent_name(disc_parent), 0);
3792
3793 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3794 (char *)fw_ddb_entry->iscsi_alias, 0);
Adheer Chandravanshifb734ee32013-11-22 05:28:22 -05003795
3796 options = le16_to_cpu(fw_ddb_entry->options);
3797 if (options & DDB_OPT_IPV6_DEVICE) {
3798 memset(ip_addr, 0, sizeof(ip_addr));
3799 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3800 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3801 (char *)ip_addr, 0);
3802 }
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003803}
3804
Mike Christie13483732011-12-01 21:38:41 -06003805static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3806 struct dev_db_entry *fw_ddb_entry,
3807 struct iscsi_cls_session *cls_sess,
3808 struct iscsi_cls_conn *cls_conn)
3809{
3810 int buflen = 0;
3811 struct iscsi_session *sess;
Nilesh Javali376738a2012-02-27 03:08:52 -08003812 struct ddb_entry *ddb_entry;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003813 struct ql4_chap_table chap_tbl;
Mike Christie13483732011-12-01 21:38:41 -06003814 struct iscsi_conn *conn;
3815 char ip_addr[DDB_IPADDR_LEN];
3816 uint16_t options = 0;
3817
3818 sess = cls_sess->dd_data;
Nilesh Javali376738a2012-02-27 03:08:52 -08003819 ddb_entry = sess->dd_data;
Mike Christie13483732011-12-01 21:38:41 -06003820 conn = cls_conn->dd_data;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003821 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christie13483732011-12-01 21:38:41 -06003822
Nilesh Javali376738a2012-02-27 03:08:52 -08003823 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3824
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003825 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Mike Christie13483732011-12-01 21:38:41 -06003826
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003827 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06003828 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3829
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003830 memset(ip_addr, 0, sizeof(ip_addr));
Mike Christie13483732011-12-01 21:38:41 -06003831 options = le16_to_cpu(fw_ddb_entry->options);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003832 if (options & DDB_OPT_IPV6_DEVICE) {
3833 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
Mike Christie13483732011-12-01 21:38:41 -06003834
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003835 memset(ip_addr, 0, sizeof(ip_addr));
3836 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3837 } else {
3838 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3839 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3840 }
3841
3842 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3843 (char *)ip_addr, buflen);
Mike Christie13483732011-12-01 21:38:41 -06003844 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3845 (char *)fw_ddb_entry->iscsi_name, buflen);
3846 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3847 (char *)ha->name_string, buflen);
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003848
3849 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3850 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3851 chap_tbl.secret,
3852 ddb_entry->chap_tbl_idx)) {
3853 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3854 (char *)chap_tbl.name,
3855 strlen((char *)chap_tbl.name));
3856 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3857 (char *)chap_tbl.secret,
3858 chap_tbl.secret_len);
3859 }
3860 }
Mike Christie13483732011-12-01 21:38:41 -06003861}
3862
3863void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3864 struct ddb_entry *ddb_entry)
3865{
3866 struct iscsi_cls_session *cls_sess;
3867 struct iscsi_cls_conn *cls_conn;
3868 uint32_t ddb_state;
3869 dma_addr_t fw_ddb_entry_dma;
3870 struct dev_db_entry *fw_ddb_entry;
3871
3872 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3873 &fw_ddb_entry_dma, GFP_KERNEL);
3874 if (!fw_ddb_entry) {
3875 ql4_printk(KERN_ERR, ha,
3876 "%s: Unable to allocate dma buffer\n", __func__);
3877 goto exit_session_conn_fwddb_param;
3878 }
3879
3880 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3881 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3882 NULL, NULL, NULL) == QLA_ERROR) {
3883 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3884 "get_ddb_entry for fw_ddb_index %d\n",
3885 ha->host_no, __func__,
3886 ddb_entry->fw_ddb_index));
3887 goto exit_session_conn_fwddb_param;
3888 }
3889
3890 cls_sess = ddb_entry->sess;
3891
3892 cls_conn = ddb_entry->conn;
3893
3894 /* Update params */
3895 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3896
3897exit_session_conn_fwddb_param:
3898 if (fw_ddb_entry)
3899 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3900 fw_ddb_entry, fw_ddb_entry_dma);
3901}
3902
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003903void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3904 struct ddb_entry *ddb_entry)
3905{
3906 struct iscsi_cls_session *cls_sess;
3907 struct iscsi_cls_conn *cls_conn;
3908 struct iscsi_session *sess;
3909 struct iscsi_conn *conn;
3910 uint32_t ddb_state;
3911 dma_addr_t fw_ddb_entry_dma;
3912 struct dev_db_entry *fw_ddb_entry;
3913
3914 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3915 &fw_ddb_entry_dma, GFP_KERNEL);
3916 if (!fw_ddb_entry) {
3917 ql4_printk(KERN_ERR, ha,
3918 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003919 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003920 }
3921
3922 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3923 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3924 NULL, NULL, NULL) == QLA_ERROR) {
3925 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3926 "get_ddb_entry for fw_ddb_index %d\n",
3927 ha->host_no, __func__,
3928 ddb_entry->fw_ddb_index));
Mike Christie13483732011-12-01 21:38:41 -06003929 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003930 }
3931
3932 cls_sess = ddb_entry->sess;
3933 sess = cls_sess->dd_data;
3934
3935 cls_conn = ddb_entry->conn;
3936 conn = cls_conn->dd_data;
3937
Mike Christie13483732011-12-01 21:38:41 -06003938 /* Update timers after login */
3939 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003940 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3941 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3942 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06003943 ddb_entry->default_time2wait =
3944 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3945
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003946 /* Update params */
Nilesh Javali376738a2012-02-27 03:08:52 -08003947 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003948 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003949
3950 memcpy(sess->initiatorname, ha->name_string,
3951 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
Mike Christie13483732011-12-01 21:38:41 -06003952
3953exit_session_conn_param:
3954 if (fw_ddb_entry)
3955 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3956 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003957}
3958
David Somayajuluafaf5a22006-09-19 10:28:00 -07003959/*
3960 * Timer routines
3961 */
3962
3963static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
3964 unsigned long interval)
3965{
3966 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3967 __func__, ha->host->host_no));
3968 init_timer(&ha->timer);
3969 ha->timer.expires = jiffies + interval * HZ;
3970 ha->timer.data = (unsigned long)ha;
3971 ha->timer.function = (void (*)(unsigned long))func;
3972 add_timer(&ha->timer);
3973 ha->timer_active = 1;
3974}
3975
3976static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3977{
3978 del_timer_sync(&ha->timer);
3979 ha->timer_active = 0;
3980}
3981
3982/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003983 * qla4xxx_mark_device_missing - blocks the session
3984 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07003985 * @ddb_entry: Pointer to device database entry
3986 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303987 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07003988 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003989void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003990{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003991 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003992}
3993
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303994/**
3995 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
3996 * @ha: Pointer to host adapter structure.
3997 *
3998 * This routine marks a device missing and resets the relogin retry count.
3999 **/
4000void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4001{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004002 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304003}
4004
David Somayajuluafaf5a22006-09-19 10:28:00 -07004005static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4006 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004007 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004008{
4009 struct srb *srb;
4010
4011 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4012 if (!srb)
4013 return srb;
4014
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304015 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004016 srb->ha = ha;
4017 srb->ddb = ddb_entry;
4018 srb->cmd = cmd;
4019 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05304020 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004021
4022 return srb;
4023}
4024
4025static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4026{
4027 struct scsi_cmnd *cmd = srb->cmd;
4028
4029 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09004030 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004031 srb->flags &= ~SRB_DMA_VALID;
4032 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05304033 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004034}
4035
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304036void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004037{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304038 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004039 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304040 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004041
4042 qla4xxx_srb_free_dma(ha, srb);
4043
4044 mempool_free(srb, ha->srb_mempool);
4045
4046 cmd->scsi_done(cmd);
4047}
4048
4049/**
4050 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004051 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07004052 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07004053 *
4054 * Remarks:
4055 * This routine is invoked by Linux to send a SCSI command to the driver.
4056 * The mid-level driver tries to ensure that queuecommand never gets
4057 * invoked concurrently with itself or the interrupt handler (although
4058 * the interrupt handler may call this routine as part of request-
4059 * completion handling). Unfortunely, it sometimes calls the scheduler
4060 * in interrupt context which is a big NO! NO!.
4061 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004062static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004063{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004064 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004065 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06004066 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004067 struct srb *srb;
4068 int rval;
4069
Lalit Chandivade2232be02010-07-30 14:38:47 +05304070 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4071 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4072 cmd->result = DID_NO_CONNECT << 16;
4073 else
4074 cmd->result = DID_REQUEUE << 16;
4075 goto qc_fail_command;
4076 }
4077
Mike Christie7fb19212008-01-31 13:36:45 -06004078 if (!sess) {
4079 cmd->result = DID_IMM_RETRY << 16;
4080 goto qc_fail_command;
4081 }
4082
4083 rval = iscsi_session_chkready(sess);
4084 if (rval) {
4085 cmd->result = rval;
4086 goto qc_fail_command;
4087 }
4088
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304089 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4090 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4091 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4092 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4093 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4094 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004095 !test_bit(AF_LINK_UP, &ha->flags) ||
Nilesh Javali026fbd32013-01-20 23:50:58 -05004096 test_bit(AF_LOOPBACK, &ha->flags) ||
Nilesh Javali7ab284c2013-08-16 07:03:03 -04004097 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4098 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304099 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08004100 goto qc_host_busy;
4101
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004102 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004103 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004104 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004105
4106 rval = qla4xxx_send_command_to_isp(ha, srb);
4107 if (rval != QLA_SUCCESS)
4108 goto qc_host_busy_free_sp;
4109
David Somayajuluafaf5a22006-09-19 10:28:00 -07004110 return 0;
4111
4112qc_host_busy_free_sp:
4113 qla4xxx_srb_free_dma(ha, srb);
4114 mempool_free(srb, ha->srb_mempool);
4115
David Somayajuluafaf5a22006-09-19 10:28:00 -07004116qc_host_busy:
4117 return SCSI_MLQUEUE_HOST_BUSY;
4118
4119qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004120 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004121
4122 return 0;
4123}
4124
4125/**
4126 * qla4xxx_mem_free - frees memory allocated to adapter
4127 * @ha: Pointer to host adapter structure.
4128 *
4129 * Frees memory previously allocated by qla4xxx_mem_alloc
4130 **/
4131static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4132{
4133 if (ha->queues)
4134 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4135 ha->queues_dma);
4136
Tej Parkash068237c82012-05-18 04:41:44 -04004137 if (ha->fw_dump)
4138 vfree(ha->fw_dump);
4139
David Somayajuluafaf5a22006-09-19 10:28:00 -07004140 ha->queues_len = 0;
4141 ha->queues = NULL;
4142 ha->queues_dma = 0;
4143 ha->request_ring = NULL;
4144 ha->request_dma = 0;
4145 ha->response_ring = NULL;
4146 ha->response_dma = 0;
4147 ha->shadow_regs = NULL;
4148 ha->shadow_regs_dma = 0;
Tej Parkash068237c82012-05-18 04:41:44 -04004149 ha->fw_dump = NULL;
4150 ha->fw_dump_size = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004151
4152 /* Free srb pool. */
4153 if (ha->srb_mempool)
4154 mempool_destroy(ha->srb_mempool);
4155
4156 ha->srb_mempool = NULL;
4157
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004158 if (ha->chap_dma_pool)
4159 dma_pool_destroy(ha->chap_dma_pool);
4160
Lalit Chandivade45494152011-10-07 16:55:42 -07004161 if (ha->chap_list)
4162 vfree(ha->chap_list);
4163 ha->chap_list = NULL;
4164
Mike Christie13483732011-12-01 21:38:41 -06004165 if (ha->fw_ddb_dma_pool)
4166 dma_pool_destroy(ha->fw_ddb_dma_pool);
4167
David Somayajuluafaf5a22006-09-19 10:28:00 -07004168 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304169 if (is_qla8022(ha)) {
4170 if (ha->nx_pcibase)
4171 iounmap(
4172 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004173 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004174 if (ha->nx_pcibase)
4175 iounmap(
4176 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4177 } else if (ha->reg) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004178 iounmap(ha->reg);
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004179 }
4180
4181 if (ha->reset_tmplt.buff)
4182 vfree(ha->reset_tmplt.buff);
4183
David Somayajuluafaf5a22006-09-19 10:28:00 -07004184 pci_release_regions(ha->pdev);
4185}
4186
4187/**
4188 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4189 * @ha: Pointer to host adapter structure
4190 *
4191 * Allocates DMA memory for request and response queues. Also allocates memory
4192 * for srbs.
4193 **/
4194static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4195{
4196 unsigned long align;
4197
4198 /* Allocate contiguous block of DMA memory for queues. */
4199 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4200 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4201 sizeof(struct shadow_regs) +
4202 MEM_ALIGN_VALUE +
4203 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4204 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4205 &ha->queues_dma, GFP_KERNEL);
4206 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304207 ql4_printk(KERN_WARNING, ha,
4208 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004209
4210 goto mem_alloc_error_exit;
4211 }
4212 memset(ha->queues, 0, ha->queues_len);
4213
4214 /*
4215 * As per RISC alignment requirements -- the bus-address must be a
4216 * multiple of the request-ring size (in bytes).
4217 */
4218 align = 0;
4219 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4220 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4221 (MEM_ALIGN_VALUE - 1));
4222
4223 /* Update request and response queue pointers. */
4224 ha->request_dma = ha->queues_dma + align;
4225 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4226 ha->response_dma = ha->queues_dma + align +
4227 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4228 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4229 (REQUEST_QUEUE_DEPTH *
4230 QUEUE_SIZE));
4231 ha->shadow_regs_dma = ha->queues_dma + align +
4232 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4233 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4234 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4235 (REQUEST_QUEUE_DEPTH *
4236 QUEUE_SIZE) +
4237 (RESPONSE_QUEUE_DEPTH *
4238 QUEUE_SIZE));
4239
4240 /* Allocate memory for srb pool. */
4241 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4242 mempool_free_slab, srb_cachep);
4243 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304244 ql4_printk(KERN_WARNING, ha,
4245 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004246
4247 goto mem_alloc_error_exit;
4248 }
4249
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004250 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4251 CHAP_DMA_BLOCK_SIZE, 8, 0);
4252
4253 if (ha->chap_dma_pool == NULL) {
4254 ql4_printk(KERN_WARNING, ha,
4255 "%s: chap_dma_pool allocation failed..\n", __func__);
4256 goto mem_alloc_error_exit;
4257 }
4258
Mike Christie13483732011-12-01 21:38:41 -06004259 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4260 DDB_DMA_BLOCK_SIZE, 8, 0);
4261
4262 if (ha->fw_ddb_dma_pool == NULL) {
4263 ql4_printk(KERN_WARNING, ha,
4264 "%s: fw_ddb_dma_pool allocation failed..\n",
4265 __func__);
4266 goto mem_alloc_error_exit;
4267 }
4268
David Somayajuluafaf5a22006-09-19 10:28:00 -07004269 return QLA_SUCCESS;
4270
4271mem_alloc_error_exit:
4272 qla4xxx_mem_free(ha);
4273 return QLA_ERROR;
4274}
4275
4276/**
Mike Hernandez4f770832012-01-11 02:44:15 -08004277 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4278 * @ha: adapter block pointer.
4279 *
4280 * Note: The caller should not hold the idc lock.
4281 **/
4282static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4283{
4284 uint32_t temp, temp_state, temp_val;
4285 int status = QLA_SUCCESS;
4286
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004287 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004288
4289 temp_state = qla82xx_get_temp_state(temp);
4290 temp_val = qla82xx_get_temp_val(temp);
4291
4292 if (temp_state == QLA82XX_TEMP_PANIC) {
4293 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4294 " exceeds maximum allowed. Hardware has been shut"
4295 " down.\n", temp_val);
4296 status = QLA_ERROR;
4297 } else if (temp_state == QLA82XX_TEMP_WARN) {
4298 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4299 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4300 " degrees C exceeds operating range."
4301 " Immediate action needed.\n", temp_val);
4302 } else {
4303 if (ha->temperature == QLA82XX_TEMP_WARN)
4304 ql4_printk(KERN_INFO, ha, "Device temperature is"
4305 " now %d degrees C in normal range.\n",
4306 temp_val);
4307 }
4308 ha->temperature = temp_state;
4309 return status;
4310}
4311
4312/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304313 * qla4_8xxx_check_fw_alive - Check firmware health
4314 * @ha: Pointer to host adapter structure.
4315 *
4316 * Context: Interrupt
4317 **/
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004318static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304319{
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004320 uint32_t fw_heartbeat_counter;
4321 int status = QLA_SUCCESS;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304322
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004323 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4324 QLA8XXX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05304325 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4326 if (fw_heartbeat_counter == 0xffffffff) {
4327 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4328 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4329 ha->host_no, __func__));
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004330 return status;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304331 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304332
4333 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4334 ha->seconds_since_last_heartbeat++;
4335 /* FW not alive after 2 seconds */
4336 if (ha->seconds_since_last_heartbeat == 2) {
4337 ha->seconds_since_last_heartbeat = 0;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004338 qla4_8xxx_dump_peg_reg(ha);
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004339 status = QLA_ERROR;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304340 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07004341 } else
4342 ha->seconds_since_last_heartbeat = 0;
4343
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304344 ha->fw_heartbeat_counter = fw_heartbeat_counter;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004345 return status;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304346}
4347
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004348static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4349{
4350 uint32_t halt_status;
4351 int halt_status_unrecoverable = 0;
4352
4353 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4354
4355 if (is_qla8022(ha)) {
4356 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4357 __func__);
4358 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4359 CRB_NIU_XG_PAUSE_CTL_P0 |
4360 CRB_NIU_XG_PAUSE_CTL_P1);
4361
4362 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4363 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4364 __func__);
4365 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4366 halt_status_unrecoverable = 1;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004367 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004368 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4369 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4370 __func__);
4371 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4372 halt_status_unrecoverable = 1;
4373 }
4374
4375 /*
4376 * Since we cannot change dev_state in interrupt context,
4377 * set appropriate DPC flag then wakeup DPC
4378 */
4379 if (halt_status_unrecoverable) {
4380 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4381 } else {
4382 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4383 __func__);
4384 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4385 }
4386 qla4xxx_mailbox_premature_completion(ha);
4387 qla4xxx_wake_dpc(ha);
4388}
4389
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304390/**
4391 * qla4_8xxx_watchdog - Poll dev state
4392 * @ha: Pointer to host adapter structure.
4393 *
4394 * Context: Interrupt
4395 **/
4396void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4397{
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004398 uint32_t dev_state;
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004399 uint32_t idc_ctrl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304400
Vikas Chaudharya083e8b2013-12-16 06:49:32 -05004401 if (is_qla8032(ha) &&
4402 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4403 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4404 __func__, ha->func_num);
4405
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304406 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08004407 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4408 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07004409 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004410 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004411
4412 if (qla4_8xxx_check_temp(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004413 if (is_qla8022(ha)) {
4414 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4415 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4416 CRB_NIU_XG_PAUSE_CTL_P0 |
4417 CRB_NIU_XG_PAUSE_CTL_P1);
4418 }
Mike Hernandez4f770832012-01-11 02:44:15 -08004419 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4420 qla4xxx_wake_dpc(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004421 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004422 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004423
4424 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4425 __func__);
4426
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004427 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004428 idc_ctrl = qla4_83xx_rd_reg(ha,
4429 QLA83XX_IDC_DRV_CTRL);
4430 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4431 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4432 __func__);
4433 qla4xxx_mailbox_premature_completion(
4434 ha);
4435 }
4436 }
4437
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004438 if ((is_qla8032(ha) || is_qla8042(ha)) ||
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004439 (is_qla8022(ha) && !ql4xdontresethba)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004440 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4441 qla4xxx_wake_dpc(ha);
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004442 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004443 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304444 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004445 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4446 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304447 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4448 qla4xxx_wake_dpc(ha);
4449 } else {
4450 /* Check firmware health */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004451 if (qla4_8xxx_check_fw_alive(ha))
4452 qla4_8xxx_process_fw_error(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304453 }
4454 }
4455}
4456
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004457static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
Mike Christie13483732011-12-01 21:38:41 -06004458{
4459 struct iscsi_session *sess;
4460 struct ddb_entry *ddb_entry;
4461 struct scsi_qla_host *ha;
4462
4463 sess = cls_sess->dd_data;
4464 ddb_entry = sess->dd_data;
4465 ha = ddb_entry->ha;
4466
4467 if (!(ddb_entry->ddb_type == FLASH_DDB))
4468 return;
4469
4470 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4471 !iscsi_is_session_online(cls_sess)) {
4472 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4473 INVALID_ENTRY) {
4474 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4475 0) {
4476 atomic_set(&ddb_entry->retry_relogin_timer,
4477 INVALID_ENTRY);
4478 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4479 set_bit(DF_RELOGIN, &ddb_entry->flags);
4480 DEBUG2(ql4_printk(KERN_INFO, ha,
4481 "%s: index [%d] login device\n",
4482 __func__, ddb_entry->fw_ddb_index));
4483 } else
4484 atomic_dec(&ddb_entry->retry_relogin_timer);
4485 }
4486 }
4487
4488 /* Wait for relogin to timeout */
4489 if (atomic_read(&ddb_entry->relogin_timer) &&
4490 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4491 /*
4492 * If the relogin times out and the device is
4493 * still NOT ONLINE then try and relogin again.
4494 */
4495 if (!iscsi_is_session_online(cls_sess)) {
4496 /* Reset retry relogin timer */
4497 atomic_inc(&ddb_entry->relogin_retry_count);
4498 DEBUG2(ql4_printk(KERN_INFO, ha,
4499 "%s: index[%d] relogin timed out-retrying"
4500 " relogin (%d), retry (%d)\n", __func__,
4501 ddb_entry->fw_ddb_index,
4502 atomic_read(&ddb_entry->relogin_retry_count),
4503 ddb_entry->default_time2wait + 4));
4504 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4505 atomic_set(&ddb_entry->retry_relogin_timer,
4506 ddb_entry->default_time2wait + 4);
4507 }
4508 }
4509}
4510
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304511/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004512 * qla4xxx_timer - checks every second for work to do.
4513 * @ha: Pointer to host adapter structure.
4514 **/
4515static void qla4xxx_timer(struct scsi_qla_host *ha)
4516{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004517 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304518 uint16_t w;
4519
Mike Christie13483732011-12-01 21:38:41 -06004520 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4521
Lalit Chandivade2232be02010-07-30 14:38:47 +05304522 /* If we are in the middle of AER/EEH processing
4523 * skip any processing and reschedule the timer
4524 */
4525 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4526 mod_timer(&ha->timer, jiffies + HZ);
4527 return;
4528 }
4529
4530 /* Hardware read to trigger an EEH error during mailbox waits. */
4531 if (!pci_channel_offline(ha->pdev))
4532 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004533
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004534 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304535 qla4_8xxx_watchdog(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304536
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004537 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304538 /* Check for heartbeat interval. */
4539 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4540 ha->heartbeat_interval != 0) {
4541 ha->seconds_since_last_heartbeat++;
4542 if (ha->seconds_since_last_heartbeat >
4543 ha->heartbeat_interval + 2)
4544 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4545 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004546 }
4547
Vikas Chaudharyff884432011-08-29 23:43:02 +05304548 /* Process any deferred work. */
4549 if (!list_empty(&ha->work_list))
4550 start_dpc++;
4551
David Somayajuluafaf5a22006-09-19 10:28:00 -07004552 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07004553 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004554 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4555 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4556 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304557 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004558 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4559 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05304560 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304561 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4562 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Nilesh Javali906cbf32014-04-09 21:12:25 -04004563 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07004564 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004565 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4566 " - dpc flags = 0x%lx\n",
4567 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304568 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004569 }
4570
4571 /* Reschedule timer thread to call us back in one second */
4572 mod_timer(&ha->timer, jiffies + HZ);
4573
4574 DEBUG2(ha->seconds_since_last_intr++);
4575}
4576
4577/**
4578 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4579 * @ha: Pointer to host adapter structure.
4580 *
4581 * This routine stalls the driver until all outstanding commands are returned.
4582 * Caller must release the Hardware Lock prior to calling this routine.
4583 **/
4584static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4585{
4586 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004587 unsigned long flags;
4588 struct scsi_cmnd *cmd;
Tej Parkash61d9a2b2013-12-16 06:49:43 -05004589 unsigned long wtime;
4590 uint32_t wtmo;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004591
Tej Parkash61d9a2b2013-12-16 06:49:43 -05004592 if (is_qla40XX(ha))
4593 wtmo = WAIT_CMD_TOV;
4594 else
4595 wtmo = ha->nx_reset_timeout / 2;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304596
Tej Parkash61d9a2b2013-12-16 06:49:43 -05004597 wtime = jiffies + (wtmo * HZ);
4598
4599 DEBUG2(ql4_printk(KERN_INFO, ha,
4600 "Wait up to %u seconds for cmds to complete\n",
4601 wtmo));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304602
4603 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004604 spin_lock_irqsave(&ha->hardware_lock, flags);
4605 /* Find a command that hasn't completed. */
4606 for (index = 0; index < ha->host->can_queue; index++) {
4607 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07004608 /*
4609 * We cannot just check if the index is valid,
4610 * becase if we are run from the scsi eh, then
4611 * the scsi/block layer is going to prevent
4612 * the tag from being released.
4613 */
4614 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07004615 break;
4616 }
4617 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4618
4619 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304620 if (index == ha->host->can_queue)
4621 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004622
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304623 msleep(1000);
4624 }
4625 /* If we timed out on waiting for commands to come back
4626 * return ERROR. */
4627 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004628}
4629
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304630int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004631{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004632 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004633 unsigned long flags = 0;
4634
4635 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004636
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304637 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4638 return QLA_ERROR;
4639
David Somayajuluafaf5a22006-09-19 10:28:00 -07004640 spin_lock_irqsave(&ha->hardware_lock, flags);
4641
4642 /*
4643 * If the SCSI Reset Interrupt bit is set, clear it.
4644 * Otherwise, the Soft Reset won't work.
4645 */
4646 ctrl_status = readw(&ha->reg->ctrl_status);
4647 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4648 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4649
4650 /* Issue Soft Reset */
4651 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4652 readl(&ha->reg->ctrl_status);
4653
4654 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304655 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004656}
4657
4658/**
4659 * qla4xxx_soft_reset - performs soft reset.
4660 * @ha: Pointer to host adapter structure.
4661 **/
4662int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4663{
4664 uint32_t max_wait_time;
4665 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004666 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004667 uint32_t ctrl_status;
4668
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004669 status = qla4xxx_hw_reset(ha);
4670 if (status != QLA_SUCCESS)
4671 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004672
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004673 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004674 /* Wait until the Network Reset Intr bit is cleared */
4675 max_wait_time = RESET_INTR_TOV;
4676 do {
4677 spin_lock_irqsave(&ha->hardware_lock, flags);
4678 ctrl_status = readw(&ha->reg->ctrl_status);
4679 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4680
4681 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4682 break;
4683
4684 msleep(1000);
4685 } while ((--max_wait_time));
4686
4687 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4688 DEBUG2(printk(KERN_WARNING
4689 "scsi%ld: Network Reset Intr not cleared by "
4690 "Network function, clearing it now!\n",
4691 ha->host_no));
4692 spin_lock_irqsave(&ha->hardware_lock, flags);
4693 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4694 readl(&ha->reg->ctrl_status);
4695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4696 }
4697
4698 /* Wait until the firmware tells us the Soft Reset is done */
4699 max_wait_time = SOFT_RESET_TOV;
4700 do {
4701 spin_lock_irqsave(&ha->hardware_lock, flags);
4702 ctrl_status = readw(&ha->reg->ctrl_status);
4703 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4704
4705 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4706 status = QLA_SUCCESS;
4707 break;
4708 }
4709
4710 msleep(1000);
4711 } while ((--max_wait_time));
4712
4713 /*
4714 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4715 * after the soft reset has taken place.
4716 */
4717 spin_lock_irqsave(&ha->hardware_lock, flags);
4718 ctrl_status = readw(&ha->reg->ctrl_status);
4719 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4720 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4721 readl(&ha->reg->ctrl_status);
4722 }
4723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4724
4725 /* If soft reset fails then most probably the bios on other
4726 * function is also enabled.
4727 * Since the initialization is sequential the other fn
4728 * wont be able to acknowledge the soft reset.
4729 * Issue a force soft reset to workaround this scenario.
4730 */
4731 if (max_wait_time == 0) {
4732 /* Issue Force Soft Reset */
4733 spin_lock_irqsave(&ha->hardware_lock, flags);
4734 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4735 readl(&ha->reg->ctrl_status);
4736 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4737 /* Wait until the firmware tells us the Soft Reset is done */
4738 max_wait_time = SOFT_RESET_TOV;
4739 do {
4740 spin_lock_irqsave(&ha->hardware_lock, flags);
4741 ctrl_status = readw(&ha->reg->ctrl_status);
4742 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4743
4744 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4745 status = QLA_SUCCESS;
4746 break;
4747 }
4748
4749 msleep(1000);
4750 } while ((--max_wait_time));
4751 }
4752
4753 return status;
4754}
4755
4756/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304757 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004758 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304759 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07004760 *
4761 * This routine is called just prior to a HARD RESET to return all
4762 * outstanding commands back to the Operating System.
4763 * Caller should make sure that the following locks are released
4764 * before this calling routine: Hardware lock, and io_request_lock.
4765 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304766static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004767{
4768 struct srb *srb;
4769 int i;
4770 unsigned long flags;
4771
4772 spin_lock_irqsave(&ha->hardware_lock, flags);
4773 for (i = 0; i < ha->host->can_queue; i++) {
4774 srb = qla4xxx_del_from_active_array(ha, i);
4775 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304776 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304777 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004778 }
4779 }
4780 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004781}
4782
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304783void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4784{
4785 clear_bit(AF_ONLINE, &ha->flags);
4786
4787 /* Disable the board */
4788 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304789
4790 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4791 qla4xxx_mark_all_devices_missing(ha);
4792 clear_bit(AF_INIT_DONE, &ha->flags);
4793}
4794
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004795static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4796{
4797 struct iscsi_session *sess;
4798 struct ddb_entry *ddb_entry;
4799
4800 sess = cls_session->dd_data;
4801 ddb_entry = sess->dd_data;
4802 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
Mike Christie13483732011-12-01 21:38:41 -06004803
4804 if (ddb_entry->ddb_type == FLASH_DDB)
4805 iscsi_block_session(ddb_entry->sess);
4806 else
4807 iscsi_session_failure(cls_session->dd_data,
4808 ISCSI_ERR_CONN_FAILED);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004809}
4810
David Somayajuluafaf5a22006-09-19 10:28:00 -07004811/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004812 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4813 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004814 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304815static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004816{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304817 int status = QLA_ERROR;
4818 uint8_t reset_chip = 0;
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004819 uint32_t dev_state;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004820 unsigned long wait;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004821
4822 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304823 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004824 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004825 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06004826
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304827 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004828
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304829 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004830
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004831 if ((is_qla8032(ha) || is_qla8042(ha)) &&
Tej Parkash546fef22012-09-20 07:35:12 -04004832 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4833 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4834 __func__);
4835 /* disable pause frame for ISP83xx */
4836 qla4_83xx_disable_pause(ha);
4837 }
4838
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004839 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4840
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304841 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4842 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004843
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304844 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4845 * do not reset adapter, jump to initialize_adapter */
4846 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4847 status = QLA_SUCCESS;
4848 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004849 }
4850
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004851 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304852 * from eh_host_reset or ioctl module */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004853 if (is_qla80XX(ha) && !reset_chip &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304854 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4855
4856 DEBUG2(ql4_printk(KERN_INFO, ha,
4857 "scsi%ld: %s - Performing stop_firmware...\n",
4858 ha->host_no, __func__));
4859 status = ha->isp_ops->reset_firmware(ha);
4860 if (status == QLA_SUCCESS) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304861 ha->isp_ops->disable_intrs(ha);
4862 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4863 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4864 } else {
4865 /* If the stop_firmware fails then
4866 * reset the entire chip */
4867 reset_chip = 1;
4868 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4869 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4870 }
4871 }
4872
4873 /* Issue full chip reset if recovering from a catastrophic error,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004874 * or if stop_firmware fails for ISP-8xxx.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304875 * This is the default case for ISP-4xxx */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004876 if (is_qla40XX(ha) || reset_chip) {
4877 if (is_qla40XX(ha))
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004878 goto chip_reset;
4879
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004880 /* Check if 8XXX firmware is alive or not
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004881 * We may have arrived here from NEED_RESET
4882 * detection only */
4883 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4884 goto chip_reset;
4885
4886 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4887 while (time_before(jiffies, wait)) {
4888 if (qla4_8xxx_check_fw_alive(ha)) {
4889 qla4xxx_mailbox_premature_completion(ha);
4890 break;
4891 }
4892
4893 set_current_state(TASK_UNINTERRUPTIBLE);
4894 schedule_timeout(HZ);
4895 }
Vikas Chaudharyda106212012-08-22 07:45:26 -04004896chip_reset:
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004897 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4898 qla4xxx_cmd_wait(ha);
Vikas Chaudharyda106212012-08-22 07:45:26 -04004899
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304900 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304901 DEBUG2(ql4_printk(KERN_INFO, ha,
4902 "scsi%ld: %s - Performing chip reset..\n",
4903 ha->host_no, __func__));
4904 status = ha->isp_ops->reset_chip(ha);
Tej Parkash61d9a2b2013-12-16 06:49:43 -05004905 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304906 }
4907
4908 /* Flush any pending ddb changed AENs */
4909 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4910
4911recover_ha_init_adapter:
4912 /* Upon successful firmware/chip reset, re-initialize the adapter */
4913 if (status == QLA_SUCCESS) {
4914 /* For ISP-4xxx, force function 1 to always initialize
4915 * before function 3 to prevent both funcions from
4916 * stepping on top of the other */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004917 if (is_qla40XX(ha) && (ha->mac_index == 3))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304918 ssleep(6);
4919
4920 /* NOTE: AF_ONLINE flag set upon successful completion of
Nilesh Javali37418cc2013-12-16 06:49:31 -05004921 * qla4xxx_initialize_adapter */
Mike Christie13483732011-12-01 21:38:41 -06004922 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Nilesh Javali37418cc2013-12-16 06:49:31 -05004923 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4924 status = qla4_8xxx_check_init_adapter_retry(ha);
4925 if (status == QLA_ERROR) {
4926 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4927 ha->host_no, __func__);
4928 qla4xxx_dead_adapter_cleanup(ha);
4929 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4930 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4931 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4932 &ha->dpc_flags);
4933 goto exit_recover;
4934 }
4935 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304936 }
4937
4938 /* Retry failed adapter initialization, if necessary
4939 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4940 * case to prevent ping-pong resets between functions */
4941 if (!test_bit(AF_ONLINE, &ha->flags) &&
4942 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004943 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304944 * resetting the ha.
4945 * Since we don't want to block the DPC for too long
4946 * with multiple resets in the same thread,
4947 * utilize DPC to retry */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004948 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004949 ha->isp_ops->idc_lock(ha);
4950 dev_state = qla4_8xxx_rd_direct(ha,
4951 QLA8XXX_CRB_DEV_STATE);
4952 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004953 if (dev_state == QLA8XXX_DEV_FAILED) {
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004954 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4955 "recover adapter. H/W is in Failed "
4956 "state\n", __func__);
4957 qla4xxx_dead_adapter_cleanup(ha);
4958 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4959 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4960 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4961 &ha->dpc_flags);
4962 status = QLA_ERROR;
4963
4964 goto exit_recover;
4965 }
4966 }
4967
David Somayajuluafaf5a22006-09-19 10:28:00 -07004968 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4969 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4970 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4971 "(%d) more times\n", ha->host_no,
4972 ha->retry_reset_ha_cnt));
4973 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4974 status = QLA_ERROR;
4975 } else {
4976 if (ha->retry_reset_ha_cnt > 0) {
4977 /* Schedule another Reset HA--DPC will retry */
4978 ha->retry_reset_ha_cnt--;
4979 DEBUG2(printk("scsi%ld: recover adapter - "
4980 "retry remaining %d\n",
4981 ha->host_no,
4982 ha->retry_reset_ha_cnt));
4983 status = QLA_ERROR;
4984 }
4985
4986 if (ha->retry_reset_ha_cnt == 0) {
4987 /* Recover adapter retries have been exhausted.
4988 * Adapter DEAD */
4989 DEBUG2(printk("scsi%ld: recover adapter "
4990 "failed - board disabled\n",
4991 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304992 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004993 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4994 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304995 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004996 &ha->dpc_flags);
4997 status = QLA_ERROR;
4998 }
4999 }
5000 } else {
5001 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305002 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005003 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5004 }
5005
Sarang Radke8e0f3a62011-12-01 22:42:09 -08005006exit_recover:
David Somayajuluafaf5a22006-09-19 10:28:00 -07005007 ha->adapter_error_count++;
5008
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305009 if (test_bit(AF_ONLINE, &ha->flags))
5010 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005011
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305012 scsi_unblock_requests(ha->host);
5013
5014 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5015 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005016 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305017
David Somayajuluafaf5a22006-09-19 10:28:00 -07005018 return status;
5019}
5020
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005021static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005022{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005023 struct iscsi_session *sess;
5024 struct ddb_entry *ddb_entry;
5025 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005026
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005027 sess = cls_session->dd_data;
5028 ddb_entry = sess->dd_data;
5029 ha = ddb_entry->ha;
5030 if (!iscsi_is_session_online(cls_session)) {
5031 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5032 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5033 " unblock session\n", ha->host_no, __func__,
5034 ddb_entry->fw_ddb_index);
5035 iscsi_unblock_session(ddb_entry->sess);
5036 } else {
5037 /* Trigger relogin */
Mike Christie13483732011-12-01 21:38:41 -06005038 if (ddb_entry->ddb_type == FLASH_DDB) {
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04005039 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5040 test_bit(DF_DISABLE_RELOGIN,
5041 &ddb_entry->flags)))
Mike Christie13483732011-12-01 21:38:41 -06005042 qla4xxx_arm_relogin_timer(ddb_entry);
5043 } else
5044 iscsi_session_failure(cls_session->dd_data,
5045 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005046 }
5047 }
5048}
5049
Mike Christie13483732011-12-01 21:38:41 -06005050int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5051{
5052 struct iscsi_session *sess;
5053 struct ddb_entry *ddb_entry;
5054 struct scsi_qla_host *ha;
5055
5056 sess = cls_session->dd_data;
5057 ddb_entry = sess->dd_data;
5058 ha = ddb_entry->ha;
5059 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5060 " unblock session\n", ha->host_no, __func__,
5061 ddb_entry->fw_ddb_index);
5062
5063 iscsi_unblock_session(ddb_entry->sess);
5064
5065 /* Start scan target */
5066 if (test_bit(AF_ONLINE, &ha->flags)) {
5067 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5068 " start scan\n", ha->host_no, __func__,
5069 ddb_entry->fw_ddb_index);
5070 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5071 }
5072 return QLA_SUCCESS;
5073}
5074
5075int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5076{
5077 struct iscsi_session *sess;
5078 struct ddb_entry *ddb_entry;
5079 struct scsi_qla_host *ha;
Manish Rangankar80c53e62012-08-07 07:57:15 -04005080 int status = QLA_SUCCESS;
Mike Christie13483732011-12-01 21:38:41 -06005081
5082 sess = cls_session->dd_data;
5083 ddb_entry = sess->dd_data;
5084 ha = ddb_entry->ha;
5085 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5086 " unblock user space session\n", ha->host_no, __func__,
5087 ddb_entry->fw_ddb_index);
Mike Christie13483732011-12-01 21:38:41 -06005088
Manish Rangankar80c53e62012-08-07 07:57:15 -04005089 if (!iscsi_is_session_online(cls_session)) {
5090 iscsi_conn_start(ddb_entry->conn);
5091 iscsi_conn_login_event(ddb_entry->conn,
5092 ISCSI_CONN_STATE_LOGGED_IN);
5093 } else {
5094 ql4_printk(KERN_INFO, ha,
5095 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5096 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5097 cls_session->sid);
5098 status = QLA_ERROR;
5099 }
5100
5101 return status;
Mike Christie13483732011-12-01 21:38:41 -06005102}
5103
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005104static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5105{
5106 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5107}
5108
Mike Christie13483732011-12-01 21:38:41 -06005109static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5110{
5111 uint16_t relogin_timer;
5112 struct iscsi_session *sess;
5113 struct ddb_entry *ddb_entry;
5114 struct scsi_qla_host *ha;
5115
5116 sess = cls_sess->dd_data;
5117 ddb_entry = sess->dd_data;
5118 ha = ddb_entry->ha;
5119
5120 relogin_timer = max(ddb_entry->default_relogin_timeout,
5121 (uint16_t)RELOGIN_TOV);
5122 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5123
5124 DEBUG2(ql4_printk(KERN_INFO, ha,
5125 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5126 ddb_entry->fw_ddb_index, relogin_timer));
5127
5128 qla4xxx_login_flash_ddb(cls_sess);
5129}
5130
5131static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5132{
5133 struct iscsi_session *sess;
5134 struct ddb_entry *ddb_entry;
5135 struct scsi_qla_host *ha;
5136
5137 sess = cls_sess->dd_data;
5138 ddb_entry = sess->dd_data;
5139 ha = ddb_entry->ha;
5140
5141 if (!(ddb_entry->ddb_type == FLASH_DDB))
5142 return;
5143
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04005144 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5145 return;
5146
Mike Christie13483732011-12-01 21:38:41 -06005147 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5148 !iscsi_is_session_online(cls_sess)) {
5149 DEBUG2(ql4_printk(KERN_INFO, ha,
5150 "relogin issued\n"));
5151 qla4xxx_relogin_flash_ddb(cls_sess);
5152 }
5153}
5154
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305155void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5156{
Lalit Chandivade1b468072011-05-17 23:17:09 -07005157 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305158 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305159}
5160
Vikas Chaudharyff884432011-08-29 23:43:02 +05305161static struct qla4_work_evt *
5162qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5163 enum qla4_work_type type)
5164{
5165 struct qla4_work_evt *e;
5166 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5167
5168 e = kzalloc(size, GFP_ATOMIC);
5169 if (!e)
5170 return NULL;
5171
5172 INIT_LIST_HEAD(&e->list);
5173 e->type = type;
5174 return e;
5175}
5176
5177static void qla4xxx_post_work(struct scsi_qla_host *ha,
5178 struct qla4_work_evt *e)
5179{
5180 unsigned long flags;
5181
5182 spin_lock_irqsave(&ha->work_lock, flags);
5183 list_add_tail(&e->list, &ha->work_list);
5184 spin_unlock_irqrestore(&ha->work_lock, flags);
5185 qla4xxx_wake_dpc(ha);
5186}
5187
5188int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5189 enum iscsi_host_event_code aen_code,
5190 uint32_t data_size, uint8_t *data)
5191{
5192 struct qla4_work_evt *e;
5193
5194 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5195 if (!e)
5196 return QLA_ERROR;
5197
5198 e->u.aen.code = aen_code;
5199 e->u.aen.data_size = data_size;
5200 memcpy(e->u.aen.data, data, data_size);
5201
5202 qla4xxx_post_work(ha, e);
5203
5204 return QLA_SUCCESS;
5205}
5206
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05305207int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5208 uint32_t status, uint32_t pid,
5209 uint32_t data_size, uint8_t *data)
5210{
5211 struct qla4_work_evt *e;
5212
5213 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5214 if (!e)
5215 return QLA_ERROR;
5216
5217 e->u.ping.status = status;
5218 e->u.ping.pid = pid;
5219 e->u.ping.data_size = data_size;
5220 memcpy(e->u.ping.data, data, data_size);
5221
5222 qla4xxx_post_work(ha, e);
5223
5224 return QLA_SUCCESS;
5225}
5226
Vikas Chaudharya7380a62012-02-27 03:08:56 -08005227static void qla4xxx_do_work(struct scsi_qla_host *ha)
Vikas Chaudharyff884432011-08-29 23:43:02 +05305228{
5229 struct qla4_work_evt *e, *tmp;
5230 unsigned long flags;
5231 LIST_HEAD(work);
5232
5233 spin_lock_irqsave(&ha->work_lock, flags);
5234 list_splice_init(&ha->work_list, &work);
5235 spin_unlock_irqrestore(&ha->work_lock, flags);
5236
5237 list_for_each_entry_safe(e, tmp, &work, list) {
5238 list_del_init(&e->list);
5239
5240 switch (e->type) {
5241 case QLA4_EVENT_AEN:
5242 iscsi_post_host_event(ha->host_no,
5243 &qla4xxx_iscsi_transport,
5244 e->u.aen.code,
5245 e->u.aen.data_size,
5246 e->u.aen.data);
5247 break;
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05305248 case QLA4_EVENT_PING_STATUS:
5249 iscsi_ping_comp_event(ha->host_no,
5250 &qla4xxx_iscsi_transport,
5251 e->u.ping.status,
5252 e->u.ping.pid,
5253 e->u.ping.data_size,
5254 e->u.ping.data);
5255 break;
Vikas Chaudharyff884432011-08-29 23:43:02 +05305256 default:
5257 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5258 "supported", e->type);
5259 }
5260 kfree(e);
5261 }
5262}
5263
David Somayajuluafaf5a22006-09-19 10:28:00 -07005264/**
5265 * qla4xxx_do_dpc - dpc routine
5266 * @data: in our case pointer to adapter structure
5267 *
5268 * This routine is a task that is schedule by the interrupt handler
5269 * to perform the background processing for interrupts. We put it
5270 * on a task queue that is consumed whenever the scheduler runs; that's
5271 * so you can do anything (i.e. put the process to sleep etc). In fact,
5272 * the mid-level tries to sleep when it reaches the driver threshold
5273 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5274 **/
David Howellsc4028952006-11-22 14:57:56 +00005275static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005276{
David Howellsc4028952006-11-22 14:57:56 +00005277 struct scsi_qla_host *ha =
5278 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005279 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005280
Vikas Chaudharya7e56882013-12-16 06:49:51 -05005281 DEBUG2(ql4_printk(KERN_INFO, ha,
5282 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5283 ha->host_no, __func__, ha->flags, ha->dpc_flags));
David Somayajuluafaf5a22006-09-19 10:28:00 -07005284
5285 /* Initialization not yet finished. Don't do anything yet. */
5286 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07005287 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005288
Lalit Chandivade2232be02010-07-30 14:38:47 +05305289 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5290 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5291 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07005292 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05305293 }
5294
Vikas Chaudharyff884432011-08-29 23:43:02 +05305295 /* post events to application */
5296 qla4xxx_do_work(ha);
5297
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005298 if (is_qla80XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305299 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005300 if (is_qla8032(ha) || is_qla8042(ha)) {
Tej Parkash546fef22012-09-20 07:35:12 -04005301 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5302 __func__);
5303 /* disable pause frame for ISP83xx */
5304 qla4_83xx_disable_pause(ha);
5305 }
5306
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005307 ha->isp_ops->idc_lock(ha);
5308 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5309 QLA8XXX_DEV_FAILED);
5310 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305311 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5312 qla4_8xxx_device_state_handler(ha);
5313 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005314
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005315 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5316 if (is_qla8042(ha)) {
5317 if (ha->idc_info.info2 &
5318 ENABLE_INTERNAL_LOOPBACK) {
5319 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5320 __func__);
5321 status = qla4_84xx_config_acb(ha,
5322 ACB_CONFIG_DISABLE);
5323 if (status != QLA_SUCCESS) {
5324 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5325 __func__);
5326 }
5327 }
5328 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005329 qla4_83xx_post_idc_ack(ha);
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005330 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5331 }
5332
5333 if (is_qla8042(ha) &&
5334 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5335 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5336 __func__);
5337 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5338 QLA_SUCCESS) {
5339 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5340 __func__);
5341 }
5342 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5343 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005344
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305345 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5346 qla4_8xxx_need_qsnt_handler(ha);
5347 }
5348 }
5349
5350 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5351 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07005352 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305353 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005354 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005355 ((is_qla8032(ha) || is_qla8042(ha)) &&
5356 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305357 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5358 ha->host_no, __func__));
5359 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5360 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5361 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5362 goto dpc_post_reset_ha;
5363 }
5364 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5365 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5366 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005367
David C Somayajulu477ffb92007-01-22 12:26:11 -08005368 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07005369 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005370
David Somayajuluafaf5a22006-09-19 10:28:00 -07005371 while ((readw(&ha->reg->ctrl_status) &
5372 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5373 if (--wait_time == 0)
5374 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005375 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005376 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005377 if (wait_time == 0)
5378 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5379 "bit not cleared-- resetting\n",
5380 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305381 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005382 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5383 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305384 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005385 }
5386 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5387 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305388 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005389 }
5390 }
5391
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305392dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07005393 /* ---- process AEN? --- */
5394 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5395 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5396
5397 /* ---- Get DHCP IP Address? --- */
5398 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5399 qla4xxx_get_dhcp_ip_address(ha);
5400
Mike Christie13483732011-12-01 21:38:41 -06005401 /* ---- relogin device? --- */
5402 if (adapter_up(ha) &&
5403 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5404 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5405 }
5406
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305407 /* ---- link change? --- */
Nilesh Javali026fbd32013-01-20 23:50:58 -05005408 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5409 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305410 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5411 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005412 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305413 } else {
5414 /* ---- link up? --- *
5415 * F/W will auto login to all devices ONLY ONCE after
5416 * link up during driver initialization and runtime
5417 * fatal error recovery. Therefore, the driver must
5418 * manually relogin to devices when recovering from
5419 * connection failures, logouts, expired KATO, etc. */
Mike Christie13483732011-12-01 21:38:41 -06005420 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5421 qla4xxx_build_ddb_list(ha, ha->is_reset);
5422 iscsi_host_for_each_session(ha->host,
5423 qla4xxx_login_flash_ddb);
5424 } else
5425 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305426 }
5427 }
Nilesh Javali906cbf32014-04-09 21:12:25 -04005428 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5429 if (qla4xxx_sysfs_ddb_export(ha))
5430 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5431 __func__);
5432 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005433}
5434
5435/**
5436 * qla4xxx_free_adapter - release the adapter
5437 * @ha: pointer to adapter structure
5438 **/
5439static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5440{
Sarang Radke8a28896012011-12-06 02:34:10 -08005441 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005442
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005443 /* Turn-off interrupts on the card. */
5444 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005445
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005446 if (is_qla40XX(ha)) {
5447 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5448 &ha->reg->ctrl_status);
5449 readl(&ha->reg->ctrl_status);
5450 } else if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005451 writel(0, &ha->qla4_82xx_reg->host_int);
5452 readl(&ha->qla4_82xx_reg->host_int);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005453 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudharyfbd81072012-09-20 07:35:03 -04005454 writel(0, &ha->qla4_83xx_reg->risc_intr);
5455 readl(&ha->qla4_83xx_reg->risc_intr);
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005456 }
5457
David Somayajuluafaf5a22006-09-19 10:28:00 -07005458 /* Remove timer thread, if present */
5459 if (ha->timer_active)
5460 qla4xxx_stop_timer(ha);
5461
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305462 /* Kill the kernel thread for this host */
5463 if (ha->dpc_thread)
5464 destroy_workqueue(ha->dpc_thread);
5465
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005466 /* Kill the kernel thread for this host */
5467 if (ha->task_wq)
5468 destroy_workqueue(ha->task_wq);
5469
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305470 /* Put firmware in known state */
5471 ha->isp_ops->reset_firmware(ha);
5472
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005473 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005474 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305475 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005476 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305477 }
5478
David Somayajuluafaf5a22006-09-19 10:28:00 -07005479 /* Detach interrupts */
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005480 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005481
David C Somayajulubee4fe82007-05-23 18:03:32 -07005482 /* free extra memory */
5483 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305484}
David C Somayajulubee4fe82007-05-23 18:03:32 -07005485
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305486int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5487{
5488 int status = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305489 unsigned long mem_base, mem_len, db_base, db_len;
5490 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005491
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305492 status = pci_request_regions(pdev, DRIVER_NAME);
5493 if (status) {
5494 printk(KERN_WARNING
5495 "scsi(%ld) Failed to reserve PIO regions (%s) "
5496 "status=%d\n", ha->host_no, pci_name(pdev), status);
5497 goto iospace_error_exit;
5498 }
5499
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305500 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
Sergei Shtylyov7d7311c2012-03-14 22:04:30 +03005501 __func__, pdev->revision));
5502 ha->revision_id = pdev->revision;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305503
5504 /* remap phys address */
5505 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5506 mem_len = pci_resource_len(pdev, 0);
5507 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5508 __func__, mem_base, mem_len));
5509
5510 /* mapping of pcibase pointer */
5511 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5512 if (!ha->nx_pcibase) {
5513 printk(KERN_ERR
5514 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5515 pci_release_regions(ha->pdev);
5516 goto iospace_error_exit;
5517 }
5518
5519 /* Mapping of IO base pointer, door bell read and write pointer */
5520
5521 /* mapping of IO base pointer */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005522 if (is_qla8022(ha)) {
5523 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5524 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5525 (ha->pdev->devfn << 11));
5526 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5527 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005528 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005529 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5530 ((uint8_t *)ha->nx_pcibase);
5531 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305532
5533 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5534 db_len = pci_resource_len(pdev, 4);
5535
Shyam Sundar2657c802010-10-06 22:50:29 -07005536 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305537iospace_error_exit:
5538 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005539}
5540
5541/***
5542 * qla4xxx_iospace_config - maps registers
5543 * @ha: pointer to adapter structure
5544 *
5545 * This routines maps HBA's registers from the pci address space
5546 * into the kernel virtual address space for memory mapped i/o.
5547 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305548int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005549{
5550 unsigned long pio, pio_len, pio_flags;
5551 unsigned long mmio, mmio_len, mmio_flags;
5552
5553 pio = pci_resource_start(ha->pdev, 0);
5554 pio_len = pci_resource_len(ha->pdev, 0);
5555 pio_flags = pci_resource_flags(ha->pdev, 0);
5556 if (pio_flags & IORESOURCE_IO) {
5557 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305558 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07005559 "Invalid PCI I/O region size\n");
5560 pio = 0;
5561 }
5562 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305563 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005564 pio = 0;
5565 }
5566
5567 /* Use MMIO operations for all accesses. */
5568 mmio = pci_resource_start(ha->pdev, 1);
5569 mmio_len = pci_resource_len(ha->pdev, 1);
5570 mmio_flags = pci_resource_flags(ha->pdev, 1);
5571
5572 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305573 ql4_printk(KERN_ERR, ha,
5574 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005575
5576 goto iospace_error_exit;
5577 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305578
David Somayajuluafaf5a22006-09-19 10:28:00 -07005579 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305580 ql4_printk(KERN_ERR, ha,
5581 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005582 goto iospace_error_exit;
5583 }
5584
5585 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305586 ql4_printk(KERN_WARNING, ha,
5587 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005588
5589 goto iospace_error_exit;
5590 }
5591
5592 ha->pio_address = pio;
5593 ha->pio_length = pio_len;
5594 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5595 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305596 ql4_printk(KERN_ERR, ha,
5597 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005598
5599 goto iospace_error_exit;
5600 }
5601
5602 return 0;
5603
5604iospace_error_exit:
5605 return -ENOMEM;
5606}
5607
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305608static struct isp_operations qla4xxx_isp_ops = {
5609 .iospace_config = qla4xxx_iospace_config,
5610 .pci_config = qla4xxx_pci_config,
5611 .disable_intrs = qla4xxx_disable_intrs,
5612 .enable_intrs = qla4xxx_enable_intrs,
5613 .start_firmware = qla4xxx_start_firmware,
5614 .intr_handler = qla4xxx_intr_handler,
5615 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5616 .reset_chip = qla4xxx_soft_reset,
5617 .reset_firmware = qla4xxx_hw_reset,
5618 .queue_iocb = qla4xxx_queue_iocb,
5619 .complete_iocb = qla4xxx_complete_iocb,
5620 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5621 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5622 .get_sys_info = qla4xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005623 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5624 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305625};
5626
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005627static struct isp_operations qla4_82xx_isp_ops = {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305628 .iospace_config = qla4_8xxx_iospace_config,
5629 .pci_config = qla4_8xxx_pci_config,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005630 .disable_intrs = qla4_82xx_disable_intrs,
5631 .enable_intrs = qla4_82xx_enable_intrs,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305632 .start_firmware = qla4_8xxx_load_risc,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005633 .restart_firmware = qla4_82xx_try_start_fw,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005634 .intr_handler = qla4_82xx_intr_handler,
5635 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005636 .need_reset = qla4_8xxx_need_reset,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005637 .reset_chip = qla4_82xx_isp_reset,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305638 .reset_firmware = qla4_8xxx_stop_firmware,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005639 .queue_iocb = qla4_82xx_queue_iocb,
5640 .complete_iocb = qla4_82xx_complete_iocb,
5641 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5642 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305643 .get_sys_info = qla4_8xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005644 .rd_reg_direct = qla4_82xx_rd_32,
5645 .wr_reg_direct = qla4_82xx_wr_32,
5646 .rd_reg_indirect = qla4_82xx_md_rd_32,
5647 .wr_reg_indirect = qla4_82xx_md_wr_32,
5648 .idc_lock = qla4_82xx_idc_lock,
5649 .idc_unlock = qla4_82xx_idc_unlock,
5650 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5651 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5652 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305653};
5654
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005655static struct isp_operations qla4_83xx_isp_ops = {
5656 .iospace_config = qla4_8xxx_iospace_config,
5657 .pci_config = qla4_8xxx_pci_config,
5658 .disable_intrs = qla4_83xx_disable_intrs,
5659 .enable_intrs = qla4_83xx_enable_intrs,
5660 .start_firmware = qla4_8xxx_load_risc,
5661 .restart_firmware = qla4_83xx_start_firmware,
5662 .intr_handler = qla4_83xx_intr_handler,
5663 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5664 .need_reset = qla4_8xxx_need_reset,
5665 .reset_chip = qla4_83xx_isp_reset,
5666 .reset_firmware = qla4_8xxx_stop_firmware,
5667 .queue_iocb = qla4_83xx_queue_iocb,
5668 .complete_iocb = qla4_83xx_complete_iocb,
Tej Parkasha24058f2013-03-07 05:43:13 -05005669 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5670 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005671 .get_sys_info = qla4_8xxx_get_sys_info,
5672 .rd_reg_direct = qla4_83xx_rd_reg,
5673 .wr_reg_direct = qla4_83xx_wr_reg,
5674 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5675 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5676 .idc_lock = qla4_83xx_drv_lock,
5677 .idc_unlock = qla4_83xx_drv_unlock,
5678 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5679 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5680 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305681};
5682
5683uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5684{
5685 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5686}
5687
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005688uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305689{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005690 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305691}
5692
5693uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5694{
5695 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5696}
5697
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005698uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305699{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005700 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305701}
5702
Manish Rangankar2a991c22011-07-25 13:48:55 -05005703static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5704{
5705 struct scsi_qla_host *ha = data;
5706 char *str = buf;
5707 int rc;
5708
5709 switch (type) {
5710 case ISCSI_BOOT_ETH_FLAGS:
5711 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5712 break;
5713 case ISCSI_BOOT_ETH_INDEX:
5714 rc = sprintf(str, "0\n");
5715 break;
5716 case ISCSI_BOOT_ETH_MAC:
5717 rc = sysfs_format_mac(str, ha->my_mac,
5718 MAC_ADDR_LEN);
5719 break;
5720 default:
5721 rc = -ENOSYS;
5722 break;
5723 }
5724 return rc;
5725}
5726
Al Viro587a1f12011-07-23 23:11:19 -04005727static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005728{
5729 int rc;
5730
5731 switch (type) {
5732 case ISCSI_BOOT_ETH_FLAGS:
5733 case ISCSI_BOOT_ETH_MAC:
5734 case ISCSI_BOOT_ETH_INDEX:
5735 rc = S_IRUGO;
5736 break;
5737 default:
5738 rc = 0;
5739 break;
5740 }
5741 return rc;
5742}
5743
5744static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5745{
5746 struct scsi_qla_host *ha = data;
5747 char *str = buf;
5748 int rc;
5749
5750 switch (type) {
5751 case ISCSI_BOOT_INI_INITIATOR_NAME:
5752 rc = sprintf(str, "%s\n", ha->name_string);
5753 break;
5754 default:
5755 rc = -ENOSYS;
5756 break;
5757 }
5758 return rc;
5759}
5760
Al Viro587a1f12011-07-23 23:11:19 -04005761static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005762{
5763 int rc;
5764
5765 switch (type) {
5766 case ISCSI_BOOT_INI_INITIATOR_NAME:
5767 rc = S_IRUGO;
5768 break;
5769 default:
5770 rc = 0;
5771 break;
5772 }
5773 return rc;
5774}
5775
5776static ssize_t
5777qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5778 char *buf)
5779{
5780 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5781 char *str = buf;
5782 int rc;
5783
5784 switch (type) {
5785 case ISCSI_BOOT_TGT_NAME:
5786 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5787 break;
5788 case ISCSI_BOOT_TGT_IP_ADDR:
5789 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5790 rc = sprintf(buf, "%pI4\n",
5791 &boot_conn->dest_ipaddr.ip_address);
5792 else
5793 rc = sprintf(str, "%pI6\n",
5794 &boot_conn->dest_ipaddr.ip_address);
5795 break;
5796 case ISCSI_BOOT_TGT_PORT:
5797 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5798 break;
5799 case ISCSI_BOOT_TGT_CHAP_NAME:
5800 rc = sprintf(str, "%.*s\n",
5801 boot_conn->chap.target_chap_name_length,
5802 (char *)&boot_conn->chap.target_chap_name);
5803 break;
5804 case ISCSI_BOOT_TGT_CHAP_SECRET:
5805 rc = sprintf(str, "%.*s\n",
5806 boot_conn->chap.target_secret_length,
5807 (char *)&boot_conn->chap.target_secret);
5808 break;
5809 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5810 rc = sprintf(str, "%.*s\n",
5811 boot_conn->chap.intr_chap_name_length,
5812 (char *)&boot_conn->chap.intr_chap_name);
5813 break;
5814 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5815 rc = sprintf(str, "%.*s\n",
5816 boot_conn->chap.intr_secret_length,
5817 (char *)&boot_conn->chap.intr_secret);
5818 break;
5819 case ISCSI_BOOT_TGT_FLAGS:
5820 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5821 break;
5822 case ISCSI_BOOT_TGT_NIC_ASSOC:
5823 rc = sprintf(str, "0\n");
5824 break;
5825 default:
5826 rc = -ENOSYS;
5827 break;
5828 }
5829 return rc;
5830}
5831
5832static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5833{
5834 struct scsi_qla_host *ha = data;
5835 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5836
5837 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5838}
5839
5840static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5841{
5842 struct scsi_qla_host *ha = data;
5843 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5844
5845 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5846}
5847
Al Viro587a1f12011-07-23 23:11:19 -04005848static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005849{
5850 int rc;
5851
5852 switch (type) {
5853 case ISCSI_BOOT_TGT_NAME:
5854 case ISCSI_BOOT_TGT_IP_ADDR:
5855 case ISCSI_BOOT_TGT_PORT:
5856 case ISCSI_BOOT_TGT_CHAP_NAME:
5857 case ISCSI_BOOT_TGT_CHAP_SECRET:
5858 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5859 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5860 case ISCSI_BOOT_TGT_NIC_ASSOC:
5861 case ISCSI_BOOT_TGT_FLAGS:
5862 rc = S_IRUGO;
5863 break;
5864 default:
5865 rc = 0;
5866 break;
5867 }
5868 return rc;
5869}
5870
5871static void qla4xxx_boot_release(void *data)
5872{
5873 struct scsi_qla_host *ha = data;
5874
5875 scsi_host_put(ha->host);
5876}
5877
5878static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5879{
5880 dma_addr_t buf_dma;
5881 uint32_t addr, pri_addr, sec_addr;
5882 uint32_t offset;
5883 uint16_t func_num;
5884 uint8_t val;
5885 uint8_t *buf = NULL;
5886 size_t size = 13 * sizeof(uint8_t);
5887 int ret = QLA_SUCCESS;
5888
5889 func_num = PCI_FUNC(ha->pdev->devfn);
5890
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005891 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5892 __func__, ha->pdev->device, func_num);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005893
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005894 if (is_qla40XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005895 if (func_num == 1) {
5896 addr = NVRAM_PORT0_BOOT_MODE;
5897 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5898 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5899 } else if (func_num == 3) {
5900 addr = NVRAM_PORT1_BOOT_MODE;
5901 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5902 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5903 } else {
5904 ret = QLA_ERROR;
5905 goto exit_boot_info;
5906 }
5907
5908 /* Check Boot Mode */
5909 val = rd_nvram_byte(ha, addr);
5910 if (!(val & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305911 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5912 "options : 0x%x\n", __func__, val));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005913 ret = QLA_ERROR;
5914 goto exit_boot_info;
5915 }
5916
5917 /* get primary valid target index */
5918 val = rd_nvram_byte(ha, pri_addr);
5919 if (val & BIT_7)
5920 ddb_index[0] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005921
5922 /* get secondary valid target index */
5923 val = rd_nvram_byte(ha, sec_addr);
5924 if (val & BIT_7)
5925 ddb_index[1] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005926
Vikas Chaudhary3e788fb2013-03-07 05:43:08 -05005927 } else if (is_qla80XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005928 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5929 &buf_dma, GFP_KERNEL);
5930 if (!buf) {
5931 DEBUG2(ql4_printk(KERN_ERR, ha,
5932 "%s: Unable to allocate dma buffer\n",
5933 __func__));
5934 ret = QLA_ERROR;
5935 goto exit_boot_info;
5936 }
5937
5938 if (ha->port_num == 0)
5939 offset = BOOT_PARAM_OFFSET_PORT0;
5940 else if (ha->port_num == 1)
5941 offset = BOOT_PARAM_OFFSET_PORT1;
5942 else {
5943 ret = QLA_ERROR;
5944 goto exit_boot_info_free;
5945 }
5946 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5947 offset;
5948 if (qla4xxx_get_flash(ha, buf_dma, addr,
5949 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5950 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
Petr Uzel0bd7f842012-02-24 16:32:59 +01005951 " failed\n", ha->host_no, __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005952 ret = QLA_ERROR;
5953 goto exit_boot_info_free;
5954 }
5955 /* Check Boot Mode */
5956 if (!(buf[1] & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305957 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5958 " : 0x%x\n", buf[1]));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005959 ret = QLA_ERROR;
5960 goto exit_boot_info_free;
5961 }
5962
5963 /* get primary valid target index */
5964 if (buf[2] & BIT_7)
5965 ddb_index[0] = buf[2] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005966
5967 /* get secondary valid target index */
5968 if (buf[11] & BIT_7)
5969 ddb_index[1] = buf[11] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005970 } else {
5971 ret = QLA_ERROR;
5972 goto exit_boot_info;
5973 }
5974
5975 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5976 " target ID %d\n", __func__, ddb_index[0],
5977 ddb_index[1]));
5978
5979exit_boot_info_free:
5980 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5981exit_boot_info:
Lalit Chandivade20e835b2012-02-13 18:30:42 +05305982 ha->pri_ddb_idx = ddb_index[0];
5983 ha->sec_ddb_idx = ddb_index[1];
Manish Rangankar2a991c22011-07-25 13:48:55 -05005984 return ret;
5985}
5986
Lalit Chandivade28deb452011-10-07 16:55:44 -07005987/**
5988 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5989 * @ha: pointer to adapter structure
5990 * @username: CHAP username to be returned
5991 * @password: CHAP password to be returned
5992 *
5993 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
5994 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
5995 * So from the CHAP cache find the first BIDI CHAP entry and set it
5996 * to the boot record in sysfs.
5997 **/
5998static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
5999 char *password)
6000{
6001 int i, ret = -EINVAL;
6002 int max_chap_entries = 0;
6003 struct ql4_chap_table *chap_table;
6004
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -04006005 if (is_qla80XX(ha))
Lalit Chandivade28deb452011-10-07 16:55:44 -07006006 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6007 sizeof(struct ql4_chap_table);
6008 else
6009 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6010
6011 if (!ha->chap_list) {
6012 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6013 return ret;
6014 }
6015
6016 mutex_lock(&ha->chap_sem);
6017 for (i = 0; i < max_chap_entries; i++) {
6018 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6019 if (chap_table->cookie !=
6020 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6021 continue;
6022 }
6023
6024 if (chap_table->flags & BIT_7) /* local */
6025 continue;
6026
6027 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6028 continue;
6029
6030 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6031 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6032 ret = 0;
6033 break;
6034 }
6035 mutex_unlock(&ha->chap_sem);
6036
6037 return ret;
6038}
6039
6040
Manish Rangankar2a991c22011-07-25 13:48:55 -05006041static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6042 struct ql4_boot_session_info *boot_sess,
6043 uint16_t ddb_index)
6044{
6045 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6046 struct dev_db_entry *fw_ddb_entry;
6047 dma_addr_t fw_ddb_entry_dma;
6048 uint16_t idx;
6049 uint16_t options;
6050 int ret = QLA_SUCCESS;
6051
6052 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6053 &fw_ddb_entry_dma, GFP_KERNEL);
6054 if (!fw_ddb_entry) {
6055 DEBUG2(ql4_printk(KERN_ERR, ha,
6056 "%s: Unable to allocate dma buffer.\n",
6057 __func__));
6058 ret = QLA_ERROR;
6059 return ret;
6060 }
6061
6062 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6063 fw_ddb_entry_dma, ddb_index)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306064 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6065 "index [%d]\n", __func__, ddb_index));
Manish Rangankar2a991c22011-07-25 13:48:55 -05006066 ret = QLA_ERROR;
6067 goto exit_boot_target;
6068 }
6069
6070 /* Update target name and IP from DDB */
6071 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6072 min(sizeof(boot_sess->target_name),
6073 sizeof(fw_ddb_entry->iscsi_name)));
6074
6075 options = le16_to_cpu(fw_ddb_entry->options);
6076 if (options & DDB_OPT_IPV6_DEVICE) {
6077 memcpy(&boot_conn->dest_ipaddr.ip_address,
6078 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6079 } else {
6080 boot_conn->dest_ipaddr.ip_type = 0x1;
6081 memcpy(&boot_conn->dest_ipaddr.ip_address,
6082 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6083 }
6084
6085 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6086
6087 /* update chap information */
6088 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6089
6090 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6091
6092 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6093
6094 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6095 target_chap_name,
6096 (char *)&boot_conn->chap.target_secret,
6097 idx);
6098 if (ret) {
6099 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6100 ret = QLA_ERROR;
6101 goto exit_boot_target;
6102 }
6103
6104 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6105 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6106 }
6107
6108 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6109
6110 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6111
Lalit Chandivade28deb452011-10-07 16:55:44 -07006112 ret = qla4xxx_get_bidi_chap(ha,
6113 (char *)&boot_conn->chap.intr_chap_name,
6114 (char *)&boot_conn->chap.intr_secret);
6115
Manish Rangankar2a991c22011-07-25 13:48:55 -05006116 if (ret) {
6117 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6118 ret = QLA_ERROR;
6119 goto exit_boot_target;
6120 }
6121
6122 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6123 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6124 }
6125
6126exit_boot_target:
6127 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6128 fw_ddb_entry, fw_ddb_entry_dma);
6129 return ret;
6130}
6131
6132static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6133{
6134 uint16_t ddb_index[2];
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006135 int ret = QLA_ERROR;
6136 int rval;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006137
6138 memset(ddb_index, 0, sizeof(ddb_index));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006139 ddb_index[0] = 0xffff;
6140 ddb_index[1] = 0xffff;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006141 ret = get_fw_boot_info(ha, ddb_index);
6142 if (ret != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306143 DEBUG2(ql4_printk(KERN_INFO, ha,
6144 "%s: No boot target configured.\n", __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05006145 return ret;
6146 }
6147
Mike Christie13483732011-12-01 21:38:41 -06006148 if (ql4xdisablesysfsboot)
6149 return QLA_SUCCESS;
6150
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006151 if (ddb_index[0] == 0xffff)
6152 goto sec_target;
6153
6154 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05006155 ddb_index[0]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006156 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306157 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6158 "configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006159 } else
6160 ret = QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006161
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006162sec_target:
6163 if (ddb_index[1] == 0xffff)
6164 goto exit_get_boot_info;
6165
6166 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05006167 ddb_index[1]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006168 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306169 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6170 " configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006171 } else
6172 ret = QLA_SUCCESS;
6173
6174exit_get_boot_info:
Manish Rangankar2a991c22011-07-25 13:48:55 -05006175 return ret;
6176}
6177
6178static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6179{
6180 struct iscsi_boot_kobj *boot_kobj;
6181
6182 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
Mike Christie13483732011-12-01 21:38:41 -06006183 return QLA_ERROR;
6184
6185 if (ql4xdisablesysfsboot) {
6186 ql4_printk(KERN_INFO, ha,
Petr Uzel0bd7f842012-02-24 16:32:59 +01006187 "%s: syfsboot disabled - driver will trigger login "
Mike Christie13483732011-12-01 21:38:41 -06006188 "and publish session for discovery .\n", __func__);
6189 return QLA_SUCCESS;
6190 }
6191
Manish Rangankar2a991c22011-07-25 13:48:55 -05006192
6193 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6194 if (!ha->boot_kset)
6195 goto kset_free;
6196
6197 if (!scsi_host_get(ha->host))
6198 goto kset_free;
6199 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6200 qla4xxx_show_boot_tgt_pri_info,
6201 qla4xxx_tgt_get_attr_visibility,
6202 qla4xxx_boot_release);
6203 if (!boot_kobj)
6204 goto put_host;
6205
6206 if (!scsi_host_get(ha->host))
6207 goto kset_free;
6208 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6209 qla4xxx_show_boot_tgt_sec_info,
6210 qla4xxx_tgt_get_attr_visibility,
6211 qla4xxx_boot_release);
6212 if (!boot_kobj)
6213 goto put_host;
6214
6215 if (!scsi_host_get(ha->host))
6216 goto kset_free;
6217 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6218 qla4xxx_show_boot_ini_info,
6219 qla4xxx_ini_get_attr_visibility,
6220 qla4xxx_boot_release);
6221 if (!boot_kobj)
6222 goto put_host;
6223
6224 if (!scsi_host_get(ha->host))
6225 goto kset_free;
6226 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6227 qla4xxx_show_boot_eth_info,
6228 qla4xxx_eth_get_attr_visibility,
6229 qla4xxx_boot_release);
6230 if (!boot_kobj)
6231 goto put_host;
6232
Mike Christie13483732011-12-01 21:38:41 -06006233 return QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006234
6235put_host:
6236 scsi_host_put(ha->host);
6237kset_free:
6238 iscsi_boot_destroy_kset(ha->boot_kset);
6239 return -ENOMEM;
6240}
6241
Lalit Chandivade45494152011-10-07 16:55:42 -07006242
Mike Christie13483732011-12-01 21:38:41 -06006243static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6244 struct ql4_tuple_ddb *tddb)
6245{
6246 struct scsi_qla_host *ha;
6247 struct iscsi_cls_session *cls_sess;
6248 struct iscsi_cls_conn *cls_conn;
6249 struct iscsi_session *sess;
6250 struct iscsi_conn *conn;
6251
6252 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6253 ha = ddb_entry->ha;
6254 cls_sess = ddb_entry->sess;
6255 sess = cls_sess->dd_data;
6256 cls_conn = ddb_entry->conn;
6257 conn = cls_conn->dd_data;
6258
6259 tddb->tpgt = sess->tpgt;
6260 tddb->port = conn->persistent_port;
6261 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6262 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6263}
6264
6265static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006266 struct ql4_tuple_ddb *tddb,
6267 uint8_t *flash_isid)
Mike Christie13483732011-12-01 21:38:41 -06006268{
6269 uint16_t options = 0;
6270
6271 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6272 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6273 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6274
6275 options = le16_to_cpu(fw_ddb_entry->options);
6276 if (options & DDB_OPT_IPV6_DEVICE)
6277 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6278 else
6279 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6280
6281 tddb->port = le16_to_cpu(fw_ddb_entry->port);
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006282
6283 if (flash_isid == NULL)
6284 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6285 sizeof(tddb->isid));
6286 else
6287 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
Mike Christie13483732011-12-01 21:38:41 -06006288}
6289
6290static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6291 struct ql4_tuple_ddb *old_tddb,
Manish Rangankar173269e2012-02-27 03:08:55 -08006292 struct ql4_tuple_ddb *new_tddb,
6293 uint8_t is_isid_compare)
Mike Christie13483732011-12-01 21:38:41 -06006294{
6295 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6296 return QLA_ERROR;
6297
6298 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6299 return QLA_ERROR;
6300
6301 if (old_tddb->port != new_tddb->port)
6302 return QLA_ERROR;
6303
Manish Rangankar173269e2012-02-27 03:08:55 -08006304 /* For multi sessions, driver generates the ISID, so do not compare
Masanari Iida59e13d42012-04-25 00:24:16 +09006305 * ISID in reset path since it would be a comparison between the
Manish Rangankar173269e2012-02-27 03:08:55 -08006306 * driver generated ISID and firmware generated ISID. This could
6307 * lead to adding duplicated DDBs in the list as driver generated
6308 * ISID would not match firmware generated ISID.
6309 */
6310 if (is_isid_compare) {
6311 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
6312 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
6313 __func__, old_tddb->isid[5], old_tddb->isid[4],
6314 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
6315 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
6316 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
6317 new_tddb->isid[0]));
6318
6319 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6320 sizeof(old_tddb->isid)))
6321 return QLA_ERROR;
6322 }
6323
Mike Christie13483732011-12-01 21:38:41 -06006324 DEBUG2(ql4_printk(KERN_INFO, ha,
6325 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6326 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6327 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6328 new_tddb->ip_addr, new_tddb->iscsi_name));
6329
6330 return QLA_SUCCESS;
6331}
6332
6333static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006334 struct dev_db_entry *fw_ddb_entry,
6335 uint32_t *index)
Mike Christie13483732011-12-01 21:38:41 -06006336{
6337 struct ddb_entry *ddb_entry;
6338 struct ql4_tuple_ddb *fw_tddb = NULL;
6339 struct ql4_tuple_ddb *tmp_tddb = NULL;
6340 int idx;
6341 int ret = QLA_ERROR;
6342
6343 fw_tddb = vzalloc(sizeof(*fw_tddb));
6344 if (!fw_tddb) {
6345 DEBUG2(ql4_printk(KERN_WARNING, ha,
6346 "Memory Allocation failed.\n"));
6347 ret = QLA_SUCCESS;
6348 goto exit_check;
6349 }
6350
6351 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6352 if (!tmp_tddb) {
6353 DEBUG2(ql4_printk(KERN_WARNING, ha,
6354 "Memory Allocation failed.\n"));
6355 ret = QLA_SUCCESS;
6356 goto exit_check;
6357 }
6358
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006359 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006360
6361 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6362 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6363 if (ddb_entry == NULL)
6364 continue;
6365
6366 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
Manish Rangankar173269e2012-02-27 03:08:55 -08006367 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
Mike Christie13483732011-12-01 21:38:41 -06006368 ret = QLA_SUCCESS; /* found */
Manish Rangankarad8bd452013-09-17 07:30:02 -04006369 if (index != NULL)
6370 *index = idx;
Mike Christie13483732011-12-01 21:38:41 -06006371 goto exit_check;
6372 }
6373 }
6374
6375exit_check:
6376 if (fw_tddb)
6377 vfree(fw_tddb);
6378 if (tmp_tddb)
6379 vfree(tmp_tddb);
6380 return ret;
6381}
6382
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006383/**
6384 * qla4xxx_check_existing_isid - check if target with same isid exist
6385 * in target list
6386 * @list_nt: list of target
6387 * @isid: isid to check
6388 *
6389 * This routine return QLA_SUCCESS if target with same isid exist
6390 **/
6391static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6392{
6393 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6394 struct dev_db_entry *fw_ddb_entry;
6395
6396 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6397 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6398
6399 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6400 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6401 return QLA_SUCCESS;
6402 }
6403 }
6404 return QLA_ERROR;
6405}
6406
6407/**
6408 * qla4xxx_update_isid - compare ddbs and updated isid
6409 * @ha: Pointer to host adapter structure.
6410 * @list_nt: list of nt target
6411 * @fw_ddb_entry: firmware ddb entry
6412 *
6413 * This routine update isid if ddbs have same iqn, same isid and
6414 * different IP addr.
6415 * Return QLA_SUCCESS if isid is updated.
6416 **/
6417static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6418 struct list_head *list_nt,
6419 struct dev_db_entry *fw_ddb_entry)
6420{
6421 uint8_t base_value, i;
6422
6423 base_value = fw_ddb_entry->isid[1] & 0x1f;
6424 for (i = 0; i < 8; i++) {
6425 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6426 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6427 break;
6428 }
6429
6430 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6431 return QLA_ERROR;
6432
6433 return QLA_SUCCESS;
6434}
6435
6436/**
6437 * qla4xxx_should_update_isid - check if isid need to update
6438 * @ha: Pointer to host adapter structure.
6439 * @old_tddb: ddb tuple
6440 * @new_tddb: ddb tuple
6441 *
6442 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6443 * same isid
6444 **/
6445static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6446 struct ql4_tuple_ddb *old_tddb,
6447 struct ql4_tuple_ddb *new_tddb)
6448{
6449 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6450 /* Same ip */
6451 if (old_tddb->port == new_tddb->port)
6452 return QLA_ERROR;
6453 }
6454
6455 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6456 /* different iqn */
6457 return QLA_ERROR;
6458
6459 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6460 sizeof(old_tddb->isid)))
6461 /* different isid */
6462 return QLA_ERROR;
6463
6464 return QLA_SUCCESS;
6465}
6466
6467/**
6468 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6469 * @ha: Pointer to host adapter structure.
6470 * @list_nt: list of nt target.
6471 * @fw_ddb_entry: firmware ddb entry.
6472 *
6473 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6474 * duplicate ddb in list_nt.
6475 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6476 * Note: This function also update isid of DDB if required.
6477 **/
6478
Mike Christie13483732011-12-01 21:38:41 -06006479static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6480 struct list_head *list_nt,
6481 struct dev_db_entry *fw_ddb_entry)
6482{
6483 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6484 struct ql4_tuple_ddb *fw_tddb = NULL;
6485 struct ql4_tuple_ddb *tmp_tddb = NULL;
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006486 int rval, ret = QLA_ERROR;
Mike Christie13483732011-12-01 21:38:41 -06006487
6488 fw_tddb = vzalloc(sizeof(*fw_tddb));
6489 if (!fw_tddb) {
6490 DEBUG2(ql4_printk(KERN_WARNING, ha,
6491 "Memory Allocation failed.\n"));
6492 ret = QLA_SUCCESS;
6493 goto exit_check;
6494 }
6495
6496 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6497 if (!tmp_tddb) {
6498 DEBUG2(ql4_printk(KERN_WARNING, ha,
6499 "Memory Allocation failed.\n"));
6500 ret = QLA_SUCCESS;
6501 goto exit_check;
6502 }
6503
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006504 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006505
6506 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006507 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6508 nt_ddb_idx->flash_isid);
6509 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6510 /* found duplicate ddb */
6511 if (ret == QLA_SUCCESS)
6512 goto exit_check;
6513 }
6514
6515 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6516 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6517
6518 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6519 if (ret == QLA_SUCCESS) {
6520 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6521 if (rval == QLA_SUCCESS)
6522 ret = QLA_ERROR;
6523 else
6524 ret = QLA_SUCCESS;
6525
Mike Christie13483732011-12-01 21:38:41 -06006526 goto exit_check;
6527 }
6528 }
6529
6530exit_check:
6531 if (fw_tddb)
6532 vfree(fw_tddb);
6533 if (tmp_tddb)
6534 vfree(tmp_tddb);
6535 return ret;
6536}
6537
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006538static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
Mike Christie13483732011-12-01 21:38:41 -06006539{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006540 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
Mike Christie13483732011-12-01 21:38:41 -06006541
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006542 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6543 list_del_init(&ddb_idx->list);
6544 vfree(ddb_idx);
Mike Christie13483732011-12-01 21:38:41 -06006545 }
Mike Christie13483732011-12-01 21:38:41 -06006546}
6547
6548static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6549 struct dev_db_entry *fw_ddb_entry)
6550{
6551 struct iscsi_endpoint *ep;
6552 struct sockaddr_in *addr;
6553 struct sockaddr_in6 *addr6;
Manish Rangankar3dd48492012-11-23 06:58:40 -05006554 struct sockaddr *t_addr;
6555 struct sockaddr_storage *dst_addr;
Mike Christie13483732011-12-01 21:38:41 -06006556 char *ip;
6557
6558 /* TODO: need to destroy on unload iscsi_endpoint*/
6559 dst_addr = vmalloc(sizeof(*dst_addr));
6560 if (!dst_addr)
6561 return NULL;
6562
6563 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006564 t_addr = (struct sockaddr *)dst_addr;
6565 t_addr->sa_family = AF_INET6;
Mike Christie13483732011-12-01 21:38:41 -06006566 addr6 = (struct sockaddr_in6 *)dst_addr;
6567 ip = (char *)&addr6->sin6_addr;
6568 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6569 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6570
6571 } else {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006572 t_addr = (struct sockaddr *)dst_addr;
6573 t_addr->sa_family = AF_INET;
Mike Christie13483732011-12-01 21:38:41 -06006574 addr = (struct sockaddr_in *)dst_addr;
6575 ip = (char *)&addr->sin_addr;
6576 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6577 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6578 }
6579
Manish Rangankar3dd48492012-11-23 06:58:40 -05006580 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
Mike Christie13483732011-12-01 21:38:41 -06006581 vfree(dst_addr);
6582 return ep;
6583}
6584
6585static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6586{
6587 if (ql4xdisablesysfsboot)
6588 return QLA_SUCCESS;
6589 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6590 return QLA_ERROR;
6591 return QLA_SUCCESS;
6592}
6593
6594static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006595 struct ddb_entry *ddb_entry,
6596 uint16_t idx)
Mike Christie13483732011-12-01 21:38:41 -06006597{
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006598 uint16_t def_timeout;
6599
Mike Christie13483732011-12-01 21:38:41 -06006600 ddb_entry->ddb_type = FLASH_DDB;
6601 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6602 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6603 ddb_entry->ha = ha;
6604 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6605 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04006606 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
Mike Christie13483732011-12-01 21:38:41 -06006607
6608 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6609 atomic_set(&ddb_entry->relogin_timer, 0);
6610 atomic_set(&ddb_entry->relogin_retry_count, 0);
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006611 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06006612 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006613 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6614 def_timeout : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06006615 ddb_entry->default_time2wait =
6616 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006617
6618 if (ql4xdisablesysfsboot &&
6619 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6620 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
Mike Christie13483732011-12-01 21:38:41 -06006621}
6622
6623static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6624{
6625 uint32_t idx = 0;
6626 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6627 uint32_t sts[MBOX_REG_COUNT];
6628 uint32_t ip_state;
6629 unsigned long wtime;
6630 int ret;
6631
6632 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6633 do {
6634 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6635 if (ip_idx[idx] == -1)
6636 continue;
6637
6638 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6639
6640 if (ret == QLA_ERROR) {
6641 ip_idx[idx] = -1;
6642 continue;
6643 }
6644
6645 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6646
6647 DEBUG2(ql4_printk(KERN_INFO, ha,
6648 "Waiting for IP state for idx = %d, state = 0x%x\n",
6649 ip_idx[idx], ip_state));
6650 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6651 ip_state == IP_ADDRSTATE_INVALID ||
6652 ip_state == IP_ADDRSTATE_PREFERRED ||
6653 ip_state == IP_ADDRSTATE_DEPRICATED ||
6654 ip_state == IP_ADDRSTATE_DISABLING)
6655 ip_idx[idx] = -1;
Mike Christie13483732011-12-01 21:38:41 -06006656 }
6657
6658 /* Break if all IP states checked */
6659 if ((ip_idx[0] == -1) &&
6660 (ip_idx[1] == -1) &&
6661 (ip_idx[2] == -1) &&
6662 (ip_idx[3] == -1))
6663 break;
6664 schedule_timeout_uninterruptible(HZ);
6665 } while (time_after(wtime, jiffies));
6666}
6667
Manish Rangankarad8bd452013-09-17 07:30:02 -04006668static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6669 struct dev_db_entry *flash_ddb_entry)
6670{
6671 uint16_t options = 0;
6672 size_t ip_len = IP_ADDR_LEN;
6673
6674 options = le16_to_cpu(fw_ddb_entry->options);
6675 if (options & DDB_OPT_IPV6_DEVICE)
6676 ip_len = IPv6_ADDR_LEN;
6677
6678 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6679 return QLA_ERROR;
6680
6681 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6682 sizeof(fw_ddb_entry->isid)))
6683 return QLA_ERROR;
6684
6685 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6686 sizeof(fw_ddb_entry->port)))
6687 return QLA_ERROR;
6688
6689 return QLA_SUCCESS;
6690}
6691
6692static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6693 struct dev_db_entry *fw_ddb_entry,
6694 uint32_t fw_idx, uint32_t *flash_index)
6695{
6696 struct dev_db_entry *flash_ddb_entry;
6697 dma_addr_t flash_ddb_entry_dma;
6698 uint32_t idx = 0;
6699 int max_ddbs;
6700 int ret = QLA_ERROR, status;
6701
6702 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6703 MAX_DEV_DB_ENTRIES;
6704
6705 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6706 &flash_ddb_entry_dma);
6707 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6708 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6709 goto exit_find_st_idx;
6710 }
6711
6712 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6713 flash_ddb_entry_dma, fw_idx);
6714 if (status == QLA_SUCCESS) {
6715 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6716 if (status == QLA_SUCCESS) {
6717 *flash_index = fw_idx;
6718 ret = QLA_SUCCESS;
6719 goto exit_find_st_idx;
6720 }
6721 }
6722
6723 for (idx = 0; idx < max_ddbs; idx++) {
6724 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6725 flash_ddb_entry_dma, idx);
6726 if (status == QLA_ERROR)
6727 continue;
6728
6729 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6730 if (status == QLA_SUCCESS) {
6731 *flash_index = idx;
6732 ret = QLA_SUCCESS;
6733 goto exit_find_st_idx;
6734 }
6735 }
6736
6737 if (idx == max_ddbs)
6738 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6739 fw_idx);
6740
6741exit_find_st_idx:
6742 if (flash_ddb_entry)
6743 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6744 flash_ddb_entry_dma);
6745
6746 return ret;
6747}
6748
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006749static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6750 struct list_head *list_st)
Mike Christie13483732011-12-01 21:38:41 -06006751{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006752 struct qla_ddb_index *st_ddb_idx;
Mike Christie13483732011-12-01 21:38:41 -06006753 int max_ddbs;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006754 int fw_idx_size;
6755 struct dev_db_entry *fw_ddb_entry;
6756 dma_addr_t fw_ddb_dma;
Mike Christie13483732011-12-01 21:38:41 -06006757 int ret;
6758 uint32_t idx = 0, next_idx = 0;
6759 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006760 uint32_t flash_index = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006761 uint16_t conn_id = 0;
Mike Christie13483732011-12-01 21:38:41 -06006762
6763 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6764 &fw_ddb_dma);
6765 if (fw_ddb_entry == NULL) {
6766 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006767 goto exit_st_list;
Mike Christie13483732011-12-01 21:38:41 -06006768 }
6769
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006770 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6771 MAX_DEV_DB_ENTRIES;
Mike Christie13483732011-12-01 21:38:41 -06006772 fw_idx_size = sizeof(struct qla_ddb_index);
6773
6774 for (idx = 0; idx < max_ddbs; idx = next_idx) {
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006775 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6776 NULL, &next_idx, &state,
6777 &conn_err, NULL, &conn_id);
Mike Christie13483732011-12-01 21:38:41 -06006778 if (ret == QLA_ERROR)
6779 break;
6780
Lalit Chandivade981c9822012-02-13 18:30:41 +05306781 /* Ignore DDB if invalid state (unassigned) */
6782 if (state == DDB_DS_UNASSIGNED)
6783 goto continue_next_st;
6784
Mike Christie13483732011-12-01 21:38:41 -06006785 /* Check if ST, add to the list_st */
6786 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6787 goto continue_next_st;
6788
6789 st_ddb_idx = vzalloc(fw_idx_size);
6790 if (!st_ddb_idx)
6791 break;
6792
Manish Rangankarad8bd452013-09-17 07:30:02 -04006793 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6794 &flash_index);
6795 if (ret == QLA_ERROR) {
6796 ql4_printk(KERN_ERR, ha,
6797 "No flash entry for ST at idx [%d]\n", idx);
6798 st_ddb_idx->flash_ddb_idx = idx;
6799 } else {
6800 ql4_printk(KERN_INFO, ha,
6801 "ST at idx [%d] is stored at flash [%d]\n",
6802 idx, flash_index);
6803 st_ddb_idx->flash_ddb_idx = flash_index;
6804 }
6805
Mike Christie13483732011-12-01 21:38:41 -06006806 st_ddb_idx->fw_ddb_idx = idx;
6807
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006808 list_add_tail(&st_ddb_idx->list, list_st);
Mike Christie13483732011-12-01 21:38:41 -06006809continue_next_st:
6810 if (next_idx == 0)
6811 break;
6812 }
6813
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006814exit_st_list:
6815 if (fw_ddb_entry)
6816 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6817}
6818
6819/**
6820 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6821 * @ha: pointer to adapter structure
6822 * @list_ddb: List from which failed ddb to be removed
6823 *
6824 * Iterate over the list of DDBs and find and remove DDBs that are either in
6825 * no connection active state or failed state
6826 **/
6827static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6828 struct list_head *list_ddb)
6829{
6830 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6831 uint32_t next_idx = 0;
6832 uint32_t state = 0, conn_err = 0;
6833 int ret;
6834
6835 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6836 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6837 NULL, 0, NULL, &next_idx, &state,
6838 &conn_err, NULL, NULL);
6839 if (ret == QLA_ERROR)
6840 continue;
6841
6842 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6843 state == DDB_DS_SESSION_FAILED) {
6844 list_del_init(&ddb_idx->list);
6845 vfree(ddb_idx);
6846 }
6847 }
6848}
6849
Manish Rangankarad8bd452013-09-17 07:30:02 -04006850static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6851 struct ddb_entry *ddb_entry,
6852 struct dev_db_entry *fw_ddb_entry)
6853{
6854 struct iscsi_cls_session *cls_sess;
6855 struct iscsi_session *sess;
6856 uint32_t max_ddbs = 0;
6857 uint16_t ddb_link = -1;
6858
6859 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6860 MAX_DEV_DB_ENTRIES;
6861
6862 cls_sess = ddb_entry->sess;
6863 sess = cls_sess->dd_data;
6864
6865 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6866 if (ddb_link < max_ddbs)
6867 sess->discovery_parent_idx = ddb_link;
6868 else
6869 sess->discovery_parent_idx = DDB_NO_LINK;
6870}
6871
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006872static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6873 struct dev_db_entry *fw_ddb_entry,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006874 int is_reset, uint16_t idx)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006875{
6876 struct iscsi_cls_session *cls_sess;
6877 struct iscsi_session *sess;
6878 struct iscsi_cls_conn *cls_conn;
6879 struct iscsi_endpoint *ep;
6880 uint16_t cmds_max = 32;
6881 uint16_t conn_id = 0;
6882 uint32_t initial_cmdsn = 0;
6883 int ret = QLA_SUCCESS;
6884
6885 struct ddb_entry *ddb_entry = NULL;
6886
6887 /* Create session object, with INVALID_ENTRY,
6888 * the targer_id would get set when we issue the login
6889 */
6890 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6891 cmds_max, sizeof(struct ddb_entry),
6892 sizeof(struct ql4_task_data),
6893 initial_cmdsn, INVALID_ENTRY);
6894 if (!cls_sess) {
6895 ret = QLA_ERROR;
6896 goto exit_setup;
6897 }
6898
6899 /*
6900 * so calling module_put function to decrement the
6901 * reference count.
6902 **/
6903 module_put(qla4xxx_iscsi_transport.owner);
6904 sess = cls_sess->dd_data;
6905 ddb_entry = sess->dd_data;
6906 ddb_entry->sess = cls_sess;
6907
6908 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6909 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6910 sizeof(struct dev_db_entry));
6911
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006912 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006913
6914 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6915
6916 if (!cls_conn) {
6917 ret = QLA_ERROR;
6918 goto exit_setup;
6919 }
6920
6921 ddb_entry->conn = cls_conn;
6922
6923 /* Setup ep, for displaying attributes in sysfs */
6924 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6925 if (ep) {
6926 ep->conn = cls_conn;
6927 cls_conn->ep = ep;
6928 } else {
6929 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6930 ret = QLA_ERROR;
6931 goto exit_setup;
6932 }
6933
6934 /* Update sess/conn params */
6935 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
Manish Rangankarad8bd452013-09-17 07:30:02 -04006936 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006937
6938 if (is_reset == RESET_ADAPTER) {
6939 iscsi_block_session(cls_sess);
6940 /* Use the relogin path to discover new devices
6941 * by short-circuting the logic of setting
6942 * timer to relogin - instead set the flags
6943 * to initiate login right away.
6944 */
6945 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6946 set_bit(DF_RELOGIN, &ddb_entry->flags);
6947 }
6948
6949exit_setup:
6950 return ret;
6951}
6952
Manish Rangankarad8bd452013-09-17 07:30:02 -04006953static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6954 struct list_head *list_ddb,
6955 struct dev_db_entry *fw_ddb_entry)
6956{
6957 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6958 uint16_t ddb_link;
6959
6960 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6961
6962 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6963 if (ddb_idx->fw_ddb_idx == ddb_link) {
6964 DEBUG2(ql4_printk(KERN_INFO, ha,
6965 "Updating NT parent idx from [%d] to [%d]\n",
6966 ddb_link, ddb_idx->flash_ddb_idx));
6967 fw_ddb_entry->ddb_link =
6968 cpu_to_le16(ddb_idx->flash_ddb_idx);
6969 return;
6970 }
6971 }
6972}
6973
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006974static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006975 struct list_head *list_nt,
6976 struct list_head *list_st,
6977 int is_reset)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006978{
6979 struct dev_db_entry *fw_ddb_entry;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006980 struct ddb_entry *ddb_entry = NULL;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006981 dma_addr_t fw_ddb_dma;
6982 int max_ddbs;
6983 int fw_idx_size;
6984 int ret;
6985 uint32_t idx = 0, next_idx = 0;
6986 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006987 uint32_t ddb_idx = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006988 uint16_t conn_id = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006989 uint16_t ddb_link = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006990 struct qla_ddb_index *nt_ddb_idx;
6991
6992 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6993 &fw_ddb_dma);
6994 if (fw_ddb_entry == NULL) {
6995 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6996 goto exit_nt_list;
6997 }
6998 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6999 MAX_DEV_DB_ENTRIES;
7000 fw_idx_size = sizeof(struct qla_ddb_index);
7001
7002 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7003 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7004 NULL, &next_idx, &state,
7005 &conn_err, NULL, &conn_id);
7006 if (ret == QLA_ERROR)
7007 break;
7008
7009 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7010 goto continue_next_nt;
7011
7012 /* Check if NT, then add to list it */
7013 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7014 goto continue_next_nt;
7015
Manish Rangankarad8bd452013-09-17 07:30:02 -04007016 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7017 if (ddb_link < max_ddbs)
7018 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7019
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007020 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
Manish Rangankarad8bd452013-09-17 07:30:02 -04007021 state == DDB_DS_SESSION_FAILED) &&
7022 (is_reset == INIT_ADAPTER))
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007023 goto continue_next_nt;
7024
7025 DEBUG2(ql4_printk(KERN_INFO, ha,
7026 "Adding DDB to session = 0x%x\n", idx));
Manish Rangankarad8bd452013-09-17 07:30:02 -04007027
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007028 if (is_reset == INIT_ADAPTER) {
7029 nt_ddb_idx = vmalloc(fw_idx_size);
7030 if (!nt_ddb_idx)
7031 break;
7032
7033 nt_ddb_idx->fw_ddb_idx = idx;
7034
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04007035 /* Copy original isid as it may get updated in function
7036 * qla4xxx_update_isid(). We need original isid in
7037 * function qla4xxx_compare_tuple_ddb to find duplicate
7038 * target */
7039 memcpy(&nt_ddb_idx->flash_isid[0],
7040 &fw_ddb_entry->isid[0],
7041 sizeof(nt_ddb_idx->flash_isid));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007042
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04007043 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7044 fw_ddb_entry);
7045 if (ret == QLA_SUCCESS) {
7046 /* free nt_ddb_idx and do not add to list_nt */
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007047 vfree(nt_ddb_idx);
7048 goto continue_next_nt;
7049 }
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04007050
7051 /* Copy updated isid */
7052 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7053 sizeof(struct dev_db_entry));
7054
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007055 list_add_tail(&nt_ddb_idx->list, list_nt);
7056 } else if (is_reset == RESET_ADAPTER) {
Manish Rangankarad8bd452013-09-17 07:30:02 -04007057 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7058 &ddb_idx);
7059 if (ret == QLA_SUCCESS) {
7060 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7061 ddb_idx);
7062 if (ddb_entry != NULL)
7063 qla4xxx_update_sess_disc_idx(ha,
7064 ddb_entry,
7065 fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007066 goto continue_next_nt;
Manish Rangankarad8bd452013-09-17 07:30:02 -04007067 }
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007068 }
7069
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05007070 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007071 if (ret == QLA_ERROR)
7072 goto exit_nt_list;
7073
7074continue_next_nt:
7075 if (next_idx == 0)
7076 break;
7077 }
7078
7079exit_nt_list:
7080 if (fw_ddb_entry)
7081 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7082}
7083
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007084static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007085 struct list_head *list_nt,
7086 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007087{
7088 struct dev_db_entry *fw_ddb_entry;
7089 dma_addr_t fw_ddb_dma;
7090 int max_ddbs;
7091 int fw_idx_size;
7092 int ret;
7093 uint32_t idx = 0, next_idx = 0;
7094 uint32_t state = 0, conn_err = 0;
7095 uint16_t conn_id = 0;
7096 struct qla_ddb_index *nt_ddb_idx;
7097
7098 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7099 &fw_ddb_dma);
7100 if (fw_ddb_entry == NULL) {
7101 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7102 goto exit_new_nt_list;
7103 }
7104 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7105 MAX_DEV_DB_ENTRIES;
7106 fw_idx_size = sizeof(struct qla_ddb_index);
7107
7108 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7109 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7110 NULL, &next_idx, &state,
7111 &conn_err, NULL, &conn_id);
7112 if (ret == QLA_ERROR)
7113 break;
7114
7115 /* Check if NT, then add it to list */
7116 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7117 goto continue_next_new_nt;
7118
7119 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7120 goto continue_next_new_nt;
7121
7122 DEBUG2(ql4_printk(KERN_INFO, ha,
7123 "Adding DDB to session = 0x%x\n", idx));
7124
7125 nt_ddb_idx = vmalloc(fw_idx_size);
7126 if (!nt_ddb_idx)
7127 break;
7128
7129 nt_ddb_idx->fw_ddb_idx = idx;
7130
Manish Rangankarad8bd452013-09-17 07:30:02 -04007131 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007132 if (ret == QLA_SUCCESS) {
7133 /* free nt_ddb_idx and do not add to list_nt */
7134 vfree(nt_ddb_idx);
7135 goto continue_next_new_nt;
7136 }
7137
Manish Rangankarad8bd452013-09-17 07:30:02 -04007138 if (target_id < max_ddbs)
7139 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7140
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007141 list_add_tail(&nt_ddb_idx->list, list_nt);
7142
7143 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7144 idx);
7145 if (ret == QLA_ERROR)
7146 goto exit_new_nt_list;
7147
7148continue_next_new_nt:
7149 if (next_idx == 0)
7150 break;
7151 }
7152
7153exit_new_nt_list:
7154 if (fw_ddb_entry)
7155 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7156}
7157
7158/**
7159 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7160 * @dev: dev associated with the sysfs entry
7161 * @data: pointer to flashnode session object
7162 *
7163 * Returns:
7164 * 1: if flashnode entry is non-persistent
7165 * 0: if flashnode entry is persistent
7166 **/
7167static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7168{
7169 struct iscsi_bus_flash_session *fnode_sess;
7170
7171 if (!iscsi_flashnode_bus_match(dev, NULL))
7172 return 0;
7173
7174 fnode_sess = iscsi_dev_to_flash_session(dev);
7175
7176 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7177}
7178
7179/**
7180 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7181 * @ha: pointer to host
7182 * @fw_ddb_entry: flash ddb data
7183 * @idx: target index
7184 * @user: if set then this call is made from userland else from kernel
7185 *
7186 * Returns:
7187 * On sucess: QLA_SUCCESS
7188 * On failure: QLA_ERROR
7189 *
7190 * This create separate sysfs entries for session and connection attributes of
7191 * the given fw ddb entry.
7192 * If this is invoked as a result of a userspace call then the entry is marked
7193 * as nonpersistent using flash_state field.
7194 **/
Vikas Chaudhary28e02f12013-04-17 05:15:27 -04007195static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7196 struct dev_db_entry *fw_ddb_entry,
7197 uint16_t *idx, int user)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007198{
7199 struct iscsi_bus_flash_session *fnode_sess = NULL;
7200 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7201 int rc = QLA_ERROR;
7202
7203 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7204 &qla4xxx_iscsi_transport, 0);
7205 if (!fnode_sess) {
7206 ql4_printk(KERN_ERR, ha,
7207 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7208 __func__, *idx, ha->host_no);
7209 goto exit_tgt_create;
7210 }
7211
7212 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7213 &qla4xxx_iscsi_transport, 0);
7214 if (!fnode_conn) {
7215 ql4_printk(KERN_ERR, ha,
7216 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7217 __func__, *idx, ha->host_no);
7218 goto free_sess;
7219 }
7220
7221 if (user) {
7222 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7223 } else {
7224 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7225
7226 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7227 fnode_sess->is_boot_target = 1;
7228 else
7229 fnode_sess->is_boot_target = 0;
7230 }
7231
7232 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7233 fw_ddb_entry);
7234
7235 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7236 __func__, fnode_sess->dev.kobj.name);
7237
7238 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7239 __func__, fnode_conn->dev.kobj.name);
7240
7241 return QLA_SUCCESS;
7242
7243free_sess:
7244 iscsi_destroy_flashnode_sess(fnode_sess);
7245
7246exit_tgt_create:
7247 return QLA_ERROR;
7248}
7249
7250/**
7251 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7252 * @shost: pointer to host
7253 * @buf: type of ddb entry (ipv4/ipv6)
7254 * @len: length of buf
7255 *
7256 * This creates new ddb entry in the flash by finding first free index and
7257 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7258 **/
7259static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7260 int len)
7261{
7262 struct scsi_qla_host *ha = to_qla_host(shost);
7263 struct dev_db_entry *fw_ddb_entry = NULL;
7264 dma_addr_t fw_ddb_entry_dma;
7265 struct device *dev;
7266 uint16_t idx = 0;
7267 uint16_t max_ddbs = 0;
7268 uint32_t options = 0;
7269 uint32_t rval = QLA_ERROR;
7270
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007271 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7272 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007273 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7274 __func__));
7275 goto exit_ddb_add;
7276 }
7277
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04007278 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007279 MAX_DEV_DB_ENTRIES;
7280
7281 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7282 &fw_ddb_entry_dma, GFP_KERNEL);
7283 if (!fw_ddb_entry) {
7284 DEBUG2(ql4_printk(KERN_ERR, ha,
7285 "%s: Unable to allocate dma buffer\n",
7286 __func__));
7287 goto exit_ddb_add;
7288 }
7289
7290 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7291 qla4xxx_sysfs_ddb_is_non_persistent);
7292 if (dev) {
7293 ql4_printk(KERN_ERR, ha,
7294 "%s: A non-persistent entry %s found\n",
7295 __func__, dev->kobj.name);
Mike Christie8526cb12013-05-06 12:06:56 -05007296 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007297 goto exit_ddb_add;
7298 }
7299
Adheer Chandravanshi99937572013-07-08 08:33:09 -04007300 /* Index 0 and 1 are reserved for boot target entries */
7301 for (idx = 2; idx < max_ddbs; idx++) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007302 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7303 fw_ddb_entry_dma, idx))
7304 break;
7305 }
7306
7307 if (idx == max_ddbs)
7308 goto exit_ddb_add;
7309
7310 if (!strncasecmp("ipv6", buf, 4))
7311 options |= IPV6_DEFAULT_DDB_ENTRY;
7312
7313 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7314 if (rval == QLA_ERROR)
7315 goto exit_ddb_add;
7316
7317 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7318
7319exit_ddb_add:
7320 if (fw_ddb_entry)
7321 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7322 fw_ddb_entry, fw_ddb_entry_dma);
7323 if (rval == QLA_SUCCESS)
7324 return idx;
7325 else
7326 return -EIO;
7327}
7328
7329/**
7330 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7331 * @fnode_sess: pointer to session attrs of flash ddb entry
7332 * @fnode_conn: pointer to connection attrs of flash ddb entry
7333 *
7334 * This writes the contents of target ddb buffer to Flash with a valid cookie
7335 * value in order to make the ddb entry persistent.
7336 **/
7337static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7338 struct iscsi_bus_flash_conn *fnode_conn)
7339{
7340 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7341 struct scsi_qla_host *ha = to_qla_host(shost);
7342 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7343 struct dev_db_entry *fw_ddb_entry = NULL;
7344 dma_addr_t fw_ddb_entry_dma;
7345 uint32_t options = 0;
7346 int rval = 0;
7347
7348 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7349 &fw_ddb_entry_dma, GFP_KERNEL);
7350 if (!fw_ddb_entry) {
7351 DEBUG2(ql4_printk(KERN_ERR, ha,
7352 "%s: Unable to allocate dma buffer\n",
7353 __func__));
7354 rval = -ENOMEM;
7355 goto exit_ddb_apply;
7356 }
7357
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007358 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007359 options |= IPV6_DEFAULT_DDB_ENTRY;
7360
7361 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7362 if (rval == QLA_ERROR)
7363 goto exit_ddb_apply;
7364
7365 dev_db_start_offset += (fnode_sess->target_id *
7366 sizeof(*fw_ddb_entry));
7367
7368 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7369 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7370
7371 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7372 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7373
7374 if (rval == QLA_SUCCESS) {
7375 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7376 ql4_printk(KERN_INFO, ha,
7377 "%s: flash node %u of host %lu written to flash\n",
7378 __func__, fnode_sess->target_id, ha->host_no);
7379 } else {
7380 rval = -EIO;
7381 ql4_printk(KERN_ERR, ha,
7382 "%s: Error while writing flash node %u of host %lu to flash\n",
7383 __func__, fnode_sess->target_id, ha->host_no);
7384 }
7385
7386exit_ddb_apply:
7387 if (fw_ddb_entry)
7388 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7389 fw_ddb_entry, fw_ddb_entry_dma);
7390 return rval;
7391}
7392
7393static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7394 struct dev_db_entry *fw_ddb_entry,
7395 uint16_t idx)
7396{
7397 struct dev_db_entry *ddb_entry = NULL;
7398 dma_addr_t ddb_entry_dma;
7399 unsigned long wtime;
7400 uint32_t mbx_sts = 0;
7401 uint32_t state = 0, conn_err = 0;
7402 uint16_t tmo = 0;
7403 int ret = 0;
7404
7405 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7406 &ddb_entry_dma, GFP_KERNEL);
7407 if (!ddb_entry) {
7408 DEBUG2(ql4_printk(KERN_ERR, ha,
7409 "%s: Unable to allocate dma buffer\n",
7410 __func__));
7411 return QLA_ERROR;
7412 }
7413
7414 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7415
7416 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7417 if (ret != QLA_SUCCESS) {
7418 DEBUG2(ql4_printk(KERN_ERR, ha,
7419 "%s: Unable to set ddb entry for index %d\n",
7420 __func__, idx));
7421 goto exit_ddb_conn_open;
7422 }
7423
7424 qla4xxx_conn_open(ha, idx);
7425
7426 /* To ensure that sendtargets is done, wait for at least 12 secs */
7427 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7428 (ha->def_timeout < LOGIN_TOV * 10) ?
7429 ha->def_timeout : LOGIN_TOV);
7430
7431 DEBUG2(ql4_printk(KERN_INFO, ha,
7432 "Default time to wait for login to ddb %d\n", tmo));
7433
7434 wtime = jiffies + (HZ * tmo);
7435 do {
7436 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7437 NULL, &state, &conn_err, NULL,
7438 NULL);
7439 if (ret == QLA_ERROR)
7440 continue;
7441
7442 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7443 state == DDB_DS_SESSION_FAILED)
7444 break;
7445
7446 schedule_timeout_uninterruptible(HZ / 10);
7447 } while (time_after(wtime, jiffies));
7448
7449exit_ddb_conn_open:
7450 if (ddb_entry)
7451 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7452 ddb_entry, ddb_entry_dma);
7453 return ret;
7454}
7455
7456static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007457 struct dev_db_entry *fw_ddb_entry,
7458 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007459{
7460 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7461 struct list_head list_nt;
7462 uint16_t ddb_index;
7463 int ret = 0;
7464
7465 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7466 ql4_printk(KERN_WARNING, ha,
7467 "%s: A discovery already in progress!\n", __func__);
7468 return QLA_ERROR;
7469 }
7470
7471 INIT_LIST_HEAD(&list_nt);
7472
7473 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7474
7475 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7476 if (ret == QLA_ERROR)
7477 goto exit_login_st_clr_bit;
7478
7479 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7480 if (ret == QLA_ERROR)
7481 goto exit_login_st;
7482
Manish Rangankarad8bd452013-09-17 07:30:02 -04007483 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007484
7485 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7486 list_del_init(&ddb_idx->list);
7487 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7488 vfree(ddb_idx);
7489 }
7490
7491exit_login_st:
7492 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7493 ql4_printk(KERN_ERR, ha,
7494 "Unable to clear DDB index = 0x%x\n", ddb_index);
7495 }
7496
7497 clear_bit(ddb_index, ha->ddb_idx_map);
7498
7499exit_login_st_clr_bit:
7500 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7501 return ret;
7502}
7503
7504static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7505 struct dev_db_entry *fw_ddb_entry,
7506 uint16_t idx)
7507{
7508 int ret = QLA_ERROR;
7509
Manish Rangankarad8bd452013-09-17 07:30:02 -04007510 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007511 if (ret != QLA_SUCCESS)
7512 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7513 idx);
7514 else
7515 ret = -EPERM;
7516
7517 return ret;
7518}
7519
7520/**
7521 * qla4xxx_sysfs_ddb_login - Login to the specified target
7522 * @fnode_sess: pointer to session attrs of flash ddb entry
7523 * @fnode_conn: pointer to connection attrs of flash ddb entry
7524 *
7525 * This logs in to the specified target
7526 **/
7527static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7528 struct iscsi_bus_flash_conn *fnode_conn)
7529{
7530 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7531 struct scsi_qla_host *ha = to_qla_host(shost);
7532 struct dev_db_entry *fw_ddb_entry = NULL;
7533 dma_addr_t fw_ddb_entry_dma;
7534 uint32_t options = 0;
7535 int ret = 0;
7536
7537 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7538 ql4_printk(KERN_ERR, ha,
7539 "%s: Target info is not persistent\n", __func__);
7540 ret = -EIO;
7541 goto exit_ddb_login;
7542 }
7543
7544 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7545 &fw_ddb_entry_dma, GFP_KERNEL);
7546 if (!fw_ddb_entry) {
7547 DEBUG2(ql4_printk(KERN_ERR, ha,
7548 "%s: Unable to allocate dma buffer\n",
7549 __func__));
7550 ret = -ENOMEM;
7551 goto exit_ddb_login;
7552 }
7553
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007554 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007555 options |= IPV6_DEFAULT_DDB_ENTRY;
7556
7557 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7558 if (ret == QLA_ERROR)
7559 goto exit_ddb_login;
7560
7561 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7562 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7563
7564 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
Manish Rangankarad8bd452013-09-17 07:30:02 -04007565 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7566 fnode_sess->target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007567 else
7568 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7569 fnode_sess->target_id);
7570
7571 if (ret > 0)
7572 ret = -EIO;
7573
7574exit_ddb_login:
7575 if (fw_ddb_entry)
7576 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7577 fw_ddb_entry, fw_ddb_entry_dma);
7578 return ret;
7579}
7580
7581/**
7582 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7583 * @cls_sess: pointer to session to be logged out
7584 *
7585 * This performs session log out from the specified target
7586 **/
7587static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7588{
7589 struct iscsi_session *sess;
7590 struct ddb_entry *ddb_entry = NULL;
7591 struct scsi_qla_host *ha;
7592 struct dev_db_entry *fw_ddb_entry = NULL;
7593 dma_addr_t fw_ddb_entry_dma;
7594 unsigned long flags;
7595 unsigned long wtime;
7596 uint32_t ddb_state;
7597 int options;
7598 int ret = 0;
7599
7600 sess = cls_sess->dd_data;
7601 ddb_entry = sess->dd_data;
7602 ha = ddb_entry->ha;
7603
7604 if (ddb_entry->ddb_type != FLASH_DDB) {
7605 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7606 __func__);
7607 ret = -ENXIO;
7608 goto exit_ddb_logout;
7609 }
7610
Adheer Chandravanshi37719c22013-04-05 07:06:07 -04007611 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7612 ql4_printk(KERN_ERR, ha,
7613 "%s: Logout from boot target entry is not permitted.\n",
7614 __func__);
7615 ret = -EPERM;
7616 goto exit_ddb_logout;
7617 }
7618
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007619 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7620 &fw_ddb_entry_dma, GFP_KERNEL);
7621 if (!fw_ddb_entry) {
7622 ql4_printk(KERN_ERR, ha,
7623 "%s: Unable to allocate dma buffer\n", __func__);
7624 ret = -ENOMEM;
7625 goto exit_ddb_logout;
7626 }
7627
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007628 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7629 goto ddb_logout_init;
7630
7631 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7632 fw_ddb_entry, fw_ddb_entry_dma,
7633 NULL, NULL, &ddb_state, NULL,
7634 NULL, NULL);
7635 if (ret == QLA_ERROR)
7636 goto ddb_logout_init;
7637
7638 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7639 goto ddb_logout_init;
7640
7641 /* wait until next relogin is triggered using DF_RELOGIN and
7642 * clear DF_RELOGIN to avoid invocation of further relogin
7643 */
7644 wtime = jiffies + (HZ * RELOGIN_TOV);
7645 do {
7646 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7647 goto ddb_logout_init;
7648
7649 schedule_timeout_uninterruptible(HZ);
7650 } while ((time_after(wtime, jiffies)));
7651
7652ddb_logout_init:
7653 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7654 atomic_set(&ddb_entry->relogin_timer, 0);
7655
7656 options = LOGOUT_OPTION_CLOSE_SESSION;
7657 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7658
7659 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007660 wtime = jiffies + (HZ * LOGOUT_TOV);
7661 do {
7662 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7663 fw_ddb_entry, fw_ddb_entry_dma,
7664 NULL, NULL, &ddb_state, NULL,
7665 NULL, NULL);
7666 if (ret == QLA_ERROR)
7667 goto ddb_logout_clr_sess;
7668
7669 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7670 (ddb_state == DDB_DS_SESSION_FAILED))
7671 goto ddb_logout_clr_sess;
7672
7673 schedule_timeout_uninterruptible(HZ);
7674 } while ((time_after(wtime, jiffies)));
7675
7676ddb_logout_clr_sess:
7677 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7678 /*
7679 * we have decremented the reference count of the driver
7680 * when we setup the session to have the driver unload
7681 * to be seamless without actually destroying the
7682 * session
7683 **/
7684 try_module_get(qla4xxx_iscsi_transport.owner);
7685 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7686
7687 spin_lock_irqsave(&ha->hardware_lock, flags);
7688 qla4xxx_free_ddb(ha, ddb_entry);
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007689 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007690 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7691
7692 iscsi_session_teardown(ddb_entry->sess);
7693
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007694 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007695 ret = QLA_SUCCESS;
7696
7697exit_ddb_logout:
7698 if (fw_ddb_entry)
7699 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7700 fw_ddb_entry, fw_ddb_entry_dma);
7701 return ret;
7702}
7703
7704/**
7705 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7706 * @fnode_sess: pointer to session attrs of flash ddb entry
7707 * @fnode_conn: pointer to connection attrs of flash ddb entry
7708 *
7709 * This performs log out from the specified target
7710 **/
7711static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7712 struct iscsi_bus_flash_conn *fnode_conn)
7713{
7714 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7715 struct scsi_qla_host *ha = to_qla_host(shost);
7716 struct ql4_tuple_ddb *flash_tddb = NULL;
7717 struct ql4_tuple_ddb *tmp_tddb = NULL;
7718 struct dev_db_entry *fw_ddb_entry = NULL;
7719 struct ddb_entry *ddb_entry = NULL;
7720 dma_addr_t fw_ddb_dma;
7721 uint32_t next_idx = 0;
7722 uint32_t state = 0, conn_err = 0;
7723 uint16_t conn_id = 0;
7724 int idx, index;
7725 int status, ret = 0;
7726
7727 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7728 &fw_ddb_dma);
7729 if (fw_ddb_entry == NULL) {
7730 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7731 ret = -ENOMEM;
7732 goto exit_ddb_logout;
7733 }
7734
7735 flash_tddb = vzalloc(sizeof(*flash_tddb));
7736 if (!flash_tddb) {
7737 ql4_printk(KERN_WARNING, ha,
7738 "%s:Memory Allocation failed.\n", __func__);
7739 ret = -ENOMEM;
7740 goto exit_ddb_logout;
7741 }
7742
7743 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7744 if (!tmp_tddb) {
7745 ql4_printk(KERN_WARNING, ha,
7746 "%s:Memory Allocation failed.\n", __func__);
7747 ret = -ENOMEM;
7748 goto exit_ddb_logout;
7749 }
7750
7751 if (!fnode_sess->targetname) {
7752 ql4_printk(KERN_ERR, ha,
7753 "%s:Cannot logout from SendTarget entry\n",
7754 __func__);
7755 ret = -EPERM;
7756 goto exit_ddb_logout;
7757 }
7758
7759 if (fnode_sess->is_boot_target) {
7760 ql4_printk(KERN_ERR, ha,
7761 "%s: Logout from boot target entry is not permitted.\n",
7762 __func__);
7763 ret = -EPERM;
7764 goto exit_ddb_logout;
7765 }
7766
7767 strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7768 ISCSI_NAME_SIZE);
7769
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007770 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007771 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7772 else
7773 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7774
7775 flash_tddb->tpgt = fnode_sess->tpgt;
7776 flash_tddb->port = fnode_conn->port;
7777
7778 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7779
7780 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7781 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7782 if (ddb_entry == NULL)
7783 continue;
7784
7785 if (ddb_entry->ddb_type != FLASH_DDB)
7786 continue;
7787
7788 index = ddb_entry->sess->target_id;
7789 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7790 fw_ddb_dma, NULL, &next_idx,
7791 &state, &conn_err, NULL,
7792 &conn_id);
7793 if (status == QLA_ERROR) {
7794 ret = -ENOMEM;
7795 break;
7796 }
7797
7798 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7799
7800 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7801 true);
7802 if (status == QLA_SUCCESS) {
7803 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7804 break;
7805 }
7806 }
7807
7808 if (idx == MAX_DDB_ENTRIES)
7809 ret = -ESRCH;
7810
7811exit_ddb_logout:
7812 if (flash_tddb)
7813 vfree(flash_tddb);
7814 if (tmp_tddb)
7815 vfree(tmp_tddb);
7816 if (fw_ddb_entry)
7817 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7818
7819 return ret;
7820}
7821
7822static int
7823qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7824 int param, char *buf)
7825{
7826 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7827 struct scsi_qla_host *ha = to_qla_host(shost);
7828 struct iscsi_bus_flash_conn *fnode_conn;
7829 struct ql4_chap_table chap_tbl;
7830 struct device *dev;
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007831 int parent_type;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007832 int rc = 0;
7833
Mike Christie8526cb12013-05-06 12:06:56 -05007834 dev = iscsi_find_flashnode_conn(fnode_sess);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007835 if (!dev)
7836 return -EIO;
7837
7838 fnode_conn = iscsi_dev_to_flash_conn(dev);
7839
7840 switch (param) {
7841 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7842 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7843 break;
7844 case ISCSI_FLASHNODE_PORTAL_TYPE:
7845 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7846 break;
7847 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7848 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7849 break;
7850 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7851 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7852 break;
7853 case ISCSI_FLASHNODE_ENTRY_EN:
7854 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7855 break;
7856 case ISCSI_FLASHNODE_HDR_DGST_EN:
7857 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7858 break;
7859 case ISCSI_FLASHNODE_DATA_DGST_EN:
7860 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7861 break;
7862 case ISCSI_FLASHNODE_IMM_DATA_EN:
7863 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7864 break;
7865 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7866 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7867 break;
7868 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7869 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7870 break;
7871 case ISCSI_FLASHNODE_PDU_INORDER:
7872 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7873 break;
7874 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7875 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7876 break;
7877 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7878 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7879 break;
7880 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7881 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7882 break;
7883 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7884 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7885 break;
7886 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7887 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7888 break;
7889 case ISCSI_FLASHNODE_ERL:
7890 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7891 break;
7892 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7893 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7894 break;
7895 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7896 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7897 break;
7898 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7899 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7900 break;
7901 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7902 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7903 break;
7904 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7905 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7906 break;
7907 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7908 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7909 break;
7910 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7911 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7912 break;
7913 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7914 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7915 break;
7916 case ISCSI_FLASHNODE_FIRST_BURST:
7917 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7918 break;
7919 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7920 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7921 break;
7922 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7923 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7924 break;
7925 case ISCSI_FLASHNODE_MAX_R2T:
7926 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7927 break;
7928 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7929 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7930 break;
7931 case ISCSI_FLASHNODE_ISID:
7932 rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
7933 fnode_sess->isid[0], fnode_sess->isid[1],
7934 fnode_sess->isid[2], fnode_sess->isid[3],
7935 fnode_sess->isid[4], fnode_sess->isid[5]);
7936 break;
7937 case ISCSI_FLASHNODE_TSID:
7938 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7939 break;
7940 case ISCSI_FLASHNODE_PORT:
7941 rc = sprintf(buf, "%d\n", fnode_conn->port);
7942 break;
7943 case ISCSI_FLASHNODE_MAX_BURST:
7944 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7945 break;
7946 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7947 rc = sprintf(buf, "%u\n",
7948 fnode_sess->default_taskmgmt_timeout);
7949 break;
7950 case ISCSI_FLASHNODE_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007951 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007952 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7953 else
7954 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7955 break;
7956 case ISCSI_FLASHNODE_ALIAS:
7957 if (fnode_sess->targetalias)
7958 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7959 else
7960 rc = sprintf(buf, "\n");
7961 break;
7962 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007963 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007964 rc = sprintf(buf, "%pI6\n",
7965 fnode_conn->redirect_ipaddr);
7966 else
7967 rc = sprintf(buf, "%pI4\n",
7968 fnode_conn->redirect_ipaddr);
7969 break;
7970 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7971 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7972 break;
7973 case ISCSI_FLASHNODE_LOCAL_PORT:
7974 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7975 break;
7976 case ISCSI_FLASHNODE_IPV4_TOS:
7977 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7978 break;
7979 case ISCSI_FLASHNODE_IPV6_TC:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007980 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007981 rc = sprintf(buf, "%u\n",
7982 fnode_conn->ipv6_traffic_class);
7983 else
7984 rc = sprintf(buf, "\n");
7985 break;
7986 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7987 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7988 break;
7989 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007990 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007991 rc = sprintf(buf, "%pI6\n",
7992 fnode_conn->link_local_ipv6_addr);
7993 else
7994 rc = sprintf(buf, "\n");
7995 break;
7996 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007997 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007998 break;
7999 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8000 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8001 parent_type = ISCSI_DISC_PARENT_ISNS;
8002 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8003 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04008004 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008005 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8006 else
8007 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8008
8009 rc = sprintf(buf, "%s\n",
8010 iscsi_get_discovery_parent_name(parent_type));
8011 break;
8012 case ISCSI_FLASHNODE_NAME:
8013 if (fnode_sess->targetname)
8014 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8015 else
8016 rc = sprintf(buf, "\n");
8017 break;
8018 case ISCSI_FLASHNODE_TPGT:
8019 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8020 break;
8021 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8022 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8023 break;
8024 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8025 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8026 break;
8027 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8028 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8029 break;
8030 case ISCSI_FLASHNODE_USERNAME:
8031 if (fnode_sess->chap_auth_en) {
8032 qla4xxx_get_uni_chap_at_index(ha,
8033 chap_tbl.name,
8034 chap_tbl.secret,
8035 fnode_sess->chap_out_idx);
8036 rc = sprintf(buf, "%s\n", chap_tbl.name);
8037 } else {
8038 rc = sprintf(buf, "\n");
8039 }
8040 break;
8041 case ISCSI_FLASHNODE_PASSWORD:
8042 if (fnode_sess->chap_auth_en) {
8043 qla4xxx_get_uni_chap_at_index(ha,
8044 chap_tbl.name,
8045 chap_tbl.secret,
8046 fnode_sess->chap_out_idx);
8047 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8048 } else {
8049 rc = sprintf(buf, "\n");
8050 }
8051 break;
8052 case ISCSI_FLASHNODE_STATSN:
8053 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8054 break;
8055 case ISCSI_FLASHNODE_EXP_STATSN:
8056 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8057 break;
8058 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8059 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8060 break;
8061 default:
8062 rc = -ENOSYS;
8063 break;
8064 }
Mike Christie8526cb12013-05-06 12:06:56 -05008065
8066 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008067 return rc;
8068}
8069
8070/**
8071 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8072 * @fnode_sess: pointer to session attrs of flash ddb entry
8073 * @fnode_conn: pointer to connection attrs of flash ddb entry
8074 * @data: Parameters and their values to update
8075 * @len: len of data
8076 *
8077 * This sets the parameter of flash ddb entry and writes them to flash
8078 **/
8079static int
8080qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8081 struct iscsi_bus_flash_conn *fnode_conn,
8082 void *data, int len)
8083{
8084 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8085 struct scsi_qla_host *ha = to_qla_host(shost);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008086 struct iscsi_flashnode_param_info *fnode_param;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008087 struct ql4_chap_table chap_tbl;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008088 struct nlattr *attr;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008089 uint16_t chap_out_idx = INVALID_ENTRY;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008090 int rc = QLA_ERROR;
8091 uint32_t rem = len;
8092
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008093 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008094 nla_for_each_attr(attr, data, len, rem) {
8095 fnode_param = nla_data(attr);
8096
8097 switch (fnode_param->param) {
8098 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8099 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8100 break;
8101 case ISCSI_FLASHNODE_PORTAL_TYPE:
8102 memcpy(fnode_sess->portal_type, fnode_param->value,
8103 strlen(fnode_sess->portal_type));
8104 break;
8105 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8106 fnode_sess->auto_snd_tgt_disable =
8107 fnode_param->value[0];
8108 break;
8109 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8110 fnode_sess->discovery_sess = fnode_param->value[0];
8111 break;
8112 case ISCSI_FLASHNODE_ENTRY_EN:
8113 fnode_sess->entry_state = fnode_param->value[0];
8114 break;
8115 case ISCSI_FLASHNODE_HDR_DGST_EN:
8116 fnode_conn->hdrdgst_en = fnode_param->value[0];
8117 break;
8118 case ISCSI_FLASHNODE_DATA_DGST_EN:
8119 fnode_conn->datadgst_en = fnode_param->value[0];
8120 break;
8121 case ISCSI_FLASHNODE_IMM_DATA_EN:
8122 fnode_sess->imm_data_en = fnode_param->value[0];
8123 break;
8124 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8125 fnode_sess->initial_r2t_en = fnode_param->value[0];
8126 break;
8127 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8128 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8129 break;
8130 case ISCSI_FLASHNODE_PDU_INORDER:
8131 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8132 break;
8133 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8134 fnode_sess->chap_auth_en = fnode_param->value[0];
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008135 /* Invalidate chap index if chap auth is disabled */
8136 if (!fnode_sess->chap_auth_en)
8137 fnode_sess->chap_out_idx = INVALID_ENTRY;
8138
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008139 break;
8140 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8141 fnode_conn->snack_req_en = fnode_param->value[0];
8142 break;
8143 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8144 fnode_sess->discovery_logout_en = fnode_param->value[0];
8145 break;
8146 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8147 fnode_sess->bidi_chap_en = fnode_param->value[0];
8148 break;
8149 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8150 fnode_sess->discovery_auth_optional =
8151 fnode_param->value[0];
8152 break;
8153 case ISCSI_FLASHNODE_ERL:
8154 fnode_sess->erl = fnode_param->value[0];
8155 break;
8156 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8157 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8158 break;
8159 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8160 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8161 break;
8162 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8163 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8164 break;
8165 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8166 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8167 break;
8168 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8169 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8170 break;
8171 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8172 fnode_conn->fragment_disable = fnode_param->value[0];
8173 break;
8174 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8175 fnode_conn->max_recv_dlength =
8176 *(unsigned *)fnode_param->value;
8177 break;
8178 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8179 fnode_conn->max_xmit_dlength =
8180 *(unsigned *)fnode_param->value;
8181 break;
8182 case ISCSI_FLASHNODE_FIRST_BURST:
8183 fnode_sess->first_burst =
8184 *(unsigned *)fnode_param->value;
8185 break;
8186 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8187 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8188 break;
8189 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8190 fnode_sess->time2retain =
8191 *(uint16_t *)fnode_param->value;
8192 break;
8193 case ISCSI_FLASHNODE_MAX_R2T:
8194 fnode_sess->max_r2t =
8195 *(uint16_t *)fnode_param->value;
8196 break;
8197 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8198 fnode_conn->keepalive_timeout =
8199 *(uint16_t *)fnode_param->value;
8200 break;
8201 case ISCSI_FLASHNODE_ISID:
8202 memcpy(fnode_sess->isid, fnode_param->value,
8203 sizeof(fnode_sess->isid));
8204 break;
8205 case ISCSI_FLASHNODE_TSID:
8206 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8207 break;
8208 case ISCSI_FLASHNODE_PORT:
8209 fnode_conn->port = *(uint16_t *)fnode_param->value;
8210 break;
8211 case ISCSI_FLASHNODE_MAX_BURST:
8212 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8213 break;
8214 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8215 fnode_sess->default_taskmgmt_timeout =
8216 *(uint16_t *)fnode_param->value;
8217 break;
8218 case ISCSI_FLASHNODE_IPADDR:
8219 memcpy(fnode_conn->ipaddress, fnode_param->value,
8220 IPv6_ADDR_LEN);
8221 break;
8222 case ISCSI_FLASHNODE_ALIAS:
8223 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8224 (char *)fnode_param->value);
8225 break;
8226 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8227 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8228 IPv6_ADDR_LEN);
8229 break;
8230 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8231 fnode_conn->max_segment_size =
8232 *(unsigned *)fnode_param->value;
8233 break;
8234 case ISCSI_FLASHNODE_LOCAL_PORT:
8235 fnode_conn->local_port =
8236 *(uint16_t *)fnode_param->value;
8237 break;
8238 case ISCSI_FLASHNODE_IPV4_TOS:
8239 fnode_conn->ipv4_tos = fnode_param->value[0];
8240 break;
8241 case ISCSI_FLASHNODE_IPV6_TC:
8242 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8243 break;
8244 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8245 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8246 break;
8247 case ISCSI_FLASHNODE_NAME:
8248 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8249 (char *)fnode_param->value);
8250 break;
8251 case ISCSI_FLASHNODE_TPGT:
8252 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8253 break;
8254 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8255 memcpy(fnode_conn->link_local_ipv6_addr,
8256 fnode_param->value, IPv6_ADDR_LEN);
8257 break;
Adheer Chandravanshi65560162013-07-08 08:33:06 -04008258 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8259 fnode_sess->discovery_parent_idx =
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008260 *(uint16_t *)fnode_param->value;
8261 break;
8262 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8263 fnode_conn->tcp_xmit_wsf =
8264 *(uint8_t *)fnode_param->value;
8265 break;
8266 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8267 fnode_conn->tcp_recv_wsf =
8268 *(uint8_t *)fnode_param->value;
8269 break;
8270 case ISCSI_FLASHNODE_STATSN:
8271 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8272 break;
8273 case ISCSI_FLASHNODE_EXP_STATSN:
8274 fnode_conn->exp_statsn =
8275 *(uint32_t *)fnode_param->value;
8276 break;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008277 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8278 chap_out_idx = *(uint16_t *)fnode_param->value;
8279 if (!qla4xxx_get_uni_chap_at_index(ha,
8280 chap_tbl.name,
8281 chap_tbl.secret,
8282 chap_out_idx)) {
8283 fnode_sess->chap_out_idx = chap_out_idx;
8284 /* Enable chap auth if chap index is valid */
8285 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8286 }
8287 break;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008288 default:
8289 ql4_printk(KERN_ERR, ha,
8290 "%s: No such sysfs attribute\n", __func__);
8291 rc = -ENOSYS;
8292 goto exit_set_param;
8293 }
8294 }
8295
8296 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8297
8298exit_set_param:
8299 return rc;
8300}
8301
8302/**
8303 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8304 * @fnode_sess: pointer to session attrs of flash ddb entry
8305 *
8306 * This invalidates the flash ddb entry at the given index
8307 **/
8308static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8309{
8310 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8311 struct scsi_qla_host *ha = to_qla_host(shost);
8312 uint32_t dev_db_start_offset;
8313 uint32_t dev_db_end_offset;
8314 struct dev_db_entry *fw_ddb_entry = NULL;
8315 dma_addr_t fw_ddb_entry_dma;
8316 uint16_t *ddb_cookie = NULL;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04008317 size_t ddb_size = 0;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008318 void *pddb = NULL;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008319 int target_id;
8320 int rc = 0;
8321
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008322 if (fnode_sess->is_boot_target) {
8323 rc = -EPERM;
8324 DEBUG2(ql4_printk(KERN_ERR, ha,
8325 "%s: Deletion of boot target entry is not permitted.\n",
8326 __func__));
8327 goto exit_ddb_del;
8328 }
8329
8330 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8331 goto sysfs_ddb_del;
8332
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008333 if (is_qla40XX(ha)) {
8334 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008335 dev_db_end_offset = FLASH_OFFSET_DB_END;
8336 dev_db_start_offset += (fnode_sess->target_id *
8337 sizeof(*fw_ddb_entry));
8338 ddb_size = sizeof(*fw_ddb_entry);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008339 } else {
8340 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8341 (ha->hw.flt_region_ddb << 2);
8342 /* flt_ddb_size is DDB table size for both ports
8343 * so divide it by 2 to calculate the offset for second port
8344 */
8345 if (ha->port_num == 1)
8346 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008347
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008348 dev_db_end_offset = dev_db_start_offset +
8349 (ha->hw.flt_ddb_size / 2);
8350
8351 dev_db_start_offset += (fnode_sess->target_id *
8352 sizeof(*fw_ddb_entry));
Adheer Chandravanshi1bcb5612013-04-17 05:15:28 -04008353 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008354
8355 ddb_size = sizeof(*ddb_cookie);
8356 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008357
8358 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8359 __func__, dev_db_start_offset, dev_db_end_offset));
8360
8361 if (dev_db_start_offset > dev_db_end_offset) {
8362 rc = -EIO;
8363 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8364 __func__, fnode_sess->target_id));
8365 goto exit_ddb_del;
8366 }
8367
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008368 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8369 &fw_ddb_entry_dma, GFP_KERNEL);
8370 if (!pddb) {
8371 rc = -ENOMEM;
8372 DEBUG2(ql4_printk(KERN_ERR, ha,
8373 "%s: Unable to allocate dma buffer\n",
8374 __func__));
8375 goto exit_ddb_del;
8376 }
8377
8378 if (is_qla40XX(ha)) {
8379 fw_ddb_entry = pddb;
8380 memset(fw_ddb_entry, 0, ddb_size);
8381 ddb_cookie = &fw_ddb_entry->cookie;
8382 } else {
8383 ddb_cookie = pddb;
8384 }
8385
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008386 /* invalidate the cookie */
8387 *ddb_cookie = 0xFFEE;
8388 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008389 ddb_size, FLASH_OPT_RMW_COMMIT);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008390
8391sysfs_ddb_del:
8392 target_id = fnode_sess->target_id;
8393 iscsi_destroy_flashnode_sess(fnode_sess);
8394 ql4_printk(KERN_INFO, ha,
8395 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8396 __func__, target_id, ha->host_no);
8397exit_ddb_del:
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008398 if (pddb)
8399 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8400 fw_ddb_entry_dma);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008401 return rc;
8402}
8403
8404/**
8405 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8406 * @ha: pointer to adapter structure
8407 *
8408 * Export the firmware DDB for all send targets and normal targets to sysfs.
8409 **/
Nilesh Javali906cbf32014-04-09 21:12:25 -04008410int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008411{
8412 struct dev_db_entry *fw_ddb_entry = NULL;
8413 dma_addr_t fw_ddb_entry_dma;
8414 uint16_t max_ddbs;
8415 uint16_t idx = 0;
8416 int ret = QLA_SUCCESS;
8417
8418 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8419 sizeof(*fw_ddb_entry),
8420 &fw_ddb_entry_dma, GFP_KERNEL);
8421 if (!fw_ddb_entry) {
8422 DEBUG2(ql4_printk(KERN_ERR, ha,
8423 "%s: Unable to allocate dma buffer\n",
8424 __func__));
8425 return -ENOMEM;
8426 }
8427
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04008428 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008429 MAX_DEV_DB_ENTRIES;
8430
8431 for (idx = 0; idx < max_ddbs; idx++) {
8432 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8433 idx))
8434 continue;
8435
8436 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8437 if (ret) {
8438 ret = -EIO;
8439 break;
8440 }
8441 }
8442
8443 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8444 fw_ddb_entry_dma);
8445
8446 return ret;
8447}
8448
8449static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8450{
8451 iscsi_destroy_all_flashnode(ha->host);
8452}
8453
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008454/**
8455 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8456 * @ha: pointer to adapter structure
8457 * @is_reset: Is this init path or reset path
8458 *
8459 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8460 * using connection open, then create the list of normal targets (nt)
8461 * from firmware DDBs. Based on the list of nt setup session and connection
8462 * objects.
8463 **/
8464void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8465{
8466 uint16_t tmo = 0;
8467 struct list_head list_st, list_nt;
8468 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8469 unsigned long wtime;
8470
8471 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8472 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8473 ha->is_reset = is_reset;
8474 return;
8475 }
8476
8477 INIT_LIST_HEAD(&list_st);
8478 INIT_LIST_HEAD(&list_nt);
8479
8480 qla4xxx_build_st_list(ha, &list_st);
8481
Mike Christie13483732011-12-01 21:38:41 -06008482 /* Before issuing conn open mbox, ensure all IPs states are configured
8483 * Note, conn open fails if IPs are not configured
8484 */
8485 qla4xxx_wait_for_ip_configuration(ha);
8486
8487 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8488 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8489 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8490 }
8491
8492 /* Wait to ensure all sendtargets are done for min 12 sec wait */
Nilesh Javalic28eaac2011-12-18 21:40:44 -08008493 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8494 (ha->def_timeout < LOGIN_TOV * 10) ?
8495 ha->def_timeout : LOGIN_TOV);
8496
Mike Christie13483732011-12-01 21:38:41 -06008497 DEBUG2(ql4_printk(KERN_INFO, ha,
8498 "Default time to wait for build ddb %d\n", tmo));
8499
8500 wtime = jiffies + (HZ * tmo);
8501 do {
Nilesh Javalif1f2e602011-12-16 01:58:57 -08008502 if (list_empty(&list_st))
8503 break;
8504
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008505 qla4xxx_remove_failed_ddb(ha, &list_st);
Mike Christie13483732011-12-01 21:38:41 -06008506 schedule_timeout_uninterruptible(HZ / 10);
8507 } while (time_after(wtime, jiffies));
8508
Manish Rangankarad8bd452013-09-17 07:30:02 -04008509
8510 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8511
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008512 qla4xxx_free_ddb_list(&list_st);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008513 qla4xxx_free_ddb_list(&list_nt);
Mike Christie13483732011-12-01 21:38:41 -06008514
8515 qla4xxx_free_ddb_index(ha);
8516}
8517
David Somayajuluafaf5a22006-09-19 10:28:00 -07008518/**
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008519 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8520 * response.
8521 * @ha: pointer to adapter structure
8522 *
8523 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8524 * set in DDB and we will wait for login response of boot targets during
8525 * probe.
8526 **/
8527static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8528{
8529 struct ddb_entry *ddb_entry;
8530 struct dev_db_entry *fw_ddb_entry = NULL;
8531 dma_addr_t fw_ddb_entry_dma;
8532 unsigned long wtime;
8533 uint32_t ddb_state;
8534 int max_ddbs, idx, ret;
8535
8536 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8537 MAX_DEV_DB_ENTRIES;
8538
8539 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8540 &fw_ddb_entry_dma, GFP_KERNEL);
8541 if (!fw_ddb_entry) {
8542 ql4_printk(KERN_ERR, ha,
8543 "%s: Unable to allocate dma buffer\n", __func__);
8544 goto exit_login_resp;
8545 }
8546
8547 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8548
8549 for (idx = 0; idx < max_ddbs; idx++) {
8550 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8551 if (ddb_entry == NULL)
8552 continue;
8553
8554 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8555 DEBUG2(ql4_printk(KERN_INFO, ha,
8556 "%s: DDB index [%d]\n", __func__,
8557 ddb_entry->fw_ddb_index));
8558 do {
8559 ret = qla4xxx_get_fwddb_entry(ha,
8560 ddb_entry->fw_ddb_index,
8561 fw_ddb_entry, fw_ddb_entry_dma,
8562 NULL, NULL, &ddb_state, NULL,
8563 NULL, NULL);
8564 if (ret == QLA_ERROR)
8565 goto exit_login_resp;
8566
8567 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8568 (ddb_state == DDB_DS_SESSION_FAILED))
8569 break;
8570
8571 schedule_timeout_uninterruptible(HZ);
8572
8573 } while ((time_after(wtime, jiffies)));
8574
8575 if (!time_after(wtime, jiffies)) {
8576 DEBUG2(ql4_printk(KERN_INFO, ha,
8577 "%s: Login response wait timer expired\n",
8578 __func__));
8579 goto exit_login_resp;
8580 }
8581 }
8582 }
8583
8584exit_login_resp:
8585 if (fw_ddb_entry)
8586 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8587 fw_ddb_entry, fw_ddb_entry_dma);
8588}
8589
8590/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07008591 * qla4xxx_probe_adapter - callback function to probe HBA
8592 * @pdev: pointer to pci_dev structure
8593 * @pci_device_id: pointer to pci_device entry
8594 *
8595 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8596 * It returns zero if successful. It also initializes all data necessary for
8597 * the driver.
8598 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008599static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8600 const struct pci_device_id *ent)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008601{
8602 int ret = -ENODEV, status;
8603 struct Scsi_Host *host;
8604 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008605 uint8_t init_retry_count = 0;
8606 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308607 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008608 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008609
8610 if (pci_enable_device(pdev))
8611 return -1;
8612
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008613 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008614 if (host == NULL) {
8615 printk(KERN_WARNING
8616 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8617 goto probe_disable_device;
8618 }
8619
8620 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008621 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008622 memset(ha, 0, sizeof(*ha));
8623
8624 /* Save the information from PCI BIOS. */
8625 ha->pdev = pdev;
8626 ha->host = host;
8627 ha->host_no = host->host_no;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008628 ha->func_num = PCI_FUNC(ha->pdev->devfn);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008629
Lalit Chandivade2232be02010-07-30 14:38:47 +05308630 pci_enable_pcie_error_reporting(pdev);
8631
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308632 /* Setup Runtime configurable options */
8633 if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04008634 ha->isp_ops = &qla4_82xx_isp_ops;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008635 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308636 ha->qdr_sn_window = -1;
8637 ha->ddr_mn_window = -1;
8638 ha->curr_window = 255;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308639 nx_legacy_intr = &legacy_intr[ha->func_num];
8640 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8641 ha->nx_legacy_intr.tgt_status_reg =
8642 nx_legacy_intr->tgt_status_reg;
8643 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8644 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008645 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008646 ha->isp_ops = &qla4_83xx_isp_ops;
8647 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308648 } else {
8649 ha->isp_ops = &qla4xxx_isp_ops;
8650 }
8651
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008652 if (is_qla80XX(ha)) {
8653 rwlock_init(&ha->hw_lock);
8654 ha->pf_bit = ha->func_num << 16;
8655 /* Set EEH reset type to fundamental if required by hba */
Lalit Chandivade2232be02010-07-30 14:38:47 +05308656 pdev->needs_freset = 1;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008657 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05308658
David Somayajuluafaf5a22006-09-19 10:28:00 -07008659 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308660 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008661 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308662 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008663
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308664 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07008665 pdev->device, pdev->irq, ha->reg);
8666
8667 qla4xxx_config_dma_addressing(ha);
8668
8669 /* Initialize lists and spinlocks. */
David Somayajuluafaf5a22006-09-19 10:28:00 -07008670 INIT_LIST_HEAD(&ha->free_srb_q);
8671
8672 mutex_init(&ha->mbox_sem);
Lalit Chandivade45494152011-10-07 16:55:42 -07008673 mutex_init(&ha->chap_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308674 init_completion(&ha->mbx_intr_comp);
Vikas Chaudhary95d31262011-08-12 02:51:29 -07008675 init_completion(&ha->disable_acb_comp);
Vikas Chaudharydf86f772013-11-22 05:28:17 -05008676 init_completion(&ha->idc_comp);
8677 init_completion(&ha->link_up_comp);
8678 init_completion(&ha->disable_acb_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008679
8680 spin_lock_init(&ha->hardware_lock);
Vikas Chaudhary8e9157c2012-08-22 07:45:24 -04008681 spin_lock_init(&ha->work_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008682
Vikas Chaudharyff884432011-08-29 23:43:02 +05308683 /* Initialize work list */
8684 INIT_LIST_HEAD(&ha->work_list);
8685
David Somayajuluafaf5a22006-09-19 10:28:00 -07008686 /* Allocate dma buffers */
8687 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308688 ql4_printk(KERN_WARNING, ha,
8689 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008690
8691 ret = -ENOMEM;
8692 goto probe_failed;
8693 }
8694
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008695 host->cmd_per_lun = 3;
8696 host->max_channel = 0;
8697 host->max_lun = MAX_LUNS - 1;
8698 host->max_id = MAX_TARGETS;
8699 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8700 host->can_queue = MAX_SRBS ;
8701 host->transportt = qla4xxx_scsi_transport;
8702
8703 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
8704 if (ret) {
8705 ql4_printk(KERN_WARNING, ha,
8706 "%s: scsi_init_shared_tag_map failed\n", __func__);
8707 goto probe_failed;
8708 }
8709
8710 pci_set_drvdata(pdev, ha);
8711
8712 ret = scsi_add_host(host, &pdev->dev);
8713 if (ret)
8714 goto probe_failed;
8715
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008716 if (is_qla80XX(ha))
8717 qla4_8xxx_get_flash_info(ha);
8718
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008719 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008720 qla4_83xx_read_reset_template(ha);
8721 /*
8722 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8723 * If DONRESET_BIT0 is set, drivers should not set dev_state
8724 * to NEED_RESET. But if NEED_RESET is set, drivers should
8725 * should honor the reset.
8726 */
8727 if (ql4xdontresethba == 1)
8728 qla4_83xx_set_idc_dontreset(ha);
8729 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308730
David Somayajuluafaf5a22006-09-19 10:28:00 -07008731 /*
8732 * Initialize the Host adapter request/response queues and
8733 * firmware
8734 * NOTE: interrupts enabled upon successful completion
8735 */
Mike Christie13483732011-12-01 21:38:41 -06008736 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Poornima Vonti7977f822012-09-20 07:35:07 -04008737
8738 /* Dont retry adapter initialization if IRQ allocation failed */
Nilesh Javali37418cc2013-12-16 06:49:31 -05008739 if (is_qla80XX(ha) && (status == QLA_ERROR))
Poornima Vonti7977f822012-09-20 07:35:07 -04008740 goto skip_retry_init;
8741
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308742 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8743 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008744
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008745 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008746 ha->isp_ops->idc_lock(ha);
8747 dev_state = qla4_8xxx_rd_direct(ha,
Vikas Chaudharye951aca2012-12-29 02:24:52 -05008748 QLA8XXX_CRB_DEV_STATE);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008749 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04008750 if (dev_state == QLA8XXX_DEV_FAILED) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008751 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8752 "initialize adapter. H/W is in failed state\n",
8753 __func__);
8754 break;
8755 }
8756 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008757 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8758 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308759
8760 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8761 continue;
8762
Mike Christie13483732011-12-01 21:38:41 -06008763 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Nilesh Javali37418cc2013-12-16 06:49:31 -05008764 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8765 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8766 goto skip_retry_init;
8767 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008768 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308769
Poornima Vonti7977f822012-09-20 07:35:07 -04008770skip_retry_init:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308771 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308772 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008773
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008774 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008775 ((is_qla8032(ha) || is_qla8042(ha)) &&
8776 qla4_83xx_idc_dontreset(ha))) {
Lalit Chandivadefe998522010-12-02 22:12:36 -08008777 /* Put the device in failed state. */
8778 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008779 ha->isp_ops->idc_lock(ha);
8780 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8781 QLA8XXX_DEV_FAILED);
8782 ha->isp_ops->idc_unlock(ha);
Lalit Chandivadefe998522010-12-02 22:12:36 -08008783 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008784 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008785 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008786 }
8787
David Somayajuluafaf5a22006-09-19 10:28:00 -07008788 /* Startup the kernel thread for this host adapter. */
8789 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8790 "qla4xxx_dpc\n", __func__));
8791 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8792 ha->dpc_thread = create_singlethread_workqueue(buf);
8793 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308794 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008795 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008796 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008797 }
David Howellsc4028952006-11-22 14:57:56 +00008798 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008799
Kees Cookd8537542013-07-03 15:04:57 -07008800 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8801 ha->host_no);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008802 if (!ha->task_wq) {
8803 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8804 ret = -ENODEV;
8805 goto remove_host;
8806 }
8807
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008808 /*
8809 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308810 * (which is called indirectly by qla4xxx_initialize_adapter),
8811 * so that irqs will be registered after crbinit but before
8812 * mbx_intr_enable.
8813 */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008814 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308815 ret = qla4xxx_request_irqs(ha);
8816 if (ret) {
8817 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8818 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008819 goto remove_host;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308820 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008821 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008822
Lalit Chandivade2232be02010-07-30 14:38:47 +05308823 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308824 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008825
8826 /* Start timer thread. */
8827 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
8828
8829 set_bit(AF_INIT_DONE, &ha->flags);
8830
Tej Parkash068237c82012-05-18 04:41:44 -04008831 qla4_8xxx_alloc_sysfs_attr(ha);
8832
David Somayajuluafaf5a22006-09-19 10:28:00 -07008833 printk(KERN_INFO
8834 " QLogic iSCSI HBA Driver version: %s\n"
8835 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8836 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
Adheer Chandravanshieee06a02013-07-08 08:33:10 -04008837 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8838 ha->fw_info.fw_patch, ha->fw_info.fw_build);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008839
Manish Dusanecfb27872012-09-20 07:35:01 -04008840 /* Set the driver version */
8841 if (is_qla80XX(ha))
8842 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8843
Manish Rangankar2a991c22011-07-25 13:48:55 -05008844 if (qla4xxx_setup_boot_info(ha))
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -08008845 ql4_printk(KERN_ERR, ha,
8846 "%s: No iSCSI boot target configured\n", __func__);
Manish Rangankar2a991c22011-07-25 13:48:55 -05008847
Nilesh Javali906cbf32014-04-09 21:12:25 -04008848 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8849 /* Perform the build ddb list and login to each */
Mike Christie13483732011-12-01 21:38:41 -06008850 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8851 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008852 qla4xxx_wait_login_resp_boot_tgt(ha);
Mike Christie13483732011-12-01 21:38:41 -06008853
8854 qla4xxx_create_chap_list(ha);
8855
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008856 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008857 return 0;
8858
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008859remove_host:
8860 scsi_remove_host(ha->host);
8861
David Somayajuluafaf5a22006-09-19 10:28:00 -07008862probe_failed:
8863 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308864
8865probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05308866 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008867 scsi_host_put(ha->host);
8868
8869probe_disable_device:
8870 pci_disable_device(pdev);
8871
8872 return ret;
8873}
8874
8875/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07008876 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8877 * @ha: pointer to adapter structure
8878 *
8879 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8880 * so that the other port will not re-initialize while in the process of
8881 * removing the ha due to driver unload or hba hotplug.
8882 **/
8883static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8884{
8885 struct scsi_qla_host *other_ha = NULL;
8886 struct pci_dev *other_pdev = NULL;
8887 int fn = ISP4XXX_PCI_FN_2;
8888
8889 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8890 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8891 fn = ISP4XXX_PCI_FN_1;
8892
8893 other_pdev =
8894 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8895 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8896 fn));
8897
8898 /* Get other_ha if other_pdev is valid and state is enable*/
8899 if (other_pdev) {
8900 if (atomic_read(&other_pdev->enable_cnt)) {
8901 other_ha = pci_get_drvdata(other_pdev);
8902 if (other_ha) {
8903 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8904 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8905 "Prevent %s reinit\n", __func__,
8906 dev_name(&other_ha->pdev->dev)));
8907 }
8908 }
8909 pci_dev_put(other_pdev);
8910 }
8911}
8912
Vikas Chaudhary28d958b2014-01-17 04:43:28 -05008913static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8914 struct ddb_entry *ddb_entry)
8915{
8916 struct dev_db_entry *fw_ddb_entry = NULL;
8917 dma_addr_t fw_ddb_entry_dma;
8918 unsigned long wtime;
8919 uint32_t ddb_state;
8920 int options;
8921 int status;
8922
8923 options = LOGOUT_OPTION_CLOSE_SESSION;
8924 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8925 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8926 goto clear_ddb;
8927 }
8928
8929 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8930 &fw_ddb_entry_dma, GFP_KERNEL);
8931 if (!fw_ddb_entry) {
8932 ql4_printk(KERN_ERR, ha,
8933 "%s: Unable to allocate dma buffer\n", __func__);
8934 goto clear_ddb;
8935 }
8936
8937 wtime = jiffies + (HZ * LOGOUT_TOV);
8938 do {
8939 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8940 fw_ddb_entry, fw_ddb_entry_dma,
8941 NULL, NULL, &ddb_state, NULL,
8942 NULL, NULL);
8943 if (status == QLA_ERROR)
8944 goto free_ddb;
8945
8946 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8947 (ddb_state == DDB_DS_SESSION_FAILED))
8948 goto free_ddb;
8949
8950 schedule_timeout_uninterruptible(HZ);
8951 } while ((time_after(wtime, jiffies)));
8952
8953free_ddb:
8954 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8955 fw_ddb_entry, fw_ddb_entry_dma);
8956clear_ddb:
8957 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8958}
8959
Mike Christie13483732011-12-01 21:38:41 -06008960static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8961{
8962 struct ddb_entry *ddb_entry;
Mike Christie13483732011-12-01 21:38:41 -06008963 int idx;
8964
8965 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8966
8967 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8968 if ((ddb_entry != NULL) &&
8969 (ddb_entry->ddb_type == FLASH_DDB)) {
8970
Vikas Chaudhary28d958b2014-01-17 04:43:28 -05008971 qla4xxx_destroy_ddb(ha, ddb_entry);
Mike Christie13483732011-12-01 21:38:41 -06008972 /*
8973 * we have decremented the reference count of the driver
8974 * when we setup the session to have the driver unload
8975 * to be seamless without actually destroying the
8976 * session
8977 **/
8978 try_module_get(qla4xxx_iscsi_transport.owner);
8979 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8980 qla4xxx_free_ddb(ha, ddb_entry);
8981 iscsi_session_teardown(ddb_entry->sess);
8982 }
8983 }
8984}
Karen Higgins7eece5a2011-03-21 03:34:29 -07008985/**
Masanari Iida59e13d42012-04-25 00:24:16 +09008986 * qla4xxx_remove_adapter - callback function to remove adapter.
David Somayajuluafaf5a22006-09-19 10:28:00 -07008987 * @pci_dev: PCI device pointer
8988 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008989static void qla4xxx_remove_adapter(struct pci_dev *pdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008990{
8991 struct scsi_qla_host *ha;
8992
Vikas Chaudharyf8b07512012-09-20 07:35:08 -04008993 /*
8994 * If the PCI device is disabled then it means probe_adapter had
8995 * failed and resources already cleaned up on probe_adapter exit.
8996 */
8997 if (!pci_is_enabled(pdev))
8998 return;
8999
David Somayajuluafaf5a22006-09-19 10:28:00 -07009000 ha = pci_get_drvdata(pdev);
9001
Vikas Chaudharyee996a62012-08-22 07:55:05 -04009002 if (is_qla40XX(ha))
Karen Higgins7eece5a2011-03-21 03:34:29 -07009003 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07009004
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05009005 /* destroy iface from sysfs */
9006 qla4xxx_destroy_ifaces(ha);
9007
Mike Christie13483732011-12-01 21:38:41 -06009008 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
Manish Rangankar2a991c22011-07-25 13:48:55 -05009009 iscsi_boot_destroy_kset(ha->boot_kset);
9010
Mike Christie13483732011-12-01 21:38:41 -06009011 qla4xxx_destroy_fw_ddb_session(ha);
Tej Parkash068237c82012-05-18 04:41:44 -04009012 qla4_8xxx_free_sysfs_attr(ha);
Mike Christie13483732011-12-01 21:38:41 -06009013
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04009014 qla4xxx_sysfs_ddb_remove(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009015 scsi_remove_host(ha->host);
9016
9017 qla4xxx_free_adapter(ha);
9018
9019 scsi_host_put(ha->host);
9020
Lalit Chandivade2232be02010-07-30 14:38:47 +05309021 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309022 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009023}
9024
9025/**
9026 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9027 * @ha: HA context
9028 *
9029 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
9030 * supported addressing method.
9031 */
Adrian Bunk47975472007-04-26 00:35:16 -07009032static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009033{
9034 int retval;
9035
9036 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07009037 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
9038 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009039 dev_dbg(&ha->pdev->dev,
9040 "Failed to set 64 bit PCI consistent mask; "
9041 "using 32 bit.\n");
9042 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07009043 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07009044 }
9045 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07009046 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07009047}
9048
9049static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9050{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009051 struct iscsi_cls_session *cls_sess;
9052 struct iscsi_session *sess;
9053 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07009054 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009055
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009056 cls_sess = starget_to_session(sdev->sdev_target);
9057 sess = cls_sess->dd_data;
9058 ddb = sess->dd_data;
9059
David Somayajuluafaf5a22006-09-19 10:28:00 -07009060 sdev->hostdata = ddb;
9061 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07009062
9063 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9064 queue_depth = ql4xmaxqdepth;
9065
9066 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009067 return 0;
9068}
9069
9070static int qla4xxx_slave_configure(struct scsi_device *sdev)
9071{
9072 sdev->tagged_supported = 1;
9073 return 0;
9074}
9075
9076static void qla4xxx_slave_destroy(struct scsi_device *sdev)
9077{
9078 scsi_deactivate_tcq(sdev, 1);
9079}
9080
Tej Parkashf7b4aa62012-04-30 04:12:19 -07009081static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
9082 int reason)
9083{
9084 if (!ql4xqfulltracking)
9085 return -EOPNOTSUPP;
9086
9087 return iscsi_change_queue_depth(sdev, qdepth, reason);
9088}
9089
David Somayajuluafaf5a22006-09-19 10:28:00 -07009090/**
9091 * qla4xxx_del_from_active_array - returns an active srb
9092 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02009093 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07009094 *
9095 * This routine removes and returns the srb at the specified index
9096 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309097struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9098 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009099{
9100 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05309101 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009102
Vikas Chaudhary53698872010-04-28 11:41:59 +05309103 cmd = scsi_host_find_tag(ha->host, index);
9104 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009105 return srb;
9106
Vikas Chaudhary53698872010-04-28 11:41:59 +05309107 srb = (struct srb *)CMD_SP(cmd);
9108 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009109 return srb;
9110
9111 /* update counters */
9112 if (srb->flags & SRB_DMA_VALID) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009113 ha->iocb_cnt -= srb->iocb_cnt;
9114 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05309115 srb->cmd->host_scribble =
9116 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009117 }
9118 return srb;
9119}
9120
9121/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009122 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309123 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07009124 * @cmd: Scsi Command to wait on.
9125 *
9126 * This routine waits for the command to be returned by the Firmware
9127 * for some max time.
9128 **/
9129static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9130 struct scsi_cmnd *cmd)
9131{
9132 int done = 0;
9133 struct srb *rp;
9134 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309135 int ret = SUCCESS;
9136
9137 /* Dont wait on command if PCI error is being handled
9138 * by PCI AER driver
9139 */
9140 if (unlikely(pci_channel_offline(ha->pdev)) ||
9141 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9142 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9143 ha->host_no, __func__);
9144 return ret;
9145 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07009146
9147 do {
9148 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05309149 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009150 if (rp == NULL) {
9151 done++;
9152 break;
9153 }
9154
9155 msleep(2000);
9156 } while (max_wait_time--);
9157
9158 return done;
9159}
9160
9161/**
9162 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9163 * @ha: Pointer to host adapter structure
9164 **/
9165static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9166{
9167 unsigned long wait_online;
9168
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07009169 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009170 while (time_before(jiffies, wait_online)) {
9171
9172 if (adapter_up(ha))
9173 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009174
9175 msleep(2000);
9176 }
9177
9178 return QLA_ERROR;
9179}
9180
9181/**
Mike Christiece545032008-02-29 18:25:20 -06009182 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02009183 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07009184 * @t: target id
9185 * @l: lun id
9186 *
9187 * This function waits for all outstanding commands to a lun to complete. It
9188 * returns 0 if all pending commands are returned and 1 otherwise.
9189 **/
Mike Christiece545032008-02-29 18:25:20 -06009190static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9191 struct scsi_target *stgt,
9192 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009193{
9194 int cnt;
9195 int status = 0;
9196 struct scsi_cmnd *cmd;
9197
9198 /*
Mike Christiece545032008-02-29 18:25:20 -06009199 * Waiting for all commands for the designated target or dev
9200 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07009201 */
9202 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9203 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06009204 if (cmd && stgt == scsi_target(cmd->device) &&
9205 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009206 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9207 status++;
9208 break;
9209 }
9210 }
9211 }
9212 return status;
9213}
9214
9215/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309216 * qla4xxx_eh_abort - callback for abort task.
9217 * @cmd: Pointer to Linux's SCSI command structure
9218 *
9219 * This routine is called by the Linux OS to abort the specified
9220 * command.
9221 **/
9222static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9223{
9224 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9225 unsigned int id = cmd->device->id;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009226 uint64_t lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07009227 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309228 struct srb *srb = NULL;
9229 int ret = SUCCESS;
9230 int wait = 0;
9231
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009232 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
Vikas Chaudhary63c9e812013-12-16 06:49:50 -05009233 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309234
Mike Christie92b3e5b2010-10-06 22:51:17 -07009235 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309236 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07009237 if (!srb) {
9238 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009239 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
Vikas Chaudhary63c9e812013-12-16 06:49:50 -05009240 ha->host_no, id, lun);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309241 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07009242 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309243 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07009244 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309245
9246 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009247 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309248 ha->host_no, id, lun));
9249 ret = FAILED;
9250 } else {
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009251 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309252 ha->host_no, id, lun));
9253 wait = 1;
9254 }
9255
9256 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9257
9258 /* Wait for command to complete */
9259 if (wait) {
9260 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009261 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309262 ha->host_no, id, lun));
9263 ret = FAILED;
9264 }
9265 }
9266
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309267 ql4_printk(KERN_INFO, ha,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009268 "scsi%ld:%d:%llu: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009269 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309270
9271 return ret;
9272}
9273
9274/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009275 * qla4xxx_eh_device_reset - callback for target reset.
9276 * @cmd: Pointer to Linux's SCSI command structure
9277 *
9278 * This routine is called by the Linux OS to reset all luns on the
9279 * specified target.
9280 **/
9281static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9282{
9283 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9284 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009285 int ret = FAILED, stat;
9286
Karen Higgins612f7342009-07-15 15:03:01 -05009287 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009288 return ret;
9289
Mike Christiec01be6d2010-07-22 16:59:49 +05309290 ret = iscsi_block_scsi_eh(cmd);
9291 if (ret)
9292 return ret;
9293 ret = FAILED;
9294
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309295 ql4_printk(KERN_INFO, ha,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009296 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009297 cmd->device->channel, cmd->device->id, cmd->device->lun);
9298
9299 DEBUG2(printk(KERN_INFO
9300 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9301 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07009302 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009303 ha->dpc_flags, cmd->result, cmd->allowed));
9304
9305 /* FIXME: wait for hba to go online */
9306 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9307 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309308 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009309 goto eh_dev_reset_done;
9310 }
9311
Mike Christiece545032008-02-29 18:25:20 -06009312 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9313 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309314 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06009315 "DEVICE RESET FAILED - waiting for "
9316 "commands.\n");
9317 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009318 }
9319
David C Somayajulu9d562912008-03-19 11:23:03 -07009320 /* Send marker. */
9321 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9322 MM_LUN_RESET) != QLA_SUCCESS)
9323 goto eh_dev_reset_done;
9324
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309325 ql4_printk(KERN_INFO, ha,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009326 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07009327 ha->host_no, cmd->device->channel, cmd->device->id,
9328 cmd->device->lun);
9329
9330 ret = SUCCESS;
9331
9332eh_dev_reset_done:
9333
9334 return ret;
9335}
9336
9337/**
Mike Christiece545032008-02-29 18:25:20 -06009338 * qla4xxx_eh_target_reset - callback for target reset.
9339 * @cmd: Pointer to Linux's SCSI command structure
9340 *
9341 * This routine is called by the Linux OS to reset the target.
9342 **/
9343static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9344{
9345 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9346 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05309347 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06009348
9349 if (!ddb_entry)
9350 return FAILED;
9351
Mike Christiec01be6d2010-07-22 16:59:49 +05309352 ret = iscsi_block_scsi_eh(cmd);
9353 if (ret)
9354 return ret;
9355
Mike Christiece545032008-02-29 18:25:20 -06009356 starget_printk(KERN_INFO, scsi_target(cmd->device),
9357 "WARM TARGET RESET ISSUED.\n");
9358
9359 DEBUG2(printk(KERN_INFO
9360 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9361 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07009362 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06009363 ha->dpc_flags, cmd->result, cmd->allowed));
9364
9365 stat = qla4xxx_reset_target(ha, ddb_entry);
9366 if (stat != QLA_SUCCESS) {
9367 starget_printk(KERN_INFO, scsi_target(cmd->device),
9368 "WARM TARGET RESET FAILED.\n");
9369 return FAILED;
9370 }
9371
Mike Christiece545032008-02-29 18:25:20 -06009372 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9373 NULL)) {
9374 starget_printk(KERN_INFO, scsi_target(cmd->device),
9375 "WARM TARGET DEVICE RESET FAILED - "
9376 "waiting for commands.\n");
9377 return FAILED;
9378 }
9379
David C Somayajulu9d562912008-03-19 11:23:03 -07009380 /* Send marker. */
9381 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9382 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9383 starget_printk(KERN_INFO, scsi_target(cmd->device),
9384 "WARM TARGET DEVICE RESET FAILED - "
9385 "marker iocb failed.\n");
9386 return FAILED;
9387 }
9388
Mike Christiece545032008-02-29 18:25:20 -06009389 starget_printk(KERN_INFO, scsi_target(cmd->device),
9390 "WARM TARGET RESET SUCCEEDED.\n");
9391 return SUCCESS;
9392}
9393
9394/**
Sarang Radke8a28896012011-12-06 02:34:10 -08009395 * qla4xxx_is_eh_active - check if error handler is running
9396 * @shost: Pointer to SCSI Host struct
9397 *
9398 * This routine finds that if reset host is called in EH
9399 * scenario or from some application like sg_reset
9400 **/
9401static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9402{
9403 if (shost->shost_state == SHOST_RECOVERY)
9404 return 1;
9405 return 0;
9406}
9407
9408/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009409 * qla4xxx_eh_host_reset - kernel callback
9410 * @cmd: Pointer to Linux's SCSI command structure
9411 *
9412 * This routine is invoked by the Linux kernel to perform fatal error
9413 * recovery on the specified adapter.
9414 **/
9415static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9416{
9417 int return_status = FAILED;
9418 struct scsi_qla_host *ha;
9419
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009420 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009421
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009422 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009423 qla4_83xx_set_idc_dontreset(ha);
9424
9425 /*
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009426 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9427 * protocol drivers, we should not set device_state to NEED_RESET
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009428 */
9429 if (ql4xdontresethba ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009430 ((is_qla8032(ha) || is_qla8042(ha)) &&
9431 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309432 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9433 ha->host_no, __func__));
Sarang Radke8a28896012011-12-06 02:34:10 -08009434
9435 /* Clear outstanding srb in queues */
9436 if (qla4xxx_is_eh_active(cmd->device->host))
9437 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9438
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309439 return FAILED;
9440 }
9441
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309442 ql4_printk(KERN_INFO, ha,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02009443 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009444 cmd->device->channel, cmd->device->id, cmd->device->lun);
9445
9446 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9447 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9448 "DEAD.\n", ha->host_no, cmd->device->channel,
9449 __func__));
9450
9451 return FAILED;
9452 }
9453
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309454 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009455 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309456 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9457 else
9458 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9459 }
Mike Christie50a29ae2008-03-04 13:26:53 -06009460
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309461 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009462 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009463
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309464 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009465 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07009466
9467 return return_status;
9468}
9469
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009470static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9471{
9472 uint32_t mbox_cmd[MBOX_REG_COUNT];
9473 uint32_t mbox_sts[MBOX_REG_COUNT];
9474 struct addr_ctrl_blk_def *acb = NULL;
9475 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9476 int rval = QLA_SUCCESS;
9477 dma_addr_t acb_dma;
9478
9479 acb = dma_alloc_coherent(&ha->pdev->dev,
9480 sizeof(struct addr_ctrl_blk_def),
9481 &acb_dma, GFP_KERNEL);
9482 if (!acb) {
9483 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9484 __func__);
9485 rval = -ENOMEM;
9486 goto exit_port_reset;
9487 }
9488
9489 memset(acb, 0, acb_len);
9490
9491 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9492 if (rval != QLA_SUCCESS) {
9493 rval = -EIO;
9494 goto exit_free_acb;
9495 }
9496
9497 rval = qla4xxx_disable_acb(ha);
9498 if (rval != QLA_SUCCESS) {
9499 rval = -EIO;
9500 goto exit_free_acb;
9501 }
9502
9503 wait_for_completion_timeout(&ha->disable_acb_comp,
9504 DISABLE_ACB_TOV * HZ);
9505
9506 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9507 if (rval != QLA_SUCCESS) {
9508 rval = -EIO;
9509 goto exit_free_acb;
9510 }
9511
9512exit_free_acb:
9513 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9514 acb, acb_dma);
9515exit_port_reset:
9516 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9517 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9518 return rval;
9519}
9520
9521static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9522{
9523 struct scsi_qla_host *ha = to_qla_host(shost);
9524 int rval = QLA_SUCCESS;
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009525 uint32_t idc_ctrl;
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009526
9527 if (ql4xdontresethba) {
9528 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9529 __func__));
9530 rval = -EPERM;
9531 goto exit_host_reset;
9532 }
9533
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009534 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9535 goto recover_adapter;
9536
9537 switch (reset_type) {
9538 case SCSI_ADAPTER_RESET:
9539 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9540 break;
9541 case SCSI_FIRMWARE_RESET:
9542 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009543 if (is_qla80XX(ha))
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009544 /* set firmware context reset */
9545 set_bit(DPC_RESET_HA_FW_CONTEXT,
9546 &ha->dpc_flags);
9547 else {
9548 rval = qla4xxx_context_reset(ha);
9549 goto exit_host_reset;
9550 }
9551 }
9552 break;
9553 }
9554
9555recover_adapter:
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009556 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009557 * reset is issued by application */
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009558 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9559 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009560 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9561 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9562 (idc_ctrl | GRACEFUL_RESET_BIT1));
9563 }
9564
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009565 rval = qla4xxx_recover_adapter(ha);
9566 if (rval != QLA_SUCCESS) {
9567 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9568 __func__));
9569 rval = -EIO;
9570 }
9571
9572exit_host_reset:
9573 return rval;
9574}
9575
Lalit Chandivade2232be02010-07-30 14:38:47 +05309576/* PCI AER driver recovers from all correctable errors w/o
9577 * driver intervention. For uncorrectable errors PCI AER
9578 * driver calls the following device driver's callbacks
9579 *
9580 * - Fatal Errors - link_reset
9581 * - Non-Fatal Errors - driver's pci_error_detected() which
9582 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9583 *
9584 * PCI AER driver calls
9585 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
9586 * returns RECOVERED or NEED_RESET if fw_hung
9587 * NEED_RESET - driver's slot_reset()
9588 * DISCONNECT - device is dead & cannot recover
9589 * RECOVERED - driver's pci_resume()
9590 */
9591static pci_ers_result_t
9592qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9593{
9594 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9595
9596 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9597 ha->host_no, __func__, state);
9598
9599 if (!is_aer_supported(ha))
9600 return PCI_ERS_RESULT_NONE;
9601
9602 switch (state) {
9603 case pci_channel_io_normal:
9604 clear_bit(AF_EEH_BUSY, &ha->flags);
9605 return PCI_ERS_RESULT_CAN_RECOVER;
9606 case pci_channel_io_frozen:
9607 set_bit(AF_EEH_BUSY, &ha->flags);
9608 qla4xxx_mailbox_premature_completion(ha);
9609 qla4xxx_free_irqs(ha);
9610 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009611 /* Return back all IOs */
9612 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309613 return PCI_ERS_RESULT_NEED_RESET;
9614 case pci_channel_io_perm_failure:
9615 set_bit(AF_EEH_BUSY, &ha->flags);
9616 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9617 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9618 return PCI_ERS_RESULT_DISCONNECT;
9619 }
9620 return PCI_ERS_RESULT_NEED_RESET;
9621}
9622
9623/**
9624 * qla4xxx_pci_mmio_enabled() gets called if
9625 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9626 * and read/write to the device still works.
9627 **/
9628static pci_ers_result_t
9629qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9630{
9631 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9632
9633 if (!is_aer_supported(ha))
9634 return PCI_ERS_RESULT_NONE;
9635
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009636 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309637}
9638
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009639static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05309640{
9641 uint32_t rval = QLA_ERROR;
9642 int fn;
9643 struct pci_dev *other_pdev = NULL;
9644
9645 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9646
9647 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9648
9649 if (test_bit(AF_ONLINE, &ha->flags)) {
9650 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009651 clear_bit(AF_LINK_UP, &ha->flags);
9652 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309653 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309654 }
9655
9656 fn = PCI_FUNC(ha->pdev->devfn);
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009657 if (is_qla8022(ha)) {
9658 while (fn > 0) {
9659 fn--;
9660 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9661 ha->host_no, __func__, fn);
9662 /* Get the pci device given the domain, bus,
9663 * slot/function number */
9664 other_pdev = pci_get_domain_bus_and_slot(
9665 pci_domain_nr(ha->pdev->bus),
9666 ha->pdev->bus->number,
9667 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9668 fn));
Lalit Chandivade2232be02010-07-30 14:38:47 +05309669
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009670 if (!other_pdev)
9671 continue;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309672
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009673 if (atomic_read(&other_pdev->enable_cnt)) {
9674 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9675 ha->host_no, __func__, fn);
9676 pci_dev_put(other_pdev);
9677 break;
9678 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309679 pci_dev_put(other_pdev);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309680 }
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009681 } else {
9682 /* this case is meant for ISP83xx/ISP84xx only */
9683 if (qla4_83xx_can_perform_reset(ha)) {
9684 /* reset fn as iSCSI is going to perform the reset */
9685 fn = 0;
9686 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309687 }
9688
9689 /* The first function on the card, the reset owner will
9690 * start & initialize the firmware. The other functions
9691 * on the card will reset the firmware context
9692 */
9693 if (!fn) {
9694 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9695 "0x%x is the owner\n", ha->host_no, __func__,
9696 ha->pdev->devfn);
9697
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009698 ha->isp_ops->idc_lock(ha);
9699 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9700 QLA8XXX_DEV_COLD);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009701 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309702
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009703 rval = qla4_8xxx_update_idc_reg(ha);
9704 if (rval == QLA_ERROR) {
9705 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9706 ha->host_no, __func__);
9707 ha->isp_ops->idc_lock(ha);
9708 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9709 QLA8XXX_DEV_FAILED);
9710 ha->isp_ops->idc_unlock(ha);
9711 goto exit_error_recovery;
9712 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309713
Lalit Chandivade2232be02010-07-30 14:38:47 +05309714 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009715 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309716
9717 if (rval != QLA_SUCCESS) {
9718 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9719 "FAILED\n", ha->host_no, __func__);
Nilesh Javali37418cc2013-12-16 06:49:31 -05009720 qla4xxx_free_irqs(ha);
Poornima Vonti82761902012-09-20 07:35:04 -04009721 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309722 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009723 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9724 QLA8XXX_DEV_FAILED);
Poornima Vonti82761902012-09-20 07:35:04 -04009725 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309726 } else {
9727 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9728 "READY\n", ha->host_no, __func__);
Poornima Vonti82761902012-09-20 07:35:04 -04009729 ha->isp_ops->idc_lock(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009730 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9731 QLA8XXX_DEV_READY);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309732 /* Clear driver state register */
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009733 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309734 qla4_8xxx_set_drv_active(ha);
Poornima Vonti82761902012-09-20 07:35:04 -04009735 ha->isp_ops->idc_unlock(ha);
Poornima Vonti137257d2013-01-20 23:51:01 -05009736 ha->isp_ops->enable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309737 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309738 } else {
9739 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9740 "the reset owner\n", ha->host_no, __func__,
9741 ha->pdev->devfn);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009742 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9743 QLA8XXX_DEV_READY)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309744 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009745 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Poornima Vonti137257d2013-01-20 23:51:01 -05009746 if (rval == QLA_SUCCESS)
9747 ha->isp_ops->enable_intrs(ha);
Nilesh Javali37418cc2013-12-16 06:49:31 -05009748 else
9749 qla4xxx_free_irqs(ha);
Poornima Vonti137257d2013-01-20 23:51:01 -05009750
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009751 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309752 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009753 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309754 }
9755 }
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009756exit_error_recovery:
Lalit Chandivade2232be02010-07-30 14:38:47 +05309757 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9758 return rval;
9759}
9760
9761static pci_ers_result_t
9762qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9763{
9764 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9765 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9766 int rc;
9767
9768 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9769 ha->host_no, __func__);
9770
9771 if (!is_aer_supported(ha))
9772 return PCI_ERS_RESULT_NONE;
9773
9774 /* Restore the saved state of PCIe device -
9775 * BAR registers, PCI Config space, PCIX, MSI,
9776 * IOV states
9777 */
9778 pci_restore_state(pdev);
9779
9780 /* pci_restore_state() clears the saved_state flag of the device
9781 * save restored state which resets saved_state flag
9782 */
9783 pci_save_state(pdev);
9784
9785 /* Initialize device or resume if in suspended state */
9786 rc = pci_enable_device(pdev);
9787 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009788 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05309789 "device after reset\n", ha->host_no, __func__);
9790 goto exit_slot_reset;
9791 }
9792
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009793 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309794
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009795 if (is_qla80XX(ha)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309796 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9797 ret = PCI_ERS_RESULT_RECOVERED;
9798 goto exit_slot_reset;
9799 } else
9800 goto exit_slot_reset;
9801 }
9802
9803exit_slot_reset:
9804 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9805 "device after reset\n", ha->host_no, __func__, ret);
9806 return ret;
9807}
9808
9809static void
9810qla4xxx_pci_resume(struct pci_dev *pdev)
9811{
9812 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9813 int ret;
9814
9815 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9816 ha->host_no, __func__);
9817
9818 ret = qla4xxx_wait_for_hba_online(ha);
9819 if (ret != QLA_SUCCESS) {
9820 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9821 "resume I/O from slot/link_reset\n", ha->host_no,
9822 __func__);
9823 }
9824
9825 pci_cleanup_aer_uncorrect_error_status(pdev);
9826 clear_bit(AF_EEH_BUSY, &ha->flags);
9827}
9828
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07009829static const struct pci_error_handlers qla4xxx_err_handler = {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309830 .error_detected = qla4xxx_pci_error_detected,
9831 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9832 .slot_reset = qla4xxx_pci_slot_reset,
9833 .resume = qla4xxx_pci_resume,
9834};
9835
David Somayajuluafaf5a22006-09-19 10:28:00 -07009836static struct pci_device_id qla4xxx_pci_tbl[] = {
9837 {
9838 .vendor = PCI_VENDOR_ID_QLOGIC,
9839 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9840 .subvendor = PCI_ANY_ID,
9841 .subdevice = PCI_ANY_ID,
9842 },
9843 {
9844 .vendor = PCI_VENDOR_ID_QLOGIC,
9845 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9846 .subvendor = PCI_ANY_ID,
9847 .subdevice = PCI_ANY_ID,
9848 },
David C Somayajulud9150582006-11-15 17:38:40 -08009849 {
9850 .vendor = PCI_VENDOR_ID_QLOGIC,
9851 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9852 .subvendor = PCI_ANY_ID,
9853 .subdevice = PCI_ANY_ID,
9854 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309855 {
9856 .vendor = PCI_VENDOR_ID_QLOGIC,
9857 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9858 .subvendor = PCI_ANY_ID,
9859 .subdevice = PCI_ANY_ID,
9860 },
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009861 {
9862 .vendor = PCI_VENDOR_ID_QLOGIC,
9863 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9864 .subvendor = PCI_ANY_ID,
9865 .subdevice = PCI_ANY_ID,
9866 },
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009867 {
9868 .vendor = PCI_VENDOR_ID_QLOGIC,
9869 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9870 .subvendor = PCI_ANY_ID,
9871 .subdevice = PCI_ANY_ID,
9872 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07009873 {0, 0},
9874};
9875MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9876
Adrian Bunk47975472007-04-26 00:35:16 -07009877static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009878 .name = DRIVER_NAME,
9879 .id_table = qla4xxx_pci_tbl,
9880 .probe = qla4xxx_probe_adapter,
9881 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05309882 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009883};
9884
9885static int __init qla4xxx_module_init(void)
9886{
9887 int ret;
9888
9889 /* Allocate cache for SRBs. */
9890 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09009891 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009892 if (srb_cachep == NULL) {
9893 printk(KERN_ERR
9894 "%s: Unable to allocate SRB cache..."
9895 "Failing load!\n", DRIVER_NAME);
9896 ret = -ENOMEM;
9897 goto no_srp_cache;
9898 }
9899
9900 /* Derive version string. */
9901 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07009902 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009903 strcat(qla4xxx_version_str, "-debug");
9904
9905 qla4xxx_scsi_transport =
9906 iscsi_register_transport(&qla4xxx_iscsi_transport);
9907 if (!qla4xxx_scsi_transport){
9908 ret = -ENODEV;
9909 goto release_srb_cache;
9910 }
9911
David Somayajuluafaf5a22006-09-19 10:28:00 -07009912 ret = pci_register_driver(&qla4xxx_pci_driver);
9913 if (ret)
9914 goto unregister_transport;
9915
9916 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9917 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05009918
David Somayajuluafaf5a22006-09-19 10:28:00 -07009919unregister_transport:
9920 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9921release_srb_cache:
9922 kmem_cache_destroy(srb_cachep);
9923no_srp_cache:
9924 return ret;
9925}
9926
9927static void __exit qla4xxx_module_exit(void)
9928{
David Somayajuluafaf5a22006-09-19 10:28:00 -07009929 pci_unregister_driver(&qla4xxx_pci_driver);
9930 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9931 kmem_cache_destroy(srb_cachep);
9932}
9933
9934module_init(qla4xxx_module_init);
9935module_exit(qla4xxx_module_exit);
9936
9937MODULE_AUTHOR("QLogic Corporation");
9938MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9939MODULE_LICENSE("GPL");
9940MODULE_VERSION(QLA4XXX_DRIVER_VERSION);