2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/blkdev.h>
10 #include <linux/iscsi_boot_sysfs.h>
11 #include <linux/inet.h>
13 #include <scsi/scsi_tcq.h>
14 #include <scsi/scsicam.h>
17 #include "ql4_version.h"
20 #include "ql4_inline.h"
26 static char qla4xxx_version_str[40];
29 * SRB allocation cache
31 static struct kmem_cache *srb_cachep;
34 * Module parameter information and variables
36 static int ql4xdisablesysfsboot = 1;
37 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
38 MODULE_PARM_DESC(ql4xdisablesysfsboot,
39 " 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)");
44 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql4xdontresethba,
46 " 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");
50 int ql4xextended_error_logging;
51 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
52 MODULE_PARM_DESC(ql4xextended_error_logging,
53 " Option to enable extended error logging.\n"
54 "\t\t 0 - no logging (Default)\n"
55 "\t\t 2 - debug logging");
57 int ql4xenablemsix = 1;
58 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
59 MODULE_PARM_DESC(ql4xenablemsix,
60 " 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.");
65 #define QL4_DEF_QDEPTH 32
66 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
67 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
68 MODULE_PARM_DESC(ql4xmaxqdepth,
69 " Maximum queue depth to report for target devices.\n"
72 static int ql4xqfulltracking = 1;
73 module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
74 MODULE_PARM_DESC(ql4xqfulltracking,
75 " Enable or disable dynamic tracking and adjustment of\n"
76 "\t\t scsi device queue depth.\n"
78 "\t\t 1 - Enable. (Default)");
80 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
81 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
82 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
83 " Target Session Recovery Timeout.\n"
84 "\t\t Default: 120 sec.");
86 int ql4xmdcapmask = 0;
87 module_param(ql4xmdcapmask, int, S_IRUGO);
88 MODULE_PARM_DESC(ql4xmdcapmask,
89 " Set the Minidump driver capture mask level.\n"
90 "\t\t Default is 0 (firmware default capture mask)\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
94 module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
95 MODULE_PARM_DESC(ql4xenablemd,
96 " Set to enable minidump.\n"
97 "\t\t 0 - disable minidump\n"
98 "\t\t 1 - enable minidump (Default)");
100 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
102 * SCSI host template entry points
104 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
107 * iSCSI template entry points
109 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
110 enum iscsi_param param, char *buf);
111 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
112 enum iscsi_param param, char *buf);
113 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
114 enum iscsi_host_param param, char *buf);
115 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
117 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
118 enum iscsi_param_type param_type,
119 int param, char *buf);
120 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
121 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
122 struct sockaddr *dst_addr,
124 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
125 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
126 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
127 enum iscsi_param param, char *buf);
128 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
129 static struct iscsi_cls_conn *
130 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
131 static 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);
134 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
135 static struct iscsi_cls_session *
136 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
137 uint16_t qdepth, uint32_t initial_cmdsn);
138 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
139 static void qla4xxx_task_work(struct work_struct *wdata);
140 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
141 static int qla4xxx_task_xmit(struct iscsi_task *);
142 static void qla4xxx_task_cleanup(struct iscsi_task *);
143 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
144 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
145 struct iscsi_stats *stats);
146 static 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);
149 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
150 uint32_t *num_entries, char *buf);
151 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
152 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
154 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
157 * SCSI host template entry points
159 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
161 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
162 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
163 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164 static int qla4xxx_slave_alloc(struct scsi_device *device);
165 static umode_t qla4_attr_is_visible(int param_type, int param);
166 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
169 * iSCSI Flash DDB sysfs entry points
172 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
173 struct iscsi_bus_flash_conn *fnode_conn,
174 void *data, int len);
176 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
177 int param, char *buf);
178 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
181 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
182 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
183 struct iscsi_bus_flash_conn *fnode_conn);
184 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
185 struct iscsi_bus_flash_conn *fnode_conn);
186 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
188 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
189 QLA82XX_LEGACY_INTR_CONFIG;
191 static struct scsi_host_template qla4xxx_driver_template = {
192 .module = THIS_MODULE,
194 .proc_name = DRIVER_NAME,
195 .queuecommand = qla4xxx_queuecommand,
197 .eh_abort_handler = qla4xxx_eh_abort,
198 .eh_device_reset_handler = qla4xxx_eh_device_reset,
199 .eh_target_reset_handler = qla4xxx_eh_target_reset,
200 .eh_host_reset_handler = qla4xxx_eh_host_reset,
201 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
203 .slave_alloc = qla4xxx_slave_alloc,
204 .change_queue_depth = scsi_change_queue_depth,
208 .sg_tablesize = SG_ALL,
210 .max_sectors = 0xFFFF,
211 .shost_attrs = qla4xxx_host_attrs,
212 .host_reset = qla4xxx_host_reset,
213 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
216 static struct iscsi_transport qla4xxx_iscsi_transport = {
217 .owner = THIS_MODULE,
219 .caps = CAP_TEXT_NEGO |
220 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
221 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
223 .attr_is_visible = qla4_attr_is_visible,
224 .create_session = qla4xxx_session_create,
225 .destroy_session = qla4xxx_session_destroy,
226 .start_conn = qla4xxx_conn_start,
227 .create_conn = qla4xxx_conn_create,
228 .bind_conn = qla4xxx_conn_bind,
229 .stop_conn = iscsi_conn_stop,
230 .destroy_conn = qla4xxx_conn_destroy,
231 .set_param = iscsi_set_param,
232 .get_conn_param = qla4xxx_conn_get_param,
233 .get_session_param = qla4xxx_session_get_param,
234 .get_ep_param = qla4xxx_get_ep_param,
235 .ep_connect = qla4xxx_ep_connect,
236 .ep_poll = qla4xxx_ep_poll,
237 .ep_disconnect = qla4xxx_ep_disconnect,
238 .get_stats = qla4xxx_conn_get_stats,
239 .send_pdu = iscsi_conn_send_pdu,
240 .xmit_task = qla4xxx_task_xmit,
241 .cleanup_task = qla4xxx_task_cleanup,
242 .alloc_pdu = qla4xxx_alloc_pdu,
244 .get_host_param = qla4xxx_host_get_param,
245 .set_iface_param = qla4xxx_iface_set_param,
246 .get_iface_param = qla4xxx_get_iface_param,
247 .bsg_request = qla4xxx_bsg_request,
248 .send_ping = qla4xxx_send_ping,
249 .get_chap = qla4xxx_get_chap_list,
250 .delete_chap = qla4xxx_delete_chap,
251 .set_chap = qla4xxx_set_chap_entry,
252 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
253 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
254 .new_flashnode = qla4xxx_sysfs_ddb_add,
255 .del_flashnode = qla4xxx_sysfs_ddb_delete,
256 .login_flashnode = qla4xxx_sysfs_ddb_login,
257 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
258 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
259 .get_host_stats = qla4xxx_get_host_stats,
262 static struct scsi_transport_template *qla4xxx_scsi_transport;
264 static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
267 int rval = QLA_SUCCESS;
270 reg_val = readl(&ha->qla4_82xx_reg->host_status);
271 else if (is_qla8032(ha) || is_qla8042(ha))
272 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
274 reg_val = readw(&ha->reg->ctrl_status);
276 if (reg_val == QL4_ISP_REG_DISCONNECT)
282 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
283 uint32_t iface_type, uint32_t payload_size,
284 uint32_t pid, struct sockaddr *dst_addr)
286 struct scsi_qla_host *ha = to_qla_host(shost);
287 struct sockaddr_in *addr;
288 struct sockaddr_in6 *addr6;
289 uint32_t options = 0;
290 uint8_t ipaddr[IPv6_ADDR_LEN];
293 memset(ipaddr, 0, IPv6_ADDR_LEN);
295 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
296 (dst_addr->sa_family == AF_INET)) {
297 addr = (struct sockaddr_in *)dst_addr;
298 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
299 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
300 "dest: %pI4\n", __func__,
301 &ha->ip_config.ip_address, ipaddr));
302 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
306 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
307 (dst_addr->sa_family == AF_INET6)) {
309 addr6 = (struct sockaddr_in6 *)dst_addr;
310 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
312 options |= PING_IPV6_PROTOCOL_ENABLE;
314 /* Ping using LinkLocal address */
315 if ((iface_num == 0) || (iface_num == 1)) {
316 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
317 "src: %pI6 dest: %pI6\n", __func__,
318 &ha->ip_config.ipv6_link_local_addr,
320 options |= PING_IPV6_LINKLOCAL_ADDR;
321 rval = qla4xxx_ping_iocb(ha, options, payload_size,
324 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
325 "not supported\n", __func__, iface_num);
331 * If ping using LinkLocal address fails, try ping using
334 if (rval != QLA_SUCCESS) {
335 options &= ~PING_IPV6_LINKLOCAL_ADDR;
336 if (iface_num == 0) {
337 options |= PING_IPV6_ADDR0;
338 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
340 "dest: %pI6\n", __func__,
341 &ha->ip_config.ipv6_addr0,
343 } else if (iface_num == 1) {
344 options |= PING_IPV6_ADDR1;
345 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
347 "dest: %pI6\n", __func__,
348 &ha->ip_config.ipv6_addr1,
351 rval = qla4xxx_ping_iocb(ha, options, payload_size,
362 static umode_t qla4_attr_is_visible(int param_type, int param)
364 switch (param_type) {
365 case ISCSI_HOST_PARAM:
367 case ISCSI_HOST_PARAM_HWADDRESS:
368 case ISCSI_HOST_PARAM_IPADDRESS:
369 case ISCSI_HOST_PARAM_INITIATOR_NAME:
370 case ISCSI_HOST_PARAM_PORT_STATE:
371 case ISCSI_HOST_PARAM_PORT_SPEED:
378 case ISCSI_PARAM_PERSISTENT_ADDRESS:
379 case ISCSI_PARAM_PERSISTENT_PORT:
380 case ISCSI_PARAM_CONN_ADDRESS:
381 case ISCSI_PARAM_CONN_PORT:
382 case ISCSI_PARAM_TARGET_NAME:
383 case ISCSI_PARAM_TPGT:
384 case ISCSI_PARAM_TARGET_ALIAS:
385 case ISCSI_PARAM_MAX_BURST:
386 case ISCSI_PARAM_MAX_R2T:
387 case ISCSI_PARAM_FIRST_BURST:
388 case ISCSI_PARAM_MAX_RECV_DLENGTH:
389 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
390 case ISCSI_PARAM_IFACE_NAME:
391 case ISCSI_PARAM_CHAP_OUT_IDX:
392 case ISCSI_PARAM_CHAP_IN_IDX:
393 case ISCSI_PARAM_USERNAME:
394 case ISCSI_PARAM_PASSWORD:
395 case ISCSI_PARAM_USERNAME_IN:
396 case ISCSI_PARAM_PASSWORD_IN:
397 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
398 case ISCSI_PARAM_DISCOVERY_SESS:
399 case ISCSI_PARAM_PORTAL_TYPE:
400 case ISCSI_PARAM_CHAP_AUTH_EN:
401 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
402 case ISCSI_PARAM_BIDI_CHAP_EN:
403 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
404 case ISCSI_PARAM_DEF_TIME2WAIT:
405 case ISCSI_PARAM_DEF_TIME2RETAIN:
406 case ISCSI_PARAM_HDRDGST_EN:
407 case ISCSI_PARAM_DATADGST_EN:
408 case ISCSI_PARAM_INITIAL_R2T_EN:
409 case ISCSI_PARAM_IMM_DATA_EN:
410 case ISCSI_PARAM_PDU_INORDER_EN:
411 case ISCSI_PARAM_DATASEQ_INORDER_EN:
412 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
413 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
414 case ISCSI_PARAM_TCP_WSF_DISABLE:
415 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
416 case ISCSI_PARAM_TCP_TIMER_SCALE:
417 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
418 case ISCSI_PARAM_TCP_XMIT_WSF:
419 case ISCSI_PARAM_TCP_RECV_WSF:
420 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
421 case ISCSI_PARAM_IPV4_TOS:
422 case ISCSI_PARAM_IPV6_TC:
423 case ISCSI_PARAM_IPV6_FLOW_LABEL:
424 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
425 case ISCSI_PARAM_KEEPALIVE_TMO:
426 case ISCSI_PARAM_LOCAL_PORT:
427 case ISCSI_PARAM_ISID:
428 case ISCSI_PARAM_TSID:
429 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
430 case ISCSI_PARAM_ERL:
431 case ISCSI_PARAM_STATSN:
432 case ISCSI_PARAM_EXP_STATSN:
433 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
434 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
435 case ISCSI_PARAM_LOCAL_IPADDR:
440 case ISCSI_NET_PARAM:
442 case ISCSI_NET_PARAM_IPV4_ADDR:
443 case ISCSI_NET_PARAM_IPV4_SUBNET:
444 case ISCSI_NET_PARAM_IPV4_GW:
445 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
446 case ISCSI_NET_PARAM_IFACE_ENABLE:
447 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
448 case ISCSI_NET_PARAM_IPV6_ADDR:
449 case ISCSI_NET_PARAM_IPV6_ROUTER:
450 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
451 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
452 case ISCSI_NET_PARAM_VLAN_ID:
453 case ISCSI_NET_PARAM_VLAN_PRIORITY:
454 case ISCSI_NET_PARAM_VLAN_ENABLED:
455 case ISCSI_NET_PARAM_MTU:
456 case ISCSI_NET_PARAM_PORT:
457 case ISCSI_NET_PARAM_IPADDR_STATE:
458 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
459 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
460 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
461 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
462 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
463 case ISCSI_NET_PARAM_TCP_WSF:
464 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
465 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
466 case ISCSI_NET_PARAM_CACHE_ID:
467 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
468 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
469 case ISCSI_NET_PARAM_IPV4_TOS_EN:
470 case ISCSI_NET_PARAM_IPV4_TOS:
471 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
472 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
473 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
474 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
475 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
476 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
477 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
478 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
479 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
480 case ISCSI_NET_PARAM_REDIRECT_EN:
481 case ISCSI_NET_PARAM_IPV4_TTL:
482 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
483 case ISCSI_NET_PARAM_IPV6_MLD_EN:
484 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
485 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
486 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
487 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
488 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
489 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
490 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
491 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
496 case ISCSI_IFACE_PARAM:
498 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
499 case ISCSI_IFACE_PARAM_HDRDGST_EN:
500 case ISCSI_IFACE_PARAM_DATADGST_EN:
501 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
502 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
503 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
504 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
505 case ISCSI_IFACE_PARAM_ERL:
506 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
507 case ISCSI_IFACE_PARAM_FIRST_BURST:
508 case ISCSI_IFACE_PARAM_MAX_R2T:
509 case ISCSI_IFACE_PARAM_MAX_BURST:
510 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
511 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
512 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
513 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
514 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
515 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
520 case ISCSI_FLASHNODE_PARAM:
522 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
523 case ISCSI_FLASHNODE_PORTAL_TYPE:
524 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
525 case ISCSI_FLASHNODE_DISCOVERY_SESS:
526 case ISCSI_FLASHNODE_ENTRY_EN:
527 case ISCSI_FLASHNODE_HDR_DGST_EN:
528 case ISCSI_FLASHNODE_DATA_DGST_EN:
529 case ISCSI_FLASHNODE_IMM_DATA_EN:
530 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
531 case ISCSI_FLASHNODE_DATASEQ_INORDER:
532 case ISCSI_FLASHNODE_PDU_INORDER:
533 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
534 case ISCSI_FLASHNODE_SNACK_REQ_EN:
535 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
536 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
537 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
538 case ISCSI_FLASHNODE_ERL:
539 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
540 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
541 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
542 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
543 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
544 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
545 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
546 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
547 case ISCSI_FLASHNODE_FIRST_BURST:
548 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
549 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
550 case ISCSI_FLASHNODE_MAX_R2T:
551 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
552 case ISCSI_FLASHNODE_ISID:
553 case ISCSI_FLASHNODE_TSID:
554 case ISCSI_FLASHNODE_PORT:
555 case ISCSI_FLASHNODE_MAX_BURST:
556 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
557 case ISCSI_FLASHNODE_IPADDR:
558 case ISCSI_FLASHNODE_ALIAS:
559 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
560 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
561 case ISCSI_FLASHNODE_LOCAL_PORT:
562 case ISCSI_FLASHNODE_IPV4_TOS:
563 case ISCSI_FLASHNODE_IPV6_TC:
564 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
565 case ISCSI_FLASHNODE_NAME:
566 case ISCSI_FLASHNODE_TPGT:
567 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
568 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
569 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
570 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
571 case ISCSI_FLASHNODE_TCP_RECV_WSF:
572 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
573 case ISCSI_FLASHNODE_USERNAME:
574 case ISCSI_FLASHNODE_PASSWORD:
575 case ISCSI_FLASHNODE_STATSN:
576 case ISCSI_FLASHNODE_EXP_STATSN:
577 case ISCSI_FLASHNODE_IS_BOOT_TGT:
588 * qla4xxx_create chap_list - Create CHAP list from FLASH
589 * @ha: pointer to adapter structure
591 * Read flash and make a list of CHAP entries, during login when a CHAP entry
592 * is received, it will be checked in this list. If entry exist then the CHAP
593 * entry index is set in the DDB. If CHAP entry does not exist in this list
594 * then a new entry is added in FLASH in CHAP table and the index obtained is
597 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
600 uint8_t *chap_flash_data = NULL;
603 uint32_t chap_size = 0;
606 chap_size = MAX_CHAP_ENTRIES_40XX *
607 sizeof(struct ql4_chap_table);
608 else /* Single region contains CHAP info for both
609 * ports which is divided into half for each port.
611 chap_size = ha->hw.flt_chap_size / 2;
613 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
614 &chap_dma, GFP_KERNEL);
615 if (!chap_flash_data) {
616 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
620 if (is_qla40XX(ha)) {
621 offset = FLASH_CHAP_OFFSET;
623 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
624 if (ha->port_num == 1)
628 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
629 if (rval != QLA_SUCCESS)
632 if (ha->chap_list == NULL)
633 ha->chap_list = vmalloc(chap_size);
634 if (ha->chap_list == NULL) {
635 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
639 memset(ha->chap_list, 0, chap_size);
640 memcpy(ha->chap_list, chap_flash_data, chap_size);
643 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
646 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
648 struct ql4_chap_table **chap_entry)
650 int rval = QLA_ERROR;
651 int max_chap_entries;
653 if (!ha->chap_list) {
654 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
660 max_chap_entries = (ha->hw.flt_chap_size / 2) /
661 sizeof(struct ql4_chap_table);
663 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
665 if (chap_index > max_chap_entries) {
666 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
671 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
672 if ((*chap_entry)->cookie !=
673 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
685 * qla4xxx_find_free_chap_index - Find the first free chap index
686 * @ha: pointer to adapter structure
687 * @chap_index: CHAP index to be returned
689 * Find the first free chap index available in the chap table
691 * Note: Caller should acquire the chap lock before getting here.
693 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
694 uint16_t *chap_index)
698 int max_chap_entries = 0;
699 struct ql4_chap_table *chap_table;
702 max_chap_entries = (ha->hw.flt_chap_size / 2) /
703 sizeof(struct ql4_chap_table);
705 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
707 if (!ha->chap_list) {
708 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
713 for (i = 0; i < max_chap_entries; i++) {
714 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
716 if ((chap_table->cookie !=
717 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
718 (i > MAX_RESRV_CHAP_IDX)) {
724 if (free_index != -1) {
725 *chap_index = free_index;
735 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
736 uint32_t *num_entries, char *buf)
738 struct scsi_qla_host *ha = to_qla_host(shost);
739 struct ql4_chap_table *chap_table;
740 struct iscsi_chap_rec *chap_rec;
741 int max_chap_entries = 0;
742 int valid_chap_entries = 0;
746 max_chap_entries = (ha->hw.flt_chap_size / 2) /
747 sizeof(struct ql4_chap_table);
749 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
751 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
752 __func__, *num_entries, chap_tbl_idx);
756 goto exit_get_chap_list;
759 qla4xxx_create_chap_list(ha);
761 chap_rec = (struct iscsi_chap_rec *) buf;
762 mutex_lock(&ha->chap_sem);
763 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
764 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
765 if (chap_table->cookie !=
766 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
769 chap_rec->chap_tbl_idx = i;
770 strlcpy(chap_rec->username, chap_table->name,
771 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
772 strlcpy(chap_rec->password, chap_table->secret,
773 QL4_CHAP_MAX_SECRET_LEN);
774 chap_rec->password_length = chap_table->secret_len;
776 if (chap_table->flags & BIT_7) /* local */
777 chap_rec->chap_type = CHAP_TYPE_OUT;
779 if (chap_table->flags & BIT_6) /* peer */
780 chap_rec->chap_type = CHAP_TYPE_IN;
784 valid_chap_entries++;
785 if (valid_chap_entries == *num_entries)
790 mutex_unlock(&ha->chap_sem);
793 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
794 __func__, valid_chap_entries);
795 *num_entries = valid_chap_entries;
799 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
802 uint16_t *chap_tbl_idx = (uint16_t *) data;
803 struct iscsi_cls_session *cls_session;
804 struct iscsi_session *sess;
805 struct ddb_entry *ddb_entry;
807 if (!iscsi_is_session_dev(dev))
808 goto exit_is_chap_active;
810 cls_session = iscsi_dev_to_session(dev);
811 sess = cls_session->dd_data;
812 ddb_entry = sess->dd_data;
814 if (iscsi_session_chkready(cls_session))
815 goto exit_is_chap_active;
817 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
824 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
825 uint16_t chap_tbl_idx)
829 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
830 __qla4xxx_is_chap_active);
835 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
837 struct scsi_qla_host *ha = to_qla_host(shost);
838 struct ql4_chap_table *chap_table;
840 int max_chap_entries = 0;
845 chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
846 if (chap_table == NULL)
850 max_chap_entries = (ha->hw.flt_chap_size / 2) /
851 sizeof(struct ql4_chap_table);
853 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
855 if (chap_tbl_idx > max_chap_entries) {
857 goto exit_delete_chap;
860 /* Check if chap index is in use.
861 * If chap is in use don't delet chap entry */
862 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
864 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
865 "delete from flash\n", chap_tbl_idx);
867 goto exit_delete_chap;
870 chap_size = sizeof(struct ql4_chap_table);
872 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
874 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
875 /* flt_chap_size is CHAP table size for both ports
876 * so divide it by 2 to calculate the offset for second port
878 if (ha->port_num == 1)
879 offset += (ha->hw.flt_chap_size / 2);
880 offset += (chap_tbl_idx * chap_size);
883 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
884 if (ret != QLA_SUCCESS) {
886 goto exit_delete_chap;
889 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
890 __le16_to_cpu(chap_table->cookie)));
892 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
893 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
894 goto exit_delete_chap;
897 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
899 offset = FLASH_CHAP_OFFSET |
900 (chap_tbl_idx * sizeof(struct ql4_chap_table));
901 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
902 FLASH_OPT_RMW_COMMIT);
903 if (ret == QLA_SUCCESS && ha->chap_list) {
904 mutex_lock(&ha->chap_sem);
905 /* Update ha chap_list cache */
906 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
907 chap_table, sizeof(struct ql4_chap_table));
908 mutex_unlock(&ha->chap_sem);
910 if (ret != QLA_SUCCESS)
914 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
919 * qla4xxx_set_chap_entry - Make chap entry with given information
920 * @shost: pointer to host
921 * @data: chap info - credentials, index and type to make chap entry
922 * @len: length of data
924 * Add or update chap entry with the given information
926 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
928 struct scsi_qla_host *ha = to_qla_host(shost);
929 struct iscsi_chap_rec chap_rec;
930 struct ql4_chap_table *chap_entry = NULL;
931 struct iscsi_param_info *param_info;
933 int max_chap_entries = 0;
939 memset(&chap_rec, 0, sizeof(chap_rec));
941 nla_for_each_attr(attr, data, len, rem) {
942 param_info = nla_data(attr);
944 switch (param_info->param) {
945 case ISCSI_CHAP_PARAM_INDEX:
946 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
948 case ISCSI_CHAP_PARAM_CHAP_TYPE:
949 chap_rec.chap_type = param_info->value[0];
951 case ISCSI_CHAP_PARAM_USERNAME:
952 size = min_t(size_t, sizeof(chap_rec.username),
954 memcpy(chap_rec.username, param_info->value, size);
956 case ISCSI_CHAP_PARAM_PASSWORD:
957 size = min_t(size_t, sizeof(chap_rec.password),
959 memcpy(chap_rec.password, param_info->value, size);
961 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
962 chap_rec.password_length = param_info->value[0];
965 ql4_printk(KERN_ERR, ha,
966 "%s: No such sysfs attribute\n", __func__);
972 if (chap_rec.chap_type == CHAP_TYPE_IN)
978 max_chap_entries = (ha->hw.flt_chap_size / 2) /
979 sizeof(struct ql4_chap_table);
981 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
983 mutex_lock(&ha->chap_sem);
984 if (chap_rec.chap_tbl_idx < max_chap_entries) {
985 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
988 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
989 ql4_printk(KERN_INFO, ha,
990 "Type mismatch for CHAP entry %d\n",
991 chap_rec.chap_tbl_idx);
993 goto exit_unlock_chap;
996 /* If chap index is in use then don't modify it */
997 rc = qla4xxx_is_chap_active(shost,
998 chap_rec.chap_tbl_idx);
1000 ql4_printk(KERN_INFO, ha,
1001 "CHAP entry %d is in use\n",
1002 chap_rec.chap_tbl_idx);
1004 goto exit_unlock_chap;
1008 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1010 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1012 goto exit_unlock_chap;
1016 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1017 chap_rec.chap_tbl_idx, type);
1020 mutex_unlock(&ha->chap_sem);
1027 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1029 struct scsi_qla_host *ha = to_qla_host(shost);
1030 struct iscsi_offload_host_stats *host_stats = NULL;
1031 int host_stats_size;
1034 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1036 dma_addr_t iscsi_stats_dma;
1038 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1040 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1042 if (host_stats_size != len) {
1043 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1044 __func__, len, host_stats_size);
1046 goto exit_host_stats;
1048 host_stats = (struct iscsi_offload_host_stats *)buf;
1052 goto exit_host_stats;
1055 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1057 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1058 &iscsi_stats_dma, GFP_KERNEL);
1059 if (!ql_iscsi_stats) {
1060 ql4_printk(KERN_ERR, ha,
1061 "Unable to allocate memory for iscsi stats\n");
1063 goto exit_host_stats;
1066 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1068 if (ret != QLA_SUCCESS) {
1069 ql4_printk(KERN_ERR, ha,
1070 "Unable to retrieve iscsi stats\n");
1072 goto exit_host_stats;
1074 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1075 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1076 host_stats->mactx_multicast_frames =
1077 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1078 host_stats->mactx_broadcast_frames =
1079 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1080 host_stats->mactx_pause_frames =
1081 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1082 host_stats->mactx_control_frames =
1083 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1084 host_stats->mactx_deferral =
1085 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1086 host_stats->mactx_excess_deferral =
1087 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1088 host_stats->mactx_late_collision =
1089 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1090 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1091 host_stats->mactx_single_collision =
1092 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1093 host_stats->mactx_multiple_collision =
1094 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1095 host_stats->mactx_collision =
1096 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1097 host_stats->mactx_frames_dropped =
1098 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1099 host_stats->mactx_jumbo_frames =
1100 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1101 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1102 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1103 host_stats->macrx_unknown_control_frames =
1104 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1105 host_stats->macrx_pause_frames =
1106 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1107 host_stats->macrx_control_frames =
1108 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1109 host_stats->macrx_dribble =
1110 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1111 host_stats->macrx_frame_length_error =
1112 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1113 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1114 host_stats->macrx_carrier_sense_error =
1115 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1116 host_stats->macrx_frame_discarded =
1117 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1118 host_stats->macrx_frames_dropped =
1119 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1120 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1121 host_stats->mac_encoding_error =
1122 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1123 host_stats->macrx_length_error_large =
1124 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1125 host_stats->macrx_length_error_small =
1126 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1127 host_stats->macrx_multicast_frames =
1128 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1129 host_stats->macrx_broadcast_frames =
1130 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1131 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1132 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1133 host_stats->iptx_fragments =
1134 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1135 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1136 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1137 host_stats->iprx_fragments =
1138 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1139 host_stats->ip_datagram_reassembly =
1140 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1141 host_stats->ip_invalid_address_error =
1142 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1143 host_stats->ip_error_packets =
1144 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1145 host_stats->ip_fragrx_overlap =
1146 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1147 host_stats->ip_fragrx_outoforder =
1148 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1149 host_stats->ip_datagram_reassembly_timeout =
1150 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1151 host_stats->ipv6tx_packets =
1152 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1153 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1154 host_stats->ipv6tx_fragments =
1155 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1156 host_stats->ipv6rx_packets =
1157 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1158 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1159 host_stats->ipv6rx_fragments =
1160 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1161 host_stats->ipv6_datagram_reassembly =
1162 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1163 host_stats->ipv6_invalid_address_error =
1164 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1165 host_stats->ipv6_error_packets =
1166 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1167 host_stats->ipv6_fragrx_overlap =
1168 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1169 host_stats->ipv6_fragrx_outoforder =
1170 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1171 host_stats->ipv6_datagram_reassembly_timeout =
1172 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1173 host_stats->tcptx_segments =
1174 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1175 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1176 host_stats->tcprx_segments =
1177 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1178 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1179 host_stats->tcp_duplicate_ack_retx =
1180 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1181 host_stats->tcp_retx_timer_expired =
1182 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1183 host_stats->tcprx_duplicate_ack =
1184 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1185 host_stats->tcprx_pure_ackr =
1186 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1187 host_stats->tcptx_delayed_ack =
1188 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1189 host_stats->tcptx_pure_ack =
1190 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1191 host_stats->tcprx_segment_error =
1192 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1193 host_stats->tcprx_segment_outoforder =
1194 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1195 host_stats->tcprx_window_probe =
1196 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1197 host_stats->tcprx_window_update =
1198 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1199 host_stats->tcptx_window_probe_persist =
1200 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1201 host_stats->ecc_error_correction =
1202 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1203 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1204 host_stats->iscsi_data_bytes_tx =
1205 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1206 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1207 host_stats->iscsi_data_bytes_rx =
1208 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1209 host_stats->iscsi_io_completed =
1210 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1211 host_stats->iscsi_unexpected_io_rx =
1212 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1213 host_stats->iscsi_format_error =
1214 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1215 host_stats->iscsi_hdr_digest_error =
1216 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1217 host_stats->iscsi_data_digest_error =
1218 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1219 host_stats->iscsi_sequence_error =
1220 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1223 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1224 ql_iscsi_stats, iscsi_stats_dma);
1226 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1231 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1232 enum iscsi_param_type param_type,
1233 int param, char *buf)
1235 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1236 struct scsi_qla_host *ha = to_qla_host(shost);
1241 if (param_type == ISCSI_NET_PARAM) {
1243 case ISCSI_NET_PARAM_IPV4_ADDR:
1244 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1246 case ISCSI_NET_PARAM_IPV4_SUBNET:
1247 len = sprintf(buf, "%pI4\n",
1248 &ha->ip_config.subnet_mask);
1250 case ISCSI_NET_PARAM_IPV4_GW:
1251 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1253 case ISCSI_NET_PARAM_IFACE_ENABLE:
1254 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1255 OP_STATE(ha->ip_config.ipv4_options,
1256 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1258 OP_STATE(ha->ip_config.ipv6_options,
1259 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1262 len = sprintf(buf, "%s\n", pval);
1264 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1265 len = sprintf(buf, "%s\n",
1266 (ha->ip_config.tcp_options &
1267 TCPOPT_DHCP_ENABLE) ?
1270 case ISCSI_NET_PARAM_IPV6_ADDR:
1271 if (iface->iface_num == 0)
1272 len = sprintf(buf, "%pI6\n",
1273 &ha->ip_config.ipv6_addr0);
1274 if (iface->iface_num == 1)
1275 len = sprintf(buf, "%pI6\n",
1276 &ha->ip_config.ipv6_addr1);
1278 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1279 len = sprintf(buf, "%pI6\n",
1280 &ha->ip_config.ipv6_link_local_addr);
1282 case ISCSI_NET_PARAM_IPV6_ROUTER:
1283 len = sprintf(buf, "%pI6\n",
1284 &ha->ip_config.ipv6_default_router_addr);
1286 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1287 pval = (ha->ip_config.ipv6_addl_options &
1288 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1291 len = sprintf(buf, "%s\n", pval);
1293 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1294 pval = (ha->ip_config.ipv6_addl_options &
1295 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1298 len = sprintf(buf, "%s\n", pval);
1300 case ISCSI_NET_PARAM_VLAN_ID:
1301 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1302 ival = ha->ip_config.ipv4_vlan_tag &
1305 ival = ha->ip_config.ipv6_vlan_tag &
1308 len = sprintf(buf, "%d\n", ival);
1310 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1311 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1312 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1313 ISCSI_MAX_VLAN_PRIORITY;
1315 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1316 ISCSI_MAX_VLAN_PRIORITY;
1318 len = sprintf(buf, "%d\n", ival);
1320 case ISCSI_NET_PARAM_VLAN_ENABLED:
1321 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1322 OP_STATE(ha->ip_config.ipv4_options,
1323 IPOPT_VLAN_TAGGING_ENABLE, pval);
1325 OP_STATE(ha->ip_config.ipv6_options,
1326 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1328 len = sprintf(buf, "%s\n", pval);
1330 case ISCSI_NET_PARAM_MTU:
1331 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1333 case ISCSI_NET_PARAM_PORT:
1334 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1335 len = sprintf(buf, "%d\n",
1336 ha->ip_config.ipv4_port);
1338 len = sprintf(buf, "%d\n",
1339 ha->ip_config.ipv6_port);
1341 case ISCSI_NET_PARAM_IPADDR_STATE:
1342 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1343 pval = iscsi_get_ipaddress_state_name(
1344 ha->ip_config.ipv4_addr_state);
1346 if (iface->iface_num == 0)
1347 pval = iscsi_get_ipaddress_state_name(
1348 ha->ip_config.ipv6_addr0_state);
1349 else if (iface->iface_num == 1)
1350 pval = iscsi_get_ipaddress_state_name(
1351 ha->ip_config.ipv6_addr1_state);
1354 len = sprintf(buf, "%s\n", pval);
1356 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1357 pval = iscsi_get_ipaddress_state_name(
1358 ha->ip_config.ipv6_link_local_state);
1359 len = sprintf(buf, "%s\n", pval);
1361 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1362 pval = iscsi_get_router_state_name(
1363 ha->ip_config.ipv6_default_router_state);
1364 len = sprintf(buf, "%s\n", pval);
1366 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1367 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1368 OP_STATE(~ha->ip_config.tcp_options,
1369 TCPOPT_DELAYED_ACK_DISABLE, pval);
1371 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1372 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1374 len = sprintf(buf, "%s\n", pval);
1376 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1377 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1378 OP_STATE(~ha->ip_config.tcp_options,
1379 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1381 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1382 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1384 len = sprintf(buf, "%s\n", pval);
1386 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1387 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1388 OP_STATE(~ha->ip_config.tcp_options,
1389 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1391 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1392 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1395 len = sprintf(buf, "%s\n", pval);
1397 case ISCSI_NET_PARAM_TCP_WSF:
1398 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1399 len = sprintf(buf, "%d\n",
1400 ha->ip_config.tcp_wsf);
1402 len = sprintf(buf, "%d\n",
1403 ha->ip_config.ipv6_tcp_wsf);
1405 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1406 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1407 ival = (ha->ip_config.tcp_options &
1408 TCPOPT_TIMER_SCALE) >> 1;
1410 ival = (ha->ip_config.ipv6_tcp_options &
1411 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1413 len = sprintf(buf, "%d\n", ival);
1415 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1416 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1417 OP_STATE(ha->ip_config.tcp_options,
1418 TCPOPT_TIMESTAMP_ENABLE, pval);
1420 OP_STATE(ha->ip_config.ipv6_tcp_options,
1421 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1423 len = sprintf(buf, "%s\n", pval);
1425 case ISCSI_NET_PARAM_CACHE_ID:
1426 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1427 len = sprintf(buf, "%d\n",
1428 ha->ip_config.ipv4_cache_id);
1430 len = sprintf(buf, "%d\n",
1431 ha->ip_config.ipv6_cache_id);
1433 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1434 OP_STATE(ha->ip_config.tcp_options,
1435 TCPOPT_DNS_SERVER_IP_EN, pval);
1437 len = sprintf(buf, "%s\n", pval);
1439 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1440 OP_STATE(ha->ip_config.tcp_options,
1441 TCPOPT_SLP_DA_INFO_EN, pval);
1443 len = sprintf(buf, "%s\n", pval);
1445 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1446 OP_STATE(ha->ip_config.ipv4_options,
1447 IPOPT_IPV4_TOS_EN, pval);
1449 len = sprintf(buf, "%s\n", pval);
1451 case ISCSI_NET_PARAM_IPV4_TOS:
1452 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1454 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1455 OP_STATE(ha->ip_config.ipv4_options,
1456 IPOPT_GRAT_ARP_EN, pval);
1458 len = sprintf(buf, "%s\n", pval);
1460 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1461 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1464 len = sprintf(buf, "%s\n", pval);
1466 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1467 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1468 (char *)ha->ip_config.ipv4_alt_cid : "";
1470 len = sprintf(buf, "%s\n", pval);
1472 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1473 OP_STATE(ha->ip_config.ipv4_options,
1474 IPOPT_REQ_VID_EN, pval);
1476 len = sprintf(buf, "%s\n", pval);
1478 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1479 OP_STATE(ha->ip_config.ipv4_options,
1480 IPOPT_USE_VID_EN, pval);
1482 len = sprintf(buf, "%s\n", pval);
1484 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1485 pval = (ha->ip_config.ipv4_vid_len) ?
1486 (char *)ha->ip_config.ipv4_vid : "";
1488 len = sprintf(buf, "%s\n", pval);
1490 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1491 OP_STATE(ha->ip_config.ipv4_options,
1492 IPOPT_LEARN_IQN_EN, pval);
1494 len = sprintf(buf, "%s\n", pval);
1496 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1497 OP_STATE(~ha->ip_config.ipv4_options,
1498 IPOPT_FRAGMENTATION_DISABLE, pval);
1500 len = sprintf(buf, "%s\n", pval);
1502 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1503 OP_STATE(ha->ip_config.ipv4_options,
1504 IPOPT_IN_FORWARD_EN, pval);
1506 len = sprintf(buf, "%s\n", pval);
1508 case ISCSI_NET_PARAM_REDIRECT_EN:
1509 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1510 OP_STATE(ha->ip_config.ipv4_options,
1511 IPOPT_ARP_REDIRECT_EN, pval);
1513 OP_STATE(ha->ip_config.ipv6_options,
1514 IPV6_OPT_REDIRECT_EN, pval);
1516 len = sprintf(buf, "%s\n", pval);
1518 case ISCSI_NET_PARAM_IPV4_TTL:
1519 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1521 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1522 OP_STATE(ha->ip_config.ipv6_options,
1523 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1525 len = sprintf(buf, "%s\n", pval);
1527 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1528 OP_STATE(ha->ip_config.ipv6_addl_options,
1529 IPV6_ADDOPT_MLD_EN, pval);
1531 len = sprintf(buf, "%s\n", pval);
1533 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1534 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1536 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1537 len = sprintf(buf, "%d\n",
1538 ha->ip_config.ipv6_traffic_class);
1540 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1541 len = sprintf(buf, "%d\n",
1542 ha->ip_config.ipv6_hop_limit);
1544 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1545 len = sprintf(buf, "%d\n",
1546 ha->ip_config.ipv6_nd_reach_time);
1548 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1549 len = sprintf(buf, "%d\n",
1550 ha->ip_config.ipv6_nd_rexmit_timer);
1552 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1553 len = sprintf(buf, "%d\n",
1554 ha->ip_config.ipv6_nd_stale_timeout);
1556 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1557 len = sprintf(buf, "%d\n",
1558 ha->ip_config.ipv6_dup_addr_detect_count);
1560 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1561 len = sprintf(buf, "%d\n",
1562 ha->ip_config.ipv6_gw_advrt_mtu);
1567 } else if (param_type == ISCSI_IFACE_PARAM) {
1569 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1570 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1572 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1573 OP_STATE(ha->ip_config.iscsi_options,
1574 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1576 len = sprintf(buf, "%s\n", pval);
1578 case ISCSI_IFACE_PARAM_DATADGST_EN:
1579 OP_STATE(ha->ip_config.iscsi_options,
1580 ISCSIOPTS_DATA_DIGEST_EN, pval);
1582 len = sprintf(buf, "%s\n", pval);
1584 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1585 OP_STATE(ha->ip_config.iscsi_options,
1586 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1588 len = sprintf(buf, "%s\n", pval);
1590 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1591 OP_STATE(ha->ip_config.iscsi_options,
1592 ISCSIOPTS_INITIAL_R2T_EN, pval);
1594 len = sprintf(buf, "%s\n", pval);
1596 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1597 OP_STATE(ha->ip_config.iscsi_options,
1598 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1600 len = sprintf(buf, "%s\n", pval);
1602 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1603 OP_STATE(ha->ip_config.iscsi_options,
1604 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1606 len = sprintf(buf, "%s\n", pval);
1608 case ISCSI_IFACE_PARAM_ERL:
1609 len = sprintf(buf, "%d\n",
1610 (ha->ip_config.iscsi_options &
1613 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1614 len = sprintf(buf, "%u\n",
1615 ha->ip_config.iscsi_max_pdu_size *
1618 case ISCSI_IFACE_PARAM_FIRST_BURST:
1619 len = sprintf(buf, "%u\n",
1620 ha->ip_config.iscsi_first_burst_len *
1623 case ISCSI_IFACE_PARAM_MAX_R2T:
1624 len = sprintf(buf, "%d\n",
1625 ha->ip_config.iscsi_max_outstnd_r2t);
1627 case ISCSI_IFACE_PARAM_MAX_BURST:
1628 len = sprintf(buf, "%u\n",
1629 ha->ip_config.iscsi_max_burst_len *
1632 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1633 OP_STATE(ha->ip_config.iscsi_options,
1634 ISCSIOPTS_CHAP_AUTH_EN, pval);
1636 len = sprintf(buf, "%s\n", pval);
1638 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1639 OP_STATE(ha->ip_config.iscsi_options,
1640 ISCSIOPTS_BIDI_CHAP_EN, pval);
1642 len = sprintf(buf, "%s\n", pval);
1644 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1645 OP_STATE(ha->ip_config.iscsi_options,
1646 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1648 len = sprintf(buf, "%s\n", pval);
1650 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1651 OP_STATE(ha->ip_config.iscsi_options,
1652 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1654 len = sprintf(buf, "%s\n", pval);
1656 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1657 OP_STATE(ha->ip_config.iscsi_options,
1658 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1660 len = sprintf(buf, "%s\n", pval);
1662 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1663 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1673 static struct iscsi_endpoint *
1674 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1678 struct iscsi_endpoint *ep;
1679 struct qla_endpoint *qla_ep;
1680 struct scsi_qla_host *ha;
1681 struct sockaddr_in *addr;
1682 struct sockaddr_in6 *addr6;
1686 pr_err("%s: shost is NULL\n", __func__);
1687 return ERR_PTR(ret);
1690 ha = iscsi_host_priv(shost);
1691 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1694 return ERR_PTR(ret);
1697 qla_ep = ep->dd_data;
1698 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1699 if (dst_addr->sa_family == AF_INET) {
1700 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1701 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1702 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1703 (char *)&addr->sin_addr));
1704 } else if (dst_addr->sa_family == AF_INET6) {
1705 memcpy(&qla_ep->dst_addr, dst_addr,
1706 sizeof(struct sockaddr_in6));
1707 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1708 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1709 (char *)&addr6->sin6_addr));
1711 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1715 qla_ep->host = shost;
1720 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1722 struct qla_endpoint *qla_ep;
1723 struct scsi_qla_host *ha;
1726 qla_ep = ep->dd_data;
1727 ha = to_qla_host(qla_ep->host);
1728 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1730 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1736 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1738 struct qla_endpoint *qla_ep;
1739 struct scsi_qla_host *ha;
1741 qla_ep = ep->dd_data;
1742 ha = to_qla_host(qla_ep->host);
1743 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1745 iscsi_destroy_endpoint(ep);
1748 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1749 enum iscsi_param param,
1752 struct qla_endpoint *qla_ep = ep->dd_data;
1753 struct sockaddr *dst_addr;
1754 struct scsi_qla_host *ha;
1759 ha = to_qla_host(qla_ep->host);
1760 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1764 case ISCSI_PARAM_CONN_PORT:
1765 case ISCSI_PARAM_CONN_ADDRESS:
1766 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1770 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1771 &qla_ep->dst_addr, param, buf);
1777 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1778 struct iscsi_stats *stats)
1780 struct iscsi_session *sess;
1781 struct iscsi_cls_session *cls_sess;
1782 struct ddb_entry *ddb_entry;
1783 struct scsi_qla_host *ha;
1784 struct ql_iscsi_stats *ql_iscsi_stats;
1787 dma_addr_t iscsi_stats_dma;
1789 cls_sess = iscsi_conn_to_session(cls_conn);
1790 sess = cls_sess->dd_data;
1791 ddb_entry = sess->dd_data;
1794 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1796 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1797 /* Allocate memory */
1798 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1799 &iscsi_stats_dma, GFP_KERNEL);
1800 if (!ql_iscsi_stats) {
1801 ql4_printk(KERN_ERR, ha,
1802 "Unable to allocate memory for iscsi stats\n");
1803 goto exit_get_stats;
1806 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1808 if (ret != QLA_SUCCESS) {
1809 ql4_printk(KERN_ERR, ha,
1810 "Unable to retrieve iscsi stats\n");
1815 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1816 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1818 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1819 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1820 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1821 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1822 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1823 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1824 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1825 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1827 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1828 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1829 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1830 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1831 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1832 stats->logoutrsp_pdus =
1833 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1834 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1835 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1836 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1839 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1845 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1847 struct iscsi_cls_session *session;
1848 struct iscsi_session *sess;
1849 unsigned long flags;
1850 enum blk_eh_timer_return ret = BLK_EH_DONE;
1852 session = starget_to_session(scsi_target(sc->device));
1853 sess = session->dd_data;
1855 spin_lock_irqsave(&session->lock, flags);
1856 if (session->state == ISCSI_SESSION_FAILED)
1857 ret = BLK_EH_RESET_TIMER;
1858 spin_unlock_irqrestore(&session->lock, flags);
1863 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1865 struct scsi_qla_host *ha = to_qla_host(shost);
1866 struct iscsi_cls_host *ihost = shost->shost_data;
1867 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1869 qla4xxx_get_firmware_state(ha);
1871 switch (ha->addl_fw_state & 0x0F00) {
1872 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1873 speed = ISCSI_PORT_SPEED_10MBPS;
1875 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1876 speed = ISCSI_PORT_SPEED_100MBPS;
1878 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1879 speed = ISCSI_PORT_SPEED_1GBPS;
1881 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1882 speed = ISCSI_PORT_SPEED_10GBPS;
1885 ihost->port_speed = speed;
1888 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1890 struct scsi_qla_host *ha = to_qla_host(shost);
1891 struct iscsi_cls_host *ihost = shost->shost_data;
1892 uint32_t state = ISCSI_PORT_STATE_DOWN;
1894 if (test_bit(AF_LINK_UP, &ha->flags))
1895 state = ISCSI_PORT_STATE_UP;
1897 ihost->port_state = state;
1900 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1901 enum iscsi_host_param param, char *buf)
1903 struct scsi_qla_host *ha = to_qla_host(shost);
1907 case ISCSI_HOST_PARAM_HWADDRESS:
1908 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1910 case ISCSI_HOST_PARAM_IPADDRESS:
1911 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1913 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1914 len = sprintf(buf, "%s\n", ha->name_string);
1916 case ISCSI_HOST_PARAM_PORT_STATE:
1917 qla4xxx_set_port_state(shost);
1918 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1920 case ISCSI_HOST_PARAM_PORT_SPEED:
1921 qla4xxx_set_port_speed(shost);
1922 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1931 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1937 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1938 &qla4xxx_iscsi_transport,
1939 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1940 if (!ha->iface_ipv4)
1941 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1945 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1947 if (!ha->iface_ipv6_0)
1949 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1950 &qla4xxx_iscsi_transport,
1951 ISCSI_IFACE_TYPE_IPV6, 0,
1953 if (!ha->iface_ipv6_0)
1954 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1957 if (!ha->iface_ipv6_1)
1959 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1960 &qla4xxx_iscsi_transport,
1961 ISCSI_IFACE_TYPE_IPV6, 1,
1963 if (!ha->iface_ipv6_1)
1964 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1968 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1970 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1971 qla4xxx_create_ipv4_iface(ha);
1973 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1974 qla4xxx_create_ipv6_iface(ha);
1977 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1979 if (ha->iface_ipv4) {
1980 iscsi_destroy_iface(ha->iface_ipv4);
1981 ha->iface_ipv4 = NULL;
1985 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1987 if (ha->iface_ipv6_0) {
1988 iscsi_destroy_iface(ha->iface_ipv6_0);
1989 ha->iface_ipv6_0 = NULL;
1991 if (ha->iface_ipv6_1) {
1992 iscsi_destroy_iface(ha->iface_ipv6_1);
1993 ha->iface_ipv6_1 = NULL;
1997 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1999 qla4xxx_destroy_ipv4_iface(ha);
2000 qla4xxx_destroy_ipv6_iface(ha);
2003 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2004 struct iscsi_iface_param_info *iface_param,
2005 struct addr_ctrl_blk *init_fw_cb)
2008 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2009 * iface_num 1 is valid only for IPv6 Addr.
2011 switch (iface_param->param) {
2012 case ISCSI_NET_PARAM_IPV6_ADDR:
2013 if (iface_param->iface_num & 0x1)
2015 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2016 sizeof(init_fw_cb->ipv6_addr1));
2019 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2020 sizeof(init_fw_cb->ipv6_addr0));
2022 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2023 if (iface_param->iface_num & 0x1)
2025 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2026 sizeof(init_fw_cb->ipv6_if_id));
2028 case ISCSI_NET_PARAM_IPV6_ROUTER:
2029 if (iface_param->iface_num & 0x1)
2031 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2032 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2034 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2035 /* Autocfg applies to even interface */
2036 if (iface_param->iface_num & 0x1)
2039 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2040 init_fw_cb->ipv6_addtl_opts &=
2042 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2043 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2044 init_fw_cb->ipv6_addtl_opts |=
2046 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2048 ql4_printk(KERN_ERR, ha,
2049 "Invalid autocfg setting for IPv6 addr\n");
2051 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2052 /* Autocfg applies to even interface */
2053 if (iface_param->iface_num & 0x1)
2056 if (iface_param->value[0] ==
2057 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2058 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2059 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2060 else if (iface_param->value[0] ==
2061 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2062 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2063 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2065 ql4_printk(KERN_ERR, ha,
2066 "Invalid autocfg setting for IPv6 linklocal addr\n");
2068 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2069 /* Autocfg applies to even interface */
2070 if (iface_param->iface_num & 0x1)
2073 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2074 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2075 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2077 case ISCSI_NET_PARAM_IFACE_ENABLE:
2078 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2079 init_fw_cb->ipv6_opts |=
2080 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2081 qla4xxx_create_ipv6_iface(ha);
2083 init_fw_cb->ipv6_opts &=
2084 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2086 qla4xxx_destroy_ipv6_iface(ha);
2089 case ISCSI_NET_PARAM_VLAN_TAG:
2090 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2092 init_fw_cb->ipv6_vlan_tag =
2093 cpu_to_be16(*(uint16_t *)iface_param->value);
2095 case ISCSI_NET_PARAM_VLAN_ENABLED:
2096 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2097 init_fw_cb->ipv6_opts |=
2098 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2100 init_fw_cb->ipv6_opts &=
2101 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2103 case ISCSI_NET_PARAM_MTU:
2104 init_fw_cb->eth_mtu_size =
2105 cpu_to_le16(*(uint16_t *)iface_param->value);
2107 case ISCSI_NET_PARAM_PORT:
2108 /* Autocfg applies to even interface */
2109 if (iface_param->iface_num & 0x1)
2112 init_fw_cb->ipv6_port =
2113 cpu_to_le16(*(uint16_t *)iface_param->value);
2115 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2116 if (iface_param->iface_num & 0x1)
2118 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2119 init_fw_cb->ipv6_tcp_opts |=
2120 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2122 init_fw_cb->ipv6_tcp_opts &=
2123 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2126 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2127 if (iface_param->iface_num & 0x1)
2129 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2130 init_fw_cb->ipv6_tcp_opts |=
2131 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2133 init_fw_cb->ipv6_tcp_opts &=
2134 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2136 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2137 if (iface_param->iface_num & 0x1)
2139 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2140 init_fw_cb->ipv6_tcp_opts |=
2141 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2143 init_fw_cb->ipv6_tcp_opts &=
2144 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2146 case ISCSI_NET_PARAM_TCP_WSF:
2147 if (iface_param->iface_num & 0x1)
2149 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2151 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2152 if (iface_param->iface_num & 0x1)
2154 init_fw_cb->ipv6_tcp_opts &=
2155 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2156 init_fw_cb->ipv6_tcp_opts |=
2157 cpu_to_le16((iface_param->value[0] << 1) &
2158 IPV6_TCPOPT_TIMER_SCALE);
2160 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2161 if (iface_param->iface_num & 0x1)
2163 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2164 init_fw_cb->ipv6_tcp_opts |=
2165 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2167 init_fw_cb->ipv6_tcp_opts &=
2168 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2170 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2171 if (iface_param->iface_num & 0x1)
2173 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2174 init_fw_cb->ipv6_opts |=
2175 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2177 init_fw_cb->ipv6_opts &=
2178 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2180 case ISCSI_NET_PARAM_REDIRECT_EN:
2181 if (iface_param->iface_num & 0x1)
2183 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2184 init_fw_cb->ipv6_opts |=
2185 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2187 init_fw_cb->ipv6_opts &=
2188 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2190 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2191 if (iface_param->iface_num & 0x1)
2193 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2194 init_fw_cb->ipv6_addtl_opts |=
2195 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2197 init_fw_cb->ipv6_addtl_opts &=
2198 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2200 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2201 if (iface_param->iface_num & 0x1)
2203 init_fw_cb->ipv6_flow_lbl =
2204 cpu_to_le16(*(uint16_t *)iface_param->value);
2206 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2207 if (iface_param->iface_num & 0x1)
2209 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2211 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2212 if (iface_param->iface_num & 0x1)
2214 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2216 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2217 if (iface_param->iface_num & 0x1)
2219 init_fw_cb->ipv6_nd_reach_time =
2220 cpu_to_le32(*(uint32_t *)iface_param->value);
2222 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2223 if (iface_param->iface_num & 0x1)
2225 init_fw_cb->ipv6_nd_rexmit_timer =
2226 cpu_to_le32(*(uint32_t *)iface_param->value);
2228 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2229 if (iface_param->iface_num & 0x1)
2231 init_fw_cb->ipv6_nd_stale_timeout =
2232 cpu_to_le32(*(uint32_t *)iface_param->value);
2234 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2235 if (iface_param->iface_num & 0x1)
2237 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2239 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2240 if (iface_param->iface_num & 0x1)
2242 init_fw_cb->ipv6_gw_advrt_mtu =
2243 cpu_to_le32(*(uint32_t *)iface_param->value);
2246 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2247 iface_param->param);
2252 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2253 struct iscsi_iface_param_info *iface_param,
2254 struct addr_ctrl_blk *init_fw_cb)
2256 switch (iface_param->param) {
2257 case ISCSI_NET_PARAM_IPV4_ADDR:
2258 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2259 sizeof(init_fw_cb->ipv4_addr));
2261 case ISCSI_NET_PARAM_IPV4_SUBNET:
2262 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2263 sizeof(init_fw_cb->ipv4_subnet));
2265 case ISCSI_NET_PARAM_IPV4_GW:
2266 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2267 sizeof(init_fw_cb->ipv4_gw_addr));
2269 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2270 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2271 init_fw_cb->ipv4_tcp_opts |=
2272 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2273 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2274 init_fw_cb->ipv4_tcp_opts &=
2275 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2277 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2279 case ISCSI_NET_PARAM_IFACE_ENABLE:
2280 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2281 init_fw_cb->ipv4_ip_opts |=
2282 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2283 qla4xxx_create_ipv4_iface(ha);
2285 init_fw_cb->ipv4_ip_opts &=
2286 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2288 qla4xxx_destroy_ipv4_iface(ha);
2291 case ISCSI_NET_PARAM_VLAN_TAG:
2292 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2294 init_fw_cb->ipv4_vlan_tag =
2295 cpu_to_be16(*(uint16_t *)iface_param->value);
2297 case ISCSI_NET_PARAM_VLAN_ENABLED:
2298 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2299 init_fw_cb->ipv4_ip_opts |=
2300 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2302 init_fw_cb->ipv4_ip_opts &=
2303 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2305 case ISCSI_NET_PARAM_MTU:
2306 init_fw_cb->eth_mtu_size =
2307 cpu_to_le16(*(uint16_t *)iface_param->value);
2309 case ISCSI_NET_PARAM_PORT:
2310 init_fw_cb->ipv4_port =
2311 cpu_to_le16(*(uint16_t *)iface_param->value);
2313 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2314 if (iface_param->iface_num & 0x1)
2316 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2317 init_fw_cb->ipv4_tcp_opts |=
2318 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2320 init_fw_cb->ipv4_tcp_opts &=
2321 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2324 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2325 if (iface_param->iface_num & 0x1)
2327 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2328 init_fw_cb->ipv4_tcp_opts |=
2329 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2331 init_fw_cb->ipv4_tcp_opts &=
2332 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2334 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2335 if (iface_param->iface_num & 0x1)
2337 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2338 init_fw_cb->ipv4_tcp_opts |=
2339 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2341 init_fw_cb->ipv4_tcp_opts &=
2342 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2344 case ISCSI_NET_PARAM_TCP_WSF:
2345 if (iface_param->iface_num & 0x1)
2347 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2349 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2350 if (iface_param->iface_num & 0x1)
2352 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2353 init_fw_cb->ipv4_tcp_opts |=
2354 cpu_to_le16((iface_param->value[0] << 1) &
2355 TCPOPT_TIMER_SCALE);
2357 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2358 if (iface_param->iface_num & 0x1)
2360 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2361 init_fw_cb->ipv4_tcp_opts |=
2362 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2364 init_fw_cb->ipv4_tcp_opts &=
2365 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2367 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2368 if (iface_param->iface_num & 0x1)
2370 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2371 init_fw_cb->ipv4_tcp_opts |=
2372 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2374 init_fw_cb->ipv4_tcp_opts &=
2375 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2377 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2378 if (iface_param->iface_num & 0x1)
2380 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2381 init_fw_cb->ipv4_tcp_opts |=
2382 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2384 init_fw_cb->ipv4_tcp_opts &=
2385 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2387 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2388 if (iface_param->iface_num & 0x1)
2390 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2391 init_fw_cb->ipv4_ip_opts |=
2392 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2394 init_fw_cb->ipv4_ip_opts &=
2395 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2397 case ISCSI_NET_PARAM_IPV4_TOS:
2398 if (iface_param->iface_num & 0x1)
2400 init_fw_cb->ipv4_tos = iface_param->value[0];
2402 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2403 if (iface_param->iface_num & 0x1)
2405 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2406 init_fw_cb->ipv4_ip_opts |=
2407 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2409 init_fw_cb->ipv4_ip_opts &=
2410 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2412 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2413 if (iface_param->iface_num & 0x1)
2415 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2416 init_fw_cb->ipv4_ip_opts |=
2417 cpu_to_le16(IPOPT_ALT_CID_EN);
2419 init_fw_cb->ipv4_ip_opts &=
2420 cpu_to_le16(~IPOPT_ALT_CID_EN);
2422 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2423 if (iface_param->iface_num & 0x1)
2425 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2426 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2427 init_fw_cb->ipv4_dhcp_alt_cid_len =
2428 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2430 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2431 if (iface_param->iface_num & 0x1)
2433 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2434 init_fw_cb->ipv4_ip_opts |=
2435 cpu_to_le16(IPOPT_REQ_VID_EN);
2437 init_fw_cb->ipv4_ip_opts &=
2438 cpu_to_le16(~IPOPT_REQ_VID_EN);
2440 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2441 if (iface_param->iface_num & 0x1)
2443 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2444 init_fw_cb->ipv4_ip_opts |=
2445 cpu_to_le16(IPOPT_USE_VID_EN);
2447 init_fw_cb->ipv4_ip_opts &=
2448 cpu_to_le16(~IPOPT_USE_VID_EN);
2450 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2451 if (iface_param->iface_num & 0x1)
2453 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2454 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2455 init_fw_cb->ipv4_dhcp_vid_len =
2456 strlen(init_fw_cb->ipv4_dhcp_vid);
2458 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2459 if (iface_param->iface_num & 0x1)
2461 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2462 init_fw_cb->ipv4_ip_opts |=
2463 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2465 init_fw_cb->ipv4_ip_opts &=
2466 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2468 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2469 if (iface_param->iface_num & 0x1)
2471 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2472 init_fw_cb->ipv4_ip_opts |=
2473 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2475 init_fw_cb->ipv4_ip_opts &=
2476 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2478 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2479 if (iface_param->iface_num & 0x1)
2481 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2482 init_fw_cb->ipv4_ip_opts |=
2483 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2485 init_fw_cb->ipv4_ip_opts &=
2486 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2488 case ISCSI_NET_PARAM_REDIRECT_EN:
2489 if (iface_param->iface_num & 0x1)
2491 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2492 init_fw_cb->ipv4_ip_opts |=
2493 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2495 init_fw_cb->ipv4_ip_opts &=
2496 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2498 case ISCSI_NET_PARAM_IPV4_TTL:
2499 if (iface_param->iface_num & 0x1)
2501 init_fw_cb->ipv4_ttl = iface_param->value[0];
2504 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2505 iface_param->param);
2510 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2511 struct iscsi_iface_param_info *iface_param,
2512 struct addr_ctrl_blk *init_fw_cb)
2514 switch (iface_param->param) {
2515 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2516 if (iface_param->iface_num & 0x1)
2518 init_fw_cb->def_timeout =
2519 cpu_to_le16(*(uint16_t *)iface_param->value);
2521 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2522 if (iface_param->iface_num & 0x1)
2524 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2525 init_fw_cb->iscsi_opts |=
2526 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2528 init_fw_cb->iscsi_opts &=
2529 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2531 case ISCSI_IFACE_PARAM_DATADGST_EN:
2532 if (iface_param->iface_num & 0x1)
2534 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2535 init_fw_cb->iscsi_opts |=
2536 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2538 init_fw_cb->iscsi_opts &=
2539 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2541 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2542 if (iface_param->iface_num & 0x1)
2544 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2545 init_fw_cb->iscsi_opts |=
2546 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2548 init_fw_cb->iscsi_opts &=
2549 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2551 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2552 if (iface_param->iface_num & 0x1)
2554 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2555 init_fw_cb->iscsi_opts |=
2556 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2558 init_fw_cb->iscsi_opts &=
2559 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2561 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2562 if (iface_param->iface_num & 0x1)
2564 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2565 init_fw_cb->iscsi_opts |=
2566 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2568 init_fw_cb->iscsi_opts &=
2569 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2571 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2572 if (iface_param->iface_num & 0x1)
2574 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2575 init_fw_cb->iscsi_opts |=
2576 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2578 init_fw_cb->iscsi_opts &=
2579 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2581 case ISCSI_IFACE_PARAM_ERL:
2582 if (iface_param->iface_num & 0x1)
2584 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2585 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2588 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2589 if (iface_param->iface_num & 0x1)
2591 init_fw_cb->iscsi_max_pdu_size =
2592 cpu_to_le32(*(uint32_t *)iface_param->value) /
2595 case ISCSI_IFACE_PARAM_FIRST_BURST:
2596 if (iface_param->iface_num & 0x1)
2598 init_fw_cb->iscsi_fburst_len =
2599 cpu_to_le32(*(uint32_t *)iface_param->value) /
2602 case ISCSI_IFACE_PARAM_MAX_R2T:
2603 if (iface_param->iface_num & 0x1)
2605 init_fw_cb->iscsi_max_outstnd_r2t =
2606 cpu_to_le16(*(uint16_t *)iface_param->value);
2608 case ISCSI_IFACE_PARAM_MAX_BURST:
2609 if (iface_param->iface_num & 0x1)
2611 init_fw_cb->iscsi_max_burst_len =
2612 cpu_to_le32(*(uint32_t *)iface_param->value) /
2615 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2616 if (iface_param->iface_num & 0x1)
2618 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2619 init_fw_cb->iscsi_opts |=
2620 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2622 init_fw_cb->iscsi_opts &=
2623 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2625 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2626 if (iface_param->iface_num & 0x1)
2628 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2629 init_fw_cb->iscsi_opts |=
2630 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2632 init_fw_cb->iscsi_opts &=
2633 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2635 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2636 if (iface_param->iface_num & 0x1)
2638 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2639 init_fw_cb->iscsi_opts |=
2640 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2642 init_fw_cb->iscsi_opts &=
2643 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2645 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2646 if (iface_param->iface_num & 0x1)
2648 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2649 init_fw_cb->iscsi_opts |=
2650 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2652 init_fw_cb->iscsi_opts &=
2653 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2655 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2656 if (iface_param->iface_num & 0x1)
2658 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2659 init_fw_cb->iscsi_opts |=
2660 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2662 init_fw_cb->iscsi_opts &=
2663 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2666 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2667 iface_param->param);
2673 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2675 struct addr_ctrl_blk_def *acb;
2676 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2677 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2678 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2679 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2680 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2681 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2682 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2683 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2684 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2685 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2686 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2687 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2688 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2689 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2690 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2691 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2695 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2697 struct scsi_qla_host *ha = to_qla_host(shost);
2699 struct iscsi_iface_param_info *iface_param = NULL;
2700 struct addr_ctrl_blk *init_fw_cb = NULL;
2701 dma_addr_t init_fw_cb_dma;
2702 uint32_t mbox_cmd[MBOX_REG_COUNT];
2703 uint32_t mbox_sts[MBOX_REG_COUNT];
2705 struct nlattr *attr;
2707 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2708 sizeof(struct addr_ctrl_blk),
2709 &init_fw_cb_dma, GFP_KERNEL);
2711 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2716 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2717 memset(&mbox_sts, 0, sizeof(mbox_sts));
2719 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2720 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2722 goto exit_init_fw_cb;
2725 nla_for_each_attr(attr, data, len, rem) {
2726 iface_param = nla_data(attr);
2728 if (iface_param->param_type == ISCSI_NET_PARAM) {
2729 switch (iface_param->iface_type) {
2730 case ISCSI_IFACE_TYPE_IPV4:
2731 switch (iface_param->iface_num) {
2733 qla4xxx_set_ipv4(ha, iface_param,
2737 /* Cannot have more than one IPv4 interface */
2738 ql4_printk(KERN_ERR, ha,
2739 "Invalid IPv4 iface number = %d\n",
2740 iface_param->iface_num);
2744 case ISCSI_IFACE_TYPE_IPV6:
2745 switch (iface_param->iface_num) {
2748 qla4xxx_set_ipv6(ha, iface_param,
2752 /* Cannot have more than two IPv6 interface */
2753 ql4_printk(KERN_ERR, ha,
2754 "Invalid IPv6 iface number = %d\n",
2755 iface_param->iface_num);
2760 ql4_printk(KERN_ERR, ha,
2761 "Invalid iface type\n");
2764 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2765 qla4xxx_set_iscsi_param(ha, iface_param,
2772 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2774 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2775 sizeof(struct addr_ctrl_blk),
2776 FLASH_OPT_RMW_COMMIT);
2777 if (rval != QLA_SUCCESS) {
2778 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2781 goto exit_init_fw_cb;
2784 rval = qla4xxx_disable_acb(ha);
2785 if (rval != QLA_SUCCESS) {
2786 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2789 goto exit_init_fw_cb;
2792 wait_for_completion_timeout(&ha->disable_acb_comp,
2793 DISABLE_ACB_TOV * HZ);
2795 qla4xxx_initcb_to_acb(init_fw_cb);
2797 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2798 if (rval != QLA_SUCCESS) {
2799 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2802 goto exit_init_fw_cb;
2805 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2806 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2810 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2811 init_fw_cb, init_fw_cb_dma);
2816 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2817 enum iscsi_param param, char *buf)
2819 struct iscsi_session *sess = cls_sess->dd_data;
2820 struct ddb_entry *ddb_entry = sess->dd_data;
2821 struct scsi_qla_host *ha = ddb_entry->ha;
2822 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2823 struct ql4_chap_table chap_tbl;
2827 memset(&chap_tbl, 0, sizeof(chap_tbl));
2829 case ISCSI_PARAM_CHAP_IN_IDX:
2830 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2831 sess->password_in, BIDI_CHAP,
2834 len = sprintf(buf, "\n");
2836 len = sprintf(buf, "%hu\n", idx);
2838 case ISCSI_PARAM_CHAP_OUT_IDX:
2839 if (ddb_entry->ddb_type == FLASH_DDB) {
2840 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2841 idx = ddb_entry->chap_tbl_idx;
2847 rval = qla4xxx_get_chap_index(ha, sess->username,
2852 len = sprintf(buf, "\n");
2854 len = sprintf(buf, "%hu\n", idx);
2856 case ISCSI_PARAM_USERNAME:
2857 case ISCSI_PARAM_PASSWORD:
2858 /* First, populate session username and password for FLASH DDB,
2859 * if not already done. This happens when session login fails
2862 if (ddb_entry->ddb_type == FLASH_DDB &&
2863 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2864 !sess->username && !sess->password) {
2865 idx = ddb_entry->chap_tbl_idx;
2866 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2870 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2871 (char *)chap_tbl.name,
2872 strlen((char *)chap_tbl.name));
2873 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2874 (char *)chap_tbl.secret,
2875 chap_tbl.secret_len);
2880 return iscsi_session_get_param(cls_sess, param, buf);
2886 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2887 enum iscsi_param param, char *buf)
2889 struct iscsi_conn *conn;
2890 struct qla_conn *qla_conn;
2891 struct sockaddr *dst_addr;
2893 conn = cls_conn->dd_data;
2894 qla_conn = conn->dd_data;
2895 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2898 case ISCSI_PARAM_CONN_PORT:
2899 case ISCSI_PARAM_CONN_ADDRESS:
2900 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2901 dst_addr, param, buf);
2903 return iscsi_conn_get_param(cls_conn, param, buf);
2907 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2909 uint32_t mbx_sts = 0;
2910 uint16_t tmp_ddb_index;
2914 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2916 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2917 DEBUG2(ql4_printk(KERN_INFO, ha,
2918 "Free DDB index not available\n"));
2920 goto exit_get_ddb_index;
2923 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2926 DEBUG2(ql4_printk(KERN_INFO, ha,
2927 "Found a free DDB index at %d\n", tmp_ddb_index));
2928 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2929 if (ret == QLA_ERROR) {
2930 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2931 ql4_printk(KERN_INFO, ha,
2932 "DDB index = %d not available trying next\n",
2936 DEBUG2(ql4_printk(KERN_INFO, ha,
2937 "Free FW DDB not available\n"));
2940 *ddb_index = tmp_ddb_index;
2946 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2947 struct ddb_entry *ddb_entry,
2948 char *existing_ipaddr,
2951 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2952 char formatted_ipaddr[DDB_IPADDR_LEN];
2953 int status = QLA_SUCCESS, ret = 0;
2955 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2956 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2962 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2964 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2970 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2973 if (strcmp(existing_ipaddr, formatted_ipaddr))
2980 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2981 struct iscsi_cls_conn *cls_conn)
2983 int idx = 0, max_ddbs, rval;
2984 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2985 struct iscsi_session *sess, *existing_sess;
2986 struct iscsi_conn *conn, *existing_conn;
2987 struct ddb_entry *ddb_entry;
2989 sess = cls_sess->dd_data;
2990 conn = cls_conn->dd_data;
2992 if (sess->targetname == NULL ||
2993 conn->persistent_address == NULL ||
2994 conn->persistent_port == 0)
2997 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3000 for (idx = 0; idx < max_ddbs; idx++) {
3001 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3002 if (ddb_entry == NULL)
3005 if (ddb_entry->ddb_type != FLASH_DDB)
3008 existing_sess = ddb_entry->sess->dd_data;
3009 existing_conn = ddb_entry->conn->dd_data;
3011 if (existing_sess->targetname == NULL ||
3012 existing_conn->persistent_address == NULL ||
3013 existing_conn->persistent_port == 0)
3016 DEBUG2(ql4_printk(KERN_INFO, ha,
3017 "IQN = %s User IQN = %s\n",
3018 existing_sess->targetname,
3021 DEBUG2(ql4_printk(KERN_INFO, ha,
3022 "IP = %s User IP = %s\n",
3023 existing_conn->persistent_address,
3024 conn->persistent_address));
3026 DEBUG2(ql4_printk(KERN_INFO, ha,
3027 "Port = %d User Port = %d\n",
3028 existing_conn->persistent_port,
3029 conn->persistent_port));
3031 if (strcmp(existing_sess->targetname, sess->targetname))
3033 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3034 existing_conn->persistent_address,
3035 conn->persistent_address);
3036 if (rval == QLA_ERROR)
3038 if (existing_conn->persistent_port != conn->persistent_port)
3043 if (idx == max_ddbs)
3046 DEBUG2(ql4_printk(KERN_INFO, ha,
3047 "Match found in fwdb sessions\n"));
3051 static struct iscsi_cls_session *
3052 qla4xxx_session_create(struct iscsi_endpoint *ep,
3053 uint16_t cmds_max, uint16_t qdepth,
3054 uint32_t initial_cmdsn)
3056 struct iscsi_cls_session *cls_sess;
3057 struct scsi_qla_host *ha;
3058 struct qla_endpoint *qla_ep;
3059 struct ddb_entry *ddb_entry;
3061 struct iscsi_session *sess;
3062 struct sockaddr *dst_addr;
3066 printk(KERN_ERR "qla4xxx: missing ep.\n");
3070 qla_ep = ep->dd_data;
3071 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3072 ha = to_qla_host(qla_ep->host);
3073 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3076 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3077 if (ret == QLA_ERROR)
3080 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3081 cmds_max, sizeof(struct ddb_entry),
3082 sizeof(struct ql4_task_data),
3083 initial_cmdsn, ddb_index);
3087 sess = cls_sess->dd_data;
3088 ddb_entry = sess->dd_data;
3089 ddb_entry->fw_ddb_index = ddb_index;
3090 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3092 ddb_entry->sess = cls_sess;
3093 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3094 ddb_entry->ddb_change = qla4xxx_ddb_change;
3095 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3096 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3097 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3103 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3105 struct iscsi_session *sess;
3106 struct ddb_entry *ddb_entry;
3107 struct scsi_qla_host *ha;
3108 unsigned long flags, wtime;
3109 struct dev_db_entry *fw_ddb_entry = NULL;
3110 dma_addr_t fw_ddb_entry_dma;
3114 sess = cls_sess->dd_data;
3115 ddb_entry = sess->dd_data;
3117 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3120 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3121 &fw_ddb_entry_dma, GFP_KERNEL);
3122 if (!fw_ddb_entry) {
3123 ql4_printk(KERN_ERR, ha,
3124 "%s: Unable to allocate dma buffer\n", __func__);
3125 goto destroy_session;
3128 wtime = jiffies + (HZ * LOGOUT_TOV);
3130 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3131 fw_ddb_entry, fw_ddb_entry_dma,
3132 NULL, NULL, &ddb_state, NULL,
3134 if (ret == QLA_ERROR)
3135 goto destroy_session;
3137 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3138 (ddb_state == DDB_DS_SESSION_FAILED))
3139 goto destroy_session;
3141 schedule_timeout_uninterruptible(HZ);
3142 } while ((time_after(wtime, jiffies)));
3145 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3146 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3147 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3148 spin_lock_irqsave(&ha->hardware_lock, flags);
3149 qla4xxx_free_ddb(ha, ddb_entry);
3150 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3152 iscsi_session_teardown(cls_sess);
3155 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3156 fw_ddb_entry, fw_ddb_entry_dma);
3159 static struct iscsi_cls_conn *
3160 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3162 struct iscsi_cls_conn *cls_conn;
3163 struct iscsi_session *sess;
3164 struct ddb_entry *ddb_entry;
3165 struct scsi_qla_host *ha;
3167 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3170 pr_info("%s: Can not create connection for conn_idx = %u\n",
3171 __func__, conn_idx);
3175 sess = cls_sess->dd_data;
3176 ddb_entry = sess->dd_data;
3177 ddb_entry->conn = cls_conn;
3180 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3185 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3186 struct iscsi_cls_conn *cls_conn,
3187 uint64_t transport_fd, int is_leading)
3189 struct iscsi_conn *conn;
3190 struct qla_conn *qla_conn;
3191 struct iscsi_endpoint *ep;
3192 struct ddb_entry *ddb_entry;
3193 struct scsi_qla_host *ha;
3194 struct iscsi_session *sess;
3196 sess = cls_session->dd_data;
3197 ddb_entry = sess->dd_data;
3200 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3201 cls_session->sid, cls_conn->cid));
3203 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3205 ep = iscsi_lookup_endpoint(transport_fd);
3208 conn = cls_conn->dd_data;
3209 qla_conn = conn->dd_data;
3210 qla_conn->qla_ep = ep->dd_data;
3214 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3216 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3217 struct iscsi_session *sess;
3218 struct ddb_entry *ddb_entry;
3219 struct scsi_qla_host *ha;
3220 struct dev_db_entry *fw_ddb_entry = NULL;
3221 dma_addr_t fw_ddb_entry_dma;
3222 uint32_t mbx_sts = 0;
3224 int status = QLA_SUCCESS;
3226 sess = cls_sess->dd_data;
3227 ddb_entry = sess->dd_data;
3229 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3230 cls_sess->sid, cls_conn->cid));
3232 /* Check if we have matching FW DDB, if yes then do not
3233 * login to this target. This could cause target to logout previous
3236 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3237 if (ret == QLA_SUCCESS) {
3238 ql4_printk(KERN_INFO, ha,
3239 "Session already exist in FW.\n");
3241 goto exit_conn_start;
3244 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3245 &fw_ddb_entry_dma, GFP_KERNEL);
3246 if (!fw_ddb_entry) {
3247 ql4_printk(KERN_ERR, ha,
3248 "%s: Unable to allocate dma buffer\n", __func__);
3250 goto exit_conn_start;
3253 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3255 /* If iscsid is stopped and started then no need to do
3256 * set param again since ddb state will be already
3257 * active and FW does not allow set ddb to an
3261 if (ddb_entry->fw_ddb_device_state ==
3262 DDB_DS_SESSION_ACTIVE) {
3263 ddb_entry->unblock_sess(ddb_entry->sess);
3264 goto exit_set_param;
3267 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3268 __func__, ddb_entry->fw_ddb_index);
3269 goto exit_conn_start;
3272 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3273 if (status == QLA_ERROR) {
3274 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3277 goto exit_conn_start;
3280 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3281 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3283 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3284 ddb_entry->fw_ddb_device_state));
3291 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3292 fw_ddb_entry, fw_ddb_entry_dma);
3296 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3298 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3299 struct iscsi_session *sess;
3300 struct scsi_qla_host *ha;
3301 struct ddb_entry *ddb_entry;
3304 sess = cls_sess->dd_data;
3305 ddb_entry = sess->dd_data;
3307 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3310 options = LOGOUT_OPTION_CLOSE_SESSION;
3311 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3312 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3315 static void qla4xxx_task_work(struct work_struct *wdata)
3317 struct ql4_task_data *task_data;
3318 struct scsi_qla_host *ha;
3319 struct passthru_status *sts;
3320 struct iscsi_task *task;
3321 struct iscsi_hdr *hdr;
3324 struct iscsi_conn *conn;
3328 task_data = container_of(wdata, struct ql4_task_data, task_work);
3330 task = task_data->task;
3331 sts = &task_data->sts;
3332 hdr_len = sizeof(struct iscsi_hdr);
3334 DEBUG3(printk(KERN_INFO "Status returned\n"));
3335 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3336 DEBUG3(printk(KERN_INFO "Response buffer"));
3337 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3341 switch (sts->completionStatus) {
3342 case PASSTHRU_STATUS_COMPLETE:
3343 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3344 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3347 data = task_data->resp_buffer + hdr_len;
3348 data_len = task_data->resp_len - hdr_len;
3349 iscsi_complete_pdu(conn, hdr, data, data_len);
3352 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3353 sts->completionStatus);
3359 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3361 struct ql4_task_data *task_data;
3362 struct iscsi_session *sess;
3363 struct ddb_entry *ddb_entry;
3364 struct scsi_qla_host *ha;
3367 sess = task->conn->session;
3368 ddb_entry = sess->dd_data;
3370 task_data = task->dd_data;
3371 memset(task_data, 0, sizeof(struct ql4_task_data));
3374 ql4_printk(KERN_INFO, ha,
3375 "%s: SCSI Commands not implemented\n", __func__);
3379 hdr_len = sizeof(struct iscsi_hdr);
3381 task_data->task = task;
3383 if (task->data_count) {
3384 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3389 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3390 __func__, task->conn->max_recv_dlength, hdr_len));
3392 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3393 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3394 task_data->resp_len,
3395 &task_data->resp_dma,
3397 if (!task_data->resp_buffer)
3398 goto exit_alloc_pdu;
3400 task_data->req_len = task->data_count + hdr_len;
3401 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3403 &task_data->req_dma,
3405 if (!task_data->req_buffer)
3406 goto exit_alloc_pdu;
3408 task->hdr = task_data->req_buffer;
3410 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3415 if (task_data->resp_buffer)
3416 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3417 task_data->resp_buffer, task_data->resp_dma);
3419 if (task_data->req_buffer)
3420 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3421 task_data->req_buffer, task_data->req_dma);
3425 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3427 struct ql4_task_data *task_data;
3428 struct iscsi_session *sess;
3429 struct ddb_entry *ddb_entry;
3430 struct scsi_qla_host *ha;
3433 hdr_len = sizeof(struct iscsi_hdr);
3434 sess = task->conn->session;
3435 ddb_entry = sess->dd_data;
3437 task_data = task->dd_data;
3439 if (task->data_count) {
3440 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3441 task->data_count, DMA_TO_DEVICE);
3444 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3445 __func__, task->conn->max_recv_dlength, hdr_len));
3447 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3448 task_data->resp_buffer, task_data->resp_dma);
3449 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3450 task_data->req_buffer, task_data->req_dma);
3454 static int qla4xxx_task_xmit(struct iscsi_task *task)
3456 struct scsi_cmnd *sc = task->sc;
3457 struct iscsi_session *sess = task->conn->session;
3458 struct ddb_entry *ddb_entry = sess->dd_data;
3459 struct scsi_qla_host *ha = ddb_entry->ha;
3462 return qla4xxx_send_passthru0(task);
3464 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3469 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3470 struct iscsi_bus_flash_conn *conn,
3471 struct dev_db_entry *fw_ddb_entry)
3473 unsigned long options = 0;
3476 options = le16_to_cpu(fw_ddb_entry->options);
3477 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3478 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3479 rc = iscsi_switch_str_param(&sess->portal_type,
3484 rc = iscsi_switch_str_param(&sess->portal_type,
3490 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3492 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3493 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3495 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3496 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3497 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3498 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3499 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3500 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3502 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3503 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3504 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3505 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3507 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3508 sess->discovery_auth_optional =
3509 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3510 if (test_bit(ISCSIOPT_ERL1, &options))
3512 if (test_bit(ISCSIOPT_ERL0, &options))
3515 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3516 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3517 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3518 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3519 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3520 conn->tcp_timer_scale |= BIT_3;
3521 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3522 conn->tcp_timer_scale |= BIT_2;
3523 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3524 conn->tcp_timer_scale |= BIT_1;
3526 conn->tcp_timer_scale >>= 1;
3527 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3529 options = le16_to_cpu(fw_ddb_entry->ip_options);
3530 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3532 conn->max_recv_dlength = BYTE_UNITS *
3533 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3534 conn->max_xmit_dlength = BYTE_UNITS *
3535 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3536 sess->first_burst = BYTE_UNITS *
3537 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3538 sess->max_burst = BYTE_UNITS *
3539 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3540 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3541 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3542 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3543 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3544 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3545 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3546 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3547 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3548 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3549 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3550 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3551 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3552 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3553 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3554 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3555 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3557 sess->default_taskmgmt_timeout =
3558 le16_to_cpu(fw_ddb_entry->def_timeout);
3559 conn->port = le16_to_cpu(fw_ddb_entry->port);
3561 options = le16_to_cpu(fw_ddb_entry->options);
3562 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3563 if (!conn->ipaddress) {
3568 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3569 if (!conn->redirect_ipaddr) {
3574 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3575 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3577 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3578 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3580 conn->link_local_ipv6_addr = kmemdup(
3581 fw_ddb_entry->link_local_ipv6_addr,
3582 IPv6_ADDR_LEN, GFP_KERNEL);
3583 if (!conn->link_local_ipv6_addr) {
3588 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3591 if (fw_ddb_entry->iscsi_name[0]) {
3592 rc = iscsi_switch_str_param(&sess->targetname,
3593 (char *)fw_ddb_entry->iscsi_name);
3598 if (fw_ddb_entry->iscsi_alias[0]) {
3599 rc = iscsi_switch_str_param(&sess->targetalias,
3600 (char *)fw_ddb_entry->iscsi_alias);
3605 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3611 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3612 struct iscsi_bus_flash_conn *conn,
3613 struct dev_db_entry *fw_ddb_entry)
3618 options = le16_to_cpu(fw_ddb_entry->options);
3619 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3620 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3625 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3626 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3627 SET_BITVAL(sess->entry_state, options, BIT_3);
3628 fw_ddb_entry->options = cpu_to_le16(options);
3630 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3631 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3632 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3633 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3634 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3635 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3636 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3637 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3638 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3639 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3640 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3641 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3642 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3643 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3644 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3646 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3647 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3648 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3649 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3650 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3651 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3652 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3653 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3654 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3656 options = le16_to_cpu(fw_ddb_entry->ip_options);
3657 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3658 fw_ddb_entry->ip_options = cpu_to_le16(options);
3660 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3661 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3662 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3663 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3664 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3665 fw_ddb_entry->iscsi_first_burst_len =
3666 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3667 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3669 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3670 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3671 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3672 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3673 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3674 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3675 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3676 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3677 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3678 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3679 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3680 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3681 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3682 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3683 fw_ddb_entry->port = cpu_to_le16(conn->port);
3684 fw_ddb_entry->def_timeout =
3685 cpu_to_le16(sess->default_taskmgmt_timeout);
3687 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3688 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3690 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3692 if (conn->ipaddress)
3693 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3694 sizeof(fw_ddb_entry->ip_addr));
3696 if (conn->redirect_ipaddr)
3697 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3698 sizeof(fw_ddb_entry->tgt_addr));
3700 if (conn->link_local_ipv6_addr)
3701 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3702 conn->link_local_ipv6_addr,
3703 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3705 if (sess->targetname)
3706 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3707 sizeof(fw_ddb_entry->iscsi_name));
3709 if (sess->targetalias)
3710 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3711 sizeof(fw_ddb_entry->iscsi_alias));
3713 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3718 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3719 struct iscsi_session *sess,
3720 struct dev_db_entry *fw_ddb_entry)
3722 unsigned long options = 0;
3724 uint16_t disc_parent;
3725 char ip_addr[DDB_IPADDR_LEN];
3727 options = le16_to_cpu(fw_ddb_entry->options);
3728 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3729 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3731 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3733 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3734 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3735 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3736 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3737 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3738 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3740 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3741 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3742 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3744 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3745 sess->discovery_auth_optional =
3746 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3747 if (test_bit(ISCSIOPT_ERL1, &options))
3749 if (test_bit(ISCSIOPT_ERL0, &options))
3752 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3753 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3754 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3755 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3756 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3757 conn->tcp_timer_scale |= BIT_3;
3758 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3759 conn->tcp_timer_scale |= BIT_2;
3760 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3761 conn->tcp_timer_scale |= BIT_1;
3763 conn->tcp_timer_scale >>= 1;
3764 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3766 options = le16_to_cpu(fw_ddb_entry->ip_options);
3767 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3769 conn->max_recv_dlength = BYTE_UNITS *
3770 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3771 conn->max_xmit_dlength = BYTE_UNITS *
3772 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3773 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3774 sess->first_burst = BYTE_UNITS *
3775 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3776 sess->max_burst = BYTE_UNITS *
3777 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3778 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3779 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3780 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3781 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3782 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3783 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3784 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3785 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3786 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3787 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3788 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3789 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3790 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3792 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3793 if (ddb_link == DDB_ISNS)
3794 disc_parent = ISCSI_DISC_PARENT_ISNS;
3795 else if (ddb_link == DDB_NO_LINK)
3796 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3797 else if (ddb_link < MAX_DDB_ENTRIES)
3798 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3800 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3802 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3803 iscsi_get_discovery_parent_name(disc_parent), 0);
3805 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3806 (char *)fw_ddb_entry->iscsi_alias, 0);
3808 options = le16_to_cpu(fw_ddb_entry->options);
3809 if (options & DDB_OPT_IPV6_DEVICE) {
3810 memset(ip_addr, 0, sizeof(ip_addr));
3811 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3812 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3813 (char *)ip_addr, 0);
3817 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3818 struct dev_db_entry *fw_ddb_entry,
3819 struct iscsi_cls_session *cls_sess,
3820 struct iscsi_cls_conn *cls_conn)
3823 struct iscsi_session *sess;
3824 struct ddb_entry *ddb_entry;
3825 struct ql4_chap_table chap_tbl;
3826 struct iscsi_conn *conn;
3827 char ip_addr[DDB_IPADDR_LEN];
3828 uint16_t options = 0;
3830 sess = cls_sess->dd_data;
3831 ddb_entry = sess->dd_data;
3832 conn = cls_conn->dd_data;
3833 memset(&chap_tbl, 0, sizeof(chap_tbl));
3835 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3837 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3839 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3840 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3842 memset(ip_addr, 0, sizeof(ip_addr));
3843 options = le16_to_cpu(fw_ddb_entry->options);
3844 if (options & DDB_OPT_IPV6_DEVICE) {
3845 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3847 memset(ip_addr, 0, sizeof(ip_addr));
3848 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3850 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3851 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3854 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3855 (char *)ip_addr, buflen);
3856 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3857 (char *)fw_ddb_entry->iscsi_name, buflen);
3858 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3859 (char *)ha->name_string, buflen);
3861 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3862 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3864 ddb_entry->chap_tbl_idx)) {
3865 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3866 (char *)chap_tbl.name,
3867 strlen((char *)chap_tbl.name));
3868 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3869 (char *)chap_tbl.secret,
3870 chap_tbl.secret_len);
3875 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3876 struct ddb_entry *ddb_entry)
3878 struct iscsi_cls_session *cls_sess;
3879 struct iscsi_cls_conn *cls_conn;
3881 dma_addr_t fw_ddb_entry_dma;
3882 struct dev_db_entry *fw_ddb_entry;
3884 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3885 &fw_ddb_entry_dma, GFP_KERNEL);
3886 if (!fw_ddb_entry) {
3887 ql4_printk(KERN_ERR, ha,
3888 "%s: Unable to allocate dma buffer\n", __func__);
3889 goto exit_session_conn_fwddb_param;
3892 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3893 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3894 NULL, NULL, NULL) == QLA_ERROR) {
3895 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3896 "get_ddb_entry for fw_ddb_index %d\n",
3897 ha->host_no, __func__,
3898 ddb_entry->fw_ddb_index));
3899 goto exit_session_conn_fwddb_param;
3902 cls_sess = ddb_entry->sess;
3904 cls_conn = ddb_entry->conn;
3907 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3909 exit_session_conn_fwddb_param:
3911 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3912 fw_ddb_entry, fw_ddb_entry_dma);
3915 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3916 struct ddb_entry *ddb_entry)
3918 struct iscsi_cls_session *cls_sess;
3919 struct iscsi_cls_conn *cls_conn;
3920 struct iscsi_session *sess;
3921 struct iscsi_conn *conn;
3923 dma_addr_t fw_ddb_entry_dma;
3924 struct dev_db_entry *fw_ddb_entry;
3926 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3927 &fw_ddb_entry_dma, GFP_KERNEL);
3928 if (!fw_ddb_entry) {
3929 ql4_printk(KERN_ERR, ha,
3930 "%s: Unable to allocate dma buffer\n", __func__);
3931 goto exit_session_conn_param;
3934 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3935 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3936 NULL, NULL, NULL) == QLA_ERROR) {
3937 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3938 "get_ddb_entry for fw_ddb_index %d\n",
3939 ha->host_no, __func__,
3940 ddb_entry->fw_ddb_index));
3941 goto exit_session_conn_param;
3944 cls_sess = ddb_entry->sess;
3945 sess = cls_sess->dd_data;
3947 cls_conn = ddb_entry->conn;
3948 conn = cls_conn->dd_data;
3950 /* Update timers after login */
3951 ddb_entry->default_relogin_timeout =
3952 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3953 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3954 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3955 ddb_entry->default_time2wait =
3956 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3959 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3960 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3962 memcpy(sess->initiatorname, ha->name_string,
3963 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3965 exit_session_conn_param:
3967 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3968 fw_ddb_entry, fw_ddb_entry_dma);
3974 static void qla4xxx_timer(struct timer_list *t);
3976 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
3977 unsigned long interval)
3979 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3980 __func__, ha->host->host_no));
3981 timer_setup(&ha->timer, qla4xxx_timer, 0);
3982 ha->timer.expires = jiffies + interval * HZ;
3983 add_timer(&ha->timer);
3984 ha->timer_active = 1;
3987 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3989 del_timer_sync(&ha->timer);
3990 ha->timer_active = 0;
3994 * qla4xxx_mark_device_missing - blocks the session
3995 * @cls_session: Pointer to the session to be blocked
3996 * @ddb_entry: Pointer to device database entry
3998 * This routine marks a device missing and close connection.
4000 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4002 iscsi_block_session(cls_session);
4006 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4007 * @ha: Pointer to host adapter structure.
4009 * This routine marks a device missing and resets the relogin retry count.
4011 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4013 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4016 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4017 struct ddb_entry *ddb_entry,
4018 struct scsi_cmnd *cmd)
4022 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4026 kref_init(&srb->srb_ref);
4028 srb->ddb = ddb_entry;
4031 CMD_SP(cmd) = (void *)srb;
4036 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4038 struct scsi_cmnd *cmd = srb->cmd;
4040 if (srb->flags & SRB_DMA_VALID) {
4041 scsi_dma_unmap(cmd);
4042 srb->flags &= ~SRB_DMA_VALID;
4047 void qla4xxx_srb_compl(struct kref *ref)
4049 struct srb *srb = container_of(ref, struct srb, srb_ref);
4050 struct scsi_cmnd *cmd = srb->cmd;
4051 struct scsi_qla_host *ha = srb->ha;
4053 qla4xxx_srb_free_dma(ha, srb);
4055 mempool_free(srb, ha->srb_mempool);
4057 cmd->scsi_done(cmd);
4061 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4063 * @cmd: Pointer to Linux's SCSI command structure
4066 * This routine is invoked by Linux to send a SCSI command to the driver.
4067 * The mid-level driver tries to ensure that queuecommand never gets
4068 * invoked concurrently with itself or the interrupt handler (although
4069 * the interrupt handler may call this routine as part of request-
4070 * completion handling). Unfortunely, it sometimes calls the scheduler
4071 * in interrupt context which is a big NO! NO!.
4073 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4075 struct scsi_qla_host *ha = to_qla_host(host);
4076 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4077 struct iscsi_cls_session *sess = ddb_entry->sess;
4081 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4082 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4083 cmd->result = DID_NO_CONNECT << 16;
4085 cmd->result = DID_REQUEUE << 16;
4086 goto qc_fail_command;
4090 cmd->result = DID_IMM_RETRY << 16;
4091 goto qc_fail_command;
4094 rval = iscsi_session_chkready(sess);
4097 goto qc_fail_command;
4100 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4101 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4102 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4103 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4104 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4105 !test_bit(AF_ONLINE, &ha->flags) ||
4106 !test_bit(AF_LINK_UP, &ha->flags) ||
4107 test_bit(AF_LOOPBACK, &ha->flags) ||
4108 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4109 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4110 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4113 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4117 rval = qla4xxx_send_command_to_isp(ha, srb);
4118 if (rval != QLA_SUCCESS)
4119 goto qc_host_busy_free_sp;
4123 qc_host_busy_free_sp:
4124 qla4xxx_srb_free_dma(ha, srb);
4125 mempool_free(srb, ha->srb_mempool);
4128 return SCSI_MLQUEUE_HOST_BUSY;
4131 cmd->scsi_done(cmd);
4137 * qla4xxx_mem_free - frees memory allocated to adapter
4138 * @ha: Pointer to host adapter structure.
4140 * Frees memory previously allocated by qla4xxx_mem_alloc
4142 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4145 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4154 ha->request_ring = NULL;
4155 ha->request_dma = 0;
4156 ha->response_ring = NULL;
4157 ha->response_dma = 0;
4158 ha->shadow_regs = NULL;
4159 ha->shadow_regs_dma = 0;
4161 ha->fw_dump_size = 0;
4163 /* Free srb pool. */
4164 mempool_destroy(ha->srb_mempool);
4165 ha->srb_mempool = NULL;
4167 dma_pool_destroy(ha->chap_dma_pool);
4170 vfree(ha->chap_list);
4171 ha->chap_list = NULL;
4173 dma_pool_destroy(ha->fw_ddb_dma_pool);
4175 /* release io space registers */
4176 if (is_qla8022(ha)) {
4179 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4180 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4183 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4184 } else if (ha->reg) {
4188 if (ha->reset_tmplt.buff)
4189 vfree(ha->reset_tmplt.buff);
4191 pci_release_regions(ha->pdev);
4195 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4196 * @ha: Pointer to host adapter structure
4198 * Allocates DMA memory for request and response queues. Also allocates memory
4201 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4203 unsigned long align;
4205 /* Allocate contiguous block of DMA memory for queues. */
4206 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4207 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4208 sizeof(struct shadow_regs) +
4210 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4211 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4212 &ha->queues_dma, GFP_KERNEL);
4213 if (ha->queues == NULL) {
4214 ql4_printk(KERN_WARNING, ha,
4215 "Memory Allocation failed - queues.\n");
4217 goto mem_alloc_error_exit;
4221 * As per RISC alignment requirements -- the bus-address must be a
4222 * multiple of the request-ring size (in bytes).
4225 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4226 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4227 (MEM_ALIGN_VALUE - 1));
4229 /* Update request and response queue pointers. */
4230 ha->request_dma = ha->queues_dma + align;
4231 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4232 ha->response_dma = ha->queues_dma + align +
4233 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4234 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4235 (REQUEST_QUEUE_DEPTH *
4237 ha->shadow_regs_dma = ha->queues_dma + align +
4238 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4239 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4240 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4241 (REQUEST_QUEUE_DEPTH *
4243 (RESPONSE_QUEUE_DEPTH *
4246 /* Allocate memory for srb pool. */
4247 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4248 mempool_free_slab, srb_cachep);
4249 if (ha->srb_mempool == NULL) {
4250 ql4_printk(KERN_WARNING, ha,
4251 "Memory Allocation failed - SRB Pool.\n");
4253 goto mem_alloc_error_exit;
4256 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4257 CHAP_DMA_BLOCK_SIZE, 8, 0);
4259 if (ha->chap_dma_pool == NULL) {
4260 ql4_printk(KERN_WARNING, ha,
4261 "%s: chap_dma_pool allocation failed..\n", __func__);
4262 goto mem_alloc_error_exit;
4265 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4266 DDB_DMA_BLOCK_SIZE, 8, 0);
4268 if (ha->fw_ddb_dma_pool == NULL) {
4269 ql4_printk(KERN_WARNING, ha,
4270 "%s: fw_ddb_dma_pool allocation failed..\n",
4272 goto mem_alloc_error_exit;
4277 mem_alloc_error_exit:
4278 qla4xxx_mem_free(ha);
4283 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4284 * @ha: adapter block pointer.
4286 * Note: The caller should not hold the idc lock.
4288 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4290 uint32_t temp, temp_state, temp_val;
4291 int status = QLA_SUCCESS;
4293 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4295 temp_state = qla82xx_get_temp_state(temp);
4296 temp_val = qla82xx_get_temp_val(temp);
4298 if (temp_state == QLA82XX_TEMP_PANIC) {
4299 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4300 " exceeds maximum allowed. Hardware has been shut"
4301 " down.\n", temp_val);
4303 } else if (temp_state == QLA82XX_TEMP_WARN) {
4304 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4305 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4306 " degrees C exceeds operating range."
4307 " Immediate action needed.\n", temp_val);
4309 if (ha->temperature == QLA82XX_TEMP_WARN)
4310 ql4_printk(KERN_INFO, ha, "Device temperature is"
4311 " now %d degrees C in normal range.\n",
4314 ha->temperature = temp_state;
4319 * qla4_8xxx_check_fw_alive - Check firmware health
4320 * @ha: Pointer to host adapter structure.
4322 * Context: Interrupt
4324 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4326 uint32_t fw_heartbeat_counter;
4327 int status = QLA_SUCCESS;
4329 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4330 QLA8XXX_PEG_ALIVE_COUNTER);
4331 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4332 if (fw_heartbeat_counter == 0xffffffff) {
4333 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4334 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4335 ha->host_no, __func__));
4339 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4340 ha->seconds_since_last_heartbeat++;
4341 /* FW not alive after 2 seconds */
4342 if (ha->seconds_since_last_heartbeat == 2) {
4343 ha->seconds_since_last_heartbeat = 0;
4344 qla4_8xxx_dump_peg_reg(ha);
4348 ha->seconds_since_last_heartbeat = 0;
4350 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4354 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4356 uint32_t halt_status;
4357 int halt_status_unrecoverable = 0;
4359 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4361 if (is_qla8022(ha)) {
4362 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4364 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4365 CRB_NIU_XG_PAUSE_CTL_P0 |
4366 CRB_NIU_XG_PAUSE_CTL_P1);
4368 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4369 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4371 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4372 halt_status_unrecoverable = 1;
4373 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4374 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4375 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4377 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4378 halt_status_unrecoverable = 1;
4382 * Since we cannot change dev_state in interrupt context,
4383 * set appropriate DPC flag then wakeup DPC
4385 if (halt_status_unrecoverable) {
4386 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4388 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4390 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4392 qla4xxx_mailbox_premature_completion(ha);
4393 qla4xxx_wake_dpc(ha);
4397 * qla4_8xxx_watchdog - Poll dev state
4398 * @ha: Pointer to host adapter structure.
4400 * Context: Interrupt
4402 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4407 if (is_qla8032(ha) &&
4408 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4409 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4410 __func__, ha->func_num);
4412 /* don't poll if reset is going on */
4413 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4414 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4415 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4416 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4418 if (qla4_8xxx_check_temp(ha)) {
4419 if (is_qla8022(ha)) {
4420 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4421 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4422 CRB_NIU_XG_PAUSE_CTL_P0 |
4423 CRB_NIU_XG_PAUSE_CTL_P1);
4425 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4426 qla4xxx_wake_dpc(ha);
4427 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4428 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4430 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4433 if (is_qla8032(ha) || is_qla8042(ha)) {
4434 idc_ctrl = qla4_83xx_rd_reg(ha,
4435 QLA83XX_IDC_DRV_CTRL);
4436 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4437 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4439 qla4xxx_mailbox_premature_completion(
4444 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4445 (is_qla8022(ha) && !ql4xdontresethba)) {
4446 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4447 qla4xxx_wake_dpc(ha);
4449 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4450 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4451 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4453 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4454 qla4xxx_wake_dpc(ha);
4456 /* Check firmware health */
4457 if (qla4_8xxx_check_fw_alive(ha))
4458 qla4_8xxx_process_fw_error(ha);
4463 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4465 struct iscsi_session *sess;
4466 struct ddb_entry *ddb_entry;
4467 struct scsi_qla_host *ha;
4469 sess = cls_sess->dd_data;
4470 ddb_entry = sess->dd_data;
4473 if (!(ddb_entry->ddb_type == FLASH_DDB))
4476 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4477 !iscsi_is_session_online(cls_sess)) {
4478 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4480 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4482 atomic_set(&ddb_entry->retry_relogin_timer,
4484 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4485 set_bit(DF_RELOGIN, &ddb_entry->flags);
4486 DEBUG2(ql4_printk(KERN_INFO, ha,
4487 "%s: index [%d] login device\n",
4488 __func__, ddb_entry->fw_ddb_index));
4490 atomic_dec(&ddb_entry->retry_relogin_timer);
4494 /* Wait for relogin to timeout */
4495 if (atomic_read(&ddb_entry->relogin_timer) &&
4496 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4498 * If the relogin times out and the device is
4499 * still NOT ONLINE then try and relogin again.
4501 if (!iscsi_is_session_online(cls_sess)) {
4502 /* Reset retry relogin timer */
4503 atomic_inc(&ddb_entry->relogin_retry_count);
4504 DEBUG2(ql4_printk(KERN_INFO, ha,
4505 "%s: index[%d] relogin timed out-retrying"
4506 " relogin (%d), retry (%d)\n", __func__,
4507 ddb_entry->fw_ddb_index,
4508 atomic_read(&ddb_entry->relogin_retry_count),
4509 ddb_entry->default_time2wait + 4));
4510 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4511 atomic_set(&ddb_entry->retry_relogin_timer,
4512 ddb_entry->default_time2wait + 4);
4518 * qla4xxx_timer - checks every second for work to do.
4519 * @ha: Pointer to host adapter structure.
4521 static void qla4xxx_timer(struct timer_list *t)
4523 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4527 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4529 /* If we are in the middle of AER/EEH processing
4530 * skip any processing and reschedule the timer
4532 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4533 mod_timer(&ha->timer, jiffies + HZ);
4537 /* Hardware read to trigger an EEH error during mailbox waits. */
4538 if (!pci_channel_offline(ha->pdev))
4539 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4542 qla4_8xxx_watchdog(ha);
4544 if (is_qla40XX(ha)) {
4545 /* Check for heartbeat interval. */
4546 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4547 ha->heartbeat_interval != 0) {
4548 ha->seconds_since_last_heartbeat++;
4549 if (ha->seconds_since_last_heartbeat >
4550 ha->heartbeat_interval + 2)
4551 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4555 /* Process any deferred work. */
4556 if (!list_empty(&ha->work_list))
4559 /* Wakeup the dpc routine for this adapter, if needed. */
4561 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4562 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4563 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4564 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4565 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4566 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4567 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4568 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4569 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4570 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4571 test_bit(DPC_AEN, &ha->dpc_flags)) {
4572 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4573 " - dpc flags = 0x%lx\n",
4574 ha->host_no, __func__, ha->dpc_flags));
4575 qla4xxx_wake_dpc(ha);
4578 /* Reschedule timer thread to call us back in one second */
4579 mod_timer(&ha->timer, jiffies + HZ);
4581 DEBUG2(ha->seconds_since_last_intr++);
4585 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4586 * @ha: Pointer to host adapter structure.
4588 * This routine stalls the driver until all outstanding commands are returned.
4589 * Caller must release the Hardware Lock prior to calling this routine.
4591 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4594 unsigned long flags;
4595 struct scsi_cmnd *cmd;
4596 unsigned long wtime;
4600 wtmo = WAIT_CMD_TOV;
4602 wtmo = ha->nx_reset_timeout / 2;
4604 wtime = jiffies + (wtmo * HZ);
4606 DEBUG2(ql4_printk(KERN_INFO, ha,
4607 "Wait up to %u seconds for cmds to complete\n",
4610 while (!time_after_eq(jiffies, wtime)) {
4611 spin_lock_irqsave(&ha->hardware_lock, flags);
4612 /* Find a command that hasn't completed. */
4613 for (index = 0; index < ha->host->can_queue; index++) {
4614 cmd = scsi_host_find_tag(ha->host, index);
4616 * We cannot just check if the index is valid,
4617 * becase if we are run from the scsi eh, then
4618 * the scsi/block layer is going to prevent
4619 * the tag from being released.
4621 if (cmd != NULL && CMD_SP(cmd))
4624 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4626 /* If No Commands are pending, wait is complete */
4627 if (index == ha->host->can_queue)
4632 /* If we timed out on waiting for commands to come back
4637 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4639 uint32_t ctrl_status;
4640 unsigned long flags = 0;
4642 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4644 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4647 spin_lock_irqsave(&ha->hardware_lock, flags);
4650 * If the SCSI Reset Interrupt bit is set, clear it.
4651 * Otherwise, the Soft Reset won't work.
4653 ctrl_status = readw(&ha->reg->ctrl_status);
4654 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4655 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4657 /* Issue Soft Reset */
4658 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4659 readl(&ha->reg->ctrl_status);
4661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4666 * qla4xxx_soft_reset - performs soft reset.
4667 * @ha: Pointer to host adapter structure.
4669 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4671 uint32_t max_wait_time;
4672 unsigned long flags = 0;
4674 uint32_t ctrl_status;
4676 status = qla4xxx_hw_reset(ha);
4677 if (status != QLA_SUCCESS)
4681 /* Wait until the Network Reset Intr bit is cleared */
4682 max_wait_time = RESET_INTR_TOV;
4684 spin_lock_irqsave(&ha->hardware_lock, flags);
4685 ctrl_status = readw(&ha->reg->ctrl_status);
4686 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4688 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4692 } while ((--max_wait_time));
4694 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4695 DEBUG2(printk(KERN_WARNING
4696 "scsi%ld: Network Reset Intr not cleared by "
4697 "Network function, clearing it now!\n",
4699 spin_lock_irqsave(&ha->hardware_lock, flags);
4700 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4701 readl(&ha->reg->ctrl_status);
4702 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4705 /* Wait until the firmware tells us the Soft Reset is done */
4706 max_wait_time = SOFT_RESET_TOV;
4708 spin_lock_irqsave(&ha->hardware_lock, flags);
4709 ctrl_status = readw(&ha->reg->ctrl_status);
4710 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4712 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4713 status = QLA_SUCCESS;
4718 } while ((--max_wait_time));
4721 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4722 * after the soft reset has taken place.
4724 spin_lock_irqsave(&ha->hardware_lock, flags);
4725 ctrl_status = readw(&ha->reg->ctrl_status);
4726 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4727 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4728 readl(&ha->reg->ctrl_status);
4730 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4732 /* If soft reset fails then most probably the bios on other
4733 * function is also enabled.
4734 * Since the initialization is sequential the other fn
4735 * wont be able to acknowledge the soft reset.
4736 * Issue a force soft reset to workaround this scenario.
4738 if (max_wait_time == 0) {
4739 /* Issue Force Soft Reset */
4740 spin_lock_irqsave(&ha->hardware_lock, flags);
4741 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4742 readl(&ha->reg->ctrl_status);
4743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4744 /* Wait until the firmware tells us the Soft Reset is done */
4745 max_wait_time = SOFT_RESET_TOV;
4747 spin_lock_irqsave(&ha->hardware_lock, flags);
4748 ctrl_status = readw(&ha->reg->ctrl_status);
4749 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4751 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4752 status = QLA_SUCCESS;
4757 } while ((--max_wait_time));
4764 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4765 * @ha: Pointer to host adapter structure.
4766 * @res: returned scsi status
4768 * This routine is called just prior to a HARD RESET to return all
4769 * outstanding commands back to the Operating System.
4770 * Caller should make sure that the following locks are released
4771 * before this calling routine: Hardware lock, and io_request_lock.
4773 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4777 unsigned long flags;
4779 spin_lock_irqsave(&ha->hardware_lock, flags);
4780 for (i = 0; i < ha->host->can_queue; i++) {
4781 srb = qla4xxx_del_from_active_array(ha, i);
4783 srb->cmd->result = res;
4784 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4787 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4790 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4792 clear_bit(AF_ONLINE, &ha->flags);
4794 /* Disable the board */
4795 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4797 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4798 qla4xxx_mark_all_devices_missing(ha);
4799 clear_bit(AF_INIT_DONE, &ha->flags);
4802 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4804 struct iscsi_session *sess;
4805 struct ddb_entry *ddb_entry;
4807 sess = cls_session->dd_data;
4808 ddb_entry = sess->dd_data;
4809 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4811 if (ddb_entry->ddb_type == FLASH_DDB)
4812 iscsi_block_session(ddb_entry->sess);
4814 iscsi_session_failure(cls_session->dd_data,
4815 ISCSI_ERR_CONN_FAILED);
4819 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4820 * @ha: Pointer to host adapter structure.
4822 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4824 int status = QLA_ERROR;
4825 uint8_t reset_chip = 0;
4829 /* Stall incoming I/O until we are done */
4830 scsi_block_requests(ha->host);
4831 clear_bit(AF_ONLINE, &ha->flags);
4832 clear_bit(AF_LINK_UP, &ha->flags);
4834 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4836 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4838 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4839 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4840 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4842 /* disable pause frame for ISP83xx */
4843 qla4_83xx_disable_pause(ha);
4846 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4848 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4851 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4852 * do not reset adapter, jump to initialize_adapter */
4853 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4854 status = QLA_SUCCESS;
4855 goto recover_ha_init_adapter;
4858 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4859 * from eh_host_reset or ioctl module */
4860 if (is_qla80XX(ha) && !reset_chip &&
4861 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4863 DEBUG2(ql4_printk(KERN_INFO, ha,
4864 "scsi%ld: %s - Performing stop_firmware...\n",
4865 ha->host_no, __func__));
4866 status = ha->isp_ops->reset_firmware(ha);
4867 if (status == QLA_SUCCESS) {
4868 ha->isp_ops->disable_intrs(ha);
4869 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4870 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4872 /* If the stop_firmware fails then
4873 * reset the entire chip */
4875 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4876 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4880 /* Issue full chip reset if recovering from a catastrophic error,
4881 * or if stop_firmware fails for ISP-8xxx.
4882 * This is the default case for ISP-4xxx */
4883 if (is_qla40XX(ha) || reset_chip) {
4887 /* Check if 8XXX firmware is alive or not
4888 * We may have arrived here from NEED_RESET
4890 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4893 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4894 while (time_before(jiffies, wait)) {
4895 if (qla4_8xxx_check_fw_alive(ha)) {
4896 qla4xxx_mailbox_premature_completion(ha);
4900 set_current_state(TASK_UNINTERRUPTIBLE);
4901 schedule_timeout(HZ);
4904 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4905 qla4xxx_cmd_wait(ha);
4907 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4908 DEBUG2(ql4_printk(KERN_INFO, ha,
4909 "scsi%ld: %s - Performing chip reset..\n",
4910 ha->host_no, __func__));
4911 status = ha->isp_ops->reset_chip(ha);
4912 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4915 /* Flush any pending ddb changed AENs */
4916 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4918 recover_ha_init_adapter:
4919 /* Upon successful firmware/chip reset, re-initialize the adapter */
4920 if (status == QLA_SUCCESS) {
4921 /* For ISP-4xxx, force function 1 to always initialize
4922 * before function 3 to prevent both funcions from
4923 * stepping on top of the other */
4924 if (is_qla40XX(ha) && (ha->mac_index == 3))
4927 /* NOTE: AF_ONLINE flag set upon successful completion of
4928 * qla4xxx_initialize_adapter */
4929 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4930 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4931 status = qla4_8xxx_check_init_adapter_retry(ha);
4932 if (status == QLA_ERROR) {
4933 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4934 ha->host_no, __func__);
4935 qla4xxx_dead_adapter_cleanup(ha);
4936 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4937 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4938 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4945 /* Retry failed adapter initialization, if necessary
4946 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4947 * case to prevent ping-pong resets between functions */
4948 if (!test_bit(AF_ONLINE, &ha->flags) &&
4949 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4950 /* Adapter initialization failed, see if we can retry
4952 * Since we don't want to block the DPC for too long
4953 * with multiple resets in the same thread,
4954 * utilize DPC to retry */
4955 if (is_qla80XX(ha)) {
4956 ha->isp_ops->idc_lock(ha);
4957 dev_state = qla4_8xxx_rd_direct(ha,
4958 QLA8XXX_CRB_DEV_STATE);
4959 ha->isp_ops->idc_unlock(ha);
4960 if (dev_state == QLA8XXX_DEV_FAILED) {
4961 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4962 "recover adapter. H/W is in Failed "
4963 "state\n", __func__);
4964 qla4xxx_dead_adapter_cleanup(ha);
4965 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4966 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4967 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4975 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4976 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4977 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4978 "(%d) more times\n", ha->host_no,
4979 ha->retry_reset_ha_cnt));
4980 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4983 if (ha->retry_reset_ha_cnt > 0) {
4984 /* Schedule another Reset HA--DPC will retry */
4985 ha->retry_reset_ha_cnt--;
4986 DEBUG2(printk("scsi%ld: recover adapter - "
4987 "retry remaining %d\n",
4989 ha->retry_reset_ha_cnt));
4993 if (ha->retry_reset_ha_cnt == 0) {
4994 /* Recover adapter retries have been exhausted.
4996 DEBUG2(printk("scsi%ld: recover adapter "
4997 "failed - board disabled\n",
4999 qla4xxx_dead_adapter_cleanup(ha);
5000 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5001 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5002 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5008 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5009 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5010 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5014 ha->adapter_error_count++;
5016 if (test_bit(AF_ONLINE, &ha->flags))
5017 ha->isp_ops->enable_intrs(ha);
5019 scsi_unblock_requests(ha->host);
5021 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5022 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5023 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5028 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5030 struct iscsi_session *sess;
5031 struct ddb_entry *ddb_entry;
5032 struct scsi_qla_host *ha;
5034 sess = cls_session->dd_data;
5035 ddb_entry = sess->dd_data;
5037 if (!iscsi_is_session_online(cls_session)) {
5038 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5039 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5040 " unblock session\n", ha->host_no, __func__,
5041 ddb_entry->fw_ddb_index);
5042 iscsi_unblock_session(ddb_entry->sess);
5044 /* Trigger relogin */
5045 if (ddb_entry->ddb_type == FLASH_DDB) {
5046 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5047 test_bit(DF_DISABLE_RELOGIN,
5048 &ddb_entry->flags)))
5049 qla4xxx_arm_relogin_timer(ddb_entry);
5051 iscsi_session_failure(cls_session->dd_data,
5052 ISCSI_ERR_CONN_FAILED);
5057 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5059 struct iscsi_session *sess;
5060 struct ddb_entry *ddb_entry;
5061 struct scsi_qla_host *ha;
5063 sess = cls_session->dd_data;
5064 ddb_entry = sess->dd_data;
5066 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5067 " unblock session\n", ha->host_no, __func__,
5068 ddb_entry->fw_ddb_index);
5070 iscsi_unblock_session(ddb_entry->sess);
5072 /* Start scan target */
5073 if (test_bit(AF_ONLINE, &ha->flags)) {
5074 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5075 " start scan\n", ha->host_no, __func__,
5076 ddb_entry->fw_ddb_index);
5077 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5082 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5084 struct iscsi_session *sess;
5085 struct ddb_entry *ddb_entry;
5086 struct scsi_qla_host *ha;
5087 int status = QLA_SUCCESS;
5089 sess = cls_session->dd_data;
5090 ddb_entry = sess->dd_data;
5092 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5093 " unblock user space session\n", ha->host_no, __func__,
5094 ddb_entry->fw_ddb_index);
5096 if (!iscsi_is_session_online(cls_session)) {
5097 iscsi_conn_start(ddb_entry->conn);
5098 iscsi_conn_login_event(ddb_entry->conn,
5099 ISCSI_CONN_STATE_LOGGED_IN);
5101 ql4_printk(KERN_INFO, ha,
5102 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5103 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5111 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5113 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5116 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5118 uint16_t relogin_timer;
5119 struct iscsi_session *sess;
5120 struct ddb_entry *ddb_entry;
5121 struct scsi_qla_host *ha;
5123 sess = cls_sess->dd_data;
5124 ddb_entry = sess->dd_data;
5127 relogin_timer = max(ddb_entry->default_relogin_timeout,
5128 (uint16_t)RELOGIN_TOV);
5129 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5131 DEBUG2(ql4_printk(KERN_INFO, ha,
5132 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5133 ddb_entry->fw_ddb_index, relogin_timer));
5135 qla4xxx_login_flash_ddb(cls_sess);
5138 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5140 struct iscsi_session *sess;
5141 struct ddb_entry *ddb_entry;
5142 struct scsi_qla_host *ha;
5144 sess = cls_sess->dd_data;
5145 ddb_entry = sess->dd_data;
5148 if (!(ddb_entry->ddb_type == FLASH_DDB))
5151 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5154 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5155 !iscsi_is_session_online(cls_sess)) {
5156 DEBUG2(ql4_printk(KERN_INFO, ha,
5157 "relogin issued\n"));
5158 qla4xxx_relogin_flash_ddb(cls_sess);
5162 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5165 queue_work(ha->dpc_thread, &ha->dpc_work);
5168 static struct qla4_work_evt *
5169 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5170 enum qla4_work_type type)
5172 struct qla4_work_evt *e;
5173 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5175 e = kzalloc(size, GFP_ATOMIC);
5179 INIT_LIST_HEAD(&e->list);
5184 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5185 struct qla4_work_evt *e)
5187 unsigned long flags;
5189 spin_lock_irqsave(&ha->work_lock, flags);
5190 list_add_tail(&e->list, &ha->work_list);
5191 spin_unlock_irqrestore(&ha->work_lock, flags);
5192 qla4xxx_wake_dpc(ha);
5195 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5196 enum iscsi_host_event_code aen_code,
5197 uint32_t data_size, uint8_t *data)
5199 struct qla4_work_evt *e;
5201 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5205 e->u.aen.code = aen_code;
5206 e->u.aen.data_size = data_size;
5207 memcpy(e->u.aen.data, data, data_size);
5209 qla4xxx_post_work(ha, e);
5214 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5215 uint32_t status, uint32_t pid,
5216 uint32_t data_size, uint8_t *data)
5218 struct qla4_work_evt *e;
5220 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5224 e->u.ping.status = status;
5225 e->u.ping.pid = pid;
5226 e->u.ping.data_size = data_size;
5227 memcpy(e->u.ping.data, data, data_size);
5229 qla4xxx_post_work(ha, e);
5234 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5236 struct qla4_work_evt *e, *tmp;
5237 unsigned long flags;
5240 spin_lock_irqsave(&ha->work_lock, flags);
5241 list_splice_init(&ha->work_list, &work);
5242 spin_unlock_irqrestore(&ha->work_lock, flags);
5244 list_for_each_entry_safe(e, tmp, &work, list) {
5245 list_del_init(&e->list);
5248 case QLA4_EVENT_AEN:
5249 iscsi_post_host_event(ha->host_no,
5250 &qla4xxx_iscsi_transport,
5255 case QLA4_EVENT_PING_STATUS:
5256 iscsi_ping_comp_event(ha->host_no,
5257 &qla4xxx_iscsi_transport,
5260 e->u.ping.data_size,
5264 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5265 "supported", e->type);
5272 * qla4xxx_do_dpc - dpc routine
5273 * @data: in our case pointer to adapter structure
5275 * This routine is a task that is schedule by the interrupt handler
5276 * to perform the background processing for interrupts. We put it
5277 * on a task queue that is consumed whenever the scheduler runs; that's
5278 * so you can do anything (i.e. put the process to sleep etc). In fact,
5279 * the mid-level tries to sleep when it reaches the driver threshold
5280 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5282 static void qla4xxx_do_dpc(struct work_struct *work)
5284 struct scsi_qla_host *ha =
5285 container_of(work, struct scsi_qla_host, dpc_work);
5286 int status = QLA_ERROR;
5288 DEBUG2(ql4_printk(KERN_INFO, ha,
5289 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5290 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5292 /* Initialization not yet finished. Don't do anything yet. */
5293 if (!test_bit(AF_INIT_DONE, &ha->flags))
5296 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5297 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5298 ha->host_no, __func__, ha->flags));
5302 /* post events to application */
5303 qla4xxx_do_work(ha);
5305 if (is_qla80XX(ha)) {
5306 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5307 if (is_qla8032(ha) || is_qla8042(ha)) {
5308 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5310 /* disable pause frame for ISP83xx */
5311 qla4_83xx_disable_pause(ha);
5314 ha->isp_ops->idc_lock(ha);
5315 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5316 QLA8XXX_DEV_FAILED);
5317 ha->isp_ops->idc_unlock(ha);
5318 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5319 qla4_8xxx_device_state_handler(ha);
5322 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5323 if (is_qla8042(ha)) {
5324 if (ha->idc_info.info2 &
5325 ENABLE_INTERNAL_LOOPBACK) {
5326 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5328 status = qla4_84xx_config_acb(ha,
5329 ACB_CONFIG_DISABLE);
5330 if (status != QLA_SUCCESS) {
5331 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5336 qla4_83xx_post_idc_ack(ha);
5337 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5340 if (is_qla8042(ha) &&
5341 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5342 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5344 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5346 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5349 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5352 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5353 qla4_8xxx_need_qsnt_handler(ha);
5357 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5358 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5359 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5360 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5361 if ((is_qla8022(ha) && ql4xdontresethba) ||
5362 ((is_qla8032(ha) || is_qla8042(ha)) &&
5363 qla4_83xx_idc_dontreset(ha))) {
5364 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5365 ha->host_no, __func__));
5366 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5367 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5368 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5369 goto dpc_post_reset_ha;
5371 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5372 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5373 qla4xxx_recover_adapter(ha);
5375 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5376 uint8_t wait_time = RESET_INTR_TOV;
5378 while ((readw(&ha->reg->ctrl_status) &
5379 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5380 if (--wait_time == 0)
5385 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5386 "bit not cleared-- resetting\n",
5387 ha->host_no, __func__));
5388 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5389 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5390 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5391 status = qla4xxx_recover_adapter(ha);
5393 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5394 if (status == QLA_SUCCESS)
5395 ha->isp_ops->enable_intrs(ha);
5400 /* ---- process AEN? --- */
5401 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5402 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5404 /* ---- Get DHCP IP Address? --- */
5405 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5406 qla4xxx_get_dhcp_ip_address(ha);
5408 /* ---- relogin device? --- */
5409 if (adapter_up(ha) &&
5410 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5411 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5414 /* ---- link change? --- */
5415 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5416 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5417 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5418 /* ---- link down? --- */
5419 qla4xxx_mark_all_devices_missing(ha);
5421 /* ---- link up? --- *
5422 * F/W will auto login to all devices ONLY ONCE after
5423 * link up during driver initialization and runtime
5424 * fatal error recovery. Therefore, the driver must
5425 * manually relogin to devices when recovering from
5426 * connection failures, logouts, expired KATO, etc. */
5427 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5428 qla4xxx_build_ddb_list(ha, ha->is_reset);
5429 iscsi_host_for_each_session(ha->host,
5430 qla4xxx_login_flash_ddb);
5432 qla4xxx_relogin_all_devices(ha);
5435 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5436 if (qla4xxx_sysfs_ddb_export(ha))
5437 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5443 * qla4xxx_free_adapter - release the adapter
5444 * @ha: pointer to adapter structure
5446 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5448 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5450 /* Turn-off interrupts on the card. */
5451 ha->isp_ops->disable_intrs(ha);
5453 if (is_qla40XX(ha)) {
5454 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5455 &ha->reg->ctrl_status);
5456 readl(&ha->reg->ctrl_status);
5457 } else if (is_qla8022(ha)) {
5458 writel(0, &ha->qla4_82xx_reg->host_int);
5459 readl(&ha->qla4_82xx_reg->host_int);
5460 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5461 writel(0, &ha->qla4_83xx_reg->risc_intr);
5462 readl(&ha->qla4_83xx_reg->risc_intr);
5465 /* Remove timer thread, if present */
5466 if (ha->timer_active)
5467 qla4xxx_stop_timer(ha);
5469 /* Kill the kernel thread for this host */
5471 destroy_workqueue(ha->dpc_thread);
5473 /* Kill the kernel thread for this host */
5475 destroy_workqueue(ha->task_wq);
5477 /* Put firmware in known state */
5478 ha->isp_ops->reset_firmware(ha);
5480 if (is_qla80XX(ha)) {
5481 ha->isp_ops->idc_lock(ha);
5482 qla4_8xxx_clear_drv_active(ha);
5483 ha->isp_ops->idc_unlock(ha);
5486 /* Detach interrupts */
5487 qla4xxx_free_irqs(ha);
5489 /* free extra memory */
5490 qla4xxx_mem_free(ha);
5493 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5496 unsigned long mem_base, mem_len, db_base, db_len;
5497 struct pci_dev *pdev = ha->pdev;
5499 status = pci_request_regions(pdev, DRIVER_NAME);
5502 "scsi(%ld) Failed to reserve PIO regions (%s) "
5503 "status=%d\n", ha->host_no, pci_name(pdev), status);
5504 goto iospace_error_exit;
5507 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5508 __func__, pdev->revision));
5509 ha->revision_id = pdev->revision;
5511 /* remap phys address */
5512 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5513 mem_len = pci_resource_len(pdev, 0);
5514 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5515 __func__, mem_base, mem_len));
5517 /* mapping of pcibase pointer */
5518 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5519 if (!ha->nx_pcibase) {
5521 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5522 pci_release_regions(ha->pdev);
5523 goto iospace_error_exit;
5526 /* Mapping of IO base pointer, door bell read and write pointer */
5528 /* mapping of IO base pointer */
5529 if (is_qla8022(ha)) {
5530 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5531 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5532 (ha->pdev->devfn << 11));
5533 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5534 QLA82XX_CAM_RAM_DB2);
5535 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5536 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5537 ((uint8_t *)ha->nx_pcibase);
5540 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5541 db_len = pci_resource_len(pdev, 4);
5549 * qla4xxx_iospace_config - maps registers
5550 * @ha: pointer to adapter structure
5552 * This routines maps HBA's registers from the pci address space
5553 * into the kernel virtual address space for memory mapped i/o.
5555 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5557 unsigned long pio, pio_len, pio_flags;
5558 unsigned long mmio, mmio_len, mmio_flags;
5560 pio = pci_resource_start(ha->pdev, 0);
5561 pio_len = pci_resource_len(ha->pdev, 0);
5562 pio_flags = pci_resource_flags(ha->pdev, 0);
5563 if (pio_flags & IORESOURCE_IO) {
5564 if (pio_len < MIN_IOBASE_LEN) {
5565 ql4_printk(KERN_WARNING, ha,
5566 "Invalid PCI I/O region size\n");
5570 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5574 /* Use MMIO operations for all accesses. */
5575 mmio = pci_resource_start(ha->pdev, 1);
5576 mmio_len = pci_resource_len(ha->pdev, 1);
5577 mmio_flags = pci_resource_flags(ha->pdev, 1);
5579 if (!(mmio_flags & IORESOURCE_MEM)) {
5580 ql4_printk(KERN_ERR, ha,
5581 "region #0 not an MMIO resource, aborting\n");
5583 goto iospace_error_exit;
5586 if (mmio_len < MIN_IOBASE_LEN) {
5587 ql4_printk(KERN_ERR, ha,
5588 "Invalid PCI mem region size, aborting\n");
5589 goto iospace_error_exit;
5592 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5593 ql4_printk(KERN_WARNING, ha,
5594 "Failed to reserve PIO/MMIO regions\n");
5596 goto iospace_error_exit;
5599 ha->pio_address = pio;
5600 ha->pio_length = pio_len;
5601 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5603 ql4_printk(KERN_ERR, ha,
5604 "cannot remap MMIO, aborting\n");
5606 goto iospace_error_exit;
5615 static struct isp_operations qla4xxx_isp_ops = {
5616 .iospace_config = qla4xxx_iospace_config,
5617 .pci_config = qla4xxx_pci_config,
5618 .disable_intrs = qla4xxx_disable_intrs,
5619 .enable_intrs = qla4xxx_enable_intrs,
5620 .start_firmware = qla4xxx_start_firmware,
5621 .intr_handler = qla4xxx_intr_handler,
5622 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5623 .reset_chip = qla4xxx_soft_reset,
5624 .reset_firmware = qla4xxx_hw_reset,
5625 .queue_iocb = qla4xxx_queue_iocb,
5626 .complete_iocb = qla4xxx_complete_iocb,
5627 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5628 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5629 .get_sys_info = qla4xxx_get_sys_info,
5630 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5631 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5634 static struct isp_operations qla4_82xx_isp_ops = {
5635 .iospace_config = qla4_8xxx_iospace_config,
5636 .pci_config = qla4_8xxx_pci_config,
5637 .disable_intrs = qla4_82xx_disable_intrs,
5638 .enable_intrs = qla4_82xx_enable_intrs,
5639 .start_firmware = qla4_8xxx_load_risc,
5640 .restart_firmware = qla4_82xx_try_start_fw,
5641 .intr_handler = qla4_82xx_intr_handler,
5642 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5643 .need_reset = qla4_8xxx_need_reset,
5644 .reset_chip = qla4_82xx_isp_reset,
5645 .reset_firmware = qla4_8xxx_stop_firmware,
5646 .queue_iocb = qla4_82xx_queue_iocb,
5647 .complete_iocb = qla4_82xx_complete_iocb,
5648 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5649 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5650 .get_sys_info = qla4_8xxx_get_sys_info,
5651 .rd_reg_direct = qla4_82xx_rd_32,
5652 .wr_reg_direct = qla4_82xx_wr_32,
5653 .rd_reg_indirect = qla4_82xx_md_rd_32,
5654 .wr_reg_indirect = qla4_82xx_md_wr_32,
5655 .idc_lock = qla4_82xx_idc_lock,
5656 .idc_unlock = qla4_82xx_idc_unlock,
5657 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5658 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5659 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5662 static struct isp_operations qla4_83xx_isp_ops = {
5663 .iospace_config = qla4_8xxx_iospace_config,
5664 .pci_config = qla4_8xxx_pci_config,
5665 .disable_intrs = qla4_83xx_disable_intrs,
5666 .enable_intrs = qla4_83xx_enable_intrs,
5667 .start_firmware = qla4_8xxx_load_risc,
5668 .restart_firmware = qla4_83xx_start_firmware,
5669 .intr_handler = qla4_83xx_intr_handler,
5670 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5671 .need_reset = qla4_8xxx_need_reset,
5672 .reset_chip = qla4_83xx_isp_reset,
5673 .reset_firmware = qla4_8xxx_stop_firmware,
5674 .queue_iocb = qla4_83xx_queue_iocb,
5675 .complete_iocb = qla4_83xx_complete_iocb,
5676 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5677 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5678 .get_sys_info = qla4_8xxx_get_sys_info,
5679 .rd_reg_direct = qla4_83xx_rd_reg,
5680 .wr_reg_direct = qla4_83xx_wr_reg,
5681 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5682 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5683 .idc_lock = qla4_83xx_drv_lock,
5684 .idc_unlock = qla4_83xx_drv_unlock,
5685 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5686 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5687 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5690 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5692 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5695 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5697 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5700 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5702 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5705 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5707 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5710 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5712 struct scsi_qla_host *ha = data;
5717 case ISCSI_BOOT_ETH_FLAGS:
5718 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5720 case ISCSI_BOOT_ETH_INDEX:
5721 rc = sprintf(str, "0\n");
5723 case ISCSI_BOOT_ETH_MAC:
5724 rc = sysfs_format_mac(str, ha->my_mac,
5734 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5739 case ISCSI_BOOT_ETH_FLAGS:
5740 case ISCSI_BOOT_ETH_MAC:
5741 case ISCSI_BOOT_ETH_INDEX:
5751 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5753 struct scsi_qla_host *ha = data;
5758 case ISCSI_BOOT_INI_INITIATOR_NAME:
5759 rc = sprintf(str, "%s\n", ha->name_string);
5768 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5773 case ISCSI_BOOT_INI_INITIATOR_NAME:
5784 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5787 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5792 case ISCSI_BOOT_TGT_NAME:
5793 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5795 case ISCSI_BOOT_TGT_IP_ADDR:
5796 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5797 rc = sprintf(buf, "%pI4\n",
5798 &boot_conn->dest_ipaddr.ip_address);
5800 rc = sprintf(str, "%pI6\n",
5801 &boot_conn->dest_ipaddr.ip_address);
5803 case ISCSI_BOOT_TGT_PORT:
5804 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5806 case ISCSI_BOOT_TGT_CHAP_NAME:
5807 rc = sprintf(str, "%.*s\n",
5808 boot_conn->chap.target_chap_name_length,
5809 (char *)&boot_conn->chap.target_chap_name);
5811 case ISCSI_BOOT_TGT_CHAP_SECRET:
5812 rc = sprintf(str, "%.*s\n",
5813 boot_conn->chap.target_secret_length,
5814 (char *)&boot_conn->chap.target_secret);
5816 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5817 rc = sprintf(str, "%.*s\n",
5818 boot_conn->chap.intr_chap_name_length,
5819 (char *)&boot_conn->chap.intr_chap_name);
5821 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5822 rc = sprintf(str, "%.*s\n",
5823 boot_conn->chap.intr_secret_length,
5824 (char *)&boot_conn->chap.intr_secret);
5826 case ISCSI_BOOT_TGT_FLAGS:
5827 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5829 case ISCSI_BOOT_TGT_NIC_ASSOC:
5830 rc = sprintf(str, "0\n");
5839 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5841 struct scsi_qla_host *ha = data;
5842 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5844 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5847 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5849 struct scsi_qla_host *ha = data;
5850 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5852 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5855 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5860 case ISCSI_BOOT_TGT_NAME:
5861 case ISCSI_BOOT_TGT_IP_ADDR:
5862 case ISCSI_BOOT_TGT_PORT:
5863 case ISCSI_BOOT_TGT_CHAP_NAME:
5864 case ISCSI_BOOT_TGT_CHAP_SECRET:
5865 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5866 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5867 case ISCSI_BOOT_TGT_NIC_ASSOC:
5868 case ISCSI_BOOT_TGT_FLAGS:
5878 static void qla4xxx_boot_release(void *data)
5880 struct scsi_qla_host *ha = data;
5882 scsi_host_put(ha->host);
5885 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5888 uint32_t addr, pri_addr, sec_addr;
5892 uint8_t *buf = NULL;
5893 size_t size = 13 * sizeof(uint8_t);
5894 int ret = QLA_SUCCESS;
5896 func_num = PCI_FUNC(ha->pdev->devfn);
5898 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5899 __func__, ha->pdev->device, func_num);
5901 if (is_qla40XX(ha)) {
5902 if (func_num == 1) {
5903 addr = NVRAM_PORT0_BOOT_MODE;
5904 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5905 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5906 } else if (func_num == 3) {
5907 addr = NVRAM_PORT1_BOOT_MODE;
5908 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5909 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5912 goto exit_boot_info;
5915 /* Check Boot Mode */
5916 val = rd_nvram_byte(ha, addr);
5917 if (!(val & 0x07)) {
5918 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5919 "options : 0x%x\n", __func__, val));
5921 goto exit_boot_info;
5924 /* get primary valid target index */
5925 val = rd_nvram_byte(ha, pri_addr);
5927 ddb_index[0] = (val & 0x7f);
5929 /* get secondary valid target index */
5930 val = rd_nvram_byte(ha, sec_addr);
5932 ddb_index[1] = (val & 0x7f);
5933 goto exit_boot_info;
5934 } else if (is_qla80XX(ha)) {
5935 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5936 &buf_dma, GFP_KERNEL);
5938 DEBUG2(ql4_printk(KERN_ERR, ha,
5939 "%s: Unable to allocate dma buffer\n",
5942 goto exit_boot_info;
5945 if (ha->port_num == 0)
5946 offset = BOOT_PARAM_OFFSET_PORT0;
5947 else if (ha->port_num == 1)
5948 offset = BOOT_PARAM_OFFSET_PORT1;
5951 goto exit_boot_info_free;
5953 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5955 if (qla4xxx_get_flash(ha, buf_dma, addr,
5956 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5957 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5958 " failed\n", ha->host_no, __func__));
5960 goto exit_boot_info_free;
5962 /* Check Boot Mode */
5963 if (!(buf[1] & 0x07)) {
5964 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5965 " : 0x%x\n", buf[1]));
5967 goto exit_boot_info_free;
5970 /* get primary valid target index */
5972 ddb_index[0] = buf[2] & 0x7f;
5974 /* get secondary valid target index */
5975 if (buf[11] & BIT_7)
5976 ddb_index[1] = buf[11] & 0x7f;
5979 goto exit_boot_info;
5982 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5983 " target ID %d\n", __func__, ddb_index[0],
5986 exit_boot_info_free:
5987 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5989 ha->pri_ddb_idx = ddb_index[0];
5990 ha->sec_ddb_idx = ddb_index[1];
5995 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5996 * @ha: pointer to adapter structure
5997 * @username: CHAP username to be returned
5998 * @password: CHAP password to be returned
6000 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6001 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6002 * So from the CHAP cache find the first BIDI CHAP entry and set it
6003 * to the boot record in sysfs.
6005 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6008 int i, ret = -EINVAL;
6009 int max_chap_entries = 0;
6010 struct ql4_chap_table *chap_table;
6013 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6014 sizeof(struct ql4_chap_table);
6016 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6018 if (!ha->chap_list) {
6019 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6023 mutex_lock(&ha->chap_sem);
6024 for (i = 0; i < max_chap_entries; i++) {
6025 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6026 if (chap_table->cookie !=
6027 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6031 if (chap_table->flags & BIT_7) /* local */
6034 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6037 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6038 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6042 mutex_unlock(&ha->chap_sem);
6048 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6049 struct ql4_boot_session_info *boot_sess,
6052 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6053 struct dev_db_entry *fw_ddb_entry;
6054 dma_addr_t fw_ddb_entry_dma;
6057 int ret = QLA_SUCCESS;
6059 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6060 &fw_ddb_entry_dma, GFP_KERNEL);
6061 if (!fw_ddb_entry) {
6062 DEBUG2(ql4_printk(KERN_ERR, ha,
6063 "%s: Unable to allocate dma buffer.\n",
6069 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6070 fw_ddb_entry_dma, ddb_index)) {
6071 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6072 "index [%d]\n", __func__, ddb_index));
6074 goto exit_boot_target;
6077 /* Update target name and IP from DDB */
6078 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6079 min(sizeof(boot_sess->target_name),
6080 sizeof(fw_ddb_entry->iscsi_name)));
6082 options = le16_to_cpu(fw_ddb_entry->options);
6083 if (options & DDB_OPT_IPV6_DEVICE) {
6084 memcpy(&boot_conn->dest_ipaddr.ip_address,
6085 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6087 boot_conn->dest_ipaddr.ip_type = 0x1;
6088 memcpy(&boot_conn->dest_ipaddr.ip_address,
6089 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6092 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6094 /* update chap information */
6095 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6097 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6099 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6101 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6103 (char *)&boot_conn->chap.target_secret,
6106 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6108 goto exit_boot_target;
6111 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6112 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6115 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6117 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6119 ret = qla4xxx_get_bidi_chap(ha,
6120 (char *)&boot_conn->chap.intr_chap_name,
6121 (char *)&boot_conn->chap.intr_secret);
6124 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6126 goto exit_boot_target;
6129 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6130 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6134 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6135 fw_ddb_entry, fw_ddb_entry_dma);
6139 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6141 uint16_t ddb_index[2];
6142 int ret = QLA_ERROR;
6145 memset(ddb_index, 0, sizeof(ddb_index));
6146 ddb_index[0] = 0xffff;
6147 ddb_index[1] = 0xffff;
6148 ret = get_fw_boot_info(ha, ddb_index);
6149 if (ret != QLA_SUCCESS) {
6150 DEBUG2(ql4_printk(KERN_INFO, ha,
6151 "%s: No boot target configured.\n", __func__));
6155 if (ql4xdisablesysfsboot)
6158 if (ddb_index[0] == 0xffff)
6161 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6163 if (rval != QLA_SUCCESS) {
6164 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6165 "configured\n", __func__));
6170 if (ddb_index[1] == 0xffff)
6171 goto exit_get_boot_info;
6173 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6175 if (rval != QLA_SUCCESS) {
6176 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6177 " configured\n", __func__));
6185 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6187 struct iscsi_boot_kobj *boot_kobj;
6189 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6192 if (ql4xdisablesysfsboot) {
6193 ql4_printk(KERN_INFO, ha,
6194 "%s: syfsboot disabled - driver will trigger login "
6195 "and publish session for discovery .\n", __func__);
6200 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6204 if (!scsi_host_get(ha->host))
6206 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6207 qla4xxx_show_boot_tgt_pri_info,
6208 qla4xxx_tgt_get_attr_visibility,
6209 qla4xxx_boot_release);
6213 if (!scsi_host_get(ha->host))
6215 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6216 qla4xxx_show_boot_tgt_sec_info,
6217 qla4xxx_tgt_get_attr_visibility,
6218 qla4xxx_boot_release);
6222 if (!scsi_host_get(ha->host))
6224 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6225 qla4xxx_show_boot_ini_info,
6226 qla4xxx_ini_get_attr_visibility,
6227 qla4xxx_boot_release);
6231 if (!scsi_host_get(ha->host))
6233 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6234 qla4xxx_show_boot_eth_info,
6235 qla4xxx_eth_get_attr_visibility,
6236 qla4xxx_boot_release);
6243 scsi_host_put(ha->host);
6245 iscsi_boot_destroy_kset(ha->boot_kset);
6250 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6251 struct ql4_tuple_ddb *tddb)
6253 struct scsi_qla_host *ha;
6254 struct iscsi_cls_session *cls_sess;
6255 struct iscsi_cls_conn *cls_conn;
6256 struct iscsi_session *sess;
6257 struct iscsi_conn *conn;
6259 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6261 cls_sess = ddb_entry->sess;
6262 sess = cls_sess->dd_data;
6263 cls_conn = ddb_entry->conn;
6264 conn = cls_conn->dd_data;
6266 tddb->tpgt = sess->tpgt;
6267 tddb->port = conn->persistent_port;
6268 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6269 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6272 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6273 struct ql4_tuple_ddb *tddb,
6274 uint8_t *flash_isid)
6276 uint16_t options = 0;
6278 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6279 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6280 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6282 options = le16_to_cpu(fw_ddb_entry->options);
6283 if (options & DDB_OPT_IPV6_DEVICE)
6284 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6286 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6288 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6290 if (flash_isid == NULL)
6291 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6292 sizeof(tddb->isid));
6294 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6297 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6298 struct ql4_tuple_ddb *old_tddb,
6299 struct ql4_tuple_ddb *new_tddb,
6300 uint8_t is_isid_compare)
6302 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6305 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6308 if (old_tddb->port != new_tddb->port)
6311 /* For multi sessions, driver generates the ISID, so do not compare
6312 * ISID in reset path since it would be a comparison between the
6313 * driver generated ISID and firmware generated ISID. This could
6314 * lead to adding duplicated DDBs in the list as driver generated
6315 * ISID would not match firmware generated ISID.
6317 if (is_isid_compare) {
6318 DEBUG2(ql4_printk(KERN_INFO, ha,
6319 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6320 __func__, old_tddb->isid, new_tddb->isid));
6322 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6323 sizeof(old_tddb->isid)))
6327 DEBUG2(ql4_printk(KERN_INFO, ha,
6328 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6329 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6330 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6331 new_tddb->ip_addr, new_tddb->iscsi_name));
6336 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6337 struct dev_db_entry *fw_ddb_entry,
6340 struct ddb_entry *ddb_entry;
6341 struct ql4_tuple_ddb *fw_tddb = NULL;
6342 struct ql4_tuple_ddb *tmp_tddb = NULL;
6344 int ret = QLA_ERROR;
6346 fw_tddb = vzalloc(sizeof(*fw_tddb));
6348 DEBUG2(ql4_printk(KERN_WARNING, ha,
6349 "Memory Allocation failed.\n"));
6354 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6356 DEBUG2(ql4_printk(KERN_WARNING, ha,
6357 "Memory Allocation failed.\n"));
6362 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6364 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6365 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6366 if (ddb_entry == NULL)
6369 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6370 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6371 ret = QLA_SUCCESS; /* found */
6387 * qla4xxx_check_existing_isid - check if target with same isid exist
6389 * @list_nt: list of target
6390 * @isid: isid to check
6392 * This routine return QLA_SUCCESS if target with same isid exist
6394 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6396 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6397 struct dev_db_entry *fw_ddb_entry;
6399 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6400 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6402 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6403 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6411 * qla4xxx_update_isid - compare ddbs and updated isid
6412 * @ha: Pointer to host adapter structure.
6413 * @list_nt: list of nt target
6414 * @fw_ddb_entry: firmware ddb entry
6416 * This routine update isid if ddbs have same iqn, same isid and
6417 * different IP addr.
6418 * Return QLA_SUCCESS if isid is updated.
6420 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6421 struct list_head *list_nt,
6422 struct dev_db_entry *fw_ddb_entry)
6424 uint8_t base_value, i;
6426 base_value = fw_ddb_entry->isid[1] & 0x1f;
6427 for (i = 0; i < 8; i++) {
6428 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6429 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6433 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6440 * qla4xxx_should_update_isid - check if isid need to update
6441 * @ha: Pointer to host adapter structure.
6442 * @old_tddb: ddb tuple
6443 * @new_tddb: ddb tuple
6445 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6448 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6449 struct ql4_tuple_ddb *old_tddb,
6450 struct ql4_tuple_ddb *new_tddb)
6452 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6454 if (old_tddb->port == new_tddb->port)
6458 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6462 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6463 sizeof(old_tddb->isid)))
6464 /* different isid */
6471 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6472 * @ha: Pointer to host adapter structure.
6473 * @list_nt: list of nt target.
6474 * @fw_ddb_entry: firmware ddb entry.
6476 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6477 * duplicate ddb in list_nt.
6478 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6479 * Note: This function also update isid of DDB if required.
6482 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6483 struct list_head *list_nt,
6484 struct dev_db_entry *fw_ddb_entry)
6486 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6487 struct ql4_tuple_ddb *fw_tddb = NULL;
6488 struct ql4_tuple_ddb *tmp_tddb = NULL;
6489 int rval, ret = QLA_ERROR;
6491 fw_tddb = vzalloc(sizeof(*fw_tddb));
6493 DEBUG2(ql4_printk(KERN_WARNING, ha,
6494 "Memory Allocation failed.\n"));
6499 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6501 DEBUG2(ql4_printk(KERN_WARNING, ha,
6502 "Memory Allocation failed.\n"));
6507 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6509 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6510 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6511 nt_ddb_idx->flash_isid);
6512 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6513 /* found duplicate ddb */
6514 if (ret == QLA_SUCCESS)
6518 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6519 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6521 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6522 if (ret == QLA_SUCCESS) {
6523 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6524 if (rval == QLA_SUCCESS)
6541 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6543 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6545 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6546 list_del_init(&ddb_idx->list);
6551 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6552 struct dev_db_entry *fw_ddb_entry)
6554 struct iscsi_endpoint *ep;
6555 struct sockaddr_in *addr;
6556 struct sockaddr_in6 *addr6;
6557 struct sockaddr *t_addr;
6558 struct sockaddr_storage *dst_addr;
6561 /* TODO: need to destroy on unload iscsi_endpoint*/
6562 dst_addr = vmalloc(sizeof(*dst_addr));
6566 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6567 t_addr = (struct sockaddr *)dst_addr;
6568 t_addr->sa_family = AF_INET6;
6569 addr6 = (struct sockaddr_in6 *)dst_addr;
6570 ip = (char *)&addr6->sin6_addr;
6571 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6572 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6575 t_addr = (struct sockaddr *)dst_addr;
6576 t_addr->sa_family = AF_INET;
6577 addr = (struct sockaddr_in *)dst_addr;
6578 ip = (char *)&addr->sin_addr;
6579 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6580 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6583 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6588 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6590 if (ql4xdisablesysfsboot)
6592 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6597 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6598 struct ddb_entry *ddb_entry,
6601 uint16_t def_timeout;
6603 ddb_entry->ddb_type = FLASH_DDB;
6604 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6605 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6607 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6608 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6609 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6611 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6612 atomic_set(&ddb_entry->relogin_timer, 0);
6613 atomic_set(&ddb_entry->relogin_retry_count, 0);
6614 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6615 ddb_entry->default_relogin_timeout =
6616 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6617 def_timeout : LOGIN_TOV;
6618 ddb_entry->default_time2wait =
6619 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6621 if (ql4xdisablesysfsboot &&
6622 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6623 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6626 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6629 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6630 uint32_t sts[MBOX_REG_COUNT];
6632 unsigned long wtime;
6635 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6637 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6638 if (ip_idx[idx] == -1)
6641 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6643 if (ret == QLA_ERROR) {
6648 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6650 DEBUG2(ql4_printk(KERN_INFO, ha,
6651 "Waiting for IP state for idx = %d, state = 0x%x\n",
6652 ip_idx[idx], ip_state));
6653 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6654 ip_state == IP_ADDRSTATE_INVALID ||
6655 ip_state == IP_ADDRSTATE_PREFERRED ||
6656 ip_state == IP_ADDRSTATE_DEPRICATED ||
6657 ip_state == IP_ADDRSTATE_DISABLING)
6661 /* Break if all IP states checked */
6662 if ((ip_idx[0] == -1) &&
6663 (ip_idx[1] == -1) &&
6664 (ip_idx[2] == -1) &&
6667 schedule_timeout_uninterruptible(HZ);
6668 } while (time_after(wtime, jiffies));
6671 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6672 struct dev_db_entry *flash_ddb_entry)
6674 uint16_t options = 0;
6675 size_t ip_len = IP_ADDR_LEN;
6677 options = le16_to_cpu(fw_ddb_entry->options);
6678 if (options & DDB_OPT_IPV6_DEVICE)
6679 ip_len = IPv6_ADDR_LEN;
6681 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6684 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6685 sizeof(fw_ddb_entry->isid)))
6688 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6689 sizeof(fw_ddb_entry->port)))
6695 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6696 struct dev_db_entry *fw_ddb_entry,
6697 uint32_t fw_idx, uint32_t *flash_index)
6699 struct dev_db_entry *flash_ddb_entry;
6700 dma_addr_t flash_ddb_entry_dma;
6703 int ret = QLA_ERROR, status;
6705 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6708 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6709 &flash_ddb_entry_dma);
6710 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6711 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6712 goto exit_find_st_idx;
6715 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6716 flash_ddb_entry_dma, fw_idx);
6717 if (status == QLA_SUCCESS) {
6718 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6719 if (status == QLA_SUCCESS) {
6720 *flash_index = fw_idx;
6722 goto exit_find_st_idx;
6726 for (idx = 0; idx < max_ddbs; idx++) {
6727 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6728 flash_ddb_entry_dma, idx);
6729 if (status == QLA_ERROR)
6732 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6733 if (status == QLA_SUCCESS) {
6736 goto exit_find_st_idx;
6740 if (idx == max_ddbs)
6741 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6745 if (flash_ddb_entry)
6746 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6747 flash_ddb_entry_dma);
6752 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6753 struct list_head *list_st)
6755 struct qla_ddb_index *st_ddb_idx;
6758 struct dev_db_entry *fw_ddb_entry;
6759 dma_addr_t fw_ddb_dma;
6761 uint32_t idx = 0, next_idx = 0;
6762 uint32_t state = 0, conn_err = 0;
6763 uint32_t flash_index = -1;
6764 uint16_t conn_id = 0;
6766 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6768 if (fw_ddb_entry == NULL) {
6769 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6773 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6775 fw_idx_size = sizeof(struct qla_ddb_index);
6777 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6778 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6779 NULL, &next_idx, &state,
6780 &conn_err, NULL, &conn_id);
6781 if (ret == QLA_ERROR)
6784 /* Ignore DDB if invalid state (unassigned) */
6785 if (state == DDB_DS_UNASSIGNED)
6786 goto continue_next_st;
6788 /* Check if ST, add to the list_st */
6789 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6790 goto continue_next_st;
6792 st_ddb_idx = vzalloc(fw_idx_size);
6796 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6798 if (ret == QLA_ERROR) {
6799 ql4_printk(KERN_ERR, ha,
6800 "No flash entry for ST at idx [%d]\n", idx);
6801 st_ddb_idx->flash_ddb_idx = idx;
6803 ql4_printk(KERN_INFO, ha,
6804 "ST at idx [%d] is stored at flash [%d]\n",
6806 st_ddb_idx->flash_ddb_idx = flash_index;
6809 st_ddb_idx->fw_ddb_idx = idx;
6811 list_add_tail(&st_ddb_idx->list, list_st);
6819 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6823 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6824 * @ha: pointer to adapter structure
6825 * @list_ddb: List from which failed ddb to be removed
6827 * Iterate over the list of DDBs and find and remove DDBs that are either in
6828 * no connection active state or failed state
6830 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6831 struct list_head *list_ddb)
6833 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6834 uint32_t next_idx = 0;
6835 uint32_t state = 0, conn_err = 0;
6838 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6839 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6840 NULL, 0, NULL, &next_idx, &state,
6841 &conn_err, NULL, NULL);
6842 if (ret == QLA_ERROR)
6845 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6846 state == DDB_DS_SESSION_FAILED) {
6847 list_del_init(&ddb_idx->list);
6853 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6854 struct ddb_entry *ddb_entry,
6855 struct dev_db_entry *fw_ddb_entry)
6857 struct iscsi_cls_session *cls_sess;
6858 struct iscsi_session *sess;
6859 uint32_t max_ddbs = 0;
6860 uint16_t ddb_link = -1;
6862 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6865 cls_sess = ddb_entry->sess;
6866 sess = cls_sess->dd_data;
6868 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6869 if (ddb_link < max_ddbs)
6870 sess->discovery_parent_idx = ddb_link;
6872 sess->discovery_parent_idx = DDB_NO_LINK;
6875 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6876 struct dev_db_entry *fw_ddb_entry,
6877 int is_reset, uint16_t idx)
6879 struct iscsi_cls_session *cls_sess;
6880 struct iscsi_session *sess;
6881 struct iscsi_cls_conn *cls_conn;
6882 struct iscsi_endpoint *ep;
6883 uint16_t cmds_max = 32;
6884 uint16_t conn_id = 0;
6885 uint32_t initial_cmdsn = 0;
6886 int ret = QLA_SUCCESS;
6888 struct ddb_entry *ddb_entry = NULL;
6890 /* Create session object, with INVALID_ENTRY,
6891 * the targer_id would get set when we issue the login
6893 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6894 cmds_max, sizeof(struct ddb_entry),
6895 sizeof(struct ql4_task_data),
6896 initial_cmdsn, INVALID_ENTRY);
6903 * so calling module_put function to decrement the
6906 module_put(qla4xxx_iscsi_transport.owner);
6907 sess = cls_sess->dd_data;
6908 ddb_entry = sess->dd_data;
6909 ddb_entry->sess = cls_sess;
6911 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6912 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6913 sizeof(struct dev_db_entry));
6915 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6917 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6924 ddb_entry->conn = cls_conn;
6926 /* Setup ep, for displaying attributes in sysfs */
6927 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6929 ep->conn = cls_conn;
6932 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6937 /* Update sess/conn params */
6938 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6939 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6941 if (is_reset == RESET_ADAPTER) {
6942 iscsi_block_session(cls_sess);
6943 /* Use the relogin path to discover new devices
6944 * by short-circuting the logic of setting
6945 * timer to relogin - instead set the flags
6946 * to initiate login right away.
6948 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6949 set_bit(DF_RELOGIN, &ddb_entry->flags);
6956 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6957 struct list_head *list_ddb,
6958 struct dev_db_entry *fw_ddb_entry)
6960 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6963 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6965 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6966 if (ddb_idx->fw_ddb_idx == ddb_link) {
6967 DEBUG2(ql4_printk(KERN_INFO, ha,
6968 "Updating NT parent idx from [%d] to [%d]\n",
6969 ddb_link, ddb_idx->flash_ddb_idx));
6970 fw_ddb_entry->ddb_link =
6971 cpu_to_le16(ddb_idx->flash_ddb_idx);
6977 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6978 struct list_head *list_nt,
6979 struct list_head *list_st,
6982 struct dev_db_entry *fw_ddb_entry;
6983 struct ddb_entry *ddb_entry = NULL;
6984 dma_addr_t fw_ddb_dma;
6988 uint32_t idx = 0, next_idx = 0;
6989 uint32_t state = 0, conn_err = 0;
6990 uint32_t ddb_idx = -1;
6991 uint16_t conn_id = 0;
6992 uint16_t ddb_link = -1;
6993 struct qla_ddb_index *nt_ddb_idx;
6995 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6997 if (fw_ddb_entry == NULL) {
6998 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7001 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7003 fw_idx_size = sizeof(struct qla_ddb_index);
7005 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7006 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7007 NULL, &next_idx, &state,
7008 &conn_err, NULL, &conn_id);
7009 if (ret == QLA_ERROR)
7012 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7013 goto continue_next_nt;
7015 /* Check if NT, then add to list it */
7016 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7017 goto continue_next_nt;
7019 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7020 if (ddb_link < max_ddbs)
7021 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7023 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7024 state == DDB_DS_SESSION_FAILED) &&
7025 (is_reset == INIT_ADAPTER))
7026 goto continue_next_nt;
7028 DEBUG2(ql4_printk(KERN_INFO, ha,
7029 "Adding DDB to session = 0x%x\n", idx));
7031 if (is_reset == INIT_ADAPTER) {
7032 nt_ddb_idx = vmalloc(fw_idx_size);
7036 nt_ddb_idx->fw_ddb_idx = idx;
7038 /* Copy original isid as it may get updated in function
7039 * qla4xxx_update_isid(). We need original isid in
7040 * function qla4xxx_compare_tuple_ddb to find duplicate
7042 memcpy(&nt_ddb_idx->flash_isid[0],
7043 &fw_ddb_entry->isid[0],
7044 sizeof(nt_ddb_idx->flash_isid));
7046 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7048 if (ret == QLA_SUCCESS) {
7049 /* free nt_ddb_idx and do not add to list_nt */
7051 goto continue_next_nt;
7054 /* Copy updated isid */
7055 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7056 sizeof(struct dev_db_entry));
7058 list_add_tail(&nt_ddb_idx->list, list_nt);
7059 } else if (is_reset == RESET_ADAPTER) {
7060 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7062 if (ret == QLA_SUCCESS) {
7063 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7065 if (ddb_entry != NULL)
7066 qla4xxx_update_sess_disc_idx(ha,
7069 goto continue_next_nt;
7073 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7074 if (ret == QLA_ERROR)
7084 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7087 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7088 struct list_head *list_nt,
7091 struct dev_db_entry *fw_ddb_entry;
7092 dma_addr_t fw_ddb_dma;
7096 uint32_t idx = 0, next_idx = 0;
7097 uint32_t state = 0, conn_err = 0;
7098 uint16_t conn_id = 0;
7099 struct qla_ddb_index *nt_ddb_idx;
7101 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7103 if (fw_ddb_entry == NULL) {
7104 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7105 goto exit_new_nt_list;
7107 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7109 fw_idx_size = sizeof(struct qla_ddb_index);
7111 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7112 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7113 NULL, &next_idx, &state,
7114 &conn_err, NULL, &conn_id);
7115 if (ret == QLA_ERROR)
7118 /* Check if NT, then add it to list */
7119 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7120 goto continue_next_new_nt;
7122 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7123 goto continue_next_new_nt;
7125 DEBUG2(ql4_printk(KERN_INFO, ha,
7126 "Adding DDB to session = 0x%x\n", idx));
7128 nt_ddb_idx = vmalloc(fw_idx_size);
7132 nt_ddb_idx->fw_ddb_idx = idx;
7134 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7135 if (ret == QLA_SUCCESS) {
7136 /* free nt_ddb_idx and do not add to list_nt */
7138 goto continue_next_new_nt;
7141 if (target_id < max_ddbs)
7142 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7144 list_add_tail(&nt_ddb_idx->list, list_nt);
7146 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7148 if (ret == QLA_ERROR)
7149 goto exit_new_nt_list;
7151 continue_next_new_nt:
7158 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7162 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7163 * @dev: dev associated with the sysfs entry
7164 * @data: pointer to flashnode session object
7167 * 1: if flashnode entry is non-persistent
7168 * 0: if flashnode entry is persistent
7170 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7172 struct iscsi_bus_flash_session *fnode_sess;
7174 if (!iscsi_flashnode_bus_match(dev, NULL))
7177 fnode_sess = iscsi_dev_to_flash_session(dev);
7179 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7183 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7184 * @ha: pointer to host
7185 * @fw_ddb_entry: flash ddb data
7186 * @idx: target index
7187 * @user: if set then this call is made from userland else from kernel
7190 * On sucess: QLA_SUCCESS
7191 * On failure: QLA_ERROR
7193 * This create separate sysfs entries for session and connection attributes of
7194 * the given fw ddb entry.
7195 * If this is invoked as a result of a userspace call then the entry is marked
7196 * as nonpersistent using flash_state field.
7198 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7199 struct dev_db_entry *fw_ddb_entry,
7200 uint16_t *idx, int user)
7202 struct iscsi_bus_flash_session *fnode_sess = NULL;
7203 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7206 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7207 &qla4xxx_iscsi_transport, 0);
7209 ql4_printk(KERN_ERR, ha,
7210 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7211 __func__, *idx, ha->host_no);
7212 goto exit_tgt_create;
7215 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7216 &qla4xxx_iscsi_transport, 0);
7218 ql4_printk(KERN_ERR, ha,
7219 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7220 __func__, *idx, ha->host_no);
7225 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7227 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7229 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7230 fnode_sess->is_boot_target = 1;
7232 fnode_sess->is_boot_target = 0;
7235 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7240 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7241 __func__, fnode_sess->dev.kobj.name);
7243 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7244 __func__, fnode_conn->dev.kobj.name);
7249 iscsi_destroy_flashnode_sess(fnode_sess);
7256 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7257 * @shost: pointer to host
7258 * @buf: type of ddb entry (ipv4/ipv6)
7259 * @len: length of buf
7261 * This creates new ddb entry in the flash by finding first free index and
7262 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7264 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7267 struct scsi_qla_host *ha = to_qla_host(shost);
7268 struct dev_db_entry *fw_ddb_entry = NULL;
7269 dma_addr_t fw_ddb_entry_dma;
7272 uint16_t max_ddbs = 0;
7273 uint32_t options = 0;
7274 uint32_t rval = QLA_ERROR;
7276 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7277 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7278 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7283 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7286 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7287 &fw_ddb_entry_dma, GFP_KERNEL);
7288 if (!fw_ddb_entry) {
7289 DEBUG2(ql4_printk(KERN_ERR, ha,
7290 "%s: Unable to allocate dma buffer\n",
7295 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7296 qla4xxx_sysfs_ddb_is_non_persistent);
7298 ql4_printk(KERN_ERR, ha,
7299 "%s: A non-persistent entry %s found\n",
7300 __func__, dev->kobj.name);
7305 /* Index 0 and 1 are reserved for boot target entries */
7306 for (idx = 2; idx < max_ddbs; idx++) {
7307 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7308 fw_ddb_entry_dma, idx))
7312 if (idx == max_ddbs)
7315 if (!strncasecmp("ipv6", buf, 4))
7316 options |= IPV6_DEFAULT_DDB_ENTRY;
7318 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7319 if (rval == QLA_ERROR)
7322 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7326 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7327 fw_ddb_entry, fw_ddb_entry_dma);
7328 if (rval == QLA_SUCCESS)
7335 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7336 * @fnode_sess: pointer to session attrs of flash ddb entry
7337 * @fnode_conn: pointer to connection attrs of flash ddb entry
7339 * This writes the contents of target ddb buffer to Flash with a valid cookie
7340 * value in order to make the ddb entry persistent.
7342 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7343 struct iscsi_bus_flash_conn *fnode_conn)
7345 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7346 struct scsi_qla_host *ha = to_qla_host(shost);
7347 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7348 struct dev_db_entry *fw_ddb_entry = NULL;
7349 dma_addr_t fw_ddb_entry_dma;
7350 uint32_t options = 0;
7353 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7354 &fw_ddb_entry_dma, GFP_KERNEL);
7355 if (!fw_ddb_entry) {
7356 DEBUG2(ql4_printk(KERN_ERR, ha,
7357 "%s: Unable to allocate dma buffer\n",
7360 goto exit_ddb_apply;
7363 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7364 options |= IPV6_DEFAULT_DDB_ENTRY;
7366 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7367 if (rval == QLA_ERROR)
7368 goto exit_ddb_apply;
7370 dev_db_start_offset += (fnode_sess->target_id *
7371 sizeof(*fw_ddb_entry));
7373 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7374 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7376 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7377 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7379 if (rval == QLA_SUCCESS) {
7380 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7381 ql4_printk(KERN_INFO, ha,
7382 "%s: flash node %u of host %lu written to flash\n",
7383 __func__, fnode_sess->target_id, ha->host_no);
7386 ql4_printk(KERN_ERR, ha,
7387 "%s: Error while writing flash node %u of host %lu to flash\n",
7388 __func__, fnode_sess->target_id, ha->host_no);
7393 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7394 fw_ddb_entry, fw_ddb_entry_dma);
7398 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7399 struct dev_db_entry *fw_ddb_entry,
7402 struct dev_db_entry *ddb_entry = NULL;
7403 dma_addr_t ddb_entry_dma;
7404 unsigned long wtime;
7405 uint32_t mbx_sts = 0;
7406 uint32_t state = 0, conn_err = 0;
7410 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7411 &ddb_entry_dma, GFP_KERNEL);
7413 DEBUG2(ql4_printk(KERN_ERR, ha,
7414 "%s: Unable to allocate dma buffer\n",
7419 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7421 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7422 if (ret != QLA_SUCCESS) {
7423 DEBUG2(ql4_printk(KERN_ERR, ha,
7424 "%s: Unable to set ddb entry for index %d\n",
7426 goto exit_ddb_conn_open;
7429 qla4xxx_conn_open(ha, idx);
7431 /* To ensure that sendtargets is done, wait for at least 12 secs */
7432 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7433 (ha->def_timeout < LOGIN_TOV * 10) ?
7434 ha->def_timeout : LOGIN_TOV);
7436 DEBUG2(ql4_printk(KERN_INFO, ha,
7437 "Default time to wait for login to ddb %d\n", tmo));
7439 wtime = jiffies + (HZ * tmo);
7441 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7442 NULL, &state, &conn_err, NULL,
7444 if (ret == QLA_ERROR)
7447 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7448 state == DDB_DS_SESSION_FAILED)
7451 schedule_timeout_uninterruptible(HZ / 10);
7452 } while (time_after(wtime, jiffies));
7456 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7457 ddb_entry, ddb_entry_dma);
7461 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7462 struct dev_db_entry *fw_ddb_entry,
7465 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7466 struct list_head list_nt;
7470 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7471 ql4_printk(KERN_WARNING, ha,
7472 "%s: A discovery already in progress!\n", __func__);
7476 INIT_LIST_HEAD(&list_nt);
7478 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7480 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7481 if (ret == QLA_ERROR)
7482 goto exit_login_st_clr_bit;
7484 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7485 if (ret == QLA_ERROR)
7488 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7490 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7491 list_del_init(&ddb_idx->list);
7492 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7497 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7498 ql4_printk(KERN_ERR, ha,
7499 "Unable to clear DDB index = 0x%x\n", ddb_index);
7502 clear_bit(ddb_index, ha->ddb_idx_map);
7504 exit_login_st_clr_bit:
7505 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7509 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7510 struct dev_db_entry *fw_ddb_entry,
7513 int ret = QLA_ERROR;
7515 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7516 if (ret != QLA_SUCCESS)
7517 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7526 * qla4xxx_sysfs_ddb_login - Login to the specified target
7527 * @fnode_sess: pointer to session attrs of flash ddb entry
7528 * @fnode_conn: pointer to connection attrs of flash ddb entry
7530 * This logs in to the specified target
7532 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7533 struct iscsi_bus_flash_conn *fnode_conn)
7535 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7536 struct scsi_qla_host *ha = to_qla_host(shost);
7537 struct dev_db_entry *fw_ddb_entry = NULL;
7538 dma_addr_t fw_ddb_entry_dma;
7539 uint32_t options = 0;
7542 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7543 ql4_printk(KERN_ERR, ha,
7544 "%s: Target info is not persistent\n", __func__);
7546 goto exit_ddb_login;
7549 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7550 &fw_ddb_entry_dma, GFP_KERNEL);
7551 if (!fw_ddb_entry) {
7552 DEBUG2(ql4_printk(KERN_ERR, ha,
7553 "%s: Unable to allocate dma buffer\n",
7556 goto exit_ddb_login;
7559 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7560 options |= IPV6_DEFAULT_DDB_ENTRY;
7562 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7563 if (ret == QLA_ERROR)
7564 goto exit_ddb_login;
7566 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7567 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7569 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7570 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7571 fnode_sess->target_id);
7573 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7574 fnode_sess->target_id);
7581 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7582 fw_ddb_entry, fw_ddb_entry_dma);
7587 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7588 * @cls_sess: pointer to session to be logged out
7590 * This performs session log out from the specified target
7592 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7594 struct iscsi_session *sess;
7595 struct ddb_entry *ddb_entry = NULL;
7596 struct scsi_qla_host *ha;
7597 struct dev_db_entry *fw_ddb_entry = NULL;
7598 dma_addr_t fw_ddb_entry_dma;
7599 unsigned long flags;
7600 unsigned long wtime;
7605 sess = cls_sess->dd_data;
7606 ddb_entry = sess->dd_data;
7609 if (ddb_entry->ddb_type != FLASH_DDB) {
7610 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7613 goto exit_ddb_logout;
7616 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7617 ql4_printk(KERN_ERR, ha,
7618 "%s: Logout from boot target entry is not permitted.\n",
7621 goto exit_ddb_logout;
7624 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7625 &fw_ddb_entry_dma, GFP_KERNEL);
7626 if (!fw_ddb_entry) {
7627 ql4_printk(KERN_ERR, ha,
7628 "%s: Unable to allocate dma buffer\n", __func__);
7630 goto exit_ddb_logout;
7633 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7634 goto ddb_logout_init;
7636 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7637 fw_ddb_entry, fw_ddb_entry_dma,
7638 NULL, NULL, &ddb_state, NULL,
7640 if (ret == QLA_ERROR)
7641 goto ddb_logout_init;
7643 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7644 goto ddb_logout_init;
7646 /* wait until next relogin is triggered using DF_RELOGIN and
7647 * clear DF_RELOGIN to avoid invocation of further relogin
7649 wtime = jiffies + (HZ * RELOGIN_TOV);
7651 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7652 goto ddb_logout_init;
7654 schedule_timeout_uninterruptible(HZ);
7655 } while ((time_after(wtime, jiffies)));
7658 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7659 atomic_set(&ddb_entry->relogin_timer, 0);
7661 options = LOGOUT_OPTION_CLOSE_SESSION;
7662 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7664 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7665 wtime = jiffies + (HZ * LOGOUT_TOV);
7667 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7668 fw_ddb_entry, fw_ddb_entry_dma,
7669 NULL, NULL, &ddb_state, NULL,
7671 if (ret == QLA_ERROR)
7672 goto ddb_logout_clr_sess;
7674 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7675 (ddb_state == DDB_DS_SESSION_FAILED))
7676 goto ddb_logout_clr_sess;
7678 schedule_timeout_uninterruptible(HZ);
7679 } while ((time_after(wtime, jiffies)));
7681 ddb_logout_clr_sess:
7682 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7684 * we have decremented the reference count of the driver
7685 * when we setup the session to have the driver unload
7686 * to be seamless without actually destroying the
7689 try_module_get(qla4xxx_iscsi_transport.owner);
7690 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7692 spin_lock_irqsave(&ha->hardware_lock, flags);
7693 qla4xxx_free_ddb(ha, ddb_entry);
7694 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7697 iscsi_session_teardown(ddb_entry->sess);
7699 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7704 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7705 fw_ddb_entry, fw_ddb_entry_dma);
7710 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7711 * @fnode_sess: pointer to session attrs of flash ddb entry
7712 * @fnode_conn: pointer to connection attrs of flash ddb entry
7714 * This performs log out from the specified target
7716 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7717 struct iscsi_bus_flash_conn *fnode_conn)
7719 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7720 struct scsi_qla_host *ha = to_qla_host(shost);
7721 struct ql4_tuple_ddb *flash_tddb = NULL;
7722 struct ql4_tuple_ddb *tmp_tddb = NULL;
7723 struct dev_db_entry *fw_ddb_entry = NULL;
7724 struct ddb_entry *ddb_entry = NULL;
7725 dma_addr_t fw_ddb_dma;
7726 uint32_t next_idx = 0;
7727 uint32_t state = 0, conn_err = 0;
7728 uint16_t conn_id = 0;
7730 int status, ret = 0;
7732 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7734 if (fw_ddb_entry == NULL) {
7735 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7737 goto exit_ddb_logout;
7740 flash_tddb = vzalloc(sizeof(*flash_tddb));
7742 ql4_printk(KERN_WARNING, ha,
7743 "%s:Memory Allocation failed.\n", __func__);
7745 goto exit_ddb_logout;
7748 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7750 ql4_printk(KERN_WARNING, ha,
7751 "%s:Memory Allocation failed.\n", __func__);
7753 goto exit_ddb_logout;
7756 if (!fnode_sess->targetname) {
7757 ql4_printk(KERN_ERR, ha,
7758 "%s:Cannot logout from SendTarget entry\n",
7761 goto exit_ddb_logout;
7764 if (fnode_sess->is_boot_target) {
7765 ql4_printk(KERN_ERR, ha,
7766 "%s: Logout from boot target entry is not permitted.\n",
7769 goto exit_ddb_logout;
7772 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7775 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7776 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7778 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7780 flash_tddb->tpgt = fnode_sess->tpgt;
7781 flash_tddb->port = fnode_conn->port;
7783 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7785 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7786 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7787 if (ddb_entry == NULL)
7790 if (ddb_entry->ddb_type != FLASH_DDB)
7793 index = ddb_entry->sess->target_id;
7794 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7795 fw_ddb_dma, NULL, &next_idx,
7796 &state, &conn_err, NULL,
7798 if (status == QLA_ERROR) {
7803 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7805 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7807 if (status == QLA_SUCCESS) {
7808 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7813 if (idx == MAX_DDB_ENTRIES)
7822 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7828 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7829 int param, char *buf)
7831 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7832 struct scsi_qla_host *ha = to_qla_host(shost);
7833 struct iscsi_bus_flash_conn *fnode_conn;
7834 struct ql4_chap_table chap_tbl;
7839 dev = iscsi_find_flashnode_conn(fnode_sess);
7843 fnode_conn = iscsi_dev_to_flash_conn(dev);
7846 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7847 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7849 case ISCSI_FLASHNODE_PORTAL_TYPE:
7850 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7852 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7853 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7855 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7856 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7858 case ISCSI_FLASHNODE_ENTRY_EN:
7859 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7861 case ISCSI_FLASHNODE_HDR_DGST_EN:
7862 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7864 case ISCSI_FLASHNODE_DATA_DGST_EN:
7865 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7867 case ISCSI_FLASHNODE_IMM_DATA_EN:
7868 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7870 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7871 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7873 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7874 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7876 case ISCSI_FLASHNODE_PDU_INORDER:
7877 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7879 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7880 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7882 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7883 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7885 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7886 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7888 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7889 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7891 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7892 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7894 case ISCSI_FLASHNODE_ERL:
7895 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7897 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7898 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7900 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7901 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7903 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7904 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7906 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7907 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7909 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7910 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7912 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7913 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7915 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7916 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7918 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7919 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7921 case ISCSI_FLASHNODE_FIRST_BURST:
7922 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7924 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7925 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7927 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7928 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7930 case ISCSI_FLASHNODE_MAX_R2T:
7931 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7933 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7934 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7936 case ISCSI_FLASHNODE_ISID:
7937 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7939 case ISCSI_FLASHNODE_TSID:
7940 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7942 case ISCSI_FLASHNODE_PORT:
7943 rc = sprintf(buf, "%d\n", fnode_conn->port);
7945 case ISCSI_FLASHNODE_MAX_BURST:
7946 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7948 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7949 rc = sprintf(buf, "%u\n",
7950 fnode_sess->default_taskmgmt_timeout);
7952 case ISCSI_FLASHNODE_IPADDR:
7953 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7954 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7956 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7958 case ISCSI_FLASHNODE_ALIAS:
7959 if (fnode_sess->targetalias)
7960 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7962 rc = sprintf(buf, "\n");
7964 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7965 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7966 rc = sprintf(buf, "%pI6\n",
7967 fnode_conn->redirect_ipaddr);
7969 rc = sprintf(buf, "%pI4\n",
7970 fnode_conn->redirect_ipaddr);
7972 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7973 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7975 case ISCSI_FLASHNODE_LOCAL_PORT:
7976 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7978 case ISCSI_FLASHNODE_IPV4_TOS:
7979 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7981 case ISCSI_FLASHNODE_IPV6_TC:
7982 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7983 rc = sprintf(buf, "%u\n",
7984 fnode_conn->ipv6_traffic_class);
7986 rc = sprintf(buf, "\n");
7988 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7989 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7991 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
7992 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7993 rc = sprintf(buf, "%pI6\n",
7994 fnode_conn->link_local_ipv6_addr);
7996 rc = sprintf(buf, "\n");
7998 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
7999 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8001 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8002 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8003 parent_type = ISCSI_DISC_PARENT_ISNS;
8004 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8005 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8006 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8007 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8009 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8011 rc = sprintf(buf, "%s\n",
8012 iscsi_get_discovery_parent_name(parent_type));
8014 case ISCSI_FLASHNODE_NAME:
8015 if (fnode_sess->targetname)
8016 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8018 rc = sprintf(buf, "\n");
8020 case ISCSI_FLASHNODE_TPGT:
8021 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8023 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8024 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8026 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8027 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8029 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8030 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8032 case ISCSI_FLASHNODE_USERNAME:
8033 if (fnode_sess->chap_auth_en) {
8034 qla4xxx_get_uni_chap_at_index(ha,
8037 fnode_sess->chap_out_idx);
8038 rc = sprintf(buf, "%s\n", chap_tbl.name);
8040 rc = sprintf(buf, "\n");
8043 case ISCSI_FLASHNODE_PASSWORD:
8044 if (fnode_sess->chap_auth_en) {
8045 qla4xxx_get_uni_chap_at_index(ha,
8048 fnode_sess->chap_out_idx);
8049 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8051 rc = sprintf(buf, "\n");
8054 case ISCSI_FLASHNODE_STATSN:
8055 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8057 case ISCSI_FLASHNODE_EXP_STATSN:
8058 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8060 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8061 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8073 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8074 * @fnode_sess: pointer to session attrs of flash ddb entry
8075 * @fnode_conn: pointer to connection attrs of flash ddb entry
8076 * @data: Parameters and their values to update
8079 * This sets the parameter of flash ddb entry and writes them to flash
8082 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8083 struct iscsi_bus_flash_conn *fnode_conn,
8084 void *data, int len)
8086 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8087 struct scsi_qla_host *ha = to_qla_host(shost);
8088 struct iscsi_flashnode_param_info *fnode_param;
8089 struct ql4_chap_table chap_tbl;
8090 struct nlattr *attr;
8091 uint16_t chap_out_idx = INVALID_ENTRY;
8095 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8096 nla_for_each_attr(attr, data, len, rem) {
8097 fnode_param = nla_data(attr);
8099 switch (fnode_param->param) {
8100 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8101 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8103 case ISCSI_FLASHNODE_PORTAL_TYPE:
8104 memcpy(fnode_sess->portal_type, fnode_param->value,
8105 strlen(fnode_sess->portal_type));
8107 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8108 fnode_sess->auto_snd_tgt_disable =
8109 fnode_param->value[0];
8111 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8112 fnode_sess->discovery_sess = fnode_param->value[0];
8114 case ISCSI_FLASHNODE_ENTRY_EN:
8115 fnode_sess->entry_state = fnode_param->value[0];
8117 case ISCSI_FLASHNODE_HDR_DGST_EN:
8118 fnode_conn->hdrdgst_en = fnode_param->value[0];
8120 case ISCSI_FLASHNODE_DATA_DGST_EN:
8121 fnode_conn->datadgst_en = fnode_param->value[0];
8123 case ISCSI_FLASHNODE_IMM_DATA_EN:
8124 fnode_sess->imm_data_en = fnode_param->value[0];
8126 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8127 fnode_sess->initial_r2t_en = fnode_param->value[0];
8129 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8130 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8132 case ISCSI_FLASHNODE_PDU_INORDER:
8133 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8135 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8136 fnode_sess->chap_auth_en = fnode_param->value[0];
8137 /* Invalidate chap index if chap auth is disabled */
8138 if (!fnode_sess->chap_auth_en)
8139 fnode_sess->chap_out_idx = INVALID_ENTRY;
8142 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8143 fnode_conn->snack_req_en = fnode_param->value[0];
8145 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8146 fnode_sess->discovery_logout_en = fnode_param->value[0];
8148 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8149 fnode_sess->bidi_chap_en = fnode_param->value[0];
8151 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8152 fnode_sess->discovery_auth_optional =
8153 fnode_param->value[0];
8155 case ISCSI_FLASHNODE_ERL:
8156 fnode_sess->erl = fnode_param->value[0];
8158 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8159 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8161 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8162 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8164 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8165 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8167 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8168 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8170 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8171 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8173 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8174 fnode_conn->fragment_disable = fnode_param->value[0];
8176 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8177 fnode_conn->max_recv_dlength =
8178 *(unsigned *)fnode_param->value;
8180 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8181 fnode_conn->max_xmit_dlength =
8182 *(unsigned *)fnode_param->value;
8184 case ISCSI_FLASHNODE_FIRST_BURST:
8185 fnode_sess->first_burst =
8186 *(unsigned *)fnode_param->value;
8188 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8189 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8191 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8192 fnode_sess->time2retain =
8193 *(uint16_t *)fnode_param->value;
8195 case ISCSI_FLASHNODE_MAX_R2T:
8196 fnode_sess->max_r2t =
8197 *(uint16_t *)fnode_param->value;
8199 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8200 fnode_conn->keepalive_timeout =
8201 *(uint16_t *)fnode_param->value;
8203 case ISCSI_FLASHNODE_ISID:
8204 memcpy(fnode_sess->isid, fnode_param->value,
8205 sizeof(fnode_sess->isid));
8207 case ISCSI_FLASHNODE_TSID:
8208 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8210 case ISCSI_FLASHNODE_PORT:
8211 fnode_conn->port = *(uint16_t *)fnode_param->value;
8213 case ISCSI_FLASHNODE_MAX_BURST:
8214 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8216 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8217 fnode_sess->default_taskmgmt_timeout =
8218 *(uint16_t *)fnode_param->value;
8220 case ISCSI_FLASHNODE_IPADDR:
8221 memcpy(fnode_conn->ipaddress, fnode_param->value,
8224 case ISCSI_FLASHNODE_ALIAS:
8225 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8226 (char *)fnode_param->value);
8228 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8229 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8232 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8233 fnode_conn->max_segment_size =
8234 *(unsigned *)fnode_param->value;
8236 case ISCSI_FLASHNODE_LOCAL_PORT:
8237 fnode_conn->local_port =
8238 *(uint16_t *)fnode_param->value;
8240 case ISCSI_FLASHNODE_IPV4_TOS:
8241 fnode_conn->ipv4_tos = fnode_param->value[0];
8243 case ISCSI_FLASHNODE_IPV6_TC:
8244 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8246 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8247 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8249 case ISCSI_FLASHNODE_NAME:
8250 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8251 (char *)fnode_param->value);
8253 case ISCSI_FLASHNODE_TPGT:
8254 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8256 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8257 memcpy(fnode_conn->link_local_ipv6_addr,
8258 fnode_param->value, IPv6_ADDR_LEN);
8260 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8261 fnode_sess->discovery_parent_idx =
8262 *(uint16_t *)fnode_param->value;
8264 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8265 fnode_conn->tcp_xmit_wsf =
8266 *(uint8_t *)fnode_param->value;
8268 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8269 fnode_conn->tcp_recv_wsf =
8270 *(uint8_t *)fnode_param->value;
8272 case ISCSI_FLASHNODE_STATSN:
8273 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8275 case ISCSI_FLASHNODE_EXP_STATSN:
8276 fnode_conn->exp_statsn =
8277 *(uint32_t *)fnode_param->value;
8279 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8280 chap_out_idx = *(uint16_t *)fnode_param->value;
8281 if (!qla4xxx_get_uni_chap_at_index(ha,
8285 fnode_sess->chap_out_idx = chap_out_idx;
8286 /* Enable chap auth if chap index is valid */
8287 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8291 ql4_printk(KERN_ERR, ha,
8292 "%s: No such sysfs attribute\n", __func__);
8294 goto exit_set_param;
8298 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8305 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8306 * @fnode_sess: pointer to session attrs of flash ddb entry
8308 * This invalidates the flash ddb entry at the given index
8310 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8312 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8313 struct scsi_qla_host *ha = to_qla_host(shost);
8314 uint32_t dev_db_start_offset;
8315 uint32_t dev_db_end_offset;
8316 struct dev_db_entry *fw_ddb_entry = NULL;
8317 dma_addr_t fw_ddb_entry_dma;
8318 uint16_t *ddb_cookie = NULL;
8319 size_t ddb_size = 0;
8324 if (fnode_sess->is_boot_target) {
8326 DEBUG2(ql4_printk(KERN_ERR, ha,
8327 "%s: Deletion of boot target entry is not permitted.\n",
8332 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8335 if (is_qla40XX(ha)) {
8336 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8337 dev_db_end_offset = FLASH_OFFSET_DB_END;
8338 dev_db_start_offset += (fnode_sess->target_id *
8339 sizeof(*fw_ddb_entry));
8340 ddb_size = sizeof(*fw_ddb_entry);
8342 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8343 (ha->hw.flt_region_ddb << 2);
8344 /* flt_ddb_size is DDB table size for both ports
8345 * so divide it by 2 to calculate the offset for second port
8347 if (ha->port_num == 1)
8348 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8350 dev_db_end_offset = dev_db_start_offset +
8351 (ha->hw.flt_ddb_size / 2);
8353 dev_db_start_offset += (fnode_sess->target_id *
8354 sizeof(*fw_ddb_entry));
8355 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8357 ddb_size = sizeof(*ddb_cookie);
8360 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8361 __func__, dev_db_start_offset, dev_db_end_offset));
8363 if (dev_db_start_offset > dev_db_end_offset) {
8365 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8366 __func__, fnode_sess->target_id));
8370 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8371 &fw_ddb_entry_dma, GFP_KERNEL);
8374 DEBUG2(ql4_printk(KERN_ERR, ha,
8375 "%s: Unable to allocate dma buffer\n",
8380 if (is_qla40XX(ha)) {
8381 fw_ddb_entry = pddb;
8382 memset(fw_ddb_entry, 0, ddb_size);
8383 ddb_cookie = &fw_ddb_entry->cookie;
8388 /* invalidate the cookie */
8389 *ddb_cookie = 0xFFEE;
8390 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8391 ddb_size, FLASH_OPT_RMW_COMMIT);
8394 target_id = fnode_sess->target_id;
8395 iscsi_destroy_flashnode_sess(fnode_sess);
8396 ql4_printk(KERN_INFO, ha,
8397 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8398 __func__, target_id, ha->host_no);
8401 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8407 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8408 * @ha: pointer to adapter structure
8410 * Export the firmware DDB for all send targets and normal targets to sysfs.
8412 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8414 struct dev_db_entry *fw_ddb_entry = NULL;
8415 dma_addr_t fw_ddb_entry_dma;
8418 int ret = QLA_SUCCESS;
8420 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8421 sizeof(*fw_ddb_entry),
8422 &fw_ddb_entry_dma, GFP_KERNEL);
8423 if (!fw_ddb_entry) {
8424 DEBUG2(ql4_printk(KERN_ERR, ha,
8425 "%s: Unable to allocate dma buffer\n",
8430 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8433 for (idx = 0; idx < max_ddbs; idx++) {
8434 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8438 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8445 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8451 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8453 iscsi_destroy_all_flashnode(ha->host);
8457 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8458 * @ha: pointer to adapter structure
8459 * @is_reset: Is this init path or reset path
8461 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8462 * using connection open, then create the list of normal targets (nt)
8463 * from firmware DDBs. Based on the list of nt setup session and connection
8466 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8469 struct list_head list_st, list_nt;
8470 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8471 unsigned long wtime;
8473 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8474 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8475 ha->is_reset = is_reset;
8479 INIT_LIST_HEAD(&list_st);
8480 INIT_LIST_HEAD(&list_nt);
8482 qla4xxx_build_st_list(ha, &list_st);
8484 /* Before issuing conn open mbox, ensure all IPs states are configured
8485 * Note, conn open fails if IPs are not configured
8487 qla4xxx_wait_for_ip_configuration(ha);
8489 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8490 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8491 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8494 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8495 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8496 (ha->def_timeout < LOGIN_TOV * 10) ?
8497 ha->def_timeout : LOGIN_TOV);
8499 DEBUG2(ql4_printk(KERN_INFO, ha,
8500 "Default time to wait for build ddb %d\n", tmo));
8502 wtime = jiffies + (HZ * tmo);
8504 if (list_empty(&list_st))
8507 qla4xxx_remove_failed_ddb(ha, &list_st);
8508 schedule_timeout_uninterruptible(HZ / 10);
8509 } while (time_after(wtime, jiffies));
8512 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8514 qla4xxx_free_ddb_list(&list_st);
8515 qla4xxx_free_ddb_list(&list_nt);
8517 qla4xxx_free_ddb_index(ha);
8521 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8523 * @ha: pointer to adapter structure
8525 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8526 * set in DDB and we will wait for login response of boot targets during
8529 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8531 struct ddb_entry *ddb_entry;
8532 struct dev_db_entry *fw_ddb_entry = NULL;
8533 dma_addr_t fw_ddb_entry_dma;
8534 unsigned long wtime;
8536 int max_ddbs, idx, ret;
8538 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8541 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8542 &fw_ddb_entry_dma, GFP_KERNEL);
8543 if (!fw_ddb_entry) {
8544 ql4_printk(KERN_ERR, ha,
8545 "%s: Unable to allocate dma buffer\n", __func__);
8546 goto exit_login_resp;
8549 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8551 for (idx = 0; idx < max_ddbs; idx++) {
8552 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8553 if (ddb_entry == NULL)
8556 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8557 DEBUG2(ql4_printk(KERN_INFO, ha,
8558 "%s: DDB index [%d]\n", __func__,
8559 ddb_entry->fw_ddb_index));
8561 ret = qla4xxx_get_fwddb_entry(ha,
8562 ddb_entry->fw_ddb_index,
8563 fw_ddb_entry, fw_ddb_entry_dma,
8564 NULL, NULL, &ddb_state, NULL,
8566 if (ret == QLA_ERROR)
8567 goto exit_login_resp;
8569 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8570 (ddb_state == DDB_DS_SESSION_FAILED))
8573 schedule_timeout_uninterruptible(HZ);
8575 } while ((time_after(wtime, jiffies)));
8577 if (!time_after(wtime, jiffies)) {
8578 DEBUG2(ql4_printk(KERN_INFO, ha,
8579 "%s: Login response wait timer expired\n",
8581 goto exit_login_resp;
8588 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8589 fw_ddb_entry, fw_ddb_entry_dma);
8593 * qla4xxx_probe_adapter - callback function to probe HBA
8594 * @pdev: pointer to pci_dev structure
8595 * @pci_device_id: pointer to pci_device entry
8597 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8598 * It returns zero if successful. It also initializes all data necessary for
8601 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8602 const struct pci_device_id *ent)
8604 int ret = -ENODEV, status;
8605 struct Scsi_Host *host;
8606 struct scsi_qla_host *ha;
8607 uint8_t init_retry_count = 0;
8609 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8612 if (pci_enable_device(pdev))
8615 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8618 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8619 goto probe_disable_device;
8622 /* Clear our data area */
8623 ha = to_qla_host(host);
8624 memset(ha, 0, sizeof(*ha));
8626 /* Save the information from PCI BIOS. */
8629 ha->host_no = host->host_no;
8630 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8632 pci_enable_pcie_error_reporting(pdev);
8634 /* Setup Runtime configurable options */
8635 if (is_qla8022(ha)) {
8636 ha->isp_ops = &qla4_82xx_isp_ops;
8637 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8638 ha->qdr_sn_window = -1;
8639 ha->ddr_mn_window = -1;
8640 ha->curr_window = 255;
8641 nx_legacy_intr = &legacy_intr[ha->func_num];
8642 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8643 ha->nx_legacy_intr.tgt_status_reg =
8644 nx_legacy_intr->tgt_status_reg;
8645 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8646 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8647 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8648 ha->isp_ops = &qla4_83xx_isp_ops;
8649 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8651 ha->isp_ops = &qla4xxx_isp_ops;
8654 if (is_qla80XX(ha)) {
8655 rwlock_init(&ha->hw_lock);
8656 ha->pf_bit = ha->func_num << 16;
8657 /* Set EEH reset type to fundamental if required by hba */
8658 pdev->needs_freset = 1;
8661 /* Configure PCI I/O space. */
8662 ret = ha->isp_ops->iospace_config(ha);
8664 goto probe_failed_ioconfig;
8666 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8667 pdev->device, pdev->irq, ha->reg);
8669 qla4xxx_config_dma_addressing(ha);
8671 /* Initialize lists and spinlocks. */
8672 INIT_LIST_HEAD(&ha->free_srb_q);
8674 mutex_init(&ha->mbox_sem);
8675 mutex_init(&ha->chap_sem);
8676 init_completion(&ha->mbx_intr_comp);
8677 init_completion(&ha->disable_acb_comp);
8678 init_completion(&ha->idc_comp);
8679 init_completion(&ha->link_up_comp);
8681 spin_lock_init(&ha->hardware_lock);
8682 spin_lock_init(&ha->work_lock);
8684 /* Initialize work list */
8685 INIT_LIST_HEAD(&ha->work_list);
8687 /* Allocate dma buffers */
8688 if (qla4xxx_mem_alloc(ha)) {
8689 ql4_printk(KERN_WARNING, ha,
8690 "[ERROR] Failed to allocate memory for adapter\n");
8696 host->cmd_per_lun = 3;
8697 host->max_channel = 0;
8698 host->max_lun = MAX_LUNS - 1;
8699 host->max_id = MAX_TARGETS;
8700 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8701 host->can_queue = MAX_SRBS ;
8702 host->transportt = qla4xxx_scsi_transport;
8704 pci_set_drvdata(pdev, ha);
8706 ret = scsi_add_host(host, &pdev->dev);
8711 qla4_8xxx_get_flash_info(ha);
8713 if (is_qla8032(ha) || is_qla8042(ha)) {
8714 qla4_83xx_read_reset_template(ha);
8716 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8717 * If DONRESET_BIT0 is set, drivers should not set dev_state
8718 * to NEED_RESET. But if NEED_RESET is set, drivers should
8719 * should honor the reset.
8721 if (ql4xdontresethba == 1)
8722 qla4_83xx_set_idc_dontreset(ha);
8726 * Initialize the Host adapter request/response queues and
8728 * NOTE: interrupts enabled upon successful completion
8730 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8732 /* Dont retry adapter initialization if IRQ allocation failed */
8733 if (is_qla80XX(ha) && (status == QLA_ERROR))
8734 goto skip_retry_init;
8736 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8737 init_retry_count++ < MAX_INIT_RETRIES) {
8739 if (is_qla80XX(ha)) {
8740 ha->isp_ops->idc_lock(ha);
8741 dev_state = qla4_8xxx_rd_direct(ha,
8742 QLA8XXX_CRB_DEV_STATE);
8743 ha->isp_ops->idc_unlock(ha);
8744 if (dev_state == QLA8XXX_DEV_FAILED) {
8745 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8746 "initialize adapter. H/W is in failed state\n",
8751 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8752 "(%d)\n", __func__, init_retry_count));
8754 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8757 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8758 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8759 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8760 goto skip_retry_init;
8765 if (!test_bit(AF_ONLINE, &ha->flags)) {
8766 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8768 if ((is_qla8022(ha) && ql4xdontresethba) ||
8769 ((is_qla8032(ha) || is_qla8042(ha)) &&
8770 qla4_83xx_idc_dontreset(ha))) {
8771 /* Put the device in failed state. */
8772 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8773 ha->isp_ops->idc_lock(ha);
8774 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8775 QLA8XXX_DEV_FAILED);
8776 ha->isp_ops->idc_unlock(ha);
8782 /* Startup the kernel thread for this host adapter. */
8783 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8784 "qla4xxx_dpc\n", __func__));
8785 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8786 ha->dpc_thread = create_singlethread_workqueue(buf);
8787 if (!ha->dpc_thread) {
8788 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8792 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8794 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8797 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8803 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8804 * (which is called indirectly by qla4xxx_initialize_adapter),
8805 * so that irqs will be registered after crbinit but before
8808 if (is_qla40XX(ha)) {
8809 ret = qla4xxx_request_irqs(ha);
8811 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8812 "interrupt %d already in use.\n", pdev->irq);
8817 pci_save_state(ha->pdev);
8818 ha->isp_ops->enable_intrs(ha);
8820 /* Start timer thread. */
8821 qla4xxx_start_timer(ha, 1);
8823 set_bit(AF_INIT_DONE, &ha->flags);
8825 qla4_8xxx_alloc_sysfs_attr(ha);
8828 " QLogic iSCSI HBA Driver version: %s\n"
8829 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8830 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8831 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8832 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8834 /* Set the driver version */
8836 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8838 if (qla4xxx_setup_boot_info(ha))
8839 ql4_printk(KERN_ERR, ha,
8840 "%s: No iSCSI boot target configured\n", __func__);
8842 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8843 /* Perform the build ddb list and login to each */
8844 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8845 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8846 qla4xxx_wait_login_resp_boot_tgt(ha);
8848 qla4xxx_create_chap_list(ha);
8850 qla4xxx_create_ifaces(ha);
8854 scsi_remove_host(ha->host);
8857 qla4xxx_free_adapter(ha);
8859 probe_failed_ioconfig:
8860 pci_disable_pcie_error_reporting(pdev);
8861 scsi_host_put(ha->host);
8863 probe_disable_device:
8864 pci_disable_device(pdev);
8870 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8871 * @ha: pointer to adapter structure
8873 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8874 * so that the other port will not re-initialize while in the process of
8875 * removing the ha due to driver unload or hba hotplug.
8877 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8879 struct scsi_qla_host *other_ha = NULL;
8880 struct pci_dev *other_pdev = NULL;
8881 int fn = ISP4XXX_PCI_FN_2;
8883 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8884 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8885 fn = ISP4XXX_PCI_FN_1;
8888 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8889 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8892 /* Get other_ha if other_pdev is valid and state is enable*/
8894 if (atomic_read(&other_pdev->enable_cnt)) {
8895 other_ha = pci_get_drvdata(other_pdev);
8897 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8898 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8899 "Prevent %s reinit\n", __func__,
8900 dev_name(&other_ha->pdev->dev)));
8903 pci_dev_put(other_pdev);
8907 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8908 struct ddb_entry *ddb_entry)
8910 struct dev_db_entry *fw_ddb_entry = NULL;
8911 dma_addr_t fw_ddb_entry_dma;
8912 unsigned long wtime;
8917 options = LOGOUT_OPTION_CLOSE_SESSION;
8918 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8919 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8923 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8924 &fw_ddb_entry_dma, GFP_KERNEL);
8925 if (!fw_ddb_entry) {
8926 ql4_printk(KERN_ERR, ha,
8927 "%s: Unable to allocate dma buffer\n", __func__);
8931 wtime = jiffies + (HZ * LOGOUT_TOV);
8933 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8934 fw_ddb_entry, fw_ddb_entry_dma,
8935 NULL, NULL, &ddb_state, NULL,
8937 if (status == QLA_ERROR)
8940 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8941 (ddb_state == DDB_DS_SESSION_FAILED))
8944 schedule_timeout_uninterruptible(HZ);
8945 } while ((time_after(wtime, jiffies)));
8948 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8949 fw_ddb_entry, fw_ddb_entry_dma);
8951 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8954 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8956 struct ddb_entry *ddb_entry;
8959 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8961 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8962 if ((ddb_entry != NULL) &&
8963 (ddb_entry->ddb_type == FLASH_DDB)) {
8965 qla4xxx_destroy_ddb(ha, ddb_entry);
8967 * we have decremented the reference count of the driver
8968 * when we setup the session to have the driver unload
8969 * to be seamless without actually destroying the
8972 try_module_get(qla4xxx_iscsi_transport.owner);
8973 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8974 qla4xxx_free_ddb(ha, ddb_entry);
8975 iscsi_session_teardown(ddb_entry->sess);
8980 * qla4xxx_remove_adapter - callback function to remove adapter.
8981 * @pci_dev: PCI device pointer
8983 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
8985 struct scsi_qla_host *ha;
8988 * If the PCI device is disabled then it means probe_adapter had
8989 * failed and resources already cleaned up on probe_adapter exit.
8991 if (!pci_is_enabled(pdev))
8994 ha = pci_get_drvdata(pdev);
8997 qla4xxx_prevent_other_port_reinit(ha);
8999 /* destroy iface from sysfs */
9000 qla4xxx_destroy_ifaces(ha);
9002 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9003 iscsi_boot_destroy_kset(ha->boot_kset);
9005 qla4xxx_destroy_fw_ddb_session(ha);
9006 qla4_8xxx_free_sysfs_attr(ha);
9008 qla4xxx_sysfs_ddb_remove(ha);
9009 scsi_remove_host(ha->host);
9011 qla4xxx_free_adapter(ha);
9013 scsi_host_put(ha->host);
9015 pci_disable_pcie_error_reporting(pdev);
9016 pci_disable_device(pdev);
9020 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9023 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9025 /* Update our PCI device dma_mask for full 64 bit mask */
9026 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9027 dev_dbg(&ha->pdev->dev,
9028 "Failed to set 64 bit PCI consistent mask; "
9030 dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9034 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9036 struct iscsi_cls_session *cls_sess;
9037 struct iscsi_session *sess;
9038 struct ddb_entry *ddb;
9039 int queue_depth = QL4_DEF_QDEPTH;
9041 cls_sess = starget_to_session(sdev->sdev_target);
9042 sess = cls_sess->dd_data;
9043 ddb = sess->dd_data;
9045 sdev->hostdata = ddb;
9047 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9048 queue_depth = ql4xmaxqdepth;
9050 scsi_change_queue_depth(sdev, queue_depth);
9055 * qla4xxx_del_from_active_array - returns an active srb
9056 * @ha: Pointer to host adapter structure.
9057 * @index: index into the active_array
9059 * This routine removes and returns the srb at the specified index
9061 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9064 struct srb *srb = NULL;
9065 struct scsi_cmnd *cmd = NULL;
9067 cmd = scsi_host_find_tag(ha->host, index);
9071 srb = (struct srb *)CMD_SP(cmd);
9075 /* update counters */
9076 if (srb->flags & SRB_DMA_VALID) {
9077 ha->iocb_cnt -= srb->iocb_cnt;
9079 srb->cmd->host_scribble =
9080 (unsigned char *)(unsigned long) MAX_SRBS;
9086 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9087 * @ha: Pointer to host adapter structure.
9088 * @cmd: Scsi Command to wait on.
9090 * This routine waits for the command to be returned by the Firmware
9091 * for some max time.
9093 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9094 struct scsi_cmnd *cmd)
9098 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9101 /* Dont wait on command if PCI error is being handled
9104 if (unlikely(pci_channel_offline(ha->pdev)) ||
9105 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9106 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9107 ha->host_no, __func__);
9112 /* Checking to see if its returned to OS */
9113 rp = (struct srb *) CMD_SP(cmd);
9120 } while (max_wait_time--);
9126 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9127 * @ha: Pointer to host adapter structure
9129 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9131 unsigned long wait_online;
9133 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9134 while (time_before(jiffies, wait_online)) {
9146 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9147 * @ha: pointer to HBA
9151 * This function waits for all outstanding commands to a lun to complete. It
9152 * returns 0 if all pending commands are returned and 1 otherwise.
9154 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9155 struct scsi_target *stgt,
9156 struct scsi_device *sdev)
9160 struct scsi_cmnd *cmd;
9163 * Waiting for all commands for the designated target or dev
9164 * in the active array
9166 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9167 cmd = scsi_host_find_tag(ha->host, cnt);
9168 if (cmd && stgt == scsi_target(cmd->device) &&
9169 (!sdev || sdev == cmd->device)) {
9170 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9180 * qla4xxx_eh_abort - callback for abort task.
9181 * @cmd: Pointer to Linux's SCSI command structure
9183 * This routine is called by the Linux OS to abort the specified
9186 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9188 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9189 unsigned int id = cmd->device->id;
9190 uint64_t lun = cmd->device->lun;
9191 unsigned long flags;
9192 struct srb *srb = NULL;
9197 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9198 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9200 rval = qla4xxx_isp_check_reg(ha);
9201 if (rval != QLA_SUCCESS) {
9202 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9206 spin_lock_irqsave(&ha->hardware_lock, flags);
9207 srb = (struct srb *) CMD_SP(cmd);
9209 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9210 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9211 ha->host_no, id, lun);
9214 kref_get(&srb->srb_ref);
9215 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9217 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9218 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9219 ha->host_no, id, lun));
9222 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9223 ha->host_no, id, lun));
9227 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9229 /* Wait for command to complete */
9231 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9232 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9233 ha->host_no, id, lun));
9238 ql4_printk(KERN_INFO, ha,
9239 "scsi%ld:%d:%llu: Abort command - %s\n",
9240 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9246 * qla4xxx_eh_device_reset - callback for target reset.
9247 * @cmd: Pointer to Linux's SCSI command structure
9249 * This routine is called by the Linux OS to reset all luns on the
9252 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9254 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9255 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9256 int ret = FAILED, stat;
9262 ret = iscsi_block_scsi_eh(cmd);
9267 ql4_printk(KERN_INFO, ha,
9268 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9269 cmd->device->channel, cmd->device->id, cmd->device->lun);
9271 DEBUG2(printk(KERN_INFO
9272 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9273 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9274 cmd, jiffies, cmd->request->timeout / HZ,
9275 ha->dpc_flags, cmd->result, cmd->allowed));
9277 rval = qla4xxx_isp_check_reg(ha);
9278 if (rval != QLA_SUCCESS) {
9279 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9283 /* FIXME: wait for hba to go online */
9284 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9285 if (stat != QLA_SUCCESS) {
9286 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9287 goto eh_dev_reset_done;
9290 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9292 ql4_printk(KERN_INFO, ha,
9293 "DEVICE RESET FAILED - waiting for "
9295 goto eh_dev_reset_done;
9299 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9300 MM_LUN_RESET) != QLA_SUCCESS)
9301 goto eh_dev_reset_done;
9303 ql4_printk(KERN_INFO, ha,
9304 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9305 ha->host_no, cmd->device->channel, cmd->device->id,
9316 * qla4xxx_eh_target_reset - callback for target reset.
9317 * @cmd: Pointer to Linux's SCSI command structure
9319 * This routine is called by the Linux OS to reset the target.
9321 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9323 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9324 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9331 ret = iscsi_block_scsi_eh(cmd);
9335 starget_printk(KERN_INFO, scsi_target(cmd->device),
9336 "WARM TARGET RESET ISSUED.\n");
9338 DEBUG2(printk(KERN_INFO
9339 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9340 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9341 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9342 ha->dpc_flags, cmd->result, cmd->allowed));
9344 rval = qla4xxx_isp_check_reg(ha);
9345 if (rval != QLA_SUCCESS) {
9346 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9350 stat = qla4xxx_reset_target(ha, ddb_entry);
9351 if (stat != QLA_SUCCESS) {
9352 starget_printk(KERN_INFO, scsi_target(cmd->device),
9353 "WARM TARGET RESET FAILED.\n");
9357 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9359 starget_printk(KERN_INFO, scsi_target(cmd->device),
9360 "WARM TARGET DEVICE RESET FAILED - "
9361 "waiting for commands.\n");
9366 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9367 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9368 starget_printk(KERN_INFO, scsi_target(cmd->device),
9369 "WARM TARGET DEVICE RESET FAILED - "
9370 "marker iocb failed.\n");
9374 starget_printk(KERN_INFO, scsi_target(cmd->device),
9375 "WARM TARGET RESET SUCCEEDED.\n");
9380 * qla4xxx_is_eh_active - check if error handler is running
9381 * @shost: Pointer to SCSI Host struct
9383 * This routine finds that if reset host is called in EH
9384 * scenario or from some application like sg_reset
9386 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9388 if (shost->shost_state == SHOST_RECOVERY)
9394 * qla4xxx_eh_host_reset - kernel callback
9395 * @cmd: Pointer to Linux's SCSI command structure
9397 * This routine is invoked by the Linux kernel to perform fatal error
9398 * recovery on the specified adapter.
9400 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9402 int return_status = FAILED;
9403 struct scsi_qla_host *ha;
9406 ha = to_qla_host(cmd->device->host);
9408 rval = qla4xxx_isp_check_reg(ha);
9409 if (rval != QLA_SUCCESS) {
9410 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9414 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9415 qla4_83xx_set_idc_dontreset(ha);
9418 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9419 * protocol drivers, we should not set device_state to NEED_RESET
9421 if (ql4xdontresethba ||
9422 ((is_qla8032(ha) || is_qla8042(ha)) &&
9423 qla4_83xx_idc_dontreset(ha))) {
9424 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9425 ha->host_no, __func__));
9427 /* Clear outstanding srb in queues */
9428 if (qla4xxx_is_eh_active(cmd->device->host))
9429 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9434 ql4_printk(KERN_INFO, ha,
9435 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9436 cmd->device->channel, cmd->device->id, cmd->device->lun);
9438 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9439 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9440 "DEAD.\n", ha->host_no, cmd->device->channel,
9446 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9448 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9450 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9453 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9454 return_status = SUCCESS;
9456 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9457 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9459 return return_status;
9462 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9464 uint32_t mbox_cmd[MBOX_REG_COUNT];
9465 uint32_t mbox_sts[MBOX_REG_COUNT];
9466 struct addr_ctrl_blk_def *acb = NULL;
9467 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9468 int rval = QLA_SUCCESS;
9471 acb = dma_alloc_coherent(&ha->pdev->dev,
9472 sizeof(struct addr_ctrl_blk_def),
9473 &acb_dma, GFP_KERNEL);
9475 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9478 goto exit_port_reset;
9481 memset(acb, 0, acb_len);
9483 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9484 if (rval != QLA_SUCCESS) {
9489 rval = qla4xxx_disable_acb(ha);
9490 if (rval != QLA_SUCCESS) {
9495 wait_for_completion_timeout(&ha->disable_acb_comp,
9496 DISABLE_ACB_TOV * HZ);
9498 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9499 if (rval != QLA_SUCCESS) {
9505 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9508 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9509 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9513 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9515 struct scsi_qla_host *ha = to_qla_host(shost);
9516 int rval = QLA_SUCCESS;
9519 if (ql4xdontresethba) {
9520 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9523 goto exit_host_reset;
9526 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9527 goto recover_adapter;
9529 switch (reset_type) {
9530 case SCSI_ADAPTER_RESET:
9531 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9533 case SCSI_FIRMWARE_RESET:
9534 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9536 /* set firmware context reset */
9537 set_bit(DPC_RESET_HA_FW_CONTEXT,
9540 rval = qla4xxx_context_reset(ha);
9541 goto exit_host_reset;
9548 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9549 * reset is issued by application */
9550 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9551 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9552 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9553 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9554 (idc_ctrl | GRACEFUL_RESET_BIT1));
9557 rval = qla4xxx_recover_adapter(ha);
9558 if (rval != QLA_SUCCESS) {
9559 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9568 /* PCI AER driver recovers from all correctable errors w/o
9569 * driver intervention. For uncorrectable errors PCI AER
9570 * driver calls the following device driver's callbacks
9572 * - Fatal Errors - link_reset
9573 * - Non-Fatal Errors - driver's error_detected() which
9574 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9576 * PCI AER driver calls
9577 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9578 * returns RECOVERED or NEED_RESET if fw_hung
9579 * NEED_RESET - driver's slot_reset()
9580 * DISCONNECT - device is dead & cannot recover
9581 * RECOVERED - driver's resume()
9583 static pci_ers_result_t
9584 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9586 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9588 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9589 ha->host_no, __func__, state);
9591 if (!is_aer_supported(ha))
9592 return PCI_ERS_RESULT_NONE;
9595 case pci_channel_io_normal:
9596 clear_bit(AF_EEH_BUSY, &ha->flags);
9597 return PCI_ERS_RESULT_CAN_RECOVER;
9598 case pci_channel_io_frozen:
9599 set_bit(AF_EEH_BUSY, &ha->flags);
9600 qla4xxx_mailbox_premature_completion(ha);
9601 qla4xxx_free_irqs(ha);
9602 pci_disable_device(pdev);
9603 /* Return back all IOs */
9604 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9605 return PCI_ERS_RESULT_NEED_RESET;
9606 case pci_channel_io_perm_failure:
9607 set_bit(AF_EEH_BUSY, &ha->flags);
9608 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9609 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9610 return PCI_ERS_RESULT_DISCONNECT;
9612 return PCI_ERS_RESULT_NEED_RESET;
9616 * qla4xxx_pci_mmio_enabled() gets called if
9617 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9618 * and read/write to the device still works.
9620 static pci_ers_result_t
9621 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9623 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9625 if (!is_aer_supported(ha))
9626 return PCI_ERS_RESULT_NONE;
9628 return PCI_ERS_RESULT_RECOVERED;
9631 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9633 uint32_t rval = QLA_ERROR;
9635 struct pci_dev *other_pdev = NULL;
9637 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9639 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9641 if (test_bit(AF_ONLINE, &ha->flags)) {
9642 clear_bit(AF_ONLINE, &ha->flags);
9643 clear_bit(AF_LINK_UP, &ha->flags);
9644 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9645 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9648 fn = PCI_FUNC(ha->pdev->devfn);
9649 if (is_qla8022(ha)) {
9652 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9653 ha->host_no, __func__, fn);
9654 /* Get the pci device given the domain, bus,
9655 * slot/function number */
9656 other_pdev = pci_get_domain_bus_and_slot(
9657 pci_domain_nr(ha->pdev->bus),
9658 ha->pdev->bus->number,
9659 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9665 if (atomic_read(&other_pdev->enable_cnt)) {
9666 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9667 ha->host_no, __func__, fn);
9668 pci_dev_put(other_pdev);
9671 pci_dev_put(other_pdev);
9674 /* this case is meant for ISP83xx/ISP84xx only */
9675 if (qla4_83xx_can_perform_reset(ha)) {
9676 /* reset fn as iSCSI is going to perform the reset */
9681 /* The first function on the card, the reset owner will
9682 * start & initialize the firmware. The other functions
9683 * on the card will reset the firmware context
9686 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9687 "0x%x is the owner\n", ha->host_no, __func__,
9690 ha->isp_ops->idc_lock(ha);
9691 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9693 ha->isp_ops->idc_unlock(ha);
9695 rval = qla4_8xxx_update_idc_reg(ha);
9696 if (rval == QLA_ERROR) {
9697 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9698 ha->host_no, __func__);
9699 ha->isp_ops->idc_lock(ha);
9700 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9701 QLA8XXX_DEV_FAILED);
9702 ha->isp_ops->idc_unlock(ha);
9703 goto exit_error_recovery;
9706 clear_bit(AF_FW_RECOVERY, &ha->flags);
9707 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9709 if (rval != QLA_SUCCESS) {
9710 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9711 "FAILED\n", ha->host_no, __func__);
9712 qla4xxx_free_irqs(ha);
9713 ha->isp_ops->idc_lock(ha);
9714 qla4_8xxx_clear_drv_active(ha);
9715 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9716 QLA8XXX_DEV_FAILED);
9717 ha->isp_ops->idc_unlock(ha);
9719 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9720 "READY\n", ha->host_no, __func__);
9721 ha->isp_ops->idc_lock(ha);
9722 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9724 /* Clear driver state register */
9725 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9726 qla4_8xxx_set_drv_active(ha);
9727 ha->isp_ops->idc_unlock(ha);
9728 ha->isp_ops->enable_intrs(ha);
9731 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9732 "the reset owner\n", ha->host_no, __func__,
9734 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9735 QLA8XXX_DEV_READY)) {
9736 clear_bit(AF_FW_RECOVERY, &ha->flags);
9737 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9738 if (rval == QLA_SUCCESS)
9739 ha->isp_ops->enable_intrs(ha);
9741 qla4xxx_free_irqs(ha);
9743 ha->isp_ops->idc_lock(ha);
9744 qla4_8xxx_set_drv_active(ha);
9745 ha->isp_ops->idc_unlock(ha);
9748 exit_error_recovery:
9749 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9753 static pci_ers_result_t
9754 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9756 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9757 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9760 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9761 ha->host_no, __func__);
9763 if (!is_aer_supported(ha))
9764 return PCI_ERS_RESULT_NONE;
9766 /* Restore the saved state of PCIe device -
9767 * BAR registers, PCI Config space, PCIX, MSI,
9770 pci_restore_state(pdev);
9772 /* pci_restore_state() clears the saved_state flag of the device
9773 * save restored state which resets saved_state flag
9775 pci_save_state(pdev);
9777 /* Initialize device or resume if in suspended state */
9778 rc = pci_enable_device(pdev);
9780 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9781 "device after reset\n", ha->host_no, __func__);
9782 goto exit_slot_reset;
9785 ha->isp_ops->disable_intrs(ha);
9787 if (is_qla80XX(ha)) {
9788 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9789 ret = PCI_ERS_RESULT_RECOVERED;
9790 goto exit_slot_reset;
9792 goto exit_slot_reset;
9796 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9797 "device after reset\n", ha->host_no, __func__, ret);
9802 qla4xxx_pci_resume(struct pci_dev *pdev)
9804 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9807 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9808 ha->host_no, __func__);
9810 ret = qla4xxx_wait_for_hba_online(ha);
9811 if (ret != QLA_SUCCESS) {
9812 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9813 "resume I/O from slot/link_reset\n", ha->host_no,
9817 clear_bit(AF_EEH_BUSY, &ha->flags);
9820 static const struct pci_error_handlers qla4xxx_err_handler = {
9821 .error_detected = qla4xxx_pci_error_detected,
9822 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9823 .slot_reset = qla4xxx_pci_slot_reset,
9824 .resume = qla4xxx_pci_resume,
9827 static struct pci_device_id qla4xxx_pci_tbl[] = {
9829 .vendor = PCI_VENDOR_ID_QLOGIC,
9830 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9831 .subvendor = PCI_ANY_ID,
9832 .subdevice = PCI_ANY_ID,
9835 .vendor = PCI_VENDOR_ID_QLOGIC,
9836 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9837 .subvendor = PCI_ANY_ID,
9838 .subdevice = PCI_ANY_ID,
9841 .vendor = PCI_VENDOR_ID_QLOGIC,
9842 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9843 .subvendor = PCI_ANY_ID,
9844 .subdevice = PCI_ANY_ID,
9847 .vendor = PCI_VENDOR_ID_QLOGIC,
9848 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9849 .subvendor = PCI_ANY_ID,
9850 .subdevice = PCI_ANY_ID,
9853 .vendor = PCI_VENDOR_ID_QLOGIC,
9854 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9855 .subvendor = PCI_ANY_ID,
9856 .subdevice = PCI_ANY_ID,
9859 .vendor = PCI_VENDOR_ID_QLOGIC,
9860 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9861 .subvendor = PCI_ANY_ID,
9862 .subdevice = PCI_ANY_ID,
9866 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9868 static struct pci_driver qla4xxx_pci_driver = {
9869 .name = DRIVER_NAME,
9870 .id_table = qla4xxx_pci_tbl,
9871 .probe = qla4xxx_probe_adapter,
9872 .remove = qla4xxx_remove_adapter,
9873 .err_handler = &qla4xxx_err_handler,
9876 static int __init qla4xxx_module_init(void)
9880 if (ql4xqfulltracking)
9881 qla4xxx_driver_template.track_queue_depth = 1;
9883 /* Allocate cache for SRBs. */
9884 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9885 SLAB_HWCACHE_ALIGN, NULL);
9886 if (srb_cachep == NULL) {
9888 "%s: Unable to allocate SRB cache..."
9889 "Failing load!\n", DRIVER_NAME);
9894 /* Derive version string. */
9895 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9896 if (ql4xextended_error_logging)
9897 strcat(qla4xxx_version_str, "-debug");
9899 qla4xxx_scsi_transport =
9900 iscsi_register_transport(&qla4xxx_iscsi_transport);
9901 if (!qla4xxx_scsi_transport){
9903 goto release_srb_cache;
9906 ret = pci_register_driver(&qla4xxx_pci_driver);
9908 goto unregister_transport;
9910 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9913 unregister_transport:
9914 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9916 kmem_cache_destroy(srb_cachep);
9921 static void __exit qla4xxx_module_exit(void)
9923 pci_unregister_driver(&qla4xxx_pci_driver);
9924 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9925 kmem_cache_destroy(srb_cachep);
9928 module_init(qla4xxx_module_init);
9929 module_exit(qla4xxx_module_exit);
9931 MODULE_AUTHOR("QLogic Corporation");
9932 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9933 MODULE_LICENSE("GPL");
9934 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);