blob: 295b8d401bc4f279bdd13cdcaba9159d46a2f402 [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:
Mike Christie3128c6c2011-07-25 13:48:42 -0500424 return S_IRUGO;
425 default:
426 return 0;
427 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500428 case ISCSI_NET_PARAM:
429 switch (param) {
430 case ISCSI_NET_PARAM_IPV4_ADDR:
431 case ISCSI_NET_PARAM_IPV4_SUBNET:
432 case ISCSI_NET_PARAM_IPV4_GW:
433 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
434 case ISCSI_NET_PARAM_IFACE_ENABLE:
435 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
436 case ISCSI_NET_PARAM_IPV6_ADDR:
437 case ISCSI_NET_PARAM_IPV6_ROUTER:
438 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
439 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500440 case ISCSI_NET_PARAM_VLAN_ID:
441 case ISCSI_NET_PARAM_VLAN_PRIORITY:
442 case ISCSI_NET_PARAM_VLAN_ENABLED:
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700443 case ISCSI_NET_PARAM_MTU:
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700444 case ISCSI_NET_PARAM_PORT:
Harish Zunjarraof8e93412013-10-18 09:01:42 -0400445 case ISCSI_NET_PARAM_IPADDR_STATE:
446 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
447 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
448 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
449 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
450 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
451 case ISCSI_NET_PARAM_TCP_WSF:
452 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
453 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
454 case ISCSI_NET_PARAM_CACHE_ID:
455 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
456 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
457 case ISCSI_NET_PARAM_IPV4_TOS_EN:
458 case ISCSI_NET_PARAM_IPV4_TOS:
459 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
460 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
461 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
462 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
463 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
464 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
465 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
466 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
467 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
468 case ISCSI_NET_PARAM_REDIRECT_EN:
469 case ISCSI_NET_PARAM_IPV4_TTL:
470 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
471 case ISCSI_NET_PARAM_IPV6_MLD_EN:
472 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
473 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
474 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
475 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
476 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
477 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
478 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
479 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
480 return S_IRUGO;
481 default:
482 return 0;
483 }
484 case ISCSI_IFACE_PARAM:
485 switch (param) {
486 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
487 case ISCSI_IFACE_PARAM_HDRDGST_EN:
488 case ISCSI_IFACE_PARAM_DATADGST_EN:
489 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
490 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
491 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
492 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
493 case ISCSI_IFACE_PARAM_ERL:
494 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
495 case ISCSI_IFACE_PARAM_FIRST_BURST:
496 case ISCSI_IFACE_PARAM_MAX_R2T:
497 case ISCSI_IFACE_PARAM_MAX_BURST:
498 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
499 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
500 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
501 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
502 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
503 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
Mike Christieb78dbba2011-07-25 13:48:44 -0500504 return S_IRUGO;
505 default:
506 return 0;
507 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -0400508 case ISCSI_FLASHNODE_PARAM:
509 switch (param) {
510 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
511 case ISCSI_FLASHNODE_PORTAL_TYPE:
512 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
513 case ISCSI_FLASHNODE_DISCOVERY_SESS:
514 case ISCSI_FLASHNODE_ENTRY_EN:
515 case ISCSI_FLASHNODE_HDR_DGST_EN:
516 case ISCSI_FLASHNODE_DATA_DGST_EN:
517 case ISCSI_FLASHNODE_IMM_DATA_EN:
518 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
519 case ISCSI_FLASHNODE_DATASEQ_INORDER:
520 case ISCSI_FLASHNODE_PDU_INORDER:
521 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
522 case ISCSI_FLASHNODE_SNACK_REQ_EN:
523 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
524 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
525 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
526 case ISCSI_FLASHNODE_ERL:
527 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
528 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
529 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
530 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
531 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
532 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
533 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
534 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
535 case ISCSI_FLASHNODE_FIRST_BURST:
536 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
537 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
538 case ISCSI_FLASHNODE_MAX_R2T:
539 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
540 case ISCSI_FLASHNODE_ISID:
541 case ISCSI_FLASHNODE_TSID:
542 case ISCSI_FLASHNODE_PORT:
543 case ISCSI_FLASHNODE_MAX_BURST:
544 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
545 case ISCSI_FLASHNODE_IPADDR:
546 case ISCSI_FLASHNODE_ALIAS:
547 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
548 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
549 case ISCSI_FLASHNODE_LOCAL_PORT:
550 case ISCSI_FLASHNODE_IPV4_TOS:
551 case ISCSI_FLASHNODE_IPV6_TC:
552 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
553 case ISCSI_FLASHNODE_NAME:
554 case ISCSI_FLASHNODE_TPGT:
555 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
556 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
557 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
558 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
559 case ISCSI_FLASHNODE_TCP_RECV_WSF:
560 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
561 case ISCSI_FLASHNODE_USERNAME:
562 case ISCSI_FLASHNODE_PASSWORD:
563 case ISCSI_FLASHNODE_STATSN:
564 case ISCSI_FLASHNODE_EXP_STATSN:
565 case ISCSI_FLASHNODE_IS_BOOT_TGT:
566 return S_IRUGO;
567 default:
568 return 0;
569 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500570 }
571
572 return 0;
573}
574
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400575static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
576 int16_t chap_index,
577 struct ql4_chap_table **chap_entry)
578{
579 int rval = QLA_ERROR;
580 int max_chap_entries;
581
582 if (!ha->chap_list) {
583 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
584 rval = QLA_ERROR;
585 goto exit_get_chap;
586 }
587
588 if (is_qla80XX(ha))
589 max_chap_entries = (ha->hw.flt_chap_size / 2) /
590 sizeof(struct ql4_chap_table);
591 else
592 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
593
594 if (chap_index > max_chap_entries) {
595 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
596 rval = QLA_ERROR;
597 goto exit_get_chap;
598 }
599
600 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
601 if ((*chap_entry)->cookie !=
602 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
603 rval = QLA_ERROR;
604 *chap_entry = NULL;
605 } else {
606 rval = QLA_SUCCESS;
607 }
608
609exit_get_chap:
610 return rval;
611}
612
613/**
614 * qla4xxx_find_free_chap_index - Find the first free chap index
615 * @ha: pointer to adapter structure
616 * @chap_index: CHAP index to be returned
617 *
618 * Find the first free chap index available in the chap table
619 *
620 * Note: Caller should acquire the chap lock before getting here.
621 **/
622static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
623 uint16_t *chap_index)
624{
625 int i, rval;
626 int free_index = -1;
627 int max_chap_entries = 0;
628 struct ql4_chap_table *chap_table;
629
630 if (is_qla80XX(ha))
631 max_chap_entries = (ha->hw.flt_chap_size / 2) /
632 sizeof(struct ql4_chap_table);
633 else
634 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
635
636 if (!ha->chap_list) {
637 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
638 rval = QLA_ERROR;
639 goto exit_find_chap;
640 }
641
642 for (i = 0; i < max_chap_entries; i++) {
643 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
644
645 if ((chap_table->cookie !=
646 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
647 (i > MAX_RESRV_CHAP_IDX)) {
648 free_index = i;
649 break;
650 }
651 }
652
653 if (free_index != -1) {
654 *chap_index = free_index;
655 rval = QLA_SUCCESS;
656 } else {
657 rval = QLA_ERROR;
658 }
659
660exit_find_chap:
661 return rval;
662}
663
Nilesh Javali376738a2012-02-27 03:08:52 -0800664static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
665 uint32_t *num_entries, char *buf)
666{
667 struct scsi_qla_host *ha = to_qla_host(shost);
668 struct ql4_chap_table *chap_table;
669 struct iscsi_chap_rec *chap_rec;
670 int max_chap_entries = 0;
671 int valid_chap_entries = 0;
672 int ret = 0, i;
673
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400674 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800675 max_chap_entries = (ha->hw.flt_chap_size / 2) /
676 sizeof(struct ql4_chap_table);
677 else
678 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
679
680 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
681 __func__, *num_entries, chap_tbl_idx);
682
683 if (!buf) {
684 ret = -ENOMEM;
685 goto exit_get_chap_list;
686 }
687
688 chap_rec = (struct iscsi_chap_rec *) buf;
689 mutex_lock(&ha->chap_sem);
690 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
691 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
692 if (chap_table->cookie !=
693 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
694 continue;
695
696 chap_rec->chap_tbl_idx = i;
697 strncpy(chap_rec->username, chap_table->name,
698 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
699 strncpy(chap_rec->password, chap_table->secret,
700 QL4_CHAP_MAX_SECRET_LEN);
701 chap_rec->password_length = chap_table->secret_len;
702
703 if (chap_table->flags & BIT_7) /* local */
704 chap_rec->chap_type = CHAP_TYPE_OUT;
705
706 if (chap_table->flags & BIT_6) /* peer */
707 chap_rec->chap_type = CHAP_TYPE_IN;
708
709 chap_rec++;
710
711 valid_chap_entries++;
712 if (valid_chap_entries == *num_entries)
713 break;
714 else
715 continue;
716 }
717 mutex_unlock(&ha->chap_sem);
718
719exit_get_chap_list:
720 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
721 __func__, valid_chap_entries);
722 *num_entries = valid_chap_entries;
723 return ret;
724}
725
726static int __qla4xxx_is_chap_active(struct device *dev, void *data)
727{
728 int ret = 0;
729 uint16_t *chap_tbl_idx = (uint16_t *) data;
730 struct iscsi_cls_session *cls_session;
731 struct iscsi_session *sess;
732 struct ddb_entry *ddb_entry;
733
734 if (!iscsi_is_session_dev(dev))
735 goto exit_is_chap_active;
736
737 cls_session = iscsi_dev_to_session(dev);
738 sess = cls_session->dd_data;
739 ddb_entry = sess->dd_data;
740
741 if (iscsi_session_chkready(cls_session))
742 goto exit_is_chap_active;
743
744 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
745 ret = 1;
746
747exit_is_chap_active:
748 return ret;
749}
750
751static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
752 uint16_t chap_tbl_idx)
753{
754 int ret = 0;
755
756 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
757 __qla4xxx_is_chap_active);
758
759 return ret;
760}
761
762static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
763{
764 struct scsi_qla_host *ha = to_qla_host(shost);
765 struct ql4_chap_table *chap_table;
766 dma_addr_t chap_dma;
767 int max_chap_entries = 0;
768 uint32_t offset = 0;
769 uint32_t chap_size;
770 int ret = 0;
771
772 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
773 if (chap_table == NULL)
774 return -ENOMEM;
775
776 memset(chap_table, 0, sizeof(struct ql4_chap_table));
777
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -0400778 if (is_qla80XX(ha))
Nilesh Javali376738a2012-02-27 03:08:52 -0800779 max_chap_entries = (ha->hw.flt_chap_size / 2) /
780 sizeof(struct ql4_chap_table);
781 else
782 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
783
784 if (chap_tbl_idx > max_chap_entries) {
785 ret = -EINVAL;
786 goto exit_delete_chap;
787 }
788
789 /* Check if chap index is in use.
790 * If chap is in use don't delet chap entry */
791 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
792 if (ret) {
793 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
794 "delete from flash\n", chap_tbl_idx);
795 ret = -EBUSY;
796 goto exit_delete_chap;
797 }
798
799 chap_size = sizeof(struct ql4_chap_table);
800 if (is_qla40XX(ha))
801 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
802 else {
803 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
804 /* flt_chap_size is CHAP table size for both ports
805 * so divide it by 2 to calculate the offset for second port
806 */
807 if (ha->port_num == 1)
808 offset += (ha->hw.flt_chap_size / 2);
809 offset += (chap_tbl_idx * chap_size);
810 }
811
812 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
813 if (ret != QLA_SUCCESS) {
814 ret = -EINVAL;
815 goto exit_delete_chap;
816 }
817
818 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
819 __le16_to_cpu(chap_table->cookie)));
820
821 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
822 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
823 goto exit_delete_chap;
824 }
825
826 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
827
828 offset = FLASH_CHAP_OFFSET |
829 (chap_tbl_idx * sizeof(struct ql4_chap_table));
830 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
831 FLASH_OPT_RMW_COMMIT);
832 if (ret == QLA_SUCCESS && ha->chap_list) {
833 mutex_lock(&ha->chap_sem);
834 /* Update ha chap_list cache */
835 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
836 chap_table, sizeof(struct ql4_chap_table));
837 mutex_unlock(&ha->chap_sem);
838 }
839 if (ret != QLA_SUCCESS)
840 ret = -EINVAL;
841
842exit_delete_chap:
843 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
844 return ret;
845}
846
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400847/**
848 * qla4xxx_set_chap_entry - Make chap entry with given information
849 * @shost: pointer to host
850 * @data: chap info - credentials, index and type to make chap entry
851 * @len: length of data
852 *
853 * Add or update chap entry with the given information
854 **/
855static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
856{
857 struct scsi_qla_host *ha = to_qla_host(shost);
858 struct iscsi_chap_rec chap_rec;
859 struct ql4_chap_table *chap_entry = NULL;
860 struct iscsi_param_info *param_info;
861 struct nlattr *attr;
862 int max_chap_entries = 0;
863 int type;
864 int rem = len;
865 int rc = 0;
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300866 int size;
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400867
868 memset(&chap_rec, 0, sizeof(chap_rec));
869
870 nla_for_each_attr(attr, data, len, rem) {
871 param_info = nla_data(attr);
872
873 switch (param_info->param) {
874 case ISCSI_CHAP_PARAM_INDEX:
875 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
876 break;
877 case ISCSI_CHAP_PARAM_CHAP_TYPE:
878 chap_rec.chap_type = param_info->value[0];
879 break;
880 case ISCSI_CHAP_PARAM_USERNAME:
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300881 size = min_t(size_t, sizeof(chap_rec.username),
882 param_info->len);
883 memcpy(chap_rec.username, param_info->value, size);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400884 break;
885 case ISCSI_CHAP_PARAM_PASSWORD:
Dan Carpenter3c60cfd2013-11-13 10:48:11 +0300886 size = min_t(size_t, sizeof(chap_rec.password),
887 param_info->len);
888 memcpy(chap_rec.password, param_info->value, size);
Adheer Chandravanshi26ffd7b2013-09-17 07:54:49 -0400889 break;
890 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
891 chap_rec.password_length = param_info->value[0];
892 break;
893 default:
894 ql4_printk(KERN_ERR, ha,
895 "%s: No such sysfs attribute\n", __func__);
896 rc = -ENOSYS;
897 goto exit_set_chap;
898 };
899 }
900
901 if (chap_rec.chap_type == CHAP_TYPE_IN)
902 type = BIDI_CHAP;
903 else
904 type = LOCAL_CHAP;
905
906 if (is_qla80XX(ha))
907 max_chap_entries = (ha->hw.flt_chap_size / 2) /
908 sizeof(struct ql4_chap_table);
909 else
910 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
911
912 mutex_lock(&ha->chap_sem);
913 if (chap_rec.chap_tbl_idx < max_chap_entries) {
914 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
915 &chap_entry);
916 if (!rc) {
917 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
918 ql4_printk(KERN_INFO, ha,
919 "Type mismatch for CHAP entry %d\n",
920 chap_rec.chap_tbl_idx);
921 rc = -EINVAL;
922 goto exit_unlock_chap;
923 }
924
925 /* If chap index is in use then don't modify it */
926 rc = qla4xxx_is_chap_active(shost,
927 chap_rec.chap_tbl_idx);
928 if (rc) {
929 ql4_printk(KERN_INFO, ha,
930 "CHAP entry %d is in use\n",
931 chap_rec.chap_tbl_idx);
932 rc = -EBUSY;
933 goto exit_unlock_chap;
934 }
935 }
936 } else {
937 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
938 if (rc) {
939 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
940 rc = -EBUSY;
941 goto exit_unlock_chap;
942 }
943 }
944
945 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
946 chap_rec.chap_tbl_idx, type);
947
948exit_unlock_chap:
949 mutex_unlock(&ha->chap_sem);
950
951exit_set_chap:
952 return rc;
953}
954
Lalit Chandivade4161cee2013-11-22 05:28:19 -0500955
956static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
957{
958 struct scsi_qla_host *ha = to_qla_host(shost);
959 struct iscsi_offload_host_stats *host_stats = NULL;
960 int host_stats_size;
961 int ret = 0;
962 int ddb_idx = 0;
963 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
964 int stats_size;
965 dma_addr_t iscsi_stats_dma;
966
967 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
968
969 host_stats_size = sizeof(struct iscsi_offload_host_stats);
970
971 if (host_stats_size != len) {
972 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
973 __func__, len, host_stats_size);
974 ret = -EINVAL;
975 goto exit_host_stats;
976 }
977 host_stats = (struct iscsi_offload_host_stats *)buf;
978
979 if (!buf) {
980 ret = -ENOMEM;
981 goto exit_host_stats;
982 }
983
984 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
985
986 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
987 &iscsi_stats_dma, GFP_KERNEL);
988 if (!ql_iscsi_stats) {
989 ql4_printk(KERN_ERR, ha,
990 "Unable to allocate memory for iscsi stats\n");
991 goto exit_host_stats;
992 }
993
994 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
995 iscsi_stats_dma);
996 if (ret != QLA_SUCCESS) {
997 ql4_printk(KERN_ERR, ha,
998 "Unable to retrieve iscsi stats\n");
999 goto exit_host_stats;
1000 }
1001 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1002 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1003 host_stats->mactx_multicast_frames =
1004 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1005 host_stats->mactx_broadcast_frames =
1006 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1007 host_stats->mactx_pause_frames =
1008 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1009 host_stats->mactx_control_frames =
1010 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1011 host_stats->mactx_deferral =
1012 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1013 host_stats->mactx_excess_deferral =
1014 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1015 host_stats->mactx_late_collision =
1016 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1017 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1018 host_stats->mactx_single_collision =
1019 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1020 host_stats->mactx_multiple_collision =
1021 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1022 host_stats->mactx_collision =
1023 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1024 host_stats->mactx_frames_dropped =
1025 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1026 host_stats->mactx_jumbo_frames =
1027 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1028 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1029 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1030 host_stats->macrx_unknown_control_frames =
1031 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1032 host_stats->macrx_pause_frames =
1033 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1034 host_stats->macrx_control_frames =
1035 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1036 host_stats->macrx_dribble =
1037 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1038 host_stats->macrx_frame_length_error =
1039 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1040 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1041 host_stats->macrx_carrier_sense_error =
1042 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1043 host_stats->macrx_frame_discarded =
1044 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1045 host_stats->macrx_frames_dropped =
1046 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1047 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1048 host_stats->mac_encoding_error =
1049 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1050 host_stats->macrx_length_error_large =
1051 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1052 host_stats->macrx_length_error_small =
1053 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1054 host_stats->macrx_multicast_frames =
1055 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1056 host_stats->macrx_broadcast_frames =
1057 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1058 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1059 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1060 host_stats->iptx_fragments =
1061 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1062 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1063 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1064 host_stats->iprx_fragments =
1065 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1066 host_stats->ip_datagram_reassembly =
1067 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1068 host_stats->ip_invalid_address_error =
1069 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1070 host_stats->ip_error_packets =
1071 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1072 host_stats->ip_fragrx_overlap =
1073 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1074 host_stats->ip_fragrx_outoforder =
1075 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1076 host_stats->ip_datagram_reassembly_timeout =
1077 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1078 host_stats->ipv6tx_packets =
1079 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1080 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1081 host_stats->ipv6tx_fragments =
1082 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1083 host_stats->ipv6rx_packets =
1084 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1085 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1086 host_stats->ipv6rx_fragments =
1087 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1088 host_stats->ipv6_datagram_reassembly =
1089 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1090 host_stats->ipv6_invalid_address_error =
1091 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1092 host_stats->ipv6_error_packets =
1093 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1094 host_stats->ipv6_fragrx_overlap =
1095 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1096 host_stats->ipv6_fragrx_outoforder =
1097 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1098 host_stats->ipv6_datagram_reassembly_timeout =
1099 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1100 host_stats->tcptx_segments =
1101 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1102 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1103 host_stats->tcprx_segments =
1104 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1105 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1106 host_stats->tcp_duplicate_ack_retx =
1107 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1108 host_stats->tcp_retx_timer_expired =
1109 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1110 host_stats->tcprx_duplicate_ack =
1111 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1112 host_stats->tcprx_pure_ackr =
1113 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1114 host_stats->tcptx_delayed_ack =
1115 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1116 host_stats->tcptx_pure_ack =
1117 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1118 host_stats->tcprx_segment_error =
1119 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1120 host_stats->tcprx_segment_outoforder =
1121 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1122 host_stats->tcprx_window_probe =
1123 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1124 host_stats->tcprx_window_update =
1125 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1126 host_stats->tcptx_window_probe_persist =
1127 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1128 host_stats->ecc_error_correction =
1129 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1130 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1131 host_stats->iscsi_data_bytes_tx =
1132 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1133 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1134 host_stats->iscsi_data_bytes_rx =
1135 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1136 host_stats->iscsi_io_completed =
1137 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1138 host_stats->iscsi_unexpected_io_rx =
1139 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1140 host_stats->iscsi_format_error =
1141 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1142 host_stats->iscsi_hdr_digest_error =
1143 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1144 host_stats->iscsi_data_digest_error =
1145 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1146 host_stats->iscsi_sequence_error =
1147 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1148exit_host_stats:
1149 if (ql_iscsi_stats)
1150 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1151 ql_iscsi_stats, iscsi_stats_dma);
1152
1153 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1154 __func__);
1155 return ret;
1156}
1157
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001158static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1159 enum iscsi_param_type param_type,
1160 int param, char *buf)
1161{
1162 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1163 struct scsi_qla_host *ha = to_qla_host(shost);
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001164 int ival;
1165 char *pval = NULL;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001166 int len = -ENOSYS;
1167
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001168 if (param_type == ISCSI_NET_PARAM) {
1169 switch (param) {
1170 case ISCSI_NET_PARAM_IPV4_ADDR:
1171 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1172 break;
1173 case ISCSI_NET_PARAM_IPV4_SUBNET:
1174 len = sprintf(buf, "%pI4\n",
1175 &ha->ip_config.subnet_mask);
1176 break;
1177 case ISCSI_NET_PARAM_IPV4_GW:
1178 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1179 break;
1180 case ISCSI_NET_PARAM_IFACE_ENABLE:
1181 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1182 OP_STATE(ha->ip_config.ipv4_options,
1183 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1184 } else {
1185 OP_STATE(ha->ip_config.ipv6_options,
1186 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1187 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001188
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001189 len = sprintf(buf, "%s\n", pval);
1190 break;
1191 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001192 len = sprintf(buf, "%s\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001193 (ha->ip_config.tcp_options &
1194 TCPOPT_DHCP_ENABLE) ?
1195 "dhcp" : "static");
1196 break;
1197 case ISCSI_NET_PARAM_IPV6_ADDR:
1198 if (iface->iface_num == 0)
1199 len = sprintf(buf, "%pI6\n",
1200 &ha->ip_config.ipv6_addr0);
1201 if (iface->iface_num == 1)
1202 len = sprintf(buf, "%pI6\n",
1203 &ha->ip_config.ipv6_addr1);
1204 break;
1205 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1206 len = sprintf(buf, "%pI6\n",
1207 &ha->ip_config.ipv6_link_local_addr);
1208 break;
1209 case ISCSI_NET_PARAM_IPV6_ROUTER:
1210 len = sprintf(buf, "%pI6\n",
1211 &ha->ip_config.ipv6_default_router_addr);
1212 break;
1213 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1214 pval = (ha->ip_config.ipv6_addl_options &
1215 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1216 "nd" : "static";
1217
1218 len = sprintf(buf, "%s\n", pval);
1219 break;
1220 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1221 pval = (ha->ip_config.ipv6_addl_options &
1222 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1223 "auto" : "static";
1224
1225 len = sprintf(buf, "%s\n", pval);
1226 break;
1227 case ISCSI_NET_PARAM_VLAN_ID:
1228 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1229 ival = ha->ip_config.ipv4_vlan_tag &
1230 ISCSI_MAX_VLAN_ID;
1231 else
1232 ival = ha->ip_config.ipv6_vlan_tag &
1233 ISCSI_MAX_VLAN_ID;
1234
1235 len = sprintf(buf, "%d\n", ival);
1236 break;
1237 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1238 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1239 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1240 ISCSI_MAX_VLAN_PRIORITY;
1241 else
1242 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1243 ISCSI_MAX_VLAN_PRIORITY;
1244
1245 len = sprintf(buf, "%d\n", ival);
1246 break;
1247 case ISCSI_NET_PARAM_VLAN_ENABLED:
1248 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1249 OP_STATE(ha->ip_config.ipv4_options,
1250 IPOPT_VLAN_TAGGING_ENABLE, pval);
1251 } else {
1252 OP_STATE(ha->ip_config.ipv6_options,
1253 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1254 }
1255 len = sprintf(buf, "%s\n", pval);
1256 break;
1257 case ISCSI_NET_PARAM_MTU:
1258 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1259 break;
1260 case ISCSI_NET_PARAM_PORT:
1261 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1262 len = sprintf(buf, "%d\n",
1263 ha->ip_config.ipv4_port);
1264 else
1265 len = sprintf(buf, "%d\n",
1266 ha->ip_config.ipv6_port);
1267 break;
1268 case ISCSI_NET_PARAM_IPADDR_STATE:
1269 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1270 pval = iscsi_get_ipaddress_state_name(
1271 ha->ip_config.ipv4_addr_state);
1272 } else {
1273 if (iface->iface_num == 0)
1274 pval = iscsi_get_ipaddress_state_name(
1275 ha->ip_config.ipv6_addr0_state);
1276 else if (iface->iface_num == 1)
1277 pval = iscsi_get_ipaddress_state_name(
1278 ha->ip_config.ipv6_addr1_state);
1279 }
1280
1281 len = sprintf(buf, "%s\n", pval);
1282 break;
1283 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1284 pval = iscsi_get_ipaddress_state_name(
1285 ha->ip_config.ipv6_link_local_state);
1286 len = sprintf(buf, "%s\n", pval);
1287 break;
1288 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1289 pval = iscsi_get_router_state_name(
1290 ha->ip_config.ipv6_default_router_state);
1291 len = sprintf(buf, "%s\n", pval);
1292 break;
1293 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1294 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1295 OP_STATE(~ha->ip_config.tcp_options,
1296 TCPOPT_DELAYED_ACK_DISABLE, pval);
1297 } else {
1298 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1299 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1300 }
1301 len = sprintf(buf, "%s\n", pval);
1302 break;
1303 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1304 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1305 OP_STATE(~ha->ip_config.tcp_options,
1306 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1307 } else {
1308 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1309 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1310 }
1311 len = sprintf(buf, "%s\n", pval);
1312 break;
1313 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1314 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1315 OP_STATE(~ha->ip_config.tcp_options,
1316 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1317 } else {
1318 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1319 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1320 pval);
1321 }
1322 len = sprintf(buf, "%s\n", pval);
1323 break;
1324 case ISCSI_NET_PARAM_TCP_WSF:
1325 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1326 len = sprintf(buf, "%d\n",
1327 ha->ip_config.tcp_wsf);
1328 else
1329 len = sprintf(buf, "%d\n",
1330 ha->ip_config.ipv6_tcp_wsf);
1331 break;
1332 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1333 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1334 ival = (ha->ip_config.tcp_options &
1335 TCPOPT_TIMER_SCALE) >> 1;
1336 else
1337 ival = (ha->ip_config.ipv6_tcp_options &
1338 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1339
1340 len = sprintf(buf, "%d\n", ival);
1341 break;
1342 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1343 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1344 OP_STATE(ha->ip_config.tcp_options,
1345 TCPOPT_TIMESTAMP_ENABLE, pval);
1346 } else {
1347 OP_STATE(ha->ip_config.ipv6_tcp_options,
1348 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1349 }
1350 len = sprintf(buf, "%s\n", pval);
1351 break;
1352 case ISCSI_NET_PARAM_CACHE_ID:
1353 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1354 len = sprintf(buf, "%d\n",
1355 ha->ip_config.ipv4_cache_id);
1356 else
1357 len = sprintf(buf, "%d\n",
1358 ha->ip_config.ipv6_cache_id);
1359 break;
1360 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1361 OP_STATE(ha->ip_config.tcp_options,
1362 TCPOPT_DNS_SERVER_IP_EN, pval);
1363
1364 len = sprintf(buf, "%s\n", pval);
1365 break;
1366 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1367 OP_STATE(ha->ip_config.tcp_options,
1368 TCPOPT_SLP_DA_INFO_EN, pval);
1369
1370 len = sprintf(buf, "%s\n", pval);
1371 break;
1372 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1373 OP_STATE(ha->ip_config.ipv4_options,
1374 IPOPT_IPV4_TOS_EN, pval);
1375
1376 len = sprintf(buf, "%s\n", pval);
1377 break;
1378 case ISCSI_NET_PARAM_IPV4_TOS:
1379 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1380 break;
1381 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1382 OP_STATE(ha->ip_config.ipv4_options,
1383 IPOPT_GRAT_ARP_EN, pval);
1384
1385 len = sprintf(buf, "%s\n", pval);
1386 break;
1387 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1388 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1389 pval);
1390
1391 len = sprintf(buf, "%s\n", pval);
1392 break;
1393 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1394 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1395 (char *)ha->ip_config.ipv4_alt_cid : "";
1396
1397 len = sprintf(buf, "%s\n", pval);
1398 break;
1399 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1400 OP_STATE(ha->ip_config.ipv4_options,
1401 IPOPT_REQ_VID_EN, pval);
1402
1403 len = sprintf(buf, "%s\n", pval);
1404 break;
1405 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1406 OP_STATE(ha->ip_config.ipv4_options,
1407 IPOPT_USE_VID_EN, pval);
1408
1409 len = sprintf(buf, "%s\n", pval);
1410 break;
1411 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1412 pval = (ha->ip_config.ipv4_vid_len) ?
1413 (char *)ha->ip_config.ipv4_vid : "";
1414
1415 len = sprintf(buf, "%s\n", pval);
1416 break;
1417 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1418 OP_STATE(ha->ip_config.ipv4_options,
1419 IPOPT_LEARN_IQN_EN, pval);
1420
1421 len = sprintf(buf, "%s\n", pval);
1422 break;
1423 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1424 OP_STATE(~ha->ip_config.ipv4_options,
1425 IPOPT_FRAGMENTATION_DISABLE, pval);
1426
1427 len = sprintf(buf, "%s\n", pval);
1428 break;
1429 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1430 OP_STATE(ha->ip_config.ipv4_options,
1431 IPOPT_IN_FORWARD_EN, pval);
1432
1433 len = sprintf(buf, "%s\n", pval);
1434 break;
1435 case ISCSI_NET_PARAM_REDIRECT_EN:
1436 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1437 OP_STATE(ha->ip_config.ipv4_options,
1438 IPOPT_ARP_REDIRECT_EN, pval);
1439 } else {
1440 OP_STATE(ha->ip_config.ipv6_options,
1441 IPV6_OPT_REDIRECT_EN, pval);
1442 }
1443 len = sprintf(buf, "%s\n", pval);
1444 break;
1445 case ISCSI_NET_PARAM_IPV4_TTL:
1446 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1447 break;
1448 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1449 OP_STATE(ha->ip_config.ipv6_options,
1450 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1451
1452 len = sprintf(buf, "%s\n", pval);
1453 break;
1454 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1455 OP_STATE(ha->ip_config.ipv6_addl_options,
1456 IPV6_ADDOPT_MLD_EN, pval);
1457
1458 len = sprintf(buf, "%s\n", pval);
1459 break;
1460 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1461 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1462 break;
1463 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001464 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001465 ha->ip_config.ipv6_traffic_class);
1466 break;
1467 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001468 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001469 ha->ip_config.ipv6_hop_limit);
1470 break;
1471 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001472 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001473 ha->ip_config.ipv6_nd_reach_time);
1474 break;
1475 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05001476 len = sprintf(buf, "%d\n",
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001477 ha->ip_config.ipv6_nd_rexmit_timer);
1478 break;
1479 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1480 len = sprintf(buf, "%d\n",
1481 ha->ip_config.ipv6_nd_stale_timeout);
1482 break;
1483 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1484 len = sprintf(buf, "%d\n",
1485 ha->ip_config.ipv6_dup_addr_detect_count);
1486 break;
1487 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1488 len = sprintf(buf, "%d\n",
1489 ha->ip_config.ipv6_gw_advrt_mtu);
1490 break;
1491 default:
1492 len = -ENOSYS;
1493 }
1494 } else if (param_type == ISCSI_IFACE_PARAM) {
1495 switch (param) {
1496 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1497 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1498 break;
1499 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1500 OP_STATE(ha->ip_config.iscsi_options,
1501 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1502
1503 len = sprintf(buf, "%s\n", pval);
1504 break;
1505 case ISCSI_IFACE_PARAM_DATADGST_EN:
1506 OP_STATE(ha->ip_config.iscsi_options,
1507 ISCSIOPTS_DATA_DIGEST_EN, pval);
1508
1509 len = sprintf(buf, "%s\n", pval);
1510 break;
1511 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1512 OP_STATE(ha->ip_config.iscsi_options,
1513 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1514
1515 len = sprintf(buf, "%s\n", pval);
1516 break;
1517 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1518 OP_STATE(ha->ip_config.iscsi_options,
1519 ISCSIOPTS_INITIAL_R2T_EN, pval);
1520
1521 len = sprintf(buf, "%s\n", pval);
1522 break;
1523 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1524 OP_STATE(ha->ip_config.iscsi_options,
1525 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1526
1527 len = sprintf(buf, "%s\n", pval);
1528 break;
1529 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1530 OP_STATE(ha->ip_config.iscsi_options,
1531 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1532
1533 len = sprintf(buf, "%s\n", pval);
1534 break;
1535 case ISCSI_IFACE_PARAM_ERL:
1536 len = sprintf(buf, "%d\n",
1537 (ha->ip_config.iscsi_options &
1538 ISCSIOPTS_ERL));
1539 break;
1540 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1541 len = sprintf(buf, "%u\n",
1542 ha->ip_config.iscsi_max_pdu_size *
1543 BYTE_UNITS);
1544 break;
1545 case ISCSI_IFACE_PARAM_FIRST_BURST:
1546 len = sprintf(buf, "%u\n",
1547 ha->ip_config.iscsi_first_burst_len *
1548 BYTE_UNITS);
1549 break;
1550 case ISCSI_IFACE_PARAM_MAX_R2T:
1551 len = sprintf(buf, "%d\n",
1552 ha->ip_config.iscsi_max_outstnd_r2t);
1553 break;
1554 case ISCSI_IFACE_PARAM_MAX_BURST:
1555 len = sprintf(buf, "%u\n",
1556 ha->ip_config.iscsi_max_burst_len *
1557 BYTE_UNITS);
1558 break;
1559 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1560 OP_STATE(ha->ip_config.iscsi_options,
1561 ISCSIOPTS_CHAP_AUTH_EN, pval);
1562
1563 len = sprintf(buf, "%s\n", pval);
1564 break;
1565 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1566 OP_STATE(ha->ip_config.iscsi_options,
1567 ISCSIOPTS_BIDI_CHAP_EN, pval);
1568
1569 len = sprintf(buf, "%s\n", pval);
1570 break;
1571 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1572 OP_STATE(ha->ip_config.iscsi_options,
1573 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1574
1575 len = sprintf(buf, "%s\n", pval);
1576 break;
1577 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1578 OP_STATE(ha->ip_config.iscsi_options,
1579 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1580
1581 len = sprintf(buf, "%s\n", pval);
1582 break;
1583 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1584 OP_STATE(ha->ip_config.iscsi_options,
1585 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1586
1587 len = sprintf(buf, "%s\n", pval);
1588 break;
1589 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1590 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1591 break;
1592 default:
1593 len = -ENOSYS;
1594 }
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001595 }
1596
1597 return len;
1598}
1599
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001600static struct iscsi_endpoint *
1601qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1602 int non_blocking)
1603{
1604 int ret;
1605 struct iscsi_endpoint *ep;
1606 struct qla_endpoint *qla_ep;
1607 struct scsi_qla_host *ha;
1608 struct sockaddr_in *addr;
1609 struct sockaddr_in6 *addr6;
1610
1611 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1612 if (!shost) {
1613 ret = -ENXIO;
1614 printk(KERN_ERR "%s: shost is NULL\n",
1615 __func__);
1616 return ERR_PTR(ret);
1617 }
1618
1619 ha = iscsi_host_priv(shost);
1620
1621 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1622 if (!ep) {
1623 ret = -ENOMEM;
1624 return ERR_PTR(ret);
1625 }
1626
1627 qla_ep = ep->dd_data;
1628 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1629 if (dst_addr->sa_family == AF_INET) {
1630 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1631 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1632 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1633 (char *)&addr->sin_addr));
1634 } else if (dst_addr->sa_family == AF_INET6) {
1635 memcpy(&qla_ep->dst_addr, dst_addr,
1636 sizeof(struct sockaddr_in6));
1637 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1638 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1639 (char *)&addr6->sin6_addr));
1640 }
1641
1642 qla_ep->host = shost;
1643
1644 return ep;
1645}
1646
1647static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1648{
1649 struct qla_endpoint *qla_ep;
1650 struct scsi_qla_host *ha;
1651 int ret = 0;
1652
1653 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1654 qla_ep = ep->dd_data;
1655 ha = to_qla_host(qla_ep->host);
1656
Mike Christie13483732011-12-01 21:38:41 -06001657 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001658 ret = 1;
1659
1660 return ret;
1661}
1662
1663static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1664{
1665 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1666 iscsi_destroy_endpoint(ep);
1667}
1668
1669static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1670 enum iscsi_param param,
1671 char *buf)
1672{
1673 struct qla_endpoint *qla_ep = ep->dd_data;
1674 struct sockaddr *dst_addr;
1675
1676 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1677
1678 switch (param) {
1679 case ISCSI_PARAM_CONN_PORT:
1680 case ISCSI_PARAM_CONN_ADDRESS:
1681 if (!qla_ep)
1682 return -ENOTCONN;
1683
1684 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1685 if (!dst_addr)
1686 return -ENOTCONN;
1687
1688 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1689 &qla_ep->dst_addr, param, buf);
1690 default:
1691 return -ENOSYS;
1692 }
1693}
1694
1695static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1696 struct iscsi_stats *stats)
1697{
1698 struct iscsi_session *sess;
1699 struct iscsi_cls_session *cls_sess;
1700 struct ddb_entry *ddb_entry;
1701 struct scsi_qla_host *ha;
1702 struct ql_iscsi_stats *ql_iscsi_stats;
1703 int stats_size;
1704 int ret;
1705 dma_addr_t iscsi_stats_dma;
1706
1707 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1708
1709 cls_sess = iscsi_conn_to_session(cls_conn);
1710 sess = cls_sess->dd_data;
1711 ddb_entry = sess->dd_data;
1712 ha = ddb_entry->ha;
1713
1714 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1715 /* Allocate memory */
1716 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1717 &iscsi_stats_dma, GFP_KERNEL);
1718 if (!ql_iscsi_stats) {
1719 ql4_printk(KERN_ERR, ha,
1720 "Unable to allocate memory for iscsi stats\n");
1721 goto exit_get_stats;
1722 }
1723
1724 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1725 iscsi_stats_dma);
1726 if (ret != QLA_SUCCESS) {
1727 ql4_printk(KERN_ERR, ha,
Masanari Iida59e13d42012-04-25 00:24:16 +09001728 "Unable to retrieve iscsi stats\n");
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001729 goto free_stats;
1730 }
1731
1732 /* octets */
1733 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1734 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1735 /* xmit pdus */
1736 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1737 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1738 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1739 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1740 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1741 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1742 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1743 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1744 /* recv pdus */
1745 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1746 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1747 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1748 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1749 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1750 stats->logoutrsp_pdus =
1751 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1752 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1753 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1754 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1755
1756free_stats:
1757 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1758 iscsi_stats_dma);
1759exit_get_stats:
1760 return;
1761}
1762
Mike Christie5c656af2009-07-15 15:02:59 -05001763static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1764{
1765 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001766 struct iscsi_session *sess;
1767 unsigned long flags;
1768 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -05001769
1770 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001771 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -05001772
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001773 spin_lock_irqsave(&session->lock, flags);
1774 if (session->state == ISCSI_SESSION_FAILED)
1775 ret = BLK_EH_RESET_TIMER;
1776 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -05001777
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001778 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001779}
1780
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001781static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1782{
1783 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001784 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001785 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1786
1787 qla4xxx_get_firmware_state(ha);
1788
1789 switch (ha->addl_fw_state & 0x0F00) {
1790 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1791 speed = ISCSI_PORT_SPEED_10MBPS;
1792 break;
1793 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1794 speed = ISCSI_PORT_SPEED_100MBPS;
1795 break;
1796 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1797 speed = ISCSI_PORT_SPEED_1GBPS;
1798 break;
1799 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1800 speed = ISCSI_PORT_SPEED_10GBPS;
1801 break;
1802 }
1803 ihost->port_speed = speed;
1804}
1805
1806static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1807{
1808 struct scsi_qla_host *ha = to_qla_host(shost);
Vikas Chaudharye16d1662012-03-02 01:55:31 -08001809 struct iscsi_cls_host *ihost = shost->shost_data;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001810 uint32_t state = ISCSI_PORT_STATE_DOWN;
1811
1812 if (test_bit(AF_LINK_UP, &ha->flags))
1813 state = ISCSI_PORT_STATE_UP;
1814
1815 ihost->port_state = state;
1816}
1817
Mike Christieaa1e93a2007-05-30 12:57:09 -05001818static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1819 enum iscsi_host_param param, char *buf)
1820{
1821 struct scsi_qla_host *ha = to_qla_host(shost);
1822 int len;
1823
1824 switch (param) {
1825 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -08001826 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -05001827 break;
Mike Christie22236962007-05-30 12:57:24 -05001828 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05001829 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -05001830 break;
Mike Christie8ad57812007-05-30 12:57:13 -05001831 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -05001832 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -05001833 break;
Vikas Chaudhary3254dbe2012-01-19 03:06:56 -08001834 case ISCSI_HOST_PARAM_PORT_STATE:
1835 qla4xxx_set_port_state(shost);
1836 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1837 break;
1838 case ISCSI_HOST_PARAM_PORT_SPEED:
1839 qla4xxx_set_port_speed(shost);
1840 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1841 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -05001842 default:
1843 return -ENOSYS;
1844 }
1845
1846 return len;
1847}
1848
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001849static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1850{
1851 if (ha->iface_ipv4)
1852 return;
1853
1854 /* IPv4 */
1855 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1856 &qla4xxx_iscsi_transport,
1857 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1858 if (!ha->iface_ipv4)
1859 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1860 "iface0.\n");
1861}
1862
1863static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1864{
1865 if (!ha->iface_ipv6_0)
1866 /* IPv6 iface-0 */
1867 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1868 &qla4xxx_iscsi_transport,
1869 ISCSI_IFACE_TYPE_IPV6, 0,
1870 0);
1871 if (!ha->iface_ipv6_0)
1872 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1873 "iface0.\n");
1874
1875 if (!ha->iface_ipv6_1)
1876 /* IPv6 iface-1 */
1877 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1878 &qla4xxx_iscsi_transport,
1879 ISCSI_IFACE_TYPE_IPV6, 1,
1880 0);
1881 if (!ha->iface_ipv6_1)
1882 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1883 "iface1.\n");
1884}
1885
1886static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1887{
1888 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1889 qla4xxx_create_ipv4_iface(ha);
1890
1891 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1892 qla4xxx_create_ipv6_iface(ha);
1893}
1894
1895static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1896{
1897 if (ha->iface_ipv4) {
1898 iscsi_destroy_iface(ha->iface_ipv4);
1899 ha->iface_ipv4 = NULL;
1900 }
1901}
1902
1903static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1904{
1905 if (ha->iface_ipv6_0) {
1906 iscsi_destroy_iface(ha->iface_ipv6_0);
1907 ha->iface_ipv6_0 = NULL;
1908 }
1909 if (ha->iface_ipv6_1) {
1910 iscsi_destroy_iface(ha->iface_ipv6_1);
1911 ha->iface_ipv6_1 = NULL;
1912 }
1913}
1914
1915static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1916{
1917 qla4xxx_destroy_ipv4_iface(ha);
1918 qla4xxx_destroy_ipv6_iface(ha);
1919}
1920
Mike Christied00efe32011-07-25 13:48:38 -05001921static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1922 struct iscsi_iface_param_info *iface_param,
1923 struct addr_ctrl_blk *init_fw_cb)
1924{
1925 /*
1926 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1927 * iface_num 1 is valid only for IPv6 Addr.
1928 */
1929 switch (iface_param->param) {
1930 case ISCSI_NET_PARAM_IPV6_ADDR:
1931 if (iface_param->iface_num & 0x1)
1932 /* IPv6 Addr 1 */
1933 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
1934 sizeof(init_fw_cb->ipv6_addr1));
1935 else
1936 /* IPv6 Addr 0 */
1937 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
1938 sizeof(init_fw_cb->ipv6_addr0));
1939 break;
1940 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1941 if (iface_param->iface_num & 0x1)
1942 break;
1943 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
1944 sizeof(init_fw_cb->ipv6_if_id));
1945 break;
1946 case ISCSI_NET_PARAM_IPV6_ROUTER:
1947 if (iface_param->iface_num & 0x1)
1948 break;
1949 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
1950 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1951 break;
1952 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1953 /* Autocfg applies to even interface */
1954 if (iface_param->iface_num & 0x1)
1955 break;
1956
1957 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
1958 init_fw_cb->ipv6_addtl_opts &=
1959 cpu_to_le16(
1960 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1961 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
1962 init_fw_cb->ipv6_addtl_opts |=
1963 cpu_to_le16(
1964 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1965 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001966 ql4_printk(KERN_ERR, ha,
1967 "Invalid autocfg setting for IPv6 addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05001968 break;
1969 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1970 /* Autocfg applies to even interface */
1971 if (iface_param->iface_num & 0x1)
1972 break;
1973
1974 if (iface_param->value[0] ==
1975 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
1976 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
1977 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1978 else if (iface_param->value[0] ==
1979 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
1980 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
1981 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1982 else
Harish Zunjarraof8e93412013-10-18 09:01:42 -04001983 ql4_printk(KERN_ERR, ha,
1984 "Invalid autocfg setting for IPv6 linklocal addr\n");
Mike Christied00efe32011-07-25 13:48:38 -05001985 break;
1986 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
1987 /* Autocfg applies to even interface */
1988 if (iface_param->iface_num & 0x1)
1989 break;
1990
1991 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
1992 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
1993 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1994 break;
1995 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001996 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05001997 init_fw_cb->ipv6_opts |=
1998 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05001999 qla4xxx_create_ipv6_iface(ha);
2000 } else {
Mike Christied00efe32011-07-25 13:48:38 -05002001 init_fw_cb->ipv6_opts &=
2002 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2003 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002004 qla4xxx_destroy_ipv6_iface(ha);
2005 }
Mike Christied00efe32011-07-25 13:48:38 -05002006 break;
Mike Christie2d636732011-10-11 17:55:11 -05002007 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002008 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2009 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002010 init_fw_cb->ipv6_vlan_tag =
2011 cpu_to_be16(*(uint16_t *)iface_param->value);
2012 break;
2013 case ISCSI_NET_PARAM_VLAN_ENABLED:
2014 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2015 init_fw_cb->ipv6_opts |=
2016 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2017 else
2018 init_fw_cb->ipv6_opts &=
2019 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002020 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002021 case ISCSI_NET_PARAM_MTU:
2022 init_fw_cb->eth_mtu_size =
2023 cpu_to_le16(*(uint16_t *)iface_param->value);
2024 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002025 case ISCSI_NET_PARAM_PORT:
2026 /* Autocfg applies to even interface */
2027 if (iface_param->iface_num & 0x1)
2028 break;
2029
2030 init_fw_cb->ipv6_port =
2031 cpu_to_le16(*(uint16_t *)iface_param->value);
2032 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002033 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2034 if (iface_param->iface_num & 0x1)
2035 break;
2036 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2037 init_fw_cb->ipv6_tcp_opts |=
2038 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2039 else
2040 init_fw_cb->ipv6_tcp_opts &=
2041 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2042 break;
2043 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2044 if (iface_param->iface_num & 0x1)
2045 break;
2046 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2047 init_fw_cb->ipv6_tcp_opts |=
2048 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2049 else
2050 init_fw_cb->ipv6_tcp_opts &=
2051 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2052 break;
2053 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2054 if (iface_param->iface_num & 0x1)
2055 break;
2056 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2057 init_fw_cb->ipv6_tcp_opts |=
2058 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2059 else
2060 init_fw_cb->ipv6_tcp_opts &=
2061 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2062 break;
2063 case ISCSI_NET_PARAM_TCP_WSF:
2064 if (iface_param->iface_num & 0x1)
2065 break;
2066 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2067 break;
2068 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2069 if (iface_param->iface_num & 0x1)
2070 break;
2071 init_fw_cb->ipv6_tcp_opts &=
2072 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2073 init_fw_cb->ipv6_tcp_opts |=
2074 cpu_to_le16((iface_param->value[0] << 1) &
2075 IPV6_TCPOPT_TIMER_SCALE);
2076 break;
2077 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2078 if (iface_param->iface_num & 0x1)
2079 break;
2080 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2081 init_fw_cb->ipv6_tcp_opts |=
2082 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2083 else
2084 init_fw_cb->ipv6_tcp_opts &=
2085 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2086 break;
2087 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2088 if (iface_param->iface_num & 0x1)
2089 break;
2090 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2091 init_fw_cb->ipv6_opts |=
2092 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2093 else
2094 init_fw_cb->ipv6_opts &=
2095 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2096 break;
2097 case ISCSI_NET_PARAM_REDIRECT_EN:
2098 if (iface_param->iface_num & 0x1)
2099 break;
2100 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2101 init_fw_cb->ipv6_opts |=
2102 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2103 else
2104 init_fw_cb->ipv6_opts &=
2105 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2106 break;
2107 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2108 if (iface_param->iface_num & 0x1)
2109 break;
2110 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2111 init_fw_cb->ipv6_addtl_opts |=
2112 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2113 else
2114 init_fw_cb->ipv6_addtl_opts &=
2115 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2116 break;
2117 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2118 if (iface_param->iface_num & 0x1)
2119 break;
2120 init_fw_cb->ipv6_flow_lbl =
2121 cpu_to_le16(*(uint16_t *)iface_param->value);
2122 break;
2123 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2124 if (iface_param->iface_num & 0x1)
2125 break;
2126 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2127 break;
2128 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2129 if (iface_param->iface_num & 0x1)
2130 break;
2131 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2132 break;
2133 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2134 if (iface_param->iface_num & 0x1)
2135 break;
2136 init_fw_cb->ipv6_nd_reach_time =
2137 cpu_to_le32(*(uint32_t *)iface_param->value);
2138 break;
2139 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2140 if (iface_param->iface_num & 0x1)
2141 break;
2142 init_fw_cb->ipv6_nd_rexmit_timer =
2143 cpu_to_le32(*(uint32_t *)iface_param->value);
2144 break;
2145 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2146 if (iface_param->iface_num & 0x1)
2147 break;
2148 init_fw_cb->ipv6_nd_stale_timeout =
2149 cpu_to_le32(*(uint32_t *)iface_param->value);
2150 break;
2151 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2152 if (iface_param->iface_num & 0x1)
2153 break;
2154 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2155 break;
2156 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2157 if (iface_param->iface_num & 0x1)
2158 break;
2159 init_fw_cb->ipv6_gw_advrt_mtu =
2160 cpu_to_le32(*(uint32_t *)iface_param->value);
2161 break;
Mike Christied00efe32011-07-25 13:48:38 -05002162 default:
2163 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2164 iface_param->param);
2165 break;
2166 }
2167}
2168
2169static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2170 struct iscsi_iface_param_info *iface_param,
2171 struct addr_ctrl_blk *init_fw_cb)
2172{
2173 switch (iface_param->param) {
2174 case ISCSI_NET_PARAM_IPV4_ADDR:
2175 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2176 sizeof(init_fw_cb->ipv4_addr));
2177 break;
2178 case ISCSI_NET_PARAM_IPV4_SUBNET:
2179 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2180 sizeof(init_fw_cb->ipv4_subnet));
2181 break;
2182 case ISCSI_NET_PARAM_IPV4_GW:
2183 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2184 sizeof(init_fw_cb->ipv4_gw_addr));
2185 break;
2186 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2187 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2188 init_fw_cb->ipv4_tcp_opts |=
2189 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2190 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2191 init_fw_cb->ipv4_tcp_opts &=
2192 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2193 else
2194 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2195 break;
2196 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002197 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -05002198 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05002199 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002200 qla4xxx_create_ipv4_iface(ha);
2201 } else {
Mike Christied00efe32011-07-25 13:48:38 -05002202 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -05002203 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -05002204 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002205 qla4xxx_destroy_ipv4_iface(ha);
2206 }
Mike Christied00efe32011-07-25 13:48:38 -05002207 break;
Mike Christie2d636732011-10-11 17:55:11 -05002208 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -05002209 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2210 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -05002211 init_fw_cb->ipv4_vlan_tag =
2212 cpu_to_be16(*(uint16_t *)iface_param->value);
2213 break;
2214 case ISCSI_NET_PARAM_VLAN_ENABLED:
2215 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2216 init_fw_cb->ipv4_ip_opts |=
2217 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2218 else
2219 init_fw_cb->ipv4_ip_opts &=
2220 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -05002221 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -07002222 case ISCSI_NET_PARAM_MTU:
2223 init_fw_cb->eth_mtu_size =
2224 cpu_to_le16(*(uint16_t *)iface_param->value);
2225 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -07002226 case ISCSI_NET_PARAM_PORT:
2227 init_fw_cb->ipv4_port =
2228 cpu_to_le16(*(uint16_t *)iface_param->value);
2229 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002230 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2231 if (iface_param->iface_num & 0x1)
2232 break;
2233 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2234 init_fw_cb->ipv4_tcp_opts |=
2235 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2236 else
2237 init_fw_cb->ipv4_tcp_opts &=
2238 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE);
2239 break;
2240 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2241 if (iface_param->iface_num & 0x1)
2242 break;
2243 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2244 init_fw_cb->ipv4_tcp_opts |=
2245 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2246 else
2247 init_fw_cb->ipv4_tcp_opts &=
2248 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2249 break;
2250 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2251 if (iface_param->iface_num & 0x1)
2252 break;
2253 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2254 init_fw_cb->ipv4_tcp_opts |=
2255 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2256 else
2257 init_fw_cb->ipv4_tcp_opts &=
2258 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2259 break;
2260 case ISCSI_NET_PARAM_TCP_WSF:
2261 if (iface_param->iface_num & 0x1)
2262 break;
2263 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2264 break;
2265 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2266 if (iface_param->iface_num & 0x1)
2267 break;
2268 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2269 init_fw_cb->ipv4_tcp_opts |=
2270 cpu_to_le16((iface_param->value[0] << 1) &
2271 TCPOPT_TIMER_SCALE);
2272 break;
2273 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2274 if (iface_param->iface_num & 0x1)
2275 break;
2276 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2277 init_fw_cb->ipv4_tcp_opts |=
2278 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2279 else
2280 init_fw_cb->ipv4_tcp_opts &=
2281 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2282 break;
2283 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2284 if (iface_param->iface_num & 0x1)
2285 break;
2286 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2287 init_fw_cb->ipv4_tcp_opts |=
2288 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2289 else
2290 init_fw_cb->ipv4_tcp_opts &=
2291 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2292 break;
2293 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2294 if (iface_param->iface_num & 0x1)
2295 break;
2296 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2297 init_fw_cb->ipv4_tcp_opts |=
2298 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2299 else
2300 init_fw_cb->ipv4_tcp_opts &=
2301 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2302 break;
2303 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2304 if (iface_param->iface_num & 0x1)
2305 break;
2306 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2307 init_fw_cb->ipv4_ip_opts |=
2308 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2309 else
2310 init_fw_cb->ipv4_ip_opts &=
2311 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2312 break;
2313 case ISCSI_NET_PARAM_IPV4_TOS:
2314 if (iface_param->iface_num & 0x1)
2315 break;
2316 init_fw_cb->ipv4_tos = iface_param->value[0];
2317 break;
2318 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2319 if (iface_param->iface_num & 0x1)
2320 break;
2321 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2322 init_fw_cb->ipv4_ip_opts |=
2323 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2324 else
2325 init_fw_cb->ipv4_ip_opts &=
2326 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2327 break;
2328 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2329 if (iface_param->iface_num & 0x1)
2330 break;
2331 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2332 init_fw_cb->ipv4_ip_opts |=
2333 cpu_to_le16(IPOPT_ALT_CID_EN);
2334 else
2335 init_fw_cb->ipv4_ip_opts &=
2336 cpu_to_le16(~IPOPT_ALT_CID_EN);
2337 break;
2338 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2339 if (iface_param->iface_num & 0x1)
2340 break;
2341 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2342 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2343 init_fw_cb->ipv4_dhcp_alt_cid_len =
2344 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2345 break;
2346 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2347 if (iface_param->iface_num & 0x1)
2348 break;
2349 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2350 init_fw_cb->ipv4_ip_opts |=
2351 cpu_to_le16(IPOPT_REQ_VID_EN);
2352 else
2353 init_fw_cb->ipv4_ip_opts &=
2354 cpu_to_le16(~IPOPT_REQ_VID_EN);
2355 break;
2356 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2357 if (iface_param->iface_num & 0x1)
2358 break;
2359 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2360 init_fw_cb->ipv4_ip_opts |=
2361 cpu_to_le16(IPOPT_USE_VID_EN);
2362 else
2363 init_fw_cb->ipv4_ip_opts &=
2364 cpu_to_le16(~IPOPT_USE_VID_EN);
2365 break;
2366 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2367 if (iface_param->iface_num & 0x1)
2368 break;
2369 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2370 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2371 init_fw_cb->ipv4_dhcp_vid_len =
2372 strlen(init_fw_cb->ipv4_dhcp_vid);
2373 break;
2374 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2375 if (iface_param->iface_num & 0x1)
2376 break;
2377 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2378 init_fw_cb->ipv4_ip_opts |=
2379 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2380 else
2381 init_fw_cb->ipv4_ip_opts &=
2382 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2383 break;
2384 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2385 if (iface_param->iface_num & 0x1)
2386 break;
2387 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2388 init_fw_cb->ipv4_ip_opts |=
2389 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2390 else
2391 init_fw_cb->ipv4_ip_opts &=
2392 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2393 break;
2394 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2395 if (iface_param->iface_num & 0x1)
2396 break;
2397 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2398 init_fw_cb->ipv4_ip_opts |=
2399 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2400 else
2401 init_fw_cb->ipv4_ip_opts &=
2402 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2403 break;
2404 case ISCSI_NET_PARAM_REDIRECT_EN:
2405 if (iface_param->iface_num & 0x1)
2406 break;
2407 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2408 init_fw_cb->ipv4_ip_opts |=
2409 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2410 else
2411 init_fw_cb->ipv4_ip_opts &=
2412 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2413 break;
2414 case ISCSI_NET_PARAM_IPV4_TTL:
2415 if (iface_param->iface_num & 0x1)
2416 break;
2417 init_fw_cb->ipv4_ttl = iface_param->value[0];
2418 break;
Mike Christied00efe32011-07-25 13:48:38 -05002419 default:
2420 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2421 iface_param->param);
2422 break;
2423 }
2424}
2425
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002426static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2427 struct iscsi_iface_param_info *iface_param,
2428 struct addr_ctrl_blk *init_fw_cb)
2429{
2430 switch (iface_param->param) {
2431 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2432 if (iface_param->iface_num & 0x1)
2433 break;
2434 init_fw_cb->def_timeout =
2435 cpu_to_le16(*(uint16_t *)iface_param->value);
2436 break;
2437 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2438 if (iface_param->iface_num & 0x1)
2439 break;
2440 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2441 init_fw_cb->iscsi_opts |=
2442 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2443 else
2444 init_fw_cb->iscsi_opts &=
2445 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2446 break;
2447 case ISCSI_IFACE_PARAM_DATADGST_EN:
2448 if (iface_param->iface_num & 0x1)
2449 break;
2450 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2451 init_fw_cb->iscsi_opts |=
2452 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2453 else
2454 init_fw_cb->iscsi_opts &=
2455 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2456 break;
2457 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2458 if (iface_param->iface_num & 0x1)
2459 break;
2460 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2461 init_fw_cb->iscsi_opts |=
2462 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2463 else
2464 init_fw_cb->iscsi_opts &=
2465 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2466 break;
2467 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2468 if (iface_param->iface_num & 0x1)
2469 break;
2470 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2471 init_fw_cb->iscsi_opts |=
2472 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2473 else
2474 init_fw_cb->iscsi_opts &=
2475 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2476 break;
2477 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2478 if (iface_param->iface_num & 0x1)
2479 break;
2480 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2481 init_fw_cb->iscsi_opts |=
2482 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2483 else
2484 init_fw_cb->iscsi_opts &=
2485 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2486 break;
2487 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2488 if (iface_param->iface_num & 0x1)
2489 break;
2490 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2491 init_fw_cb->iscsi_opts |=
2492 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2493 else
2494 init_fw_cb->iscsi_opts &=
2495 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2496 break;
2497 case ISCSI_IFACE_PARAM_ERL:
2498 if (iface_param->iface_num & 0x1)
2499 break;
2500 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2501 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2502 ISCSIOPTS_ERL);
2503 break;
2504 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2505 if (iface_param->iface_num & 0x1)
2506 break;
2507 init_fw_cb->iscsi_max_pdu_size =
2508 cpu_to_le32(*(uint32_t *)iface_param->value) /
2509 BYTE_UNITS;
2510 break;
2511 case ISCSI_IFACE_PARAM_FIRST_BURST:
2512 if (iface_param->iface_num & 0x1)
2513 break;
2514 init_fw_cb->iscsi_fburst_len =
2515 cpu_to_le32(*(uint32_t *)iface_param->value) /
2516 BYTE_UNITS;
2517 break;
2518 case ISCSI_IFACE_PARAM_MAX_R2T:
2519 if (iface_param->iface_num & 0x1)
2520 break;
2521 init_fw_cb->iscsi_max_outstnd_r2t =
2522 cpu_to_le16(*(uint16_t *)iface_param->value);
2523 break;
2524 case ISCSI_IFACE_PARAM_MAX_BURST:
2525 if (iface_param->iface_num & 0x1)
2526 break;
2527 init_fw_cb->iscsi_max_burst_len =
2528 cpu_to_le32(*(uint32_t *)iface_param->value) /
2529 BYTE_UNITS;
2530 break;
2531 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2532 if (iface_param->iface_num & 0x1)
2533 break;
2534 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2535 init_fw_cb->iscsi_opts |=
2536 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2537 else
2538 init_fw_cb->iscsi_opts &=
2539 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2540 break;
2541 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2542 if (iface_param->iface_num & 0x1)
2543 break;
2544 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2545 init_fw_cb->iscsi_opts |=
2546 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2547 else
2548 init_fw_cb->iscsi_opts &=
2549 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2550 break;
2551 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2552 if (iface_param->iface_num & 0x1)
2553 break;
2554 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2555 init_fw_cb->iscsi_opts |=
2556 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2557 else
2558 init_fw_cb->iscsi_opts &=
2559 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2560 break;
2561 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2562 if (iface_param->iface_num & 0x1)
2563 break;
2564 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2565 init_fw_cb->iscsi_opts |=
2566 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2567 else
2568 init_fw_cb->iscsi_opts &=
2569 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2570 break;
2571 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2572 if (iface_param->iface_num & 0x1)
2573 break;
2574 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2575 init_fw_cb->iscsi_opts |=
2576 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2577 else
2578 init_fw_cb->iscsi_opts &=
2579 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2580 break;
2581 default:
2582 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2583 iface_param->param);
2584 break;
2585 }
2586}
2587
Mike Christied00efe32011-07-25 13:48:38 -05002588static void
2589qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2590{
2591 struct addr_ctrl_blk_def *acb;
2592 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2593 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2594 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2595 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2596 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2597 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2598 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2599 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2600 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2601 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2602 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2603 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2604 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2605 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2606 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2607 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2608}
2609
2610static int
Mike Christie00c31882011-10-06 03:56:59 -05002611qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -05002612{
2613 struct scsi_qla_host *ha = to_qla_host(shost);
2614 int rval = 0;
2615 struct iscsi_iface_param_info *iface_param = NULL;
2616 struct addr_ctrl_blk *init_fw_cb = NULL;
2617 dma_addr_t init_fw_cb_dma;
2618 uint32_t mbox_cmd[MBOX_REG_COUNT];
2619 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christie00c31882011-10-06 03:56:59 -05002620 uint32_t rem = len;
2621 struct nlattr *attr;
Mike Christied00efe32011-07-25 13:48:38 -05002622
2623 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2624 sizeof(struct addr_ctrl_blk),
2625 &init_fw_cb_dma, GFP_KERNEL);
2626 if (!init_fw_cb) {
2627 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2628 __func__);
2629 return -ENOMEM;
2630 }
2631
2632 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2633 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2634 memset(&mbox_sts, 0, sizeof(mbox_sts));
2635
2636 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2637 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2638 rval = -EIO;
2639 goto exit_init_fw_cb;
2640 }
2641
Mike Christie00c31882011-10-06 03:56:59 -05002642 nla_for_each_attr(attr, data, len, rem) {
2643 iface_param = nla_data(attr);
Mike Christied00efe32011-07-25 13:48:38 -05002644
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002645 if (iface_param->param_type == ISCSI_NET_PARAM) {
2646 switch (iface_param->iface_type) {
2647 case ISCSI_IFACE_TYPE_IPV4:
2648 switch (iface_param->iface_num) {
2649 case 0:
2650 qla4xxx_set_ipv4(ha, iface_param,
2651 init_fw_cb);
2652 break;
2653 default:
Mike Christied00efe32011-07-25 13:48:38 -05002654 /* Cannot have more than one IPv4 interface */
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002655 ql4_printk(KERN_ERR, ha,
2656 "Invalid IPv4 iface number = %d\n",
2657 iface_param->iface_num);
2658 break;
2659 }
Mike Christied00efe32011-07-25 13:48:38 -05002660 break;
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002661 case ISCSI_IFACE_TYPE_IPV6:
2662 switch (iface_param->iface_num) {
2663 case 0:
2664 case 1:
2665 qla4xxx_set_ipv6(ha, iface_param,
2666 init_fw_cb);
2667 break;
2668 default:
2669 /* Cannot have more than two IPv6 interface */
2670 ql4_printk(KERN_ERR, ha,
2671 "Invalid IPv6 iface number = %d\n",
2672 iface_param->iface_num);
2673 break;
2674 }
Mike Christied00efe32011-07-25 13:48:38 -05002675 break;
2676 default:
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002677 ql4_printk(KERN_ERR, ha,
2678 "Invalid iface type\n");
Mike Christied00efe32011-07-25 13:48:38 -05002679 break;
2680 }
Harish Zunjarraof8e93412013-10-18 09:01:42 -04002681 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2682 qla4xxx_set_iscsi_param(ha, iface_param,
2683 init_fw_cb);
2684 } else {
2685 continue;
Mike Christied00efe32011-07-25 13:48:38 -05002686 }
Mike Christied00efe32011-07-25 13:48:38 -05002687 }
2688
2689 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2690
2691 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2692 sizeof(struct addr_ctrl_blk),
2693 FLASH_OPT_RMW_COMMIT);
2694 if (rval != QLA_SUCCESS) {
2695 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2696 __func__);
2697 rval = -EIO;
2698 goto exit_init_fw_cb;
2699 }
2700
Vikas Chaudharyce505f92011-12-01 22:42:10 -08002701 rval = qla4xxx_disable_acb(ha);
2702 if (rval != QLA_SUCCESS) {
2703 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2704 __func__);
2705 rval = -EIO;
2706 goto exit_init_fw_cb;
2707 }
2708
2709 wait_for_completion_timeout(&ha->disable_acb_comp,
2710 DISABLE_ACB_TOV * HZ);
Mike Christied00efe32011-07-25 13:48:38 -05002711
2712 qla4xxx_initcb_to_acb(init_fw_cb);
2713
2714 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2715 if (rval != QLA_SUCCESS) {
2716 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2717 __func__);
2718 rval = -EIO;
2719 goto exit_init_fw_cb;
2720 }
2721
2722 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2723 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2724 init_fw_cb_dma);
2725
2726exit_init_fw_cb:
2727 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2728 init_fw_cb, init_fw_cb_dma);
2729
2730 return rval;
2731}
2732
Mike Christiefca9f042012-02-27 03:08:54 -08002733static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2734 enum iscsi_param param, char *buf)
2735{
2736 struct iscsi_session *sess = cls_sess->dd_data;
2737 struct ddb_entry *ddb_entry = sess->dd_data;
2738 struct scsi_qla_host *ha = ddb_entry->ha;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002739 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2740 struct ql4_chap_table chap_tbl;
Mike Christiefca9f042012-02-27 03:08:54 -08002741 int rval, len;
2742 uint16_t idx;
2743
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002744 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christiefca9f042012-02-27 03:08:54 -08002745 switch (param) {
2746 case ISCSI_PARAM_CHAP_IN_IDX:
2747 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2748 sess->password_in, BIDI_CHAP,
2749 &idx);
2750 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002751 len = sprintf(buf, "\n");
2752 else
2753 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002754 break;
2755 case ISCSI_PARAM_CHAP_OUT_IDX:
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002756 if (ddb_entry->ddb_type == FLASH_DDB) {
2757 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2758 idx = ddb_entry->chap_tbl_idx;
2759 rval = QLA_SUCCESS;
2760 } else {
2761 rval = QLA_ERROR;
2762 }
2763 } else {
2764 rval = qla4xxx_get_chap_index(ha, sess->username,
2765 sess->password,
2766 LOCAL_CHAP, &idx);
2767 }
Mike Christiefca9f042012-02-27 03:08:54 -08002768 if (rval)
Manish Rangankarc7a5e0d2013-01-20 23:51:04 -05002769 len = sprintf(buf, "\n");
2770 else
2771 len = sprintf(buf, "%hu\n", idx);
Mike Christiefca9f042012-02-27 03:08:54 -08002772 break;
Adheer Chandravanshi97c27302013-09-17 07:54:50 -04002773 case ISCSI_PARAM_USERNAME:
2774 case ISCSI_PARAM_PASSWORD:
2775 /* First, populate session username and password for FLASH DDB,
2776 * if not already done. This happens when session login fails
2777 * for a FLASH DDB.
2778 */
2779 if (ddb_entry->ddb_type == FLASH_DDB &&
2780 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2781 !sess->username && !sess->password) {
2782 idx = ddb_entry->chap_tbl_idx;
2783 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2784 chap_tbl.secret,
2785 idx);
2786 if (!rval) {
2787 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2788 (char *)chap_tbl.name,
2789 strlen((char *)chap_tbl.name));
2790 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2791 (char *)chap_tbl.secret,
2792 chap_tbl.secret_len);
2793 }
2794 }
2795 /* allow fall-through */
Mike Christiefca9f042012-02-27 03:08:54 -08002796 default:
2797 return iscsi_session_get_param(cls_sess, param, buf);
2798 }
2799
2800 return len;
2801}
2802
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002803static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002804 enum iscsi_param param, char *buf)
2805{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002806 struct iscsi_conn *conn;
2807 struct qla_conn *qla_conn;
2808 struct sockaddr *dst_addr;
2809 int len = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002810
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002811 conn = cls_conn->dd_data;
2812 qla_conn = conn->dd_data;
Manish Rangankard46bdeb12012-08-07 07:57:13 -04002813 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002814
2815 switch (param) {
2816 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002817 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002818 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2819 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002820 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002821 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002822 }
2823
2824 return len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002825
David Somayajuluafaf5a22006-09-19 10:28:00 -07002826}
2827
Mike Christie13483732011-12-01 21:38:41 -06002828int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2829{
2830 uint32_t mbx_sts = 0;
2831 uint16_t tmp_ddb_index;
2832 int ret;
2833
2834get_ddb_index:
2835 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2836
2837 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2838 DEBUG2(ql4_printk(KERN_INFO, ha,
2839 "Free DDB index not available\n"));
2840 ret = QLA_ERROR;
2841 goto exit_get_ddb_index;
2842 }
2843
2844 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2845 goto get_ddb_index;
2846
2847 DEBUG2(ql4_printk(KERN_INFO, ha,
2848 "Found a free DDB index at %d\n", tmp_ddb_index));
2849 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2850 if (ret == QLA_ERROR) {
2851 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2852 ql4_printk(KERN_INFO, ha,
2853 "DDB index = %d not available trying next\n",
2854 tmp_ddb_index);
2855 goto get_ddb_index;
2856 }
2857 DEBUG2(ql4_printk(KERN_INFO, ha,
2858 "Free FW DDB not available\n"));
2859 }
2860
2861 *ddb_index = tmp_ddb_index;
2862
2863exit_get_ddb_index:
2864 return ret;
2865}
2866
2867static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2868 struct ddb_entry *ddb_entry,
2869 char *existing_ipaddr,
2870 char *user_ipaddr)
2871{
2872 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2873 char formatted_ipaddr[DDB_IPADDR_LEN];
2874 int status = QLA_SUCCESS, ret = 0;
2875
2876 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2877 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2878 '\0', NULL);
2879 if (ret == 0) {
2880 status = QLA_ERROR;
2881 goto out_match;
2882 }
2883 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2884 } else {
2885 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2886 '\0', NULL);
2887 if (ret == 0) {
2888 status = QLA_ERROR;
2889 goto out_match;
2890 }
2891 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2892 }
2893
2894 if (strcmp(existing_ipaddr, formatted_ipaddr))
2895 status = QLA_ERROR;
2896
2897out_match:
2898 return status;
2899}
2900
2901static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2902 struct iscsi_cls_conn *cls_conn)
2903{
2904 int idx = 0, max_ddbs, rval;
2905 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2906 struct iscsi_session *sess, *existing_sess;
2907 struct iscsi_conn *conn, *existing_conn;
2908 struct ddb_entry *ddb_entry;
2909
2910 sess = cls_sess->dd_data;
2911 conn = cls_conn->dd_data;
2912
2913 if (sess->targetname == NULL ||
2914 conn->persistent_address == NULL ||
2915 conn->persistent_port == 0)
2916 return QLA_ERROR;
2917
2918 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
2919 MAX_DEV_DB_ENTRIES;
2920
2921 for (idx = 0; idx < max_ddbs; idx++) {
2922 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
2923 if (ddb_entry == NULL)
2924 continue;
2925
2926 if (ddb_entry->ddb_type != FLASH_DDB)
2927 continue;
2928
2929 existing_sess = ddb_entry->sess->dd_data;
2930 existing_conn = ddb_entry->conn->dd_data;
2931
2932 if (existing_sess->targetname == NULL ||
2933 existing_conn->persistent_address == NULL ||
2934 existing_conn->persistent_port == 0)
2935 continue;
2936
2937 DEBUG2(ql4_printk(KERN_INFO, ha,
2938 "IQN = %s User IQN = %s\n",
2939 existing_sess->targetname,
2940 sess->targetname));
2941
2942 DEBUG2(ql4_printk(KERN_INFO, ha,
2943 "IP = %s User IP = %s\n",
2944 existing_conn->persistent_address,
2945 conn->persistent_address));
2946
2947 DEBUG2(ql4_printk(KERN_INFO, ha,
2948 "Port = %d User Port = %d\n",
2949 existing_conn->persistent_port,
2950 conn->persistent_port));
2951
2952 if (strcmp(existing_sess->targetname, sess->targetname))
2953 continue;
2954 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
2955 existing_conn->persistent_address,
2956 conn->persistent_address);
2957 if (rval == QLA_ERROR)
2958 continue;
2959 if (existing_conn->persistent_port != conn->persistent_port)
2960 continue;
2961 break;
2962 }
2963
2964 if (idx == max_ddbs)
2965 return QLA_ERROR;
2966
2967 DEBUG2(ql4_printk(KERN_INFO, ha,
2968 "Match found in fwdb sessions\n"));
2969 return QLA_SUCCESS;
2970}
2971
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002972static struct iscsi_cls_session *
2973qla4xxx_session_create(struct iscsi_endpoint *ep,
2974 uint16_t cmds_max, uint16_t qdepth,
2975 uint32_t initial_cmdsn)
2976{
2977 struct iscsi_cls_session *cls_sess;
2978 struct scsi_qla_host *ha;
2979 struct qla_endpoint *qla_ep;
2980 struct ddb_entry *ddb_entry;
Mike Christie13483732011-12-01 21:38:41 -06002981 uint16_t ddb_index;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002982 struct iscsi_session *sess;
2983 struct sockaddr *dst_addr;
2984 int ret;
2985
2986 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
2987 if (!ep) {
2988 printk(KERN_ERR "qla4xxx: missing ep.\n");
2989 return NULL;
2990 }
2991
2992 qla_ep = ep->dd_data;
2993 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
2994 ha = to_qla_host(qla_ep->host);
Manish Rangankar736cf362011-10-07 16:55:46 -07002995
Mike Christie13483732011-12-01 21:38:41 -06002996 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
2997 if (ret == QLA_ERROR)
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002998 return NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002999
3000 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3001 cmds_max, sizeof(struct ddb_entry),
3002 sizeof(struct ql4_task_data),
3003 initial_cmdsn, ddb_index);
3004 if (!cls_sess)
3005 return NULL;
3006
3007 sess = cls_sess->dd_data;
3008 ddb_entry = sess->dd_data;
3009 ddb_entry->fw_ddb_index = ddb_index;
3010 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3011 ddb_entry->ha = ha;
3012 ddb_entry->sess = cls_sess;
Mike Christie13483732011-12-01 21:38:41 -06003013 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3014 ddb_entry->ddb_change = qla4xxx_ddb_change;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003015 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3016 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3017 ha->tot_ddbs++;
3018
3019 return cls_sess;
3020}
3021
3022static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3023{
3024 struct iscsi_session *sess;
3025 struct ddb_entry *ddb_entry;
3026 struct scsi_qla_host *ha;
Manish Rangankar90599b62012-04-23 22:32:34 -07003027 unsigned long flags, wtime;
3028 struct dev_db_entry *fw_ddb_entry = NULL;
3029 dma_addr_t fw_ddb_entry_dma;
3030 uint32_t ddb_state;
3031 int ret;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003032
3033 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3034 sess = cls_sess->dd_data;
3035 ddb_entry = sess->dd_data;
3036 ha = ddb_entry->ha;
3037
Manish Rangankar90599b62012-04-23 22:32:34 -07003038 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3039 &fw_ddb_entry_dma, GFP_KERNEL);
3040 if (!fw_ddb_entry) {
3041 ql4_printk(KERN_ERR, ha,
3042 "%s: Unable to allocate dma buffer\n", __func__);
3043 goto destroy_session;
3044 }
3045
3046 wtime = jiffies + (HZ * LOGOUT_TOV);
3047 do {
3048 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3049 fw_ddb_entry, fw_ddb_entry_dma,
3050 NULL, NULL, &ddb_state, NULL,
3051 NULL, NULL);
3052 if (ret == QLA_ERROR)
3053 goto destroy_session;
3054
3055 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3056 (ddb_state == DDB_DS_SESSION_FAILED))
3057 goto destroy_session;
3058
3059 schedule_timeout_uninterruptible(HZ);
3060 } while ((time_after(wtime, jiffies)));
3061
3062destroy_session:
Manish Rangankar736cf362011-10-07 16:55:46 -07003063 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3064
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003065 spin_lock_irqsave(&ha->hardware_lock, flags);
3066 qla4xxx_free_ddb(ha, ddb_entry);
3067 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Manish Rangankar90599b62012-04-23 22:32:34 -07003068
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003069 iscsi_session_teardown(cls_sess);
Manish Rangankar90599b62012-04-23 22:32:34 -07003070
3071 if (fw_ddb_entry)
3072 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3073 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003074}
3075
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003076static struct iscsi_cls_conn *
3077qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3078{
3079 struct iscsi_cls_conn *cls_conn;
3080 struct iscsi_session *sess;
3081 struct ddb_entry *ddb_entry;
3082
3083 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3084 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3085 conn_idx);
Mike Christieff1d0312011-12-01 21:38:43 -06003086 if (!cls_conn)
3087 return NULL;
3088
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003089 sess = cls_sess->dd_data;
3090 ddb_entry = sess->dd_data;
3091 ddb_entry->conn = cls_conn;
3092
3093 return cls_conn;
3094}
3095
3096static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3097 struct iscsi_cls_conn *cls_conn,
3098 uint64_t transport_fd, int is_leading)
3099{
3100 struct iscsi_conn *conn;
3101 struct qla_conn *qla_conn;
3102 struct iscsi_endpoint *ep;
3103
3104 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3105
3106 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3107 return -EINVAL;
3108 ep = iscsi_lookup_endpoint(transport_fd);
3109 conn = cls_conn->dd_data;
3110 qla_conn = conn->dd_data;
3111 qla_conn->qla_ep = ep->dd_data;
3112 return 0;
3113}
3114
3115static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3116{
3117 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3118 struct iscsi_session *sess;
3119 struct ddb_entry *ddb_entry;
3120 struct scsi_qla_host *ha;
Mike Christie13483732011-12-01 21:38:41 -06003121 struct dev_db_entry *fw_ddb_entry = NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003122 dma_addr_t fw_ddb_entry_dma;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003123 uint32_t mbx_sts = 0;
3124 int ret = 0;
3125 int status = QLA_SUCCESS;
3126
3127 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3128 sess = cls_sess->dd_data;
3129 ddb_entry = sess->dd_data;
3130 ha = ddb_entry->ha;
3131
Mike Christie13483732011-12-01 21:38:41 -06003132 /* Check if we have matching FW DDB, if yes then do not
3133 * login to this target. This could cause target to logout previous
3134 * connection
3135 */
3136 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3137 if (ret == QLA_SUCCESS) {
3138 ql4_printk(KERN_INFO, ha,
3139 "Session already exist in FW.\n");
3140 ret = -EEXIST;
3141 goto exit_conn_start;
3142 }
3143
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003144 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3145 &fw_ddb_entry_dma, GFP_KERNEL);
3146 if (!fw_ddb_entry) {
3147 ql4_printk(KERN_ERR, ha,
3148 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003149 ret = -ENOMEM;
3150 goto exit_conn_start;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003151 }
3152
3153 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3154 if (ret) {
3155 /* If iscsid is stopped and started then no need to do
3156 * set param again since ddb state will be already
3157 * active and FW does not allow set ddb to an
3158 * active session.
3159 */
3160 if (mbx_sts)
3161 if (ddb_entry->fw_ddb_device_state ==
Manish Rangankarf922da72011-10-07 16:55:49 -07003162 DDB_DS_SESSION_ACTIVE) {
Mike Christie13483732011-12-01 21:38:41 -06003163 ddb_entry->unblock_sess(ddb_entry->sess);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003164 goto exit_set_param;
Manish Rangankarf922da72011-10-07 16:55:49 -07003165 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003166
3167 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3168 __func__, ddb_entry->fw_ddb_index);
3169 goto exit_conn_start;
3170 }
3171
3172 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3173 if (status == QLA_ERROR) {
Manish Rangankar0e7e8502011-07-25 13:48:54 -05003174 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3175 sess->targetname);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003176 ret = -EINVAL;
3177 goto exit_conn_start;
3178 }
3179
Manish Rangankar98270ab2011-10-07 16:55:47 -07003180 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3181 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3182
3183 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3184 ddb_entry->fw_ddb_device_state));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003185
3186exit_set_param:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003187 ret = 0;
3188
3189exit_conn_start:
Mike Christie13483732011-12-01 21:38:41 -06003190 if (fw_ddb_entry)
3191 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3192 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003193 return ret;
3194}
3195
3196static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3197{
3198 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3199 struct iscsi_session *sess;
3200 struct scsi_qla_host *ha;
3201 struct ddb_entry *ddb_entry;
3202 int options;
3203
3204 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3205 sess = cls_sess->dd_data;
3206 ddb_entry = sess->dd_data;
3207 ha = ddb_entry->ha;
3208
3209 options = LOGOUT_OPTION_CLOSE_SESSION;
3210 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3211 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003212}
3213
3214static void qla4xxx_task_work(struct work_struct *wdata)
3215{
3216 struct ql4_task_data *task_data;
3217 struct scsi_qla_host *ha;
3218 struct passthru_status *sts;
3219 struct iscsi_task *task;
3220 struct iscsi_hdr *hdr;
3221 uint8_t *data;
3222 uint32_t data_len;
3223 struct iscsi_conn *conn;
3224 int hdr_len;
3225 itt_t itt;
3226
3227 task_data = container_of(wdata, struct ql4_task_data, task_work);
3228 ha = task_data->ha;
3229 task = task_data->task;
3230 sts = &task_data->sts;
3231 hdr_len = sizeof(struct iscsi_hdr);
3232
3233 DEBUG3(printk(KERN_INFO "Status returned\n"));
3234 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3235 DEBUG3(printk(KERN_INFO "Response buffer"));
3236 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3237
3238 conn = task->conn;
3239
3240 switch (sts->completionStatus) {
3241 case PASSTHRU_STATUS_COMPLETE:
3242 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3243 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3244 itt = sts->handle;
3245 hdr->itt = itt;
3246 data = task_data->resp_buffer + hdr_len;
3247 data_len = task_data->resp_len - hdr_len;
3248 iscsi_complete_pdu(conn, hdr, data, data_len);
3249 break;
3250 default:
3251 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3252 sts->completionStatus);
3253 break;
3254 }
3255 return;
3256}
3257
3258static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3259{
3260 struct ql4_task_data *task_data;
3261 struct iscsi_session *sess;
3262 struct ddb_entry *ddb_entry;
3263 struct scsi_qla_host *ha;
3264 int hdr_len;
3265
3266 sess = task->conn->session;
3267 ddb_entry = sess->dd_data;
3268 ha = ddb_entry->ha;
3269 task_data = task->dd_data;
3270 memset(task_data, 0, sizeof(struct ql4_task_data));
3271
3272 if (task->sc) {
3273 ql4_printk(KERN_INFO, ha,
3274 "%s: SCSI Commands not implemented\n", __func__);
3275 return -EINVAL;
3276 }
3277
3278 hdr_len = sizeof(struct iscsi_hdr);
3279 task_data->ha = ha;
3280 task_data->task = task;
3281
3282 if (task->data_count) {
3283 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3284 task->data_count,
3285 PCI_DMA_TODEVICE);
3286 }
3287
3288 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3289 __func__, task->conn->max_recv_dlength, hdr_len));
3290
Manish Rangankar69ca2162011-10-07 16:55:50 -07003291 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003292 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3293 task_data->resp_len,
3294 &task_data->resp_dma,
3295 GFP_ATOMIC);
3296 if (!task_data->resp_buffer)
3297 goto exit_alloc_pdu;
3298
Manish Rangankar69ca2162011-10-07 16:55:50 -07003299 task_data->req_len = task->data_count + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003300 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
Manish Rangankar69ca2162011-10-07 16:55:50 -07003301 task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003302 &task_data->req_dma,
3303 GFP_ATOMIC);
3304 if (!task_data->req_buffer)
3305 goto exit_alloc_pdu;
3306
3307 task->hdr = task_data->req_buffer;
3308
3309 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3310
3311 return 0;
3312
3313exit_alloc_pdu:
3314 if (task_data->resp_buffer)
3315 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3316 task_data->resp_buffer, task_data->resp_dma);
3317
3318 if (task_data->req_buffer)
Manish Rangankar69ca2162011-10-07 16:55:50 -07003319 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003320 task_data->req_buffer, task_data->req_dma);
3321 return -ENOMEM;
3322}
3323
3324static void qla4xxx_task_cleanup(struct iscsi_task *task)
3325{
3326 struct ql4_task_data *task_data;
3327 struct iscsi_session *sess;
3328 struct ddb_entry *ddb_entry;
3329 struct scsi_qla_host *ha;
3330 int hdr_len;
3331
3332 hdr_len = sizeof(struct iscsi_hdr);
3333 sess = task->conn->session;
3334 ddb_entry = sess->dd_data;
3335 ha = ddb_entry->ha;
3336 task_data = task->dd_data;
3337
3338 if (task->data_count) {
3339 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3340 task->data_count, PCI_DMA_TODEVICE);
3341 }
3342
3343 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3344 __func__, task->conn->max_recv_dlength, hdr_len));
3345
3346 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3347 task_data->resp_buffer, task_data->resp_dma);
Manish Rangankar69ca2162011-10-07 16:55:50 -07003348 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003349 task_data->req_buffer, task_data->req_dma);
3350 return;
3351}
3352
3353static int qla4xxx_task_xmit(struct iscsi_task *task)
3354{
3355 struct scsi_cmnd *sc = task->sc;
3356 struct iscsi_session *sess = task->conn->session;
3357 struct ddb_entry *ddb_entry = sess->dd_data;
3358 struct scsi_qla_host *ha = ddb_entry->ha;
3359
3360 if (!sc)
3361 return qla4xxx_send_passthru0(task);
3362
3363 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3364 __func__);
3365 return -ENOSYS;
3366}
3367
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003368static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3369 struct iscsi_bus_flash_conn *conn,
3370 struct dev_db_entry *fw_ddb_entry)
3371{
3372 unsigned long options = 0;
3373 int rc = 0;
3374
3375 options = le16_to_cpu(fw_ddb_entry->options);
3376 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3377 if (test_bit(OPT_IPV6_DEVICE, &options)) {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003378 rc = iscsi_switch_str_param(&sess->portal_type,
3379 PORTAL_TYPE_IPV6);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003380 if (rc)
3381 goto exit_copy;
3382 } else {
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003383 rc = iscsi_switch_str_param(&sess->portal_type,
3384 PORTAL_TYPE_IPV4);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003385 if (rc)
3386 goto exit_copy;
3387 }
3388
3389 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3390 &options);
3391 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3392 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3393
3394 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3395 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3396 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3397 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3398 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3399 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3400 &options);
3401 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3402 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3403 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3404 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3405 &options);
3406 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3407 sess->discovery_auth_optional =
3408 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3409 if (test_bit(ISCSIOPT_ERL1, &options))
3410 sess->erl |= BIT_1;
3411 if (test_bit(ISCSIOPT_ERL0, &options))
3412 sess->erl |= BIT_0;
3413
3414 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3415 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3416 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3417 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3418 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3419 conn->tcp_timer_scale |= BIT_3;
3420 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3421 conn->tcp_timer_scale |= BIT_2;
3422 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3423 conn->tcp_timer_scale |= BIT_1;
3424
3425 conn->tcp_timer_scale >>= 1;
3426 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3427
3428 options = le16_to_cpu(fw_ddb_entry->ip_options);
3429 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3430
3431 conn->max_recv_dlength = BYTE_UNITS *
3432 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3433 conn->max_xmit_dlength = BYTE_UNITS *
3434 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3435 sess->first_burst = BYTE_UNITS *
3436 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3437 sess->max_burst = BYTE_UNITS *
3438 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3439 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3440 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3441 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3442 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3443 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3444 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3445 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3446 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3447 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3448 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3449 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3450 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3451 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3452 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3453 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3454 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3455
3456 sess->default_taskmgmt_timeout =
3457 le16_to_cpu(fw_ddb_entry->def_timeout);
3458 conn->port = le16_to_cpu(fw_ddb_entry->port);
3459
3460 options = le16_to_cpu(fw_ddb_entry->options);
3461 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3462 if (!conn->ipaddress) {
3463 rc = -ENOMEM;
3464 goto exit_copy;
3465 }
3466
3467 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3468 if (!conn->redirect_ipaddr) {
3469 rc = -ENOMEM;
3470 goto exit_copy;
3471 }
3472
3473 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3474 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3475
3476 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3477 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3478
3479 conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3480 if (!conn->link_local_ipv6_addr) {
3481 rc = -ENOMEM;
3482 goto exit_copy;
3483 }
3484
3485 memcpy(conn->link_local_ipv6_addr,
3486 fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN);
3487 } else {
3488 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3489 }
3490
3491 if (fw_ddb_entry->iscsi_name[0]) {
3492 rc = iscsi_switch_str_param(&sess->targetname,
3493 (char *)fw_ddb_entry->iscsi_name);
3494 if (rc)
3495 goto exit_copy;
3496 }
3497
3498 if (fw_ddb_entry->iscsi_alias[0]) {
3499 rc = iscsi_switch_str_param(&sess->targetalias,
3500 (char *)fw_ddb_entry->iscsi_alias);
3501 if (rc)
3502 goto exit_copy;
3503 }
3504
3505 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3506
3507exit_copy:
3508 return rc;
3509}
3510
3511static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3512 struct iscsi_bus_flash_conn *conn,
3513 struct dev_db_entry *fw_ddb_entry)
3514{
3515 uint16_t options;
3516 int rc = 0;
3517
3518 options = le16_to_cpu(fw_ddb_entry->options);
3519 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
Adheer Chandravanshic962c182013-03-25 08:08:32 -04003520 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003521 options |= BIT_8;
3522 else
3523 options &= ~BIT_8;
3524
3525 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3526 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3527 SET_BITVAL(sess->entry_state, options, BIT_3);
3528 fw_ddb_entry->options = cpu_to_le16(options);
3529
3530 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3531 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3532 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3533 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3534 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3535 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3536 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3537 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3538 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3539 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3540 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3541 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3542 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3543 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3544 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3545
3546 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3547 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3548 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3549 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3550 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3551 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3552 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3553 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3554 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3555
3556 options = le16_to_cpu(fw_ddb_entry->ip_options);
3557 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3558 fw_ddb_entry->ip_options = cpu_to_le16(options);
3559
3560 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3561 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3562 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3563 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3564 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3565 fw_ddb_entry->iscsi_first_burst_len =
3566 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3567 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3568 BYTE_UNITS);
3569 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3570 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3571 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3572 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003573 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3574 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003575 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3576 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3577 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
Adheer Chandravanshifbcd4832013-04-17 05:15:29 -04003578 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3579 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
Adheer Chandravanshi65560162013-07-08 08:33:06 -04003580 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003581 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3582 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3583 fw_ddb_entry->port = cpu_to_le16(conn->port);
3584 fw_ddb_entry->def_timeout =
3585 cpu_to_le16(sess->default_taskmgmt_timeout);
3586
Adheer Chandravanshi84595802013-07-08 08:33:07 -04003587 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3588 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3589 else
3590 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3591
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04003592 if (conn->ipaddress)
3593 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3594 sizeof(fw_ddb_entry->ip_addr));
3595
3596 if (conn->redirect_ipaddr)
3597 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3598 sizeof(fw_ddb_entry->tgt_addr));
3599
3600 if (conn->link_local_ipv6_addr)
3601 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3602 conn->link_local_ipv6_addr,
3603 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3604
3605 if (sess->targetname)
3606 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3607 sizeof(fw_ddb_entry->iscsi_name));
3608
3609 if (sess->targetalias)
3610 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3611 sizeof(fw_ddb_entry->iscsi_alias));
3612
3613 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3614
3615 return rc;
3616}
3617
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003618static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3619 struct iscsi_session *sess,
3620 struct dev_db_entry *fw_ddb_entry)
3621{
3622 unsigned long options = 0;
3623 uint16_t ddb_link;
3624 uint16_t disc_parent;
3625
3626 options = le16_to_cpu(fw_ddb_entry->options);
3627 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3628 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3629 &options);
3630 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3631
3632 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3633 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3634 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3635 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3636 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3637 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3638 &options);
3639 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3640 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3641 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3642 &options);
3643 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3644 sess->discovery_auth_optional =
3645 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3646 if (test_bit(ISCSIOPT_ERL1, &options))
3647 sess->erl |= BIT_1;
3648 if (test_bit(ISCSIOPT_ERL0, &options))
3649 sess->erl |= BIT_0;
3650
3651 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3652 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3653 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3654 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3655 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3656 conn->tcp_timer_scale |= BIT_3;
3657 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3658 conn->tcp_timer_scale |= BIT_2;
3659 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3660 conn->tcp_timer_scale |= BIT_1;
3661
3662 conn->tcp_timer_scale >>= 1;
3663 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3664
3665 options = le16_to_cpu(fw_ddb_entry->ip_options);
3666 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3667
3668 conn->max_recv_dlength = BYTE_UNITS *
3669 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3670 conn->max_xmit_dlength = BYTE_UNITS *
3671 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3672 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3673 sess->first_burst = BYTE_UNITS *
3674 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3675 sess->max_burst = BYTE_UNITS *
3676 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3677 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3678 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3679 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3680 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3681 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3682 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3683 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3684 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3685 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3686 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3687 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3688 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3689 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3690
3691 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003692 if (ddb_link == DDB_ISNS)
3693 disc_parent = ISCSI_DISC_PARENT_ISNS;
3694 else if (ddb_link == DDB_NO_LINK)
3695 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3696 else if (ddb_link < MAX_DDB_ENTRIES)
3697 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3698 else
3699 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3700
3701 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3702 iscsi_get_discovery_parent_name(disc_parent), 0);
3703
3704 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3705 (char *)fw_ddb_entry->iscsi_alias, 0);
3706}
3707
Mike Christie13483732011-12-01 21:38:41 -06003708static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3709 struct dev_db_entry *fw_ddb_entry,
3710 struct iscsi_cls_session *cls_sess,
3711 struct iscsi_cls_conn *cls_conn)
3712{
3713 int buflen = 0;
3714 struct iscsi_session *sess;
Nilesh Javali376738a2012-02-27 03:08:52 -08003715 struct ddb_entry *ddb_entry;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003716 struct ql4_chap_table chap_tbl;
Mike Christie13483732011-12-01 21:38:41 -06003717 struct iscsi_conn *conn;
3718 char ip_addr[DDB_IPADDR_LEN];
3719 uint16_t options = 0;
3720
3721 sess = cls_sess->dd_data;
Nilesh Javali376738a2012-02-27 03:08:52 -08003722 ddb_entry = sess->dd_data;
Mike Christie13483732011-12-01 21:38:41 -06003723 conn = cls_conn->dd_data;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003724 memset(&chap_tbl, 0, sizeof(chap_tbl));
Mike Christie13483732011-12-01 21:38:41 -06003725
Nilesh Javali376738a2012-02-27 03:08:52 -08003726 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3727
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003728 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Mike Christie13483732011-12-01 21:38:41 -06003729
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003730 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06003731 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3732
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003733 memset(ip_addr, 0, sizeof(ip_addr));
Mike Christie13483732011-12-01 21:38:41 -06003734 options = le16_to_cpu(fw_ddb_entry->options);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003735 if (options & DDB_OPT_IPV6_DEVICE) {
3736 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
Mike Christie13483732011-12-01 21:38:41 -06003737
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003738 memset(ip_addr, 0, sizeof(ip_addr));
3739 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3740 } else {
3741 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3742 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3743 }
3744
3745 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3746 (char *)ip_addr, buflen);
Mike Christie13483732011-12-01 21:38:41 -06003747 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3748 (char *)fw_ddb_entry->iscsi_name, buflen);
3749 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3750 (char *)ha->name_string, buflen);
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04003751
3752 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3753 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3754 chap_tbl.secret,
3755 ddb_entry->chap_tbl_idx)) {
3756 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3757 (char *)chap_tbl.name,
3758 strlen((char *)chap_tbl.name));
3759 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3760 (char *)chap_tbl.secret,
3761 chap_tbl.secret_len);
3762 }
3763 }
Mike Christie13483732011-12-01 21:38:41 -06003764}
3765
3766void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3767 struct ddb_entry *ddb_entry)
3768{
3769 struct iscsi_cls_session *cls_sess;
3770 struct iscsi_cls_conn *cls_conn;
3771 uint32_t ddb_state;
3772 dma_addr_t fw_ddb_entry_dma;
3773 struct dev_db_entry *fw_ddb_entry;
3774
3775 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3776 &fw_ddb_entry_dma, GFP_KERNEL);
3777 if (!fw_ddb_entry) {
3778 ql4_printk(KERN_ERR, ha,
3779 "%s: Unable to allocate dma buffer\n", __func__);
3780 goto exit_session_conn_fwddb_param;
3781 }
3782
3783 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3784 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3785 NULL, NULL, NULL) == QLA_ERROR) {
3786 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3787 "get_ddb_entry for fw_ddb_index %d\n",
3788 ha->host_no, __func__,
3789 ddb_entry->fw_ddb_index));
3790 goto exit_session_conn_fwddb_param;
3791 }
3792
3793 cls_sess = ddb_entry->sess;
3794
3795 cls_conn = ddb_entry->conn;
3796
3797 /* Update params */
3798 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3799
3800exit_session_conn_fwddb_param:
3801 if (fw_ddb_entry)
3802 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3803 fw_ddb_entry, fw_ddb_entry_dma);
3804}
3805
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003806void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3807 struct ddb_entry *ddb_entry)
3808{
3809 struct iscsi_cls_session *cls_sess;
3810 struct iscsi_cls_conn *cls_conn;
3811 struct iscsi_session *sess;
3812 struct iscsi_conn *conn;
3813 uint32_t ddb_state;
3814 dma_addr_t fw_ddb_entry_dma;
3815 struct dev_db_entry *fw_ddb_entry;
3816
3817 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3818 &fw_ddb_entry_dma, GFP_KERNEL);
3819 if (!fw_ddb_entry) {
3820 ql4_printk(KERN_ERR, ha,
3821 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06003822 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003823 }
3824
3825 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3826 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3827 NULL, NULL, NULL) == QLA_ERROR) {
3828 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3829 "get_ddb_entry for fw_ddb_index %d\n",
3830 ha->host_no, __func__,
3831 ddb_entry->fw_ddb_index));
Mike Christie13483732011-12-01 21:38:41 -06003832 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003833 }
3834
3835 cls_sess = ddb_entry->sess;
3836 sess = cls_sess->dd_data;
3837
3838 cls_conn = ddb_entry->conn;
3839 conn = cls_conn->dd_data;
3840
Mike Christie13483732011-12-01 21:38:41 -06003841 /* Update timers after login */
3842 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003843 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3844 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3845 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06003846 ddb_entry->default_time2wait =
3847 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3848
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003849 /* Update params */
Nilesh Javali376738a2012-02-27 03:08:52 -08003850 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
Adheer Chandravanshi8cc91d42013-07-01 05:54:13 -04003851 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003852
3853 memcpy(sess->initiatorname, ha->name_string,
3854 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
Mike Christie13483732011-12-01 21:38:41 -06003855
3856exit_session_conn_param:
3857 if (fw_ddb_entry)
3858 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3859 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003860}
3861
David Somayajuluafaf5a22006-09-19 10:28:00 -07003862/*
3863 * Timer routines
3864 */
3865
3866static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
3867 unsigned long interval)
3868{
3869 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3870 __func__, ha->host->host_no));
3871 init_timer(&ha->timer);
3872 ha->timer.expires = jiffies + interval * HZ;
3873 ha->timer.data = (unsigned long)ha;
3874 ha->timer.function = (void (*)(unsigned long))func;
3875 add_timer(&ha->timer);
3876 ha->timer_active = 1;
3877}
3878
3879static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3880{
3881 del_timer_sync(&ha->timer);
3882 ha->timer_active = 0;
3883}
3884
3885/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003886 * qla4xxx_mark_device_missing - blocks the session
3887 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07003888 * @ddb_entry: Pointer to device database entry
3889 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303890 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07003891 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003892void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003893{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003894 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003895}
3896
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303897/**
3898 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
3899 * @ha: Pointer to host adapter structure.
3900 *
3901 * This routine marks a device missing and resets the relogin retry count.
3902 **/
3903void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
3904{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003905 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303906}
3907
David Somayajuluafaf5a22006-09-19 10:28:00 -07003908static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
3909 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003910 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003911{
3912 struct srb *srb;
3913
3914 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
3915 if (!srb)
3916 return srb;
3917
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303918 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003919 srb->ha = ha;
3920 srb->ddb = ddb_entry;
3921 srb->cmd = cmd;
3922 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05303923 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003924
3925 return srb;
3926}
3927
3928static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
3929{
3930 struct scsi_cmnd *cmd = srb->cmd;
3931
3932 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09003933 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003934 srb->flags &= ~SRB_DMA_VALID;
3935 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05303936 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003937}
3938
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303939void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003940{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303941 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003942 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303943 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003944
3945 qla4xxx_srb_free_dma(ha, srb);
3946
3947 mempool_free(srb, ha->srb_mempool);
3948
3949 cmd->scsi_done(cmd);
3950}
3951
3952/**
3953 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003954 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07003955 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07003956 *
3957 * Remarks:
3958 * This routine is invoked by Linux to send a SCSI command to the driver.
3959 * The mid-level driver tries to ensure that queuecommand never gets
3960 * invoked concurrently with itself or the interrupt handler (although
3961 * the interrupt handler may call this routine as part of request-
3962 * completion handling). Unfortunely, it sometimes calls the scheduler
3963 * in interrupt context which is a big NO! NO!.
3964 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003965static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003966{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07003967 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003968 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06003969 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003970 struct srb *srb;
3971 int rval;
3972
Lalit Chandivade2232be02010-07-30 14:38:47 +05303973 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
3974 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
3975 cmd->result = DID_NO_CONNECT << 16;
3976 else
3977 cmd->result = DID_REQUEUE << 16;
3978 goto qc_fail_command;
3979 }
3980
Mike Christie7fb19212008-01-31 13:36:45 -06003981 if (!sess) {
3982 cmd->result = DID_IMM_RETRY << 16;
3983 goto qc_fail_command;
3984 }
3985
3986 rval = iscsi_session_chkready(sess);
3987 if (rval) {
3988 cmd->result = rval;
3989 goto qc_fail_command;
3990 }
3991
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303992 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
3993 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
3994 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
3995 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
3996 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
3997 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003998 !test_bit(AF_LINK_UP, &ha->flags) ||
Nilesh Javali026fbd32013-01-20 23:50:58 -05003999 test_bit(AF_LOOPBACK, &ha->flags) ||
Nilesh Javali7ab284c2013-08-16 07:03:03 -04004000 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4001 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304002 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08004003 goto qc_host_busy;
4004
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004005 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004006 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004007 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004008
4009 rval = qla4xxx_send_command_to_isp(ha, srb);
4010 if (rval != QLA_SUCCESS)
4011 goto qc_host_busy_free_sp;
4012
David Somayajuluafaf5a22006-09-19 10:28:00 -07004013 return 0;
4014
4015qc_host_busy_free_sp:
4016 qla4xxx_srb_free_dma(ha, srb);
4017 mempool_free(srb, ha->srb_mempool);
4018
David Somayajuluafaf5a22006-09-19 10:28:00 -07004019qc_host_busy:
4020 return SCSI_MLQUEUE_HOST_BUSY;
4021
4022qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07004023 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004024
4025 return 0;
4026}
4027
4028/**
4029 * qla4xxx_mem_free - frees memory allocated to adapter
4030 * @ha: Pointer to host adapter structure.
4031 *
4032 * Frees memory previously allocated by qla4xxx_mem_alloc
4033 **/
4034static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4035{
4036 if (ha->queues)
4037 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4038 ha->queues_dma);
4039
Tej Parkash068237c82012-05-18 04:41:44 -04004040 if (ha->fw_dump)
4041 vfree(ha->fw_dump);
4042
David Somayajuluafaf5a22006-09-19 10:28:00 -07004043 ha->queues_len = 0;
4044 ha->queues = NULL;
4045 ha->queues_dma = 0;
4046 ha->request_ring = NULL;
4047 ha->request_dma = 0;
4048 ha->response_ring = NULL;
4049 ha->response_dma = 0;
4050 ha->shadow_regs = NULL;
4051 ha->shadow_regs_dma = 0;
Tej Parkash068237c82012-05-18 04:41:44 -04004052 ha->fw_dump = NULL;
4053 ha->fw_dump_size = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004054
4055 /* Free srb pool. */
4056 if (ha->srb_mempool)
4057 mempool_destroy(ha->srb_mempool);
4058
4059 ha->srb_mempool = NULL;
4060
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004061 if (ha->chap_dma_pool)
4062 dma_pool_destroy(ha->chap_dma_pool);
4063
Lalit Chandivade45494152011-10-07 16:55:42 -07004064 if (ha->chap_list)
4065 vfree(ha->chap_list);
4066 ha->chap_list = NULL;
4067
Mike Christie13483732011-12-01 21:38:41 -06004068 if (ha->fw_ddb_dma_pool)
4069 dma_pool_destroy(ha->fw_ddb_dma_pool);
4070
David Somayajuluafaf5a22006-09-19 10:28:00 -07004071 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304072 if (is_qla8022(ha)) {
4073 if (ha->nx_pcibase)
4074 iounmap(
4075 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004076 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004077 if (ha->nx_pcibase)
4078 iounmap(
4079 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4080 } else if (ha->reg) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004081 iounmap(ha->reg);
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004082 }
4083
4084 if (ha->reset_tmplt.buff)
4085 vfree(ha->reset_tmplt.buff);
4086
David Somayajuluafaf5a22006-09-19 10:28:00 -07004087 pci_release_regions(ha->pdev);
4088}
4089
4090/**
4091 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4092 * @ha: Pointer to host adapter structure
4093 *
4094 * Allocates DMA memory for request and response queues. Also allocates memory
4095 * for srbs.
4096 **/
4097static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4098{
4099 unsigned long align;
4100
4101 /* Allocate contiguous block of DMA memory for queues. */
4102 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4103 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4104 sizeof(struct shadow_regs) +
4105 MEM_ALIGN_VALUE +
4106 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4107 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4108 &ha->queues_dma, GFP_KERNEL);
4109 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304110 ql4_printk(KERN_WARNING, ha,
4111 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004112
4113 goto mem_alloc_error_exit;
4114 }
4115 memset(ha->queues, 0, ha->queues_len);
4116
4117 /*
4118 * As per RISC alignment requirements -- the bus-address must be a
4119 * multiple of the request-ring size (in bytes).
4120 */
4121 align = 0;
4122 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4123 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4124 (MEM_ALIGN_VALUE - 1));
4125
4126 /* Update request and response queue pointers. */
4127 ha->request_dma = ha->queues_dma + align;
4128 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4129 ha->response_dma = ha->queues_dma + align +
4130 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4131 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4132 (REQUEST_QUEUE_DEPTH *
4133 QUEUE_SIZE));
4134 ha->shadow_regs_dma = ha->queues_dma + align +
4135 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4136 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4137 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4138 (REQUEST_QUEUE_DEPTH *
4139 QUEUE_SIZE) +
4140 (RESPONSE_QUEUE_DEPTH *
4141 QUEUE_SIZE));
4142
4143 /* Allocate memory for srb pool. */
4144 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4145 mempool_free_slab, srb_cachep);
4146 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304147 ql4_printk(KERN_WARNING, ha,
4148 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004149
4150 goto mem_alloc_error_exit;
4151 }
4152
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004153 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4154 CHAP_DMA_BLOCK_SIZE, 8, 0);
4155
4156 if (ha->chap_dma_pool == NULL) {
4157 ql4_printk(KERN_WARNING, ha,
4158 "%s: chap_dma_pool allocation failed..\n", __func__);
4159 goto mem_alloc_error_exit;
4160 }
4161
Mike Christie13483732011-12-01 21:38:41 -06004162 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4163 DDB_DMA_BLOCK_SIZE, 8, 0);
4164
4165 if (ha->fw_ddb_dma_pool == NULL) {
4166 ql4_printk(KERN_WARNING, ha,
4167 "%s: fw_ddb_dma_pool allocation failed..\n",
4168 __func__);
4169 goto mem_alloc_error_exit;
4170 }
4171
David Somayajuluafaf5a22006-09-19 10:28:00 -07004172 return QLA_SUCCESS;
4173
4174mem_alloc_error_exit:
4175 qla4xxx_mem_free(ha);
4176 return QLA_ERROR;
4177}
4178
4179/**
Mike Hernandez4f770832012-01-11 02:44:15 -08004180 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4181 * @ha: adapter block pointer.
4182 *
4183 * Note: The caller should not hold the idc lock.
4184 **/
4185static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4186{
4187 uint32_t temp, temp_state, temp_val;
4188 int status = QLA_SUCCESS;
4189
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004190 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004191
4192 temp_state = qla82xx_get_temp_state(temp);
4193 temp_val = qla82xx_get_temp_val(temp);
4194
4195 if (temp_state == QLA82XX_TEMP_PANIC) {
4196 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4197 " exceeds maximum allowed. Hardware has been shut"
4198 " down.\n", temp_val);
4199 status = QLA_ERROR;
4200 } else if (temp_state == QLA82XX_TEMP_WARN) {
4201 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4202 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4203 " degrees C exceeds operating range."
4204 " Immediate action needed.\n", temp_val);
4205 } else {
4206 if (ha->temperature == QLA82XX_TEMP_WARN)
4207 ql4_printk(KERN_INFO, ha, "Device temperature is"
4208 " now %d degrees C in normal range.\n",
4209 temp_val);
4210 }
4211 ha->temperature = temp_state;
4212 return status;
4213}
4214
4215/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304216 * qla4_8xxx_check_fw_alive - Check firmware health
4217 * @ha: Pointer to host adapter structure.
4218 *
4219 * Context: Interrupt
4220 **/
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004221static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304222{
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004223 uint32_t fw_heartbeat_counter;
4224 int status = QLA_SUCCESS;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304225
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004226 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4227 QLA8XXX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05304228 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4229 if (fw_heartbeat_counter == 0xffffffff) {
4230 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4231 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4232 ha->host_no, __func__));
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004233 return status;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304234 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304235
4236 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4237 ha->seconds_since_last_heartbeat++;
4238 /* FW not alive after 2 seconds */
4239 if (ha->seconds_since_last_heartbeat == 2) {
4240 ha->seconds_since_last_heartbeat = 0;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004241 qla4_8xxx_dump_peg_reg(ha);
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004242 status = QLA_ERROR;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304243 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07004244 } else
4245 ha->seconds_since_last_heartbeat = 0;
4246
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304247 ha->fw_heartbeat_counter = fw_heartbeat_counter;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004248 return status;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304249}
4250
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004251static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4252{
4253 uint32_t halt_status;
4254 int halt_status_unrecoverable = 0;
4255
4256 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4257
4258 if (is_qla8022(ha)) {
4259 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4260 __func__);
4261 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4262 CRB_NIU_XG_PAUSE_CTL_P0 |
4263 CRB_NIU_XG_PAUSE_CTL_P1);
4264
4265 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4266 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4267 __func__);
4268 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4269 halt_status_unrecoverable = 1;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004270 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004271 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4272 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4273 __func__);
4274 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4275 halt_status_unrecoverable = 1;
4276 }
4277
4278 /*
4279 * Since we cannot change dev_state in interrupt context,
4280 * set appropriate DPC flag then wakeup DPC
4281 */
4282 if (halt_status_unrecoverable) {
4283 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4284 } else {
4285 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4286 __func__);
4287 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4288 }
4289 qla4xxx_mailbox_premature_completion(ha);
4290 qla4xxx_wake_dpc(ha);
4291}
4292
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304293/**
4294 * qla4_8xxx_watchdog - Poll dev state
4295 * @ha: Pointer to host adapter structure.
4296 *
4297 * Context: Interrupt
4298 **/
4299void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4300{
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004301 uint32_t dev_state;
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004302 uint32_t idc_ctrl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304303
4304 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08004305 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4306 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07004307 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004308 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08004309
4310 if (qla4_8xxx_check_temp(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004311 if (is_qla8022(ha)) {
4312 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4313 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4314 CRB_NIU_XG_PAUSE_CTL_P0 |
4315 CRB_NIU_XG_PAUSE_CTL_P1);
4316 }
Mike Hernandez4f770832012-01-11 02:44:15 -08004317 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4318 qla4xxx_wake_dpc(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004319 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004320 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004321
4322 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4323 __func__);
4324
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004325 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6cf94122013-03-07 05:43:10 -05004326 idc_ctrl = qla4_83xx_rd_reg(ha,
4327 QLA83XX_IDC_DRV_CTRL);
4328 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4329 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4330 __func__);
4331 qla4xxx_mailbox_premature_completion(
4332 ha);
4333 }
4334 }
4335
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004336 if ((is_qla8032(ha) || is_qla8042(ha)) ||
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004337 (is_qla8022(ha) && !ql4xdontresethba)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004338 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4339 qla4xxx_wake_dpc(ha);
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004340 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004341 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304342 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08004343 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4344 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304345 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4346 qla4xxx_wake_dpc(ha);
4347 } else {
4348 /* Check firmware health */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004349 if (qla4_8xxx_check_fw_alive(ha))
4350 qla4_8xxx_process_fw_error(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304351 }
4352 }
4353}
4354
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004355static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
Mike Christie13483732011-12-01 21:38:41 -06004356{
4357 struct iscsi_session *sess;
4358 struct ddb_entry *ddb_entry;
4359 struct scsi_qla_host *ha;
4360
4361 sess = cls_sess->dd_data;
4362 ddb_entry = sess->dd_data;
4363 ha = ddb_entry->ha;
4364
4365 if (!(ddb_entry->ddb_type == FLASH_DDB))
4366 return;
4367
4368 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4369 !iscsi_is_session_online(cls_sess)) {
4370 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4371 INVALID_ENTRY) {
4372 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4373 0) {
4374 atomic_set(&ddb_entry->retry_relogin_timer,
4375 INVALID_ENTRY);
4376 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4377 set_bit(DF_RELOGIN, &ddb_entry->flags);
4378 DEBUG2(ql4_printk(KERN_INFO, ha,
4379 "%s: index [%d] login device\n",
4380 __func__, ddb_entry->fw_ddb_index));
4381 } else
4382 atomic_dec(&ddb_entry->retry_relogin_timer);
4383 }
4384 }
4385
4386 /* Wait for relogin to timeout */
4387 if (atomic_read(&ddb_entry->relogin_timer) &&
4388 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4389 /*
4390 * If the relogin times out and the device is
4391 * still NOT ONLINE then try and relogin again.
4392 */
4393 if (!iscsi_is_session_online(cls_sess)) {
4394 /* Reset retry relogin timer */
4395 atomic_inc(&ddb_entry->relogin_retry_count);
4396 DEBUG2(ql4_printk(KERN_INFO, ha,
4397 "%s: index[%d] relogin timed out-retrying"
4398 " relogin (%d), retry (%d)\n", __func__,
4399 ddb_entry->fw_ddb_index,
4400 atomic_read(&ddb_entry->relogin_retry_count),
4401 ddb_entry->default_time2wait + 4));
4402 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4403 atomic_set(&ddb_entry->retry_relogin_timer,
4404 ddb_entry->default_time2wait + 4);
4405 }
4406 }
4407}
4408
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304409/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004410 * qla4xxx_timer - checks every second for work to do.
4411 * @ha: Pointer to host adapter structure.
4412 **/
4413static void qla4xxx_timer(struct scsi_qla_host *ha)
4414{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004415 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304416 uint16_t w;
4417
Mike Christie13483732011-12-01 21:38:41 -06004418 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4419
Lalit Chandivade2232be02010-07-30 14:38:47 +05304420 /* If we are in the middle of AER/EEH processing
4421 * skip any processing and reschedule the timer
4422 */
4423 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4424 mod_timer(&ha->timer, jiffies + HZ);
4425 return;
4426 }
4427
4428 /* Hardware read to trigger an EEH error during mailbox waits. */
4429 if (!pci_channel_offline(ha->pdev))
4430 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004431
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004432 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304433 qla4_8xxx_watchdog(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304434
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004435 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304436 /* Check for heartbeat interval. */
4437 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4438 ha->heartbeat_interval != 0) {
4439 ha->seconds_since_last_heartbeat++;
4440 if (ha->seconds_since_last_heartbeat >
4441 ha->heartbeat_interval + 2)
4442 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4443 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004444 }
4445
Vikas Chaudharyff884432011-08-29 23:43:02 +05304446 /* Process any deferred work. */
4447 if (!list_empty(&ha->work_list))
4448 start_dpc++;
4449
David Somayajuluafaf5a22006-09-19 10:28:00 -07004450 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07004451 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004452 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4453 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4454 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304455 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07004456 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4457 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05304458 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304459 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4460 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07004461 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004462 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4463 " - dpc flags = 0x%lx\n",
4464 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304465 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004466 }
4467
4468 /* Reschedule timer thread to call us back in one second */
4469 mod_timer(&ha->timer, jiffies + HZ);
4470
4471 DEBUG2(ha->seconds_since_last_intr++);
4472}
4473
4474/**
4475 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4476 * @ha: Pointer to host adapter structure.
4477 *
4478 * This routine stalls the driver until all outstanding commands are returned.
4479 * Caller must release the Hardware Lock prior to calling this routine.
4480 **/
4481static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4482{
4483 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004484 unsigned long flags;
4485 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004486
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304487 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
4488
4489 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
4490 "complete\n", WAIT_CMD_TOV));
4491
4492 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004493 spin_lock_irqsave(&ha->hardware_lock, flags);
4494 /* Find a command that hasn't completed. */
4495 for (index = 0; index < ha->host->can_queue; index++) {
4496 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07004497 /*
4498 * We cannot just check if the index is valid,
4499 * becase if we are run from the scsi eh, then
4500 * the scsi/block layer is going to prevent
4501 * the tag from being released.
4502 */
4503 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07004504 break;
4505 }
4506 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4507
4508 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304509 if (index == ha->host->can_queue)
4510 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004511
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304512 msleep(1000);
4513 }
4514 /* If we timed out on waiting for commands to come back
4515 * return ERROR. */
4516 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004517}
4518
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304519int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004520{
David Somayajuluafaf5a22006-09-19 10:28:00 -07004521 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004522 unsigned long flags = 0;
4523
4524 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004525
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304526 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4527 return QLA_ERROR;
4528
David Somayajuluafaf5a22006-09-19 10:28:00 -07004529 spin_lock_irqsave(&ha->hardware_lock, flags);
4530
4531 /*
4532 * If the SCSI Reset Interrupt bit is set, clear it.
4533 * Otherwise, the Soft Reset won't work.
4534 */
4535 ctrl_status = readw(&ha->reg->ctrl_status);
4536 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4537 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4538
4539 /* Issue Soft Reset */
4540 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4541 readl(&ha->reg->ctrl_status);
4542
4543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304544 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004545}
4546
4547/**
4548 * qla4xxx_soft_reset - performs soft reset.
4549 * @ha: Pointer to host adapter structure.
4550 **/
4551int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4552{
4553 uint32_t max_wait_time;
4554 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004555 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08004556 uint32_t ctrl_status;
4557
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004558 status = qla4xxx_hw_reset(ha);
4559 if (status != QLA_SUCCESS)
4560 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004561
Vikas Chaudharyf931c532010-10-06 22:48:07 -07004562 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004563 /* Wait until the Network Reset Intr bit is cleared */
4564 max_wait_time = RESET_INTR_TOV;
4565 do {
4566 spin_lock_irqsave(&ha->hardware_lock, flags);
4567 ctrl_status = readw(&ha->reg->ctrl_status);
4568 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4569
4570 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4571 break;
4572
4573 msleep(1000);
4574 } while ((--max_wait_time));
4575
4576 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4577 DEBUG2(printk(KERN_WARNING
4578 "scsi%ld: Network Reset Intr not cleared by "
4579 "Network function, clearing it now!\n",
4580 ha->host_no));
4581 spin_lock_irqsave(&ha->hardware_lock, flags);
4582 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4583 readl(&ha->reg->ctrl_status);
4584 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4585 }
4586
4587 /* Wait until the firmware tells us the Soft Reset is done */
4588 max_wait_time = SOFT_RESET_TOV;
4589 do {
4590 spin_lock_irqsave(&ha->hardware_lock, flags);
4591 ctrl_status = readw(&ha->reg->ctrl_status);
4592 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4593
4594 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4595 status = QLA_SUCCESS;
4596 break;
4597 }
4598
4599 msleep(1000);
4600 } while ((--max_wait_time));
4601
4602 /*
4603 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4604 * after the soft reset has taken place.
4605 */
4606 spin_lock_irqsave(&ha->hardware_lock, flags);
4607 ctrl_status = readw(&ha->reg->ctrl_status);
4608 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4609 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4610 readl(&ha->reg->ctrl_status);
4611 }
4612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4613
4614 /* If soft reset fails then most probably the bios on other
4615 * function is also enabled.
4616 * Since the initialization is sequential the other fn
4617 * wont be able to acknowledge the soft reset.
4618 * Issue a force soft reset to workaround this scenario.
4619 */
4620 if (max_wait_time == 0) {
4621 /* Issue Force Soft Reset */
4622 spin_lock_irqsave(&ha->hardware_lock, flags);
4623 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4624 readl(&ha->reg->ctrl_status);
4625 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4626 /* Wait until the firmware tells us the Soft Reset is done */
4627 max_wait_time = SOFT_RESET_TOV;
4628 do {
4629 spin_lock_irqsave(&ha->hardware_lock, flags);
4630 ctrl_status = readw(&ha->reg->ctrl_status);
4631 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4632
4633 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4634 status = QLA_SUCCESS;
4635 break;
4636 }
4637
4638 msleep(1000);
4639 } while ((--max_wait_time));
4640 }
4641
4642 return status;
4643}
4644
4645/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304646 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004647 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304648 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07004649 *
4650 * This routine is called just prior to a HARD RESET to return all
4651 * outstanding commands back to the Operating System.
4652 * Caller should make sure that the following locks are released
4653 * before this calling routine: Hardware lock, and io_request_lock.
4654 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304655static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004656{
4657 struct srb *srb;
4658 int i;
4659 unsigned long flags;
4660
4661 spin_lock_irqsave(&ha->hardware_lock, flags);
4662 for (i = 0; i < ha->host->can_queue; i++) {
4663 srb = qla4xxx_del_from_active_array(ha, i);
4664 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304665 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304666 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004667 }
4668 }
4669 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004670}
4671
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304672void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4673{
4674 clear_bit(AF_ONLINE, &ha->flags);
4675
4676 /* Disable the board */
4677 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304678
4679 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4680 qla4xxx_mark_all_devices_missing(ha);
4681 clear_bit(AF_INIT_DONE, &ha->flags);
4682}
4683
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004684static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4685{
4686 struct iscsi_session *sess;
4687 struct ddb_entry *ddb_entry;
4688
4689 sess = cls_session->dd_data;
4690 ddb_entry = sess->dd_data;
4691 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
Mike Christie13483732011-12-01 21:38:41 -06004692
4693 if (ddb_entry->ddb_type == FLASH_DDB)
4694 iscsi_block_session(ddb_entry->sess);
4695 else
4696 iscsi_session_failure(cls_session->dd_data,
4697 ISCSI_ERR_CONN_FAILED);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004698}
4699
David Somayajuluafaf5a22006-09-19 10:28:00 -07004700/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004701 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4702 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004703 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304704static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004705{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304706 int status = QLA_ERROR;
4707 uint8_t reset_chip = 0;
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004708 uint32_t dev_state;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004709 unsigned long wait;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004710
4711 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304712 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004713 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004714 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06004715
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304716 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004717
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304718 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004719
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04004720 if ((is_qla8032(ha) || is_qla8042(ha)) &&
Tej Parkash546fef22012-09-20 07:35:12 -04004721 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4722 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4723 __func__);
4724 /* disable pause frame for ISP83xx */
4725 qla4_83xx_disable_pause(ha);
4726 }
4727
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004728 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4729
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304730 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4731 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004732
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304733 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4734 * do not reset adapter, jump to initialize_adapter */
4735 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4736 status = QLA_SUCCESS;
4737 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004738 }
4739
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004740 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304741 * from eh_host_reset or ioctl module */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004742 if (is_qla80XX(ha) && !reset_chip &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304743 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4744
4745 DEBUG2(ql4_printk(KERN_INFO, ha,
4746 "scsi%ld: %s - Performing stop_firmware...\n",
4747 ha->host_no, __func__));
4748 status = ha->isp_ops->reset_firmware(ha);
4749 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004750 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4751 qla4xxx_cmd_wait(ha);
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05004752
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304753 ha->isp_ops->disable_intrs(ha);
4754 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4755 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4756 } else {
4757 /* If the stop_firmware fails then
4758 * reset the entire chip */
4759 reset_chip = 1;
4760 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4761 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4762 }
4763 }
4764
4765 /* Issue full chip reset if recovering from a catastrophic error,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004766 * or if stop_firmware fails for ISP-8xxx.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304767 * This is the default case for ISP-4xxx */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004768 if (is_qla40XX(ha) || reset_chip) {
4769 if (is_qla40XX(ha))
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004770 goto chip_reset;
4771
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004772 /* Check if 8XXX firmware is alive or not
Shyam Sunder9ee91a32011-12-01 22:42:13 -08004773 * We may have arrived here from NEED_RESET
4774 * detection only */
4775 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4776 goto chip_reset;
4777
4778 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4779 while (time_before(jiffies, wait)) {
4780 if (qla4_8xxx_check_fw_alive(ha)) {
4781 qla4xxx_mailbox_premature_completion(ha);
4782 break;
4783 }
4784
4785 set_current_state(TASK_UNINTERRUPTIBLE);
4786 schedule_timeout(HZ);
4787 }
Vikas Chaudharyda106212012-08-22 07:45:26 -04004788chip_reset:
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07004789 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4790 qla4xxx_cmd_wait(ha);
Vikas Chaudharyda106212012-08-22 07:45:26 -04004791
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304792 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4793 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4794 DEBUG2(ql4_printk(KERN_INFO, ha,
4795 "scsi%ld: %s - Performing chip reset..\n",
4796 ha->host_no, __func__));
4797 status = ha->isp_ops->reset_chip(ha);
4798 }
4799
4800 /* Flush any pending ddb changed AENs */
4801 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4802
4803recover_ha_init_adapter:
4804 /* Upon successful firmware/chip reset, re-initialize the adapter */
4805 if (status == QLA_SUCCESS) {
4806 /* For ISP-4xxx, force function 1 to always initialize
4807 * before function 3 to prevent both funcions from
4808 * stepping on top of the other */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04004809 if (is_qla40XX(ha) && (ha->mac_index == 3))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304810 ssleep(6);
4811
4812 /* NOTE: AF_ONLINE flag set upon successful completion of
4813 * qla4xxx_initialize_adapter */
Mike Christie13483732011-12-01 21:38:41 -06004814 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304815 }
4816
4817 /* Retry failed adapter initialization, if necessary
4818 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4819 * case to prevent ping-pong resets between functions */
4820 if (!test_bit(AF_ONLINE, &ha->flags) &&
4821 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004822 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304823 * resetting the ha.
4824 * Since we don't want to block the DPC for too long
4825 * with multiple resets in the same thread,
4826 * utilize DPC to retry */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04004827 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04004828 ha->isp_ops->idc_lock(ha);
4829 dev_state = qla4_8xxx_rd_direct(ha,
4830 QLA8XXX_CRB_DEV_STATE);
4831 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04004832 if (dev_state == QLA8XXX_DEV_FAILED) {
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004833 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4834 "recover adapter. H/W is in Failed "
4835 "state\n", __func__);
4836 qla4xxx_dead_adapter_cleanup(ha);
4837 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4838 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4839 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4840 &ha->dpc_flags);
4841 status = QLA_ERROR;
4842
4843 goto exit_recover;
4844 }
4845 }
4846
David Somayajuluafaf5a22006-09-19 10:28:00 -07004847 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4848 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4849 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4850 "(%d) more times\n", ha->host_no,
4851 ha->retry_reset_ha_cnt));
4852 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4853 status = QLA_ERROR;
4854 } else {
4855 if (ha->retry_reset_ha_cnt > 0) {
4856 /* Schedule another Reset HA--DPC will retry */
4857 ha->retry_reset_ha_cnt--;
4858 DEBUG2(printk("scsi%ld: recover adapter - "
4859 "retry remaining %d\n",
4860 ha->host_no,
4861 ha->retry_reset_ha_cnt));
4862 status = QLA_ERROR;
4863 }
4864
4865 if (ha->retry_reset_ha_cnt == 0) {
4866 /* Recover adapter retries have been exhausted.
4867 * Adapter DEAD */
4868 DEBUG2(printk("scsi%ld: recover adapter "
4869 "failed - board disabled\n",
4870 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304871 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004872 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4873 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304874 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004875 &ha->dpc_flags);
4876 status = QLA_ERROR;
4877 }
4878 }
4879 } else {
4880 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304881 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004882 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4883 }
4884
Sarang Radke8e0f3a62011-12-01 22:42:09 -08004885exit_recover:
David Somayajuluafaf5a22006-09-19 10:28:00 -07004886 ha->adapter_error_count++;
4887
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304888 if (test_bit(AF_ONLINE, &ha->flags))
4889 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004890
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304891 scsi_unblock_requests(ha->host);
4892
4893 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4894 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004895 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304896
David Somayajuluafaf5a22006-09-19 10:28:00 -07004897 return status;
4898}
4899
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004900static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004901{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004902 struct iscsi_session *sess;
4903 struct ddb_entry *ddb_entry;
4904 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004905
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004906 sess = cls_session->dd_data;
4907 ddb_entry = sess->dd_data;
4908 ha = ddb_entry->ha;
4909 if (!iscsi_is_session_online(cls_session)) {
4910 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
4911 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4912 " unblock session\n", ha->host_no, __func__,
4913 ddb_entry->fw_ddb_index);
4914 iscsi_unblock_session(ddb_entry->sess);
4915 } else {
4916 /* Trigger relogin */
Mike Christie13483732011-12-01 21:38:41 -06004917 if (ddb_entry->ddb_type == FLASH_DDB) {
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04004918 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
4919 test_bit(DF_DISABLE_RELOGIN,
4920 &ddb_entry->flags)))
Mike Christie13483732011-12-01 21:38:41 -06004921 qla4xxx_arm_relogin_timer(ddb_entry);
4922 } else
4923 iscsi_session_failure(cls_session->dd_data,
4924 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07004925 }
4926 }
4927}
4928
Mike Christie13483732011-12-01 21:38:41 -06004929int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
4930{
4931 struct iscsi_session *sess;
4932 struct ddb_entry *ddb_entry;
4933 struct scsi_qla_host *ha;
4934
4935 sess = cls_session->dd_data;
4936 ddb_entry = sess->dd_data;
4937 ha = ddb_entry->ha;
4938 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4939 " unblock session\n", ha->host_no, __func__,
4940 ddb_entry->fw_ddb_index);
4941
4942 iscsi_unblock_session(ddb_entry->sess);
4943
4944 /* Start scan target */
4945 if (test_bit(AF_ONLINE, &ha->flags)) {
4946 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4947 " start scan\n", ha->host_no, __func__,
4948 ddb_entry->fw_ddb_index);
4949 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
4950 }
4951 return QLA_SUCCESS;
4952}
4953
4954int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
4955{
4956 struct iscsi_session *sess;
4957 struct ddb_entry *ddb_entry;
4958 struct scsi_qla_host *ha;
Manish Rangankar80c53e62012-08-07 07:57:15 -04004959 int status = QLA_SUCCESS;
Mike Christie13483732011-12-01 21:38:41 -06004960
4961 sess = cls_session->dd_data;
4962 ddb_entry = sess->dd_data;
4963 ha = ddb_entry->ha;
4964 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
4965 " unblock user space session\n", ha->host_no, __func__,
4966 ddb_entry->fw_ddb_index);
Mike Christie13483732011-12-01 21:38:41 -06004967
Manish Rangankar80c53e62012-08-07 07:57:15 -04004968 if (!iscsi_is_session_online(cls_session)) {
4969 iscsi_conn_start(ddb_entry->conn);
4970 iscsi_conn_login_event(ddb_entry->conn,
4971 ISCSI_CONN_STATE_LOGGED_IN);
4972 } else {
4973 ql4_printk(KERN_INFO, ha,
4974 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
4975 ha->host_no, __func__, ddb_entry->fw_ddb_index,
4976 cls_session->sid);
4977 status = QLA_ERROR;
4978 }
4979
4980 return status;
Mike Christie13483732011-12-01 21:38:41 -06004981}
4982
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004983static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
4984{
4985 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
4986}
4987
Mike Christie13483732011-12-01 21:38:41 -06004988static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4989{
4990 uint16_t relogin_timer;
4991 struct iscsi_session *sess;
4992 struct ddb_entry *ddb_entry;
4993 struct scsi_qla_host *ha;
4994
4995 sess = cls_sess->dd_data;
4996 ddb_entry = sess->dd_data;
4997 ha = ddb_entry->ha;
4998
4999 relogin_timer = max(ddb_entry->default_relogin_timeout,
5000 (uint16_t)RELOGIN_TOV);
5001 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5002
5003 DEBUG2(ql4_printk(KERN_INFO, ha,
5004 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5005 ddb_entry->fw_ddb_index, relogin_timer));
5006
5007 qla4xxx_login_flash_ddb(cls_sess);
5008}
5009
5010static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5011{
5012 struct iscsi_session *sess;
5013 struct ddb_entry *ddb_entry;
5014 struct scsi_qla_host *ha;
5015
5016 sess = cls_sess->dd_data;
5017 ddb_entry = sess->dd_data;
5018 ha = ddb_entry->ha;
5019
5020 if (!(ddb_entry->ddb_type == FLASH_DDB))
5021 return;
5022
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04005023 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5024 return;
5025
Mike Christie13483732011-12-01 21:38:41 -06005026 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5027 !iscsi_is_session_online(cls_sess)) {
5028 DEBUG2(ql4_printk(KERN_INFO, ha,
5029 "relogin issued\n"));
5030 qla4xxx_relogin_flash_ddb(cls_sess);
5031 }
5032}
5033
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305034void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5035{
Lalit Chandivade1b468072011-05-17 23:17:09 -07005036 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305037 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305038}
5039
Vikas Chaudharyff884432011-08-29 23:43:02 +05305040static struct qla4_work_evt *
5041qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5042 enum qla4_work_type type)
5043{
5044 struct qla4_work_evt *e;
5045 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5046
5047 e = kzalloc(size, GFP_ATOMIC);
5048 if (!e)
5049 return NULL;
5050
5051 INIT_LIST_HEAD(&e->list);
5052 e->type = type;
5053 return e;
5054}
5055
5056static void qla4xxx_post_work(struct scsi_qla_host *ha,
5057 struct qla4_work_evt *e)
5058{
5059 unsigned long flags;
5060
5061 spin_lock_irqsave(&ha->work_lock, flags);
5062 list_add_tail(&e->list, &ha->work_list);
5063 spin_unlock_irqrestore(&ha->work_lock, flags);
5064 qla4xxx_wake_dpc(ha);
5065}
5066
5067int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5068 enum iscsi_host_event_code aen_code,
5069 uint32_t data_size, uint8_t *data)
5070{
5071 struct qla4_work_evt *e;
5072
5073 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5074 if (!e)
5075 return QLA_ERROR;
5076
5077 e->u.aen.code = aen_code;
5078 e->u.aen.data_size = data_size;
5079 memcpy(e->u.aen.data, data, data_size);
5080
5081 qla4xxx_post_work(ha, e);
5082
5083 return QLA_SUCCESS;
5084}
5085
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05305086int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5087 uint32_t status, uint32_t pid,
5088 uint32_t data_size, uint8_t *data)
5089{
5090 struct qla4_work_evt *e;
5091
5092 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5093 if (!e)
5094 return QLA_ERROR;
5095
5096 e->u.ping.status = status;
5097 e->u.ping.pid = pid;
5098 e->u.ping.data_size = data_size;
5099 memcpy(e->u.ping.data, data, data_size);
5100
5101 qla4xxx_post_work(ha, e);
5102
5103 return QLA_SUCCESS;
5104}
5105
Vikas Chaudharya7380a62012-02-27 03:08:56 -08005106static void qla4xxx_do_work(struct scsi_qla_host *ha)
Vikas Chaudharyff884432011-08-29 23:43:02 +05305107{
5108 struct qla4_work_evt *e, *tmp;
5109 unsigned long flags;
5110 LIST_HEAD(work);
5111
5112 spin_lock_irqsave(&ha->work_lock, flags);
5113 list_splice_init(&ha->work_list, &work);
5114 spin_unlock_irqrestore(&ha->work_lock, flags);
5115
5116 list_for_each_entry_safe(e, tmp, &work, list) {
5117 list_del_init(&e->list);
5118
5119 switch (e->type) {
5120 case QLA4_EVENT_AEN:
5121 iscsi_post_host_event(ha->host_no,
5122 &qla4xxx_iscsi_transport,
5123 e->u.aen.code,
5124 e->u.aen.data_size,
5125 e->u.aen.data);
5126 break;
Vikas Chaudharyc0b9d3f2012-02-13 18:30:49 +05305127 case QLA4_EVENT_PING_STATUS:
5128 iscsi_ping_comp_event(ha->host_no,
5129 &qla4xxx_iscsi_transport,
5130 e->u.ping.status,
5131 e->u.ping.pid,
5132 e->u.ping.data_size,
5133 e->u.ping.data);
5134 break;
Vikas Chaudharyff884432011-08-29 23:43:02 +05305135 default:
5136 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5137 "supported", e->type);
5138 }
5139 kfree(e);
5140 }
5141}
5142
David Somayajuluafaf5a22006-09-19 10:28:00 -07005143/**
5144 * qla4xxx_do_dpc - dpc routine
5145 * @data: in our case pointer to adapter structure
5146 *
5147 * This routine is a task that is schedule by the interrupt handler
5148 * to perform the background processing for interrupts. We put it
5149 * on a task queue that is consumed whenever the scheduler runs; that's
5150 * so you can do anything (i.e. put the process to sleep etc). In fact,
5151 * the mid-level tries to sleep when it reaches the driver threshold
5152 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5153 **/
David Howellsc4028952006-11-22 14:57:56 +00005154static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005155{
David Howellsc4028952006-11-22 14:57:56 +00005156 struct scsi_qla_host *ha =
5157 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005158 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005159
David C Somayajuluf26b9042006-11-15 16:41:09 -08005160 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305161 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5162 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07005163
5164 /* Initialization not yet finished. Don't do anything yet. */
5165 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07005166 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005167
Lalit Chandivade2232be02010-07-30 14:38:47 +05305168 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5169 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5170 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07005171 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05305172 }
5173
Vikas Chaudharyff884432011-08-29 23:43:02 +05305174 /* post events to application */
5175 qla4xxx_do_work(ha);
5176
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005177 if (is_qla80XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305178 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005179 if (is_qla8032(ha) || is_qla8042(ha)) {
Tej Parkash546fef22012-09-20 07:35:12 -04005180 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5181 __func__);
5182 /* disable pause frame for ISP83xx */
5183 qla4_83xx_disable_pause(ha);
5184 }
5185
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005186 ha->isp_ops->idc_lock(ha);
5187 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5188 QLA8XXX_DEV_FAILED);
5189 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305190 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5191 qla4_8xxx_device_state_handler(ha);
5192 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005193
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005194 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5195 if (is_qla8042(ha)) {
5196 if (ha->idc_info.info2 &
5197 ENABLE_INTERNAL_LOOPBACK) {
5198 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5199 __func__);
5200 status = qla4_84xx_config_acb(ha,
5201 ACB_CONFIG_DISABLE);
5202 if (status != QLA_SUCCESS) {
5203 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5204 __func__);
5205 }
5206 }
5207 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005208 qla4_83xx_post_idc_ack(ha);
Nilesh Javali7ab284c2013-08-16 07:03:03 -04005209 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5210 }
5211
5212 if (is_qla8042(ha) &&
5213 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5214 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5215 __func__);
5216 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5217 QLA_SUCCESS) {
5218 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5219 __func__);
5220 }
5221 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5222 }
Nilesh Javali320a61d2012-09-20 07:35:10 -04005223
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305224 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5225 qla4_8xxx_need_qsnt_handler(ha);
5226 }
5227 }
5228
5229 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5230 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07005231 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305232 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005233 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005234 ((is_qla8032(ha) || is_qla8042(ha)) &&
5235 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305236 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5237 ha->host_no, __func__));
5238 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5239 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5240 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5241 goto dpc_post_reset_ha;
5242 }
5243 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5244 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5245 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005246
David C Somayajulu477ffb92007-01-22 12:26:11 -08005247 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07005248 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005249
David Somayajuluafaf5a22006-09-19 10:28:00 -07005250 while ((readw(&ha->reg->ctrl_status) &
5251 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5252 if (--wait_time == 0)
5253 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005254 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005255 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005256 if (wait_time == 0)
5257 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5258 "bit not cleared-- resetting\n",
5259 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305260 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005261 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5262 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305263 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08005264 }
5265 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5266 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305267 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005268 }
5269 }
5270
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305271dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07005272 /* ---- process AEN? --- */
5273 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5274 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5275
5276 /* ---- Get DHCP IP Address? --- */
5277 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5278 qla4xxx_get_dhcp_ip_address(ha);
5279
Mike Christie13483732011-12-01 21:38:41 -06005280 /* ---- relogin device? --- */
5281 if (adapter_up(ha) &&
5282 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5283 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5284 }
5285
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305286 /* ---- link change? --- */
Nilesh Javali026fbd32013-01-20 23:50:58 -05005287 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5288 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305289 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5290 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07005291 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305292 } else {
5293 /* ---- link up? --- *
5294 * F/W will auto login to all devices ONLY ONCE after
5295 * link up during driver initialization and runtime
5296 * fatal error recovery. Therefore, the driver must
5297 * manually relogin to devices when recovering from
5298 * connection failures, logouts, expired KATO, etc. */
Mike Christie13483732011-12-01 21:38:41 -06005299 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5300 qla4xxx_build_ddb_list(ha, ha->is_reset);
5301 iscsi_host_for_each_session(ha->host,
5302 qla4xxx_login_flash_ddb);
5303 } else
5304 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05305305 }
5306 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07005307}
5308
5309/**
5310 * qla4xxx_free_adapter - release the adapter
5311 * @ha: pointer to adapter structure
5312 **/
5313static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5314{
Sarang Radke8a28896012011-12-06 02:34:10 -08005315 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005316
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005317 /* Turn-off interrupts on the card. */
5318 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005319
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005320 if (is_qla40XX(ha)) {
5321 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5322 &ha->reg->ctrl_status);
5323 readl(&ha->reg->ctrl_status);
5324 } else if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005325 writel(0, &ha->qla4_82xx_reg->host_int);
5326 readl(&ha->qla4_82xx_reg->host_int);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005327 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudharyfbd81072012-09-20 07:35:03 -04005328 writel(0, &ha->qla4_83xx_reg->risc_intr);
5329 readl(&ha->qla4_83xx_reg->risc_intr);
Vikas Chaudharyd9e62e52012-08-22 07:45:25 -04005330 }
5331
David Somayajuluafaf5a22006-09-19 10:28:00 -07005332 /* Remove timer thread, if present */
5333 if (ha->timer_active)
5334 qla4xxx_stop_timer(ha);
5335
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305336 /* Kill the kernel thread for this host */
5337 if (ha->dpc_thread)
5338 destroy_workqueue(ha->dpc_thread);
5339
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005340 /* Kill the kernel thread for this host */
5341 if (ha->task_wq)
5342 destroy_workqueue(ha->task_wq);
5343
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305344 /* Put firmware in known state */
5345 ha->isp_ops->reset_firmware(ha);
5346
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005347 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005348 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305349 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005350 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305351 }
5352
David Somayajuluafaf5a22006-09-19 10:28:00 -07005353 /* Detach interrupts */
Vikas Chaudhary5c19b922012-11-23 06:58:38 -05005354 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005355
David C Somayajulubee4fe82007-05-23 18:03:32 -07005356 /* free extra memory */
5357 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305358}
David C Somayajulubee4fe82007-05-23 18:03:32 -07005359
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305360int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5361{
5362 int status = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305363 unsigned long mem_base, mem_len, db_base, db_len;
5364 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005365
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305366 status = pci_request_regions(pdev, DRIVER_NAME);
5367 if (status) {
5368 printk(KERN_WARNING
5369 "scsi(%ld) Failed to reserve PIO regions (%s) "
5370 "status=%d\n", ha->host_no, pci_name(pdev), status);
5371 goto iospace_error_exit;
5372 }
5373
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305374 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
Sergei Shtylyov7d7311c2012-03-14 22:04:30 +03005375 __func__, pdev->revision));
5376 ha->revision_id = pdev->revision;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305377
5378 /* remap phys address */
5379 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5380 mem_len = pci_resource_len(pdev, 0);
5381 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5382 __func__, mem_base, mem_len));
5383
5384 /* mapping of pcibase pointer */
5385 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5386 if (!ha->nx_pcibase) {
5387 printk(KERN_ERR
5388 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5389 pci_release_regions(ha->pdev);
5390 goto iospace_error_exit;
5391 }
5392
5393 /* Mapping of IO base pointer, door bell read and write pointer */
5394
5395 /* mapping of IO base pointer */
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005396 if (is_qla8022(ha)) {
5397 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5398 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5399 (ha->pdev->devfn << 11));
5400 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5401 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04005402 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005403 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5404 ((uint8_t *)ha->nx_pcibase);
5405 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305406
5407 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5408 db_len = pci_resource_len(pdev, 4);
5409
Shyam Sundar2657c802010-10-06 22:50:29 -07005410 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305411iospace_error_exit:
5412 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005413}
5414
5415/***
5416 * qla4xxx_iospace_config - maps registers
5417 * @ha: pointer to adapter structure
5418 *
5419 * This routines maps HBA's registers from the pci address space
5420 * into the kernel virtual address space for memory mapped i/o.
5421 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305422int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005423{
5424 unsigned long pio, pio_len, pio_flags;
5425 unsigned long mmio, mmio_len, mmio_flags;
5426
5427 pio = pci_resource_start(ha->pdev, 0);
5428 pio_len = pci_resource_len(ha->pdev, 0);
5429 pio_flags = pci_resource_flags(ha->pdev, 0);
5430 if (pio_flags & IORESOURCE_IO) {
5431 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305432 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07005433 "Invalid PCI I/O region size\n");
5434 pio = 0;
5435 }
5436 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305437 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005438 pio = 0;
5439 }
5440
5441 /* Use MMIO operations for all accesses. */
5442 mmio = pci_resource_start(ha->pdev, 1);
5443 mmio_len = pci_resource_len(ha->pdev, 1);
5444 mmio_flags = pci_resource_flags(ha->pdev, 1);
5445
5446 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305447 ql4_printk(KERN_ERR, ha,
5448 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005449
5450 goto iospace_error_exit;
5451 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305452
David Somayajuluafaf5a22006-09-19 10:28:00 -07005453 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305454 ql4_printk(KERN_ERR, ha,
5455 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005456 goto iospace_error_exit;
5457 }
5458
5459 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305460 ql4_printk(KERN_WARNING, ha,
5461 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005462
5463 goto iospace_error_exit;
5464 }
5465
5466 ha->pio_address = pio;
5467 ha->pio_length = pio_len;
5468 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5469 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305470 ql4_printk(KERN_ERR, ha,
5471 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005472
5473 goto iospace_error_exit;
5474 }
5475
5476 return 0;
5477
5478iospace_error_exit:
5479 return -ENOMEM;
5480}
5481
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305482static struct isp_operations qla4xxx_isp_ops = {
5483 .iospace_config = qla4xxx_iospace_config,
5484 .pci_config = qla4xxx_pci_config,
5485 .disable_intrs = qla4xxx_disable_intrs,
5486 .enable_intrs = qla4xxx_enable_intrs,
5487 .start_firmware = qla4xxx_start_firmware,
5488 .intr_handler = qla4xxx_intr_handler,
5489 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5490 .reset_chip = qla4xxx_soft_reset,
5491 .reset_firmware = qla4xxx_hw_reset,
5492 .queue_iocb = qla4xxx_queue_iocb,
5493 .complete_iocb = qla4xxx_complete_iocb,
5494 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5495 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5496 .get_sys_info = qla4xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005497 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5498 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305499};
5500
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005501static struct isp_operations qla4_82xx_isp_ops = {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305502 .iospace_config = qla4_8xxx_iospace_config,
5503 .pci_config = qla4_8xxx_pci_config,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005504 .disable_intrs = qla4_82xx_disable_intrs,
5505 .enable_intrs = qla4_82xx_enable_intrs,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305506 .start_firmware = qla4_8xxx_load_risc,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005507 .restart_firmware = qla4_82xx_try_start_fw,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005508 .intr_handler = qla4_82xx_intr_handler,
5509 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005510 .need_reset = qla4_8xxx_need_reset,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005511 .reset_chip = qla4_82xx_isp_reset,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305512 .reset_firmware = qla4_8xxx_stop_firmware,
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005513 .queue_iocb = qla4_82xx_queue_iocb,
5514 .complete_iocb = qla4_82xx_complete_iocb,
5515 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5516 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305517 .get_sys_info = qla4_8xxx_get_sys_info,
Vikas Chaudhary33693c72012-08-22 07:55:04 -04005518 .rd_reg_direct = qla4_82xx_rd_32,
5519 .wr_reg_direct = qla4_82xx_wr_32,
5520 .rd_reg_indirect = qla4_82xx_md_rd_32,
5521 .wr_reg_indirect = qla4_82xx_md_wr_32,
5522 .idc_lock = qla4_82xx_idc_lock,
5523 .idc_unlock = qla4_82xx_idc_unlock,
5524 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5525 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5526 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305527};
5528
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005529static struct isp_operations qla4_83xx_isp_ops = {
5530 .iospace_config = qla4_8xxx_iospace_config,
5531 .pci_config = qla4_8xxx_pci_config,
5532 .disable_intrs = qla4_83xx_disable_intrs,
5533 .enable_intrs = qla4_83xx_enable_intrs,
5534 .start_firmware = qla4_8xxx_load_risc,
5535 .restart_firmware = qla4_83xx_start_firmware,
5536 .intr_handler = qla4_83xx_intr_handler,
5537 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5538 .need_reset = qla4_8xxx_need_reset,
5539 .reset_chip = qla4_83xx_isp_reset,
5540 .reset_firmware = qla4_8xxx_stop_firmware,
5541 .queue_iocb = qla4_83xx_queue_iocb,
5542 .complete_iocb = qla4_83xx_complete_iocb,
Tej Parkasha24058f2013-03-07 05:43:13 -05005543 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5544 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04005545 .get_sys_info = qla4_8xxx_get_sys_info,
5546 .rd_reg_direct = qla4_83xx_rd_reg,
5547 .wr_reg_direct = qla4_83xx_wr_reg,
5548 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5549 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5550 .idc_lock = qla4_83xx_drv_lock,
5551 .idc_unlock = qla4_83xx_drv_unlock,
5552 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5553 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5554 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305555};
5556
5557uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5558{
5559 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5560}
5561
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005562uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305563{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005564 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305565}
5566
5567uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5568{
5569 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5570}
5571
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04005572uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305573{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04005574 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305575}
5576
Manish Rangankar2a991c22011-07-25 13:48:55 -05005577static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5578{
5579 struct scsi_qla_host *ha = data;
5580 char *str = buf;
5581 int rc;
5582
5583 switch (type) {
5584 case ISCSI_BOOT_ETH_FLAGS:
5585 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5586 break;
5587 case ISCSI_BOOT_ETH_INDEX:
5588 rc = sprintf(str, "0\n");
5589 break;
5590 case ISCSI_BOOT_ETH_MAC:
5591 rc = sysfs_format_mac(str, ha->my_mac,
5592 MAC_ADDR_LEN);
5593 break;
5594 default:
5595 rc = -ENOSYS;
5596 break;
5597 }
5598 return rc;
5599}
5600
Al Viro587a1f12011-07-23 23:11:19 -04005601static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005602{
5603 int rc;
5604
5605 switch (type) {
5606 case ISCSI_BOOT_ETH_FLAGS:
5607 case ISCSI_BOOT_ETH_MAC:
5608 case ISCSI_BOOT_ETH_INDEX:
5609 rc = S_IRUGO;
5610 break;
5611 default:
5612 rc = 0;
5613 break;
5614 }
5615 return rc;
5616}
5617
5618static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5619{
5620 struct scsi_qla_host *ha = data;
5621 char *str = buf;
5622 int rc;
5623
5624 switch (type) {
5625 case ISCSI_BOOT_INI_INITIATOR_NAME:
5626 rc = sprintf(str, "%s\n", ha->name_string);
5627 break;
5628 default:
5629 rc = -ENOSYS;
5630 break;
5631 }
5632 return rc;
5633}
5634
Al Viro587a1f12011-07-23 23:11:19 -04005635static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005636{
5637 int rc;
5638
5639 switch (type) {
5640 case ISCSI_BOOT_INI_INITIATOR_NAME:
5641 rc = S_IRUGO;
5642 break;
5643 default:
5644 rc = 0;
5645 break;
5646 }
5647 return rc;
5648}
5649
5650static ssize_t
5651qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5652 char *buf)
5653{
5654 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5655 char *str = buf;
5656 int rc;
5657
5658 switch (type) {
5659 case ISCSI_BOOT_TGT_NAME:
5660 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5661 break;
5662 case ISCSI_BOOT_TGT_IP_ADDR:
5663 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5664 rc = sprintf(buf, "%pI4\n",
5665 &boot_conn->dest_ipaddr.ip_address);
5666 else
5667 rc = sprintf(str, "%pI6\n",
5668 &boot_conn->dest_ipaddr.ip_address);
5669 break;
5670 case ISCSI_BOOT_TGT_PORT:
5671 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5672 break;
5673 case ISCSI_BOOT_TGT_CHAP_NAME:
5674 rc = sprintf(str, "%.*s\n",
5675 boot_conn->chap.target_chap_name_length,
5676 (char *)&boot_conn->chap.target_chap_name);
5677 break;
5678 case ISCSI_BOOT_TGT_CHAP_SECRET:
5679 rc = sprintf(str, "%.*s\n",
5680 boot_conn->chap.target_secret_length,
5681 (char *)&boot_conn->chap.target_secret);
5682 break;
5683 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5684 rc = sprintf(str, "%.*s\n",
5685 boot_conn->chap.intr_chap_name_length,
5686 (char *)&boot_conn->chap.intr_chap_name);
5687 break;
5688 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5689 rc = sprintf(str, "%.*s\n",
5690 boot_conn->chap.intr_secret_length,
5691 (char *)&boot_conn->chap.intr_secret);
5692 break;
5693 case ISCSI_BOOT_TGT_FLAGS:
5694 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5695 break;
5696 case ISCSI_BOOT_TGT_NIC_ASSOC:
5697 rc = sprintf(str, "0\n");
5698 break;
5699 default:
5700 rc = -ENOSYS;
5701 break;
5702 }
5703 return rc;
5704}
5705
5706static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5707{
5708 struct scsi_qla_host *ha = data;
5709 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5710
5711 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5712}
5713
5714static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5715{
5716 struct scsi_qla_host *ha = data;
5717 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5718
5719 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5720}
5721
Al Viro587a1f12011-07-23 23:11:19 -04005722static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05005723{
5724 int rc;
5725
5726 switch (type) {
5727 case ISCSI_BOOT_TGT_NAME:
5728 case ISCSI_BOOT_TGT_IP_ADDR:
5729 case ISCSI_BOOT_TGT_PORT:
5730 case ISCSI_BOOT_TGT_CHAP_NAME:
5731 case ISCSI_BOOT_TGT_CHAP_SECRET:
5732 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5733 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5734 case ISCSI_BOOT_TGT_NIC_ASSOC:
5735 case ISCSI_BOOT_TGT_FLAGS:
5736 rc = S_IRUGO;
5737 break;
5738 default:
5739 rc = 0;
5740 break;
5741 }
5742 return rc;
5743}
5744
5745static void qla4xxx_boot_release(void *data)
5746{
5747 struct scsi_qla_host *ha = data;
5748
5749 scsi_host_put(ha->host);
5750}
5751
5752static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5753{
5754 dma_addr_t buf_dma;
5755 uint32_t addr, pri_addr, sec_addr;
5756 uint32_t offset;
5757 uint16_t func_num;
5758 uint8_t val;
5759 uint8_t *buf = NULL;
5760 size_t size = 13 * sizeof(uint8_t);
5761 int ret = QLA_SUCCESS;
5762
5763 func_num = PCI_FUNC(ha->pdev->devfn);
5764
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005765 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5766 __func__, ha->pdev->device, func_num);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005767
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07005768 if (is_qla40XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005769 if (func_num == 1) {
5770 addr = NVRAM_PORT0_BOOT_MODE;
5771 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5772 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5773 } else if (func_num == 3) {
5774 addr = NVRAM_PORT1_BOOT_MODE;
5775 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5776 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5777 } else {
5778 ret = QLA_ERROR;
5779 goto exit_boot_info;
5780 }
5781
5782 /* Check Boot Mode */
5783 val = rd_nvram_byte(ha, addr);
5784 if (!(val & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305785 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5786 "options : 0x%x\n", __func__, val));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005787 ret = QLA_ERROR;
5788 goto exit_boot_info;
5789 }
5790
5791 /* get primary valid target index */
5792 val = rd_nvram_byte(ha, pri_addr);
5793 if (val & BIT_7)
5794 ddb_index[0] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005795
5796 /* get secondary valid target index */
5797 val = rd_nvram_byte(ha, sec_addr);
5798 if (val & BIT_7)
5799 ddb_index[1] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05005800
Vikas Chaudhary3e788fb2013-03-07 05:43:08 -05005801 } else if (is_qla80XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05005802 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5803 &buf_dma, GFP_KERNEL);
5804 if (!buf) {
5805 DEBUG2(ql4_printk(KERN_ERR, ha,
5806 "%s: Unable to allocate dma buffer\n",
5807 __func__));
5808 ret = QLA_ERROR;
5809 goto exit_boot_info;
5810 }
5811
5812 if (ha->port_num == 0)
5813 offset = BOOT_PARAM_OFFSET_PORT0;
5814 else if (ha->port_num == 1)
5815 offset = BOOT_PARAM_OFFSET_PORT1;
5816 else {
5817 ret = QLA_ERROR;
5818 goto exit_boot_info_free;
5819 }
5820 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5821 offset;
5822 if (qla4xxx_get_flash(ha, buf_dma, addr,
5823 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5824 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
Petr Uzel0bd7f842012-02-24 16:32:59 +01005825 " failed\n", ha->host_no, __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005826 ret = QLA_ERROR;
5827 goto exit_boot_info_free;
5828 }
5829 /* Check Boot Mode */
5830 if (!(buf[1] & 0x07)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305831 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5832 " : 0x%x\n", buf[1]));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005833 ret = QLA_ERROR;
5834 goto exit_boot_info_free;
5835 }
5836
5837 /* get primary valid target index */
5838 if (buf[2] & BIT_7)
5839 ddb_index[0] = buf[2] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005840
5841 /* get secondary valid target index */
5842 if (buf[11] & BIT_7)
5843 ddb_index[1] = buf[11] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05005844 } else {
5845 ret = QLA_ERROR;
5846 goto exit_boot_info;
5847 }
5848
5849 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5850 " target ID %d\n", __func__, ddb_index[0],
5851 ddb_index[1]));
5852
5853exit_boot_info_free:
5854 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5855exit_boot_info:
Lalit Chandivade20e835b2012-02-13 18:30:42 +05305856 ha->pri_ddb_idx = ddb_index[0];
5857 ha->sec_ddb_idx = ddb_index[1];
Manish Rangankar2a991c22011-07-25 13:48:55 -05005858 return ret;
5859}
5860
Lalit Chandivade28deb452011-10-07 16:55:44 -07005861/**
5862 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5863 * @ha: pointer to adapter structure
5864 * @username: CHAP username to be returned
5865 * @password: CHAP password to be returned
5866 *
5867 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
5868 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
5869 * So from the CHAP cache find the first BIDI CHAP entry and set it
5870 * to the boot record in sysfs.
5871 **/
5872static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
5873 char *password)
5874{
5875 int i, ret = -EINVAL;
5876 int max_chap_entries = 0;
5877 struct ql4_chap_table *chap_table;
5878
Vikas Chaudharyd11b0ca2013-03-22 07:08:31 -04005879 if (is_qla80XX(ha))
Lalit Chandivade28deb452011-10-07 16:55:44 -07005880 max_chap_entries = (ha->hw.flt_chap_size / 2) /
5881 sizeof(struct ql4_chap_table);
5882 else
5883 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
5884
5885 if (!ha->chap_list) {
5886 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
5887 return ret;
5888 }
5889
5890 mutex_lock(&ha->chap_sem);
5891 for (i = 0; i < max_chap_entries; i++) {
5892 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
5893 if (chap_table->cookie !=
5894 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
5895 continue;
5896 }
5897
5898 if (chap_table->flags & BIT_7) /* local */
5899 continue;
5900
5901 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
5902 continue;
5903
5904 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
5905 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
5906 ret = 0;
5907 break;
5908 }
5909 mutex_unlock(&ha->chap_sem);
5910
5911 return ret;
5912}
5913
5914
Manish Rangankar2a991c22011-07-25 13:48:55 -05005915static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
5916 struct ql4_boot_session_info *boot_sess,
5917 uint16_t ddb_index)
5918{
5919 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5920 struct dev_db_entry *fw_ddb_entry;
5921 dma_addr_t fw_ddb_entry_dma;
5922 uint16_t idx;
5923 uint16_t options;
5924 int ret = QLA_SUCCESS;
5925
5926 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5927 &fw_ddb_entry_dma, GFP_KERNEL);
5928 if (!fw_ddb_entry) {
5929 DEBUG2(ql4_printk(KERN_ERR, ha,
5930 "%s: Unable to allocate dma buffer.\n",
5931 __func__));
5932 ret = QLA_ERROR;
5933 return ret;
5934 }
5935
5936 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
5937 fw_ddb_entry_dma, ddb_index)) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05305938 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
5939 "index [%d]\n", __func__, ddb_index));
Manish Rangankar2a991c22011-07-25 13:48:55 -05005940 ret = QLA_ERROR;
5941 goto exit_boot_target;
5942 }
5943
5944 /* Update target name and IP from DDB */
5945 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
5946 min(sizeof(boot_sess->target_name),
5947 sizeof(fw_ddb_entry->iscsi_name)));
5948
5949 options = le16_to_cpu(fw_ddb_entry->options);
5950 if (options & DDB_OPT_IPV6_DEVICE) {
5951 memcpy(&boot_conn->dest_ipaddr.ip_address,
5952 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
5953 } else {
5954 boot_conn->dest_ipaddr.ip_type = 0x1;
5955 memcpy(&boot_conn->dest_ipaddr.ip_address,
5956 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
5957 }
5958
5959 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
5960
5961 /* update chap information */
5962 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
5963
5964 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
5965
5966 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
5967
5968 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
5969 target_chap_name,
5970 (char *)&boot_conn->chap.target_secret,
5971 idx);
5972 if (ret) {
5973 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
5974 ret = QLA_ERROR;
5975 goto exit_boot_target;
5976 }
5977
5978 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
5979 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
5980 }
5981
5982 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
5983
5984 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
5985
Lalit Chandivade28deb452011-10-07 16:55:44 -07005986 ret = qla4xxx_get_bidi_chap(ha,
5987 (char *)&boot_conn->chap.intr_chap_name,
5988 (char *)&boot_conn->chap.intr_secret);
5989
Manish Rangankar2a991c22011-07-25 13:48:55 -05005990 if (ret) {
5991 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
5992 ret = QLA_ERROR;
5993 goto exit_boot_target;
5994 }
5995
5996 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
5997 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
5998 }
5999
6000exit_boot_target:
6001 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6002 fw_ddb_entry, fw_ddb_entry_dma);
6003 return ret;
6004}
6005
6006static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6007{
6008 uint16_t ddb_index[2];
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006009 int ret = QLA_ERROR;
6010 int rval;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006011
6012 memset(ddb_index, 0, sizeof(ddb_index));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006013 ddb_index[0] = 0xffff;
6014 ddb_index[1] = 0xffff;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006015 ret = get_fw_boot_info(ha, ddb_index);
6016 if (ret != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306017 DEBUG2(ql4_printk(KERN_INFO, ha,
6018 "%s: No boot target configured.\n", __func__));
Manish Rangankar2a991c22011-07-25 13:48:55 -05006019 return ret;
6020 }
6021
Mike Christie13483732011-12-01 21:38:41 -06006022 if (ql4xdisablesysfsboot)
6023 return QLA_SUCCESS;
6024
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006025 if (ddb_index[0] == 0xffff)
6026 goto sec_target;
6027
6028 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05006029 ddb_index[0]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006030 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306031 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6032 "configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006033 } else
6034 ret = QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006035
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006036sec_target:
6037 if (ddb_index[1] == 0xffff)
6038 goto exit_get_boot_info;
6039
6040 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05006041 ddb_index[1]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006042 if (rval != QLA_SUCCESS) {
Manish Rangankare8fb00e2012-02-13 18:30:43 +05306043 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6044 " configured\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07006045 } else
6046 ret = QLA_SUCCESS;
6047
6048exit_get_boot_info:
Manish Rangankar2a991c22011-07-25 13:48:55 -05006049 return ret;
6050}
6051
6052static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6053{
6054 struct iscsi_boot_kobj *boot_kobj;
6055
6056 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
Mike Christie13483732011-12-01 21:38:41 -06006057 return QLA_ERROR;
6058
6059 if (ql4xdisablesysfsboot) {
6060 ql4_printk(KERN_INFO, ha,
Petr Uzel0bd7f842012-02-24 16:32:59 +01006061 "%s: syfsboot disabled - driver will trigger login "
Mike Christie13483732011-12-01 21:38:41 -06006062 "and publish session for discovery .\n", __func__);
6063 return QLA_SUCCESS;
6064 }
6065
Manish Rangankar2a991c22011-07-25 13:48:55 -05006066
6067 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6068 if (!ha->boot_kset)
6069 goto kset_free;
6070
6071 if (!scsi_host_get(ha->host))
6072 goto kset_free;
6073 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6074 qla4xxx_show_boot_tgt_pri_info,
6075 qla4xxx_tgt_get_attr_visibility,
6076 qla4xxx_boot_release);
6077 if (!boot_kobj)
6078 goto put_host;
6079
6080 if (!scsi_host_get(ha->host))
6081 goto kset_free;
6082 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6083 qla4xxx_show_boot_tgt_sec_info,
6084 qla4xxx_tgt_get_attr_visibility,
6085 qla4xxx_boot_release);
6086 if (!boot_kobj)
6087 goto put_host;
6088
6089 if (!scsi_host_get(ha->host))
6090 goto kset_free;
6091 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6092 qla4xxx_show_boot_ini_info,
6093 qla4xxx_ini_get_attr_visibility,
6094 qla4xxx_boot_release);
6095 if (!boot_kobj)
6096 goto put_host;
6097
6098 if (!scsi_host_get(ha->host))
6099 goto kset_free;
6100 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6101 qla4xxx_show_boot_eth_info,
6102 qla4xxx_eth_get_attr_visibility,
6103 qla4xxx_boot_release);
6104 if (!boot_kobj)
6105 goto put_host;
6106
Mike Christie13483732011-12-01 21:38:41 -06006107 return QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05006108
6109put_host:
6110 scsi_host_put(ha->host);
6111kset_free:
6112 iscsi_boot_destroy_kset(ha->boot_kset);
6113 return -ENOMEM;
6114}
6115
Lalit Chandivade45494152011-10-07 16:55:42 -07006116
6117/**
6118 * qla4xxx_create chap_list - Create CHAP list from FLASH
6119 * @ha: pointer to adapter structure
6120 *
6121 * Read flash and make a list of CHAP entries, during login when a CHAP entry
6122 * is received, it will be checked in this list. If entry exist then the CHAP
6123 * entry index is set in the DDB. If CHAP entry does not exist in this list
6124 * then a new entry is added in FLASH in CHAP table and the index obtained is
6125 * used in the DDB.
6126 **/
6127static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
6128{
6129 int rval = 0;
6130 uint8_t *chap_flash_data = NULL;
6131 uint32_t offset;
6132 dma_addr_t chap_dma;
6133 uint32_t chap_size = 0;
6134
6135 if (is_qla40XX(ha))
6136 chap_size = MAX_CHAP_ENTRIES_40XX *
6137 sizeof(struct ql4_chap_table);
6138 else /* Single region contains CHAP info for both
6139 * ports which is divided into half for each port.
6140 */
6141 chap_size = ha->hw.flt_chap_size / 2;
6142
6143 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
6144 &chap_dma, GFP_KERNEL);
6145 if (!chap_flash_data) {
6146 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
6147 return;
6148 }
6149 if (is_qla40XX(ha))
6150 offset = FLASH_CHAP_OFFSET;
6151 else {
6152 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
6153 if (ha->port_num == 1)
6154 offset += chap_size;
6155 }
6156
6157 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
6158 if (rval != QLA_SUCCESS)
6159 goto exit_chap_list;
6160
6161 if (ha->chap_list == NULL)
6162 ha->chap_list = vmalloc(chap_size);
6163 if (ha->chap_list == NULL) {
6164 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
6165 goto exit_chap_list;
6166 }
6167
6168 memcpy(ha->chap_list, chap_flash_data, chap_size);
6169
6170exit_chap_list:
6171 dma_free_coherent(&ha->pdev->dev, chap_size,
6172 chap_flash_data, chap_dma);
Lalit Chandivade45494152011-10-07 16:55:42 -07006173}
6174
Mike Christie13483732011-12-01 21:38:41 -06006175static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6176 struct ql4_tuple_ddb *tddb)
6177{
6178 struct scsi_qla_host *ha;
6179 struct iscsi_cls_session *cls_sess;
6180 struct iscsi_cls_conn *cls_conn;
6181 struct iscsi_session *sess;
6182 struct iscsi_conn *conn;
6183
6184 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6185 ha = ddb_entry->ha;
6186 cls_sess = ddb_entry->sess;
6187 sess = cls_sess->dd_data;
6188 cls_conn = ddb_entry->conn;
6189 conn = cls_conn->dd_data;
6190
6191 tddb->tpgt = sess->tpgt;
6192 tddb->port = conn->persistent_port;
6193 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6194 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6195}
6196
6197static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006198 struct ql4_tuple_ddb *tddb,
6199 uint8_t *flash_isid)
Mike Christie13483732011-12-01 21:38:41 -06006200{
6201 uint16_t options = 0;
6202
6203 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6204 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6205 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6206
6207 options = le16_to_cpu(fw_ddb_entry->options);
6208 if (options & DDB_OPT_IPV6_DEVICE)
6209 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6210 else
6211 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6212
6213 tddb->port = le16_to_cpu(fw_ddb_entry->port);
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006214
6215 if (flash_isid == NULL)
6216 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6217 sizeof(tddb->isid));
6218 else
6219 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
Mike Christie13483732011-12-01 21:38:41 -06006220}
6221
6222static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6223 struct ql4_tuple_ddb *old_tddb,
Manish Rangankar173269e2012-02-27 03:08:55 -08006224 struct ql4_tuple_ddb *new_tddb,
6225 uint8_t is_isid_compare)
Mike Christie13483732011-12-01 21:38:41 -06006226{
6227 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6228 return QLA_ERROR;
6229
6230 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6231 return QLA_ERROR;
6232
6233 if (old_tddb->port != new_tddb->port)
6234 return QLA_ERROR;
6235
Manish Rangankar173269e2012-02-27 03:08:55 -08006236 /* For multi sessions, driver generates the ISID, so do not compare
Masanari Iida59e13d42012-04-25 00:24:16 +09006237 * ISID in reset path since it would be a comparison between the
Manish Rangankar173269e2012-02-27 03:08:55 -08006238 * driver generated ISID and firmware generated ISID. This could
6239 * lead to adding duplicated DDBs in the list as driver generated
6240 * ISID would not match firmware generated ISID.
6241 */
6242 if (is_isid_compare) {
6243 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
6244 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
6245 __func__, old_tddb->isid[5], old_tddb->isid[4],
6246 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
6247 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
6248 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
6249 new_tddb->isid[0]));
6250
6251 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6252 sizeof(old_tddb->isid)))
6253 return QLA_ERROR;
6254 }
6255
Mike Christie13483732011-12-01 21:38:41 -06006256 DEBUG2(ql4_printk(KERN_INFO, ha,
6257 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6258 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6259 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6260 new_tddb->ip_addr, new_tddb->iscsi_name));
6261
6262 return QLA_SUCCESS;
6263}
6264
6265static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006266 struct dev_db_entry *fw_ddb_entry,
6267 uint32_t *index)
Mike Christie13483732011-12-01 21:38:41 -06006268{
6269 struct ddb_entry *ddb_entry;
6270 struct ql4_tuple_ddb *fw_tddb = NULL;
6271 struct ql4_tuple_ddb *tmp_tddb = NULL;
6272 int idx;
6273 int ret = QLA_ERROR;
6274
6275 fw_tddb = vzalloc(sizeof(*fw_tddb));
6276 if (!fw_tddb) {
6277 DEBUG2(ql4_printk(KERN_WARNING, ha,
6278 "Memory Allocation failed.\n"));
6279 ret = QLA_SUCCESS;
6280 goto exit_check;
6281 }
6282
6283 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6284 if (!tmp_tddb) {
6285 DEBUG2(ql4_printk(KERN_WARNING, ha,
6286 "Memory Allocation failed.\n"));
6287 ret = QLA_SUCCESS;
6288 goto exit_check;
6289 }
6290
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006291 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006292
6293 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6294 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6295 if (ddb_entry == NULL)
6296 continue;
6297
6298 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
Manish Rangankar173269e2012-02-27 03:08:55 -08006299 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
Mike Christie13483732011-12-01 21:38:41 -06006300 ret = QLA_SUCCESS; /* found */
Manish Rangankarad8bd452013-09-17 07:30:02 -04006301 if (index != NULL)
6302 *index = idx;
Mike Christie13483732011-12-01 21:38:41 -06006303 goto exit_check;
6304 }
6305 }
6306
6307exit_check:
6308 if (fw_tddb)
6309 vfree(fw_tddb);
6310 if (tmp_tddb)
6311 vfree(tmp_tddb);
6312 return ret;
6313}
6314
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006315/**
6316 * qla4xxx_check_existing_isid - check if target with same isid exist
6317 * in target list
6318 * @list_nt: list of target
6319 * @isid: isid to check
6320 *
6321 * This routine return QLA_SUCCESS if target with same isid exist
6322 **/
6323static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6324{
6325 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6326 struct dev_db_entry *fw_ddb_entry;
6327
6328 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6329 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6330
6331 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6332 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6333 return QLA_SUCCESS;
6334 }
6335 }
6336 return QLA_ERROR;
6337}
6338
6339/**
6340 * qla4xxx_update_isid - compare ddbs and updated isid
6341 * @ha: Pointer to host adapter structure.
6342 * @list_nt: list of nt target
6343 * @fw_ddb_entry: firmware ddb entry
6344 *
6345 * This routine update isid if ddbs have same iqn, same isid and
6346 * different IP addr.
6347 * Return QLA_SUCCESS if isid is updated.
6348 **/
6349static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6350 struct list_head *list_nt,
6351 struct dev_db_entry *fw_ddb_entry)
6352{
6353 uint8_t base_value, i;
6354
6355 base_value = fw_ddb_entry->isid[1] & 0x1f;
6356 for (i = 0; i < 8; i++) {
6357 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6358 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6359 break;
6360 }
6361
6362 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6363 return QLA_ERROR;
6364
6365 return QLA_SUCCESS;
6366}
6367
6368/**
6369 * qla4xxx_should_update_isid - check if isid need to update
6370 * @ha: Pointer to host adapter structure.
6371 * @old_tddb: ddb tuple
6372 * @new_tddb: ddb tuple
6373 *
6374 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6375 * same isid
6376 **/
6377static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6378 struct ql4_tuple_ddb *old_tddb,
6379 struct ql4_tuple_ddb *new_tddb)
6380{
6381 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6382 /* Same ip */
6383 if (old_tddb->port == new_tddb->port)
6384 return QLA_ERROR;
6385 }
6386
6387 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6388 /* different iqn */
6389 return QLA_ERROR;
6390
6391 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6392 sizeof(old_tddb->isid)))
6393 /* different isid */
6394 return QLA_ERROR;
6395
6396 return QLA_SUCCESS;
6397}
6398
6399/**
6400 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6401 * @ha: Pointer to host adapter structure.
6402 * @list_nt: list of nt target.
6403 * @fw_ddb_entry: firmware ddb entry.
6404 *
6405 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6406 * duplicate ddb in list_nt.
6407 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6408 * Note: This function also update isid of DDB if required.
6409 **/
6410
Mike Christie13483732011-12-01 21:38:41 -06006411static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6412 struct list_head *list_nt,
6413 struct dev_db_entry *fw_ddb_entry)
6414{
6415 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6416 struct ql4_tuple_ddb *fw_tddb = NULL;
6417 struct ql4_tuple_ddb *tmp_tddb = NULL;
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006418 int rval, ret = QLA_ERROR;
Mike Christie13483732011-12-01 21:38:41 -06006419
6420 fw_tddb = vzalloc(sizeof(*fw_tddb));
6421 if (!fw_tddb) {
6422 DEBUG2(ql4_printk(KERN_WARNING, ha,
6423 "Memory Allocation failed.\n"));
6424 ret = QLA_SUCCESS;
6425 goto exit_check;
6426 }
6427
6428 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6429 if (!tmp_tddb) {
6430 DEBUG2(ql4_printk(KERN_WARNING, ha,
6431 "Memory Allocation failed.\n"));
6432 ret = QLA_SUCCESS;
6433 goto exit_check;
6434 }
6435
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006436 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
Mike Christie13483732011-12-01 21:38:41 -06006437
6438 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006439 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6440 nt_ddb_idx->flash_isid);
6441 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6442 /* found duplicate ddb */
6443 if (ret == QLA_SUCCESS)
6444 goto exit_check;
6445 }
6446
6447 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6448 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6449
6450 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6451 if (ret == QLA_SUCCESS) {
6452 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6453 if (rval == QLA_SUCCESS)
6454 ret = QLA_ERROR;
6455 else
6456 ret = QLA_SUCCESS;
6457
Mike Christie13483732011-12-01 21:38:41 -06006458 goto exit_check;
6459 }
6460 }
6461
6462exit_check:
6463 if (fw_tddb)
6464 vfree(fw_tddb);
6465 if (tmp_tddb)
6466 vfree(tmp_tddb);
6467 return ret;
6468}
6469
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006470static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
Mike Christie13483732011-12-01 21:38:41 -06006471{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006472 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
Mike Christie13483732011-12-01 21:38:41 -06006473
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006474 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6475 list_del_init(&ddb_idx->list);
6476 vfree(ddb_idx);
Mike Christie13483732011-12-01 21:38:41 -06006477 }
Mike Christie13483732011-12-01 21:38:41 -06006478}
6479
6480static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6481 struct dev_db_entry *fw_ddb_entry)
6482{
6483 struct iscsi_endpoint *ep;
6484 struct sockaddr_in *addr;
6485 struct sockaddr_in6 *addr6;
Manish Rangankar3dd48492012-11-23 06:58:40 -05006486 struct sockaddr *t_addr;
6487 struct sockaddr_storage *dst_addr;
Mike Christie13483732011-12-01 21:38:41 -06006488 char *ip;
6489
6490 /* TODO: need to destroy on unload iscsi_endpoint*/
6491 dst_addr = vmalloc(sizeof(*dst_addr));
6492 if (!dst_addr)
6493 return NULL;
6494
6495 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006496 t_addr = (struct sockaddr *)dst_addr;
6497 t_addr->sa_family = AF_INET6;
Mike Christie13483732011-12-01 21:38:41 -06006498 addr6 = (struct sockaddr_in6 *)dst_addr;
6499 ip = (char *)&addr6->sin6_addr;
6500 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6501 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6502
6503 } else {
Manish Rangankar3dd48492012-11-23 06:58:40 -05006504 t_addr = (struct sockaddr *)dst_addr;
6505 t_addr->sa_family = AF_INET;
Mike Christie13483732011-12-01 21:38:41 -06006506 addr = (struct sockaddr_in *)dst_addr;
6507 ip = (char *)&addr->sin_addr;
6508 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6509 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6510 }
6511
Manish Rangankar3dd48492012-11-23 06:58:40 -05006512 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
Mike Christie13483732011-12-01 21:38:41 -06006513 vfree(dst_addr);
6514 return ep;
6515}
6516
6517static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6518{
6519 if (ql4xdisablesysfsboot)
6520 return QLA_SUCCESS;
6521 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6522 return QLA_ERROR;
6523 return QLA_SUCCESS;
6524}
6525
6526static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006527 struct ddb_entry *ddb_entry,
6528 uint16_t idx)
Mike Christie13483732011-12-01 21:38:41 -06006529{
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006530 uint16_t def_timeout;
6531
Mike Christie13483732011-12-01 21:38:41 -06006532 ddb_entry->ddb_type = FLASH_DDB;
6533 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6534 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6535 ddb_entry->ha = ha;
6536 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6537 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
Adheer Chandravanshi946ac572013-09-17 07:54:46 -04006538 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
Mike Christie13483732011-12-01 21:38:41 -06006539
6540 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6541 atomic_set(&ddb_entry->relogin_timer, 0);
6542 atomic_set(&ddb_entry->relogin_retry_count, 0);
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006543 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06006544 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08006545 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6546 def_timeout : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06006547 ddb_entry->default_time2wait =
6548 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006549
6550 if (ql4xdisablesysfsboot &&
6551 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6552 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
Mike Christie13483732011-12-01 21:38:41 -06006553}
6554
6555static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6556{
6557 uint32_t idx = 0;
6558 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6559 uint32_t sts[MBOX_REG_COUNT];
6560 uint32_t ip_state;
6561 unsigned long wtime;
6562 int ret;
6563
6564 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6565 do {
6566 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6567 if (ip_idx[idx] == -1)
6568 continue;
6569
6570 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6571
6572 if (ret == QLA_ERROR) {
6573 ip_idx[idx] = -1;
6574 continue;
6575 }
6576
6577 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6578
6579 DEBUG2(ql4_printk(KERN_INFO, ha,
6580 "Waiting for IP state for idx = %d, state = 0x%x\n",
6581 ip_idx[idx], ip_state));
6582 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6583 ip_state == IP_ADDRSTATE_INVALID ||
6584 ip_state == IP_ADDRSTATE_PREFERRED ||
6585 ip_state == IP_ADDRSTATE_DEPRICATED ||
6586 ip_state == IP_ADDRSTATE_DISABLING)
6587 ip_idx[idx] = -1;
Mike Christie13483732011-12-01 21:38:41 -06006588 }
6589
6590 /* Break if all IP states checked */
6591 if ((ip_idx[0] == -1) &&
6592 (ip_idx[1] == -1) &&
6593 (ip_idx[2] == -1) &&
6594 (ip_idx[3] == -1))
6595 break;
6596 schedule_timeout_uninterruptible(HZ);
6597 } while (time_after(wtime, jiffies));
6598}
6599
Manish Rangankarad8bd452013-09-17 07:30:02 -04006600static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6601 struct dev_db_entry *flash_ddb_entry)
6602{
6603 uint16_t options = 0;
6604 size_t ip_len = IP_ADDR_LEN;
6605
6606 options = le16_to_cpu(fw_ddb_entry->options);
6607 if (options & DDB_OPT_IPV6_DEVICE)
6608 ip_len = IPv6_ADDR_LEN;
6609
6610 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6611 return QLA_ERROR;
6612
6613 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6614 sizeof(fw_ddb_entry->isid)))
6615 return QLA_ERROR;
6616
6617 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6618 sizeof(fw_ddb_entry->port)))
6619 return QLA_ERROR;
6620
6621 return QLA_SUCCESS;
6622}
6623
6624static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6625 struct dev_db_entry *fw_ddb_entry,
6626 uint32_t fw_idx, uint32_t *flash_index)
6627{
6628 struct dev_db_entry *flash_ddb_entry;
6629 dma_addr_t flash_ddb_entry_dma;
6630 uint32_t idx = 0;
6631 int max_ddbs;
6632 int ret = QLA_ERROR, status;
6633
6634 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6635 MAX_DEV_DB_ENTRIES;
6636
6637 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6638 &flash_ddb_entry_dma);
6639 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6640 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6641 goto exit_find_st_idx;
6642 }
6643
6644 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6645 flash_ddb_entry_dma, fw_idx);
6646 if (status == QLA_SUCCESS) {
6647 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6648 if (status == QLA_SUCCESS) {
6649 *flash_index = fw_idx;
6650 ret = QLA_SUCCESS;
6651 goto exit_find_st_idx;
6652 }
6653 }
6654
6655 for (idx = 0; idx < max_ddbs; idx++) {
6656 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6657 flash_ddb_entry_dma, idx);
6658 if (status == QLA_ERROR)
6659 continue;
6660
6661 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6662 if (status == QLA_SUCCESS) {
6663 *flash_index = idx;
6664 ret = QLA_SUCCESS;
6665 goto exit_find_st_idx;
6666 }
6667 }
6668
6669 if (idx == max_ddbs)
6670 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6671 fw_idx);
6672
6673exit_find_st_idx:
6674 if (flash_ddb_entry)
6675 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6676 flash_ddb_entry_dma);
6677
6678 return ret;
6679}
6680
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006681static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6682 struct list_head *list_st)
Mike Christie13483732011-12-01 21:38:41 -06006683{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006684 struct qla_ddb_index *st_ddb_idx;
Mike Christie13483732011-12-01 21:38:41 -06006685 int max_ddbs;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006686 int fw_idx_size;
6687 struct dev_db_entry *fw_ddb_entry;
6688 dma_addr_t fw_ddb_dma;
Mike Christie13483732011-12-01 21:38:41 -06006689 int ret;
6690 uint32_t idx = 0, next_idx = 0;
6691 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006692 uint32_t flash_index = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006693 uint16_t conn_id = 0;
Mike Christie13483732011-12-01 21:38:41 -06006694
6695 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6696 &fw_ddb_dma);
6697 if (fw_ddb_entry == NULL) {
6698 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006699 goto exit_st_list;
Mike Christie13483732011-12-01 21:38:41 -06006700 }
6701
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006702 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6703 MAX_DEV_DB_ENTRIES;
Mike Christie13483732011-12-01 21:38:41 -06006704 fw_idx_size = sizeof(struct qla_ddb_index);
6705
6706 for (idx = 0; idx < max_ddbs; idx = next_idx) {
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006707 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6708 NULL, &next_idx, &state,
6709 &conn_err, NULL, &conn_id);
Mike Christie13483732011-12-01 21:38:41 -06006710 if (ret == QLA_ERROR)
6711 break;
6712
Lalit Chandivade981c9822012-02-13 18:30:41 +05306713 /* Ignore DDB if invalid state (unassigned) */
6714 if (state == DDB_DS_UNASSIGNED)
6715 goto continue_next_st;
6716
Mike Christie13483732011-12-01 21:38:41 -06006717 /* Check if ST, add to the list_st */
6718 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6719 goto continue_next_st;
6720
6721 st_ddb_idx = vzalloc(fw_idx_size);
6722 if (!st_ddb_idx)
6723 break;
6724
Manish Rangankarad8bd452013-09-17 07:30:02 -04006725 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6726 &flash_index);
6727 if (ret == QLA_ERROR) {
6728 ql4_printk(KERN_ERR, ha,
6729 "No flash entry for ST at idx [%d]\n", idx);
6730 st_ddb_idx->flash_ddb_idx = idx;
6731 } else {
6732 ql4_printk(KERN_INFO, ha,
6733 "ST at idx [%d] is stored at flash [%d]\n",
6734 idx, flash_index);
6735 st_ddb_idx->flash_ddb_idx = flash_index;
6736 }
6737
Mike Christie13483732011-12-01 21:38:41 -06006738 st_ddb_idx->fw_ddb_idx = idx;
6739
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006740 list_add_tail(&st_ddb_idx->list, list_st);
Mike Christie13483732011-12-01 21:38:41 -06006741continue_next_st:
6742 if (next_idx == 0)
6743 break;
6744 }
6745
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006746exit_st_list:
6747 if (fw_ddb_entry)
6748 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6749}
6750
6751/**
6752 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6753 * @ha: pointer to adapter structure
6754 * @list_ddb: List from which failed ddb to be removed
6755 *
6756 * Iterate over the list of DDBs and find and remove DDBs that are either in
6757 * no connection active state or failed state
6758 **/
6759static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6760 struct list_head *list_ddb)
6761{
6762 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6763 uint32_t next_idx = 0;
6764 uint32_t state = 0, conn_err = 0;
6765 int ret;
6766
6767 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6768 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6769 NULL, 0, NULL, &next_idx, &state,
6770 &conn_err, NULL, NULL);
6771 if (ret == QLA_ERROR)
6772 continue;
6773
6774 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6775 state == DDB_DS_SESSION_FAILED) {
6776 list_del_init(&ddb_idx->list);
6777 vfree(ddb_idx);
6778 }
6779 }
6780}
6781
Manish Rangankarad8bd452013-09-17 07:30:02 -04006782static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6783 struct ddb_entry *ddb_entry,
6784 struct dev_db_entry *fw_ddb_entry)
6785{
6786 struct iscsi_cls_session *cls_sess;
6787 struct iscsi_session *sess;
6788 uint32_t max_ddbs = 0;
6789 uint16_t ddb_link = -1;
6790
6791 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6792 MAX_DEV_DB_ENTRIES;
6793
6794 cls_sess = ddb_entry->sess;
6795 sess = cls_sess->dd_data;
6796
6797 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6798 if (ddb_link < max_ddbs)
6799 sess->discovery_parent_idx = ddb_link;
6800 else
6801 sess->discovery_parent_idx = DDB_NO_LINK;
6802}
6803
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006804static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6805 struct dev_db_entry *fw_ddb_entry,
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006806 int is_reset, uint16_t idx)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006807{
6808 struct iscsi_cls_session *cls_sess;
6809 struct iscsi_session *sess;
6810 struct iscsi_cls_conn *cls_conn;
6811 struct iscsi_endpoint *ep;
6812 uint16_t cmds_max = 32;
6813 uint16_t conn_id = 0;
6814 uint32_t initial_cmdsn = 0;
6815 int ret = QLA_SUCCESS;
6816
6817 struct ddb_entry *ddb_entry = NULL;
6818
6819 /* Create session object, with INVALID_ENTRY,
6820 * the targer_id would get set when we issue the login
6821 */
6822 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6823 cmds_max, sizeof(struct ddb_entry),
6824 sizeof(struct ql4_task_data),
6825 initial_cmdsn, INVALID_ENTRY);
6826 if (!cls_sess) {
6827 ret = QLA_ERROR;
6828 goto exit_setup;
6829 }
6830
6831 /*
6832 * so calling module_put function to decrement the
6833 * reference count.
6834 **/
6835 module_put(qla4xxx_iscsi_transport.owner);
6836 sess = cls_sess->dd_data;
6837 ddb_entry = sess->dd_data;
6838 ddb_entry->sess = cls_sess;
6839
6840 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6841 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6842 sizeof(struct dev_db_entry));
6843
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05006844 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006845
6846 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6847
6848 if (!cls_conn) {
6849 ret = QLA_ERROR;
6850 goto exit_setup;
6851 }
6852
6853 ddb_entry->conn = cls_conn;
6854
6855 /* Setup ep, for displaying attributes in sysfs */
6856 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6857 if (ep) {
6858 ep->conn = cls_conn;
6859 cls_conn->ep = ep;
6860 } else {
6861 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6862 ret = QLA_ERROR;
6863 goto exit_setup;
6864 }
6865
6866 /* Update sess/conn params */
6867 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
Manish Rangankarad8bd452013-09-17 07:30:02 -04006868 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006869
6870 if (is_reset == RESET_ADAPTER) {
6871 iscsi_block_session(cls_sess);
6872 /* Use the relogin path to discover new devices
6873 * by short-circuting the logic of setting
6874 * timer to relogin - instead set the flags
6875 * to initiate login right away.
6876 */
6877 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6878 set_bit(DF_RELOGIN, &ddb_entry->flags);
6879 }
6880
6881exit_setup:
6882 return ret;
6883}
6884
Manish Rangankarad8bd452013-09-17 07:30:02 -04006885static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6886 struct list_head *list_ddb,
6887 struct dev_db_entry *fw_ddb_entry)
6888{
6889 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6890 uint16_t ddb_link;
6891
6892 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6893
6894 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6895 if (ddb_idx->fw_ddb_idx == ddb_link) {
6896 DEBUG2(ql4_printk(KERN_INFO, ha,
6897 "Updating NT parent idx from [%d] to [%d]\n",
6898 ddb_link, ddb_idx->flash_ddb_idx));
6899 fw_ddb_entry->ddb_link =
6900 cpu_to_le16(ddb_idx->flash_ddb_idx);
6901 return;
6902 }
6903 }
6904}
6905
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006906static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04006907 struct list_head *list_nt,
6908 struct list_head *list_st,
6909 int is_reset)
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006910{
6911 struct dev_db_entry *fw_ddb_entry;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006912 struct ddb_entry *ddb_entry = NULL;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006913 dma_addr_t fw_ddb_dma;
6914 int max_ddbs;
6915 int fw_idx_size;
6916 int ret;
6917 uint32_t idx = 0, next_idx = 0;
6918 uint32_t state = 0, conn_err = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006919 uint32_t ddb_idx = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006920 uint16_t conn_id = 0;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006921 uint16_t ddb_link = -1;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006922 struct qla_ddb_index *nt_ddb_idx;
6923
6924 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6925 &fw_ddb_dma);
6926 if (fw_ddb_entry == NULL) {
6927 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6928 goto exit_nt_list;
6929 }
6930 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6931 MAX_DEV_DB_ENTRIES;
6932 fw_idx_size = sizeof(struct qla_ddb_index);
6933
6934 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6935 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6936 NULL, &next_idx, &state,
6937 &conn_err, NULL, &conn_id);
6938 if (ret == QLA_ERROR)
6939 break;
6940
6941 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
6942 goto continue_next_nt;
6943
6944 /* Check if NT, then add to list it */
6945 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
6946 goto continue_next_nt;
6947
Manish Rangankarad8bd452013-09-17 07:30:02 -04006948 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6949 if (ddb_link < max_ddbs)
6950 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
6951
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006952 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
Manish Rangankarad8bd452013-09-17 07:30:02 -04006953 state == DDB_DS_SESSION_FAILED) &&
6954 (is_reset == INIT_ADAPTER))
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006955 goto continue_next_nt;
6956
6957 DEBUG2(ql4_printk(KERN_INFO, ha,
6958 "Adding DDB to session = 0x%x\n", idx));
Manish Rangankarad8bd452013-09-17 07:30:02 -04006959
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006960 if (is_reset == INIT_ADAPTER) {
6961 nt_ddb_idx = vmalloc(fw_idx_size);
6962 if (!nt_ddb_idx)
6963 break;
6964
6965 nt_ddb_idx->fw_ddb_idx = idx;
6966
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006967 /* Copy original isid as it may get updated in function
6968 * qla4xxx_update_isid(). We need original isid in
6969 * function qla4xxx_compare_tuple_ddb to find duplicate
6970 * target */
6971 memcpy(&nt_ddb_idx->flash_isid[0],
6972 &fw_ddb_entry->isid[0],
6973 sizeof(nt_ddb_idx->flash_isid));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006974
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006975 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
6976 fw_ddb_entry);
6977 if (ret == QLA_SUCCESS) {
6978 /* free nt_ddb_idx and do not add to list_nt */
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006979 vfree(nt_ddb_idx);
6980 goto continue_next_nt;
6981 }
Vikas Chaudhary1cb78d72012-06-14 06:35:48 -04006982
6983 /* Copy updated isid */
6984 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
6985 sizeof(struct dev_db_entry));
6986
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006987 list_add_tail(&nt_ddb_idx->list, list_nt);
6988 } else if (is_reset == RESET_ADAPTER) {
Manish Rangankarad8bd452013-09-17 07:30:02 -04006989 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
6990 &ddb_idx);
6991 if (ret == QLA_SUCCESS) {
6992 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
6993 ddb_idx);
6994 if (ddb_entry != NULL)
6995 qla4xxx_update_sess_disc_idx(ha,
6996 ddb_entry,
6997 fw_ddb_entry);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08006998 goto continue_next_nt;
Manish Rangankarad8bd452013-09-17 07:30:02 -04006999 }
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007000 }
7001
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05007002 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08007003 if (ret == QLA_ERROR)
7004 goto exit_nt_list;
7005
7006continue_next_nt:
7007 if (next_idx == 0)
7008 break;
7009 }
7010
7011exit_nt_list:
7012 if (fw_ddb_entry)
7013 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7014}
7015
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007016static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007017 struct list_head *list_nt,
7018 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007019{
7020 struct dev_db_entry *fw_ddb_entry;
7021 dma_addr_t fw_ddb_dma;
7022 int max_ddbs;
7023 int fw_idx_size;
7024 int ret;
7025 uint32_t idx = 0, next_idx = 0;
7026 uint32_t state = 0, conn_err = 0;
7027 uint16_t conn_id = 0;
7028 struct qla_ddb_index *nt_ddb_idx;
7029
7030 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7031 &fw_ddb_dma);
7032 if (fw_ddb_entry == NULL) {
7033 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7034 goto exit_new_nt_list;
7035 }
7036 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7037 MAX_DEV_DB_ENTRIES;
7038 fw_idx_size = sizeof(struct qla_ddb_index);
7039
7040 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7041 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7042 NULL, &next_idx, &state,
7043 &conn_err, NULL, &conn_id);
7044 if (ret == QLA_ERROR)
7045 break;
7046
7047 /* Check if NT, then add it to list */
7048 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7049 goto continue_next_new_nt;
7050
7051 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7052 goto continue_next_new_nt;
7053
7054 DEBUG2(ql4_printk(KERN_INFO, ha,
7055 "Adding DDB to session = 0x%x\n", idx));
7056
7057 nt_ddb_idx = vmalloc(fw_idx_size);
7058 if (!nt_ddb_idx)
7059 break;
7060
7061 nt_ddb_idx->fw_ddb_idx = idx;
7062
Manish Rangankarad8bd452013-09-17 07:30:02 -04007063 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007064 if (ret == QLA_SUCCESS) {
7065 /* free nt_ddb_idx and do not add to list_nt */
7066 vfree(nt_ddb_idx);
7067 goto continue_next_new_nt;
7068 }
7069
Manish Rangankarad8bd452013-09-17 07:30:02 -04007070 if (target_id < max_ddbs)
7071 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7072
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007073 list_add_tail(&nt_ddb_idx->list, list_nt);
7074
7075 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7076 idx);
7077 if (ret == QLA_ERROR)
7078 goto exit_new_nt_list;
7079
7080continue_next_new_nt:
7081 if (next_idx == 0)
7082 break;
7083 }
7084
7085exit_new_nt_list:
7086 if (fw_ddb_entry)
7087 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7088}
7089
7090/**
7091 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7092 * @dev: dev associated with the sysfs entry
7093 * @data: pointer to flashnode session object
7094 *
7095 * Returns:
7096 * 1: if flashnode entry is non-persistent
7097 * 0: if flashnode entry is persistent
7098 **/
7099static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7100{
7101 struct iscsi_bus_flash_session *fnode_sess;
7102
7103 if (!iscsi_flashnode_bus_match(dev, NULL))
7104 return 0;
7105
7106 fnode_sess = iscsi_dev_to_flash_session(dev);
7107
7108 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7109}
7110
7111/**
7112 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7113 * @ha: pointer to host
7114 * @fw_ddb_entry: flash ddb data
7115 * @idx: target index
7116 * @user: if set then this call is made from userland else from kernel
7117 *
7118 * Returns:
7119 * On sucess: QLA_SUCCESS
7120 * On failure: QLA_ERROR
7121 *
7122 * This create separate sysfs entries for session and connection attributes of
7123 * the given fw ddb entry.
7124 * If this is invoked as a result of a userspace call then the entry is marked
7125 * as nonpersistent using flash_state field.
7126 **/
Vikas Chaudhary28e02f12013-04-17 05:15:27 -04007127static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7128 struct dev_db_entry *fw_ddb_entry,
7129 uint16_t *idx, int user)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007130{
7131 struct iscsi_bus_flash_session *fnode_sess = NULL;
7132 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7133 int rc = QLA_ERROR;
7134
7135 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7136 &qla4xxx_iscsi_transport, 0);
7137 if (!fnode_sess) {
7138 ql4_printk(KERN_ERR, ha,
7139 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7140 __func__, *idx, ha->host_no);
7141 goto exit_tgt_create;
7142 }
7143
7144 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7145 &qla4xxx_iscsi_transport, 0);
7146 if (!fnode_conn) {
7147 ql4_printk(KERN_ERR, ha,
7148 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7149 __func__, *idx, ha->host_no);
7150 goto free_sess;
7151 }
7152
7153 if (user) {
7154 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7155 } else {
7156 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7157
7158 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7159 fnode_sess->is_boot_target = 1;
7160 else
7161 fnode_sess->is_boot_target = 0;
7162 }
7163
7164 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7165 fw_ddb_entry);
7166
7167 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7168 __func__, fnode_sess->dev.kobj.name);
7169
7170 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7171 __func__, fnode_conn->dev.kobj.name);
7172
7173 return QLA_SUCCESS;
7174
7175free_sess:
7176 iscsi_destroy_flashnode_sess(fnode_sess);
7177
7178exit_tgt_create:
7179 return QLA_ERROR;
7180}
7181
7182/**
7183 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7184 * @shost: pointer to host
7185 * @buf: type of ddb entry (ipv4/ipv6)
7186 * @len: length of buf
7187 *
7188 * This creates new ddb entry in the flash by finding first free index and
7189 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7190 **/
7191static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7192 int len)
7193{
7194 struct scsi_qla_host *ha = to_qla_host(shost);
7195 struct dev_db_entry *fw_ddb_entry = NULL;
7196 dma_addr_t fw_ddb_entry_dma;
7197 struct device *dev;
7198 uint16_t idx = 0;
7199 uint16_t max_ddbs = 0;
7200 uint32_t options = 0;
7201 uint32_t rval = QLA_ERROR;
7202
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007203 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7204 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007205 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7206 __func__));
7207 goto exit_ddb_add;
7208 }
7209
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04007210 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007211 MAX_DEV_DB_ENTRIES;
7212
7213 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7214 &fw_ddb_entry_dma, GFP_KERNEL);
7215 if (!fw_ddb_entry) {
7216 DEBUG2(ql4_printk(KERN_ERR, ha,
7217 "%s: Unable to allocate dma buffer\n",
7218 __func__));
7219 goto exit_ddb_add;
7220 }
7221
7222 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7223 qla4xxx_sysfs_ddb_is_non_persistent);
7224 if (dev) {
7225 ql4_printk(KERN_ERR, ha,
7226 "%s: A non-persistent entry %s found\n",
7227 __func__, dev->kobj.name);
Mike Christie8526cb12013-05-06 12:06:56 -05007228 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007229 goto exit_ddb_add;
7230 }
7231
Adheer Chandravanshi99937572013-07-08 08:33:09 -04007232 /* Index 0 and 1 are reserved for boot target entries */
7233 for (idx = 2; idx < max_ddbs; idx++) {
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007234 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7235 fw_ddb_entry_dma, idx))
7236 break;
7237 }
7238
7239 if (idx == max_ddbs)
7240 goto exit_ddb_add;
7241
7242 if (!strncasecmp("ipv6", buf, 4))
7243 options |= IPV6_DEFAULT_DDB_ENTRY;
7244
7245 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7246 if (rval == QLA_ERROR)
7247 goto exit_ddb_add;
7248
7249 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7250
7251exit_ddb_add:
7252 if (fw_ddb_entry)
7253 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7254 fw_ddb_entry, fw_ddb_entry_dma);
7255 if (rval == QLA_SUCCESS)
7256 return idx;
7257 else
7258 return -EIO;
7259}
7260
7261/**
7262 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7263 * @fnode_sess: pointer to session attrs of flash ddb entry
7264 * @fnode_conn: pointer to connection attrs of flash ddb entry
7265 *
7266 * This writes the contents of target ddb buffer to Flash with a valid cookie
7267 * value in order to make the ddb entry persistent.
7268 **/
7269static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7270 struct iscsi_bus_flash_conn *fnode_conn)
7271{
7272 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7273 struct scsi_qla_host *ha = to_qla_host(shost);
7274 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7275 struct dev_db_entry *fw_ddb_entry = NULL;
7276 dma_addr_t fw_ddb_entry_dma;
7277 uint32_t options = 0;
7278 int rval = 0;
7279
7280 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7281 &fw_ddb_entry_dma, GFP_KERNEL);
7282 if (!fw_ddb_entry) {
7283 DEBUG2(ql4_printk(KERN_ERR, ha,
7284 "%s: Unable to allocate dma buffer\n",
7285 __func__));
7286 rval = -ENOMEM;
7287 goto exit_ddb_apply;
7288 }
7289
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007290 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007291 options |= IPV6_DEFAULT_DDB_ENTRY;
7292
7293 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7294 if (rval == QLA_ERROR)
7295 goto exit_ddb_apply;
7296
7297 dev_db_start_offset += (fnode_sess->target_id *
7298 sizeof(*fw_ddb_entry));
7299
7300 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7301 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7302
7303 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7304 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7305
7306 if (rval == QLA_SUCCESS) {
7307 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7308 ql4_printk(KERN_INFO, ha,
7309 "%s: flash node %u of host %lu written to flash\n",
7310 __func__, fnode_sess->target_id, ha->host_no);
7311 } else {
7312 rval = -EIO;
7313 ql4_printk(KERN_ERR, ha,
7314 "%s: Error while writing flash node %u of host %lu to flash\n",
7315 __func__, fnode_sess->target_id, ha->host_no);
7316 }
7317
7318exit_ddb_apply:
7319 if (fw_ddb_entry)
7320 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7321 fw_ddb_entry, fw_ddb_entry_dma);
7322 return rval;
7323}
7324
7325static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7326 struct dev_db_entry *fw_ddb_entry,
7327 uint16_t idx)
7328{
7329 struct dev_db_entry *ddb_entry = NULL;
7330 dma_addr_t ddb_entry_dma;
7331 unsigned long wtime;
7332 uint32_t mbx_sts = 0;
7333 uint32_t state = 0, conn_err = 0;
7334 uint16_t tmo = 0;
7335 int ret = 0;
7336
7337 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7338 &ddb_entry_dma, GFP_KERNEL);
7339 if (!ddb_entry) {
7340 DEBUG2(ql4_printk(KERN_ERR, ha,
7341 "%s: Unable to allocate dma buffer\n",
7342 __func__));
7343 return QLA_ERROR;
7344 }
7345
7346 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7347
7348 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7349 if (ret != QLA_SUCCESS) {
7350 DEBUG2(ql4_printk(KERN_ERR, ha,
7351 "%s: Unable to set ddb entry for index %d\n",
7352 __func__, idx));
7353 goto exit_ddb_conn_open;
7354 }
7355
7356 qla4xxx_conn_open(ha, idx);
7357
7358 /* To ensure that sendtargets is done, wait for at least 12 secs */
7359 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7360 (ha->def_timeout < LOGIN_TOV * 10) ?
7361 ha->def_timeout : LOGIN_TOV);
7362
7363 DEBUG2(ql4_printk(KERN_INFO, ha,
7364 "Default time to wait for login to ddb %d\n", tmo));
7365
7366 wtime = jiffies + (HZ * tmo);
7367 do {
7368 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7369 NULL, &state, &conn_err, NULL,
7370 NULL);
7371 if (ret == QLA_ERROR)
7372 continue;
7373
7374 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7375 state == DDB_DS_SESSION_FAILED)
7376 break;
7377
7378 schedule_timeout_uninterruptible(HZ / 10);
7379 } while (time_after(wtime, jiffies));
7380
7381exit_ddb_conn_open:
7382 if (ddb_entry)
7383 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7384 ddb_entry, ddb_entry_dma);
7385 return ret;
7386}
7387
7388static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
Manish Rangankarad8bd452013-09-17 07:30:02 -04007389 struct dev_db_entry *fw_ddb_entry,
7390 uint16_t target_id)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007391{
7392 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7393 struct list_head list_nt;
7394 uint16_t ddb_index;
7395 int ret = 0;
7396
7397 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7398 ql4_printk(KERN_WARNING, ha,
7399 "%s: A discovery already in progress!\n", __func__);
7400 return QLA_ERROR;
7401 }
7402
7403 INIT_LIST_HEAD(&list_nt);
7404
7405 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7406
7407 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7408 if (ret == QLA_ERROR)
7409 goto exit_login_st_clr_bit;
7410
7411 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7412 if (ret == QLA_ERROR)
7413 goto exit_login_st;
7414
Manish Rangankarad8bd452013-09-17 07:30:02 -04007415 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007416
7417 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7418 list_del_init(&ddb_idx->list);
7419 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7420 vfree(ddb_idx);
7421 }
7422
7423exit_login_st:
7424 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7425 ql4_printk(KERN_ERR, ha,
7426 "Unable to clear DDB index = 0x%x\n", ddb_index);
7427 }
7428
7429 clear_bit(ddb_index, ha->ddb_idx_map);
7430
7431exit_login_st_clr_bit:
7432 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7433 return ret;
7434}
7435
7436static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7437 struct dev_db_entry *fw_ddb_entry,
7438 uint16_t idx)
7439{
7440 int ret = QLA_ERROR;
7441
Manish Rangankarad8bd452013-09-17 07:30:02 -04007442 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007443 if (ret != QLA_SUCCESS)
7444 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7445 idx);
7446 else
7447 ret = -EPERM;
7448
7449 return ret;
7450}
7451
7452/**
7453 * qla4xxx_sysfs_ddb_login - Login to the specified target
7454 * @fnode_sess: pointer to session attrs of flash ddb entry
7455 * @fnode_conn: pointer to connection attrs of flash ddb entry
7456 *
7457 * This logs in to the specified target
7458 **/
7459static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7460 struct iscsi_bus_flash_conn *fnode_conn)
7461{
7462 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7463 struct scsi_qla_host *ha = to_qla_host(shost);
7464 struct dev_db_entry *fw_ddb_entry = NULL;
7465 dma_addr_t fw_ddb_entry_dma;
7466 uint32_t options = 0;
7467 int ret = 0;
7468
7469 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7470 ql4_printk(KERN_ERR, ha,
7471 "%s: Target info is not persistent\n", __func__);
7472 ret = -EIO;
7473 goto exit_ddb_login;
7474 }
7475
7476 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7477 &fw_ddb_entry_dma, GFP_KERNEL);
7478 if (!fw_ddb_entry) {
7479 DEBUG2(ql4_printk(KERN_ERR, ha,
7480 "%s: Unable to allocate dma buffer\n",
7481 __func__));
7482 ret = -ENOMEM;
7483 goto exit_ddb_login;
7484 }
7485
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007486 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007487 options |= IPV6_DEFAULT_DDB_ENTRY;
7488
7489 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7490 if (ret == QLA_ERROR)
7491 goto exit_ddb_login;
7492
7493 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7494 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7495
7496 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
Manish Rangankarad8bd452013-09-17 07:30:02 -04007497 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7498 fnode_sess->target_id);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007499 else
7500 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7501 fnode_sess->target_id);
7502
7503 if (ret > 0)
7504 ret = -EIO;
7505
7506exit_ddb_login:
7507 if (fw_ddb_entry)
7508 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7509 fw_ddb_entry, fw_ddb_entry_dma);
7510 return ret;
7511}
7512
7513/**
7514 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7515 * @cls_sess: pointer to session to be logged out
7516 *
7517 * This performs session log out from the specified target
7518 **/
7519static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7520{
7521 struct iscsi_session *sess;
7522 struct ddb_entry *ddb_entry = NULL;
7523 struct scsi_qla_host *ha;
7524 struct dev_db_entry *fw_ddb_entry = NULL;
7525 dma_addr_t fw_ddb_entry_dma;
7526 unsigned long flags;
7527 unsigned long wtime;
7528 uint32_t ddb_state;
7529 int options;
7530 int ret = 0;
7531
7532 sess = cls_sess->dd_data;
7533 ddb_entry = sess->dd_data;
7534 ha = ddb_entry->ha;
7535
7536 if (ddb_entry->ddb_type != FLASH_DDB) {
7537 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7538 __func__);
7539 ret = -ENXIO;
7540 goto exit_ddb_logout;
7541 }
7542
Adheer Chandravanshi37719c22013-04-05 07:06:07 -04007543 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7544 ql4_printk(KERN_ERR, ha,
7545 "%s: Logout from boot target entry is not permitted.\n",
7546 __func__);
7547 ret = -EPERM;
7548 goto exit_ddb_logout;
7549 }
7550
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007551 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7552 &fw_ddb_entry_dma, GFP_KERNEL);
7553 if (!fw_ddb_entry) {
7554 ql4_printk(KERN_ERR, ha,
7555 "%s: Unable to allocate dma buffer\n", __func__);
7556 ret = -ENOMEM;
7557 goto exit_ddb_logout;
7558 }
7559
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007560 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7561 goto ddb_logout_init;
7562
7563 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7564 fw_ddb_entry, fw_ddb_entry_dma,
7565 NULL, NULL, &ddb_state, NULL,
7566 NULL, NULL);
7567 if (ret == QLA_ERROR)
7568 goto ddb_logout_init;
7569
7570 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7571 goto ddb_logout_init;
7572
7573 /* wait until next relogin is triggered using DF_RELOGIN and
7574 * clear DF_RELOGIN to avoid invocation of further relogin
7575 */
7576 wtime = jiffies + (HZ * RELOGIN_TOV);
7577 do {
7578 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7579 goto ddb_logout_init;
7580
7581 schedule_timeout_uninterruptible(HZ);
7582 } while ((time_after(wtime, jiffies)));
7583
7584ddb_logout_init:
7585 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7586 atomic_set(&ddb_entry->relogin_timer, 0);
7587
7588 options = LOGOUT_OPTION_CLOSE_SESSION;
7589 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7590
7591 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007592 wtime = jiffies + (HZ * LOGOUT_TOV);
7593 do {
7594 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7595 fw_ddb_entry, fw_ddb_entry_dma,
7596 NULL, NULL, &ddb_state, NULL,
7597 NULL, NULL);
7598 if (ret == QLA_ERROR)
7599 goto ddb_logout_clr_sess;
7600
7601 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7602 (ddb_state == DDB_DS_SESSION_FAILED))
7603 goto ddb_logout_clr_sess;
7604
7605 schedule_timeout_uninterruptible(HZ);
7606 } while ((time_after(wtime, jiffies)));
7607
7608ddb_logout_clr_sess:
7609 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7610 /*
7611 * we have decremented the reference count of the driver
7612 * when we setup the session to have the driver unload
7613 * to be seamless without actually destroying the
7614 * session
7615 **/
7616 try_module_get(qla4xxx_iscsi_transport.owner);
7617 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7618
7619 spin_lock_irqsave(&ha->hardware_lock, flags);
7620 qla4xxx_free_ddb(ha, ddb_entry);
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007621 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007622 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7623
7624 iscsi_session_teardown(ddb_entry->sess);
7625
Adheer Chandravanshi99c6a332013-07-08 08:33:05 -04007626 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007627 ret = QLA_SUCCESS;
7628
7629exit_ddb_logout:
7630 if (fw_ddb_entry)
7631 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7632 fw_ddb_entry, fw_ddb_entry_dma);
7633 return ret;
7634}
7635
7636/**
7637 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7638 * @fnode_sess: pointer to session attrs of flash ddb entry
7639 * @fnode_conn: pointer to connection attrs of flash ddb entry
7640 *
7641 * This performs log out from the specified target
7642 **/
7643static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7644 struct iscsi_bus_flash_conn *fnode_conn)
7645{
7646 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7647 struct scsi_qla_host *ha = to_qla_host(shost);
7648 struct ql4_tuple_ddb *flash_tddb = NULL;
7649 struct ql4_tuple_ddb *tmp_tddb = NULL;
7650 struct dev_db_entry *fw_ddb_entry = NULL;
7651 struct ddb_entry *ddb_entry = NULL;
7652 dma_addr_t fw_ddb_dma;
7653 uint32_t next_idx = 0;
7654 uint32_t state = 0, conn_err = 0;
7655 uint16_t conn_id = 0;
7656 int idx, index;
7657 int status, ret = 0;
7658
7659 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7660 &fw_ddb_dma);
7661 if (fw_ddb_entry == NULL) {
7662 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7663 ret = -ENOMEM;
7664 goto exit_ddb_logout;
7665 }
7666
7667 flash_tddb = vzalloc(sizeof(*flash_tddb));
7668 if (!flash_tddb) {
7669 ql4_printk(KERN_WARNING, ha,
7670 "%s:Memory Allocation failed.\n", __func__);
7671 ret = -ENOMEM;
7672 goto exit_ddb_logout;
7673 }
7674
7675 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7676 if (!tmp_tddb) {
7677 ql4_printk(KERN_WARNING, ha,
7678 "%s:Memory Allocation failed.\n", __func__);
7679 ret = -ENOMEM;
7680 goto exit_ddb_logout;
7681 }
7682
7683 if (!fnode_sess->targetname) {
7684 ql4_printk(KERN_ERR, ha,
7685 "%s:Cannot logout from SendTarget entry\n",
7686 __func__);
7687 ret = -EPERM;
7688 goto exit_ddb_logout;
7689 }
7690
7691 if (fnode_sess->is_boot_target) {
7692 ql4_printk(KERN_ERR, ha,
7693 "%s: Logout from boot target entry is not permitted.\n",
7694 __func__);
7695 ret = -EPERM;
7696 goto exit_ddb_logout;
7697 }
7698
7699 strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7700 ISCSI_NAME_SIZE);
7701
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007702 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007703 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7704 else
7705 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7706
7707 flash_tddb->tpgt = fnode_sess->tpgt;
7708 flash_tddb->port = fnode_conn->port;
7709
7710 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7711
7712 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7713 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7714 if (ddb_entry == NULL)
7715 continue;
7716
7717 if (ddb_entry->ddb_type != FLASH_DDB)
7718 continue;
7719
7720 index = ddb_entry->sess->target_id;
7721 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7722 fw_ddb_dma, NULL, &next_idx,
7723 &state, &conn_err, NULL,
7724 &conn_id);
7725 if (status == QLA_ERROR) {
7726 ret = -ENOMEM;
7727 break;
7728 }
7729
7730 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7731
7732 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7733 true);
7734 if (status == QLA_SUCCESS) {
7735 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7736 break;
7737 }
7738 }
7739
7740 if (idx == MAX_DDB_ENTRIES)
7741 ret = -ESRCH;
7742
7743exit_ddb_logout:
7744 if (flash_tddb)
7745 vfree(flash_tddb);
7746 if (tmp_tddb)
7747 vfree(tmp_tddb);
7748 if (fw_ddb_entry)
7749 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7750
7751 return ret;
7752}
7753
7754static int
7755qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7756 int param, char *buf)
7757{
7758 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7759 struct scsi_qla_host *ha = to_qla_host(shost);
7760 struct iscsi_bus_flash_conn *fnode_conn;
7761 struct ql4_chap_table chap_tbl;
7762 struct device *dev;
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007763 int parent_type;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007764 int rc = 0;
7765
Mike Christie8526cb12013-05-06 12:06:56 -05007766 dev = iscsi_find_flashnode_conn(fnode_sess);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007767 if (!dev)
7768 return -EIO;
7769
7770 fnode_conn = iscsi_dev_to_flash_conn(dev);
7771
7772 switch (param) {
7773 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7774 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7775 break;
7776 case ISCSI_FLASHNODE_PORTAL_TYPE:
7777 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7778 break;
7779 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7780 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7781 break;
7782 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7783 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7784 break;
7785 case ISCSI_FLASHNODE_ENTRY_EN:
7786 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7787 break;
7788 case ISCSI_FLASHNODE_HDR_DGST_EN:
7789 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7790 break;
7791 case ISCSI_FLASHNODE_DATA_DGST_EN:
7792 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7793 break;
7794 case ISCSI_FLASHNODE_IMM_DATA_EN:
7795 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7796 break;
7797 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7798 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7799 break;
7800 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7801 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7802 break;
7803 case ISCSI_FLASHNODE_PDU_INORDER:
7804 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7805 break;
7806 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7807 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7808 break;
7809 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7810 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7811 break;
7812 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7813 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7814 break;
7815 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7816 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7817 break;
7818 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7819 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7820 break;
7821 case ISCSI_FLASHNODE_ERL:
7822 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7823 break;
7824 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7825 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7826 break;
7827 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7828 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7829 break;
7830 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7831 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7832 break;
7833 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7834 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7835 break;
7836 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7837 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7838 break;
7839 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7840 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7841 break;
7842 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7843 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7844 break;
7845 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7846 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7847 break;
7848 case ISCSI_FLASHNODE_FIRST_BURST:
7849 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7850 break;
7851 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7852 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7853 break;
7854 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7855 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7856 break;
7857 case ISCSI_FLASHNODE_MAX_R2T:
7858 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7859 break;
7860 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7861 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7862 break;
7863 case ISCSI_FLASHNODE_ISID:
7864 rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
7865 fnode_sess->isid[0], fnode_sess->isid[1],
7866 fnode_sess->isid[2], fnode_sess->isid[3],
7867 fnode_sess->isid[4], fnode_sess->isid[5]);
7868 break;
7869 case ISCSI_FLASHNODE_TSID:
7870 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7871 break;
7872 case ISCSI_FLASHNODE_PORT:
7873 rc = sprintf(buf, "%d\n", fnode_conn->port);
7874 break;
7875 case ISCSI_FLASHNODE_MAX_BURST:
7876 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7877 break;
7878 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7879 rc = sprintf(buf, "%u\n",
7880 fnode_sess->default_taskmgmt_timeout);
7881 break;
7882 case ISCSI_FLASHNODE_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007883 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007884 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7885 else
7886 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7887 break;
7888 case ISCSI_FLASHNODE_ALIAS:
7889 if (fnode_sess->targetalias)
7890 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7891 else
7892 rc = sprintf(buf, "\n");
7893 break;
7894 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007895 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007896 rc = sprintf(buf, "%pI6\n",
7897 fnode_conn->redirect_ipaddr);
7898 else
7899 rc = sprintf(buf, "%pI4\n",
7900 fnode_conn->redirect_ipaddr);
7901 break;
7902 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7903 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7904 break;
7905 case ISCSI_FLASHNODE_LOCAL_PORT:
7906 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7907 break;
7908 case ISCSI_FLASHNODE_IPV4_TOS:
7909 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7910 break;
7911 case ISCSI_FLASHNODE_IPV6_TC:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007912 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007913 rc = sprintf(buf, "%u\n",
7914 fnode_conn->ipv6_traffic_class);
7915 else
7916 rc = sprintf(buf, "\n");
7917 break;
7918 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7919 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7920 break;
7921 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
Adheer Chandravanshic962c182013-03-25 08:08:32 -04007922 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007923 rc = sprintf(buf, "%pI6\n",
7924 fnode_conn->link_local_ipv6_addr);
7925 else
7926 rc = sprintf(buf, "\n");
7927 break;
7928 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
Adheer Chandravanshia2f76632013-07-08 08:33:08 -04007929 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007930 break;
7931 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
7932 if (fnode_sess->discovery_parent_type == DDB_ISNS)
7933 parent_type = ISCSI_DISC_PARENT_ISNS;
7934 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
7935 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04007936 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007937 parent_type = ISCSI_DISC_PARENT_SENDTGT;
7938 else
7939 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
7940
7941 rc = sprintf(buf, "%s\n",
7942 iscsi_get_discovery_parent_name(parent_type));
7943 break;
7944 case ISCSI_FLASHNODE_NAME:
7945 if (fnode_sess->targetname)
7946 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
7947 else
7948 rc = sprintf(buf, "\n");
7949 break;
7950 case ISCSI_FLASHNODE_TPGT:
7951 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
7952 break;
7953 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
7954 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
7955 break;
7956 case ISCSI_FLASHNODE_TCP_RECV_WSF:
7957 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
7958 break;
7959 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
7960 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
7961 break;
7962 case ISCSI_FLASHNODE_USERNAME:
7963 if (fnode_sess->chap_auth_en) {
7964 qla4xxx_get_uni_chap_at_index(ha,
7965 chap_tbl.name,
7966 chap_tbl.secret,
7967 fnode_sess->chap_out_idx);
7968 rc = sprintf(buf, "%s\n", chap_tbl.name);
7969 } else {
7970 rc = sprintf(buf, "\n");
7971 }
7972 break;
7973 case ISCSI_FLASHNODE_PASSWORD:
7974 if (fnode_sess->chap_auth_en) {
7975 qla4xxx_get_uni_chap_at_index(ha,
7976 chap_tbl.name,
7977 chap_tbl.secret,
7978 fnode_sess->chap_out_idx);
7979 rc = sprintf(buf, "%s\n", chap_tbl.secret);
7980 } else {
7981 rc = sprintf(buf, "\n");
7982 }
7983 break;
7984 case ISCSI_FLASHNODE_STATSN:
7985 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
7986 break;
7987 case ISCSI_FLASHNODE_EXP_STATSN:
7988 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
7989 break;
7990 case ISCSI_FLASHNODE_IS_BOOT_TGT:
7991 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
7992 break;
7993 default:
7994 rc = -ENOSYS;
7995 break;
7996 }
Mike Christie8526cb12013-05-06 12:06:56 -05007997
7998 put_device(dev);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04007999 return rc;
8000}
8001
8002/**
8003 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8004 * @fnode_sess: pointer to session attrs of flash ddb entry
8005 * @fnode_conn: pointer to connection attrs of flash ddb entry
8006 * @data: Parameters and their values to update
8007 * @len: len of data
8008 *
8009 * This sets the parameter of flash ddb entry and writes them to flash
8010 **/
8011static int
8012qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8013 struct iscsi_bus_flash_conn *fnode_conn,
8014 void *data, int len)
8015{
8016 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8017 struct scsi_qla_host *ha = to_qla_host(shost);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008018 struct iscsi_flashnode_param_info *fnode_param;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008019 struct ql4_chap_table chap_tbl;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008020 struct nlattr *attr;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008021 uint16_t chap_out_idx = INVALID_ENTRY;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008022 int rc = QLA_ERROR;
8023 uint32_t rem = len;
8024
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008025 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008026 nla_for_each_attr(attr, data, len, rem) {
8027 fnode_param = nla_data(attr);
8028
8029 switch (fnode_param->param) {
8030 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8031 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8032 break;
8033 case ISCSI_FLASHNODE_PORTAL_TYPE:
8034 memcpy(fnode_sess->portal_type, fnode_param->value,
8035 strlen(fnode_sess->portal_type));
8036 break;
8037 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8038 fnode_sess->auto_snd_tgt_disable =
8039 fnode_param->value[0];
8040 break;
8041 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8042 fnode_sess->discovery_sess = fnode_param->value[0];
8043 break;
8044 case ISCSI_FLASHNODE_ENTRY_EN:
8045 fnode_sess->entry_state = fnode_param->value[0];
8046 break;
8047 case ISCSI_FLASHNODE_HDR_DGST_EN:
8048 fnode_conn->hdrdgst_en = fnode_param->value[0];
8049 break;
8050 case ISCSI_FLASHNODE_DATA_DGST_EN:
8051 fnode_conn->datadgst_en = fnode_param->value[0];
8052 break;
8053 case ISCSI_FLASHNODE_IMM_DATA_EN:
8054 fnode_sess->imm_data_en = fnode_param->value[0];
8055 break;
8056 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8057 fnode_sess->initial_r2t_en = fnode_param->value[0];
8058 break;
8059 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8060 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8061 break;
8062 case ISCSI_FLASHNODE_PDU_INORDER:
8063 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8064 break;
8065 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8066 fnode_sess->chap_auth_en = fnode_param->value[0];
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008067 /* Invalidate chap index if chap auth is disabled */
8068 if (!fnode_sess->chap_auth_en)
8069 fnode_sess->chap_out_idx = INVALID_ENTRY;
8070
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008071 break;
8072 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8073 fnode_conn->snack_req_en = fnode_param->value[0];
8074 break;
8075 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8076 fnode_sess->discovery_logout_en = fnode_param->value[0];
8077 break;
8078 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8079 fnode_sess->bidi_chap_en = fnode_param->value[0];
8080 break;
8081 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8082 fnode_sess->discovery_auth_optional =
8083 fnode_param->value[0];
8084 break;
8085 case ISCSI_FLASHNODE_ERL:
8086 fnode_sess->erl = fnode_param->value[0];
8087 break;
8088 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8089 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8090 break;
8091 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8092 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8093 break;
8094 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8095 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8096 break;
8097 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8098 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8099 break;
8100 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8101 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8102 break;
8103 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8104 fnode_conn->fragment_disable = fnode_param->value[0];
8105 break;
8106 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8107 fnode_conn->max_recv_dlength =
8108 *(unsigned *)fnode_param->value;
8109 break;
8110 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8111 fnode_conn->max_xmit_dlength =
8112 *(unsigned *)fnode_param->value;
8113 break;
8114 case ISCSI_FLASHNODE_FIRST_BURST:
8115 fnode_sess->first_burst =
8116 *(unsigned *)fnode_param->value;
8117 break;
8118 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8119 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8120 break;
8121 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8122 fnode_sess->time2retain =
8123 *(uint16_t *)fnode_param->value;
8124 break;
8125 case ISCSI_FLASHNODE_MAX_R2T:
8126 fnode_sess->max_r2t =
8127 *(uint16_t *)fnode_param->value;
8128 break;
8129 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8130 fnode_conn->keepalive_timeout =
8131 *(uint16_t *)fnode_param->value;
8132 break;
8133 case ISCSI_FLASHNODE_ISID:
8134 memcpy(fnode_sess->isid, fnode_param->value,
8135 sizeof(fnode_sess->isid));
8136 break;
8137 case ISCSI_FLASHNODE_TSID:
8138 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8139 break;
8140 case ISCSI_FLASHNODE_PORT:
8141 fnode_conn->port = *(uint16_t *)fnode_param->value;
8142 break;
8143 case ISCSI_FLASHNODE_MAX_BURST:
8144 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8145 break;
8146 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8147 fnode_sess->default_taskmgmt_timeout =
8148 *(uint16_t *)fnode_param->value;
8149 break;
8150 case ISCSI_FLASHNODE_IPADDR:
8151 memcpy(fnode_conn->ipaddress, fnode_param->value,
8152 IPv6_ADDR_LEN);
8153 break;
8154 case ISCSI_FLASHNODE_ALIAS:
8155 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8156 (char *)fnode_param->value);
8157 break;
8158 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8159 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8160 IPv6_ADDR_LEN);
8161 break;
8162 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8163 fnode_conn->max_segment_size =
8164 *(unsigned *)fnode_param->value;
8165 break;
8166 case ISCSI_FLASHNODE_LOCAL_PORT:
8167 fnode_conn->local_port =
8168 *(uint16_t *)fnode_param->value;
8169 break;
8170 case ISCSI_FLASHNODE_IPV4_TOS:
8171 fnode_conn->ipv4_tos = fnode_param->value[0];
8172 break;
8173 case ISCSI_FLASHNODE_IPV6_TC:
8174 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8175 break;
8176 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8177 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8178 break;
8179 case ISCSI_FLASHNODE_NAME:
8180 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8181 (char *)fnode_param->value);
8182 break;
8183 case ISCSI_FLASHNODE_TPGT:
8184 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8185 break;
8186 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8187 memcpy(fnode_conn->link_local_ipv6_addr,
8188 fnode_param->value, IPv6_ADDR_LEN);
8189 break;
Adheer Chandravanshi65560162013-07-08 08:33:06 -04008190 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8191 fnode_sess->discovery_parent_idx =
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008192 *(uint16_t *)fnode_param->value;
8193 break;
8194 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8195 fnode_conn->tcp_xmit_wsf =
8196 *(uint8_t *)fnode_param->value;
8197 break;
8198 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8199 fnode_conn->tcp_recv_wsf =
8200 *(uint8_t *)fnode_param->value;
8201 break;
8202 case ISCSI_FLASHNODE_STATSN:
8203 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8204 break;
8205 case ISCSI_FLASHNODE_EXP_STATSN:
8206 fnode_conn->exp_statsn =
8207 *(uint32_t *)fnode_param->value;
8208 break;
Adheer Chandravanshi244c0792013-09-17 07:54:45 -04008209 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8210 chap_out_idx = *(uint16_t *)fnode_param->value;
8211 if (!qla4xxx_get_uni_chap_at_index(ha,
8212 chap_tbl.name,
8213 chap_tbl.secret,
8214 chap_out_idx)) {
8215 fnode_sess->chap_out_idx = chap_out_idx;
8216 /* Enable chap auth if chap index is valid */
8217 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8218 }
8219 break;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008220 default:
8221 ql4_printk(KERN_ERR, ha,
8222 "%s: No such sysfs attribute\n", __func__);
8223 rc = -ENOSYS;
8224 goto exit_set_param;
8225 }
8226 }
8227
8228 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8229
8230exit_set_param:
8231 return rc;
8232}
8233
8234/**
8235 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8236 * @fnode_sess: pointer to session attrs of flash ddb entry
8237 *
8238 * This invalidates the flash ddb entry at the given index
8239 **/
8240static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8241{
8242 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8243 struct scsi_qla_host *ha = to_qla_host(shost);
8244 uint32_t dev_db_start_offset;
8245 uint32_t dev_db_end_offset;
8246 struct dev_db_entry *fw_ddb_entry = NULL;
8247 dma_addr_t fw_ddb_entry_dma;
8248 uint16_t *ddb_cookie = NULL;
Vikas Chaudharyb6130ce2013-04-17 05:15:26 -04008249 size_t ddb_size = 0;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008250 void *pddb = NULL;
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008251 int target_id;
8252 int rc = 0;
8253
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008254 if (fnode_sess->is_boot_target) {
8255 rc = -EPERM;
8256 DEBUG2(ql4_printk(KERN_ERR, ha,
8257 "%s: Deletion of boot target entry is not permitted.\n",
8258 __func__));
8259 goto exit_ddb_del;
8260 }
8261
8262 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8263 goto sysfs_ddb_del;
8264
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008265 if (is_qla40XX(ha)) {
8266 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008267 dev_db_end_offset = FLASH_OFFSET_DB_END;
8268 dev_db_start_offset += (fnode_sess->target_id *
8269 sizeof(*fw_ddb_entry));
8270 ddb_size = sizeof(*fw_ddb_entry);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008271 } else {
8272 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8273 (ha->hw.flt_region_ddb << 2);
8274 /* flt_ddb_size is DDB table size for both ports
8275 * so divide it by 2 to calculate the offset for second port
8276 */
8277 if (ha->port_num == 1)
8278 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008279
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008280 dev_db_end_offset = dev_db_start_offset +
8281 (ha->hw.flt_ddb_size / 2);
8282
8283 dev_db_start_offset += (fnode_sess->target_id *
8284 sizeof(*fw_ddb_entry));
Adheer Chandravanshi1bcb5612013-04-17 05:15:28 -04008285 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008286
8287 ddb_size = sizeof(*ddb_cookie);
8288 }
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008289
8290 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8291 __func__, dev_db_start_offset, dev_db_end_offset));
8292
8293 if (dev_db_start_offset > dev_db_end_offset) {
8294 rc = -EIO;
8295 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8296 __func__, fnode_sess->target_id));
8297 goto exit_ddb_del;
8298 }
8299
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008300 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8301 &fw_ddb_entry_dma, GFP_KERNEL);
8302 if (!pddb) {
8303 rc = -ENOMEM;
8304 DEBUG2(ql4_printk(KERN_ERR, ha,
8305 "%s: Unable to allocate dma buffer\n",
8306 __func__));
8307 goto exit_ddb_del;
8308 }
8309
8310 if (is_qla40XX(ha)) {
8311 fw_ddb_entry = pddb;
8312 memset(fw_ddb_entry, 0, ddb_size);
8313 ddb_cookie = &fw_ddb_entry->cookie;
8314 } else {
8315 ddb_cookie = pddb;
8316 }
8317
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008318 /* invalidate the cookie */
8319 *ddb_cookie = 0xFFEE;
8320 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008321 ddb_size, FLASH_OPT_RMW_COMMIT);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008322
8323sysfs_ddb_del:
8324 target_id = fnode_sess->target_id;
8325 iscsi_destroy_flashnode_sess(fnode_sess);
8326 ql4_printk(KERN_INFO, ha,
8327 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8328 __func__, target_id, ha->host_no);
8329exit_ddb_del:
Adheer Chandravanshi039acc12013-04-05 07:06:06 -04008330 if (pddb)
8331 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8332 fw_ddb_entry_dma);
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008333 return rc;
8334}
8335
8336/**
8337 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8338 * @ha: pointer to adapter structure
8339 *
8340 * Export the firmware DDB for all send targets and normal targets to sysfs.
8341 **/
8342static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8343{
8344 struct dev_db_entry *fw_ddb_entry = NULL;
8345 dma_addr_t fw_ddb_entry_dma;
8346 uint16_t max_ddbs;
8347 uint16_t idx = 0;
8348 int ret = QLA_SUCCESS;
8349
8350 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8351 sizeof(*fw_ddb_entry),
8352 &fw_ddb_entry_dma, GFP_KERNEL);
8353 if (!fw_ddb_entry) {
8354 DEBUG2(ql4_printk(KERN_ERR, ha,
8355 "%s: Unable to allocate dma buffer\n",
8356 __func__));
8357 return -ENOMEM;
8358 }
8359
Adheer Chandravanshia957a7d2013-04-05 07:06:08 -04008360 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008361 MAX_DEV_DB_ENTRIES;
8362
8363 for (idx = 0; idx < max_ddbs; idx++) {
8364 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8365 idx))
8366 continue;
8367
8368 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8369 if (ret) {
8370 ret = -EIO;
8371 break;
8372 }
8373 }
8374
8375 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8376 fw_ddb_entry_dma);
8377
8378 return ret;
8379}
8380
8381static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8382{
8383 iscsi_destroy_all_flashnode(ha->host);
8384}
8385
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008386/**
8387 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8388 * @ha: pointer to adapter structure
8389 * @is_reset: Is this init path or reset path
8390 *
8391 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8392 * using connection open, then create the list of normal targets (nt)
8393 * from firmware DDBs. Based on the list of nt setup session and connection
8394 * objects.
8395 **/
8396void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8397{
8398 uint16_t tmo = 0;
8399 struct list_head list_st, list_nt;
8400 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8401 unsigned long wtime;
8402
8403 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8404 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8405 ha->is_reset = is_reset;
8406 return;
8407 }
8408
8409 INIT_LIST_HEAD(&list_st);
8410 INIT_LIST_HEAD(&list_nt);
8411
8412 qla4xxx_build_st_list(ha, &list_st);
8413
Mike Christie13483732011-12-01 21:38:41 -06008414 /* Before issuing conn open mbox, ensure all IPs states are configured
8415 * Note, conn open fails if IPs are not configured
8416 */
8417 qla4xxx_wait_for_ip_configuration(ha);
8418
8419 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8420 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8421 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8422 }
8423
8424 /* Wait to ensure all sendtargets are done for min 12 sec wait */
Nilesh Javalic28eaac2011-12-18 21:40:44 -08008425 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8426 (ha->def_timeout < LOGIN_TOV * 10) ?
8427 ha->def_timeout : LOGIN_TOV);
8428
Mike Christie13483732011-12-01 21:38:41 -06008429 DEBUG2(ql4_printk(KERN_INFO, ha,
8430 "Default time to wait for build ddb %d\n", tmo));
8431
8432 wtime = jiffies + (HZ * tmo);
8433 do {
Nilesh Javalif1f2e602011-12-16 01:58:57 -08008434 if (list_empty(&list_st))
8435 break;
8436
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008437 qla4xxx_remove_failed_ddb(ha, &list_st);
Mike Christie13483732011-12-01 21:38:41 -06008438 schedule_timeout_uninterruptible(HZ / 10);
8439 } while (time_after(wtime, jiffies));
8440
Manish Rangankarad8bd452013-09-17 07:30:02 -04008441
8442 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8443
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008444 qla4xxx_free_ddb_list(&list_st);
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08008445 qla4xxx_free_ddb_list(&list_nt);
Mike Christie13483732011-12-01 21:38:41 -06008446
8447 qla4xxx_free_ddb_index(ha);
8448}
8449
David Somayajuluafaf5a22006-09-19 10:28:00 -07008450/**
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008451 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8452 * response.
8453 * @ha: pointer to adapter structure
8454 *
8455 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8456 * set in DDB and we will wait for login response of boot targets during
8457 * probe.
8458 **/
8459static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8460{
8461 struct ddb_entry *ddb_entry;
8462 struct dev_db_entry *fw_ddb_entry = NULL;
8463 dma_addr_t fw_ddb_entry_dma;
8464 unsigned long wtime;
8465 uint32_t ddb_state;
8466 int max_ddbs, idx, ret;
8467
8468 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8469 MAX_DEV_DB_ENTRIES;
8470
8471 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8472 &fw_ddb_entry_dma, GFP_KERNEL);
8473 if (!fw_ddb_entry) {
8474 ql4_printk(KERN_ERR, ha,
8475 "%s: Unable to allocate dma buffer\n", __func__);
8476 goto exit_login_resp;
8477 }
8478
8479 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8480
8481 for (idx = 0; idx < max_ddbs; idx++) {
8482 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8483 if (ddb_entry == NULL)
8484 continue;
8485
8486 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8487 DEBUG2(ql4_printk(KERN_INFO, ha,
8488 "%s: DDB index [%d]\n", __func__,
8489 ddb_entry->fw_ddb_index));
8490 do {
8491 ret = qla4xxx_get_fwddb_entry(ha,
8492 ddb_entry->fw_ddb_index,
8493 fw_ddb_entry, fw_ddb_entry_dma,
8494 NULL, NULL, &ddb_state, NULL,
8495 NULL, NULL);
8496 if (ret == QLA_ERROR)
8497 goto exit_login_resp;
8498
8499 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8500 (ddb_state == DDB_DS_SESSION_FAILED))
8501 break;
8502
8503 schedule_timeout_uninterruptible(HZ);
8504
8505 } while ((time_after(wtime, jiffies)));
8506
8507 if (!time_after(wtime, jiffies)) {
8508 DEBUG2(ql4_printk(KERN_INFO, ha,
8509 "%s: Login response wait timer expired\n",
8510 __func__));
8511 goto exit_login_resp;
8512 }
8513 }
8514 }
8515
8516exit_login_resp:
8517 if (fw_ddb_entry)
8518 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8519 fw_ddb_entry, fw_ddb_entry_dma);
8520}
8521
8522/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07008523 * qla4xxx_probe_adapter - callback function to probe HBA
8524 * @pdev: pointer to pci_dev structure
8525 * @pci_device_id: pointer to pci_device entry
8526 *
8527 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8528 * It returns zero if successful. It also initializes all data necessary for
8529 * the driver.
8530 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008531static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8532 const struct pci_device_id *ent)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008533{
8534 int ret = -ENODEV, status;
8535 struct Scsi_Host *host;
8536 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008537 uint8_t init_retry_count = 0;
8538 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308539 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008540 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008541
8542 if (pci_enable_device(pdev))
8543 return -1;
8544
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008545 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008546 if (host == NULL) {
8547 printk(KERN_WARNING
8548 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8549 goto probe_disable_device;
8550 }
8551
8552 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008553 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008554 memset(ha, 0, sizeof(*ha));
8555
8556 /* Save the information from PCI BIOS. */
8557 ha->pdev = pdev;
8558 ha->host = host;
8559 ha->host_no = host->host_no;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008560 ha->func_num = PCI_FUNC(ha->pdev->devfn);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008561
Lalit Chandivade2232be02010-07-30 14:38:47 +05308562 pci_enable_pcie_error_reporting(pdev);
8563
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308564 /* Setup Runtime configurable options */
8565 if (is_qla8022(ha)) {
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04008566 ha->isp_ops = &qla4_82xx_isp_ops;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008567 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308568 ha->qdr_sn_window = -1;
8569 ha->ddr_mn_window = -1;
8570 ha->curr_window = 255;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308571 nx_legacy_intr = &legacy_intr[ha->func_num];
8572 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8573 ha->nx_legacy_intr.tgt_status_reg =
8574 nx_legacy_intr->tgt_status_reg;
8575 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8576 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008577 } else if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008578 ha->isp_ops = &qla4_83xx_isp_ops;
8579 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308580 } else {
8581 ha->isp_ops = &qla4xxx_isp_ops;
8582 }
8583
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008584 if (is_qla80XX(ha)) {
8585 rwlock_init(&ha->hw_lock);
8586 ha->pf_bit = ha->func_num << 16;
8587 /* Set EEH reset type to fundamental if required by hba */
Lalit Chandivade2232be02010-07-30 14:38:47 +05308588 pdev->needs_freset = 1;
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008589 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05308590
David Somayajuluafaf5a22006-09-19 10:28:00 -07008591 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308592 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008593 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308594 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008595
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308596 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07008597 pdev->device, pdev->irq, ha->reg);
8598
8599 qla4xxx_config_dma_addressing(ha);
8600
8601 /* Initialize lists and spinlocks. */
David Somayajuluafaf5a22006-09-19 10:28:00 -07008602 INIT_LIST_HEAD(&ha->free_srb_q);
8603
8604 mutex_init(&ha->mbox_sem);
Lalit Chandivade45494152011-10-07 16:55:42 -07008605 mutex_init(&ha->chap_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308606 init_completion(&ha->mbx_intr_comp);
Vikas Chaudhary95d31262011-08-12 02:51:29 -07008607 init_completion(&ha->disable_acb_comp);
Vikas Chaudharydf86f772013-11-22 05:28:17 -05008608 init_completion(&ha->idc_comp);
8609 init_completion(&ha->link_up_comp);
8610 init_completion(&ha->disable_acb_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008611
8612 spin_lock_init(&ha->hardware_lock);
Vikas Chaudhary8e9157c2012-08-22 07:45:24 -04008613 spin_lock_init(&ha->work_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008614
Vikas Chaudharyff884432011-08-29 23:43:02 +05308615 /* Initialize work list */
8616 INIT_LIST_HEAD(&ha->work_list);
8617
David Somayajuluafaf5a22006-09-19 10:28:00 -07008618 /* Allocate dma buffers */
8619 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308620 ql4_printk(KERN_WARNING, ha,
8621 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008622
8623 ret = -ENOMEM;
8624 goto probe_failed;
8625 }
8626
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008627 host->cmd_per_lun = 3;
8628 host->max_channel = 0;
8629 host->max_lun = MAX_LUNS - 1;
8630 host->max_id = MAX_TARGETS;
8631 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8632 host->can_queue = MAX_SRBS ;
8633 host->transportt = qla4xxx_scsi_transport;
8634
8635 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
8636 if (ret) {
8637 ql4_printk(KERN_WARNING, ha,
8638 "%s: scsi_init_shared_tag_map failed\n", __func__);
8639 goto probe_failed;
8640 }
8641
8642 pci_set_drvdata(pdev, ha);
8643
8644 ret = scsi_add_host(host, &pdev->dev);
8645 if (ret)
8646 goto probe_failed;
8647
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008648 if (is_qla80XX(ha))
8649 qla4_8xxx_get_flash_info(ha);
8650
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008651 if (is_qla8032(ha) || is_qla8042(ha)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008652 qla4_83xx_read_reset_template(ha);
8653 /*
8654 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8655 * If DONRESET_BIT0 is set, drivers should not set dev_state
8656 * to NEED_RESET. But if NEED_RESET is set, drivers should
8657 * should honor the reset.
8658 */
8659 if (ql4xdontresethba == 1)
8660 qla4_83xx_set_idc_dontreset(ha);
8661 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308662
David Somayajuluafaf5a22006-09-19 10:28:00 -07008663 /*
8664 * Initialize the Host adapter request/response queues and
8665 * firmware
8666 * NOTE: interrupts enabled upon successful completion
8667 */
Mike Christie13483732011-12-01 21:38:41 -06008668 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Poornima Vonti7977f822012-09-20 07:35:07 -04008669
8670 /* Dont retry adapter initialization if IRQ allocation failed */
Nilesh Javali17801c92013-03-22 07:22:42 -04008671 if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
8672 ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
8673 __func__);
Poornima Vonti7977f822012-09-20 07:35:07 -04008674 goto skip_retry_init;
Nilesh Javali17801c92013-03-22 07:22:42 -04008675 }
Poornima Vonti7977f822012-09-20 07:35:07 -04008676
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308677 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8678 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008679
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008680 if (is_qla80XX(ha)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008681 ha->isp_ops->idc_lock(ha);
8682 dev_state = qla4_8xxx_rd_direct(ha,
Vikas Chaudharye951aca2012-12-29 02:24:52 -05008683 QLA8XXX_CRB_DEV_STATE);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008684 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04008685 if (dev_state == QLA8XXX_DEV_FAILED) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07008686 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8687 "initialize adapter. H/W is in failed state\n",
8688 __func__);
8689 break;
8690 }
8691 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008692 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8693 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308694
8695 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8696 continue;
8697
Mike Christie13483732011-12-01 21:38:41 -06008698 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008699 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308700
Poornima Vonti7977f822012-09-20 07:35:07 -04008701skip_retry_init:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308702 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308703 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008704
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008705 if ((is_qla8022(ha) && ql4xdontresethba) ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04008706 ((is_qla8032(ha) || is_qla8042(ha)) &&
8707 qla4_83xx_idc_dontreset(ha))) {
Lalit Chandivadefe998522010-12-02 22:12:36 -08008708 /* Put the device in failed state. */
8709 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
Vikas Chaudhary33693c72012-08-22 07:55:04 -04008710 ha->isp_ops->idc_lock(ha);
8711 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8712 QLA8XXX_DEV_FAILED);
8713 ha->isp_ops->idc_unlock(ha);
Lalit Chandivadefe998522010-12-02 22:12:36 -08008714 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008715 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008716 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008717 }
8718
David Somayajuluafaf5a22006-09-19 10:28:00 -07008719 /* Startup the kernel thread for this host adapter. */
8720 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8721 "qla4xxx_dpc\n", __func__));
8722 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8723 ha->dpc_thread = create_singlethread_workqueue(buf);
8724 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05308725 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07008726 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008727 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008728 }
David Howellsc4028952006-11-22 14:57:56 +00008729 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008730
Kees Cookd8537542013-07-03 15:04:57 -07008731 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8732 ha->host_no);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008733 if (!ha->task_wq) {
8734 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8735 ret = -ENODEV;
8736 goto remove_host;
8737 }
8738
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04008739 /*
8740 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308741 * (which is called indirectly by qla4xxx_initialize_adapter),
8742 * so that irqs will be registered after crbinit but before
8743 * mbx_intr_enable.
8744 */
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008745 if (is_qla40XX(ha)) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308746 ret = qla4xxx_request_irqs(ha);
8747 if (ret) {
8748 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8749 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008750 goto remove_host;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308751 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008752 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07008753
Lalit Chandivade2232be02010-07-30 14:38:47 +05308754 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308755 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008756
8757 /* Start timer thread. */
8758 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
8759
8760 set_bit(AF_INIT_DONE, &ha->flags);
8761
Tej Parkash068237c82012-05-18 04:41:44 -04008762 qla4_8xxx_alloc_sysfs_attr(ha);
8763
David Somayajuluafaf5a22006-09-19 10:28:00 -07008764 printk(KERN_INFO
8765 " QLogic iSCSI HBA Driver version: %s\n"
8766 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8767 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
Adheer Chandravanshieee06a02013-07-08 08:33:10 -04008768 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8769 ha->fw_info.fw_patch, ha->fw_info.fw_build);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008770
Manish Dusanecfb27872012-09-20 07:35:01 -04008771 /* Set the driver version */
8772 if (is_qla80XX(ha))
8773 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8774
Manish Rangankar2a991c22011-07-25 13:48:55 -05008775 if (qla4xxx_setup_boot_info(ha))
Vikas Chaudhary3573bfb2012-02-27 03:08:57 -08008776 ql4_printk(KERN_ERR, ha,
8777 "%s: No iSCSI boot target configured\n", __func__);
Manish Rangankar2a991c22011-07-25 13:48:55 -05008778
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008779 if (qla4xxx_sysfs_ddb_export(ha))
8780 ql4_printk(KERN_ERR, ha,
8781 "%s: Error exporting ddb to sysfs\n", __func__);
8782
Mike Christie13483732011-12-01 21:38:41 -06008783 /* Perform the build ddb list and login to each */
8784 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8785 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
Manish Rangankar1dc8ed52013-01-20 23:51:03 -05008786 qla4xxx_wait_login_resp_boot_tgt(ha);
Mike Christie13483732011-12-01 21:38:41 -06008787
8788 qla4xxx_create_chap_list(ha);
8789
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008790 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008791 return 0;
8792
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008793remove_host:
8794 scsi_remove_host(ha->host);
8795
David Somayajuluafaf5a22006-09-19 10:28:00 -07008796probe_failed:
8797 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308798
8799probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05308800 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008801 scsi_host_put(ha->host);
8802
8803probe_disable_device:
8804 pci_disable_device(pdev);
8805
8806 return ret;
8807}
8808
8809/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07008810 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8811 * @ha: pointer to adapter structure
8812 *
8813 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8814 * so that the other port will not re-initialize while in the process of
8815 * removing the ha due to driver unload or hba hotplug.
8816 **/
8817static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8818{
8819 struct scsi_qla_host *other_ha = NULL;
8820 struct pci_dev *other_pdev = NULL;
8821 int fn = ISP4XXX_PCI_FN_2;
8822
8823 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8824 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8825 fn = ISP4XXX_PCI_FN_1;
8826
8827 other_pdev =
8828 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8829 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8830 fn));
8831
8832 /* Get other_ha if other_pdev is valid and state is enable*/
8833 if (other_pdev) {
8834 if (atomic_read(&other_pdev->enable_cnt)) {
8835 other_ha = pci_get_drvdata(other_pdev);
8836 if (other_ha) {
8837 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8838 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8839 "Prevent %s reinit\n", __func__,
8840 dev_name(&other_ha->pdev->dev)));
8841 }
8842 }
8843 pci_dev_put(other_pdev);
8844 }
8845}
8846
Mike Christie13483732011-12-01 21:38:41 -06008847static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8848{
8849 struct ddb_entry *ddb_entry;
8850 int options;
8851 int idx;
8852
8853 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8854
8855 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8856 if ((ddb_entry != NULL) &&
8857 (ddb_entry->ddb_type == FLASH_DDB)) {
8858
8859 options = LOGOUT_OPTION_CLOSE_SESSION;
8860 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
8861 == QLA_ERROR)
8862 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
8863 __func__);
8864
8865 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8866 /*
8867 * we have decremented the reference count of the driver
8868 * when we setup the session to have the driver unload
8869 * to be seamless without actually destroying the
8870 * session
8871 **/
8872 try_module_get(qla4xxx_iscsi_transport.owner);
8873 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8874 qla4xxx_free_ddb(ha, ddb_entry);
8875 iscsi_session_teardown(ddb_entry->sess);
8876 }
8877 }
8878}
Karen Higgins7eece5a2011-03-21 03:34:29 -07008879/**
Masanari Iida59e13d42012-04-25 00:24:16 +09008880 * qla4xxx_remove_adapter - callback function to remove adapter.
David Somayajuluafaf5a22006-09-19 10:28:00 -07008881 * @pci_dev: PCI device pointer
8882 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008883static void qla4xxx_remove_adapter(struct pci_dev *pdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008884{
8885 struct scsi_qla_host *ha;
8886
Vikas Chaudharyf8b07512012-09-20 07:35:08 -04008887 /*
8888 * If the PCI device is disabled then it means probe_adapter had
8889 * failed and resources already cleaned up on probe_adapter exit.
8890 */
8891 if (!pci_is_enabled(pdev))
8892 return;
8893
David Somayajuluafaf5a22006-09-19 10:28:00 -07008894 ha = pci_get_drvdata(pdev);
8895
Vikas Chaudharyee996a62012-08-22 07:55:05 -04008896 if (is_qla40XX(ha))
Karen Higgins7eece5a2011-03-21 03:34:29 -07008897 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07008898
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05008899 /* destroy iface from sysfs */
8900 qla4xxx_destroy_ifaces(ha);
8901
Mike Christie13483732011-12-01 21:38:41 -06008902 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
Manish Rangankar2a991c22011-07-25 13:48:55 -05008903 iscsi_boot_destroy_kset(ha->boot_kset);
8904
Mike Christie13483732011-12-01 21:38:41 -06008905 qla4xxx_destroy_fw_ddb_session(ha);
Tej Parkash068237c82012-05-18 04:41:44 -04008906 qla4_8xxx_free_sysfs_attr(ha);
Mike Christie13483732011-12-01 21:38:41 -06008907
Adheer Chandravanshi1e9e2be2013-03-22 07:41:31 -04008908 qla4xxx_sysfs_ddb_remove(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008909 scsi_remove_host(ha->host);
8910
8911 qla4xxx_free_adapter(ha);
8912
8913 scsi_host_put(ha->host);
8914
Lalit Chandivade2232be02010-07-30 14:38:47 +05308915 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308916 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008917}
8918
8919/**
8920 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
8921 * @ha: HA context
8922 *
8923 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
8924 * supported addressing method.
8925 */
Adrian Bunk47975472007-04-26 00:35:16 -07008926static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008927{
8928 int retval;
8929
8930 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07008931 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
8932 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07008933 dev_dbg(&ha->pdev->dev,
8934 "Failed to set 64 bit PCI consistent mask; "
8935 "using 32 bit.\n");
8936 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07008937 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07008938 }
8939 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07008940 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07008941}
8942
8943static int qla4xxx_slave_alloc(struct scsi_device *sdev)
8944{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008945 struct iscsi_cls_session *cls_sess;
8946 struct iscsi_session *sess;
8947 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07008948 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008949
Manish Rangankarb3a271a2011-07-25 13:48:53 -05008950 cls_sess = starget_to_session(sdev->sdev_target);
8951 sess = cls_sess->dd_data;
8952 ddb = sess->dd_data;
8953
David Somayajuluafaf5a22006-09-19 10:28:00 -07008954 sdev->hostdata = ddb;
8955 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07008956
8957 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
8958 queue_depth = ql4xmaxqdepth;
8959
8960 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07008961 return 0;
8962}
8963
8964static int qla4xxx_slave_configure(struct scsi_device *sdev)
8965{
8966 sdev->tagged_supported = 1;
8967 return 0;
8968}
8969
8970static void qla4xxx_slave_destroy(struct scsi_device *sdev)
8971{
8972 scsi_deactivate_tcq(sdev, 1);
8973}
8974
Tej Parkashf7b4aa62012-04-30 04:12:19 -07008975static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
8976 int reason)
8977{
8978 if (!ql4xqfulltracking)
8979 return -EOPNOTSUPP;
8980
8981 return iscsi_change_queue_depth(sdev, qdepth, reason);
8982}
8983
David Somayajuluafaf5a22006-09-19 10:28:00 -07008984/**
8985 * qla4xxx_del_from_active_array - returns an active srb
8986 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02008987 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07008988 *
8989 * This routine removes and returns the srb at the specified index
8990 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05308991struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
8992 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008993{
8994 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05308995 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07008996
Vikas Chaudhary53698872010-04-28 11:41:59 +05308997 cmd = scsi_host_find_tag(ha->host, index);
8998 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07008999 return srb;
9000
Vikas Chaudhary53698872010-04-28 11:41:59 +05309001 srb = (struct srb *)CMD_SP(cmd);
9002 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009003 return srb;
9004
9005 /* update counters */
9006 if (srb->flags & SRB_DMA_VALID) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009007 ha->iocb_cnt -= srb->iocb_cnt;
9008 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05309009 srb->cmd->host_scribble =
9010 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009011 }
9012 return srb;
9013}
9014
9015/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009016 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309017 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07009018 * @cmd: Scsi Command to wait on.
9019 *
9020 * This routine waits for the command to be returned by the Firmware
9021 * for some max time.
9022 **/
9023static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9024 struct scsi_cmnd *cmd)
9025{
9026 int done = 0;
9027 struct srb *rp;
9028 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309029 int ret = SUCCESS;
9030
9031 /* Dont wait on command if PCI error is being handled
9032 * by PCI AER driver
9033 */
9034 if (unlikely(pci_channel_offline(ha->pdev)) ||
9035 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9036 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9037 ha->host_no, __func__);
9038 return ret;
9039 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07009040
9041 do {
9042 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05309043 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009044 if (rp == NULL) {
9045 done++;
9046 break;
9047 }
9048
9049 msleep(2000);
9050 } while (max_wait_time--);
9051
9052 return done;
9053}
9054
9055/**
9056 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9057 * @ha: Pointer to host adapter structure
9058 **/
9059static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9060{
9061 unsigned long wait_online;
9062
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07009063 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009064 while (time_before(jiffies, wait_online)) {
9065
9066 if (adapter_up(ha))
9067 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009068
9069 msleep(2000);
9070 }
9071
9072 return QLA_ERROR;
9073}
9074
9075/**
Mike Christiece545032008-02-29 18:25:20 -06009076 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02009077 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07009078 * @t: target id
9079 * @l: lun id
9080 *
9081 * This function waits for all outstanding commands to a lun to complete. It
9082 * returns 0 if all pending commands are returned and 1 otherwise.
9083 **/
Mike Christiece545032008-02-29 18:25:20 -06009084static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9085 struct scsi_target *stgt,
9086 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009087{
9088 int cnt;
9089 int status = 0;
9090 struct scsi_cmnd *cmd;
9091
9092 /*
Mike Christiece545032008-02-29 18:25:20 -06009093 * Waiting for all commands for the designated target or dev
9094 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07009095 */
9096 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9097 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06009098 if (cmd && stgt == scsi_target(cmd->device) &&
9099 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009100 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9101 status++;
9102 break;
9103 }
9104 }
9105 }
9106 return status;
9107}
9108
9109/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309110 * qla4xxx_eh_abort - callback for abort task.
9111 * @cmd: Pointer to Linux's SCSI command structure
9112 *
9113 * This routine is called by the Linux OS to abort the specified
9114 * command.
9115 **/
9116static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9117{
9118 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9119 unsigned int id = cmd->device->id;
9120 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07009121 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309122 struct srb *srb = NULL;
9123 int ret = SUCCESS;
9124 int wait = 0;
9125
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309126 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04009127 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
9128 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309129
Mike Christie92b3e5b2010-10-06 22:51:17 -07009130 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309131 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07009132 if (!srb) {
9133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309134 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07009135 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309136 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07009137 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309138
9139 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9140 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
9141 ha->host_no, id, lun));
9142 ret = FAILED;
9143 } else {
9144 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
9145 ha->host_no, id, lun));
9146 wait = 1;
9147 }
9148
9149 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9150
9151 /* Wait for command to complete */
9152 if (wait) {
9153 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9154 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
9155 ha->host_no, id, lun));
9156 ret = FAILED;
9157 }
9158 }
9159
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309160 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309161 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009162 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05309163
9164 return ret;
9165}
9166
9167/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009168 * qla4xxx_eh_device_reset - callback for target reset.
9169 * @cmd: Pointer to Linux's SCSI command structure
9170 *
9171 * This routine is called by the Linux OS to reset all luns on the
9172 * specified target.
9173 **/
9174static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9175{
9176 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9177 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009178 int ret = FAILED, stat;
9179
Karen Higgins612f7342009-07-15 15:03:01 -05009180 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009181 return ret;
9182
Mike Christiec01be6d2010-07-22 16:59:49 +05309183 ret = iscsi_block_scsi_eh(cmd);
9184 if (ret)
9185 return ret;
9186 ret = FAILED;
9187
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309188 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009189 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
9190 cmd->device->channel, cmd->device->id, cmd->device->lun);
9191
9192 DEBUG2(printk(KERN_INFO
9193 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9194 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07009195 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009196 ha->dpc_flags, cmd->result, cmd->allowed));
9197
9198 /* FIXME: wait for hba to go online */
9199 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9200 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309201 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009202 goto eh_dev_reset_done;
9203 }
9204
Mike Christiece545032008-02-29 18:25:20 -06009205 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9206 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309207 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06009208 "DEVICE RESET FAILED - waiting for "
9209 "commands.\n");
9210 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009211 }
9212
David C Somayajulu9d562912008-03-19 11:23:03 -07009213 /* Send marker. */
9214 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9215 MM_LUN_RESET) != QLA_SUCCESS)
9216 goto eh_dev_reset_done;
9217
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309218 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009219 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
9220 ha->host_no, cmd->device->channel, cmd->device->id,
9221 cmd->device->lun);
9222
9223 ret = SUCCESS;
9224
9225eh_dev_reset_done:
9226
9227 return ret;
9228}
9229
9230/**
Mike Christiece545032008-02-29 18:25:20 -06009231 * qla4xxx_eh_target_reset - callback for target reset.
9232 * @cmd: Pointer to Linux's SCSI command structure
9233 *
9234 * This routine is called by the Linux OS to reset the target.
9235 **/
9236static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9237{
9238 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9239 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05309240 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06009241
9242 if (!ddb_entry)
9243 return FAILED;
9244
Mike Christiec01be6d2010-07-22 16:59:49 +05309245 ret = iscsi_block_scsi_eh(cmd);
9246 if (ret)
9247 return ret;
9248
Mike Christiece545032008-02-29 18:25:20 -06009249 starget_printk(KERN_INFO, scsi_target(cmd->device),
9250 "WARM TARGET RESET ISSUED.\n");
9251
9252 DEBUG2(printk(KERN_INFO
9253 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9254 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07009255 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06009256 ha->dpc_flags, cmd->result, cmd->allowed));
9257
9258 stat = qla4xxx_reset_target(ha, ddb_entry);
9259 if (stat != QLA_SUCCESS) {
9260 starget_printk(KERN_INFO, scsi_target(cmd->device),
9261 "WARM TARGET RESET FAILED.\n");
9262 return FAILED;
9263 }
9264
Mike Christiece545032008-02-29 18:25:20 -06009265 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9266 NULL)) {
9267 starget_printk(KERN_INFO, scsi_target(cmd->device),
9268 "WARM TARGET DEVICE RESET FAILED - "
9269 "waiting for commands.\n");
9270 return FAILED;
9271 }
9272
David C Somayajulu9d562912008-03-19 11:23:03 -07009273 /* Send marker. */
9274 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9275 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9276 starget_printk(KERN_INFO, scsi_target(cmd->device),
9277 "WARM TARGET DEVICE RESET FAILED - "
9278 "marker iocb failed.\n");
9279 return FAILED;
9280 }
9281
Mike Christiece545032008-02-29 18:25:20 -06009282 starget_printk(KERN_INFO, scsi_target(cmd->device),
9283 "WARM TARGET RESET SUCCEEDED.\n");
9284 return SUCCESS;
9285}
9286
9287/**
Sarang Radke8a28896012011-12-06 02:34:10 -08009288 * qla4xxx_is_eh_active - check if error handler is running
9289 * @shost: Pointer to SCSI Host struct
9290 *
9291 * This routine finds that if reset host is called in EH
9292 * scenario or from some application like sg_reset
9293 **/
9294static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9295{
9296 if (shost->shost_state == SHOST_RECOVERY)
9297 return 1;
9298 return 0;
9299}
9300
9301/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07009302 * qla4xxx_eh_host_reset - kernel callback
9303 * @cmd: Pointer to Linux's SCSI command structure
9304 *
9305 * This routine is invoked by the Linux kernel to perform fatal error
9306 * recovery on the specified adapter.
9307 **/
9308static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9309{
9310 int return_status = FAILED;
9311 struct scsi_qla_host *ha;
9312
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009313 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009314
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009315 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009316 qla4_83xx_set_idc_dontreset(ha);
9317
9318 /*
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009319 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9320 * protocol drivers, we should not set device_state to NEED_RESET
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009321 */
9322 if (ql4xdontresethba ||
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009323 ((is_qla8032(ha) || is_qla8042(ha)) &&
9324 qla4_83xx_idc_dontreset(ha))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309325 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9326 ha->host_no, __func__));
Sarang Radke8a28896012011-12-06 02:34:10 -08009327
9328 /* Clear outstanding srb in queues */
9329 if (qla4xxx_is_eh_active(cmd->device->host))
9330 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9331
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309332 return FAILED;
9333 }
9334
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309335 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05009336 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009337 cmd->device->channel, cmd->device->id, cmd->device->lun);
9338
9339 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9340 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9341 "DEAD.\n", ha->host_no, cmd->device->channel,
9342 __func__));
9343
9344 return FAILED;
9345 }
9346
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309347 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009348 if (is_qla80XX(ha))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309349 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9350 else
9351 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9352 }
Mike Christie50a29ae2008-03-04 13:26:53 -06009353
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309354 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009355 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07009356
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05309357 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009358 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07009359
9360 return return_status;
9361}
9362
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009363static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9364{
9365 uint32_t mbox_cmd[MBOX_REG_COUNT];
9366 uint32_t mbox_sts[MBOX_REG_COUNT];
9367 struct addr_ctrl_blk_def *acb = NULL;
9368 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9369 int rval = QLA_SUCCESS;
9370 dma_addr_t acb_dma;
9371
9372 acb = dma_alloc_coherent(&ha->pdev->dev,
9373 sizeof(struct addr_ctrl_blk_def),
9374 &acb_dma, GFP_KERNEL);
9375 if (!acb) {
9376 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9377 __func__);
9378 rval = -ENOMEM;
9379 goto exit_port_reset;
9380 }
9381
9382 memset(acb, 0, acb_len);
9383
9384 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9385 if (rval != QLA_SUCCESS) {
9386 rval = -EIO;
9387 goto exit_free_acb;
9388 }
9389
9390 rval = qla4xxx_disable_acb(ha);
9391 if (rval != QLA_SUCCESS) {
9392 rval = -EIO;
9393 goto exit_free_acb;
9394 }
9395
9396 wait_for_completion_timeout(&ha->disable_acb_comp,
9397 DISABLE_ACB_TOV * HZ);
9398
9399 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9400 if (rval != QLA_SUCCESS) {
9401 rval = -EIO;
9402 goto exit_free_acb;
9403 }
9404
9405exit_free_acb:
9406 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9407 acb, acb_dma);
9408exit_port_reset:
9409 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9410 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9411 return rval;
9412}
9413
9414static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9415{
9416 struct scsi_qla_host *ha = to_qla_host(shost);
9417 int rval = QLA_SUCCESS;
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009418 uint32_t idc_ctrl;
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009419
9420 if (ql4xdontresethba) {
9421 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9422 __func__));
9423 rval = -EPERM;
9424 goto exit_host_reset;
9425 }
9426
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009427 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9428 goto recover_adapter;
9429
9430 switch (reset_type) {
9431 case SCSI_ADAPTER_RESET:
9432 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9433 break;
9434 case SCSI_FIRMWARE_RESET:
9435 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009436 if (is_qla80XX(ha))
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009437 /* set firmware context reset */
9438 set_bit(DPC_RESET_HA_FW_CONTEXT,
9439 &ha->dpc_flags);
9440 else {
9441 rval = qla4xxx_context_reset(ha);
9442 goto exit_host_reset;
9443 }
9444 }
9445 break;
9446 }
9447
9448recover_adapter:
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009449 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009450 * reset is issued by application */
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009451 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9452 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudharyebd777d2013-03-07 05:43:09 -05009453 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9454 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9455 (idc_ctrl | GRACEFUL_RESET_BIT1));
9456 }
9457
Vikas Chaudhary95d31262011-08-12 02:51:29 -07009458 rval = qla4xxx_recover_adapter(ha);
9459 if (rval != QLA_SUCCESS) {
9460 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9461 __func__));
9462 rval = -EIO;
9463 }
9464
9465exit_host_reset:
9466 return rval;
9467}
9468
Lalit Chandivade2232be02010-07-30 14:38:47 +05309469/* PCI AER driver recovers from all correctable errors w/o
9470 * driver intervention. For uncorrectable errors PCI AER
9471 * driver calls the following device driver's callbacks
9472 *
9473 * - Fatal Errors - link_reset
9474 * - Non-Fatal Errors - driver's pci_error_detected() which
9475 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9476 *
9477 * PCI AER driver calls
9478 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
9479 * returns RECOVERED or NEED_RESET if fw_hung
9480 * NEED_RESET - driver's slot_reset()
9481 * DISCONNECT - device is dead & cannot recover
9482 * RECOVERED - driver's pci_resume()
9483 */
9484static pci_ers_result_t
9485qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9486{
9487 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9488
9489 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9490 ha->host_no, __func__, state);
9491
9492 if (!is_aer_supported(ha))
9493 return PCI_ERS_RESULT_NONE;
9494
9495 switch (state) {
9496 case pci_channel_io_normal:
9497 clear_bit(AF_EEH_BUSY, &ha->flags);
9498 return PCI_ERS_RESULT_CAN_RECOVER;
9499 case pci_channel_io_frozen:
9500 set_bit(AF_EEH_BUSY, &ha->flags);
9501 qla4xxx_mailbox_premature_completion(ha);
9502 qla4xxx_free_irqs(ha);
9503 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009504 /* Return back all IOs */
9505 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309506 return PCI_ERS_RESULT_NEED_RESET;
9507 case pci_channel_io_perm_failure:
9508 set_bit(AF_EEH_BUSY, &ha->flags);
9509 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9510 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9511 return PCI_ERS_RESULT_DISCONNECT;
9512 }
9513 return PCI_ERS_RESULT_NEED_RESET;
9514}
9515
9516/**
9517 * qla4xxx_pci_mmio_enabled() gets called if
9518 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9519 * and read/write to the device still works.
9520 **/
9521static pci_ers_result_t
9522qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9523{
9524 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9525
9526 if (!is_aer_supported(ha))
9527 return PCI_ERS_RESULT_NONE;
9528
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009529 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05309530}
9531
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009532static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05309533{
9534 uint32_t rval = QLA_ERROR;
9535 int fn;
9536 struct pci_dev *other_pdev = NULL;
9537
9538 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9539
9540 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9541
9542 if (test_bit(AF_ONLINE, &ha->flags)) {
9543 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05009544 clear_bit(AF_LINK_UP, &ha->flags);
9545 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309546 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309547 }
9548
9549 fn = PCI_FUNC(ha->pdev->devfn);
9550 while (fn > 0) {
9551 fn--;
9552 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
9553 "func %x\n", ha->host_no, __func__, fn);
9554 /* Get the pci device given the domain, bus,
9555 * slot/function number */
9556 other_pdev =
9557 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
9558 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9559 fn));
9560
9561 if (!other_pdev)
9562 continue;
9563
9564 if (atomic_read(&other_pdev->enable_cnt)) {
9565 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
9566 "func in enabled state%x\n", ha->host_no,
9567 __func__, fn);
9568 pci_dev_put(other_pdev);
9569 break;
9570 }
9571 pci_dev_put(other_pdev);
9572 }
9573
9574 /* The first function on the card, the reset owner will
9575 * start & initialize the firmware. The other functions
9576 * on the card will reset the firmware context
9577 */
9578 if (!fn) {
9579 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9580 "0x%x is the owner\n", ha->host_no, __func__,
9581 ha->pdev->devfn);
9582
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009583 ha->isp_ops->idc_lock(ha);
9584 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9585 QLA8XXX_DEV_COLD);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009586 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309587
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009588 rval = qla4_8xxx_update_idc_reg(ha);
9589 if (rval == QLA_ERROR) {
9590 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9591 ha->host_no, __func__);
9592 ha->isp_ops->idc_lock(ha);
9593 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9594 QLA8XXX_DEV_FAILED);
9595 ha->isp_ops->idc_unlock(ha);
9596 goto exit_error_recovery;
9597 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309598
Lalit Chandivade2232be02010-07-30 14:38:47 +05309599 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009600 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309601
9602 if (rval != QLA_SUCCESS) {
9603 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9604 "FAILED\n", ha->host_no, __func__);
Poornima Vonti82761902012-09-20 07:35:04 -04009605 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309606 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009607 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9608 QLA8XXX_DEV_FAILED);
Poornima Vonti82761902012-09-20 07:35:04 -04009609 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309610 } else {
9611 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9612 "READY\n", ha->host_no, __func__);
Poornima Vonti82761902012-09-20 07:35:04 -04009613 ha->isp_ops->idc_lock(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009614 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9615 QLA8XXX_DEV_READY);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309616 /* Clear driver state register */
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009617 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309618 qla4_8xxx_set_drv_active(ha);
Poornima Vonti82761902012-09-20 07:35:04 -04009619 ha->isp_ops->idc_unlock(ha);
Poornima Vonti137257d2013-01-20 23:51:01 -05009620 ha->isp_ops->enable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309621 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05309622 } else {
9623 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9624 "the reset owner\n", ha->host_no, __func__,
9625 ha->pdev->devfn);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009626 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9627 QLA8XXX_DEV_READY)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309628 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06009629 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Poornima Vonti137257d2013-01-20 23:51:01 -05009630 if (rval == QLA_SUCCESS)
9631 ha->isp_ops->enable_intrs(ha);
9632
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009633 ha->isp_ops->idc_lock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309634 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04009635 ha->isp_ops->idc_unlock(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309636 }
9637 }
Vikas Chaudhary39c95822012-09-20 07:35:05 -04009638exit_error_recovery:
Lalit Chandivade2232be02010-07-30 14:38:47 +05309639 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9640 return rval;
9641}
9642
9643static pci_ers_result_t
9644qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9645{
9646 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9647 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9648 int rc;
9649
9650 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9651 ha->host_no, __func__);
9652
9653 if (!is_aer_supported(ha))
9654 return PCI_ERS_RESULT_NONE;
9655
9656 /* Restore the saved state of PCIe device -
9657 * BAR registers, PCI Config space, PCIX, MSI,
9658 * IOV states
9659 */
9660 pci_restore_state(pdev);
9661
9662 /* pci_restore_state() clears the saved_state flag of the device
9663 * save restored state which resets saved_state flag
9664 */
9665 pci_save_state(pdev);
9666
9667 /* Initialize device or resume if in suspended state */
9668 rc = pci_enable_device(pdev);
9669 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03009670 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05309671 "device after reset\n", ha->host_no, __func__);
9672 goto exit_slot_reset;
9673 }
9674
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07009675 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05309676
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009677 if (is_qla80XX(ha)) {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309678 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9679 ret = PCI_ERS_RESULT_RECOVERED;
9680 goto exit_slot_reset;
9681 } else
9682 goto exit_slot_reset;
9683 }
9684
9685exit_slot_reset:
9686 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9687 "device after reset\n", ha->host_no, __func__, ret);
9688 return ret;
9689}
9690
9691static void
9692qla4xxx_pci_resume(struct pci_dev *pdev)
9693{
9694 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9695 int ret;
9696
9697 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9698 ha->host_no, __func__);
9699
9700 ret = qla4xxx_wait_for_hba_online(ha);
9701 if (ret != QLA_SUCCESS) {
9702 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9703 "resume I/O from slot/link_reset\n", ha->host_no,
9704 __func__);
9705 }
9706
9707 pci_cleanup_aer_uncorrect_error_status(pdev);
9708 clear_bit(AF_EEH_BUSY, &ha->flags);
9709}
9710
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07009711static const struct pci_error_handlers qla4xxx_err_handler = {
Lalit Chandivade2232be02010-07-30 14:38:47 +05309712 .error_detected = qla4xxx_pci_error_detected,
9713 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9714 .slot_reset = qla4xxx_pci_slot_reset,
9715 .resume = qla4xxx_pci_resume,
9716};
9717
David Somayajuluafaf5a22006-09-19 10:28:00 -07009718static struct pci_device_id qla4xxx_pci_tbl[] = {
9719 {
9720 .vendor = PCI_VENDOR_ID_QLOGIC,
9721 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9722 .subvendor = PCI_ANY_ID,
9723 .subdevice = PCI_ANY_ID,
9724 },
9725 {
9726 .vendor = PCI_VENDOR_ID_QLOGIC,
9727 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9728 .subvendor = PCI_ANY_ID,
9729 .subdevice = PCI_ANY_ID,
9730 },
David C Somayajulud9150582006-11-15 17:38:40 -08009731 {
9732 .vendor = PCI_VENDOR_ID_QLOGIC,
9733 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9734 .subvendor = PCI_ANY_ID,
9735 .subdevice = PCI_ANY_ID,
9736 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05309737 {
9738 .vendor = PCI_VENDOR_ID_QLOGIC,
9739 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9740 .subvendor = PCI_ANY_ID,
9741 .subdevice = PCI_ANY_ID,
9742 },
Vikas Chaudhary6e7b4292012-08-22 07:55:08 -04009743 {
9744 .vendor = PCI_VENDOR_ID_QLOGIC,
9745 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9746 .subvendor = PCI_ANY_ID,
9747 .subdevice = PCI_ANY_ID,
9748 },
Vikas Chaudharyb37ca412013-08-16 07:03:02 -04009749 {
9750 .vendor = PCI_VENDOR_ID_QLOGIC,
9751 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9752 .subvendor = PCI_ANY_ID,
9753 .subdevice = PCI_ANY_ID,
9754 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07009755 {0, 0},
9756};
9757MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9758
Adrian Bunk47975472007-04-26 00:35:16 -07009759static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07009760 .name = DRIVER_NAME,
9761 .id_table = qla4xxx_pci_tbl,
9762 .probe = qla4xxx_probe_adapter,
9763 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05309764 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07009765};
9766
9767static int __init qla4xxx_module_init(void)
9768{
9769 int ret;
9770
9771 /* Allocate cache for SRBs. */
9772 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09009773 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07009774 if (srb_cachep == NULL) {
9775 printk(KERN_ERR
9776 "%s: Unable to allocate SRB cache..."
9777 "Failing load!\n", DRIVER_NAME);
9778 ret = -ENOMEM;
9779 goto no_srp_cache;
9780 }
9781
9782 /* Derive version string. */
9783 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07009784 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07009785 strcat(qla4xxx_version_str, "-debug");
9786
9787 qla4xxx_scsi_transport =
9788 iscsi_register_transport(&qla4xxx_iscsi_transport);
9789 if (!qla4xxx_scsi_transport){
9790 ret = -ENODEV;
9791 goto release_srb_cache;
9792 }
9793
David Somayajuluafaf5a22006-09-19 10:28:00 -07009794 ret = pci_register_driver(&qla4xxx_pci_driver);
9795 if (ret)
9796 goto unregister_transport;
9797
9798 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9799 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05009800
David Somayajuluafaf5a22006-09-19 10:28:00 -07009801unregister_transport:
9802 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9803release_srb_cache:
9804 kmem_cache_destroy(srb_cachep);
9805no_srp_cache:
9806 return ret;
9807}
9808
9809static void __exit qla4xxx_module_exit(void)
9810{
David Somayajuluafaf5a22006-09-19 10:28:00 -07009811 pci_unregister_driver(&qla4xxx_pci_driver);
9812 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9813 kmem_cache_destroy(srb_cachep);
9814}
9815
9816module_init(qla4xxx_module_init);
9817module_exit(qla4xxx_module_exit);
9818
9819MODULE_AUTHOR("QLogic Corporation");
9820MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9821MODULE_LICENSE("GPL");
9822MODULE_VERSION(QLA4XXX_DRIVER_VERSION);