blob: b04afaefde84d17a9c23028a22cd6e363bf81196 [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 Parkash068237c82012-05-18 04:41:44 -040086int ql4xmdcapmask = 0x1F;
87module_param(ql4xmdcapmask, int, S_IRUGO);
88MODULE_PARM_DESC(ql4xmdcapmask,
89 " Set the Minidump driver capture mask level.\n"
90 "\t\t Default is 0x1F.\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
92
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);
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530154
David Somayajuluafaf5a22006-09-19 10:28:00 -0700155/*
156 * SCSI host template entry points
157 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500158static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530159static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700160static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -0600161static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700162static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
163static int qla4xxx_slave_alloc(struct scsi_device *device);
164static int qla4xxx_slave_configure(struct scsi_device *device);
165static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400166static umode_t qla4_attr_is_visible(int param_type, int param);
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700167static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
Tej Parkashf7b4aa62012-04-30 04:12:19 -0700168static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
169 int reason);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700170
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400171/*
172 * iSCSI Flash DDB sysfs entry points
173 */
174static int
175qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
176 struct iscsi_bus_flash_conn *fnode_conn,
177 void *data, int len);
178static int
179qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
180 int param, char *buf);
181static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
182 int len);
183static int
184qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
185static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
186 struct iscsi_bus_flash_conn *fnode_conn);
187static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
188 struct iscsi_bus_flash_conn *fnode_conn);
189static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
190
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530191static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
192 QLA82XX_LEGACY_INTR_CONFIG;
193
David Somayajuluafaf5a22006-09-19 10:28:00 -0700194static struct scsi_host_template qla4xxx_driver_template = {
195 .module = THIS_MODULE,
196 .name = DRIVER_NAME,
197 .proc_name = DRIVER_NAME,
198 .queuecommand = qla4xxx_queuecommand,
199
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530200 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700201 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600202 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700203 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500204 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700205
206 .slave_configure = qla4xxx_slave_configure,
207 .slave_alloc = qla4xxx_slave_alloc,
208 .slave_destroy = qla4xxx_slave_destroy,
Tej Parkashf7b4aa62012-04-30 04:12:19 -0700209 .change_queue_depth = qla4xxx_change_queue_depth,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700210
211 .this_id = -1,
212 .cmd_per_lun = 3,
213 .use_clustering = ENABLE_CLUSTERING,
214 .sg_tablesize = SG_ALL,
215
216 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700217 .shost_attrs = qla4xxx_host_attrs,
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700218 .host_reset = qla4xxx_host_reset,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500219 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700220};
221
222static struct iscsi_transport qla4xxx_iscsi_transport = {
223 .owner = THIS_MODULE,
224 .name = DRIVER_NAME,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500225 .caps = CAP_TEXT_NEGO |
226 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
227 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
228 CAP_MULTI_R2T,
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400229 .attr_is_visible = qla4_attr_is_visible,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500230 .create_session = qla4xxx_session_create,
231 .destroy_session = qla4xxx_session_destroy,
232 .start_conn = qla4xxx_conn_start,
233 .create_conn = qla4xxx_conn_create,
234 .bind_conn = qla4xxx_conn_bind,
235 .stop_conn = iscsi_conn_stop,
236 .destroy_conn = qla4xxx_conn_destroy,
237 .set_param = iscsi_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700238 .get_conn_param = qla4xxx_conn_get_param,
Mike Christiefca9f042012-02-27 03:08:54 -0800239 .get_session_param = qla4xxx_session_get_param,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500240 .get_ep_param = qla4xxx_get_ep_param,
241 .ep_connect = qla4xxx_ep_connect,
242 .ep_poll = qla4xxx_ep_poll,
243 .ep_disconnect = qla4xxx_ep_disconnect,
244 .get_stats = qla4xxx_conn_get_stats,
245 .send_pdu = iscsi_conn_send_pdu,
246 .xmit_task = qla4xxx_task_xmit,
247 .cleanup_task = qla4xxx_task_cleanup,
248 .alloc_pdu = qla4xxx_alloc_pdu,
249
Mike Christieaa1e93a2007-05-30 12:57:09 -0500250 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500251 .set_iface_param = qla4xxx_iface_set_param,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500252 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500253 .bsg_request = qla4xxx_bsg_request,
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530254 .send_ping = qla4xxx_send_ping,
Nilesh Javali376738a2012-02-27 03:08:52 -0800255 .get_chap = qla4xxx_get_chap_list,
256 .delete_chap = qla4xxx_delete_chap,
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400257 .set_chap = qla4xxx_set_chap_entry,
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400258 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
259 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
260 .new_flashnode = qla4xxx_sysfs_ddb_add,
261 .del_flashnode = qla4xxx_sysfs_ddb_delete,
262 .login_flashnode = qla4xxx_sysfs_ddb_login,
263 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
264 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700265};
266
267static struct scsi_transport_template *qla4xxx_scsi_transport;
268
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530269static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
270 uint32_t iface_type, uint32_t payload_size,
271 uint32_t pid, struct sockaddr *dst_addr)
272{
273 struct scsi_qla_host *ha = to_qla_host(shost);
274 struct sockaddr_in *addr;
275 struct sockaddr_in6 *addr6;
276 uint32_t options = 0;
277 uint8_t ipaddr[IPv6_ADDR_LEN];
278 int rval;
279
280 memset(ipaddr, 0, IPv6_ADDR_LEN);
281 /* IPv4 to IPv4 */
282 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
283 (dst_addr->sa_family == AF_INET)) {
284 addr = (struct sockaddr_in *)dst_addr;
285 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
286 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
287 "dest: %pI4\n", __func__,
288 &ha->ip_config.ip_address, ipaddr));
289 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
290 ipaddr);
291 if (rval)
292 rval = -EINVAL;
293 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
294 (dst_addr->sa_family == AF_INET6)) {
295 /* IPv6 to IPv6 */
296 addr6 = (struct sockaddr_in6 *)dst_addr;
297 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
298
299 options |= PING_IPV6_PROTOCOL_ENABLE;
300
301 /* Ping using LinkLocal address */
302 if ((iface_num == 0) || (iface_num == 1)) {
303 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
304 "src: %pI6 dest: %pI6\n", __func__,
305 &ha->ip_config.ipv6_link_local_addr,
306 ipaddr));
307 options |= PING_IPV6_LINKLOCAL_ADDR;
308 rval = qla4xxx_ping_iocb(ha, options, payload_size,
309 pid, ipaddr);
310 } else {
311 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
312 "not supported\n", __func__, iface_num);
313 rval = -ENOSYS;
314 goto exit_send_ping;
315 }
316
317 /*
318 * If ping using LinkLocal address fails, try ping using
319 * IPv6 address
320 */
321 if (rval != QLA_SUCCESS) {
322 options &= ~PING_IPV6_LINKLOCAL_ADDR;
323 if (iface_num == 0) {
324 options |= PING_IPV6_ADDR0;
325 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
326 "Ping src: %pI6 "
327 "dest: %pI6\n", __func__,
328 &ha->ip_config.ipv6_addr0,
329 ipaddr));
330 } else if (iface_num == 1) {
331 options |= PING_IPV6_ADDR1;
332 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
333 "Ping src: %pI6 "
334 "dest: %pI6\n", __func__,
335 &ha->ip_config.ipv6_addr1,
336 ipaddr));
337 }
338 rval = qla4xxx_ping_iocb(ha, options, payload_size,
339 pid, ipaddr);
340 if (rval)
341 rval = -EINVAL;
342 }
343 } else
344 rval = -ENOSYS;
345exit_send_ping:
346 return rval;
347}
348
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400349static umode_t qla4_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -0500350{
351 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500352 case ISCSI_HOST_PARAM:
353 switch (param) {
354 case ISCSI_HOST_PARAM_HWADDRESS:
355 case ISCSI_HOST_PARAM_IPADDRESS:
356 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -0800357 case ISCSI_HOST_PARAM_PORT_STATE:
358 case ISCSI_HOST_PARAM_PORT_SPEED:
Mike Christief27fb2e2011-07-25 13:48:45 -0500359 return S_IRUGO;
360 default:
361 return 0;
362 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500363 case ISCSI_PARAM:
364 switch (param) {
Mike Christie590134f2011-10-17 22:42:13 -0500365 case ISCSI_PARAM_PERSISTENT_ADDRESS:
366 case ISCSI_PARAM_PERSISTENT_PORT:
Mike Christie3128c6c2011-07-25 13:48:42 -0500367 case ISCSI_PARAM_CONN_ADDRESS:
368 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500369 case ISCSI_PARAM_TARGET_NAME:
370 case ISCSI_PARAM_TPGT:
371 case ISCSI_PARAM_TARGET_ALIAS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500372 case ISCSI_PARAM_MAX_BURST:
373 case ISCSI_PARAM_MAX_R2T:
374 case ISCSI_PARAM_FIRST_BURST:
375 case ISCSI_PARAM_MAX_RECV_DLENGTH:
376 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Mike Christiede379202011-08-14 20:42:56 -0500377 case ISCSI_PARAM_IFACE_NAME:
Mike Christiefca9f042012-02-27 03:08:54 -0800378 case ISCSI_PARAM_CHAP_OUT_IDX:
379 case ISCSI_PARAM_CHAP_IN_IDX:
380 case ISCSI_PARAM_USERNAME:
381 case ISCSI_PARAM_PASSWORD:
382 case ISCSI_PARAM_USERNAME_IN:
383 case ISCSI_PARAM_PASSWORD_IN:
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -0400384 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
385 case ISCSI_PARAM_DISCOVERY_SESS:
386 case ISCSI_PARAM_PORTAL_TYPE:
387 case ISCSI_PARAM_CHAP_AUTH_EN:
388 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
389 case ISCSI_PARAM_BIDI_CHAP_EN:
390 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
391 case ISCSI_PARAM_DEF_TIME2WAIT:
392 case ISCSI_PARAM_DEF_TIME2RETAIN:
393 case ISCSI_PARAM_HDRDGST_EN:
394 case ISCSI_PARAM_DATADGST_EN:
395 case ISCSI_PARAM_INITIAL_R2T_EN:
396 case ISCSI_PARAM_IMM_DATA_EN:
397 case ISCSI_PARAM_PDU_INORDER_EN:
398 case ISCSI_PARAM_DATASEQ_INORDER_EN:
399 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
400 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
401 case ISCSI_PARAM_TCP_WSF_DISABLE:
402 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
403 case ISCSI_PARAM_TCP_TIMER_SCALE:
404 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
405 case ISCSI_PARAM_TCP_XMIT_WSF:
406 case ISCSI_PARAM_TCP_RECV_WSF:
407 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
408 case ISCSI_PARAM_IPV4_TOS:
409 case ISCSI_PARAM_IPV6_TC:
410 case ISCSI_PARAM_IPV6_FLOW_LABEL:
411 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
412 case ISCSI_PARAM_KEEPALIVE_TMO:
413 case ISCSI_PARAM_LOCAL_PORT:
414 case ISCSI_PARAM_ISID:
415 case ISCSI_PARAM_TSID:
416 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
417 case ISCSI_PARAM_ERL:
418 case ISCSI_PARAM_STATSN:
419 case ISCSI_PARAM_EXP_STATSN:
420 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
421 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
Mike Christie3128c6c2011-07-25 13:48:42 -0500422 return S_IRUGO;
423 default:
424 return 0;
425 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500426 case ISCSI_NET_PARAM:
427 switch (param) {
428 case ISCSI_NET_PARAM_IPV4_ADDR:
429 case ISCSI_NET_PARAM_IPV4_SUBNET:
430 case ISCSI_NET_PARAM_IPV4_GW:
431 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
432 case ISCSI_NET_PARAM_IFACE_ENABLE:
433 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
434 case ISCSI_NET_PARAM_IPV6_ADDR:
435 case ISCSI_NET_PARAM_IPV6_ROUTER:
436 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
437 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500438 case ISCSI_NET_PARAM_VLAN_ID:
439 case ISCSI_NET_PARAM_VLAN_PRIORITY:
440 case ISCSI_NET_PARAM_VLAN_ENABLED:
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700441 case ISCSI_NET_PARAM_MTU:
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700442 case ISCSI_NET_PARAM_PORT:
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400443 case ISCSI_NET_PARAM_IPADDR_STATE:
444 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
445 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
446 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
447 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
448 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
449 case ISCSI_NET_PARAM_TCP_WSF:
450 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
451 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
452 case ISCSI_NET_PARAM_CACHE_ID:
453 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
454 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
455 case ISCSI_NET_PARAM_IPV4_TOS_EN:
456 case ISCSI_NET_PARAM_IPV4_TOS:
457 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
458 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
459 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
460 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
461 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
462 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
463 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
464 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
465 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
466 case ISCSI_NET_PARAM_REDIRECT_EN:
467 case ISCSI_NET_PARAM_IPV4_TTL:
468 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
469 case ISCSI_NET_PARAM_IPV6_MLD_EN:
470 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
471 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
472 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
473 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
474 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
475 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
476 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
477 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
478 return S_IRUGO;
479 default:
480 return 0;
481 }
482 case ISCSI_IFACE_PARAM:
483 switch (param) {
484 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
485 case ISCSI_IFACE_PARAM_HDRDGST_EN:
486 case ISCSI_IFACE_PARAM_DATADGST_EN:
487 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
488 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
489 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
490 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
491 case ISCSI_IFACE_PARAM_ERL:
492 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
493 case ISCSI_IFACE_PARAM_FIRST_BURST:
494 case ISCSI_IFACE_PARAM_MAX_R2T:
495 case ISCSI_IFACE_PARAM_MAX_BURST:
496 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
497 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
498 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
499 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
500 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
501 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
Mike Christieb78dbba2011-07-25 13:48:44 -0500502 return S_IRUGO;
503 default:
504 return 0;
505 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400506 case ISCSI_FLASHNODE_PARAM:
507 switch (param) {
508 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
509 case ISCSI_FLASHNODE_PORTAL_TYPE:
510 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
511 case ISCSI_FLASHNODE_DISCOVERY_SESS:
512 case ISCSI_FLASHNODE_ENTRY_EN:
513 case ISCSI_FLASHNODE_HDR_DGST_EN:
514 case ISCSI_FLASHNODE_DATA_DGST_EN:
515 case ISCSI_FLASHNODE_IMM_DATA_EN:
516 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
517 case ISCSI_FLASHNODE_DATASEQ_INORDER:
518 case ISCSI_FLASHNODE_PDU_INORDER:
519 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
520 case ISCSI_FLASHNODE_SNACK_REQ_EN:
521 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
522 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
523 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
524 case ISCSI_FLASHNODE_ERL:
525 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
526 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
527 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
528 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
529 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
530 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
531 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
532 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
533 case ISCSI_FLASHNODE_FIRST_BURST:
534 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
535 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
536 case ISCSI_FLASHNODE_MAX_R2T:
537 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
538 case ISCSI_FLASHNODE_ISID:
539 case ISCSI_FLASHNODE_TSID:
540 case ISCSI_FLASHNODE_PORT:
541 case ISCSI_FLASHNODE_MAX_BURST:
542 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
543 case ISCSI_FLASHNODE_IPADDR:
544 case ISCSI_FLASHNODE_ALIAS:
545 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
546 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
547 case ISCSI_FLASHNODE_LOCAL_PORT:
548 case ISCSI_FLASHNODE_IPV4_TOS:
549 case ISCSI_FLASHNODE_IPV6_TC:
550 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
551 case ISCSI_FLASHNODE_NAME:
552 case ISCSI_FLASHNODE_TPGT:
553 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
554 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
555 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
556 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
557 case ISCSI_FLASHNODE_TCP_RECV_WSF:
558 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
559 case ISCSI_FLASHNODE_USERNAME:
560 case ISCSI_FLASHNODE_PASSWORD:
561 case ISCSI_FLASHNODE_STATSN:
562 case ISCSI_FLASHNODE_EXP_STATSN:
563 case ISCSI_FLASHNODE_IS_BOOT_TGT:
564 return S_IRUGO;
565 default:
566 return 0;
567 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500568 }
569
570 return 0;
571}
572
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400573static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
574 int16_t chap_index,
575 struct ql4_chap_table **chap_entry)
576{
577 int rval = QLA_ERROR;
578 int max_chap_entries;
579
580 if (!ha->chap_list) {
581 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
582 rval = QLA_ERROR;
583 goto exit_get_chap;
584 }
585
586 if (is_qla80XX(ha))
587 max_chap_entries = (ha->hw.flt_chap_size / 2) /
588 sizeof(struct ql4_chap_table);
589 else
590 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
591
592 if (chap_index > max_chap_entries) {
593 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
594 rval = QLA_ERROR;
595 goto exit_get_chap;
596 }
597
598 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
599 if ((*chap_entry)->cookie !=
600 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
601 rval = QLA_ERROR;
602 *chap_entry = NULL;
603 } else {
604 rval = QLA_SUCCESS;
605 }
606
607exit_get_chap:
608 return rval;
609}
610
611/**
612 * qla4xxx_find_free_chap_index - Find the first free chap index
613 * @ha: pointer to adapter structure
614 * @chap_index: CHAP index to be returned
615 *
616 * Find the first free chap index available in the chap table
617 *
618 * Note: Caller should acquire the chap lock before getting here.
619 **/
620static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
621 uint16_t *chap_index)
622{
623 int i, rval;
624 int free_index = -1;
625 int max_chap_entries = 0;
626 struct ql4_chap_table *chap_table;
627
628 if (is_qla80XX(ha))
629 max_chap_entries = (ha->hw.flt_chap_size / 2) /
630 sizeof(struct ql4_chap_table);
631 else
632 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
633
634 if (!ha->chap_list) {
635 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
636 rval = QLA_ERROR;
637 goto exit_find_chap;
638 }
639
640 for (i = 0; i < max_chap_entries; i++) {
641 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
642
643 if ((chap_table->cookie !=
644 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
645 (i > MAX_RESRV_CHAP_IDX)) {
646 free_index = i;
647 break;
648 }
649 }
650
651 if (free_index != -1) {
652 *chap_index = free_index;
653 rval = QLA_SUCCESS;
654 } else {
655 rval = QLA_ERROR;
656 }
657
658exit_find_chap:
659 return rval;
660}
661
Nilesh Javali376738a2012-02-27 03:08:52 -0800662static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
663 uint32_t *num_entries, char *buf)
664{
665 struct scsi_qla_host *ha = to_qla_host(shost);
666 struct ql4_chap_table *chap_table;
667 struct iscsi_chap_rec *chap_rec;
668 int max_chap_entries = 0;
669 int valid_chap_entries = 0;
670 int ret = 0, i;
671
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400672 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800673 max_chap_entries = (ha->hw.flt_chap_size / 2) /
674 sizeof(struct ql4_chap_table);
675 else
676 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
677
678 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
679 __func__, *num_entries, chap_tbl_idx);
680
681 if (!buf) {
682 ret = -ENOMEM;
683 goto exit_get_chap_list;
684 }
685
686 chap_rec = (struct iscsi_chap_rec *) buf;
687 mutex_lock(&ha->chap_sem);
688 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
689 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
690 if (chap_table->cookie !=
691 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
692 continue;
693
694 chap_rec->chap_tbl_idx = i;
695 strncpy(chap_rec->username, chap_table->name,
696 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
697 strncpy(chap_rec->password, chap_table->secret,
698 QL4_CHAP_MAX_SECRET_LEN);
699 chap_rec->password_length = chap_table->secret_len;
700
701 if (chap_table->flags & BIT_7) /* local */
702 chap_rec->chap_type = CHAP_TYPE_OUT;
703
704 if (chap_table->flags & BIT_6) /* peer */
705 chap_rec->chap_type = CHAP_TYPE_IN;
706
707 chap_rec++;
708
709 valid_chap_entries++;
710 if (valid_chap_entries == *num_entries)
711 break;
712 else
713 continue;
714 }
715 mutex_unlock(&ha->chap_sem);
716
717exit_get_chap_list:
718 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
719 __func__, valid_chap_entries);
720 *num_entries = valid_chap_entries;
721 return ret;
722}
723
724static int __qla4xxx_is_chap_active(struct device *dev, void *data)
725{
726 int ret = 0;
727 uint16_t *chap_tbl_idx = (uint16_t *) data;
728 struct iscsi_cls_session *cls_session;
729 struct iscsi_session *sess;
730 struct ddb_entry *ddb_entry;
731
732 if (!iscsi_is_session_dev(dev))
733 goto exit_is_chap_active;
734
735 cls_session = iscsi_dev_to_session(dev);
736 sess = cls_session->dd_data;
737 ddb_entry = sess->dd_data;
738
739 if (iscsi_session_chkready(cls_session))
740 goto exit_is_chap_active;
741
742 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
743 ret = 1;
744
745exit_is_chap_active:
746 return ret;
747}
748
749static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
750 uint16_t chap_tbl_idx)
751{
752 int ret = 0;
753
754 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
755 __qla4xxx_is_chap_active);
756
757 return ret;
758}
759
760static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
761{
762 struct scsi_qla_host *ha = to_qla_host(shost);
763 struct ql4_chap_table *chap_table;
764 dma_addr_t chap_dma;
765 int max_chap_entries = 0;
766 uint32_t offset = 0;
767 uint32_t chap_size;
768 int ret = 0;
769
770 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
771 if (chap_table == NULL)
772 return -ENOMEM;
773
774 memset(chap_table, 0, sizeof(struct ql4_chap_table));
775
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400776 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800777 max_chap_entries = (ha->hw.flt_chap_size / 2) /
778 sizeof(struct ql4_chap_table);
779 else
780 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
781
782 if (chap_tbl_idx > max_chap_entries) {
783 ret = -EINVAL;
784 goto exit_delete_chap;
785 }
786
787 /* Check if chap index is in use.
788 * If chap is in use don't delet chap entry */
789 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
790 if (ret) {
791 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
792 "delete from flash\n", chap_tbl_idx);
793 ret = -EBUSY;
794 goto exit_delete_chap;
795 }
796
797 chap_size = sizeof(struct ql4_chap_table);
798 if (is_qla40XX(ha))
799 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
800 else {
801 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
802 /* flt_chap_size is CHAP table size for both ports
803 * so divide it by 2 to calculate the offset for second port
804 */
805 if (ha->port_num == 1)
806 offset += (ha->hw.flt_chap_size / 2);
807 offset += (chap_tbl_idx * chap_size);
808 }
809
810 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
811 if (ret != QLA_SUCCESS) {
812 ret = -EINVAL;
813 goto exit_delete_chap;
814 }
815
816 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
817 __le16_to_cpu(chap_table->cookie)));
818
819 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
820 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
821 goto exit_delete_chap;
822 }
823
824 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
825
826 offset = FLASH_CHAP_OFFSET |
827 (chap_tbl_idx * sizeof(struct ql4_chap_table));
828 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
829 FLASH_OPT_RMW_COMMIT);
830 if (ret == QLA_SUCCESS && ha->chap_list) {
831 mutex_lock(&ha->chap_sem);
832 /* Update ha chap_list cache */
833 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
834 chap_table, sizeof(struct ql4_chap_table));
835 mutex_unlock(&ha->chap_sem);
836 }
837 if (ret != QLA_SUCCESS)
838 ret = -EINVAL;
839
840exit_delete_chap:
841 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
842 return ret;
843}
844
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400845/**
846 * qla4xxx_set_chap_entry - Make chap entry with given information
847 * @shost: pointer to host
848 * @data: chap info - credentials, index and type to make chap entry
849 * @len: length of data
850 *
851 * Add or update chap entry with the given information
852 **/
853static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
854{
855 struct scsi_qla_host *ha = to_qla_host(shost);
856 struct iscsi_chap_rec chap_rec;
857 struct ql4_chap_table *chap_entry = NULL;
858 struct iscsi_param_info *param_info;
859 struct nlattr *attr;
860 int max_chap_entries = 0;
861 int type;
862 int rem = len;
863 int rc = 0;
864
865 memset(&chap_rec, 0, sizeof(chap_rec));
866
867 nla_for_each_attr(attr, data, len, rem) {
868 param_info = nla_data(attr);
869
870 switch (param_info->param) {
871 case ISCSI_CHAP_PARAM_INDEX:
872 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
873 break;
874 case ISCSI_CHAP_PARAM_CHAP_TYPE:
875 chap_rec.chap_type = param_info->value[0];
876 break;
877 case ISCSI_CHAP_PARAM_USERNAME:
878 memcpy(chap_rec.username, param_info->value,
879 param_info->len);
880 break;
881 case ISCSI_CHAP_PARAM_PASSWORD:
882 memcpy(chap_rec.password, param_info->value,
883 param_info->len);
884 break;
885 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
886 chap_rec.password_length = param_info->value[0];
887 break;
888 default:
889 ql4_printk(KERN_ERR, ha,
890 "%s: No such sysfs attribute\n", __func__);
891 rc = -ENOSYS;
892 goto exit_set_chap;
893 };
894 }
895
896 if (chap_rec.chap_type == CHAP_TYPE_IN)
897 type = BIDI_CHAP;
898 else
899 type = LOCAL_CHAP;
900
901 if (is_qla80XX(ha))
902 max_chap_entries = (ha->hw.flt_chap_size / 2) /
903 sizeof(struct ql4_chap_table);
904 else
905 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
906
907 mutex_lock(&ha->chap_sem);
908 if (chap_rec.chap_tbl_idx < max_chap_entries) {
909 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
910 &chap_entry);
911 if (!rc) {
912 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
913 ql4_printk(KERN_INFO, ha,
914 "Type mismatch for CHAP entry %d\n",
915 chap_rec.chap_tbl_idx);
916 rc = -EINVAL;
917 goto exit_unlock_chap;
918 }
919
920 /* If chap index is in use then don't modify it */
921 rc = qla4xxx_is_chap_active(shost,
922 chap_rec.chap_tbl_idx);
923 if (rc) {
924 ql4_printk(KERN_INFO, ha,
925 "CHAP entry %d is in use\n",
926 chap_rec.chap_tbl_idx);
927 rc = -EBUSY;
928 goto exit_unlock_chap;
929 }
930 }
931 } else {
932 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
933 if (rc) {
934 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
935 rc = -EBUSY;
936 goto exit_unlock_chap;
937 }
938 }
939
940 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
941 chap_rec.chap_tbl_idx, type);
942
943exit_unlock_chap:
944 mutex_unlock(&ha->chap_sem);
945
946exit_set_chap:
947 return rc;
948}
949
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500950static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
951 enum iscsi_param_type param_type,
952 int param, char *buf)
953{
954 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
955 struct scsi_qla_host *ha = to_qla_host(shost);
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400956 int ival;
957 char *pval = NULL;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500958 int len = -ENOSYS;
959
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400960 if (param_type == ISCSI_NET_PARAM) {
961 switch (param) {
962 case ISCSI_NET_PARAM_IPV4_ADDR:
963 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
964 break;
965 case ISCSI_NET_PARAM_IPV4_SUBNET:
966 len = sprintf(buf, "%pI4\n",
967 &ha->ip_config.subnet_mask);
968 break;
969 case ISCSI_NET_PARAM_IPV4_GW:
970 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
971 break;
972 case ISCSI_NET_PARAM_IFACE_ENABLE:
973 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
974 OP_STATE(ha->ip_config.ipv4_options,
975 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
976 } else {
977 OP_STATE(ha->ip_config.ipv6_options,
978 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
979 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500980
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400981 len = sprintf(buf, "%s\n", pval);
982 break;
983 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500984 len = sprintf(buf, "%s\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400985 (ha->ip_config.tcp_options &
986 TCPOPT_DHCP_ENABLE) ?
987 "dhcp" : "static");
988 break;
989 case ISCSI_NET_PARAM_IPV6_ADDR:
990 if (iface->iface_num == 0)
991 len = sprintf(buf, "%pI6\n",
992 &ha->ip_config.ipv6_addr0);
993 if (iface->iface_num == 1)
994 len = sprintf(buf, "%pI6\n",
995 &ha->ip_config.ipv6_addr1);
996 break;
997 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
998 len = sprintf(buf, "%pI6\n",
999 &ha->ip_config.ipv6_link_local_addr);
1000 break;
1001 case ISCSI_NET_PARAM_IPV6_ROUTER:
1002 len = sprintf(buf, "%pI6\n",
1003 &ha->ip_config.ipv6_default_router_addr);
1004 break;
1005 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1006 pval = (ha->ip_config.ipv6_addl_options &
1007 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1008 "nd" : "static";
1009
1010 len = sprintf(buf, "%s\n", pval);
1011 break;
1012 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1013 pval = (ha->ip_config.ipv6_addl_options &
1014 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1015 "auto" : "static";
1016
1017 len = sprintf(buf, "%s\n", pval);
1018 break;
1019 case ISCSI_NET_PARAM_VLAN_ID:
1020 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1021 ival = ha->ip_config.ipv4_vlan_tag &
1022 ISCSI_MAX_VLAN_ID;
1023 else
1024 ival = ha->ip_config.ipv6_vlan_tag &
1025 ISCSI_MAX_VLAN_ID;
1026
1027 len = sprintf(buf, "%d\n", ival);
1028 break;
1029 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1030 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1031 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1032 ISCSI_MAX_VLAN_PRIORITY;
1033 else
1034 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1035 ISCSI_MAX_VLAN_PRIORITY;
1036
1037 len = sprintf(buf, "%d\n", ival);
1038 break;
1039 case ISCSI_NET_PARAM_VLAN_ENABLED:
1040 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1041 OP_STATE(ha->ip_config.ipv4_options,
1042 IPOPT_VLAN_TAGGING_ENABLE, pval);
1043 } else {
1044 OP_STATE(ha->ip_config.ipv6_options,
1045 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1046 }
1047 len = sprintf(buf, "%s\n", pval);
1048 break;
1049 case ISCSI_NET_PARAM_MTU:
1050 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1051 break;
1052 case ISCSI_NET_PARAM_PORT:
1053 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1054 len = sprintf(buf, "%d\n",
1055 ha->ip_config.ipv4_port);
1056 else
1057 len = sprintf(buf, "%d\n",
1058 ha->ip_config.ipv6_port);
1059 break;
1060 case ISCSI_NET_PARAM_IPADDR_STATE:
1061 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1062 pval = iscsi_get_ipaddress_state_name(
1063 ha->ip_config.ipv4_addr_state);
1064 } else {
1065 if (iface->iface_num == 0)
1066 pval = iscsi_get_ipaddress_state_name(
1067 ha->ip_config.ipv6_addr0_state);
1068 else if (iface->iface_num == 1)
1069 pval = iscsi_get_ipaddress_state_name(
1070 ha->ip_config.ipv6_addr1_state);
1071 }
1072
1073 len = sprintf(buf, "%s\n", pval);
1074 break;
1075 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1076 pval = iscsi_get_ipaddress_state_name(
1077 ha->ip_config.ipv6_link_local_state);
1078 len = sprintf(buf, "%s\n", pval);
1079 break;
1080 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1081 pval = iscsi_get_router_state_name(
1082 ha->ip_config.ipv6_default_router_state);
1083 len = sprintf(buf, "%s\n", pval);
1084 break;
1085 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1086 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1087 OP_STATE(~ha->ip_config.tcp_options,
1088 TCPOPT_DELAYED_ACK_DISABLE, pval);
1089 } else {
1090 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1091 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1092 }
1093 len = sprintf(buf, "%s\n", pval);
1094 break;
1095 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1096 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1097 OP_STATE(~ha->ip_config.tcp_options,
1098 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1099 } else {
1100 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1101 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1102 }
1103 len = sprintf(buf, "%s\n", pval);
1104 break;
1105 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1106 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1107 OP_STATE(~ha->ip_config.tcp_options,
1108 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1109 } else {
1110 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1111 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1112 pval);
1113 }
1114 len = sprintf(buf, "%s\n", pval);
1115 break;
1116 case ISCSI_NET_PARAM_TCP_WSF:
1117 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1118 len = sprintf(buf, "%d\n",
1119 ha->ip_config.tcp_wsf);
1120 else
1121 len = sprintf(buf, "%d\n",
1122 ha->ip_config.ipv6_tcp_wsf);
1123 break;
1124 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1125 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1126 ival = (ha->ip_config.tcp_options &
1127 TCPOPT_TIMER_SCALE) >> 1;
1128 else
1129 ival = (ha->ip_config.ipv6_tcp_options &
1130 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1131
1132 len = sprintf(buf, "%d\n", ival);
1133 break;
1134 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1135 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1136 OP_STATE(ha->ip_config.tcp_options,
1137 TCPOPT_TIMESTAMP_ENABLE, pval);
1138 } else {
1139 OP_STATE(ha->ip_config.ipv6_tcp_options,
1140 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1141 }
1142 len = sprintf(buf, "%s\n", pval);
1143 break;
1144 case ISCSI_NET_PARAM_CACHE_ID:
1145 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1146 len = sprintf(buf, "%d\n",
1147 ha->ip_config.ipv4_cache_id);
1148 else
1149 len = sprintf(buf, "%d\n",
1150 ha->ip_config.ipv6_cache_id);
1151 break;
1152 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1153 OP_STATE(ha->ip_config.tcp_options,
1154 TCPOPT_DNS_SERVER_IP_EN, pval);
1155
1156 len = sprintf(buf, "%s\n", pval);
1157 break;
1158 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1159 OP_STATE(ha->ip_config.tcp_options,
1160 TCPOPT_SLP_DA_INFO_EN, pval);
1161
1162 len = sprintf(buf, "%s\n", pval);
1163 break;
1164 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1165 OP_STATE(ha->ip_config.ipv4_options,
1166 IPOPT_IPV4_TOS_EN, pval);
1167
1168 len = sprintf(buf, "%s\n", pval);
1169 break;
1170 case ISCSI_NET_PARAM_IPV4_TOS:
1171 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1172 break;
1173 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1174 OP_STATE(ha->ip_config.ipv4_options,
1175 IPOPT_GRAT_ARP_EN, pval);
1176
1177 len = sprintf(buf, "%s\n", pval);
1178 break;
1179 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1180 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1181 pval);
1182
1183 len = sprintf(buf, "%s\n", pval);
1184 break;
1185 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1186 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1187 (char *)ha->ip_config.ipv4_alt_cid : "";
1188
1189 len = sprintf(buf, "%s\n", pval);
1190 break;
1191 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1192 OP_STATE(ha->ip_config.ipv4_options,
1193 IPOPT_REQ_VID_EN, pval);
1194
1195 len = sprintf(buf, "%s\n", pval);
1196 break;
1197 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1198 OP_STATE(ha->ip_config.ipv4_options,
1199 IPOPT_USE_VID_EN, pval);
1200
1201 len = sprintf(buf, "%s\n", pval);
1202 break;
1203 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1204 pval = (ha->ip_config.ipv4_vid_len) ?
1205 (char *)ha->ip_config.ipv4_vid : "";
1206
1207 len = sprintf(buf, "%s\n", pval);
1208 break;
1209 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1210 OP_STATE(ha->ip_config.ipv4_options,
1211 IPOPT_LEARN_IQN_EN, pval);
1212
1213 len = sprintf(buf, "%s\n", pval);
1214 break;
1215 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1216 OP_STATE(~ha->ip_config.ipv4_options,
1217 IPOPT_FRAGMENTATION_DISABLE, pval);
1218
1219 len = sprintf(buf, "%s\n", pval);
1220 break;
1221 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1222 OP_STATE(ha->ip_config.ipv4_options,
1223 IPOPT_IN_FORWARD_EN, pval);
1224
1225 len = sprintf(buf, "%s\n", pval);
1226 break;
1227 case ISCSI_NET_PARAM_REDIRECT_EN:
1228 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1229 OP_STATE(ha->ip_config.ipv4_options,
1230 IPOPT_ARP_REDIRECT_EN, pval);
1231 } else {
1232 OP_STATE(ha->ip_config.ipv6_options,
1233 IPV6_OPT_REDIRECT_EN, pval);
1234 }
1235 len = sprintf(buf, "%s\n", pval);
1236 break;
1237 case ISCSI_NET_PARAM_IPV4_TTL:
1238 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1239 break;
1240 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1241 OP_STATE(ha->ip_config.ipv6_options,
1242 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1243
1244 len = sprintf(buf, "%s\n", pval);
1245 break;
1246 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1247 OP_STATE(ha->ip_config.ipv6_addl_options,
1248 IPV6_ADDOPT_MLD_EN, pval);
1249
1250 len = sprintf(buf, "%s\n", pval);
1251 break;
1252 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1253 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1254 break;
1255 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001256 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001257 ha->ip_config.ipv6_traffic_class);
1258 break;
1259 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001260 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001261 ha->ip_config.ipv6_hop_limit);
1262 break;
1263 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001264 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001265 ha->ip_config.ipv6_nd_reach_time);
1266 break;
1267 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001268 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001269 ha->ip_config.ipv6_nd_rexmit_timer);
1270 break;
1271 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1272 len = sprintf(buf, "%d\n",
1273 ha->ip_config.ipv6_nd_stale_timeout);
1274 break;
1275 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1276 len = sprintf(buf, "%d\n",
1277 ha->ip_config.ipv6_dup_addr_detect_count);
1278 break;
1279 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1280 len = sprintf(buf, "%d\n",
1281 ha->ip_config.ipv6_gw_advrt_mtu);
1282 break;
1283 default:
1284 len = -ENOSYS;
1285 }
1286 } else if (param_type == ISCSI_IFACE_PARAM) {
1287 switch (param) {
1288 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1289 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1290 break;
1291 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1292 OP_STATE(ha->ip_config.iscsi_options,
1293 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1294
1295 len = sprintf(buf, "%s\n", pval);
1296 break;
1297 case ISCSI_IFACE_PARAM_DATADGST_EN:
1298 OP_STATE(ha->ip_config.iscsi_options,
1299 ISCSIOPTS_DATA_DIGEST_EN, pval);
1300
1301 len = sprintf(buf, "%s\n", pval);
1302 break;
1303 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1304 OP_STATE(ha->ip_config.iscsi_options,
1305 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1306
1307 len = sprintf(buf, "%s\n", pval);
1308 break;
1309 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1310 OP_STATE(ha->ip_config.iscsi_options,
1311 ISCSIOPTS_INITIAL_R2T_EN, pval);
1312
1313 len = sprintf(buf, "%s\n", pval);
1314 break;
1315 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1316 OP_STATE(ha->ip_config.iscsi_options,
1317 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1318
1319 len = sprintf(buf, "%s\n", pval);
1320 break;
1321 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1322 OP_STATE(ha->ip_config.iscsi_options,
1323 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1324
1325 len = sprintf(buf, "%s\n", pval);
1326 break;
1327 case ISCSI_IFACE_PARAM_ERL:
1328 len = sprintf(buf, "%d\n",
1329 (ha->ip_config.iscsi_options &
1330 ISCSIOPTS_ERL));
1331 break;
1332 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1333 len = sprintf(buf, "%u\n",
1334 ha->ip_config.iscsi_max_pdu_size *
1335 BYTE_UNITS);
1336 break;
1337 case ISCSI_IFACE_PARAM_FIRST_BURST:
1338 len = sprintf(buf, "%u\n",
1339 ha->ip_config.iscsi_first_burst_len *
1340 BYTE_UNITS);
1341 break;
1342 case ISCSI_IFACE_PARAM_MAX_R2T:
1343 len = sprintf(buf, "%d\n",
1344 ha->ip_config.iscsi_max_outstnd_r2t);
1345 break;
1346 case ISCSI_IFACE_PARAM_MAX_BURST:
1347 len = sprintf(buf, "%u\n",
1348 ha->ip_config.iscsi_max_burst_len *
1349 BYTE_UNITS);
1350 break;
1351 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1352 OP_STATE(ha->ip_config.iscsi_options,
1353 ISCSIOPTS_CHAP_AUTH_EN, pval);
1354
1355 len = sprintf(buf, "%s\n", pval);
1356 break;
1357 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1358 OP_STATE(ha->ip_config.iscsi_options,
1359 ISCSIOPTS_BIDI_CHAP_EN, pval);
1360
1361 len = sprintf(buf, "%s\n", pval);
1362 break;
1363 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1364 OP_STATE(ha->ip_config.iscsi_options,
1365 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1366
1367 len = sprintf(buf, "%s\n", pval);
1368 break;
1369 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1370 OP_STATE(ha->ip_config.iscsi_options,
1371 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1372
1373 len = sprintf(buf, "%s\n", pval);
1374 break;
1375 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1376 OP_STATE(ha->ip_config.iscsi_options,
1377 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1378
1379 len = sprintf(buf, "%s\n", pval);
1380 break;
1381 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1382 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1383 break;
1384 default:
1385 len = -ENOSYS;
1386 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001387 }
1388
1389 return len;
1390}
1391
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001392static struct iscsi_endpoint *
1393qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1394 int non_blocking)
1395{
1396 int ret;
1397 struct iscsi_endpoint *ep;
1398 struct qla_endpoint *qla_ep;
1399 struct scsi_qla_host *ha;
1400 struct sockaddr_in *addr;
1401 struct sockaddr_in6 *addr6;
1402
1403 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1404 if (!shost) {
1405 ret = -ENXIO;
1406 printk(KERN_ERR "%s: shost is NULL\n",
1407 __func__);
1408 return ERR_PTR(ret);
1409 }
1410
1411 ha = iscsi_host_priv(shost);
1412
1413 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1414 if (!ep) {
1415 ret = -ENOMEM;
1416 return ERR_PTR(ret);
1417 }
1418
1419 qla_ep = ep->dd_data;
1420 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1421 if (dst_addr->sa_family == AF_INET) {
1422 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1423 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1424 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1425 (char *)&addr->sin_addr));
1426 } else if (dst_addr->sa_family == AF_INET6) {
1427 memcpy(&qla_ep->dst_addr, dst_addr,
1428 sizeof(struct sockaddr_in6));
1429 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1430 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1431 (char *)&addr6->sin6_addr));
1432 }
1433
1434 qla_ep->host = shost;
1435
1436 return ep;
1437}
1438
1439static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1440{
1441 struct qla_endpoint *qla_ep;
1442 struct scsi_qla_host *ha;
1443 int ret = 0;
1444
1445 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1446 qla_ep = ep->dd_data;
1447 ha = to_qla_host(qla_ep->host);
1448
Mike Christie13483732011-12-01 21:38:41 -06001449 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001450 ret = 1;
1451
1452 return ret;
1453}
1454
1455static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1456{
1457 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1458 iscsi_destroy_endpoint(ep);
1459}
1460
1461static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1462 enum iscsi_param param,
1463 char *buf)
1464{
1465 struct qla_endpoint *qla_ep = ep->dd_data;
1466 struct sockaddr *dst_addr;
1467
1468 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1469
1470 switch (param) {
1471 case ISCSI_PARAM_CONN_PORT:
1472 case ISCSI_PARAM_CONN_ADDRESS:
1473 if (!qla_ep)
1474 return -ENOTCONN;
1475
1476 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1477 if (!dst_addr)
1478 return -ENOTCONN;
1479
1480 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1481 &qla_ep->dst_addr, param, buf);
1482 default:
1483 return -ENOSYS;
1484 }
1485}
1486
1487static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1488 struct iscsi_stats *stats)
1489{
1490 struct iscsi_session *sess;
1491 struct iscsi_cls_session *cls_sess;
1492 struct ddb_entry *ddb_entry;
1493 struct scsi_qla_host *ha;
1494 struct ql_iscsi_stats *ql_iscsi_stats;
1495 int stats_size;
1496 int ret;
1497 dma_addr_t iscsi_stats_dma;
1498
1499 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1500
1501 cls_sess = iscsi_conn_to_session(cls_conn);
1502 sess = cls_sess->dd_data;
1503 ddb_entry = sess->dd_data;
1504 ha = ddb_entry->ha;
1505
1506 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1507 /* Allocate memory */
1508 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1509 &iscsi_stats_dma, GFP_KERNEL);
1510 if (!ql_iscsi_stats) {
1511 ql4_printk(KERN_ERR, ha,
1512 "Unable to allocate memory for iscsi stats\n");
1513 goto exit_get_stats;
1514 }
1515
1516 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1517 iscsi_stats_dma);
1518 if (ret != QLA_SUCCESS) {
1519 ql4_printk(KERN_ERR, ha,
Masanari Iida59e13d42012-04-25 00:24:16 +09001520 "Unable to retrieve iscsi stats\n");
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001521 goto free_stats;
1522 }
1523
1524 /* octets */
1525 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1526 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1527 /* xmit pdus */
1528 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1529 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1530 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1531 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1532 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1533 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1534 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1535 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1536 /* recv pdus */
1537 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1538 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1539 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1540 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1541 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1542 stats->logoutrsp_pdus =
1543 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1544 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1545 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1546 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1547
1548free_stats:
1549 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1550 iscsi_stats_dma);
1551exit_get_stats:
1552 return;
1553}
1554
Mike Christie5c656af2009-07-15 15:02:59 -05001555static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1556{
1557 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001558 struct iscsi_session *sess;
1559 unsigned long flags;
1560 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -05001561
1562 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001563 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -05001564
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001565 spin_lock_irqsave(&session->lock, flags);
1566 if (session->state == ISCSI_SESSION_FAILED)
1567 ret = BLK_EH_RESET_TIMER;
1568 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -05001569
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001570 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001571}
1572
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001573static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1574{
1575 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001576 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001577 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1578
1579 qla4xxx_get_firmware_state(ha);
1580
1581 switch (ha->addl_fw_state & 0x0F00) {
1582 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1583 speed = ISCSI_PORT_SPEED_10MBPS;
1584 break;
1585 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1586 speed = ISCSI_PORT_SPEED_100MBPS;
1587 break;
1588 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1589 speed = ISCSI_PORT_SPEED_1GBPS;
1590 break;
1591 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1592 speed = ISCSI_PORT_SPEED_10GBPS;
1593 break;
1594 }
1595 ihost->port_speed = speed;
1596}
1597
1598static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1599{
1600 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001601 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001602 uint32_t state = ISCSI_PORT_STATE_DOWN;
1603
1604 if (test_bit(AF_LINK_UP, &ha->flags))
1605 state = ISCSI_PORT_STATE_UP;
1606
1607 ihost->port_state = state;
1608}
1609
Mike Christieaa1e93a2007-05-30 12:57:09 -05001610static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1611 enum iscsi_host_param param, char *buf)
1612{
1613 struct scsi_qla_host *ha = to_qla_host(shost);
1614 int len;
1615
1616 switch (param) {
1617 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -08001618 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -05001619 break;
Mike Christie22236962007-05-30 12:57:24 -05001620 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05001621 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -05001622 break;
Mike Christie8ad57812007-05-30 12:57:13 -05001623 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -05001624 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -05001625 break;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001626 case ISCSI_HOST_PARAM_PORT_STATE:
1627 qla4xxx_set_port_state(shost);
1628 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1629 break;
1630 case ISCSI_HOST_PARAM_PORT_SPEED:
1631 qla4xxx_set_port_speed(shost);
1632 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1633 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -05001634 default:
1635 return -ENOSYS;
1636 }
1637
1638 return len;
1639}
1640
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001641static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1642{
1643 if (ha->iface_ipv4)
1644 return;
1645
1646 /* IPv4 */
1647 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1648 &qla4xxx_iscsi_transport,
1649 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1650 if (!ha->iface_ipv4)
1651 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1652 "iface0.\n");
1653}
1654
1655static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1656{
1657 if (!ha->iface_ipv6_0)
1658 /* IPv6 iface-0 */
1659 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1660 &qla4xxx_iscsi_transport,
1661 ISCSI_IFACE_TYPE_IPV6, 0,
1662 0);
1663 if (!ha->iface_ipv6_0)
1664 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1665 "iface0.\n");
1666
1667 if (!ha->iface_ipv6_1)
1668 /* IPv6 iface-1 */
1669 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1670 &qla4xxx_iscsi_transport,
1671 ISCSI_IFACE_TYPE_IPV6, 1,
1672 0);
1673 if (!ha->iface_ipv6_1)
1674 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1675 "iface1.\n");
1676}
1677
1678static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1679{
1680 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1681 qla4xxx_create_ipv4_iface(ha);
1682
1683 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1684 qla4xxx_create_ipv6_iface(ha);
1685}
1686
1687static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1688{
1689 if (ha->iface_ipv4) {
1690 iscsi_destroy_iface(ha->iface_ipv4);
1691 ha->iface_ipv4 = NULL;
1692 }
1693}
1694
1695static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1696{
1697 if (ha->iface_ipv6_0) {
1698 iscsi_destroy_iface(ha->iface_ipv6_0);
1699 ha->iface_ipv6_0 = NULL;
1700 }
1701 if (ha->iface_ipv6_1) {
1702 iscsi_destroy_iface(ha->iface_ipv6_1);
1703 ha->iface_ipv6_1 = NULL;
1704 }
1705}
1706
1707static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1708{
1709 qla4xxx_destroy_ipv4_iface(ha);
1710 qla4xxx_destroy_ipv6_iface(ha);
1711}
1712
Mike Christied00efe32011-07-25 13:48:38 -05001713static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1714 struct iscsi_iface_param_info *iface_param,
1715 struct addr_ctrl_blk *init_fw_cb)
1716{
1717 /*
1718 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1719 * iface_num 1 is valid only for IPv6 Addr.
1720 */
1721 switch (iface_param->param) {
1722 case ISCSI_NET_PARAM_IPV6_ADDR:
1723 if (iface_param->iface_num & 0x1)
1724 /* IPv6 Addr 1 */
1725 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
1726 sizeof(init_fw_cb->ipv6_addr1));
1727 else
1728 /* IPv6 Addr 0 */
1729 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
1730 sizeof(init_fw_cb->ipv6_addr0));
1731 break;
1732 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1733 if (iface_param->iface_num & 0x1)
1734 break;
1735 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
1736 sizeof(init_fw_cb->ipv6_if_id));
1737 break;
1738 case ISCSI_NET_PARAM_IPV6_ROUTER:
1739 if (iface_param->iface_num & 0x1)
1740 break;
1741 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
1742 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1743 break;
1744 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1745 /* Autocfg applies to even interface */
1746 if (iface_param->iface_num & 0x1)
1747 break;
1748
1749 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
1750 init_fw_cb->ipv6_addtl_opts &=
1751 cpu_to_le16(
1752 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1753 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
1754 init_fw_cb->ipv6_addtl_opts |=
1755 cpu_to_le16(
1756 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1757 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001758 ql4_printk(KERN_ERR, ha,
1759 "Invalid autocfg setting for IPv6 addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05001760 break;
1761 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1762 /* Autocfg applies to even interface */
1763 if (iface_param->iface_num & 0x1)
1764 break;
1765
1766 if (iface_param->value[0] ==
1767 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
1768 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
1769 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1770 else if (iface_param->value[0] ==
1771 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
1772 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
1773 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1774 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001775 ql4_printk(KERN_ERR, ha,
1776 "Invalid autocfg setting for IPv6 linklocal addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05001777 break;
1778 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
1779 /* Autocfg applies to even interface */
1780 if (iface_param->iface_num & 0x1)
1781 break;
1782
1783 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
1784 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
1785 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1786 break;
1787 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001788 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05001789 init_fw_cb->ipv6_opts |=
1790 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001791 qla4xxx_create_ipv6_iface(ha);
1792 } else {
Mike Christied00efe32011-07-25 13:48:38 -05001793 init_fw_cb->ipv6_opts &=
1794 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
1795 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001796 qla4xxx_destroy_ipv6_iface(ha);
1797 }
Mike Christied00efe32011-07-25 13:48:38 -05001798 break;
Mike Christie2d636732011-10-11 17:55:11 -05001799 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05001800 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
1801 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001802 init_fw_cb->ipv6_vlan_tag =
1803 cpu_to_be16(*(uint16_t *)iface_param->value);
1804 break;
1805 case ISCSI_NET_PARAM_VLAN_ENABLED:
1806 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1807 init_fw_cb->ipv6_opts |=
1808 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
1809 else
1810 init_fw_cb->ipv6_opts &=
1811 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05001812 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07001813 case ISCSI_NET_PARAM_MTU:
1814 init_fw_cb->eth_mtu_size =
1815 cpu_to_le16(*(uint16_t *)iface_param->value);
1816 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07001817 case ISCSI_NET_PARAM_PORT:
1818 /* Autocfg applies to even interface */
1819 if (iface_param->iface_num & 0x1)
1820 break;
1821
1822 init_fw_cb->ipv6_port =
1823 cpu_to_le16(*(uint16_t *)iface_param->value);
1824 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001825 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1826 if (iface_param->iface_num & 0x1)
1827 break;
1828 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
1829 init_fw_cb->ipv6_tcp_opts |=
1830 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
1831 else
1832 init_fw_cb->ipv6_tcp_opts &=
1833 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE);
1834 break;
1835 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1836 if (iface_param->iface_num & 0x1)
1837 break;
1838 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
1839 init_fw_cb->ipv6_tcp_opts |=
1840 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
1841 else
1842 init_fw_cb->ipv6_tcp_opts &=
1843 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
1844 break;
1845 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1846 if (iface_param->iface_num & 0x1)
1847 break;
1848 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
1849 init_fw_cb->ipv6_tcp_opts |=
1850 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
1851 else
1852 init_fw_cb->ipv6_tcp_opts &=
1853 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
1854 break;
1855 case ISCSI_NET_PARAM_TCP_WSF:
1856 if (iface_param->iface_num & 0x1)
1857 break;
1858 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
1859 break;
1860 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1861 if (iface_param->iface_num & 0x1)
1862 break;
1863 init_fw_cb->ipv6_tcp_opts &=
1864 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
1865 init_fw_cb->ipv6_tcp_opts |=
1866 cpu_to_le16((iface_param->value[0] << 1) &
1867 IPV6_TCPOPT_TIMER_SCALE);
1868 break;
1869 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1870 if (iface_param->iface_num & 0x1)
1871 break;
1872 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
1873 init_fw_cb->ipv6_tcp_opts |=
1874 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
1875 else
1876 init_fw_cb->ipv6_tcp_opts &=
1877 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
1878 break;
1879 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1880 if (iface_param->iface_num & 0x1)
1881 break;
1882 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
1883 init_fw_cb->ipv6_opts |=
1884 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
1885 else
1886 init_fw_cb->ipv6_opts &=
1887 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
1888 break;
1889 case ISCSI_NET_PARAM_REDIRECT_EN:
1890 if (iface_param->iface_num & 0x1)
1891 break;
1892 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
1893 init_fw_cb->ipv6_opts |=
1894 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
1895 else
1896 init_fw_cb->ipv6_opts &=
1897 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
1898 break;
1899 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1900 if (iface_param->iface_num & 0x1)
1901 break;
1902 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
1903 init_fw_cb->ipv6_addtl_opts |=
1904 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
1905 else
1906 init_fw_cb->ipv6_addtl_opts &=
1907 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
1908 break;
1909 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1910 if (iface_param->iface_num & 0x1)
1911 break;
1912 init_fw_cb->ipv6_flow_lbl =
1913 cpu_to_le16(*(uint16_t *)iface_param->value);
1914 break;
1915 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1916 if (iface_param->iface_num & 0x1)
1917 break;
1918 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
1919 break;
1920 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1921 if (iface_param->iface_num & 0x1)
1922 break;
1923 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
1924 break;
1925 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1926 if (iface_param->iface_num & 0x1)
1927 break;
1928 init_fw_cb->ipv6_nd_reach_time =
1929 cpu_to_le32(*(uint32_t *)iface_param->value);
1930 break;
1931 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1932 if (iface_param->iface_num & 0x1)
1933 break;
1934 init_fw_cb->ipv6_nd_rexmit_timer =
1935 cpu_to_le32(*(uint32_t *)iface_param->value);
1936 break;
1937 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1938 if (iface_param->iface_num & 0x1)
1939 break;
1940 init_fw_cb->ipv6_nd_stale_timeout =
1941 cpu_to_le32(*(uint32_t *)iface_param->value);
1942 break;
1943 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1944 if (iface_param->iface_num & 0x1)
1945 break;
1946 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
1947 break;
1948 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1949 if (iface_param->iface_num & 0x1)
1950 break;
1951 init_fw_cb->ipv6_gw_advrt_mtu =
1952 cpu_to_le32(*(uint32_t *)iface_param->value);
1953 break;
Mike Christied00efe32011-07-25 13:48:38 -05001954 default:
1955 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
1956 iface_param->param);
1957 break;
1958 }
1959}
1960
1961static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
1962 struct iscsi_iface_param_info *iface_param,
1963 struct addr_ctrl_blk *init_fw_cb)
1964{
1965 switch (iface_param->param) {
1966 case ISCSI_NET_PARAM_IPV4_ADDR:
1967 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
1968 sizeof(init_fw_cb->ipv4_addr));
1969 break;
1970 case ISCSI_NET_PARAM_IPV4_SUBNET:
1971 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
1972 sizeof(init_fw_cb->ipv4_subnet));
1973 break;
1974 case ISCSI_NET_PARAM_IPV4_GW:
1975 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
1976 sizeof(init_fw_cb->ipv4_gw_addr));
1977 break;
1978 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1979 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
1980 init_fw_cb->ipv4_tcp_opts |=
1981 cpu_to_le16(TCPOPT_DHCP_ENABLE);
1982 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
1983 init_fw_cb->ipv4_tcp_opts &=
1984 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
1985 else
1986 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
1987 break;
1988 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001989 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05001990 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05001991 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001992 qla4xxx_create_ipv4_iface(ha);
1993 } else {
Mike Christied00efe32011-07-25 13:48:38 -05001994 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05001995 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -05001996 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001997 qla4xxx_destroy_ipv4_iface(ha);
1998 }
Mike Christied00efe32011-07-25 13:48:38 -05001999 break;
Mike Christie2d636732011-10-11 17:55:11 -05002000 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002001 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2002 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002003 init_fw_cb->ipv4_vlan_tag =
2004 cpu_to_be16(*(uint16_t *)iface_param->value);
2005 break;
2006 case ISCSI_NET_PARAM_VLAN_ENABLED:
2007 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2008 init_fw_cb->ipv4_ip_opts |=
2009 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2010 else
2011 init_fw_cb->ipv4_ip_opts &=
2012 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002013 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002014 case ISCSI_NET_PARAM_MTU:
2015 init_fw_cb->eth_mtu_size =
2016 cpu_to_le16(*(uint16_t *)iface_param->value);
2017 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002018 case ISCSI_NET_PARAM_PORT:
2019 init_fw_cb->ipv4_port =
2020 cpu_to_le16(*(uint16_t *)iface_param->value);
2021 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002022 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2023 if (iface_param->iface_num & 0x1)
2024 break;
2025 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2026 init_fw_cb->ipv4_tcp_opts |=
2027 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2028 else
2029 init_fw_cb->ipv4_tcp_opts &=
2030 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE);
2031 break;
2032 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2033 if (iface_param->iface_num & 0x1)
2034 break;
2035 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2036 init_fw_cb->ipv4_tcp_opts |=
2037 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2038 else
2039 init_fw_cb->ipv4_tcp_opts &=
2040 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2041 break;
2042 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2043 if (iface_param->iface_num & 0x1)
2044 break;
2045 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2046 init_fw_cb->ipv4_tcp_opts |=
2047 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2048 else
2049 init_fw_cb->ipv4_tcp_opts &=
2050 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2051 break;
2052 case ISCSI_NET_PARAM_TCP_WSF:
2053 if (iface_param->iface_num & 0x1)
2054 break;
2055 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2056 break;
2057 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2058 if (iface_param->iface_num & 0x1)
2059 break;
2060 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2061 init_fw_cb->ipv4_tcp_opts |=
2062 cpu_to_le16((iface_param->value[0] << 1) &
2063 TCPOPT_TIMER_SCALE);
2064 break;
2065 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2066 if (iface_param->iface_num & 0x1)
2067 break;
2068 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2069 init_fw_cb->ipv4_tcp_opts |=
2070 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2071 else
2072 init_fw_cb->ipv4_tcp_opts &=
2073 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2074 break;
2075 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2076 if (iface_param->iface_num & 0x1)
2077 break;
2078 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2079 init_fw_cb->ipv4_tcp_opts |=
2080 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2081 else
2082 init_fw_cb->ipv4_tcp_opts &=
2083 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2084 break;
2085 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2086 if (iface_param->iface_num & 0x1)
2087 break;
2088 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2089 init_fw_cb->ipv4_tcp_opts |=
2090 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2091 else
2092 init_fw_cb->ipv4_tcp_opts &=
2093 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2094 break;
2095 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2096 if (iface_param->iface_num & 0x1)
2097 break;
2098 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2099 init_fw_cb->ipv4_ip_opts |=
2100 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2101 else
2102 init_fw_cb->ipv4_ip_opts &=
2103 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2104 break;
2105 case ISCSI_NET_PARAM_IPV4_TOS:
2106 if (iface_param->iface_num & 0x1)
2107 break;
2108 init_fw_cb->ipv4_tos = iface_param->value[0];
2109 break;
2110 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2111 if (iface_param->iface_num & 0x1)
2112 break;
2113 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2114 init_fw_cb->ipv4_ip_opts |=
2115 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2116 else
2117 init_fw_cb->ipv4_ip_opts &=
2118 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2119 break;
2120 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2121 if (iface_param->iface_num & 0x1)
2122 break;
2123 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2124 init_fw_cb->ipv4_ip_opts |=
2125 cpu_to_le16(IPOPT_ALT_CID_EN);
2126 else
2127 init_fw_cb->ipv4_ip_opts &=
2128 cpu_to_le16(~IPOPT_ALT_CID_EN);
2129 break;
2130 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2131 if (iface_param->iface_num & 0x1)
2132 break;
2133 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2134 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2135 init_fw_cb->ipv4_dhcp_alt_cid_len =
2136 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2137 break;
2138 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2139 if (iface_param->iface_num & 0x1)
2140 break;
2141 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2142 init_fw_cb->ipv4_ip_opts |=
2143 cpu_to_le16(IPOPT_REQ_VID_EN);
2144 else
2145 init_fw_cb->ipv4_ip_opts &=
2146 cpu_to_le16(~IPOPT_REQ_VID_EN);
2147 break;
2148 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2149 if (iface_param->iface_num & 0x1)
2150 break;
2151 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2152 init_fw_cb->ipv4_ip_opts |=
2153 cpu_to_le16(IPOPT_USE_VID_EN);
2154 else
2155 init_fw_cb->ipv4_ip_opts &=
2156 cpu_to_le16(~IPOPT_USE_VID_EN);
2157 break;
2158 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2159 if (iface_param->iface_num & 0x1)
2160 break;
2161 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2162 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2163 init_fw_cb->ipv4_dhcp_vid_len =
2164 strlen(init_fw_cb->ipv4_dhcp_vid);
2165 break;
2166 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2167 if (iface_param->iface_num & 0x1)
2168 break;
2169 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2170 init_fw_cb->ipv4_ip_opts |=
2171 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2172 else
2173 init_fw_cb->ipv4_ip_opts &=
2174 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2175 break;
2176 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2177 if (iface_param->iface_num & 0x1)
2178 break;
2179 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2180 init_fw_cb->ipv4_ip_opts |=
2181 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2182 else
2183 init_fw_cb->ipv4_ip_opts &=
2184 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2185 break;
2186 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2187 if (iface_param->iface_num & 0x1)
2188 break;
2189 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2190 init_fw_cb->ipv4_ip_opts |=
2191 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2192 else
2193 init_fw_cb->ipv4_ip_opts &=
2194 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2195 break;
2196 case ISCSI_NET_PARAM_REDIRECT_EN:
2197 if (iface_param->iface_num & 0x1)
2198 break;
2199 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2200 init_fw_cb->ipv4_ip_opts |=
2201 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2202 else
2203 init_fw_cb->ipv4_ip_opts &=
2204 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2205 break;
2206 case ISCSI_NET_PARAM_IPV4_TTL:
2207 if (iface_param->iface_num & 0x1)
2208 break;
2209 init_fw_cb->ipv4_ttl = iface_param->value[0];
2210 break;
Mike Christied00efe32011-07-25 13:48:38 -05002211 default:
2212 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2213 iface_param->param);
2214 break;
2215 }
2216}
2217
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002218static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2219 struct iscsi_iface_param_info *iface_param,
2220 struct addr_ctrl_blk *init_fw_cb)
2221{
2222 switch (iface_param->param) {
2223 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2224 if (iface_param->iface_num & 0x1)
2225 break;
2226 init_fw_cb->def_timeout =
2227 cpu_to_le16(*(uint16_t *)iface_param->value);
2228 break;
2229 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2230 if (iface_param->iface_num & 0x1)
2231 break;
2232 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2233 init_fw_cb->iscsi_opts |=
2234 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2235 else
2236 init_fw_cb->iscsi_opts &=
2237 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2238 break;
2239 case ISCSI_IFACE_PARAM_DATADGST_EN:
2240 if (iface_param->iface_num & 0x1)
2241 break;
2242 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2243 init_fw_cb->iscsi_opts |=
2244 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2245 else
2246 init_fw_cb->iscsi_opts &=
2247 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2248 break;
2249 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2250 if (iface_param->iface_num & 0x1)
2251 break;
2252 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2253 init_fw_cb->iscsi_opts |=
2254 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2255 else
2256 init_fw_cb->iscsi_opts &=
2257 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2258 break;
2259 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2260 if (iface_param->iface_num & 0x1)
2261 break;
2262 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2263 init_fw_cb->iscsi_opts |=
2264 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2265 else
2266 init_fw_cb->iscsi_opts &=
2267 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2268 break;
2269 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2270 if (iface_param->iface_num & 0x1)
2271 break;
2272 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2273 init_fw_cb->iscsi_opts |=
2274 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2275 else
2276 init_fw_cb->iscsi_opts &=
2277 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2278 break;
2279 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2280 if (iface_param->iface_num & 0x1)
2281 break;
2282 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2283 init_fw_cb->iscsi_opts |=
2284 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2285 else
2286 init_fw_cb->iscsi_opts &=
2287 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2288 break;
2289 case ISCSI_IFACE_PARAM_ERL:
2290 if (iface_param->iface_num & 0x1)
2291 break;
2292 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2293 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2294 ISCSIOPTS_ERL);
2295 break;
2296 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2297 if (iface_param->iface_num & 0x1)
2298 break;
2299 init_fw_cb->iscsi_max_pdu_size =
2300 cpu_to_le32(*(uint32_t *)iface_param->value) /
2301 BYTE_UNITS;
2302 break;
2303 case ISCSI_IFACE_PARAM_FIRST_BURST:
2304 if (iface_param->iface_num & 0x1)
2305 break;
2306 init_fw_cb->iscsi_fburst_len =
2307 cpu_to_le32(*(uint32_t *)iface_param->value) /
2308 BYTE_UNITS;
2309 break;
2310 case ISCSI_IFACE_PARAM_MAX_R2T:
2311 if (iface_param->iface_num & 0x1)
2312 break;
2313 init_fw_cb->iscsi_max_outstnd_r2t =
2314 cpu_to_le16(*(uint16_t *)iface_param->value);
2315 break;
2316 case ISCSI_IFACE_PARAM_MAX_BURST:
2317 if (iface_param->iface_num & 0x1)
2318 break;
2319 init_fw_cb->iscsi_max_burst_len =
2320 cpu_to_le32(*(uint32_t *)iface_param->value) /
2321 BYTE_UNITS;
2322 break;
2323 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2324 if (iface_param->iface_num & 0x1)
2325 break;
2326 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2327 init_fw_cb->iscsi_opts |=
2328 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2329 else
2330 init_fw_cb->iscsi_opts &=
2331 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2332 break;
2333 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2334 if (iface_param->iface_num & 0x1)
2335 break;
2336 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2337 init_fw_cb->iscsi_opts |=
2338 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2339 else
2340 init_fw_cb->iscsi_opts &=
2341 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2342 break;
2343 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2344 if (iface_param->iface_num & 0x1)
2345 break;
2346 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2347 init_fw_cb->iscsi_opts |=
2348 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2349 else
2350 init_fw_cb->iscsi_opts &=
2351 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2352 break;
2353 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2354 if (iface_param->iface_num & 0x1)
2355 break;
2356 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2357 init_fw_cb->iscsi_opts |=
2358 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2359 else
2360 init_fw_cb->iscsi_opts &=
2361 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2362 break;
2363 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2364 if (iface_param->iface_num & 0x1)
2365 break;
2366 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2367 init_fw_cb->iscsi_opts |=
2368 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2369 else
2370 init_fw_cb->iscsi_opts &=
2371 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2372 break;
2373 default:
2374 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2375 iface_param->param);
2376 break;
2377 }
2378}
2379
Mike Christied00efe32011-07-25 13:48:38 -05002380static void
2381qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2382{
2383 struct addr_ctrl_blk_def *acb;
2384 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2385 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2386 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2387 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2388 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2389 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2390 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2391 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2392 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2393 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2394 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2395 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2396 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2397 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2398 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2399 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2400}
2401
2402static int
Mike Christie00c31882011-10-06 03:56:59 -05002403qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05002404{
2405 struct scsi_qla_host *ha = to_qla_host(shost);
2406 int rval = 0;
2407 struct iscsi_iface_param_info *iface_param = NULL;
2408 struct addr_ctrl_blk *init_fw_cb = NULL;
2409 dma_addr_t init_fw_cb_dma;
2410 uint32_t mbox_cmd[MBOX_REG_COUNT];
2411 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christie00c31882011-10-06 03:56:59 -05002412 uint32_t rem = len;
2413 struct nlattr *attr;
Mike Christied00efe32011-07-25 13:48:38 -05002414
2415 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2416 sizeof(struct addr_ctrl_blk),
2417 &init_fw_cb_dma, GFP_KERNEL);
2418 if (!init_fw_cb) {
2419 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2420 __func__);
2421 return -ENOMEM;
2422 }
2423
2424 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2425 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2426 memset(&mbox_sts, 0, sizeof(mbox_sts));
2427
2428 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2429 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2430 rval = -EIO;
2431 goto exit_init_fw_cb;
2432 }
2433
Mike Christie00c31882011-10-06 03:56:59 -05002434 nla_for_each_attr(attr, data, len, rem) {
2435 iface_param = nla_data(attr);
Mike Christied00efe32011-07-25 13:48:38 -05002436
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002437 if (iface_param->param_type == ISCSI_NET_PARAM) {
2438 switch (iface_param->iface_type) {
2439 case ISCSI_IFACE_TYPE_IPV4:
2440 switch (iface_param->iface_num) {
2441 case 0:
2442 qla4xxx_set_ipv4(ha, iface_param,
2443 init_fw_cb);
2444 break;
2445 default:
Mike Christied00efe32011-07-25 13:48:38 -05002446 /* Cannot have more than one IPv4 interface */
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002447 ql4_printk(KERN_ERR, ha,
2448 "Invalid IPv4 iface number = %d\n",
2449 iface_param->iface_num);
2450 break;
2451 }
Mike Christied00efe32011-07-25 13:48:38 -05002452 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002453 case ISCSI_IFACE_TYPE_IPV6:
2454 switch (iface_param->iface_num) {
2455 case 0:
2456 case 1:
2457 qla4xxx_set_ipv6(ha, iface_param,
2458 init_fw_cb);
2459 break;
2460 default:
2461 /* Cannot have more than two IPv6 interface */
2462 ql4_printk(KERN_ERR, ha,
2463 "Invalid IPv6 iface number = %d\n",
2464 iface_param->iface_num);
2465 break;
2466 }
Mike Christied00efe32011-07-25 13:48:38 -05002467 break;
2468 default:
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002469 ql4_printk(KERN_ERR, ha,
2470 "Invalid iface type\n");
Mike Christied00efe32011-07-25 13:48:38 -05002471 break;
2472 }
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002473 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2474 qla4xxx_set_iscsi_param(ha, iface_param,
2475 init_fw_cb);
2476 } else {
2477 continue;
Mike Christied00efe32011-07-25 13:48:38 -05002478 }
Mike Christied00efe32011-07-25 13:48:38 -05002479 }
2480
2481 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2482
2483 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2484 sizeof(struct addr_ctrl_blk),
2485 FLASH_OPT_RMW_COMMIT);
2486 if (rval != QLA_SUCCESS) {
2487 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2488 __func__);
2489 rval = -EIO;
2490 goto exit_init_fw_cb;
2491 }
2492
Vikas Chaudharyce505f92011-12-01 22:42:10 -08002493 rval = qla4xxx_disable_acb(ha);
2494 if (rval != QLA_SUCCESS) {
2495 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2496 __func__);
2497 rval = -EIO;
2498 goto exit_init_fw_cb;
2499 }
2500
2501 wait_for_completion_timeout(&ha->disable_acb_comp,
2502 DISABLE_ACB_TOV * HZ);
Mike Christied00efe32011-07-25 13:48:38 -05002503
2504 qla4xxx_initcb_to_acb(init_fw_cb);
2505
2506 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2507 if (rval != QLA_SUCCESS) {
2508 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2509 __func__);
2510 rval = -EIO;
2511 goto exit_init_fw_cb;
2512 }
2513
2514 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2515 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2516 init_fw_cb_dma);
2517
2518exit_init_fw_cb:
2519 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2520 init_fw_cb, init_fw_cb_dma);
2521
2522 return rval;
2523}
2524
Mike Christiefca9f042012-02-27 03:08:54 -08002525static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2526 enum iscsi_param param, char *buf)
2527{
2528 struct iscsi_session *sess = cls_sess->dd_data;
2529 struct ddb_entry *ddb_entry = sess->dd_data;
2530 struct scsi_qla_host *ha = ddb_entry->ha;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002531 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2532 struct ql4_chap_table chap_tbl;
Mike Christiefca9f042012-02-27 03:08:54 -08002533 int rval, len;
2534 uint16_t idx;
2535
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002536 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christiefca9f042012-02-27 03:08:54 -08002537 switch (param) {
2538 case ISCSI_PARAM_CHAP_IN_IDX:
2539 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2540 sess->password_in, BIDI_CHAP,
2541 &idx);
2542 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002543 len = sprintf(buf, "\n");
2544 else
2545 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002546 break;
2547 case ISCSI_PARAM_CHAP_OUT_IDX:
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002548 if (ddb_entry->ddb_type == FLASH_DDB) {
2549 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2550 idx = ddb_entry->chap_tbl_idx;
2551 rval = QLA_SUCCESS;
2552 } else {
2553 rval = QLA_ERROR;
2554 }
2555 } else {
2556 rval = qla4xxx_get_chap_index(ha, sess->username,
2557 sess->password,
2558 LOCAL_CHAP, &idx);
2559 }
Mike Christiefca9f042012-02-27 03:08:54 -08002560 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002561 len = sprintf(buf, "\n");
2562 else
2563 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002564 break;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002565 case ISCSI_PARAM_USERNAME:
2566 case ISCSI_PARAM_PASSWORD:
2567 /* First, populate session username and password for FLASH DDB,
2568 * if not already done. This happens when session login fails
2569 * for a FLASH DDB.
2570 */
2571 if (ddb_entry->ddb_type == FLASH_DDB &&
2572 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2573 !sess->username && !sess->password) {
2574 idx = ddb_entry->chap_tbl_idx;
2575 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2576 chap_tbl.secret,
2577 idx);
2578 if (!rval) {
2579 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2580 (char *)chap_tbl.name,
2581 strlen((char *)chap_tbl.name));
2582 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2583 (char *)chap_tbl.secret,
2584 chap_tbl.secret_len);
2585 }
2586 }
2587 /* allow fall-through */
Mike Christiefca9f042012-02-27 03:08:54 -08002588 default:
2589 return iscsi_session_get_param(cls_sess, param, buf);
2590 }
2591
2592 return len;
2593}
2594
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002595static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002596 enum iscsi_param param, char *buf)
2597{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002598 struct iscsi_conn *conn;
2599 struct qla_conn *qla_conn;
2600 struct sockaddr *dst_addr;
2601 int len = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002602
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002603 conn = cls_conn->dd_data;
2604 qla_conn = conn->dd_data;
Manish Rangankard46bdeb12012-08-07 07:57:13 -04002605 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002606
2607 switch (param) {
2608 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002609 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002610 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2611 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002612 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002613 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002614 }
2615
2616 return len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002617
David Somayajuluafaf5a22006-09-19 10:28:00 -07002618}
2619
Mike Christie13483732011-12-01 21:38:41 -06002620int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2621{
2622 uint32_t mbx_sts = 0;
2623 uint16_t tmp_ddb_index;
2624 int ret;
2625
2626get_ddb_index:
2627 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2628
2629 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2630 DEBUG2(ql4_printk(KERN_INFO, ha,
2631 "Free DDB index not available\n"));
2632 ret = QLA_ERROR;
2633 goto exit_get_ddb_index;
2634 }
2635
2636 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2637 goto get_ddb_index;
2638
2639 DEBUG2(ql4_printk(KERN_INFO, ha,
2640 "Found a free DDB index at %d\n", tmp_ddb_index));
2641 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2642 if (ret == QLA_ERROR) {
2643 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2644 ql4_printk(KERN_INFO, ha,
2645 "DDB index = %d not available trying next\n",
2646 tmp_ddb_index);
2647 goto get_ddb_index;
2648 }
2649 DEBUG2(ql4_printk(KERN_INFO, ha,
2650 "Free FW DDB not available\n"));
2651 }
2652
2653 *ddb_index = tmp_ddb_index;
2654
2655exit_get_ddb_index:
2656 return ret;
2657}
2658
2659static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2660 struct ddb_entry *ddb_entry,
2661 char *existing_ipaddr,
2662 char *user_ipaddr)
2663{
2664 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2665 char formatted_ipaddr[DDB_IPADDR_LEN];
2666 int status = QLA_SUCCESS, ret = 0;
2667
2668 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2669 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2670 '\0', NULL);
2671 if (ret == 0) {
2672 status = QLA_ERROR;
2673 goto out_match;
2674 }
2675 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2676 } else {
2677 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2678 '\0', NULL);
2679 if (ret == 0) {
2680 status = QLA_ERROR;
2681 goto out_match;
2682 }
2683 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2684 }
2685
2686 if (strcmp(existing_ipaddr, formatted_ipaddr))
2687 status = QLA_ERROR;
2688
2689out_match:
2690 return status;
2691}
2692
2693static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2694 struct iscsi_cls_conn *cls_conn)
2695{
2696 int idx = 0, max_ddbs, rval;
2697 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2698 struct iscsi_session *sess, *existing_sess;
2699 struct iscsi_conn *conn, *existing_conn;
2700 struct ddb_entry *ddb_entry;
2701
2702 sess = cls_sess->dd_data;
2703 conn = cls_conn->dd_data;
2704
2705 if (sess->targetname == NULL ||
2706 conn->persistent_address == NULL ||
2707 conn->persistent_port == 0)
2708 return QLA_ERROR;
2709
2710 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
2711 MAX_DEV_DB_ENTRIES;
2712
2713 for (idx = 0; idx < max_ddbs; idx++) {
2714 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
2715 if (ddb_entry == NULL)
2716 continue;
2717
2718 if (ddb_entry->ddb_type != FLASH_DDB)
2719 continue;
2720
2721 existing_sess = ddb_entry->sess->dd_data;
2722 existing_conn = ddb_entry->conn->dd_data;
2723
2724 if (existing_sess->targetname == NULL ||
2725 existing_conn->persistent_address == NULL ||
2726 existing_conn->persistent_port == 0)
2727 continue;
2728
2729 DEBUG2(ql4_printk(KERN_INFO, ha,
2730 "IQN = %s User IQN = %s\n",
2731 existing_sess->targetname,
2732 sess->targetname));
2733
2734 DEBUG2(ql4_printk(KERN_INFO, ha,
2735 "IP = %s User IP = %s\n",
2736 existing_conn->persistent_address,
2737 conn->persistent_address));
2738
2739 DEBUG2(ql4_printk(KERN_INFO, ha,
2740 "Port = %d User Port = %d\n",
2741 existing_conn->persistent_port,
2742 conn->persistent_port));
2743
2744 if (strcmp(existing_sess->targetname, sess->targetname))
2745 continue;
2746 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
2747 existing_conn->persistent_address,
2748 conn->persistent_address);
2749 if (rval == QLA_ERROR)
2750 continue;
2751 if (existing_conn->persistent_port != conn->persistent_port)
2752 continue;
2753 break;
2754 }
2755
2756 if (idx == max_ddbs)
2757 return QLA_ERROR;
2758
2759 DEBUG2(ql4_printk(KERN_INFO, ha,
2760 "Match found in fwdb sessions\n"));
2761 return QLA_SUCCESS;
2762}
2763
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002764static struct iscsi_cls_session *
2765qla4xxx_session_create(struct iscsi_endpoint *ep,
2766 uint16_t cmds_max, uint16_t qdepth,
2767 uint32_t initial_cmdsn)
2768{
2769 struct iscsi_cls_session *cls_sess;
2770 struct scsi_qla_host *ha;
2771 struct qla_endpoint *qla_ep;
2772 struct ddb_entry *ddb_entry;
Mike Christie13483732011-12-01 21:38:41 -06002773 uint16_t ddb_index;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002774 struct iscsi_session *sess;
2775 struct sockaddr *dst_addr;
2776 int ret;
2777
2778 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2779 if (!ep) {
2780 printk(KERN_ERR "qla4xxx: missing ep.\n");
2781 return NULL;
2782 }
2783
2784 qla_ep = ep->dd_data;
2785 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
2786 ha = to_qla_host(qla_ep->host);
Manish Rangankar736cf362011-10-07 16:55:46 -07002787
Mike Christie13483732011-12-01 21:38:41 -06002788 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
2789 if (ret == QLA_ERROR)
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002790 return NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002791
2792 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
2793 cmds_max, sizeof(struct ddb_entry),
2794 sizeof(struct ql4_task_data),
2795 initial_cmdsn, ddb_index);
2796 if (!cls_sess)
2797 return NULL;
2798
2799 sess = cls_sess->dd_data;
2800 ddb_entry = sess->dd_data;
2801 ddb_entry->fw_ddb_index = ddb_index;
2802 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
2803 ddb_entry->ha = ha;
2804 ddb_entry->sess = cls_sess;
Mike Christie13483732011-12-01 21:38:41 -06002805 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
2806 ddb_entry->ddb_change = qla4xxx_ddb_change;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002807 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
2808 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
2809 ha->tot_ddbs++;
2810
2811 return cls_sess;
2812}
2813
2814static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
2815{
2816 struct iscsi_session *sess;
2817 struct ddb_entry *ddb_entry;
2818 struct scsi_qla_host *ha;
Manish Rangankar90599b62012-04-23 22:32:34 -07002819 unsigned long flags, wtime;
2820 struct dev_db_entry *fw_ddb_entry = NULL;
2821 dma_addr_t fw_ddb_entry_dma;
2822 uint32_t ddb_state;
2823 int ret;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002824
2825 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2826 sess = cls_sess->dd_data;
2827 ddb_entry = sess->dd_data;
2828 ha = ddb_entry->ha;
2829
Manish Rangankar90599b62012-04-23 22:32:34 -07002830 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2831 &fw_ddb_entry_dma, GFP_KERNEL);
2832 if (!fw_ddb_entry) {
2833 ql4_printk(KERN_ERR, ha,
2834 "%s: Unable to allocate dma buffer\n", __func__);
2835 goto destroy_session;
2836 }
2837
2838 wtime = jiffies + (HZ * LOGOUT_TOV);
2839 do {
2840 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
2841 fw_ddb_entry, fw_ddb_entry_dma,
2842 NULL, NULL, &ddb_state, NULL,
2843 NULL, NULL);
2844 if (ret == QLA_ERROR)
2845 goto destroy_session;
2846
2847 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
2848 (ddb_state == DDB_DS_SESSION_FAILED))
2849 goto destroy_session;
2850
2851 schedule_timeout_uninterruptible(HZ);
2852 } while ((time_after(wtime, jiffies)));
2853
2854destroy_session:
Manish Rangankar736cf362011-10-07 16:55:46 -07002855 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
2856
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002857 spin_lock_irqsave(&ha->hardware_lock, flags);
2858 qla4xxx_free_ddb(ha, ddb_entry);
2859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Manish Rangankar90599b62012-04-23 22:32:34 -07002860
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002861 iscsi_session_teardown(cls_sess);
Manish Rangankar90599b62012-04-23 22:32:34 -07002862
2863 if (fw_ddb_entry)
2864 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2865 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002866}
2867
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002868static struct iscsi_cls_conn *
2869qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
2870{
2871 struct iscsi_cls_conn *cls_conn;
2872 struct iscsi_session *sess;
2873 struct ddb_entry *ddb_entry;
2874
2875 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2876 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
2877 conn_idx);
Mike Christieff1d0312011-12-01 21:38:43 -06002878 if (!cls_conn)
2879 return NULL;
2880
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002881 sess = cls_sess->dd_data;
2882 ddb_entry = sess->dd_data;
2883 ddb_entry->conn = cls_conn;
2884
2885 return cls_conn;
2886}
2887
2888static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
2889 struct iscsi_cls_conn *cls_conn,
2890 uint64_t transport_fd, int is_leading)
2891{
2892 struct iscsi_conn *conn;
2893 struct qla_conn *qla_conn;
2894 struct iscsi_endpoint *ep;
2895
2896 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2897
2898 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
2899 return -EINVAL;
2900 ep = iscsi_lookup_endpoint(transport_fd);
2901 conn = cls_conn->dd_data;
2902 qla_conn = conn->dd_data;
2903 qla_conn->qla_ep = ep->dd_data;
2904 return 0;
2905}
2906
2907static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
2908{
2909 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2910 struct iscsi_session *sess;
2911 struct ddb_entry *ddb_entry;
2912 struct scsi_qla_host *ha;
Mike Christie13483732011-12-01 21:38:41 -06002913 struct dev_db_entry *fw_ddb_entry = NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002914 dma_addr_t fw_ddb_entry_dma;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002915 uint32_t mbx_sts = 0;
2916 int ret = 0;
2917 int status = QLA_SUCCESS;
2918
2919 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2920 sess = cls_sess->dd_data;
2921 ddb_entry = sess->dd_data;
2922 ha = ddb_entry->ha;
2923
Mike Christie13483732011-12-01 21:38:41 -06002924 /* Check if we have matching FW DDB, if yes then do not
2925 * login to this target. This could cause target to logout previous
2926 * connection
2927 */
2928 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
2929 if (ret == QLA_SUCCESS) {
2930 ql4_printk(KERN_INFO, ha,
2931 "Session already exist in FW.\n");
2932 ret = -EEXIST;
2933 goto exit_conn_start;
2934 }
2935
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002936 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2937 &fw_ddb_entry_dma, GFP_KERNEL);
2938 if (!fw_ddb_entry) {
2939 ql4_printk(KERN_ERR, ha,
2940 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06002941 ret = -ENOMEM;
2942 goto exit_conn_start;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002943 }
2944
2945 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
2946 if (ret) {
2947 /* If iscsid is stopped and started then no need to do
2948 * set param again since ddb state will be already
2949 * active and FW does not allow set ddb to an
2950 * active session.
2951 */
2952 if (mbx_sts)
2953 if (ddb_entry->fw_ddb_device_state ==
Manish Rangankarf922da72011-10-07 16:55:49 -07002954 DDB_DS_SESSION_ACTIVE) {
Mike Christie13483732011-12-01 21:38:41 -06002955 ddb_entry->unblock_sess(ddb_entry->sess);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002956 goto exit_set_param;
Manish Rangankarf922da72011-10-07 16:55:49 -07002957 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002958
2959 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
2960 __func__, ddb_entry->fw_ddb_index);
2961 goto exit_conn_start;
2962 }
2963
2964 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
2965 if (status == QLA_ERROR) {
Manish Rangankar0e7e8502011-07-25 13:48:54 -05002966 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
2967 sess->targetname);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002968 ret = -EINVAL;
2969 goto exit_conn_start;
2970 }
2971
Manish Rangankar98270ab2011-10-07 16:55:47 -07002972 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
2973 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
2974
2975 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
2976 ddb_entry->fw_ddb_device_state));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002977
2978exit_set_param:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002979 ret = 0;
2980
2981exit_conn_start:
Mike Christie13483732011-12-01 21:38:41 -06002982 if (fw_ddb_entry)
2983 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2984 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002985 return ret;
2986}
2987
2988static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
2989{
2990 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2991 struct iscsi_session *sess;
2992 struct scsi_qla_host *ha;
2993 struct ddb_entry *ddb_entry;
2994 int options;
2995
2996 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2997 sess = cls_sess->dd_data;
2998 ddb_entry = sess->dd_data;
2999 ha = ddb_entry->ha;
3000
3001 options = LOGOUT_OPTION_CLOSE_SESSION;
3002 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3003 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003004}
3005
3006static void qla4xxx_task_work(struct work_struct *wdata)
3007{
3008 struct ql4_task_data *task_data;
3009 struct scsi_qla_host *ha;
3010 struct passthru_status *sts;
3011 struct iscsi_task *task;
3012 struct iscsi_hdr *hdr;
3013 uint8_t *data;
3014 uint32_t data_len;
3015 struct iscsi_conn *conn;
3016 int hdr_len;
3017 itt_t itt;
3018
3019 task_data = container_of(wdata, struct ql4_task_data, task_work);
3020 ha = task_data->ha;
3021 task = task_data->task;
3022 sts = &task_data->sts;
3023 hdr_len = sizeof(struct iscsi_hdr);
3024
3025 DEBUG3(printk(KERN_INFO "Status returned\n"));
3026 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3027 DEBUG3(printk(KERN_INFO "Response buffer"));
3028 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3029
3030 conn = task->conn;
3031
3032 switch (sts->completionStatus) {
3033 case PASSTHRU_STATUS_COMPLETE:
3034 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3035 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3036 itt = sts->handle;
3037 hdr->itt = itt;
3038 data = task_data->resp_buffer + hdr_len;
3039 data_len = task_data->resp_len - hdr_len;
3040 iscsi_complete_pdu(conn, hdr, data, data_len);
3041 break;
3042 default:
3043 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3044 sts->completionStatus);
3045 break;
3046 }
3047 return;
3048}
3049
3050static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3051{
3052 struct ql4_task_data *task_data;
3053 struct iscsi_session *sess;
3054 struct ddb_entry *ddb_entry;
3055 struct scsi_qla_host *ha;
3056 int hdr_len;
3057
3058 sess = task->conn->session;
3059 ddb_entry = sess->dd_data;
3060 ha = ddb_entry->ha;
3061 task_data = task->dd_data;
3062 memset(task_data, 0, sizeof(struct ql4_task_data));
3063
3064 if (task->sc) {
3065 ql4_printk(KERN_INFO, ha,
3066 "%s: SCSI Commands not implemented\n", __func__);
3067 return -EINVAL;
3068 }
3069
3070 hdr_len = sizeof(struct iscsi_hdr);
3071 task_data->ha = ha;
3072 task_data->task = task;
3073
3074 if (task->data_count) {
3075 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3076 task->data_count,
3077 PCI_DMA_TODEVICE);
3078 }
3079
3080 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3081 __func__, task->conn->max_recv_dlength, hdr_len));
3082
Manish Rangankar69ca2162011-10-07 16:55:50 -07003083 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003084 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3085 task_data->resp_len,
3086 &task_data->resp_dma,
3087 GFP_ATOMIC);
3088 if (!task_data->resp_buffer)
3089 goto exit_alloc_pdu;
3090
Manish Rangankar69ca2162011-10-07 16:55:50 -07003091 task_data->req_len = task->data_count + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003092 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
Manish Rangankar69ca2162011-10-07 16:55:50 -07003093 task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003094 &task_data->req_dma,
3095 GFP_ATOMIC);
3096 if (!task_data->req_buffer)
3097 goto exit_alloc_pdu;
3098
3099 task->hdr = task_data->req_buffer;
3100
3101 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3102
3103 return 0;
3104
3105exit_alloc_pdu:
3106 if (task_data->resp_buffer)
3107 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3108 task_data->resp_buffer, task_data->resp_dma);
3109
3110 if (task_data->req_buffer)
Manish Rangankar69ca2162011-10-07 16:55:50 -07003111 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003112 task_data->req_buffer, task_data->req_dma);
3113 return -ENOMEM;
3114}
3115
3116static void qla4xxx_task_cleanup(struct iscsi_task *task)
3117{
3118 struct ql4_task_data *task_data;
3119 struct iscsi_session *sess;
3120 struct ddb_entry *ddb_entry;
3121 struct scsi_qla_host *ha;
3122 int hdr_len;
3123
3124 hdr_len = sizeof(struct iscsi_hdr);
3125 sess = task->conn->session;
3126 ddb_entry = sess->dd_data;
3127 ha = ddb_entry->ha;
3128 task_data = task->dd_data;
3129
3130 if (task->data_count) {
3131 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3132 task->data_count, PCI_DMA_TODEVICE);
3133 }
3134
3135 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3136 __func__, task->conn->max_recv_dlength, hdr_len));
3137
3138 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3139 task_data->resp_buffer, task_data->resp_dma);
Manish Rangankar69ca2162011-10-07 16:55:50 -07003140 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003141 task_data->req_buffer, task_data->req_dma);
3142 return;
3143}
3144
3145static int qla4xxx_task_xmit(struct iscsi_task *task)
3146{
3147 struct scsi_cmnd *sc = task->sc;
3148 struct iscsi_session *sess = task->conn->session;
3149 struct ddb_entry *ddb_entry = sess->dd_data;
3150 struct scsi_qla_host *ha = ddb_entry->ha;
3151
3152 if (!sc)
3153 return qla4xxx_send_passthru0(task);
3154
3155 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3156 __func__);
3157 return -ENOSYS;
3158}
3159
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003160static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3161 struct iscsi_bus_flash_conn *conn,
3162 struct dev_db_entry *fw_ddb_entry)
3163{
3164 unsigned long options = 0;
3165 int rc = 0;
3166
3167 options = le16_to_cpu(fw_ddb_entry->options);
3168 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3169 if (test_bit(OPT_IPV6_DEVICE, &options)) {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003170 rc = iscsi_switch_str_param(&sess->portal_type,
3171 PORTAL_TYPE_IPV6);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003172 if (rc)
3173 goto exit_copy;
3174 } else {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003175 rc = iscsi_switch_str_param(&sess->portal_type,
3176 PORTAL_TYPE_IPV4);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003177 if (rc)
3178 goto exit_copy;
3179 }
3180
3181 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3182 &options);
3183 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3184 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3185
3186 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3187 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3188 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3189 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3190 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3191 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3192 &options);
3193 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3194 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3195 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3196 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3197 &options);
3198 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3199 sess->discovery_auth_optional =
3200 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3201 if (test_bit(ISCSIOPT_ERL1, &options))
3202 sess->erl |= BIT_1;
3203 if (test_bit(ISCSIOPT_ERL0, &options))
3204 sess->erl |= BIT_0;
3205
3206 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3207 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3208 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3209 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3210 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3211 conn->tcp_timer_scale |= BIT_3;
3212 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3213 conn->tcp_timer_scale |= BIT_2;
3214 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3215 conn->tcp_timer_scale |= BIT_1;
3216
3217 conn->tcp_timer_scale >>= 1;
3218 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3219
3220 options = le16_to_cpu(fw_ddb_entry->ip_options);
3221 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3222
3223 conn->max_recv_dlength = BYTE_UNITS *
3224 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3225 conn->max_xmit_dlength = BYTE_UNITS *
3226 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3227 sess->first_burst = BYTE_UNITS *
3228 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3229 sess->max_burst = BYTE_UNITS *
3230 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3231 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3232 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3233 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3234 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3235 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3236 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3237 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3238 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3239 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3240 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3241 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3242 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3243 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3244 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3245 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3246 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3247
3248 sess->default_taskmgmt_timeout =
3249 le16_to_cpu(fw_ddb_entry->def_timeout);
3250 conn->port = le16_to_cpu(fw_ddb_entry->port);
3251
3252 options = le16_to_cpu(fw_ddb_entry->options);
3253 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3254 if (!conn->ipaddress) {
3255 rc = -ENOMEM;
3256 goto exit_copy;
3257 }
3258
3259 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3260 if (!conn->redirect_ipaddr) {
3261 rc = -ENOMEM;
3262 goto exit_copy;
3263 }
3264
3265 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3266 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3267
3268 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3269 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3270
3271 conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3272 if (!conn->link_local_ipv6_addr) {
3273 rc = -ENOMEM;
3274 goto exit_copy;
3275 }
3276
3277 memcpy(conn->link_local_ipv6_addr,
3278 fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN);
3279 } else {
3280 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3281 }
3282
3283 if (fw_ddb_entry->iscsi_name[0]) {
3284 rc = iscsi_switch_str_param(&sess->targetname,
3285 (char *)fw_ddb_entry->iscsi_name);
3286 if (rc)
3287 goto exit_copy;
3288 }
3289
3290 if (fw_ddb_entry->iscsi_alias[0]) {
3291 rc = iscsi_switch_str_param(&sess->targetalias,
3292 (char *)fw_ddb_entry->iscsi_alias);
3293 if (rc)
3294 goto exit_copy;
3295 }
3296
3297 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3298
3299exit_copy:
3300 return rc;
3301}
3302
3303static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3304 struct iscsi_bus_flash_conn *conn,
3305 struct dev_db_entry *fw_ddb_entry)
3306{
3307 uint16_t options;
3308 int rc = 0;
3309
3310 options = le16_to_cpu(fw_ddb_entry->options);
3311 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003312 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003313 options |= BIT_8;
3314 else
3315 options &= ~BIT_8;
3316
3317 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3318 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3319 SET_BITVAL(sess->entry_state, options, BIT_3);
3320 fw_ddb_entry->options = cpu_to_le16(options);
3321
3322 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3323 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3324 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3325 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3326 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3327 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3328 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3329 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3330 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3331 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3332 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3333 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3334 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3335 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3336 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3337
3338 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3339 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3340 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3341 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3342 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3343 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3344 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3345 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3346 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3347
3348 options = le16_to_cpu(fw_ddb_entry->ip_options);
3349 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3350 fw_ddb_entry->ip_options = cpu_to_le16(options);
3351
3352 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3353 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3354 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3355 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3356 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3357 fw_ddb_entry->iscsi_first_burst_len =
3358 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3359 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3360 BYTE_UNITS);
3361 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3362 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3363 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3364 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003365 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3366 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003367 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3368 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3369 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003370 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3371 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
Adheer Chandravanshi65560162013-07-08 08:33:06 -04003372 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003373 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3374 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3375 fw_ddb_entry->port = cpu_to_le16(conn->port);
3376 fw_ddb_entry->def_timeout =
3377 cpu_to_le16(sess->default_taskmgmt_timeout);
3378
Adheer Chandravanshi84595802013-07-08 08:33:07 -04003379 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3380 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3381 else
3382 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3383
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003384 if (conn->ipaddress)
3385 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3386 sizeof(fw_ddb_entry->ip_addr));
3387
3388 if (conn->redirect_ipaddr)
3389 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3390 sizeof(fw_ddb_entry->tgt_addr));
3391
3392 if (conn->link_local_ipv6_addr)
3393 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3394 conn->link_local_ipv6_addr,
3395 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3396
3397 if (sess->targetname)
3398 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3399 sizeof(fw_ddb_entry->iscsi_name));
3400
3401 if (sess->targetalias)
3402 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3403 sizeof(fw_ddb_entry->iscsi_alias));
3404
3405 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3406
3407 return rc;
3408}
3409
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003410static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3411 struct iscsi_session *sess,
3412 struct dev_db_entry *fw_ddb_entry)
3413{
3414 unsigned long options = 0;
3415 uint16_t ddb_link;
3416 uint16_t disc_parent;
3417
3418 options = le16_to_cpu(fw_ddb_entry->options);
3419 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3420 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3421 &options);
3422 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3423
3424 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3425 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3426 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3427 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3428 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3429 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3430 &options);
3431 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3432 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3433 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3434 &options);
3435 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3436 sess->discovery_auth_optional =
3437 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3438 if (test_bit(ISCSIOPT_ERL1, &options))
3439 sess->erl |= BIT_1;
3440 if (test_bit(ISCSIOPT_ERL0, &options))
3441 sess->erl |= BIT_0;
3442
3443 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3444 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3445 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3446 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3447 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3448 conn->tcp_timer_scale |= BIT_3;
3449 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3450 conn->tcp_timer_scale |= BIT_2;
3451 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3452 conn->tcp_timer_scale |= BIT_1;
3453
3454 conn->tcp_timer_scale >>= 1;
3455 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3456
3457 options = le16_to_cpu(fw_ddb_entry->ip_options);
3458 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3459
3460 conn->max_recv_dlength = BYTE_UNITS *
3461 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3462 conn->max_xmit_dlength = BYTE_UNITS *
3463 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3464 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3465 sess->first_burst = BYTE_UNITS *
3466 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3467 sess->max_burst = BYTE_UNITS *
3468 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3469 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3470 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3471 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3472 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3473 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3474 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3475 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3476 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3477 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3478 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3479 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3480 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3481 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3482
3483 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003484 if (ddb_link == DDB_ISNS)
3485 disc_parent = ISCSI_DISC_PARENT_ISNS;
3486 else if (ddb_link == DDB_NO_LINK)
3487 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3488 else if (ddb_link < MAX_DDB_ENTRIES)
3489 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3490 else
3491 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3492
3493 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3494 iscsi_get_discovery_parent_name(disc_parent), 0);
3495
3496 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3497 (char *)fw_ddb_entry->iscsi_alias, 0);
3498}
3499
Mike Christie13483732011-12-01 21:38:41 -06003500static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3501 struct dev_db_entry *fw_ddb_entry,
3502 struct iscsi_cls_session *cls_sess,
3503 struct iscsi_cls_conn *cls_conn)
3504{
3505 int buflen = 0;
3506 struct iscsi_session *sess;
Nilesh Javali376738a2012-02-27 03:08:52 -08003507 struct ddb_entry *ddb_entry;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003508 struct ql4_chap_table chap_tbl;
Mike Christie13483732011-12-01 21:38:41 -06003509 struct iscsi_conn *conn;
3510 char ip_addr[DDB_IPADDR_LEN];
3511 uint16_t options = 0;
3512
3513 sess = cls_sess->dd_data;
Nilesh Javali376738a2012-02-27 03:08:52 -08003514 ddb_entry = sess->dd_data;
Mike Christie13483732011-12-01 21:38:41 -06003515 conn = cls_conn->dd_data;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003516 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christie13483732011-12-01 21:38:41 -06003517
Nilesh Javali376738a2012-02-27 03:08:52 -08003518 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3519
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003520 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Mike Christie13483732011-12-01 21:38:41 -06003521
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003522 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06003523 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3524
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003525 memset(ip_addr, 0, sizeof(ip_addr));
Mike Christie13483732011-12-01 21:38:41 -06003526 options = le16_to_cpu(fw_ddb_entry->options);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003527 if (options & DDB_OPT_IPV6_DEVICE) {
3528 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
Mike Christie13483732011-12-01 21:38:41 -06003529
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003530 memset(ip_addr, 0, sizeof(ip_addr));
3531 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3532 } else {
3533 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3534 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3535 }
3536
3537 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3538 (char *)ip_addr, buflen);
Mike Christie13483732011-12-01 21:38:41 -06003539 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3540 (char *)fw_ddb_entry->iscsi_name, buflen);
3541 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3542 (char *)ha->name_string, buflen);
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003543
3544 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3545 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3546 chap_tbl.secret,
3547 ddb_entry->chap_tbl_idx)) {
3548 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3549 (char *)chap_tbl.name,
3550 strlen((char *)chap_tbl.name));
3551 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3552 (char *)chap_tbl.secret,
3553 chap_tbl.secret_len);
3554 }
3555 }
Mike Christie13483732011-12-01 21:38:41 -06003556}
3557
3558void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3559 struct ddb_entry *ddb_entry)
3560{
3561 struct iscsi_cls_session *cls_sess;
3562 struct iscsi_cls_conn *cls_conn;
3563 uint32_t ddb_state;
3564 dma_addr_t fw_ddb_entry_dma;
3565 struct dev_db_entry *fw_ddb_entry;
3566
3567 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3568 &fw_ddb_entry_dma, GFP_KERNEL);
3569 if (!fw_ddb_entry) {
3570 ql4_printk(KERN_ERR, ha,
3571 "%s: Unable to allocate dma buffer\n", __func__);
3572 goto exit_session_conn_fwddb_param;
3573 }
3574
3575 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3576 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3577 NULL, NULL, NULL) == QLA_ERROR) {
3578 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3579 "get_ddb_entry for fw_ddb_index %d\n",
3580 ha->host_no, __func__,
3581 ddb_entry->fw_ddb_index));
3582 goto exit_session_conn_fwddb_param;
3583 }
3584
3585 cls_sess = ddb_entry->sess;
3586
3587 cls_conn = ddb_entry->conn;
3588
3589 /* Update params */
3590 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3591
3592exit_session_conn_fwddb_param:
3593 if (fw_ddb_entry)
3594 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3595 fw_ddb_entry, fw_ddb_entry_dma);
3596}
3597
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003598void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3599 struct ddb_entry *ddb_entry)
3600{
3601 struct iscsi_cls_session *cls_sess;
3602 struct iscsi_cls_conn *cls_conn;
3603 struct iscsi_session *sess;
3604 struct iscsi_conn *conn;
3605 uint32_t ddb_state;
3606 dma_addr_t fw_ddb_entry_dma;
3607 struct dev_db_entry *fw_ddb_entry;
3608
3609 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3610 &fw_ddb_entry_dma, GFP_KERNEL);
3611 if (!fw_ddb_entry) {
3612 ql4_printk(KERN_ERR, ha,
3613 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003614 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003615 }
3616
3617 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3618 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3619 NULL, NULL, NULL) == QLA_ERROR) {
3620 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3621 "get_ddb_entry for fw_ddb_index %d\n",
3622 ha->host_no, __func__,
3623 ddb_entry->fw_ddb_index));
Mike Christie13483732011-12-01 21:38:41 -06003624 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003625 }
3626
3627 cls_sess = ddb_entry->sess;
3628 sess = cls_sess->dd_data;
3629
3630 cls_conn = ddb_entry->conn;
3631 conn = cls_conn->dd_data;
3632
Mike Christie13483732011-12-01 21:38:41 -06003633 /* Update timers after login */
3634 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003635 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3636 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3637 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06003638 ddb_entry->default_time2wait =
3639 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3640
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003641 /* Update params */
Nilesh Javali376738a2012-02-27 03:08:52 -08003642 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003643 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003644
3645 memcpy(sess->initiatorname, ha->name_string,
3646 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
Mike Christie13483732011-12-01 21:38:41 -06003647
3648exit_session_conn_param:
3649 if (fw_ddb_entry)
3650 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3651 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003652}
3653
David Somayajuluafaf5a22006-09-19 10:28:00 -07003654/*
3655 * Timer routines
3656 */
3657
3658static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
3659 unsigned long interval)
3660{
3661 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3662 __func__, ha->host->host_no));
3663 init_timer(&ha->timer);
3664 ha->timer.expires = jiffies + interval * HZ;
3665 ha->timer.data = (unsigned long)ha;
3666 ha->timer.function = (void (*)(unsigned long))func;
3667 add_timer(&ha->timer);
3668 ha->timer_active = 1;
3669}
3670
3671static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3672{
3673 del_timer_sync(&ha->timer);
3674 ha->timer_active = 0;
3675}
3676
3677/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003678 * qla4xxx_mark_device_missing - blocks the session
3679 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07003680 * @ddb_entry: Pointer to device database entry
3681 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303682 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07003683 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003684void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003685{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003686 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003687}
3688
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303689/**
3690 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
3691 * @ha: Pointer to host adapter structure.
3692 *
3693 * This routine marks a device missing and resets the relogin retry count.
3694 **/
3695void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
3696{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003697 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303698}
3699
David Somayajuluafaf5a22006-09-19 10:28:00 -07003700static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
3701 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003702 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003703{
3704 struct srb *srb;
3705
3706 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
3707 if (!srb)
3708 return srb;
3709
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303710 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003711 srb->ha = ha;
3712 srb->ddb = ddb_entry;
3713 srb->cmd = cmd;
3714 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05303715 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003716
3717 return srb;
3718}
3719
3720static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
3721{
3722 struct scsi_cmnd *cmd = srb->cmd;
3723
3724 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09003725 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003726 srb->flags &= ~SRB_DMA_VALID;
3727 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05303728 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003729}
3730
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303731void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003732{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303733 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003734 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303735 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003736
3737 qla4xxx_srb_free_dma(ha, srb);
3738
3739 mempool_free(srb, ha->srb_mempool);
3740
3741 cmd->scsi_done(cmd);
3742}
3743
3744/**
3745 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003746 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07003747 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07003748 *
3749 * Remarks:
3750 * This routine is invoked by Linux to send a SCSI command to the driver.
3751 * The mid-level driver tries to ensure that queuecommand never gets
3752 * invoked concurrently with itself or the interrupt handler (although
3753 * the interrupt handler may call this routine as part of request-
3754 * completion handling). Unfortunely, it sometimes calls the scheduler
3755 * in interrupt context which is a big NO! NO!.
3756 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003757static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003758{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003759 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003760 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06003761 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003762 struct srb *srb;
3763 int rval;
3764
Lalit Chandivade2232be02010-07-30 14:38:47 +05303765 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
3766 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
3767 cmd->result = DID_NO_CONNECT << 16;
3768 else
3769 cmd->result = DID_REQUEUE << 16;
3770 goto qc_fail_command;
3771 }
3772
Mike Christie7fb19212008-01-31 13:36:45 -06003773 if (!sess) {
3774 cmd->result = DID_IMM_RETRY << 16;
3775 goto qc_fail_command;
3776 }
3777
3778 rval = iscsi_session_chkready(sess);
3779 if (rval) {
3780 cmd->result = rval;
3781 goto qc_fail_command;
3782 }
3783
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303784 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
3785 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
3786 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
3787 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
3788 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
3789 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003790 !test_bit(AF_LINK_UP, &ha->flags) ||
Nilesh Javali026fbd32013-01-20 23:50:58 -05003791 test_bit(AF_LOOPBACK, &ha->flags) ||
Nilesh Javali7ab284c2013-08-16 07:03:03 -04003792 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
3793 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303794 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08003795 goto qc_host_busy;
3796
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003797 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003798 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003799 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003800
3801 rval = qla4xxx_send_command_to_isp(ha, srb);
3802 if (rval != QLA_SUCCESS)
3803 goto qc_host_busy_free_sp;
3804
David Somayajuluafaf5a22006-09-19 10:28:00 -07003805 return 0;
3806
3807qc_host_busy_free_sp:
3808 qla4xxx_srb_free_dma(ha, srb);
3809 mempool_free(srb, ha->srb_mempool);
3810
David Somayajuluafaf5a22006-09-19 10:28:00 -07003811qc_host_busy:
3812 return SCSI_MLQUEUE_HOST_BUSY;
3813
3814qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003815 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003816
3817 return 0;
3818}
3819
3820/**
3821 * qla4xxx_mem_free - frees memory allocated to adapter
3822 * @ha: Pointer to host adapter structure.
3823 *
3824 * Frees memory previously allocated by qla4xxx_mem_alloc
3825 **/
3826static void qla4xxx_mem_free(struct scsi_qla_host *ha)
3827{
3828 if (ha->queues)
3829 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
3830 ha->queues_dma);
3831
Tej Parkash068237c82012-05-18 04:41:44 -04003832 if (ha->fw_dump)
3833 vfree(ha->fw_dump);
3834
David Somayajuluafaf5a22006-09-19 10:28:00 -07003835 ha->queues_len = 0;
3836 ha->queues = NULL;
3837 ha->queues_dma = 0;
3838 ha->request_ring = NULL;
3839 ha->request_dma = 0;
3840 ha->response_ring = NULL;
3841 ha->response_dma = 0;
3842 ha->shadow_regs = NULL;
3843 ha->shadow_regs_dma = 0;
Tej Parkash068237c82012-05-18 04:41:44 -04003844 ha->fw_dump = NULL;
3845 ha->fw_dump_size = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003846
3847 /* Free srb pool. */
3848 if (ha->srb_mempool)
3849 mempool_destroy(ha->srb_mempool);
3850
3851 ha->srb_mempool = NULL;
3852
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003853 if (ha->chap_dma_pool)
3854 dma_pool_destroy(ha->chap_dma_pool);
3855
Lalit Chandivade45494152011-10-07 16:55:42 -07003856 if (ha->chap_list)
3857 vfree(ha->chap_list);
3858 ha->chap_list = NULL;
3859
Mike Christie13483732011-12-01 21:38:41 -06003860 if (ha->fw_ddb_dma_pool)
3861 dma_pool_destroy(ha->fw_ddb_dma_pool);
3862
David Somayajuluafaf5a22006-09-19 10:28:00 -07003863 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303864 if (is_qla8022(ha)) {
3865 if (ha->nx_pcibase)
3866 iounmap(
3867 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04003868 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04003869 if (ha->nx_pcibase)
3870 iounmap(
3871 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
3872 } else if (ha->reg) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003873 iounmap(ha->reg);
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04003874 }
3875
3876 if (ha->reset_tmplt.buff)
3877 vfree(ha->reset_tmplt.buff);
3878
David Somayajuluafaf5a22006-09-19 10:28:00 -07003879 pci_release_regions(ha->pdev);
3880}
3881
3882/**
3883 * qla4xxx_mem_alloc - allocates memory for use by adapter.
3884 * @ha: Pointer to host adapter structure
3885 *
3886 * Allocates DMA memory for request and response queues. Also allocates memory
3887 * for srbs.
3888 **/
3889static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
3890{
3891 unsigned long align;
3892
3893 /* Allocate contiguous block of DMA memory for queues. */
3894 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
3895 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
3896 sizeof(struct shadow_regs) +
3897 MEM_ALIGN_VALUE +
3898 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
3899 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
3900 &ha->queues_dma, GFP_KERNEL);
3901 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303902 ql4_printk(KERN_WARNING, ha,
3903 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003904
3905 goto mem_alloc_error_exit;
3906 }
3907 memset(ha->queues, 0, ha->queues_len);
3908
3909 /*
3910 * As per RISC alignment requirements -- the bus-address must be a
3911 * multiple of the request-ring size (in bytes).
3912 */
3913 align = 0;
3914 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
3915 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
3916 (MEM_ALIGN_VALUE - 1));
3917
3918 /* Update request and response queue pointers. */
3919 ha->request_dma = ha->queues_dma + align;
3920 ha->request_ring = (struct queue_entry *) (ha->queues + align);
3921 ha->response_dma = ha->queues_dma + align +
3922 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
3923 ha->response_ring = (struct queue_entry *) (ha->queues + align +
3924 (REQUEST_QUEUE_DEPTH *
3925 QUEUE_SIZE));
3926 ha->shadow_regs_dma = ha->queues_dma + align +
3927 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
3928 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
3929 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
3930 (REQUEST_QUEUE_DEPTH *
3931 QUEUE_SIZE) +
3932 (RESPONSE_QUEUE_DEPTH *
3933 QUEUE_SIZE));
3934
3935 /* Allocate memory for srb pool. */
3936 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
3937 mempool_free_slab, srb_cachep);
3938 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303939 ql4_printk(KERN_WARNING, ha,
3940 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003941
3942 goto mem_alloc_error_exit;
3943 }
3944
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003945 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
3946 CHAP_DMA_BLOCK_SIZE, 8, 0);
3947
3948 if (ha->chap_dma_pool == NULL) {
3949 ql4_printk(KERN_WARNING, ha,
3950 "%s: chap_dma_pool allocation failed..\n", __func__);
3951 goto mem_alloc_error_exit;
3952 }
3953
Mike Christie13483732011-12-01 21:38:41 -06003954 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
3955 DDB_DMA_BLOCK_SIZE, 8, 0);
3956
3957 if (ha->fw_ddb_dma_pool == NULL) {
3958 ql4_printk(KERN_WARNING, ha,
3959 "%s: fw_ddb_dma_pool allocation failed..\n",
3960 __func__);
3961 goto mem_alloc_error_exit;
3962 }
3963
David Somayajuluafaf5a22006-09-19 10:28:00 -07003964 return QLA_SUCCESS;
3965
3966mem_alloc_error_exit:
3967 qla4xxx_mem_free(ha);
3968 return QLA_ERROR;
3969}
3970
3971/**
Mike Hernandez4f770832012-01-11 02:44:15 -08003972 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
3973 * @ha: adapter block pointer.
3974 *
3975 * Note: The caller should not hold the idc lock.
3976 **/
3977static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
3978{
3979 uint32_t temp, temp_state, temp_val;
3980 int status = QLA_SUCCESS;
3981
Vikas Chaudhary33693c72012-08-22 07:55:04 -04003982 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08003983
3984 temp_state = qla82xx_get_temp_state(temp);
3985 temp_val = qla82xx_get_temp_val(temp);
3986
3987 if (temp_state == QLA82XX_TEMP_PANIC) {
3988 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
3989 " exceeds maximum allowed. Hardware has been shut"
3990 " down.\n", temp_val);
3991 status = QLA_ERROR;
3992 } else if (temp_state == QLA82XX_TEMP_WARN) {
3993 if (ha->temperature == QLA82XX_TEMP_NORMAL)
3994 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
3995 " degrees C exceeds operating range."
3996 " Immediate action needed.\n", temp_val);
3997 } else {
3998 if (ha->temperature == QLA82XX_TEMP_WARN)
3999 ql4_printk(KERN_INFO, ha, "Device temperature is"
4000 " now %d degrees C in normal range.\n",
4001 temp_val);
4002 }
4003 ha->temperature = temp_state;
4004 return status;
4005}
4006
4007/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304008 * qla4_8xxx_check_fw_alive - Check firmware health
4009 * @ha: Pointer to host adapter structure.
4010 *
4011 * Context: Interrupt
4012 **/
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004013static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304014{
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004015 uint32_t fw_heartbeat_counter;
4016 int status = QLA_SUCCESS;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304017
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004018 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4019 QLA8XXX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05304020 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4021 if (fw_heartbeat_counter == 0xffffffff) {
4022 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4023 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4024 ha->host_no, __func__));
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004025 return status;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304026 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304027
4028 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4029 ha->seconds_since_last_heartbeat++;
4030 /* FW not alive after 2 seconds */
4031 if (ha->seconds_since_last_heartbeat == 2) {
4032 ha->seconds_since_last_heartbeat = 0;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004033 qla4_8xxx_dump_peg_reg(ha);
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004034 status = QLA_ERROR;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304035 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07004036 } else
4037 ha->seconds_since_last_heartbeat = 0;
4038
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304039 ha->fw_heartbeat_counter = fw_heartbeat_counter;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004040 return status;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304041}
4042
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004043static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4044{
4045 uint32_t halt_status;
4046 int halt_status_unrecoverable = 0;
4047
4048 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4049
4050 if (is_qla8022(ha)) {
4051 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4052 __func__);
4053 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4054 CRB_NIU_XG_PAUSE_CTL_P0 |
4055 CRB_NIU_XG_PAUSE_CTL_P1);
4056
4057 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4058 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4059 __func__);
4060 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4061 halt_status_unrecoverable = 1;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004062 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004063 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4064 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4065 __func__);
4066 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4067 halt_status_unrecoverable = 1;
4068 }
4069
4070 /*
4071 * Since we cannot change dev_state in interrupt context,
4072 * set appropriate DPC flag then wakeup DPC
4073 */
4074 if (halt_status_unrecoverable) {
4075 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4076 } else {
4077 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4078 __func__);
4079 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4080 }
4081 qla4xxx_mailbox_premature_completion(ha);
4082 qla4xxx_wake_dpc(ha);
4083}
4084
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304085/**
4086 * qla4_8xxx_watchdog - Poll dev state
4087 * @ha: Pointer to host adapter structure.
4088 *
4089 * Context: Interrupt
4090 **/
4091void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4092{
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004093 uint32_t dev_state;
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004094 uint32_t idc_ctrl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304095
4096 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08004097 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4098 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07004099 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004100 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004101
4102 if (qla4_8xxx_check_temp(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004103 if (is_qla8022(ha)) {
4104 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4105 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4106 CRB_NIU_XG_PAUSE_CTL_P0 |
4107 CRB_NIU_XG_PAUSE_CTL_P1);
4108 }
Mike Hernandez4f770832012-01-11 02:44:15 -08004109 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4110 qla4xxx_wake_dpc(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004111 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004112 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004113
4114 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4115 __func__);
4116
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004117 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004118 idc_ctrl = qla4_83xx_rd_reg(ha,
4119 QLA83XX_IDC_DRV_CTRL);
4120 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4121 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4122 __func__);
4123 qla4xxx_mailbox_premature_completion(
4124 ha);
4125 }
4126 }
4127
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004128 if ((is_qla8032(ha) || is_qla8042(ha)) ||
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004129 (is_qla8022(ha) && !ql4xdontresethba)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004130 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4131 qla4xxx_wake_dpc(ha);
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004132 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004133 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304134 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004135 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4136 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304137 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4138 qla4xxx_wake_dpc(ha);
4139 } else {
4140 /* Check firmware health */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004141 if (qla4_8xxx_check_fw_alive(ha))
4142 qla4_8xxx_process_fw_error(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304143 }
4144 }
4145}
4146
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004147static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
Mike Christie13483732011-12-01 21:38:41 -06004148{
4149 struct iscsi_session *sess;
4150 struct ddb_entry *ddb_entry;
4151 struct scsi_qla_host *ha;
4152
4153 sess = cls_sess->dd_data;
4154 ddb_entry = sess->dd_data;
4155 ha = ddb_entry->ha;
4156
4157 if (!(ddb_entry->ddb_type == FLASH_DDB))
4158 return;
4159
4160 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4161 !iscsi_is_session_online(cls_sess)) {
4162 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4163 INVALID_ENTRY) {
4164 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4165 0) {
4166 atomic_set(&ddb_entry->retry_relogin_timer,
4167 INVALID_ENTRY);
4168 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4169 set_bit(DF_RELOGIN, &ddb_entry->flags);
4170 DEBUG2(ql4_printk(KERN_INFO, ha,
4171 "%s: index [%d] login device\n",
4172 __func__, ddb_entry->fw_ddb_index));
4173 } else
4174 atomic_dec(&ddb_entry->retry_relogin_timer);
4175 }
4176 }
4177
4178 /* Wait for relogin to timeout */
4179 if (atomic_read(&ddb_entry->relogin_timer) &&
4180 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4181 /*
4182 * If the relogin times out and the device is
4183 * still NOT ONLINE then try and relogin again.
4184 */
4185 if (!iscsi_is_session_online(cls_sess)) {
4186 /* Reset retry relogin timer */
4187 atomic_inc(&ddb_entry->relogin_retry_count);
4188 DEBUG2(ql4_printk(KERN_INFO, ha,
4189 "%s: index[%d] relogin timed out-retrying"
4190 " relogin (%d), retry (%d)\n", __func__,
4191 ddb_entry->fw_ddb_index,
4192 atomic_read(&ddb_entry->relogin_retry_count),
4193 ddb_entry->default_time2wait + 4));
4194 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4195 atomic_set(&ddb_entry->retry_relogin_timer,
4196 ddb_entry->default_time2wait + 4);
4197 }
4198 }
4199}
4200
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304201/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004202 * qla4xxx_timer - checks every second for work to do.
4203 * @ha: Pointer to host adapter structure.
4204 **/
4205static void qla4xxx_timer(struct scsi_qla_host *ha)
4206{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004207 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304208 uint16_t w;
4209
Mike Christie13483732011-12-01 21:38:41 -06004210 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4211
Lalit Chandivade2232be02010-07-30 14:38:47 +05304212 /* If we are in the middle of AER/EEH processing
4213 * skip any processing and reschedule the timer
4214 */
4215 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4216 mod_timer(&ha->timer, jiffies + HZ);
4217 return;
4218 }
4219
4220 /* Hardware read to trigger an EEH error during mailbox waits. */
4221 if (!pci_channel_offline(ha->pdev))
4222 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004223
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004224 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304225 qla4_8xxx_watchdog(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304226
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004227 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304228 /* Check for heartbeat interval. */
4229 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4230 ha->heartbeat_interval != 0) {
4231 ha->seconds_since_last_heartbeat++;
4232 if (ha->seconds_since_last_heartbeat >
4233 ha->heartbeat_interval + 2)
4234 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4235 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004236 }
4237
Vikas Chaudharyff884432011-08-29 23:43:02 +05304238 /* Process any deferred work. */
4239 if (!list_empty(&ha->work_list))
4240 start_dpc++;
4241
David Somayajuluafaf5a22006-09-19 10:28:00 -07004242 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07004243 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004244 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4245 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4246 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304247 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004248 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4249 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05304250 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304251 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4252 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07004253 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004254 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4255 " - dpc flags = 0x%lx\n",
4256 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304257 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004258 }
4259
4260 /* Reschedule timer thread to call us back in one second */
4261 mod_timer(&ha->timer, jiffies + HZ);
4262
4263 DEBUG2(ha->seconds_since_last_intr++);
4264}
4265
4266/**
4267 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4268 * @ha: Pointer to host adapter structure.
4269 *
4270 * This routine stalls the driver until all outstanding commands are returned.
4271 * Caller must release the Hardware Lock prior to calling this routine.
4272 **/
4273static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4274{
4275 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004276 unsigned long flags;
4277 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004278
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304279 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
4280
4281 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
4282 "complete\n", WAIT_CMD_TOV));
4283
4284 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004285 spin_lock_irqsave(&ha->hardware_lock, flags);
4286 /* Find a command that hasn't completed. */
4287 for (index = 0; index < ha->host->can_queue; index++) {
4288 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07004289 /*
4290 * We cannot just check if the index is valid,
4291 * becase if we are run from the scsi eh, then
4292 * the scsi/block layer is going to prevent
4293 * the tag from being released.
4294 */
4295 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07004296 break;
4297 }
4298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4299
4300 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304301 if (index == ha->host->can_queue)
4302 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004303
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304304 msleep(1000);
4305 }
4306 /* If we timed out on waiting for commands to come back
4307 * return ERROR. */
4308 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004309}
4310
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304311int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004312{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004313 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004314 unsigned long flags = 0;
4315
4316 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004317
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304318 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4319 return QLA_ERROR;
4320
David Somayajuluafaf5a22006-09-19 10:28:00 -07004321 spin_lock_irqsave(&ha->hardware_lock, flags);
4322
4323 /*
4324 * If the SCSI Reset Interrupt bit is set, clear it.
4325 * Otherwise, the Soft Reset won't work.
4326 */
4327 ctrl_status = readw(&ha->reg->ctrl_status);
4328 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4329 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4330
4331 /* Issue Soft Reset */
4332 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4333 readl(&ha->reg->ctrl_status);
4334
4335 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304336 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004337}
4338
4339/**
4340 * qla4xxx_soft_reset - performs soft reset.
4341 * @ha: Pointer to host adapter structure.
4342 **/
4343int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4344{
4345 uint32_t max_wait_time;
4346 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004347 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004348 uint32_t ctrl_status;
4349
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004350 status = qla4xxx_hw_reset(ha);
4351 if (status != QLA_SUCCESS)
4352 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004353
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004354 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004355 /* Wait until the Network Reset Intr bit is cleared */
4356 max_wait_time = RESET_INTR_TOV;
4357 do {
4358 spin_lock_irqsave(&ha->hardware_lock, flags);
4359 ctrl_status = readw(&ha->reg->ctrl_status);
4360 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4361
4362 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4363 break;
4364
4365 msleep(1000);
4366 } while ((--max_wait_time));
4367
4368 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4369 DEBUG2(printk(KERN_WARNING
4370 "scsi%ld: Network Reset Intr not cleared by "
4371 "Network function, clearing it now!\n",
4372 ha->host_no));
4373 spin_lock_irqsave(&ha->hardware_lock, flags);
4374 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4375 readl(&ha->reg->ctrl_status);
4376 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4377 }
4378
4379 /* Wait until the firmware tells us the Soft Reset is done */
4380 max_wait_time = SOFT_RESET_TOV;
4381 do {
4382 spin_lock_irqsave(&ha->hardware_lock, flags);
4383 ctrl_status = readw(&ha->reg->ctrl_status);
4384 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4385
4386 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4387 status = QLA_SUCCESS;
4388 break;
4389 }
4390
4391 msleep(1000);
4392 } while ((--max_wait_time));
4393
4394 /*
4395 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4396 * after the soft reset has taken place.
4397 */
4398 spin_lock_irqsave(&ha->hardware_lock, flags);
4399 ctrl_status = readw(&ha->reg->ctrl_status);
4400 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4401 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4402 readl(&ha->reg->ctrl_status);
4403 }
4404 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4405
4406 /* If soft reset fails then most probably the bios on other
4407 * function is also enabled.
4408 * Since the initialization is sequential the other fn
4409 * wont be able to acknowledge the soft reset.
4410 * Issue a force soft reset to workaround this scenario.
4411 */
4412 if (max_wait_time == 0) {
4413 /* Issue Force Soft Reset */
4414 spin_lock_irqsave(&ha->hardware_lock, flags);
4415 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4416 readl(&ha->reg->ctrl_status);
4417 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4418 /* Wait until the firmware tells us the Soft Reset is done */
4419 max_wait_time = SOFT_RESET_TOV;
4420 do {
4421 spin_lock_irqsave(&ha->hardware_lock, flags);
4422 ctrl_status = readw(&ha->reg->ctrl_status);
4423 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4424
4425 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4426 status = QLA_SUCCESS;
4427 break;
4428 }
4429
4430 msleep(1000);
4431 } while ((--max_wait_time));
4432 }
4433
4434 return status;
4435}
4436
4437/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304438 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004439 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304440 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07004441 *
4442 * This routine is called just prior to a HARD RESET to return all
4443 * outstanding commands back to the Operating System.
4444 * Caller should make sure that the following locks are released
4445 * before this calling routine: Hardware lock, and io_request_lock.
4446 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304447static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004448{
4449 struct srb *srb;
4450 int i;
4451 unsigned long flags;
4452
4453 spin_lock_irqsave(&ha->hardware_lock, flags);
4454 for (i = 0; i < ha->host->can_queue; i++) {
4455 srb = qla4xxx_del_from_active_array(ha, i);
4456 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304457 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304458 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004459 }
4460 }
4461 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004462}
4463
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304464void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4465{
4466 clear_bit(AF_ONLINE, &ha->flags);
4467
4468 /* Disable the board */
4469 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304470
4471 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4472 qla4xxx_mark_all_devices_missing(ha);
4473 clear_bit(AF_INIT_DONE, &ha->flags);
4474}
4475
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004476static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4477{
4478 struct iscsi_session *sess;
4479 struct ddb_entry *ddb_entry;
4480
4481 sess = cls_session->dd_data;
4482 ddb_entry = sess->dd_data;
4483 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
Mike Christie13483732011-12-01 21:38:41 -06004484
4485 if (ddb_entry->ddb_type == FLASH_DDB)
4486 iscsi_block_session(ddb_entry->sess);
4487 else
4488 iscsi_session_failure(cls_session->dd_data,
4489 ISCSI_ERR_CONN_FAILED);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004490}
4491
David Somayajuluafaf5a22006-09-19 10:28:00 -07004492/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004493 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4494 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004495 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304496static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004497{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304498 int status = QLA_ERROR;
4499 uint8_t reset_chip = 0;
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004500 uint32_t dev_state;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004501 unsigned long wait;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004502
4503 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304504 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004505 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004506 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06004507
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304508 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004509
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304510 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004511
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004512 if ((is_qla8032(ha) || is_qla8042(ha)) &&
Tej Parkash546fef22012-09-20 07:35:12 -04004513 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4514 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4515 __func__);
4516 /* disable pause frame for ISP83xx */
4517 qla4_83xx_disable_pause(ha);
4518 }
4519
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004520 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4521
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304522 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4523 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004524
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304525 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4526 * do not reset adapter, jump to initialize_adapter */
4527 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4528 status = QLA_SUCCESS;
4529 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004530 }
4531
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004532 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304533 * from eh_host_reset or ioctl module */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004534 if (is_qla80XX(ha) && !reset_chip &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304535 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4536
4537 DEBUG2(ql4_printk(KERN_INFO, ha,
4538 "scsi%ld: %s - Performing stop_firmware...\n",
4539 ha->host_no, __func__));
4540 status = ha->isp_ops->reset_firmware(ha);
4541 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004542 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4543 qla4xxx_cmd_wait(ha);
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05004544
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304545 ha->isp_ops->disable_intrs(ha);
4546 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4547 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4548 } else {
4549 /* If the stop_firmware fails then
4550 * reset the entire chip */
4551 reset_chip = 1;
4552 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4553 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4554 }
4555 }
4556
4557 /* Issue full chip reset if recovering from a catastrophic error,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004558 * or if stop_firmware fails for ISP-8xxx.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304559 * This is the default case for ISP-4xxx */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004560 if (is_qla40XX(ha) || reset_chip) {
4561 if (is_qla40XX(ha))
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004562 goto chip_reset;
4563
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004564 /* Check if 8XXX firmware is alive or not
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004565 * We may have arrived here from NEED_RESET
4566 * detection only */
4567 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4568 goto chip_reset;
4569
4570 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4571 while (time_before(jiffies, wait)) {
4572 if (qla4_8xxx_check_fw_alive(ha)) {
4573 qla4xxx_mailbox_premature_completion(ha);
4574 break;
4575 }
4576
4577 set_current_state(TASK_UNINTERRUPTIBLE);
4578 schedule_timeout(HZ);
4579 }
Vikas Chaudharyda106212012-08-22 07:45:26 -04004580chip_reset:
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004581 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4582 qla4xxx_cmd_wait(ha);
Vikas Chaudharyda106212012-08-22 07:45:26 -04004583
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304584 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4585 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4586 DEBUG2(ql4_printk(KERN_INFO, ha,
4587 "scsi%ld: %s - Performing chip reset..\n",
4588 ha->host_no, __func__));
4589 status = ha->isp_ops->reset_chip(ha);
4590 }
4591
4592 /* Flush any pending ddb changed AENs */
4593 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4594
4595recover_ha_init_adapter:
4596 /* Upon successful firmware/chip reset, re-initialize the adapter */
4597 if (status == QLA_SUCCESS) {
4598 /* For ISP-4xxx, force function 1 to always initialize
4599 * before function 3 to prevent both funcions from
4600 * stepping on top of the other */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004601 if (is_qla40XX(ha) && (ha->mac_index == 3))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304602 ssleep(6);
4603
4604 /* NOTE: AF_ONLINE flag set upon successful completion of
4605 * qla4xxx_initialize_adapter */
Mike Christie13483732011-12-01 21:38:41 -06004606 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304607 }
4608
4609 /* Retry failed adapter initialization, if necessary
4610 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4611 * case to prevent ping-pong resets between functions */
4612 if (!test_bit(AF_ONLINE, &ha->flags) &&
4613 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004614 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304615 * resetting the ha.
4616 * Since we don't want to block the DPC for too long
4617 * with multiple resets in the same thread,
4618 * utilize DPC to retry */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004619 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004620 ha->isp_ops->idc_lock(ha);
4621 dev_state = qla4_8xxx_rd_direct(ha,
4622 QLA8XXX_CRB_DEV_STATE);
4623 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004624 if (dev_state == QLA8XXX_DEV_FAILED) {
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004625 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4626 "recover adapter. H/W is in Failed "
4627 "state\n", __func__);
4628 qla4xxx_dead_adapter_cleanup(ha);
4629 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4630 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4631 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4632 &ha->dpc_flags);
4633 status = QLA_ERROR;
4634
4635 goto exit_recover;
4636 }
4637 }
4638
David Somayajuluafaf5a22006-09-19 10:28:00 -07004639 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4640 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4641 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4642 "(%d) more times\n", ha->host_no,
4643 ha->retry_reset_ha_cnt));
4644 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4645 status = QLA_ERROR;
4646 } else {
4647 if (ha->retry_reset_ha_cnt > 0) {
4648 /* Schedule another Reset HA--DPC will retry */
4649 ha->retry_reset_ha_cnt--;
4650 DEBUG2(printk("scsi%ld: recover adapter - "
4651 "retry remaining %d\n",
4652 ha->host_no,
4653 ha->retry_reset_ha_cnt));
4654 status = QLA_ERROR;
4655 }
4656
4657 if (ha->retry_reset_ha_cnt == 0) {
4658 /* Recover adapter retries have been exhausted.
4659 * Adapter DEAD */
4660 DEBUG2(printk("scsi%ld: recover adapter "
4661 "failed - board disabled\n",
4662 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304663 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004664 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4665 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304666 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004667 &ha->dpc_flags);
4668 status = QLA_ERROR;
4669 }
4670 }
4671 } else {
4672 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304673 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004674 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4675 }
4676
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004677exit_recover:
David Somayajuluafaf5a22006-09-19 10:28:00 -07004678 ha->adapter_error_count++;
4679
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304680 if (test_bit(AF_ONLINE, &ha->flags))
4681 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004682
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304683 scsi_unblock_requests(ha->host);
4684
4685 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4686 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004687 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304688
David Somayajuluafaf5a22006-09-19 10:28:00 -07004689 return status;
4690}
4691
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004692static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004693{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004694 struct iscsi_session *sess;
4695 struct ddb_entry *ddb_entry;
4696 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004697
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004698 sess = cls_session->dd_data;
4699 ddb_entry = sess->dd_data;
4700 ha = ddb_entry->ha;
4701 if (!iscsi_is_session_online(cls_session)) {
4702 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
4703 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4704 " unblock session\n", ha->host_no, __func__,
4705 ddb_entry->fw_ddb_index);
4706 iscsi_unblock_session(ddb_entry->sess);
4707 } else {
4708 /* Trigger relogin */
Mike Christie13483732011-12-01 21:38:41 -06004709 if (ddb_entry->ddb_type == FLASH_DDB) {
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04004710 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
4711 test_bit(DF_DISABLE_RELOGIN,
4712 &ddb_entry->flags)))
Mike Christie13483732011-12-01 21:38:41 -06004713 qla4xxx_arm_relogin_timer(ddb_entry);
4714 } else
4715 iscsi_session_failure(cls_session->dd_data,
4716 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004717 }
4718 }
4719}
4720
Mike Christie13483732011-12-01 21:38:41 -06004721int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
4722{
4723 struct iscsi_session *sess;
4724 struct ddb_entry *ddb_entry;
4725 struct scsi_qla_host *ha;
4726
4727 sess = cls_session->dd_data;
4728 ddb_entry = sess->dd_data;
4729 ha = ddb_entry->ha;
4730 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4731 " unblock session\n", ha->host_no, __func__,
4732 ddb_entry->fw_ddb_index);
4733
4734 iscsi_unblock_session(ddb_entry->sess);
4735
4736 /* Start scan target */
4737 if (test_bit(AF_ONLINE, &ha->flags)) {
4738 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4739 " start scan\n", ha->host_no, __func__,
4740 ddb_entry->fw_ddb_index);
4741 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
4742 }
4743 return QLA_SUCCESS;
4744}
4745
4746int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
4747{
4748 struct iscsi_session *sess;
4749 struct ddb_entry *ddb_entry;
4750 struct scsi_qla_host *ha;
Manish Rangankar80c53e62012-08-07 07:57:15 -04004751 int status = QLA_SUCCESS;
Mike Christie13483732011-12-01 21:38:41 -06004752
4753 sess = cls_session->dd_data;
4754 ddb_entry = sess->dd_data;
4755 ha = ddb_entry->ha;
4756 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4757 " unblock user space session\n", ha->host_no, __func__,
4758 ddb_entry->fw_ddb_index);
Mike Christie13483732011-12-01 21:38:41 -06004759
Manish Rangankar80c53e62012-08-07 07:57:15 -04004760 if (!iscsi_is_session_online(cls_session)) {
4761 iscsi_conn_start(ddb_entry->conn);
4762 iscsi_conn_login_event(ddb_entry->conn,
4763 ISCSI_CONN_STATE_LOGGED_IN);
4764 } else {
4765 ql4_printk(KERN_INFO, ha,
4766 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
4767 ha->host_no, __func__, ddb_entry->fw_ddb_index,
4768 cls_session->sid);
4769 status = QLA_ERROR;
4770 }
4771
4772 return status;
Mike Christie13483732011-12-01 21:38:41 -06004773}
4774
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004775static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
4776{
4777 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
4778}
4779
Mike Christie13483732011-12-01 21:38:41 -06004780static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4781{
4782 uint16_t relogin_timer;
4783 struct iscsi_session *sess;
4784 struct ddb_entry *ddb_entry;
4785 struct scsi_qla_host *ha;
4786
4787 sess = cls_sess->dd_data;
4788 ddb_entry = sess->dd_data;
4789 ha = ddb_entry->ha;
4790
4791 relogin_timer = max(ddb_entry->default_relogin_timeout,
4792 (uint16_t)RELOGIN_TOV);
4793 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
4794
4795 DEBUG2(ql4_printk(KERN_INFO, ha,
4796 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
4797 ddb_entry->fw_ddb_index, relogin_timer));
4798
4799 qla4xxx_login_flash_ddb(cls_sess);
4800}
4801
4802static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
4803{
4804 struct iscsi_session *sess;
4805 struct ddb_entry *ddb_entry;
4806 struct scsi_qla_host *ha;
4807
4808 sess = cls_sess->dd_data;
4809 ddb_entry = sess->dd_data;
4810 ha = ddb_entry->ha;
4811
4812 if (!(ddb_entry->ddb_type == FLASH_DDB))
4813 return;
4814
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04004815 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
4816 return;
4817
Mike Christie13483732011-12-01 21:38:41 -06004818 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
4819 !iscsi_is_session_online(cls_sess)) {
4820 DEBUG2(ql4_printk(KERN_INFO, ha,
4821 "relogin issued\n"));
4822 qla4xxx_relogin_flash_ddb(cls_sess);
4823 }
4824}
4825
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304826void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
4827{
Lalit Chandivade1b468072011-05-17 23:17:09 -07004828 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304829 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304830}
4831
Vikas Chaudharyff884432011-08-29 23:43:02 +05304832static struct qla4_work_evt *
4833qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
4834 enum qla4_work_type type)
4835{
4836 struct qla4_work_evt *e;
4837 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
4838
4839 e = kzalloc(size, GFP_ATOMIC);
4840 if (!e)
4841 return NULL;
4842
4843 INIT_LIST_HEAD(&e->list);
4844 e->type = type;
4845 return e;
4846}
4847
4848static void qla4xxx_post_work(struct scsi_qla_host *ha,
4849 struct qla4_work_evt *e)
4850{
4851 unsigned long flags;
4852
4853 spin_lock_irqsave(&ha->work_lock, flags);
4854 list_add_tail(&e->list, &ha->work_list);
4855 spin_unlock_irqrestore(&ha->work_lock, flags);
4856 qla4xxx_wake_dpc(ha);
4857}
4858
4859int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
4860 enum iscsi_host_event_code aen_code,
4861 uint32_t data_size, uint8_t *data)
4862{
4863 struct qla4_work_evt *e;
4864
4865 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
4866 if (!e)
4867 return QLA_ERROR;
4868
4869 e->u.aen.code = aen_code;
4870 e->u.aen.data_size = data_size;
4871 memcpy(e->u.aen.data, data, data_size);
4872
4873 qla4xxx_post_work(ha, e);
4874
4875 return QLA_SUCCESS;
4876}
4877
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05304878int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
4879 uint32_t status, uint32_t pid,
4880 uint32_t data_size, uint8_t *data)
4881{
4882 struct qla4_work_evt *e;
4883
4884 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
4885 if (!e)
4886 return QLA_ERROR;
4887
4888 e->u.ping.status = status;
4889 e->u.ping.pid = pid;
4890 e->u.ping.data_size = data_size;
4891 memcpy(e->u.ping.data, data, data_size);
4892
4893 qla4xxx_post_work(ha, e);
4894
4895 return QLA_SUCCESS;
4896}
4897
Vikas Chaudharya7380a62012-02-27 03:08:56 -08004898static void qla4xxx_do_work(struct scsi_qla_host *ha)
Vikas Chaudharyff884432011-08-29 23:43:02 +05304899{
4900 struct qla4_work_evt *e, *tmp;
4901 unsigned long flags;
4902 LIST_HEAD(work);
4903
4904 spin_lock_irqsave(&ha->work_lock, flags);
4905 list_splice_init(&ha->work_list, &work);
4906 spin_unlock_irqrestore(&ha->work_lock, flags);
4907
4908 list_for_each_entry_safe(e, tmp, &work, list) {
4909 list_del_init(&e->list);
4910
4911 switch (e->type) {
4912 case QLA4_EVENT_AEN:
4913 iscsi_post_host_event(ha->host_no,
4914 &qla4xxx_iscsi_transport,
4915 e->u.aen.code,
4916 e->u.aen.data_size,
4917 e->u.aen.data);
4918 break;
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05304919 case QLA4_EVENT_PING_STATUS:
4920 iscsi_ping_comp_event(ha->host_no,
4921 &qla4xxx_iscsi_transport,
4922 e->u.ping.status,
4923 e->u.ping.pid,
4924 e->u.ping.data_size,
4925 e->u.ping.data);
4926 break;
Vikas Chaudharyff884432011-08-29 23:43:02 +05304927 default:
4928 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
4929 "supported", e->type);
4930 }
4931 kfree(e);
4932 }
4933}
4934
David Somayajuluafaf5a22006-09-19 10:28:00 -07004935/**
4936 * qla4xxx_do_dpc - dpc routine
4937 * @data: in our case pointer to adapter structure
4938 *
4939 * This routine is a task that is schedule by the interrupt handler
4940 * to perform the background processing for interrupts. We put it
4941 * on a task queue that is consumed whenever the scheduler runs; that's
4942 * so you can do anything (i.e. put the process to sleep etc). In fact,
4943 * the mid-level tries to sleep when it reaches the driver threshold
4944 * "host->can_queue". This can cause a panic if we were in our interrupt code.
4945 **/
David Howellsc4028952006-11-22 14:57:56 +00004946static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004947{
David Howellsc4028952006-11-22 14:57:56 +00004948 struct scsi_qla_host *ha =
4949 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08004950 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004951
David C Somayajuluf26b9042006-11-15 16:41:09 -08004952 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304953 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
4954 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07004955
4956 /* Initialization not yet finished. Don't do anything yet. */
4957 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07004958 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004959
Lalit Chandivade2232be02010-07-30 14:38:47 +05304960 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4961 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
4962 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07004963 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304964 }
4965
Vikas Chaudharyff884432011-08-29 23:43:02 +05304966 /* post events to application */
4967 qla4xxx_do_work(ha);
4968
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004969 if (is_qla80XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304970 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004971 if (is_qla8032(ha) || is_qla8042(ha)) {
Tej Parkash546fef22012-09-20 07:35:12 -04004972 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4973 __func__);
4974 /* disable pause frame for ISP83xx */
4975 qla4_83xx_disable_pause(ha);
4976 }
4977
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004978 ha->isp_ops->idc_lock(ha);
4979 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
4980 QLA8XXX_DEV_FAILED);
4981 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304982 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
4983 qla4_8xxx_device_state_handler(ha);
4984 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04004985
Nilesh Javali7ab284c2013-08-16 07:03:03 -04004986 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
4987 if (is_qla8042(ha)) {
4988 if (ha->idc_info.info2 &
4989 ENABLE_INTERNAL_LOOPBACK) {
4990 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
4991 __func__);
4992 status = qla4_84xx_config_acb(ha,
4993 ACB_CONFIG_DISABLE);
4994 if (status != QLA_SUCCESS) {
4995 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
4996 __func__);
4997 }
4998 }
4999 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005000 qla4_83xx_post_idc_ack(ha);
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005001 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5002 }
5003
5004 if (is_qla8042(ha) &&
5005 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5006 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5007 __func__);
5008 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5009 QLA_SUCCESS) {
5010 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5011 __func__);
5012 }
5013 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5014 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005015
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305016 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5017 qla4_8xxx_need_qsnt_handler(ha);
5018 }
5019 }
5020
5021 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5022 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07005023 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305024 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005025 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005026 ((is_qla8032(ha) || is_qla8042(ha)) &&
5027 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305028 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5029 ha->host_no, __func__));
5030 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5031 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5032 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5033 goto dpc_post_reset_ha;
5034 }
5035 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5036 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5037 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005038
David C Somayajulu477ffb92007-01-22 12:26:11 -08005039 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07005040 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005041
David Somayajuluafaf5a22006-09-19 10:28:00 -07005042 while ((readw(&ha->reg->ctrl_status) &
5043 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5044 if (--wait_time == 0)
5045 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005046 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005047 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005048 if (wait_time == 0)
5049 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5050 "bit not cleared-- resetting\n",
5051 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305052 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005053 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5054 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305055 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005056 }
5057 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5058 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305059 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005060 }
5061 }
5062
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305063dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07005064 /* ---- process AEN? --- */
5065 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5066 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5067
5068 /* ---- Get DHCP IP Address? --- */
5069 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5070 qla4xxx_get_dhcp_ip_address(ha);
5071
Mike Christie13483732011-12-01 21:38:41 -06005072 /* ---- relogin device? --- */
5073 if (adapter_up(ha) &&
5074 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5075 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5076 }
5077
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305078 /* ---- link change? --- */
Nilesh Javali026fbd32013-01-20 23:50:58 -05005079 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5080 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305081 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5082 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005083 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305084 } else {
5085 /* ---- link up? --- *
5086 * F/W will auto login to all devices ONLY ONCE after
5087 * link up during driver initialization and runtime
5088 * fatal error recovery. Therefore, the driver must
5089 * manually relogin to devices when recovering from
5090 * connection failures, logouts, expired KATO, etc. */
Mike Christie13483732011-12-01 21:38:41 -06005091 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5092 qla4xxx_build_ddb_list(ha, ha->is_reset);
5093 iscsi_host_for_each_session(ha->host,
5094 qla4xxx_login_flash_ddb);
5095 } else
5096 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305097 }
5098 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005099}
5100
5101/**
5102 * qla4xxx_free_adapter - release the adapter
5103 * @ha: pointer to adapter structure
5104 **/
5105static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5106{
Sarang Radke8a28896012011-12-06 02:34:10 -08005107 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005108
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005109 /* Turn-off interrupts on the card. */
5110 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005111
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005112 if (is_qla40XX(ha)) {
5113 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5114 &ha->reg->ctrl_status);
5115 readl(&ha->reg->ctrl_status);
5116 } else if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005117 writel(0, &ha->qla4_82xx_reg->host_int);
5118 readl(&ha->qla4_82xx_reg->host_int);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005119 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudharyfbd81072012-09-20 07:35:03 -04005120 writel(0, &ha->qla4_83xx_reg->risc_intr);
5121 readl(&ha->qla4_83xx_reg->risc_intr);
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005122 }
5123
David Somayajuluafaf5a22006-09-19 10:28:00 -07005124 /* Remove timer thread, if present */
5125 if (ha->timer_active)
5126 qla4xxx_stop_timer(ha);
5127
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305128 /* Kill the kernel thread for this host */
5129 if (ha->dpc_thread)
5130 destroy_workqueue(ha->dpc_thread);
5131
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005132 /* Kill the kernel thread for this host */
5133 if (ha->task_wq)
5134 destroy_workqueue(ha->task_wq);
5135
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305136 /* Put firmware in known state */
5137 ha->isp_ops->reset_firmware(ha);
5138
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005139 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005140 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305141 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005142 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305143 }
5144
David Somayajuluafaf5a22006-09-19 10:28:00 -07005145 /* Detach interrupts */
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005146 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005147
David C Somayajulubee4fe82007-05-23 18:03:32 -07005148 /* free extra memory */
5149 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305150}
David C Somayajulubee4fe82007-05-23 18:03:32 -07005151
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305152int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5153{
5154 int status = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305155 unsigned long mem_base, mem_len, db_base, db_len;
5156 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005157
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305158 status = pci_request_regions(pdev, DRIVER_NAME);
5159 if (status) {
5160 printk(KERN_WARNING
5161 "scsi(%ld) Failed to reserve PIO regions (%s) "
5162 "status=%d\n", ha->host_no, pci_name(pdev), status);
5163 goto iospace_error_exit;
5164 }
5165
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305166 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
Sergei Shtylyov7d7311c2012-03-14 22:04:30 +03005167 __func__, pdev->revision));
5168 ha->revision_id = pdev->revision;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305169
5170 /* remap phys address */
5171 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5172 mem_len = pci_resource_len(pdev, 0);
5173 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5174 __func__, mem_base, mem_len));
5175
5176 /* mapping of pcibase pointer */
5177 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5178 if (!ha->nx_pcibase) {
5179 printk(KERN_ERR
5180 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5181 pci_release_regions(ha->pdev);
5182 goto iospace_error_exit;
5183 }
5184
5185 /* Mapping of IO base pointer, door bell read and write pointer */
5186
5187 /* mapping of IO base pointer */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005188 if (is_qla8022(ha)) {
5189 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5190 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5191 (ha->pdev->devfn << 11));
5192 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5193 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005194 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005195 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5196 ((uint8_t *)ha->nx_pcibase);
5197 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305198
5199 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5200 db_len = pci_resource_len(pdev, 4);
5201
Shyam Sundar2657c802010-10-06 22:50:29 -07005202 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305203iospace_error_exit:
5204 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005205}
5206
5207/***
5208 * qla4xxx_iospace_config - maps registers
5209 * @ha: pointer to adapter structure
5210 *
5211 * This routines maps HBA's registers from the pci address space
5212 * into the kernel virtual address space for memory mapped i/o.
5213 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305214int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005215{
5216 unsigned long pio, pio_len, pio_flags;
5217 unsigned long mmio, mmio_len, mmio_flags;
5218
5219 pio = pci_resource_start(ha->pdev, 0);
5220 pio_len = pci_resource_len(ha->pdev, 0);
5221 pio_flags = pci_resource_flags(ha->pdev, 0);
5222 if (pio_flags & IORESOURCE_IO) {
5223 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305224 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07005225 "Invalid PCI I/O region size\n");
5226 pio = 0;
5227 }
5228 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305229 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005230 pio = 0;
5231 }
5232
5233 /* Use MMIO operations for all accesses. */
5234 mmio = pci_resource_start(ha->pdev, 1);
5235 mmio_len = pci_resource_len(ha->pdev, 1);
5236 mmio_flags = pci_resource_flags(ha->pdev, 1);
5237
5238 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305239 ql4_printk(KERN_ERR, ha,
5240 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005241
5242 goto iospace_error_exit;
5243 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305244
David Somayajuluafaf5a22006-09-19 10:28:00 -07005245 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305246 ql4_printk(KERN_ERR, ha,
5247 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005248 goto iospace_error_exit;
5249 }
5250
5251 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305252 ql4_printk(KERN_WARNING, ha,
5253 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005254
5255 goto iospace_error_exit;
5256 }
5257
5258 ha->pio_address = pio;
5259 ha->pio_length = pio_len;
5260 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5261 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305262 ql4_printk(KERN_ERR, ha,
5263 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005264
5265 goto iospace_error_exit;
5266 }
5267
5268 return 0;
5269
5270iospace_error_exit:
5271 return -ENOMEM;
5272}
5273
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305274static struct isp_operations qla4xxx_isp_ops = {
5275 .iospace_config = qla4xxx_iospace_config,
5276 .pci_config = qla4xxx_pci_config,
5277 .disable_intrs = qla4xxx_disable_intrs,
5278 .enable_intrs = qla4xxx_enable_intrs,
5279 .start_firmware = qla4xxx_start_firmware,
5280 .intr_handler = qla4xxx_intr_handler,
5281 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5282 .reset_chip = qla4xxx_soft_reset,
5283 .reset_firmware = qla4xxx_hw_reset,
5284 .queue_iocb = qla4xxx_queue_iocb,
5285 .complete_iocb = qla4xxx_complete_iocb,
5286 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5287 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5288 .get_sys_info = qla4xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005289 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5290 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305291};
5292
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005293static struct isp_operations qla4_82xx_isp_ops = {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305294 .iospace_config = qla4_8xxx_iospace_config,
5295 .pci_config = qla4_8xxx_pci_config,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005296 .disable_intrs = qla4_82xx_disable_intrs,
5297 .enable_intrs = qla4_82xx_enable_intrs,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305298 .start_firmware = qla4_8xxx_load_risc,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005299 .restart_firmware = qla4_82xx_try_start_fw,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005300 .intr_handler = qla4_82xx_intr_handler,
5301 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005302 .need_reset = qla4_8xxx_need_reset,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005303 .reset_chip = qla4_82xx_isp_reset,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305304 .reset_firmware = qla4_8xxx_stop_firmware,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005305 .queue_iocb = qla4_82xx_queue_iocb,
5306 .complete_iocb = qla4_82xx_complete_iocb,
5307 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5308 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305309 .get_sys_info = qla4_8xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005310 .rd_reg_direct = qla4_82xx_rd_32,
5311 .wr_reg_direct = qla4_82xx_wr_32,
5312 .rd_reg_indirect = qla4_82xx_md_rd_32,
5313 .wr_reg_indirect = qla4_82xx_md_wr_32,
5314 .idc_lock = qla4_82xx_idc_lock,
5315 .idc_unlock = qla4_82xx_idc_unlock,
5316 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5317 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5318 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305319};
5320
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005321static struct isp_operations qla4_83xx_isp_ops = {
5322 .iospace_config = qla4_8xxx_iospace_config,
5323 .pci_config = qla4_8xxx_pci_config,
5324 .disable_intrs = qla4_83xx_disable_intrs,
5325 .enable_intrs = qla4_83xx_enable_intrs,
5326 .start_firmware = qla4_8xxx_load_risc,
5327 .restart_firmware = qla4_83xx_start_firmware,
5328 .intr_handler = qla4_83xx_intr_handler,
5329 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5330 .need_reset = qla4_8xxx_need_reset,
5331 .reset_chip = qla4_83xx_isp_reset,
5332 .reset_firmware = qla4_8xxx_stop_firmware,
5333 .queue_iocb = qla4_83xx_queue_iocb,
5334 .complete_iocb = qla4_83xx_complete_iocb,
Tej Parkasha24058f2013-03-07 05:43:13 -05005335 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5336 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005337 .get_sys_info = qla4_8xxx_get_sys_info,
5338 .rd_reg_direct = qla4_83xx_rd_reg,
5339 .wr_reg_direct = qla4_83xx_wr_reg,
5340 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5341 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5342 .idc_lock = qla4_83xx_drv_lock,
5343 .idc_unlock = qla4_83xx_drv_unlock,
5344 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5345 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5346 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305347};
5348
5349uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5350{
5351 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5352}
5353
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005354uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305355{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005356 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305357}
5358
5359uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5360{
5361 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5362}
5363
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005364uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305365{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005366 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305367}
5368
Manish Rangankar2a991c22011-07-25 13:48:55 -05005369static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5370{
5371 struct scsi_qla_host *ha = data;
5372 char *str = buf;
5373 int rc;
5374
5375 switch (type) {
5376 case ISCSI_BOOT_ETH_FLAGS:
5377 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5378 break;
5379 case ISCSI_BOOT_ETH_INDEX:
5380 rc = sprintf(str, "0\n");
5381 break;
5382 case ISCSI_BOOT_ETH_MAC:
5383 rc = sysfs_format_mac(str, ha->my_mac,
5384 MAC_ADDR_LEN);
5385 break;
5386 default:
5387 rc = -ENOSYS;
5388 break;
5389 }
5390 return rc;
5391}
5392
Al Viro587a1f12011-07-23 23:11:19 -04005393static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005394{
5395 int rc;
5396
5397 switch (type) {
5398 case ISCSI_BOOT_ETH_FLAGS:
5399 case ISCSI_BOOT_ETH_MAC:
5400 case ISCSI_BOOT_ETH_INDEX:
5401 rc = S_IRUGO;
5402 break;
5403 default:
5404 rc = 0;
5405 break;
5406 }
5407 return rc;
5408}
5409
5410static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5411{
5412 struct scsi_qla_host *ha = data;
5413 char *str = buf;
5414 int rc;
5415
5416 switch (type) {
5417 case ISCSI_BOOT_INI_INITIATOR_NAME:
5418 rc = sprintf(str, "%s\n", ha->name_string);
5419 break;
5420 default:
5421 rc = -ENOSYS;
5422 break;
5423 }
5424 return rc;
5425}
5426
Al Viro587a1f12011-07-23 23:11:19 -04005427static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005428{
5429 int rc;
5430
5431 switch (type) {
5432 case ISCSI_BOOT_INI_INITIATOR_NAME:
5433 rc = S_IRUGO;
5434 break;
5435 default:
5436 rc = 0;
5437 break;
5438 }
5439 return rc;
5440}
5441
5442static ssize_t
5443qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5444 char *buf)
5445{
5446 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5447 char *str = buf;
5448 int rc;
5449
5450 switch (type) {
5451 case ISCSI_BOOT_TGT_NAME:
5452 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5453 break;
5454 case ISCSI_BOOT_TGT_IP_ADDR:
5455 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5456 rc = sprintf(buf, "%pI4\n",
5457 &boot_conn->dest_ipaddr.ip_address);
5458 else
5459 rc = sprintf(str, "%pI6\n",
5460 &boot_conn->dest_ipaddr.ip_address);
5461 break;
5462 case ISCSI_BOOT_TGT_PORT:
5463 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5464 break;
5465 case ISCSI_BOOT_TGT_CHAP_NAME:
5466 rc = sprintf(str, "%.*s\n",
5467 boot_conn->chap.target_chap_name_length,
5468 (char *)&boot_conn->chap.target_chap_name);
5469 break;
5470 case ISCSI_BOOT_TGT_CHAP_SECRET:
5471 rc = sprintf(str, "%.*s\n",
5472 boot_conn->chap.target_secret_length,
5473 (char *)&boot_conn->chap.target_secret);
5474 break;
5475 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5476 rc = sprintf(str, "%.*s\n",
5477 boot_conn->chap.intr_chap_name_length,
5478 (char *)&boot_conn->chap.intr_chap_name);
5479 break;
5480 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5481 rc = sprintf(str, "%.*s\n",
5482 boot_conn->chap.intr_secret_length,
5483 (char *)&boot_conn->chap.intr_secret);
5484 break;
5485 case ISCSI_BOOT_TGT_FLAGS:
5486 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5487 break;
5488 case ISCSI_BOOT_TGT_NIC_ASSOC:
5489 rc = sprintf(str, "0\n");
5490 break;
5491 default:
5492 rc = -ENOSYS;
5493 break;
5494 }
5495 return rc;
5496}
5497
5498static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5499{
5500 struct scsi_qla_host *ha = data;
5501 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5502
5503 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5504}
5505
5506static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5507{
5508 struct scsi_qla_host *ha = data;
5509 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5510
5511 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5512}
5513
Al Viro587a1f12011-07-23 23:11:19 -04005514static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005515{
5516 int rc;
5517
5518 switch (type) {
5519 case ISCSI_BOOT_TGT_NAME:
5520 case ISCSI_BOOT_TGT_IP_ADDR:
5521 case ISCSI_BOOT_TGT_PORT:
5522 case ISCSI_BOOT_TGT_CHAP_NAME:
5523 case ISCSI_BOOT_TGT_CHAP_SECRET:
5524 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5525 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5526 case ISCSI_BOOT_TGT_NIC_ASSOC:
5527 case ISCSI_BOOT_TGT_FLAGS:
5528 rc = S_IRUGO;
5529 break;
5530 default:
5531 rc = 0;
5532 break;
5533 }
5534 return rc;
5535}
5536
5537static void qla4xxx_boot_release(void *data)
5538{
5539 struct scsi_qla_host *ha = data;
5540
5541 scsi_host_put(ha->host);
5542}
5543
5544static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5545{
5546 dma_addr_t buf_dma;
5547 uint32_t addr, pri_addr, sec_addr;
5548 uint32_t offset;
5549 uint16_t func_num;
5550 uint8_t val;
5551 uint8_t *buf = NULL;
5552 size_t size = 13 * sizeof(uint8_t);
5553 int ret = QLA_SUCCESS;
5554
5555 func_num = PCI_FUNC(ha->pdev->devfn);
5556
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005557 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5558 __func__, ha->pdev->device, func_num);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005559
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005560 if (is_qla40XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005561 if (func_num == 1) {
5562 addr = NVRAM_PORT0_BOOT_MODE;
5563 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5564 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5565 } else if (func_num == 3) {
5566 addr = NVRAM_PORT1_BOOT_MODE;
5567 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5568 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5569 } else {
5570 ret = QLA_ERROR;
5571 goto exit_boot_info;
5572 }
5573
5574 /* Check Boot Mode */
5575 val = rd_nvram_byte(ha, addr);
5576 if (!(val & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305577 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5578 "options : 0x%x\n", __func__, val));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005579 ret = QLA_ERROR;
5580 goto exit_boot_info;
5581 }
5582
5583 /* get primary valid target index */
5584 val = rd_nvram_byte(ha, pri_addr);
5585 if (val & BIT_7)
5586 ddb_index[0] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005587
5588 /* get secondary valid target index */
5589 val = rd_nvram_byte(ha, sec_addr);
5590 if (val & BIT_7)
5591 ddb_index[1] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005592
Vikas Chaudhary3e788fb2013-03-07 05:43:08 -05005593 } else if (is_qla80XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005594 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5595 &buf_dma, GFP_KERNEL);
5596 if (!buf) {
5597 DEBUG2(ql4_printk(KERN_ERR, ha,
5598 "%s: Unable to allocate dma buffer\n",
5599 __func__));
5600 ret = QLA_ERROR;
5601 goto exit_boot_info;
5602 }
5603
5604 if (ha->port_num == 0)
5605 offset = BOOT_PARAM_OFFSET_PORT0;
5606 else if (ha->port_num == 1)
5607 offset = BOOT_PARAM_OFFSET_PORT1;
5608 else {
5609 ret = QLA_ERROR;
5610 goto exit_boot_info_free;
5611 }
5612 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5613 offset;
5614 if (qla4xxx_get_flash(ha, buf_dma, addr,
5615 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5616 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
Petr Uzel0bd7f842012-02-24 16:32:59 +01005617 " failed\n", ha->host_no, __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005618 ret = QLA_ERROR;
5619 goto exit_boot_info_free;
5620 }
5621 /* Check Boot Mode */
5622 if (!(buf[1] & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305623 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5624 " : 0x%x\n", buf[1]));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005625 ret = QLA_ERROR;
5626 goto exit_boot_info_free;
5627 }
5628
5629 /* get primary valid target index */
5630 if (buf[2] & BIT_7)
5631 ddb_index[0] = buf[2] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005632
5633 /* get secondary valid target index */
5634 if (buf[11] & BIT_7)
5635 ddb_index[1] = buf[11] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005636 } else {
5637 ret = QLA_ERROR;
5638 goto exit_boot_info;
5639 }
5640
5641 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5642 " target ID %d\n", __func__, ddb_index[0],
5643 ddb_index[1]));
5644
5645exit_boot_info_free:
5646 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5647exit_boot_info:
Lalit Chandivade20e835b2012-02-13 18:30:42 +05305648 ha->pri_ddb_idx = ddb_index[0];
5649 ha->sec_ddb_idx = ddb_index[1];
Manish Rangankar2a991c22011-07-25 13:48:55 -05005650 return ret;
5651}
5652
Lalit Chandivade28deb452011-10-07 16:55:44 -07005653/**
5654 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5655 * @ha: pointer to adapter structure
5656 * @username: CHAP username to be returned
5657 * @password: CHAP password to be returned
5658 *
5659 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
5660 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
5661 * So from the CHAP cache find the first BIDI CHAP entry and set it
5662 * to the boot record in sysfs.
5663 **/
5664static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
5665 char *password)
5666{
5667 int i, ret = -EINVAL;
5668 int max_chap_entries = 0;
5669 struct ql4_chap_table *chap_table;
5670
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -04005671 if (is_qla80XX(ha))
Lalit Chandivade28deb452011-10-07 16:55:44 -07005672 max_chap_entries = (ha->hw.flt_chap_size / 2) /
5673 sizeof(struct ql4_chap_table);
5674 else
5675 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
5676
5677 if (!ha->chap_list) {
5678 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
5679 return ret;
5680 }
5681
5682 mutex_lock(&ha->chap_sem);
5683 for (i = 0; i < max_chap_entries; i++) {
5684 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
5685 if (chap_table->cookie !=
5686 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
5687 continue;
5688 }
5689
5690 if (chap_table->flags & BIT_7) /* local */
5691 continue;
5692
5693 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
5694 continue;
5695
5696 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
5697 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
5698 ret = 0;
5699 break;
5700 }
5701 mutex_unlock(&ha->chap_sem);
5702
5703 return ret;
5704}
5705
5706
Manish Rangankar2a991c22011-07-25 13:48:55 -05005707static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
5708 struct ql4_boot_session_info *boot_sess,
5709 uint16_t ddb_index)
5710{
5711 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5712 struct dev_db_entry *fw_ddb_entry;
5713 dma_addr_t fw_ddb_entry_dma;
5714 uint16_t idx;
5715 uint16_t options;
5716 int ret = QLA_SUCCESS;
5717
5718 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5719 &fw_ddb_entry_dma, GFP_KERNEL);
5720 if (!fw_ddb_entry) {
5721 DEBUG2(ql4_printk(KERN_ERR, ha,
5722 "%s: Unable to allocate dma buffer.\n",
5723 __func__));
5724 ret = QLA_ERROR;
5725 return ret;
5726 }
5727
5728 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
5729 fw_ddb_entry_dma, ddb_index)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305730 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
5731 "index [%d]\n", __func__, ddb_index));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005732 ret = QLA_ERROR;
5733 goto exit_boot_target;
5734 }
5735
5736 /* Update target name and IP from DDB */
5737 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
5738 min(sizeof(boot_sess->target_name),
5739 sizeof(fw_ddb_entry->iscsi_name)));
5740
5741 options = le16_to_cpu(fw_ddb_entry->options);
5742 if (options & DDB_OPT_IPV6_DEVICE) {
5743 memcpy(&boot_conn->dest_ipaddr.ip_address,
5744 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
5745 } else {
5746 boot_conn->dest_ipaddr.ip_type = 0x1;
5747 memcpy(&boot_conn->dest_ipaddr.ip_address,
5748 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
5749 }
5750
5751 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
5752
5753 /* update chap information */
5754 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
5755
5756 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
5757
5758 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
5759
5760 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
5761 target_chap_name,
5762 (char *)&boot_conn->chap.target_secret,
5763 idx);
5764 if (ret) {
5765 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
5766 ret = QLA_ERROR;
5767 goto exit_boot_target;
5768 }
5769
5770 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
5771 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
5772 }
5773
5774 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
5775
5776 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
5777
Lalit Chandivade28deb452011-10-07 16:55:44 -07005778 ret = qla4xxx_get_bidi_chap(ha,
5779 (char *)&boot_conn->chap.intr_chap_name,
5780 (char *)&boot_conn->chap.intr_secret);
5781
Manish Rangankar2a991c22011-07-25 13:48:55 -05005782 if (ret) {
5783 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
5784 ret = QLA_ERROR;
5785 goto exit_boot_target;
5786 }
5787
5788 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
5789 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
5790 }
5791
5792exit_boot_target:
5793 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5794 fw_ddb_entry, fw_ddb_entry_dma);
5795 return ret;
5796}
5797
5798static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
5799{
5800 uint16_t ddb_index[2];
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005801 int ret = QLA_ERROR;
5802 int rval;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005803
5804 memset(ddb_index, 0, sizeof(ddb_index));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005805 ddb_index[0] = 0xffff;
5806 ddb_index[1] = 0xffff;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005807 ret = get_fw_boot_info(ha, ddb_index);
5808 if (ret != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305809 DEBUG2(ql4_printk(KERN_INFO, ha,
5810 "%s: No boot target configured.\n", __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005811 return ret;
5812 }
5813
Mike Christie13483732011-12-01 21:38:41 -06005814 if (ql4xdisablesysfsboot)
5815 return QLA_SUCCESS;
5816
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005817 if (ddb_index[0] == 0xffff)
5818 goto sec_target;
5819
5820 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05005821 ddb_index[0]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005822 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305823 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
5824 "configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005825 } else
5826 ret = QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005827
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005828sec_target:
5829 if (ddb_index[1] == 0xffff)
5830 goto exit_get_boot_info;
5831
5832 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05005833 ddb_index[1]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005834 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305835 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
5836 " configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07005837 } else
5838 ret = QLA_SUCCESS;
5839
5840exit_get_boot_info:
Manish Rangankar2a991c22011-07-25 13:48:55 -05005841 return ret;
5842}
5843
5844static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
5845{
5846 struct iscsi_boot_kobj *boot_kobj;
5847
5848 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
Mike Christie13483732011-12-01 21:38:41 -06005849 return QLA_ERROR;
5850
5851 if (ql4xdisablesysfsboot) {
5852 ql4_printk(KERN_INFO, ha,
Petr Uzel0bd7f842012-02-24 16:32:59 +01005853 "%s: syfsboot disabled - driver will trigger login "
Mike Christie13483732011-12-01 21:38:41 -06005854 "and publish session for discovery .\n", __func__);
5855 return QLA_SUCCESS;
5856 }
5857
Manish Rangankar2a991c22011-07-25 13:48:55 -05005858
5859 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
5860 if (!ha->boot_kset)
5861 goto kset_free;
5862
5863 if (!scsi_host_get(ha->host))
5864 goto kset_free;
5865 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
5866 qla4xxx_show_boot_tgt_pri_info,
5867 qla4xxx_tgt_get_attr_visibility,
5868 qla4xxx_boot_release);
5869 if (!boot_kobj)
5870 goto put_host;
5871
5872 if (!scsi_host_get(ha->host))
5873 goto kset_free;
5874 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
5875 qla4xxx_show_boot_tgt_sec_info,
5876 qla4xxx_tgt_get_attr_visibility,
5877 qla4xxx_boot_release);
5878 if (!boot_kobj)
5879 goto put_host;
5880
5881 if (!scsi_host_get(ha->host))
5882 goto kset_free;
5883 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
5884 qla4xxx_show_boot_ini_info,
5885 qla4xxx_ini_get_attr_visibility,
5886 qla4xxx_boot_release);
5887 if (!boot_kobj)
5888 goto put_host;
5889
5890 if (!scsi_host_get(ha->host))
5891 goto kset_free;
5892 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
5893 qla4xxx_show_boot_eth_info,
5894 qla4xxx_eth_get_attr_visibility,
5895 qla4xxx_boot_release);
5896 if (!boot_kobj)
5897 goto put_host;
5898
Mike Christie13483732011-12-01 21:38:41 -06005899 return QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005900
5901put_host:
5902 scsi_host_put(ha->host);
5903kset_free:
5904 iscsi_boot_destroy_kset(ha->boot_kset);
5905 return -ENOMEM;
5906}
5907
Lalit Chandivade45494152011-10-07 16:55:42 -07005908
5909/**
5910 * qla4xxx_create chap_list - Create CHAP list from FLASH
5911 * @ha: pointer to adapter structure
5912 *
5913 * Read flash and make a list of CHAP entries, during login when a CHAP entry
5914 * is received, it will be checked in this list. If entry exist then the CHAP
5915 * entry index is set in the DDB. If CHAP entry does not exist in this list
5916 * then a new entry is added in FLASH in CHAP table and the index obtained is
5917 * used in the DDB.
5918 **/
5919static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
5920{
5921 int rval = 0;
5922 uint8_t *chap_flash_data = NULL;
5923 uint32_t offset;
5924 dma_addr_t chap_dma;
5925 uint32_t chap_size = 0;
5926
5927 if (is_qla40XX(ha))
5928 chap_size = MAX_CHAP_ENTRIES_40XX *
5929 sizeof(struct ql4_chap_table);
5930 else /* Single region contains CHAP info for both
5931 * ports which is divided into half for each port.
5932 */
5933 chap_size = ha->hw.flt_chap_size / 2;
5934
5935 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
5936 &chap_dma, GFP_KERNEL);
5937 if (!chap_flash_data) {
5938 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
5939 return;
5940 }
5941 if (is_qla40XX(ha))
5942 offset = FLASH_CHAP_OFFSET;
5943 else {
5944 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
5945 if (ha->port_num == 1)
5946 offset += chap_size;
5947 }
5948
5949 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
5950 if (rval != QLA_SUCCESS)
5951 goto exit_chap_list;
5952
5953 if (ha->chap_list == NULL)
5954 ha->chap_list = vmalloc(chap_size);
5955 if (ha->chap_list == NULL) {
5956 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
5957 goto exit_chap_list;
5958 }
5959
5960 memcpy(ha->chap_list, chap_flash_data, chap_size);
5961
5962exit_chap_list:
5963 dma_free_coherent(&ha->pdev->dev, chap_size,
5964 chap_flash_data, chap_dma);
Lalit Chandivade45494152011-10-07 16:55:42 -07005965}
5966
Mike Christie13483732011-12-01 21:38:41 -06005967static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
5968 struct ql4_tuple_ddb *tddb)
5969{
5970 struct scsi_qla_host *ha;
5971 struct iscsi_cls_session *cls_sess;
5972 struct iscsi_cls_conn *cls_conn;
5973 struct iscsi_session *sess;
5974 struct iscsi_conn *conn;
5975
5976 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
5977 ha = ddb_entry->ha;
5978 cls_sess = ddb_entry->sess;
5979 sess = cls_sess->dd_data;
5980 cls_conn = ddb_entry->conn;
5981 conn = cls_conn->dd_data;
5982
5983 tddb->tpgt = sess->tpgt;
5984 tddb->port = conn->persistent_port;
5985 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
5986 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
5987}
5988
5989static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04005990 struct ql4_tuple_ddb *tddb,
5991 uint8_t *flash_isid)
Mike Christie13483732011-12-01 21:38:41 -06005992{
5993 uint16_t options = 0;
5994
5995 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
5996 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
5997 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
5998
5999 options = le16_to_cpu(fw_ddb_entry->options);
6000 if (options & DDB_OPT_IPV6_DEVICE)
6001 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6002 else
6003 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6004
6005 tddb->port = le16_to_cpu(fw_ddb_entry->port);
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006006
6007 if (flash_isid == NULL)
6008 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6009 sizeof(tddb->isid));
6010 else
6011 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
Mike Christie13483732011-12-01 21:38:41 -06006012}
6013
6014static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6015 struct ql4_tuple_ddb *old_tddb,
Manish Rangankar173269e2012-02-27 03:08:55 -08006016 struct ql4_tuple_ddb *new_tddb,
6017 uint8_t is_isid_compare)
Mike Christie13483732011-12-01 21:38:41 -06006018{
6019 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6020 return QLA_ERROR;
6021
6022 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6023 return QLA_ERROR;
6024
6025 if (old_tddb->port != new_tddb->port)
6026 return QLA_ERROR;
6027
Manish Rangankar173269e2012-02-27 03:08:55 -08006028 /* For multi sessions, driver generates the ISID, so do not compare
Masanari Iida59e13d42012-04-25 00:24:16 +09006029 * ISID in reset path since it would be a comparison between the
Manish Rangankar173269e2012-02-27 03:08:55 -08006030 * driver generated ISID and firmware generated ISID. This could
6031 * lead to adding duplicated DDBs in the list as driver generated
6032 * ISID would not match firmware generated ISID.
6033 */
6034 if (is_isid_compare) {
6035 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
6036 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
6037 __func__, old_tddb->isid[5], old_tddb->isid[4],
6038 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
6039 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
6040 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
6041 new_tddb->isid[0]));
6042
6043 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6044 sizeof(old_tddb->isid)))
6045 return QLA_ERROR;
6046 }
6047
Mike Christie13483732011-12-01 21:38:41 -06006048 DEBUG2(ql4_printk(KERN_INFO, ha,
6049 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6050 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6051 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6052 new_tddb->ip_addr, new_tddb->iscsi_name));
6053
6054 return QLA_SUCCESS;
6055}
6056
6057static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006058 struct dev_db_entry *fw_ddb_entry,
6059 uint32_t *index)
Mike Christie13483732011-12-01 21:38:41 -06006060{
6061 struct ddb_entry *ddb_entry;
6062 struct ql4_tuple_ddb *fw_tddb = NULL;
6063 struct ql4_tuple_ddb *tmp_tddb = NULL;
6064 int idx;
6065 int ret = QLA_ERROR;
6066
6067 fw_tddb = vzalloc(sizeof(*fw_tddb));
6068 if (!fw_tddb) {
6069 DEBUG2(ql4_printk(KERN_WARNING, ha,
6070 "Memory Allocation failed.\n"));
6071 ret = QLA_SUCCESS;
6072 goto exit_check;
6073 }
6074
6075 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6076 if (!tmp_tddb) {
6077 DEBUG2(ql4_printk(KERN_WARNING, ha,
6078 "Memory Allocation failed.\n"));
6079 ret = QLA_SUCCESS;
6080 goto exit_check;
6081 }
6082
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006083 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006084
6085 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6086 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6087 if (ddb_entry == NULL)
6088 continue;
6089
6090 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
Manish Rangankar173269e2012-02-27 03:08:55 -08006091 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
Mike Christie13483732011-12-01 21:38:41 -06006092 ret = QLA_SUCCESS; /* found */
Manish Rangankarad8bd452013-09-17 07:30:02 -04006093 if (index != NULL)
6094 *index = idx;
Mike Christie13483732011-12-01 21:38:41 -06006095 goto exit_check;
6096 }
6097 }
6098
6099exit_check:
6100 if (fw_tddb)
6101 vfree(fw_tddb);
6102 if (tmp_tddb)
6103 vfree(tmp_tddb);
6104 return ret;
6105}
6106
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006107/**
6108 * qla4xxx_check_existing_isid - check if target with same isid exist
6109 * in target list
6110 * @list_nt: list of target
6111 * @isid: isid to check
6112 *
6113 * This routine return QLA_SUCCESS if target with same isid exist
6114 **/
6115static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6116{
6117 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6118 struct dev_db_entry *fw_ddb_entry;
6119
6120 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6121 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6122
6123 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6124 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6125 return QLA_SUCCESS;
6126 }
6127 }
6128 return QLA_ERROR;
6129}
6130
6131/**
6132 * qla4xxx_update_isid - compare ddbs and updated isid
6133 * @ha: Pointer to host adapter structure.
6134 * @list_nt: list of nt target
6135 * @fw_ddb_entry: firmware ddb entry
6136 *
6137 * This routine update isid if ddbs have same iqn, same isid and
6138 * different IP addr.
6139 * Return QLA_SUCCESS if isid is updated.
6140 **/
6141static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6142 struct list_head *list_nt,
6143 struct dev_db_entry *fw_ddb_entry)
6144{
6145 uint8_t base_value, i;
6146
6147 base_value = fw_ddb_entry->isid[1] & 0x1f;
6148 for (i = 0; i < 8; i++) {
6149 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6150 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6151 break;
6152 }
6153
6154 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6155 return QLA_ERROR;
6156
6157 return QLA_SUCCESS;
6158}
6159
6160/**
6161 * qla4xxx_should_update_isid - check if isid need to update
6162 * @ha: Pointer to host adapter structure.
6163 * @old_tddb: ddb tuple
6164 * @new_tddb: ddb tuple
6165 *
6166 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6167 * same isid
6168 **/
6169static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6170 struct ql4_tuple_ddb *old_tddb,
6171 struct ql4_tuple_ddb *new_tddb)
6172{
6173 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6174 /* Same ip */
6175 if (old_tddb->port == new_tddb->port)
6176 return QLA_ERROR;
6177 }
6178
6179 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6180 /* different iqn */
6181 return QLA_ERROR;
6182
6183 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6184 sizeof(old_tddb->isid)))
6185 /* different isid */
6186 return QLA_ERROR;
6187
6188 return QLA_SUCCESS;
6189}
6190
6191/**
6192 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6193 * @ha: Pointer to host adapter structure.
6194 * @list_nt: list of nt target.
6195 * @fw_ddb_entry: firmware ddb entry.
6196 *
6197 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6198 * duplicate ddb in list_nt.
6199 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6200 * Note: This function also update isid of DDB if required.
6201 **/
6202
Mike Christie13483732011-12-01 21:38:41 -06006203static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6204 struct list_head *list_nt,
6205 struct dev_db_entry *fw_ddb_entry)
6206{
6207 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6208 struct ql4_tuple_ddb *fw_tddb = NULL;
6209 struct ql4_tuple_ddb *tmp_tddb = NULL;
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006210 int rval, ret = QLA_ERROR;
Mike Christie13483732011-12-01 21:38:41 -06006211
6212 fw_tddb = vzalloc(sizeof(*fw_tddb));
6213 if (!fw_tddb) {
6214 DEBUG2(ql4_printk(KERN_WARNING, ha,
6215 "Memory Allocation failed.\n"));
6216 ret = QLA_SUCCESS;
6217 goto exit_check;
6218 }
6219
6220 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6221 if (!tmp_tddb) {
6222 DEBUG2(ql4_printk(KERN_WARNING, ha,
6223 "Memory Allocation failed.\n"));
6224 ret = QLA_SUCCESS;
6225 goto exit_check;
6226 }
6227
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006228 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006229
6230 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006231 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6232 nt_ddb_idx->flash_isid);
6233 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6234 /* found duplicate ddb */
6235 if (ret == QLA_SUCCESS)
6236 goto exit_check;
6237 }
6238
6239 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6240 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6241
6242 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6243 if (ret == QLA_SUCCESS) {
6244 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6245 if (rval == QLA_SUCCESS)
6246 ret = QLA_ERROR;
6247 else
6248 ret = QLA_SUCCESS;
6249
Mike Christie13483732011-12-01 21:38:41 -06006250 goto exit_check;
6251 }
6252 }
6253
6254exit_check:
6255 if (fw_tddb)
6256 vfree(fw_tddb);
6257 if (tmp_tddb)
6258 vfree(tmp_tddb);
6259 return ret;
6260}
6261
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006262static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
Mike Christie13483732011-12-01 21:38:41 -06006263{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006264 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
Mike Christie13483732011-12-01 21:38:41 -06006265
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006266 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6267 list_del_init(&ddb_idx->list);
6268 vfree(ddb_idx);
Mike Christie13483732011-12-01 21:38:41 -06006269 }
Mike Christie13483732011-12-01 21:38:41 -06006270}
6271
6272static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6273 struct dev_db_entry *fw_ddb_entry)
6274{
6275 struct iscsi_endpoint *ep;
6276 struct sockaddr_in *addr;
6277 struct sockaddr_in6 *addr6;
Manish Rangankar3dd48492012-11-23 06:58:40 -05006278 struct sockaddr *t_addr;
6279 struct sockaddr_storage *dst_addr;
Mike Christie13483732011-12-01 21:38:41 -06006280 char *ip;
6281
6282 /* TODO: need to destroy on unload iscsi_endpoint*/
6283 dst_addr = vmalloc(sizeof(*dst_addr));
6284 if (!dst_addr)
6285 return NULL;
6286
6287 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006288 t_addr = (struct sockaddr *)dst_addr;
6289 t_addr->sa_family = AF_INET6;
Mike Christie13483732011-12-01 21:38:41 -06006290 addr6 = (struct sockaddr_in6 *)dst_addr;
6291 ip = (char *)&addr6->sin6_addr;
6292 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6293 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6294
6295 } else {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006296 t_addr = (struct sockaddr *)dst_addr;
6297 t_addr->sa_family = AF_INET;
Mike Christie13483732011-12-01 21:38:41 -06006298 addr = (struct sockaddr_in *)dst_addr;
6299 ip = (char *)&addr->sin_addr;
6300 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6301 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6302 }
6303
Manish Rangankar3dd48492012-11-23 06:58:40 -05006304 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
Mike Christie13483732011-12-01 21:38:41 -06006305 vfree(dst_addr);
6306 return ep;
6307}
6308
6309static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6310{
6311 if (ql4xdisablesysfsboot)
6312 return QLA_SUCCESS;
6313 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6314 return QLA_ERROR;
6315 return QLA_SUCCESS;
6316}
6317
6318static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006319 struct ddb_entry *ddb_entry,
6320 uint16_t idx)
Mike Christie13483732011-12-01 21:38:41 -06006321{
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006322 uint16_t def_timeout;
6323
Mike Christie13483732011-12-01 21:38:41 -06006324 ddb_entry->ddb_type = FLASH_DDB;
6325 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6326 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6327 ddb_entry->ha = ha;
6328 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6329 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04006330 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
Mike Christie13483732011-12-01 21:38:41 -06006331
6332 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6333 atomic_set(&ddb_entry->relogin_timer, 0);
6334 atomic_set(&ddb_entry->relogin_retry_count, 0);
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006335 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06006336 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006337 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6338 def_timeout : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06006339 ddb_entry->default_time2wait =
6340 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006341
6342 if (ql4xdisablesysfsboot &&
6343 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6344 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
Mike Christie13483732011-12-01 21:38:41 -06006345}
6346
6347static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6348{
6349 uint32_t idx = 0;
6350 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6351 uint32_t sts[MBOX_REG_COUNT];
6352 uint32_t ip_state;
6353 unsigned long wtime;
6354 int ret;
6355
6356 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6357 do {
6358 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6359 if (ip_idx[idx] == -1)
6360 continue;
6361
6362 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6363
6364 if (ret == QLA_ERROR) {
6365 ip_idx[idx] = -1;
6366 continue;
6367 }
6368
6369 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6370
6371 DEBUG2(ql4_printk(KERN_INFO, ha,
6372 "Waiting for IP state for idx = %d, state = 0x%x\n",
6373 ip_idx[idx], ip_state));
6374 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6375 ip_state == IP_ADDRSTATE_INVALID ||
6376 ip_state == IP_ADDRSTATE_PREFERRED ||
6377 ip_state == IP_ADDRSTATE_DEPRICATED ||
6378 ip_state == IP_ADDRSTATE_DISABLING)
6379 ip_idx[idx] = -1;
Mike Christie13483732011-12-01 21:38:41 -06006380 }
6381
6382 /* Break if all IP states checked */
6383 if ((ip_idx[0] == -1) &&
6384 (ip_idx[1] == -1) &&
6385 (ip_idx[2] == -1) &&
6386 (ip_idx[3] == -1))
6387 break;
6388 schedule_timeout_uninterruptible(HZ);
6389 } while (time_after(wtime, jiffies));
6390}
6391
Manish Rangankarad8bd452013-09-17 07:30:02 -04006392static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6393 struct dev_db_entry *flash_ddb_entry)
6394{
6395 uint16_t options = 0;
6396 size_t ip_len = IP_ADDR_LEN;
6397
6398 options = le16_to_cpu(fw_ddb_entry->options);
6399 if (options & DDB_OPT_IPV6_DEVICE)
6400 ip_len = IPv6_ADDR_LEN;
6401
6402 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6403 return QLA_ERROR;
6404
6405 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6406 sizeof(fw_ddb_entry->isid)))
6407 return QLA_ERROR;
6408
6409 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6410 sizeof(fw_ddb_entry->port)))
6411 return QLA_ERROR;
6412
6413 return QLA_SUCCESS;
6414}
6415
6416static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6417 struct dev_db_entry *fw_ddb_entry,
6418 uint32_t fw_idx, uint32_t *flash_index)
6419{
6420 struct dev_db_entry *flash_ddb_entry;
6421 dma_addr_t flash_ddb_entry_dma;
6422 uint32_t idx = 0;
6423 int max_ddbs;
6424 int ret = QLA_ERROR, status;
6425
6426 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6427 MAX_DEV_DB_ENTRIES;
6428
6429 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6430 &flash_ddb_entry_dma);
6431 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6432 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6433 goto exit_find_st_idx;
6434 }
6435
6436 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6437 flash_ddb_entry_dma, fw_idx);
6438 if (status == QLA_SUCCESS) {
6439 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6440 if (status == QLA_SUCCESS) {
6441 *flash_index = fw_idx;
6442 ret = QLA_SUCCESS;
6443 goto exit_find_st_idx;
6444 }
6445 }
6446
6447 for (idx = 0; idx < max_ddbs; idx++) {
6448 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6449 flash_ddb_entry_dma, idx);
6450 if (status == QLA_ERROR)
6451 continue;
6452
6453 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6454 if (status == QLA_SUCCESS) {
6455 *flash_index = idx;
6456 ret = QLA_SUCCESS;
6457 goto exit_find_st_idx;
6458 }
6459 }
6460
6461 if (idx == max_ddbs)
6462 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6463 fw_idx);
6464
6465exit_find_st_idx:
6466 if (flash_ddb_entry)
6467 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6468 flash_ddb_entry_dma);
6469
6470 return ret;
6471}
6472
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006473static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6474 struct list_head *list_st)
Mike Christie13483732011-12-01 21:38:41 -06006475{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006476 struct qla_ddb_index *st_ddb_idx;
Mike Christie13483732011-12-01 21:38:41 -06006477 int max_ddbs;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006478 int fw_idx_size;
6479 struct dev_db_entry *fw_ddb_entry;
6480 dma_addr_t fw_ddb_dma;
Mike Christie13483732011-12-01 21:38:41 -06006481 int ret;
6482 uint32_t idx = 0, next_idx = 0;
6483 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006484 uint32_t flash_index = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006485 uint16_t conn_id = 0;
Mike Christie13483732011-12-01 21:38:41 -06006486
6487 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6488 &fw_ddb_dma);
6489 if (fw_ddb_entry == NULL) {
6490 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006491 goto exit_st_list;
Mike Christie13483732011-12-01 21:38:41 -06006492 }
6493
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006494 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6495 MAX_DEV_DB_ENTRIES;
Mike Christie13483732011-12-01 21:38:41 -06006496 fw_idx_size = sizeof(struct qla_ddb_index);
6497
6498 for (idx = 0; idx < max_ddbs; idx = next_idx) {
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006499 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6500 NULL, &next_idx, &state,
6501 &conn_err, NULL, &conn_id);
Mike Christie13483732011-12-01 21:38:41 -06006502 if (ret == QLA_ERROR)
6503 break;
6504
Lalit Chandivade981c9822012-02-13 18:30:41 +05306505 /* Ignore DDB if invalid state (unassigned) */
6506 if (state == DDB_DS_UNASSIGNED)
6507 goto continue_next_st;
6508
Mike Christie13483732011-12-01 21:38:41 -06006509 /* Check if ST, add to the list_st */
6510 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6511 goto continue_next_st;
6512
6513 st_ddb_idx = vzalloc(fw_idx_size);
6514 if (!st_ddb_idx)
6515 break;
6516
Manish Rangankarad8bd452013-09-17 07:30:02 -04006517 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6518 &flash_index);
6519 if (ret == QLA_ERROR) {
6520 ql4_printk(KERN_ERR, ha,
6521 "No flash entry for ST at idx [%d]\n", idx);
6522 st_ddb_idx->flash_ddb_idx = idx;
6523 } else {
6524 ql4_printk(KERN_INFO, ha,
6525 "ST at idx [%d] is stored at flash [%d]\n",
6526 idx, flash_index);
6527 st_ddb_idx->flash_ddb_idx = flash_index;
6528 }
6529
Mike Christie13483732011-12-01 21:38:41 -06006530 st_ddb_idx->fw_ddb_idx = idx;
6531
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006532 list_add_tail(&st_ddb_idx->list, list_st);
Mike Christie13483732011-12-01 21:38:41 -06006533continue_next_st:
6534 if (next_idx == 0)
6535 break;
6536 }
6537
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006538exit_st_list:
6539 if (fw_ddb_entry)
6540 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6541}
6542
6543/**
6544 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6545 * @ha: pointer to adapter structure
6546 * @list_ddb: List from which failed ddb to be removed
6547 *
6548 * Iterate over the list of DDBs and find and remove DDBs that are either in
6549 * no connection active state or failed state
6550 **/
6551static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6552 struct list_head *list_ddb)
6553{
6554 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6555 uint32_t next_idx = 0;
6556 uint32_t state = 0, conn_err = 0;
6557 int ret;
6558
6559 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6560 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6561 NULL, 0, NULL, &next_idx, &state,
6562 &conn_err, NULL, NULL);
6563 if (ret == QLA_ERROR)
6564 continue;
6565
6566 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6567 state == DDB_DS_SESSION_FAILED) {
6568 list_del_init(&ddb_idx->list);
6569 vfree(ddb_idx);
6570 }
6571 }
6572}
6573
Manish Rangankarad8bd452013-09-17 07:30:02 -04006574static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6575 struct ddb_entry *ddb_entry,
6576 struct dev_db_entry *fw_ddb_entry)
6577{
6578 struct iscsi_cls_session *cls_sess;
6579 struct iscsi_session *sess;
6580 uint32_t max_ddbs = 0;
6581 uint16_t ddb_link = -1;
6582
6583 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6584 MAX_DEV_DB_ENTRIES;
6585
6586 cls_sess = ddb_entry->sess;
6587 sess = cls_sess->dd_data;
6588
6589 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6590 if (ddb_link < max_ddbs)
6591 sess->discovery_parent_idx = ddb_link;
6592 else
6593 sess->discovery_parent_idx = DDB_NO_LINK;
6594}
6595
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006596static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6597 struct dev_db_entry *fw_ddb_entry,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006598 int is_reset, uint16_t idx)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006599{
6600 struct iscsi_cls_session *cls_sess;
6601 struct iscsi_session *sess;
6602 struct iscsi_cls_conn *cls_conn;
6603 struct iscsi_endpoint *ep;
6604 uint16_t cmds_max = 32;
6605 uint16_t conn_id = 0;
6606 uint32_t initial_cmdsn = 0;
6607 int ret = QLA_SUCCESS;
6608
6609 struct ddb_entry *ddb_entry = NULL;
6610
6611 /* Create session object, with INVALID_ENTRY,
6612 * the targer_id would get set when we issue the login
6613 */
6614 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6615 cmds_max, sizeof(struct ddb_entry),
6616 sizeof(struct ql4_task_data),
6617 initial_cmdsn, INVALID_ENTRY);
6618 if (!cls_sess) {
6619 ret = QLA_ERROR;
6620 goto exit_setup;
6621 }
6622
6623 /*
6624 * so calling module_put function to decrement the
6625 * reference count.
6626 **/
6627 module_put(qla4xxx_iscsi_transport.owner);
6628 sess = cls_sess->dd_data;
6629 ddb_entry = sess->dd_data;
6630 ddb_entry->sess = cls_sess;
6631
6632 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6633 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6634 sizeof(struct dev_db_entry));
6635
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006636 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006637
6638 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6639
6640 if (!cls_conn) {
6641 ret = QLA_ERROR;
6642 goto exit_setup;
6643 }
6644
6645 ddb_entry->conn = cls_conn;
6646
6647 /* Setup ep, for displaying attributes in sysfs */
6648 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6649 if (ep) {
6650 ep->conn = cls_conn;
6651 cls_conn->ep = ep;
6652 } else {
6653 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6654 ret = QLA_ERROR;
6655 goto exit_setup;
6656 }
6657
6658 /* Update sess/conn params */
6659 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
Manish Rangankarad8bd452013-09-17 07:30:02 -04006660 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006661
6662 if (is_reset == RESET_ADAPTER) {
6663 iscsi_block_session(cls_sess);
6664 /* Use the relogin path to discover new devices
6665 * by short-circuting the logic of setting
6666 * timer to relogin - instead set the flags
6667 * to initiate login right away.
6668 */
6669 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6670 set_bit(DF_RELOGIN, &ddb_entry->flags);
6671 }
6672
6673exit_setup:
6674 return ret;
6675}
6676
Manish Rangankarad8bd452013-09-17 07:30:02 -04006677static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6678 struct list_head *list_ddb,
6679 struct dev_db_entry *fw_ddb_entry)
6680{
6681 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6682 uint16_t ddb_link;
6683
6684 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6685
6686 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6687 if (ddb_idx->fw_ddb_idx == ddb_link) {
6688 DEBUG2(ql4_printk(KERN_INFO, ha,
6689 "Updating NT parent idx from [%d] to [%d]\n",
6690 ddb_link, ddb_idx->flash_ddb_idx));
6691 fw_ddb_entry->ddb_link =
6692 cpu_to_le16(ddb_idx->flash_ddb_idx);
6693 return;
6694 }
6695 }
6696}
6697
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006698static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006699 struct list_head *list_nt,
6700 struct list_head *list_st,
6701 int is_reset)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006702{
6703 struct dev_db_entry *fw_ddb_entry;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006704 struct ddb_entry *ddb_entry = NULL;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006705 dma_addr_t fw_ddb_dma;
6706 int max_ddbs;
6707 int fw_idx_size;
6708 int ret;
6709 uint32_t idx = 0, next_idx = 0;
6710 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006711 uint32_t ddb_idx = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006712 uint16_t conn_id = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006713 uint16_t ddb_link = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006714 struct qla_ddb_index *nt_ddb_idx;
6715
6716 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6717 &fw_ddb_dma);
6718 if (fw_ddb_entry == NULL) {
6719 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6720 goto exit_nt_list;
6721 }
6722 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6723 MAX_DEV_DB_ENTRIES;
6724 fw_idx_size = sizeof(struct qla_ddb_index);
6725
6726 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6727 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6728 NULL, &next_idx, &state,
6729 &conn_err, NULL, &conn_id);
6730 if (ret == QLA_ERROR)
6731 break;
6732
6733 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
6734 goto continue_next_nt;
6735
6736 /* Check if NT, then add to list it */
6737 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
6738 goto continue_next_nt;
6739
Manish Rangankarad8bd452013-09-17 07:30:02 -04006740 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6741 if (ddb_link < max_ddbs)
6742 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
6743
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006744 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
Manish Rangankarad8bd452013-09-17 07:30:02 -04006745 state == DDB_DS_SESSION_FAILED) &&
6746 (is_reset == INIT_ADAPTER))
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006747 goto continue_next_nt;
6748
6749 DEBUG2(ql4_printk(KERN_INFO, ha,
6750 "Adding DDB to session = 0x%x\n", idx));
Manish Rangankarad8bd452013-09-17 07:30:02 -04006751
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006752 if (is_reset == INIT_ADAPTER) {
6753 nt_ddb_idx = vmalloc(fw_idx_size);
6754 if (!nt_ddb_idx)
6755 break;
6756
6757 nt_ddb_idx->fw_ddb_idx = idx;
6758
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006759 /* Copy original isid as it may get updated in function
6760 * qla4xxx_update_isid(). We need original isid in
6761 * function qla4xxx_compare_tuple_ddb to find duplicate
6762 * target */
6763 memcpy(&nt_ddb_idx->flash_isid[0],
6764 &fw_ddb_entry->isid[0],
6765 sizeof(nt_ddb_idx->flash_isid));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006766
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006767 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
6768 fw_ddb_entry);
6769 if (ret == QLA_SUCCESS) {
6770 /* free nt_ddb_idx and do not add to list_nt */
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006771 vfree(nt_ddb_idx);
6772 goto continue_next_nt;
6773 }
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006774
6775 /* Copy updated isid */
6776 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
6777 sizeof(struct dev_db_entry));
6778
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006779 list_add_tail(&nt_ddb_idx->list, list_nt);
6780 } else if (is_reset == RESET_ADAPTER) {
Manish Rangankarad8bd452013-09-17 07:30:02 -04006781 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
6782 &ddb_idx);
6783 if (ret == QLA_SUCCESS) {
6784 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
6785 ddb_idx);
6786 if (ddb_entry != NULL)
6787 qla4xxx_update_sess_disc_idx(ha,
6788 ddb_entry,
6789 fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006790 goto continue_next_nt;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006791 }
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006792 }
6793
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006794 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006795 if (ret == QLA_ERROR)
6796 goto exit_nt_list;
6797
6798continue_next_nt:
6799 if (next_idx == 0)
6800 break;
6801 }
6802
6803exit_nt_list:
6804 if (fw_ddb_entry)
6805 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6806}
6807
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04006808static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006809 struct list_head *list_nt,
6810 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04006811{
6812 struct dev_db_entry *fw_ddb_entry;
6813 dma_addr_t fw_ddb_dma;
6814 int max_ddbs;
6815 int fw_idx_size;
6816 int ret;
6817 uint32_t idx = 0, next_idx = 0;
6818 uint32_t state = 0, conn_err = 0;
6819 uint16_t conn_id = 0;
6820 struct qla_ddb_index *nt_ddb_idx;
6821
6822 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6823 &fw_ddb_dma);
6824 if (fw_ddb_entry == NULL) {
6825 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6826 goto exit_new_nt_list;
6827 }
6828 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6829 MAX_DEV_DB_ENTRIES;
6830 fw_idx_size = sizeof(struct qla_ddb_index);
6831
6832 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6833 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6834 NULL, &next_idx, &state,
6835 &conn_err, NULL, &conn_id);
6836 if (ret == QLA_ERROR)
6837 break;
6838
6839 /* Check if NT, then add it to list */
6840 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
6841 goto continue_next_new_nt;
6842
6843 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
6844 goto continue_next_new_nt;
6845
6846 DEBUG2(ql4_printk(KERN_INFO, ha,
6847 "Adding DDB to session = 0x%x\n", idx));
6848
6849 nt_ddb_idx = vmalloc(fw_idx_size);
6850 if (!nt_ddb_idx)
6851 break;
6852
6853 nt_ddb_idx->fw_ddb_idx = idx;
6854
Manish Rangankarad8bd452013-09-17 07:30:02 -04006855 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04006856 if (ret == QLA_SUCCESS) {
6857 /* free nt_ddb_idx and do not add to list_nt */
6858 vfree(nt_ddb_idx);
6859 goto continue_next_new_nt;
6860 }
6861
Manish Rangankarad8bd452013-09-17 07:30:02 -04006862 if (target_id < max_ddbs)
6863 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
6864
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04006865 list_add_tail(&nt_ddb_idx->list, list_nt);
6866
6867 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
6868 idx);
6869 if (ret == QLA_ERROR)
6870 goto exit_new_nt_list;
6871
6872continue_next_new_nt:
6873 if (next_idx == 0)
6874 break;
6875 }
6876
6877exit_new_nt_list:
6878 if (fw_ddb_entry)
6879 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6880}
6881
6882/**
6883 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
6884 * @dev: dev associated with the sysfs entry
6885 * @data: pointer to flashnode session object
6886 *
6887 * Returns:
6888 * 1: if flashnode entry is non-persistent
6889 * 0: if flashnode entry is persistent
6890 **/
6891static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
6892{
6893 struct iscsi_bus_flash_session *fnode_sess;
6894
6895 if (!iscsi_flashnode_bus_match(dev, NULL))
6896 return 0;
6897
6898 fnode_sess = iscsi_dev_to_flash_session(dev);
6899
6900 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
6901}
6902
6903/**
6904 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
6905 * @ha: pointer to host
6906 * @fw_ddb_entry: flash ddb data
6907 * @idx: target index
6908 * @user: if set then this call is made from userland else from kernel
6909 *
6910 * Returns:
6911 * On sucess: QLA_SUCCESS
6912 * On failure: QLA_ERROR
6913 *
6914 * This create separate sysfs entries for session and connection attributes of
6915 * the given fw ddb entry.
6916 * If this is invoked as a result of a userspace call then the entry is marked
6917 * as nonpersistent using flash_state field.
6918 **/
Vikas Chaudhary28e02f12013-04-17 05:15:27 -04006919static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
6920 struct dev_db_entry *fw_ddb_entry,
6921 uint16_t *idx, int user)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04006922{
6923 struct iscsi_bus_flash_session *fnode_sess = NULL;
6924 struct iscsi_bus_flash_conn *fnode_conn = NULL;
6925 int rc = QLA_ERROR;
6926
6927 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
6928 &qla4xxx_iscsi_transport, 0);
6929 if (!fnode_sess) {
6930 ql4_printk(KERN_ERR, ha,
6931 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
6932 __func__, *idx, ha->host_no);
6933 goto exit_tgt_create;
6934 }
6935
6936 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
6937 &qla4xxx_iscsi_transport, 0);
6938 if (!fnode_conn) {
6939 ql4_printk(KERN_ERR, ha,
6940 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
6941 __func__, *idx, ha->host_no);
6942 goto free_sess;
6943 }
6944
6945 if (user) {
6946 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
6947 } else {
6948 fnode_sess->flash_state = DEV_DB_PERSISTENT;
6949
6950 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
6951 fnode_sess->is_boot_target = 1;
6952 else
6953 fnode_sess->is_boot_target = 0;
6954 }
6955
6956 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
6957 fw_ddb_entry);
6958
6959 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
6960 __func__, fnode_sess->dev.kobj.name);
6961
6962 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
6963 __func__, fnode_conn->dev.kobj.name);
6964
6965 return QLA_SUCCESS;
6966
6967free_sess:
6968 iscsi_destroy_flashnode_sess(fnode_sess);
6969
6970exit_tgt_create:
6971 return QLA_ERROR;
6972}
6973
6974/**
6975 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
6976 * @shost: pointer to host
6977 * @buf: type of ddb entry (ipv4/ipv6)
6978 * @len: length of buf
6979 *
6980 * This creates new ddb entry in the flash by finding first free index and
6981 * storing default ddb there. And then create sysfs entry for the new ddb entry.
6982 **/
6983static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
6984 int len)
6985{
6986 struct scsi_qla_host *ha = to_qla_host(shost);
6987 struct dev_db_entry *fw_ddb_entry = NULL;
6988 dma_addr_t fw_ddb_entry_dma;
6989 struct device *dev;
6990 uint16_t idx = 0;
6991 uint16_t max_ddbs = 0;
6992 uint32_t options = 0;
6993 uint32_t rval = QLA_ERROR;
6994
Adheer Chandravanshic962c182013-03-25 08:08:32 -04006995 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
6996 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04006997 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
6998 __func__));
6999 goto exit_ddb_add;
7000 }
7001
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04007002 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007003 MAX_DEV_DB_ENTRIES;
7004
7005 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7006 &fw_ddb_entry_dma, GFP_KERNEL);
7007 if (!fw_ddb_entry) {
7008 DEBUG2(ql4_printk(KERN_ERR, ha,
7009 "%s: Unable to allocate dma buffer\n",
7010 __func__));
7011 goto exit_ddb_add;
7012 }
7013
7014 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7015 qla4xxx_sysfs_ddb_is_non_persistent);
7016 if (dev) {
7017 ql4_printk(KERN_ERR, ha,
7018 "%s: A non-persistent entry %s found\n",
7019 __func__, dev->kobj.name);
Mike Christie8526cb12013-05-06 12:06:56 -05007020 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007021 goto exit_ddb_add;
7022 }
7023
Adheer Chandravanshi99937572013-07-08 08:33:09 -04007024 /* Index 0 and 1 are reserved for boot target entries */
7025 for (idx = 2; idx < max_ddbs; idx++) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007026 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7027 fw_ddb_entry_dma, idx))
7028 break;
7029 }
7030
7031 if (idx == max_ddbs)
7032 goto exit_ddb_add;
7033
7034 if (!strncasecmp("ipv6", buf, 4))
7035 options |= IPV6_DEFAULT_DDB_ENTRY;
7036
7037 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7038 if (rval == QLA_ERROR)
7039 goto exit_ddb_add;
7040
7041 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7042
7043exit_ddb_add:
7044 if (fw_ddb_entry)
7045 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7046 fw_ddb_entry, fw_ddb_entry_dma);
7047 if (rval == QLA_SUCCESS)
7048 return idx;
7049 else
7050 return -EIO;
7051}
7052
7053/**
7054 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7055 * @fnode_sess: pointer to session attrs of flash ddb entry
7056 * @fnode_conn: pointer to connection attrs of flash ddb entry
7057 *
7058 * This writes the contents of target ddb buffer to Flash with a valid cookie
7059 * value in order to make the ddb entry persistent.
7060 **/
7061static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7062 struct iscsi_bus_flash_conn *fnode_conn)
7063{
7064 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7065 struct scsi_qla_host *ha = to_qla_host(shost);
7066 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7067 struct dev_db_entry *fw_ddb_entry = NULL;
7068 dma_addr_t fw_ddb_entry_dma;
7069 uint32_t options = 0;
7070 int rval = 0;
7071
7072 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7073 &fw_ddb_entry_dma, GFP_KERNEL);
7074 if (!fw_ddb_entry) {
7075 DEBUG2(ql4_printk(KERN_ERR, ha,
7076 "%s: Unable to allocate dma buffer\n",
7077 __func__));
7078 rval = -ENOMEM;
7079 goto exit_ddb_apply;
7080 }
7081
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007082 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007083 options |= IPV6_DEFAULT_DDB_ENTRY;
7084
7085 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7086 if (rval == QLA_ERROR)
7087 goto exit_ddb_apply;
7088
7089 dev_db_start_offset += (fnode_sess->target_id *
7090 sizeof(*fw_ddb_entry));
7091
7092 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7093 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7094
7095 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7096 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7097
7098 if (rval == QLA_SUCCESS) {
7099 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7100 ql4_printk(KERN_INFO, ha,
7101 "%s: flash node %u of host %lu written to flash\n",
7102 __func__, fnode_sess->target_id, ha->host_no);
7103 } else {
7104 rval = -EIO;
7105 ql4_printk(KERN_ERR, ha,
7106 "%s: Error while writing flash node %u of host %lu to flash\n",
7107 __func__, fnode_sess->target_id, ha->host_no);
7108 }
7109
7110exit_ddb_apply:
7111 if (fw_ddb_entry)
7112 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7113 fw_ddb_entry, fw_ddb_entry_dma);
7114 return rval;
7115}
7116
7117static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7118 struct dev_db_entry *fw_ddb_entry,
7119 uint16_t idx)
7120{
7121 struct dev_db_entry *ddb_entry = NULL;
7122 dma_addr_t ddb_entry_dma;
7123 unsigned long wtime;
7124 uint32_t mbx_sts = 0;
7125 uint32_t state = 0, conn_err = 0;
7126 uint16_t tmo = 0;
7127 int ret = 0;
7128
7129 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7130 &ddb_entry_dma, GFP_KERNEL);
7131 if (!ddb_entry) {
7132 DEBUG2(ql4_printk(KERN_ERR, ha,
7133 "%s: Unable to allocate dma buffer\n",
7134 __func__));
7135 return QLA_ERROR;
7136 }
7137
7138 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7139
7140 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7141 if (ret != QLA_SUCCESS) {
7142 DEBUG2(ql4_printk(KERN_ERR, ha,
7143 "%s: Unable to set ddb entry for index %d\n",
7144 __func__, idx));
7145 goto exit_ddb_conn_open;
7146 }
7147
7148 qla4xxx_conn_open(ha, idx);
7149
7150 /* To ensure that sendtargets is done, wait for at least 12 secs */
7151 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7152 (ha->def_timeout < LOGIN_TOV * 10) ?
7153 ha->def_timeout : LOGIN_TOV);
7154
7155 DEBUG2(ql4_printk(KERN_INFO, ha,
7156 "Default time to wait for login to ddb %d\n", tmo));
7157
7158 wtime = jiffies + (HZ * tmo);
7159 do {
7160 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7161 NULL, &state, &conn_err, NULL,
7162 NULL);
7163 if (ret == QLA_ERROR)
7164 continue;
7165
7166 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7167 state == DDB_DS_SESSION_FAILED)
7168 break;
7169
7170 schedule_timeout_uninterruptible(HZ / 10);
7171 } while (time_after(wtime, jiffies));
7172
7173exit_ddb_conn_open:
7174 if (ddb_entry)
7175 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7176 ddb_entry, ddb_entry_dma);
7177 return ret;
7178}
7179
7180static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007181 struct dev_db_entry *fw_ddb_entry,
7182 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007183{
7184 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7185 struct list_head list_nt;
7186 uint16_t ddb_index;
7187 int ret = 0;
7188
7189 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7190 ql4_printk(KERN_WARNING, ha,
7191 "%s: A discovery already in progress!\n", __func__);
7192 return QLA_ERROR;
7193 }
7194
7195 INIT_LIST_HEAD(&list_nt);
7196
7197 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7198
7199 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7200 if (ret == QLA_ERROR)
7201 goto exit_login_st_clr_bit;
7202
7203 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7204 if (ret == QLA_ERROR)
7205 goto exit_login_st;
7206
Manish Rangankarad8bd452013-09-17 07:30:02 -04007207 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007208
7209 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7210 list_del_init(&ddb_idx->list);
7211 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7212 vfree(ddb_idx);
7213 }
7214
7215exit_login_st:
7216 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7217 ql4_printk(KERN_ERR, ha,
7218 "Unable to clear DDB index = 0x%x\n", ddb_index);
7219 }
7220
7221 clear_bit(ddb_index, ha->ddb_idx_map);
7222
7223exit_login_st_clr_bit:
7224 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7225 return ret;
7226}
7227
7228static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7229 struct dev_db_entry *fw_ddb_entry,
7230 uint16_t idx)
7231{
7232 int ret = QLA_ERROR;
7233
Manish Rangankarad8bd452013-09-17 07:30:02 -04007234 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007235 if (ret != QLA_SUCCESS)
7236 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7237 idx);
7238 else
7239 ret = -EPERM;
7240
7241 return ret;
7242}
7243
7244/**
7245 * qla4xxx_sysfs_ddb_login - Login to the specified target
7246 * @fnode_sess: pointer to session attrs of flash ddb entry
7247 * @fnode_conn: pointer to connection attrs of flash ddb entry
7248 *
7249 * This logs in to the specified target
7250 **/
7251static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7252 struct iscsi_bus_flash_conn *fnode_conn)
7253{
7254 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7255 struct scsi_qla_host *ha = to_qla_host(shost);
7256 struct dev_db_entry *fw_ddb_entry = NULL;
7257 dma_addr_t fw_ddb_entry_dma;
7258 uint32_t options = 0;
7259 int ret = 0;
7260
7261 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7262 ql4_printk(KERN_ERR, ha,
7263 "%s: Target info is not persistent\n", __func__);
7264 ret = -EIO;
7265 goto exit_ddb_login;
7266 }
7267
7268 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7269 &fw_ddb_entry_dma, GFP_KERNEL);
7270 if (!fw_ddb_entry) {
7271 DEBUG2(ql4_printk(KERN_ERR, ha,
7272 "%s: Unable to allocate dma buffer\n",
7273 __func__));
7274 ret = -ENOMEM;
7275 goto exit_ddb_login;
7276 }
7277
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007278 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007279 options |= IPV6_DEFAULT_DDB_ENTRY;
7280
7281 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7282 if (ret == QLA_ERROR)
7283 goto exit_ddb_login;
7284
7285 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7286 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7287
7288 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
Manish Rangankarad8bd452013-09-17 07:30:02 -04007289 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7290 fnode_sess->target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007291 else
7292 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7293 fnode_sess->target_id);
7294
7295 if (ret > 0)
7296 ret = -EIO;
7297
7298exit_ddb_login:
7299 if (fw_ddb_entry)
7300 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7301 fw_ddb_entry, fw_ddb_entry_dma);
7302 return ret;
7303}
7304
7305/**
7306 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7307 * @cls_sess: pointer to session to be logged out
7308 *
7309 * This performs session log out from the specified target
7310 **/
7311static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7312{
7313 struct iscsi_session *sess;
7314 struct ddb_entry *ddb_entry = NULL;
7315 struct scsi_qla_host *ha;
7316 struct dev_db_entry *fw_ddb_entry = NULL;
7317 dma_addr_t fw_ddb_entry_dma;
7318 unsigned long flags;
7319 unsigned long wtime;
7320 uint32_t ddb_state;
7321 int options;
7322 int ret = 0;
7323
7324 sess = cls_sess->dd_data;
7325 ddb_entry = sess->dd_data;
7326 ha = ddb_entry->ha;
7327
7328 if (ddb_entry->ddb_type != FLASH_DDB) {
7329 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7330 __func__);
7331 ret = -ENXIO;
7332 goto exit_ddb_logout;
7333 }
7334
Adheer Chandravanshi37719c22013-04-05 07:06:07 -04007335 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7336 ql4_printk(KERN_ERR, ha,
7337 "%s: Logout from boot target entry is not permitted.\n",
7338 __func__);
7339 ret = -EPERM;
7340 goto exit_ddb_logout;
7341 }
7342
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007343 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7344 &fw_ddb_entry_dma, GFP_KERNEL);
7345 if (!fw_ddb_entry) {
7346 ql4_printk(KERN_ERR, ha,
7347 "%s: Unable to allocate dma buffer\n", __func__);
7348 ret = -ENOMEM;
7349 goto exit_ddb_logout;
7350 }
7351
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007352 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7353 goto ddb_logout_init;
7354
7355 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7356 fw_ddb_entry, fw_ddb_entry_dma,
7357 NULL, NULL, &ddb_state, NULL,
7358 NULL, NULL);
7359 if (ret == QLA_ERROR)
7360 goto ddb_logout_init;
7361
7362 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7363 goto ddb_logout_init;
7364
7365 /* wait until next relogin is triggered using DF_RELOGIN and
7366 * clear DF_RELOGIN to avoid invocation of further relogin
7367 */
7368 wtime = jiffies + (HZ * RELOGIN_TOV);
7369 do {
7370 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7371 goto ddb_logout_init;
7372
7373 schedule_timeout_uninterruptible(HZ);
7374 } while ((time_after(wtime, jiffies)));
7375
7376ddb_logout_init:
7377 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7378 atomic_set(&ddb_entry->relogin_timer, 0);
7379
7380 options = LOGOUT_OPTION_CLOSE_SESSION;
7381 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7382
7383 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007384 wtime = jiffies + (HZ * LOGOUT_TOV);
7385 do {
7386 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7387 fw_ddb_entry, fw_ddb_entry_dma,
7388 NULL, NULL, &ddb_state, NULL,
7389 NULL, NULL);
7390 if (ret == QLA_ERROR)
7391 goto ddb_logout_clr_sess;
7392
7393 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7394 (ddb_state == DDB_DS_SESSION_FAILED))
7395 goto ddb_logout_clr_sess;
7396
7397 schedule_timeout_uninterruptible(HZ);
7398 } while ((time_after(wtime, jiffies)));
7399
7400ddb_logout_clr_sess:
7401 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7402 /*
7403 * we have decremented the reference count of the driver
7404 * when we setup the session to have the driver unload
7405 * to be seamless without actually destroying the
7406 * session
7407 **/
7408 try_module_get(qla4xxx_iscsi_transport.owner);
7409 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7410
7411 spin_lock_irqsave(&ha->hardware_lock, flags);
7412 qla4xxx_free_ddb(ha, ddb_entry);
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007413 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007414 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7415
7416 iscsi_session_teardown(ddb_entry->sess);
7417
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007418 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007419 ret = QLA_SUCCESS;
7420
7421exit_ddb_logout:
7422 if (fw_ddb_entry)
7423 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7424 fw_ddb_entry, fw_ddb_entry_dma);
7425 return ret;
7426}
7427
7428/**
7429 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7430 * @fnode_sess: pointer to session attrs of flash ddb entry
7431 * @fnode_conn: pointer to connection attrs of flash ddb entry
7432 *
7433 * This performs log out from the specified target
7434 **/
7435static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7436 struct iscsi_bus_flash_conn *fnode_conn)
7437{
7438 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7439 struct scsi_qla_host *ha = to_qla_host(shost);
7440 struct ql4_tuple_ddb *flash_tddb = NULL;
7441 struct ql4_tuple_ddb *tmp_tddb = NULL;
7442 struct dev_db_entry *fw_ddb_entry = NULL;
7443 struct ddb_entry *ddb_entry = NULL;
7444 dma_addr_t fw_ddb_dma;
7445 uint32_t next_idx = 0;
7446 uint32_t state = 0, conn_err = 0;
7447 uint16_t conn_id = 0;
7448 int idx, index;
7449 int status, ret = 0;
7450
7451 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7452 &fw_ddb_dma);
7453 if (fw_ddb_entry == NULL) {
7454 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7455 ret = -ENOMEM;
7456 goto exit_ddb_logout;
7457 }
7458
7459 flash_tddb = vzalloc(sizeof(*flash_tddb));
7460 if (!flash_tddb) {
7461 ql4_printk(KERN_WARNING, ha,
7462 "%s:Memory Allocation failed.\n", __func__);
7463 ret = -ENOMEM;
7464 goto exit_ddb_logout;
7465 }
7466
7467 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7468 if (!tmp_tddb) {
7469 ql4_printk(KERN_WARNING, ha,
7470 "%s:Memory Allocation failed.\n", __func__);
7471 ret = -ENOMEM;
7472 goto exit_ddb_logout;
7473 }
7474
7475 if (!fnode_sess->targetname) {
7476 ql4_printk(KERN_ERR, ha,
7477 "%s:Cannot logout from SendTarget entry\n",
7478 __func__);
7479 ret = -EPERM;
7480 goto exit_ddb_logout;
7481 }
7482
7483 if (fnode_sess->is_boot_target) {
7484 ql4_printk(KERN_ERR, ha,
7485 "%s: Logout from boot target entry is not permitted.\n",
7486 __func__);
7487 ret = -EPERM;
7488 goto exit_ddb_logout;
7489 }
7490
7491 strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7492 ISCSI_NAME_SIZE);
7493
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007494 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007495 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7496 else
7497 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7498
7499 flash_tddb->tpgt = fnode_sess->tpgt;
7500 flash_tddb->port = fnode_conn->port;
7501
7502 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7503
7504 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7505 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7506 if (ddb_entry == NULL)
7507 continue;
7508
7509 if (ddb_entry->ddb_type != FLASH_DDB)
7510 continue;
7511
7512 index = ddb_entry->sess->target_id;
7513 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7514 fw_ddb_dma, NULL, &next_idx,
7515 &state, &conn_err, NULL,
7516 &conn_id);
7517 if (status == QLA_ERROR) {
7518 ret = -ENOMEM;
7519 break;
7520 }
7521
7522 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7523
7524 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7525 true);
7526 if (status == QLA_SUCCESS) {
7527 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7528 break;
7529 }
7530 }
7531
7532 if (idx == MAX_DDB_ENTRIES)
7533 ret = -ESRCH;
7534
7535exit_ddb_logout:
7536 if (flash_tddb)
7537 vfree(flash_tddb);
7538 if (tmp_tddb)
7539 vfree(tmp_tddb);
7540 if (fw_ddb_entry)
7541 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7542
7543 return ret;
7544}
7545
7546static int
7547qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7548 int param, char *buf)
7549{
7550 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7551 struct scsi_qla_host *ha = to_qla_host(shost);
7552 struct iscsi_bus_flash_conn *fnode_conn;
7553 struct ql4_chap_table chap_tbl;
7554 struct device *dev;
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007555 int parent_type;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007556 int rc = 0;
7557
Mike Christie8526cb12013-05-06 12:06:56 -05007558 dev = iscsi_find_flashnode_conn(fnode_sess);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007559 if (!dev)
7560 return -EIO;
7561
7562 fnode_conn = iscsi_dev_to_flash_conn(dev);
7563
7564 switch (param) {
7565 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7566 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7567 break;
7568 case ISCSI_FLASHNODE_PORTAL_TYPE:
7569 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7570 break;
7571 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7572 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7573 break;
7574 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7575 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7576 break;
7577 case ISCSI_FLASHNODE_ENTRY_EN:
7578 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7579 break;
7580 case ISCSI_FLASHNODE_HDR_DGST_EN:
7581 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7582 break;
7583 case ISCSI_FLASHNODE_DATA_DGST_EN:
7584 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7585 break;
7586 case ISCSI_FLASHNODE_IMM_DATA_EN:
7587 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7588 break;
7589 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7590 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7591 break;
7592 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7593 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7594 break;
7595 case ISCSI_FLASHNODE_PDU_INORDER:
7596 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7597 break;
7598 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7599 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7600 break;
7601 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7602 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7603 break;
7604 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7605 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7606 break;
7607 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7608 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7609 break;
7610 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7611 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7612 break;
7613 case ISCSI_FLASHNODE_ERL:
7614 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7615 break;
7616 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7617 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7618 break;
7619 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7620 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7621 break;
7622 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7623 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7624 break;
7625 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7626 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7627 break;
7628 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7629 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7630 break;
7631 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7632 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7633 break;
7634 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7635 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7636 break;
7637 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7638 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7639 break;
7640 case ISCSI_FLASHNODE_FIRST_BURST:
7641 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7642 break;
7643 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7644 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7645 break;
7646 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7647 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7648 break;
7649 case ISCSI_FLASHNODE_MAX_R2T:
7650 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7651 break;
7652 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7653 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7654 break;
7655 case ISCSI_FLASHNODE_ISID:
7656 rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
7657 fnode_sess->isid[0], fnode_sess->isid[1],
7658 fnode_sess->isid[2], fnode_sess->isid[3],
7659 fnode_sess->isid[4], fnode_sess->isid[5]);
7660 break;
7661 case ISCSI_FLASHNODE_TSID:
7662 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7663 break;
7664 case ISCSI_FLASHNODE_PORT:
7665 rc = sprintf(buf, "%d\n", fnode_conn->port);
7666 break;
7667 case ISCSI_FLASHNODE_MAX_BURST:
7668 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7669 break;
7670 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7671 rc = sprintf(buf, "%u\n",
7672 fnode_sess->default_taskmgmt_timeout);
7673 break;
7674 case ISCSI_FLASHNODE_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007675 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007676 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7677 else
7678 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7679 break;
7680 case ISCSI_FLASHNODE_ALIAS:
7681 if (fnode_sess->targetalias)
7682 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7683 else
7684 rc = sprintf(buf, "\n");
7685 break;
7686 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007687 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007688 rc = sprintf(buf, "%pI6\n",
7689 fnode_conn->redirect_ipaddr);
7690 else
7691 rc = sprintf(buf, "%pI4\n",
7692 fnode_conn->redirect_ipaddr);
7693 break;
7694 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7695 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7696 break;
7697 case ISCSI_FLASHNODE_LOCAL_PORT:
7698 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7699 break;
7700 case ISCSI_FLASHNODE_IPV4_TOS:
7701 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7702 break;
7703 case ISCSI_FLASHNODE_IPV6_TC:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007704 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007705 rc = sprintf(buf, "%u\n",
7706 fnode_conn->ipv6_traffic_class);
7707 else
7708 rc = sprintf(buf, "\n");
7709 break;
7710 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7711 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7712 break;
7713 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007714 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007715 rc = sprintf(buf, "%pI6\n",
7716 fnode_conn->link_local_ipv6_addr);
7717 else
7718 rc = sprintf(buf, "\n");
7719 break;
7720 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007721 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007722 break;
7723 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
7724 if (fnode_sess->discovery_parent_type == DDB_ISNS)
7725 parent_type = ISCSI_DISC_PARENT_ISNS;
7726 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
7727 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04007728 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007729 parent_type = ISCSI_DISC_PARENT_SENDTGT;
7730 else
7731 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
7732
7733 rc = sprintf(buf, "%s\n",
7734 iscsi_get_discovery_parent_name(parent_type));
7735 break;
7736 case ISCSI_FLASHNODE_NAME:
7737 if (fnode_sess->targetname)
7738 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
7739 else
7740 rc = sprintf(buf, "\n");
7741 break;
7742 case ISCSI_FLASHNODE_TPGT:
7743 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
7744 break;
7745 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
7746 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
7747 break;
7748 case ISCSI_FLASHNODE_TCP_RECV_WSF:
7749 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
7750 break;
7751 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
7752 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
7753 break;
7754 case ISCSI_FLASHNODE_USERNAME:
7755 if (fnode_sess->chap_auth_en) {
7756 qla4xxx_get_uni_chap_at_index(ha,
7757 chap_tbl.name,
7758 chap_tbl.secret,
7759 fnode_sess->chap_out_idx);
7760 rc = sprintf(buf, "%s\n", chap_tbl.name);
7761 } else {
7762 rc = sprintf(buf, "\n");
7763 }
7764 break;
7765 case ISCSI_FLASHNODE_PASSWORD:
7766 if (fnode_sess->chap_auth_en) {
7767 qla4xxx_get_uni_chap_at_index(ha,
7768 chap_tbl.name,
7769 chap_tbl.secret,
7770 fnode_sess->chap_out_idx);
7771 rc = sprintf(buf, "%s\n", chap_tbl.secret);
7772 } else {
7773 rc = sprintf(buf, "\n");
7774 }
7775 break;
7776 case ISCSI_FLASHNODE_STATSN:
7777 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
7778 break;
7779 case ISCSI_FLASHNODE_EXP_STATSN:
7780 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
7781 break;
7782 case ISCSI_FLASHNODE_IS_BOOT_TGT:
7783 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
7784 break;
7785 default:
7786 rc = -ENOSYS;
7787 break;
7788 }
Mike Christie8526cb12013-05-06 12:06:56 -05007789
7790 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007791 return rc;
7792}
7793
7794/**
7795 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
7796 * @fnode_sess: pointer to session attrs of flash ddb entry
7797 * @fnode_conn: pointer to connection attrs of flash ddb entry
7798 * @data: Parameters and their values to update
7799 * @len: len of data
7800 *
7801 * This sets the parameter of flash ddb entry and writes them to flash
7802 **/
7803static int
7804qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
7805 struct iscsi_bus_flash_conn *fnode_conn,
7806 void *data, int len)
7807{
7808 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7809 struct scsi_qla_host *ha = to_qla_host(shost);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007810 struct iscsi_flashnode_param_info *fnode_param;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04007811 struct ql4_chap_table chap_tbl;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007812 struct nlattr *attr;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04007813 uint16_t chap_out_idx = INVALID_ENTRY;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007814 int rc = QLA_ERROR;
7815 uint32_t rem = len;
7816
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04007817 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007818 nla_for_each_attr(attr, data, len, rem) {
7819 fnode_param = nla_data(attr);
7820
7821 switch (fnode_param->param) {
7822 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7823 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
7824 break;
7825 case ISCSI_FLASHNODE_PORTAL_TYPE:
7826 memcpy(fnode_sess->portal_type, fnode_param->value,
7827 strlen(fnode_sess->portal_type));
7828 break;
7829 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7830 fnode_sess->auto_snd_tgt_disable =
7831 fnode_param->value[0];
7832 break;
7833 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7834 fnode_sess->discovery_sess = fnode_param->value[0];
7835 break;
7836 case ISCSI_FLASHNODE_ENTRY_EN:
7837 fnode_sess->entry_state = fnode_param->value[0];
7838 break;
7839 case ISCSI_FLASHNODE_HDR_DGST_EN:
7840 fnode_conn->hdrdgst_en = fnode_param->value[0];
7841 break;
7842 case ISCSI_FLASHNODE_DATA_DGST_EN:
7843 fnode_conn->datadgst_en = fnode_param->value[0];
7844 break;
7845 case ISCSI_FLASHNODE_IMM_DATA_EN:
7846 fnode_sess->imm_data_en = fnode_param->value[0];
7847 break;
7848 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7849 fnode_sess->initial_r2t_en = fnode_param->value[0];
7850 break;
7851 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7852 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
7853 break;
7854 case ISCSI_FLASHNODE_PDU_INORDER:
7855 fnode_sess->pdu_inorder_en = fnode_param->value[0];
7856 break;
7857 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7858 fnode_sess->chap_auth_en = fnode_param->value[0];
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04007859 /* Invalidate chap index if chap auth is disabled */
7860 if (!fnode_sess->chap_auth_en)
7861 fnode_sess->chap_out_idx = INVALID_ENTRY;
7862
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007863 break;
7864 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7865 fnode_conn->snack_req_en = fnode_param->value[0];
7866 break;
7867 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7868 fnode_sess->discovery_logout_en = fnode_param->value[0];
7869 break;
7870 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7871 fnode_sess->bidi_chap_en = fnode_param->value[0];
7872 break;
7873 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7874 fnode_sess->discovery_auth_optional =
7875 fnode_param->value[0];
7876 break;
7877 case ISCSI_FLASHNODE_ERL:
7878 fnode_sess->erl = fnode_param->value[0];
7879 break;
7880 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7881 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
7882 break;
7883 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7884 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
7885 break;
7886 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7887 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
7888 break;
7889 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7890 fnode_conn->tcp_timer_scale = fnode_param->value[0];
7891 break;
7892 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7893 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
7894 break;
7895 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7896 fnode_conn->fragment_disable = fnode_param->value[0];
7897 break;
7898 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7899 fnode_conn->max_recv_dlength =
7900 *(unsigned *)fnode_param->value;
7901 break;
7902 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7903 fnode_conn->max_xmit_dlength =
7904 *(unsigned *)fnode_param->value;
7905 break;
7906 case ISCSI_FLASHNODE_FIRST_BURST:
7907 fnode_sess->first_burst =
7908 *(unsigned *)fnode_param->value;
7909 break;
7910 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7911 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
7912 break;
7913 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7914 fnode_sess->time2retain =
7915 *(uint16_t *)fnode_param->value;
7916 break;
7917 case ISCSI_FLASHNODE_MAX_R2T:
7918 fnode_sess->max_r2t =
7919 *(uint16_t *)fnode_param->value;
7920 break;
7921 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7922 fnode_conn->keepalive_timeout =
7923 *(uint16_t *)fnode_param->value;
7924 break;
7925 case ISCSI_FLASHNODE_ISID:
7926 memcpy(fnode_sess->isid, fnode_param->value,
7927 sizeof(fnode_sess->isid));
7928 break;
7929 case ISCSI_FLASHNODE_TSID:
7930 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
7931 break;
7932 case ISCSI_FLASHNODE_PORT:
7933 fnode_conn->port = *(uint16_t *)fnode_param->value;
7934 break;
7935 case ISCSI_FLASHNODE_MAX_BURST:
7936 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
7937 break;
7938 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7939 fnode_sess->default_taskmgmt_timeout =
7940 *(uint16_t *)fnode_param->value;
7941 break;
7942 case ISCSI_FLASHNODE_IPADDR:
7943 memcpy(fnode_conn->ipaddress, fnode_param->value,
7944 IPv6_ADDR_LEN);
7945 break;
7946 case ISCSI_FLASHNODE_ALIAS:
7947 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
7948 (char *)fnode_param->value);
7949 break;
7950 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7951 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
7952 IPv6_ADDR_LEN);
7953 break;
7954 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7955 fnode_conn->max_segment_size =
7956 *(unsigned *)fnode_param->value;
7957 break;
7958 case ISCSI_FLASHNODE_LOCAL_PORT:
7959 fnode_conn->local_port =
7960 *(uint16_t *)fnode_param->value;
7961 break;
7962 case ISCSI_FLASHNODE_IPV4_TOS:
7963 fnode_conn->ipv4_tos = fnode_param->value[0];
7964 break;
7965 case ISCSI_FLASHNODE_IPV6_TC:
7966 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
7967 break;
7968 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7969 fnode_conn->ipv6_flow_label = fnode_param->value[0];
7970 break;
7971 case ISCSI_FLASHNODE_NAME:
7972 rc = iscsi_switch_str_param(&fnode_sess->targetname,
7973 (char *)fnode_param->value);
7974 break;
7975 case ISCSI_FLASHNODE_TPGT:
7976 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
7977 break;
7978 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
7979 memcpy(fnode_conn->link_local_ipv6_addr,
7980 fnode_param->value, IPv6_ADDR_LEN);
7981 break;
Adheer Chandravanshi65560162013-07-08 08:33:06 -04007982 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
7983 fnode_sess->discovery_parent_idx =
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007984 *(uint16_t *)fnode_param->value;
7985 break;
7986 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
7987 fnode_conn->tcp_xmit_wsf =
7988 *(uint8_t *)fnode_param->value;
7989 break;
7990 case ISCSI_FLASHNODE_TCP_RECV_WSF:
7991 fnode_conn->tcp_recv_wsf =
7992 *(uint8_t *)fnode_param->value;
7993 break;
7994 case ISCSI_FLASHNODE_STATSN:
7995 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
7996 break;
7997 case ISCSI_FLASHNODE_EXP_STATSN:
7998 fnode_conn->exp_statsn =
7999 *(uint32_t *)fnode_param->value;
8000 break;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008001 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8002 chap_out_idx = *(uint16_t *)fnode_param->value;
8003 if (!qla4xxx_get_uni_chap_at_index(ha,
8004 chap_tbl.name,
8005 chap_tbl.secret,
8006 chap_out_idx)) {
8007 fnode_sess->chap_out_idx = chap_out_idx;
8008 /* Enable chap auth if chap index is valid */
8009 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8010 }
8011 break;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008012 default:
8013 ql4_printk(KERN_ERR, ha,
8014 "%s: No such sysfs attribute\n", __func__);
8015 rc = -ENOSYS;
8016 goto exit_set_param;
8017 }
8018 }
8019
8020 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8021
8022exit_set_param:
8023 return rc;
8024}
8025
8026/**
8027 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8028 * @fnode_sess: pointer to session attrs of flash ddb entry
8029 *
8030 * This invalidates the flash ddb entry at the given index
8031 **/
8032static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8033{
8034 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8035 struct scsi_qla_host *ha = to_qla_host(shost);
8036 uint32_t dev_db_start_offset;
8037 uint32_t dev_db_end_offset;
8038 struct dev_db_entry *fw_ddb_entry = NULL;
8039 dma_addr_t fw_ddb_entry_dma;
8040 uint16_t *ddb_cookie = NULL;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04008041 size_t ddb_size = 0;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008042 void *pddb = NULL;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008043 int target_id;
8044 int rc = 0;
8045
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008046 if (fnode_sess->is_boot_target) {
8047 rc = -EPERM;
8048 DEBUG2(ql4_printk(KERN_ERR, ha,
8049 "%s: Deletion of boot target entry is not permitted.\n",
8050 __func__));
8051 goto exit_ddb_del;
8052 }
8053
8054 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8055 goto sysfs_ddb_del;
8056
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008057 if (is_qla40XX(ha)) {
8058 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008059 dev_db_end_offset = FLASH_OFFSET_DB_END;
8060 dev_db_start_offset += (fnode_sess->target_id *
8061 sizeof(*fw_ddb_entry));
8062 ddb_size = sizeof(*fw_ddb_entry);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008063 } else {
8064 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8065 (ha->hw.flt_region_ddb << 2);
8066 /* flt_ddb_size is DDB table size for both ports
8067 * so divide it by 2 to calculate the offset for second port
8068 */
8069 if (ha->port_num == 1)
8070 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008071
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008072 dev_db_end_offset = dev_db_start_offset +
8073 (ha->hw.flt_ddb_size / 2);
8074
8075 dev_db_start_offset += (fnode_sess->target_id *
8076 sizeof(*fw_ddb_entry));
Adheer Chandravanshi1bcb5612013-04-17 05:15:28 -04008077 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008078
8079 ddb_size = sizeof(*ddb_cookie);
8080 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008081
8082 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8083 __func__, dev_db_start_offset, dev_db_end_offset));
8084
8085 if (dev_db_start_offset > dev_db_end_offset) {
8086 rc = -EIO;
8087 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8088 __func__, fnode_sess->target_id));
8089 goto exit_ddb_del;
8090 }
8091
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008092 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8093 &fw_ddb_entry_dma, GFP_KERNEL);
8094 if (!pddb) {
8095 rc = -ENOMEM;
8096 DEBUG2(ql4_printk(KERN_ERR, ha,
8097 "%s: Unable to allocate dma buffer\n",
8098 __func__));
8099 goto exit_ddb_del;
8100 }
8101
8102 if (is_qla40XX(ha)) {
8103 fw_ddb_entry = pddb;
8104 memset(fw_ddb_entry, 0, ddb_size);
8105 ddb_cookie = &fw_ddb_entry->cookie;
8106 } else {
8107 ddb_cookie = pddb;
8108 }
8109
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008110 /* invalidate the cookie */
8111 *ddb_cookie = 0xFFEE;
8112 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008113 ddb_size, FLASH_OPT_RMW_COMMIT);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008114
8115sysfs_ddb_del:
8116 target_id = fnode_sess->target_id;
8117 iscsi_destroy_flashnode_sess(fnode_sess);
8118 ql4_printk(KERN_INFO, ha,
8119 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8120 __func__, target_id, ha->host_no);
8121exit_ddb_del:
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008122 if (pddb)
8123 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8124 fw_ddb_entry_dma);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008125 return rc;
8126}
8127
8128/**
8129 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8130 * @ha: pointer to adapter structure
8131 *
8132 * Export the firmware DDB for all send targets and normal targets to sysfs.
8133 **/
8134static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8135{
8136 struct dev_db_entry *fw_ddb_entry = NULL;
8137 dma_addr_t fw_ddb_entry_dma;
8138 uint16_t max_ddbs;
8139 uint16_t idx = 0;
8140 int ret = QLA_SUCCESS;
8141
8142 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8143 sizeof(*fw_ddb_entry),
8144 &fw_ddb_entry_dma, GFP_KERNEL);
8145 if (!fw_ddb_entry) {
8146 DEBUG2(ql4_printk(KERN_ERR, ha,
8147 "%s: Unable to allocate dma buffer\n",
8148 __func__));
8149 return -ENOMEM;
8150 }
8151
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04008152 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008153 MAX_DEV_DB_ENTRIES;
8154
8155 for (idx = 0; idx < max_ddbs; idx++) {
8156 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8157 idx))
8158 continue;
8159
8160 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8161 if (ret) {
8162 ret = -EIO;
8163 break;
8164 }
8165 }
8166
8167 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8168 fw_ddb_entry_dma);
8169
8170 return ret;
8171}
8172
8173static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8174{
8175 iscsi_destroy_all_flashnode(ha->host);
8176}
8177
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008178/**
8179 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8180 * @ha: pointer to adapter structure
8181 * @is_reset: Is this init path or reset path
8182 *
8183 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8184 * using connection open, then create the list of normal targets (nt)
8185 * from firmware DDBs. Based on the list of nt setup session and connection
8186 * objects.
8187 **/
8188void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8189{
8190 uint16_t tmo = 0;
8191 struct list_head list_st, list_nt;
8192 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8193 unsigned long wtime;
8194
8195 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8196 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8197 ha->is_reset = is_reset;
8198 return;
8199 }
8200
8201 INIT_LIST_HEAD(&list_st);
8202 INIT_LIST_HEAD(&list_nt);
8203
8204 qla4xxx_build_st_list(ha, &list_st);
8205
Mike Christie13483732011-12-01 21:38:41 -06008206 /* Before issuing conn open mbox, ensure all IPs states are configured
8207 * Note, conn open fails if IPs are not configured
8208 */
8209 qla4xxx_wait_for_ip_configuration(ha);
8210
8211 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8212 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8213 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8214 }
8215
8216 /* Wait to ensure all sendtargets are done for min 12 sec wait */
Nilesh Javalic28eaac2011-12-18 21:40:44 -08008217 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8218 (ha->def_timeout < LOGIN_TOV * 10) ?
8219 ha->def_timeout : LOGIN_TOV);
8220
Mike Christie13483732011-12-01 21:38:41 -06008221 DEBUG2(ql4_printk(KERN_INFO, ha,
8222 "Default time to wait for build ddb %d\n", tmo));
8223
8224 wtime = jiffies + (HZ * tmo);
8225 do {
Nilesh Javalif1f2e602011-12-16 01:58:57 -08008226 if (list_empty(&list_st))
8227 break;
8228
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008229 qla4xxx_remove_failed_ddb(ha, &list_st);
Mike Christie13483732011-12-01 21:38:41 -06008230 schedule_timeout_uninterruptible(HZ / 10);
8231 } while (time_after(wtime, jiffies));
8232
Manish Rangankarad8bd452013-09-17 07:30:02 -04008233
8234 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8235
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008236 qla4xxx_free_ddb_list(&list_st);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008237 qla4xxx_free_ddb_list(&list_nt);
Mike Christie13483732011-12-01 21:38:41 -06008238
8239 qla4xxx_free_ddb_index(ha);
8240}
8241
David Somayajuluafaf5a22006-09-19 10:28:00 -07008242/**
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008243 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8244 * response.
8245 * @ha: pointer to adapter structure
8246 *
8247 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8248 * set in DDB and we will wait for login response of boot targets during
8249 * probe.
8250 **/
8251static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8252{
8253 struct ddb_entry *ddb_entry;
8254 struct dev_db_entry *fw_ddb_entry = NULL;
8255 dma_addr_t fw_ddb_entry_dma;
8256 unsigned long wtime;
8257 uint32_t ddb_state;
8258 int max_ddbs, idx, ret;
8259
8260 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8261 MAX_DEV_DB_ENTRIES;
8262
8263 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8264 &fw_ddb_entry_dma, GFP_KERNEL);
8265 if (!fw_ddb_entry) {
8266 ql4_printk(KERN_ERR, ha,
8267 "%s: Unable to allocate dma buffer\n", __func__);
8268 goto exit_login_resp;
8269 }
8270
8271 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8272
8273 for (idx = 0; idx < max_ddbs; idx++) {
8274 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8275 if (ddb_entry == NULL)
8276 continue;
8277
8278 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8279 DEBUG2(ql4_printk(KERN_INFO, ha,
8280 "%s: DDB index [%d]\n", __func__,
8281 ddb_entry->fw_ddb_index));
8282 do {
8283 ret = qla4xxx_get_fwddb_entry(ha,
8284 ddb_entry->fw_ddb_index,
8285 fw_ddb_entry, fw_ddb_entry_dma,
8286 NULL, NULL, &ddb_state, NULL,
8287 NULL, NULL);
8288 if (ret == QLA_ERROR)
8289 goto exit_login_resp;
8290
8291 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8292 (ddb_state == DDB_DS_SESSION_FAILED))
8293 break;
8294
8295 schedule_timeout_uninterruptible(HZ);
8296
8297 } while ((time_after(wtime, jiffies)));
8298
8299 if (!time_after(wtime, jiffies)) {
8300 DEBUG2(ql4_printk(KERN_INFO, ha,
8301 "%s: Login response wait timer expired\n",
8302 __func__));
8303 goto exit_login_resp;
8304 }
8305 }
8306 }
8307
8308exit_login_resp:
8309 if (fw_ddb_entry)
8310 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8311 fw_ddb_entry, fw_ddb_entry_dma);
8312}
8313
8314/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07008315 * qla4xxx_probe_adapter - callback function to probe HBA
8316 * @pdev: pointer to pci_dev structure
8317 * @pci_device_id: pointer to pci_device entry
8318 *
8319 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8320 * It returns zero if successful. It also initializes all data necessary for
8321 * the driver.
8322 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008323static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8324 const struct pci_device_id *ent)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008325{
8326 int ret = -ENODEV, status;
8327 struct Scsi_Host *host;
8328 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008329 uint8_t init_retry_count = 0;
8330 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308331 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008332 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008333
8334 if (pci_enable_device(pdev))
8335 return -1;
8336
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008337 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008338 if (host == NULL) {
8339 printk(KERN_WARNING
8340 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8341 goto probe_disable_device;
8342 }
8343
8344 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008345 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008346 memset(ha, 0, sizeof(*ha));
8347
8348 /* Save the information from PCI BIOS. */
8349 ha->pdev = pdev;
8350 ha->host = host;
8351 ha->host_no = host->host_no;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008352 ha->func_num = PCI_FUNC(ha->pdev->devfn);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008353
Lalit Chandivade2232be02010-07-30 14:38:47 +05308354 pci_enable_pcie_error_reporting(pdev);
8355
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308356 /* Setup Runtime configurable options */
8357 if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04008358 ha->isp_ops = &qla4_82xx_isp_ops;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008359 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308360 ha->qdr_sn_window = -1;
8361 ha->ddr_mn_window = -1;
8362 ha->curr_window = 255;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308363 nx_legacy_intr = &legacy_intr[ha->func_num];
8364 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8365 ha->nx_legacy_intr.tgt_status_reg =
8366 nx_legacy_intr->tgt_status_reg;
8367 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8368 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008369 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008370 ha->isp_ops = &qla4_83xx_isp_ops;
8371 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308372 } else {
8373 ha->isp_ops = &qla4xxx_isp_ops;
8374 }
8375
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008376 if (is_qla80XX(ha)) {
8377 rwlock_init(&ha->hw_lock);
8378 ha->pf_bit = ha->func_num << 16;
8379 /* Set EEH reset type to fundamental if required by hba */
Lalit Chandivade2232be02010-07-30 14:38:47 +05308380 pdev->needs_freset = 1;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008381 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05308382
David Somayajuluafaf5a22006-09-19 10:28:00 -07008383 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308384 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008385 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308386 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008387
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308388 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07008389 pdev->device, pdev->irq, ha->reg);
8390
8391 qla4xxx_config_dma_addressing(ha);
8392
8393 /* Initialize lists and spinlocks. */
David Somayajuluafaf5a22006-09-19 10:28:00 -07008394 INIT_LIST_HEAD(&ha->free_srb_q);
8395
8396 mutex_init(&ha->mbox_sem);
Lalit Chandivade45494152011-10-07 16:55:42 -07008397 mutex_init(&ha->chap_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308398 init_completion(&ha->mbx_intr_comp);
Vikas Chaudhary95d31262011-08-12 02:51:29 -07008399 init_completion(&ha->disable_acb_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008400
8401 spin_lock_init(&ha->hardware_lock);
Vikas Chaudhary8e9157c2012-08-22 07:45:24 -04008402 spin_lock_init(&ha->work_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008403
Vikas Chaudharyff884432011-08-29 23:43:02 +05308404 /* Initialize work list */
8405 INIT_LIST_HEAD(&ha->work_list);
8406
David Somayajuluafaf5a22006-09-19 10:28:00 -07008407 /* Allocate dma buffers */
8408 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308409 ql4_printk(KERN_WARNING, ha,
8410 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008411
8412 ret = -ENOMEM;
8413 goto probe_failed;
8414 }
8415
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008416 host->cmd_per_lun = 3;
8417 host->max_channel = 0;
8418 host->max_lun = MAX_LUNS - 1;
8419 host->max_id = MAX_TARGETS;
8420 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8421 host->can_queue = MAX_SRBS ;
8422 host->transportt = qla4xxx_scsi_transport;
8423
8424 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
8425 if (ret) {
8426 ql4_printk(KERN_WARNING, ha,
8427 "%s: scsi_init_shared_tag_map failed\n", __func__);
8428 goto probe_failed;
8429 }
8430
8431 pci_set_drvdata(pdev, ha);
8432
8433 ret = scsi_add_host(host, &pdev->dev);
8434 if (ret)
8435 goto probe_failed;
8436
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008437 if (is_qla80XX(ha))
8438 qla4_8xxx_get_flash_info(ha);
8439
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008440 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008441 qla4_83xx_read_reset_template(ha);
8442 /*
8443 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8444 * If DONRESET_BIT0 is set, drivers should not set dev_state
8445 * to NEED_RESET. But if NEED_RESET is set, drivers should
8446 * should honor the reset.
8447 */
8448 if (ql4xdontresethba == 1)
8449 qla4_83xx_set_idc_dontreset(ha);
8450 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308451
David Somayajuluafaf5a22006-09-19 10:28:00 -07008452 /*
8453 * Initialize the Host adapter request/response queues and
8454 * firmware
8455 * NOTE: interrupts enabled upon successful completion
8456 */
Mike Christie13483732011-12-01 21:38:41 -06008457 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Poornima Vonti7977f822012-09-20 07:35:07 -04008458
8459 /* Dont retry adapter initialization if IRQ allocation failed */
Nilesh Javali17801c92013-03-22 07:22:42 -04008460 if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
8461 ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
8462 __func__);
Poornima Vonti7977f822012-09-20 07:35:07 -04008463 goto skip_retry_init;
Nilesh Javali17801c92013-03-22 07:22:42 -04008464 }
Poornima Vonti7977f822012-09-20 07:35:07 -04008465
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308466 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8467 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008468
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008469 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008470 ha->isp_ops->idc_lock(ha);
8471 dev_state = qla4_8xxx_rd_direct(ha,
Vikas Chaudharye951aca2012-12-29 02:24:52 -05008472 QLA8XXX_CRB_DEV_STATE);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008473 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04008474 if (dev_state == QLA8XXX_DEV_FAILED) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008475 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8476 "initialize adapter. H/W is in failed state\n",
8477 __func__);
8478 break;
8479 }
8480 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008481 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8482 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308483
8484 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8485 continue;
8486
Mike Christie13483732011-12-01 21:38:41 -06008487 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008488 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308489
Poornima Vonti7977f822012-09-20 07:35:07 -04008490skip_retry_init:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308491 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308492 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008493
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008494 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008495 ((is_qla8032(ha) || is_qla8042(ha)) &&
8496 qla4_83xx_idc_dontreset(ha))) {
Lalit Chandivadefe998522010-12-02 22:12:36 -08008497 /* Put the device in failed state. */
8498 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008499 ha->isp_ops->idc_lock(ha);
8500 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8501 QLA8XXX_DEV_FAILED);
8502 ha->isp_ops->idc_unlock(ha);
Lalit Chandivadefe998522010-12-02 22:12:36 -08008503 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008504 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008505 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008506 }
8507
David Somayajuluafaf5a22006-09-19 10:28:00 -07008508 /* Startup the kernel thread for this host adapter. */
8509 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8510 "qla4xxx_dpc\n", __func__));
8511 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8512 ha->dpc_thread = create_singlethread_workqueue(buf);
8513 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308514 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008515 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008516 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008517 }
David Howellsc4028952006-11-22 14:57:56 +00008518 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008519
Kees Cookd8537542013-07-03 15:04:57 -07008520 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8521 ha->host_no);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008522 if (!ha->task_wq) {
8523 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8524 ret = -ENODEV;
8525 goto remove_host;
8526 }
8527
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008528 /*
8529 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308530 * (which is called indirectly by qla4xxx_initialize_adapter),
8531 * so that irqs will be registered after crbinit but before
8532 * mbx_intr_enable.
8533 */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008534 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308535 ret = qla4xxx_request_irqs(ha);
8536 if (ret) {
8537 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8538 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008539 goto remove_host;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308540 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008541 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008542
Lalit Chandivade2232be02010-07-30 14:38:47 +05308543 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308544 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008545
8546 /* Start timer thread. */
8547 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
8548
8549 set_bit(AF_INIT_DONE, &ha->flags);
8550
Tej Parkash068237c82012-05-18 04:41:44 -04008551 qla4_8xxx_alloc_sysfs_attr(ha);
8552
David Somayajuluafaf5a22006-09-19 10:28:00 -07008553 printk(KERN_INFO
8554 " QLogic iSCSI HBA Driver version: %s\n"
8555 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8556 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
Adheer Chandravanshieee06a02013-07-08 08:33:10 -04008557 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8558 ha->fw_info.fw_patch, ha->fw_info.fw_build);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008559
Manish Dusanecfb27872012-09-20 07:35:01 -04008560 /* Set the driver version */
8561 if (is_qla80XX(ha))
8562 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8563
Manish Rangankar2a991c22011-07-25 13:48:55 -05008564 if (qla4xxx_setup_boot_info(ha))
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -08008565 ql4_printk(KERN_ERR, ha,
8566 "%s: No iSCSI boot target configured\n", __func__);
Manish Rangankar2a991c22011-07-25 13:48:55 -05008567
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008568 if (qla4xxx_sysfs_ddb_export(ha))
8569 ql4_printk(KERN_ERR, ha,
8570 "%s: Error exporting ddb to sysfs\n", __func__);
8571
Mike Christie13483732011-12-01 21:38:41 -06008572 /* Perform the build ddb list and login to each */
8573 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8574 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008575 qla4xxx_wait_login_resp_boot_tgt(ha);
Mike Christie13483732011-12-01 21:38:41 -06008576
8577 qla4xxx_create_chap_list(ha);
8578
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008579 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008580 return 0;
8581
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008582remove_host:
8583 scsi_remove_host(ha->host);
8584
David Somayajuluafaf5a22006-09-19 10:28:00 -07008585probe_failed:
8586 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308587
8588probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05308589 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008590 scsi_host_put(ha->host);
8591
8592probe_disable_device:
8593 pci_disable_device(pdev);
8594
8595 return ret;
8596}
8597
8598/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07008599 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8600 * @ha: pointer to adapter structure
8601 *
8602 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8603 * so that the other port will not re-initialize while in the process of
8604 * removing the ha due to driver unload or hba hotplug.
8605 **/
8606static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8607{
8608 struct scsi_qla_host *other_ha = NULL;
8609 struct pci_dev *other_pdev = NULL;
8610 int fn = ISP4XXX_PCI_FN_2;
8611
8612 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8613 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8614 fn = ISP4XXX_PCI_FN_1;
8615
8616 other_pdev =
8617 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8618 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8619 fn));
8620
8621 /* Get other_ha if other_pdev is valid and state is enable*/
8622 if (other_pdev) {
8623 if (atomic_read(&other_pdev->enable_cnt)) {
8624 other_ha = pci_get_drvdata(other_pdev);
8625 if (other_ha) {
8626 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8627 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8628 "Prevent %s reinit\n", __func__,
8629 dev_name(&other_ha->pdev->dev)));
8630 }
8631 }
8632 pci_dev_put(other_pdev);
8633 }
8634}
8635
Mike Christie13483732011-12-01 21:38:41 -06008636static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8637{
8638 struct ddb_entry *ddb_entry;
8639 int options;
8640 int idx;
8641
8642 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8643
8644 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8645 if ((ddb_entry != NULL) &&
8646 (ddb_entry->ddb_type == FLASH_DDB)) {
8647
8648 options = LOGOUT_OPTION_CLOSE_SESSION;
8649 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
8650 == QLA_ERROR)
8651 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
8652 __func__);
8653
8654 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8655 /*
8656 * we have decremented the reference count of the driver
8657 * when we setup the session to have the driver unload
8658 * to be seamless without actually destroying the
8659 * session
8660 **/
8661 try_module_get(qla4xxx_iscsi_transport.owner);
8662 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8663 qla4xxx_free_ddb(ha, ddb_entry);
8664 iscsi_session_teardown(ddb_entry->sess);
8665 }
8666 }
8667}
Karen Higgins7eece5a2011-03-21 03:34:29 -07008668/**
Masanari Iida59e13d42012-04-25 00:24:16 +09008669 * qla4xxx_remove_adapter - callback function to remove adapter.
David Somayajuluafaf5a22006-09-19 10:28:00 -07008670 * @pci_dev: PCI device pointer
8671 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008672static void qla4xxx_remove_adapter(struct pci_dev *pdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008673{
8674 struct scsi_qla_host *ha;
8675
Vikas Chaudharyf8b07512012-09-20 07:35:08 -04008676 /*
8677 * If the PCI device is disabled then it means probe_adapter had
8678 * failed and resources already cleaned up on probe_adapter exit.
8679 */
8680 if (!pci_is_enabled(pdev))
8681 return;
8682
David Somayajuluafaf5a22006-09-19 10:28:00 -07008683 ha = pci_get_drvdata(pdev);
8684
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008685 if (is_qla40XX(ha))
Karen Higgins7eece5a2011-03-21 03:34:29 -07008686 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07008687
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008688 /* destroy iface from sysfs */
8689 qla4xxx_destroy_ifaces(ha);
8690
Mike Christie13483732011-12-01 21:38:41 -06008691 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
Manish Rangankar2a991c22011-07-25 13:48:55 -05008692 iscsi_boot_destroy_kset(ha->boot_kset);
8693
Mike Christie13483732011-12-01 21:38:41 -06008694 qla4xxx_destroy_fw_ddb_session(ha);
Tej Parkash068237c82012-05-18 04:41:44 -04008695 qla4_8xxx_free_sysfs_attr(ha);
Mike Christie13483732011-12-01 21:38:41 -06008696
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008697 qla4xxx_sysfs_ddb_remove(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008698 scsi_remove_host(ha->host);
8699
8700 qla4xxx_free_adapter(ha);
8701
8702 scsi_host_put(ha->host);
8703
Lalit Chandivade2232be02010-07-30 14:38:47 +05308704 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308705 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008706}
8707
8708/**
8709 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
8710 * @ha: HA context
8711 *
8712 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
8713 * supported addressing method.
8714 */
Adrian Bunk47975472007-04-26 00:35:16 -07008715static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008716{
8717 int retval;
8718
8719 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07008720 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
8721 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07008722 dev_dbg(&ha->pdev->dev,
8723 "Failed to set 64 bit PCI consistent mask; "
8724 "using 32 bit.\n");
8725 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07008726 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07008727 }
8728 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07008729 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07008730}
8731
8732static int qla4xxx_slave_alloc(struct scsi_device *sdev)
8733{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008734 struct iscsi_cls_session *cls_sess;
8735 struct iscsi_session *sess;
8736 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07008737 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008738
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008739 cls_sess = starget_to_session(sdev->sdev_target);
8740 sess = cls_sess->dd_data;
8741 ddb = sess->dd_data;
8742
David Somayajuluafaf5a22006-09-19 10:28:00 -07008743 sdev->hostdata = ddb;
8744 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07008745
8746 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
8747 queue_depth = ql4xmaxqdepth;
8748
8749 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008750 return 0;
8751}
8752
8753static int qla4xxx_slave_configure(struct scsi_device *sdev)
8754{
8755 sdev->tagged_supported = 1;
8756 return 0;
8757}
8758
8759static void qla4xxx_slave_destroy(struct scsi_device *sdev)
8760{
8761 scsi_deactivate_tcq(sdev, 1);
8762}
8763
Tej Parkashf7b4aa62012-04-30 04:12:19 -07008764static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
8765 int reason)
8766{
8767 if (!ql4xqfulltracking)
8768 return -EOPNOTSUPP;
8769
8770 return iscsi_change_queue_depth(sdev, qdepth, reason);
8771}
8772
David Somayajuluafaf5a22006-09-19 10:28:00 -07008773/**
8774 * qla4xxx_del_from_active_array - returns an active srb
8775 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02008776 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07008777 *
8778 * This routine removes and returns the srb at the specified index
8779 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308780struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
8781 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008782{
8783 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05308784 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008785
Vikas Chaudhary53698872010-04-28 11:41:59 +05308786 cmd = scsi_host_find_tag(ha->host, index);
8787 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008788 return srb;
8789
Vikas Chaudhary53698872010-04-28 11:41:59 +05308790 srb = (struct srb *)CMD_SP(cmd);
8791 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008792 return srb;
8793
8794 /* update counters */
8795 if (srb->flags & SRB_DMA_VALID) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07008796 ha->iocb_cnt -= srb->iocb_cnt;
8797 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05308798 srb->cmd->host_scribble =
8799 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008800 }
8801 return srb;
8802}
8803
8804/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07008805 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308806 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07008807 * @cmd: Scsi Command to wait on.
8808 *
8809 * This routine waits for the command to be returned by the Firmware
8810 * for some max time.
8811 **/
8812static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
8813 struct scsi_cmnd *cmd)
8814{
8815 int done = 0;
8816 struct srb *rp;
8817 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05308818 int ret = SUCCESS;
8819
8820 /* Dont wait on command if PCI error is being handled
8821 * by PCI AER driver
8822 */
8823 if (unlikely(pci_channel_offline(ha->pdev)) ||
8824 (test_bit(AF_EEH_BUSY, &ha->flags))) {
8825 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
8826 ha->host_no, __func__);
8827 return ret;
8828 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008829
8830 do {
8831 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05308832 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008833 if (rp == NULL) {
8834 done++;
8835 break;
8836 }
8837
8838 msleep(2000);
8839 } while (max_wait_time--);
8840
8841 return done;
8842}
8843
8844/**
8845 * qla4xxx_wait_for_hba_online - waits for HBA to come online
8846 * @ha: Pointer to host adapter structure
8847 **/
8848static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
8849{
8850 unsigned long wait_online;
8851
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07008852 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008853 while (time_before(jiffies, wait_online)) {
8854
8855 if (adapter_up(ha))
8856 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008857
8858 msleep(2000);
8859 }
8860
8861 return QLA_ERROR;
8862}
8863
8864/**
Mike Christiece545032008-02-29 18:25:20 -06008865 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02008866 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07008867 * @t: target id
8868 * @l: lun id
8869 *
8870 * This function waits for all outstanding commands to a lun to complete. It
8871 * returns 0 if all pending commands are returned and 1 otherwise.
8872 **/
Mike Christiece545032008-02-29 18:25:20 -06008873static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
8874 struct scsi_target *stgt,
8875 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008876{
8877 int cnt;
8878 int status = 0;
8879 struct scsi_cmnd *cmd;
8880
8881 /*
Mike Christiece545032008-02-29 18:25:20 -06008882 * Waiting for all commands for the designated target or dev
8883 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07008884 */
8885 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
8886 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06008887 if (cmd && stgt == scsi_target(cmd->device) &&
8888 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07008889 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
8890 status++;
8891 break;
8892 }
8893 }
8894 }
8895 return status;
8896}
8897
8898/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308899 * qla4xxx_eh_abort - callback for abort task.
8900 * @cmd: Pointer to Linux's SCSI command structure
8901 *
8902 * This routine is called by the Linux OS to abort the specified
8903 * command.
8904 **/
8905static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
8906{
8907 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
8908 unsigned int id = cmd->device->id;
8909 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07008910 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308911 struct srb *srb = NULL;
8912 int ret = SUCCESS;
8913 int wait = 0;
8914
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308915 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04008916 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
8917 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308918
Mike Christie92b3e5b2010-10-06 22:51:17 -07008919 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308920 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07008921 if (!srb) {
8922 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308923 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07008924 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308925 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07008926 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308927
8928 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
8929 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
8930 ha->host_no, id, lun));
8931 ret = FAILED;
8932 } else {
8933 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
8934 ha->host_no, id, lun));
8935 wait = 1;
8936 }
8937
8938 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
8939
8940 /* Wait for command to complete */
8941 if (wait) {
8942 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
8943 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
8944 ha->host_no, id, lun));
8945 ret = FAILED;
8946 }
8947 }
8948
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308949 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308950 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03008951 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05308952
8953 return ret;
8954}
8955
8956/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07008957 * qla4xxx_eh_device_reset - callback for target reset.
8958 * @cmd: Pointer to Linux's SCSI command structure
8959 *
8960 * This routine is called by the Linux OS to reset all luns on the
8961 * specified target.
8962 **/
8963static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
8964{
8965 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
8966 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008967 int ret = FAILED, stat;
8968
Karen Higgins612f7342009-07-15 15:03:01 -05008969 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008970 return ret;
8971
Mike Christiec01be6d2010-07-22 16:59:49 +05308972 ret = iscsi_block_scsi_eh(cmd);
8973 if (ret)
8974 return ret;
8975 ret = FAILED;
8976
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308977 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07008978 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
8979 cmd->device->channel, cmd->device->id, cmd->device->lun);
8980
8981 DEBUG2(printk(KERN_INFO
8982 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
8983 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07008984 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07008985 ha->dpc_flags, cmd->result, cmd->allowed));
8986
8987 /* FIXME: wait for hba to go online */
8988 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
8989 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308990 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008991 goto eh_dev_reset_done;
8992 }
8993
Mike Christiece545032008-02-29 18:25:20 -06008994 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
8995 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308996 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06008997 "DEVICE RESET FAILED - waiting for "
8998 "commands.\n");
8999 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009000 }
9001
David C Somayajulu9d562912008-03-19 11:23:03 -07009002 /* Send marker. */
9003 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9004 MM_LUN_RESET) != QLA_SUCCESS)
9005 goto eh_dev_reset_done;
9006
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309007 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009008 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
9009 ha->host_no, cmd->device->channel, cmd->device->id,
9010 cmd->device->lun);
9011
9012 ret = SUCCESS;
9013
9014eh_dev_reset_done:
9015
9016 return ret;
9017}
9018
9019/**
Mike Christiece545032008-02-29 18:25:20 -06009020 * qla4xxx_eh_target_reset - callback for target reset.
9021 * @cmd: Pointer to Linux's SCSI command structure
9022 *
9023 * This routine is called by the Linux OS to reset the target.
9024 **/
9025static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9026{
9027 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9028 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05309029 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06009030
9031 if (!ddb_entry)
9032 return FAILED;
9033
Mike Christiec01be6d2010-07-22 16:59:49 +05309034 ret = iscsi_block_scsi_eh(cmd);
9035 if (ret)
9036 return ret;
9037
Mike Christiece545032008-02-29 18:25:20 -06009038 starget_printk(KERN_INFO, scsi_target(cmd->device),
9039 "WARM TARGET RESET ISSUED.\n");
9040
9041 DEBUG2(printk(KERN_INFO
9042 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9043 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07009044 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06009045 ha->dpc_flags, cmd->result, cmd->allowed));
9046
9047 stat = qla4xxx_reset_target(ha, ddb_entry);
9048 if (stat != QLA_SUCCESS) {
9049 starget_printk(KERN_INFO, scsi_target(cmd->device),
9050 "WARM TARGET RESET FAILED.\n");
9051 return FAILED;
9052 }
9053
Mike Christiece545032008-02-29 18:25:20 -06009054 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9055 NULL)) {
9056 starget_printk(KERN_INFO, scsi_target(cmd->device),
9057 "WARM TARGET DEVICE RESET FAILED - "
9058 "waiting for commands.\n");
9059 return FAILED;
9060 }
9061
David C Somayajulu9d562912008-03-19 11:23:03 -07009062 /* Send marker. */
9063 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9064 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9065 starget_printk(KERN_INFO, scsi_target(cmd->device),
9066 "WARM TARGET DEVICE RESET FAILED - "
9067 "marker iocb failed.\n");
9068 return FAILED;
9069 }
9070
Mike Christiece545032008-02-29 18:25:20 -06009071 starget_printk(KERN_INFO, scsi_target(cmd->device),
9072 "WARM TARGET RESET SUCCEEDED.\n");
9073 return SUCCESS;
9074}
9075
9076/**
Sarang Radke8a28896012011-12-06 02:34:10 -08009077 * qla4xxx_is_eh_active - check if error handler is running
9078 * @shost: Pointer to SCSI Host struct
9079 *
9080 * This routine finds that if reset host is called in EH
9081 * scenario or from some application like sg_reset
9082 **/
9083static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9084{
9085 if (shost->shost_state == SHOST_RECOVERY)
9086 return 1;
9087 return 0;
9088}
9089
9090/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009091 * qla4xxx_eh_host_reset - kernel callback
9092 * @cmd: Pointer to Linux's SCSI command structure
9093 *
9094 * This routine is invoked by the Linux kernel to perform fatal error
9095 * recovery on the specified adapter.
9096 **/
9097static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9098{
9099 int return_status = FAILED;
9100 struct scsi_qla_host *ha;
9101
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009102 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009103
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009104 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009105 qla4_83xx_set_idc_dontreset(ha);
9106
9107 /*
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009108 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9109 * protocol drivers, we should not set device_state to NEED_RESET
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009110 */
9111 if (ql4xdontresethba ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009112 ((is_qla8032(ha) || is_qla8042(ha)) &&
9113 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309114 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9115 ha->host_no, __func__));
Sarang Radke8a28896012011-12-06 02:34:10 -08009116
9117 /* Clear outstanding srb in queues */
9118 if (qla4xxx_is_eh_active(cmd->device->host))
9119 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9120
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309121 return FAILED;
9122 }
9123
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309124 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05009125 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009126 cmd->device->channel, cmd->device->id, cmd->device->lun);
9127
9128 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9129 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9130 "DEAD.\n", ha->host_no, cmd->device->channel,
9131 __func__));
9132
9133 return FAILED;
9134 }
9135
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309136 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009137 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309138 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9139 else
9140 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9141 }
Mike Christie50a29ae2008-03-04 13:26:53 -06009142
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309143 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009144 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009145
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309146 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009147 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07009148
9149 return return_status;
9150}
9151
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009152static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9153{
9154 uint32_t mbox_cmd[MBOX_REG_COUNT];
9155 uint32_t mbox_sts[MBOX_REG_COUNT];
9156 struct addr_ctrl_blk_def *acb = NULL;
9157 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9158 int rval = QLA_SUCCESS;
9159 dma_addr_t acb_dma;
9160
9161 acb = dma_alloc_coherent(&ha->pdev->dev,
9162 sizeof(struct addr_ctrl_blk_def),
9163 &acb_dma, GFP_KERNEL);
9164 if (!acb) {
9165 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9166 __func__);
9167 rval = -ENOMEM;
9168 goto exit_port_reset;
9169 }
9170
9171 memset(acb, 0, acb_len);
9172
9173 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9174 if (rval != QLA_SUCCESS) {
9175 rval = -EIO;
9176 goto exit_free_acb;
9177 }
9178
9179 rval = qla4xxx_disable_acb(ha);
9180 if (rval != QLA_SUCCESS) {
9181 rval = -EIO;
9182 goto exit_free_acb;
9183 }
9184
9185 wait_for_completion_timeout(&ha->disable_acb_comp,
9186 DISABLE_ACB_TOV * HZ);
9187
9188 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9189 if (rval != QLA_SUCCESS) {
9190 rval = -EIO;
9191 goto exit_free_acb;
9192 }
9193
9194exit_free_acb:
9195 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9196 acb, acb_dma);
9197exit_port_reset:
9198 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9199 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9200 return rval;
9201}
9202
9203static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9204{
9205 struct scsi_qla_host *ha = to_qla_host(shost);
9206 int rval = QLA_SUCCESS;
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009207 uint32_t idc_ctrl;
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009208
9209 if (ql4xdontresethba) {
9210 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9211 __func__));
9212 rval = -EPERM;
9213 goto exit_host_reset;
9214 }
9215
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009216 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9217 goto recover_adapter;
9218
9219 switch (reset_type) {
9220 case SCSI_ADAPTER_RESET:
9221 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9222 break;
9223 case SCSI_FIRMWARE_RESET:
9224 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009225 if (is_qla80XX(ha))
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009226 /* set firmware context reset */
9227 set_bit(DPC_RESET_HA_FW_CONTEXT,
9228 &ha->dpc_flags);
9229 else {
9230 rval = qla4xxx_context_reset(ha);
9231 goto exit_host_reset;
9232 }
9233 }
9234 break;
9235 }
9236
9237recover_adapter:
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009238 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009239 * reset is issued by application */
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009240 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9241 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009242 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9243 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9244 (idc_ctrl | GRACEFUL_RESET_BIT1));
9245 }
9246
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009247 rval = qla4xxx_recover_adapter(ha);
9248 if (rval != QLA_SUCCESS) {
9249 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9250 __func__));
9251 rval = -EIO;
9252 }
9253
9254exit_host_reset:
9255 return rval;
9256}
9257
Lalit Chandivade2232be02010-07-30 14:38:47 +05309258/* PCI AER driver recovers from all correctable errors w/o
9259 * driver intervention. For uncorrectable errors PCI AER
9260 * driver calls the following device driver's callbacks
9261 *
9262 * - Fatal Errors - link_reset
9263 * - Non-Fatal Errors - driver's pci_error_detected() which
9264 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9265 *
9266 * PCI AER driver calls
9267 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
9268 * returns RECOVERED or NEED_RESET if fw_hung
9269 * NEED_RESET - driver's slot_reset()
9270 * DISCONNECT - device is dead & cannot recover
9271 * RECOVERED - driver's pci_resume()
9272 */
9273static pci_ers_result_t
9274qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9275{
9276 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9277
9278 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9279 ha->host_no, __func__, state);
9280
9281 if (!is_aer_supported(ha))
9282 return PCI_ERS_RESULT_NONE;
9283
9284 switch (state) {
9285 case pci_channel_io_normal:
9286 clear_bit(AF_EEH_BUSY, &ha->flags);
9287 return PCI_ERS_RESULT_CAN_RECOVER;
9288 case pci_channel_io_frozen:
9289 set_bit(AF_EEH_BUSY, &ha->flags);
9290 qla4xxx_mailbox_premature_completion(ha);
9291 qla4xxx_free_irqs(ha);
9292 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009293 /* Return back all IOs */
9294 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309295 return PCI_ERS_RESULT_NEED_RESET;
9296 case pci_channel_io_perm_failure:
9297 set_bit(AF_EEH_BUSY, &ha->flags);
9298 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9299 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9300 return PCI_ERS_RESULT_DISCONNECT;
9301 }
9302 return PCI_ERS_RESULT_NEED_RESET;
9303}
9304
9305/**
9306 * qla4xxx_pci_mmio_enabled() gets called if
9307 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9308 * and read/write to the device still works.
9309 **/
9310static pci_ers_result_t
9311qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9312{
9313 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9314
9315 if (!is_aer_supported(ha))
9316 return PCI_ERS_RESULT_NONE;
9317
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009318 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309319}
9320
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009321static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05309322{
9323 uint32_t rval = QLA_ERROR;
9324 int fn;
9325 struct pci_dev *other_pdev = NULL;
9326
9327 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9328
9329 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9330
9331 if (test_bit(AF_ONLINE, &ha->flags)) {
9332 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009333 clear_bit(AF_LINK_UP, &ha->flags);
9334 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309335 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309336 }
9337
9338 fn = PCI_FUNC(ha->pdev->devfn);
9339 while (fn > 0) {
9340 fn--;
9341 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
9342 "func %x\n", ha->host_no, __func__, fn);
9343 /* Get the pci device given the domain, bus,
9344 * slot/function number */
9345 other_pdev =
9346 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
9347 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9348 fn));
9349
9350 if (!other_pdev)
9351 continue;
9352
9353 if (atomic_read(&other_pdev->enable_cnt)) {
9354 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
9355 "func in enabled state%x\n", ha->host_no,
9356 __func__, fn);
9357 pci_dev_put(other_pdev);
9358 break;
9359 }
9360 pci_dev_put(other_pdev);
9361 }
9362
9363 /* The first function on the card, the reset owner will
9364 * start & initialize the firmware. The other functions
9365 * on the card will reset the firmware context
9366 */
9367 if (!fn) {
9368 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9369 "0x%x is the owner\n", ha->host_no, __func__,
9370 ha->pdev->devfn);
9371
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009372 ha->isp_ops->idc_lock(ha);
9373 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9374 QLA8XXX_DEV_COLD);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009375 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309376
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009377 rval = qla4_8xxx_update_idc_reg(ha);
9378 if (rval == QLA_ERROR) {
9379 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9380 ha->host_no, __func__);
9381 ha->isp_ops->idc_lock(ha);
9382 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9383 QLA8XXX_DEV_FAILED);
9384 ha->isp_ops->idc_unlock(ha);
9385 goto exit_error_recovery;
9386 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309387
Lalit Chandivade2232be02010-07-30 14:38:47 +05309388 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009389 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309390
9391 if (rval != QLA_SUCCESS) {
9392 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9393 "FAILED\n", ha->host_no, __func__);
Poornima Vonti82761902012-09-20 07:35:04 -04009394 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309395 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009396 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9397 QLA8XXX_DEV_FAILED);
Poornima Vonti82761902012-09-20 07:35:04 -04009398 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309399 } else {
9400 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9401 "READY\n", ha->host_no, __func__);
Poornima Vonti82761902012-09-20 07:35:04 -04009402 ha->isp_ops->idc_lock(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009403 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9404 QLA8XXX_DEV_READY);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309405 /* Clear driver state register */
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009406 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309407 qla4_8xxx_set_drv_active(ha);
Poornima Vonti82761902012-09-20 07:35:04 -04009408 ha->isp_ops->idc_unlock(ha);
Poornima Vonti137257d2013-01-20 23:51:01 -05009409 ha->isp_ops->enable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309410 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309411 } else {
9412 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9413 "the reset owner\n", ha->host_no, __func__,
9414 ha->pdev->devfn);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009415 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9416 QLA8XXX_DEV_READY)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309417 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009418 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Poornima Vonti137257d2013-01-20 23:51:01 -05009419 if (rval == QLA_SUCCESS)
9420 ha->isp_ops->enable_intrs(ha);
9421
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009422 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309423 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009424 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309425 }
9426 }
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009427exit_error_recovery:
Lalit Chandivade2232be02010-07-30 14:38:47 +05309428 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9429 return rval;
9430}
9431
9432static pci_ers_result_t
9433qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9434{
9435 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9436 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9437 int rc;
9438
9439 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9440 ha->host_no, __func__);
9441
9442 if (!is_aer_supported(ha))
9443 return PCI_ERS_RESULT_NONE;
9444
9445 /* Restore the saved state of PCIe device -
9446 * BAR registers, PCI Config space, PCIX, MSI,
9447 * IOV states
9448 */
9449 pci_restore_state(pdev);
9450
9451 /* pci_restore_state() clears the saved_state flag of the device
9452 * save restored state which resets saved_state flag
9453 */
9454 pci_save_state(pdev);
9455
9456 /* Initialize device or resume if in suspended state */
9457 rc = pci_enable_device(pdev);
9458 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009459 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05309460 "device after reset\n", ha->host_no, __func__);
9461 goto exit_slot_reset;
9462 }
9463
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009464 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309465
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009466 if (is_qla80XX(ha)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309467 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9468 ret = PCI_ERS_RESULT_RECOVERED;
9469 goto exit_slot_reset;
9470 } else
9471 goto exit_slot_reset;
9472 }
9473
9474exit_slot_reset:
9475 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9476 "device after reset\n", ha->host_no, __func__, ret);
9477 return ret;
9478}
9479
9480static void
9481qla4xxx_pci_resume(struct pci_dev *pdev)
9482{
9483 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9484 int ret;
9485
9486 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9487 ha->host_no, __func__);
9488
9489 ret = qla4xxx_wait_for_hba_online(ha);
9490 if (ret != QLA_SUCCESS) {
9491 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9492 "resume I/O from slot/link_reset\n", ha->host_no,
9493 __func__);
9494 }
9495
9496 pci_cleanup_aer_uncorrect_error_status(pdev);
9497 clear_bit(AF_EEH_BUSY, &ha->flags);
9498}
9499
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07009500static const struct pci_error_handlers qla4xxx_err_handler = {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309501 .error_detected = qla4xxx_pci_error_detected,
9502 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9503 .slot_reset = qla4xxx_pci_slot_reset,
9504 .resume = qla4xxx_pci_resume,
9505};
9506
David Somayajuluafaf5a22006-09-19 10:28:00 -07009507static struct pci_device_id qla4xxx_pci_tbl[] = {
9508 {
9509 .vendor = PCI_VENDOR_ID_QLOGIC,
9510 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9511 .subvendor = PCI_ANY_ID,
9512 .subdevice = PCI_ANY_ID,
9513 },
9514 {
9515 .vendor = PCI_VENDOR_ID_QLOGIC,
9516 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9517 .subvendor = PCI_ANY_ID,
9518 .subdevice = PCI_ANY_ID,
9519 },
David C Somayajulud9150582006-11-15 17:38:40 -08009520 {
9521 .vendor = PCI_VENDOR_ID_QLOGIC,
9522 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9523 .subvendor = PCI_ANY_ID,
9524 .subdevice = PCI_ANY_ID,
9525 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309526 {
9527 .vendor = PCI_VENDOR_ID_QLOGIC,
9528 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9529 .subvendor = PCI_ANY_ID,
9530 .subdevice = PCI_ANY_ID,
9531 },
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009532 {
9533 .vendor = PCI_VENDOR_ID_QLOGIC,
9534 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9535 .subvendor = PCI_ANY_ID,
9536 .subdevice = PCI_ANY_ID,
9537 },
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009538 {
9539 .vendor = PCI_VENDOR_ID_QLOGIC,
9540 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9541 .subvendor = PCI_ANY_ID,
9542 .subdevice = PCI_ANY_ID,
9543 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07009544 {0, 0},
9545};
9546MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9547
Adrian Bunk47975472007-04-26 00:35:16 -07009548static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009549 .name = DRIVER_NAME,
9550 .id_table = qla4xxx_pci_tbl,
9551 .probe = qla4xxx_probe_adapter,
9552 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05309553 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009554};
9555
9556static int __init qla4xxx_module_init(void)
9557{
9558 int ret;
9559
9560 /* Allocate cache for SRBs. */
9561 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09009562 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009563 if (srb_cachep == NULL) {
9564 printk(KERN_ERR
9565 "%s: Unable to allocate SRB cache..."
9566 "Failing load!\n", DRIVER_NAME);
9567 ret = -ENOMEM;
9568 goto no_srp_cache;
9569 }
9570
9571 /* Derive version string. */
9572 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07009573 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009574 strcat(qla4xxx_version_str, "-debug");
9575
9576 qla4xxx_scsi_transport =
9577 iscsi_register_transport(&qla4xxx_iscsi_transport);
9578 if (!qla4xxx_scsi_transport){
9579 ret = -ENODEV;
9580 goto release_srb_cache;
9581 }
9582
David Somayajuluafaf5a22006-09-19 10:28:00 -07009583 ret = pci_register_driver(&qla4xxx_pci_driver);
9584 if (ret)
9585 goto unregister_transport;
9586
9587 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9588 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05009589
David Somayajuluafaf5a22006-09-19 10:28:00 -07009590unregister_transport:
9591 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9592release_srb_cache:
9593 kmem_cache_destroy(srb_cachep);
9594no_srp_cache:
9595 return ret;
9596}
9597
9598static void __exit qla4xxx_module_exit(void)
9599{
David Somayajuluafaf5a22006-09-19 10:28:00 -07009600 pci_unregister_driver(&qla4xxx_pci_driver);
9601 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9602 kmem_cache_destroy(srb_cachep);
9603}
9604
9605module_init(qla4xxx_module_init);
9606module_exit(qla4xxx_module_exit);
9607
9608MODULE_AUTHOR("QLogic Corporation");
9609MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9610MODULE_LICENSE("GPL");
9611MODULE_VERSION(QLA4XXX_DRIVER_VERSION);