blob: 3fec116e2724f29e5c8a1e5afe1cd6b243561959 [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);
Lalit Chandivade4161cee2013-11-22 05:28:19 -0500154static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530155
David Somayajuluafaf5a22006-09-19 10:28:00 -0700156/*
157 * SCSI host template entry points
158 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500159static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530160static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700161static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -0600162static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700163static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164static int qla4xxx_slave_alloc(struct scsi_device *device);
165static int qla4xxx_slave_configure(struct scsi_device *device);
166static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400167static umode_t qla4_attr_is_visible(int param_type, int param);
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700168static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
Tej Parkashf7b4aa62012-04-30 04:12:19 -0700169static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
170 int reason);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700171
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400172/*
173 * iSCSI Flash DDB sysfs entry points
174 */
175static int
176qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
177 struct iscsi_bus_flash_conn *fnode_conn,
178 void *data, int len);
179static int
180qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
181 int param, char *buf);
182static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
183 int len);
184static int
185qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
186static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
187 struct iscsi_bus_flash_conn *fnode_conn);
188static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
189 struct iscsi_bus_flash_conn *fnode_conn);
190static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
191
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530192static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
193 QLA82XX_LEGACY_INTR_CONFIG;
194
David Somayajuluafaf5a22006-09-19 10:28:00 -0700195static struct scsi_host_template qla4xxx_driver_template = {
196 .module = THIS_MODULE,
197 .name = DRIVER_NAME,
198 .proc_name = DRIVER_NAME,
199 .queuecommand = qla4xxx_queuecommand,
200
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530201 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700202 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600203 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700204 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500205 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700206
207 .slave_configure = qla4xxx_slave_configure,
208 .slave_alloc = qla4xxx_slave_alloc,
209 .slave_destroy = qla4xxx_slave_destroy,
Tej Parkashf7b4aa62012-04-30 04:12:19 -0700210 .change_queue_depth = qla4xxx_change_queue_depth,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700211
212 .this_id = -1,
213 .cmd_per_lun = 3,
214 .use_clustering = ENABLE_CLUSTERING,
215 .sg_tablesize = SG_ALL,
216
217 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700218 .shost_attrs = qla4xxx_host_attrs,
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700219 .host_reset = qla4xxx_host_reset,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500220 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700221};
222
223static struct iscsi_transport qla4xxx_iscsi_transport = {
224 .owner = THIS_MODULE,
225 .name = DRIVER_NAME,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500226 .caps = CAP_TEXT_NEGO |
227 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
228 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
229 CAP_MULTI_R2T,
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400230 .attr_is_visible = qla4_attr_is_visible,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500231 .create_session = qla4xxx_session_create,
232 .destroy_session = qla4xxx_session_destroy,
233 .start_conn = qla4xxx_conn_start,
234 .create_conn = qla4xxx_conn_create,
235 .bind_conn = qla4xxx_conn_bind,
236 .stop_conn = iscsi_conn_stop,
237 .destroy_conn = qla4xxx_conn_destroy,
238 .set_param = iscsi_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700239 .get_conn_param = qla4xxx_conn_get_param,
Mike Christiefca9f042012-02-27 03:08:54 -0800240 .get_session_param = qla4xxx_session_get_param,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500241 .get_ep_param = qla4xxx_get_ep_param,
242 .ep_connect = qla4xxx_ep_connect,
243 .ep_poll = qla4xxx_ep_poll,
244 .ep_disconnect = qla4xxx_ep_disconnect,
245 .get_stats = qla4xxx_conn_get_stats,
246 .send_pdu = iscsi_conn_send_pdu,
247 .xmit_task = qla4xxx_task_xmit,
248 .cleanup_task = qla4xxx_task_cleanup,
249 .alloc_pdu = qla4xxx_alloc_pdu,
250
Mike Christieaa1e93a2007-05-30 12:57:09 -0500251 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500252 .set_iface_param = qla4xxx_iface_set_param,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500253 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500254 .bsg_request = qla4xxx_bsg_request,
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530255 .send_ping = qla4xxx_send_ping,
Nilesh Javali376738a2012-02-27 03:08:52 -0800256 .get_chap = qla4xxx_get_chap_list,
257 .delete_chap = qla4xxx_delete_chap,
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400258 .set_chap = qla4xxx_set_chap_entry,
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400259 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
260 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
261 .new_flashnode = qla4xxx_sysfs_ddb_add,
262 .del_flashnode = qla4xxx_sysfs_ddb_delete,
263 .login_flashnode = qla4xxx_sysfs_ddb_login,
264 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
265 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
Lalit Chandivade4161cee2013-11-22 05:28:19 -0500266 .get_host_stats = qla4xxx_get_host_stats,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700267};
268
269static struct scsi_transport_template *qla4xxx_scsi_transport;
270
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +0530271static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
272 uint32_t iface_type, uint32_t payload_size,
273 uint32_t pid, struct sockaddr *dst_addr)
274{
275 struct scsi_qla_host *ha = to_qla_host(shost);
276 struct sockaddr_in *addr;
277 struct sockaddr_in6 *addr6;
278 uint32_t options = 0;
279 uint8_t ipaddr[IPv6_ADDR_LEN];
280 int rval;
281
282 memset(ipaddr, 0, IPv6_ADDR_LEN);
283 /* IPv4 to IPv4 */
284 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
285 (dst_addr->sa_family == AF_INET)) {
286 addr = (struct sockaddr_in *)dst_addr;
287 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
288 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
289 "dest: %pI4\n", __func__,
290 &ha->ip_config.ip_address, ipaddr));
291 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
292 ipaddr);
293 if (rval)
294 rval = -EINVAL;
295 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
296 (dst_addr->sa_family == AF_INET6)) {
297 /* IPv6 to IPv6 */
298 addr6 = (struct sockaddr_in6 *)dst_addr;
299 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
300
301 options |= PING_IPV6_PROTOCOL_ENABLE;
302
303 /* Ping using LinkLocal address */
304 if ((iface_num == 0) || (iface_num == 1)) {
305 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
306 "src: %pI6 dest: %pI6\n", __func__,
307 &ha->ip_config.ipv6_link_local_addr,
308 ipaddr));
309 options |= PING_IPV6_LINKLOCAL_ADDR;
310 rval = qla4xxx_ping_iocb(ha, options, payload_size,
311 pid, ipaddr);
312 } else {
313 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
314 "not supported\n", __func__, iface_num);
315 rval = -ENOSYS;
316 goto exit_send_ping;
317 }
318
319 /*
320 * If ping using LinkLocal address fails, try ping using
321 * IPv6 address
322 */
323 if (rval != QLA_SUCCESS) {
324 options &= ~PING_IPV6_LINKLOCAL_ADDR;
325 if (iface_num == 0) {
326 options |= PING_IPV6_ADDR0;
327 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
328 "Ping src: %pI6 "
329 "dest: %pI6\n", __func__,
330 &ha->ip_config.ipv6_addr0,
331 ipaddr));
332 } else if (iface_num == 1) {
333 options |= PING_IPV6_ADDR1;
334 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
335 "Ping src: %pI6 "
336 "dest: %pI6\n", __func__,
337 &ha->ip_config.ipv6_addr1,
338 ipaddr));
339 }
340 rval = qla4xxx_ping_iocb(ha, options, payload_size,
341 pid, ipaddr);
342 if (rval)
343 rval = -EINVAL;
344 }
345 } else
346 rval = -ENOSYS;
347exit_send_ping:
348 return rval;
349}
350
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -0400351static umode_t qla4_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -0500352{
353 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500354 case ISCSI_HOST_PARAM:
355 switch (param) {
356 case ISCSI_HOST_PARAM_HWADDRESS:
357 case ISCSI_HOST_PARAM_IPADDRESS:
358 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -0800359 case ISCSI_HOST_PARAM_PORT_STATE:
360 case ISCSI_HOST_PARAM_PORT_SPEED:
Mike Christief27fb2e2011-07-25 13:48:45 -0500361 return S_IRUGO;
362 default:
363 return 0;
364 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500365 case ISCSI_PARAM:
366 switch (param) {
Mike Christie590134f2011-10-17 22:42:13 -0500367 case ISCSI_PARAM_PERSISTENT_ADDRESS:
368 case ISCSI_PARAM_PERSISTENT_PORT:
Mike Christie3128c6c2011-07-25 13:48:42 -0500369 case ISCSI_PARAM_CONN_ADDRESS:
370 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500371 case ISCSI_PARAM_TARGET_NAME:
372 case ISCSI_PARAM_TPGT:
373 case ISCSI_PARAM_TARGET_ALIAS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500374 case ISCSI_PARAM_MAX_BURST:
375 case ISCSI_PARAM_MAX_R2T:
376 case ISCSI_PARAM_FIRST_BURST:
377 case ISCSI_PARAM_MAX_RECV_DLENGTH:
378 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Mike Christiede379202011-08-14 20:42:56 -0500379 case ISCSI_PARAM_IFACE_NAME:
Mike Christiefca9f042012-02-27 03:08:54 -0800380 case ISCSI_PARAM_CHAP_OUT_IDX:
381 case ISCSI_PARAM_CHAP_IN_IDX:
382 case ISCSI_PARAM_USERNAME:
383 case ISCSI_PARAM_PASSWORD:
384 case ISCSI_PARAM_USERNAME_IN:
385 case ISCSI_PARAM_PASSWORD_IN:
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -0400386 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
387 case ISCSI_PARAM_DISCOVERY_SESS:
388 case ISCSI_PARAM_PORTAL_TYPE:
389 case ISCSI_PARAM_CHAP_AUTH_EN:
390 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
391 case ISCSI_PARAM_BIDI_CHAP_EN:
392 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
393 case ISCSI_PARAM_DEF_TIME2WAIT:
394 case ISCSI_PARAM_DEF_TIME2RETAIN:
395 case ISCSI_PARAM_HDRDGST_EN:
396 case ISCSI_PARAM_DATADGST_EN:
397 case ISCSI_PARAM_INITIAL_R2T_EN:
398 case ISCSI_PARAM_IMM_DATA_EN:
399 case ISCSI_PARAM_PDU_INORDER_EN:
400 case ISCSI_PARAM_DATASEQ_INORDER_EN:
401 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
402 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
403 case ISCSI_PARAM_TCP_WSF_DISABLE:
404 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
405 case ISCSI_PARAM_TCP_TIMER_SCALE:
406 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
407 case ISCSI_PARAM_TCP_XMIT_WSF:
408 case ISCSI_PARAM_TCP_RECV_WSF:
409 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
410 case ISCSI_PARAM_IPV4_TOS:
411 case ISCSI_PARAM_IPV6_TC:
412 case ISCSI_PARAM_IPV6_FLOW_LABEL:
413 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
414 case ISCSI_PARAM_KEEPALIVE_TMO:
415 case ISCSI_PARAM_LOCAL_PORT:
416 case ISCSI_PARAM_ISID:
417 case ISCSI_PARAM_TSID:
418 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
419 case ISCSI_PARAM_ERL:
420 case ISCSI_PARAM_STATSN:
421 case ISCSI_PARAM_EXP_STATSN:
422 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
423 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
Adheer Chandravanshifb734ee32013-11-22 05:28:22 -0500424 case ISCSI_PARAM_LOCAL_IPADDR:
Mike Christie3128c6c2011-07-25 13:48:42 -0500425 return S_IRUGO;
426 default:
427 return 0;
428 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500429 case ISCSI_NET_PARAM:
430 switch (param) {
431 case ISCSI_NET_PARAM_IPV4_ADDR:
432 case ISCSI_NET_PARAM_IPV4_SUBNET:
433 case ISCSI_NET_PARAM_IPV4_GW:
434 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
435 case ISCSI_NET_PARAM_IFACE_ENABLE:
436 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
437 case ISCSI_NET_PARAM_IPV6_ADDR:
438 case ISCSI_NET_PARAM_IPV6_ROUTER:
439 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
440 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500441 case ISCSI_NET_PARAM_VLAN_ID:
442 case ISCSI_NET_PARAM_VLAN_PRIORITY:
443 case ISCSI_NET_PARAM_VLAN_ENABLED:
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700444 case ISCSI_NET_PARAM_MTU:
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700445 case ISCSI_NET_PARAM_PORT:
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400446 case ISCSI_NET_PARAM_IPADDR_STATE:
447 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
448 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
449 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
450 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
451 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
452 case ISCSI_NET_PARAM_TCP_WSF:
453 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
454 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
455 case ISCSI_NET_PARAM_CACHE_ID:
456 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
457 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
458 case ISCSI_NET_PARAM_IPV4_TOS_EN:
459 case ISCSI_NET_PARAM_IPV4_TOS:
460 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
461 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
462 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
463 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
464 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
465 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
466 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
467 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
468 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
469 case ISCSI_NET_PARAM_REDIRECT_EN:
470 case ISCSI_NET_PARAM_IPV4_TTL:
471 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
472 case ISCSI_NET_PARAM_IPV6_MLD_EN:
473 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
474 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
475 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
476 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
477 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
478 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
479 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
480 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
481 return S_IRUGO;
482 default:
483 return 0;
484 }
485 case ISCSI_IFACE_PARAM:
486 switch (param) {
487 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
488 case ISCSI_IFACE_PARAM_HDRDGST_EN:
489 case ISCSI_IFACE_PARAM_DATADGST_EN:
490 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
491 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
492 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
493 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
494 case ISCSI_IFACE_PARAM_ERL:
495 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
496 case ISCSI_IFACE_PARAM_FIRST_BURST:
497 case ISCSI_IFACE_PARAM_MAX_R2T:
498 case ISCSI_IFACE_PARAM_MAX_BURST:
499 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
500 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
501 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
502 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
503 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
504 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
Mike Christieb78dbba2011-07-25 13:48:44 -0500505 return S_IRUGO;
506 default:
507 return 0;
508 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400509 case ISCSI_FLASHNODE_PARAM:
510 switch (param) {
511 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
512 case ISCSI_FLASHNODE_PORTAL_TYPE:
513 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
514 case ISCSI_FLASHNODE_DISCOVERY_SESS:
515 case ISCSI_FLASHNODE_ENTRY_EN:
516 case ISCSI_FLASHNODE_HDR_DGST_EN:
517 case ISCSI_FLASHNODE_DATA_DGST_EN:
518 case ISCSI_FLASHNODE_IMM_DATA_EN:
519 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
520 case ISCSI_FLASHNODE_DATASEQ_INORDER:
521 case ISCSI_FLASHNODE_PDU_INORDER:
522 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
523 case ISCSI_FLASHNODE_SNACK_REQ_EN:
524 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
525 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
526 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
527 case ISCSI_FLASHNODE_ERL:
528 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
529 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
530 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
531 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
532 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
533 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
534 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
535 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
536 case ISCSI_FLASHNODE_FIRST_BURST:
537 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
538 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
539 case ISCSI_FLASHNODE_MAX_R2T:
540 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
541 case ISCSI_FLASHNODE_ISID:
542 case ISCSI_FLASHNODE_TSID:
543 case ISCSI_FLASHNODE_PORT:
544 case ISCSI_FLASHNODE_MAX_BURST:
545 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
546 case ISCSI_FLASHNODE_IPADDR:
547 case ISCSI_FLASHNODE_ALIAS:
548 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
549 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
550 case ISCSI_FLASHNODE_LOCAL_PORT:
551 case ISCSI_FLASHNODE_IPV4_TOS:
552 case ISCSI_FLASHNODE_IPV6_TC:
553 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
554 case ISCSI_FLASHNODE_NAME:
555 case ISCSI_FLASHNODE_TPGT:
556 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
557 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
558 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
559 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
560 case ISCSI_FLASHNODE_TCP_RECV_WSF:
561 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
562 case ISCSI_FLASHNODE_USERNAME:
563 case ISCSI_FLASHNODE_PASSWORD:
564 case ISCSI_FLASHNODE_STATSN:
565 case ISCSI_FLASHNODE_EXP_STATSN:
566 case ISCSI_FLASHNODE_IS_BOOT_TGT:
567 return S_IRUGO;
568 default:
569 return 0;
570 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500571 }
572
573 return 0;
574}
575
Adheer Chandravanshiea507a22013-11-22 05:28:23 -0500576/**
577 * qla4xxx_create chap_list - Create CHAP list from FLASH
578 * @ha: pointer to adapter structure
579 *
580 * Read flash and make a list of CHAP entries, during login when a CHAP entry
581 * is received, it will be checked in this list. If entry exist then the CHAP
582 * entry index is set in the DDB. If CHAP entry does not exist in this list
583 * then a new entry is added in FLASH in CHAP table and the index obtained is
584 * used in the DDB.
585 **/
586static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
587{
588 int rval = 0;
589 uint8_t *chap_flash_data = NULL;
590 uint32_t offset;
591 dma_addr_t chap_dma;
592 uint32_t chap_size = 0;
593
594 if (is_qla40XX(ha))
595 chap_size = MAX_CHAP_ENTRIES_40XX *
596 sizeof(struct ql4_chap_table);
597 else /* Single region contains CHAP info for both
598 * ports which is divided into half for each port.
599 */
600 chap_size = ha->hw.flt_chap_size / 2;
601
602 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
603 &chap_dma, GFP_KERNEL);
604 if (!chap_flash_data) {
605 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
606 return;
607 }
608
609 if (is_qla40XX(ha)) {
610 offset = FLASH_CHAP_OFFSET;
611 } else {
612 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
613 if (ha->port_num == 1)
614 offset += chap_size;
615 }
616
617 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
618 if (rval != QLA_SUCCESS)
619 goto exit_chap_list;
620
621 if (ha->chap_list == NULL)
622 ha->chap_list = vmalloc(chap_size);
623 if (ha->chap_list == NULL) {
624 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
625 goto exit_chap_list;
626 }
627
628 memset(ha->chap_list, 0, chap_size);
629 memcpy(ha->chap_list, chap_flash_data, chap_size);
630
631exit_chap_list:
632 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
633}
634
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400635static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
636 int16_t chap_index,
637 struct ql4_chap_table **chap_entry)
638{
639 int rval = QLA_ERROR;
640 int max_chap_entries;
641
642 if (!ha->chap_list) {
643 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
644 rval = QLA_ERROR;
645 goto exit_get_chap;
646 }
647
648 if (is_qla80XX(ha))
649 max_chap_entries = (ha->hw.flt_chap_size / 2) /
650 sizeof(struct ql4_chap_table);
651 else
652 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
653
654 if (chap_index > max_chap_entries) {
655 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
656 rval = QLA_ERROR;
657 goto exit_get_chap;
658 }
659
660 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
661 if ((*chap_entry)->cookie !=
662 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
663 rval = QLA_ERROR;
664 *chap_entry = NULL;
665 } else {
666 rval = QLA_SUCCESS;
667 }
668
669exit_get_chap:
670 return rval;
671}
672
673/**
674 * qla4xxx_find_free_chap_index - Find the first free chap index
675 * @ha: pointer to adapter structure
676 * @chap_index: CHAP index to be returned
677 *
678 * Find the first free chap index available in the chap table
679 *
680 * Note: Caller should acquire the chap lock before getting here.
681 **/
682static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
683 uint16_t *chap_index)
684{
685 int i, rval;
686 int free_index = -1;
687 int max_chap_entries = 0;
688 struct ql4_chap_table *chap_table;
689
690 if (is_qla80XX(ha))
691 max_chap_entries = (ha->hw.flt_chap_size / 2) /
692 sizeof(struct ql4_chap_table);
693 else
694 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
695
696 if (!ha->chap_list) {
697 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
698 rval = QLA_ERROR;
699 goto exit_find_chap;
700 }
701
702 for (i = 0; i < max_chap_entries; i++) {
703 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
704
705 if ((chap_table->cookie !=
706 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
707 (i > MAX_RESRV_CHAP_IDX)) {
708 free_index = i;
709 break;
710 }
711 }
712
713 if (free_index != -1) {
714 *chap_index = free_index;
715 rval = QLA_SUCCESS;
716 } else {
717 rval = QLA_ERROR;
718 }
719
720exit_find_chap:
721 return rval;
722}
723
Nilesh Javali376738a2012-02-27 03:08:52 -0800724static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
725 uint32_t *num_entries, char *buf)
726{
727 struct scsi_qla_host *ha = to_qla_host(shost);
728 struct ql4_chap_table *chap_table;
729 struct iscsi_chap_rec *chap_rec;
730 int max_chap_entries = 0;
731 int valid_chap_entries = 0;
732 int ret = 0, i;
733
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400734 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800735 max_chap_entries = (ha->hw.flt_chap_size / 2) /
736 sizeof(struct ql4_chap_table);
737 else
738 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
739
740 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
741 __func__, *num_entries, chap_tbl_idx);
742
743 if (!buf) {
744 ret = -ENOMEM;
745 goto exit_get_chap_list;
746 }
747
Adheer Chandravanshiea507a22013-11-22 05:28:23 -0500748 qla4xxx_create_chap_list(ha);
749
Nilesh Javali376738a2012-02-27 03:08:52 -0800750 chap_rec = (struct iscsi_chap_rec *) buf;
751 mutex_lock(&ha->chap_sem);
752 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
753 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
754 if (chap_table->cookie !=
755 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
756 continue;
757
758 chap_rec->chap_tbl_idx = i;
759 strncpy(chap_rec->username, chap_table->name,
760 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
761 strncpy(chap_rec->password, chap_table->secret,
762 QL4_CHAP_MAX_SECRET_LEN);
763 chap_rec->password_length = chap_table->secret_len;
764
765 if (chap_table->flags & BIT_7) /* local */
766 chap_rec->chap_type = CHAP_TYPE_OUT;
767
768 if (chap_table->flags & BIT_6) /* peer */
769 chap_rec->chap_type = CHAP_TYPE_IN;
770
771 chap_rec++;
772
773 valid_chap_entries++;
774 if (valid_chap_entries == *num_entries)
775 break;
776 else
777 continue;
778 }
779 mutex_unlock(&ha->chap_sem);
780
781exit_get_chap_list:
782 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
783 __func__, valid_chap_entries);
784 *num_entries = valid_chap_entries;
785 return ret;
786}
787
788static int __qla4xxx_is_chap_active(struct device *dev, void *data)
789{
790 int ret = 0;
791 uint16_t *chap_tbl_idx = (uint16_t *) data;
792 struct iscsi_cls_session *cls_session;
793 struct iscsi_session *sess;
794 struct ddb_entry *ddb_entry;
795
796 if (!iscsi_is_session_dev(dev))
797 goto exit_is_chap_active;
798
799 cls_session = iscsi_dev_to_session(dev);
800 sess = cls_session->dd_data;
801 ddb_entry = sess->dd_data;
802
803 if (iscsi_session_chkready(cls_session))
804 goto exit_is_chap_active;
805
806 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
807 ret = 1;
808
809exit_is_chap_active:
810 return ret;
811}
812
813static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
814 uint16_t chap_tbl_idx)
815{
816 int ret = 0;
817
818 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
819 __qla4xxx_is_chap_active);
820
821 return ret;
822}
823
824static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
825{
826 struct scsi_qla_host *ha = to_qla_host(shost);
827 struct ql4_chap_table *chap_table;
828 dma_addr_t chap_dma;
829 int max_chap_entries = 0;
830 uint32_t offset = 0;
831 uint32_t chap_size;
832 int ret = 0;
833
834 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
835 if (chap_table == NULL)
836 return -ENOMEM;
837
838 memset(chap_table, 0, sizeof(struct ql4_chap_table));
839
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400840 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800841 max_chap_entries = (ha->hw.flt_chap_size / 2) /
842 sizeof(struct ql4_chap_table);
843 else
844 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
845
846 if (chap_tbl_idx > max_chap_entries) {
847 ret = -EINVAL;
848 goto exit_delete_chap;
849 }
850
851 /* Check if chap index is in use.
852 * If chap is in use don't delet chap entry */
853 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
854 if (ret) {
855 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
856 "delete from flash\n", chap_tbl_idx);
857 ret = -EBUSY;
858 goto exit_delete_chap;
859 }
860
861 chap_size = sizeof(struct ql4_chap_table);
862 if (is_qla40XX(ha))
863 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
864 else {
865 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
866 /* flt_chap_size is CHAP table size for both ports
867 * so divide it by 2 to calculate the offset for second port
868 */
869 if (ha->port_num == 1)
870 offset += (ha->hw.flt_chap_size / 2);
871 offset += (chap_tbl_idx * chap_size);
872 }
873
874 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
875 if (ret != QLA_SUCCESS) {
876 ret = -EINVAL;
877 goto exit_delete_chap;
878 }
879
880 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
881 __le16_to_cpu(chap_table->cookie)));
882
883 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
884 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
885 goto exit_delete_chap;
886 }
887
888 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
889
890 offset = FLASH_CHAP_OFFSET |
891 (chap_tbl_idx * sizeof(struct ql4_chap_table));
892 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
893 FLASH_OPT_RMW_COMMIT);
894 if (ret == QLA_SUCCESS && ha->chap_list) {
895 mutex_lock(&ha->chap_sem);
896 /* Update ha chap_list cache */
897 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
898 chap_table, sizeof(struct ql4_chap_table));
899 mutex_unlock(&ha->chap_sem);
900 }
901 if (ret != QLA_SUCCESS)
902 ret = -EINVAL;
903
904exit_delete_chap:
905 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
906 return ret;
907}
908
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400909/**
910 * qla4xxx_set_chap_entry - Make chap entry with given information
911 * @shost: pointer to host
912 * @data: chap info - credentials, index and type to make chap entry
913 * @len: length of data
914 *
915 * Add or update chap entry with the given information
916 **/
917static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
918{
919 struct scsi_qla_host *ha = to_qla_host(shost);
920 struct iscsi_chap_rec chap_rec;
921 struct ql4_chap_table *chap_entry = NULL;
922 struct iscsi_param_info *param_info;
923 struct nlattr *attr;
924 int max_chap_entries = 0;
925 int type;
926 int rem = len;
927 int rc = 0;
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300928 int size;
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400929
930 memset(&chap_rec, 0, sizeof(chap_rec));
931
932 nla_for_each_attr(attr, data, len, rem) {
933 param_info = nla_data(attr);
934
935 switch (param_info->param) {
936 case ISCSI_CHAP_PARAM_INDEX:
937 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
938 break;
939 case ISCSI_CHAP_PARAM_CHAP_TYPE:
940 chap_rec.chap_type = param_info->value[0];
941 break;
942 case ISCSI_CHAP_PARAM_USERNAME:
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300943 size = min_t(size_t, sizeof(chap_rec.username),
944 param_info->len);
945 memcpy(chap_rec.username, param_info->value, size);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400946 break;
947 case ISCSI_CHAP_PARAM_PASSWORD:
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300948 size = min_t(size_t, sizeof(chap_rec.password),
949 param_info->len);
950 memcpy(chap_rec.password, param_info->value, size);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400951 break;
952 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
953 chap_rec.password_length = param_info->value[0];
954 break;
955 default:
956 ql4_printk(KERN_ERR, ha,
957 "%s: No such sysfs attribute\n", __func__);
958 rc = -ENOSYS;
959 goto exit_set_chap;
960 };
961 }
962
963 if (chap_rec.chap_type == CHAP_TYPE_IN)
964 type = BIDI_CHAP;
965 else
966 type = LOCAL_CHAP;
967
968 if (is_qla80XX(ha))
969 max_chap_entries = (ha->hw.flt_chap_size / 2) /
970 sizeof(struct ql4_chap_table);
971 else
972 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
973
974 mutex_lock(&ha->chap_sem);
975 if (chap_rec.chap_tbl_idx < max_chap_entries) {
976 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
977 &chap_entry);
978 if (!rc) {
979 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
980 ql4_printk(KERN_INFO, ha,
981 "Type mismatch for CHAP entry %d\n",
982 chap_rec.chap_tbl_idx);
983 rc = -EINVAL;
984 goto exit_unlock_chap;
985 }
986
987 /* If chap index is in use then don't modify it */
988 rc = qla4xxx_is_chap_active(shost,
989 chap_rec.chap_tbl_idx);
990 if (rc) {
991 ql4_printk(KERN_INFO, ha,
992 "CHAP entry %d is in use\n",
993 chap_rec.chap_tbl_idx);
994 rc = -EBUSY;
995 goto exit_unlock_chap;
996 }
997 }
998 } else {
999 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1000 if (rc) {
1001 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1002 rc = -EBUSY;
1003 goto exit_unlock_chap;
1004 }
1005 }
1006
1007 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1008 chap_rec.chap_tbl_idx, type);
1009
1010exit_unlock_chap:
1011 mutex_unlock(&ha->chap_sem);
1012
1013exit_set_chap:
1014 return rc;
1015}
1016
Lalit Chandivade4161cee2013-11-22 05:28:19 -05001017
1018static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1019{
1020 struct scsi_qla_host *ha = to_qla_host(shost);
1021 struct iscsi_offload_host_stats *host_stats = NULL;
1022 int host_stats_size;
1023 int ret = 0;
1024 int ddb_idx = 0;
1025 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1026 int stats_size;
1027 dma_addr_t iscsi_stats_dma;
1028
1029 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1030
1031 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1032
1033 if (host_stats_size != len) {
1034 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1035 __func__, len, host_stats_size);
1036 ret = -EINVAL;
1037 goto exit_host_stats;
1038 }
1039 host_stats = (struct iscsi_offload_host_stats *)buf;
1040
1041 if (!buf) {
1042 ret = -ENOMEM;
1043 goto exit_host_stats;
1044 }
1045
1046 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1047
1048 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1049 &iscsi_stats_dma, GFP_KERNEL);
1050 if (!ql_iscsi_stats) {
1051 ql4_printk(KERN_ERR, ha,
1052 "Unable to allocate memory for iscsi stats\n");
1053 goto exit_host_stats;
1054 }
1055
1056 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1057 iscsi_stats_dma);
1058 if (ret != QLA_SUCCESS) {
1059 ql4_printk(KERN_ERR, ha,
1060 "Unable to retrieve iscsi stats\n");
1061 goto exit_host_stats;
1062 }
1063 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1064 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1065 host_stats->mactx_multicast_frames =
1066 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1067 host_stats->mactx_broadcast_frames =
1068 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1069 host_stats->mactx_pause_frames =
1070 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1071 host_stats->mactx_control_frames =
1072 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1073 host_stats->mactx_deferral =
1074 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1075 host_stats->mactx_excess_deferral =
1076 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1077 host_stats->mactx_late_collision =
1078 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1079 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1080 host_stats->mactx_single_collision =
1081 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1082 host_stats->mactx_multiple_collision =
1083 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1084 host_stats->mactx_collision =
1085 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1086 host_stats->mactx_frames_dropped =
1087 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1088 host_stats->mactx_jumbo_frames =
1089 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1090 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1091 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1092 host_stats->macrx_unknown_control_frames =
1093 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1094 host_stats->macrx_pause_frames =
1095 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1096 host_stats->macrx_control_frames =
1097 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1098 host_stats->macrx_dribble =
1099 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1100 host_stats->macrx_frame_length_error =
1101 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1102 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1103 host_stats->macrx_carrier_sense_error =
1104 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1105 host_stats->macrx_frame_discarded =
1106 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1107 host_stats->macrx_frames_dropped =
1108 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1109 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1110 host_stats->mac_encoding_error =
1111 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1112 host_stats->macrx_length_error_large =
1113 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1114 host_stats->macrx_length_error_small =
1115 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1116 host_stats->macrx_multicast_frames =
1117 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1118 host_stats->macrx_broadcast_frames =
1119 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1120 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1121 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1122 host_stats->iptx_fragments =
1123 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1124 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1125 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1126 host_stats->iprx_fragments =
1127 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1128 host_stats->ip_datagram_reassembly =
1129 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1130 host_stats->ip_invalid_address_error =
1131 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1132 host_stats->ip_error_packets =
1133 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1134 host_stats->ip_fragrx_overlap =
1135 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1136 host_stats->ip_fragrx_outoforder =
1137 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1138 host_stats->ip_datagram_reassembly_timeout =
1139 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1140 host_stats->ipv6tx_packets =
1141 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1142 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1143 host_stats->ipv6tx_fragments =
1144 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1145 host_stats->ipv6rx_packets =
1146 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1147 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1148 host_stats->ipv6rx_fragments =
1149 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1150 host_stats->ipv6_datagram_reassembly =
1151 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1152 host_stats->ipv6_invalid_address_error =
1153 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1154 host_stats->ipv6_error_packets =
1155 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1156 host_stats->ipv6_fragrx_overlap =
1157 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1158 host_stats->ipv6_fragrx_outoforder =
1159 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1160 host_stats->ipv6_datagram_reassembly_timeout =
1161 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1162 host_stats->tcptx_segments =
1163 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1164 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1165 host_stats->tcprx_segments =
1166 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1167 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1168 host_stats->tcp_duplicate_ack_retx =
1169 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1170 host_stats->tcp_retx_timer_expired =
1171 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1172 host_stats->tcprx_duplicate_ack =
1173 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1174 host_stats->tcprx_pure_ackr =
1175 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1176 host_stats->tcptx_delayed_ack =
1177 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1178 host_stats->tcptx_pure_ack =
1179 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1180 host_stats->tcprx_segment_error =
1181 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1182 host_stats->tcprx_segment_outoforder =
1183 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1184 host_stats->tcprx_window_probe =
1185 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1186 host_stats->tcprx_window_update =
1187 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1188 host_stats->tcptx_window_probe_persist =
1189 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1190 host_stats->ecc_error_correction =
1191 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1192 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1193 host_stats->iscsi_data_bytes_tx =
1194 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1195 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1196 host_stats->iscsi_data_bytes_rx =
1197 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1198 host_stats->iscsi_io_completed =
1199 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1200 host_stats->iscsi_unexpected_io_rx =
1201 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1202 host_stats->iscsi_format_error =
1203 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1204 host_stats->iscsi_hdr_digest_error =
1205 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1206 host_stats->iscsi_data_digest_error =
1207 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1208 host_stats->iscsi_sequence_error =
1209 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1210exit_host_stats:
1211 if (ql_iscsi_stats)
1212 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1213 ql_iscsi_stats, iscsi_stats_dma);
1214
1215 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1216 __func__);
1217 return ret;
1218}
1219
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001220static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1221 enum iscsi_param_type param_type,
1222 int param, char *buf)
1223{
1224 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1225 struct scsi_qla_host *ha = to_qla_host(shost);
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001226 int ival;
1227 char *pval = NULL;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001228 int len = -ENOSYS;
1229
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001230 if (param_type == ISCSI_NET_PARAM) {
1231 switch (param) {
1232 case ISCSI_NET_PARAM_IPV4_ADDR:
1233 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1234 break;
1235 case ISCSI_NET_PARAM_IPV4_SUBNET:
1236 len = sprintf(buf, "%pI4\n",
1237 &ha->ip_config.subnet_mask);
1238 break;
1239 case ISCSI_NET_PARAM_IPV4_GW:
1240 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1241 break;
1242 case ISCSI_NET_PARAM_IFACE_ENABLE:
1243 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1244 OP_STATE(ha->ip_config.ipv4_options,
1245 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1246 } else {
1247 OP_STATE(ha->ip_config.ipv6_options,
1248 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1249 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001250
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001251 len = sprintf(buf, "%s\n", pval);
1252 break;
1253 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001254 len = sprintf(buf, "%s\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001255 (ha->ip_config.tcp_options &
1256 TCPOPT_DHCP_ENABLE) ?
1257 "dhcp" : "static");
1258 break;
1259 case ISCSI_NET_PARAM_IPV6_ADDR:
1260 if (iface->iface_num == 0)
1261 len = sprintf(buf, "%pI6\n",
1262 &ha->ip_config.ipv6_addr0);
1263 if (iface->iface_num == 1)
1264 len = sprintf(buf, "%pI6\n",
1265 &ha->ip_config.ipv6_addr1);
1266 break;
1267 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1268 len = sprintf(buf, "%pI6\n",
1269 &ha->ip_config.ipv6_link_local_addr);
1270 break;
1271 case ISCSI_NET_PARAM_IPV6_ROUTER:
1272 len = sprintf(buf, "%pI6\n",
1273 &ha->ip_config.ipv6_default_router_addr);
1274 break;
1275 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1276 pval = (ha->ip_config.ipv6_addl_options &
1277 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1278 "nd" : "static";
1279
1280 len = sprintf(buf, "%s\n", pval);
1281 break;
1282 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1283 pval = (ha->ip_config.ipv6_addl_options &
1284 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1285 "auto" : "static";
1286
1287 len = sprintf(buf, "%s\n", pval);
1288 break;
1289 case ISCSI_NET_PARAM_VLAN_ID:
1290 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1291 ival = ha->ip_config.ipv4_vlan_tag &
1292 ISCSI_MAX_VLAN_ID;
1293 else
1294 ival = ha->ip_config.ipv6_vlan_tag &
1295 ISCSI_MAX_VLAN_ID;
1296
1297 len = sprintf(buf, "%d\n", ival);
1298 break;
1299 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1300 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1301 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1302 ISCSI_MAX_VLAN_PRIORITY;
1303 else
1304 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1305 ISCSI_MAX_VLAN_PRIORITY;
1306
1307 len = sprintf(buf, "%d\n", ival);
1308 break;
1309 case ISCSI_NET_PARAM_VLAN_ENABLED:
1310 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1311 OP_STATE(ha->ip_config.ipv4_options,
1312 IPOPT_VLAN_TAGGING_ENABLE, pval);
1313 } else {
1314 OP_STATE(ha->ip_config.ipv6_options,
1315 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1316 }
1317 len = sprintf(buf, "%s\n", pval);
1318 break;
1319 case ISCSI_NET_PARAM_MTU:
1320 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1321 break;
1322 case ISCSI_NET_PARAM_PORT:
1323 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1324 len = sprintf(buf, "%d\n",
1325 ha->ip_config.ipv4_port);
1326 else
1327 len = sprintf(buf, "%d\n",
1328 ha->ip_config.ipv6_port);
1329 break;
1330 case ISCSI_NET_PARAM_IPADDR_STATE:
1331 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1332 pval = iscsi_get_ipaddress_state_name(
1333 ha->ip_config.ipv4_addr_state);
1334 } else {
1335 if (iface->iface_num == 0)
1336 pval = iscsi_get_ipaddress_state_name(
1337 ha->ip_config.ipv6_addr0_state);
1338 else if (iface->iface_num == 1)
1339 pval = iscsi_get_ipaddress_state_name(
1340 ha->ip_config.ipv6_addr1_state);
1341 }
1342
1343 len = sprintf(buf, "%s\n", pval);
1344 break;
1345 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1346 pval = iscsi_get_ipaddress_state_name(
1347 ha->ip_config.ipv6_link_local_state);
1348 len = sprintf(buf, "%s\n", pval);
1349 break;
1350 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1351 pval = iscsi_get_router_state_name(
1352 ha->ip_config.ipv6_default_router_state);
1353 len = sprintf(buf, "%s\n", pval);
1354 break;
1355 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1356 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1357 OP_STATE(~ha->ip_config.tcp_options,
1358 TCPOPT_DELAYED_ACK_DISABLE, pval);
1359 } else {
1360 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1361 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1362 }
1363 len = sprintf(buf, "%s\n", pval);
1364 break;
1365 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1366 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1367 OP_STATE(~ha->ip_config.tcp_options,
1368 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1369 } else {
1370 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1371 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1372 }
1373 len = sprintf(buf, "%s\n", pval);
1374 break;
1375 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1376 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1377 OP_STATE(~ha->ip_config.tcp_options,
1378 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1379 } else {
1380 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1381 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1382 pval);
1383 }
1384 len = sprintf(buf, "%s\n", pval);
1385 break;
1386 case ISCSI_NET_PARAM_TCP_WSF:
1387 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1388 len = sprintf(buf, "%d\n",
1389 ha->ip_config.tcp_wsf);
1390 else
1391 len = sprintf(buf, "%d\n",
1392 ha->ip_config.ipv6_tcp_wsf);
1393 break;
1394 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1395 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1396 ival = (ha->ip_config.tcp_options &
1397 TCPOPT_TIMER_SCALE) >> 1;
1398 else
1399 ival = (ha->ip_config.ipv6_tcp_options &
1400 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1401
1402 len = sprintf(buf, "%d\n", ival);
1403 break;
1404 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1405 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1406 OP_STATE(ha->ip_config.tcp_options,
1407 TCPOPT_TIMESTAMP_ENABLE, pval);
1408 } else {
1409 OP_STATE(ha->ip_config.ipv6_tcp_options,
1410 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1411 }
1412 len = sprintf(buf, "%s\n", pval);
1413 break;
1414 case ISCSI_NET_PARAM_CACHE_ID:
1415 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1416 len = sprintf(buf, "%d\n",
1417 ha->ip_config.ipv4_cache_id);
1418 else
1419 len = sprintf(buf, "%d\n",
1420 ha->ip_config.ipv6_cache_id);
1421 break;
1422 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1423 OP_STATE(ha->ip_config.tcp_options,
1424 TCPOPT_DNS_SERVER_IP_EN, pval);
1425
1426 len = sprintf(buf, "%s\n", pval);
1427 break;
1428 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1429 OP_STATE(ha->ip_config.tcp_options,
1430 TCPOPT_SLP_DA_INFO_EN, pval);
1431
1432 len = sprintf(buf, "%s\n", pval);
1433 break;
1434 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1435 OP_STATE(ha->ip_config.ipv4_options,
1436 IPOPT_IPV4_TOS_EN, pval);
1437
1438 len = sprintf(buf, "%s\n", pval);
1439 break;
1440 case ISCSI_NET_PARAM_IPV4_TOS:
1441 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1442 break;
1443 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1444 OP_STATE(ha->ip_config.ipv4_options,
1445 IPOPT_GRAT_ARP_EN, pval);
1446
1447 len = sprintf(buf, "%s\n", pval);
1448 break;
1449 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1450 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1451 pval);
1452
1453 len = sprintf(buf, "%s\n", pval);
1454 break;
1455 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1456 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1457 (char *)ha->ip_config.ipv4_alt_cid : "";
1458
1459 len = sprintf(buf, "%s\n", pval);
1460 break;
1461 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1462 OP_STATE(ha->ip_config.ipv4_options,
1463 IPOPT_REQ_VID_EN, pval);
1464
1465 len = sprintf(buf, "%s\n", pval);
1466 break;
1467 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1468 OP_STATE(ha->ip_config.ipv4_options,
1469 IPOPT_USE_VID_EN, pval);
1470
1471 len = sprintf(buf, "%s\n", pval);
1472 break;
1473 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1474 pval = (ha->ip_config.ipv4_vid_len) ?
1475 (char *)ha->ip_config.ipv4_vid : "";
1476
1477 len = sprintf(buf, "%s\n", pval);
1478 break;
1479 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1480 OP_STATE(ha->ip_config.ipv4_options,
1481 IPOPT_LEARN_IQN_EN, pval);
1482
1483 len = sprintf(buf, "%s\n", pval);
1484 break;
1485 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1486 OP_STATE(~ha->ip_config.ipv4_options,
1487 IPOPT_FRAGMENTATION_DISABLE, pval);
1488
1489 len = sprintf(buf, "%s\n", pval);
1490 break;
1491 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1492 OP_STATE(ha->ip_config.ipv4_options,
1493 IPOPT_IN_FORWARD_EN, pval);
1494
1495 len = sprintf(buf, "%s\n", pval);
1496 break;
1497 case ISCSI_NET_PARAM_REDIRECT_EN:
1498 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1499 OP_STATE(ha->ip_config.ipv4_options,
1500 IPOPT_ARP_REDIRECT_EN, pval);
1501 } else {
1502 OP_STATE(ha->ip_config.ipv6_options,
1503 IPV6_OPT_REDIRECT_EN, pval);
1504 }
1505 len = sprintf(buf, "%s\n", pval);
1506 break;
1507 case ISCSI_NET_PARAM_IPV4_TTL:
1508 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1509 break;
1510 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1511 OP_STATE(ha->ip_config.ipv6_options,
1512 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1513
1514 len = sprintf(buf, "%s\n", pval);
1515 break;
1516 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1517 OP_STATE(ha->ip_config.ipv6_addl_options,
1518 IPV6_ADDOPT_MLD_EN, pval);
1519
1520 len = sprintf(buf, "%s\n", pval);
1521 break;
1522 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1523 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1524 break;
1525 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001526 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001527 ha->ip_config.ipv6_traffic_class);
1528 break;
1529 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001530 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001531 ha->ip_config.ipv6_hop_limit);
1532 break;
1533 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001534 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001535 ha->ip_config.ipv6_nd_reach_time);
1536 break;
1537 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001538 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001539 ha->ip_config.ipv6_nd_rexmit_timer);
1540 break;
1541 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1542 len = sprintf(buf, "%d\n",
1543 ha->ip_config.ipv6_nd_stale_timeout);
1544 break;
1545 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1546 len = sprintf(buf, "%d\n",
1547 ha->ip_config.ipv6_dup_addr_detect_count);
1548 break;
1549 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1550 len = sprintf(buf, "%d\n",
1551 ha->ip_config.ipv6_gw_advrt_mtu);
1552 break;
1553 default:
1554 len = -ENOSYS;
1555 }
1556 } else if (param_type == ISCSI_IFACE_PARAM) {
1557 switch (param) {
1558 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1559 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1560 break;
1561 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1562 OP_STATE(ha->ip_config.iscsi_options,
1563 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1564
1565 len = sprintf(buf, "%s\n", pval);
1566 break;
1567 case ISCSI_IFACE_PARAM_DATADGST_EN:
1568 OP_STATE(ha->ip_config.iscsi_options,
1569 ISCSIOPTS_DATA_DIGEST_EN, pval);
1570
1571 len = sprintf(buf, "%s\n", pval);
1572 break;
1573 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1574 OP_STATE(ha->ip_config.iscsi_options,
1575 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1576
1577 len = sprintf(buf, "%s\n", pval);
1578 break;
1579 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1580 OP_STATE(ha->ip_config.iscsi_options,
1581 ISCSIOPTS_INITIAL_R2T_EN, pval);
1582
1583 len = sprintf(buf, "%s\n", pval);
1584 break;
1585 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1586 OP_STATE(ha->ip_config.iscsi_options,
1587 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1588
1589 len = sprintf(buf, "%s\n", pval);
1590 break;
1591 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1592 OP_STATE(ha->ip_config.iscsi_options,
1593 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1594
1595 len = sprintf(buf, "%s\n", pval);
1596 break;
1597 case ISCSI_IFACE_PARAM_ERL:
1598 len = sprintf(buf, "%d\n",
1599 (ha->ip_config.iscsi_options &
1600 ISCSIOPTS_ERL));
1601 break;
1602 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1603 len = sprintf(buf, "%u\n",
1604 ha->ip_config.iscsi_max_pdu_size *
1605 BYTE_UNITS);
1606 break;
1607 case ISCSI_IFACE_PARAM_FIRST_BURST:
1608 len = sprintf(buf, "%u\n",
1609 ha->ip_config.iscsi_first_burst_len *
1610 BYTE_UNITS);
1611 break;
1612 case ISCSI_IFACE_PARAM_MAX_R2T:
1613 len = sprintf(buf, "%d\n",
1614 ha->ip_config.iscsi_max_outstnd_r2t);
1615 break;
1616 case ISCSI_IFACE_PARAM_MAX_BURST:
1617 len = sprintf(buf, "%u\n",
1618 ha->ip_config.iscsi_max_burst_len *
1619 BYTE_UNITS);
1620 break;
1621 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1622 OP_STATE(ha->ip_config.iscsi_options,
1623 ISCSIOPTS_CHAP_AUTH_EN, pval);
1624
1625 len = sprintf(buf, "%s\n", pval);
1626 break;
1627 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1628 OP_STATE(ha->ip_config.iscsi_options,
1629 ISCSIOPTS_BIDI_CHAP_EN, pval);
1630
1631 len = sprintf(buf, "%s\n", pval);
1632 break;
1633 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1634 OP_STATE(ha->ip_config.iscsi_options,
1635 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1636
1637 len = sprintf(buf, "%s\n", pval);
1638 break;
1639 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1640 OP_STATE(ha->ip_config.iscsi_options,
1641 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1642
1643 len = sprintf(buf, "%s\n", pval);
1644 break;
1645 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1646 OP_STATE(ha->ip_config.iscsi_options,
1647 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1648
1649 len = sprintf(buf, "%s\n", pval);
1650 break;
1651 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1652 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1653 break;
1654 default:
1655 len = -ENOSYS;
1656 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001657 }
1658
1659 return len;
1660}
1661
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001662static struct iscsi_endpoint *
1663qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1664 int non_blocking)
1665{
1666 int ret;
1667 struct iscsi_endpoint *ep;
1668 struct qla_endpoint *qla_ep;
1669 struct scsi_qla_host *ha;
1670 struct sockaddr_in *addr;
1671 struct sockaddr_in6 *addr6;
1672
1673 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1674 if (!shost) {
1675 ret = -ENXIO;
1676 printk(KERN_ERR "%s: shost is NULL\n",
1677 __func__);
1678 return ERR_PTR(ret);
1679 }
1680
1681 ha = iscsi_host_priv(shost);
1682
1683 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1684 if (!ep) {
1685 ret = -ENOMEM;
1686 return ERR_PTR(ret);
1687 }
1688
1689 qla_ep = ep->dd_data;
1690 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1691 if (dst_addr->sa_family == AF_INET) {
1692 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1693 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1694 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1695 (char *)&addr->sin_addr));
1696 } else if (dst_addr->sa_family == AF_INET6) {
1697 memcpy(&qla_ep->dst_addr, dst_addr,
1698 sizeof(struct sockaddr_in6));
1699 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1700 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1701 (char *)&addr6->sin6_addr));
1702 }
1703
1704 qla_ep->host = shost;
1705
1706 return ep;
1707}
1708
1709static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1710{
1711 struct qla_endpoint *qla_ep;
1712 struct scsi_qla_host *ha;
1713 int ret = 0;
1714
1715 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1716 qla_ep = ep->dd_data;
1717 ha = to_qla_host(qla_ep->host);
1718
Mike Christie13483732011-12-01 21:38:41 -06001719 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001720 ret = 1;
1721
1722 return ret;
1723}
1724
1725static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1726{
1727 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1728 iscsi_destroy_endpoint(ep);
1729}
1730
1731static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1732 enum iscsi_param param,
1733 char *buf)
1734{
1735 struct qla_endpoint *qla_ep = ep->dd_data;
1736 struct sockaddr *dst_addr;
1737
1738 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1739
1740 switch (param) {
1741 case ISCSI_PARAM_CONN_PORT:
1742 case ISCSI_PARAM_CONN_ADDRESS:
1743 if (!qla_ep)
1744 return -ENOTCONN;
1745
1746 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1747 if (!dst_addr)
1748 return -ENOTCONN;
1749
1750 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1751 &qla_ep->dst_addr, param, buf);
1752 default:
1753 return -ENOSYS;
1754 }
1755}
1756
1757static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1758 struct iscsi_stats *stats)
1759{
1760 struct iscsi_session *sess;
1761 struct iscsi_cls_session *cls_sess;
1762 struct ddb_entry *ddb_entry;
1763 struct scsi_qla_host *ha;
1764 struct ql_iscsi_stats *ql_iscsi_stats;
1765 int stats_size;
1766 int ret;
1767 dma_addr_t iscsi_stats_dma;
1768
1769 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1770
1771 cls_sess = iscsi_conn_to_session(cls_conn);
1772 sess = cls_sess->dd_data;
1773 ddb_entry = sess->dd_data;
1774 ha = ddb_entry->ha;
1775
1776 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1777 /* Allocate memory */
1778 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1779 &iscsi_stats_dma, GFP_KERNEL);
1780 if (!ql_iscsi_stats) {
1781 ql4_printk(KERN_ERR, ha,
1782 "Unable to allocate memory for iscsi stats\n");
1783 goto exit_get_stats;
1784 }
1785
1786 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1787 iscsi_stats_dma);
1788 if (ret != QLA_SUCCESS) {
1789 ql4_printk(KERN_ERR, ha,
Masanari Iida59e13d42012-04-25 00:24:16 +09001790 "Unable to retrieve iscsi stats\n");
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001791 goto free_stats;
1792 }
1793
1794 /* octets */
1795 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1796 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1797 /* xmit pdus */
1798 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1799 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1800 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1801 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1802 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1803 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1804 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1805 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1806 /* recv pdus */
1807 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1808 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1809 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1810 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1811 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1812 stats->logoutrsp_pdus =
1813 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1814 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1815 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1816 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1817
1818free_stats:
1819 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1820 iscsi_stats_dma);
1821exit_get_stats:
1822 return;
1823}
1824
Mike Christie5c656af2009-07-15 15:02:59 -05001825static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1826{
1827 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001828 struct iscsi_session *sess;
1829 unsigned long flags;
1830 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -05001831
1832 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001833 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -05001834
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001835 spin_lock_irqsave(&session->lock, flags);
1836 if (session->state == ISCSI_SESSION_FAILED)
1837 ret = BLK_EH_RESET_TIMER;
1838 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -05001839
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001840 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001841}
1842
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001843static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1844{
1845 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001846 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001847 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1848
1849 qla4xxx_get_firmware_state(ha);
1850
1851 switch (ha->addl_fw_state & 0x0F00) {
1852 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1853 speed = ISCSI_PORT_SPEED_10MBPS;
1854 break;
1855 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1856 speed = ISCSI_PORT_SPEED_100MBPS;
1857 break;
1858 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1859 speed = ISCSI_PORT_SPEED_1GBPS;
1860 break;
1861 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1862 speed = ISCSI_PORT_SPEED_10GBPS;
1863 break;
1864 }
1865 ihost->port_speed = speed;
1866}
1867
1868static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1869{
1870 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001871 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001872 uint32_t state = ISCSI_PORT_STATE_DOWN;
1873
1874 if (test_bit(AF_LINK_UP, &ha->flags))
1875 state = ISCSI_PORT_STATE_UP;
1876
1877 ihost->port_state = state;
1878}
1879
Mike Christieaa1e93a2007-05-30 12:57:09 -05001880static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1881 enum iscsi_host_param param, char *buf)
1882{
1883 struct scsi_qla_host *ha = to_qla_host(shost);
1884 int len;
1885
1886 switch (param) {
1887 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -08001888 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -05001889 break;
Mike Christie22236962007-05-30 12:57:24 -05001890 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05001891 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -05001892 break;
Mike Christie8ad57812007-05-30 12:57:13 -05001893 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -05001894 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -05001895 break;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001896 case ISCSI_HOST_PARAM_PORT_STATE:
1897 qla4xxx_set_port_state(shost);
1898 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1899 break;
1900 case ISCSI_HOST_PARAM_PORT_SPEED:
1901 qla4xxx_set_port_speed(shost);
1902 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1903 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -05001904 default:
1905 return -ENOSYS;
1906 }
1907
1908 return len;
1909}
1910
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001911static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1912{
1913 if (ha->iface_ipv4)
1914 return;
1915
1916 /* IPv4 */
1917 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1918 &qla4xxx_iscsi_transport,
1919 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1920 if (!ha->iface_ipv4)
1921 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1922 "iface0.\n");
1923}
1924
1925static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1926{
1927 if (!ha->iface_ipv6_0)
1928 /* IPv6 iface-0 */
1929 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1930 &qla4xxx_iscsi_transport,
1931 ISCSI_IFACE_TYPE_IPV6, 0,
1932 0);
1933 if (!ha->iface_ipv6_0)
1934 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1935 "iface0.\n");
1936
1937 if (!ha->iface_ipv6_1)
1938 /* IPv6 iface-1 */
1939 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1940 &qla4xxx_iscsi_transport,
1941 ISCSI_IFACE_TYPE_IPV6, 1,
1942 0);
1943 if (!ha->iface_ipv6_1)
1944 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1945 "iface1.\n");
1946}
1947
1948static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1949{
1950 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1951 qla4xxx_create_ipv4_iface(ha);
1952
1953 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1954 qla4xxx_create_ipv6_iface(ha);
1955}
1956
1957static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1958{
1959 if (ha->iface_ipv4) {
1960 iscsi_destroy_iface(ha->iface_ipv4);
1961 ha->iface_ipv4 = NULL;
1962 }
1963}
1964
1965static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1966{
1967 if (ha->iface_ipv6_0) {
1968 iscsi_destroy_iface(ha->iface_ipv6_0);
1969 ha->iface_ipv6_0 = NULL;
1970 }
1971 if (ha->iface_ipv6_1) {
1972 iscsi_destroy_iface(ha->iface_ipv6_1);
1973 ha->iface_ipv6_1 = NULL;
1974 }
1975}
1976
1977static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1978{
1979 qla4xxx_destroy_ipv4_iface(ha);
1980 qla4xxx_destroy_ipv6_iface(ha);
1981}
1982
Mike Christied00efe32011-07-25 13:48:38 -05001983static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1984 struct iscsi_iface_param_info *iface_param,
1985 struct addr_ctrl_blk *init_fw_cb)
1986{
1987 /*
1988 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1989 * iface_num 1 is valid only for IPv6 Addr.
1990 */
1991 switch (iface_param->param) {
1992 case ISCSI_NET_PARAM_IPV6_ADDR:
1993 if (iface_param->iface_num & 0x1)
1994 /* IPv6 Addr 1 */
1995 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
1996 sizeof(init_fw_cb->ipv6_addr1));
1997 else
1998 /* IPv6 Addr 0 */
1999 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2000 sizeof(init_fw_cb->ipv6_addr0));
2001 break;
2002 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2003 if (iface_param->iface_num & 0x1)
2004 break;
2005 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2006 sizeof(init_fw_cb->ipv6_if_id));
2007 break;
2008 case ISCSI_NET_PARAM_IPV6_ROUTER:
2009 if (iface_param->iface_num & 0x1)
2010 break;
2011 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2012 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2013 break;
2014 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2015 /* Autocfg applies to even interface */
2016 if (iface_param->iface_num & 0x1)
2017 break;
2018
2019 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2020 init_fw_cb->ipv6_addtl_opts &=
2021 cpu_to_le16(
2022 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2023 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2024 init_fw_cb->ipv6_addtl_opts |=
2025 cpu_to_le16(
2026 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2027 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002028 ql4_printk(KERN_ERR, ha,
2029 "Invalid autocfg setting for IPv6 addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05002030 break;
2031 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2032 /* Autocfg applies to even interface */
2033 if (iface_param->iface_num & 0x1)
2034 break;
2035
2036 if (iface_param->value[0] ==
2037 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2038 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2039 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2040 else if (iface_param->value[0] ==
2041 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2042 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2043 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2044 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002045 ql4_printk(KERN_ERR, ha,
2046 "Invalid autocfg setting for IPv6 linklocal addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05002047 break;
2048 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2049 /* Autocfg applies to even interface */
2050 if (iface_param->iface_num & 0x1)
2051 break;
2052
2053 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2054 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2055 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2056 break;
2057 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002058 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05002059 init_fw_cb->ipv6_opts |=
2060 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002061 qla4xxx_create_ipv6_iface(ha);
2062 } else {
Mike Christied00efe32011-07-25 13:48:38 -05002063 init_fw_cb->ipv6_opts &=
2064 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2065 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002066 qla4xxx_destroy_ipv6_iface(ha);
2067 }
Mike Christied00efe32011-07-25 13:48:38 -05002068 break;
Mike Christie2d636732011-10-11 17:55:11 -05002069 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002070 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2071 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002072 init_fw_cb->ipv6_vlan_tag =
2073 cpu_to_be16(*(uint16_t *)iface_param->value);
2074 break;
2075 case ISCSI_NET_PARAM_VLAN_ENABLED:
2076 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2077 init_fw_cb->ipv6_opts |=
2078 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2079 else
2080 init_fw_cb->ipv6_opts &=
2081 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002082 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002083 case ISCSI_NET_PARAM_MTU:
2084 init_fw_cb->eth_mtu_size =
2085 cpu_to_le16(*(uint16_t *)iface_param->value);
2086 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002087 case ISCSI_NET_PARAM_PORT:
2088 /* Autocfg applies to even interface */
2089 if (iface_param->iface_num & 0x1)
2090 break;
2091
2092 init_fw_cb->ipv6_port =
2093 cpu_to_le16(*(uint16_t *)iface_param->value);
2094 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002095 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2096 if (iface_param->iface_num & 0x1)
2097 break;
2098 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2099 init_fw_cb->ipv6_tcp_opts |=
2100 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2101 else
2102 init_fw_cb->ipv6_tcp_opts &=
2103 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2104 break;
2105 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2106 if (iface_param->iface_num & 0x1)
2107 break;
2108 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2109 init_fw_cb->ipv6_tcp_opts |=
2110 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2111 else
2112 init_fw_cb->ipv6_tcp_opts &=
2113 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2114 break;
2115 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2116 if (iface_param->iface_num & 0x1)
2117 break;
2118 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2119 init_fw_cb->ipv6_tcp_opts |=
2120 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2121 else
2122 init_fw_cb->ipv6_tcp_opts &=
2123 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2124 break;
2125 case ISCSI_NET_PARAM_TCP_WSF:
2126 if (iface_param->iface_num & 0x1)
2127 break;
2128 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2129 break;
2130 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2131 if (iface_param->iface_num & 0x1)
2132 break;
2133 init_fw_cb->ipv6_tcp_opts &=
2134 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2135 init_fw_cb->ipv6_tcp_opts |=
2136 cpu_to_le16((iface_param->value[0] << 1) &
2137 IPV6_TCPOPT_TIMER_SCALE);
2138 break;
2139 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2140 if (iface_param->iface_num & 0x1)
2141 break;
2142 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2143 init_fw_cb->ipv6_tcp_opts |=
2144 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2145 else
2146 init_fw_cb->ipv6_tcp_opts &=
2147 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2148 break;
2149 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2150 if (iface_param->iface_num & 0x1)
2151 break;
2152 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2153 init_fw_cb->ipv6_opts |=
2154 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2155 else
2156 init_fw_cb->ipv6_opts &=
2157 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2158 break;
2159 case ISCSI_NET_PARAM_REDIRECT_EN:
2160 if (iface_param->iface_num & 0x1)
2161 break;
2162 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2163 init_fw_cb->ipv6_opts |=
2164 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2165 else
2166 init_fw_cb->ipv6_opts &=
2167 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2168 break;
2169 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2170 if (iface_param->iface_num & 0x1)
2171 break;
2172 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2173 init_fw_cb->ipv6_addtl_opts |=
2174 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2175 else
2176 init_fw_cb->ipv6_addtl_opts &=
2177 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2178 break;
2179 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2180 if (iface_param->iface_num & 0x1)
2181 break;
2182 init_fw_cb->ipv6_flow_lbl =
2183 cpu_to_le16(*(uint16_t *)iface_param->value);
2184 break;
2185 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2186 if (iface_param->iface_num & 0x1)
2187 break;
2188 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2189 break;
2190 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2191 if (iface_param->iface_num & 0x1)
2192 break;
2193 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2194 break;
2195 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2196 if (iface_param->iface_num & 0x1)
2197 break;
2198 init_fw_cb->ipv6_nd_reach_time =
2199 cpu_to_le32(*(uint32_t *)iface_param->value);
2200 break;
2201 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2202 if (iface_param->iface_num & 0x1)
2203 break;
2204 init_fw_cb->ipv6_nd_rexmit_timer =
2205 cpu_to_le32(*(uint32_t *)iface_param->value);
2206 break;
2207 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2208 if (iface_param->iface_num & 0x1)
2209 break;
2210 init_fw_cb->ipv6_nd_stale_timeout =
2211 cpu_to_le32(*(uint32_t *)iface_param->value);
2212 break;
2213 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2214 if (iface_param->iface_num & 0x1)
2215 break;
2216 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2217 break;
2218 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2219 if (iface_param->iface_num & 0x1)
2220 break;
2221 init_fw_cb->ipv6_gw_advrt_mtu =
2222 cpu_to_le32(*(uint32_t *)iface_param->value);
2223 break;
Mike Christied00efe32011-07-25 13:48:38 -05002224 default:
2225 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2226 iface_param->param);
2227 break;
2228 }
2229}
2230
2231static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2232 struct iscsi_iface_param_info *iface_param,
2233 struct addr_ctrl_blk *init_fw_cb)
2234{
2235 switch (iface_param->param) {
2236 case ISCSI_NET_PARAM_IPV4_ADDR:
2237 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2238 sizeof(init_fw_cb->ipv4_addr));
2239 break;
2240 case ISCSI_NET_PARAM_IPV4_SUBNET:
2241 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2242 sizeof(init_fw_cb->ipv4_subnet));
2243 break;
2244 case ISCSI_NET_PARAM_IPV4_GW:
2245 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2246 sizeof(init_fw_cb->ipv4_gw_addr));
2247 break;
2248 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2249 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2250 init_fw_cb->ipv4_tcp_opts |=
2251 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2252 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2253 init_fw_cb->ipv4_tcp_opts &=
2254 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2255 else
2256 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2257 break;
2258 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002259 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05002260 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05002261 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002262 qla4xxx_create_ipv4_iface(ha);
2263 } else {
Mike Christied00efe32011-07-25 13:48:38 -05002264 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05002265 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -05002266 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002267 qla4xxx_destroy_ipv4_iface(ha);
2268 }
Mike Christied00efe32011-07-25 13:48:38 -05002269 break;
Mike Christie2d636732011-10-11 17:55:11 -05002270 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002271 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2272 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002273 init_fw_cb->ipv4_vlan_tag =
2274 cpu_to_be16(*(uint16_t *)iface_param->value);
2275 break;
2276 case ISCSI_NET_PARAM_VLAN_ENABLED:
2277 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2278 init_fw_cb->ipv4_ip_opts |=
2279 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2280 else
2281 init_fw_cb->ipv4_ip_opts &=
2282 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002283 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002284 case ISCSI_NET_PARAM_MTU:
2285 init_fw_cb->eth_mtu_size =
2286 cpu_to_le16(*(uint16_t *)iface_param->value);
2287 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002288 case ISCSI_NET_PARAM_PORT:
2289 init_fw_cb->ipv4_port =
2290 cpu_to_le16(*(uint16_t *)iface_param->value);
2291 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002292 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2293 if (iface_param->iface_num & 0x1)
2294 break;
2295 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2296 init_fw_cb->ipv4_tcp_opts |=
2297 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2298 else
2299 init_fw_cb->ipv4_tcp_opts &=
2300 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE);
2301 break;
2302 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2303 if (iface_param->iface_num & 0x1)
2304 break;
2305 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2306 init_fw_cb->ipv4_tcp_opts |=
2307 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2308 else
2309 init_fw_cb->ipv4_tcp_opts &=
2310 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2311 break;
2312 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2313 if (iface_param->iface_num & 0x1)
2314 break;
2315 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2316 init_fw_cb->ipv4_tcp_opts |=
2317 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2318 else
2319 init_fw_cb->ipv4_tcp_opts &=
2320 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2321 break;
2322 case ISCSI_NET_PARAM_TCP_WSF:
2323 if (iface_param->iface_num & 0x1)
2324 break;
2325 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2326 break;
2327 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2328 if (iface_param->iface_num & 0x1)
2329 break;
2330 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2331 init_fw_cb->ipv4_tcp_opts |=
2332 cpu_to_le16((iface_param->value[0] << 1) &
2333 TCPOPT_TIMER_SCALE);
2334 break;
2335 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2336 if (iface_param->iface_num & 0x1)
2337 break;
2338 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2339 init_fw_cb->ipv4_tcp_opts |=
2340 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2341 else
2342 init_fw_cb->ipv4_tcp_opts &=
2343 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2344 break;
2345 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2346 if (iface_param->iface_num & 0x1)
2347 break;
2348 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2349 init_fw_cb->ipv4_tcp_opts |=
2350 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2351 else
2352 init_fw_cb->ipv4_tcp_opts &=
2353 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2354 break;
2355 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2356 if (iface_param->iface_num & 0x1)
2357 break;
2358 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2359 init_fw_cb->ipv4_tcp_opts |=
2360 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2361 else
2362 init_fw_cb->ipv4_tcp_opts &=
2363 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2364 break;
2365 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2366 if (iface_param->iface_num & 0x1)
2367 break;
2368 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2369 init_fw_cb->ipv4_ip_opts |=
2370 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2371 else
2372 init_fw_cb->ipv4_ip_opts &=
2373 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2374 break;
2375 case ISCSI_NET_PARAM_IPV4_TOS:
2376 if (iface_param->iface_num & 0x1)
2377 break;
2378 init_fw_cb->ipv4_tos = iface_param->value[0];
2379 break;
2380 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2381 if (iface_param->iface_num & 0x1)
2382 break;
2383 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2384 init_fw_cb->ipv4_ip_opts |=
2385 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2386 else
2387 init_fw_cb->ipv4_ip_opts &=
2388 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2389 break;
2390 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2391 if (iface_param->iface_num & 0x1)
2392 break;
2393 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2394 init_fw_cb->ipv4_ip_opts |=
2395 cpu_to_le16(IPOPT_ALT_CID_EN);
2396 else
2397 init_fw_cb->ipv4_ip_opts &=
2398 cpu_to_le16(~IPOPT_ALT_CID_EN);
2399 break;
2400 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2401 if (iface_param->iface_num & 0x1)
2402 break;
2403 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2404 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2405 init_fw_cb->ipv4_dhcp_alt_cid_len =
2406 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2407 break;
2408 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2409 if (iface_param->iface_num & 0x1)
2410 break;
2411 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2412 init_fw_cb->ipv4_ip_opts |=
2413 cpu_to_le16(IPOPT_REQ_VID_EN);
2414 else
2415 init_fw_cb->ipv4_ip_opts &=
2416 cpu_to_le16(~IPOPT_REQ_VID_EN);
2417 break;
2418 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2419 if (iface_param->iface_num & 0x1)
2420 break;
2421 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2422 init_fw_cb->ipv4_ip_opts |=
2423 cpu_to_le16(IPOPT_USE_VID_EN);
2424 else
2425 init_fw_cb->ipv4_ip_opts &=
2426 cpu_to_le16(~IPOPT_USE_VID_EN);
2427 break;
2428 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2429 if (iface_param->iface_num & 0x1)
2430 break;
2431 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2432 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2433 init_fw_cb->ipv4_dhcp_vid_len =
2434 strlen(init_fw_cb->ipv4_dhcp_vid);
2435 break;
2436 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2437 if (iface_param->iface_num & 0x1)
2438 break;
2439 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2440 init_fw_cb->ipv4_ip_opts |=
2441 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2442 else
2443 init_fw_cb->ipv4_ip_opts &=
2444 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2445 break;
2446 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2447 if (iface_param->iface_num & 0x1)
2448 break;
2449 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2450 init_fw_cb->ipv4_ip_opts |=
2451 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2452 else
2453 init_fw_cb->ipv4_ip_opts &=
2454 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2455 break;
2456 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2457 if (iface_param->iface_num & 0x1)
2458 break;
2459 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2460 init_fw_cb->ipv4_ip_opts |=
2461 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2462 else
2463 init_fw_cb->ipv4_ip_opts &=
2464 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2465 break;
2466 case ISCSI_NET_PARAM_REDIRECT_EN:
2467 if (iface_param->iface_num & 0x1)
2468 break;
2469 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2470 init_fw_cb->ipv4_ip_opts |=
2471 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2472 else
2473 init_fw_cb->ipv4_ip_opts &=
2474 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2475 break;
2476 case ISCSI_NET_PARAM_IPV4_TTL:
2477 if (iface_param->iface_num & 0x1)
2478 break;
2479 init_fw_cb->ipv4_ttl = iface_param->value[0];
2480 break;
Mike Christied00efe32011-07-25 13:48:38 -05002481 default:
2482 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2483 iface_param->param);
2484 break;
2485 }
2486}
2487
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002488static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2489 struct iscsi_iface_param_info *iface_param,
2490 struct addr_ctrl_blk *init_fw_cb)
2491{
2492 switch (iface_param->param) {
2493 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2494 if (iface_param->iface_num & 0x1)
2495 break;
2496 init_fw_cb->def_timeout =
2497 cpu_to_le16(*(uint16_t *)iface_param->value);
2498 break;
2499 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2500 if (iface_param->iface_num & 0x1)
2501 break;
2502 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2503 init_fw_cb->iscsi_opts |=
2504 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2505 else
2506 init_fw_cb->iscsi_opts &=
2507 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2508 break;
2509 case ISCSI_IFACE_PARAM_DATADGST_EN:
2510 if (iface_param->iface_num & 0x1)
2511 break;
2512 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2513 init_fw_cb->iscsi_opts |=
2514 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2515 else
2516 init_fw_cb->iscsi_opts &=
2517 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2518 break;
2519 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2520 if (iface_param->iface_num & 0x1)
2521 break;
2522 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2523 init_fw_cb->iscsi_opts |=
2524 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2525 else
2526 init_fw_cb->iscsi_opts &=
2527 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2528 break;
2529 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2530 if (iface_param->iface_num & 0x1)
2531 break;
2532 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2533 init_fw_cb->iscsi_opts |=
2534 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2535 else
2536 init_fw_cb->iscsi_opts &=
2537 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2538 break;
2539 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2540 if (iface_param->iface_num & 0x1)
2541 break;
2542 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2543 init_fw_cb->iscsi_opts |=
2544 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2545 else
2546 init_fw_cb->iscsi_opts &=
2547 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2548 break;
2549 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2550 if (iface_param->iface_num & 0x1)
2551 break;
2552 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2553 init_fw_cb->iscsi_opts |=
2554 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2555 else
2556 init_fw_cb->iscsi_opts &=
2557 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2558 break;
2559 case ISCSI_IFACE_PARAM_ERL:
2560 if (iface_param->iface_num & 0x1)
2561 break;
2562 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2563 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2564 ISCSIOPTS_ERL);
2565 break;
2566 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2567 if (iface_param->iface_num & 0x1)
2568 break;
2569 init_fw_cb->iscsi_max_pdu_size =
2570 cpu_to_le32(*(uint32_t *)iface_param->value) /
2571 BYTE_UNITS;
2572 break;
2573 case ISCSI_IFACE_PARAM_FIRST_BURST:
2574 if (iface_param->iface_num & 0x1)
2575 break;
2576 init_fw_cb->iscsi_fburst_len =
2577 cpu_to_le32(*(uint32_t *)iface_param->value) /
2578 BYTE_UNITS;
2579 break;
2580 case ISCSI_IFACE_PARAM_MAX_R2T:
2581 if (iface_param->iface_num & 0x1)
2582 break;
2583 init_fw_cb->iscsi_max_outstnd_r2t =
2584 cpu_to_le16(*(uint16_t *)iface_param->value);
2585 break;
2586 case ISCSI_IFACE_PARAM_MAX_BURST:
2587 if (iface_param->iface_num & 0x1)
2588 break;
2589 init_fw_cb->iscsi_max_burst_len =
2590 cpu_to_le32(*(uint32_t *)iface_param->value) /
2591 BYTE_UNITS;
2592 break;
2593 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2594 if (iface_param->iface_num & 0x1)
2595 break;
2596 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2597 init_fw_cb->iscsi_opts |=
2598 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2599 else
2600 init_fw_cb->iscsi_opts &=
2601 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2602 break;
2603 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2604 if (iface_param->iface_num & 0x1)
2605 break;
2606 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2607 init_fw_cb->iscsi_opts |=
2608 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2609 else
2610 init_fw_cb->iscsi_opts &=
2611 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2612 break;
2613 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2614 if (iface_param->iface_num & 0x1)
2615 break;
2616 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2617 init_fw_cb->iscsi_opts |=
2618 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2619 else
2620 init_fw_cb->iscsi_opts &=
2621 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2622 break;
2623 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2624 if (iface_param->iface_num & 0x1)
2625 break;
2626 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2627 init_fw_cb->iscsi_opts |=
2628 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2629 else
2630 init_fw_cb->iscsi_opts &=
2631 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2632 break;
2633 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2634 if (iface_param->iface_num & 0x1)
2635 break;
2636 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2637 init_fw_cb->iscsi_opts |=
2638 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2639 else
2640 init_fw_cb->iscsi_opts &=
2641 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2642 break;
2643 default:
2644 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2645 iface_param->param);
2646 break;
2647 }
2648}
2649
Mike Christied00efe32011-07-25 13:48:38 -05002650static void
2651qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2652{
2653 struct addr_ctrl_blk_def *acb;
2654 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2655 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2656 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2657 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2658 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2659 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2660 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2661 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2662 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2663 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2664 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2665 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2666 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2667 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2668 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2669 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2670}
2671
2672static int
Mike Christie00c31882011-10-06 03:56:59 -05002673qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05002674{
2675 struct scsi_qla_host *ha = to_qla_host(shost);
2676 int rval = 0;
2677 struct iscsi_iface_param_info *iface_param = NULL;
2678 struct addr_ctrl_blk *init_fw_cb = NULL;
2679 dma_addr_t init_fw_cb_dma;
2680 uint32_t mbox_cmd[MBOX_REG_COUNT];
2681 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christie00c31882011-10-06 03:56:59 -05002682 uint32_t rem = len;
2683 struct nlattr *attr;
Mike Christied00efe32011-07-25 13:48:38 -05002684
2685 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2686 sizeof(struct addr_ctrl_blk),
2687 &init_fw_cb_dma, GFP_KERNEL);
2688 if (!init_fw_cb) {
2689 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2690 __func__);
2691 return -ENOMEM;
2692 }
2693
2694 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2695 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2696 memset(&mbox_sts, 0, sizeof(mbox_sts));
2697
2698 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2699 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2700 rval = -EIO;
2701 goto exit_init_fw_cb;
2702 }
2703
Mike Christie00c31882011-10-06 03:56:59 -05002704 nla_for_each_attr(attr, data, len, rem) {
2705 iface_param = nla_data(attr);
Mike Christied00efe32011-07-25 13:48:38 -05002706
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002707 if (iface_param->param_type == ISCSI_NET_PARAM) {
2708 switch (iface_param->iface_type) {
2709 case ISCSI_IFACE_TYPE_IPV4:
2710 switch (iface_param->iface_num) {
2711 case 0:
2712 qla4xxx_set_ipv4(ha, iface_param,
2713 init_fw_cb);
2714 break;
2715 default:
Mike Christied00efe32011-07-25 13:48:38 -05002716 /* Cannot have more than one IPv4 interface */
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002717 ql4_printk(KERN_ERR, ha,
2718 "Invalid IPv4 iface number = %d\n",
2719 iface_param->iface_num);
2720 break;
2721 }
Mike Christied00efe32011-07-25 13:48:38 -05002722 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002723 case ISCSI_IFACE_TYPE_IPV6:
2724 switch (iface_param->iface_num) {
2725 case 0:
2726 case 1:
2727 qla4xxx_set_ipv6(ha, iface_param,
2728 init_fw_cb);
2729 break;
2730 default:
2731 /* Cannot have more than two IPv6 interface */
2732 ql4_printk(KERN_ERR, ha,
2733 "Invalid IPv6 iface number = %d\n",
2734 iface_param->iface_num);
2735 break;
2736 }
Mike Christied00efe32011-07-25 13:48:38 -05002737 break;
2738 default:
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002739 ql4_printk(KERN_ERR, ha,
2740 "Invalid iface type\n");
Mike Christied00efe32011-07-25 13:48:38 -05002741 break;
2742 }
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002743 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2744 qla4xxx_set_iscsi_param(ha, iface_param,
2745 init_fw_cb);
2746 } else {
2747 continue;
Mike Christied00efe32011-07-25 13:48:38 -05002748 }
Mike Christied00efe32011-07-25 13:48:38 -05002749 }
2750
2751 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2752
2753 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2754 sizeof(struct addr_ctrl_blk),
2755 FLASH_OPT_RMW_COMMIT);
2756 if (rval != QLA_SUCCESS) {
2757 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2758 __func__);
2759 rval = -EIO;
2760 goto exit_init_fw_cb;
2761 }
2762
Vikas Chaudharyce505f92011-12-01 22:42:10 -08002763 rval = qla4xxx_disable_acb(ha);
2764 if (rval != QLA_SUCCESS) {
2765 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2766 __func__);
2767 rval = -EIO;
2768 goto exit_init_fw_cb;
2769 }
2770
2771 wait_for_completion_timeout(&ha->disable_acb_comp,
2772 DISABLE_ACB_TOV * HZ);
Mike Christied00efe32011-07-25 13:48:38 -05002773
2774 qla4xxx_initcb_to_acb(init_fw_cb);
2775
2776 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2777 if (rval != QLA_SUCCESS) {
2778 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2779 __func__);
2780 rval = -EIO;
2781 goto exit_init_fw_cb;
2782 }
2783
2784 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2785 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2786 init_fw_cb_dma);
2787
2788exit_init_fw_cb:
2789 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2790 init_fw_cb, init_fw_cb_dma);
2791
2792 return rval;
2793}
2794
Mike Christiefca9f042012-02-27 03:08:54 -08002795static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2796 enum iscsi_param param, char *buf)
2797{
2798 struct iscsi_session *sess = cls_sess->dd_data;
2799 struct ddb_entry *ddb_entry = sess->dd_data;
2800 struct scsi_qla_host *ha = ddb_entry->ha;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002801 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2802 struct ql4_chap_table chap_tbl;
Mike Christiefca9f042012-02-27 03:08:54 -08002803 int rval, len;
2804 uint16_t idx;
2805
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002806 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christiefca9f042012-02-27 03:08:54 -08002807 switch (param) {
2808 case ISCSI_PARAM_CHAP_IN_IDX:
2809 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2810 sess->password_in, BIDI_CHAP,
2811 &idx);
2812 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002813 len = sprintf(buf, "\n");
2814 else
2815 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002816 break;
2817 case ISCSI_PARAM_CHAP_OUT_IDX:
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002818 if (ddb_entry->ddb_type == FLASH_DDB) {
2819 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2820 idx = ddb_entry->chap_tbl_idx;
2821 rval = QLA_SUCCESS;
2822 } else {
2823 rval = QLA_ERROR;
2824 }
2825 } else {
2826 rval = qla4xxx_get_chap_index(ha, sess->username,
2827 sess->password,
2828 LOCAL_CHAP, &idx);
2829 }
Mike Christiefca9f042012-02-27 03:08:54 -08002830 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002831 len = sprintf(buf, "\n");
2832 else
2833 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002834 break;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002835 case ISCSI_PARAM_USERNAME:
2836 case ISCSI_PARAM_PASSWORD:
2837 /* First, populate session username and password for FLASH DDB,
2838 * if not already done. This happens when session login fails
2839 * for a FLASH DDB.
2840 */
2841 if (ddb_entry->ddb_type == FLASH_DDB &&
2842 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2843 !sess->username && !sess->password) {
2844 idx = ddb_entry->chap_tbl_idx;
2845 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2846 chap_tbl.secret,
2847 idx);
2848 if (!rval) {
2849 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2850 (char *)chap_tbl.name,
2851 strlen((char *)chap_tbl.name));
2852 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2853 (char *)chap_tbl.secret,
2854 chap_tbl.secret_len);
2855 }
2856 }
2857 /* allow fall-through */
Mike Christiefca9f042012-02-27 03:08:54 -08002858 default:
2859 return iscsi_session_get_param(cls_sess, param, buf);
2860 }
2861
2862 return len;
2863}
2864
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002865static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002866 enum iscsi_param param, char *buf)
2867{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002868 struct iscsi_conn *conn;
2869 struct qla_conn *qla_conn;
2870 struct sockaddr *dst_addr;
2871 int len = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002872
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002873 conn = cls_conn->dd_data;
2874 qla_conn = conn->dd_data;
Manish Rangankard46bdeb12012-08-07 07:57:13 -04002875 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002876
2877 switch (param) {
2878 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002879 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002880 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2881 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002882 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002883 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002884 }
2885
2886 return len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002887
David Somayajuluafaf5a22006-09-19 10:28:00 -07002888}
2889
Mike Christie13483732011-12-01 21:38:41 -06002890int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2891{
2892 uint32_t mbx_sts = 0;
2893 uint16_t tmp_ddb_index;
2894 int ret;
2895
2896get_ddb_index:
2897 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2898
2899 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2900 DEBUG2(ql4_printk(KERN_INFO, ha,
2901 "Free DDB index not available\n"));
2902 ret = QLA_ERROR;
2903 goto exit_get_ddb_index;
2904 }
2905
2906 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2907 goto get_ddb_index;
2908
2909 DEBUG2(ql4_printk(KERN_INFO, ha,
2910 "Found a free DDB index at %d\n", tmp_ddb_index));
2911 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2912 if (ret == QLA_ERROR) {
2913 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2914 ql4_printk(KERN_INFO, ha,
2915 "DDB index = %d not available trying next\n",
2916 tmp_ddb_index);
2917 goto get_ddb_index;
2918 }
2919 DEBUG2(ql4_printk(KERN_INFO, ha,
2920 "Free FW DDB not available\n"));
2921 }
2922
2923 *ddb_index = tmp_ddb_index;
2924
2925exit_get_ddb_index:
2926 return ret;
2927}
2928
2929static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2930 struct ddb_entry *ddb_entry,
2931 char *existing_ipaddr,
2932 char *user_ipaddr)
2933{
2934 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2935 char formatted_ipaddr[DDB_IPADDR_LEN];
2936 int status = QLA_SUCCESS, ret = 0;
2937
2938 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2939 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2940 '\0', NULL);
2941 if (ret == 0) {
2942 status = QLA_ERROR;
2943 goto out_match;
2944 }
2945 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2946 } else {
2947 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2948 '\0', NULL);
2949 if (ret == 0) {
2950 status = QLA_ERROR;
2951 goto out_match;
2952 }
2953 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2954 }
2955
2956 if (strcmp(existing_ipaddr, formatted_ipaddr))
2957 status = QLA_ERROR;
2958
2959out_match:
2960 return status;
2961}
2962
2963static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2964 struct iscsi_cls_conn *cls_conn)
2965{
2966 int idx = 0, max_ddbs, rval;
2967 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2968 struct iscsi_session *sess, *existing_sess;
2969 struct iscsi_conn *conn, *existing_conn;
2970 struct ddb_entry *ddb_entry;
2971
2972 sess = cls_sess->dd_data;
2973 conn = cls_conn->dd_data;
2974
2975 if (sess->targetname == NULL ||
2976 conn->persistent_address == NULL ||
2977 conn->persistent_port == 0)
2978 return QLA_ERROR;
2979
2980 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
2981 MAX_DEV_DB_ENTRIES;
2982
2983 for (idx = 0; idx < max_ddbs; idx++) {
2984 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
2985 if (ddb_entry == NULL)
2986 continue;
2987
2988 if (ddb_entry->ddb_type != FLASH_DDB)
2989 continue;
2990
2991 existing_sess = ddb_entry->sess->dd_data;
2992 existing_conn = ddb_entry->conn->dd_data;
2993
2994 if (existing_sess->targetname == NULL ||
2995 existing_conn->persistent_address == NULL ||
2996 existing_conn->persistent_port == 0)
2997 continue;
2998
2999 DEBUG2(ql4_printk(KERN_INFO, ha,
3000 "IQN = %s User IQN = %s\n",
3001 existing_sess->targetname,
3002 sess->targetname));
3003
3004 DEBUG2(ql4_printk(KERN_INFO, ha,
3005 "IP = %s User IP = %s\n",
3006 existing_conn->persistent_address,
3007 conn->persistent_address));
3008
3009 DEBUG2(ql4_printk(KERN_INFO, ha,
3010 "Port = %d User Port = %d\n",
3011 existing_conn->persistent_port,
3012 conn->persistent_port));
3013
3014 if (strcmp(existing_sess->targetname, sess->targetname))
3015 continue;
3016 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3017 existing_conn->persistent_address,
3018 conn->persistent_address);
3019 if (rval == QLA_ERROR)
3020 continue;
3021 if (existing_conn->persistent_port != conn->persistent_port)
3022 continue;
3023 break;
3024 }
3025
3026 if (idx == max_ddbs)
3027 return QLA_ERROR;
3028
3029 DEBUG2(ql4_printk(KERN_INFO, ha,
3030 "Match found in fwdb sessions\n"));
3031 return QLA_SUCCESS;
3032}
3033
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003034static struct iscsi_cls_session *
3035qla4xxx_session_create(struct iscsi_endpoint *ep,
3036 uint16_t cmds_max, uint16_t qdepth,
3037 uint32_t initial_cmdsn)
3038{
3039 struct iscsi_cls_session *cls_sess;
3040 struct scsi_qla_host *ha;
3041 struct qla_endpoint *qla_ep;
3042 struct ddb_entry *ddb_entry;
Mike Christie13483732011-12-01 21:38:41 -06003043 uint16_t ddb_index;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003044 struct iscsi_session *sess;
3045 struct sockaddr *dst_addr;
3046 int ret;
3047
3048 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3049 if (!ep) {
3050 printk(KERN_ERR "qla4xxx: missing ep.\n");
3051 return NULL;
3052 }
3053
3054 qla_ep = ep->dd_data;
3055 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3056 ha = to_qla_host(qla_ep->host);
Manish Rangankar736cf362011-10-07 16:55:46 -07003057
Mike Christie13483732011-12-01 21:38:41 -06003058 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3059 if (ret == QLA_ERROR)
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003060 return NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003061
3062 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3063 cmds_max, sizeof(struct ddb_entry),
3064 sizeof(struct ql4_task_data),
3065 initial_cmdsn, ddb_index);
3066 if (!cls_sess)
3067 return NULL;
3068
3069 sess = cls_sess->dd_data;
3070 ddb_entry = sess->dd_data;
3071 ddb_entry->fw_ddb_index = ddb_index;
3072 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3073 ddb_entry->ha = ha;
3074 ddb_entry->sess = cls_sess;
Mike Christie13483732011-12-01 21:38:41 -06003075 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3076 ddb_entry->ddb_change = qla4xxx_ddb_change;
Nilesh Javalide2efea2013-12-16 06:49:40 -05003077 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003078 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3079 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3080 ha->tot_ddbs++;
3081
3082 return cls_sess;
3083}
3084
3085static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3086{
3087 struct iscsi_session *sess;
3088 struct ddb_entry *ddb_entry;
3089 struct scsi_qla_host *ha;
Manish Rangankar90599b62012-04-23 22:32:34 -07003090 unsigned long flags, wtime;
3091 struct dev_db_entry *fw_ddb_entry = NULL;
3092 dma_addr_t fw_ddb_entry_dma;
3093 uint32_t ddb_state;
3094 int ret;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003095
3096 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3097 sess = cls_sess->dd_data;
3098 ddb_entry = sess->dd_data;
3099 ha = ddb_entry->ha;
3100
Manish Rangankar90599b62012-04-23 22:32:34 -07003101 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3102 &fw_ddb_entry_dma, GFP_KERNEL);
3103 if (!fw_ddb_entry) {
3104 ql4_printk(KERN_ERR, ha,
3105 "%s: Unable to allocate dma buffer\n", __func__);
3106 goto destroy_session;
3107 }
3108
3109 wtime = jiffies + (HZ * LOGOUT_TOV);
3110 do {
3111 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3112 fw_ddb_entry, fw_ddb_entry_dma,
3113 NULL, NULL, &ddb_state, NULL,
3114 NULL, NULL);
3115 if (ret == QLA_ERROR)
3116 goto destroy_session;
3117
3118 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3119 (ddb_state == DDB_DS_SESSION_FAILED))
3120 goto destroy_session;
3121
3122 schedule_timeout_uninterruptible(HZ);
3123 } while ((time_after(wtime, jiffies)));
3124
3125destroy_session:
Manish Rangankar736cf362011-10-07 16:55:46 -07003126 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
Nilesh Javalide2efea2013-12-16 06:49:40 -05003127 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3128 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003129 spin_lock_irqsave(&ha->hardware_lock, flags);
3130 qla4xxx_free_ddb(ha, ddb_entry);
3131 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Manish Rangankar90599b62012-04-23 22:32:34 -07003132
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003133 iscsi_session_teardown(cls_sess);
Manish Rangankar90599b62012-04-23 22:32:34 -07003134
3135 if (fw_ddb_entry)
3136 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3137 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003138}
3139
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003140static struct iscsi_cls_conn *
3141qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3142{
3143 struct iscsi_cls_conn *cls_conn;
3144 struct iscsi_session *sess;
3145 struct ddb_entry *ddb_entry;
3146
3147 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3148 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3149 conn_idx);
Mike Christieff1d0312011-12-01 21:38:43 -06003150 if (!cls_conn)
3151 return NULL;
3152
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003153 sess = cls_sess->dd_data;
3154 ddb_entry = sess->dd_data;
3155 ddb_entry->conn = cls_conn;
3156
3157 return cls_conn;
3158}
3159
3160static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3161 struct iscsi_cls_conn *cls_conn,
3162 uint64_t transport_fd, int is_leading)
3163{
3164 struct iscsi_conn *conn;
3165 struct qla_conn *qla_conn;
3166 struct iscsi_endpoint *ep;
3167
3168 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3169
3170 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3171 return -EINVAL;
3172 ep = iscsi_lookup_endpoint(transport_fd);
3173 conn = cls_conn->dd_data;
3174 qla_conn = conn->dd_data;
3175 qla_conn->qla_ep = ep->dd_data;
3176 return 0;
3177}
3178
3179static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3180{
3181 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3182 struct iscsi_session *sess;
3183 struct ddb_entry *ddb_entry;
3184 struct scsi_qla_host *ha;
Mike Christie13483732011-12-01 21:38:41 -06003185 struct dev_db_entry *fw_ddb_entry = NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003186 dma_addr_t fw_ddb_entry_dma;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003187 uint32_t mbx_sts = 0;
3188 int ret = 0;
3189 int status = QLA_SUCCESS;
3190
3191 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3192 sess = cls_sess->dd_data;
3193 ddb_entry = sess->dd_data;
3194 ha = ddb_entry->ha;
3195
Mike Christie13483732011-12-01 21:38:41 -06003196 /* Check if we have matching FW DDB, if yes then do not
3197 * login to this target. This could cause target to logout previous
3198 * connection
3199 */
3200 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3201 if (ret == QLA_SUCCESS) {
3202 ql4_printk(KERN_INFO, ha,
3203 "Session already exist in FW.\n");
3204 ret = -EEXIST;
3205 goto exit_conn_start;
3206 }
3207
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003208 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3209 &fw_ddb_entry_dma, GFP_KERNEL);
3210 if (!fw_ddb_entry) {
3211 ql4_printk(KERN_ERR, ha,
3212 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003213 ret = -ENOMEM;
3214 goto exit_conn_start;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003215 }
3216
3217 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3218 if (ret) {
3219 /* If iscsid is stopped and started then no need to do
3220 * set param again since ddb state will be already
3221 * active and FW does not allow set ddb to an
3222 * active session.
3223 */
3224 if (mbx_sts)
3225 if (ddb_entry->fw_ddb_device_state ==
Manish Rangankarf922da72011-10-07 16:55:49 -07003226 DDB_DS_SESSION_ACTIVE) {
Mike Christie13483732011-12-01 21:38:41 -06003227 ddb_entry->unblock_sess(ddb_entry->sess);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003228 goto exit_set_param;
Manish Rangankarf922da72011-10-07 16:55:49 -07003229 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003230
3231 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3232 __func__, ddb_entry->fw_ddb_index);
3233 goto exit_conn_start;
3234 }
3235
3236 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3237 if (status == QLA_ERROR) {
Manish Rangankar0e7e8502011-07-25 13:48:54 -05003238 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3239 sess->targetname);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003240 ret = -EINVAL;
3241 goto exit_conn_start;
3242 }
3243
Manish Rangankar98270ab2011-10-07 16:55:47 -07003244 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3245 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3246
3247 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3248 ddb_entry->fw_ddb_device_state));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003249
3250exit_set_param:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003251 ret = 0;
3252
3253exit_conn_start:
Mike Christie13483732011-12-01 21:38:41 -06003254 if (fw_ddb_entry)
3255 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3256 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003257 return ret;
3258}
3259
3260static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3261{
3262 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3263 struct iscsi_session *sess;
3264 struct scsi_qla_host *ha;
3265 struct ddb_entry *ddb_entry;
3266 int options;
3267
3268 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3269 sess = cls_sess->dd_data;
3270 ddb_entry = sess->dd_data;
3271 ha = ddb_entry->ha;
3272
3273 options = LOGOUT_OPTION_CLOSE_SESSION;
3274 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3275 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003276}
3277
3278static void qla4xxx_task_work(struct work_struct *wdata)
3279{
3280 struct ql4_task_data *task_data;
3281 struct scsi_qla_host *ha;
3282 struct passthru_status *sts;
3283 struct iscsi_task *task;
3284 struct iscsi_hdr *hdr;
3285 uint8_t *data;
3286 uint32_t data_len;
3287 struct iscsi_conn *conn;
3288 int hdr_len;
3289 itt_t itt;
3290
3291 task_data = container_of(wdata, struct ql4_task_data, task_work);
3292 ha = task_data->ha;
3293 task = task_data->task;
3294 sts = &task_data->sts;
3295 hdr_len = sizeof(struct iscsi_hdr);
3296
3297 DEBUG3(printk(KERN_INFO "Status returned\n"));
3298 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3299 DEBUG3(printk(KERN_INFO "Response buffer"));
3300 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3301
3302 conn = task->conn;
3303
3304 switch (sts->completionStatus) {
3305 case PASSTHRU_STATUS_COMPLETE:
3306 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3307 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3308 itt = sts->handle;
3309 hdr->itt = itt;
3310 data = task_data->resp_buffer + hdr_len;
3311 data_len = task_data->resp_len - hdr_len;
3312 iscsi_complete_pdu(conn, hdr, data, data_len);
3313 break;
3314 default:
3315 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3316 sts->completionStatus);
3317 break;
3318 }
3319 return;
3320}
3321
3322static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3323{
3324 struct ql4_task_data *task_data;
3325 struct iscsi_session *sess;
3326 struct ddb_entry *ddb_entry;
3327 struct scsi_qla_host *ha;
3328 int hdr_len;
3329
3330 sess = task->conn->session;
3331 ddb_entry = sess->dd_data;
3332 ha = ddb_entry->ha;
3333 task_data = task->dd_data;
3334 memset(task_data, 0, sizeof(struct ql4_task_data));
3335
3336 if (task->sc) {
3337 ql4_printk(KERN_INFO, ha,
3338 "%s: SCSI Commands not implemented\n", __func__);
3339 return -EINVAL;
3340 }
3341
3342 hdr_len = sizeof(struct iscsi_hdr);
3343 task_data->ha = ha;
3344 task_data->task = task;
3345
3346 if (task->data_count) {
3347 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3348 task->data_count,
3349 PCI_DMA_TODEVICE);
3350 }
3351
3352 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3353 __func__, task->conn->max_recv_dlength, hdr_len));
3354
Manish Rangankar69ca2162011-10-07 16:55:50 -07003355 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003356 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3357 task_data->resp_len,
3358 &task_data->resp_dma,
3359 GFP_ATOMIC);
3360 if (!task_data->resp_buffer)
3361 goto exit_alloc_pdu;
3362
Manish Rangankar69ca2162011-10-07 16:55:50 -07003363 task_data->req_len = task->data_count + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003364 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
Manish Rangankar69ca2162011-10-07 16:55:50 -07003365 task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003366 &task_data->req_dma,
3367 GFP_ATOMIC);
3368 if (!task_data->req_buffer)
3369 goto exit_alloc_pdu;
3370
3371 task->hdr = task_data->req_buffer;
3372
3373 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3374
3375 return 0;
3376
3377exit_alloc_pdu:
3378 if (task_data->resp_buffer)
3379 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3380 task_data->resp_buffer, task_data->resp_dma);
3381
3382 if (task_data->req_buffer)
Manish Rangankar69ca2162011-10-07 16:55:50 -07003383 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003384 task_data->req_buffer, task_data->req_dma);
3385 return -ENOMEM;
3386}
3387
3388static void qla4xxx_task_cleanup(struct iscsi_task *task)
3389{
3390 struct ql4_task_data *task_data;
3391 struct iscsi_session *sess;
3392 struct ddb_entry *ddb_entry;
3393 struct scsi_qla_host *ha;
3394 int hdr_len;
3395
3396 hdr_len = sizeof(struct iscsi_hdr);
3397 sess = task->conn->session;
3398 ddb_entry = sess->dd_data;
3399 ha = ddb_entry->ha;
3400 task_data = task->dd_data;
3401
3402 if (task->data_count) {
3403 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3404 task->data_count, PCI_DMA_TODEVICE);
3405 }
3406
3407 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3408 __func__, task->conn->max_recv_dlength, hdr_len));
3409
3410 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3411 task_data->resp_buffer, task_data->resp_dma);
Manish Rangankar69ca2162011-10-07 16:55:50 -07003412 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003413 task_data->req_buffer, task_data->req_dma);
3414 return;
3415}
3416
3417static int qla4xxx_task_xmit(struct iscsi_task *task)
3418{
3419 struct scsi_cmnd *sc = task->sc;
3420 struct iscsi_session *sess = task->conn->session;
3421 struct ddb_entry *ddb_entry = sess->dd_data;
3422 struct scsi_qla_host *ha = ddb_entry->ha;
3423
3424 if (!sc)
3425 return qla4xxx_send_passthru0(task);
3426
3427 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3428 __func__);
3429 return -ENOSYS;
3430}
3431
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003432static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3433 struct iscsi_bus_flash_conn *conn,
3434 struct dev_db_entry *fw_ddb_entry)
3435{
3436 unsigned long options = 0;
3437 int rc = 0;
3438
3439 options = le16_to_cpu(fw_ddb_entry->options);
3440 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3441 if (test_bit(OPT_IPV6_DEVICE, &options)) {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003442 rc = iscsi_switch_str_param(&sess->portal_type,
3443 PORTAL_TYPE_IPV6);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003444 if (rc)
3445 goto exit_copy;
3446 } else {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003447 rc = iscsi_switch_str_param(&sess->portal_type,
3448 PORTAL_TYPE_IPV4);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003449 if (rc)
3450 goto exit_copy;
3451 }
3452
3453 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3454 &options);
3455 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3456 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3457
3458 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3459 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3460 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3461 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3462 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3463 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3464 &options);
3465 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3466 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3467 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3468 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3469 &options);
3470 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3471 sess->discovery_auth_optional =
3472 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3473 if (test_bit(ISCSIOPT_ERL1, &options))
3474 sess->erl |= BIT_1;
3475 if (test_bit(ISCSIOPT_ERL0, &options))
3476 sess->erl |= BIT_0;
3477
3478 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3479 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3480 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3481 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3482 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3483 conn->tcp_timer_scale |= BIT_3;
3484 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3485 conn->tcp_timer_scale |= BIT_2;
3486 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3487 conn->tcp_timer_scale |= BIT_1;
3488
3489 conn->tcp_timer_scale >>= 1;
3490 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3491
3492 options = le16_to_cpu(fw_ddb_entry->ip_options);
3493 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3494
3495 conn->max_recv_dlength = BYTE_UNITS *
3496 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3497 conn->max_xmit_dlength = BYTE_UNITS *
3498 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3499 sess->first_burst = BYTE_UNITS *
3500 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3501 sess->max_burst = BYTE_UNITS *
3502 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3503 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3504 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3505 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3506 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3507 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3508 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3509 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3510 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3511 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3512 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3513 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3514 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3515 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3516 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3517 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3518 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3519
3520 sess->default_taskmgmt_timeout =
3521 le16_to_cpu(fw_ddb_entry->def_timeout);
3522 conn->port = le16_to_cpu(fw_ddb_entry->port);
3523
3524 options = le16_to_cpu(fw_ddb_entry->options);
3525 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3526 if (!conn->ipaddress) {
3527 rc = -ENOMEM;
3528 goto exit_copy;
3529 }
3530
3531 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3532 if (!conn->redirect_ipaddr) {
3533 rc = -ENOMEM;
3534 goto exit_copy;
3535 }
3536
3537 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3538 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3539
3540 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3541 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3542
3543 conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3544 if (!conn->link_local_ipv6_addr) {
3545 rc = -ENOMEM;
3546 goto exit_copy;
3547 }
3548
3549 memcpy(conn->link_local_ipv6_addr,
3550 fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN);
3551 } else {
3552 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3553 }
3554
3555 if (fw_ddb_entry->iscsi_name[0]) {
3556 rc = iscsi_switch_str_param(&sess->targetname,
3557 (char *)fw_ddb_entry->iscsi_name);
3558 if (rc)
3559 goto exit_copy;
3560 }
3561
3562 if (fw_ddb_entry->iscsi_alias[0]) {
3563 rc = iscsi_switch_str_param(&sess->targetalias,
3564 (char *)fw_ddb_entry->iscsi_alias);
3565 if (rc)
3566 goto exit_copy;
3567 }
3568
3569 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3570
3571exit_copy:
3572 return rc;
3573}
3574
3575static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3576 struct iscsi_bus_flash_conn *conn,
3577 struct dev_db_entry *fw_ddb_entry)
3578{
3579 uint16_t options;
3580 int rc = 0;
3581
3582 options = le16_to_cpu(fw_ddb_entry->options);
3583 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003584 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003585 options |= BIT_8;
3586 else
3587 options &= ~BIT_8;
3588
3589 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3590 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3591 SET_BITVAL(sess->entry_state, options, BIT_3);
3592 fw_ddb_entry->options = cpu_to_le16(options);
3593
3594 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3595 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3596 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3597 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3598 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3599 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3600 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3601 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3602 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3603 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3604 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3605 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3606 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3607 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3608 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3609
3610 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3611 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3612 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3613 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3614 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3615 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3616 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3617 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3618 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3619
3620 options = le16_to_cpu(fw_ddb_entry->ip_options);
3621 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3622 fw_ddb_entry->ip_options = cpu_to_le16(options);
3623
3624 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3625 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3626 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3627 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3628 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3629 fw_ddb_entry->iscsi_first_burst_len =
3630 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3631 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3632 BYTE_UNITS);
3633 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3634 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3635 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3636 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003637 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3638 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003639 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3640 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3641 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003642 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3643 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
Adheer Chandravanshi65560162013-07-08 08:33:06 -04003644 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003645 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3646 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3647 fw_ddb_entry->port = cpu_to_le16(conn->port);
3648 fw_ddb_entry->def_timeout =
3649 cpu_to_le16(sess->default_taskmgmt_timeout);
3650
Adheer Chandravanshi84595802013-07-08 08:33:07 -04003651 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3652 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3653 else
3654 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3655
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003656 if (conn->ipaddress)
3657 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3658 sizeof(fw_ddb_entry->ip_addr));
3659
3660 if (conn->redirect_ipaddr)
3661 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3662 sizeof(fw_ddb_entry->tgt_addr));
3663
3664 if (conn->link_local_ipv6_addr)
3665 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3666 conn->link_local_ipv6_addr,
3667 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3668
3669 if (sess->targetname)
3670 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3671 sizeof(fw_ddb_entry->iscsi_name));
3672
3673 if (sess->targetalias)
3674 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3675 sizeof(fw_ddb_entry->iscsi_alias));
3676
3677 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3678
3679 return rc;
3680}
3681
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003682static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3683 struct iscsi_session *sess,
3684 struct dev_db_entry *fw_ddb_entry)
3685{
3686 unsigned long options = 0;
3687 uint16_t ddb_link;
3688 uint16_t disc_parent;
Adheer Chandravanshifb734ee32013-11-22 05:28:22 -05003689 char ip_addr[DDB_IPADDR_LEN];
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003690
3691 options = le16_to_cpu(fw_ddb_entry->options);
3692 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3693 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3694 &options);
3695 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3696
3697 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3698 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3699 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3700 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3701 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3702 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3703 &options);
3704 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3705 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3706 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3707 &options);
3708 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3709 sess->discovery_auth_optional =
3710 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3711 if (test_bit(ISCSIOPT_ERL1, &options))
3712 sess->erl |= BIT_1;
3713 if (test_bit(ISCSIOPT_ERL0, &options))
3714 sess->erl |= BIT_0;
3715
3716 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3717 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3718 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3719 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3720 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3721 conn->tcp_timer_scale |= BIT_3;
3722 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3723 conn->tcp_timer_scale |= BIT_2;
3724 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3725 conn->tcp_timer_scale |= BIT_1;
3726
3727 conn->tcp_timer_scale >>= 1;
3728 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3729
3730 options = le16_to_cpu(fw_ddb_entry->ip_options);
3731 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3732
3733 conn->max_recv_dlength = BYTE_UNITS *
3734 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3735 conn->max_xmit_dlength = BYTE_UNITS *
3736 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3737 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3738 sess->first_burst = BYTE_UNITS *
3739 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3740 sess->max_burst = BYTE_UNITS *
3741 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3742 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3743 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3744 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3745 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3746 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3747 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3748 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3749 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3750 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3751 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3752 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3753 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3754 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3755
3756 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003757 if (ddb_link == DDB_ISNS)
3758 disc_parent = ISCSI_DISC_PARENT_ISNS;
3759 else if (ddb_link == DDB_NO_LINK)
3760 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3761 else if (ddb_link < MAX_DDB_ENTRIES)
3762 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3763 else
3764 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3765
3766 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3767 iscsi_get_discovery_parent_name(disc_parent), 0);
3768
3769 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3770 (char *)fw_ddb_entry->iscsi_alias, 0);
Adheer Chandravanshifb734ee32013-11-22 05:28:22 -05003771
3772 options = le16_to_cpu(fw_ddb_entry->options);
3773 if (options & DDB_OPT_IPV6_DEVICE) {
3774 memset(ip_addr, 0, sizeof(ip_addr));
3775 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3776 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3777 (char *)ip_addr, 0);
3778 }
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003779}
3780
Mike Christie13483732011-12-01 21:38:41 -06003781static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3782 struct dev_db_entry *fw_ddb_entry,
3783 struct iscsi_cls_session *cls_sess,
3784 struct iscsi_cls_conn *cls_conn)
3785{
3786 int buflen = 0;
3787 struct iscsi_session *sess;
Nilesh Javali376738a2012-02-27 03:08:52 -08003788 struct ddb_entry *ddb_entry;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003789 struct ql4_chap_table chap_tbl;
Mike Christie13483732011-12-01 21:38:41 -06003790 struct iscsi_conn *conn;
3791 char ip_addr[DDB_IPADDR_LEN];
3792 uint16_t options = 0;
3793
3794 sess = cls_sess->dd_data;
Nilesh Javali376738a2012-02-27 03:08:52 -08003795 ddb_entry = sess->dd_data;
Mike Christie13483732011-12-01 21:38:41 -06003796 conn = cls_conn->dd_data;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003797 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christie13483732011-12-01 21:38:41 -06003798
Nilesh Javali376738a2012-02-27 03:08:52 -08003799 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3800
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003801 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Mike Christie13483732011-12-01 21:38:41 -06003802
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003803 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06003804 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3805
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003806 memset(ip_addr, 0, sizeof(ip_addr));
Mike Christie13483732011-12-01 21:38:41 -06003807 options = le16_to_cpu(fw_ddb_entry->options);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003808 if (options & DDB_OPT_IPV6_DEVICE) {
3809 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
Mike Christie13483732011-12-01 21:38:41 -06003810
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003811 memset(ip_addr, 0, sizeof(ip_addr));
3812 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3813 } else {
3814 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3815 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3816 }
3817
3818 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3819 (char *)ip_addr, buflen);
Mike Christie13483732011-12-01 21:38:41 -06003820 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3821 (char *)fw_ddb_entry->iscsi_name, buflen);
3822 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3823 (char *)ha->name_string, buflen);
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003824
3825 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3826 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3827 chap_tbl.secret,
3828 ddb_entry->chap_tbl_idx)) {
3829 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3830 (char *)chap_tbl.name,
3831 strlen((char *)chap_tbl.name));
3832 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3833 (char *)chap_tbl.secret,
3834 chap_tbl.secret_len);
3835 }
3836 }
Mike Christie13483732011-12-01 21:38:41 -06003837}
3838
3839void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3840 struct ddb_entry *ddb_entry)
3841{
3842 struct iscsi_cls_session *cls_sess;
3843 struct iscsi_cls_conn *cls_conn;
3844 uint32_t ddb_state;
3845 dma_addr_t fw_ddb_entry_dma;
3846 struct dev_db_entry *fw_ddb_entry;
3847
3848 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3849 &fw_ddb_entry_dma, GFP_KERNEL);
3850 if (!fw_ddb_entry) {
3851 ql4_printk(KERN_ERR, ha,
3852 "%s: Unable to allocate dma buffer\n", __func__);
3853 goto exit_session_conn_fwddb_param;
3854 }
3855
3856 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3857 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3858 NULL, NULL, NULL) == QLA_ERROR) {
3859 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3860 "get_ddb_entry for fw_ddb_index %d\n",
3861 ha->host_no, __func__,
3862 ddb_entry->fw_ddb_index));
3863 goto exit_session_conn_fwddb_param;
3864 }
3865
3866 cls_sess = ddb_entry->sess;
3867
3868 cls_conn = ddb_entry->conn;
3869
3870 /* Update params */
3871 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3872
3873exit_session_conn_fwddb_param:
3874 if (fw_ddb_entry)
3875 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3876 fw_ddb_entry, fw_ddb_entry_dma);
3877}
3878
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003879void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3880 struct ddb_entry *ddb_entry)
3881{
3882 struct iscsi_cls_session *cls_sess;
3883 struct iscsi_cls_conn *cls_conn;
3884 struct iscsi_session *sess;
3885 struct iscsi_conn *conn;
3886 uint32_t ddb_state;
3887 dma_addr_t fw_ddb_entry_dma;
3888 struct dev_db_entry *fw_ddb_entry;
3889
3890 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3891 &fw_ddb_entry_dma, GFP_KERNEL);
3892 if (!fw_ddb_entry) {
3893 ql4_printk(KERN_ERR, ha,
3894 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003895 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003896 }
3897
3898 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3899 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3900 NULL, NULL, NULL) == QLA_ERROR) {
3901 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3902 "get_ddb_entry for fw_ddb_index %d\n",
3903 ha->host_no, __func__,
3904 ddb_entry->fw_ddb_index));
Mike Christie13483732011-12-01 21:38:41 -06003905 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003906 }
3907
3908 cls_sess = ddb_entry->sess;
3909 sess = cls_sess->dd_data;
3910
3911 cls_conn = ddb_entry->conn;
3912 conn = cls_conn->dd_data;
3913
Mike Christie13483732011-12-01 21:38:41 -06003914 /* Update timers after login */
3915 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003916 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3917 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3918 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06003919 ddb_entry->default_time2wait =
3920 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3921
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003922 /* Update params */
Nilesh Javali376738a2012-02-27 03:08:52 -08003923 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003924 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003925
3926 memcpy(sess->initiatorname, ha->name_string,
3927 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
Mike Christie13483732011-12-01 21:38:41 -06003928
3929exit_session_conn_param:
3930 if (fw_ddb_entry)
3931 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3932 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003933}
3934
David Somayajuluafaf5a22006-09-19 10:28:00 -07003935/*
3936 * Timer routines
3937 */
3938
3939static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
3940 unsigned long interval)
3941{
3942 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3943 __func__, ha->host->host_no));
3944 init_timer(&ha->timer);
3945 ha->timer.expires = jiffies + interval * HZ;
3946 ha->timer.data = (unsigned long)ha;
3947 ha->timer.function = (void (*)(unsigned long))func;
3948 add_timer(&ha->timer);
3949 ha->timer_active = 1;
3950}
3951
3952static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3953{
3954 del_timer_sync(&ha->timer);
3955 ha->timer_active = 0;
3956}
3957
3958/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003959 * qla4xxx_mark_device_missing - blocks the session
3960 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07003961 * @ddb_entry: Pointer to device database entry
3962 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303963 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07003964 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003965void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003966{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003967 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003968}
3969
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303970/**
3971 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
3972 * @ha: Pointer to host adapter structure.
3973 *
3974 * This routine marks a device missing and resets the relogin retry count.
3975 **/
3976void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
3977{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003978 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303979}
3980
David Somayajuluafaf5a22006-09-19 10:28:00 -07003981static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
3982 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003983 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003984{
3985 struct srb *srb;
3986
3987 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
3988 if (!srb)
3989 return srb;
3990
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303991 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003992 srb->ha = ha;
3993 srb->ddb = ddb_entry;
3994 srb->cmd = cmd;
3995 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05303996 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003997
3998 return srb;
3999}
4000
4001static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4002{
4003 struct scsi_cmnd *cmd = srb->cmd;
4004
4005 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09004006 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004007 srb->flags &= ~SRB_DMA_VALID;
4008 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05304009 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004010}
4011
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304012void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004013{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304014 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004015 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304016 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004017
4018 qla4xxx_srb_free_dma(ha, srb);
4019
4020 mempool_free(srb, ha->srb_mempool);
4021
4022 cmd->scsi_done(cmd);
4023}
4024
4025/**
4026 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004027 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07004028 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07004029 *
4030 * Remarks:
4031 * This routine is invoked by Linux to send a SCSI command to the driver.
4032 * The mid-level driver tries to ensure that queuecommand never gets
4033 * invoked concurrently with itself or the interrupt handler (although
4034 * the interrupt handler may call this routine as part of request-
4035 * completion handling). Unfortunely, it sometimes calls the scheduler
4036 * in interrupt context which is a big NO! NO!.
4037 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004038static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004039{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004040 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004041 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06004042 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004043 struct srb *srb;
4044 int rval;
4045
Lalit Chandivade2232be02010-07-30 14:38:47 +05304046 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4047 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4048 cmd->result = DID_NO_CONNECT << 16;
4049 else
4050 cmd->result = DID_REQUEUE << 16;
4051 goto qc_fail_command;
4052 }
4053
Mike Christie7fb19212008-01-31 13:36:45 -06004054 if (!sess) {
4055 cmd->result = DID_IMM_RETRY << 16;
4056 goto qc_fail_command;
4057 }
4058
4059 rval = iscsi_session_chkready(sess);
4060 if (rval) {
4061 cmd->result = rval;
4062 goto qc_fail_command;
4063 }
4064
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304065 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4066 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4067 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4068 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4069 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4070 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004071 !test_bit(AF_LINK_UP, &ha->flags) ||
Nilesh Javali026fbd32013-01-20 23:50:58 -05004072 test_bit(AF_LOOPBACK, &ha->flags) ||
Nilesh Javali7ab284c2013-08-16 07:03:03 -04004073 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4074 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304075 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08004076 goto qc_host_busy;
4077
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004078 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004079 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004080 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004081
4082 rval = qla4xxx_send_command_to_isp(ha, srb);
4083 if (rval != QLA_SUCCESS)
4084 goto qc_host_busy_free_sp;
4085
David Somayajuluafaf5a22006-09-19 10:28:00 -07004086 return 0;
4087
4088qc_host_busy_free_sp:
4089 qla4xxx_srb_free_dma(ha, srb);
4090 mempool_free(srb, ha->srb_mempool);
4091
David Somayajuluafaf5a22006-09-19 10:28:00 -07004092qc_host_busy:
4093 return SCSI_MLQUEUE_HOST_BUSY;
4094
4095qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004096 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004097
4098 return 0;
4099}
4100
4101/**
4102 * qla4xxx_mem_free - frees memory allocated to adapter
4103 * @ha: Pointer to host adapter structure.
4104 *
4105 * Frees memory previously allocated by qla4xxx_mem_alloc
4106 **/
4107static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4108{
4109 if (ha->queues)
4110 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4111 ha->queues_dma);
4112
Tej Parkash068237c82012-05-18 04:41:44 -04004113 if (ha->fw_dump)
4114 vfree(ha->fw_dump);
4115
David Somayajuluafaf5a22006-09-19 10:28:00 -07004116 ha->queues_len = 0;
4117 ha->queues = NULL;
4118 ha->queues_dma = 0;
4119 ha->request_ring = NULL;
4120 ha->request_dma = 0;
4121 ha->response_ring = NULL;
4122 ha->response_dma = 0;
4123 ha->shadow_regs = NULL;
4124 ha->shadow_regs_dma = 0;
Tej Parkash068237c82012-05-18 04:41:44 -04004125 ha->fw_dump = NULL;
4126 ha->fw_dump_size = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004127
4128 /* Free srb pool. */
4129 if (ha->srb_mempool)
4130 mempool_destroy(ha->srb_mempool);
4131
4132 ha->srb_mempool = NULL;
4133
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004134 if (ha->chap_dma_pool)
4135 dma_pool_destroy(ha->chap_dma_pool);
4136
Lalit Chandivade45494152011-10-07 16:55:42 -07004137 if (ha->chap_list)
4138 vfree(ha->chap_list);
4139 ha->chap_list = NULL;
4140
Mike Christie13483732011-12-01 21:38:41 -06004141 if (ha->fw_ddb_dma_pool)
4142 dma_pool_destroy(ha->fw_ddb_dma_pool);
4143
David Somayajuluafaf5a22006-09-19 10:28:00 -07004144 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304145 if (is_qla8022(ha)) {
4146 if (ha->nx_pcibase)
4147 iounmap(
4148 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004149 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004150 if (ha->nx_pcibase)
4151 iounmap(
4152 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4153 } else if (ha->reg) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004154 iounmap(ha->reg);
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004155 }
4156
4157 if (ha->reset_tmplt.buff)
4158 vfree(ha->reset_tmplt.buff);
4159
David Somayajuluafaf5a22006-09-19 10:28:00 -07004160 pci_release_regions(ha->pdev);
4161}
4162
4163/**
4164 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4165 * @ha: Pointer to host adapter structure
4166 *
4167 * Allocates DMA memory for request and response queues. Also allocates memory
4168 * for srbs.
4169 **/
4170static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4171{
4172 unsigned long align;
4173
4174 /* Allocate contiguous block of DMA memory for queues. */
4175 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4176 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4177 sizeof(struct shadow_regs) +
4178 MEM_ALIGN_VALUE +
4179 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4180 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4181 &ha->queues_dma, GFP_KERNEL);
4182 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304183 ql4_printk(KERN_WARNING, ha,
4184 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004185
4186 goto mem_alloc_error_exit;
4187 }
4188 memset(ha->queues, 0, ha->queues_len);
4189
4190 /*
4191 * As per RISC alignment requirements -- the bus-address must be a
4192 * multiple of the request-ring size (in bytes).
4193 */
4194 align = 0;
4195 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4196 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4197 (MEM_ALIGN_VALUE - 1));
4198
4199 /* Update request and response queue pointers. */
4200 ha->request_dma = ha->queues_dma + align;
4201 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4202 ha->response_dma = ha->queues_dma + align +
4203 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4204 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4205 (REQUEST_QUEUE_DEPTH *
4206 QUEUE_SIZE));
4207 ha->shadow_regs_dma = ha->queues_dma + align +
4208 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4209 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4210 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4211 (REQUEST_QUEUE_DEPTH *
4212 QUEUE_SIZE) +
4213 (RESPONSE_QUEUE_DEPTH *
4214 QUEUE_SIZE));
4215
4216 /* Allocate memory for srb pool. */
4217 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4218 mempool_free_slab, srb_cachep);
4219 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304220 ql4_printk(KERN_WARNING, ha,
4221 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004222
4223 goto mem_alloc_error_exit;
4224 }
4225
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004226 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4227 CHAP_DMA_BLOCK_SIZE, 8, 0);
4228
4229 if (ha->chap_dma_pool == NULL) {
4230 ql4_printk(KERN_WARNING, ha,
4231 "%s: chap_dma_pool allocation failed..\n", __func__);
4232 goto mem_alloc_error_exit;
4233 }
4234
Mike Christie13483732011-12-01 21:38:41 -06004235 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4236 DDB_DMA_BLOCK_SIZE, 8, 0);
4237
4238 if (ha->fw_ddb_dma_pool == NULL) {
4239 ql4_printk(KERN_WARNING, ha,
4240 "%s: fw_ddb_dma_pool allocation failed..\n",
4241 __func__);
4242 goto mem_alloc_error_exit;
4243 }
4244
David Somayajuluafaf5a22006-09-19 10:28:00 -07004245 return QLA_SUCCESS;
4246
4247mem_alloc_error_exit:
4248 qla4xxx_mem_free(ha);
4249 return QLA_ERROR;
4250}
4251
4252/**
Mike Hernandez4f770832012-01-11 02:44:15 -08004253 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4254 * @ha: adapter block pointer.
4255 *
4256 * Note: The caller should not hold the idc lock.
4257 **/
4258static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4259{
4260 uint32_t temp, temp_state, temp_val;
4261 int status = QLA_SUCCESS;
4262
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004263 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004264
4265 temp_state = qla82xx_get_temp_state(temp);
4266 temp_val = qla82xx_get_temp_val(temp);
4267
4268 if (temp_state == QLA82XX_TEMP_PANIC) {
4269 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4270 " exceeds maximum allowed. Hardware has been shut"
4271 " down.\n", temp_val);
4272 status = QLA_ERROR;
4273 } else if (temp_state == QLA82XX_TEMP_WARN) {
4274 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4275 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4276 " degrees C exceeds operating range."
4277 " Immediate action needed.\n", temp_val);
4278 } else {
4279 if (ha->temperature == QLA82XX_TEMP_WARN)
4280 ql4_printk(KERN_INFO, ha, "Device temperature is"
4281 " now %d degrees C in normal range.\n",
4282 temp_val);
4283 }
4284 ha->temperature = temp_state;
4285 return status;
4286}
4287
4288/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304289 * qla4_8xxx_check_fw_alive - Check firmware health
4290 * @ha: Pointer to host adapter structure.
4291 *
4292 * Context: Interrupt
4293 **/
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004294static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304295{
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004296 uint32_t fw_heartbeat_counter;
4297 int status = QLA_SUCCESS;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304298
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004299 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4300 QLA8XXX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05304301 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4302 if (fw_heartbeat_counter == 0xffffffff) {
4303 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4304 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4305 ha->host_no, __func__));
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004306 return status;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304307 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304308
4309 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4310 ha->seconds_since_last_heartbeat++;
4311 /* FW not alive after 2 seconds */
4312 if (ha->seconds_since_last_heartbeat == 2) {
4313 ha->seconds_since_last_heartbeat = 0;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004314 qla4_8xxx_dump_peg_reg(ha);
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004315 status = QLA_ERROR;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304316 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07004317 } else
4318 ha->seconds_since_last_heartbeat = 0;
4319
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304320 ha->fw_heartbeat_counter = fw_heartbeat_counter;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004321 return status;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304322}
4323
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004324static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4325{
4326 uint32_t halt_status;
4327 int halt_status_unrecoverable = 0;
4328
4329 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4330
4331 if (is_qla8022(ha)) {
4332 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4333 __func__);
4334 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4335 CRB_NIU_XG_PAUSE_CTL_P0 |
4336 CRB_NIU_XG_PAUSE_CTL_P1);
4337
4338 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4339 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4340 __func__);
4341 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4342 halt_status_unrecoverable = 1;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004343 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004344 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4345 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4346 __func__);
4347 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4348 halt_status_unrecoverable = 1;
4349 }
4350
4351 /*
4352 * Since we cannot change dev_state in interrupt context,
4353 * set appropriate DPC flag then wakeup DPC
4354 */
4355 if (halt_status_unrecoverable) {
4356 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4357 } else {
4358 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4359 __func__);
4360 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4361 }
4362 qla4xxx_mailbox_premature_completion(ha);
4363 qla4xxx_wake_dpc(ha);
4364}
4365
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304366/**
4367 * qla4_8xxx_watchdog - Poll dev state
4368 * @ha: Pointer to host adapter structure.
4369 *
4370 * Context: Interrupt
4371 **/
4372void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4373{
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004374 uint32_t dev_state;
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004375 uint32_t idc_ctrl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304376
Vikas Chaudharya083e8b2013-12-16 06:49:32 -05004377 if (is_qla8032(ha) &&
4378 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4379 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4380 __func__, ha->func_num);
4381
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304382 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08004383 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4384 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07004385 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004386 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004387
4388 if (qla4_8xxx_check_temp(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004389 if (is_qla8022(ha)) {
4390 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4391 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4392 CRB_NIU_XG_PAUSE_CTL_P0 |
4393 CRB_NIU_XG_PAUSE_CTL_P1);
4394 }
Mike Hernandez4f770832012-01-11 02:44:15 -08004395 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4396 qla4xxx_wake_dpc(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004397 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004398 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004399
4400 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4401 __func__);
4402
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004403 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004404 idc_ctrl = qla4_83xx_rd_reg(ha,
4405 QLA83XX_IDC_DRV_CTRL);
4406 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4407 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4408 __func__);
4409 qla4xxx_mailbox_premature_completion(
4410 ha);
4411 }
4412 }
4413
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004414 if ((is_qla8032(ha) || is_qla8042(ha)) ||
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004415 (is_qla8022(ha) && !ql4xdontresethba)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004416 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4417 qla4xxx_wake_dpc(ha);
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004418 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004419 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304420 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004421 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4422 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304423 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4424 qla4xxx_wake_dpc(ha);
4425 } else {
4426 /* Check firmware health */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004427 if (qla4_8xxx_check_fw_alive(ha))
4428 qla4_8xxx_process_fw_error(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304429 }
4430 }
4431}
4432
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004433static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
Mike Christie13483732011-12-01 21:38:41 -06004434{
4435 struct iscsi_session *sess;
4436 struct ddb_entry *ddb_entry;
4437 struct scsi_qla_host *ha;
4438
4439 sess = cls_sess->dd_data;
4440 ddb_entry = sess->dd_data;
4441 ha = ddb_entry->ha;
4442
4443 if (!(ddb_entry->ddb_type == FLASH_DDB))
4444 return;
4445
4446 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4447 !iscsi_is_session_online(cls_sess)) {
4448 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4449 INVALID_ENTRY) {
4450 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4451 0) {
4452 atomic_set(&ddb_entry->retry_relogin_timer,
4453 INVALID_ENTRY);
4454 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4455 set_bit(DF_RELOGIN, &ddb_entry->flags);
4456 DEBUG2(ql4_printk(KERN_INFO, ha,
4457 "%s: index [%d] login device\n",
4458 __func__, ddb_entry->fw_ddb_index));
4459 } else
4460 atomic_dec(&ddb_entry->retry_relogin_timer);
4461 }
4462 }
4463
4464 /* Wait for relogin to timeout */
4465 if (atomic_read(&ddb_entry->relogin_timer) &&
4466 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4467 /*
4468 * If the relogin times out and the device is
4469 * still NOT ONLINE then try and relogin again.
4470 */
4471 if (!iscsi_is_session_online(cls_sess)) {
4472 /* Reset retry relogin timer */
4473 atomic_inc(&ddb_entry->relogin_retry_count);
4474 DEBUG2(ql4_printk(KERN_INFO, ha,
4475 "%s: index[%d] relogin timed out-retrying"
4476 " relogin (%d), retry (%d)\n", __func__,
4477 ddb_entry->fw_ddb_index,
4478 atomic_read(&ddb_entry->relogin_retry_count),
4479 ddb_entry->default_time2wait + 4));
4480 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4481 atomic_set(&ddb_entry->retry_relogin_timer,
4482 ddb_entry->default_time2wait + 4);
4483 }
4484 }
4485}
4486
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304487/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004488 * qla4xxx_timer - checks every second for work to do.
4489 * @ha: Pointer to host adapter structure.
4490 **/
4491static void qla4xxx_timer(struct scsi_qla_host *ha)
4492{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004493 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304494 uint16_t w;
4495
Mike Christie13483732011-12-01 21:38:41 -06004496 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4497
Lalit Chandivade2232be02010-07-30 14:38:47 +05304498 /* If we are in the middle of AER/EEH processing
4499 * skip any processing and reschedule the timer
4500 */
4501 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4502 mod_timer(&ha->timer, jiffies + HZ);
4503 return;
4504 }
4505
4506 /* Hardware read to trigger an EEH error during mailbox waits. */
4507 if (!pci_channel_offline(ha->pdev))
4508 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004509
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004510 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304511 qla4_8xxx_watchdog(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304512
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004513 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304514 /* Check for heartbeat interval. */
4515 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4516 ha->heartbeat_interval != 0) {
4517 ha->seconds_since_last_heartbeat++;
4518 if (ha->seconds_since_last_heartbeat >
4519 ha->heartbeat_interval + 2)
4520 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4521 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004522 }
4523
Vikas Chaudharyff884432011-08-29 23:43:02 +05304524 /* Process any deferred work. */
4525 if (!list_empty(&ha->work_list))
4526 start_dpc++;
4527
David Somayajuluafaf5a22006-09-19 10:28:00 -07004528 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07004529 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004530 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4531 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4532 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304533 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004534 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4535 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05304536 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304537 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4538 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07004539 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004540 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4541 " - dpc flags = 0x%lx\n",
4542 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304543 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004544 }
4545
4546 /* Reschedule timer thread to call us back in one second */
4547 mod_timer(&ha->timer, jiffies + HZ);
4548
4549 DEBUG2(ha->seconds_since_last_intr++);
4550}
4551
4552/**
4553 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4554 * @ha: Pointer to host adapter structure.
4555 *
4556 * This routine stalls the driver until all outstanding commands are returned.
4557 * Caller must release the Hardware Lock prior to calling this routine.
4558 **/
4559static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4560{
4561 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004562 unsigned long flags;
4563 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004564
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304565 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
4566
4567 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
4568 "complete\n", WAIT_CMD_TOV));
4569
4570 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004571 spin_lock_irqsave(&ha->hardware_lock, flags);
4572 /* Find a command that hasn't completed. */
4573 for (index = 0; index < ha->host->can_queue; index++) {
4574 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07004575 /*
4576 * We cannot just check if the index is valid,
4577 * becase if we are run from the scsi eh, then
4578 * the scsi/block layer is going to prevent
4579 * the tag from being released.
4580 */
4581 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07004582 break;
4583 }
4584 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4585
4586 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304587 if (index == ha->host->can_queue)
4588 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004589
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304590 msleep(1000);
4591 }
4592 /* If we timed out on waiting for commands to come back
4593 * return ERROR. */
4594 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004595}
4596
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304597int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004598{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004599 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004600 unsigned long flags = 0;
4601
4602 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004603
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304604 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4605 return QLA_ERROR;
4606
David Somayajuluafaf5a22006-09-19 10:28:00 -07004607 spin_lock_irqsave(&ha->hardware_lock, flags);
4608
4609 /*
4610 * If the SCSI Reset Interrupt bit is set, clear it.
4611 * Otherwise, the Soft Reset won't work.
4612 */
4613 ctrl_status = readw(&ha->reg->ctrl_status);
4614 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4615 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4616
4617 /* Issue Soft Reset */
4618 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4619 readl(&ha->reg->ctrl_status);
4620
4621 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304622 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004623}
4624
4625/**
4626 * qla4xxx_soft_reset - performs soft reset.
4627 * @ha: Pointer to host adapter structure.
4628 **/
4629int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4630{
4631 uint32_t max_wait_time;
4632 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004633 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004634 uint32_t ctrl_status;
4635
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004636 status = qla4xxx_hw_reset(ha);
4637 if (status != QLA_SUCCESS)
4638 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004639
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004640 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004641 /* Wait until the Network Reset Intr bit is cleared */
4642 max_wait_time = RESET_INTR_TOV;
4643 do {
4644 spin_lock_irqsave(&ha->hardware_lock, flags);
4645 ctrl_status = readw(&ha->reg->ctrl_status);
4646 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4647
4648 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4649 break;
4650
4651 msleep(1000);
4652 } while ((--max_wait_time));
4653
4654 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4655 DEBUG2(printk(KERN_WARNING
4656 "scsi%ld: Network Reset Intr not cleared by "
4657 "Network function, clearing it now!\n",
4658 ha->host_no));
4659 spin_lock_irqsave(&ha->hardware_lock, flags);
4660 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4661 readl(&ha->reg->ctrl_status);
4662 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4663 }
4664
4665 /* Wait until the firmware tells us the Soft Reset is done */
4666 max_wait_time = SOFT_RESET_TOV;
4667 do {
4668 spin_lock_irqsave(&ha->hardware_lock, flags);
4669 ctrl_status = readw(&ha->reg->ctrl_status);
4670 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4671
4672 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4673 status = QLA_SUCCESS;
4674 break;
4675 }
4676
4677 msleep(1000);
4678 } while ((--max_wait_time));
4679
4680 /*
4681 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4682 * after the soft reset has taken place.
4683 */
4684 spin_lock_irqsave(&ha->hardware_lock, flags);
4685 ctrl_status = readw(&ha->reg->ctrl_status);
4686 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4687 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4688 readl(&ha->reg->ctrl_status);
4689 }
4690 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4691
4692 /* If soft reset fails then most probably the bios on other
4693 * function is also enabled.
4694 * Since the initialization is sequential the other fn
4695 * wont be able to acknowledge the soft reset.
4696 * Issue a force soft reset to workaround this scenario.
4697 */
4698 if (max_wait_time == 0) {
4699 /* Issue Force Soft Reset */
4700 spin_lock_irqsave(&ha->hardware_lock, flags);
4701 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4702 readl(&ha->reg->ctrl_status);
4703 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4704 /* Wait until the firmware tells us the Soft Reset is done */
4705 max_wait_time = SOFT_RESET_TOV;
4706 do {
4707 spin_lock_irqsave(&ha->hardware_lock, flags);
4708 ctrl_status = readw(&ha->reg->ctrl_status);
4709 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4710
4711 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4712 status = QLA_SUCCESS;
4713 break;
4714 }
4715
4716 msleep(1000);
4717 } while ((--max_wait_time));
4718 }
4719
4720 return status;
4721}
4722
4723/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304724 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004725 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304726 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07004727 *
4728 * This routine is called just prior to a HARD RESET to return all
4729 * outstanding commands back to the Operating System.
4730 * Caller should make sure that the following locks are released
4731 * before this calling routine: Hardware lock, and io_request_lock.
4732 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304733static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004734{
4735 struct srb *srb;
4736 int i;
4737 unsigned long flags;
4738
4739 spin_lock_irqsave(&ha->hardware_lock, flags);
4740 for (i = 0; i < ha->host->can_queue; i++) {
4741 srb = qla4xxx_del_from_active_array(ha, i);
4742 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304743 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304744 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004745 }
4746 }
4747 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004748}
4749
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304750void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4751{
4752 clear_bit(AF_ONLINE, &ha->flags);
4753
4754 /* Disable the board */
4755 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304756
4757 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4758 qla4xxx_mark_all_devices_missing(ha);
4759 clear_bit(AF_INIT_DONE, &ha->flags);
4760}
4761
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004762static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4763{
4764 struct iscsi_session *sess;
4765 struct ddb_entry *ddb_entry;
4766
4767 sess = cls_session->dd_data;
4768 ddb_entry = sess->dd_data;
4769 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
Mike Christie13483732011-12-01 21:38:41 -06004770
4771 if (ddb_entry->ddb_type == FLASH_DDB)
4772 iscsi_block_session(ddb_entry->sess);
4773 else
4774 iscsi_session_failure(cls_session->dd_data,
4775 ISCSI_ERR_CONN_FAILED);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004776}
4777
David Somayajuluafaf5a22006-09-19 10:28:00 -07004778/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004779 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4780 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004781 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304782static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004783{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304784 int status = QLA_ERROR;
4785 uint8_t reset_chip = 0;
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004786 uint32_t dev_state;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004787 unsigned long wait;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004788
4789 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304790 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004791 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004792 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06004793
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304794 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004795
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304796 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004797
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004798 if ((is_qla8032(ha) || is_qla8042(ha)) &&
Tej Parkash546fef22012-09-20 07:35:12 -04004799 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4800 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4801 __func__);
4802 /* disable pause frame for ISP83xx */
4803 qla4_83xx_disable_pause(ha);
4804 }
4805
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004806 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4807
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304808 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4809 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004810
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304811 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4812 * do not reset adapter, jump to initialize_adapter */
4813 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4814 status = QLA_SUCCESS;
4815 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004816 }
4817
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004818 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304819 * from eh_host_reset or ioctl module */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004820 if (is_qla80XX(ha) && !reset_chip &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304821 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4822
4823 DEBUG2(ql4_printk(KERN_INFO, ha,
4824 "scsi%ld: %s - Performing stop_firmware...\n",
4825 ha->host_no, __func__));
4826 status = ha->isp_ops->reset_firmware(ha);
4827 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004828 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4829 qla4xxx_cmd_wait(ha);
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05004830
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304831 ha->isp_ops->disable_intrs(ha);
4832 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4833 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4834 } else {
4835 /* If the stop_firmware fails then
4836 * reset the entire chip */
4837 reset_chip = 1;
4838 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4839 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4840 }
4841 }
4842
4843 /* Issue full chip reset if recovering from a catastrophic error,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004844 * or if stop_firmware fails for ISP-8xxx.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304845 * This is the default case for ISP-4xxx */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004846 if (is_qla40XX(ha) || reset_chip) {
4847 if (is_qla40XX(ha))
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004848 goto chip_reset;
4849
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004850 /* Check if 8XXX firmware is alive or not
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004851 * We may have arrived here from NEED_RESET
4852 * detection only */
4853 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4854 goto chip_reset;
4855
4856 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4857 while (time_before(jiffies, wait)) {
4858 if (qla4_8xxx_check_fw_alive(ha)) {
4859 qla4xxx_mailbox_premature_completion(ha);
4860 break;
4861 }
4862
4863 set_current_state(TASK_UNINTERRUPTIBLE);
4864 schedule_timeout(HZ);
4865 }
Vikas Chaudharyda106212012-08-22 07:45:26 -04004866chip_reset:
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004867 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4868 qla4xxx_cmd_wait(ha);
Vikas Chaudharyda106212012-08-22 07:45:26 -04004869
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304870 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4871 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4872 DEBUG2(ql4_printk(KERN_INFO, ha,
4873 "scsi%ld: %s - Performing chip reset..\n",
4874 ha->host_no, __func__));
4875 status = ha->isp_ops->reset_chip(ha);
4876 }
4877
4878 /* Flush any pending ddb changed AENs */
4879 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4880
4881recover_ha_init_adapter:
4882 /* Upon successful firmware/chip reset, re-initialize the adapter */
4883 if (status == QLA_SUCCESS) {
4884 /* For ISP-4xxx, force function 1 to always initialize
4885 * before function 3 to prevent both funcions from
4886 * stepping on top of the other */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004887 if (is_qla40XX(ha) && (ha->mac_index == 3))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304888 ssleep(6);
4889
4890 /* NOTE: AF_ONLINE flag set upon successful completion of
Nilesh Javali37418cc2013-12-16 06:49:31 -05004891 * qla4xxx_initialize_adapter */
Mike Christie13483732011-12-01 21:38:41 -06004892 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Nilesh Javali37418cc2013-12-16 06:49:31 -05004893 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4894 status = qla4_8xxx_check_init_adapter_retry(ha);
4895 if (status == QLA_ERROR) {
4896 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4897 ha->host_no, __func__);
4898 qla4xxx_dead_adapter_cleanup(ha);
4899 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4900 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4901 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4902 &ha->dpc_flags);
4903 goto exit_recover;
4904 }
4905 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304906 }
4907
4908 /* Retry failed adapter initialization, if necessary
4909 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4910 * case to prevent ping-pong resets between functions */
4911 if (!test_bit(AF_ONLINE, &ha->flags) &&
4912 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004913 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304914 * resetting the ha.
4915 * Since we don't want to block the DPC for too long
4916 * with multiple resets in the same thread,
4917 * utilize DPC to retry */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004918 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004919 ha->isp_ops->idc_lock(ha);
4920 dev_state = qla4_8xxx_rd_direct(ha,
4921 QLA8XXX_CRB_DEV_STATE);
4922 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004923 if (dev_state == QLA8XXX_DEV_FAILED) {
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004924 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4925 "recover adapter. H/W is in Failed "
4926 "state\n", __func__);
4927 qla4xxx_dead_adapter_cleanup(ha);
4928 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4929 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4930 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4931 &ha->dpc_flags);
4932 status = QLA_ERROR;
4933
4934 goto exit_recover;
4935 }
4936 }
4937
David Somayajuluafaf5a22006-09-19 10:28:00 -07004938 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4939 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4940 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4941 "(%d) more times\n", ha->host_no,
4942 ha->retry_reset_ha_cnt));
4943 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4944 status = QLA_ERROR;
4945 } else {
4946 if (ha->retry_reset_ha_cnt > 0) {
4947 /* Schedule another Reset HA--DPC will retry */
4948 ha->retry_reset_ha_cnt--;
4949 DEBUG2(printk("scsi%ld: recover adapter - "
4950 "retry remaining %d\n",
4951 ha->host_no,
4952 ha->retry_reset_ha_cnt));
4953 status = QLA_ERROR;
4954 }
4955
4956 if (ha->retry_reset_ha_cnt == 0) {
4957 /* Recover adapter retries have been exhausted.
4958 * Adapter DEAD */
4959 DEBUG2(printk("scsi%ld: recover adapter "
4960 "failed - board disabled\n",
4961 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304962 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004963 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4964 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304965 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004966 &ha->dpc_flags);
4967 status = QLA_ERROR;
4968 }
4969 }
4970 } else {
4971 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304972 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004973 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4974 }
4975
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004976exit_recover:
David Somayajuluafaf5a22006-09-19 10:28:00 -07004977 ha->adapter_error_count++;
4978
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304979 if (test_bit(AF_ONLINE, &ha->flags))
4980 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004981
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304982 scsi_unblock_requests(ha->host);
4983
4984 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4985 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004986 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304987
David Somayajuluafaf5a22006-09-19 10:28:00 -07004988 return status;
4989}
4990
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004991static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004992{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004993 struct iscsi_session *sess;
4994 struct ddb_entry *ddb_entry;
4995 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004996
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004997 sess = cls_session->dd_data;
4998 ddb_entry = sess->dd_data;
4999 ha = ddb_entry->ha;
5000 if (!iscsi_is_session_online(cls_session)) {
5001 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5002 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5003 " unblock session\n", ha->host_no, __func__,
5004 ddb_entry->fw_ddb_index);
5005 iscsi_unblock_session(ddb_entry->sess);
5006 } else {
5007 /* Trigger relogin */
Mike Christie13483732011-12-01 21:38:41 -06005008 if (ddb_entry->ddb_type == FLASH_DDB) {
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04005009 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5010 test_bit(DF_DISABLE_RELOGIN,
5011 &ddb_entry->flags)))
Mike Christie13483732011-12-01 21:38:41 -06005012 qla4xxx_arm_relogin_timer(ddb_entry);
5013 } else
5014 iscsi_session_failure(cls_session->dd_data,
5015 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005016 }
5017 }
5018}
5019
Mike Christie13483732011-12-01 21:38:41 -06005020int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5021{
5022 struct iscsi_session *sess;
5023 struct ddb_entry *ddb_entry;
5024 struct scsi_qla_host *ha;
5025
5026 sess = cls_session->dd_data;
5027 ddb_entry = sess->dd_data;
5028 ha = ddb_entry->ha;
5029 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5030 " unblock session\n", ha->host_no, __func__,
5031 ddb_entry->fw_ddb_index);
5032
5033 iscsi_unblock_session(ddb_entry->sess);
5034
5035 /* Start scan target */
5036 if (test_bit(AF_ONLINE, &ha->flags)) {
5037 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5038 " start scan\n", ha->host_no, __func__,
5039 ddb_entry->fw_ddb_index);
5040 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5041 }
5042 return QLA_SUCCESS;
5043}
5044
5045int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5046{
5047 struct iscsi_session *sess;
5048 struct ddb_entry *ddb_entry;
5049 struct scsi_qla_host *ha;
Manish Rangankar80c53e62012-08-07 07:57:15 -04005050 int status = QLA_SUCCESS;
Mike Christie13483732011-12-01 21:38:41 -06005051
5052 sess = cls_session->dd_data;
5053 ddb_entry = sess->dd_data;
5054 ha = ddb_entry->ha;
5055 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5056 " unblock user space session\n", ha->host_no, __func__,
5057 ddb_entry->fw_ddb_index);
Mike Christie13483732011-12-01 21:38:41 -06005058
Manish Rangankar80c53e62012-08-07 07:57:15 -04005059 if (!iscsi_is_session_online(cls_session)) {
5060 iscsi_conn_start(ddb_entry->conn);
5061 iscsi_conn_login_event(ddb_entry->conn,
5062 ISCSI_CONN_STATE_LOGGED_IN);
5063 } else {
5064 ql4_printk(KERN_INFO, ha,
5065 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5066 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5067 cls_session->sid);
5068 status = QLA_ERROR;
5069 }
5070
5071 return status;
Mike Christie13483732011-12-01 21:38:41 -06005072}
5073
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005074static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5075{
5076 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5077}
5078
Mike Christie13483732011-12-01 21:38:41 -06005079static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5080{
5081 uint16_t relogin_timer;
5082 struct iscsi_session *sess;
5083 struct ddb_entry *ddb_entry;
5084 struct scsi_qla_host *ha;
5085
5086 sess = cls_sess->dd_data;
5087 ddb_entry = sess->dd_data;
5088 ha = ddb_entry->ha;
5089
5090 relogin_timer = max(ddb_entry->default_relogin_timeout,
5091 (uint16_t)RELOGIN_TOV);
5092 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5093
5094 DEBUG2(ql4_printk(KERN_INFO, ha,
5095 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5096 ddb_entry->fw_ddb_index, relogin_timer));
5097
5098 qla4xxx_login_flash_ddb(cls_sess);
5099}
5100
5101static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5102{
5103 struct iscsi_session *sess;
5104 struct ddb_entry *ddb_entry;
5105 struct scsi_qla_host *ha;
5106
5107 sess = cls_sess->dd_data;
5108 ddb_entry = sess->dd_data;
5109 ha = ddb_entry->ha;
5110
5111 if (!(ddb_entry->ddb_type == FLASH_DDB))
5112 return;
5113
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04005114 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5115 return;
5116
Mike Christie13483732011-12-01 21:38:41 -06005117 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5118 !iscsi_is_session_online(cls_sess)) {
5119 DEBUG2(ql4_printk(KERN_INFO, ha,
5120 "relogin issued\n"));
5121 qla4xxx_relogin_flash_ddb(cls_sess);
5122 }
5123}
5124
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305125void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5126{
Lalit Chandivade1b468072011-05-17 23:17:09 -07005127 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305128 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305129}
5130
Vikas Chaudharyff884432011-08-29 23:43:02 +05305131static struct qla4_work_evt *
5132qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5133 enum qla4_work_type type)
5134{
5135 struct qla4_work_evt *e;
5136 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5137
5138 e = kzalloc(size, GFP_ATOMIC);
5139 if (!e)
5140 return NULL;
5141
5142 INIT_LIST_HEAD(&e->list);
5143 e->type = type;
5144 return e;
5145}
5146
5147static void qla4xxx_post_work(struct scsi_qla_host *ha,
5148 struct qla4_work_evt *e)
5149{
5150 unsigned long flags;
5151
5152 spin_lock_irqsave(&ha->work_lock, flags);
5153 list_add_tail(&e->list, &ha->work_list);
5154 spin_unlock_irqrestore(&ha->work_lock, flags);
5155 qla4xxx_wake_dpc(ha);
5156}
5157
5158int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5159 enum iscsi_host_event_code aen_code,
5160 uint32_t data_size, uint8_t *data)
5161{
5162 struct qla4_work_evt *e;
5163
5164 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5165 if (!e)
5166 return QLA_ERROR;
5167
5168 e->u.aen.code = aen_code;
5169 e->u.aen.data_size = data_size;
5170 memcpy(e->u.aen.data, data, data_size);
5171
5172 qla4xxx_post_work(ha, e);
5173
5174 return QLA_SUCCESS;
5175}
5176
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05305177int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5178 uint32_t status, uint32_t pid,
5179 uint32_t data_size, uint8_t *data)
5180{
5181 struct qla4_work_evt *e;
5182
5183 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5184 if (!e)
5185 return QLA_ERROR;
5186
5187 e->u.ping.status = status;
5188 e->u.ping.pid = pid;
5189 e->u.ping.data_size = data_size;
5190 memcpy(e->u.ping.data, data, data_size);
5191
5192 qla4xxx_post_work(ha, e);
5193
5194 return QLA_SUCCESS;
5195}
5196
Vikas Chaudharya7380a62012-02-27 03:08:56 -08005197static void qla4xxx_do_work(struct scsi_qla_host *ha)
Vikas Chaudharyff884432011-08-29 23:43:02 +05305198{
5199 struct qla4_work_evt *e, *tmp;
5200 unsigned long flags;
5201 LIST_HEAD(work);
5202
5203 spin_lock_irqsave(&ha->work_lock, flags);
5204 list_splice_init(&ha->work_list, &work);
5205 spin_unlock_irqrestore(&ha->work_lock, flags);
5206
5207 list_for_each_entry_safe(e, tmp, &work, list) {
5208 list_del_init(&e->list);
5209
5210 switch (e->type) {
5211 case QLA4_EVENT_AEN:
5212 iscsi_post_host_event(ha->host_no,
5213 &qla4xxx_iscsi_transport,
5214 e->u.aen.code,
5215 e->u.aen.data_size,
5216 e->u.aen.data);
5217 break;
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05305218 case QLA4_EVENT_PING_STATUS:
5219 iscsi_ping_comp_event(ha->host_no,
5220 &qla4xxx_iscsi_transport,
5221 e->u.ping.status,
5222 e->u.ping.pid,
5223 e->u.ping.data_size,
5224 e->u.ping.data);
5225 break;
Vikas Chaudharyff884432011-08-29 23:43:02 +05305226 default:
5227 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5228 "supported", e->type);
5229 }
5230 kfree(e);
5231 }
5232}
5233
David Somayajuluafaf5a22006-09-19 10:28:00 -07005234/**
5235 * qla4xxx_do_dpc - dpc routine
5236 * @data: in our case pointer to adapter structure
5237 *
5238 * This routine is a task that is schedule by the interrupt handler
5239 * to perform the background processing for interrupts. We put it
5240 * on a task queue that is consumed whenever the scheduler runs; that's
5241 * so you can do anything (i.e. put the process to sleep etc). In fact,
5242 * the mid-level tries to sleep when it reaches the driver threshold
5243 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5244 **/
David Howellsc4028952006-11-22 14:57:56 +00005245static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005246{
David Howellsc4028952006-11-22 14:57:56 +00005247 struct scsi_qla_host *ha =
5248 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005249 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005250
David C Somayajuluf26b9042006-11-15 16:41:09 -08005251 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305252 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5253 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07005254
5255 /* Initialization not yet finished. Don't do anything yet. */
5256 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07005257 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005258
Lalit Chandivade2232be02010-07-30 14:38:47 +05305259 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5260 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5261 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07005262 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05305263 }
5264
Vikas Chaudharyff884432011-08-29 23:43:02 +05305265 /* post events to application */
5266 qla4xxx_do_work(ha);
5267
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005268 if (is_qla80XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305269 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005270 if (is_qla8032(ha) || is_qla8042(ha)) {
Tej Parkash546fef22012-09-20 07:35:12 -04005271 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5272 __func__);
5273 /* disable pause frame for ISP83xx */
5274 qla4_83xx_disable_pause(ha);
5275 }
5276
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005277 ha->isp_ops->idc_lock(ha);
5278 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5279 QLA8XXX_DEV_FAILED);
5280 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305281 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5282 qla4_8xxx_device_state_handler(ha);
5283 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005284
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005285 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5286 if (is_qla8042(ha)) {
5287 if (ha->idc_info.info2 &
5288 ENABLE_INTERNAL_LOOPBACK) {
5289 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5290 __func__);
5291 status = qla4_84xx_config_acb(ha,
5292 ACB_CONFIG_DISABLE);
5293 if (status != QLA_SUCCESS) {
5294 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5295 __func__);
5296 }
5297 }
5298 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005299 qla4_83xx_post_idc_ack(ha);
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005300 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5301 }
5302
5303 if (is_qla8042(ha) &&
5304 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5305 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5306 __func__);
5307 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5308 QLA_SUCCESS) {
5309 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5310 __func__);
5311 }
5312 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5313 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005314
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305315 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5316 qla4_8xxx_need_qsnt_handler(ha);
5317 }
5318 }
5319
5320 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5321 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07005322 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305323 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005324 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005325 ((is_qla8032(ha) || is_qla8042(ha)) &&
5326 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305327 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5328 ha->host_no, __func__));
5329 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5330 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5331 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5332 goto dpc_post_reset_ha;
5333 }
5334 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5335 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5336 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005337
David C Somayajulu477ffb92007-01-22 12:26:11 -08005338 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07005339 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005340
David Somayajuluafaf5a22006-09-19 10:28:00 -07005341 while ((readw(&ha->reg->ctrl_status) &
5342 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5343 if (--wait_time == 0)
5344 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005345 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005346 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005347 if (wait_time == 0)
5348 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5349 "bit not cleared-- resetting\n",
5350 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305351 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005352 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5353 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305354 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005355 }
5356 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5357 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305358 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005359 }
5360 }
5361
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305362dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07005363 /* ---- process AEN? --- */
5364 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5365 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5366
5367 /* ---- Get DHCP IP Address? --- */
5368 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5369 qla4xxx_get_dhcp_ip_address(ha);
5370
Mike Christie13483732011-12-01 21:38:41 -06005371 /* ---- relogin device? --- */
5372 if (adapter_up(ha) &&
5373 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5374 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5375 }
5376
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305377 /* ---- link change? --- */
Nilesh Javali026fbd32013-01-20 23:50:58 -05005378 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5379 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305380 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5381 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005382 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305383 } else {
5384 /* ---- link up? --- *
5385 * F/W will auto login to all devices ONLY ONCE after
5386 * link up during driver initialization and runtime
5387 * fatal error recovery. Therefore, the driver must
5388 * manually relogin to devices when recovering from
5389 * connection failures, logouts, expired KATO, etc. */
Mike Christie13483732011-12-01 21:38:41 -06005390 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5391 qla4xxx_build_ddb_list(ha, ha->is_reset);
5392 iscsi_host_for_each_session(ha->host,
5393 qla4xxx_login_flash_ddb);
5394 } else
5395 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305396 }
5397 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005398}
5399
5400/**
5401 * qla4xxx_free_adapter - release the adapter
5402 * @ha: pointer to adapter structure
5403 **/
5404static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5405{
Sarang Radke8a28896012011-12-06 02:34:10 -08005406 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005407
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005408 /* Turn-off interrupts on the card. */
5409 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005410
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005411 if (is_qla40XX(ha)) {
5412 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5413 &ha->reg->ctrl_status);
5414 readl(&ha->reg->ctrl_status);
5415 } else if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005416 writel(0, &ha->qla4_82xx_reg->host_int);
5417 readl(&ha->qla4_82xx_reg->host_int);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005418 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudharyfbd81072012-09-20 07:35:03 -04005419 writel(0, &ha->qla4_83xx_reg->risc_intr);
5420 readl(&ha->qla4_83xx_reg->risc_intr);
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005421 }
5422
David Somayajuluafaf5a22006-09-19 10:28:00 -07005423 /* Remove timer thread, if present */
5424 if (ha->timer_active)
5425 qla4xxx_stop_timer(ha);
5426
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305427 /* Kill the kernel thread for this host */
5428 if (ha->dpc_thread)
5429 destroy_workqueue(ha->dpc_thread);
5430
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005431 /* Kill the kernel thread for this host */
5432 if (ha->task_wq)
5433 destroy_workqueue(ha->task_wq);
5434
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305435 /* Put firmware in known state */
5436 ha->isp_ops->reset_firmware(ha);
5437
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005438 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005439 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305440 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005441 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305442 }
5443
David Somayajuluafaf5a22006-09-19 10:28:00 -07005444 /* Detach interrupts */
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005445 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005446
David C Somayajulubee4fe82007-05-23 18:03:32 -07005447 /* free extra memory */
5448 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305449}
David C Somayajulubee4fe82007-05-23 18:03:32 -07005450
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305451int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5452{
5453 int status = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305454 unsigned long mem_base, mem_len, db_base, db_len;
5455 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005456
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305457 status = pci_request_regions(pdev, DRIVER_NAME);
5458 if (status) {
5459 printk(KERN_WARNING
5460 "scsi(%ld) Failed to reserve PIO regions (%s) "
5461 "status=%d\n", ha->host_no, pci_name(pdev), status);
5462 goto iospace_error_exit;
5463 }
5464
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305465 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
Sergei Shtylyov7d7311c2012-03-14 22:04:30 +03005466 __func__, pdev->revision));
5467 ha->revision_id = pdev->revision;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305468
5469 /* remap phys address */
5470 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5471 mem_len = pci_resource_len(pdev, 0);
5472 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5473 __func__, mem_base, mem_len));
5474
5475 /* mapping of pcibase pointer */
5476 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5477 if (!ha->nx_pcibase) {
5478 printk(KERN_ERR
5479 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5480 pci_release_regions(ha->pdev);
5481 goto iospace_error_exit;
5482 }
5483
5484 /* Mapping of IO base pointer, door bell read and write pointer */
5485
5486 /* mapping of IO base pointer */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005487 if (is_qla8022(ha)) {
5488 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5489 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5490 (ha->pdev->devfn << 11));
5491 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5492 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005493 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005494 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5495 ((uint8_t *)ha->nx_pcibase);
5496 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305497
5498 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5499 db_len = pci_resource_len(pdev, 4);
5500
Shyam Sundar2657c802010-10-06 22:50:29 -07005501 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305502iospace_error_exit:
5503 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005504}
5505
5506/***
5507 * qla4xxx_iospace_config - maps registers
5508 * @ha: pointer to adapter structure
5509 *
5510 * This routines maps HBA's registers from the pci address space
5511 * into the kernel virtual address space for memory mapped i/o.
5512 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305513int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005514{
5515 unsigned long pio, pio_len, pio_flags;
5516 unsigned long mmio, mmio_len, mmio_flags;
5517
5518 pio = pci_resource_start(ha->pdev, 0);
5519 pio_len = pci_resource_len(ha->pdev, 0);
5520 pio_flags = pci_resource_flags(ha->pdev, 0);
5521 if (pio_flags & IORESOURCE_IO) {
5522 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305523 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07005524 "Invalid PCI I/O region size\n");
5525 pio = 0;
5526 }
5527 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305528 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005529 pio = 0;
5530 }
5531
5532 /* Use MMIO operations for all accesses. */
5533 mmio = pci_resource_start(ha->pdev, 1);
5534 mmio_len = pci_resource_len(ha->pdev, 1);
5535 mmio_flags = pci_resource_flags(ha->pdev, 1);
5536
5537 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305538 ql4_printk(KERN_ERR, ha,
5539 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005540
5541 goto iospace_error_exit;
5542 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305543
David Somayajuluafaf5a22006-09-19 10:28:00 -07005544 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305545 ql4_printk(KERN_ERR, ha,
5546 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005547 goto iospace_error_exit;
5548 }
5549
5550 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305551 ql4_printk(KERN_WARNING, ha,
5552 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005553
5554 goto iospace_error_exit;
5555 }
5556
5557 ha->pio_address = pio;
5558 ha->pio_length = pio_len;
5559 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5560 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305561 ql4_printk(KERN_ERR, ha,
5562 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005563
5564 goto iospace_error_exit;
5565 }
5566
5567 return 0;
5568
5569iospace_error_exit:
5570 return -ENOMEM;
5571}
5572
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305573static struct isp_operations qla4xxx_isp_ops = {
5574 .iospace_config = qla4xxx_iospace_config,
5575 .pci_config = qla4xxx_pci_config,
5576 .disable_intrs = qla4xxx_disable_intrs,
5577 .enable_intrs = qla4xxx_enable_intrs,
5578 .start_firmware = qla4xxx_start_firmware,
5579 .intr_handler = qla4xxx_intr_handler,
5580 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5581 .reset_chip = qla4xxx_soft_reset,
5582 .reset_firmware = qla4xxx_hw_reset,
5583 .queue_iocb = qla4xxx_queue_iocb,
5584 .complete_iocb = qla4xxx_complete_iocb,
5585 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5586 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5587 .get_sys_info = qla4xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005588 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5589 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305590};
5591
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005592static struct isp_operations qla4_82xx_isp_ops = {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305593 .iospace_config = qla4_8xxx_iospace_config,
5594 .pci_config = qla4_8xxx_pci_config,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005595 .disable_intrs = qla4_82xx_disable_intrs,
5596 .enable_intrs = qla4_82xx_enable_intrs,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305597 .start_firmware = qla4_8xxx_load_risc,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005598 .restart_firmware = qla4_82xx_try_start_fw,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005599 .intr_handler = qla4_82xx_intr_handler,
5600 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005601 .need_reset = qla4_8xxx_need_reset,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005602 .reset_chip = qla4_82xx_isp_reset,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305603 .reset_firmware = qla4_8xxx_stop_firmware,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005604 .queue_iocb = qla4_82xx_queue_iocb,
5605 .complete_iocb = qla4_82xx_complete_iocb,
5606 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5607 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305608 .get_sys_info = qla4_8xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005609 .rd_reg_direct = qla4_82xx_rd_32,
5610 .wr_reg_direct = qla4_82xx_wr_32,
5611 .rd_reg_indirect = qla4_82xx_md_rd_32,
5612 .wr_reg_indirect = qla4_82xx_md_wr_32,
5613 .idc_lock = qla4_82xx_idc_lock,
5614 .idc_unlock = qla4_82xx_idc_unlock,
5615 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5616 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5617 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305618};
5619
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005620static struct isp_operations qla4_83xx_isp_ops = {
5621 .iospace_config = qla4_8xxx_iospace_config,
5622 .pci_config = qla4_8xxx_pci_config,
5623 .disable_intrs = qla4_83xx_disable_intrs,
5624 .enable_intrs = qla4_83xx_enable_intrs,
5625 .start_firmware = qla4_8xxx_load_risc,
5626 .restart_firmware = qla4_83xx_start_firmware,
5627 .intr_handler = qla4_83xx_intr_handler,
5628 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5629 .need_reset = qla4_8xxx_need_reset,
5630 .reset_chip = qla4_83xx_isp_reset,
5631 .reset_firmware = qla4_8xxx_stop_firmware,
5632 .queue_iocb = qla4_83xx_queue_iocb,
5633 .complete_iocb = qla4_83xx_complete_iocb,
Tej Parkasha24058f2013-03-07 05:43:13 -05005634 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5635 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005636 .get_sys_info = qla4_8xxx_get_sys_info,
5637 .rd_reg_direct = qla4_83xx_rd_reg,
5638 .wr_reg_direct = qla4_83xx_wr_reg,
5639 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5640 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5641 .idc_lock = qla4_83xx_drv_lock,
5642 .idc_unlock = qla4_83xx_drv_unlock,
5643 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5644 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5645 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305646};
5647
5648uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5649{
5650 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5651}
5652
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005653uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305654{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005655 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305656}
5657
5658uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5659{
5660 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5661}
5662
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005663uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305664{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005665 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305666}
5667
Manish Rangankar2a991c22011-07-25 13:48:55 -05005668static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5669{
5670 struct scsi_qla_host *ha = data;
5671 char *str = buf;
5672 int rc;
5673
5674 switch (type) {
5675 case ISCSI_BOOT_ETH_FLAGS:
5676 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5677 break;
5678 case ISCSI_BOOT_ETH_INDEX:
5679 rc = sprintf(str, "0\n");
5680 break;
5681 case ISCSI_BOOT_ETH_MAC:
5682 rc = sysfs_format_mac(str, ha->my_mac,
5683 MAC_ADDR_LEN);
5684 break;
5685 default:
5686 rc = -ENOSYS;
5687 break;
5688 }
5689 return rc;
5690}
5691
Al Viro587a1f12011-07-23 23:11:19 -04005692static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005693{
5694 int rc;
5695
5696 switch (type) {
5697 case ISCSI_BOOT_ETH_FLAGS:
5698 case ISCSI_BOOT_ETH_MAC:
5699 case ISCSI_BOOT_ETH_INDEX:
5700 rc = S_IRUGO;
5701 break;
5702 default:
5703 rc = 0;
5704 break;
5705 }
5706 return rc;
5707}
5708
5709static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5710{
5711 struct scsi_qla_host *ha = data;
5712 char *str = buf;
5713 int rc;
5714
5715 switch (type) {
5716 case ISCSI_BOOT_INI_INITIATOR_NAME:
5717 rc = sprintf(str, "%s\n", ha->name_string);
5718 break;
5719 default:
5720 rc = -ENOSYS;
5721 break;
5722 }
5723 return rc;
5724}
5725
Al Viro587a1f12011-07-23 23:11:19 -04005726static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005727{
5728 int rc;
5729
5730 switch (type) {
5731 case ISCSI_BOOT_INI_INITIATOR_NAME:
5732 rc = S_IRUGO;
5733 break;
5734 default:
5735 rc = 0;
5736 break;
5737 }
5738 return rc;
5739}
5740
5741static ssize_t
5742qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5743 char *buf)
5744{
5745 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5746 char *str = buf;
5747 int rc;
5748
5749 switch (type) {
5750 case ISCSI_BOOT_TGT_NAME:
5751 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5752 break;
5753 case ISCSI_BOOT_TGT_IP_ADDR:
5754 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5755 rc = sprintf(buf, "%pI4\n",
5756 &boot_conn->dest_ipaddr.ip_address);
5757 else
5758 rc = sprintf(str, "%pI6\n",
5759 &boot_conn->dest_ipaddr.ip_address);
5760 break;
5761 case ISCSI_BOOT_TGT_PORT:
5762 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5763 break;
5764 case ISCSI_BOOT_TGT_CHAP_NAME:
5765 rc = sprintf(str, "%.*s\n",
5766 boot_conn->chap.target_chap_name_length,
5767 (char *)&boot_conn->chap.target_chap_name);
5768 break;
5769 case ISCSI_BOOT_TGT_CHAP_SECRET:
5770 rc = sprintf(str, "%.*s\n",
5771 boot_conn->chap.target_secret_length,
5772 (char *)&boot_conn->chap.target_secret);
5773 break;
5774 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5775 rc = sprintf(str, "%.*s\n",
5776 boot_conn->chap.intr_chap_name_length,
5777 (char *)&boot_conn->chap.intr_chap_name);
5778 break;
5779 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5780 rc = sprintf(str, "%.*s\n",
5781 boot_conn->chap.intr_secret_length,
5782 (char *)&boot_conn->chap.intr_secret);
5783 break;
5784 case ISCSI_BOOT_TGT_FLAGS:
5785 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5786 break;
5787 case ISCSI_BOOT_TGT_NIC_ASSOC:
5788 rc = sprintf(str, "0\n");
5789 break;
5790 default:
5791 rc = -ENOSYS;
5792 break;
5793 }
5794 return rc;
5795}
5796
5797static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5798{
5799 struct scsi_qla_host *ha = data;
5800 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5801
5802 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5803}
5804
5805static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5806{
5807 struct scsi_qla_host *ha = data;
5808 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5809
5810 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5811}
5812
Al Viro587a1f12011-07-23 23:11:19 -04005813static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005814{
5815 int rc;
5816
5817 switch (type) {
5818 case ISCSI_BOOT_TGT_NAME:
5819 case ISCSI_BOOT_TGT_IP_ADDR:
5820 case ISCSI_BOOT_TGT_PORT:
5821 case ISCSI_BOOT_TGT_CHAP_NAME:
5822 case ISCSI_BOOT_TGT_CHAP_SECRET:
5823 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5824 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5825 case ISCSI_BOOT_TGT_NIC_ASSOC:
5826 case ISCSI_BOOT_TGT_FLAGS:
5827 rc = S_IRUGO;
5828 break;
5829 default:
5830 rc = 0;
5831 break;
5832 }
5833 return rc;
5834}
5835
5836static void qla4xxx_boot_release(void *data)
5837{
5838 struct scsi_qla_host *ha = data;
5839
5840 scsi_host_put(ha->host);
5841}
5842
5843static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5844{
5845 dma_addr_t buf_dma;
5846 uint32_t addr, pri_addr, sec_addr;
5847 uint32_t offset;
5848 uint16_t func_num;
5849 uint8_t val;
5850 uint8_t *buf = NULL;
5851 size_t size = 13 * sizeof(uint8_t);
5852 int ret = QLA_SUCCESS;
5853
5854 func_num = PCI_FUNC(ha->pdev->devfn);
5855
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005856 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5857 __func__, ha->pdev->device, func_num);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005858
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005859 if (is_qla40XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005860 if (func_num == 1) {
5861 addr = NVRAM_PORT0_BOOT_MODE;
5862 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5863 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5864 } else if (func_num == 3) {
5865 addr = NVRAM_PORT1_BOOT_MODE;
5866 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5867 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5868 } else {
5869 ret = QLA_ERROR;
5870 goto exit_boot_info;
5871 }
5872
5873 /* Check Boot Mode */
5874 val = rd_nvram_byte(ha, addr);
5875 if (!(val & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305876 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5877 "options : 0x%x\n", __func__, val));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005878 ret = QLA_ERROR;
5879 goto exit_boot_info;
5880 }
5881
5882 /* get primary valid target index */
5883 val = rd_nvram_byte(ha, pri_addr);
5884 if (val & BIT_7)
5885 ddb_index[0] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005886
5887 /* get secondary valid target index */
5888 val = rd_nvram_byte(ha, sec_addr);
5889 if (val & BIT_7)
5890 ddb_index[1] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005891
Vikas Chaudhary3e788fb2013-03-07 05:43:08 -05005892 } else if (is_qla80XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005893 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5894 &buf_dma, GFP_KERNEL);
5895 if (!buf) {
5896 DEBUG2(ql4_printk(KERN_ERR, ha,
5897 "%s: Unable to allocate dma buffer\n",
5898 __func__));
5899 ret = QLA_ERROR;
5900 goto exit_boot_info;
5901 }
5902
5903 if (ha->port_num == 0)
5904 offset = BOOT_PARAM_OFFSET_PORT0;
5905 else if (ha->port_num == 1)
5906 offset = BOOT_PARAM_OFFSET_PORT1;
5907 else {
5908 ret = QLA_ERROR;
5909 goto exit_boot_info_free;
5910 }
5911 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5912 offset;
5913 if (qla4xxx_get_flash(ha, buf_dma, addr,
5914 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5915 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
Petr Uzel0bd7f842012-02-24 16:32:59 +01005916 " failed\n", ha->host_no, __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005917 ret = QLA_ERROR;
5918 goto exit_boot_info_free;
5919 }
5920 /* Check Boot Mode */
5921 if (!(buf[1] & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305922 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5923 " : 0x%x\n", buf[1]));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005924 ret = QLA_ERROR;
5925 goto exit_boot_info_free;
5926 }
5927
5928 /* get primary valid target index */
5929 if (buf[2] & BIT_7)
5930 ddb_index[0] = buf[2] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005931
5932 /* get secondary valid target index */
5933 if (buf[11] & BIT_7)
5934 ddb_index[1] = buf[11] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005935 } else {
5936 ret = QLA_ERROR;
5937 goto exit_boot_info;
5938 }
5939
5940 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5941 " target ID %d\n", __func__, ddb_index[0],
5942 ddb_index[1]));
5943
5944exit_boot_info_free:
5945 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5946exit_boot_info:
Lalit Chandivade20e835b2012-02-13 18:30:42 +05305947 ha->pri_ddb_idx = ddb_index[0];
5948 ha->sec_ddb_idx = ddb_index[1];
Manish Rangankar2a991c22011-07-25 13:48:55 -05005949 return ret;
5950}
5951
Lalit Chandivade28deb452011-10-07 16:55:44 -07005952/**
5953 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5954 * @ha: pointer to adapter structure
5955 * @username: CHAP username to be returned
5956 * @password: CHAP password to be returned
5957 *
5958 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
5959 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
5960 * So from the CHAP cache find the first BIDI CHAP entry and set it
5961 * to the boot record in sysfs.
5962 **/
5963static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
5964 char *password)
5965{
5966 int i, ret = -EINVAL;
5967 int max_chap_entries = 0;
5968 struct ql4_chap_table *chap_table;
5969
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -04005970 if (is_qla80XX(ha))
Lalit Chandivade28deb452011-10-07 16:55:44 -07005971 max_chap_entries = (ha->hw.flt_chap_size / 2) /
5972 sizeof(struct ql4_chap_table);
5973 else
5974 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
5975
5976 if (!ha->chap_list) {
5977 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
5978 return ret;
5979 }
5980
5981 mutex_lock(&ha->chap_sem);
5982 for (i = 0; i < max_chap_entries; i++) {
5983 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
5984 if (chap_table->cookie !=
5985 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
5986 continue;
5987 }
5988
5989 if (chap_table->flags & BIT_7) /* local */
5990 continue;
5991
5992 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
5993 continue;
5994
5995 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
5996 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
5997 ret = 0;
5998 break;
5999 }
6000 mutex_unlock(&ha->chap_sem);
6001
6002 return ret;
6003}
6004
6005
Manish Rangankar2a991c22011-07-25 13:48:55 -05006006static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6007 struct ql4_boot_session_info *boot_sess,
6008 uint16_t ddb_index)
6009{
6010 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6011 struct dev_db_entry *fw_ddb_entry;
6012 dma_addr_t fw_ddb_entry_dma;
6013 uint16_t idx;
6014 uint16_t options;
6015 int ret = QLA_SUCCESS;
6016
6017 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6018 &fw_ddb_entry_dma, GFP_KERNEL);
6019 if (!fw_ddb_entry) {
6020 DEBUG2(ql4_printk(KERN_ERR, ha,
6021 "%s: Unable to allocate dma buffer.\n",
6022 __func__));
6023 ret = QLA_ERROR;
6024 return ret;
6025 }
6026
6027 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6028 fw_ddb_entry_dma, ddb_index)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306029 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6030 "index [%d]\n", __func__, ddb_index));
Manish Rangankar2a991c22011-07-25 13:48:55 -05006031 ret = QLA_ERROR;
6032 goto exit_boot_target;
6033 }
6034
6035 /* Update target name and IP from DDB */
6036 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6037 min(sizeof(boot_sess->target_name),
6038 sizeof(fw_ddb_entry->iscsi_name)));
6039
6040 options = le16_to_cpu(fw_ddb_entry->options);
6041 if (options & DDB_OPT_IPV6_DEVICE) {
6042 memcpy(&boot_conn->dest_ipaddr.ip_address,
6043 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6044 } else {
6045 boot_conn->dest_ipaddr.ip_type = 0x1;
6046 memcpy(&boot_conn->dest_ipaddr.ip_address,
6047 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6048 }
6049
6050 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6051
6052 /* update chap information */
6053 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6054
6055 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6056
6057 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6058
6059 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6060 target_chap_name,
6061 (char *)&boot_conn->chap.target_secret,
6062 idx);
6063 if (ret) {
6064 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6065 ret = QLA_ERROR;
6066 goto exit_boot_target;
6067 }
6068
6069 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6070 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6071 }
6072
6073 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6074
6075 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6076
Lalit Chandivade28deb452011-10-07 16:55:44 -07006077 ret = qla4xxx_get_bidi_chap(ha,
6078 (char *)&boot_conn->chap.intr_chap_name,
6079 (char *)&boot_conn->chap.intr_secret);
6080
Manish Rangankar2a991c22011-07-25 13:48:55 -05006081 if (ret) {
6082 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6083 ret = QLA_ERROR;
6084 goto exit_boot_target;
6085 }
6086
6087 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6088 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6089 }
6090
6091exit_boot_target:
6092 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6093 fw_ddb_entry, fw_ddb_entry_dma);
6094 return ret;
6095}
6096
6097static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6098{
6099 uint16_t ddb_index[2];
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006100 int ret = QLA_ERROR;
6101 int rval;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006102
6103 memset(ddb_index, 0, sizeof(ddb_index));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006104 ddb_index[0] = 0xffff;
6105 ddb_index[1] = 0xffff;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006106 ret = get_fw_boot_info(ha, ddb_index);
6107 if (ret != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306108 DEBUG2(ql4_printk(KERN_INFO, ha,
6109 "%s: No boot target configured.\n", __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05006110 return ret;
6111 }
6112
Mike Christie13483732011-12-01 21:38:41 -06006113 if (ql4xdisablesysfsboot)
6114 return QLA_SUCCESS;
6115
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006116 if (ddb_index[0] == 0xffff)
6117 goto sec_target;
6118
6119 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05006120 ddb_index[0]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006121 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306122 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6123 "configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006124 } else
6125 ret = QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006126
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006127sec_target:
6128 if (ddb_index[1] == 0xffff)
6129 goto exit_get_boot_info;
6130
6131 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05006132 ddb_index[1]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006133 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306134 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6135 " configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006136 } else
6137 ret = QLA_SUCCESS;
6138
6139exit_get_boot_info:
Manish Rangankar2a991c22011-07-25 13:48:55 -05006140 return ret;
6141}
6142
6143static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6144{
6145 struct iscsi_boot_kobj *boot_kobj;
6146
6147 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
Mike Christie13483732011-12-01 21:38:41 -06006148 return QLA_ERROR;
6149
6150 if (ql4xdisablesysfsboot) {
6151 ql4_printk(KERN_INFO, ha,
Petr Uzel0bd7f842012-02-24 16:32:59 +01006152 "%s: syfsboot disabled - driver will trigger login "
Mike Christie13483732011-12-01 21:38:41 -06006153 "and publish session for discovery .\n", __func__);
6154 return QLA_SUCCESS;
6155 }
6156
Manish Rangankar2a991c22011-07-25 13:48:55 -05006157
6158 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6159 if (!ha->boot_kset)
6160 goto kset_free;
6161
6162 if (!scsi_host_get(ha->host))
6163 goto kset_free;
6164 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6165 qla4xxx_show_boot_tgt_pri_info,
6166 qla4xxx_tgt_get_attr_visibility,
6167 qla4xxx_boot_release);
6168 if (!boot_kobj)
6169 goto put_host;
6170
6171 if (!scsi_host_get(ha->host))
6172 goto kset_free;
6173 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6174 qla4xxx_show_boot_tgt_sec_info,
6175 qla4xxx_tgt_get_attr_visibility,
6176 qla4xxx_boot_release);
6177 if (!boot_kobj)
6178 goto put_host;
6179
6180 if (!scsi_host_get(ha->host))
6181 goto kset_free;
6182 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6183 qla4xxx_show_boot_ini_info,
6184 qla4xxx_ini_get_attr_visibility,
6185 qla4xxx_boot_release);
6186 if (!boot_kobj)
6187 goto put_host;
6188
6189 if (!scsi_host_get(ha->host))
6190 goto kset_free;
6191 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6192 qla4xxx_show_boot_eth_info,
6193 qla4xxx_eth_get_attr_visibility,
6194 qla4xxx_boot_release);
6195 if (!boot_kobj)
6196 goto put_host;
6197
Mike Christie13483732011-12-01 21:38:41 -06006198 return QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006199
6200put_host:
6201 scsi_host_put(ha->host);
6202kset_free:
6203 iscsi_boot_destroy_kset(ha->boot_kset);
6204 return -ENOMEM;
6205}
6206
Lalit Chandivade45494152011-10-07 16:55:42 -07006207
Mike Christie13483732011-12-01 21:38:41 -06006208static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6209 struct ql4_tuple_ddb *tddb)
6210{
6211 struct scsi_qla_host *ha;
6212 struct iscsi_cls_session *cls_sess;
6213 struct iscsi_cls_conn *cls_conn;
6214 struct iscsi_session *sess;
6215 struct iscsi_conn *conn;
6216
6217 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6218 ha = ddb_entry->ha;
6219 cls_sess = ddb_entry->sess;
6220 sess = cls_sess->dd_data;
6221 cls_conn = ddb_entry->conn;
6222 conn = cls_conn->dd_data;
6223
6224 tddb->tpgt = sess->tpgt;
6225 tddb->port = conn->persistent_port;
6226 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6227 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6228}
6229
6230static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006231 struct ql4_tuple_ddb *tddb,
6232 uint8_t *flash_isid)
Mike Christie13483732011-12-01 21:38:41 -06006233{
6234 uint16_t options = 0;
6235
6236 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6237 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6238 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6239
6240 options = le16_to_cpu(fw_ddb_entry->options);
6241 if (options & DDB_OPT_IPV6_DEVICE)
6242 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6243 else
6244 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6245
6246 tddb->port = le16_to_cpu(fw_ddb_entry->port);
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006247
6248 if (flash_isid == NULL)
6249 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6250 sizeof(tddb->isid));
6251 else
6252 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
Mike Christie13483732011-12-01 21:38:41 -06006253}
6254
6255static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6256 struct ql4_tuple_ddb *old_tddb,
Manish Rangankar173269e2012-02-27 03:08:55 -08006257 struct ql4_tuple_ddb *new_tddb,
6258 uint8_t is_isid_compare)
Mike Christie13483732011-12-01 21:38:41 -06006259{
6260 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6261 return QLA_ERROR;
6262
6263 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6264 return QLA_ERROR;
6265
6266 if (old_tddb->port != new_tddb->port)
6267 return QLA_ERROR;
6268
Manish Rangankar173269e2012-02-27 03:08:55 -08006269 /* For multi sessions, driver generates the ISID, so do not compare
Masanari Iida59e13d42012-04-25 00:24:16 +09006270 * ISID in reset path since it would be a comparison between the
Manish Rangankar173269e2012-02-27 03:08:55 -08006271 * driver generated ISID and firmware generated ISID. This could
6272 * lead to adding duplicated DDBs in the list as driver generated
6273 * ISID would not match firmware generated ISID.
6274 */
6275 if (is_isid_compare) {
6276 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
6277 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
6278 __func__, old_tddb->isid[5], old_tddb->isid[4],
6279 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
6280 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
6281 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
6282 new_tddb->isid[0]));
6283
6284 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6285 sizeof(old_tddb->isid)))
6286 return QLA_ERROR;
6287 }
6288
Mike Christie13483732011-12-01 21:38:41 -06006289 DEBUG2(ql4_printk(KERN_INFO, ha,
6290 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6291 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6292 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6293 new_tddb->ip_addr, new_tddb->iscsi_name));
6294
6295 return QLA_SUCCESS;
6296}
6297
6298static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006299 struct dev_db_entry *fw_ddb_entry,
6300 uint32_t *index)
Mike Christie13483732011-12-01 21:38:41 -06006301{
6302 struct ddb_entry *ddb_entry;
6303 struct ql4_tuple_ddb *fw_tddb = NULL;
6304 struct ql4_tuple_ddb *tmp_tddb = NULL;
6305 int idx;
6306 int ret = QLA_ERROR;
6307
6308 fw_tddb = vzalloc(sizeof(*fw_tddb));
6309 if (!fw_tddb) {
6310 DEBUG2(ql4_printk(KERN_WARNING, ha,
6311 "Memory Allocation failed.\n"));
6312 ret = QLA_SUCCESS;
6313 goto exit_check;
6314 }
6315
6316 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6317 if (!tmp_tddb) {
6318 DEBUG2(ql4_printk(KERN_WARNING, ha,
6319 "Memory Allocation failed.\n"));
6320 ret = QLA_SUCCESS;
6321 goto exit_check;
6322 }
6323
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006324 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006325
6326 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6327 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6328 if (ddb_entry == NULL)
6329 continue;
6330
6331 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
Manish Rangankar173269e2012-02-27 03:08:55 -08006332 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
Mike Christie13483732011-12-01 21:38:41 -06006333 ret = QLA_SUCCESS; /* found */
Manish Rangankarad8bd452013-09-17 07:30:02 -04006334 if (index != NULL)
6335 *index = idx;
Mike Christie13483732011-12-01 21:38:41 -06006336 goto exit_check;
6337 }
6338 }
6339
6340exit_check:
6341 if (fw_tddb)
6342 vfree(fw_tddb);
6343 if (tmp_tddb)
6344 vfree(tmp_tddb);
6345 return ret;
6346}
6347
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006348/**
6349 * qla4xxx_check_existing_isid - check if target with same isid exist
6350 * in target list
6351 * @list_nt: list of target
6352 * @isid: isid to check
6353 *
6354 * This routine return QLA_SUCCESS if target with same isid exist
6355 **/
6356static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6357{
6358 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6359 struct dev_db_entry *fw_ddb_entry;
6360
6361 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6362 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6363
6364 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6365 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6366 return QLA_SUCCESS;
6367 }
6368 }
6369 return QLA_ERROR;
6370}
6371
6372/**
6373 * qla4xxx_update_isid - compare ddbs and updated isid
6374 * @ha: Pointer to host adapter structure.
6375 * @list_nt: list of nt target
6376 * @fw_ddb_entry: firmware ddb entry
6377 *
6378 * This routine update isid if ddbs have same iqn, same isid and
6379 * different IP addr.
6380 * Return QLA_SUCCESS if isid is updated.
6381 **/
6382static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6383 struct list_head *list_nt,
6384 struct dev_db_entry *fw_ddb_entry)
6385{
6386 uint8_t base_value, i;
6387
6388 base_value = fw_ddb_entry->isid[1] & 0x1f;
6389 for (i = 0; i < 8; i++) {
6390 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6391 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6392 break;
6393 }
6394
6395 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6396 return QLA_ERROR;
6397
6398 return QLA_SUCCESS;
6399}
6400
6401/**
6402 * qla4xxx_should_update_isid - check if isid need to update
6403 * @ha: Pointer to host adapter structure.
6404 * @old_tddb: ddb tuple
6405 * @new_tddb: ddb tuple
6406 *
6407 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6408 * same isid
6409 **/
6410static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6411 struct ql4_tuple_ddb *old_tddb,
6412 struct ql4_tuple_ddb *new_tddb)
6413{
6414 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6415 /* Same ip */
6416 if (old_tddb->port == new_tddb->port)
6417 return QLA_ERROR;
6418 }
6419
6420 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6421 /* different iqn */
6422 return QLA_ERROR;
6423
6424 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6425 sizeof(old_tddb->isid)))
6426 /* different isid */
6427 return QLA_ERROR;
6428
6429 return QLA_SUCCESS;
6430}
6431
6432/**
6433 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6434 * @ha: Pointer to host adapter structure.
6435 * @list_nt: list of nt target.
6436 * @fw_ddb_entry: firmware ddb entry.
6437 *
6438 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6439 * duplicate ddb in list_nt.
6440 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6441 * Note: This function also update isid of DDB if required.
6442 **/
6443
Mike Christie13483732011-12-01 21:38:41 -06006444static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6445 struct list_head *list_nt,
6446 struct dev_db_entry *fw_ddb_entry)
6447{
6448 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6449 struct ql4_tuple_ddb *fw_tddb = NULL;
6450 struct ql4_tuple_ddb *tmp_tddb = NULL;
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006451 int rval, ret = QLA_ERROR;
Mike Christie13483732011-12-01 21:38:41 -06006452
6453 fw_tddb = vzalloc(sizeof(*fw_tddb));
6454 if (!fw_tddb) {
6455 DEBUG2(ql4_printk(KERN_WARNING, ha,
6456 "Memory Allocation failed.\n"));
6457 ret = QLA_SUCCESS;
6458 goto exit_check;
6459 }
6460
6461 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6462 if (!tmp_tddb) {
6463 DEBUG2(ql4_printk(KERN_WARNING, ha,
6464 "Memory Allocation failed.\n"));
6465 ret = QLA_SUCCESS;
6466 goto exit_check;
6467 }
6468
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006469 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006470
6471 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006472 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6473 nt_ddb_idx->flash_isid);
6474 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6475 /* found duplicate ddb */
6476 if (ret == QLA_SUCCESS)
6477 goto exit_check;
6478 }
6479
6480 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6481 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6482
6483 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6484 if (ret == QLA_SUCCESS) {
6485 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6486 if (rval == QLA_SUCCESS)
6487 ret = QLA_ERROR;
6488 else
6489 ret = QLA_SUCCESS;
6490
Mike Christie13483732011-12-01 21:38:41 -06006491 goto exit_check;
6492 }
6493 }
6494
6495exit_check:
6496 if (fw_tddb)
6497 vfree(fw_tddb);
6498 if (tmp_tddb)
6499 vfree(tmp_tddb);
6500 return ret;
6501}
6502
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006503static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
Mike Christie13483732011-12-01 21:38:41 -06006504{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006505 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
Mike Christie13483732011-12-01 21:38:41 -06006506
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006507 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6508 list_del_init(&ddb_idx->list);
6509 vfree(ddb_idx);
Mike Christie13483732011-12-01 21:38:41 -06006510 }
Mike Christie13483732011-12-01 21:38:41 -06006511}
6512
6513static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6514 struct dev_db_entry *fw_ddb_entry)
6515{
6516 struct iscsi_endpoint *ep;
6517 struct sockaddr_in *addr;
6518 struct sockaddr_in6 *addr6;
Manish Rangankar3dd48492012-11-23 06:58:40 -05006519 struct sockaddr *t_addr;
6520 struct sockaddr_storage *dst_addr;
Mike Christie13483732011-12-01 21:38:41 -06006521 char *ip;
6522
6523 /* TODO: need to destroy on unload iscsi_endpoint*/
6524 dst_addr = vmalloc(sizeof(*dst_addr));
6525 if (!dst_addr)
6526 return NULL;
6527
6528 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006529 t_addr = (struct sockaddr *)dst_addr;
6530 t_addr->sa_family = AF_INET6;
Mike Christie13483732011-12-01 21:38:41 -06006531 addr6 = (struct sockaddr_in6 *)dst_addr;
6532 ip = (char *)&addr6->sin6_addr;
6533 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6534 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6535
6536 } else {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006537 t_addr = (struct sockaddr *)dst_addr;
6538 t_addr->sa_family = AF_INET;
Mike Christie13483732011-12-01 21:38:41 -06006539 addr = (struct sockaddr_in *)dst_addr;
6540 ip = (char *)&addr->sin_addr;
6541 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6542 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6543 }
6544
Manish Rangankar3dd48492012-11-23 06:58:40 -05006545 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
Mike Christie13483732011-12-01 21:38:41 -06006546 vfree(dst_addr);
6547 return ep;
6548}
6549
6550static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6551{
6552 if (ql4xdisablesysfsboot)
6553 return QLA_SUCCESS;
6554 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6555 return QLA_ERROR;
6556 return QLA_SUCCESS;
6557}
6558
6559static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006560 struct ddb_entry *ddb_entry,
6561 uint16_t idx)
Mike Christie13483732011-12-01 21:38:41 -06006562{
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006563 uint16_t def_timeout;
6564
Mike Christie13483732011-12-01 21:38:41 -06006565 ddb_entry->ddb_type = FLASH_DDB;
6566 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6567 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6568 ddb_entry->ha = ha;
6569 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6570 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04006571 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
Mike Christie13483732011-12-01 21:38:41 -06006572
6573 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6574 atomic_set(&ddb_entry->relogin_timer, 0);
6575 atomic_set(&ddb_entry->relogin_retry_count, 0);
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006576 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06006577 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006578 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6579 def_timeout : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06006580 ddb_entry->default_time2wait =
6581 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006582
6583 if (ql4xdisablesysfsboot &&
6584 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6585 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
Mike Christie13483732011-12-01 21:38:41 -06006586}
6587
6588static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6589{
6590 uint32_t idx = 0;
6591 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6592 uint32_t sts[MBOX_REG_COUNT];
6593 uint32_t ip_state;
6594 unsigned long wtime;
6595 int ret;
6596
6597 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6598 do {
6599 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6600 if (ip_idx[idx] == -1)
6601 continue;
6602
6603 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6604
6605 if (ret == QLA_ERROR) {
6606 ip_idx[idx] = -1;
6607 continue;
6608 }
6609
6610 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6611
6612 DEBUG2(ql4_printk(KERN_INFO, ha,
6613 "Waiting for IP state for idx = %d, state = 0x%x\n",
6614 ip_idx[idx], ip_state));
6615 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6616 ip_state == IP_ADDRSTATE_INVALID ||
6617 ip_state == IP_ADDRSTATE_PREFERRED ||
6618 ip_state == IP_ADDRSTATE_DEPRICATED ||
6619 ip_state == IP_ADDRSTATE_DISABLING)
6620 ip_idx[idx] = -1;
Mike Christie13483732011-12-01 21:38:41 -06006621 }
6622
6623 /* Break if all IP states checked */
6624 if ((ip_idx[0] == -1) &&
6625 (ip_idx[1] == -1) &&
6626 (ip_idx[2] == -1) &&
6627 (ip_idx[3] == -1))
6628 break;
6629 schedule_timeout_uninterruptible(HZ);
6630 } while (time_after(wtime, jiffies));
6631}
6632
Manish Rangankarad8bd452013-09-17 07:30:02 -04006633static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6634 struct dev_db_entry *flash_ddb_entry)
6635{
6636 uint16_t options = 0;
6637 size_t ip_len = IP_ADDR_LEN;
6638
6639 options = le16_to_cpu(fw_ddb_entry->options);
6640 if (options & DDB_OPT_IPV6_DEVICE)
6641 ip_len = IPv6_ADDR_LEN;
6642
6643 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6644 return QLA_ERROR;
6645
6646 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6647 sizeof(fw_ddb_entry->isid)))
6648 return QLA_ERROR;
6649
6650 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6651 sizeof(fw_ddb_entry->port)))
6652 return QLA_ERROR;
6653
6654 return QLA_SUCCESS;
6655}
6656
6657static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6658 struct dev_db_entry *fw_ddb_entry,
6659 uint32_t fw_idx, uint32_t *flash_index)
6660{
6661 struct dev_db_entry *flash_ddb_entry;
6662 dma_addr_t flash_ddb_entry_dma;
6663 uint32_t idx = 0;
6664 int max_ddbs;
6665 int ret = QLA_ERROR, status;
6666
6667 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6668 MAX_DEV_DB_ENTRIES;
6669
6670 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6671 &flash_ddb_entry_dma);
6672 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6673 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6674 goto exit_find_st_idx;
6675 }
6676
6677 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6678 flash_ddb_entry_dma, fw_idx);
6679 if (status == QLA_SUCCESS) {
6680 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6681 if (status == QLA_SUCCESS) {
6682 *flash_index = fw_idx;
6683 ret = QLA_SUCCESS;
6684 goto exit_find_st_idx;
6685 }
6686 }
6687
6688 for (idx = 0; idx < max_ddbs; idx++) {
6689 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6690 flash_ddb_entry_dma, idx);
6691 if (status == QLA_ERROR)
6692 continue;
6693
6694 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6695 if (status == QLA_SUCCESS) {
6696 *flash_index = idx;
6697 ret = QLA_SUCCESS;
6698 goto exit_find_st_idx;
6699 }
6700 }
6701
6702 if (idx == max_ddbs)
6703 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6704 fw_idx);
6705
6706exit_find_st_idx:
6707 if (flash_ddb_entry)
6708 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6709 flash_ddb_entry_dma);
6710
6711 return ret;
6712}
6713
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006714static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6715 struct list_head *list_st)
Mike Christie13483732011-12-01 21:38:41 -06006716{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006717 struct qla_ddb_index *st_ddb_idx;
Mike Christie13483732011-12-01 21:38:41 -06006718 int max_ddbs;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006719 int fw_idx_size;
6720 struct dev_db_entry *fw_ddb_entry;
6721 dma_addr_t fw_ddb_dma;
Mike Christie13483732011-12-01 21:38:41 -06006722 int ret;
6723 uint32_t idx = 0, next_idx = 0;
6724 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006725 uint32_t flash_index = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006726 uint16_t conn_id = 0;
Mike Christie13483732011-12-01 21:38:41 -06006727
6728 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6729 &fw_ddb_dma);
6730 if (fw_ddb_entry == NULL) {
6731 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006732 goto exit_st_list;
Mike Christie13483732011-12-01 21:38:41 -06006733 }
6734
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006735 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6736 MAX_DEV_DB_ENTRIES;
Mike Christie13483732011-12-01 21:38:41 -06006737 fw_idx_size = sizeof(struct qla_ddb_index);
6738
6739 for (idx = 0; idx < max_ddbs; idx = next_idx) {
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006740 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6741 NULL, &next_idx, &state,
6742 &conn_err, NULL, &conn_id);
Mike Christie13483732011-12-01 21:38:41 -06006743 if (ret == QLA_ERROR)
6744 break;
6745
Lalit Chandivade981c9822012-02-13 18:30:41 +05306746 /* Ignore DDB if invalid state (unassigned) */
6747 if (state == DDB_DS_UNASSIGNED)
6748 goto continue_next_st;
6749
Mike Christie13483732011-12-01 21:38:41 -06006750 /* Check if ST, add to the list_st */
6751 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6752 goto continue_next_st;
6753
6754 st_ddb_idx = vzalloc(fw_idx_size);
6755 if (!st_ddb_idx)
6756 break;
6757
Manish Rangankarad8bd452013-09-17 07:30:02 -04006758 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6759 &flash_index);
6760 if (ret == QLA_ERROR) {
6761 ql4_printk(KERN_ERR, ha,
6762 "No flash entry for ST at idx [%d]\n", idx);
6763 st_ddb_idx->flash_ddb_idx = idx;
6764 } else {
6765 ql4_printk(KERN_INFO, ha,
6766 "ST at idx [%d] is stored at flash [%d]\n",
6767 idx, flash_index);
6768 st_ddb_idx->flash_ddb_idx = flash_index;
6769 }
6770
Mike Christie13483732011-12-01 21:38:41 -06006771 st_ddb_idx->fw_ddb_idx = idx;
6772
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006773 list_add_tail(&st_ddb_idx->list, list_st);
Mike Christie13483732011-12-01 21:38:41 -06006774continue_next_st:
6775 if (next_idx == 0)
6776 break;
6777 }
6778
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006779exit_st_list:
6780 if (fw_ddb_entry)
6781 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6782}
6783
6784/**
6785 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6786 * @ha: pointer to adapter structure
6787 * @list_ddb: List from which failed ddb to be removed
6788 *
6789 * Iterate over the list of DDBs and find and remove DDBs that are either in
6790 * no connection active state or failed state
6791 **/
6792static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6793 struct list_head *list_ddb)
6794{
6795 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6796 uint32_t next_idx = 0;
6797 uint32_t state = 0, conn_err = 0;
6798 int ret;
6799
6800 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6801 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6802 NULL, 0, NULL, &next_idx, &state,
6803 &conn_err, NULL, NULL);
6804 if (ret == QLA_ERROR)
6805 continue;
6806
6807 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6808 state == DDB_DS_SESSION_FAILED) {
6809 list_del_init(&ddb_idx->list);
6810 vfree(ddb_idx);
6811 }
6812 }
6813}
6814
Manish Rangankarad8bd452013-09-17 07:30:02 -04006815static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6816 struct ddb_entry *ddb_entry,
6817 struct dev_db_entry *fw_ddb_entry)
6818{
6819 struct iscsi_cls_session *cls_sess;
6820 struct iscsi_session *sess;
6821 uint32_t max_ddbs = 0;
6822 uint16_t ddb_link = -1;
6823
6824 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6825 MAX_DEV_DB_ENTRIES;
6826
6827 cls_sess = ddb_entry->sess;
6828 sess = cls_sess->dd_data;
6829
6830 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6831 if (ddb_link < max_ddbs)
6832 sess->discovery_parent_idx = ddb_link;
6833 else
6834 sess->discovery_parent_idx = DDB_NO_LINK;
6835}
6836
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006837static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6838 struct dev_db_entry *fw_ddb_entry,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006839 int is_reset, uint16_t idx)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006840{
6841 struct iscsi_cls_session *cls_sess;
6842 struct iscsi_session *sess;
6843 struct iscsi_cls_conn *cls_conn;
6844 struct iscsi_endpoint *ep;
6845 uint16_t cmds_max = 32;
6846 uint16_t conn_id = 0;
6847 uint32_t initial_cmdsn = 0;
6848 int ret = QLA_SUCCESS;
6849
6850 struct ddb_entry *ddb_entry = NULL;
6851
6852 /* Create session object, with INVALID_ENTRY,
6853 * the targer_id would get set when we issue the login
6854 */
6855 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6856 cmds_max, sizeof(struct ddb_entry),
6857 sizeof(struct ql4_task_data),
6858 initial_cmdsn, INVALID_ENTRY);
6859 if (!cls_sess) {
6860 ret = QLA_ERROR;
6861 goto exit_setup;
6862 }
6863
6864 /*
6865 * so calling module_put function to decrement the
6866 * reference count.
6867 **/
6868 module_put(qla4xxx_iscsi_transport.owner);
6869 sess = cls_sess->dd_data;
6870 ddb_entry = sess->dd_data;
6871 ddb_entry->sess = cls_sess;
6872
6873 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6874 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6875 sizeof(struct dev_db_entry));
6876
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006877 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006878
6879 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6880
6881 if (!cls_conn) {
6882 ret = QLA_ERROR;
6883 goto exit_setup;
6884 }
6885
6886 ddb_entry->conn = cls_conn;
6887
6888 /* Setup ep, for displaying attributes in sysfs */
6889 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6890 if (ep) {
6891 ep->conn = cls_conn;
6892 cls_conn->ep = ep;
6893 } else {
6894 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6895 ret = QLA_ERROR;
6896 goto exit_setup;
6897 }
6898
6899 /* Update sess/conn params */
6900 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
Manish Rangankarad8bd452013-09-17 07:30:02 -04006901 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006902
6903 if (is_reset == RESET_ADAPTER) {
6904 iscsi_block_session(cls_sess);
6905 /* Use the relogin path to discover new devices
6906 * by short-circuting the logic of setting
6907 * timer to relogin - instead set the flags
6908 * to initiate login right away.
6909 */
6910 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6911 set_bit(DF_RELOGIN, &ddb_entry->flags);
6912 }
6913
6914exit_setup:
6915 return ret;
6916}
6917
Manish Rangankarad8bd452013-09-17 07:30:02 -04006918static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6919 struct list_head *list_ddb,
6920 struct dev_db_entry *fw_ddb_entry)
6921{
6922 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6923 uint16_t ddb_link;
6924
6925 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6926
6927 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6928 if (ddb_idx->fw_ddb_idx == ddb_link) {
6929 DEBUG2(ql4_printk(KERN_INFO, ha,
6930 "Updating NT parent idx from [%d] to [%d]\n",
6931 ddb_link, ddb_idx->flash_ddb_idx));
6932 fw_ddb_entry->ddb_link =
6933 cpu_to_le16(ddb_idx->flash_ddb_idx);
6934 return;
6935 }
6936 }
6937}
6938
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006939static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006940 struct list_head *list_nt,
6941 struct list_head *list_st,
6942 int is_reset)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006943{
6944 struct dev_db_entry *fw_ddb_entry;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006945 struct ddb_entry *ddb_entry = NULL;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006946 dma_addr_t fw_ddb_dma;
6947 int max_ddbs;
6948 int fw_idx_size;
6949 int ret;
6950 uint32_t idx = 0, next_idx = 0;
6951 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006952 uint32_t ddb_idx = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006953 uint16_t conn_id = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006954 uint16_t ddb_link = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006955 struct qla_ddb_index *nt_ddb_idx;
6956
6957 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6958 &fw_ddb_dma);
6959 if (fw_ddb_entry == NULL) {
6960 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6961 goto exit_nt_list;
6962 }
6963 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6964 MAX_DEV_DB_ENTRIES;
6965 fw_idx_size = sizeof(struct qla_ddb_index);
6966
6967 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6968 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6969 NULL, &next_idx, &state,
6970 &conn_err, NULL, &conn_id);
6971 if (ret == QLA_ERROR)
6972 break;
6973
6974 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
6975 goto continue_next_nt;
6976
6977 /* Check if NT, then add to list it */
6978 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
6979 goto continue_next_nt;
6980
Manish Rangankarad8bd452013-09-17 07:30:02 -04006981 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6982 if (ddb_link < max_ddbs)
6983 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
6984
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006985 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
Manish Rangankarad8bd452013-09-17 07:30:02 -04006986 state == DDB_DS_SESSION_FAILED) &&
6987 (is_reset == INIT_ADAPTER))
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006988 goto continue_next_nt;
6989
6990 DEBUG2(ql4_printk(KERN_INFO, ha,
6991 "Adding DDB to session = 0x%x\n", idx));
Manish Rangankarad8bd452013-09-17 07:30:02 -04006992
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006993 if (is_reset == INIT_ADAPTER) {
6994 nt_ddb_idx = vmalloc(fw_idx_size);
6995 if (!nt_ddb_idx)
6996 break;
6997
6998 nt_ddb_idx->fw_ddb_idx = idx;
6999
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04007000 /* Copy original isid as it may get updated in function
7001 * qla4xxx_update_isid(). We need original isid in
7002 * function qla4xxx_compare_tuple_ddb to find duplicate
7003 * target */
7004 memcpy(&nt_ddb_idx->flash_isid[0],
7005 &fw_ddb_entry->isid[0],
7006 sizeof(nt_ddb_idx->flash_isid));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007007
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04007008 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7009 fw_ddb_entry);
7010 if (ret == QLA_SUCCESS) {
7011 /* free nt_ddb_idx and do not add to list_nt */
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007012 vfree(nt_ddb_idx);
7013 goto continue_next_nt;
7014 }
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04007015
7016 /* Copy updated isid */
7017 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7018 sizeof(struct dev_db_entry));
7019
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007020 list_add_tail(&nt_ddb_idx->list, list_nt);
7021 } else if (is_reset == RESET_ADAPTER) {
Manish Rangankarad8bd452013-09-17 07:30:02 -04007022 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7023 &ddb_idx);
7024 if (ret == QLA_SUCCESS) {
7025 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7026 ddb_idx);
7027 if (ddb_entry != NULL)
7028 qla4xxx_update_sess_disc_idx(ha,
7029 ddb_entry,
7030 fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007031 goto continue_next_nt;
Manish Rangankarad8bd452013-09-17 07:30:02 -04007032 }
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007033 }
7034
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05007035 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007036 if (ret == QLA_ERROR)
7037 goto exit_nt_list;
7038
7039continue_next_nt:
7040 if (next_idx == 0)
7041 break;
7042 }
7043
7044exit_nt_list:
7045 if (fw_ddb_entry)
7046 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7047}
7048
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007049static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007050 struct list_head *list_nt,
7051 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007052{
7053 struct dev_db_entry *fw_ddb_entry;
7054 dma_addr_t fw_ddb_dma;
7055 int max_ddbs;
7056 int fw_idx_size;
7057 int ret;
7058 uint32_t idx = 0, next_idx = 0;
7059 uint32_t state = 0, conn_err = 0;
7060 uint16_t conn_id = 0;
7061 struct qla_ddb_index *nt_ddb_idx;
7062
7063 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7064 &fw_ddb_dma);
7065 if (fw_ddb_entry == NULL) {
7066 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7067 goto exit_new_nt_list;
7068 }
7069 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7070 MAX_DEV_DB_ENTRIES;
7071 fw_idx_size = sizeof(struct qla_ddb_index);
7072
7073 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7074 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7075 NULL, &next_idx, &state,
7076 &conn_err, NULL, &conn_id);
7077 if (ret == QLA_ERROR)
7078 break;
7079
7080 /* Check if NT, then add it to list */
7081 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7082 goto continue_next_new_nt;
7083
7084 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7085 goto continue_next_new_nt;
7086
7087 DEBUG2(ql4_printk(KERN_INFO, ha,
7088 "Adding DDB to session = 0x%x\n", idx));
7089
7090 nt_ddb_idx = vmalloc(fw_idx_size);
7091 if (!nt_ddb_idx)
7092 break;
7093
7094 nt_ddb_idx->fw_ddb_idx = idx;
7095
Manish Rangankarad8bd452013-09-17 07:30:02 -04007096 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007097 if (ret == QLA_SUCCESS) {
7098 /* free nt_ddb_idx and do not add to list_nt */
7099 vfree(nt_ddb_idx);
7100 goto continue_next_new_nt;
7101 }
7102
Manish Rangankarad8bd452013-09-17 07:30:02 -04007103 if (target_id < max_ddbs)
7104 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7105
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007106 list_add_tail(&nt_ddb_idx->list, list_nt);
7107
7108 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7109 idx);
7110 if (ret == QLA_ERROR)
7111 goto exit_new_nt_list;
7112
7113continue_next_new_nt:
7114 if (next_idx == 0)
7115 break;
7116 }
7117
7118exit_new_nt_list:
7119 if (fw_ddb_entry)
7120 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7121}
7122
7123/**
7124 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7125 * @dev: dev associated with the sysfs entry
7126 * @data: pointer to flashnode session object
7127 *
7128 * Returns:
7129 * 1: if flashnode entry is non-persistent
7130 * 0: if flashnode entry is persistent
7131 **/
7132static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7133{
7134 struct iscsi_bus_flash_session *fnode_sess;
7135
7136 if (!iscsi_flashnode_bus_match(dev, NULL))
7137 return 0;
7138
7139 fnode_sess = iscsi_dev_to_flash_session(dev);
7140
7141 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7142}
7143
7144/**
7145 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7146 * @ha: pointer to host
7147 * @fw_ddb_entry: flash ddb data
7148 * @idx: target index
7149 * @user: if set then this call is made from userland else from kernel
7150 *
7151 * Returns:
7152 * On sucess: QLA_SUCCESS
7153 * On failure: QLA_ERROR
7154 *
7155 * This create separate sysfs entries for session and connection attributes of
7156 * the given fw ddb entry.
7157 * If this is invoked as a result of a userspace call then the entry is marked
7158 * as nonpersistent using flash_state field.
7159 **/
Vikas Chaudhary28e02f12013-04-17 05:15:27 -04007160static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7161 struct dev_db_entry *fw_ddb_entry,
7162 uint16_t *idx, int user)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007163{
7164 struct iscsi_bus_flash_session *fnode_sess = NULL;
7165 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7166 int rc = QLA_ERROR;
7167
7168 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7169 &qla4xxx_iscsi_transport, 0);
7170 if (!fnode_sess) {
7171 ql4_printk(KERN_ERR, ha,
7172 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7173 __func__, *idx, ha->host_no);
7174 goto exit_tgt_create;
7175 }
7176
7177 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7178 &qla4xxx_iscsi_transport, 0);
7179 if (!fnode_conn) {
7180 ql4_printk(KERN_ERR, ha,
7181 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7182 __func__, *idx, ha->host_no);
7183 goto free_sess;
7184 }
7185
7186 if (user) {
7187 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7188 } else {
7189 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7190
7191 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7192 fnode_sess->is_boot_target = 1;
7193 else
7194 fnode_sess->is_boot_target = 0;
7195 }
7196
7197 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7198 fw_ddb_entry);
7199
7200 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7201 __func__, fnode_sess->dev.kobj.name);
7202
7203 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7204 __func__, fnode_conn->dev.kobj.name);
7205
7206 return QLA_SUCCESS;
7207
7208free_sess:
7209 iscsi_destroy_flashnode_sess(fnode_sess);
7210
7211exit_tgt_create:
7212 return QLA_ERROR;
7213}
7214
7215/**
7216 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7217 * @shost: pointer to host
7218 * @buf: type of ddb entry (ipv4/ipv6)
7219 * @len: length of buf
7220 *
7221 * This creates new ddb entry in the flash by finding first free index and
7222 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7223 **/
7224static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7225 int len)
7226{
7227 struct scsi_qla_host *ha = to_qla_host(shost);
7228 struct dev_db_entry *fw_ddb_entry = NULL;
7229 dma_addr_t fw_ddb_entry_dma;
7230 struct device *dev;
7231 uint16_t idx = 0;
7232 uint16_t max_ddbs = 0;
7233 uint32_t options = 0;
7234 uint32_t rval = QLA_ERROR;
7235
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007236 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7237 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007238 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7239 __func__));
7240 goto exit_ddb_add;
7241 }
7242
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04007243 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007244 MAX_DEV_DB_ENTRIES;
7245
7246 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7247 &fw_ddb_entry_dma, GFP_KERNEL);
7248 if (!fw_ddb_entry) {
7249 DEBUG2(ql4_printk(KERN_ERR, ha,
7250 "%s: Unable to allocate dma buffer\n",
7251 __func__));
7252 goto exit_ddb_add;
7253 }
7254
7255 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7256 qla4xxx_sysfs_ddb_is_non_persistent);
7257 if (dev) {
7258 ql4_printk(KERN_ERR, ha,
7259 "%s: A non-persistent entry %s found\n",
7260 __func__, dev->kobj.name);
Mike Christie8526cb12013-05-06 12:06:56 -05007261 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007262 goto exit_ddb_add;
7263 }
7264
Adheer Chandravanshi99937572013-07-08 08:33:09 -04007265 /* Index 0 and 1 are reserved for boot target entries */
7266 for (idx = 2; idx < max_ddbs; idx++) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007267 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7268 fw_ddb_entry_dma, idx))
7269 break;
7270 }
7271
7272 if (idx == max_ddbs)
7273 goto exit_ddb_add;
7274
7275 if (!strncasecmp("ipv6", buf, 4))
7276 options |= IPV6_DEFAULT_DDB_ENTRY;
7277
7278 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7279 if (rval == QLA_ERROR)
7280 goto exit_ddb_add;
7281
7282 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7283
7284exit_ddb_add:
7285 if (fw_ddb_entry)
7286 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7287 fw_ddb_entry, fw_ddb_entry_dma);
7288 if (rval == QLA_SUCCESS)
7289 return idx;
7290 else
7291 return -EIO;
7292}
7293
7294/**
7295 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7296 * @fnode_sess: pointer to session attrs of flash ddb entry
7297 * @fnode_conn: pointer to connection attrs of flash ddb entry
7298 *
7299 * This writes the contents of target ddb buffer to Flash with a valid cookie
7300 * value in order to make the ddb entry persistent.
7301 **/
7302static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7303 struct iscsi_bus_flash_conn *fnode_conn)
7304{
7305 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7306 struct scsi_qla_host *ha = to_qla_host(shost);
7307 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7308 struct dev_db_entry *fw_ddb_entry = NULL;
7309 dma_addr_t fw_ddb_entry_dma;
7310 uint32_t options = 0;
7311 int rval = 0;
7312
7313 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7314 &fw_ddb_entry_dma, GFP_KERNEL);
7315 if (!fw_ddb_entry) {
7316 DEBUG2(ql4_printk(KERN_ERR, ha,
7317 "%s: Unable to allocate dma buffer\n",
7318 __func__));
7319 rval = -ENOMEM;
7320 goto exit_ddb_apply;
7321 }
7322
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007323 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007324 options |= IPV6_DEFAULT_DDB_ENTRY;
7325
7326 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7327 if (rval == QLA_ERROR)
7328 goto exit_ddb_apply;
7329
7330 dev_db_start_offset += (fnode_sess->target_id *
7331 sizeof(*fw_ddb_entry));
7332
7333 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7334 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7335
7336 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7337 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7338
7339 if (rval == QLA_SUCCESS) {
7340 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7341 ql4_printk(KERN_INFO, ha,
7342 "%s: flash node %u of host %lu written to flash\n",
7343 __func__, fnode_sess->target_id, ha->host_no);
7344 } else {
7345 rval = -EIO;
7346 ql4_printk(KERN_ERR, ha,
7347 "%s: Error while writing flash node %u of host %lu to flash\n",
7348 __func__, fnode_sess->target_id, ha->host_no);
7349 }
7350
7351exit_ddb_apply:
7352 if (fw_ddb_entry)
7353 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7354 fw_ddb_entry, fw_ddb_entry_dma);
7355 return rval;
7356}
7357
7358static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7359 struct dev_db_entry *fw_ddb_entry,
7360 uint16_t idx)
7361{
7362 struct dev_db_entry *ddb_entry = NULL;
7363 dma_addr_t ddb_entry_dma;
7364 unsigned long wtime;
7365 uint32_t mbx_sts = 0;
7366 uint32_t state = 0, conn_err = 0;
7367 uint16_t tmo = 0;
7368 int ret = 0;
7369
7370 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7371 &ddb_entry_dma, GFP_KERNEL);
7372 if (!ddb_entry) {
7373 DEBUG2(ql4_printk(KERN_ERR, ha,
7374 "%s: Unable to allocate dma buffer\n",
7375 __func__));
7376 return QLA_ERROR;
7377 }
7378
7379 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7380
7381 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7382 if (ret != QLA_SUCCESS) {
7383 DEBUG2(ql4_printk(KERN_ERR, ha,
7384 "%s: Unable to set ddb entry for index %d\n",
7385 __func__, idx));
7386 goto exit_ddb_conn_open;
7387 }
7388
7389 qla4xxx_conn_open(ha, idx);
7390
7391 /* To ensure that sendtargets is done, wait for at least 12 secs */
7392 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7393 (ha->def_timeout < LOGIN_TOV * 10) ?
7394 ha->def_timeout : LOGIN_TOV);
7395
7396 DEBUG2(ql4_printk(KERN_INFO, ha,
7397 "Default time to wait for login to ddb %d\n", tmo));
7398
7399 wtime = jiffies + (HZ * tmo);
7400 do {
7401 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7402 NULL, &state, &conn_err, NULL,
7403 NULL);
7404 if (ret == QLA_ERROR)
7405 continue;
7406
7407 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7408 state == DDB_DS_SESSION_FAILED)
7409 break;
7410
7411 schedule_timeout_uninterruptible(HZ / 10);
7412 } while (time_after(wtime, jiffies));
7413
7414exit_ddb_conn_open:
7415 if (ddb_entry)
7416 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7417 ddb_entry, ddb_entry_dma);
7418 return ret;
7419}
7420
7421static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007422 struct dev_db_entry *fw_ddb_entry,
7423 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007424{
7425 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7426 struct list_head list_nt;
7427 uint16_t ddb_index;
7428 int ret = 0;
7429
7430 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7431 ql4_printk(KERN_WARNING, ha,
7432 "%s: A discovery already in progress!\n", __func__);
7433 return QLA_ERROR;
7434 }
7435
7436 INIT_LIST_HEAD(&list_nt);
7437
7438 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7439
7440 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7441 if (ret == QLA_ERROR)
7442 goto exit_login_st_clr_bit;
7443
7444 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7445 if (ret == QLA_ERROR)
7446 goto exit_login_st;
7447
Manish Rangankarad8bd452013-09-17 07:30:02 -04007448 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007449
7450 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7451 list_del_init(&ddb_idx->list);
7452 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7453 vfree(ddb_idx);
7454 }
7455
7456exit_login_st:
7457 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7458 ql4_printk(KERN_ERR, ha,
7459 "Unable to clear DDB index = 0x%x\n", ddb_index);
7460 }
7461
7462 clear_bit(ddb_index, ha->ddb_idx_map);
7463
7464exit_login_st_clr_bit:
7465 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7466 return ret;
7467}
7468
7469static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7470 struct dev_db_entry *fw_ddb_entry,
7471 uint16_t idx)
7472{
7473 int ret = QLA_ERROR;
7474
Manish Rangankarad8bd452013-09-17 07:30:02 -04007475 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007476 if (ret != QLA_SUCCESS)
7477 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7478 idx);
7479 else
7480 ret = -EPERM;
7481
7482 return ret;
7483}
7484
7485/**
7486 * qla4xxx_sysfs_ddb_login - Login to the specified target
7487 * @fnode_sess: pointer to session attrs of flash ddb entry
7488 * @fnode_conn: pointer to connection attrs of flash ddb entry
7489 *
7490 * This logs in to the specified target
7491 **/
7492static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7493 struct iscsi_bus_flash_conn *fnode_conn)
7494{
7495 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7496 struct scsi_qla_host *ha = to_qla_host(shost);
7497 struct dev_db_entry *fw_ddb_entry = NULL;
7498 dma_addr_t fw_ddb_entry_dma;
7499 uint32_t options = 0;
7500 int ret = 0;
7501
7502 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7503 ql4_printk(KERN_ERR, ha,
7504 "%s: Target info is not persistent\n", __func__);
7505 ret = -EIO;
7506 goto exit_ddb_login;
7507 }
7508
7509 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7510 &fw_ddb_entry_dma, GFP_KERNEL);
7511 if (!fw_ddb_entry) {
7512 DEBUG2(ql4_printk(KERN_ERR, ha,
7513 "%s: Unable to allocate dma buffer\n",
7514 __func__));
7515 ret = -ENOMEM;
7516 goto exit_ddb_login;
7517 }
7518
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007519 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007520 options |= IPV6_DEFAULT_DDB_ENTRY;
7521
7522 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7523 if (ret == QLA_ERROR)
7524 goto exit_ddb_login;
7525
7526 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7527 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7528
7529 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
Manish Rangankarad8bd452013-09-17 07:30:02 -04007530 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7531 fnode_sess->target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007532 else
7533 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7534 fnode_sess->target_id);
7535
7536 if (ret > 0)
7537 ret = -EIO;
7538
7539exit_ddb_login:
7540 if (fw_ddb_entry)
7541 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7542 fw_ddb_entry, fw_ddb_entry_dma);
7543 return ret;
7544}
7545
7546/**
7547 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7548 * @cls_sess: pointer to session to be logged out
7549 *
7550 * This performs session log out from the specified target
7551 **/
7552static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7553{
7554 struct iscsi_session *sess;
7555 struct ddb_entry *ddb_entry = NULL;
7556 struct scsi_qla_host *ha;
7557 struct dev_db_entry *fw_ddb_entry = NULL;
7558 dma_addr_t fw_ddb_entry_dma;
7559 unsigned long flags;
7560 unsigned long wtime;
7561 uint32_t ddb_state;
7562 int options;
7563 int ret = 0;
7564
7565 sess = cls_sess->dd_data;
7566 ddb_entry = sess->dd_data;
7567 ha = ddb_entry->ha;
7568
7569 if (ddb_entry->ddb_type != FLASH_DDB) {
7570 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7571 __func__);
7572 ret = -ENXIO;
7573 goto exit_ddb_logout;
7574 }
7575
Adheer Chandravanshi37719c22013-04-05 07:06:07 -04007576 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7577 ql4_printk(KERN_ERR, ha,
7578 "%s: Logout from boot target entry is not permitted.\n",
7579 __func__);
7580 ret = -EPERM;
7581 goto exit_ddb_logout;
7582 }
7583
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007584 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7585 &fw_ddb_entry_dma, GFP_KERNEL);
7586 if (!fw_ddb_entry) {
7587 ql4_printk(KERN_ERR, ha,
7588 "%s: Unable to allocate dma buffer\n", __func__);
7589 ret = -ENOMEM;
7590 goto exit_ddb_logout;
7591 }
7592
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007593 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7594 goto ddb_logout_init;
7595
7596 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7597 fw_ddb_entry, fw_ddb_entry_dma,
7598 NULL, NULL, &ddb_state, NULL,
7599 NULL, NULL);
7600 if (ret == QLA_ERROR)
7601 goto ddb_logout_init;
7602
7603 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7604 goto ddb_logout_init;
7605
7606 /* wait until next relogin is triggered using DF_RELOGIN and
7607 * clear DF_RELOGIN to avoid invocation of further relogin
7608 */
7609 wtime = jiffies + (HZ * RELOGIN_TOV);
7610 do {
7611 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7612 goto ddb_logout_init;
7613
7614 schedule_timeout_uninterruptible(HZ);
7615 } while ((time_after(wtime, jiffies)));
7616
7617ddb_logout_init:
7618 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7619 atomic_set(&ddb_entry->relogin_timer, 0);
7620
7621 options = LOGOUT_OPTION_CLOSE_SESSION;
7622 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7623
7624 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007625 wtime = jiffies + (HZ * LOGOUT_TOV);
7626 do {
7627 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7628 fw_ddb_entry, fw_ddb_entry_dma,
7629 NULL, NULL, &ddb_state, NULL,
7630 NULL, NULL);
7631 if (ret == QLA_ERROR)
7632 goto ddb_logout_clr_sess;
7633
7634 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7635 (ddb_state == DDB_DS_SESSION_FAILED))
7636 goto ddb_logout_clr_sess;
7637
7638 schedule_timeout_uninterruptible(HZ);
7639 } while ((time_after(wtime, jiffies)));
7640
7641ddb_logout_clr_sess:
7642 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7643 /*
7644 * we have decremented the reference count of the driver
7645 * when we setup the session to have the driver unload
7646 * to be seamless without actually destroying the
7647 * session
7648 **/
7649 try_module_get(qla4xxx_iscsi_transport.owner);
7650 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7651
7652 spin_lock_irqsave(&ha->hardware_lock, flags);
7653 qla4xxx_free_ddb(ha, ddb_entry);
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007654 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007655 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7656
7657 iscsi_session_teardown(ddb_entry->sess);
7658
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007659 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007660 ret = QLA_SUCCESS;
7661
7662exit_ddb_logout:
7663 if (fw_ddb_entry)
7664 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7665 fw_ddb_entry, fw_ddb_entry_dma);
7666 return ret;
7667}
7668
7669/**
7670 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7671 * @fnode_sess: pointer to session attrs of flash ddb entry
7672 * @fnode_conn: pointer to connection attrs of flash ddb entry
7673 *
7674 * This performs log out from the specified target
7675 **/
7676static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7677 struct iscsi_bus_flash_conn *fnode_conn)
7678{
7679 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7680 struct scsi_qla_host *ha = to_qla_host(shost);
7681 struct ql4_tuple_ddb *flash_tddb = NULL;
7682 struct ql4_tuple_ddb *tmp_tddb = NULL;
7683 struct dev_db_entry *fw_ddb_entry = NULL;
7684 struct ddb_entry *ddb_entry = NULL;
7685 dma_addr_t fw_ddb_dma;
7686 uint32_t next_idx = 0;
7687 uint32_t state = 0, conn_err = 0;
7688 uint16_t conn_id = 0;
7689 int idx, index;
7690 int status, ret = 0;
7691
7692 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7693 &fw_ddb_dma);
7694 if (fw_ddb_entry == NULL) {
7695 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7696 ret = -ENOMEM;
7697 goto exit_ddb_logout;
7698 }
7699
7700 flash_tddb = vzalloc(sizeof(*flash_tddb));
7701 if (!flash_tddb) {
7702 ql4_printk(KERN_WARNING, ha,
7703 "%s:Memory Allocation failed.\n", __func__);
7704 ret = -ENOMEM;
7705 goto exit_ddb_logout;
7706 }
7707
7708 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7709 if (!tmp_tddb) {
7710 ql4_printk(KERN_WARNING, ha,
7711 "%s:Memory Allocation failed.\n", __func__);
7712 ret = -ENOMEM;
7713 goto exit_ddb_logout;
7714 }
7715
7716 if (!fnode_sess->targetname) {
7717 ql4_printk(KERN_ERR, ha,
7718 "%s:Cannot logout from SendTarget entry\n",
7719 __func__);
7720 ret = -EPERM;
7721 goto exit_ddb_logout;
7722 }
7723
7724 if (fnode_sess->is_boot_target) {
7725 ql4_printk(KERN_ERR, ha,
7726 "%s: Logout from boot target entry is not permitted.\n",
7727 __func__);
7728 ret = -EPERM;
7729 goto exit_ddb_logout;
7730 }
7731
7732 strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7733 ISCSI_NAME_SIZE);
7734
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007735 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007736 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7737 else
7738 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7739
7740 flash_tddb->tpgt = fnode_sess->tpgt;
7741 flash_tddb->port = fnode_conn->port;
7742
7743 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7744
7745 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7746 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7747 if (ddb_entry == NULL)
7748 continue;
7749
7750 if (ddb_entry->ddb_type != FLASH_DDB)
7751 continue;
7752
7753 index = ddb_entry->sess->target_id;
7754 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7755 fw_ddb_dma, NULL, &next_idx,
7756 &state, &conn_err, NULL,
7757 &conn_id);
7758 if (status == QLA_ERROR) {
7759 ret = -ENOMEM;
7760 break;
7761 }
7762
7763 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7764
7765 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7766 true);
7767 if (status == QLA_SUCCESS) {
7768 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7769 break;
7770 }
7771 }
7772
7773 if (idx == MAX_DDB_ENTRIES)
7774 ret = -ESRCH;
7775
7776exit_ddb_logout:
7777 if (flash_tddb)
7778 vfree(flash_tddb);
7779 if (tmp_tddb)
7780 vfree(tmp_tddb);
7781 if (fw_ddb_entry)
7782 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7783
7784 return ret;
7785}
7786
7787static int
7788qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7789 int param, char *buf)
7790{
7791 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7792 struct scsi_qla_host *ha = to_qla_host(shost);
7793 struct iscsi_bus_flash_conn *fnode_conn;
7794 struct ql4_chap_table chap_tbl;
7795 struct device *dev;
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007796 int parent_type;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007797 int rc = 0;
7798
Mike Christie8526cb12013-05-06 12:06:56 -05007799 dev = iscsi_find_flashnode_conn(fnode_sess);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007800 if (!dev)
7801 return -EIO;
7802
7803 fnode_conn = iscsi_dev_to_flash_conn(dev);
7804
7805 switch (param) {
7806 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7807 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7808 break;
7809 case ISCSI_FLASHNODE_PORTAL_TYPE:
7810 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7811 break;
7812 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7813 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7814 break;
7815 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7816 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7817 break;
7818 case ISCSI_FLASHNODE_ENTRY_EN:
7819 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7820 break;
7821 case ISCSI_FLASHNODE_HDR_DGST_EN:
7822 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7823 break;
7824 case ISCSI_FLASHNODE_DATA_DGST_EN:
7825 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7826 break;
7827 case ISCSI_FLASHNODE_IMM_DATA_EN:
7828 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7829 break;
7830 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7831 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7832 break;
7833 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7834 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7835 break;
7836 case ISCSI_FLASHNODE_PDU_INORDER:
7837 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7838 break;
7839 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7840 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7841 break;
7842 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7843 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7844 break;
7845 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7846 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7847 break;
7848 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7849 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7850 break;
7851 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7852 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7853 break;
7854 case ISCSI_FLASHNODE_ERL:
7855 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7856 break;
7857 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7858 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7859 break;
7860 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7861 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7862 break;
7863 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7864 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7865 break;
7866 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7867 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7868 break;
7869 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7870 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7871 break;
7872 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7873 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7874 break;
7875 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7876 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7877 break;
7878 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7879 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7880 break;
7881 case ISCSI_FLASHNODE_FIRST_BURST:
7882 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7883 break;
7884 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7885 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7886 break;
7887 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7888 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7889 break;
7890 case ISCSI_FLASHNODE_MAX_R2T:
7891 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7892 break;
7893 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7894 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7895 break;
7896 case ISCSI_FLASHNODE_ISID:
7897 rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
7898 fnode_sess->isid[0], fnode_sess->isid[1],
7899 fnode_sess->isid[2], fnode_sess->isid[3],
7900 fnode_sess->isid[4], fnode_sess->isid[5]);
7901 break;
7902 case ISCSI_FLASHNODE_TSID:
7903 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7904 break;
7905 case ISCSI_FLASHNODE_PORT:
7906 rc = sprintf(buf, "%d\n", fnode_conn->port);
7907 break;
7908 case ISCSI_FLASHNODE_MAX_BURST:
7909 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7910 break;
7911 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7912 rc = sprintf(buf, "%u\n",
7913 fnode_sess->default_taskmgmt_timeout);
7914 break;
7915 case ISCSI_FLASHNODE_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007916 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007917 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7918 else
7919 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7920 break;
7921 case ISCSI_FLASHNODE_ALIAS:
7922 if (fnode_sess->targetalias)
7923 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7924 else
7925 rc = sprintf(buf, "\n");
7926 break;
7927 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007928 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007929 rc = sprintf(buf, "%pI6\n",
7930 fnode_conn->redirect_ipaddr);
7931 else
7932 rc = sprintf(buf, "%pI4\n",
7933 fnode_conn->redirect_ipaddr);
7934 break;
7935 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7936 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7937 break;
7938 case ISCSI_FLASHNODE_LOCAL_PORT:
7939 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7940 break;
7941 case ISCSI_FLASHNODE_IPV4_TOS:
7942 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7943 break;
7944 case ISCSI_FLASHNODE_IPV6_TC:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007945 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007946 rc = sprintf(buf, "%u\n",
7947 fnode_conn->ipv6_traffic_class);
7948 else
7949 rc = sprintf(buf, "\n");
7950 break;
7951 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7952 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7953 break;
7954 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007955 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007956 rc = sprintf(buf, "%pI6\n",
7957 fnode_conn->link_local_ipv6_addr);
7958 else
7959 rc = sprintf(buf, "\n");
7960 break;
7961 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007962 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007963 break;
7964 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
7965 if (fnode_sess->discovery_parent_type == DDB_ISNS)
7966 parent_type = ISCSI_DISC_PARENT_ISNS;
7967 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
7968 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04007969 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007970 parent_type = ISCSI_DISC_PARENT_SENDTGT;
7971 else
7972 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
7973
7974 rc = sprintf(buf, "%s\n",
7975 iscsi_get_discovery_parent_name(parent_type));
7976 break;
7977 case ISCSI_FLASHNODE_NAME:
7978 if (fnode_sess->targetname)
7979 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
7980 else
7981 rc = sprintf(buf, "\n");
7982 break;
7983 case ISCSI_FLASHNODE_TPGT:
7984 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
7985 break;
7986 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
7987 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
7988 break;
7989 case ISCSI_FLASHNODE_TCP_RECV_WSF:
7990 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
7991 break;
7992 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
7993 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
7994 break;
7995 case ISCSI_FLASHNODE_USERNAME:
7996 if (fnode_sess->chap_auth_en) {
7997 qla4xxx_get_uni_chap_at_index(ha,
7998 chap_tbl.name,
7999 chap_tbl.secret,
8000 fnode_sess->chap_out_idx);
8001 rc = sprintf(buf, "%s\n", chap_tbl.name);
8002 } else {
8003 rc = sprintf(buf, "\n");
8004 }
8005 break;
8006 case ISCSI_FLASHNODE_PASSWORD:
8007 if (fnode_sess->chap_auth_en) {
8008 qla4xxx_get_uni_chap_at_index(ha,
8009 chap_tbl.name,
8010 chap_tbl.secret,
8011 fnode_sess->chap_out_idx);
8012 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8013 } else {
8014 rc = sprintf(buf, "\n");
8015 }
8016 break;
8017 case ISCSI_FLASHNODE_STATSN:
8018 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8019 break;
8020 case ISCSI_FLASHNODE_EXP_STATSN:
8021 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8022 break;
8023 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8024 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8025 break;
8026 default:
8027 rc = -ENOSYS;
8028 break;
8029 }
Mike Christie8526cb12013-05-06 12:06:56 -05008030
8031 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008032 return rc;
8033}
8034
8035/**
8036 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8037 * @fnode_sess: pointer to session attrs of flash ddb entry
8038 * @fnode_conn: pointer to connection attrs of flash ddb entry
8039 * @data: Parameters and their values to update
8040 * @len: len of data
8041 *
8042 * This sets the parameter of flash ddb entry and writes them to flash
8043 **/
8044static int
8045qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8046 struct iscsi_bus_flash_conn *fnode_conn,
8047 void *data, int len)
8048{
8049 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8050 struct scsi_qla_host *ha = to_qla_host(shost);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008051 struct iscsi_flashnode_param_info *fnode_param;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008052 struct ql4_chap_table chap_tbl;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008053 struct nlattr *attr;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008054 uint16_t chap_out_idx = INVALID_ENTRY;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008055 int rc = QLA_ERROR;
8056 uint32_t rem = len;
8057
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008058 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008059 nla_for_each_attr(attr, data, len, rem) {
8060 fnode_param = nla_data(attr);
8061
8062 switch (fnode_param->param) {
8063 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8064 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8065 break;
8066 case ISCSI_FLASHNODE_PORTAL_TYPE:
8067 memcpy(fnode_sess->portal_type, fnode_param->value,
8068 strlen(fnode_sess->portal_type));
8069 break;
8070 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8071 fnode_sess->auto_snd_tgt_disable =
8072 fnode_param->value[0];
8073 break;
8074 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8075 fnode_sess->discovery_sess = fnode_param->value[0];
8076 break;
8077 case ISCSI_FLASHNODE_ENTRY_EN:
8078 fnode_sess->entry_state = fnode_param->value[0];
8079 break;
8080 case ISCSI_FLASHNODE_HDR_DGST_EN:
8081 fnode_conn->hdrdgst_en = fnode_param->value[0];
8082 break;
8083 case ISCSI_FLASHNODE_DATA_DGST_EN:
8084 fnode_conn->datadgst_en = fnode_param->value[0];
8085 break;
8086 case ISCSI_FLASHNODE_IMM_DATA_EN:
8087 fnode_sess->imm_data_en = fnode_param->value[0];
8088 break;
8089 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8090 fnode_sess->initial_r2t_en = fnode_param->value[0];
8091 break;
8092 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8093 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8094 break;
8095 case ISCSI_FLASHNODE_PDU_INORDER:
8096 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8097 break;
8098 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8099 fnode_sess->chap_auth_en = fnode_param->value[0];
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008100 /* Invalidate chap index if chap auth is disabled */
8101 if (!fnode_sess->chap_auth_en)
8102 fnode_sess->chap_out_idx = INVALID_ENTRY;
8103
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008104 break;
8105 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8106 fnode_conn->snack_req_en = fnode_param->value[0];
8107 break;
8108 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8109 fnode_sess->discovery_logout_en = fnode_param->value[0];
8110 break;
8111 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8112 fnode_sess->bidi_chap_en = fnode_param->value[0];
8113 break;
8114 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8115 fnode_sess->discovery_auth_optional =
8116 fnode_param->value[0];
8117 break;
8118 case ISCSI_FLASHNODE_ERL:
8119 fnode_sess->erl = fnode_param->value[0];
8120 break;
8121 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8122 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8123 break;
8124 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8125 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8126 break;
8127 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8128 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8129 break;
8130 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8131 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8132 break;
8133 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8134 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8135 break;
8136 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8137 fnode_conn->fragment_disable = fnode_param->value[0];
8138 break;
8139 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8140 fnode_conn->max_recv_dlength =
8141 *(unsigned *)fnode_param->value;
8142 break;
8143 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8144 fnode_conn->max_xmit_dlength =
8145 *(unsigned *)fnode_param->value;
8146 break;
8147 case ISCSI_FLASHNODE_FIRST_BURST:
8148 fnode_sess->first_burst =
8149 *(unsigned *)fnode_param->value;
8150 break;
8151 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8152 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8153 break;
8154 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8155 fnode_sess->time2retain =
8156 *(uint16_t *)fnode_param->value;
8157 break;
8158 case ISCSI_FLASHNODE_MAX_R2T:
8159 fnode_sess->max_r2t =
8160 *(uint16_t *)fnode_param->value;
8161 break;
8162 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8163 fnode_conn->keepalive_timeout =
8164 *(uint16_t *)fnode_param->value;
8165 break;
8166 case ISCSI_FLASHNODE_ISID:
8167 memcpy(fnode_sess->isid, fnode_param->value,
8168 sizeof(fnode_sess->isid));
8169 break;
8170 case ISCSI_FLASHNODE_TSID:
8171 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8172 break;
8173 case ISCSI_FLASHNODE_PORT:
8174 fnode_conn->port = *(uint16_t *)fnode_param->value;
8175 break;
8176 case ISCSI_FLASHNODE_MAX_BURST:
8177 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8178 break;
8179 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8180 fnode_sess->default_taskmgmt_timeout =
8181 *(uint16_t *)fnode_param->value;
8182 break;
8183 case ISCSI_FLASHNODE_IPADDR:
8184 memcpy(fnode_conn->ipaddress, fnode_param->value,
8185 IPv6_ADDR_LEN);
8186 break;
8187 case ISCSI_FLASHNODE_ALIAS:
8188 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8189 (char *)fnode_param->value);
8190 break;
8191 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8192 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8193 IPv6_ADDR_LEN);
8194 break;
8195 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8196 fnode_conn->max_segment_size =
8197 *(unsigned *)fnode_param->value;
8198 break;
8199 case ISCSI_FLASHNODE_LOCAL_PORT:
8200 fnode_conn->local_port =
8201 *(uint16_t *)fnode_param->value;
8202 break;
8203 case ISCSI_FLASHNODE_IPV4_TOS:
8204 fnode_conn->ipv4_tos = fnode_param->value[0];
8205 break;
8206 case ISCSI_FLASHNODE_IPV6_TC:
8207 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8208 break;
8209 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8210 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8211 break;
8212 case ISCSI_FLASHNODE_NAME:
8213 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8214 (char *)fnode_param->value);
8215 break;
8216 case ISCSI_FLASHNODE_TPGT:
8217 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8218 break;
8219 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8220 memcpy(fnode_conn->link_local_ipv6_addr,
8221 fnode_param->value, IPv6_ADDR_LEN);
8222 break;
Adheer Chandravanshi65560162013-07-08 08:33:06 -04008223 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8224 fnode_sess->discovery_parent_idx =
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008225 *(uint16_t *)fnode_param->value;
8226 break;
8227 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8228 fnode_conn->tcp_xmit_wsf =
8229 *(uint8_t *)fnode_param->value;
8230 break;
8231 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8232 fnode_conn->tcp_recv_wsf =
8233 *(uint8_t *)fnode_param->value;
8234 break;
8235 case ISCSI_FLASHNODE_STATSN:
8236 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8237 break;
8238 case ISCSI_FLASHNODE_EXP_STATSN:
8239 fnode_conn->exp_statsn =
8240 *(uint32_t *)fnode_param->value;
8241 break;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008242 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8243 chap_out_idx = *(uint16_t *)fnode_param->value;
8244 if (!qla4xxx_get_uni_chap_at_index(ha,
8245 chap_tbl.name,
8246 chap_tbl.secret,
8247 chap_out_idx)) {
8248 fnode_sess->chap_out_idx = chap_out_idx;
8249 /* Enable chap auth if chap index is valid */
8250 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8251 }
8252 break;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008253 default:
8254 ql4_printk(KERN_ERR, ha,
8255 "%s: No such sysfs attribute\n", __func__);
8256 rc = -ENOSYS;
8257 goto exit_set_param;
8258 }
8259 }
8260
8261 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8262
8263exit_set_param:
8264 return rc;
8265}
8266
8267/**
8268 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8269 * @fnode_sess: pointer to session attrs of flash ddb entry
8270 *
8271 * This invalidates the flash ddb entry at the given index
8272 **/
8273static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8274{
8275 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8276 struct scsi_qla_host *ha = to_qla_host(shost);
8277 uint32_t dev_db_start_offset;
8278 uint32_t dev_db_end_offset;
8279 struct dev_db_entry *fw_ddb_entry = NULL;
8280 dma_addr_t fw_ddb_entry_dma;
8281 uint16_t *ddb_cookie = NULL;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04008282 size_t ddb_size = 0;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008283 void *pddb = NULL;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008284 int target_id;
8285 int rc = 0;
8286
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008287 if (fnode_sess->is_boot_target) {
8288 rc = -EPERM;
8289 DEBUG2(ql4_printk(KERN_ERR, ha,
8290 "%s: Deletion of boot target entry is not permitted.\n",
8291 __func__));
8292 goto exit_ddb_del;
8293 }
8294
8295 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8296 goto sysfs_ddb_del;
8297
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008298 if (is_qla40XX(ha)) {
8299 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008300 dev_db_end_offset = FLASH_OFFSET_DB_END;
8301 dev_db_start_offset += (fnode_sess->target_id *
8302 sizeof(*fw_ddb_entry));
8303 ddb_size = sizeof(*fw_ddb_entry);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008304 } else {
8305 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8306 (ha->hw.flt_region_ddb << 2);
8307 /* flt_ddb_size is DDB table size for both ports
8308 * so divide it by 2 to calculate the offset for second port
8309 */
8310 if (ha->port_num == 1)
8311 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008312
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008313 dev_db_end_offset = dev_db_start_offset +
8314 (ha->hw.flt_ddb_size / 2);
8315
8316 dev_db_start_offset += (fnode_sess->target_id *
8317 sizeof(*fw_ddb_entry));
Adheer Chandravanshi1bcb5612013-04-17 05:15:28 -04008318 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008319
8320 ddb_size = sizeof(*ddb_cookie);
8321 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008322
8323 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8324 __func__, dev_db_start_offset, dev_db_end_offset));
8325
8326 if (dev_db_start_offset > dev_db_end_offset) {
8327 rc = -EIO;
8328 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8329 __func__, fnode_sess->target_id));
8330 goto exit_ddb_del;
8331 }
8332
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008333 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8334 &fw_ddb_entry_dma, GFP_KERNEL);
8335 if (!pddb) {
8336 rc = -ENOMEM;
8337 DEBUG2(ql4_printk(KERN_ERR, ha,
8338 "%s: Unable to allocate dma buffer\n",
8339 __func__));
8340 goto exit_ddb_del;
8341 }
8342
8343 if (is_qla40XX(ha)) {
8344 fw_ddb_entry = pddb;
8345 memset(fw_ddb_entry, 0, ddb_size);
8346 ddb_cookie = &fw_ddb_entry->cookie;
8347 } else {
8348 ddb_cookie = pddb;
8349 }
8350
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008351 /* invalidate the cookie */
8352 *ddb_cookie = 0xFFEE;
8353 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008354 ddb_size, FLASH_OPT_RMW_COMMIT);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008355
8356sysfs_ddb_del:
8357 target_id = fnode_sess->target_id;
8358 iscsi_destroy_flashnode_sess(fnode_sess);
8359 ql4_printk(KERN_INFO, ha,
8360 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8361 __func__, target_id, ha->host_no);
8362exit_ddb_del:
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008363 if (pddb)
8364 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8365 fw_ddb_entry_dma);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008366 return rc;
8367}
8368
8369/**
8370 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8371 * @ha: pointer to adapter structure
8372 *
8373 * Export the firmware DDB for all send targets and normal targets to sysfs.
8374 **/
8375static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8376{
8377 struct dev_db_entry *fw_ddb_entry = NULL;
8378 dma_addr_t fw_ddb_entry_dma;
8379 uint16_t max_ddbs;
8380 uint16_t idx = 0;
8381 int ret = QLA_SUCCESS;
8382
8383 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8384 sizeof(*fw_ddb_entry),
8385 &fw_ddb_entry_dma, GFP_KERNEL);
8386 if (!fw_ddb_entry) {
8387 DEBUG2(ql4_printk(KERN_ERR, ha,
8388 "%s: Unable to allocate dma buffer\n",
8389 __func__));
8390 return -ENOMEM;
8391 }
8392
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04008393 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008394 MAX_DEV_DB_ENTRIES;
8395
8396 for (idx = 0; idx < max_ddbs; idx++) {
8397 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8398 idx))
8399 continue;
8400
8401 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8402 if (ret) {
8403 ret = -EIO;
8404 break;
8405 }
8406 }
8407
8408 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8409 fw_ddb_entry_dma);
8410
8411 return ret;
8412}
8413
8414static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8415{
8416 iscsi_destroy_all_flashnode(ha->host);
8417}
8418
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008419/**
8420 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8421 * @ha: pointer to adapter structure
8422 * @is_reset: Is this init path or reset path
8423 *
8424 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8425 * using connection open, then create the list of normal targets (nt)
8426 * from firmware DDBs. Based on the list of nt setup session and connection
8427 * objects.
8428 **/
8429void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8430{
8431 uint16_t tmo = 0;
8432 struct list_head list_st, list_nt;
8433 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8434 unsigned long wtime;
8435
8436 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8437 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8438 ha->is_reset = is_reset;
8439 return;
8440 }
8441
8442 INIT_LIST_HEAD(&list_st);
8443 INIT_LIST_HEAD(&list_nt);
8444
8445 qla4xxx_build_st_list(ha, &list_st);
8446
Mike Christie13483732011-12-01 21:38:41 -06008447 /* Before issuing conn open mbox, ensure all IPs states are configured
8448 * Note, conn open fails if IPs are not configured
8449 */
8450 qla4xxx_wait_for_ip_configuration(ha);
8451
8452 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8453 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8454 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8455 }
8456
8457 /* Wait to ensure all sendtargets are done for min 12 sec wait */
Nilesh Javalic28eaac2011-12-18 21:40:44 -08008458 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8459 (ha->def_timeout < LOGIN_TOV * 10) ?
8460 ha->def_timeout : LOGIN_TOV);
8461
Mike Christie13483732011-12-01 21:38:41 -06008462 DEBUG2(ql4_printk(KERN_INFO, ha,
8463 "Default time to wait for build ddb %d\n", tmo));
8464
8465 wtime = jiffies + (HZ * tmo);
8466 do {
Nilesh Javalif1f2e602011-12-16 01:58:57 -08008467 if (list_empty(&list_st))
8468 break;
8469
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008470 qla4xxx_remove_failed_ddb(ha, &list_st);
Mike Christie13483732011-12-01 21:38:41 -06008471 schedule_timeout_uninterruptible(HZ / 10);
8472 } while (time_after(wtime, jiffies));
8473
Manish Rangankarad8bd452013-09-17 07:30:02 -04008474
8475 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8476
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008477 qla4xxx_free_ddb_list(&list_st);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008478 qla4xxx_free_ddb_list(&list_nt);
Mike Christie13483732011-12-01 21:38:41 -06008479
8480 qla4xxx_free_ddb_index(ha);
8481}
8482
David Somayajuluafaf5a22006-09-19 10:28:00 -07008483/**
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008484 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8485 * response.
8486 * @ha: pointer to adapter structure
8487 *
8488 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8489 * set in DDB and we will wait for login response of boot targets during
8490 * probe.
8491 **/
8492static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8493{
8494 struct ddb_entry *ddb_entry;
8495 struct dev_db_entry *fw_ddb_entry = NULL;
8496 dma_addr_t fw_ddb_entry_dma;
8497 unsigned long wtime;
8498 uint32_t ddb_state;
8499 int max_ddbs, idx, ret;
8500
8501 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8502 MAX_DEV_DB_ENTRIES;
8503
8504 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8505 &fw_ddb_entry_dma, GFP_KERNEL);
8506 if (!fw_ddb_entry) {
8507 ql4_printk(KERN_ERR, ha,
8508 "%s: Unable to allocate dma buffer\n", __func__);
8509 goto exit_login_resp;
8510 }
8511
8512 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8513
8514 for (idx = 0; idx < max_ddbs; idx++) {
8515 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8516 if (ddb_entry == NULL)
8517 continue;
8518
8519 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8520 DEBUG2(ql4_printk(KERN_INFO, ha,
8521 "%s: DDB index [%d]\n", __func__,
8522 ddb_entry->fw_ddb_index));
8523 do {
8524 ret = qla4xxx_get_fwddb_entry(ha,
8525 ddb_entry->fw_ddb_index,
8526 fw_ddb_entry, fw_ddb_entry_dma,
8527 NULL, NULL, &ddb_state, NULL,
8528 NULL, NULL);
8529 if (ret == QLA_ERROR)
8530 goto exit_login_resp;
8531
8532 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8533 (ddb_state == DDB_DS_SESSION_FAILED))
8534 break;
8535
8536 schedule_timeout_uninterruptible(HZ);
8537
8538 } while ((time_after(wtime, jiffies)));
8539
8540 if (!time_after(wtime, jiffies)) {
8541 DEBUG2(ql4_printk(KERN_INFO, ha,
8542 "%s: Login response wait timer expired\n",
8543 __func__));
8544 goto exit_login_resp;
8545 }
8546 }
8547 }
8548
8549exit_login_resp:
8550 if (fw_ddb_entry)
8551 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8552 fw_ddb_entry, fw_ddb_entry_dma);
8553}
8554
8555/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07008556 * qla4xxx_probe_adapter - callback function to probe HBA
8557 * @pdev: pointer to pci_dev structure
8558 * @pci_device_id: pointer to pci_device entry
8559 *
8560 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8561 * It returns zero if successful. It also initializes all data necessary for
8562 * the driver.
8563 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008564static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8565 const struct pci_device_id *ent)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008566{
8567 int ret = -ENODEV, status;
8568 struct Scsi_Host *host;
8569 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008570 uint8_t init_retry_count = 0;
8571 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308572 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008573 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008574
8575 if (pci_enable_device(pdev))
8576 return -1;
8577
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008578 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008579 if (host == NULL) {
8580 printk(KERN_WARNING
8581 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8582 goto probe_disable_device;
8583 }
8584
8585 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008586 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008587 memset(ha, 0, sizeof(*ha));
8588
8589 /* Save the information from PCI BIOS. */
8590 ha->pdev = pdev;
8591 ha->host = host;
8592 ha->host_no = host->host_no;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008593 ha->func_num = PCI_FUNC(ha->pdev->devfn);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008594
Lalit Chandivade2232be02010-07-30 14:38:47 +05308595 pci_enable_pcie_error_reporting(pdev);
8596
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308597 /* Setup Runtime configurable options */
8598 if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04008599 ha->isp_ops = &qla4_82xx_isp_ops;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008600 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308601 ha->qdr_sn_window = -1;
8602 ha->ddr_mn_window = -1;
8603 ha->curr_window = 255;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308604 nx_legacy_intr = &legacy_intr[ha->func_num];
8605 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8606 ha->nx_legacy_intr.tgt_status_reg =
8607 nx_legacy_intr->tgt_status_reg;
8608 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8609 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008610 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008611 ha->isp_ops = &qla4_83xx_isp_ops;
8612 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308613 } else {
8614 ha->isp_ops = &qla4xxx_isp_ops;
8615 }
8616
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008617 if (is_qla80XX(ha)) {
8618 rwlock_init(&ha->hw_lock);
8619 ha->pf_bit = ha->func_num << 16;
8620 /* Set EEH reset type to fundamental if required by hba */
Lalit Chandivade2232be02010-07-30 14:38:47 +05308621 pdev->needs_freset = 1;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008622 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05308623
David Somayajuluafaf5a22006-09-19 10:28:00 -07008624 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308625 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008626 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308627 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008628
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308629 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07008630 pdev->device, pdev->irq, ha->reg);
8631
8632 qla4xxx_config_dma_addressing(ha);
8633
8634 /* Initialize lists and spinlocks. */
David Somayajuluafaf5a22006-09-19 10:28:00 -07008635 INIT_LIST_HEAD(&ha->free_srb_q);
8636
8637 mutex_init(&ha->mbox_sem);
Lalit Chandivade45494152011-10-07 16:55:42 -07008638 mutex_init(&ha->chap_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308639 init_completion(&ha->mbx_intr_comp);
Vikas Chaudhary95d31262011-08-12 02:51:29 -07008640 init_completion(&ha->disable_acb_comp);
Vikas Chaudharydf86f772013-11-22 05:28:17 -05008641 init_completion(&ha->idc_comp);
8642 init_completion(&ha->link_up_comp);
8643 init_completion(&ha->disable_acb_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008644
8645 spin_lock_init(&ha->hardware_lock);
Vikas Chaudhary8e9157c2012-08-22 07:45:24 -04008646 spin_lock_init(&ha->work_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008647
Vikas Chaudharyff884432011-08-29 23:43:02 +05308648 /* Initialize work list */
8649 INIT_LIST_HEAD(&ha->work_list);
8650
David Somayajuluafaf5a22006-09-19 10:28:00 -07008651 /* Allocate dma buffers */
8652 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308653 ql4_printk(KERN_WARNING, ha,
8654 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008655
8656 ret = -ENOMEM;
8657 goto probe_failed;
8658 }
8659
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008660 host->cmd_per_lun = 3;
8661 host->max_channel = 0;
8662 host->max_lun = MAX_LUNS - 1;
8663 host->max_id = MAX_TARGETS;
8664 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8665 host->can_queue = MAX_SRBS ;
8666 host->transportt = qla4xxx_scsi_transport;
8667
8668 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
8669 if (ret) {
8670 ql4_printk(KERN_WARNING, ha,
8671 "%s: scsi_init_shared_tag_map failed\n", __func__);
8672 goto probe_failed;
8673 }
8674
8675 pci_set_drvdata(pdev, ha);
8676
8677 ret = scsi_add_host(host, &pdev->dev);
8678 if (ret)
8679 goto probe_failed;
8680
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008681 if (is_qla80XX(ha))
8682 qla4_8xxx_get_flash_info(ha);
8683
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008684 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008685 qla4_83xx_read_reset_template(ha);
8686 /*
8687 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8688 * If DONRESET_BIT0 is set, drivers should not set dev_state
8689 * to NEED_RESET. But if NEED_RESET is set, drivers should
8690 * should honor the reset.
8691 */
8692 if (ql4xdontresethba == 1)
8693 qla4_83xx_set_idc_dontreset(ha);
8694 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308695
David Somayajuluafaf5a22006-09-19 10:28:00 -07008696 /*
8697 * Initialize the Host adapter request/response queues and
8698 * firmware
8699 * NOTE: interrupts enabled upon successful completion
8700 */
Mike Christie13483732011-12-01 21:38:41 -06008701 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Poornima Vonti7977f822012-09-20 07:35:07 -04008702
8703 /* Dont retry adapter initialization if IRQ allocation failed */
Nilesh Javali37418cc2013-12-16 06:49:31 -05008704 if (is_qla80XX(ha) && (status == QLA_ERROR))
Poornima Vonti7977f822012-09-20 07:35:07 -04008705 goto skip_retry_init;
8706
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308707 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8708 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008709
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008710 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008711 ha->isp_ops->idc_lock(ha);
8712 dev_state = qla4_8xxx_rd_direct(ha,
Vikas Chaudharye951aca2012-12-29 02:24:52 -05008713 QLA8XXX_CRB_DEV_STATE);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008714 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04008715 if (dev_state == QLA8XXX_DEV_FAILED) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008716 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8717 "initialize adapter. H/W is in failed state\n",
8718 __func__);
8719 break;
8720 }
8721 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008722 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8723 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308724
8725 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8726 continue;
8727
Mike Christie13483732011-12-01 21:38:41 -06008728 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Nilesh Javali37418cc2013-12-16 06:49:31 -05008729 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8730 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8731 goto skip_retry_init;
8732 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008733 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308734
Poornima Vonti7977f822012-09-20 07:35:07 -04008735skip_retry_init:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308736 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308737 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008738
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008739 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008740 ((is_qla8032(ha) || is_qla8042(ha)) &&
8741 qla4_83xx_idc_dontreset(ha))) {
Lalit Chandivadefe998522010-12-02 22:12:36 -08008742 /* Put the device in failed state. */
8743 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008744 ha->isp_ops->idc_lock(ha);
8745 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8746 QLA8XXX_DEV_FAILED);
8747 ha->isp_ops->idc_unlock(ha);
Lalit Chandivadefe998522010-12-02 22:12:36 -08008748 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008749 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008750 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008751 }
8752
David Somayajuluafaf5a22006-09-19 10:28:00 -07008753 /* Startup the kernel thread for this host adapter. */
8754 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8755 "qla4xxx_dpc\n", __func__));
8756 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8757 ha->dpc_thread = create_singlethread_workqueue(buf);
8758 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308759 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008760 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008761 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008762 }
David Howellsc4028952006-11-22 14:57:56 +00008763 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008764
Kees Cookd8537542013-07-03 15:04:57 -07008765 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8766 ha->host_no);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008767 if (!ha->task_wq) {
8768 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8769 ret = -ENODEV;
8770 goto remove_host;
8771 }
8772
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008773 /*
8774 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308775 * (which is called indirectly by qla4xxx_initialize_adapter),
8776 * so that irqs will be registered after crbinit but before
8777 * mbx_intr_enable.
8778 */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008779 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308780 ret = qla4xxx_request_irqs(ha);
8781 if (ret) {
8782 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8783 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008784 goto remove_host;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308785 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008786 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008787
Lalit Chandivade2232be02010-07-30 14:38:47 +05308788 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308789 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008790
8791 /* Start timer thread. */
8792 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
8793
8794 set_bit(AF_INIT_DONE, &ha->flags);
8795
Tej Parkash068237c82012-05-18 04:41:44 -04008796 qla4_8xxx_alloc_sysfs_attr(ha);
8797
David Somayajuluafaf5a22006-09-19 10:28:00 -07008798 printk(KERN_INFO
8799 " QLogic iSCSI HBA Driver version: %s\n"
8800 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8801 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
Adheer Chandravanshieee06a02013-07-08 08:33:10 -04008802 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8803 ha->fw_info.fw_patch, ha->fw_info.fw_build);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008804
Manish Dusanecfb27872012-09-20 07:35:01 -04008805 /* Set the driver version */
8806 if (is_qla80XX(ha))
8807 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8808
Manish Rangankar2a991c22011-07-25 13:48:55 -05008809 if (qla4xxx_setup_boot_info(ha))
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -08008810 ql4_printk(KERN_ERR, ha,
8811 "%s: No iSCSI boot target configured\n", __func__);
Manish Rangankar2a991c22011-07-25 13:48:55 -05008812
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008813 if (qla4xxx_sysfs_ddb_export(ha))
8814 ql4_printk(KERN_ERR, ha,
8815 "%s: Error exporting ddb to sysfs\n", __func__);
8816
Mike Christie13483732011-12-01 21:38:41 -06008817 /* Perform the build ddb list and login to each */
8818 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8819 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008820 qla4xxx_wait_login_resp_boot_tgt(ha);
Mike Christie13483732011-12-01 21:38:41 -06008821
8822 qla4xxx_create_chap_list(ha);
8823
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008824 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008825 return 0;
8826
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008827remove_host:
8828 scsi_remove_host(ha->host);
8829
David Somayajuluafaf5a22006-09-19 10:28:00 -07008830probe_failed:
8831 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308832
8833probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05308834 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008835 scsi_host_put(ha->host);
8836
8837probe_disable_device:
8838 pci_disable_device(pdev);
8839
8840 return ret;
8841}
8842
8843/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07008844 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8845 * @ha: pointer to adapter structure
8846 *
8847 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8848 * so that the other port will not re-initialize while in the process of
8849 * removing the ha due to driver unload or hba hotplug.
8850 **/
8851static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8852{
8853 struct scsi_qla_host *other_ha = NULL;
8854 struct pci_dev *other_pdev = NULL;
8855 int fn = ISP4XXX_PCI_FN_2;
8856
8857 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8858 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8859 fn = ISP4XXX_PCI_FN_1;
8860
8861 other_pdev =
8862 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8863 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8864 fn));
8865
8866 /* Get other_ha if other_pdev is valid and state is enable*/
8867 if (other_pdev) {
8868 if (atomic_read(&other_pdev->enable_cnt)) {
8869 other_ha = pci_get_drvdata(other_pdev);
8870 if (other_ha) {
8871 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8872 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8873 "Prevent %s reinit\n", __func__,
8874 dev_name(&other_ha->pdev->dev)));
8875 }
8876 }
8877 pci_dev_put(other_pdev);
8878 }
8879}
8880
Mike Christie13483732011-12-01 21:38:41 -06008881static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8882{
8883 struct ddb_entry *ddb_entry;
8884 int options;
8885 int idx;
8886
8887 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8888
8889 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8890 if ((ddb_entry != NULL) &&
8891 (ddb_entry->ddb_type == FLASH_DDB)) {
8892
8893 options = LOGOUT_OPTION_CLOSE_SESSION;
8894 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
8895 == QLA_ERROR)
8896 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
8897 __func__);
8898
8899 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8900 /*
8901 * we have decremented the reference count of the driver
8902 * when we setup the session to have the driver unload
8903 * to be seamless without actually destroying the
8904 * session
8905 **/
8906 try_module_get(qla4xxx_iscsi_transport.owner);
8907 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8908 qla4xxx_free_ddb(ha, ddb_entry);
8909 iscsi_session_teardown(ddb_entry->sess);
8910 }
8911 }
8912}
Karen Higgins7eece5a2011-03-21 03:34:29 -07008913/**
Masanari Iida59e13d42012-04-25 00:24:16 +09008914 * qla4xxx_remove_adapter - callback function to remove adapter.
David Somayajuluafaf5a22006-09-19 10:28:00 -07008915 * @pci_dev: PCI device pointer
8916 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008917static void qla4xxx_remove_adapter(struct pci_dev *pdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008918{
8919 struct scsi_qla_host *ha;
8920
Vikas Chaudharyf8b07512012-09-20 07:35:08 -04008921 /*
8922 * If the PCI device is disabled then it means probe_adapter had
8923 * failed and resources already cleaned up on probe_adapter exit.
8924 */
8925 if (!pci_is_enabled(pdev))
8926 return;
8927
David Somayajuluafaf5a22006-09-19 10:28:00 -07008928 ha = pci_get_drvdata(pdev);
8929
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008930 if (is_qla40XX(ha))
Karen Higgins7eece5a2011-03-21 03:34:29 -07008931 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07008932
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008933 /* destroy iface from sysfs */
8934 qla4xxx_destroy_ifaces(ha);
8935
Mike Christie13483732011-12-01 21:38:41 -06008936 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
Manish Rangankar2a991c22011-07-25 13:48:55 -05008937 iscsi_boot_destroy_kset(ha->boot_kset);
8938
Mike Christie13483732011-12-01 21:38:41 -06008939 qla4xxx_destroy_fw_ddb_session(ha);
Tej Parkash068237c82012-05-18 04:41:44 -04008940 qla4_8xxx_free_sysfs_attr(ha);
Mike Christie13483732011-12-01 21:38:41 -06008941
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008942 qla4xxx_sysfs_ddb_remove(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008943 scsi_remove_host(ha->host);
8944
8945 qla4xxx_free_adapter(ha);
8946
8947 scsi_host_put(ha->host);
8948
Lalit Chandivade2232be02010-07-30 14:38:47 +05308949 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308950 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008951}
8952
8953/**
8954 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
8955 * @ha: HA context
8956 *
8957 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
8958 * supported addressing method.
8959 */
Adrian Bunk47975472007-04-26 00:35:16 -07008960static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008961{
8962 int retval;
8963
8964 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07008965 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
8966 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07008967 dev_dbg(&ha->pdev->dev,
8968 "Failed to set 64 bit PCI consistent mask; "
8969 "using 32 bit.\n");
8970 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07008971 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07008972 }
8973 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07008974 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07008975}
8976
8977static int qla4xxx_slave_alloc(struct scsi_device *sdev)
8978{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008979 struct iscsi_cls_session *cls_sess;
8980 struct iscsi_session *sess;
8981 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07008982 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008983
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008984 cls_sess = starget_to_session(sdev->sdev_target);
8985 sess = cls_sess->dd_data;
8986 ddb = sess->dd_data;
8987
David Somayajuluafaf5a22006-09-19 10:28:00 -07008988 sdev->hostdata = ddb;
8989 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07008990
8991 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
8992 queue_depth = ql4xmaxqdepth;
8993
8994 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008995 return 0;
8996}
8997
8998static int qla4xxx_slave_configure(struct scsi_device *sdev)
8999{
9000 sdev->tagged_supported = 1;
9001 return 0;
9002}
9003
9004static void qla4xxx_slave_destroy(struct scsi_device *sdev)
9005{
9006 scsi_deactivate_tcq(sdev, 1);
9007}
9008
Tej Parkashf7b4aa62012-04-30 04:12:19 -07009009static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
9010 int reason)
9011{
9012 if (!ql4xqfulltracking)
9013 return -EOPNOTSUPP;
9014
9015 return iscsi_change_queue_depth(sdev, qdepth, reason);
9016}
9017
David Somayajuluafaf5a22006-09-19 10:28:00 -07009018/**
9019 * qla4xxx_del_from_active_array - returns an active srb
9020 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02009021 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07009022 *
9023 * This routine removes and returns the srb at the specified index
9024 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309025struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9026 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009027{
9028 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05309029 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009030
Vikas Chaudhary53698872010-04-28 11:41:59 +05309031 cmd = scsi_host_find_tag(ha->host, index);
9032 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009033 return srb;
9034
Vikas Chaudhary53698872010-04-28 11:41:59 +05309035 srb = (struct srb *)CMD_SP(cmd);
9036 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009037 return srb;
9038
9039 /* update counters */
9040 if (srb->flags & SRB_DMA_VALID) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009041 ha->iocb_cnt -= srb->iocb_cnt;
9042 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05309043 srb->cmd->host_scribble =
9044 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009045 }
9046 return srb;
9047}
9048
9049/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009050 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309051 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07009052 * @cmd: Scsi Command to wait on.
9053 *
9054 * This routine waits for the command to be returned by the Firmware
9055 * for some max time.
9056 **/
9057static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9058 struct scsi_cmnd *cmd)
9059{
9060 int done = 0;
9061 struct srb *rp;
9062 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309063 int ret = SUCCESS;
9064
9065 /* Dont wait on command if PCI error is being handled
9066 * by PCI AER driver
9067 */
9068 if (unlikely(pci_channel_offline(ha->pdev)) ||
9069 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9070 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9071 ha->host_no, __func__);
9072 return ret;
9073 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07009074
9075 do {
9076 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05309077 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009078 if (rp == NULL) {
9079 done++;
9080 break;
9081 }
9082
9083 msleep(2000);
9084 } while (max_wait_time--);
9085
9086 return done;
9087}
9088
9089/**
9090 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9091 * @ha: Pointer to host adapter structure
9092 **/
9093static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9094{
9095 unsigned long wait_online;
9096
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07009097 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009098 while (time_before(jiffies, wait_online)) {
9099
9100 if (adapter_up(ha))
9101 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009102
9103 msleep(2000);
9104 }
9105
9106 return QLA_ERROR;
9107}
9108
9109/**
Mike Christiece545032008-02-29 18:25:20 -06009110 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02009111 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07009112 * @t: target id
9113 * @l: lun id
9114 *
9115 * This function waits for all outstanding commands to a lun to complete. It
9116 * returns 0 if all pending commands are returned and 1 otherwise.
9117 **/
Mike Christiece545032008-02-29 18:25:20 -06009118static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9119 struct scsi_target *stgt,
9120 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009121{
9122 int cnt;
9123 int status = 0;
9124 struct scsi_cmnd *cmd;
9125
9126 /*
Mike Christiece545032008-02-29 18:25:20 -06009127 * Waiting for all commands for the designated target or dev
9128 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07009129 */
9130 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9131 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06009132 if (cmd && stgt == scsi_target(cmd->device) &&
9133 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009134 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9135 status++;
9136 break;
9137 }
9138 }
9139 }
9140 return status;
9141}
9142
9143/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309144 * qla4xxx_eh_abort - callback for abort task.
9145 * @cmd: Pointer to Linux's SCSI command structure
9146 *
9147 * This routine is called by the Linux OS to abort the specified
9148 * command.
9149 **/
9150static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9151{
9152 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9153 unsigned int id = cmd->device->id;
9154 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07009155 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309156 struct srb *srb = NULL;
9157 int ret = SUCCESS;
9158 int wait = 0;
9159
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309160 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04009161 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
9162 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309163
Mike Christie92b3e5b2010-10-06 22:51:17 -07009164 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309165 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07009166 if (!srb) {
9167 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309168 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07009169 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309170 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07009171 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309172
9173 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9174 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
9175 ha->host_no, id, lun));
9176 ret = FAILED;
9177 } else {
9178 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
9179 ha->host_no, id, lun));
9180 wait = 1;
9181 }
9182
9183 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9184
9185 /* Wait for command to complete */
9186 if (wait) {
9187 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9188 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
9189 ha->host_no, id, lun));
9190 ret = FAILED;
9191 }
9192 }
9193
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309194 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309195 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009196 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309197
9198 return ret;
9199}
9200
9201/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009202 * qla4xxx_eh_device_reset - callback for target reset.
9203 * @cmd: Pointer to Linux's SCSI command structure
9204 *
9205 * This routine is called by the Linux OS to reset all luns on the
9206 * specified target.
9207 **/
9208static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9209{
9210 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9211 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009212 int ret = FAILED, stat;
9213
Karen Higgins612f7342009-07-15 15:03:01 -05009214 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009215 return ret;
9216
Mike Christiec01be6d2010-07-22 16:59:49 +05309217 ret = iscsi_block_scsi_eh(cmd);
9218 if (ret)
9219 return ret;
9220 ret = FAILED;
9221
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309222 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009223 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
9224 cmd->device->channel, cmd->device->id, cmd->device->lun);
9225
9226 DEBUG2(printk(KERN_INFO
9227 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9228 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07009229 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009230 ha->dpc_flags, cmd->result, cmd->allowed));
9231
9232 /* FIXME: wait for hba to go online */
9233 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9234 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309235 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009236 goto eh_dev_reset_done;
9237 }
9238
Mike Christiece545032008-02-29 18:25:20 -06009239 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9240 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309241 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06009242 "DEVICE RESET FAILED - waiting for "
9243 "commands.\n");
9244 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009245 }
9246
David C Somayajulu9d562912008-03-19 11:23:03 -07009247 /* Send marker. */
9248 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9249 MM_LUN_RESET) != QLA_SUCCESS)
9250 goto eh_dev_reset_done;
9251
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309252 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009253 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
9254 ha->host_no, cmd->device->channel, cmd->device->id,
9255 cmd->device->lun);
9256
9257 ret = SUCCESS;
9258
9259eh_dev_reset_done:
9260
9261 return ret;
9262}
9263
9264/**
Mike Christiece545032008-02-29 18:25:20 -06009265 * qla4xxx_eh_target_reset - callback for target reset.
9266 * @cmd: Pointer to Linux's SCSI command structure
9267 *
9268 * This routine is called by the Linux OS to reset the target.
9269 **/
9270static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9271{
9272 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9273 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05309274 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06009275
9276 if (!ddb_entry)
9277 return FAILED;
9278
Mike Christiec01be6d2010-07-22 16:59:49 +05309279 ret = iscsi_block_scsi_eh(cmd);
9280 if (ret)
9281 return ret;
9282
Mike Christiece545032008-02-29 18:25:20 -06009283 starget_printk(KERN_INFO, scsi_target(cmd->device),
9284 "WARM TARGET RESET ISSUED.\n");
9285
9286 DEBUG2(printk(KERN_INFO
9287 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9288 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07009289 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06009290 ha->dpc_flags, cmd->result, cmd->allowed));
9291
9292 stat = qla4xxx_reset_target(ha, ddb_entry);
9293 if (stat != QLA_SUCCESS) {
9294 starget_printk(KERN_INFO, scsi_target(cmd->device),
9295 "WARM TARGET RESET FAILED.\n");
9296 return FAILED;
9297 }
9298
Mike Christiece545032008-02-29 18:25:20 -06009299 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9300 NULL)) {
9301 starget_printk(KERN_INFO, scsi_target(cmd->device),
9302 "WARM TARGET DEVICE RESET FAILED - "
9303 "waiting for commands.\n");
9304 return FAILED;
9305 }
9306
David C Somayajulu9d562912008-03-19 11:23:03 -07009307 /* Send marker. */
9308 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9309 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9310 starget_printk(KERN_INFO, scsi_target(cmd->device),
9311 "WARM TARGET DEVICE RESET FAILED - "
9312 "marker iocb failed.\n");
9313 return FAILED;
9314 }
9315
Mike Christiece545032008-02-29 18:25:20 -06009316 starget_printk(KERN_INFO, scsi_target(cmd->device),
9317 "WARM TARGET RESET SUCCEEDED.\n");
9318 return SUCCESS;
9319}
9320
9321/**
Sarang Radke8a28896012011-12-06 02:34:10 -08009322 * qla4xxx_is_eh_active - check if error handler is running
9323 * @shost: Pointer to SCSI Host struct
9324 *
9325 * This routine finds that if reset host is called in EH
9326 * scenario or from some application like sg_reset
9327 **/
9328static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9329{
9330 if (shost->shost_state == SHOST_RECOVERY)
9331 return 1;
9332 return 0;
9333}
9334
9335/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009336 * qla4xxx_eh_host_reset - kernel callback
9337 * @cmd: Pointer to Linux's SCSI command structure
9338 *
9339 * This routine is invoked by the Linux kernel to perform fatal error
9340 * recovery on the specified adapter.
9341 **/
9342static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9343{
9344 int return_status = FAILED;
9345 struct scsi_qla_host *ha;
9346
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009347 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009348
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009349 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009350 qla4_83xx_set_idc_dontreset(ha);
9351
9352 /*
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009353 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9354 * protocol drivers, we should not set device_state to NEED_RESET
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009355 */
9356 if (ql4xdontresethba ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009357 ((is_qla8032(ha) || is_qla8042(ha)) &&
9358 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309359 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9360 ha->host_no, __func__));
Sarang Radke8a28896012011-12-06 02:34:10 -08009361
9362 /* Clear outstanding srb in queues */
9363 if (qla4xxx_is_eh_active(cmd->device->host))
9364 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9365
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309366 return FAILED;
9367 }
9368
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309369 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05009370 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009371 cmd->device->channel, cmd->device->id, cmd->device->lun);
9372
9373 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9374 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9375 "DEAD.\n", ha->host_no, cmd->device->channel,
9376 __func__));
9377
9378 return FAILED;
9379 }
9380
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309381 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009382 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309383 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9384 else
9385 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9386 }
Mike Christie50a29ae2008-03-04 13:26:53 -06009387
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309388 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009389 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009390
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309391 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009392 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07009393
9394 return return_status;
9395}
9396
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009397static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9398{
9399 uint32_t mbox_cmd[MBOX_REG_COUNT];
9400 uint32_t mbox_sts[MBOX_REG_COUNT];
9401 struct addr_ctrl_blk_def *acb = NULL;
9402 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9403 int rval = QLA_SUCCESS;
9404 dma_addr_t acb_dma;
9405
9406 acb = dma_alloc_coherent(&ha->pdev->dev,
9407 sizeof(struct addr_ctrl_blk_def),
9408 &acb_dma, GFP_KERNEL);
9409 if (!acb) {
9410 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9411 __func__);
9412 rval = -ENOMEM;
9413 goto exit_port_reset;
9414 }
9415
9416 memset(acb, 0, acb_len);
9417
9418 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9419 if (rval != QLA_SUCCESS) {
9420 rval = -EIO;
9421 goto exit_free_acb;
9422 }
9423
9424 rval = qla4xxx_disable_acb(ha);
9425 if (rval != QLA_SUCCESS) {
9426 rval = -EIO;
9427 goto exit_free_acb;
9428 }
9429
9430 wait_for_completion_timeout(&ha->disable_acb_comp,
9431 DISABLE_ACB_TOV * HZ);
9432
9433 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9434 if (rval != QLA_SUCCESS) {
9435 rval = -EIO;
9436 goto exit_free_acb;
9437 }
9438
9439exit_free_acb:
9440 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9441 acb, acb_dma);
9442exit_port_reset:
9443 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9444 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9445 return rval;
9446}
9447
9448static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9449{
9450 struct scsi_qla_host *ha = to_qla_host(shost);
9451 int rval = QLA_SUCCESS;
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009452 uint32_t idc_ctrl;
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009453
9454 if (ql4xdontresethba) {
9455 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9456 __func__));
9457 rval = -EPERM;
9458 goto exit_host_reset;
9459 }
9460
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009461 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9462 goto recover_adapter;
9463
9464 switch (reset_type) {
9465 case SCSI_ADAPTER_RESET:
9466 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9467 break;
9468 case SCSI_FIRMWARE_RESET:
9469 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009470 if (is_qla80XX(ha))
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009471 /* set firmware context reset */
9472 set_bit(DPC_RESET_HA_FW_CONTEXT,
9473 &ha->dpc_flags);
9474 else {
9475 rval = qla4xxx_context_reset(ha);
9476 goto exit_host_reset;
9477 }
9478 }
9479 break;
9480 }
9481
9482recover_adapter:
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009483 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009484 * reset is issued by application */
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009485 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9486 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009487 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9488 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9489 (idc_ctrl | GRACEFUL_RESET_BIT1));
9490 }
9491
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009492 rval = qla4xxx_recover_adapter(ha);
9493 if (rval != QLA_SUCCESS) {
9494 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9495 __func__));
9496 rval = -EIO;
9497 }
9498
9499exit_host_reset:
9500 return rval;
9501}
9502
Lalit Chandivade2232be02010-07-30 14:38:47 +05309503/* PCI AER driver recovers from all correctable errors w/o
9504 * driver intervention. For uncorrectable errors PCI AER
9505 * driver calls the following device driver's callbacks
9506 *
9507 * - Fatal Errors - link_reset
9508 * - Non-Fatal Errors - driver's pci_error_detected() which
9509 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9510 *
9511 * PCI AER driver calls
9512 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
9513 * returns RECOVERED or NEED_RESET if fw_hung
9514 * NEED_RESET - driver's slot_reset()
9515 * DISCONNECT - device is dead & cannot recover
9516 * RECOVERED - driver's pci_resume()
9517 */
9518static pci_ers_result_t
9519qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9520{
9521 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9522
9523 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9524 ha->host_no, __func__, state);
9525
9526 if (!is_aer_supported(ha))
9527 return PCI_ERS_RESULT_NONE;
9528
9529 switch (state) {
9530 case pci_channel_io_normal:
9531 clear_bit(AF_EEH_BUSY, &ha->flags);
9532 return PCI_ERS_RESULT_CAN_RECOVER;
9533 case pci_channel_io_frozen:
9534 set_bit(AF_EEH_BUSY, &ha->flags);
9535 qla4xxx_mailbox_premature_completion(ha);
9536 qla4xxx_free_irqs(ha);
9537 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009538 /* Return back all IOs */
9539 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309540 return PCI_ERS_RESULT_NEED_RESET;
9541 case pci_channel_io_perm_failure:
9542 set_bit(AF_EEH_BUSY, &ha->flags);
9543 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9544 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9545 return PCI_ERS_RESULT_DISCONNECT;
9546 }
9547 return PCI_ERS_RESULT_NEED_RESET;
9548}
9549
9550/**
9551 * qla4xxx_pci_mmio_enabled() gets called if
9552 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9553 * and read/write to the device still works.
9554 **/
9555static pci_ers_result_t
9556qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9557{
9558 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9559
9560 if (!is_aer_supported(ha))
9561 return PCI_ERS_RESULT_NONE;
9562
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009563 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309564}
9565
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009566static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05309567{
9568 uint32_t rval = QLA_ERROR;
9569 int fn;
9570 struct pci_dev *other_pdev = NULL;
9571
9572 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9573
9574 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9575
9576 if (test_bit(AF_ONLINE, &ha->flags)) {
9577 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009578 clear_bit(AF_LINK_UP, &ha->flags);
9579 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309580 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309581 }
9582
9583 fn = PCI_FUNC(ha->pdev->devfn);
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009584 if (is_qla8022(ha)) {
9585 while (fn > 0) {
9586 fn--;
9587 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9588 ha->host_no, __func__, fn);
9589 /* Get the pci device given the domain, bus,
9590 * slot/function number */
9591 other_pdev = pci_get_domain_bus_and_slot(
9592 pci_domain_nr(ha->pdev->bus),
9593 ha->pdev->bus->number,
9594 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9595 fn));
Lalit Chandivade2232be02010-07-30 14:38:47 +05309596
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009597 if (!other_pdev)
9598 continue;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309599
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009600 if (atomic_read(&other_pdev->enable_cnt)) {
9601 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9602 ha->host_no, __func__, fn);
9603 pci_dev_put(other_pdev);
9604 break;
9605 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309606 pci_dev_put(other_pdev);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309607 }
Tej Parkashdaa34eb2013-12-16 06:49:38 -05009608 } else {
9609 /* this case is meant for ISP83xx/ISP84xx only */
9610 if (qla4_83xx_can_perform_reset(ha)) {
9611 /* reset fn as iSCSI is going to perform the reset */
9612 fn = 0;
9613 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309614 }
9615
9616 /* The first function on the card, the reset owner will
9617 * start & initialize the firmware. The other functions
9618 * on the card will reset the firmware context
9619 */
9620 if (!fn) {
9621 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9622 "0x%x is the owner\n", ha->host_no, __func__,
9623 ha->pdev->devfn);
9624
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009625 ha->isp_ops->idc_lock(ha);
9626 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9627 QLA8XXX_DEV_COLD);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009628 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309629
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009630 rval = qla4_8xxx_update_idc_reg(ha);
9631 if (rval == QLA_ERROR) {
9632 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9633 ha->host_no, __func__);
9634 ha->isp_ops->idc_lock(ha);
9635 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9636 QLA8XXX_DEV_FAILED);
9637 ha->isp_ops->idc_unlock(ha);
9638 goto exit_error_recovery;
9639 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309640
Lalit Chandivade2232be02010-07-30 14:38:47 +05309641 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009642 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309643
9644 if (rval != QLA_SUCCESS) {
9645 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9646 "FAILED\n", ha->host_no, __func__);
Nilesh Javali37418cc2013-12-16 06:49:31 -05009647 qla4xxx_free_irqs(ha);
Poornima Vonti82761902012-09-20 07:35:04 -04009648 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309649 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009650 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9651 QLA8XXX_DEV_FAILED);
Poornima Vonti82761902012-09-20 07:35:04 -04009652 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309653 } else {
9654 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9655 "READY\n", ha->host_no, __func__);
Poornima Vonti82761902012-09-20 07:35:04 -04009656 ha->isp_ops->idc_lock(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009657 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9658 QLA8XXX_DEV_READY);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309659 /* Clear driver state register */
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009660 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309661 qla4_8xxx_set_drv_active(ha);
Poornima Vonti82761902012-09-20 07:35:04 -04009662 ha->isp_ops->idc_unlock(ha);
Poornima Vonti137257d2013-01-20 23:51:01 -05009663 ha->isp_ops->enable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309664 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309665 } else {
9666 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9667 "the reset owner\n", ha->host_no, __func__,
9668 ha->pdev->devfn);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009669 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9670 QLA8XXX_DEV_READY)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309671 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009672 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Poornima Vonti137257d2013-01-20 23:51:01 -05009673 if (rval == QLA_SUCCESS)
9674 ha->isp_ops->enable_intrs(ha);
Nilesh Javali37418cc2013-12-16 06:49:31 -05009675 else
9676 qla4xxx_free_irqs(ha);
Poornima Vonti137257d2013-01-20 23:51:01 -05009677
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009678 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309679 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009680 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309681 }
9682 }
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009683exit_error_recovery:
Lalit Chandivade2232be02010-07-30 14:38:47 +05309684 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9685 return rval;
9686}
9687
9688static pci_ers_result_t
9689qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9690{
9691 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9692 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9693 int rc;
9694
9695 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9696 ha->host_no, __func__);
9697
9698 if (!is_aer_supported(ha))
9699 return PCI_ERS_RESULT_NONE;
9700
9701 /* Restore the saved state of PCIe device -
9702 * BAR registers, PCI Config space, PCIX, MSI,
9703 * IOV states
9704 */
9705 pci_restore_state(pdev);
9706
9707 /* pci_restore_state() clears the saved_state flag of the device
9708 * save restored state which resets saved_state flag
9709 */
9710 pci_save_state(pdev);
9711
9712 /* Initialize device or resume if in suspended state */
9713 rc = pci_enable_device(pdev);
9714 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009715 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05309716 "device after reset\n", ha->host_no, __func__);
9717 goto exit_slot_reset;
9718 }
9719
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009720 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309721
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009722 if (is_qla80XX(ha)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309723 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9724 ret = PCI_ERS_RESULT_RECOVERED;
9725 goto exit_slot_reset;
9726 } else
9727 goto exit_slot_reset;
9728 }
9729
9730exit_slot_reset:
9731 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9732 "device after reset\n", ha->host_no, __func__, ret);
9733 return ret;
9734}
9735
9736static void
9737qla4xxx_pci_resume(struct pci_dev *pdev)
9738{
9739 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9740 int ret;
9741
9742 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9743 ha->host_no, __func__);
9744
9745 ret = qla4xxx_wait_for_hba_online(ha);
9746 if (ret != QLA_SUCCESS) {
9747 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9748 "resume I/O from slot/link_reset\n", ha->host_no,
9749 __func__);
9750 }
9751
9752 pci_cleanup_aer_uncorrect_error_status(pdev);
9753 clear_bit(AF_EEH_BUSY, &ha->flags);
9754}
9755
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07009756static const struct pci_error_handlers qla4xxx_err_handler = {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309757 .error_detected = qla4xxx_pci_error_detected,
9758 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9759 .slot_reset = qla4xxx_pci_slot_reset,
9760 .resume = qla4xxx_pci_resume,
9761};
9762
David Somayajuluafaf5a22006-09-19 10:28:00 -07009763static struct pci_device_id qla4xxx_pci_tbl[] = {
9764 {
9765 .vendor = PCI_VENDOR_ID_QLOGIC,
9766 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9767 .subvendor = PCI_ANY_ID,
9768 .subdevice = PCI_ANY_ID,
9769 },
9770 {
9771 .vendor = PCI_VENDOR_ID_QLOGIC,
9772 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9773 .subvendor = PCI_ANY_ID,
9774 .subdevice = PCI_ANY_ID,
9775 },
David C Somayajulud9150582006-11-15 17:38:40 -08009776 {
9777 .vendor = PCI_VENDOR_ID_QLOGIC,
9778 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9779 .subvendor = PCI_ANY_ID,
9780 .subdevice = PCI_ANY_ID,
9781 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309782 {
9783 .vendor = PCI_VENDOR_ID_QLOGIC,
9784 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9785 .subvendor = PCI_ANY_ID,
9786 .subdevice = PCI_ANY_ID,
9787 },
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009788 {
9789 .vendor = PCI_VENDOR_ID_QLOGIC,
9790 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9791 .subvendor = PCI_ANY_ID,
9792 .subdevice = PCI_ANY_ID,
9793 },
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009794 {
9795 .vendor = PCI_VENDOR_ID_QLOGIC,
9796 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9797 .subvendor = PCI_ANY_ID,
9798 .subdevice = PCI_ANY_ID,
9799 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07009800 {0, 0},
9801};
9802MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9803
Adrian Bunk47975472007-04-26 00:35:16 -07009804static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009805 .name = DRIVER_NAME,
9806 .id_table = qla4xxx_pci_tbl,
9807 .probe = qla4xxx_probe_adapter,
9808 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05309809 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009810};
9811
9812static int __init qla4xxx_module_init(void)
9813{
9814 int ret;
9815
9816 /* Allocate cache for SRBs. */
9817 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09009818 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009819 if (srb_cachep == NULL) {
9820 printk(KERN_ERR
9821 "%s: Unable to allocate SRB cache..."
9822 "Failing load!\n", DRIVER_NAME);
9823 ret = -ENOMEM;
9824 goto no_srp_cache;
9825 }
9826
9827 /* Derive version string. */
9828 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07009829 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009830 strcat(qla4xxx_version_str, "-debug");
9831
9832 qla4xxx_scsi_transport =
9833 iscsi_register_transport(&qla4xxx_iscsi_transport);
9834 if (!qla4xxx_scsi_transport){
9835 ret = -ENODEV;
9836 goto release_srb_cache;
9837 }
9838
David Somayajuluafaf5a22006-09-19 10:28:00 -07009839 ret = pci_register_driver(&qla4xxx_pci_driver);
9840 if (ret)
9841 goto unregister_transport;
9842
9843 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9844 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05009845
David Somayajuluafaf5a22006-09-19 10:28:00 -07009846unregister_transport:
9847 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9848release_srb_cache:
9849 kmem_cache_destroy(srb_cachep);
9850no_srp_cache:
9851 return ret;
9852}
9853
9854static void __exit qla4xxx_module_exit(void)
9855{
David Somayajuluafaf5a22006-09-19 10:28:00 -07009856 pci_unregister_driver(&qla4xxx_pci_driver);
9857 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9858 kmem_cache_destroy(srb_cachep);
9859}
9860
9861module_init(qla4xxx_module_init);
9862module_exit(qla4xxx_module_exit);
9863
9864MODULE_AUTHOR("QLogic Corporation");
9865MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9866MODULE_LICENSE("GPL");
9867MODULE_VERSION(QLA4XXX_DRIVER_VERSION);