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 .use_clustering = ENABLE_CLUSTERING,
209 .sg_tablesize = SG_ALL,
211 .max_sectors = 0xFFFF,
212 .shost_attrs = qla4xxx_host_attrs,
213 .host_reset = qla4xxx_host_reset,
214 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
217 static struct iscsi_transport qla4xxx_iscsi_transport = {
218 .owner = THIS_MODULE,
220 .caps = CAP_TEXT_NEGO |
221 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
222 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
224 .attr_is_visible = qla4_attr_is_visible,
225 .create_session = qla4xxx_session_create,
226 .destroy_session = qla4xxx_session_destroy,
227 .start_conn = qla4xxx_conn_start,
228 .create_conn = qla4xxx_conn_create,
229 .bind_conn = qla4xxx_conn_bind,
230 .stop_conn = iscsi_conn_stop,
231 .destroy_conn = qla4xxx_conn_destroy,
232 .set_param = iscsi_set_param,
233 .get_conn_param = qla4xxx_conn_get_param,
234 .get_session_param = qla4xxx_session_get_param,
235 .get_ep_param = qla4xxx_get_ep_param,
236 .ep_connect = qla4xxx_ep_connect,
237 .ep_poll = qla4xxx_ep_poll,
238 .ep_disconnect = qla4xxx_ep_disconnect,
239 .get_stats = qla4xxx_conn_get_stats,
240 .send_pdu = iscsi_conn_send_pdu,
241 .xmit_task = qla4xxx_task_xmit,
242 .cleanup_task = qla4xxx_task_cleanup,
243 .alloc_pdu = qla4xxx_alloc_pdu,
245 .get_host_param = qla4xxx_host_get_param,
246 .set_iface_param = qla4xxx_iface_set_param,
247 .get_iface_param = qla4xxx_get_iface_param,
248 .bsg_request = qla4xxx_bsg_request,
249 .send_ping = qla4xxx_send_ping,
250 .get_chap = qla4xxx_get_chap_list,
251 .delete_chap = qla4xxx_delete_chap,
252 .set_chap = qla4xxx_set_chap_entry,
253 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
254 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
255 .new_flashnode = qla4xxx_sysfs_ddb_add,
256 .del_flashnode = qla4xxx_sysfs_ddb_delete,
257 .login_flashnode = qla4xxx_sysfs_ddb_login,
258 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
259 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
260 .get_host_stats = qla4xxx_get_host_stats,
263 static struct scsi_transport_template *qla4xxx_scsi_transport;
265 static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
268 int rval = QLA_SUCCESS;
271 reg_val = readl(&ha->qla4_82xx_reg->host_status);
272 else if (is_qla8032(ha) || is_qla8042(ha))
273 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
275 reg_val = readw(&ha->reg->ctrl_status);
277 if (reg_val == QL4_ISP_REG_DISCONNECT)
283 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
284 uint32_t iface_type, uint32_t payload_size,
285 uint32_t pid, struct sockaddr *dst_addr)
287 struct scsi_qla_host *ha = to_qla_host(shost);
288 struct sockaddr_in *addr;
289 struct sockaddr_in6 *addr6;
290 uint32_t options = 0;
291 uint8_t ipaddr[IPv6_ADDR_LEN];
294 memset(ipaddr, 0, IPv6_ADDR_LEN);
296 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
297 (dst_addr->sa_family == AF_INET)) {
298 addr = (struct sockaddr_in *)dst_addr;
299 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
300 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
301 "dest: %pI4\n", __func__,
302 &ha->ip_config.ip_address, ipaddr));
303 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
307 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
308 (dst_addr->sa_family == AF_INET6)) {
310 addr6 = (struct sockaddr_in6 *)dst_addr;
311 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
313 options |= PING_IPV6_PROTOCOL_ENABLE;
315 /* Ping using LinkLocal address */
316 if ((iface_num == 0) || (iface_num == 1)) {
317 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
318 "src: %pI6 dest: %pI6\n", __func__,
319 &ha->ip_config.ipv6_link_local_addr,
321 options |= PING_IPV6_LINKLOCAL_ADDR;
322 rval = qla4xxx_ping_iocb(ha, options, payload_size,
325 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
326 "not supported\n", __func__, iface_num);
332 * If ping using LinkLocal address fails, try ping using
335 if (rval != QLA_SUCCESS) {
336 options &= ~PING_IPV6_LINKLOCAL_ADDR;
337 if (iface_num == 0) {
338 options |= PING_IPV6_ADDR0;
339 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
341 "dest: %pI6\n", __func__,
342 &ha->ip_config.ipv6_addr0,
344 } else if (iface_num == 1) {
345 options |= PING_IPV6_ADDR1;
346 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
348 "dest: %pI6\n", __func__,
349 &ha->ip_config.ipv6_addr1,
352 rval = qla4xxx_ping_iocb(ha, options, payload_size,
363 static umode_t qla4_attr_is_visible(int param_type, int param)
365 switch (param_type) {
366 case ISCSI_HOST_PARAM:
368 case ISCSI_HOST_PARAM_HWADDRESS:
369 case ISCSI_HOST_PARAM_IPADDRESS:
370 case ISCSI_HOST_PARAM_INITIATOR_NAME:
371 case ISCSI_HOST_PARAM_PORT_STATE:
372 case ISCSI_HOST_PARAM_PORT_SPEED:
379 case ISCSI_PARAM_PERSISTENT_ADDRESS:
380 case ISCSI_PARAM_PERSISTENT_PORT:
381 case ISCSI_PARAM_CONN_ADDRESS:
382 case ISCSI_PARAM_CONN_PORT:
383 case ISCSI_PARAM_TARGET_NAME:
384 case ISCSI_PARAM_TPGT:
385 case ISCSI_PARAM_TARGET_ALIAS:
386 case ISCSI_PARAM_MAX_BURST:
387 case ISCSI_PARAM_MAX_R2T:
388 case ISCSI_PARAM_FIRST_BURST:
389 case ISCSI_PARAM_MAX_RECV_DLENGTH:
390 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
391 case ISCSI_PARAM_IFACE_NAME:
392 case ISCSI_PARAM_CHAP_OUT_IDX:
393 case ISCSI_PARAM_CHAP_IN_IDX:
394 case ISCSI_PARAM_USERNAME:
395 case ISCSI_PARAM_PASSWORD:
396 case ISCSI_PARAM_USERNAME_IN:
397 case ISCSI_PARAM_PASSWORD_IN:
398 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
399 case ISCSI_PARAM_DISCOVERY_SESS:
400 case ISCSI_PARAM_PORTAL_TYPE:
401 case ISCSI_PARAM_CHAP_AUTH_EN:
402 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
403 case ISCSI_PARAM_BIDI_CHAP_EN:
404 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
405 case ISCSI_PARAM_DEF_TIME2WAIT:
406 case ISCSI_PARAM_DEF_TIME2RETAIN:
407 case ISCSI_PARAM_HDRDGST_EN:
408 case ISCSI_PARAM_DATADGST_EN:
409 case ISCSI_PARAM_INITIAL_R2T_EN:
410 case ISCSI_PARAM_IMM_DATA_EN:
411 case ISCSI_PARAM_PDU_INORDER_EN:
412 case ISCSI_PARAM_DATASEQ_INORDER_EN:
413 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
414 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
415 case ISCSI_PARAM_TCP_WSF_DISABLE:
416 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
417 case ISCSI_PARAM_TCP_TIMER_SCALE:
418 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
419 case ISCSI_PARAM_TCP_XMIT_WSF:
420 case ISCSI_PARAM_TCP_RECV_WSF:
421 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
422 case ISCSI_PARAM_IPV4_TOS:
423 case ISCSI_PARAM_IPV6_TC:
424 case ISCSI_PARAM_IPV6_FLOW_LABEL:
425 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
426 case ISCSI_PARAM_KEEPALIVE_TMO:
427 case ISCSI_PARAM_LOCAL_PORT:
428 case ISCSI_PARAM_ISID:
429 case ISCSI_PARAM_TSID:
430 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
431 case ISCSI_PARAM_ERL:
432 case ISCSI_PARAM_STATSN:
433 case ISCSI_PARAM_EXP_STATSN:
434 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
435 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
436 case ISCSI_PARAM_LOCAL_IPADDR:
441 case ISCSI_NET_PARAM:
443 case ISCSI_NET_PARAM_IPV4_ADDR:
444 case ISCSI_NET_PARAM_IPV4_SUBNET:
445 case ISCSI_NET_PARAM_IPV4_GW:
446 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
447 case ISCSI_NET_PARAM_IFACE_ENABLE:
448 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
449 case ISCSI_NET_PARAM_IPV6_ADDR:
450 case ISCSI_NET_PARAM_IPV6_ROUTER:
451 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
452 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
453 case ISCSI_NET_PARAM_VLAN_ID:
454 case ISCSI_NET_PARAM_VLAN_PRIORITY:
455 case ISCSI_NET_PARAM_VLAN_ENABLED:
456 case ISCSI_NET_PARAM_MTU:
457 case ISCSI_NET_PARAM_PORT:
458 case ISCSI_NET_PARAM_IPADDR_STATE:
459 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
460 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
461 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
462 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
463 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
464 case ISCSI_NET_PARAM_TCP_WSF:
465 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
466 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
467 case ISCSI_NET_PARAM_CACHE_ID:
468 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
469 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
470 case ISCSI_NET_PARAM_IPV4_TOS_EN:
471 case ISCSI_NET_PARAM_IPV4_TOS:
472 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
473 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
474 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
475 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
476 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
477 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
478 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
479 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
480 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
481 case ISCSI_NET_PARAM_REDIRECT_EN:
482 case ISCSI_NET_PARAM_IPV4_TTL:
483 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
484 case ISCSI_NET_PARAM_IPV6_MLD_EN:
485 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
486 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
487 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
488 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
489 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
490 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
491 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
492 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
497 case ISCSI_IFACE_PARAM:
499 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
500 case ISCSI_IFACE_PARAM_HDRDGST_EN:
501 case ISCSI_IFACE_PARAM_DATADGST_EN:
502 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
503 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
504 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
505 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
506 case ISCSI_IFACE_PARAM_ERL:
507 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
508 case ISCSI_IFACE_PARAM_FIRST_BURST:
509 case ISCSI_IFACE_PARAM_MAX_R2T:
510 case ISCSI_IFACE_PARAM_MAX_BURST:
511 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
512 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
513 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
514 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
515 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
516 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
521 case ISCSI_FLASHNODE_PARAM:
523 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
524 case ISCSI_FLASHNODE_PORTAL_TYPE:
525 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
526 case ISCSI_FLASHNODE_DISCOVERY_SESS:
527 case ISCSI_FLASHNODE_ENTRY_EN:
528 case ISCSI_FLASHNODE_HDR_DGST_EN:
529 case ISCSI_FLASHNODE_DATA_DGST_EN:
530 case ISCSI_FLASHNODE_IMM_DATA_EN:
531 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
532 case ISCSI_FLASHNODE_DATASEQ_INORDER:
533 case ISCSI_FLASHNODE_PDU_INORDER:
534 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
535 case ISCSI_FLASHNODE_SNACK_REQ_EN:
536 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
537 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
538 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
539 case ISCSI_FLASHNODE_ERL:
540 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
541 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
542 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
543 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
544 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
545 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
546 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
547 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
548 case ISCSI_FLASHNODE_FIRST_BURST:
549 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
550 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
551 case ISCSI_FLASHNODE_MAX_R2T:
552 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
553 case ISCSI_FLASHNODE_ISID:
554 case ISCSI_FLASHNODE_TSID:
555 case ISCSI_FLASHNODE_PORT:
556 case ISCSI_FLASHNODE_MAX_BURST:
557 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
558 case ISCSI_FLASHNODE_IPADDR:
559 case ISCSI_FLASHNODE_ALIAS:
560 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
561 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
562 case ISCSI_FLASHNODE_LOCAL_PORT:
563 case ISCSI_FLASHNODE_IPV4_TOS:
564 case ISCSI_FLASHNODE_IPV6_TC:
565 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
566 case ISCSI_FLASHNODE_NAME:
567 case ISCSI_FLASHNODE_TPGT:
568 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
569 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
570 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
571 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
572 case ISCSI_FLASHNODE_TCP_RECV_WSF:
573 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
574 case ISCSI_FLASHNODE_USERNAME:
575 case ISCSI_FLASHNODE_PASSWORD:
576 case ISCSI_FLASHNODE_STATSN:
577 case ISCSI_FLASHNODE_EXP_STATSN:
578 case ISCSI_FLASHNODE_IS_BOOT_TGT:
589 * qla4xxx_create chap_list - Create CHAP list from FLASH
590 * @ha: pointer to adapter structure
592 * Read flash and make a list of CHAP entries, during login when a CHAP entry
593 * is received, it will be checked in this list. If entry exist then the CHAP
594 * entry index is set in the DDB. If CHAP entry does not exist in this list
595 * then a new entry is added in FLASH in CHAP table and the index obtained is
598 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
601 uint8_t *chap_flash_data = NULL;
604 uint32_t chap_size = 0;
607 chap_size = MAX_CHAP_ENTRIES_40XX *
608 sizeof(struct ql4_chap_table);
609 else /* Single region contains CHAP info for both
610 * ports which is divided into half for each port.
612 chap_size = ha->hw.flt_chap_size / 2;
614 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
615 &chap_dma, GFP_KERNEL);
616 if (!chap_flash_data) {
617 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
621 if (is_qla40XX(ha)) {
622 offset = FLASH_CHAP_OFFSET;
624 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
625 if (ha->port_num == 1)
629 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
630 if (rval != QLA_SUCCESS)
633 if (ha->chap_list == NULL)
634 ha->chap_list = vmalloc(chap_size);
635 if (ha->chap_list == NULL) {
636 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
640 memset(ha->chap_list, 0, chap_size);
641 memcpy(ha->chap_list, chap_flash_data, chap_size);
644 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
647 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
649 struct ql4_chap_table **chap_entry)
651 int rval = QLA_ERROR;
652 int max_chap_entries;
654 if (!ha->chap_list) {
655 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
661 max_chap_entries = (ha->hw.flt_chap_size / 2) /
662 sizeof(struct ql4_chap_table);
664 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
666 if (chap_index > max_chap_entries) {
667 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
672 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
673 if ((*chap_entry)->cookie !=
674 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
686 * qla4xxx_find_free_chap_index - Find the first free chap index
687 * @ha: pointer to adapter structure
688 * @chap_index: CHAP index to be returned
690 * Find the first free chap index available in the chap table
692 * Note: Caller should acquire the chap lock before getting here.
694 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
695 uint16_t *chap_index)
699 int max_chap_entries = 0;
700 struct ql4_chap_table *chap_table;
703 max_chap_entries = (ha->hw.flt_chap_size / 2) /
704 sizeof(struct ql4_chap_table);
706 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
708 if (!ha->chap_list) {
709 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
714 for (i = 0; i < max_chap_entries; i++) {
715 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
717 if ((chap_table->cookie !=
718 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
719 (i > MAX_RESRV_CHAP_IDX)) {
725 if (free_index != -1) {
726 *chap_index = free_index;
736 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
737 uint32_t *num_entries, char *buf)
739 struct scsi_qla_host *ha = to_qla_host(shost);
740 struct ql4_chap_table *chap_table;
741 struct iscsi_chap_rec *chap_rec;
742 int max_chap_entries = 0;
743 int valid_chap_entries = 0;
747 max_chap_entries = (ha->hw.flt_chap_size / 2) /
748 sizeof(struct ql4_chap_table);
750 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
752 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
753 __func__, *num_entries, chap_tbl_idx);
757 goto exit_get_chap_list;
760 qla4xxx_create_chap_list(ha);
762 chap_rec = (struct iscsi_chap_rec *) buf;
763 mutex_lock(&ha->chap_sem);
764 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
765 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
766 if (chap_table->cookie !=
767 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
770 chap_rec->chap_tbl_idx = i;
771 strlcpy(chap_rec->username, chap_table->name,
772 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
773 strlcpy(chap_rec->password, chap_table->secret,
774 QL4_CHAP_MAX_SECRET_LEN);
775 chap_rec->password_length = chap_table->secret_len;
777 if (chap_table->flags & BIT_7) /* local */
778 chap_rec->chap_type = CHAP_TYPE_OUT;
780 if (chap_table->flags & BIT_6) /* peer */
781 chap_rec->chap_type = CHAP_TYPE_IN;
785 valid_chap_entries++;
786 if (valid_chap_entries == *num_entries)
791 mutex_unlock(&ha->chap_sem);
794 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
795 __func__, valid_chap_entries);
796 *num_entries = valid_chap_entries;
800 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
803 uint16_t *chap_tbl_idx = (uint16_t *) data;
804 struct iscsi_cls_session *cls_session;
805 struct iscsi_session *sess;
806 struct ddb_entry *ddb_entry;
808 if (!iscsi_is_session_dev(dev))
809 goto exit_is_chap_active;
811 cls_session = iscsi_dev_to_session(dev);
812 sess = cls_session->dd_data;
813 ddb_entry = sess->dd_data;
815 if (iscsi_session_chkready(cls_session))
816 goto exit_is_chap_active;
818 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
825 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
826 uint16_t chap_tbl_idx)
830 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
831 __qla4xxx_is_chap_active);
836 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
838 struct scsi_qla_host *ha = to_qla_host(shost);
839 struct ql4_chap_table *chap_table;
841 int max_chap_entries = 0;
846 chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
847 if (chap_table == NULL)
851 max_chap_entries = (ha->hw.flt_chap_size / 2) /
852 sizeof(struct ql4_chap_table);
854 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
856 if (chap_tbl_idx > max_chap_entries) {
858 goto exit_delete_chap;
861 /* Check if chap index is in use.
862 * If chap is in use don't delet chap entry */
863 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
865 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
866 "delete from flash\n", chap_tbl_idx);
868 goto exit_delete_chap;
871 chap_size = sizeof(struct ql4_chap_table);
873 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
875 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
876 /* flt_chap_size is CHAP table size for both ports
877 * so divide it by 2 to calculate the offset for second port
879 if (ha->port_num == 1)
880 offset += (ha->hw.flt_chap_size / 2);
881 offset += (chap_tbl_idx * chap_size);
884 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
885 if (ret != QLA_SUCCESS) {
887 goto exit_delete_chap;
890 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
891 __le16_to_cpu(chap_table->cookie)));
893 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
894 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
895 goto exit_delete_chap;
898 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
900 offset = FLASH_CHAP_OFFSET |
901 (chap_tbl_idx * sizeof(struct ql4_chap_table));
902 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
903 FLASH_OPT_RMW_COMMIT);
904 if (ret == QLA_SUCCESS && ha->chap_list) {
905 mutex_lock(&ha->chap_sem);
906 /* Update ha chap_list cache */
907 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
908 chap_table, sizeof(struct ql4_chap_table));
909 mutex_unlock(&ha->chap_sem);
911 if (ret != QLA_SUCCESS)
915 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
920 * qla4xxx_set_chap_entry - Make chap entry with given information
921 * @shost: pointer to host
922 * @data: chap info - credentials, index and type to make chap entry
923 * @len: length of data
925 * Add or update chap entry with the given information
927 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
929 struct scsi_qla_host *ha = to_qla_host(shost);
930 struct iscsi_chap_rec chap_rec;
931 struct ql4_chap_table *chap_entry = NULL;
932 struct iscsi_param_info *param_info;
934 int max_chap_entries = 0;
940 memset(&chap_rec, 0, sizeof(chap_rec));
942 nla_for_each_attr(attr, data, len, rem) {
943 if (nla_len(attr) < sizeof(*param_info)) {
948 param_info = nla_data(attr);
950 switch (param_info->param) {
951 case ISCSI_CHAP_PARAM_INDEX:
952 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
954 case ISCSI_CHAP_PARAM_CHAP_TYPE:
955 chap_rec.chap_type = param_info->value[0];
957 case ISCSI_CHAP_PARAM_USERNAME:
958 size = min_t(size_t, sizeof(chap_rec.username),
960 memcpy(chap_rec.username, param_info->value, size);
962 case ISCSI_CHAP_PARAM_PASSWORD:
963 size = min_t(size_t, sizeof(chap_rec.password),
965 memcpy(chap_rec.password, param_info->value, size);
967 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
968 chap_rec.password_length = param_info->value[0];
971 ql4_printk(KERN_ERR, ha,
972 "%s: No such sysfs attribute\n", __func__);
978 if (chap_rec.chap_type == CHAP_TYPE_IN)
984 max_chap_entries = (ha->hw.flt_chap_size / 2) /
985 sizeof(struct ql4_chap_table);
987 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
989 mutex_lock(&ha->chap_sem);
990 if (chap_rec.chap_tbl_idx < max_chap_entries) {
991 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
994 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
995 ql4_printk(KERN_INFO, ha,
996 "Type mismatch for CHAP entry %d\n",
997 chap_rec.chap_tbl_idx);
999 goto exit_unlock_chap;
1002 /* If chap index is in use then don't modify it */
1003 rc = qla4xxx_is_chap_active(shost,
1004 chap_rec.chap_tbl_idx);
1006 ql4_printk(KERN_INFO, ha,
1007 "CHAP entry %d is in use\n",
1008 chap_rec.chap_tbl_idx);
1010 goto exit_unlock_chap;
1014 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1016 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1018 goto exit_unlock_chap;
1022 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1023 chap_rec.chap_tbl_idx, type);
1026 mutex_unlock(&ha->chap_sem);
1033 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1035 struct scsi_qla_host *ha = to_qla_host(shost);
1036 struct iscsi_offload_host_stats *host_stats = NULL;
1037 int host_stats_size;
1040 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1042 dma_addr_t iscsi_stats_dma;
1044 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1046 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1048 if (host_stats_size != len) {
1049 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1050 __func__, len, host_stats_size);
1052 goto exit_host_stats;
1054 host_stats = (struct iscsi_offload_host_stats *)buf;
1058 goto exit_host_stats;
1061 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1063 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1064 &iscsi_stats_dma, GFP_KERNEL);
1065 if (!ql_iscsi_stats) {
1066 ql4_printk(KERN_ERR, ha,
1067 "Unable to allocate memory for iscsi stats\n");
1069 goto exit_host_stats;
1072 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1074 if (ret != QLA_SUCCESS) {
1075 ql4_printk(KERN_ERR, ha,
1076 "Unable to retrieve iscsi stats\n");
1078 goto exit_host_stats;
1080 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1081 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1082 host_stats->mactx_multicast_frames =
1083 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1084 host_stats->mactx_broadcast_frames =
1085 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1086 host_stats->mactx_pause_frames =
1087 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1088 host_stats->mactx_control_frames =
1089 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1090 host_stats->mactx_deferral =
1091 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1092 host_stats->mactx_excess_deferral =
1093 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1094 host_stats->mactx_late_collision =
1095 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1096 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1097 host_stats->mactx_single_collision =
1098 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1099 host_stats->mactx_multiple_collision =
1100 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1101 host_stats->mactx_collision =
1102 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1103 host_stats->mactx_frames_dropped =
1104 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1105 host_stats->mactx_jumbo_frames =
1106 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1107 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1108 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1109 host_stats->macrx_unknown_control_frames =
1110 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1111 host_stats->macrx_pause_frames =
1112 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1113 host_stats->macrx_control_frames =
1114 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1115 host_stats->macrx_dribble =
1116 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1117 host_stats->macrx_frame_length_error =
1118 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1119 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1120 host_stats->macrx_carrier_sense_error =
1121 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1122 host_stats->macrx_frame_discarded =
1123 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1124 host_stats->macrx_frames_dropped =
1125 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1126 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1127 host_stats->mac_encoding_error =
1128 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1129 host_stats->macrx_length_error_large =
1130 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1131 host_stats->macrx_length_error_small =
1132 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1133 host_stats->macrx_multicast_frames =
1134 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1135 host_stats->macrx_broadcast_frames =
1136 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1137 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1138 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1139 host_stats->iptx_fragments =
1140 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1141 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1142 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1143 host_stats->iprx_fragments =
1144 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1145 host_stats->ip_datagram_reassembly =
1146 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1147 host_stats->ip_invalid_address_error =
1148 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1149 host_stats->ip_error_packets =
1150 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1151 host_stats->ip_fragrx_overlap =
1152 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1153 host_stats->ip_fragrx_outoforder =
1154 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1155 host_stats->ip_datagram_reassembly_timeout =
1156 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1157 host_stats->ipv6tx_packets =
1158 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1159 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1160 host_stats->ipv6tx_fragments =
1161 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1162 host_stats->ipv6rx_packets =
1163 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1164 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1165 host_stats->ipv6rx_fragments =
1166 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1167 host_stats->ipv6_datagram_reassembly =
1168 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1169 host_stats->ipv6_invalid_address_error =
1170 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1171 host_stats->ipv6_error_packets =
1172 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1173 host_stats->ipv6_fragrx_overlap =
1174 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1175 host_stats->ipv6_fragrx_outoforder =
1176 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1177 host_stats->ipv6_datagram_reassembly_timeout =
1178 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1179 host_stats->tcptx_segments =
1180 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1181 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1182 host_stats->tcprx_segments =
1183 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1184 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1185 host_stats->tcp_duplicate_ack_retx =
1186 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1187 host_stats->tcp_retx_timer_expired =
1188 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1189 host_stats->tcprx_duplicate_ack =
1190 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1191 host_stats->tcprx_pure_ackr =
1192 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1193 host_stats->tcptx_delayed_ack =
1194 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1195 host_stats->tcptx_pure_ack =
1196 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1197 host_stats->tcprx_segment_error =
1198 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1199 host_stats->tcprx_segment_outoforder =
1200 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1201 host_stats->tcprx_window_probe =
1202 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1203 host_stats->tcprx_window_update =
1204 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1205 host_stats->tcptx_window_probe_persist =
1206 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1207 host_stats->ecc_error_correction =
1208 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1209 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1210 host_stats->iscsi_data_bytes_tx =
1211 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1212 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1213 host_stats->iscsi_data_bytes_rx =
1214 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1215 host_stats->iscsi_io_completed =
1216 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1217 host_stats->iscsi_unexpected_io_rx =
1218 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1219 host_stats->iscsi_format_error =
1220 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1221 host_stats->iscsi_hdr_digest_error =
1222 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1223 host_stats->iscsi_data_digest_error =
1224 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1225 host_stats->iscsi_sequence_error =
1226 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1229 dma_free_coherent(&ha->pdev->dev, stats_size,
1230 ql_iscsi_stats, iscsi_stats_dma);
1232 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1237 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1238 enum iscsi_param_type param_type,
1239 int param, char *buf)
1241 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1242 struct scsi_qla_host *ha = to_qla_host(shost);
1247 if (param_type == ISCSI_NET_PARAM) {
1249 case ISCSI_NET_PARAM_IPV4_ADDR:
1250 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1252 case ISCSI_NET_PARAM_IPV4_SUBNET:
1253 len = sprintf(buf, "%pI4\n",
1254 &ha->ip_config.subnet_mask);
1256 case ISCSI_NET_PARAM_IPV4_GW:
1257 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1259 case ISCSI_NET_PARAM_IFACE_ENABLE:
1260 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1261 OP_STATE(ha->ip_config.ipv4_options,
1262 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1264 OP_STATE(ha->ip_config.ipv6_options,
1265 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1268 len = sprintf(buf, "%s\n", pval);
1270 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1271 len = sprintf(buf, "%s\n",
1272 (ha->ip_config.tcp_options &
1273 TCPOPT_DHCP_ENABLE) ?
1276 case ISCSI_NET_PARAM_IPV6_ADDR:
1277 if (iface->iface_num == 0)
1278 len = sprintf(buf, "%pI6\n",
1279 &ha->ip_config.ipv6_addr0);
1280 if (iface->iface_num == 1)
1281 len = sprintf(buf, "%pI6\n",
1282 &ha->ip_config.ipv6_addr1);
1284 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1285 len = sprintf(buf, "%pI6\n",
1286 &ha->ip_config.ipv6_link_local_addr);
1288 case ISCSI_NET_PARAM_IPV6_ROUTER:
1289 len = sprintf(buf, "%pI6\n",
1290 &ha->ip_config.ipv6_default_router_addr);
1292 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1293 pval = (ha->ip_config.ipv6_addl_options &
1294 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1297 len = sprintf(buf, "%s\n", pval);
1299 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1300 pval = (ha->ip_config.ipv6_addl_options &
1301 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1304 len = sprintf(buf, "%s\n", pval);
1306 case ISCSI_NET_PARAM_VLAN_ID:
1307 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1308 ival = ha->ip_config.ipv4_vlan_tag &
1311 ival = ha->ip_config.ipv6_vlan_tag &
1314 len = sprintf(buf, "%d\n", ival);
1316 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1317 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1318 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1319 ISCSI_MAX_VLAN_PRIORITY;
1321 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1322 ISCSI_MAX_VLAN_PRIORITY;
1324 len = sprintf(buf, "%d\n", ival);
1326 case ISCSI_NET_PARAM_VLAN_ENABLED:
1327 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1328 OP_STATE(ha->ip_config.ipv4_options,
1329 IPOPT_VLAN_TAGGING_ENABLE, pval);
1331 OP_STATE(ha->ip_config.ipv6_options,
1332 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1334 len = sprintf(buf, "%s\n", pval);
1336 case ISCSI_NET_PARAM_MTU:
1337 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1339 case ISCSI_NET_PARAM_PORT:
1340 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1341 len = sprintf(buf, "%d\n",
1342 ha->ip_config.ipv4_port);
1344 len = sprintf(buf, "%d\n",
1345 ha->ip_config.ipv6_port);
1347 case ISCSI_NET_PARAM_IPADDR_STATE:
1348 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1349 pval = iscsi_get_ipaddress_state_name(
1350 ha->ip_config.ipv4_addr_state);
1352 if (iface->iface_num == 0)
1353 pval = iscsi_get_ipaddress_state_name(
1354 ha->ip_config.ipv6_addr0_state);
1355 else if (iface->iface_num == 1)
1356 pval = iscsi_get_ipaddress_state_name(
1357 ha->ip_config.ipv6_addr1_state);
1360 len = sprintf(buf, "%s\n", pval);
1362 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1363 pval = iscsi_get_ipaddress_state_name(
1364 ha->ip_config.ipv6_link_local_state);
1365 len = sprintf(buf, "%s\n", pval);
1367 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1368 pval = iscsi_get_router_state_name(
1369 ha->ip_config.ipv6_default_router_state);
1370 len = sprintf(buf, "%s\n", pval);
1372 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1373 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1374 OP_STATE(~ha->ip_config.tcp_options,
1375 TCPOPT_DELAYED_ACK_DISABLE, pval);
1377 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1378 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1380 len = sprintf(buf, "%s\n", pval);
1382 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1383 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1384 OP_STATE(~ha->ip_config.tcp_options,
1385 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1387 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1388 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1390 len = sprintf(buf, "%s\n", pval);
1392 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1393 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1394 OP_STATE(~ha->ip_config.tcp_options,
1395 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1397 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1398 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1401 len = sprintf(buf, "%s\n", pval);
1403 case ISCSI_NET_PARAM_TCP_WSF:
1404 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1405 len = sprintf(buf, "%d\n",
1406 ha->ip_config.tcp_wsf);
1408 len = sprintf(buf, "%d\n",
1409 ha->ip_config.ipv6_tcp_wsf);
1411 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1412 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1413 ival = (ha->ip_config.tcp_options &
1414 TCPOPT_TIMER_SCALE) >> 1;
1416 ival = (ha->ip_config.ipv6_tcp_options &
1417 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1419 len = sprintf(buf, "%d\n", ival);
1421 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1422 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1423 OP_STATE(ha->ip_config.tcp_options,
1424 TCPOPT_TIMESTAMP_ENABLE, pval);
1426 OP_STATE(ha->ip_config.ipv6_tcp_options,
1427 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1429 len = sprintf(buf, "%s\n", pval);
1431 case ISCSI_NET_PARAM_CACHE_ID:
1432 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1433 len = sprintf(buf, "%d\n",
1434 ha->ip_config.ipv4_cache_id);
1436 len = sprintf(buf, "%d\n",
1437 ha->ip_config.ipv6_cache_id);
1439 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1440 OP_STATE(ha->ip_config.tcp_options,
1441 TCPOPT_DNS_SERVER_IP_EN, pval);
1443 len = sprintf(buf, "%s\n", pval);
1445 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1446 OP_STATE(ha->ip_config.tcp_options,
1447 TCPOPT_SLP_DA_INFO_EN, pval);
1449 len = sprintf(buf, "%s\n", pval);
1451 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1452 OP_STATE(ha->ip_config.ipv4_options,
1453 IPOPT_IPV4_TOS_EN, pval);
1455 len = sprintf(buf, "%s\n", pval);
1457 case ISCSI_NET_PARAM_IPV4_TOS:
1458 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1460 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1461 OP_STATE(ha->ip_config.ipv4_options,
1462 IPOPT_GRAT_ARP_EN, pval);
1464 len = sprintf(buf, "%s\n", pval);
1466 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1467 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1470 len = sprintf(buf, "%s\n", pval);
1472 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1473 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1474 (char *)ha->ip_config.ipv4_alt_cid : "";
1476 len = sprintf(buf, "%s\n", pval);
1478 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1479 OP_STATE(ha->ip_config.ipv4_options,
1480 IPOPT_REQ_VID_EN, pval);
1482 len = sprintf(buf, "%s\n", pval);
1484 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1485 OP_STATE(ha->ip_config.ipv4_options,
1486 IPOPT_USE_VID_EN, pval);
1488 len = sprintf(buf, "%s\n", pval);
1490 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1491 pval = (ha->ip_config.ipv4_vid_len) ?
1492 (char *)ha->ip_config.ipv4_vid : "";
1494 len = sprintf(buf, "%s\n", pval);
1496 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1497 OP_STATE(ha->ip_config.ipv4_options,
1498 IPOPT_LEARN_IQN_EN, pval);
1500 len = sprintf(buf, "%s\n", pval);
1502 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1503 OP_STATE(~ha->ip_config.ipv4_options,
1504 IPOPT_FRAGMENTATION_DISABLE, pval);
1506 len = sprintf(buf, "%s\n", pval);
1508 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1509 OP_STATE(ha->ip_config.ipv4_options,
1510 IPOPT_IN_FORWARD_EN, pval);
1512 len = sprintf(buf, "%s\n", pval);
1514 case ISCSI_NET_PARAM_REDIRECT_EN:
1515 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1516 OP_STATE(ha->ip_config.ipv4_options,
1517 IPOPT_ARP_REDIRECT_EN, pval);
1519 OP_STATE(ha->ip_config.ipv6_options,
1520 IPV6_OPT_REDIRECT_EN, pval);
1522 len = sprintf(buf, "%s\n", pval);
1524 case ISCSI_NET_PARAM_IPV4_TTL:
1525 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1527 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1528 OP_STATE(ha->ip_config.ipv6_options,
1529 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1531 len = sprintf(buf, "%s\n", pval);
1533 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1534 OP_STATE(ha->ip_config.ipv6_addl_options,
1535 IPV6_ADDOPT_MLD_EN, pval);
1537 len = sprintf(buf, "%s\n", pval);
1539 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1540 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1542 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1543 len = sprintf(buf, "%d\n",
1544 ha->ip_config.ipv6_traffic_class);
1546 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1547 len = sprintf(buf, "%d\n",
1548 ha->ip_config.ipv6_hop_limit);
1550 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1551 len = sprintf(buf, "%d\n",
1552 ha->ip_config.ipv6_nd_reach_time);
1554 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1555 len = sprintf(buf, "%d\n",
1556 ha->ip_config.ipv6_nd_rexmit_timer);
1558 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1559 len = sprintf(buf, "%d\n",
1560 ha->ip_config.ipv6_nd_stale_timeout);
1562 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1563 len = sprintf(buf, "%d\n",
1564 ha->ip_config.ipv6_dup_addr_detect_count);
1566 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1567 len = sprintf(buf, "%d\n",
1568 ha->ip_config.ipv6_gw_advrt_mtu);
1573 } else if (param_type == ISCSI_IFACE_PARAM) {
1575 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1576 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1578 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1579 OP_STATE(ha->ip_config.iscsi_options,
1580 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1582 len = sprintf(buf, "%s\n", pval);
1584 case ISCSI_IFACE_PARAM_DATADGST_EN:
1585 OP_STATE(ha->ip_config.iscsi_options,
1586 ISCSIOPTS_DATA_DIGEST_EN, pval);
1588 len = sprintf(buf, "%s\n", pval);
1590 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1591 OP_STATE(ha->ip_config.iscsi_options,
1592 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1594 len = sprintf(buf, "%s\n", pval);
1596 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1597 OP_STATE(ha->ip_config.iscsi_options,
1598 ISCSIOPTS_INITIAL_R2T_EN, pval);
1600 len = sprintf(buf, "%s\n", pval);
1602 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1603 OP_STATE(ha->ip_config.iscsi_options,
1604 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1606 len = sprintf(buf, "%s\n", pval);
1608 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1609 OP_STATE(ha->ip_config.iscsi_options,
1610 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1612 len = sprintf(buf, "%s\n", pval);
1614 case ISCSI_IFACE_PARAM_ERL:
1615 len = sprintf(buf, "%d\n",
1616 (ha->ip_config.iscsi_options &
1619 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1620 len = sprintf(buf, "%u\n",
1621 ha->ip_config.iscsi_max_pdu_size *
1624 case ISCSI_IFACE_PARAM_FIRST_BURST:
1625 len = sprintf(buf, "%u\n",
1626 ha->ip_config.iscsi_first_burst_len *
1629 case ISCSI_IFACE_PARAM_MAX_R2T:
1630 len = sprintf(buf, "%d\n",
1631 ha->ip_config.iscsi_max_outstnd_r2t);
1633 case ISCSI_IFACE_PARAM_MAX_BURST:
1634 len = sprintf(buf, "%u\n",
1635 ha->ip_config.iscsi_max_burst_len *
1638 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1639 OP_STATE(ha->ip_config.iscsi_options,
1640 ISCSIOPTS_CHAP_AUTH_EN, pval);
1642 len = sprintf(buf, "%s\n", pval);
1644 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1645 OP_STATE(ha->ip_config.iscsi_options,
1646 ISCSIOPTS_BIDI_CHAP_EN, pval);
1648 len = sprintf(buf, "%s\n", pval);
1650 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1651 OP_STATE(ha->ip_config.iscsi_options,
1652 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1654 len = sprintf(buf, "%s\n", pval);
1656 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1657 OP_STATE(ha->ip_config.iscsi_options,
1658 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1660 len = sprintf(buf, "%s\n", pval);
1662 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1663 OP_STATE(ha->ip_config.iscsi_options,
1664 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1666 len = sprintf(buf, "%s\n", pval);
1668 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1669 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1679 static struct iscsi_endpoint *
1680 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1684 struct iscsi_endpoint *ep;
1685 struct qla_endpoint *qla_ep;
1686 struct scsi_qla_host *ha;
1687 struct sockaddr_in *addr;
1688 struct sockaddr_in6 *addr6;
1692 pr_err("%s: shost is NULL\n", __func__);
1693 return ERR_PTR(ret);
1696 ha = iscsi_host_priv(shost);
1697 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1700 return ERR_PTR(ret);
1703 qla_ep = ep->dd_data;
1704 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1705 if (dst_addr->sa_family == AF_INET) {
1706 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1707 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1708 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1709 (char *)&addr->sin_addr));
1710 } else if (dst_addr->sa_family == AF_INET6) {
1711 memcpy(&qla_ep->dst_addr, dst_addr,
1712 sizeof(struct sockaddr_in6));
1713 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1714 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1715 (char *)&addr6->sin6_addr));
1717 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1721 qla_ep->host = shost;
1726 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1728 struct qla_endpoint *qla_ep;
1729 struct scsi_qla_host *ha;
1732 qla_ep = ep->dd_data;
1733 ha = to_qla_host(qla_ep->host);
1734 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1736 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1742 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1744 struct qla_endpoint *qla_ep;
1745 struct scsi_qla_host *ha;
1747 qla_ep = ep->dd_data;
1748 ha = to_qla_host(qla_ep->host);
1749 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1751 iscsi_destroy_endpoint(ep);
1754 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1755 enum iscsi_param param,
1758 struct qla_endpoint *qla_ep = ep->dd_data;
1759 struct sockaddr *dst_addr;
1760 struct scsi_qla_host *ha;
1765 ha = to_qla_host(qla_ep->host);
1766 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1770 case ISCSI_PARAM_CONN_PORT:
1771 case ISCSI_PARAM_CONN_ADDRESS:
1772 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1776 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1777 &qla_ep->dst_addr, param, buf);
1783 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1784 struct iscsi_stats *stats)
1786 struct iscsi_session *sess;
1787 struct iscsi_cls_session *cls_sess;
1788 struct ddb_entry *ddb_entry;
1789 struct scsi_qla_host *ha;
1790 struct ql_iscsi_stats *ql_iscsi_stats;
1793 dma_addr_t iscsi_stats_dma;
1795 cls_sess = iscsi_conn_to_session(cls_conn);
1796 sess = cls_sess->dd_data;
1797 ddb_entry = sess->dd_data;
1800 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1802 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1803 /* Allocate memory */
1804 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1805 &iscsi_stats_dma, GFP_KERNEL);
1806 if (!ql_iscsi_stats) {
1807 ql4_printk(KERN_ERR, ha,
1808 "Unable to allocate memory for iscsi stats\n");
1809 goto exit_get_stats;
1812 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1814 if (ret != QLA_SUCCESS) {
1815 ql4_printk(KERN_ERR, ha,
1816 "Unable to retrieve iscsi stats\n");
1821 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1822 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1824 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1825 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1826 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1827 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1828 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1829 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1830 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1831 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1833 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1834 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1835 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1836 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1837 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1838 stats->logoutrsp_pdus =
1839 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1840 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1841 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1842 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1845 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1851 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1853 struct iscsi_cls_session *session;
1854 struct iscsi_session *sess;
1855 unsigned long flags;
1856 enum blk_eh_timer_return ret = BLK_EH_DONE;
1858 session = starget_to_session(scsi_target(sc->device));
1859 sess = session->dd_data;
1861 spin_lock_irqsave(&session->lock, flags);
1862 if (session->state == ISCSI_SESSION_FAILED)
1863 ret = BLK_EH_RESET_TIMER;
1864 spin_unlock_irqrestore(&session->lock, flags);
1869 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1871 struct scsi_qla_host *ha = to_qla_host(shost);
1872 struct iscsi_cls_host *ihost = shost->shost_data;
1873 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1875 qla4xxx_get_firmware_state(ha);
1877 switch (ha->addl_fw_state & 0x0F00) {
1878 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1879 speed = ISCSI_PORT_SPEED_10MBPS;
1881 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1882 speed = ISCSI_PORT_SPEED_100MBPS;
1884 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1885 speed = ISCSI_PORT_SPEED_1GBPS;
1887 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1888 speed = ISCSI_PORT_SPEED_10GBPS;
1891 ihost->port_speed = speed;
1894 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1896 struct scsi_qla_host *ha = to_qla_host(shost);
1897 struct iscsi_cls_host *ihost = shost->shost_data;
1898 uint32_t state = ISCSI_PORT_STATE_DOWN;
1900 if (test_bit(AF_LINK_UP, &ha->flags))
1901 state = ISCSI_PORT_STATE_UP;
1903 ihost->port_state = state;
1906 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1907 enum iscsi_host_param param, char *buf)
1909 struct scsi_qla_host *ha = to_qla_host(shost);
1913 case ISCSI_HOST_PARAM_HWADDRESS:
1914 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1916 case ISCSI_HOST_PARAM_IPADDRESS:
1917 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1919 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1920 len = sprintf(buf, "%s\n", ha->name_string);
1922 case ISCSI_HOST_PARAM_PORT_STATE:
1923 qla4xxx_set_port_state(shost);
1924 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1926 case ISCSI_HOST_PARAM_PORT_SPEED:
1927 qla4xxx_set_port_speed(shost);
1928 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1937 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1943 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1944 &qla4xxx_iscsi_transport,
1945 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1946 if (!ha->iface_ipv4)
1947 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1951 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1953 if (!ha->iface_ipv6_0)
1955 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1956 &qla4xxx_iscsi_transport,
1957 ISCSI_IFACE_TYPE_IPV6, 0,
1959 if (!ha->iface_ipv6_0)
1960 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1963 if (!ha->iface_ipv6_1)
1965 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1966 &qla4xxx_iscsi_transport,
1967 ISCSI_IFACE_TYPE_IPV6, 1,
1969 if (!ha->iface_ipv6_1)
1970 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1974 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1976 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1977 qla4xxx_create_ipv4_iface(ha);
1979 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1980 qla4xxx_create_ipv6_iface(ha);
1983 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1985 if (ha->iface_ipv4) {
1986 iscsi_destroy_iface(ha->iface_ipv4);
1987 ha->iface_ipv4 = NULL;
1991 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1993 if (ha->iface_ipv6_0) {
1994 iscsi_destroy_iface(ha->iface_ipv6_0);
1995 ha->iface_ipv6_0 = NULL;
1997 if (ha->iface_ipv6_1) {
1998 iscsi_destroy_iface(ha->iface_ipv6_1);
1999 ha->iface_ipv6_1 = NULL;
2003 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
2005 qla4xxx_destroy_ipv4_iface(ha);
2006 qla4xxx_destroy_ipv6_iface(ha);
2009 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2010 struct iscsi_iface_param_info *iface_param,
2011 struct addr_ctrl_blk *init_fw_cb)
2014 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2015 * iface_num 1 is valid only for IPv6 Addr.
2017 switch (iface_param->param) {
2018 case ISCSI_NET_PARAM_IPV6_ADDR:
2019 if (iface_param->iface_num & 0x1)
2021 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2022 sizeof(init_fw_cb->ipv6_addr1));
2025 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2026 sizeof(init_fw_cb->ipv6_addr0));
2028 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2029 if (iface_param->iface_num & 0x1)
2031 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2032 sizeof(init_fw_cb->ipv6_if_id));
2034 case ISCSI_NET_PARAM_IPV6_ROUTER:
2035 if (iface_param->iface_num & 0x1)
2037 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2038 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2040 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2041 /* Autocfg applies to even interface */
2042 if (iface_param->iface_num & 0x1)
2045 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2046 init_fw_cb->ipv6_addtl_opts &=
2048 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2049 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2050 init_fw_cb->ipv6_addtl_opts |=
2052 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2054 ql4_printk(KERN_ERR, ha,
2055 "Invalid autocfg setting for IPv6 addr\n");
2057 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2058 /* Autocfg applies to even interface */
2059 if (iface_param->iface_num & 0x1)
2062 if (iface_param->value[0] ==
2063 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2064 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2065 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2066 else if (iface_param->value[0] ==
2067 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2068 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2069 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2071 ql4_printk(KERN_ERR, ha,
2072 "Invalid autocfg setting for IPv6 linklocal addr\n");
2074 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2075 /* Autocfg applies to even interface */
2076 if (iface_param->iface_num & 0x1)
2079 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2080 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2081 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2083 case ISCSI_NET_PARAM_IFACE_ENABLE:
2084 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2085 init_fw_cb->ipv6_opts |=
2086 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2087 qla4xxx_create_ipv6_iface(ha);
2089 init_fw_cb->ipv6_opts &=
2090 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2092 qla4xxx_destroy_ipv6_iface(ha);
2095 case ISCSI_NET_PARAM_VLAN_TAG:
2096 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2098 init_fw_cb->ipv6_vlan_tag =
2099 cpu_to_be16(*(uint16_t *)iface_param->value);
2101 case ISCSI_NET_PARAM_VLAN_ENABLED:
2102 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2103 init_fw_cb->ipv6_opts |=
2104 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2106 init_fw_cb->ipv6_opts &=
2107 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2109 case ISCSI_NET_PARAM_MTU:
2110 init_fw_cb->eth_mtu_size =
2111 cpu_to_le16(*(uint16_t *)iface_param->value);
2113 case ISCSI_NET_PARAM_PORT:
2114 /* Autocfg applies to even interface */
2115 if (iface_param->iface_num & 0x1)
2118 init_fw_cb->ipv6_port =
2119 cpu_to_le16(*(uint16_t *)iface_param->value);
2121 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2122 if (iface_param->iface_num & 0x1)
2124 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2125 init_fw_cb->ipv6_tcp_opts |=
2126 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2128 init_fw_cb->ipv6_tcp_opts &=
2129 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2132 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2133 if (iface_param->iface_num & 0x1)
2135 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2136 init_fw_cb->ipv6_tcp_opts |=
2137 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2139 init_fw_cb->ipv6_tcp_opts &=
2140 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2142 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2143 if (iface_param->iface_num & 0x1)
2145 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2146 init_fw_cb->ipv6_tcp_opts |=
2147 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2149 init_fw_cb->ipv6_tcp_opts &=
2150 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2152 case ISCSI_NET_PARAM_TCP_WSF:
2153 if (iface_param->iface_num & 0x1)
2155 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2157 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2158 if (iface_param->iface_num & 0x1)
2160 init_fw_cb->ipv6_tcp_opts &=
2161 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2162 init_fw_cb->ipv6_tcp_opts |=
2163 cpu_to_le16((iface_param->value[0] << 1) &
2164 IPV6_TCPOPT_TIMER_SCALE);
2166 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2167 if (iface_param->iface_num & 0x1)
2169 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2170 init_fw_cb->ipv6_tcp_opts |=
2171 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2173 init_fw_cb->ipv6_tcp_opts &=
2174 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2176 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2177 if (iface_param->iface_num & 0x1)
2179 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2180 init_fw_cb->ipv6_opts |=
2181 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2183 init_fw_cb->ipv6_opts &=
2184 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2186 case ISCSI_NET_PARAM_REDIRECT_EN:
2187 if (iface_param->iface_num & 0x1)
2189 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2190 init_fw_cb->ipv6_opts |=
2191 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2193 init_fw_cb->ipv6_opts &=
2194 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2196 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2197 if (iface_param->iface_num & 0x1)
2199 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2200 init_fw_cb->ipv6_addtl_opts |=
2201 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2203 init_fw_cb->ipv6_addtl_opts &=
2204 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2206 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2207 if (iface_param->iface_num & 0x1)
2209 init_fw_cb->ipv6_flow_lbl =
2210 cpu_to_le16(*(uint16_t *)iface_param->value);
2212 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2213 if (iface_param->iface_num & 0x1)
2215 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2217 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2218 if (iface_param->iface_num & 0x1)
2220 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2222 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2223 if (iface_param->iface_num & 0x1)
2225 init_fw_cb->ipv6_nd_reach_time =
2226 cpu_to_le32(*(uint32_t *)iface_param->value);
2228 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2229 if (iface_param->iface_num & 0x1)
2231 init_fw_cb->ipv6_nd_rexmit_timer =
2232 cpu_to_le32(*(uint32_t *)iface_param->value);
2234 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2235 if (iface_param->iface_num & 0x1)
2237 init_fw_cb->ipv6_nd_stale_timeout =
2238 cpu_to_le32(*(uint32_t *)iface_param->value);
2240 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2241 if (iface_param->iface_num & 0x1)
2243 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2245 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2246 if (iface_param->iface_num & 0x1)
2248 init_fw_cb->ipv6_gw_advrt_mtu =
2249 cpu_to_le32(*(uint32_t *)iface_param->value);
2252 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2253 iface_param->param);
2258 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2259 struct iscsi_iface_param_info *iface_param,
2260 struct addr_ctrl_blk *init_fw_cb)
2262 switch (iface_param->param) {
2263 case ISCSI_NET_PARAM_IPV4_ADDR:
2264 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2265 sizeof(init_fw_cb->ipv4_addr));
2267 case ISCSI_NET_PARAM_IPV4_SUBNET:
2268 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2269 sizeof(init_fw_cb->ipv4_subnet));
2271 case ISCSI_NET_PARAM_IPV4_GW:
2272 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2273 sizeof(init_fw_cb->ipv4_gw_addr));
2275 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2276 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2277 init_fw_cb->ipv4_tcp_opts |=
2278 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2279 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2280 init_fw_cb->ipv4_tcp_opts &=
2281 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2283 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2285 case ISCSI_NET_PARAM_IFACE_ENABLE:
2286 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2287 init_fw_cb->ipv4_ip_opts |=
2288 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2289 qla4xxx_create_ipv4_iface(ha);
2291 init_fw_cb->ipv4_ip_opts &=
2292 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2294 qla4xxx_destroy_ipv4_iface(ha);
2297 case ISCSI_NET_PARAM_VLAN_TAG:
2298 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2300 init_fw_cb->ipv4_vlan_tag =
2301 cpu_to_be16(*(uint16_t *)iface_param->value);
2303 case ISCSI_NET_PARAM_VLAN_ENABLED:
2304 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2305 init_fw_cb->ipv4_ip_opts |=
2306 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2308 init_fw_cb->ipv4_ip_opts &=
2309 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2311 case ISCSI_NET_PARAM_MTU:
2312 init_fw_cb->eth_mtu_size =
2313 cpu_to_le16(*(uint16_t *)iface_param->value);
2315 case ISCSI_NET_PARAM_PORT:
2316 init_fw_cb->ipv4_port =
2317 cpu_to_le16(*(uint16_t *)iface_param->value);
2319 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2320 if (iface_param->iface_num & 0x1)
2322 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2323 init_fw_cb->ipv4_tcp_opts |=
2324 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2326 init_fw_cb->ipv4_tcp_opts &=
2327 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2330 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2331 if (iface_param->iface_num & 0x1)
2333 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2334 init_fw_cb->ipv4_tcp_opts |=
2335 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2337 init_fw_cb->ipv4_tcp_opts &=
2338 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2340 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2341 if (iface_param->iface_num & 0x1)
2343 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2344 init_fw_cb->ipv4_tcp_opts |=
2345 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2347 init_fw_cb->ipv4_tcp_opts &=
2348 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2350 case ISCSI_NET_PARAM_TCP_WSF:
2351 if (iface_param->iface_num & 0x1)
2353 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2355 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2356 if (iface_param->iface_num & 0x1)
2358 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2359 init_fw_cb->ipv4_tcp_opts |=
2360 cpu_to_le16((iface_param->value[0] << 1) &
2361 TCPOPT_TIMER_SCALE);
2363 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2364 if (iface_param->iface_num & 0x1)
2366 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2367 init_fw_cb->ipv4_tcp_opts |=
2368 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2370 init_fw_cb->ipv4_tcp_opts &=
2371 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2373 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2374 if (iface_param->iface_num & 0x1)
2376 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2377 init_fw_cb->ipv4_tcp_opts |=
2378 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2380 init_fw_cb->ipv4_tcp_opts &=
2381 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2383 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2384 if (iface_param->iface_num & 0x1)
2386 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2387 init_fw_cb->ipv4_tcp_opts |=
2388 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2390 init_fw_cb->ipv4_tcp_opts &=
2391 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2393 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2394 if (iface_param->iface_num & 0x1)
2396 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2397 init_fw_cb->ipv4_ip_opts |=
2398 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2400 init_fw_cb->ipv4_ip_opts &=
2401 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2403 case ISCSI_NET_PARAM_IPV4_TOS:
2404 if (iface_param->iface_num & 0x1)
2406 init_fw_cb->ipv4_tos = iface_param->value[0];
2408 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2409 if (iface_param->iface_num & 0x1)
2411 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2412 init_fw_cb->ipv4_ip_opts |=
2413 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2415 init_fw_cb->ipv4_ip_opts &=
2416 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2418 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2419 if (iface_param->iface_num & 0x1)
2421 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2422 init_fw_cb->ipv4_ip_opts |=
2423 cpu_to_le16(IPOPT_ALT_CID_EN);
2425 init_fw_cb->ipv4_ip_opts &=
2426 cpu_to_le16(~IPOPT_ALT_CID_EN);
2428 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2429 if (iface_param->iface_num & 0x1)
2431 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2432 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2433 init_fw_cb->ipv4_dhcp_alt_cid_len =
2434 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2436 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2437 if (iface_param->iface_num & 0x1)
2439 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2440 init_fw_cb->ipv4_ip_opts |=
2441 cpu_to_le16(IPOPT_REQ_VID_EN);
2443 init_fw_cb->ipv4_ip_opts &=
2444 cpu_to_le16(~IPOPT_REQ_VID_EN);
2446 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2447 if (iface_param->iface_num & 0x1)
2449 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2450 init_fw_cb->ipv4_ip_opts |=
2451 cpu_to_le16(IPOPT_USE_VID_EN);
2453 init_fw_cb->ipv4_ip_opts &=
2454 cpu_to_le16(~IPOPT_USE_VID_EN);
2456 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2457 if (iface_param->iface_num & 0x1)
2459 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2460 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2461 init_fw_cb->ipv4_dhcp_vid_len =
2462 strlen(init_fw_cb->ipv4_dhcp_vid);
2464 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2465 if (iface_param->iface_num & 0x1)
2467 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2468 init_fw_cb->ipv4_ip_opts |=
2469 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2471 init_fw_cb->ipv4_ip_opts &=
2472 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2474 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2475 if (iface_param->iface_num & 0x1)
2477 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2478 init_fw_cb->ipv4_ip_opts |=
2479 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2481 init_fw_cb->ipv4_ip_opts &=
2482 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2484 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2485 if (iface_param->iface_num & 0x1)
2487 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2488 init_fw_cb->ipv4_ip_opts |=
2489 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2491 init_fw_cb->ipv4_ip_opts &=
2492 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2494 case ISCSI_NET_PARAM_REDIRECT_EN:
2495 if (iface_param->iface_num & 0x1)
2497 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2498 init_fw_cb->ipv4_ip_opts |=
2499 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2501 init_fw_cb->ipv4_ip_opts &=
2502 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2504 case ISCSI_NET_PARAM_IPV4_TTL:
2505 if (iface_param->iface_num & 0x1)
2507 init_fw_cb->ipv4_ttl = iface_param->value[0];
2510 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2511 iface_param->param);
2516 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2517 struct iscsi_iface_param_info *iface_param,
2518 struct addr_ctrl_blk *init_fw_cb)
2520 switch (iface_param->param) {
2521 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2522 if (iface_param->iface_num & 0x1)
2524 init_fw_cb->def_timeout =
2525 cpu_to_le16(*(uint16_t *)iface_param->value);
2527 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2528 if (iface_param->iface_num & 0x1)
2530 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2531 init_fw_cb->iscsi_opts |=
2532 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2534 init_fw_cb->iscsi_opts &=
2535 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2537 case ISCSI_IFACE_PARAM_DATADGST_EN:
2538 if (iface_param->iface_num & 0x1)
2540 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2541 init_fw_cb->iscsi_opts |=
2542 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2544 init_fw_cb->iscsi_opts &=
2545 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2547 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2548 if (iface_param->iface_num & 0x1)
2550 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2551 init_fw_cb->iscsi_opts |=
2552 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2554 init_fw_cb->iscsi_opts &=
2555 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2557 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2558 if (iface_param->iface_num & 0x1)
2560 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2561 init_fw_cb->iscsi_opts |=
2562 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2564 init_fw_cb->iscsi_opts &=
2565 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2567 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2568 if (iface_param->iface_num & 0x1)
2570 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2571 init_fw_cb->iscsi_opts |=
2572 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2574 init_fw_cb->iscsi_opts &=
2575 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2577 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2578 if (iface_param->iface_num & 0x1)
2580 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2581 init_fw_cb->iscsi_opts |=
2582 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2584 init_fw_cb->iscsi_opts &=
2585 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2587 case ISCSI_IFACE_PARAM_ERL:
2588 if (iface_param->iface_num & 0x1)
2590 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2591 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2594 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2595 if (iface_param->iface_num & 0x1)
2597 init_fw_cb->iscsi_max_pdu_size =
2598 cpu_to_le32(*(uint32_t *)iface_param->value) /
2601 case ISCSI_IFACE_PARAM_FIRST_BURST:
2602 if (iface_param->iface_num & 0x1)
2604 init_fw_cb->iscsi_fburst_len =
2605 cpu_to_le32(*(uint32_t *)iface_param->value) /
2608 case ISCSI_IFACE_PARAM_MAX_R2T:
2609 if (iface_param->iface_num & 0x1)
2611 init_fw_cb->iscsi_max_outstnd_r2t =
2612 cpu_to_le16(*(uint16_t *)iface_param->value);
2614 case ISCSI_IFACE_PARAM_MAX_BURST:
2615 if (iface_param->iface_num & 0x1)
2617 init_fw_cb->iscsi_max_burst_len =
2618 cpu_to_le32(*(uint32_t *)iface_param->value) /
2621 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2622 if (iface_param->iface_num & 0x1)
2624 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2625 init_fw_cb->iscsi_opts |=
2626 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2628 init_fw_cb->iscsi_opts &=
2629 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2631 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2632 if (iface_param->iface_num & 0x1)
2634 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2635 init_fw_cb->iscsi_opts |=
2636 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2638 init_fw_cb->iscsi_opts &=
2639 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2641 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2642 if (iface_param->iface_num & 0x1)
2644 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2645 init_fw_cb->iscsi_opts |=
2646 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2648 init_fw_cb->iscsi_opts &=
2649 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2651 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2652 if (iface_param->iface_num & 0x1)
2654 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2655 init_fw_cb->iscsi_opts |=
2656 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2658 init_fw_cb->iscsi_opts &=
2659 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2661 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2662 if (iface_param->iface_num & 0x1)
2664 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2665 init_fw_cb->iscsi_opts |=
2666 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2668 init_fw_cb->iscsi_opts &=
2669 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2672 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2673 iface_param->param);
2679 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2681 struct addr_ctrl_blk_def *acb;
2682 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2683 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2684 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2685 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2686 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2687 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2688 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2689 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2690 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2691 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2692 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2693 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2694 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2695 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2696 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2697 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2701 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2703 struct scsi_qla_host *ha = to_qla_host(shost);
2705 struct iscsi_iface_param_info *iface_param = NULL;
2706 struct addr_ctrl_blk *init_fw_cb = NULL;
2707 dma_addr_t init_fw_cb_dma;
2708 uint32_t mbox_cmd[MBOX_REG_COUNT];
2709 uint32_t mbox_sts[MBOX_REG_COUNT];
2711 struct nlattr *attr;
2713 init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
2714 sizeof(struct addr_ctrl_blk),
2715 &init_fw_cb_dma, GFP_KERNEL);
2717 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2722 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2723 memset(&mbox_sts, 0, sizeof(mbox_sts));
2725 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2726 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2728 goto exit_init_fw_cb;
2731 nla_for_each_attr(attr, data, len, rem) {
2732 if (nla_len(attr) < sizeof(*iface_param)) {
2734 goto exit_init_fw_cb;
2737 iface_param = nla_data(attr);
2739 if (iface_param->param_type == ISCSI_NET_PARAM) {
2740 switch (iface_param->iface_type) {
2741 case ISCSI_IFACE_TYPE_IPV4:
2742 switch (iface_param->iface_num) {
2744 qla4xxx_set_ipv4(ha, iface_param,
2748 /* Cannot have more than one IPv4 interface */
2749 ql4_printk(KERN_ERR, ha,
2750 "Invalid IPv4 iface number = %d\n",
2751 iface_param->iface_num);
2755 case ISCSI_IFACE_TYPE_IPV6:
2756 switch (iface_param->iface_num) {
2759 qla4xxx_set_ipv6(ha, iface_param,
2763 /* Cannot have more than two IPv6 interface */
2764 ql4_printk(KERN_ERR, ha,
2765 "Invalid IPv6 iface number = %d\n",
2766 iface_param->iface_num);
2771 ql4_printk(KERN_ERR, ha,
2772 "Invalid iface type\n");
2775 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2776 qla4xxx_set_iscsi_param(ha, iface_param,
2783 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2785 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2786 sizeof(struct addr_ctrl_blk),
2787 FLASH_OPT_RMW_COMMIT);
2788 if (rval != QLA_SUCCESS) {
2789 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2792 goto exit_init_fw_cb;
2795 rval = qla4xxx_disable_acb(ha);
2796 if (rval != QLA_SUCCESS) {
2797 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2800 goto exit_init_fw_cb;
2803 wait_for_completion_timeout(&ha->disable_acb_comp,
2804 DISABLE_ACB_TOV * HZ);
2806 qla4xxx_initcb_to_acb(init_fw_cb);
2808 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2809 if (rval != QLA_SUCCESS) {
2810 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2813 goto exit_init_fw_cb;
2816 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2817 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2821 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2822 init_fw_cb, init_fw_cb_dma);
2827 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2828 enum iscsi_param param, char *buf)
2830 struct iscsi_session *sess = cls_sess->dd_data;
2831 struct ddb_entry *ddb_entry = sess->dd_data;
2832 struct scsi_qla_host *ha = ddb_entry->ha;
2833 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2834 struct ql4_chap_table chap_tbl;
2838 memset(&chap_tbl, 0, sizeof(chap_tbl));
2840 case ISCSI_PARAM_CHAP_IN_IDX:
2841 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2842 sess->password_in, BIDI_CHAP,
2845 len = sprintf(buf, "\n");
2847 len = sprintf(buf, "%hu\n", idx);
2849 case ISCSI_PARAM_CHAP_OUT_IDX:
2850 if (ddb_entry->ddb_type == FLASH_DDB) {
2851 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2852 idx = ddb_entry->chap_tbl_idx;
2858 rval = qla4xxx_get_chap_index(ha, sess->username,
2863 len = sprintf(buf, "\n");
2865 len = sprintf(buf, "%hu\n", idx);
2867 case ISCSI_PARAM_USERNAME:
2868 case ISCSI_PARAM_PASSWORD:
2869 /* First, populate session username and password for FLASH DDB,
2870 * if not already done. This happens when session login fails
2873 if (ddb_entry->ddb_type == FLASH_DDB &&
2874 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2875 !sess->username && !sess->password) {
2876 idx = ddb_entry->chap_tbl_idx;
2877 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2881 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2882 (char *)chap_tbl.name,
2883 strlen((char *)chap_tbl.name));
2884 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2885 (char *)chap_tbl.secret,
2886 chap_tbl.secret_len);
2889 /* allow fall-through */
2891 return iscsi_session_get_param(cls_sess, param, buf);
2897 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2898 enum iscsi_param param, char *buf)
2900 struct iscsi_conn *conn;
2901 struct qla_conn *qla_conn;
2902 struct sockaddr *dst_addr;
2904 conn = cls_conn->dd_data;
2905 qla_conn = conn->dd_data;
2906 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2909 case ISCSI_PARAM_CONN_PORT:
2910 case ISCSI_PARAM_CONN_ADDRESS:
2911 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2912 dst_addr, param, buf);
2914 return iscsi_conn_get_param(cls_conn, param, buf);
2918 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2920 uint32_t mbx_sts = 0;
2921 uint16_t tmp_ddb_index;
2925 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2927 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2928 DEBUG2(ql4_printk(KERN_INFO, ha,
2929 "Free DDB index not available\n"));
2931 goto exit_get_ddb_index;
2934 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2937 DEBUG2(ql4_printk(KERN_INFO, ha,
2938 "Found a free DDB index at %d\n", tmp_ddb_index));
2939 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2940 if (ret == QLA_ERROR) {
2941 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2942 ql4_printk(KERN_INFO, ha,
2943 "DDB index = %d not available trying next\n",
2947 DEBUG2(ql4_printk(KERN_INFO, ha,
2948 "Free FW DDB not available\n"));
2951 *ddb_index = tmp_ddb_index;
2957 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2958 struct ddb_entry *ddb_entry,
2959 char *existing_ipaddr,
2962 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2963 char formatted_ipaddr[DDB_IPADDR_LEN];
2964 int status = QLA_SUCCESS, ret = 0;
2966 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2967 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2973 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2975 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2981 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2984 if (strcmp(existing_ipaddr, formatted_ipaddr))
2991 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2992 struct iscsi_cls_conn *cls_conn)
2994 int idx = 0, max_ddbs, rval;
2995 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2996 struct iscsi_session *sess, *existing_sess;
2997 struct iscsi_conn *conn, *existing_conn;
2998 struct ddb_entry *ddb_entry;
3000 sess = cls_sess->dd_data;
3001 conn = cls_conn->dd_data;
3003 if (sess->targetname == NULL ||
3004 conn->persistent_address == NULL ||
3005 conn->persistent_port == 0)
3008 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3011 for (idx = 0; idx < max_ddbs; idx++) {
3012 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3013 if (ddb_entry == NULL)
3016 if (ddb_entry->ddb_type != FLASH_DDB)
3019 existing_sess = ddb_entry->sess->dd_data;
3020 existing_conn = ddb_entry->conn->dd_data;
3022 if (existing_sess->targetname == NULL ||
3023 existing_conn->persistent_address == NULL ||
3024 existing_conn->persistent_port == 0)
3027 DEBUG2(ql4_printk(KERN_INFO, ha,
3028 "IQN = %s User IQN = %s\n",
3029 existing_sess->targetname,
3032 DEBUG2(ql4_printk(KERN_INFO, ha,
3033 "IP = %s User IP = %s\n",
3034 existing_conn->persistent_address,
3035 conn->persistent_address));
3037 DEBUG2(ql4_printk(KERN_INFO, ha,
3038 "Port = %d User Port = %d\n",
3039 existing_conn->persistent_port,
3040 conn->persistent_port));
3042 if (strcmp(existing_sess->targetname, sess->targetname))
3044 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3045 existing_conn->persistent_address,
3046 conn->persistent_address);
3047 if (rval == QLA_ERROR)
3049 if (existing_conn->persistent_port != conn->persistent_port)
3054 if (idx == max_ddbs)
3057 DEBUG2(ql4_printk(KERN_INFO, ha,
3058 "Match found in fwdb sessions\n"));
3062 static struct iscsi_cls_session *
3063 qla4xxx_session_create(struct iscsi_endpoint *ep,
3064 uint16_t cmds_max, uint16_t qdepth,
3065 uint32_t initial_cmdsn)
3067 struct iscsi_cls_session *cls_sess;
3068 struct scsi_qla_host *ha;
3069 struct qla_endpoint *qla_ep;
3070 struct ddb_entry *ddb_entry;
3072 struct iscsi_session *sess;
3073 struct sockaddr *dst_addr;
3077 printk(KERN_ERR "qla4xxx: missing ep.\n");
3081 qla_ep = ep->dd_data;
3082 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3083 ha = to_qla_host(qla_ep->host);
3084 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3087 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3088 if (ret == QLA_ERROR)
3091 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3092 cmds_max, sizeof(struct ddb_entry),
3093 sizeof(struct ql4_task_data),
3094 initial_cmdsn, ddb_index);
3098 sess = cls_sess->dd_data;
3099 ddb_entry = sess->dd_data;
3100 ddb_entry->fw_ddb_index = ddb_index;
3101 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3103 ddb_entry->sess = cls_sess;
3104 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3105 ddb_entry->ddb_change = qla4xxx_ddb_change;
3106 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3107 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3108 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3114 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3116 struct iscsi_session *sess;
3117 struct ddb_entry *ddb_entry;
3118 struct scsi_qla_host *ha;
3119 unsigned long flags, wtime;
3120 struct dev_db_entry *fw_ddb_entry = NULL;
3121 dma_addr_t fw_ddb_entry_dma;
3125 sess = cls_sess->dd_data;
3126 ddb_entry = sess->dd_data;
3128 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3131 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3132 &fw_ddb_entry_dma, GFP_KERNEL);
3133 if (!fw_ddb_entry) {
3134 ql4_printk(KERN_ERR, ha,
3135 "%s: Unable to allocate dma buffer\n", __func__);
3136 goto destroy_session;
3139 wtime = jiffies + (HZ * LOGOUT_TOV);
3141 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3142 fw_ddb_entry, fw_ddb_entry_dma,
3143 NULL, NULL, &ddb_state, NULL,
3145 if (ret == QLA_ERROR)
3146 goto destroy_session;
3148 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3149 (ddb_state == DDB_DS_SESSION_FAILED))
3150 goto destroy_session;
3152 schedule_timeout_uninterruptible(HZ);
3153 } while ((time_after(wtime, jiffies)));
3156 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3157 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3158 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3159 spin_lock_irqsave(&ha->hardware_lock, flags);
3160 qla4xxx_free_ddb(ha, ddb_entry);
3161 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3163 iscsi_session_teardown(cls_sess);
3166 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3167 fw_ddb_entry, fw_ddb_entry_dma);
3170 static struct iscsi_cls_conn *
3171 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3173 struct iscsi_cls_conn *cls_conn;
3174 struct iscsi_session *sess;
3175 struct ddb_entry *ddb_entry;
3176 struct scsi_qla_host *ha;
3178 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3181 pr_info("%s: Can not create connection for conn_idx = %u\n",
3182 __func__, conn_idx);
3186 sess = cls_sess->dd_data;
3187 ddb_entry = sess->dd_data;
3188 ddb_entry->conn = cls_conn;
3191 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3196 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3197 struct iscsi_cls_conn *cls_conn,
3198 uint64_t transport_fd, int is_leading)
3200 struct iscsi_conn *conn;
3201 struct qla_conn *qla_conn;
3202 struct iscsi_endpoint *ep;
3203 struct ddb_entry *ddb_entry;
3204 struct scsi_qla_host *ha;
3205 struct iscsi_session *sess;
3207 sess = cls_session->dd_data;
3208 ddb_entry = sess->dd_data;
3211 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3212 cls_session->sid, cls_conn->cid));
3214 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3216 ep = iscsi_lookup_endpoint(transport_fd);
3219 conn = cls_conn->dd_data;
3220 qla_conn = conn->dd_data;
3221 qla_conn->qla_ep = ep->dd_data;
3225 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3227 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3228 struct iscsi_session *sess;
3229 struct ddb_entry *ddb_entry;
3230 struct scsi_qla_host *ha;
3231 struct dev_db_entry *fw_ddb_entry = NULL;
3232 dma_addr_t fw_ddb_entry_dma;
3233 uint32_t mbx_sts = 0;
3235 int status = QLA_SUCCESS;
3237 sess = cls_sess->dd_data;
3238 ddb_entry = sess->dd_data;
3240 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3241 cls_sess->sid, cls_conn->cid));
3243 /* Check if we have matching FW DDB, if yes then do not
3244 * login to this target. This could cause target to logout previous
3247 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3248 if (ret == QLA_SUCCESS) {
3249 ql4_printk(KERN_INFO, ha,
3250 "Session already exist in FW.\n");
3252 goto exit_conn_start;
3255 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3256 &fw_ddb_entry_dma, GFP_KERNEL);
3257 if (!fw_ddb_entry) {
3258 ql4_printk(KERN_ERR, ha,
3259 "%s: Unable to allocate dma buffer\n", __func__);
3261 goto exit_conn_start;
3264 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3266 /* If iscsid is stopped and started then no need to do
3267 * set param again since ddb state will be already
3268 * active and FW does not allow set ddb to an
3272 if (ddb_entry->fw_ddb_device_state ==
3273 DDB_DS_SESSION_ACTIVE) {
3274 ddb_entry->unblock_sess(ddb_entry->sess);
3275 goto exit_set_param;
3278 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3279 __func__, ddb_entry->fw_ddb_index);
3280 goto exit_conn_start;
3283 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3284 if (status == QLA_ERROR) {
3285 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3288 goto exit_conn_start;
3291 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3292 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3294 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3295 ddb_entry->fw_ddb_device_state));
3302 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3303 fw_ddb_entry, fw_ddb_entry_dma);
3307 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3309 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3310 struct iscsi_session *sess;
3311 struct scsi_qla_host *ha;
3312 struct ddb_entry *ddb_entry;
3315 sess = cls_sess->dd_data;
3316 ddb_entry = sess->dd_data;
3318 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3321 options = LOGOUT_OPTION_CLOSE_SESSION;
3322 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3323 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3326 static void qla4xxx_task_work(struct work_struct *wdata)
3328 struct ql4_task_data *task_data;
3329 struct scsi_qla_host *ha;
3330 struct passthru_status *sts;
3331 struct iscsi_task *task;
3332 struct iscsi_hdr *hdr;
3335 struct iscsi_conn *conn;
3339 task_data = container_of(wdata, struct ql4_task_data, task_work);
3341 task = task_data->task;
3342 sts = &task_data->sts;
3343 hdr_len = sizeof(struct iscsi_hdr);
3345 DEBUG3(printk(KERN_INFO "Status returned\n"));
3346 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3347 DEBUG3(printk(KERN_INFO "Response buffer"));
3348 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3352 switch (sts->completionStatus) {
3353 case PASSTHRU_STATUS_COMPLETE:
3354 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3355 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3358 data = task_data->resp_buffer + hdr_len;
3359 data_len = task_data->resp_len - hdr_len;
3360 iscsi_complete_pdu(conn, hdr, data, data_len);
3363 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3364 sts->completionStatus);
3370 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3372 struct ql4_task_data *task_data;
3373 struct iscsi_session *sess;
3374 struct ddb_entry *ddb_entry;
3375 struct scsi_qla_host *ha;
3378 sess = task->conn->session;
3379 ddb_entry = sess->dd_data;
3381 task_data = task->dd_data;
3382 memset(task_data, 0, sizeof(struct ql4_task_data));
3385 ql4_printk(KERN_INFO, ha,
3386 "%s: SCSI Commands not implemented\n", __func__);
3390 hdr_len = sizeof(struct iscsi_hdr);
3392 task_data->task = task;
3394 if (task->data_count) {
3395 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3400 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3401 __func__, task->conn->max_recv_dlength, hdr_len));
3403 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3404 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3405 task_data->resp_len,
3406 &task_data->resp_dma,
3408 if (!task_data->resp_buffer)
3409 goto exit_alloc_pdu;
3411 task_data->req_len = task->data_count + hdr_len;
3412 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3414 &task_data->req_dma,
3416 if (!task_data->req_buffer)
3417 goto exit_alloc_pdu;
3419 task->hdr = task_data->req_buffer;
3421 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3426 if (task_data->resp_buffer)
3427 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3428 task_data->resp_buffer, task_data->resp_dma);
3430 if (task_data->req_buffer)
3431 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3432 task_data->req_buffer, task_data->req_dma);
3436 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3438 struct ql4_task_data *task_data;
3439 struct iscsi_session *sess;
3440 struct ddb_entry *ddb_entry;
3441 struct scsi_qla_host *ha;
3444 hdr_len = sizeof(struct iscsi_hdr);
3445 sess = task->conn->session;
3446 ddb_entry = sess->dd_data;
3448 task_data = task->dd_data;
3450 if (task->data_count) {
3451 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3452 task->data_count, PCI_DMA_TODEVICE);
3455 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3456 __func__, task->conn->max_recv_dlength, hdr_len));
3458 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3459 task_data->resp_buffer, task_data->resp_dma);
3460 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3461 task_data->req_buffer, task_data->req_dma);
3465 static int qla4xxx_task_xmit(struct iscsi_task *task)
3467 struct scsi_cmnd *sc = task->sc;
3468 struct iscsi_session *sess = task->conn->session;
3469 struct ddb_entry *ddb_entry = sess->dd_data;
3470 struct scsi_qla_host *ha = ddb_entry->ha;
3473 return qla4xxx_send_passthru0(task);
3475 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3480 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3481 struct iscsi_bus_flash_conn *conn,
3482 struct dev_db_entry *fw_ddb_entry)
3484 unsigned long options = 0;
3487 options = le16_to_cpu(fw_ddb_entry->options);
3488 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3489 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3490 rc = iscsi_switch_str_param(&sess->portal_type,
3495 rc = iscsi_switch_str_param(&sess->portal_type,
3501 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3503 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3504 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3506 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3507 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3508 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3509 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3510 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3511 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3513 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3514 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3515 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3516 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3518 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3519 sess->discovery_auth_optional =
3520 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3521 if (test_bit(ISCSIOPT_ERL1, &options))
3523 if (test_bit(ISCSIOPT_ERL0, &options))
3526 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3527 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3528 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3529 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3530 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3531 conn->tcp_timer_scale |= BIT_3;
3532 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3533 conn->tcp_timer_scale |= BIT_2;
3534 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3535 conn->tcp_timer_scale |= BIT_1;
3537 conn->tcp_timer_scale >>= 1;
3538 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3540 options = le16_to_cpu(fw_ddb_entry->ip_options);
3541 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3543 conn->max_recv_dlength = BYTE_UNITS *
3544 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3545 conn->max_xmit_dlength = BYTE_UNITS *
3546 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3547 sess->first_burst = BYTE_UNITS *
3548 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3549 sess->max_burst = BYTE_UNITS *
3550 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3551 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3552 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3553 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3554 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3555 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3556 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3557 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3558 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3559 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3560 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3561 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3562 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3563 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3564 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3565 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3566 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3568 sess->default_taskmgmt_timeout =
3569 le16_to_cpu(fw_ddb_entry->def_timeout);
3570 conn->port = le16_to_cpu(fw_ddb_entry->port);
3572 options = le16_to_cpu(fw_ddb_entry->options);
3573 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3574 if (!conn->ipaddress) {
3579 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3580 if (!conn->redirect_ipaddr) {
3585 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3586 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3588 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3589 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3591 conn->link_local_ipv6_addr = kmemdup(
3592 fw_ddb_entry->link_local_ipv6_addr,
3593 IPv6_ADDR_LEN, GFP_KERNEL);
3594 if (!conn->link_local_ipv6_addr) {
3599 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3602 if (fw_ddb_entry->iscsi_name[0]) {
3603 rc = iscsi_switch_str_param(&sess->targetname,
3604 (char *)fw_ddb_entry->iscsi_name);
3609 if (fw_ddb_entry->iscsi_alias[0]) {
3610 rc = iscsi_switch_str_param(&sess->targetalias,
3611 (char *)fw_ddb_entry->iscsi_alias);
3616 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3622 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3623 struct iscsi_bus_flash_conn *conn,
3624 struct dev_db_entry *fw_ddb_entry)
3629 options = le16_to_cpu(fw_ddb_entry->options);
3630 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3631 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3636 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3637 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3638 SET_BITVAL(sess->entry_state, options, BIT_3);
3639 fw_ddb_entry->options = cpu_to_le16(options);
3641 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3642 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3643 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3644 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3645 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3646 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3647 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3648 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3649 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3650 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3651 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3652 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3653 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3654 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3655 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3657 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3658 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3659 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3660 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3661 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3662 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3663 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3664 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3665 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3667 options = le16_to_cpu(fw_ddb_entry->ip_options);
3668 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3669 fw_ddb_entry->ip_options = cpu_to_le16(options);
3671 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3672 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3673 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3674 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3675 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3676 fw_ddb_entry->iscsi_first_burst_len =
3677 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3678 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3680 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3681 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3682 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3683 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3684 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3685 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3686 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3687 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3688 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3689 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3690 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3691 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3692 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3693 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3694 fw_ddb_entry->port = cpu_to_le16(conn->port);
3695 fw_ddb_entry->def_timeout =
3696 cpu_to_le16(sess->default_taskmgmt_timeout);
3698 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3699 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3701 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3703 if (conn->ipaddress)
3704 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3705 sizeof(fw_ddb_entry->ip_addr));
3707 if (conn->redirect_ipaddr)
3708 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3709 sizeof(fw_ddb_entry->tgt_addr));
3711 if (conn->link_local_ipv6_addr)
3712 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3713 conn->link_local_ipv6_addr,
3714 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3716 if (sess->targetname)
3717 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3718 sizeof(fw_ddb_entry->iscsi_name));
3720 if (sess->targetalias)
3721 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3722 sizeof(fw_ddb_entry->iscsi_alias));
3724 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3729 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3730 struct iscsi_session *sess,
3731 struct dev_db_entry *fw_ddb_entry)
3733 unsigned long options = 0;
3735 uint16_t disc_parent;
3736 char ip_addr[DDB_IPADDR_LEN];
3738 options = le16_to_cpu(fw_ddb_entry->options);
3739 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3740 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3742 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3744 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3745 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3746 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3747 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3748 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3749 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3751 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3752 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3753 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3755 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3756 sess->discovery_auth_optional =
3757 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3758 if (test_bit(ISCSIOPT_ERL1, &options))
3760 if (test_bit(ISCSIOPT_ERL0, &options))
3763 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3764 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3765 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3766 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3767 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3768 conn->tcp_timer_scale |= BIT_3;
3769 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3770 conn->tcp_timer_scale |= BIT_2;
3771 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3772 conn->tcp_timer_scale |= BIT_1;
3774 conn->tcp_timer_scale >>= 1;
3775 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3777 options = le16_to_cpu(fw_ddb_entry->ip_options);
3778 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3780 conn->max_recv_dlength = BYTE_UNITS *
3781 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3782 conn->max_xmit_dlength = BYTE_UNITS *
3783 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3784 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3785 sess->first_burst = BYTE_UNITS *
3786 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3787 sess->max_burst = BYTE_UNITS *
3788 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3789 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3790 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3791 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3792 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3793 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3794 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3795 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3796 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3797 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3798 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3799 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3800 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3801 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3803 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3804 if (ddb_link == DDB_ISNS)
3805 disc_parent = ISCSI_DISC_PARENT_ISNS;
3806 else if (ddb_link == DDB_NO_LINK)
3807 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3808 else if (ddb_link < MAX_DDB_ENTRIES)
3809 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3811 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3813 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3814 iscsi_get_discovery_parent_name(disc_parent), 0);
3816 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3817 (char *)fw_ddb_entry->iscsi_alias, 0);
3819 options = le16_to_cpu(fw_ddb_entry->options);
3820 if (options & DDB_OPT_IPV6_DEVICE) {
3821 memset(ip_addr, 0, sizeof(ip_addr));
3822 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3823 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3824 (char *)ip_addr, 0);
3828 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3829 struct dev_db_entry *fw_ddb_entry,
3830 struct iscsi_cls_session *cls_sess,
3831 struct iscsi_cls_conn *cls_conn)
3834 struct iscsi_session *sess;
3835 struct ddb_entry *ddb_entry;
3836 struct ql4_chap_table chap_tbl;
3837 struct iscsi_conn *conn;
3838 char ip_addr[DDB_IPADDR_LEN];
3839 uint16_t options = 0;
3841 sess = cls_sess->dd_data;
3842 ddb_entry = sess->dd_data;
3843 conn = cls_conn->dd_data;
3844 memset(&chap_tbl, 0, sizeof(chap_tbl));
3846 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3848 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3850 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3851 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3853 memset(ip_addr, 0, sizeof(ip_addr));
3854 options = le16_to_cpu(fw_ddb_entry->options);
3855 if (options & DDB_OPT_IPV6_DEVICE) {
3856 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3858 memset(ip_addr, 0, sizeof(ip_addr));
3859 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3861 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3862 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3865 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3866 (char *)ip_addr, buflen);
3867 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3868 (char *)fw_ddb_entry->iscsi_name, buflen);
3869 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3870 (char *)ha->name_string, buflen);
3872 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3873 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3875 ddb_entry->chap_tbl_idx)) {
3876 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3877 (char *)chap_tbl.name,
3878 strlen((char *)chap_tbl.name));
3879 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3880 (char *)chap_tbl.secret,
3881 chap_tbl.secret_len);
3886 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3887 struct ddb_entry *ddb_entry)
3889 struct iscsi_cls_session *cls_sess;
3890 struct iscsi_cls_conn *cls_conn;
3892 dma_addr_t fw_ddb_entry_dma;
3893 struct dev_db_entry *fw_ddb_entry;
3895 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3896 &fw_ddb_entry_dma, GFP_KERNEL);
3897 if (!fw_ddb_entry) {
3898 ql4_printk(KERN_ERR, ha,
3899 "%s: Unable to allocate dma buffer\n", __func__);
3900 goto exit_session_conn_fwddb_param;
3903 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3904 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3905 NULL, NULL, NULL) == QLA_ERROR) {
3906 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3907 "get_ddb_entry for fw_ddb_index %d\n",
3908 ha->host_no, __func__,
3909 ddb_entry->fw_ddb_index));
3910 goto exit_session_conn_fwddb_param;
3913 cls_sess = ddb_entry->sess;
3915 cls_conn = ddb_entry->conn;
3918 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3920 exit_session_conn_fwddb_param:
3922 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3923 fw_ddb_entry, fw_ddb_entry_dma);
3926 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3927 struct ddb_entry *ddb_entry)
3929 struct iscsi_cls_session *cls_sess;
3930 struct iscsi_cls_conn *cls_conn;
3931 struct iscsi_session *sess;
3932 struct iscsi_conn *conn;
3934 dma_addr_t fw_ddb_entry_dma;
3935 struct dev_db_entry *fw_ddb_entry;
3937 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3938 &fw_ddb_entry_dma, GFP_KERNEL);
3939 if (!fw_ddb_entry) {
3940 ql4_printk(KERN_ERR, ha,
3941 "%s: Unable to allocate dma buffer\n", __func__);
3942 goto exit_session_conn_param;
3945 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3946 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3947 NULL, NULL, NULL) == QLA_ERROR) {
3948 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3949 "get_ddb_entry for fw_ddb_index %d\n",
3950 ha->host_no, __func__,
3951 ddb_entry->fw_ddb_index));
3952 goto exit_session_conn_param;
3955 cls_sess = ddb_entry->sess;
3956 sess = cls_sess->dd_data;
3958 cls_conn = ddb_entry->conn;
3959 conn = cls_conn->dd_data;
3961 /* Update timers after login */
3962 ddb_entry->default_relogin_timeout =
3963 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3964 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3965 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3966 ddb_entry->default_time2wait =
3967 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3970 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3971 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3973 memcpy(sess->initiatorname, ha->name_string,
3974 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3976 exit_session_conn_param:
3978 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3979 fw_ddb_entry, fw_ddb_entry_dma);
3985 static void qla4xxx_timer(struct timer_list *t);
3987 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
3988 unsigned long interval)
3990 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3991 __func__, ha->host->host_no));
3992 timer_setup(&ha->timer, qla4xxx_timer, 0);
3993 ha->timer.expires = jiffies + interval * HZ;
3994 add_timer(&ha->timer);
3995 ha->timer_active = 1;
3998 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4000 del_timer_sync(&ha->timer);
4001 ha->timer_active = 0;
4005 * qla4xxx_mark_device_missing - blocks the session
4006 * @cls_session: Pointer to the session to be blocked
4007 * @ddb_entry: Pointer to device database entry
4009 * This routine marks a device missing and close connection.
4011 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4013 iscsi_block_session(cls_session);
4017 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4018 * @ha: Pointer to host adapter structure.
4020 * This routine marks a device missing and resets the relogin retry count.
4022 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4024 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4027 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4028 struct ddb_entry *ddb_entry,
4029 struct scsi_cmnd *cmd)
4033 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4037 kref_init(&srb->srb_ref);
4039 srb->ddb = ddb_entry;
4042 CMD_SP(cmd) = (void *)srb;
4047 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4049 struct scsi_cmnd *cmd = srb->cmd;
4051 if (srb->flags & SRB_DMA_VALID) {
4052 scsi_dma_unmap(cmd);
4053 srb->flags &= ~SRB_DMA_VALID;
4058 void qla4xxx_srb_compl(struct kref *ref)
4060 struct srb *srb = container_of(ref, struct srb, srb_ref);
4061 struct scsi_cmnd *cmd = srb->cmd;
4062 struct scsi_qla_host *ha = srb->ha;
4064 qla4xxx_srb_free_dma(ha, srb);
4066 mempool_free(srb, ha->srb_mempool);
4068 cmd->scsi_done(cmd);
4072 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4074 * @cmd: Pointer to Linux's SCSI command structure
4077 * This routine is invoked by Linux to send a SCSI command to the driver.
4078 * The mid-level driver tries to ensure that queuecommand never gets
4079 * invoked concurrently with itself or the interrupt handler (although
4080 * the interrupt handler may call this routine as part of request-
4081 * completion handling). Unfortunely, it sometimes calls the scheduler
4082 * in interrupt context which is a big NO! NO!.
4084 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4086 struct scsi_qla_host *ha = to_qla_host(host);
4087 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4088 struct iscsi_cls_session *sess = ddb_entry->sess;
4092 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4093 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4094 cmd->result = DID_NO_CONNECT << 16;
4096 cmd->result = DID_REQUEUE << 16;
4097 goto qc_fail_command;
4101 cmd->result = DID_IMM_RETRY << 16;
4102 goto qc_fail_command;
4105 rval = iscsi_session_chkready(sess);
4108 goto qc_fail_command;
4111 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4112 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4113 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4114 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4115 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4116 !test_bit(AF_ONLINE, &ha->flags) ||
4117 !test_bit(AF_LINK_UP, &ha->flags) ||
4118 test_bit(AF_LOOPBACK, &ha->flags) ||
4119 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4120 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4121 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4124 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4128 rval = qla4xxx_send_command_to_isp(ha, srb);
4129 if (rval != QLA_SUCCESS)
4130 goto qc_host_busy_free_sp;
4134 qc_host_busy_free_sp:
4135 qla4xxx_srb_free_dma(ha, srb);
4136 mempool_free(srb, ha->srb_mempool);
4139 return SCSI_MLQUEUE_HOST_BUSY;
4142 cmd->scsi_done(cmd);
4148 * qla4xxx_mem_free - frees memory allocated to adapter
4149 * @ha: Pointer to host adapter structure.
4151 * Frees memory previously allocated by qla4xxx_mem_alloc
4153 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4156 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4165 ha->request_ring = NULL;
4166 ha->request_dma = 0;
4167 ha->response_ring = NULL;
4168 ha->response_dma = 0;
4169 ha->shadow_regs = NULL;
4170 ha->shadow_regs_dma = 0;
4172 ha->fw_dump_size = 0;
4174 /* Free srb pool. */
4175 if (ha->srb_mempool)
4176 mempool_destroy(ha->srb_mempool);
4178 ha->srb_mempool = NULL;
4180 if (ha->chap_dma_pool)
4181 dma_pool_destroy(ha->chap_dma_pool);
4184 vfree(ha->chap_list);
4185 ha->chap_list = NULL;
4187 if (ha->fw_ddb_dma_pool)
4188 dma_pool_destroy(ha->fw_ddb_dma_pool);
4190 /* release io space registers */
4191 if (is_qla8022(ha)) {
4194 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4195 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4198 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4199 } else if (ha->reg) {
4203 if (ha->reset_tmplt.buff)
4204 vfree(ha->reset_tmplt.buff);
4206 pci_release_regions(ha->pdev);
4210 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4211 * @ha: Pointer to host adapter structure
4213 * Allocates DMA memory for request and response queues. Also allocates memory
4216 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4218 unsigned long align;
4220 /* Allocate contiguous block of DMA memory for queues. */
4221 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4222 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4223 sizeof(struct shadow_regs) +
4225 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4226 ha->queues = dma_zalloc_coherent(&ha->pdev->dev, ha->queues_len,
4227 &ha->queues_dma, GFP_KERNEL);
4228 if (ha->queues == NULL) {
4229 ql4_printk(KERN_WARNING, ha,
4230 "Memory Allocation failed - queues.\n");
4232 goto mem_alloc_error_exit;
4236 * As per RISC alignment requirements -- the bus-address must be a
4237 * multiple of the request-ring size (in bytes).
4240 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4241 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4242 (MEM_ALIGN_VALUE - 1));
4244 /* Update request and response queue pointers. */
4245 ha->request_dma = ha->queues_dma + align;
4246 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4247 ha->response_dma = ha->queues_dma + align +
4248 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4249 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4250 (REQUEST_QUEUE_DEPTH *
4252 ha->shadow_regs_dma = ha->queues_dma + align +
4253 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4254 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4255 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4256 (REQUEST_QUEUE_DEPTH *
4258 (RESPONSE_QUEUE_DEPTH *
4261 /* Allocate memory for srb pool. */
4262 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4263 mempool_free_slab, srb_cachep);
4264 if (ha->srb_mempool == NULL) {
4265 ql4_printk(KERN_WARNING, ha,
4266 "Memory Allocation failed - SRB Pool.\n");
4268 goto mem_alloc_error_exit;
4271 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4272 CHAP_DMA_BLOCK_SIZE, 8, 0);
4274 if (ha->chap_dma_pool == NULL) {
4275 ql4_printk(KERN_WARNING, ha,
4276 "%s: chap_dma_pool allocation failed..\n", __func__);
4277 goto mem_alloc_error_exit;
4280 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4281 DDB_DMA_BLOCK_SIZE, 8, 0);
4283 if (ha->fw_ddb_dma_pool == NULL) {
4284 ql4_printk(KERN_WARNING, ha,
4285 "%s: fw_ddb_dma_pool allocation failed..\n",
4287 goto mem_alloc_error_exit;
4292 mem_alloc_error_exit:
4297 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4298 * @ha: adapter block pointer.
4300 * Note: The caller should not hold the idc lock.
4302 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4304 uint32_t temp, temp_state, temp_val;
4305 int status = QLA_SUCCESS;
4307 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4309 temp_state = qla82xx_get_temp_state(temp);
4310 temp_val = qla82xx_get_temp_val(temp);
4312 if (temp_state == QLA82XX_TEMP_PANIC) {
4313 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4314 " exceeds maximum allowed. Hardware has been shut"
4315 " down.\n", temp_val);
4317 } else if (temp_state == QLA82XX_TEMP_WARN) {
4318 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4319 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4320 " degrees C exceeds operating range."
4321 " Immediate action needed.\n", temp_val);
4323 if (ha->temperature == QLA82XX_TEMP_WARN)
4324 ql4_printk(KERN_INFO, ha, "Device temperature is"
4325 " now %d degrees C in normal range.\n",
4328 ha->temperature = temp_state;
4333 * qla4_8xxx_check_fw_alive - Check firmware health
4334 * @ha: Pointer to host adapter structure.
4336 * Context: Interrupt
4338 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4340 uint32_t fw_heartbeat_counter;
4341 int status = QLA_SUCCESS;
4343 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4344 QLA8XXX_PEG_ALIVE_COUNTER);
4345 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4346 if (fw_heartbeat_counter == 0xffffffff) {
4347 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4348 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4349 ha->host_no, __func__));
4353 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4354 ha->seconds_since_last_heartbeat++;
4355 /* FW not alive after 2 seconds */
4356 if (ha->seconds_since_last_heartbeat == 2) {
4357 ha->seconds_since_last_heartbeat = 0;
4358 qla4_8xxx_dump_peg_reg(ha);
4362 ha->seconds_since_last_heartbeat = 0;
4364 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4368 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4370 uint32_t halt_status;
4371 int halt_status_unrecoverable = 0;
4373 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4375 if (is_qla8022(ha)) {
4376 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4378 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4379 CRB_NIU_XG_PAUSE_CTL_P0 |
4380 CRB_NIU_XG_PAUSE_CTL_P1);
4382 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4383 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4385 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4386 halt_status_unrecoverable = 1;
4387 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4388 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4389 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4391 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4392 halt_status_unrecoverable = 1;
4396 * Since we cannot change dev_state in interrupt context,
4397 * set appropriate DPC flag then wakeup DPC
4399 if (halt_status_unrecoverable) {
4400 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4402 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4404 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4406 qla4xxx_mailbox_premature_completion(ha);
4407 qla4xxx_wake_dpc(ha);
4411 * qla4_8xxx_watchdog - Poll dev state
4412 * @ha: Pointer to host adapter structure.
4414 * Context: Interrupt
4416 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4421 if (is_qla8032(ha) &&
4422 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4423 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4424 __func__, ha->func_num);
4426 /* don't poll if reset is going on */
4427 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4428 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4429 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4430 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4432 if (qla4_8xxx_check_temp(ha)) {
4433 if (is_qla8022(ha)) {
4434 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4435 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4436 CRB_NIU_XG_PAUSE_CTL_P0 |
4437 CRB_NIU_XG_PAUSE_CTL_P1);
4439 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4440 qla4xxx_wake_dpc(ha);
4441 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4442 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4444 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4447 if (is_qla8032(ha) || is_qla8042(ha)) {
4448 idc_ctrl = qla4_83xx_rd_reg(ha,
4449 QLA83XX_IDC_DRV_CTRL);
4450 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4451 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4453 qla4xxx_mailbox_premature_completion(
4458 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4459 (is_qla8022(ha) && !ql4xdontresethba)) {
4460 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4461 qla4xxx_wake_dpc(ha);
4463 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4464 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4465 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4467 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4468 qla4xxx_wake_dpc(ha);
4470 /* Check firmware health */
4471 if (qla4_8xxx_check_fw_alive(ha))
4472 qla4_8xxx_process_fw_error(ha);
4477 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4479 struct iscsi_session *sess;
4480 struct ddb_entry *ddb_entry;
4481 struct scsi_qla_host *ha;
4483 sess = cls_sess->dd_data;
4484 ddb_entry = sess->dd_data;
4487 if (!(ddb_entry->ddb_type == FLASH_DDB))
4490 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4491 !iscsi_is_session_online(cls_sess)) {
4492 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4494 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4496 atomic_set(&ddb_entry->retry_relogin_timer,
4498 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4499 set_bit(DF_RELOGIN, &ddb_entry->flags);
4500 DEBUG2(ql4_printk(KERN_INFO, ha,
4501 "%s: index [%d] login device\n",
4502 __func__, ddb_entry->fw_ddb_index));
4504 atomic_dec(&ddb_entry->retry_relogin_timer);
4508 /* Wait for relogin to timeout */
4509 if (atomic_read(&ddb_entry->relogin_timer) &&
4510 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4512 * If the relogin times out and the device is
4513 * still NOT ONLINE then try and relogin again.
4515 if (!iscsi_is_session_online(cls_sess)) {
4516 /* Reset retry relogin timer */
4517 atomic_inc(&ddb_entry->relogin_retry_count);
4518 DEBUG2(ql4_printk(KERN_INFO, ha,
4519 "%s: index[%d] relogin timed out-retrying"
4520 " relogin (%d), retry (%d)\n", __func__,
4521 ddb_entry->fw_ddb_index,
4522 atomic_read(&ddb_entry->relogin_retry_count),
4523 ddb_entry->default_time2wait + 4));
4524 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4525 atomic_set(&ddb_entry->retry_relogin_timer,
4526 ddb_entry->default_time2wait + 4);
4532 * qla4xxx_timer - checks every second for work to do.
4533 * @ha: Pointer to host adapter structure.
4535 static void qla4xxx_timer(struct timer_list *t)
4537 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4541 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4543 /* If we are in the middle of AER/EEH processing
4544 * skip any processing and reschedule the timer
4546 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4547 mod_timer(&ha->timer, jiffies + HZ);
4551 /* Hardware read to trigger an EEH error during mailbox waits. */
4552 if (!pci_channel_offline(ha->pdev))
4553 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4556 qla4_8xxx_watchdog(ha);
4558 if (is_qla40XX(ha)) {
4559 /* Check for heartbeat interval. */
4560 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4561 ha->heartbeat_interval != 0) {
4562 ha->seconds_since_last_heartbeat++;
4563 if (ha->seconds_since_last_heartbeat >
4564 ha->heartbeat_interval + 2)
4565 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4569 /* Process any deferred work. */
4570 if (!list_empty(&ha->work_list))
4573 /* Wakeup the dpc routine for this adapter, if needed. */
4575 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4576 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4577 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4578 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4579 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4580 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4581 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4582 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4583 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4584 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4585 test_bit(DPC_AEN, &ha->dpc_flags)) {
4586 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4587 " - dpc flags = 0x%lx\n",
4588 ha->host_no, __func__, ha->dpc_flags));
4589 qla4xxx_wake_dpc(ha);
4592 /* Reschedule timer thread to call us back in one second */
4593 mod_timer(&ha->timer, jiffies + HZ);
4595 DEBUG2(ha->seconds_since_last_intr++);
4599 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4600 * @ha: Pointer to host adapter structure.
4602 * This routine stalls the driver until all outstanding commands are returned.
4603 * Caller must release the Hardware Lock prior to calling this routine.
4605 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4608 unsigned long flags;
4609 struct scsi_cmnd *cmd;
4610 unsigned long wtime;
4614 wtmo = WAIT_CMD_TOV;
4616 wtmo = ha->nx_reset_timeout / 2;
4618 wtime = jiffies + (wtmo * HZ);
4620 DEBUG2(ql4_printk(KERN_INFO, ha,
4621 "Wait up to %u seconds for cmds to complete\n",
4624 while (!time_after_eq(jiffies, wtime)) {
4625 spin_lock_irqsave(&ha->hardware_lock, flags);
4626 /* Find a command that hasn't completed. */
4627 for (index = 0; index < ha->host->can_queue; index++) {
4628 cmd = scsi_host_find_tag(ha->host, index);
4630 * We cannot just check if the index is valid,
4631 * becase if we are run from the scsi eh, then
4632 * the scsi/block layer is going to prevent
4633 * the tag from being released.
4635 if (cmd != NULL && CMD_SP(cmd))
4638 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4640 /* If No Commands are pending, wait is complete */
4641 if (index == ha->host->can_queue)
4646 /* If we timed out on waiting for commands to come back
4651 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4653 uint32_t ctrl_status;
4654 unsigned long flags = 0;
4656 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4658 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4661 spin_lock_irqsave(&ha->hardware_lock, flags);
4664 * If the SCSI Reset Interrupt bit is set, clear it.
4665 * Otherwise, the Soft Reset won't work.
4667 ctrl_status = readw(&ha->reg->ctrl_status);
4668 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4669 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4671 /* Issue Soft Reset */
4672 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4673 readl(&ha->reg->ctrl_status);
4675 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4680 * qla4xxx_soft_reset - performs soft reset.
4681 * @ha: Pointer to host adapter structure.
4683 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4685 uint32_t max_wait_time;
4686 unsigned long flags = 0;
4688 uint32_t ctrl_status;
4690 status = qla4xxx_hw_reset(ha);
4691 if (status != QLA_SUCCESS)
4695 /* Wait until the Network Reset Intr bit is cleared */
4696 max_wait_time = RESET_INTR_TOV;
4698 spin_lock_irqsave(&ha->hardware_lock, flags);
4699 ctrl_status = readw(&ha->reg->ctrl_status);
4700 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4702 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4706 } while ((--max_wait_time));
4708 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4709 DEBUG2(printk(KERN_WARNING
4710 "scsi%ld: Network Reset Intr not cleared by "
4711 "Network function, clearing it now!\n",
4713 spin_lock_irqsave(&ha->hardware_lock, flags);
4714 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4715 readl(&ha->reg->ctrl_status);
4716 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4719 /* Wait until the firmware tells us the Soft Reset is done */
4720 max_wait_time = SOFT_RESET_TOV;
4722 spin_lock_irqsave(&ha->hardware_lock, flags);
4723 ctrl_status = readw(&ha->reg->ctrl_status);
4724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4726 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4727 status = QLA_SUCCESS;
4732 } while ((--max_wait_time));
4735 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4736 * after the soft reset has taken place.
4738 spin_lock_irqsave(&ha->hardware_lock, flags);
4739 ctrl_status = readw(&ha->reg->ctrl_status);
4740 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4741 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4742 readl(&ha->reg->ctrl_status);
4744 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4746 /* If soft reset fails then most probably the bios on other
4747 * function is also enabled.
4748 * Since the initialization is sequential the other fn
4749 * wont be able to acknowledge the soft reset.
4750 * Issue a force soft reset to workaround this scenario.
4752 if (max_wait_time == 0) {
4753 /* Issue Force Soft Reset */
4754 spin_lock_irqsave(&ha->hardware_lock, flags);
4755 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4756 readl(&ha->reg->ctrl_status);
4757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4758 /* Wait until the firmware tells us the Soft Reset is done */
4759 max_wait_time = SOFT_RESET_TOV;
4761 spin_lock_irqsave(&ha->hardware_lock, flags);
4762 ctrl_status = readw(&ha->reg->ctrl_status);
4763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4765 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4766 status = QLA_SUCCESS;
4771 } while ((--max_wait_time));
4778 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4779 * @ha: Pointer to host adapter structure.
4780 * @res: returned scsi status
4782 * This routine is called just prior to a HARD RESET to return all
4783 * outstanding commands back to the Operating System.
4784 * Caller should make sure that the following locks are released
4785 * before this calling routine: Hardware lock, and io_request_lock.
4787 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4791 unsigned long flags;
4793 spin_lock_irqsave(&ha->hardware_lock, flags);
4794 for (i = 0; i < ha->host->can_queue; i++) {
4795 srb = qla4xxx_del_from_active_array(ha, i);
4797 srb->cmd->result = res;
4798 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4801 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4804 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4806 clear_bit(AF_ONLINE, &ha->flags);
4808 /* Disable the board */
4809 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4811 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4812 qla4xxx_mark_all_devices_missing(ha);
4813 clear_bit(AF_INIT_DONE, &ha->flags);
4816 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4818 struct iscsi_session *sess;
4819 struct ddb_entry *ddb_entry;
4821 sess = cls_session->dd_data;
4822 ddb_entry = sess->dd_data;
4823 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4825 if (ddb_entry->ddb_type == FLASH_DDB)
4826 iscsi_block_session(ddb_entry->sess);
4828 iscsi_session_failure(cls_session->dd_data,
4829 ISCSI_ERR_CONN_FAILED);
4833 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4834 * @ha: Pointer to host adapter structure.
4836 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4838 int status = QLA_ERROR;
4839 uint8_t reset_chip = 0;
4843 /* Stall incoming I/O until we are done */
4844 scsi_block_requests(ha->host);
4845 clear_bit(AF_ONLINE, &ha->flags);
4846 clear_bit(AF_LINK_UP, &ha->flags);
4848 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4850 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4852 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4853 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4854 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4856 /* disable pause frame for ISP83xx */
4857 qla4_83xx_disable_pause(ha);
4860 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4862 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4865 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4866 * do not reset adapter, jump to initialize_adapter */
4867 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4868 status = QLA_SUCCESS;
4869 goto recover_ha_init_adapter;
4872 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4873 * from eh_host_reset or ioctl module */
4874 if (is_qla80XX(ha) && !reset_chip &&
4875 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4877 DEBUG2(ql4_printk(KERN_INFO, ha,
4878 "scsi%ld: %s - Performing stop_firmware...\n",
4879 ha->host_no, __func__));
4880 status = ha->isp_ops->reset_firmware(ha);
4881 if (status == QLA_SUCCESS) {
4882 ha->isp_ops->disable_intrs(ha);
4883 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4884 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4886 /* If the stop_firmware fails then
4887 * reset the entire chip */
4889 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4890 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4894 /* Issue full chip reset if recovering from a catastrophic error,
4895 * or if stop_firmware fails for ISP-8xxx.
4896 * This is the default case for ISP-4xxx */
4897 if (is_qla40XX(ha) || reset_chip) {
4901 /* Check if 8XXX firmware is alive or not
4902 * We may have arrived here from NEED_RESET
4904 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4907 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4908 while (time_before(jiffies, wait)) {
4909 if (qla4_8xxx_check_fw_alive(ha)) {
4910 qla4xxx_mailbox_premature_completion(ha);
4914 set_current_state(TASK_UNINTERRUPTIBLE);
4915 schedule_timeout(HZ);
4918 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4919 qla4xxx_cmd_wait(ha);
4921 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4922 DEBUG2(ql4_printk(KERN_INFO, ha,
4923 "scsi%ld: %s - Performing chip reset..\n",
4924 ha->host_no, __func__));
4925 status = ha->isp_ops->reset_chip(ha);
4926 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4929 /* Flush any pending ddb changed AENs */
4930 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4932 recover_ha_init_adapter:
4933 /* Upon successful firmware/chip reset, re-initialize the adapter */
4934 if (status == QLA_SUCCESS) {
4935 /* For ISP-4xxx, force function 1 to always initialize
4936 * before function 3 to prevent both funcions from
4937 * stepping on top of the other */
4938 if (is_qla40XX(ha) && (ha->mac_index == 3))
4941 /* NOTE: AF_ONLINE flag set upon successful completion of
4942 * qla4xxx_initialize_adapter */
4943 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4944 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4945 status = qla4_8xxx_check_init_adapter_retry(ha);
4946 if (status == QLA_ERROR) {
4947 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4948 ha->host_no, __func__);
4949 qla4xxx_dead_adapter_cleanup(ha);
4950 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4951 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4952 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4959 /* Retry failed adapter initialization, if necessary
4960 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4961 * case to prevent ping-pong resets between functions */
4962 if (!test_bit(AF_ONLINE, &ha->flags) &&
4963 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4964 /* Adapter initialization failed, see if we can retry
4966 * Since we don't want to block the DPC for too long
4967 * with multiple resets in the same thread,
4968 * utilize DPC to retry */
4969 if (is_qla80XX(ha)) {
4970 ha->isp_ops->idc_lock(ha);
4971 dev_state = qla4_8xxx_rd_direct(ha,
4972 QLA8XXX_CRB_DEV_STATE);
4973 ha->isp_ops->idc_unlock(ha);
4974 if (dev_state == QLA8XXX_DEV_FAILED) {
4975 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4976 "recover adapter. H/W is in Failed "
4977 "state\n", __func__);
4978 qla4xxx_dead_adapter_cleanup(ha);
4979 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4980 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4981 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4989 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4990 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4991 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4992 "(%d) more times\n", ha->host_no,
4993 ha->retry_reset_ha_cnt));
4994 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4997 if (ha->retry_reset_ha_cnt > 0) {
4998 /* Schedule another Reset HA--DPC will retry */
4999 ha->retry_reset_ha_cnt--;
5000 DEBUG2(printk("scsi%ld: recover adapter - "
5001 "retry remaining %d\n",
5003 ha->retry_reset_ha_cnt));
5007 if (ha->retry_reset_ha_cnt == 0) {
5008 /* Recover adapter retries have been exhausted.
5010 DEBUG2(printk("scsi%ld: recover adapter "
5011 "failed - board disabled\n",
5013 qla4xxx_dead_adapter_cleanup(ha);
5014 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5015 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5016 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5022 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5023 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5024 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5028 ha->adapter_error_count++;
5030 if (test_bit(AF_ONLINE, &ha->flags))
5031 ha->isp_ops->enable_intrs(ha);
5033 scsi_unblock_requests(ha->host);
5035 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5036 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5037 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5042 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5044 struct iscsi_session *sess;
5045 struct ddb_entry *ddb_entry;
5046 struct scsi_qla_host *ha;
5048 sess = cls_session->dd_data;
5049 ddb_entry = sess->dd_data;
5051 if (!iscsi_is_session_online(cls_session)) {
5052 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5053 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5054 " unblock session\n", ha->host_no, __func__,
5055 ddb_entry->fw_ddb_index);
5056 iscsi_unblock_session(ddb_entry->sess);
5058 /* Trigger relogin */
5059 if (ddb_entry->ddb_type == FLASH_DDB) {
5060 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5061 test_bit(DF_DISABLE_RELOGIN,
5062 &ddb_entry->flags)))
5063 qla4xxx_arm_relogin_timer(ddb_entry);
5065 iscsi_session_failure(cls_session->dd_data,
5066 ISCSI_ERR_CONN_FAILED);
5071 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5073 struct iscsi_session *sess;
5074 struct ddb_entry *ddb_entry;
5075 struct scsi_qla_host *ha;
5077 sess = cls_session->dd_data;
5078 ddb_entry = sess->dd_data;
5080 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5081 " unblock session\n", ha->host_no, __func__,
5082 ddb_entry->fw_ddb_index);
5084 iscsi_unblock_session(ddb_entry->sess);
5086 /* Start scan target */
5087 if (test_bit(AF_ONLINE, &ha->flags)) {
5088 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5089 " start scan\n", ha->host_no, __func__,
5090 ddb_entry->fw_ddb_index);
5091 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5096 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5098 struct iscsi_session *sess;
5099 struct ddb_entry *ddb_entry;
5100 struct scsi_qla_host *ha;
5101 int status = QLA_SUCCESS;
5103 sess = cls_session->dd_data;
5104 ddb_entry = sess->dd_data;
5106 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5107 " unblock user space session\n", ha->host_no, __func__,
5108 ddb_entry->fw_ddb_index);
5110 if (!iscsi_is_session_online(cls_session)) {
5111 iscsi_conn_start(ddb_entry->conn);
5112 iscsi_conn_login_event(ddb_entry->conn,
5113 ISCSI_CONN_STATE_LOGGED_IN);
5115 ql4_printk(KERN_INFO, ha,
5116 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5117 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5125 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5127 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5130 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5132 uint16_t relogin_timer;
5133 struct iscsi_session *sess;
5134 struct ddb_entry *ddb_entry;
5135 struct scsi_qla_host *ha;
5137 sess = cls_sess->dd_data;
5138 ddb_entry = sess->dd_data;
5141 relogin_timer = max(ddb_entry->default_relogin_timeout,
5142 (uint16_t)RELOGIN_TOV);
5143 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5145 DEBUG2(ql4_printk(KERN_INFO, ha,
5146 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5147 ddb_entry->fw_ddb_index, relogin_timer));
5149 qla4xxx_login_flash_ddb(cls_sess);
5152 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5154 struct iscsi_session *sess;
5155 struct ddb_entry *ddb_entry;
5156 struct scsi_qla_host *ha;
5158 sess = cls_sess->dd_data;
5159 ddb_entry = sess->dd_data;
5162 if (!(ddb_entry->ddb_type == FLASH_DDB))
5165 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5168 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5169 !iscsi_is_session_online(cls_sess)) {
5170 DEBUG2(ql4_printk(KERN_INFO, ha,
5171 "relogin issued\n"));
5172 qla4xxx_relogin_flash_ddb(cls_sess);
5176 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5179 queue_work(ha->dpc_thread, &ha->dpc_work);
5182 static struct qla4_work_evt *
5183 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5184 enum qla4_work_type type)
5186 struct qla4_work_evt *e;
5187 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5189 e = kzalloc(size, GFP_ATOMIC);
5193 INIT_LIST_HEAD(&e->list);
5198 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5199 struct qla4_work_evt *e)
5201 unsigned long flags;
5203 spin_lock_irqsave(&ha->work_lock, flags);
5204 list_add_tail(&e->list, &ha->work_list);
5205 spin_unlock_irqrestore(&ha->work_lock, flags);
5206 qla4xxx_wake_dpc(ha);
5209 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5210 enum iscsi_host_event_code aen_code,
5211 uint32_t data_size, uint8_t *data)
5213 struct qla4_work_evt *e;
5215 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5219 e->u.aen.code = aen_code;
5220 e->u.aen.data_size = data_size;
5221 memcpy(e->u.aen.data, data, data_size);
5223 qla4xxx_post_work(ha, e);
5228 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5229 uint32_t status, uint32_t pid,
5230 uint32_t data_size, uint8_t *data)
5232 struct qla4_work_evt *e;
5234 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5238 e->u.ping.status = status;
5239 e->u.ping.pid = pid;
5240 e->u.ping.data_size = data_size;
5241 memcpy(e->u.ping.data, data, data_size);
5243 qla4xxx_post_work(ha, e);
5248 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5250 struct qla4_work_evt *e, *tmp;
5251 unsigned long flags;
5254 spin_lock_irqsave(&ha->work_lock, flags);
5255 list_splice_init(&ha->work_list, &work);
5256 spin_unlock_irqrestore(&ha->work_lock, flags);
5258 list_for_each_entry_safe(e, tmp, &work, list) {
5259 list_del_init(&e->list);
5262 case QLA4_EVENT_AEN:
5263 iscsi_post_host_event(ha->host_no,
5264 &qla4xxx_iscsi_transport,
5269 case QLA4_EVENT_PING_STATUS:
5270 iscsi_ping_comp_event(ha->host_no,
5271 &qla4xxx_iscsi_transport,
5274 e->u.ping.data_size,
5278 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5279 "supported", e->type);
5286 * qla4xxx_do_dpc - dpc routine
5287 * @data: in our case pointer to adapter structure
5289 * This routine is a task that is schedule by the interrupt handler
5290 * to perform the background processing for interrupts. We put it
5291 * on a task queue that is consumed whenever the scheduler runs; that's
5292 * so you can do anything (i.e. put the process to sleep etc). In fact,
5293 * the mid-level tries to sleep when it reaches the driver threshold
5294 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5296 static void qla4xxx_do_dpc(struct work_struct *work)
5298 struct scsi_qla_host *ha =
5299 container_of(work, struct scsi_qla_host, dpc_work);
5300 int status = QLA_ERROR;
5302 DEBUG2(ql4_printk(KERN_INFO, ha,
5303 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5304 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5306 /* Initialization not yet finished. Don't do anything yet. */
5307 if (!test_bit(AF_INIT_DONE, &ha->flags))
5310 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5311 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5312 ha->host_no, __func__, ha->flags));
5316 /* post events to application */
5317 qla4xxx_do_work(ha);
5319 if (is_qla80XX(ha)) {
5320 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5321 if (is_qla8032(ha) || is_qla8042(ha)) {
5322 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5324 /* disable pause frame for ISP83xx */
5325 qla4_83xx_disable_pause(ha);
5328 ha->isp_ops->idc_lock(ha);
5329 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5330 QLA8XXX_DEV_FAILED);
5331 ha->isp_ops->idc_unlock(ha);
5332 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5333 qla4_8xxx_device_state_handler(ha);
5336 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5337 if (is_qla8042(ha)) {
5338 if (ha->idc_info.info2 &
5339 ENABLE_INTERNAL_LOOPBACK) {
5340 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5342 status = qla4_84xx_config_acb(ha,
5343 ACB_CONFIG_DISABLE);
5344 if (status != QLA_SUCCESS) {
5345 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5350 qla4_83xx_post_idc_ack(ha);
5351 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5354 if (is_qla8042(ha) &&
5355 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5356 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5358 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5360 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5363 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5366 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5367 qla4_8xxx_need_qsnt_handler(ha);
5371 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5372 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5373 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5374 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5375 if ((is_qla8022(ha) && ql4xdontresethba) ||
5376 ((is_qla8032(ha) || is_qla8042(ha)) &&
5377 qla4_83xx_idc_dontreset(ha))) {
5378 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5379 ha->host_no, __func__));
5380 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5381 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5382 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5383 goto dpc_post_reset_ha;
5385 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5386 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5387 qla4xxx_recover_adapter(ha);
5389 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5390 uint8_t wait_time = RESET_INTR_TOV;
5392 while ((readw(&ha->reg->ctrl_status) &
5393 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5394 if (--wait_time == 0)
5399 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5400 "bit not cleared-- resetting\n",
5401 ha->host_no, __func__));
5402 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5403 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5404 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5405 status = qla4xxx_recover_adapter(ha);
5407 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5408 if (status == QLA_SUCCESS)
5409 ha->isp_ops->enable_intrs(ha);
5414 /* ---- process AEN? --- */
5415 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5416 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5418 /* ---- Get DHCP IP Address? --- */
5419 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5420 qla4xxx_get_dhcp_ip_address(ha);
5422 /* ---- relogin device? --- */
5423 if (adapter_up(ha) &&
5424 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5425 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5428 /* ---- link change? --- */
5429 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5430 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5431 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5432 /* ---- link down? --- */
5433 qla4xxx_mark_all_devices_missing(ha);
5435 /* ---- link up? --- *
5436 * F/W will auto login to all devices ONLY ONCE after
5437 * link up during driver initialization and runtime
5438 * fatal error recovery. Therefore, the driver must
5439 * manually relogin to devices when recovering from
5440 * connection failures, logouts, expired KATO, etc. */
5441 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5442 qla4xxx_build_ddb_list(ha, ha->is_reset);
5443 iscsi_host_for_each_session(ha->host,
5444 qla4xxx_login_flash_ddb);
5446 qla4xxx_relogin_all_devices(ha);
5449 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5450 if (qla4xxx_sysfs_ddb_export(ha))
5451 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5457 * qla4xxx_free_adapter - release the adapter
5458 * @ha: pointer to adapter structure
5460 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5462 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5464 /* Turn-off interrupts on the card. */
5465 ha->isp_ops->disable_intrs(ha);
5467 if (is_qla40XX(ha)) {
5468 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5469 &ha->reg->ctrl_status);
5470 readl(&ha->reg->ctrl_status);
5471 } else if (is_qla8022(ha)) {
5472 writel(0, &ha->qla4_82xx_reg->host_int);
5473 readl(&ha->qla4_82xx_reg->host_int);
5474 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5475 writel(0, &ha->qla4_83xx_reg->risc_intr);
5476 readl(&ha->qla4_83xx_reg->risc_intr);
5479 /* Remove timer thread, if present */
5480 if (ha->timer_active)
5481 qla4xxx_stop_timer(ha);
5483 /* Kill the kernel thread for this host */
5485 destroy_workqueue(ha->dpc_thread);
5487 /* Kill the kernel thread for this host */
5489 destroy_workqueue(ha->task_wq);
5491 /* Put firmware in known state */
5492 ha->isp_ops->reset_firmware(ha);
5494 if (is_qla80XX(ha)) {
5495 ha->isp_ops->idc_lock(ha);
5496 qla4_8xxx_clear_drv_active(ha);
5497 ha->isp_ops->idc_unlock(ha);
5500 /* Detach interrupts */
5501 qla4xxx_free_irqs(ha);
5503 /* free extra memory */
5504 qla4xxx_mem_free(ha);
5507 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5510 unsigned long mem_base, mem_len, db_base, db_len;
5511 struct pci_dev *pdev = ha->pdev;
5513 status = pci_request_regions(pdev, DRIVER_NAME);
5516 "scsi(%ld) Failed to reserve PIO regions (%s) "
5517 "status=%d\n", ha->host_no, pci_name(pdev), status);
5518 goto iospace_error_exit;
5521 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5522 __func__, pdev->revision));
5523 ha->revision_id = pdev->revision;
5525 /* remap phys address */
5526 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5527 mem_len = pci_resource_len(pdev, 0);
5528 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5529 __func__, mem_base, mem_len));
5531 /* mapping of pcibase pointer */
5532 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5533 if (!ha->nx_pcibase) {
5535 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5536 pci_release_regions(ha->pdev);
5537 goto iospace_error_exit;
5540 /* Mapping of IO base pointer, door bell read and write pointer */
5542 /* mapping of IO base pointer */
5543 if (is_qla8022(ha)) {
5544 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5545 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5546 (ha->pdev->devfn << 11));
5547 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5548 QLA82XX_CAM_RAM_DB2);
5549 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5550 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5551 ((uint8_t *)ha->nx_pcibase);
5554 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5555 db_len = pci_resource_len(pdev, 4);
5563 * qla4xxx_iospace_config - maps registers
5564 * @ha: pointer to adapter structure
5566 * This routines maps HBA's registers from the pci address space
5567 * into the kernel virtual address space for memory mapped i/o.
5569 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5571 unsigned long pio, pio_len, pio_flags;
5572 unsigned long mmio, mmio_len, mmio_flags;
5574 pio = pci_resource_start(ha->pdev, 0);
5575 pio_len = pci_resource_len(ha->pdev, 0);
5576 pio_flags = pci_resource_flags(ha->pdev, 0);
5577 if (pio_flags & IORESOURCE_IO) {
5578 if (pio_len < MIN_IOBASE_LEN) {
5579 ql4_printk(KERN_WARNING, ha,
5580 "Invalid PCI I/O region size\n");
5584 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5588 /* Use MMIO operations for all accesses. */
5589 mmio = pci_resource_start(ha->pdev, 1);
5590 mmio_len = pci_resource_len(ha->pdev, 1);
5591 mmio_flags = pci_resource_flags(ha->pdev, 1);
5593 if (!(mmio_flags & IORESOURCE_MEM)) {
5594 ql4_printk(KERN_ERR, ha,
5595 "region #0 not an MMIO resource, aborting\n");
5597 goto iospace_error_exit;
5600 if (mmio_len < MIN_IOBASE_LEN) {
5601 ql4_printk(KERN_ERR, ha,
5602 "Invalid PCI mem region size, aborting\n");
5603 goto iospace_error_exit;
5606 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5607 ql4_printk(KERN_WARNING, ha,
5608 "Failed to reserve PIO/MMIO regions\n");
5610 goto iospace_error_exit;
5613 ha->pio_address = pio;
5614 ha->pio_length = pio_len;
5615 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5617 ql4_printk(KERN_ERR, ha,
5618 "cannot remap MMIO, aborting\n");
5620 goto iospace_error_exit;
5629 static struct isp_operations qla4xxx_isp_ops = {
5630 .iospace_config = qla4xxx_iospace_config,
5631 .pci_config = qla4xxx_pci_config,
5632 .disable_intrs = qla4xxx_disable_intrs,
5633 .enable_intrs = qla4xxx_enable_intrs,
5634 .start_firmware = qla4xxx_start_firmware,
5635 .intr_handler = qla4xxx_intr_handler,
5636 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5637 .reset_chip = qla4xxx_soft_reset,
5638 .reset_firmware = qla4xxx_hw_reset,
5639 .queue_iocb = qla4xxx_queue_iocb,
5640 .complete_iocb = qla4xxx_complete_iocb,
5641 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5642 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5643 .get_sys_info = qla4xxx_get_sys_info,
5644 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5645 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5648 static struct isp_operations qla4_82xx_isp_ops = {
5649 .iospace_config = qla4_8xxx_iospace_config,
5650 .pci_config = qla4_8xxx_pci_config,
5651 .disable_intrs = qla4_82xx_disable_intrs,
5652 .enable_intrs = qla4_82xx_enable_intrs,
5653 .start_firmware = qla4_8xxx_load_risc,
5654 .restart_firmware = qla4_82xx_try_start_fw,
5655 .intr_handler = qla4_82xx_intr_handler,
5656 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5657 .need_reset = qla4_8xxx_need_reset,
5658 .reset_chip = qla4_82xx_isp_reset,
5659 .reset_firmware = qla4_8xxx_stop_firmware,
5660 .queue_iocb = qla4_82xx_queue_iocb,
5661 .complete_iocb = qla4_82xx_complete_iocb,
5662 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5663 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5664 .get_sys_info = qla4_8xxx_get_sys_info,
5665 .rd_reg_direct = qla4_82xx_rd_32,
5666 .wr_reg_direct = qla4_82xx_wr_32,
5667 .rd_reg_indirect = qla4_82xx_md_rd_32,
5668 .wr_reg_indirect = qla4_82xx_md_wr_32,
5669 .idc_lock = qla4_82xx_idc_lock,
5670 .idc_unlock = qla4_82xx_idc_unlock,
5671 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5672 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5673 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5676 static struct isp_operations qla4_83xx_isp_ops = {
5677 .iospace_config = qla4_8xxx_iospace_config,
5678 .pci_config = qla4_8xxx_pci_config,
5679 .disable_intrs = qla4_83xx_disable_intrs,
5680 .enable_intrs = qla4_83xx_enable_intrs,
5681 .start_firmware = qla4_8xxx_load_risc,
5682 .restart_firmware = qla4_83xx_start_firmware,
5683 .intr_handler = qla4_83xx_intr_handler,
5684 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5685 .need_reset = qla4_8xxx_need_reset,
5686 .reset_chip = qla4_83xx_isp_reset,
5687 .reset_firmware = qla4_8xxx_stop_firmware,
5688 .queue_iocb = qla4_83xx_queue_iocb,
5689 .complete_iocb = qla4_83xx_complete_iocb,
5690 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5691 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5692 .get_sys_info = qla4_8xxx_get_sys_info,
5693 .rd_reg_direct = qla4_83xx_rd_reg,
5694 .wr_reg_direct = qla4_83xx_wr_reg,
5695 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5696 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5697 .idc_lock = qla4_83xx_drv_lock,
5698 .idc_unlock = qla4_83xx_drv_unlock,
5699 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5700 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5701 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5704 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5706 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5709 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5711 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5714 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5716 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5719 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5721 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5724 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5726 struct scsi_qla_host *ha = data;
5731 case ISCSI_BOOT_ETH_FLAGS:
5732 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5734 case ISCSI_BOOT_ETH_INDEX:
5735 rc = sprintf(str, "0\n");
5737 case ISCSI_BOOT_ETH_MAC:
5738 rc = sysfs_format_mac(str, ha->my_mac,
5748 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5753 case ISCSI_BOOT_ETH_FLAGS:
5754 case ISCSI_BOOT_ETH_MAC:
5755 case ISCSI_BOOT_ETH_INDEX:
5765 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5767 struct scsi_qla_host *ha = data;
5772 case ISCSI_BOOT_INI_INITIATOR_NAME:
5773 rc = sprintf(str, "%s\n", ha->name_string);
5782 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5787 case ISCSI_BOOT_INI_INITIATOR_NAME:
5798 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5801 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5806 case ISCSI_BOOT_TGT_NAME:
5807 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5809 case ISCSI_BOOT_TGT_IP_ADDR:
5810 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5811 rc = sprintf(buf, "%pI4\n",
5812 &boot_conn->dest_ipaddr.ip_address);
5814 rc = sprintf(str, "%pI6\n",
5815 &boot_conn->dest_ipaddr.ip_address);
5817 case ISCSI_BOOT_TGT_PORT:
5818 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5820 case ISCSI_BOOT_TGT_CHAP_NAME:
5821 rc = sprintf(str, "%.*s\n",
5822 boot_conn->chap.target_chap_name_length,
5823 (char *)&boot_conn->chap.target_chap_name);
5825 case ISCSI_BOOT_TGT_CHAP_SECRET:
5826 rc = sprintf(str, "%.*s\n",
5827 boot_conn->chap.target_secret_length,
5828 (char *)&boot_conn->chap.target_secret);
5830 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5831 rc = sprintf(str, "%.*s\n",
5832 boot_conn->chap.intr_chap_name_length,
5833 (char *)&boot_conn->chap.intr_chap_name);
5835 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5836 rc = sprintf(str, "%.*s\n",
5837 boot_conn->chap.intr_secret_length,
5838 (char *)&boot_conn->chap.intr_secret);
5840 case ISCSI_BOOT_TGT_FLAGS:
5841 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5843 case ISCSI_BOOT_TGT_NIC_ASSOC:
5844 rc = sprintf(str, "0\n");
5853 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5855 struct scsi_qla_host *ha = data;
5856 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5858 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5861 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5863 struct scsi_qla_host *ha = data;
5864 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5866 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5869 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5874 case ISCSI_BOOT_TGT_NAME:
5875 case ISCSI_BOOT_TGT_IP_ADDR:
5876 case ISCSI_BOOT_TGT_PORT:
5877 case ISCSI_BOOT_TGT_CHAP_NAME:
5878 case ISCSI_BOOT_TGT_CHAP_SECRET:
5879 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5880 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5881 case ISCSI_BOOT_TGT_NIC_ASSOC:
5882 case ISCSI_BOOT_TGT_FLAGS:
5892 static void qla4xxx_boot_release(void *data)
5894 struct scsi_qla_host *ha = data;
5896 scsi_host_put(ha->host);
5899 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5902 uint32_t addr, pri_addr, sec_addr;
5906 uint8_t *buf = NULL;
5907 size_t size = 13 * sizeof(uint8_t);
5908 int ret = QLA_SUCCESS;
5910 func_num = PCI_FUNC(ha->pdev->devfn);
5912 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5913 __func__, ha->pdev->device, func_num);
5915 if (is_qla40XX(ha)) {
5916 if (func_num == 1) {
5917 addr = NVRAM_PORT0_BOOT_MODE;
5918 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5919 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5920 } else if (func_num == 3) {
5921 addr = NVRAM_PORT1_BOOT_MODE;
5922 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5923 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5926 goto exit_boot_info;
5929 /* Check Boot Mode */
5930 val = rd_nvram_byte(ha, addr);
5931 if (!(val & 0x07)) {
5932 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5933 "options : 0x%x\n", __func__, val));
5935 goto exit_boot_info;
5938 /* get primary valid target index */
5939 val = rd_nvram_byte(ha, pri_addr);
5941 ddb_index[0] = (val & 0x7f);
5943 /* get secondary valid target index */
5944 val = rd_nvram_byte(ha, sec_addr);
5946 ddb_index[1] = (val & 0x7f);
5947 goto exit_boot_info;
5948 } else if (is_qla80XX(ha)) {
5949 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5950 &buf_dma, GFP_KERNEL);
5952 DEBUG2(ql4_printk(KERN_ERR, ha,
5953 "%s: Unable to allocate dma buffer\n",
5956 goto exit_boot_info;
5959 if (ha->port_num == 0)
5960 offset = BOOT_PARAM_OFFSET_PORT0;
5961 else if (ha->port_num == 1)
5962 offset = BOOT_PARAM_OFFSET_PORT1;
5965 goto exit_boot_info_free;
5967 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5969 if (qla4xxx_get_flash(ha, buf_dma, addr,
5970 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5971 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5972 " failed\n", ha->host_no, __func__));
5974 goto exit_boot_info_free;
5976 /* Check Boot Mode */
5977 if (!(buf[1] & 0x07)) {
5978 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5979 " : 0x%x\n", buf[1]));
5981 goto exit_boot_info_free;
5984 /* get primary valid target index */
5986 ddb_index[0] = buf[2] & 0x7f;
5988 /* get secondary valid target index */
5989 if (buf[11] & BIT_7)
5990 ddb_index[1] = buf[11] & 0x7f;
5993 goto exit_boot_info;
5996 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5997 " target ID %d\n", __func__, ddb_index[0],
6000 exit_boot_info_free:
6001 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
6003 ha->pri_ddb_idx = ddb_index[0];
6004 ha->sec_ddb_idx = ddb_index[1];
6009 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
6010 * @ha: pointer to adapter structure
6011 * @username: CHAP username to be returned
6012 * @password: CHAP password to be returned
6014 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6015 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6016 * So from the CHAP cache find the first BIDI CHAP entry and set it
6017 * to the boot record in sysfs.
6019 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6022 int i, ret = -EINVAL;
6023 int max_chap_entries = 0;
6024 struct ql4_chap_table *chap_table;
6027 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6028 sizeof(struct ql4_chap_table);
6030 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6032 if (!ha->chap_list) {
6033 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6037 mutex_lock(&ha->chap_sem);
6038 for (i = 0; i < max_chap_entries; i++) {
6039 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6040 if (chap_table->cookie !=
6041 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6045 if (chap_table->flags & BIT_7) /* local */
6048 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6051 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6052 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6056 mutex_unlock(&ha->chap_sem);
6062 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6063 struct ql4_boot_session_info *boot_sess,
6066 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6067 struct dev_db_entry *fw_ddb_entry;
6068 dma_addr_t fw_ddb_entry_dma;
6071 int ret = QLA_SUCCESS;
6073 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6074 &fw_ddb_entry_dma, GFP_KERNEL);
6075 if (!fw_ddb_entry) {
6076 DEBUG2(ql4_printk(KERN_ERR, ha,
6077 "%s: Unable to allocate dma buffer.\n",
6083 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6084 fw_ddb_entry_dma, ddb_index)) {
6085 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6086 "index [%d]\n", __func__, ddb_index));
6088 goto exit_boot_target;
6091 /* Update target name and IP from DDB */
6092 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6093 min(sizeof(boot_sess->target_name),
6094 sizeof(fw_ddb_entry->iscsi_name)));
6096 options = le16_to_cpu(fw_ddb_entry->options);
6097 if (options & DDB_OPT_IPV6_DEVICE) {
6098 memcpy(&boot_conn->dest_ipaddr.ip_address,
6099 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6101 boot_conn->dest_ipaddr.ip_type = 0x1;
6102 memcpy(&boot_conn->dest_ipaddr.ip_address,
6103 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6106 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6108 /* update chap information */
6109 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6111 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6113 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6115 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6117 (char *)&boot_conn->chap.target_secret,
6120 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6122 goto exit_boot_target;
6125 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6126 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6129 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6131 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6133 ret = qla4xxx_get_bidi_chap(ha,
6134 (char *)&boot_conn->chap.intr_chap_name,
6135 (char *)&boot_conn->chap.intr_secret);
6138 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6140 goto exit_boot_target;
6143 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6144 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6148 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6149 fw_ddb_entry, fw_ddb_entry_dma);
6153 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6155 uint16_t ddb_index[2];
6156 int ret = QLA_ERROR;
6159 memset(ddb_index, 0, sizeof(ddb_index));
6160 ddb_index[0] = 0xffff;
6161 ddb_index[1] = 0xffff;
6162 ret = get_fw_boot_info(ha, ddb_index);
6163 if (ret != QLA_SUCCESS) {
6164 DEBUG2(ql4_printk(KERN_INFO, ha,
6165 "%s: No boot target configured.\n", __func__));
6169 if (ql4xdisablesysfsboot)
6172 if (ddb_index[0] == 0xffff)
6175 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6177 if (rval != QLA_SUCCESS) {
6178 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6179 "configured\n", __func__));
6184 if (ddb_index[1] == 0xffff)
6185 goto exit_get_boot_info;
6187 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6189 if (rval != QLA_SUCCESS) {
6190 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6191 " configured\n", __func__));
6199 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6201 struct iscsi_boot_kobj *boot_kobj;
6203 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6206 if (ql4xdisablesysfsboot) {
6207 ql4_printk(KERN_INFO, ha,
6208 "%s: syfsboot disabled - driver will trigger login "
6209 "and publish session for discovery .\n", __func__);
6214 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6218 if (!scsi_host_get(ha->host))
6220 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6221 qla4xxx_show_boot_tgt_pri_info,
6222 qla4xxx_tgt_get_attr_visibility,
6223 qla4xxx_boot_release);
6227 if (!scsi_host_get(ha->host))
6229 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6230 qla4xxx_show_boot_tgt_sec_info,
6231 qla4xxx_tgt_get_attr_visibility,
6232 qla4xxx_boot_release);
6236 if (!scsi_host_get(ha->host))
6238 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6239 qla4xxx_show_boot_ini_info,
6240 qla4xxx_ini_get_attr_visibility,
6241 qla4xxx_boot_release);
6245 if (!scsi_host_get(ha->host))
6247 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6248 qla4xxx_show_boot_eth_info,
6249 qla4xxx_eth_get_attr_visibility,
6250 qla4xxx_boot_release);
6257 scsi_host_put(ha->host);
6259 iscsi_boot_destroy_kset(ha->boot_kset);
6264 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6265 struct ql4_tuple_ddb *tddb)
6267 struct scsi_qla_host *ha;
6268 struct iscsi_cls_session *cls_sess;
6269 struct iscsi_cls_conn *cls_conn;
6270 struct iscsi_session *sess;
6271 struct iscsi_conn *conn;
6273 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6275 cls_sess = ddb_entry->sess;
6276 sess = cls_sess->dd_data;
6277 cls_conn = ddb_entry->conn;
6278 conn = cls_conn->dd_data;
6280 tddb->tpgt = sess->tpgt;
6281 tddb->port = conn->persistent_port;
6282 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6283 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6286 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6287 struct ql4_tuple_ddb *tddb,
6288 uint8_t *flash_isid)
6290 uint16_t options = 0;
6292 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6293 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6294 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6296 options = le16_to_cpu(fw_ddb_entry->options);
6297 if (options & DDB_OPT_IPV6_DEVICE)
6298 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6300 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6302 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6304 if (flash_isid == NULL)
6305 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6306 sizeof(tddb->isid));
6308 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6311 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6312 struct ql4_tuple_ddb *old_tddb,
6313 struct ql4_tuple_ddb *new_tddb,
6314 uint8_t is_isid_compare)
6316 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6319 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6322 if (old_tddb->port != new_tddb->port)
6325 /* For multi sessions, driver generates the ISID, so do not compare
6326 * ISID in reset path since it would be a comparison between the
6327 * driver generated ISID and firmware generated ISID. This could
6328 * lead to adding duplicated DDBs in the list as driver generated
6329 * ISID would not match firmware generated ISID.
6331 if (is_isid_compare) {
6332 DEBUG2(ql4_printk(KERN_INFO, ha,
6333 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6334 __func__, old_tddb->isid, new_tddb->isid));
6336 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6337 sizeof(old_tddb->isid)))
6341 DEBUG2(ql4_printk(KERN_INFO, ha,
6342 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6343 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6344 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6345 new_tddb->ip_addr, new_tddb->iscsi_name));
6350 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6351 struct dev_db_entry *fw_ddb_entry,
6354 struct ddb_entry *ddb_entry;
6355 struct ql4_tuple_ddb *fw_tddb = NULL;
6356 struct ql4_tuple_ddb *tmp_tddb = NULL;
6358 int ret = QLA_ERROR;
6360 fw_tddb = vzalloc(sizeof(*fw_tddb));
6362 DEBUG2(ql4_printk(KERN_WARNING, ha,
6363 "Memory Allocation failed.\n"));
6368 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6370 DEBUG2(ql4_printk(KERN_WARNING, ha,
6371 "Memory Allocation failed.\n"));
6376 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6378 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6379 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6380 if (ddb_entry == NULL)
6383 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6384 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6385 ret = QLA_SUCCESS; /* found */
6401 * qla4xxx_check_existing_isid - check if target with same isid exist
6403 * @list_nt: list of target
6404 * @isid: isid to check
6406 * This routine return QLA_SUCCESS if target with same isid exist
6408 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6410 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6411 struct dev_db_entry *fw_ddb_entry;
6413 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6414 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6416 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6417 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6425 * qla4xxx_update_isid - compare ddbs and updated isid
6426 * @ha: Pointer to host adapter structure.
6427 * @list_nt: list of nt target
6428 * @fw_ddb_entry: firmware ddb entry
6430 * This routine update isid if ddbs have same iqn, same isid and
6431 * different IP addr.
6432 * Return QLA_SUCCESS if isid is updated.
6434 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6435 struct list_head *list_nt,
6436 struct dev_db_entry *fw_ddb_entry)
6438 uint8_t base_value, i;
6440 base_value = fw_ddb_entry->isid[1] & 0x1f;
6441 for (i = 0; i < 8; i++) {
6442 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6443 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6447 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6454 * qla4xxx_should_update_isid - check if isid need to update
6455 * @ha: Pointer to host adapter structure.
6456 * @old_tddb: ddb tuple
6457 * @new_tddb: ddb tuple
6459 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6462 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6463 struct ql4_tuple_ddb *old_tddb,
6464 struct ql4_tuple_ddb *new_tddb)
6466 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6468 if (old_tddb->port == new_tddb->port)
6472 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6476 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6477 sizeof(old_tddb->isid)))
6478 /* different isid */
6485 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6486 * @ha: Pointer to host adapter structure.
6487 * @list_nt: list of nt target.
6488 * @fw_ddb_entry: firmware ddb entry.
6490 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6491 * duplicate ddb in list_nt.
6492 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6493 * Note: This function also update isid of DDB if required.
6496 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6497 struct list_head *list_nt,
6498 struct dev_db_entry *fw_ddb_entry)
6500 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6501 struct ql4_tuple_ddb *fw_tddb = NULL;
6502 struct ql4_tuple_ddb *tmp_tddb = NULL;
6503 int rval, ret = QLA_ERROR;
6505 fw_tddb = vzalloc(sizeof(*fw_tddb));
6507 DEBUG2(ql4_printk(KERN_WARNING, ha,
6508 "Memory Allocation failed.\n"));
6513 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6515 DEBUG2(ql4_printk(KERN_WARNING, ha,
6516 "Memory Allocation failed.\n"));
6521 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6523 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6524 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6525 nt_ddb_idx->flash_isid);
6526 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6527 /* found duplicate ddb */
6528 if (ret == QLA_SUCCESS)
6532 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6533 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6535 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6536 if (ret == QLA_SUCCESS) {
6537 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6538 if (rval == QLA_SUCCESS)
6555 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6557 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6559 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6560 list_del_init(&ddb_idx->list);
6565 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6566 struct dev_db_entry *fw_ddb_entry)
6568 struct iscsi_endpoint *ep;
6569 struct sockaddr_in *addr;
6570 struct sockaddr_in6 *addr6;
6571 struct sockaddr *t_addr;
6572 struct sockaddr_storage *dst_addr;
6575 /* TODO: need to destroy on unload iscsi_endpoint*/
6576 dst_addr = vmalloc(sizeof(*dst_addr));
6580 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6581 t_addr = (struct sockaddr *)dst_addr;
6582 t_addr->sa_family = AF_INET6;
6583 addr6 = (struct sockaddr_in6 *)dst_addr;
6584 ip = (char *)&addr6->sin6_addr;
6585 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6586 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6589 t_addr = (struct sockaddr *)dst_addr;
6590 t_addr->sa_family = AF_INET;
6591 addr = (struct sockaddr_in *)dst_addr;
6592 ip = (char *)&addr->sin_addr;
6593 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6594 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6597 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6602 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6604 if (ql4xdisablesysfsboot)
6606 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6611 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6612 struct ddb_entry *ddb_entry,
6615 uint16_t def_timeout;
6617 ddb_entry->ddb_type = FLASH_DDB;
6618 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6619 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6621 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6622 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6623 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6625 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6626 atomic_set(&ddb_entry->relogin_timer, 0);
6627 atomic_set(&ddb_entry->relogin_retry_count, 0);
6628 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6629 ddb_entry->default_relogin_timeout =
6630 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6631 def_timeout : LOGIN_TOV;
6632 ddb_entry->default_time2wait =
6633 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6635 if (ql4xdisablesysfsboot &&
6636 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6637 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6640 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6643 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6644 uint32_t sts[MBOX_REG_COUNT];
6646 unsigned long wtime;
6649 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6651 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6652 if (ip_idx[idx] == -1)
6655 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6657 if (ret == QLA_ERROR) {
6662 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6664 DEBUG2(ql4_printk(KERN_INFO, ha,
6665 "Waiting for IP state for idx = %d, state = 0x%x\n",
6666 ip_idx[idx], ip_state));
6667 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6668 ip_state == IP_ADDRSTATE_INVALID ||
6669 ip_state == IP_ADDRSTATE_PREFERRED ||
6670 ip_state == IP_ADDRSTATE_DEPRICATED ||
6671 ip_state == IP_ADDRSTATE_DISABLING)
6675 /* Break if all IP states checked */
6676 if ((ip_idx[0] == -1) &&
6677 (ip_idx[1] == -1) &&
6678 (ip_idx[2] == -1) &&
6681 schedule_timeout_uninterruptible(HZ);
6682 } while (time_after(wtime, jiffies));
6685 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6686 struct dev_db_entry *flash_ddb_entry)
6688 uint16_t options = 0;
6689 size_t ip_len = IP_ADDR_LEN;
6691 options = le16_to_cpu(fw_ddb_entry->options);
6692 if (options & DDB_OPT_IPV6_DEVICE)
6693 ip_len = IPv6_ADDR_LEN;
6695 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6698 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6699 sizeof(fw_ddb_entry->isid)))
6702 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6703 sizeof(fw_ddb_entry->port)))
6709 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6710 struct dev_db_entry *fw_ddb_entry,
6711 uint32_t fw_idx, uint32_t *flash_index)
6713 struct dev_db_entry *flash_ddb_entry;
6714 dma_addr_t flash_ddb_entry_dma;
6717 int ret = QLA_ERROR, status;
6719 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6722 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6723 &flash_ddb_entry_dma);
6724 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6725 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6726 goto exit_find_st_idx;
6729 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6730 flash_ddb_entry_dma, fw_idx);
6731 if (status == QLA_SUCCESS) {
6732 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6733 if (status == QLA_SUCCESS) {
6734 *flash_index = fw_idx;
6736 goto exit_find_st_idx;
6740 for (idx = 0; idx < max_ddbs; idx++) {
6741 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6742 flash_ddb_entry_dma, idx);
6743 if (status == QLA_ERROR)
6746 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6747 if (status == QLA_SUCCESS) {
6750 goto exit_find_st_idx;
6754 if (idx == max_ddbs)
6755 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6759 if (flash_ddb_entry)
6760 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6761 flash_ddb_entry_dma);
6766 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6767 struct list_head *list_st)
6769 struct qla_ddb_index *st_ddb_idx;
6772 struct dev_db_entry *fw_ddb_entry;
6773 dma_addr_t fw_ddb_dma;
6775 uint32_t idx = 0, next_idx = 0;
6776 uint32_t state = 0, conn_err = 0;
6777 uint32_t flash_index = -1;
6778 uint16_t conn_id = 0;
6780 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6782 if (fw_ddb_entry == NULL) {
6783 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6787 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6789 fw_idx_size = sizeof(struct qla_ddb_index);
6791 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6792 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6793 NULL, &next_idx, &state,
6794 &conn_err, NULL, &conn_id);
6795 if (ret == QLA_ERROR)
6798 /* Ignore DDB if invalid state (unassigned) */
6799 if (state == DDB_DS_UNASSIGNED)
6800 goto continue_next_st;
6802 /* Check if ST, add to the list_st */
6803 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6804 goto continue_next_st;
6806 st_ddb_idx = vzalloc(fw_idx_size);
6810 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6812 if (ret == QLA_ERROR) {
6813 ql4_printk(KERN_ERR, ha,
6814 "No flash entry for ST at idx [%d]\n", idx);
6815 st_ddb_idx->flash_ddb_idx = idx;
6817 ql4_printk(KERN_INFO, ha,
6818 "ST at idx [%d] is stored at flash [%d]\n",
6820 st_ddb_idx->flash_ddb_idx = flash_index;
6823 st_ddb_idx->fw_ddb_idx = idx;
6825 list_add_tail(&st_ddb_idx->list, list_st);
6833 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6837 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6838 * @ha: pointer to adapter structure
6839 * @list_ddb: List from which failed ddb to be removed
6841 * Iterate over the list of DDBs and find and remove DDBs that are either in
6842 * no connection active state or failed state
6844 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6845 struct list_head *list_ddb)
6847 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6848 uint32_t next_idx = 0;
6849 uint32_t state = 0, conn_err = 0;
6852 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6853 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6854 NULL, 0, NULL, &next_idx, &state,
6855 &conn_err, NULL, NULL);
6856 if (ret == QLA_ERROR)
6859 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6860 state == DDB_DS_SESSION_FAILED) {
6861 list_del_init(&ddb_idx->list);
6867 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6868 struct ddb_entry *ddb_entry,
6869 struct dev_db_entry *fw_ddb_entry)
6871 struct iscsi_cls_session *cls_sess;
6872 struct iscsi_session *sess;
6873 uint32_t max_ddbs = 0;
6874 uint16_t ddb_link = -1;
6876 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6879 cls_sess = ddb_entry->sess;
6880 sess = cls_sess->dd_data;
6882 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6883 if (ddb_link < max_ddbs)
6884 sess->discovery_parent_idx = ddb_link;
6886 sess->discovery_parent_idx = DDB_NO_LINK;
6889 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6890 struct dev_db_entry *fw_ddb_entry,
6891 int is_reset, uint16_t idx)
6893 struct iscsi_cls_session *cls_sess;
6894 struct iscsi_session *sess;
6895 struct iscsi_cls_conn *cls_conn;
6896 struct iscsi_endpoint *ep;
6897 uint16_t cmds_max = 32;
6898 uint16_t conn_id = 0;
6899 uint32_t initial_cmdsn = 0;
6900 int ret = QLA_SUCCESS;
6902 struct ddb_entry *ddb_entry = NULL;
6904 /* Create session object, with INVALID_ENTRY,
6905 * the targer_id would get set when we issue the login
6907 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6908 cmds_max, sizeof(struct ddb_entry),
6909 sizeof(struct ql4_task_data),
6910 initial_cmdsn, INVALID_ENTRY);
6917 * so calling module_put function to decrement the
6920 module_put(qla4xxx_iscsi_transport.owner);
6921 sess = cls_sess->dd_data;
6922 ddb_entry = sess->dd_data;
6923 ddb_entry->sess = cls_sess;
6925 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6926 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6927 sizeof(struct dev_db_entry));
6929 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6931 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6938 ddb_entry->conn = cls_conn;
6940 /* Setup ep, for displaying attributes in sysfs */
6941 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6943 ep->conn = cls_conn;
6946 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6951 /* Update sess/conn params */
6952 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6953 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6955 if (is_reset == RESET_ADAPTER) {
6956 iscsi_block_session(cls_sess);
6957 /* Use the relogin path to discover new devices
6958 * by short-circuting the logic of setting
6959 * timer to relogin - instead set the flags
6960 * to initiate login right away.
6962 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6963 set_bit(DF_RELOGIN, &ddb_entry->flags);
6970 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6971 struct list_head *list_ddb,
6972 struct dev_db_entry *fw_ddb_entry)
6974 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6977 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6979 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6980 if (ddb_idx->fw_ddb_idx == ddb_link) {
6981 DEBUG2(ql4_printk(KERN_INFO, ha,
6982 "Updating NT parent idx from [%d] to [%d]\n",
6983 ddb_link, ddb_idx->flash_ddb_idx));
6984 fw_ddb_entry->ddb_link =
6985 cpu_to_le16(ddb_idx->flash_ddb_idx);
6991 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6992 struct list_head *list_nt,
6993 struct list_head *list_st,
6996 struct dev_db_entry *fw_ddb_entry;
6997 struct ddb_entry *ddb_entry = NULL;
6998 dma_addr_t fw_ddb_dma;
7002 uint32_t idx = 0, next_idx = 0;
7003 uint32_t state = 0, conn_err = 0;
7004 uint32_t ddb_idx = -1;
7005 uint16_t conn_id = 0;
7006 uint16_t ddb_link = -1;
7007 struct qla_ddb_index *nt_ddb_idx;
7009 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7011 if (fw_ddb_entry == NULL) {
7012 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7015 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7017 fw_idx_size = sizeof(struct qla_ddb_index);
7019 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7020 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7021 NULL, &next_idx, &state,
7022 &conn_err, NULL, &conn_id);
7023 if (ret == QLA_ERROR)
7026 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7027 goto continue_next_nt;
7029 /* Check if NT, then add to list it */
7030 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7031 goto continue_next_nt;
7033 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7034 if (ddb_link < max_ddbs)
7035 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7037 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7038 state == DDB_DS_SESSION_FAILED) &&
7039 (is_reset == INIT_ADAPTER))
7040 goto continue_next_nt;
7042 DEBUG2(ql4_printk(KERN_INFO, ha,
7043 "Adding DDB to session = 0x%x\n", idx));
7045 if (is_reset == INIT_ADAPTER) {
7046 nt_ddb_idx = vmalloc(fw_idx_size);
7050 nt_ddb_idx->fw_ddb_idx = idx;
7052 /* Copy original isid as it may get updated in function
7053 * qla4xxx_update_isid(). We need original isid in
7054 * function qla4xxx_compare_tuple_ddb to find duplicate
7056 memcpy(&nt_ddb_idx->flash_isid[0],
7057 &fw_ddb_entry->isid[0],
7058 sizeof(nt_ddb_idx->flash_isid));
7060 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7062 if (ret == QLA_SUCCESS) {
7063 /* free nt_ddb_idx and do not add to list_nt */
7065 goto continue_next_nt;
7068 /* Copy updated isid */
7069 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7070 sizeof(struct dev_db_entry));
7072 list_add_tail(&nt_ddb_idx->list, list_nt);
7073 } else if (is_reset == RESET_ADAPTER) {
7074 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7076 if (ret == QLA_SUCCESS) {
7077 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7079 if (ddb_entry != NULL)
7080 qla4xxx_update_sess_disc_idx(ha,
7083 goto continue_next_nt;
7087 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7088 if (ret == QLA_ERROR)
7098 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7101 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7102 struct list_head *list_nt,
7105 struct dev_db_entry *fw_ddb_entry;
7106 dma_addr_t fw_ddb_dma;
7110 uint32_t idx = 0, next_idx = 0;
7111 uint32_t state = 0, conn_err = 0;
7112 uint16_t conn_id = 0;
7113 struct qla_ddb_index *nt_ddb_idx;
7115 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7117 if (fw_ddb_entry == NULL) {
7118 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7119 goto exit_new_nt_list;
7121 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7123 fw_idx_size = sizeof(struct qla_ddb_index);
7125 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7126 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7127 NULL, &next_idx, &state,
7128 &conn_err, NULL, &conn_id);
7129 if (ret == QLA_ERROR)
7132 /* Check if NT, then add it to list */
7133 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7134 goto continue_next_new_nt;
7136 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7137 goto continue_next_new_nt;
7139 DEBUG2(ql4_printk(KERN_INFO, ha,
7140 "Adding DDB to session = 0x%x\n", idx));
7142 nt_ddb_idx = vmalloc(fw_idx_size);
7146 nt_ddb_idx->fw_ddb_idx = idx;
7148 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7149 if (ret == QLA_SUCCESS) {
7150 /* free nt_ddb_idx and do not add to list_nt */
7152 goto continue_next_new_nt;
7155 if (target_id < max_ddbs)
7156 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7158 list_add_tail(&nt_ddb_idx->list, list_nt);
7160 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7162 if (ret == QLA_ERROR)
7163 goto exit_new_nt_list;
7165 continue_next_new_nt:
7172 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7176 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7177 * @dev: dev associated with the sysfs entry
7178 * @data: pointer to flashnode session object
7181 * 1: if flashnode entry is non-persistent
7182 * 0: if flashnode entry is persistent
7184 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7186 struct iscsi_bus_flash_session *fnode_sess;
7188 if (!iscsi_flashnode_bus_match(dev, NULL))
7191 fnode_sess = iscsi_dev_to_flash_session(dev);
7193 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7197 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7198 * @ha: pointer to host
7199 * @fw_ddb_entry: flash ddb data
7200 * @idx: target index
7201 * @user: if set then this call is made from userland else from kernel
7204 * On sucess: QLA_SUCCESS
7205 * On failure: QLA_ERROR
7207 * This create separate sysfs entries for session and connection attributes of
7208 * the given fw ddb entry.
7209 * If this is invoked as a result of a userspace call then the entry is marked
7210 * as nonpersistent using flash_state field.
7212 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7213 struct dev_db_entry *fw_ddb_entry,
7214 uint16_t *idx, int user)
7216 struct iscsi_bus_flash_session *fnode_sess = NULL;
7217 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7220 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7221 &qla4xxx_iscsi_transport, 0);
7223 ql4_printk(KERN_ERR, ha,
7224 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7225 __func__, *idx, ha->host_no);
7226 goto exit_tgt_create;
7229 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7230 &qla4xxx_iscsi_transport, 0);
7232 ql4_printk(KERN_ERR, ha,
7233 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7234 __func__, *idx, ha->host_no);
7239 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7241 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7243 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7244 fnode_sess->is_boot_target = 1;
7246 fnode_sess->is_boot_target = 0;
7249 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7254 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7255 __func__, fnode_sess->dev.kobj.name);
7257 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7258 __func__, fnode_conn->dev.kobj.name);
7263 iscsi_destroy_flashnode_sess(fnode_sess);
7270 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7271 * @shost: pointer to host
7272 * @buf: type of ddb entry (ipv4/ipv6)
7273 * @len: length of buf
7275 * This creates new ddb entry in the flash by finding first free index and
7276 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7278 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7281 struct scsi_qla_host *ha = to_qla_host(shost);
7282 struct dev_db_entry *fw_ddb_entry = NULL;
7283 dma_addr_t fw_ddb_entry_dma;
7286 uint16_t max_ddbs = 0;
7287 uint32_t options = 0;
7288 uint32_t rval = QLA_ERROR;
7290 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7291 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7292 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7297 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7300 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7301 &fw_ddb_entry_dma, GFP_KERNEL);
7302 if (!fw_ddb_entry) {
7303 DEBUG2(ql4_printk(KERN_ERR, ha,
7304 "%s: Unable to allocate dma buffer\n",
7309 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7310 qla4xxx_sysfs_ddb_is_non_persistent);
7312 ql4_printk(KERN_ERR, ha,
7313 "%s: A non-persistent entry %s found\n",
7314 __func__, dev->kobj.name);
7319 /* Index 0 and 1 are reserved for boot target entries */
7320 for (idx = 2; idx < max_ddbs; idx++) {
7321 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7322 fw_ddb_entry_dma, idx))
7326 if (idx == max_ddbs)
7329 if (!strncasecmp("ipv6", buf, 4))
7330 options |= IPV6_DEFAULT_DDB_ENTRY;
7332 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7333 if (rval == QLA_ERROR)
7336 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7340 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7341 fw_ddb_entry, fw_ddb_entry_dma);
7342 if (rval == QLA_SUCCESS)
7349 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7350 * @fnode_sess: pointer to session attrs of flash ddb entry
7351 * @fnode_conn: pointer to connection attrs of flash ddb entry
7353 * This writes the contents of target ddb buffer to Flash with a valid cookie
7354 * value in order to make the ddb entry persistent.
7356 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7357 struct iscsi_bus_flash_conn *fnode_conn)
7359 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7360 struct scsi_qla_host *ha = to_qla_host(shost);
7361 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7362 struct dev_db_entry *fw_ddb_entry = NULL;
7363 dma_addr_t fw_ddb_entry_dma;
7364 uint32_t options = 0;
7367 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7368 &fw_ddb_entry_dma, GFP_KERNEL);
7369 if (!fw_ddb_entry) {
7370 DEBUG2(ql4_printk(KERN_ERR, ha,
7371 "%s: Unable to allocate dma buffer\n",
7374 goto exit_ddb_apply;
7377 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7378 options |= IPV6_DEFAULT_DDB_ENTRY;
7380 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7381 if (rval == QLA_ERROR)
7382 goto exit_ddb_apply;
7384 dev_db_start_offset += (fnode_sess->target_id *
7385 sizeof(*fw_ddb_entry));
7387 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7388 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7390 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7391 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7393 if (rval == QLA_SUCCESS) {
7394 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7395 ql4_printk(KERN_INFO, ha,
7396 "%s: flash node %u of host %lu written to flash\n",
7397 __func__, fnode_sess->target_id, ha->host_no);
7400 ql4_printk(KERN_ERR, ha,
7401 "%s: Error while writing flash node %u of host %lu to flash\n",
7402 __func__, fnode_sess->target_id, ha->host_no);
7407 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7408 fw_ddb_entry, fw_ddb_entry_dma);
7412 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7413 struct dev_db_entry *fw_ddb_entry,
7416 struct dev_db_entry *ddb_entry = NULL;
7417 dma_addr_t ddb_entry_dma;
7418 unsigned long wtime;
7419 uint32_t mbx_sts = 0;
7420 uint32_t state = 0, conn_err = 0;
7424 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7425 &ddb_entry_dma, GFP_KERNEL);
7427 DEBUG2(ql4_printk(KERN_ERR, ha,
7428 "%s: Unable to allocate dma buffer\n",
7433 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7435 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7436 if (ret != QLA_SUCCESS) {
7437 DEBUG2(ql4_printk(KERN_ERR, ha,
7438 "%s: Unable to set ddb entry for index %d\n",
7440 goto exit_ddb_conn_open;
7443 qla4xxx_conn_open(ha, idx);
7445 /* To ensure that sendtargets is done, wait for at least 12 secs */
7446 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7447 (ha->def_timeout < LOGIN_TOV * 10) ?
7448 ha->def_timeout : LOGIN_TOV);
7450 DEBUG2(ql4_printk(KERN_INFO, ha,
7451 "Default time to wait for login to ddb %d\n", tmo));
7453 wtime = jiffies + (HZ * tmo);
7455 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7456 NULL, &state, &conn_err, NULL,
7458 if (ret == QLA_ERROR)
7461 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7462 state == DDB_DS_SESSION_FAILED)
7465 schedule_timeout_uninterruptible(HZ / 10);
7466 } while (time_after(wtime, jiffies));
7470 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7471 ddb_entry, ddb_entry_dma);
7475 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7476 struct dev_db_entry *fw_ddb_entry,
7479 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7480 struct list_head list_nt;
7484 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7485 ql4_printk(KERN_WARNING, ha,
7486 "%s: A discovery already in progress!\n", __func__);
7490 INIT_LIST_HEAD(&list_nt);
7492 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7494 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7495 if (ret == QLA_ERROR)
7496 goto exit_login_st_clr_bit;
7498 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7499 if (ret == QLA_ERROR)
7502 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7504 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7505 list_del_init(&ddb_idx->list);
7506 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7511 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7512 ql4_printk(KERN_ERR, ha,
7513 "Unable to clear DDB index = 0x%x\n", ddb_index);
7516 clear_bit(ddb_index, ha->ddb_idx_map);
7518 exit_login_st_clr_bit:
7519 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7523 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7524 struct dev_db_entry *fw_ddb_entry,
7527 int ret = QLA_ERROR;
7529 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7530 if (ret != QLA_SUCCESS)
7531 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7540 * qla4xxx_sysfs_ddb_login - Login to the specified target
7541 * @fnode_sess: pointer to session attrs of flash ddb entry
7542 * @fnode_conn: pointer to connection attrs of flash ddb entry
7544 * This logs in to the specified target
7546 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7547 struct iscsi_bus_flash_conn *fnode_conn)
7549 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7550 struct scsi_qla_host *ha = to_qla_host(shost);
7551 struct dev_db_entry *fw_ddb_entry = NULL;
7552 dma_addr_t fw_ddb_entry_dma;
7553 uint32_t options = 0;
7556 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7557 ql4_printk(KERN_ERR, ha,
7558 "%s: Target info is not persistent\n", __func__);
7560 goto exit_ddb_login;
7563 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7564 &fw_ddb_entry_dma, GFP_KERNEL);
7565 if (!fw_ddb_entry) {
7566 DEBUG2(ql4_printk(KERN_ERR, ha,
7567 "%s: Unable to allocate dma buffer\n",
7570 goto exit_ddb_login;
7573 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7574 options |= IPV6_DEFAULT_DDB_ENTRY;
7576 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7577 if (ret == QLA_ERROR)
7578 goto exit_ddb_login;
7580 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7581 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7583 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7584 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7585 fnode_sess->target_id);
7587 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7588 fnode_sess->target_id);
7595 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7596 fw_ddb_entry, fw_ddb_entry_dma);
7601 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7602 * @cls_sess: pointer to session to be logged out
7604 * This performs session log out from the specified target
7606 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7608 struct iscsi_session *sess;
7609 struct ddb_entry *ddb_entry = NULL;
7610 struct scsi_qla_host *ha;
7611 struct dev_db_entry *fw_ddb_entry = NULL;
7612 dma_addr_t fw_ddb_entry_dma;
7613 unsigned long flags;
7614 unsigned long wtime;
7619 sess = cls_sess->dd_data;
7620 ddb_entry = sess->dd_data;
7623 if (ddb_entry->ddb_type != FLASH_DDB) {
7624 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7627 goto exit_ddb_logout;
7630 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7631 ql4_printk(KERN_ERR, ha,
7632 "%s: Logout from boot target entry is not permitted.\n",
7635 goto exit_ddb_logout;
7638 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7639 &fw_ddb_entry_dma, GFP_KERNEL);
7640 if (!fw_ddb_entry) {
7641 ql4_printk(KERN_ERR, ha,
7642 "%s: Unable to allocate dma buffer\n", __func__);
7644 goto exit_ddb_logout;
7647 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7648 goto ddb_logout_init;
7650 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7651 fw_ddb_entry, fw_ddb_entry_dma,
7652 NULL, NULL, &ddb_state, NULL,
7654 if (ret == QLA_ERROR)
7655 goto ddb_logout_init;
7657 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7658 goto ddb_logout_init;
7660 /* wait until next relogin is triggered using DF_RELOGIN and
7661 * clear DF_RELOGIN to avoid invocation of further relogin
7663 wtime = jiffies + (HZ * RELOGIN_TOV);
7665 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7666 goto ddb_logout_init;
7668 schedule_timeout_uninterruptible(HZ);
7669 } while ((time_after(wtime, jiffies)));
7672 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7673 atomic_set(&ddb_entry->relogin_timer, 0);
7675 options = LOGOUT_OPTION_CLOSE_SESSION;
7676 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7678 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7679 wtime = jiffies + (HZ * LOGOUT_TOV);
7681 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7682 fw_ddb_entry, fw_ddb_entry_dma,
7683 NULL, NULL, &ddb_state, NULL,
7685 if (ret == QLA_ERROR)
7686 goto ddb_logout_clr_sess;
7688 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7689 (ddb_state == DDB_DS_SESSION_FAILED))
7690 goto ddb_logout_clr_sess;
7692 schedule_timeout_uninterruptible(HZ);
7693 } while ((time_after(wtime, jiffies)));
7695 ddb_logout_clr_sess:
7696 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7698 * we have decremented the reference count of the driver
7699 * when we setup the session to have the driver unload
7700 * to be seamless without actually destroying the
7703 try_module_get(qla4xxx_iscsi_transport.owner);
7704 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7706 spin_lock_irqsave(&ha->hardware_lock, flags);
7707 qla4xxx_free_ddb(ha, ddb_entry);
7708 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7709 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7711 iscsi_session_teardown(ddb_entry->sess);
7713 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7718 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7719 fw_ddb_entry, fw_ddb_entry_dma);
7724 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7725 * @fnode_sess: pointer to session attrs of flash ddb entry
7726 * @fnode_conn: pointer to connection attrs of flash ddb entry
7728 * This performs log out from the specified target
7730 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7731 struct iscsi_bus_flash_conn *fnode_conn)
7733 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7734 struct scsi_qla_host *ha = to_qla_host(shost);
7735 struct ql4_tuple_ddb *flash_tddb = NULL;
7736 struct ql4_tuple_ddb *tmp_tddb = NULL;
7737 struct dev_db_entry *fw_ddb_entry = NULL;
7738 struct ddb_entry *ddb_entry = NULL;
7739 dma_addr_t fw_ddb_dma;
7740 uint32_t next_idx = 0;
7741 uint32_t state = 0, conn_err = 0;
7742 uint16_t conn_id = 0;
7744 int status, ret = 0;
7746 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7748 if (fw_ddb_entry == NULL) {
7749 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7751 goto exit_ddb_logout;
7754 flash_tddb = vzalloc(sizeof(*flash_tddb));
7756 ql4_printk(KERN_WARNING, ha,
7757 "%s:Memory Allocation failed.\n", __func__);
7759 goto exit_ddb_logout;
7762 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7764 ql4_printk(KERN_WARNING, ha,
7765 "%s:Memory Allocation failed.\n", __func__);
7767 goto exit_ddb_logout;
7770 if (!fnode_sess->targetname) {
7771 ql4_printk(KERN_ERR, ha,
7772 "%s:Cannot logout from SendTarget entry\n",
7775 goto exit_ddb_logout;
7778 if (fnode_sess->is_boot_target) {
7779 ql4_printk(KERN_ERR, ha,
7780 "%s: Logout from boot target entry is not permitted.\n",
7783 goto exit_ddb_logout;
7786 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7789 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7790 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7792 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7794 flash_tddb->tpgt = fnode_sess->tpgt;
7795 flash_tddb->port = fnode_conn->port;
7797 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7799 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7800 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7801 if (ddb_entry == NULL)
7804 if (ddb_entry->ddb_type != FLASH_DDB)
7807 index = ddb_entry->sess->target_id;
7808 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7809 fw_ddb_dma, NULL, &next_idx,
7810 &state, &conn_err, NULL,
7812 if (status == QLA_ERROR) {
7817 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7819 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7821 if (status == QLA_SUCCESS) {
7822 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7827 if (idx == MAX_DDB_ENTRIES)
7836 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7842 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7843 int param, char *buf)
7845 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7846 struct scsi_qla_host *ha = to_qla_host(shost);
7847 struct iscsi_bus_flash_conn *fnode_conn;
7848 struct ql4_chap_table chap_tbl;
7853 dev = iscsi_find_flashnode_conn(fnode_sess);
7857 fnode_conn = iscsi_dev_to_flash_conn(dev);
7860 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7861 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7863 case ISCSI_FLASHNODE_PORTAL_TYPE:
7864 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7866 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7867 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7869 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7870 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7872 case ISCSI_FLASHNODE_ENTRY_EN:
7873 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7875 case ISCSI_FLASHNODE_HDR_DGST_EN:
7876 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7878 case ISCSI_FLASHNODE_DATA_DGST_EN:
7879 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7881 case ISCSI_FLASHNODE_IMM_DATA_EN:
7882 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7884 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7885 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7887 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7888 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7890 case ISCSI_FLASHNODE_PDU_INORDER:
7891 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7893 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7894 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7896 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7897 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7899 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7900 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7902 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7903 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7905 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7906 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7908 case ISCSI_FLASHNODE_ERL:
7909 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7911 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7912 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7914 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7915 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7917 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7918 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7920 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7921 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7923 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7924 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7926 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7927 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7929 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7930 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7932 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7933 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7935 case ISCSI_FLASHNODE_FIRST_BURST:
7936 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7938 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7939 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7941 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7942 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7944 case ISCSI_FLASHNODE_MAX_R2T:
7945 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7947 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7948 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7950 case ISCSI_FLASHNODE_ISID:
7951 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7953 case ISCSI_FLASHNODE_TSID:
7954 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7956 case ISCSI_FLASHNODE_PORT:
7957 rc = sprintf(buf, "%d\n", fnode_conn->port);
7959 case ISCSI_FLASHNODE_MAX_BURST:
7960 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7962 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7963 rc = sprintf(buf, "%u\n",
7964 fnode_sess->default_taskmgmt_timeout);
7966 case ISCSI_FLASHNODE_IPADDR:
7967 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7968 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7970 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7972 case ISCSI_FLASHNODE_ALIAS:
7973 if (fnode_sess->targetalias)
7974 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7976 rc = sprintf(buf, "\n");
7978 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7979 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7980 rc = sprintf(buf, "%pI6\n",
7981 fnode_conn->redirect_ipaddr);
7983 rc = sprintf(buf, "%pI4\n",
7984 fnode_conn->redirect_ipaddr);
7986 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7987 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7989 case ISCSI_FLASHNODE_LOCAL_PORT:
7990 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7992 case ISCSI_FLASHNODE_IPV4_TOS:
7993 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7995 case ISCSI_FLASHNODE_IPV6_TC:
7996 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7997 rc = sprintf(buf, "%u\n",
7998 fnode_conn->ipv6_traffic_class);
8000 rc = sprintf(buf, "\n");
8002 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8003 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8005 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8006 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8007 rc = sprintf(buf, "%pI6\n",
8008 fnode_conn->link_local_ipv6_addr);
8010 rc = sprintf(buf, "\n");
8012 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8013 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8015 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8016 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8017 parent_type = ISCSI_DISC_PARENT_ISNS;
8018 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8019 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8020 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8021 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8023 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8025 rc = sprintf(buf, "%s\n",
8026 iscsi_get_discovery_parent_name(parent_type));
8028 case ISCSI_FLASHNODE_NAME:
8029 if (fnode_sess->targetname)
8030 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8032 rc = sprintf(buf, "\n");
8034 case ISCSI_FLASHNODE_TPGT:
8035 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8037 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8038 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8040 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8041 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8043 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8044 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8046 case ISCSI_FLASHNODE_USERNAME:
8047 if (fnode_sess->chap_auth_en) {
8048 qla4xxx_get_uni_chap_at_index(ha,
8051 fnode_sess->chap_out_idx);
8052 rc = sprintf(buf, "%s\n", chap_tbl.name);
8054 rc = sprintf(buf, "\n");
8057 case ISCSI_FLASHNODE_PASSWORD:
8058 if (fnode_sess->chap_auth_en) {
8059 qla4xxx_get_uni_chap_at_index(ha,
8062 fnode_sess->chap_out_idx);
8063 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8065 rc = sprintf(buf, "\n");
8068 case ISCSI_FLASHNODE_STATSN:
8069 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8071 case ISCSI_FLASHNODE_EXP_STATSN:
8072 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8074 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8075 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8087 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8088 * @fnode_sess: pointer to session attrs of flash ddb entry
8089 * @fnode_conn: pointer to connection attrs of flash ddb entry
8090 * @data: Parameters and their values to update
8093 * This sets the parameter of flash ddb entry and writes them to flash
8096 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8097 struct iscsi_bus_flash_conn *fnode_conn,
8098 void *data, int len)
8100 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8101 struct scsi_qla_host *ha = to_qla_host(shost);
8102 struct iscsi_flashnode_param_info *fnode_param;
8103 struct ql4_chap_table chap_tbl;
8104 struct nlattr *attr;
8105 uint16_t chap_out_idx = INVALID_ENTRY;
8109 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8110 nla_for_each_attr(attr, data, len, rem) {
8111 if (nla_len(attr) < sizeof(*fnode_param)) {
8113 goto exit_set_param;
8116 fnode_param = nla_data(attr);
8118 switch (fnode_param->param) {
8119 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8120 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8122 case ISCSI_FLASHNODE_PORTAL_TYPE:
8123 memcpy(fnode_sess->portal_type, fnode_param->value,
8124 strlen(fnode_sess->portal_type));
8126 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8127 fnode_sess->auto_snd_tgt_disable =
8128 fnode_param->value[0];
8130 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8131 fnode_sess->discovery_sess = fnode_param->value[0];
8133 case ISCSI_FLASHNODE_ENTRY_EN:
8134 fnode_sess->entry_state = fnode_param->value[0];
8136 case ISCSI_FLASHNODE_HDR_DGST_EN:
8137 fnode_conn->hdrdgst_en = fnode_param->value[0];
8139 case ISCSI_FLASHNODE_DATA_DGST_EN:
8140 fnode_conn->datadgst_en = fnode_param->value[0];
8142 case ISCSI_FLASHNODE_IMM_DATA_EN:
8143 fnode_sess->imm_data_en = fnode_param->value[0];
8145 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8146 fnode_sess->initial_r2t_en = fnode_param->value[0];
8148 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8149 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8151 case ISCSI_FLASHNODE_PDU_INORDER:
8152 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8154 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8155 fnode_sess->chap_auth_en = fnode_param->value[0];
8156 /* Invalidate chap index if chap auth is disabled */
8157 if (!fnode_sess->chap_auth_en)
8158 fnode_sess->chap_out_idx = INVALID_ENTRY;
8161 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8162 fnode_conn->snack_req_en = fnode_param->value[0];
8164 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8165 fnode_sess->discovery_logout_en = fnode_param->value[0];
8167 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8168 fnode_sess->bidi_chap_en = fnode_param->value[0];
8170 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8171 fnode_sess->discovery_auth_optional =
8172 fnode_param->value[0];
8174 case ISCSI_FLASHNODE_ERL:
8175 fnode_sess->erl = fnode_param->value[0];
8177 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8178 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8180 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8181 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8183 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8184 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8186 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8187 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8189 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8190 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8192 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8193 fnode_conn->fragment_disable = fnode_param->value[0];
8195 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8196 fnode_conn->max_recv_dlength =
8197 *(unsigned *)fnode_param->value;
8199 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8200 fnode_conn->max_xmit_dlength =
8201 *(unsigned *)fnode_param->value;
8203 case ISCSI_FLASHNODE_FIRST_BURST:
8204 fnode_sess->first_burst =
8205 *(unsigned *)fnode_param->value;
8207 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8208 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8210 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8211 fnode_sess->time2retain =
8212 *(uint16_t *)fnode_param->value;
8214 case ISCSI_FLASHNODE_MAX_R2T:
8215 fnode_sess->max_r2t =
8216 *(uint16_t *)fnode_param->value;
8218 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8219 fnode_conn->keepalive_timeout =
8220 *(uint16_t *)fnode_param->value;
8222 case ISCSI_FLASHNODE_ISID:
8223 memcpy(fnode_sess->isid, fnode_param->value,
8224 sizeof(fnode_sess->isid));
8226 case ISCSI_FLASHNODE_TSID:
8227 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8229 case ISCSI_FLASHNODE_PORT:
8230 fnode_conn->port = *(uint16_t *)fnode_param->value;
8232 case ISCSI_FLASHNODE_MAX_BURST:
8233 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8235 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8236 fnode_sess->default_taskmgmt_timeout =
8237 *(uint16_t *)fnode_param->value;
8239 case ISCSI_FLASHNODE_IPADDR:
8240 memcpy(fnode_conn->ipaddress, fnode_param->value,
8243 case ISCSI_FLASHNODE_ALIAS:
8244 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8245 (char *)fnode_param->value);
8247 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8248 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8251 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8252 fnode_conn->max_segment_size =
8253 *(unsigned *)fnode_param->value;
8255 case ISCSI_FLASHNODE_LOCAL_PORT:
8256 fnode_conn->local_port =
8257 *(uint16_t *)fnode_param->value;
8259 case ISCSI_FLASHNODE_IPV4_TOS:
8260 fnode_conn->ipv4_tos = fnode_param->value[0];
8262 case ISCSI_FLASHNODE_IPV6_TC:
8263 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8265 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8266 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8268 case ISCSI_FLASHNODE_NAME:
8269 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8270 (char *)fnode_param->value);
8272 case ISCSI_FLASHNODE_TPGT:
8273 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8275 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8276 memcpy(fnode_conn->link_local_ipv6_addr,
8277 fnode_param->value, IPv6_ADDR_LEN);
8279 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8280 fnode_sess->discovery_parent_idx =
8281 *(uint16_t *)fnode_param->value;
8283 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8284 fnode_conn->tcp_xmit_wsf =
8285 *(uint8_t *)fnode_param->value;
8287 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8288 fnode_conn->tcp_recv_wsf =
8289 *(uint8_t *)fnode_param->value;
8291 case ISCSI_FLASHNODE_STATSN:
8292 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8294 case ISCSI_FLASHNODE_EXP_STATSN:
8295 fnode_conn->exp_statsn =
8296 *(uint32_t *)fnode_param->value;
8298 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8299 chap_out_idx = *(uint16_t *)fnode_param->value;
8300 if (!qla4xxx_get_uni_chap_at_index(ha,
8304 fnode_sess->chap_out_idx = chap_out_idx;
8305 /* Enable chap auth if chap index is valid */
8306 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8310 ql4_printk(KERN_ERR, ha,
8311 "%s: No such sysfs attribute\n", __func__);
8313 goto exit_set_param;
8317 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8324 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8325 * @fnode_sess: pointer to session attrs of flash ddb entry
8327 * This invalidates the flash ddb entry at the given index
8329 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8331 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8332 struct scsi_qla_host *ha = to_qla_host(shost);
8333 uint32_t dev_db_start_offset;
8334 uint32_t dev_db_end_offset;
8335 struct dev_db_entry *fw_ddb_entry = NULL;
8336 dma_addr_t fw_ddb_entry_dma;
8337 uint16_t *ddb_cookie = NULL;
8338 size_t ddb_size = 0;
8343 if (fnode_sess->is_boot_target) {
8345 DEBUG2(ql4_printk(KERN_ERR, ha,
8346 "%s: Deletion of boot target entry is not permitted.\n",
8351 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8354 if (is_qla40XX(ha)) {
8355 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8356 dev_db_end_offset = FLASH_OFFSET_DB_END;
8357 dev_db_start_offset += (fnode_sess->target_id *
8358 sizeof(*fw_ddb_entry));
8359 ddb_size = sizeof(*fw_ddb_entry);
8361 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8362 (ha->hw.flt_region_ddb << 2);
8363 /* flt_ddb_size is DDB table size for both ports
8364 * so divide it by 2 to calculate the offset for second port
8366 if (ha->port_num == 1)
8367 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8369 dev_db_end_offset = dev_db_start_offset +
8370 (ha->hw.flt_ddb_size / 2);
8372 dev_db_start_offset += (fnode_sess->target_id *
8373 sizeof(*fw_ddb_entry));
8374 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8376 ddb_size = sizeof(*ddb_cookie);
8379 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8380 __func__, dev_db_start_offset, dev_db_end_offset));
8382 if (dev_db_start_offset > dev_db_end_offset) {
8384 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8385 __func__, fnode_sess->target_id));
8389 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8390 &fw_ddb_entry_dma, GFP_KERNEL);
8393 DEBUG2(ql4_printk(KERN_ERR, ha,
8394 "%s: Unable to allocate dma buffer\n",
8399 if (is_qla40XX(ha)) {
8400 fw_ddb_entry = pddb;
8401 memset(fw_ddb_entry, 0, ddb_size);
8402 ddb_cookie = &fw_ddb_entry->cookie;
8407 /* invalidate the cookie */
8408 *ddb_cookie = 0xFFEE;
8409 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8410 ddb_size, FLASH_OPT_RMW_COMMIT);
8413 target_id = fnode_sess->target_id;
8414 iscsi_destroy_flashnode_sess(fnode_sess);
8415 ql4_printk(KERN_INFO, ha,
8416 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8417 __func__, target_id, ha->host_no);
8420 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8426 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8427 * @ha: pointer to adapter structure
8429 * Export the firmware DDB for all send targets and normal targets to sysfs.
8431 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8433 struct dev_db_entry *fw_ddb_entry = NULL;
8434 dma_addr_t fw_ddb_entry_dma;
8437 int ret = QLA_SUCCESS;
8439 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8440 sizeof(*fw_ddb_entry),
8441 &fw_ddb_entry_dma, GFP_KERNEL);
8442 if (!fw_ddb_entry) {
8443 DEBUG2(ql4_printk(KERN_ERR, ha,
8444 "%s: Unable to allocate dma buffer\n",
8449 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8452 for (idx = 0; idx < max_ddbs; idx++) {
8453 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8457 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8464 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8470 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8472 iscsi_destroy_all_flashnode(ha->host);
8476 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8477 * @ha: pointer to adapter structure
8478 * @is_reset: Is this init path or reset path
8480 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8481 * using connection open, then create the list of normal targets (nt)
8482 * from firmware DDBs. Based on the list of nt setup session and connection
8485 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8488 struct list_head list_st, list_nt;
8489 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8490 unsigned long wtime;
8492 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8493 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8494 ha->is_reset = is_reset;
8498 INIT_LIST_HEAD(&list_st);
8499 INIT_LIST_HEAD(&list_nt);
8501 qla4xxx_build_st_list(ha, &list_st);
8503 /* Before issuing conn open mbox, ensure all IPs states are configured
8504 * Note, conn open fails if IPs are not configured
8506 qla4xxx_wait_for_ip_configuration(ha);
8508 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8509 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8510 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8513 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8514 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8515 (ha->def_timeout < LOGIN_TOV * 10) ?
8516 ha->def_timeout : LOGIN_TOV);
8518 DEBUG2(ql4_printk(KERN_INFO, ha,
8519 "Default time to wait for build ddb %d\n", tmo));
8521 wtime = jiffies + (HZ * tmo);
8523 if (list_empty(&list_st))
8526 qla4xxx_remove_failed_ddb(ha, &list_st);
8527 schedule_timeout_uninterruptible(HZ / 10);
8528 } while (time_after(wtime, jiffies));
8531 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8533 qla4xxx_free_ddb_list(&list_st);
8534 qla4xxx_free_ddb_list(&list_nt);
8536 qla4xxx_free_ddb_index(ha);
8540 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8542 * @ha: pointer to adapter structure
8544 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8545 * set in DDB and we will wait for login response of boot targets during
8548 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8550 struct ddb_entry *ddb_entry;
8551 struct dev_db_entry *fw_ddb_entry = NULL;
8552 dma_addr_t fw_ddb_entry_dma;
8553 unsigned long wtime;
8555 int max_ddbs, idx, ret;
8557 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8560 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8561 &fw_ddb_entry_dma, GFP_KERNEL);
8562 if (!fw_ddb_entry) {
8563 ql4_printk(KERN_ERR, ha,
8564 "%s: Unable to allocate dma buffer\n", __func__);
8565 goto exit_login_resp;
8568 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8570 for (idx = 0; idx < max_ddbs; idx++) {
8571 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8572 if (ddb_entry == NULL)
8575 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8576 DEBUG2(ql4_printk(KERN_INFO, ha,
8577 "%s: DDB index [%d]\n", __func__,
8578 ddb_entry->fw_ddb_index));
8580 ret = qla4xxx_get_fwddb_entry(ha,
8581 ddb_entry->fw_ddb_index,
8582 fw_ddb_entry, fw_ddb_entry_dma,
8583 NULL, NULL, &ddb_state, NULL,
8585 if (ret == QLA_ERROR)
8586 goto exit_login_resp;
8588 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8589 (ddb_state == DDB_DS_SESSION_FAILED))
8592 schedule_timeout_uninterruptible(HZ);
8594 } while ((time_after(wtime, jiffies)));
8596 if (!time_after(wtime, jiffies)) {
8597 DEBUG2(ql4_printk(KERN_INFO, ha,
8598 "%s: Login response wait timer expired\n",
8600 goto exit_login_resp;
8607 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8608 fw_ddb_entry, fw_ddb_entry_dma);
8612 * qla4xxx_probe_adapter - callback function to probe HBA
8613 * @pdev: pointer to pci_dev structure
8614 * @pci_device_id: pointer to pci_device entry
8616 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8617 * It returns zero if successful. It also initializes all data necessary for
8620 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8621 const struct pci_device_id *ent)
8623 int ret = -ENODEV, status;
8624 struct Scsi_Host *host;
8625 struct scsi_qla_host *ha;
8626 uint8_t init_retry_count = 0;
8628 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8631 if (pci_enable_device(pdev))
8634 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8637 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8638 goto probe_disable_device;
8641 /* Clear our data area */
8642 ha = to_qla_host(host);
8643 memset(ha, 0, sizeof(*ha));
8645 /* Save the information from PCI BIOS. */
8648 ha->host_no = host->host_no;
8649 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8651 pci_enable_pcie_error_reporting(pdev);
8653 /* Setup Runtime configurable options */
8654 if (is_qla8022(ha)) {
8655 ha->isp_ops = &qla4_82xx_isp_ops;
8656 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8657 ha->qdr_sn_window = -1;
8658 ha->ddr_mn_window = -1;
8659 ha->curr_window = 255;
8660 nx_legacy_intr = &legacy_intr[ha->func_num];
8661 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8662 ha->nx_legacy_intr.tgt_status_reg =
8663 nx_legacy_intr->tgt_status_reg;
8664 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8665 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8666 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8667 ha->isp_ops = &qla4_83xx_isp_ops;
8668 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8670 ha->isp_ops = &qla4xxx_isp_ops;
8673 if (is_qla80XX(ha)) {
8674 rwlock_init(&ha->hw_lock);
8675 ha->pf_bit = ha->func_num << 16;
8676 /* Set EEH reset type to fundamental if required by hba */
8677 pdev->needs_freset = 1;
8680 /* Configure PCI I/O space. */
8681 ret = ha->isp_ops->iospace_config(ha);
8683 goto probe_failed_ioconfig;
8685 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8686 pdev->device, pdev->irq, ha->reg);
8688 qla4xxx_config_dma_addressing(ha);
8690 /* Initialize lists and spinlocks. */
8691 INIT_LIST_HEAD(&ha->free_srb_q);
8693 mutex_init(&ha->mbox_sem);
8694 mutex_init(&ha->chap_sem);
8695 init_completion(&ha->mbx_intr_comp);
8696 init_completion(&ha->disable_acb_comp);
8697 init_completion(&ha->idc_comp);
8698 init_completion(&ha->link_up_comp);
8700 spin_lock_init(&ha->hardware_lock);
8701 spin_lock_init(&ha->work_lock);
8703 /* Initialize work list */
8704 INIT_LIST_HEAD(&ha->work_list);
8706 /* Allocate dma buffers */
8707 if (qla4xxx_mem_alloc(ha)) {
8708 ql4_printk(KERN_WARNING, ha,
8709 "[ERROR] Failed to allocate memory for adapter\n");
8715 host->cmd_per_lun = 3;
8716 host->max_channel = 0;
8717 host->max_lun = MAX_LUNS - 1;
8718 host->max_id = MAX_TARGETS;
8719 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8720 host->can_queue = MAX_SRBS ;
8721 host->transportt = qla4xxx_scsi_transport;
8723 pci_set_drvdata(pdev, ha);
8725 ret = scsi_add_host(host, &pdev->dev);
8730 qla4_8xxx_get_flash_info(ha);
8732 if (is_qla8032(ha) || is_qla8042(ha)) {
8733 qla4_83xx_read_reset_template(ha);
8735 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8736 * If DONRESET_BIT0 is set, drivers should not set dev_state
8737 * to NEED_RESET. But if NEED_RESET is set, drivers should
8738 * should honor the reset.
8740 if (ql4xdontresethba == 1)
8741 qla4_83xx_set_idc_dontreset(ha);
8745 * Initialize the Host adapter request/response queues and
8747 * NOTE: interrupts enabled upon successful completion
8749 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8751 /* Dont retry adapter initialization if IRQ allocation failed */
8752 if (is_qla80XX(ha) && (status == QLA_ERROR))
8753 goto skip_retry_init;
8755 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8756 init_retry_count++ < MAX_INIT_RETRIES) {
8758 if (is_qla80XX(ha)) {
8759 ha->isp_ops->idc_lock(ha);
8760 dev_state = qla4_8xxx_rd_direct(ha,
8761 QLA8XXX_CRB_DEV_STATE);
8762 ha->isp_ops->idc_unlock(ha);
8763 if (dev_state == QLA8XXX_DEV_FAILED) {
8764 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8765 "initialize adapter. H/W is in failed state\n",
8770 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8771 "(%d)\n", __func__, init_retry_count));
8773 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8776 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8777 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8778 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8779 goto skip_retry_init;
8784 if (!test_bit(AF_ONLINE, &ha->flags)) {
8785 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8787 if ((is_qla8022(ha) && ql4xdontresethba) ||
8788 ((is_qla8032(ha) || is_qla8042(ha)) &&
8789 qla4_83xx_idc_dontreset(ha))) {
8790 /* Put the device in failed state. */
8791 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8792 ha->isp_ops->idc_lock(ha);
8793 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8794 QLA8XXX_DEV_FAILED);
8795 ha->isp_ops->idc_unlock(ha);
8801 /* Startup the kernel thread for this host adapter. */
8802 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8803 "qla4xxx_dpc\n", __func__));
8804 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8805 ha->dpc_thread = create_singlethread_workqueue(buf);
8806 if (!ha->dpc_thread) {
8807 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8811 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8813 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8816 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8822 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8823 * (which is called indirectly by qla4xxx_initialize_adapter),
8824 * so that irqs will be registered after crbinit but before
8827 if (is_qla40XX(ha)) {
8828 ret = qla4xxx_request_irqs(ha);
8830 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8831 "interrupt %d already in use.\n", pdev->irq);
8836 pci_save_state(ha->pdev);
8837 ha->isp_ops->enable_intrs(ha);
8839 /* Start timer thread. */
8840 qla4xxx_start_timer(ha, 1);
8842 set_bit(AF_INIT_DONE, &ha->flags);
8844 qla4_8xxx_alloc_sysfs_attr(ha);
8847 " QLogic iSCSI HBA Driver version: %s\n"
8848 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8849 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8850 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8851 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8853 /* Set the driver version */
8855 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8857 if (qla4xxx_setup_boot_info(ha))
8858 ql4_printk(KERN_ERR, ha,
8859 "%s: No iSCSI boot target configured\n", __func__);
8861 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8862 /* Perform the build ddb list and login to each */
8863 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8864 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8865 qla4xxx_wait_login_resp_boot_tgt(ha);
8867 qla4xxx_create_chap_list(ha);
8869 qla4xxx_create_ifaces(ha);
8873 scsi_remove_host(ha->host);
8876 qla4xxx_free_adapter(ha);
8878 probe_failed_ioconfig:
8879 pci_disable_pcie_error_reporting(pdev);
8880 scsi_host_put(ha->host);
8882 probe_disable_device:
8883 pci_disable_device(pdev);
8889 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8890 * @ha: pointer to adapter structure
8892 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8893 * so that the other port will not re-initialize while in the process of
8894 * removing the ha due to driver unload or hba hotplug.
8896 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8898 struct scsi_qla_host *other_ha = NULL;
8899 struct pci_dev *other_pdev = NULL;
8900 int fn = ISP4XXX_PCI_FN_2;
8902 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8903 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8904 fn = ISP4XXX_PCI_FN_1;
8907 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8908 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8911 /* Get other_ha if other_pdev is valid and state is enable*/
8913 if (atomic_read(&other_pdev->enable_cnt)) {
8914 other_ha = pci_get_drvdata(other_pdev);
8916 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8917 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8918 "Prevent %s reinit\n", __func__,
8919 dev_name(&other_ha->pdev->dev)));
8922 pci_dev_put(other_pdev);
8926 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8927 struct ddb_entry *ddb_entry)
8929 struct dev_db_entry *fw_ddb_entry = NULL;
8930 dma_addr_t fw_ddb_entry_dma;
8931 unsigned long wtime;
8936 options = LOGOUT_OPTION_CLOSE_SESSION;
8937 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8938 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8942 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8943 &fw_ddb_entry_dma, GFP_KERNEL);
8944 if (!fw_ddb_entry) {
8945 ql4_printk(KERN_ERR, ha,
8946 "%s: Unable to allocate dma buffer\n", __func__);
8950 wtime = jiffies + (HZ * LOGOUT_TOV);
8952 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8953 fw_ddb_entry, fw_ddb_entry_dma,
8954 NULL, NULL, &ddb_state, NULL,
8956 if (status == QLA_ERROR)
8959 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8960 (ddb_state == DDB_DS_SESSION_FAILED))
8963 schedule_timeout_uninterruptible(HZ);
8964 } while ((time_after(wtime, jiffies)));
8967 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8968 fw_ddb_entry, fw_ddb_entry_dma);
8970 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8973 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8975 struct ddb_entry *ddb_entry;
8978 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8980 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8981 if ((ddb_entry != NULL) &&
8982 (ddb_entry->ddb_type == FLASH_DDB)) {
8984 qla4xxx_destroy_ddb(ha, ddb_entry);
8986 * we have decremented the reference count of the driver
8987 * when we setup the session to have the driver unload
8988 * to be seamless without actually destroying the
8991 try_module_get(qla4xxx_iscsi_transport.owner);
8992 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8993 qla4xxx_free_ddb(ha, ddb_entry);
8994 iscsi_session_teardown(ddb_entry->sess);
8999 * qla4xxx_remove_adapter - callback function to remove adapter.
9000 * @pci_dev: PCI device pointer
9002 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
9004 struct scsi_qla_host *ha;
9007 * If the PCI device is disabled then it means probe_adapter had
9008 * failed and resources already cleaned up on probe_adapter exit.
9010 if (!pci_is_enabled(pdev))
9013 ha = pci_get_drvdata(pdev);
9016 qla4xxx_prevent_other_port_reinit(ha);
9018 /* destroy iface from sysfs */
9019 qla4xxx_destroy_ifaces(ha);
9021 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9022 iscsi_boot_destroy_kset(ha->boot_kset);
9024 qla4xxx_destroy_fw_ddb_session(ha);
9025 qla4_8xxx_free_sysfs_attr(ha);
9027 qla4xxx_sysfs_ddb_remove(ha);
9028 scsi_remove_host(ha->host);
9030 qla4xxx_free_adapter(ha);
9032 scsi_host_put(ha->host);
9034 pci_disable_pcie_error_reporting(pdev);
9035 pci_disable_device(pdev);
9039 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9042 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
9043 * supported addressing method.
9045 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9049 /* Update our PCI device dma_mask for full 64 bit mask */
9050 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
9051 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
9052 dev_dbg(&ha->pdev->dev,
9053 "Failed to set 64 bit PCI consistent mask; "
9055 retval = pci_set_consistent_dma_mask(ha->pdev,
9059 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
9062 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9064 struct iscsi_cls_session *cls_sess;
9065 struct iscsi_session *sess;
9066 struct ddb_entry *ddb;
9067 int queue_depth = QL4_DEF_QDEPTH;
9069 cls_sess = starget_to_session(sdev->sdev_target);
9070 sess = cls_sess->dd_data;
9071 ddb = sess->dd_data;
9073 sdev->hostdata = ddb;
9075 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9076 queue_depth = ql4xmaxqdepth;
9078 scsi_change_queue_depth(sdev, queue_depth);
9083 * qla4xxx_del_from_active_array - returns an active srb
9084 * @ha: Pointer to host adapter structure.
9085 * @index: index into the active_array
9087 * This routine removes and returns the srb at the specified index
9089 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9092 struct srb *srb = NULL;
9093 struct scsi_cmnd *cmd = NULL;
9095 cmd = scsi_host_find_tag(ha->host, index);
9099 srb = (struct srb *)CMD_SP(cmd);
9103 /* update counters */
9104 if (srb->flags & SRB_DMA_VALID) {
9105 ha->iocb_cnt -= srb->iocb_cnt;
9107 srb->cmd->host_scribble =
9108 (unsigned char *)(unsigned long) MAX_SRBS;
9114 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9115 * @ha: Pointer to host adapter structure.
9116 * @cmd: Scsi Command to wait on.
9118 * This routine waits for the command to be returned by the Firmware
9119 * for some max time.
9121 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9122 struct scsi_cmnd *cmd)
9126 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9129 /* Dont wait on command if PCI error is being handled
9132 if (unlikely(pci_channel_offline(ha->pdev)) ||
9133 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9134 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9135 ha->host_no, __func__);
9140 /* Checking to see if its returned to OS */
9141 rp = (struct srb *) CMD_SP(cmd);
9148 } while (max_wait_time--);
9154 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9155 * @ha: Pointer to host adapter structure
9157 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9159 unsigned long wait_online;
9161 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9162 while (time_before(jiffies, wait_online)) {
9174 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9175 * @ha: pointer to HBA
9179 * This function waits for all outstanding commands to a lun to complete. It
9180 * returns 0 if all pending commands are returned and 1 otherwise.
9182 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9183 struct scsi_target *stgt,
9184 struct scsi_device *sdev)
9188 struct scsi_cmnd *cmd;
9191 * Waiting for all commands for the designated target or dev
9192 * in the active array
9194 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9195 cmd = scsi_host_find_tag(ha->host, cnt);
9196 if (cmd && stgt == scsi_target(cmd->device) &&
9197 (!sdev || sdev == cmd->device)) {
9198 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9208 * qla4xxx_eh_abort - callback for abort task.
9209 * @cmd: Pointer to Linux's SCSI command structure
9211 * This routine is called by the Linux OS to abort the specified
9214 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9216 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9217 unsigned int id = cmd->device->id;
9218 uint64_t lun = cmd->device->lun;
9219 unsigned long flags;
9220 struct srb *srb = NULL;
9225 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9226 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9228 rval = qla4xxx_isp_check_reg(ha);
9229 if (rval != QLA_SUCCESS) {
9230 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9234 spin_lock_irqsave(&ha->hardware_lock, flags);
9235 srb = (struct srb *) CMD_SP(cmd);
9237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9238 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9239 ha->host_no, id, lun);
9242 kref_get(&srb->srb_ref);
9243 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9245 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9246 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9247 ha->host_no, id, lun));
9250 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9251 ha->host_no, id, lun));
9255 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9257 /* Wait for command to complete */
9259 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9260 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9261 ha->host_no, id, lun));
9266 ql4_printk(KERN_INFO, ha,
9267 "scsi%ld:%d:%llu: Abort command - %s\n",
9268 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9274 * qla4xxx_eh_device_reset - callback for target reset.
9275 * @cmd: Pointer to Linux's SCSI command structure
9277 * This routine is called by the Linux OS to reset all luns on the
9280 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9282 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9283 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9284 int ret = FAILED, stat;
9290 ret = iscsi_block_scsi_eh(cmd);
9295 ql4_printk(KERN_INFO, ha,
9296 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9297 cmd->device->channel, cmd->device->id, cmd->device->lun);
9299 DEBUG2(printk(KERN_INFO
9300 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9301 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9302 cmd, jiffies, cmd->request->timeout / HZ,
9303 ha->dpc_flags, cmd->result, cmd->allowed));
9305 rval = qla4xxx_isp_check_reg(ha);
9306 if (rval != QLA_SUCCESS) {
9307 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9311 /* FIXME: wait for hba to go online */
9312 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9313 if (stat != QLA_SUCCESS) {
9314 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9315 goto eh_dev_reset_done;
9318 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9320 ql4_printk(KERN_INFO, ha,
9321 "DEVICE RESET FAILED - waiting for "
9323 goto eh_dev_reset_done;
9327 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9328 MM_LUN_RESET) != QLA_SUCCESS)
9329 goto eh_dev_reset_done;
9331 ql4_printk(KERN_INFO, ha,
9332 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9333 ha->host_no, cmd->device->channel, cmd->device->id,
9344 * qla4xxx_eh_target_reset - callback for target reset.
9345 * @cmd: Pointer to Linux's SCSI command structure
9347 * This routine is called by the Linux OS to reset the target.
9349 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9351 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9352 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9359 ret = iscsi_block_scsi_eh(cmd);
9363 starget_printk(KERN_INFO, scsi_target(cmd->device),
9364 "WARM TARGET RESET ISSUED.\n");
9366 DEBUG2(printk(KERN_INFO
9367 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9368 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9369 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9370 ha->dpc_flags, cmd->result, cmd->allowed));
9372 rval = qla4xxx_isp_check_reg(ha);
9373 if (rval != QLA_SUCCESS) {
9374 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9378 stat = qla4xxx_reset_target(ha, ddb_entry);
9379 if (stat != QLA_SUCCESS) {
9380 starget_printk(KERN_INFO, scsi_target(cmd->device),
9381 "WARM TARGET RESET FAILED.\n");
9385 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9387 starget_printk(KERN_INFO, scsi_target(cmd->device),
9388 "WARM TARGET DEVICE RESET FAILED - "
9389 "waiting for commands.\n");
9394 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9395 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9396 starget_printk(KERN_INFO, scsi_target(cmd->device),
9397 "WARM TARGET DEVICE RESET FAILED - "
9398 "marker iocb failed.\n");
9402 starget_printk(KERN_INFO, scsi_target(cmd->device),
9403 "WARM TARGET RESET SUCCEEDED.\n");
9408 * qla4xxx_is_eh_active - check if error handler is running
9409 * @shost: Pointer to SCSI Host struct
9411 * This routine finds that if reset host is called in EH
9412 * scenario or from some application like sg_reset
9414 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9416 if (shost->shost_state == SHOST_RECOVERY)
9422 * qla4xxx_eh_host_reset - kernel callback
9423 * @cmd: Pointer to Linux's SCSI command structure
9425 * This routine is invoked by the Linux kernel to perform fatal error
9426 * recovery on the specified adapter.
9428 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9430 int return_status = FAILED;
9431 struct scsi_qla_host *ha;
9434 ha = to_qla_host(cmd->device->host);
9436 rval = qla4xxx_isp_check_reg(ha);
9437 if (rval != QLA_SUCCESS) {
9438 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9442 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9443 qla4_83xx_set_idc_dontreset(ha);
9446 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9447 * protocol drivers, we should not set device_state to NEED_RESET
9449 if (ql4xdontresethba ||
9450 ((is_qla8032(ha) || is_qla8042(ha)) &&
9451 qla4_83xx_idc_dontreset(ha))) {
9452 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9453 ha->host_no, __func__));
9455 /* Clear outstanding srb in queues */
9456 if (qla4xxx_is_eh_active(cmd->device->host))
9457 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9462 ql4_printk(KERN_INFO, ha,
9463 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9464 cmd->device->channel, cmd->device->id, cmd->device->lun);
9466 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9467 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9468 "DEAD.\n", ha->host_no, cmd->device->channel,
9474 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9476 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9478 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9481 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9482 return_status = SUCCESS;
9484 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9485 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9487 return return_status;
9490 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9492 uint32_t mbox_cmd[MBOX_REG_COUNT];
9493 uint32_t mbox_sts[MBOX_REG_COUNT];
9494 struct addr_ctrl_blk_def *acb = NULL;
9495 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9496 int rval = QLA_SUCCESS;
9499 acb = dma_alloc_coherent(&ha->pdev->dev,
9500 sizeof(struct addr_ctrl_blk_def),
9501 &acb_dma, GFP_KERNEL);
9503 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9506 goto exit_port_reset;
9509 memset(acb, 0, acb_len);
9511 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9512 if (rval != QLA_SUCCESS) {
9517 rval = qla4xxx_disable_acb(ha);
9518 if (rval != QLA_SUCCESS) {
9523 wait_for_completion_timeout(&ha->disable_acb_comp,
9524 DISABLE_ACB_TOV * HZ);
9526 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9527 if (rval != QLA_SUCCESS) {
9533 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9536 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9537 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9541 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9543 struct scsi_qla_host *ha = to_qla_host(shost);
9544 int rval = QLA_SUCCESS;
9547 if (ql4xdontresethba) {
9548 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9551 goto exit_host_reset;
9554 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9555 goto recover_adapter;
9557 switch (reset_type) {
9558 case SCSI_ADAPTER_RESET:
9559 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9561 case SCSI_FIRMWARE_RESET:
9562 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9564 /* set firmware context reset */
9565 set_bit(DPC_RESET_HA_FW_CONTEXT,
9568 rval = qla4xxx_context_reset(ha);
9569 goto exit_host_reset;
9576 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9577 * reset is issued by application */
9578 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9579 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9580 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9581 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9582 (idc_ctrl | GRACEFUL_RESET_BIT1));
9585 rval = qla4xxx_recover_adapter(ha);
9586 if (rval != QLA_SUCCESS) {
9587 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9596 /* PCI AER driver recovers from all correctable errors w/o
9597 * driver intervention. For uncorrectable errors PCI AER
9598 * driver calls the following device driver's callbacks
9600 * - Fatal Errors - link_reset
9601 * - Non-Fatal Errors - driver's error_detected() which
9602 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9604 * PCI AER driver calls
9605 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9606 * returns RECOVERED or NEED_RESET if fw_hung
9607 * NEED_RESET - driver's slot_reset()
9608 * DISCONNECT - device is dead & cannot recover
9609 * RECOVERED - driver's resume()
9611 static pci_ers_result_t
9612 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9614 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9616 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9617 ha->host_no, __func__, state);
9619 if (!is_aer_supported(ha))
9620 return PCI_ERS_RESULT_NONE;
9623 case pci_channel_io_normal:
9624 clear_bit(AF_EEH_BUSY, &ha->flags);
9625 return PCI_ERS_RESULT_CAN_RECOVER;
9626 case pci_channel_io_frozen:
9627 set_bit(AF_EEH_BUSY, &ha->flags);
9628 qla4xxx_mailbox_premature_completion(ha);
9629 qla4xxx_free_irqs(ha);
9630 pci_disable_device(pdev);
9631 /* Return back all IOs */
9632 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9633 return PCI_ERS_RESULT_NEED_RESET;
9634 case pci_channel_io_perm_failure:
9635 set_bit(AF_EEH_BUSY, &ha->flags);
9636 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9637 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9638 return PCI_ERS_RESULT_DISCONNECT;
9640 return PCI_ERS_RESULT_NEED_RESET;
9644 * qla4xxx_pci_mmio_enabled() gets called if
9645 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9646 * and read/write to the device still works.
9648 static pci_ers_result_t
9649 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9651 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9653 if (!is_aer_supported(ha))
9654 return PCI_ERS_RESULT_NONE;
9656 return PCI_ERS_RESULT_RECOVERED;
9659 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9661 uint32_t rval = QLA_ERROR;
9663 struct pci_dev *other_pdev = NULL;
9665 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9667 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9669 if (test_bit(AF_ONLINE, &ha->flags)) {
9670 clear_bit(AF_ONLINE, &ha->flags);
9671 clear_bit(AF_LINK_UP, &ha->flags);
9672 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9673 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9676 fn = PCI_FUNC(ha->pdev->devfn);
9677 if (is_qla8022(ha)) {
9680 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9681 ha->host_no, __func__, fn);
9682 /* Get the pci device given the domain, bus,
9683 * slot/function number */
9684 other_pdev = pci_get_domain_bus_and_slot(
9685 pci_domain_nr(ha->pdev->bus),
9686 ha->pdev->bus->number,
9687 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9693 if (atomic_read(&other_pdev->enable_cnt)) {
9694 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9695 ha->host_no, __func__, fn);
9696 pci_dev_put(other_pdev);
9699 pci_dev_put(other_pdev);
9702 /* this case is meant for ISP83xx/ISP84xx only */
9703 if (qla4_83xx_can_perform_reset(ha)) {
9704 /* reset fn as iSCSI is going to perform the reset */
9709 /* The first function on the card, the reset owner will
9710 * start & initialize the firmware. The other functions
9711 * on the card will reset the firmware context
9714 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9715 "0x%x is the owner\n", ha->host_no, __func__,
9718 ha->isp_ops->idc_lock(ha);
9719 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9721 ha->isp_ops->idc_unlock(ha);
9723 rval = qla4_8xxx_update_idc_reg(ha);
9724 if (rval == QLA_ERROR) {
9725 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9726 ha->host_no, __func__);
9727 ha->isp_ops->idc_lock(ha);
9728 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9729 QLA8XXX_DEV_FAILED);
9730 ha->isp_ops->idc_unlock(ha);
9731 goto exit_error_recovery;
9734 clear_bit(AF_FW_RECOVERY, &ha->flags);
9735 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9737 if (rval != QLA_SUCCESS) {
9738 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9739 "FAILED\n", ha->host_no, __func__);
9740 qla4xxx_free_irqs(ha);
9741 ha->isp_ops->idc_lock(ha);
9742 qla4_8xxx_clear_drv_active(ha);
9743 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9744 QLA8XXX_DEV_FAILED);
9745 ha->isp_ops->idc_unlock(ha);
9747 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9748 "READY\n", ha->host_no, __func__);
9749 ha->isp_ops->idc_lock(ha);
9750 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9752 /* Clear driver state register */
9753 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9754 qla4_8xxx_set_drv_active(ha);
9755 ha->isp_ops->idc_unlock(ha);
9756 ha->isp_ops->enable_intrs(ha);
9759 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9760 "the reset owner\n", ha->host_no, __func__,
9762 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9763 QLA8XXX_DEV_READY)) {
9764 clear_bit(AF_FW_RECOVERY, &ha->flags);
9765 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9766 if (rval == QLA_SUCCESS)
9767 ha->isp_ops->enable_intrs(ha);
9769 qla4xxx_free_irqs(ha);
9771 ha->isp_ops->idc_lock(ha);
9772 qla4_8xxx_set_drv_active(ha);
9773 ha->isp_ops->idc_unlock(ha);
9776 exit_error_recovery:
9777 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9781 static pci_ers_result_t
9782 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9784 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9785 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9788 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9789 ha->host_no, __func__);
9791 if (!is_aer_supported(ha))
9792 return PCI_ERS_RESULT_NONE;
9794 /* Restore the saved state of PCIe device -
9795 * BAR registers, PCI Config space, PCIX, MSI,
9798 pci_restore_state(pdev);
9800 /* pci_restore_state() clears the saved_state flag of the device
9801 * save restored state which resets saved_state flag
9803 pci_save_state(pdev);
9805 /* Initialize device or resume if in suspended state */
9806 rc = pci_enable_device(pdev);
9808 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9809 "device after reset\n", ha->host_no, __func__);
9810 goto exit_slot_reset;
9813 ha->isp_ops->disable_intrs(ha);
9815 if (is_qla80XX(ha)) {
9816 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9817 ret = PCI_ERS_RESULT_RECOVERED;
9818 goto exit_slot_reset;
9820 goto exit_slot_reset;
9824 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9825 "device after reset\n", ha->host_no, __func__, ret);
9830 qla4xxx_pci_resume(struct pci_dev *pdev)
9832 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9835 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9836 ha->host_no, __func__);
9838 ret = qla4xxx_wait_for_hba_online(ha);
9839 if (ret != QLA_SUCCESS) {
9840 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9841 "resume I/O from slot/link_reset\n", ha->host_no,
9845 pci_cleanup_aer_uncorrect_error_status(pdev);
9846 clear_bit(AF_EEH_BUSY, &ha->flags);
9849 static const struct pci_error_handlers qla4xxx_err_handler = {
9850 .error_detected = qla4xxx_pci_error_detected,
9851 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9852 .slot_reset = qla4xxx_pci_slot_reset,
9853 .resume = qla4xxx_pci_resume,
9856 static struct pci_device_id qla4xxx_pci_tbl[] = {
9858 .vendor = PCI_VENDOR_ID_QLOGIC,
9859 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9860 .subvendor = PCI_ANY_ID,
9861 .subdevice = PCI_ANY_ID,
9864 .vendor = PCI_VENDOR_ID_QLOGIC,
9865 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9866 .subvendor = PCI_ANY_ID,
9867 .subdevice = PCI_ANY_ID,
9870 .vendor = PCI_VENDOR_ID_QLOGIC,
9871 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9872 .subvendor = PCI_ANY_ID,
9873 .subdevice = PCI_ANY_ID,
9876 .vendor = PCI_VENDOR_ID_QLOGIC,
9877 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9878 .subvendor = PCI_ANY_ID,
9879 .subdevice = PCI_ANY_ID,
9882 .vendor = PCI_VENDOR_ID_QLOGIC,
9883 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9884 .subvendor = PCI_ANY_ID,
9885 .subdevice = PCI_ANY_ID,
9888 .vendor = PCI_VENDOR_ID_QLOGIC,
9889 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9890 .subvendor = PCI_ANY_ID,
9891 .subdevice = PCI_ANY_ID,
9895 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9897 static struct pci_driver qla4xxx_pci_driver = {
9898 .name = DRIVER_NAME,
9899 .id_table = qla4xxx_pci_tbl,
9900 .probe = qla4xxx_probe_adapter,
9901 .remove = qla4xxx_remove_adapter,
9902 .err_handler = &qla4xxx_err_handler,
9905 static int __init qla4xxx_module_init(void)
9909 if (ql4xqfulltracking)
9910 qla4xxx_driver_template.track_queue_depth = 1;
9912 /* Allocate cache for SRBs. */
9913 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9914 SLAB_HWCACHE_ALIGN, NULL);
9915 if (srb_cachep == NULL) {
9917 "%s: Unable to allocate SRB cache..."
9918 "Failing load!\n", DRIVER_NAME);
9923 /* Derive version string. */
9924 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9925 if (ql4xextended_error_logging)
9926 strcat(qla4xxx_version_str, "-debug");
9928 qla4xxx_scsi_transport =
9929 iscsi_register_transport(&qla4xxx_iscsi_transport);
9930 if (!qla4xxx_scsi_transport){
9932 goto release_srb_cache;
9935 ret = pci_register_driver(&qla4xxx_pci_driver);
9937 goto unregister_transport;
9939 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9942 unregister_transport:
9943 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9945 kmem_cache_destroy(srb_cachep);
9950 static void __exit qla4xxx_module_exit(void)
9952 pci_unregister_driver(&qla4xxx_pci_driver);
9953 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9954 kmem_cache_destroy(srb_cachep);
9957 module_init(qla4xxx_module_init);
9958 module_exit(qla4xxx_module_exit);
9960 MODULE_AUTHOR("QLogic Corporation");
9961 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9962 MODULE_LICENSE("GPL");
9963 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);