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_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
847 if (chap_table == NULL)
850 memset(chap_table, 0, sizeof(struct ql4_chap_table));
853 max_chap_entries = (ha->hw.flt_chap_size / 2) /
854 sizeof(struct ql4_chap_table);
856 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
858 if (chap_tbl_idx > max_chap_entries) {
860 goto exit_delete_chap;
863 /* Check if chap index is in use.
864 * If chap is in use don't delet chap entry */
865 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
867 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
868 "delete from flash\n", chap_tbl_idx);
870 goto exit_delete_chap;
873 chap_size = sizeof(struct ql4_chap_table);
875 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
877 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
878 /* flt_chap_size is CHAP table size for both ports
879 * so divide it by 2 to calculate the offset for second port
881 if (ha->port_num == 1)
882 offset += (ha->hw.flt_chap_size / 2);
883 offset += (chap_tbl_idx * chap_size);
886 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
887 if (ret != QLA_SUCCESS) {
889 goto exit_delete_chap;
892 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
893 __le16_to_cpu(chap_table->cookie)));
895 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
896 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
897 goto exit_delete_chap;
900 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
902 offset = FLASH_CHAP_OFFSET |
903 (chap_tbl_idx * sizeof(struct ql4_chap_table));
904 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
905 FLASH_OPT_RMW_COMMIT);
906 if (ret == QLA_SUCCESS && ha->chap_list) {
907 mutex_lock(&ha->chap_sem);
908 /* Update ha chap_list cache */
909 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
910 chap_table, sizeof(struct ql4_chap_table));
911 mutex_unlock(&ha->chap_sem);
913 if (ret != QLA_SUCCESS)
917 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
922 * qla4xxx_set_chap_entry - Make chap entry with given information
923 * @shost: pointer to host
924 * @data: chap info - credentials, index and type to make chap entry
925 * @len: length of data
927 * Add or update chap entry with the given information
929 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
931 struct scsi_qla_host *ha = to_qla_host(shost);
932 struct iscsi_chap_rec chap_rec;
933 struct ql4_chap_table *chap_entry = NULL;
934 struct iscsi_param_info *param_info;
936 int max_chap_entries = 0;
942 memset(&chap_rec, 0, sizeof(chap_rec));
944 nla_for_each_attr(attr, data, len, rem) {
945 if (nla_len(attr) < sizeof(*param_info)) {
950 param_info = nla_data(attr);
952 switch (param_info->param) {
953 case ISCSI_CHAP_PARAM_INDEX:
954 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
956 case ISCSI_CHAP_PARAM_CHAP_TYPE:
957 chap_rec.chap_type = param_info->value[0];
959 case ISCSI_CHAP_PARAM_USERNAME:
960 size = min_t(size_t, sizeof(chap_rec.username),
962 memcpy(chap_rec.username, param_info->value, size);
964 case ISCSI_CHAP_PARAM_PASSWORD:
965 size = min_t(size_t, sizeof(chap_rec.password),
967 memcpy(chap_rec.password, param_info->value, size);
969 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
970 chap_rec.password_length = param_info->value[0];
973 ql4_printk(KERN_ERR, ha,
974 "%s: No such sysfs attribute\n", __func__);
980 if (chap_rec.chap_type == CHAP_TYPE_IN)
986 max_chap_entries = (ha->hw.flt_chap_size / 2) /
987 sizeof(struct ql4_chap_table);
989 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
991 mutex_lock(&ha->chap_sem);
992 if (chap_rec.chap_tbl_idx < max_chap_entries) {
993 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
996 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
997 ql4_printk(KERN_INFO, ha,
998 "Type mismatch for CHAP entry %d\n",
999 chap_rec.chap_tbl_idx);
1001 goto exit_unlock_chap;
1004 /* If chap index is in use then don't modify it */
1005 rc = qla4xxx_is_chap_active(shost,
1006 chap_rec.chap_tbl_idx);
1008 ql4_printk(KERN_INFO, ha,
1009 "CHAP entry %d is in use\n",
1010 chap_rec.chap_tbl_idx);
1012 goto exit_unlock_chap;
1016 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1018 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1020 goto exit_unlock_chap;
1024 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1025 chap_rec.chap_tbl_idx, type);
1028 mutex_unlock(&ha->chap_sem);
1035 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1037 struct scsi_qla_host *ha = to_qla_host(shost);
1038 struct iscsi_offload_host_stats *host_stats = NULL;
1039 int host_stats_size;
1042 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1044 dma_addr_t iscsi_stats_dma;
1046 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1048 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1050 if (host_stats_size != len) {
1051 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1052 __func__, len, host_stats_size);
1054 goto exit_host_stats;
1056 host_stats = (struct iscsi_offload_host_stats *)buf;
1060 goto exit_host_stats;
1063 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1065 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1066 &iscsi_stats_dma, GFP_KERNEL);
1067 if (!ql_iscsi_stats) {
1068 ql4_printk(KERN_ERR, ha,
1069 "Unable to allocate memory for iscsi stats\n");
1071 goto exit_host_stats;
1074 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1076 if (ret != QLA_SUCCESS) {
1077 ql4_printk(KERN_ERR, ha,
1078 "Unable to retrieve iscsi stats\n");
1080 goto exit_host_stats;
1082 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1083 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1084 host_stats->mactx_multicast_frames =
1085 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1086 host_stats->mactx_broadcast_frames =
1087 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1088 host_stats->mactx_pause_frames =
1089 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1090 host_stats->mactx_control_frames =
1091 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1092 host_stats->mactx_deferral =
1093 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1094 host_stats->mactx_excess_deferral =
1095 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1096 host_stats->mactx_late_collision =
1097 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1098 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1099 host_stats->mactx_single_collision =
1100 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1101 host_stats->mactx_multiple_collision =
1102 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1103 host_stats->mactx_collision =
1104 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1105 host_stats->mactx_frames_dropped =
1106 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1107 host_stats->mactx_jumbo_frames =
1108 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1109 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1110 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1111 host_stats->macrx_unknown_control_frames =
1112 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1113 host_stats->macrx_pause_frames =
1114 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1115 host_stats->macrx_control_frames =
1116 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1117 host_stats->macrx_dribble =
1118 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1119 host_stats->macrx_frame_length_error =
1120 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1121 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1122 host_stats->macrx_carrier_sense_error =
1123 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1124 host_stats->macrx_frame_discarded =
1125 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1126 host_stats->macrx_frames_dropped =
1127 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1128 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1129 host_stats->mac_encoding_error =
1130 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1131 host_stats->macrx_length_error_large =
1132 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1133 host_stats->macrx_length_error_small =
1134 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1135 host_stats->macrx_multicast_frames =
1136 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1137 host_stats->macrx_broadcast_frames =
1138 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1139 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1140 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1141 host_stats->iptx_fragments =
1142 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1143 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1144 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1145 host_stats->iprx_fragments =
1146 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1147 host_stats->ip_datagram_reassembly =
1148 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1149 host_stats->ip_invalid_address_error =
1150 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1151 host_stats->ip_error_packets =
1152 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1153 host_stats->ip_fragrx_overlap =
1154 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1155 host_stats->ip_fragrx_outoforder =
1156 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1157 host_stats->ip_datagram_reassembly_timeout =
1158 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1159 host_stats->ipv6tx_packets =
1160 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1161 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1162 host_stats->ipv6tx_fragments =
1163 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1164 host_stats->ipv6rx_packets =
1165 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1166 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1167 host_stats->ipv6rx_fragments =
1168 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1169 host_stats->ipv6_datagram_reassembly =
1170 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1171 host_stats->ipv6_invalid_address_error =
1172 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1173 host_stats->ipv6_error_packets =
1174 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1175 host_stats->ipv6_fragrx_overlap =
1176 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1177 host_stats->ipv6_fragrx_outoforder =
1178 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1179 host_stats->ipv6_datagram_reassembly_timeout =
1180 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1181 host_stats->tcptx_segments =
1182 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1183 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1184 host_stats->tcprx_segments =
1185 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1186 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1187 host_stats->tcp_duplicate_ack_retx =
1188 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1189 host_stats->tcp_retx_timer_expired =
1190 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1191 host_stats->tcprx_duplicate_ack =
1192 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1193 host_stats->tcprx_pure_ackr =
1194 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1195 host_stats->tcptx_delayed_ack =
1196 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1197 host_stats->tcptx_pure_ack =
1198 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1199 host_stats->tcprx_segment_error =
1200 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1201 host_stats->tcprx_segment_outoforder =
1202 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1203 host_stats->tcprx_window_probe =
1204 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1205 host_stats->tcprx_window_update =
1206 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1207 host_stats->tcptx_window_probe_persist =
1208 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1209 host_stats->ecc_error_correction =
1210 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1211 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1212 host_stats->iscsi_data_bytes_tx =
1213 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1214 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1215 host_stats->iscsi_data_bytes_rx =
1216 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1217 host_stats->iscsi_io_completed =
1218 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1219 host_stats->iscsi_unexpected_io_rx =
1220 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1221 host_stats->iscsi_format_error =
1222 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1223 host_stats->iscsi_hdr_digest_error =
1224 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1225 host_stats->iscsi_data_digest_error =
1226 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1227 host_stats->iscsi_sequence_error =
1228 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1231 dma_free_coherent(&ha->pdev->dev, stats_size,
1232 ql_iscsi_stats, iscsi_stats_dma);
1234 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1239 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1240 enum iscsi_param_type param_type,
1241 int param, char *buf)
1243 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1244 struct scsi_qla_host *ha = to_qla_host(shost);
1249 if (param_type == ISCSI_NET_PARAM) {
1251 case ISCSI_NET_PARAM_IPV4_ADDR:
1252 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1254 case ISCSI_NET_PARAM_IPV4_SUBNET:
1255 len = sprintf(buf, "%pI4\n",
1256 &ha->ip_config.subnet_mask);
1258 case ISCSI_NET_PARAM_IPV4_GW:
1259 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1261 case ISCSI_NET_PARAM_IFACE_ENABLE:
1262 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1263 OP_STATE(ha->ip_config.ipv4_options,
1264 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1266 OP_STATE(ha->ip_config.ipv6_options,
1267 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1270 len = sprintf(buf, "%s\n", pval);
1272 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1273 len = sprintf(buf, "%s\n",
1274 (ha->ip_config.tcp_options &
1275 TCPOPT_DHCP_ENABLE) ?
1278 case ISCSI_NET_PARAM_IPV6_ADDR:
1279 if (iface->iface_num == 0)
1280 len = sprintf(buf, "%pI6\n",
1281 &ha->ip_config.ipv6_addr0);
1282 if (iface->iface_num == 1)
1283 len = sprintf(buf, "%pI6\n",
1284 &ha->ip_config.ipv6_addr1);
1286 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1287 len = sprintf(buf, "%pI6\n",
1288 &ha->ip_config.ipv6_link_local_addr);
1290 case ISCSI_NET_PARAM_IPV6_ROUTER:
1291 len = sprintf(buf, "%pI6\n",
1292 &ha->ip_config.ipv6_default_router_addr);
1294 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1295 pval = (ha->ip_config.ipv6_addl_options &
1296 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1299 len = sprintf(buf, "%s\n", pval);
1301 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1302 pval = (ha->ip_config.ipv6_addl_options &
1303 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1306 len = sprintf(buf, "%s\n", pval);
1308 case ISCSI_NET_PARAM_VLAN_ID:
1309 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1310 ival = ha->ip_config.ipv4_vlan_tag &
1313 ival = ha->ip_config.ipv6_vlan_tag &
1316 len = sprintf(buf, "%d\n", ival);
1318 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1319 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1320 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1321 ISCSI_MAX_VLAN_PRIORITY;
1323 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1324 ISCSI_MAX_VLAN_PRIORITY;
1326 len = sprintf(buf, "%d\n", ival);
1328 case ISCSI_NET_PARAM_VLAN_ENABLED:
1329 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1330 OP_STATE(ha->ip_config.ipv4_options,
1331 IPOPT_VLAN_TAGGING_ENABLE, pval);
1333 OP_STATE(ha->ip_config.ipv6_options,
1334 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1336 len = sprintf(buf, "%s\n", pval);
1338 case ISCSI_NET_PARAM_MTU:
1339 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1341 case ISCSI_NET_PARAM_PORT:
1342 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1343 len = sprintf(buf, "%d\n",
1344 ha->ip_config.ipv4_port);
1346 len = sprintf(buf, "%d\n",
1347 ha->ip_config.ipv6_port);
1349 case ISCSI_NET_PARAM_IPADDR_STATE:
1350 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1351 pval = iscsi_get_ipaddress_state_name(
1352 ha->ip_config.ipv4_addr_state);
1354 if (iface->iface_num == 0)
1355 pval = iscsi_get_ipaddress_state_name(
1356 ha->ip_config.ipv6_addr0_state);
1357 else if (iface->iface_num == 1)
1358 pval = iscsi_get_ipaddress_state_name(
1359 ha->ip_config.ipv6_addr1_state);
1362 len = sprintf(buf, "%s\n", pval);
1364 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1365 pval = iscsi_get_ipaddress_state_name(
1366 ha->ip_config.ipv6_link_local_state);
1367 len = sprintf(buf, "%s\n", pval);
1369 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1370 pval = iscsi_get_router_state_name(
1371 ha->ip_config.ipv6_default_router_state);
1372 len = sprintf(buf, "%s\n", pval);
1374 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1375 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1376 OP_STATE(~ha->ip_config.tcp_options,
1377 TCPOPT_DELAYED_ACK_DISABLE, pval);
1379 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1380 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1382 len = sprintf(buf, "%s\n", pval);
1384 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1385 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1386 OP_STATE(~ha->ip_config.tcp_options,
1387 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1389 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1390 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1392 len = sprintf(buf, "%s\n", pval);
1394 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1395 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1396 OP_STATE(~ha->ip_config.tcp_options,
1397 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1399 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1400 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1403 len = sprintf(buf, "%s\n", pval);
1405 case ISCSI_NET_PARAM_TCP_WSF:
1406 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1407 len = sprintf(buf, "%d\n",
1408 ha->ip_config.tcp_wsf);
1410 len = sprintf(buf, "%d\n",
1411 ha->ip_config.ipv6_tcp_wsf);
1413 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1414 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1415 ival = (ha->ip_config.tcp_options &
1416 TCPOPT_TIMER_SCALE) >> 1;
1418 ival = (ha->ip_config.ipv6_tcp_options &
1419 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1421 len = sprintf(buf, "%d\n", ival);
1423 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1424 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1425 OP_STATE(ha->ip_config.tcp_options,
1426 TCPOPT_TIMESTAMP_ENABLE, pval);
1428 OP_STATE(ha->ip_config.ipv6_tcp_options,
1429 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1431 len = sprintf(buf, "%s\n", pval);
1433 case ISCSI_NET_PARAM_CACHE_ID:
1434 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1435 len = sprintf(buf, "%d\n",
1436 ha->ip_config.ipv4_cache_id);
1438 len = sprintf(buf, "%d\n",
1439 ha->ip_config.ipv6_cache_id);
1441 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1442 OP_STATE(ha->ip_config.tcp_options,
1443 TCPOPT_DNS_SERVER_IP_EN, pval);
1445 len = sprintf(buf, "%s\n", pval);
1447 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1448 OP_STATE(ha->ip_config.tcp_options,
1449 TCPOPT_SLP_DA_INFO_EN, pval);
1451 len = sprintf(buf, "%s\n", pval);
1453 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1454 OP_STATE(ha->ip_config.ipv4_options,
1455 IPOPT_IPV4_TOS_EN, pval);
1457 len = sprintf(buf, "%s\n", pval);
1459 case ISCSI_NET_PARAM_IPV4_TOS:
1460 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1462 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1463 OP_STATE(ha->ip_config.ipv4_options,
1464 IPOPT_GRAT_ARP_EN, pval);
1466 len = sprintf(buf, "%s\n", pval);
1468 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1469 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1472 len = sprintf(buf, "%s\n", pval);
1474 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1475 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1476 (char *)ha->ip_config.ipv4_alt_cid : "";
1478 len = sprintf(buf, "%s\n", pval);
1480 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1481 OP_STATE(ha->ip_config.ipv4_options,
1482 IPOPT_REQ_VID_EN, pval);
1484 len = sprintf(buf, "%s\n", pval);
1486 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1487 OP_STATE(ha->ip_config.ipv4_options,
1488 IPOPT_USE_VID_EN, pval);
1490 len = sprintf(buf, "%s\n", pval);
1492 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1493 pval = (ha->ip_config.ipv4_vid_len) ?
1494 (char *)ha->ip_config.ipv4_vid : "";
1496 len = sprintf(buf, "%s\n", pval);
1498 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1499 OP_STATE(ha->ip_config.ipv4_options,
1500 IPOPT_LEARN_IQN_EN, pval);
1502 len = sprintf(buf, "%s\n", pval);
1504 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1505 OP_STATE(~ha->ip_config.ipv4_options,
1506 IPOPT_FRAGMENTATION_DISABLE, pval);
1508 len = sprintf(buf, "%s\n", pval);
1510 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1511 OP_STATE(ha->ip_config.ipv4_options,
1512 IPOPT_IN_FORWARD_EN, pval);
1514 len = sprintf(buf, "%s\n", pval);
1516 case ISCSI_NET_PARAM_REDIRECT_EN:
1517 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1518 OP_STATE(ha->ip_config.ipv4_options,
1519 IPOPT_ARP_REDIRECT_EN, pval);
1521 OP_STATE(ha->ip_config.ipv6_options,
1522 IPV6_OPT_REDIRECT_EN, pval);
1524 len = sprintf(buf, "%s\n", pval);
1526 case ISCSI_NET_PARAM_IPV4_TTL:
1527 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1529 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1530 OP_STATE(ha->ip_config.ipv6_options,
1531 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1533 len = sprintf(buf, "%s\n", pval);
1535 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1536 OP_STATE(ha->ip_config.ipv6_addl_options,
1537 IPV6_ADDOPT_MLD_EN, pval);
1539 len = sprintf(buf, "%s\n", pval);
1541 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1542 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1544 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1545 len = sprintf(buf, "%d\n",
1546 ha->ip_config.ipv6_traffic_class);
1548 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1549 len = sprintf(buf, "%d\n",
1550 ha->ip_config.ipv6_hop_limit);
1552 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1553 len = sprintf(buf, "%d\n",
1554 ha->ip_config.ipv6_nd_reach_time);
1556 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1557 len = sprintf(buf, "%d\n",
1558 ha->ip_config.ipv6_nd_rexmit_timer);
1560 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1561 len = sprintf(buf, "%d\n",
1562 ha->ip_config.ipv6_nd_stale_timeout);
1564 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1565 len = sprintf(buf, "%d\n",
1566 ha->ip_config.ipv6_dup_addr_detect_count);
1568 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1569 len = sprintf(buf, "%d\n",
1570 ha->ip_config.ipv6_gw_advrt_mtu);
1575 } else if (param_type == ISCSI_IFACE_PARAM) {
1577 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1578 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1580 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1581 OP_STATE(ha->ip_config.iscsi_options,
1582 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1584 len = sprintf(buf, "%s\n", pval);
1586 case ISCSI_IFACE_PARAM_DATADGST_EN:
1587 OP_STATE(ha->ip_config.iscsi_options,
1588 ISCSIOPTS_DATA_DIGEST_EN, pval);
1590 len = sprintf(buf, "%s\n", pval);
1592 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1593 OP_STATE(ha->ip_config.iscsi_options,
1594 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1596 len = sprintf(buf, "%s\n", pval);
1598 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1599 OP_STATE(ha->ip_config.iscsi_options,
1600 ISCSIOPTS_INITIAL_R2T_EN, pval);
1602 len = sprintf(buf, "%s\n", pval);
1604 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1605 OP_STATE(ha->ip_config.iscsi_options,
1606 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1608 len = sprintf(buf, "%s\n", pval);
1610 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1611 OP_STATE(ha->ip_config.iscsi_options,
1612 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1614 len = sprintf(buf, "%s\n", pval);
1616 case ISCSI_IFACE_PARAM_ERL:
1617 len = sprintf(buf, "%d\n",
1618 (ha->ip_config.iscsi_options &
1621 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1622 len = sprintf(buf, "%u\n",
1623 ha->ip_config.iscsi_max_pdu_size *
1626 case ISCSI_IFACE_PARAM_FIRST_BURST:
1627 len = sprintf(buf, "%u\n",
1628 ha->ip_config.iscsi_first_burst_len *
1631 case ISCSI_IFACE_PARAM_MAX_R2T:
1632 len = sprintf(buf, "%d\n",
1633 ha->ip_config.iscsi_max_outstnd_r2t);
1635 case ISCSI_IFACE_PARAM_MAX_BURST:
1636 len = sprintf(buf, "%u\n",
1637 ha->ip_config.iscsi_max_burst_len *
1640 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1641 OP_STATE(ha->ip_config.iscsi_options,
1642 ISCSIOPTS_CHAP_AUTH_EN, pval);
1644 len = sprintf(buf, "%s\n", pval);
1646 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1647 OP_STATE(ha->ip_config.iscsi_options,
1648 ISCSIOPTS_BIDI_CHAP_EN, pval);
1650 len = sprintf(buf, "%s\n", pval);
1652 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1653 OP_STATE(ha->ip_config.iscsi_options,
1654 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1656 len = sprintf(buf, "%s\n", pval);
1658 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1659 OP_STATE(ha->ip_config.iscsi_options,
1660 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1662 len = sprintf(buf, "%s\n", pval);
1664 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1665 OP_STATE(ha->ip_config.iscsi_options,
1666 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1668 len = sprintf(buf, "%s\n", pval);
1670 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1671 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1681 static struct iscsi_endpoint *
1682 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1686 struct iscsi_endpoint *ep;
1687 struct qla_endpoint *qla_ep;
1688 struct scsi_qla_host *ha;
1689 struct sockaddr_in *addr;
1690 struct sockaddr_in6 *addr6;
1694 pr_err("%s: shost is NULL\n", __func__);
1695 return ERR_PTR(ret);
1698 ha = iscsi_host_priv(shost);
1699 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1702 return ERR_PTR(ret);
1705 qla_ep = ep->dd_data;
1706 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1707 if (dst_addr->sa_family == AF_INET) {
1708 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1709 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1710 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1711 (char *)&addr->sin_addr));
1712 } else if (dst_addr->sa_family == AF_INET6) {
1713 memcpy(&qla_ep->dst_addr, dst_addr,
1714 sizeof(struct sockaddr_in6));
1715 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1716 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1717 (char *)&addr6->sin6_addr));
1719 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1723 qla_ep->host = shost;
1728 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1730 struct qla_endpoint *qla_ep;
1731 struct scsi_qla_host *ha;
1734 qla_ep = ep->dd_data;
1735 ha = to_qla_host(qla_ep->host);
1736 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1738 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1744 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1746 struct qla_endpoint *qla_ep;
1747 struct scsi_qla_host *ha;
1749 qla_ep = ep->dd_data;
1750 ha = to_qla_host(qla_ep->host);
1751 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1753 iscsi_destroy_endpoint(ep);
1756 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1757 enum iscsi_param param,
1760 struct qla_endpoint *qla_ep = ep->dd_data;
1761 struct sockaddr *dst_addr;
1762 struct scsi_qla_host *ha;
1767 ha = to_qla_host(qla_ep->host);
1768 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1772 case ISCSI_PARAM_CONN_PORT:
1773 case ISCSI_PARAM_CONN_ADDRESS:
1774 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1778 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1779 &qla_ep->dst_addr, param, buf);
1785 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1786 struct iscsi_stats *stats)
1788 struct iscsi_session *sess;
1789 struct iscsi_cls_session *cls_sess;
1790 struct ddb_entry *ddb_entry;
1791 struct scsi_qla_host *ha;
1792 struct ql_iscsi_stats *ql_iscsi_stats;
1795 dma_addr_t iscsi_stats_dma;
1797 cls_sess = iscsi_conn_to_session(cls_conn);
1798 sess = cls_sess->dd_data;
1799 ddb_entry = sess->dd_data;
1802 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1804 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1805 /* Allocate memory */
1806 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1807 &iscsi_stats_dma, GFP_KERNEL);
1808 if (!ql_iscsi_stats) {
1809 ql4_printk(KERN_ERR, ha,
1810 "Unable to allocate memory for iscsi stats\n");
1811 goto exit_get_stats;
1814 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1816 if (ret != QLA_SUCCESS) {
1817 ql4_printk(KERN_ERR, ha,
1818 "Unable to retrieve iscsi stats\n");
1823 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1824 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1826 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1827 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1828 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1829 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1830 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1831 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1832 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1833 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1835 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1836 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1837 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1838 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1839 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1840 stats->logoutrsp_pdus =
1841 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1842 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1843 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1844 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1847 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1853 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1855 struct iscsi_cls_session *session;
1856 struct iscsi_session *sess;
1857 unsigned long flags;
1858 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
1860 session = starget_to_session(scsi_target(sc->device));
1861 sess = session->dd_data;
1863 spin_lock_irqsave(&session->lock, flags);
1864 if (session->state == ISCSI_SESSION_FAILED)
1865 ret = BLK_EH_RESET_TIMER;
1866 spin_unlock_irqrestore(&session->lock, flags);
1871 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1873 struct scsi_qla_host *ha = to_qla_host(shost);
1874 struct iscsi_cls_host *ihost = shost->shost_data;
1875 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1877 qla4xxx_get_firmware_state(ha);
1879 switch (ha->addl_fw_state & 0x0F00) {
1880 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1881 speed = ISCSI_PORT_SPEED_10MBPS;
1883 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1884 speed = ISCSI_PORT_SPEED_100MBPS;
1886 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1887 speed = ISCSI_PORT_SPEED_1GBPS;
1889 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1890 speed = ISCSI_PORT_SPEED_10GBPS;
1893 ihost->port_speed = speed;
1896 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1898 struct scsi_qla_host *ha = to_qla_host(shost);
1899 struct iscsi_cls_host *ihost = shost->shost_data;
1900 uint32_t state = ISCSI_PORT_STATE_DOWN;
1902 if (test_bit(AF_LINK_UP, &ha->flags))
1903 state = ISCSI_PORT_STATE_UP;
1905 ihost->port_state = state;
1908 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1909 enum iscsi_host_param param, char *buf)
1911 struct scsi_qla_host *ha = to_qla_host(shost);
1915 case ISCSI_HOST_PARAM_HWADDRESS:
1916 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1918 case ISCSI_HOST_PARAM_IPADDRESS:
1919 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1921 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1922 len = sprintf(buf, "%s\n", ha->name_string);
1924 case ISCSI_HOST_PARAM_PORT_STATE:
1925 qla4xxx_set_port_state(shost);
1926 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1928 case ISCSI_HOST_PARAM_PORT_SPEED:
1929 qla4xxx_set_port_speed(shost);
1930 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1939 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1945 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1946 &qla4xxx_iscsi_transport,
1947 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1948 if (!ha->iface_ipv4)
1949 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1953 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1955 if (!ha->iface_ipv6_0)
1957 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1958 &qla4xxx_iscsi_transport,
1959 ISCSI_IFACE_TYPE_IPV6, 0,
1961 if (!ha->iface_ipv6_0)
1962 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1965 if (!ha->iface_ipv6_1)
1967 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1968 &qla4xxx_iscsi_transport,
1969 ISCSI_IFACE_TYPE_IPV6, 1,
1971 if (!ha->iface_ipv6_1)
1972 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1976 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1978 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1979 qla4xxx_create_ipv4_iface(ha);
1981 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1982 qla4xxx_create_ipv6_iface(ha);
1985 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1987 if (ha->iface_ipv4) {
1988 iscsi_destroy_iface(ha->iface_ipv4);
1989 ha->iface_ipv4 = NULL;
1993 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1995 if (ha->iface_ipv6_0) {
1996 iscsi_destroy_iface(ha->iface_ipv6_0);
1997 ha->iface_ipv6_0 = NULL;
1999 if (ha->iface_ipv6_1) {
2000 iscsi_destroy_iface(ha->iface_ipv6_1);
2001 ha->iface_ipv6_1 = NULL;
2005 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
2007 qla4xxx_destroy_ipv4_iface(ha);
2008 qla4xxx_destroy_ipv6_iface(ha);
2011 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2012 struct iscsi_iface_param_info *iface_param,
2013 struct addr_ctrl_blk *init_fw_cb)
2016 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2017 * iface_num 1 is valid only for IPv6 Addr.
2019 switch (iface_param->param) {
2020 case ISCSI_NET_PARAM_IPV6_ADDR:
2021 if (iface_param->iface_num & 0x1)
2023 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2024 sizeof(init_fw_cb->ipv6_addr1));
2027 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2028 sizeof(init_fw_cb->ipv6_addr0));
2030 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2031 if (iface_param->iface_num & 0x1)
2033 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2034 sizeof(init_fw_cb->ipv6_if_id));
2036 case ISCSI_NET_PARAM_IPV6_ROUTER:
2037 if (iface_param->iface_num & 0x1)
2039 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2040 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2042 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2043 /* Autocfg applies to even interface */
2044 if (iface_param->iface_num & 0x1)
2047 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2048 init_fw_cb->ipv6_addtl_opts &=
2050 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2051 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2052 init_fw_cb->ipv6_addtl_opts |=
2054 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2056 ql4_printk(KERN_ERR, ha,
2057 "Invalid autocfg setting for IPv6 addr\n");
2059 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2060 /* Autocfg applies to even interface */
2061 if (iface_param->iface_num & 0x1)
2064 if (iface_param->value[0] ==
2065 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2066 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2067 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2068 else if (iface_param->value[0] ==
2069 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2070 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2071 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2073 ql4_printk(KERN_ERR, ha,
2074 "Invalid autocfg setting for IPv6 linklocal addr\n");
2076 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2077 /* Autocfg applies to even interface */
2078 if (iface_param->iface_num & 0x1)
2081 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2082 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2083 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2085 case ISCSI_NET_PARAM_IFACE_ENABLE:
2086 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2087 init_fw_cb->ipv6_opts |=
2088 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2089 qla4xxx_create_ipv6_iface(ha);
2091 init_fw_cb->ipv6_opts &=
2092 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2094 qla4xxx_destroy_ipv6_iface(ha);
2097 case ISCSI_NET_PARAM_VLAN_TAG:
2098 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2100 init_fw_cb->ipv6_vlan_tag =
2101 cpu_to_be16(*(uint16_t *)iface_param->value);
2103 case ISCSI_NET_PARAM_VLAN_ENABLED:
2104 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2105 init_fw_cb->ipv6_opts |=
2106 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2108 init_fw_cb->ipv6_opts &=
2109 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2111 case ISCSI_NET_PARAM_MTU:
2112 init_fw_cb->eth_mtu_size =
2113 cpu_to_le16(*(uint16_t *)iface_param->value);
2115 case ISCSI_NET_PARAM_PORT:
2116 /* Autocfg applies to even interface */
2117 if (iface_param->iface_num & 0x1)
2120 init_fw_cb->ipv6_port =
2121 cpu_to_le16(*(uint16_t *)iface_param->value);
2123 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2124 if (iface_param->iface_num & 0x1)
2126 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2127 init_fw_cb->ipv6_tcp_opts |=
2128 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2130 init_fw_cb->ipv6_tcp_opts &=
2131 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2134 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2135 if (iface_param->iface_num & 0x1)
2137 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2138 init_fw_cb->ipv6_tcp_opts |=
2139 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2141 init_fw_cb->ipv6_tcp_opts &=
2142 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2144 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2145 if (iface_param->iface_num & 0x1)
2147 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2148 init_fw_cb->ipv6_tcp_opts |=
2149 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2151 init_fw_cb->ipv6_tcp_opts &=
2152 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2154 case ISCSI_NET_PARAM_TCP_WSF:
2155 if (iface_param->iface_num & 0x1)
2157 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2159 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2160 if (iface_param->iface_num & 0x1)
2162 init_fw_cb->ipv6_tcp_opts &=
2163 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2164 init_fw_cb->ipv6_tcp_opts |=
2165 cpu_to_le16((iface_param->value[0] << 1) &
2166 IPV6_TCPOPT_TIMER_SCALE);
2168 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2169 if (iface_param->iface_num & 0x1)
2171 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2172 init_fw_cb->ipv6_tcp_opts |=
2173 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2175 init_fw_cb->ipv6_tcp_opts &=
2176 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2178 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2179 if (iface_param->iface_num & 0x1)
2181 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2182 init_fw_cb->ipv6_opts |=
2183 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2185 init_fw_cb->ipv6_opts &=
2186 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2188 case ISCSI_NET_PARAM_REDIRECT_EN:
2189 if (iface_param->iface_num & 0x1)
2191 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2192 init_fw_cb->ipv6_opts |=
2193 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2195 init_fw_cb->ipv6_opts &=
2196 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2198 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2199 if (iface_param->iface_num & 0x1)
2201 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2202 init_fw_cb->ipv6_addtl_opts |=
2203 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2205 init_fw_cb->ipv6_addtl_opts &=
2206 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2208 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2209 if (iface_param->iface_num & 0x1)
2211 init_fw_cb->ipv6_flow_lbl =
2212 cpu_to_le16(*(uint16_t *)iface_param->value);
2214 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2215 if (iface_param->iface_num & 0x1)
2217 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2219 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2220 if (iface_param->iface_num & 0x1)
2222 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2224 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2225 if (iface_param->iface_num & 0x1)
2227 init_fw_cb->ipv6_nd_reach_time =
2228 cpu_to_le32(*(uint32_t *)iface_param->value);
2230 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2231 if (iface_param->iface_num & 0x1)
2233 init_fw_cb->ipv6_nd_rexmit_timer =
2234 cpu_to_le32(*(uint32_t *)iface_param->value);
2236 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2237 if (iface_param->iface_num & 0x1)
2239 init_fw_cb->ipv6_nd_stale_timeout =
2240 cpu_to_le32(*(uint32_t *)iface_param->value);
2242 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2243 if (iface_param->iface_num & 0x1)
2245 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2247 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2248 if (iface_param->iface_num & 0x1)
2250 init_fw_cb->ipv6_gw_advrt_mtu =
2251 cpu_to_le32(*(uint32_t *)iface_param->value);
2254 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2255 iface_param->param);
2260 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2261 struct iscsi_iface_param_info *iface_param,
2262 struct addr_ctrl_blk *init_fw_cb)
2264 switch (iface_param->param) {
2265 case ISCSI_NET_PARAM_IPV4_ADDR:
2266 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2267 sizeof(init_fw_cb->ipv4_addr));
2269 case ISCSI_NET_PARAM_IPV4_SUBNET:
2270 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2271 sizeof(init_fw_cb->ipv4_subnet));
2273 case ISCSI_NET_PARAM_IPV4_GW:
2274 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2275 sizeof(init_fw_cb->ipv4_gw_addr));
2277 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2278 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2279 init_fw_cb->ipv4_tcp_opts |=
2280 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2281 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2282 init_fw_cb->ipv4_tcp_opts &=
2283 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2285 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2287 case ISCSI_NET_PARAM_IFACE_ENABLE:
2288 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2289 init_fw_cb->ipv4_ip_opts |=
2290 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2291 qla4xxx_create_ipv4_iface(ha);
2293 init_fw_cb->ipv4_ip_opts &=
2294 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2296 qla4xxx_destroy_ipv4_iface(ha);
2299 case ISCSI_NET_PARAM_VLAN_TAG:
2300 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2302 init_fw_cb->ipv4_vlan_tag =
2303 cpu_to_be16(*(uint16_t *)iface_param->value);
2305 case ISCSI_NET_PARAM_VLAN_ENABLED:
2306 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2307 init_fw_cb->ipv4_ip_opts |=
2308 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2310 init_fw_cb->ipv4_ip_opts &=
2311 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2313 case ISCSI_NET_PARAM_MTU:
2314 init_fw_cb->eth_mtu_size =
2315 cpu_to_le16(*(uint16_t *)iface_param->value);
2317 case ISCSI_NET_PARAM_PORT:
2318 init_fw_cb->ipv4_port =
2319 cpu_to_le16(*(uint16_t *)iface_param->value);
2321 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2322 if (iface_param->iface_num & 0x1)
2324 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2325 init_fw_cb->ipv4_tcp_opts |=
2326 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2328 init_fw_cb->ipv4_tcp_opts &=
2329 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2332 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2333 if (iface_param->iface_num & 0x1)
2335 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2336 init_fw_cb->ipv4_tcp_opts |=
2337 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2339 init_fw_cb->ipv4_tcp_opts &=
2340 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2342 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2343 if (iface_param->iface_num & 0x1)
2345 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2346 init_fw_cb->ipv4_tcp_opts |=
2347 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2349 init_fw_cb->ipv4_tcp_opts &=
2350 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2352 case ISCSI_NET_PARAM_TCP_WSF:
2353 if (iface_param->iface_num & 0x1)
2355 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2357 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2358 if (iface_param->iface_num & 0x1)
2360 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2361 init_fw_cb->ipv4_tcp_opts |=
2362 cpu_to_le16((iface_param->value[0] << 1) &
2363 TCPOPT_TIMER_SCALE);
2365 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2366 if (iface_param->iface_num & 0x1)
2368 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2369 init_fw_cb->ipv4_tcp_opts |=
2370 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2372 init_fw_cb->ipv4_tcp_opts &=
2373 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2375 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2376 if (iface_param->iface_num & 0x1)
2378 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2379 init_fw_cb->ipv4_tcp_opts |=
2380 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2382 init_fw_cb->ipv4_tcp_opts &=
2383 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2385 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2386 if (iface_param->iface_num & 0x1)
2388 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2389 init_fw_cb->ipv4_tcp_opts |=
2390 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2392 init_fw_cb->ipv4_tcp_opts &=
2393 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2395 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2396 if (iface_param->iface_num & 0x1)
2398 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2399 init_fw_cb->ipv4_ip_opts |=
2400 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2402 init_fw_cb->ipv4_ip_opts &=
2403 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2405 case ISCSI_NET_PARAM_IPV4_TOS:
2406 if (iface_param->iface_num & 0x1)
2408 init_fw_cb->ipv4_tos = iface_param->value[0];
2410 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2411 if (iface_param->iface_num & 0x1)
2413 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2414 init_fw_cb->ipv4_ip_opts |=
2415 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2417 init_fw_cb->ipv4_ip_opts &=
2418 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2420 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2421 if (iface_param->iface_num & 0x1)
2423 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2424 init_fw_cb->ipv4_ip_opts |=
2425 cpu_to_le16(IPOPT_ALT_CID_EN);
2427 init_fw_cb->ipv4_ip_opts &=
2428 cpu_to_le16(~IPOPT_ALT_CID_EN);
2430 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2431 if (iface_param->iface_num & 0x1)
2433 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2434 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2435 init_fw_cb->ipv4_dhcp_alt_cid_len =
2436 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2438 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2439 if (iface_param->iface_num & 0x1)
2441 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2442 init_fw_cb->ipv4_ip_opts |=
2443 cpu_to_le16(IPOPT_REQ_VID_EN);
2445 init_fw_cb->ipv4_ip_opts &=
2446 cpu_to_le16(~IPOPT_REQ_VID_EN);
2448 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2449 if (iface_param->iface_num & 0x1)
2451 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2452 init_fw_cb->ipv4_ip_opts |=
2453 cpu_to_le16(IPOPT_USE_VID_EN);
2455 init_fw_cb->ipv4_ip_opts &=
2456 cpu_to_le16(~IPOPT_USE_VID_EN);
2458 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2459 if (iface_param->iface_num & 0x1)
2461 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2462 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2463 init_fw_cb->ipv4_dhcp_vid_len =
2464 strlen(init_fw_cb->ipv4_dhcp_vid);
2466 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2467 if (iface_param->iface_num & 0x1)
2469 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2470 init_fw_cb->ipv4_ip_opts |=
2471 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2473 init_fw_cb->ipv4_ip_opts &=
2474 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2476 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2477 if (iface_param->iface_num & 0x1)
2479 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2480 init_fw_cb->ipv4_ip_opts |=
2481 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2483 init_fw_cb->ipv4_ip_opts &=
2484 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2486 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2487 if (iface_param->iface_num & 0x1)
2489 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2490 init_fw_cb->ipv4_ip_opts |=
2491 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2493 init_fw_cb->ipv4_ip_opts &=
2494 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2496 case ISCSI_NET_PARAM_REDIRECT_EN:
2497 if (iface_param->iface_num & 0x1)
2499 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2500 init_fw_cb->ipv4_ip_opts |=
2501 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2503 init_fw_cb->ipv4_ip_opts &=
2504 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2506 case ISCSI_NET_PARAM_IPV4_TTL:
2507 if (iface_param->iface_num & 0x1)
2509 init_fw_cb->ipv4_ttl = iface_param->value[0];
2512 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2513 iface_param->param);
2518 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2519 struct iscsi_iface_param_info *iface_param,
2520 struct addr_ctrl_blk *init_fw_cb)
2522 switch (iface_param->param) {
2523 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2524 if (iface_param->iface_num & 0x1)
2526 init_fw_cb->def_timeout =
2527 cpu_to_le16(*(uint16_t *)iface_param->value);
2529 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2530 if (iface_param->iface_num & 0x1)
2532 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2533 init_fw_cb->iscsi_opts |=
2534 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2536 init_fw_cb->iscsi_opts &=
2537 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2539 case ISCSI_IFACE_PARAM_DATADGST_EN:
2540 if (iface_param->iface_num & 0x1)
2542 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2543 init_fw_cb->iscsi_opts |=
2544 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2546 init_fw_cb->iscsi_opts &=
2547 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2549 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2550 if (iface_param->iface_num & 0x1)
2552 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2553 init_fw_cb->iscsi_opts |=
2554 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2556 init_fw_cb->iscsi_opts &=
2557 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2559 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2560 if (iface_param->iface_num & 0x1)
2562 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2563 init_fw_cb->iscsi_opts |=
2564 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2566 init_fw_cb->iscsi_opts &=
2567 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2569 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2570 if (iface_param->iface_num & 0x1)
2572 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2573 init_fw_cb->iscsi_opts |=
2574 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2576 init_fw_cb->iscsi_opts &=
2577 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2579 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2580 if (iface_param->iface_num & 0x1)
2582 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2583 init_fw_cb->iscsi_opts |=
2584 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2586 init_fw_cb->iscsi_opts &=
2587 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2589 case ISCSI_IFACE_PARAM_ERL:
2590 if (iface_param->iface_num & 0x1)
2592 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2593 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2596 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2597 if (iface_param->iface_num & 0x1)
2599 init_fw_cb->iscsi_max_pdu_size =
2600 cpu_to_le32(*(uint32_t *)iface_param->value) /
2603 case ISCSI_IFACE_PARAM_FIRST_BURST:
2604 if (iface_param->iface_num & 0x1)
2606 init_fw_cb->iscsi_fburst_len =
2607 cpu_to_le32(*(uint32_t *)iface_param->value) /
2610 case ISCSI_IFACE_PARAM_MAX_R2T:
2611 if (iface_param->iface_num & 0x1)
2613 init_fw_cb->iscsi_max_outstnd_r2t =
2614 cpu_to_le16(*(uint16_t *)iface_param->value);
2616 case ISCSI_IFACE_PARAM_MAX_BURST:
2617 if (iface_param->iface_num & 0x1)
2619 init_fw_cb->iscsi_max_burst_len =
2620 cpu_to_le32(*(uint32_t *)iface_param->value) /
2623 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2624 if (iface_param->iface_num & 0x1)
2626 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2627 init_fw_cb->iscsi_opts |=
2628 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2630 init_fw_cb->iscsi_opts &=
2631 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2633 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2634 if (iface_param->iface_num & 0x1)
2636 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2637 init_fw_cb->iscsi_opts |=
2638 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2640 init_fw_cb->iscsi_opts &=
2641 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2643 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2644 if (iface_param->iface_num & 0x1)
2646 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2647 init_fw_cb->iscsi_opts |=
2648 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2650 init_fw_cb->iscsi_opts &=
2651 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2653 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2654 if (iface_param->iface_num & 0x1)
2656 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2657 init_fw_cb->iscsi_opts |=
2658 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2660 init_fw_cb->iscsi_opts &=
2661 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2663 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2664 if (iface_param->iface_num & 0x1)
2666 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2667 init_fw_cb->iscsi_opts |=
2668 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2670 init_fw_cb->iscsi_opts &=
2671 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2674 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2675 iface_param->param);
2681 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2683 struct addr_ctrl_blk_def *acb;
2684 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2685 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2686 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2687 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2688 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2689 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2690 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2691 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2692 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2693 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2694 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2695 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2696 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2697 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2698 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2699 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2703 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2705 struct scsi_qla_host *ha = to_qla_host(shost);
2707 struct iscsi_iface_param_info *iface_param = NULL;
2708 struct addr_ctrl_blk *init_fw_cb = NULL;
2709 dma_addr_t init_fw_cb_dma;
2710 uint32_t mbox_cmd[MBOX_REG_COUNT];
2711 uint32_t mbox_sts[MBOX_REG_COUNT];
2713 struct nlattr *attr;
2715 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2716 sizeof(struct addr_ctrl_blk),
2717 &init_fw_cb_dma, GFP_KERNEL);
2719 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2724 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2725 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2726 memset(&mbox_sts, 0, sizeof(mbox_sts));
2728 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2729 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2731 goto exit_init_fw_cb;
2734 nla_for_each_attr(attr, data, len, rem) {
2735 if (nla_len(attr) < sizeof(*iface_param)) {
2737 goto exit_init_fw_cb;
2740 iface_param = nla_data(attr);
2742 if (iface_param->param_type == ISCSI_NET_PARAM) {
2743 switch (iface_param->iface_type) {
2744 case ISCSI_IFACE_TYPE_IPV4:
2745 switch (iface_param->iface_num) {
2747 qla4xxx_set_ipv4(ha, iface_param,
2751 /* Cannot have more than one IPv4 interface */
2752 ql4_printk(KERN_ERR, ha,
2753 "Invalid IPv4 iface number = %d\n",
2754 iface_param->iface_num);
2758 case ISCSI_IFACE_TYPE_IPV6:
2759 switch (iface_param->iface_num) {
2762 qla4xxx_set_ipv6(ha, iface_param,
2766 /* Cannot have more than two IPv6 interface */
2767 ql4_printk(KERN_ERR, ha,
2768 "Invalid IPv6 iface number = %d\n",
2769 iface_param->iface_num);
2774 ql4_printk(KERN_ERR, ha,
2775 "Invalid iface type\n");
2778 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2779 qla4xxx_set_iscsi_param(ha, iface_param,
2786 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2788 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2789 sizeof(struct addr_ctrl_blk),
2790 FLASH_OPT_RMW_COMMIT);
2791 if (rval != QLA_SUCCESS) {
2792 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2795 goto exit_init_fw_cb;
2798 rval = qla4xxx_disable_acb(ha);
2799 if (rval != QLA_SUCCESS) {
2800 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2803 goto exit_init_fw_cb;
2806 wait_for_completion_timeout(&ha->disable_acb_comp,
2807 DISABLE_ACB_TOV * HZ);
2809 qla4xxx_initcb_to_acb(init_fw_cb);
2811 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2812 if (rval != QLA_SUCCESS) {
2813 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2816 goto exit_init_fw_cb;
2819 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2820 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2824 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2825 init_fw_cb, init_fw_cb_dma);
2830 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2831 enum iscsi_param param, char *buf)
2833 struct iscsi_session *sess = cls_sess->dd_data;
2834 struct ddb_entry *ddb_entry = sess->dd_data;
2835 struct scsi_qla_host *ha = ddb_entry->ha;
2836 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2837 struct ql4_chap_table chap_tbl;
2841 memset(&chap_tbl, 0, sizeof(chap_tbl));
2843 case ISCSI_PARAM_CHAP_IN_IDX:
2844 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2845 sess->password_in, BIDI_CHAP,
2848 len = sprintf(buf, "\n");
2850 len = sprintf(buf, "%hu\n", idx);
2852 case ISCSI_PARAM_CHAP_OUT_IDX:
2853 if (ddb_entry->ddb_type == FLASH_DDB) {
2854 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2855 idx = ddb_entry->chap_tbl_idx;
2861 rval = qla4xxx_get_chap_index(ha, sess->username,
2866 len = sprintf(buf, "\n");
2868 len = sprintf(buf, "%hu\n", idx);
2870 case ISCSI_PARAM_USERNAME:
2871 case ISCSI_PARAM_PASSWORD:
2872 /* First, populate session username and password for FLASH DDB,
2873 * if not already done. This happens when session login fails
2876 if (ddb_entry->ddb_type == FLASH_DDB &&
2877 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2878 !sess->username && !sess->password) {
2879 idx = ddb_entry->chap_tbl_idx;
2880 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2884 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2885 (char *)chap_tbl.name,
2886 strlen((char *)chap_tbl.name));
2887 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2888 (char *)chap_tbl.secret,
2889 chap_tbl.secret_len);
2892 /* allow fall-through */
2894 return iscsi_session_get_param(cls_sess, param, buf);
2900 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2901 enum iscsi_param param, char *buf)
2903 struct iscsi_conn *conn;
2904 struct qla_conn *qla_conn;
2905 struct sockaddr *dst_addr;
2907 conn = cls_conn->dd_data;
2908 qla_conn = conn->dd_data;
2909 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2912 case ISCSI_PARAM_CONN_PORT:
2913 case ISCSI_PARAM_CONN_ADDRESS:
2914 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2915 dst_addr, param, buf);
2917 return iscsi_conn_get_param(cls_conn, param, buf);
2921 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2923 uint32_t mbx_sts = 0;
2924 uint16_t tmp_ddb_index;
2928 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2930 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2931 DEBUG2(ql4_printk(KERN_INFO, ha,
2932 "Free DDB index not available\n"));
2934 goto exit_get_ddb_index;
2937 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2940 DEBUG2(ql4_printk(KERN_INFO, ha,
2941 "Found a free DDB index at %d\n", tmp_ddb_index));
2942 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2943 if (ret == QLA_ERROR) {
2944 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2945 ql4_printk(KERN_INFO, ha,
2946 "DDB index = %d not available trying next\n",
2950 DEBUG2(ql4_printk(KERN_INFO, ha,
2951 "Free FW DDB not available\n"));
2954 *ddb_index = tmp_ddb_index;
2960 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2961 struct ddb_entry *ddb_entry,
2962 char *existing_ipaddr,
2965 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2966 char formatted_ipaddr[DDB_IPADDR_LEN];
2967 int status = QLA_SUCCESS, ret = 0;
2969 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2970 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2976 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2978 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2984 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2987 if (strcmp(existing_ipaddr, formatted_ipaddr))
2994 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2995 struct iscsi_cls_conn *cls_conn)
2997 int idx = 0, max_ddbs, rval;
2998 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2999 struct iscsi_session *sess, *existing_sess;
3000 struct iscsi_conn *conn, *existing_conn;
3001 struct ddb_entry *ddb_entry;
3003 sess = cls_sess->dd_data;
3004 conn = cls_conn->dd_data;
3006 if (sess->targetname == NULL ||
3007 conn->persistent_address == NULL ||
3008 conn->persistent_port == 0)
3011 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3014 for (idx = 0; idx < max_ddbs; idx++) {
3015 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3016 if (ddb_entry == NULL)
3019 if (ddb_entry->ddb_type != FLASH_DDB)
3022 existing_sess = ddb_entry->sess->dd_data;
3023 existing_conn = ddb_entry->conn->dd_data;
3025 if (existing_sess->targetname == NULL ||
3026 existing_conn->persistent_address == NULL ||
3027 existing_conn->persistent_port == 0)
3030 DEBUG2(ql4_printk(KERN_INFO, ha,
3031 "IQN = %s User IQN = %s\n",
3032 existing_sess->targetname,
3035 DEBUG2(ql4_printk(KERN_INFO, ha,
3036 "IP = %s User IP = %s\n",
3037 existing_conn->persistent_address,
3038 conn->persistent_address));
3040 DEBUG2(ql4_printk(KERN_INFO, ha,
3041 "Port = %d User Port = %d\n",
3042 existing_conn->persistent_port,
3043 conn->persistent_port));
3045 if (strcmp(existing_sess->targetname, sess->targetname))
3047 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3048 existing_conn->persistent_address,
3049 conn->persistent_address);
3050 if (rval == QLA_ERROR)
3052 if (existing_conn->persistent_port != conn->persistent_port)
3057 if (idx == max_ddbs)
3060 DEBUG2(ql4_printk(KERN_INFO, ha,
3061 "Match found in fwdb sessions\n"));
3065 static struct iscsi_cls_session *
3066 qla4xxx_session_create(struct iscsi_endpoint *ep,
3067 uint16_t cmds_max, uint16_t qdepth,
3068 uint32_t initial_cmdsn)
3070 struct iscsi_cls_session *cls_sess;
3071 struct scsi_qla_host *ha;
3072 struct qla_endpoint *qla_ep;
3073 struct ddb_entry *ddb_entry;
3075 struct iscsi_session *sess;
3076 struct sockaddr *dst_addr;
3080 printk(KERN_ERR "qla4xxx: missing ep.\n");
3084 qla_ep = ep->dd_data;
3085 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3086 ha = to_qla_host(qla_ep->host);
3087 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3090 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3091 if (ret == QLA_ERROR)
3094 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3095 cmds_max, sizeof(struct ddb_entry),
3096 sizeof(struct ql4_task_data),
3097 initial_cmdsn, ddb_index);
3101 sess = cls_sess->dd_data;
3102 ddb_entry = sess->dd_data;
3103 ddb_entry->fw_ddb_index = ddb_index;
3104 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3106 ddb_entry->sess = cls_sess;
3107 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3108 ddb_entry->ddb_change = qla4xxx_ddb_change;
3109 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3110 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3111 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3117 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3119 struct iscsi_session *sess;
3120 struct ddb_entry *ddb_entry;
3121 struct scsi_qla_host *ha;
3122 unsigned long flags, wtime;
3123 struct dev_db_entry *fw_ddb_entry = NULL;
3124 dma_addr_t fw_ddb_entry_dma;
3128 sess = cls_sess->dd_data;
3129 ddb_entry = sess->dd_data;
3131 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3134 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3135 &fw_ddb_entry_dma, GFP_KERNEL);
3136 if (!fw_ddb_entry) {
3137 ql4_printk(KERN_ERR, ha,
3138 "%s: Unable to allocate dma buffer\n", __func__);
3139 goto destroy_session;
3142 wtime = jiffies + (HZ * LOGOUT_TOV);
3144 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3145 fw_ddb_entry, fw_ddb_entry_dma,
3146 NULL, NULL, &ddb_state, NULL,
3148 if (ret == QLA_ERROR)
3149 goto destroy_session;
3151 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3152 (ddb_state == DDB_DS_SESSION_FAILED))
3153 goto destroy_session;
3155 schedule_timeout_uninterruptible(HZ);
3156 } while ((time_after(wtime, jiffies)));
3159 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3160 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3161 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3162 spin_lock_irqsave(&ha->hardware_lock, flags);
3163 qla4xxx_free_ddb(ha, ddb_entry);
3164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3166 iscsi_session_teardown(cls_sess);
3169 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3170 fw_ddb_entry, fw_ddb_entry_dma);
3173 static struct iscsi_cls_conn *
3174 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3176 struct iscsi_cls_conn *cls_conn;
3177 struct iscsi_session *sess;
3178 struct ddb_entry *ddb_entry;
3179 struct scsi_qla_host *ha;
3181 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3184 pr_info("%s: Can not create connection for conn_idx = %u\n",
3185 __func__, conn_idx);
3189 sess = cls_sess->dd_data;
3190 ddb_entry = sess->dd_data;
3191 ddb_entry->conn = cls_conn;
3194 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3199 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3200 struct iscsi_cls_conn *cls_conn,
3201 uint64_t transport_fd, int is_leading)
3203 struct iscsi_conn *conn;
3204 struct qla_conn *qla_conn;
3205 struct iscsi_endpoint *ep;
3206 struct ddb_entry *ddb_entry;
3207 struct scsi_qla_host *ha;
3208 struct iscsi_session *sess;
3210 sess = cls_session->dd_data;
3211 ddb_entry = sess->dd_data;
3214 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3215 cls_session->sid, cls_conn->cid));
3217 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3219 ep = iscsi_lookup_endpoint(transport_fd);
3222 conn = cls_conn->dd_data;
3223 qla_conn = conn->dd_data;
3224 qla_conn->qla_ep = ep->dd_data;
3228 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3230 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3231 struct iscsi_session *sess;
3232 struct ddb_entry *ddb_entry;
3233 struct scsi_qla_host *ha;
3234 struct dev_db_entry *fw_ddb_entry = NULL;
3235 dma_addr_t fw_ddb_entry_dma;
3236 uint32_t mbx_sts = 0;
3238 int status = QLA_SUCCESS;
3240 sess = cls_sess->dd_data;
3241 ddb_entry = sess->dd_data;
3243 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3244 cls_sess->sid, cls_conn->cid));
3246 /* Check if we have matching FW DDB, if yes then do not
3247 * login to this target. This could cause target to logout previous
3250 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3251 if (ret == QLA_SUCCESS) {
3252 ql4_printk(KERN_INFO, ha,
3253 "Session already exist in FW.\n");
3255 goto exit_conn_start;
3258 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3259 &fw_ddb_entry_dma, GFP_KERNEL);
3260 if (!fw_ddb_entry) {
3261 ql4_printk(KERN_ERR, ha,
3262 "%s: Unable to allocate dma buffer\n", __func__);
3264 goto exit_conn_start;
3267 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3269 /* If iscsid is stopped and started then no need to do
3270 * set param again since ddb state will be already
3271 * active and FW does not allow set ddb to an
3275 if (ddb_entry->fw_ddb_device_state ==
3276 DDB_DS_SESSION_ACTIVE) {
3277 ddb_entry->unblock_sess(ddb_entry->sess);
3278 goto exit_set_param;
3281 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3282 __func__, ddb_entry->fw_ddb_index);
3283 goto exit_conn_start;
3286 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3287 if (status == QLA_ERROR) {
3288 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3291 goto exit_conn_start;
3294 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3295 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3297 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3298 ddb_entry->fw_ddb_device_state));
3305 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3306 fw_ddb_entry, fw_ddb_entry_dma);
3310 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3312 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3313 struct iscsi_session *sess;
3314 struct scsi_qla_host *ha;
3315 struct ddb_entry *ddb_entry;
3318 sess = cls_sess->dd_data;
3319 ddb_entry = sess->dd_data;
3321 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3324 options = LOGOUT_OPTION_CLOSE_SESSION;
3325 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3326 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3329 static void qla4xxx_task_work(struct work_struct *wdata)
3331 struct ql4_task_data *task_data;
3332 struct scsi_qla_host *ha;
3333 struct passthru_status *sts;
3334 struct iscsi_task *task;
3335 struct iscsi_hdr *hdr;
3338 struct iscsi_conn *conn;
3342 task_data = container_of(wdata, struct ql4_task_data, task_work);
3344 task = task_data->task;
3345 sts = &task_data->sts;
3346 hdr_len = sizeof(struct iscsi_hdr);
3348 DEBUG3(printk(KERN_INFO "Status returned\n"));
3349 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3350 DEBUG3(printk(KERN_INFO "Response buffer"));
3351 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3355 switch (sts->completionStatus) {
3356 case PASSTHRU_STATUS_COMPLETE:
3357 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3358 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3361 data = task_data->resp_buffer + hdr_len;
3362 data_len = task_data->resp_len - hdr_len;
3363 iscsi_complete_pdu(conn, hdr, data, data_len);
3366 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3367 sts->completionStatus);
3373 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3375 struct ql4_task_data *task_data;
3376 struct iscsi_session *sess;
3377 struct ddb_entry *ddb_entry;
3378 struct scsi_qla_host *ha;
3381 sess = task->conn->session;
3382 ddb_entry = sess->dd_data;
3384 task_data = task->dd_data;
3385 memset(task_data, 0, sizeof(struct ql4_task_data));
3388 ql4_printk(KERN_INFO, ha,
3389 "%s: SCSI Commands not implemented\n", __func__);
3393 hdr_len = sizeof(struct iscsi_hdr);
3395 task_data->task = task;
3397 if (task->data_count) {
3398 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3403 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3404 __func__, task->conn->max_recv_dlength, hdr_len));
3406 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3407 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3408 task_data->resp_len,
3409 &task_data->resp_dma,
3411 if (!task_data->resp_buffer)
3412 goto exit_alloc_pdu;
3414 task_data->req_len = task->data_count + hdr_len;
3415 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3417 &task_data->req_dma,
3419 if (!task_data->req_buffer)
3420 goto exit_alloc_pdu;
3422 task->hdr = task_data->req_buffer;
3424 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3429 if (task_data->resp_buffer)
3430 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3431 task_data->resp_buffer, task_data->resp_dma);
3433 if (task_data->req_buffer)
3434 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3435 task_data->req_buffer, task_data->req_dma);
3439 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3441 struct ql4_task_data *task_data;
3442 struct iscsi_session *sess;
3443 struct ddb_entry *ddb_entry;
3444 struct scsi_qla_host *ha;
3447 hdr_len = sizeof(struct iscsi_hdr);
3448 sess = task->conn->session;
3449 ddb_entry = sess->dd_data;
3451 task_data = task->dd_data;
3453 if (task->data_count) {
3454 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3455 task->data_count, PCI_DMA_TODEVICE);
3458 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3459 __func__, task->conn->max_recv_dlength, hdr_len));
3461 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3462 task_data->resp_buffer, task_data->resp_dma);
3463 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3464 task_data->req_buffer, task_data->req_dma);
3468 static int qla4xxx_task_xmit(struct iscsi_task *task)
3470 struct scsi_cmnd *sc = task->sc;
3471 struct iscsi_session *sess = task->conn->session;
3472 struct ddb_entry *ddb_entry = sess->dd_data;
3473 struct scsi_qla_host *ha = ddb_entry->ha;
3476 return qla4xxx_send_passthru0(task);
3478 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3483 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3484 struct iscsi_bus_flash_conn *conn,
3485 struct dev_db_entry *fw_ddb_entry)
3487 unsigned long options = 0;
3490 options = le16_to_cpu(fw_ddb_entry->options);
3491 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3492 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3493 rc = iscsi_switch_str_param(&sess->portal_type,
3498 rc = iscsi_switch_str_param(&sess->portal_type,
3504 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3506 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3507 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3509 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3510 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3511 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3512 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3513 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3514 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3516 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3517 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3518 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3519 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3521 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3522 sess->discovery_auth_optional =
3523 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3524 if (test_bit(ISCSIOPT_ERL1, &options))
3526 if (test_bit(ISCSIOPT_ERL0, &options))
3529 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3530 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3531 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3532 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3533 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3534 conn->tcp_timer_scale |= BIT_3;
3535 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3536 conn->tcp_timer_scale |= BIT_2;
3537 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3538 conn->tcp_timer_scale |= BIT_1;
3540 conn->tcp_timer_scale >>= 1;
3541 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3543 options = le16_to_cpu(fw_ddb_entry->ip_options);
3544 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3546 conn->max_recv_dlength = BYTE_UNITS *
3547 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3548 conn->max_xmit_dlength = BYTE_UNITS *
3549 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3550 sess->first_burst = BYTE_UNITS *
3551 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3552 sess->max_burst = BYTE_UNITS *
3553 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3554 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3555 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3556 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3557 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3558 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3559 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3560 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3561 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3562 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3563 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3564 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3565 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3566 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3567 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3568 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3569 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3571 sess->default_taskmgmt_timeout =
3572 le16_to_cpu(fw_ddb_entry->def_timeout);
3573 conn->port = le16_to_cpu(fw_ddb_entry->port);
3575 options = le16_to_cpu(fw_ddb_entry->options);
3576 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3577 if (!conn->ipaddress) {
3582 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3583 if (!conn->redirect_ipaddr) {
3588 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3589 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3591 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3592 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3594 conn->link_local_ipv6_addr = kmemdup(
3595 fw_ddb_entry->link_local_ipv6_addr,
3596 IPv6_ADDR_LEN, GFP_KERNEL);
3597 if (!conn->link_local_ipv6_addr) {
3602 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3605 if (fw_ddb_entry->iscsi_name[0]) {
3606 rc = iscsi_switch_str_param(&sess->targetname,
3607 (char *)fw_ddb_entry->iscsi_name);
3612 if (fw_ddb_entry->iscsi_alias[0]) {
3613 rc = iscsi_switch_str_param(&sess->targetalias,
3614 (char *)fw_ddb_entry->iscsi_alias);
3619 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3625 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3626 struct iscsi_bus_flash_conn *conn,
3627 struct dev_db_entry *fw_ddb_entry)
3632 options = le16_to_cpu(fw_ddb_entry->options);
3633 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3634 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3639 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3640 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3641 SET_BITVAL(sess->entry_state, options, BIT_3);
3642 fw_ddb_entry->options = cpu_to_le16(options);
3644 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3645 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3646 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3647 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3648 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3649 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3650 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3651 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3652 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3653 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3654 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3655 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3656 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3657 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3658 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3660 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3661 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3662 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3663 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3664 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3665 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3666 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3667 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3668 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3670 options = le16_to_cpu(fw_ddb_entry->ip_options);
3671 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3672 fw_ddb_entry->ip_options = cpu_to_le16(options);
3674 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3675 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3676 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3677 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3678 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3679 fw_ddb_entry->iscsi_first_burst_len =
3680 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3681 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3683 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3684 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3685 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3686 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3687 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3688 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3689 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3690 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3691 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3692 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3693 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3694 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3695 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3696 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3697 fw_ddb_entry->port = cpu_to_le16(conn->port);
3698 fw_ddb_entry->def_timeout =
3699 cpu_to_le16(sess->default_taskmgmt_timeout);
3701 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3702 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3704 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3706 if (conn->ipaddress)
3707 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3708 sizeof(fw_ddb_entry->ip_addr));
3710 if (conn->redirect_ipaddr)
3711 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3712 sizeof(fw_ddb_entry->tgt_addr));
3714 if (conn->link_local_ipv6_addr)
3715 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3716 conn->link_local_ipv6_addr,
3717 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3719 if (sess->targetname)
3720 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3721 sizeof(fw_ddb_entry->iscsi_name));
3723 if (sess->targetalias)
3724 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3725 sizeof(fw_ddb_entry->iscsi_alias));
3727 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3732 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3733 struct iscsi_session *sess,
3734 struct dev_db_entry *fw_ddb_entry)
3736 unsigned long options = 0;
3738 uint16_t disc_parent;
3739 char ip_addr[DDB_IPADDR_LEN];
3741 options = le16_to_cpu(fw_ddb_entry->options);
3742 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3743 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3745 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3747 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3748 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3749 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3750 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3751 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3752 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3754 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3755 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3756 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3758 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3759 sess->discovery_auth_optional =
3760 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3761 if (test_bit(ISCSIOPT_ERL1, &options))
3763 if (test_bit(ISCSIOPT_ERL0, &options))
3766 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3767 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3768 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3769 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3770 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3771 conn->tcp_timer_scale |= BIT_3;
3772 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3773 conn->tcp_timer_scale |= BIT_2;
3774 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3775 conn->tcp_timer_scale |= BIT_1;
3777 conn->tcp_timer_scale >>= 1;
3778 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3780 options = le16_to_cpu(fw_ddb_entry->ip_options);
3781 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3783 conn->max_recv_dlength = BYTE_UNITS *
3784 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3785 conn->max_xmit_dlength = BYTE_UNITS *
3786 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3787 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3788 sess->first_burst = BYTE_UNITS *
3789 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3790 sess->max_burst = BYTE_UNITS *
3791 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3792 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3793 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3794 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3795 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3796 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3797 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3798 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3799 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3800 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3801 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3802 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3803 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3804 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3806 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3807 if (ddb_link == DDB_ISNS)
3808 disc_parent = ISCSI_DISC_PARENT_ISNS;
3809 else if (ddb_link == DDB_NO_LINK)
3810 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3811 else if (ddb_link < MAX_DDB_ENTRIES)
3812 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3814 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3816 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3817 iscsi_get_discovery_parent_name(disc_parent), 0);
3819 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3820 (char *)fw_ddb_entry->iscsi_alias, 0);
3822 options = le16_to_cpu(fw_ddb_entry->options);
3823 if (options & DDB_OPT_IPV6_DEVICE) {
3824 memset(ip_addr, 0, sizeof(ip_addr));
3825 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3826 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3827 (char *)ip_addr, 0);
3831 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3832 struct dev_db_entry *fw_ddb_entry,
3833 struct iscsi_cls_session *cls_sess,
3834 struct iscsi_cls_conn *cls_conn)
3837 struct iscsi_session *sess;
3838 struct ddb_entry *ddb_entry;
3839 struct ql4_chap_table chap_tbl;
3840 struct iscsi_conn *conn;
3841 char ip_addr[DDB_IPADDR_LEN];
3842 uint16_t options = 0;
3844 sess = cls_sess->dd_data;
3845 ddb_entry = sess->dd_data;
3846 conn = cls_conn->dd_data;
3847 memset(&chap_tbl, 0, sizeof(chap_tbl));
3849 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3851 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3853 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3854 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3856 memset(ip_addr, 0, sizeof(ip_addr));
3857 options = le16_to_cpu(fw_ddb_entry->options);
3858 if (options & DDB_OPT_IPV6_DEVICE) {
3859 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3861 memset(ip_addr, 0, sizeof(ip_addr));
3862 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3864 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3865 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3868 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3869 (char *)ip_addr, buflen);
3870 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3871 (char *)fw_ddb_entry->iscsi_name, buflen);
3872 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3873 (char *)ha->name_string, buflen);
3875 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3876 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3878 ddb_entry->chap_tbl_idx)) {
3879 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3880 (char *)chap_tbl.name,
3881 strlen((char *)chap_tbl.name));
3882 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3883 (char *)chap_tbl.secret,
3884 chap_tbl.secret_len);
3889 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3890 struct ddb_entry *ddb_entry)
3892 struct iscsi_cls_session *cls_sess;
3893 struct iscsi_cls_conn *cls_conn;
3895 dma_addr_t fw_ddb_entry_dma;
3896 struct dev_db_entry *fw_ddb_entry;
3898 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3899 &fw_ddb_entry_dma, GFP_KERNEL);
3900 if (!fw_ddb_entry) {
3901 ql4_printk(KERN_ERR, ha,
3902 "%s: Unable to allocate dma buffer\n", __func__);
3903 goto exit_session_conn_fwddb_param;
3906 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3907 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3908 NULL, NULL, NULL) == QLA_ERROR) {
3909 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3910 "get_ddb_entry for fw_ddb_index %d\n",
3911 ha->host_no, __func__,
3912 ddb_entry->fw_ddb_index));
3913 goto exit_session_conn_fwddb_param;
3916 cls_sess = ddb_entry->sess;
3918 cls_conn = ddb_entry->conn;
3921 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3923 exit_session_conn_fwddb_param:
3925 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3926 fw_ddb_entry, fw_ddb_entry_dma);
3929 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3930 struct ddb_entry *ddb_entry)
3932 struct iscsi_cls_session *cls_sess;
3933 struct iscsi_cls_conn *cls_conn;
3934 struct iscsi_session *sess;
3935 struct iscsi_conn *conn;
3937 dma_addr_t fw_ddb_entry_dma;
3938 struct dev_db_entry *fw_ddb_entry;
3940 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3941 &fw_ddb_entry_dma, GFP_KERNEL);
3942 if (!fw_ddb_entry) {
3943 ql4_printk(KERN_ERR, ha,
3944 "%s: Unable to allocate dma buffer\n", __func__);
3945 goto exit_session_conn_param;
3948 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3949 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3950 NULL, NULL, NULL) == QLA_ERROR) {
3951 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3952 "get_ddb_entry for fw_ddb_index %d\n",
3953 ha->host_no, __func__,
3954 ddb_entry->fw_ddb_index));
3955 goto exit_session_conn_param;
3958 cls_sess = ddb_entry->sess;
3959 sess = cls_sess->dd_data;
3961 cls_conn = ddb_entry->conn;
3962 conn = cls_conn->dd_data;
3964 /* Update timers after login */
3965 ddb_entry->default_relogin_timeout =
3966 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3967 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3968 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3969 ddb_entry->default_time2wait =
3970 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3973 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3974 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3976 memcpy(sess->initiatorname, ha->name_string,
3977 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3979 exit_session_conn_param:
3981 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3982 fw_ddb_entry, fw_ddb_entry_dma);
3989 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
3990 unsigned long interval)
3992 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3993 __func__, ha->host->host_no));
3994 init_timer(&ha->timer);
3995 ha->timer.expires = jiffies + interval * HZ;
3996 ha->timer.data = (unsigned long)ha;
3997 ha->timer.function = (void (*)(unsigned long))func;
3998 add_timer(&ha->timer);
3999 ha->timer_active = 1;
4002 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4004 del_timer_sync(&ha->timer);
4005 ha->timer_active = 0;
4009 * qla4xxx_mark_device_missing - blocks the session
4010 * @cls_session: Pointer to the session to be blocked
4011 * @ddb_entry: Pointer to device database entry
4013 * This routine marks a device missing and close connection.
4015 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4017 iscsi_block_session(cls_session);
4021 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4022 * @ha: Pointer to host adapter structure.
4024 * This routine marks a device missing and resets the relogin retry count.
4026 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4028 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4031 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4032 struct ddb_entry *ddb_entry,
4033 struct scsi_cmnd *cmd)
4037 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4041 kref_init(&srb->srb_ref);
4043 srb->ddb = ddb_entry;
4046 CMD_SP(cmd) = (void *)srb;
4051 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4053 struct scsi_cmnd *cmd = srb->cmd;
4055 if (srb->flags & SRB_DMA_VALID) {
4056 scsi_dma_unmap(cmd);
4057 srb->flags &= ~SRB_DMA_VALID;
4062 void qla4xxx_srb_compl(struct kref *ref)
4064 struct srb *srb = container_of(ref, struct srb, srb_ref);
4065 struct scsi_cmnd *cmd = srb->cmd;
4066 struct scsi_qla_host *ha = srb->ha;
4068 qla4xxx_srb_free_dma(ha, srb);
4070 mempool_free(srb, ha->srb_mempool);
4072 cmd->scsi_done(cmd);
4076 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4078 * @cmd: Pointer to Linux's SCSI command structure
4081 * This routine is invoked by Linux to send a SCSI command to the driver.
4082 * The mid-level driver tries to ensure that queuecommand never gets
4083 * invoked concurrently with itself or the interrupt handler (although
4084 * the interrupt handler may call this routine as part of request-
4085 * completion handling). Unfortunely, it sometimes calls the scheduler
4086 * in interrupt context which is a big NO! NO!.
4088 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4090 struct scsi_qla_host *ha = to_qla_host(host);
4091 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4092 struct iscsi_cls_session *sess = ddb_entry->sess;
4096 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4097 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4098 cmd->result = DID_NO_CONNECT << 16;
4100 cmd->result = DID_REQUEUE << 16;
4101 goto qc_fail_command;
4105 cmd->result = DID_IMM_RETRY << 16;
4106 goto qc_fail_command;
4109 rval = iscsi_session_chkready(sess);
4112 goto qc_fail_command;
4115 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4116 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4117 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4118 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4119 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4120 !test_bit(AF_ONLINE, &ha->flags) ||
4121 !test_bit(AF_LINK_UP, &ha->flags) ||
4122 test_bit(AF_LOOPBACK, &ha->flags) ||
4123 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4124 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4125 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4128 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4132 rval = qla4xxx_send_command_to_isp(ha, srb);
4133 if (rval != QLA_SUCCESS)
4134 goto qc_host_busy_free_sp;
4138 qc_host_busy_free_sp:
4139 qla4xxx_srb_free_dma(ha, srb);
4140 mempool_free(srb, ha->srb_mempool);
4143 return SCSI_MLQUEUE_HOST_BUSY;
4146 cmd->scsi_done(cmd);
4152 * qla4xxx_mem_free - frees memory allocated to adapter
4153 * @ha: Pointer to host adapter structure.
4155 * Frees memory previously allocated by qla4xxx_mem_alloc
4157 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4160 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4169 ha->request_ring = NULL;
4170 ha->request_dma = 0;
4171 ha->response_ring = NULL;
4172 ha->response_dma = 0;
4173 ha->shadow_regs = NULL;
4174 ha->shadow_regs_dma = 0;
4176 ha->fw_dump_size = 0;
4178 /* Free srb pool. */
4179 if (ha->srb_mempool)
4180 mempool_destroy(ha->srb_mempool);
4182 ha->srb_mempool = NULL;
4184 if (ha->chap_dma_pool)
4185 dma_pool_destroy(ha->chap_dma_pool);
4188 vfree(ha->chap_list);
4189 ha->chap_list = NULL;
4191 if (ha->fw_ddb_dma_pool)
4192 dma_pool_destroy(ha->fw_ddb_dma_pool);
4194 /* release io space registers */
4195 if (is_qla8022(ha)) {
4198 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4199 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4202 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4203 } else if (ha->reg) {
4207 if (ha->reset_tmplt.buff)
4208 vfree(ha->reset_tmplt.buff);
4210 pci_release_regions(ha->pdev);
4214 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4215 * @ha: Pointer to host adapter structure
4217 * Allocates DMA memory for request and response queues. Also allocates memory
4220 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4222 unsigned long align;
4224 /* Allocate contiguous block of DMA memory for queues. */
4225 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4226 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4227 sizeof(struct shadow_regs) +
4229 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4230 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4231 &ha->queues_dma, GFP_KERNEL);
4232 if (ha->queues == NULL) {
4233 ql4_printk(KERN_WARNING, ha,
4234 "Memory Allocation failed - queues.\n");
4236 goto mem_alloc_error_exit;
4238 memset(ha->queues, 0, ha->queues_len);
4241 * As per RISC alignment requirements -- the bus-address must be a
4242 * multiple of the request-ring size (in bytes).
4245 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4246 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4247 (MEM_ALIGN_VALUE - 1));
4249 /* Update request and response queue pointers. */
4250 ha->request_dma = ha->queues_dma + align;
4251 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4252 ha->response_dma = ha->queues_dma + align +
4253 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4254 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4255 (REQUEST_QUEUE_DEPTH *
4257 ha->shadow_regs_dma = ha->queues_dma + align +
4258 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4259 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4260 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4261 (REQUEST_QUEUE_DEPTH *
4263 (RESPONSE_QUEUE_DEPTH *
4266 /* Allocate memory for srb pool. */
4267 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4268 mempool_free_slab, srb_cachep);
4269 if (ha->srb_mempool == NULL) {
4270 ql4_printk(KERN_WARNING, ha,
4271 "Memory Allocation failed - SRB Pool.\n");
4273 goto mem_alloc_error_exit;
4276 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4277 CHAP_DMA_BLOCK_SIZE, 8, 0);
4279 if (ha->chap_dma_pool == NULL) {
4280 ql4_printk(KERN_WARNING, ha,
4281 "%s: chap_dma_pool allocation failed..\n", __func__);
4282 goto mem_alloc_error_exit;
4285 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4286 DDB_DMA_BLOCK_SIZE, 8, 0);
4288 if (ha->fw_ddb_dma_pool == NULL) {
4289 ql4_printk(KERN_WARNING, ha,
4290 "%s: fw_ddb_dma_pool allocation failed..\n",
4292 goto mem_alloc_error_exit;
4297 mem_alloc_error_exit:
4302 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4303 * @ha: adapter block pointer.
4305 * Note: The caller should not hold the idc lock.
4307 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4309 uint32_t temp, temp_state, temp_val;
4310 int status = QLA_SUCCESS;
4312 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4314 temp_state = qla82xx_get_temp_state(temp);
4315 temp_val = qla82xx_get_temp_val(temp);
4317 if (temp_state == QLA82XX_TEMP_PANIC) {
4318 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4319 " exceeds maximum allowed. Hardware has been shut"
4320 " down.\n", temp_val);
4322 } else if (temp_state == QLA82XX_TEMP_WARN) {
4323 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4324 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4325 " degrees C exceeds operating range."
4326 " Immediate action needed.\n", temp_val);
4328 if (ha->temperature == QLA82XX_TEMP_WARN)
4329 ql4_printk(KERN_INFO, ha, "Device temperature is"
4330 " now %d degrees C in normal range.\n",
4333 ha->temperature = temp_state;
4338 * qla4_8xxx_check_fw_alive - Check firmware health
4339 * @ha: Pointer to host adapter structure.
4341 * Context: Interrupt
4343 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4345 uint32_t fw_heartbeat_counter;
4346 int status = QLA_SUCCESS;
4348 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4349 QLA8XXX_PEG_ALIVE_COUNTER);
4350 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4351 if (fw_heartbeat_counter == 0xffffffff) {
4352 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4353 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4354 ha->host_no, __func__));
4358 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4359 ha->seconds_since_last_heartbeat++;
4360 /* FW not alive after 2 seconds */
4361 if (ha->seconds_since_last_heartbeat == 2) {
4362 ha->seconds_since_last_heartbeat = 0;
4363 qla4_8xxx_dump_peg_reg(ha);
4367 ha->seconds_since_last_heartbeat = 0;
4369 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4373 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4375 uint32_t halt_status;
4376 int halt_status_unrecoverable = 0;
4378 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4380 if (is_qla8022(ha)) {
4381 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4383 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4384 CRB_NIU_XG_PAUSE_CTL_P0 |
4385 CRB_NIU_XG_PAUSE_CTL_P1);
4387 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4388 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4390 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4391 halt_status_unrecoverable = 1;
4392 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4393 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4394 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4396 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4397 halt_status_unrecoverable = 1;
4401 * Since we cannot change dev_state in interrupt context,
4402 * set appropriate DPC flag then wakeup DPC
4404 if (halt_status_unrecoverable) {
4405 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4407 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4409 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4411 qla4xxx_mailbox_premature_completion(ha);
4412 qla4xxx_wake_dpc(ha);
4416 * qla4_8xxx_watchdog - Poll dev state
4417 * @ha: Pointer to host adapter structure.
4419 * Context: Interrupt
4421 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4426 if (is_qla8032(ha) &&
4427 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4428 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4429 __func__, ha->func_num);
4431 /* don't poll if reset is going on */
4432 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4433 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4434 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4435 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4437 if (qla4_8xxx_check_temp(ha)) {
4438 if (is_qla8022(ha)) {
4439 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4440 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4441 CRB_NIU_XG_PAUSE_CTL_P0 |
4442 CRB_NIU_XG_PAUSE_CTL_P1);
4444 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4445 qla4xxx_wake_dpc(ha);
4446 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4447 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4449 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4452 if (is_qla8032(ha) || is_qla8042(ha)) {
4453 idc_ctrl = qla4_83xx_rd_reg(ha,
4454 QLA83XX_IDC_DRV_CTRL);
4455 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4456 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4458 qla4xxx_mailbox_premature_completion(
4463 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4464 (is_qla8022(ha) && !ql4xdontresethba)) {
4465 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4466 qla4xxx_wake_dpc(ha);
4468 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4469 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4470 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4472 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4473 qla4xxx_wake_dpc(ha);
4475 /* Check firmware health */
4476 if (qla4_8xxx_check_fw_alive(ha))
4477 qla4_8xxx_process_fw_error(ha);
4482 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4484 struct iscsi_session *sess;
4485 struct ddb_entry *ddb_entry;
4486 struct scsi_qla_host *ha;
4488 sess = cls_sess->dd_data;
4489 ddb_entry = sess->dd_data;
4492 if (!(ddb_entry->ddb_type == FLASH_DDB))
4495 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4496 !iscsi_is_session_online(cls_sess)) {
4497 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4499 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4501 atomic_set(&ddb_entry->retry_relogin_timer,
4503 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4504 set_bit(DF_RELOGIN, &ddb_entry->flags);
4505 DEBUG2(ql4_printk(KERN_INFO, ha,
4506 "%s: index [%d] login device\n",
4507 __func__, ddb_entry->fw_ddb_index));
4509 atomic_dec(&ddb_entry->retry_relogin_timer);
4513 /* Wait for relogin to timeout */
4514 if (atomic_read(&ddb_entry->relogin_timer) &&
4515 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4517 * If the relogin times out and the device is
4518 * still NOT ONLINE then try and relogin again.
4520 if (!iscsi_is_session_online(cls_sess)) {
4521 /* Reset retry relogin timer */
4522 atomic_inc(&ddb_entry->relogin_retry_count);
4523 DEBUG2(ql4_printk(KERN_INFO, ha,
4524 "%s: index[%d] relogin timed out-retrying"
4525 " relogin (%d), retry (%d)\n", __func__,
4526 ddb_entry->fw_ddb_index,
4527 atomic_read(&ddb_entry->relogin_retry_count),
4528 ddb_entry->default_time2wait + 4));
4529 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4530 atomic_set(&ddb_entry->retry_relogin_timer,
4531 ddb_entry->default_time2wait + 4);
4537 * qla4xxx_timer - checks every second for work to do.
4538 * @ha: Pointer to host adapter structure.
4540 static void qla4xxx_timer(struct scsi_qla_host *ha)
4545 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4547 /* If we are in the middle of AER/EEH processing
4548 * skip any processing and reschedule the timer
4550 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4551 mod_timer(&ha->timer, jiffies + HZ);
4555 /* Hardware read to trigger an EEH error during mailbox waits. */
4556 if (!pci_channel_offline(ha->pdev))
4557 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4560 qla4_8xxx_watchdog(ha);
4562 if (is_qla40XX(ha)) {
4563 /* Check for heartbeat interval. */
4564 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4565 ha->heartbeat_interval != 0) {
4566 ha->seconds_since_last_heartbeat++;
4567 if (ha->seconds_since_last_heartbeat >
4568 ha->heartbeat_interval + 2)
4569 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4573 /* Process any deferred work. */
4574 if (!list_empty(&ha->work_list))
4577 /* Wakeup the dpc routine for this adapter, if needed. */
4579 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4580 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4581 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4582 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4583 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4584 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4585 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4586 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4587 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4588 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4589 test_bit(DPC_AEN, &ha->dpc_flags)) {
4590 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4591 " - dpc flags = 0x%lx\n",
4592 ha->host_no, __func__, ha->dpc_flags));
4593 qla4xxx_wake_dpc(ha);
4596 /* Reschedule timer thread to call us back in one second */
4597 mod_timer(&ha->timer, jiffies + HZ);
4599 DEBUG2(ha->seconds_since_last_intr++);
4603 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4604 * @ha: Pointer to host adapter structure.
4606 * This routine stalls the driver until all outstanding commands are returned.
4607 * Caller must release the Hardware Lock prior to calling this routine.
4609 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4612 unsigned long flags;
4613 struct scsi_cmnd *cmd;
4614 unsigned long wtime;
4618 wtmo = WAIT_CMD_TOV;
4620 wtmo = ha->nx_reset_timeout / 2;
4622 wtime = jiffies + (wtmo * HZ);
4624 DEBUG2(ql4_printk(KERN_INFO, ha,
4625 "Wait up to %u seconds for cmds to complete\n",
4628 while (!time_after_eq(jiffies, wtime)) {
4629 spin_lock_irqsave(&ha->hardware_lock, flags);
4630 /* Find a command that hasn't completed. */
4631 for (index = 0; index < ha->host->can_queue; index++) {
4632 cmd = scsi_host_find_tag(ha->host, index);
4634 * We cannot just check if the index is valid,
4635 * becase if we are run from the scsi eh, then
4636 * the scsi/block layer is going to prevent
4637 * the tag from being released.
4639 if (cmd != NULL && CMD_SP(cmd))
4642 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4644 /* If No Commands are pending, wait is complete */
4645 if (index == ha->host->can_queue)
4650 /* If we timed out on waiting for commands to come back
4655 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4657 uint32_t ctrl_status;
4658 unsigned long flags = 0;
4660 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4662 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4665 spin_lock_irqsave(&ha->hardware_lock, flags);
4668 * If the SCSI Reset Interrupt bit is set, clear it.
4669 * Otherwise, the Soft Reset won't work.
4671 ctrl_status = readw(&ha->reg->ctrl_status);
4672 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4673 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4675 /* Issue Soft Reset */
4676 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4677 readl(&ha->reg->ctrl_status);
4679 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4684 * qla4xxx_soft_reset - performs soft reset.
4685 * @ha: Pointer to host adapter structure.
4687 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4689 uint32_t max_wait_time;
4690 unsigned long flags = 0;
4692 uint32_t ctrl_status;
4694 status = qla4xxx_hw_reset(ha);
4695 if (status != QLA_SUCCESS)
4699 /* Wait until the Network Reset Intr bit is cleared */
4700 max_wait_time = RESET_INTR_TOV;
4702 spin_lock_irqsave(&ha->hardware_lock, flags);
4703 ctrl_status = readw(&ha->reg->ctrl_status);
4704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4706 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4710 } while ((--max_wait_time));
4712 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4713 DEBUG2(printk(KERN_WARNING
4714 "scsi%ld: Network Reset Intr not cleared by "
4715 "Network function, clearing it now!\n",
4717 spin_lock_irqsave(&ha->hardware_lock, flags);
4718 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4719 readl(&ha->reg->ctrl_status);
4720 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4723 /* Wait until the firmware tells us the Soft Reset is done */
4724 max_wait_time = SOFT_RESET_TOV;
4726 spin_lock_irqsave(&ha->hardware_lock, flags);
4727 ctrl_status = readw(&ha->reg->ctrl_status);
4728 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4730 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4731 status = QLA_SUCCESS;
4736 } while ((--max_wait_time));
4739 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4740 * after the soft reset has taken place.
4742 spin_lock_irqsave(&ha->hardware_lock, flags);
4743 ctrl_status = readw(&ha->reg->ctrl_status);
4744 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4745 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4746 readl(&ha->reg->ctrl_status);
4748 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4750 /* If soft reset fails then most probably the bios on other
4751 * function is also enabled.
4752 * Since the initialization is sequential the other fn
4753 * wont be able to acknowledge the soft reset.
4754 * Issue a force soft reset to workaround this scenario.
4756 if (max_wait_time == 0) {
4757 /* Issue Force Soft Reset */
4758 spin_lock_irqsave(&ha->hardware_lock, flags);
4759 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4760 readl(&ha->reg->ctrl_status);
4761 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4762 /* Wait until the firmware tells us the Soft Reset is done */
4763 max_wait_time = SOFT_RESET_TOV;
4765 spin_lock_irqsave(&ha->hardware_lock, flags);
4766 ctrl_status = readw(&ha->reg->ctrl_status);
4767 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4769 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4770 status = QLA_SUCCESS;
4775 } while ((--max_wait_time));
4782 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4783 * @ha: Pointer to host adapter structure.
4784 * @res: returned scsi status
4786 * This routine is called just prior to a HARD RESET to return all
4787 * outstanding commands back to the Operating System.
4788 * Caller should make sure that the following locks are released
4789 * before this calling routine: Hardware lock, and io_request_lock.
4791 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4795 unsigned long flags;
4797 spin_lock_irqsave(&ha->hardware_lock, flags);
4798 for (i = 0; i < ha->host->can_queue; i++) {
4799 srb = qla4xxx_del_from_active_array(ha, i);
4801 srb->cmd->result = res;
4802 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4805 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4808 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4810 clear_bit(AF_ONLINE, &ha->flags);
4812 /* Disable the board */
4813 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4815 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4816 qla4xxx_mark_all_devices_missing(ha);
4817 clear_bit(AF_INIT_DONE, &ha->flags);
4820 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4822 struct iscsi_session *sess;
4823 struct ddb_entry *ddb_entry;
4825 sess = cls_session->dd_data;
4826 ddb_entry = sess->dd_data;
4827 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4829 if (ddb_entry->ddb_type == FLASH_DDB)
4830 iscsi_block_session(ddb_entry->sess);
4832 iscsi_session_failure(cls_session->dd_data,
4833 ISCSI_ERR_CONN_FAILED);
4837 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4838 * @ha: Pointer to host adapter structure.
4840 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4842 int status = QLA_ERROR;
4843 uint8_t reset_chip = 0;
4847 /* Stall incoming I/O until we are done */
4848 scsi_block_requests(ha->host);
4849 clear_bit(AF_ONLINE, &ha->flags);
4850 clear_bit(AF_LINK_UP, &ha->flags);
4852 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4854 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4856 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4857 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4858 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4860 /* disable pause frame for ISP83xx */
4861 qla4_83xx_disable_pause(ha);
4864 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4866 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4869 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4870 * do not reset adapter, jump to initialize_adapter */
4871 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4872 status = QLA_SUCCESS;
4873 goto recover_ha_init_adapter;
4876 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4877 * from eh_host_reset or ioctl module */
4878 if (is_qla80XX(ha) && !reset_chip &&
4879 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4881 DEBUG2(ql4_printk(KERN_INFO, ha,
4882 "scsi%ld: %s - Performing stop_firmware...\n",
4883 ha->host_no, __func__));
4884 status = ha->isp_ops->reset_firmware(ha);
4885 if (status == QLA_SUCCESS) {
4886 ha->isp_ops->disable_intrs(ha);
4887 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4888 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4890 /* If the stop_firmware fails then
4891 * reset the entire chip */
4893 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4894 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4898 /* Issue full chip reset if recovering from a catastrophic error,
4899 * or if stop_firmware fails for ISP-8xxx.
4900 * This is the default case for ISP-4xxx */
4901 if (is_qla40XX(ha) || reset_chip) {
4905 /* Check if 8XXX firmware is alive or not
4906 * We may have arrived here from NEED_RESET
4908 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4911 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4912 while (time_before(jiffies, wait)) {
4913 if (qla4_8xxx_check_fw_alive(ha)) {
4914 qla4xxx_mailbox_premature_completion(ha);
4918 set_current_state(TASK_UNINTERRUPTIBLE);
4919 schedule_timeout(HZ);
4922 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4923 qla4xxx_cmd_wait(ha);
4925 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4926 DEBUG2(ql4_printk(KERN_INFO, ha,
4927 "scsi%ld: %s - Performing chip reset..\n",
4928 ha->host_no, __func__));
4929 status = ha->isp_ops->reset_chip(ha);
4930 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4933 /* Flush any pending ddb changed AENs */
4934 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4936 recover_ha_init_adapter:
4937 /* Upon successful firmware/chip reset, re-initialize the adapter */
4938 if (status == QLA_SUCCESS) {
4939 /* For ISP-4xxx, force function 1 to always initialize
4940 * before function 3 to prevent both funcions from
4941 * stepping on top of the other */
4942 if (is_qla40XX(ha) && (ha->mac_index == 3))
4945 /* NOTE: AF_ONLINE flag set upon successful completion of
4946 * qla4xxx_initialize_adapter */
4947 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4948 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4949 status = qla4_8xxx_check_init_adapter_retry(ha);
4950 if (status == QLA_ERROR) {
4951 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4952 ha->host_no, __func__);
4953 qla4xxx_dead_adapter_cleanup(ha);
4954 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4955 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4956 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4963 /* Retry failed adapter initialization, if necessary
4964 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4965 * case to prevent ping-pong resets between functions */
4966 if (!test_bit(AF_ONLINE, &ha->flags) &&
4967 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4968 /* Adapter initialization failed, see if we can retry
4970 * Since we don't want to block the DPC for too long
4971 * with multiple resets in the same thread,
4972 * utilize DPC to retry */
4973 if (is_qla80XX(ha)) {
4974 ha->isp_ops->idc_lock(ha);
4975 dev_state = qla4_8xxx_rd_direct(ha,
4976 QLA8XXX_CRB_DEV_STATE);
4977 ha->isp_ops->idc_unlock(ha);
4978 if (dev_state == QLA8XXX_DEV_FAILED) {
4979 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4980 "recover adapter. H/W is in Failed "
4981 "state\n", __func__);
4982 qla4xxx_dead_adapter_cleanup(ha);
4983 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4984 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4985 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4993 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4994 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4995 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4996 "(%d) more times\n", ha->host_no,
4997 ha->retry_reset_ha_cnt));
4998 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5001 if (ha->retry_reset_ha_cnt > 0) {
5002 /* Schedule another Reset HA--DPC will retry */
5003 ha->retry_reset_ha_cnt--;
5004 DEBUG2(printk("scsi%ld: recover adapter - "
5005 "retry remaining %d\n",
5007 ha->retry_reset_ha_cnt));
5011 if (ha->retry_reset_ha_cnt == 0) {
5012 /* Recover adapter retries have been exhausted.
5014 DEBUG2(printk("scsi%ld: recover adapter "
5015 "failed - board disabled\n",
5017 qla4xxx_dead_adapter_cleanup(ha);
5018 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5019 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5020 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5026 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5027 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5028 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5032 ha->adapter_error_count++;
5034 if (test_bit(AF_ONLINE, &ha->flags))
5035 ha->isp_ops->enable_intrs(ha);
5037 scsi_unblock_requests(ha->host);
5039 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5040 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5041 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5046 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5048 struct iscsi_session *sess;
5049 struct ddb_entry *ddb_entry;
5050 struct scsi_qla_host *ha;
5052 sess = cls_session->dd_data;
5053 ddb_entry = sess->dd_data;
5055 if (!iscsi_is_session_online(cls_session)) {
5056 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5057 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5058 " unblock session\n", ha->host_no, __func__,
5059 ddb_entry->fw_ddb_index);
5060 iscsi_unblock_session(ddb_entry->sess);
5062 /* Trigger relogin */
5063 if (ddb_entry->ddb_type == FLASH_DDB) {
5064 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5065 test_bit(DF_DISABLE_RELOGIN,
5066 &ddb_entry->flags)))
5067 qla4xxx_arm_relogin_timer(ddb_entry);
5069 iscsi_session_failure(cls_session->dd_data,
5070 ISCSI_ERR_CONN_FAILED);
5075 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5077 struct iscsi_session *sess;
5078 struct ddb_entry *ddb_entry;
5079 struct scsi_qla_host *ha;
5081 sess = cls_session->dd_data;
5082 ddb_entry = sess->dd_data;
5084 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5085 " unblock session\n", ha->host_no, __func__,
5086 ddb_entry->fw_ddb_index);
5088 iscsi_unblock_session(ddb_entry->sess);
5090 /* Start scan target */
5091 if (test_bit(AF_ONLINE, &ha->flags)) {
5092 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5093 " start scan\n", ha->host_no, __func__,
5094 ddb_entry->fw_ddb_index);
5095 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5100 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5102 struct iscsi_session *sess;
5103 struct ddb_entry *ddb_entry;
5104 struct scsi_qla_host *ha;
5105 int status = QLA_SUCCESS;
5107 sess = cls_session->dd_data;
5108 ddb_entry = sess->dd_data;
5110 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5111 " unblock user space session\n", ha->host_no, __func__,
5112 ddb_entry->fw_ddb_index);
5114 if (!iscsi_is_session_online(cls_session)) {
5115 iscsi_conn_start(ddb_entry->conn);
5116 iscsi_conn_login_event(ddb_entry->conn,
5117 ISCSI_CONN_STATE_LOGGED_IN);
5119 ql4_printk(KERN_INFO, ha,
5120 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5121 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5129 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5131 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5134 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5136 uint16_t relogin_timer;
5137 struct iscsi_session *sess;
5138 struct ddb_entry *ddb_entry;
5139 struct scsi_qla_host *ha;
5141 sess = cls_sess->dd_data;
5142 ddb_entry = sess->dd_data;
5145 relogin_timer = max(ddb_entry->default_relogin_timeout,
5146 (uint16_t)RELOGIN_TOV);
5147 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5149 DEBUG2(ql4_printk(KERN_INFO, ha,
5150 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5151 ddb_entry->fw_ddb_index, relogin_timer));
5153 qla4xxx_login_flash_ddb(cls_sess);
5156 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5158 struct iscsi_session *sess;
5159 struct ddb_entry *ddb_entry;
5160 struct scsi_qla_host *ha;
5162 sess = cls_sess->dd_data;
5163 ddb_entry = sess->dd_data;
5166 if (!(ddb_entry->ddb_type == FLASH_DDB))
5169 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5172 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5173 !iscsi_is_session_online(cls_sess)) {
5174 DEBUG2(ql4_printk(KERN_INFO, ha,
5175 "relogin issued\n"));
5176 qla4xxx_relogin_flash_ddb(cls_sess);
5180 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5183 queue_work(ha->dpc_thread, &ha->dpc_work);
5186 static struct qla4_work_evt *
5187 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5188 enum qla4_work_type type)
5190 struct qla4_work_evt *e;
5191 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5193 e = kzalloc(size, GFP_ATOMIC);
5197 INIT_LIST_HEAD(&e->list);
5202 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5203 struct qla4_work_evt *e)
5205 unsigned long flags;
5207 spin_lock_irqsave(&ha->work_lock, flags);
5208 list_add_tail(&e->list, &ha->work_list);
5209 spin_unlock_irqrestore(&ha->work_lock, flags);
5210 qla4xxx_wake_dpc(ha);
5213 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5214 enum iscsi_host_event_code aen_code,
5215 uint32_t data_size, uint8_t *data)
5217 struct qla4_work_evt *e;
5219 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5223 e->u.aen.code = aen_code;
5224 e->u.aen.data_size = data_size;
5225 memcpy(e->u.aen.data, data, data_size);
5227 qla4xxx_post_work(ha, e);
5232 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5233 uint32_t status, uint32_t pid,
5234 uint32_t data_size, uint8_t *data)
5236 struct qla4_work_evt *e;
5238 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5242 e->u.ping.status = status;
5243 e->u.ping.pid = pid;
5244 e->u.ping.data_size = data_size;
5245 memcpy(e->u.ping.data, data, data_size);
5247 qla4xxx_post_work(ha, e);
5252 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5254 struct qla4_work_evt *e, *tmp;
5255 unsigned long flags;
5258 spin_lock_irqsave(&ha->work_lock, flags);
5259 list_splice_init(&ha->work_list, &work);
5260 spin_unlock_irqrestore(&ha->work_lock, flags);
5262 list_for_each_entry_safe(e, tmp, &work, list) {
5263 list_del_init(&e->list);
5266 case QLA4_EVENT_AEN:
5267 iscsi_post_host_event(ha->host_no,
5268 &qla4xxx_iscsi_transport,
5273 case QLA4_EVENT_PING_STATUS:
5274 iscsi_ping_comp_event(ha->host_no,
5275 &qla4xxx_iscsi_transport,
5278 e->u.ping.data_size,
5282 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5283 "supported", e->type);
5290 * qla4xxx_do_dpc - dpc routine
5291 * @data: in our case pointer to adapter structure
5293 * This routine is a task that is schedule by the interrupt handler
5294 * to perform the background processing for interrupts. We put it
5295 * on a task queue that is consumed whenever the scheduler runs; that's
5296 * so you can do anything (i.e. put the process to sleep etc). In fact,
5297 * the mid-level tries to sleep when it reaches the driver threshold
5298 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5300 static void qla4xxx_do_dpc(struct work_struct *work)
5302 struct scsi_qla_host *ha =
5303 container_of(work, struct scsi_qla_host, dpc_work);
5304 int status = QLA_ERROR;
5306 DEBUG2(ql4_printk(KERN_INFO, ha,
5307 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5308 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5310 /* Initialization not yet finished. Don't do anything yet. */
5311 if (!test_bit(AF_INIT_DONE, &ha->flags))
5314 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5315 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5316 ha->host_no, __func__, ha->flags));
5320 /* post events to application */
5321 qla4xxx_do_work(ha);
5323 if (is_qla80XX(ha)) {
5324 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5325 if (is_qla8032(ha) || is_qla8042(ha)) {
5326 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5328 /* disable pause frame for ISP83xx */
5329 qla4_83xx_disable_pause(ha);
5332 ha->isp_ops->idc_lock(ha);
5333 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5334 QLA8XXX_DEV_FAILED);
5335 ha->isp_ops->idc_unlock(ha);
5336 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5337 qla4_8xxx_device_state_handler(ha);
5340 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5341 if (is_qla8042(ha)) {
5342 if (ha->idc_info.info2 &
5343 ENABLE_INTERNAL_LOOPBACK) {
5344 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5346 status = qla4_84xx_config_acb(ha,
5347 ACB_CONFIG_DISABLE);
5348 if (status != QLA_SUCCESS) {
5349 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5354 qla4_83xx_post_idc_ack(ha);
5355 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5358 if (is_qla8042(ha) &&
5359 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5360 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5362 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5364 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5367 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5370 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5371 qla4_8xxx_need_qsnt_handler(ha);
5375 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5376 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5377 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5378 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5379 if ((is_qla8022(ha) && ql4xdontresethba) ||
5380 ((is_qla8032(ha) || is_qla8042(ha)) &&
5381 qla4_83xx_idc_dontreset(ha))) {
5382 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5383 ha->host_no, __func__));
5384 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5385 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5386 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5387 goto dpc_post_reset_ha;
5389 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5390 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5391 qla4xxx_recover_adapter(ha);
5393 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5394 uint8_t wait_time = RESET_INTR_TOV;
5396 while ((readw(&ha->reg->ctrl_status) &
5397 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5398 if (--wait_time == 0)
5403 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5404 "bit not cleared-- resetting\n",
5405 ha->host_no, __func__));
5406 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5407 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5408 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5409 status = qla4xxx_recover_adapter(ha);
5411 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5412 if (status == QLA_SUCCESS)
5413 ha->isp_ops->enable_intrs(ha);
5418 /* ---- process AEN? --- */
5419 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5420 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5422 /* ---- Get DHCP IP Address? --- */
5423 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5424 qla4xxx_get_dhcp_ip_address(ha);
5426 /* ---- relogin device? --- */
5427 if (adapter_up(ha) &&
5428 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5429 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5432 /* ---- link change? --- */
5433 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5434 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5435 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5436 /* ---- link down? --- */
5437 qla4xxx_mark_all_devices_missing(ha);
5439 /* ---- link up? --- *
5440 * F/W will auto login to all devices ONLY ONCE after
5441 * link up during driver initialization and runtime
5442 * fatal error recovery. Therefore, the driver must
5443 * manually relogin to devices when recovering from
5444 * connection failures, logouts, expired KATO, etc. */
5445 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5446 qla4xxx_build_ddb_list(ha, ha->is_reset);
5447 iscsi_host_for_each_session(ha->host,
5448 qla4xxx_login_flash_ddb);
5450 qla4xxx_relogin_all_devices(ha);
5453 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5454 if (qla4xxx_sysfs_ddb_export(ha))
5455 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5461 * qla4xxx_free_adapter - release the adapter
5462 * @ha: pointer to adapter structure
5464 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5466 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5468 /* Turn-off interrupts on the card. */
5469 ha->isp_ops->disable_intrs(ha);
5471 if (is_qla40XX(ha)) {
5472 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5473 &ha->reg->ctrl_status);
5474 readl(&ha->reg->ctrl_status);
5475 } else if (is_qla8022(ha)) {
5476 writel(0, &ha->qla4_82xx_reg->host_int);
5477 readl(&ha->qla4_82xx_reg->host_int);
5478 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5479 writel(0, &ha->qla4_83xx_reg->risc_intr);
5480 readl(&ha->qla4_83xx_reg->risc_intr);
5483 /* Remove timer thread, if present */
5484 if (ha->timer_active)
5485 qla4xxx_stop_timer(ha);
5487 /* Kill the kernel thread for this host */
5489 destroy_workqueue(ha->dpc_thread);
5491 /* Kill the kernel thread for this host */
5493 destroy_workqueue(ha->task_wq);
5495 /* Put firmware in known state */
5496 ha->isp_ops->reset_firmware(ha);
5498 if (is_qla80XX(ha)) {
5499 ha->isp_ops->idc_lock(ha);
5500 qla4_8xxx_clear_drv_active(ha);
5501 ha->isp_ops->idc_unlock(ha);
5504 /* Detach interrupts */
5505 qla4xxx_free_irqs(ha);
5507 /* free extra memory */
5508 qla4xxx_mem_free(ha);
5511 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5514 unsigned long mem_base, mem_len, db_base, db_len;
5515 struct pci_dev *pdev = ha->pdev;
5517 status = pci_request_regions(pdev, DRIVER_NAME);
5520 "scsi(%ld) Failed to reserve PIO regions (%s) "
5521 "status=%d\n", ha->host_no, pci_name(pdev), status);
5522 goto iospace_error_exit;
5525 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5526 __func__, pdev->revision));
5527 ha->revision_id = pdev->revision;
5529 /* remap phys address */
5530 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5531 mem_len = pci_resource_len(pdev, 0);
5532 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5533 __func__, mem_base, mem_len));
5535 /* mapping of pcibase pointer */
5536 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5537 if (!ha->nx_pcibase) {
5539 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5540 pci_release_regions(ha->pdev);
5541 goto iospace_error_exit;
5544 /* Mapping of IO base pointer, door bell read and write pointer */
5546 /* mapping of IO base pointer */
5547 if (is_qla8022(ha)) {
5548 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5549 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5550 (ha->pdev->devfn << 11));
5551 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5552 QLA82XX_CAM_RAM_DB2);
5553 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5554 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5555 ((uint8_t *)ha->nx_pcibase);
5558 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5559 db_len = pci_resource_len(pdev, 4);
5567 * qla4xxx_iospace_config - maps registers
5568 * @ha: pointer to adapter structure
5570 * This routines maps HBA's registers from the pci address space
5571 * into the kernel virtual address space for memory mapped i/o.
5573 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5575 unsigned long pio, pio_len, pio_flags;
5576 unsigned long mmio, mmio_len, mmio_flags;
5578 pio = pci_resource_start(ha->pdev, 0);
5579 pio_len = pci_resource_len(ha->pdev, 0);
5580 pio_flags = pci_resource_flags(ha->pdev, 0);
5581 if (pio_flags & IORESOURCE_IO) {
5582 if (pio_len < MIN_IOBASE_LEN) {
5583 ql4_printk(KERN_WARNING, ha,
5584 "Invalid PCI I/O region size\n");
5588 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5592 /* Use MMIO operations for all accesses. */
5593 mmio = pci_resource_start(ha->pdev, 1);
5594 mmio_len = pci_resource_len(ha->pdev, 1);
5595 mmio_flags = pci_resource_flags(ha->pdev, 1);
5597 if (!(mmio_flags & IORESOURCE_MEM)) {
5598 ql4_printk(KERN_ERR, ha,
5599 "region #0 not an MMIO resource, aborting\n");
5601 goto iospace_error_exit;
5604 if (mmio_len < MIN_IOBASE_LEN) {
5605 ql4_printk(KERN_ERR, ha,
5606 "Invalid PCI mem region size, aborting\n");
5607 goto iospace_error_exit;
5610 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5611 ql4_printk(KERN_WARNING, ha,
5612 "Failed to reserve PIO/MMIO regions\n");
5614 goto iospace_error_exit;
5617 ha->pio_address = pio;
5618 ha->pio_length = pio_len;
5619 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5621 ql4_printk(KERN_ERR, ha,
5622 "cannot remap MMIO, aborting\n");
5624 goto iospace_error_exit;
5633 static struct isp_operations qla4xxx_isp_ops = {
5634 .iospace_config = qla4xxx_iospace_config,
5635 .pci_config = qla4xxx_pci_config,
5636 .disable_intrs = qla4xxx_disable_intrs,
5637 .enable_intrs = qla4xxx_enable_intrs,
5638 .start_firmware = qla4xxx_start_firmware,
5639 .intr_handler = qla4xxx_intr_handler,
5640 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5641 .reset_chip = qla4xxx_soft_reset,
5642 .reset_firmware = qla4xxx_hw_reset,
5643 .queue_iocb = qla4xxx_queue_iocb,
5644 .complete_iocb = qla4xxx_complete_iocb,
5645 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5646 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5647 .get_sys_info = qla4xxx_get_sys_info,
5648 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5649 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5652 static struct isp_operations qla4_82xx_isp_ops = {
5653 .iospace_config = qla4_8xxx_iospace_config,
5654 .pci_config = qla4_8xxx_pci_config,
5655 .disable_intrs = qla4_82xx_disable_intrs,
5656 .enable_intrs = qla4_82xx_enable_intrs,
5657 .start_firmware = qla4_8xxx_load_risc,
5658 .restart_firmware = qla4_82xx_try_start_fw,
5659 .intr_handler = qla4_82xx_intr_handler,
5660 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5661 .need_reset = qla4_8xxx_need_reset,
5662 .reset_chip = qla4_82xx_isp_reset,
5663 .reset_firmware = qla4_8xxx_stop_firmware,
5664 .queue_iocb = qla4_82xx_queue_iocb,
5665 .complete_iocb = qla4_82xx_complete_iocb,
5666 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5667 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5668 .get_sys_info = qla4_8xxx_get_sys_info,
5669 .rd_reg_direct = qla4_82xx_rd_32,
5670 .wr_reg_direct = qla4_82xx_wr_32,
5671 .rd_reg_indirect = qla4_82xx_md_rd_32,
5672 .wr_reg_indirect = qla4_82xx_md_wr_32,
5673 .idc_lock = qla4_82xx_idc_lock,
5674 .idc_unlock = qla4_82xx_idc_unlock,
5675 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5676 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5677 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5680 static struct isp_operations qla4_83xx_isp_ops = {
5681 .iospace_config = qla4_8xxx_iospace_config,
5682 .pci_config = qla4_8xxx_pci_config,
5683 .disable_intrs = qla4_83xx_disable_intrs,
5684 .enable_intrs = qla4_83xx_enable_intrs,
5685 .start_firmware = qla4_8xxx_load_risc,
5686 .restart_firmware = qla4_83xx_start_firmware,
5687 .intr_handler = qla4_83xx_intr_handler,
5688 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5689 .need_reset = qla4_8xxx_need_reset,
5690 .reset_chip = qla4_83xx_isp_reset,
5691 .reset_firmware = qla4_8xxx_stop_firmware,
5692 .queue_iocb = qla4_83xx_queue_iocb,
5693 .complete_iocb = qla4_83xx_complete_iocb,
5694 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5695 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5696 .get_sys_info = qla4_8xxx_get_sys_info,
5697 .rd_reg_direct = qla4_83xx_rd_reg,
5698 .wr_reg_direct = qla4_83xx_wr_reg,
5699 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5700 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5701 .idc_lock = qla4_83xx_drv_lock,
5702 .idc_unlock = qla4_83xx_drv_unlock,
5703 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5704 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5705 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5708 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5710 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5713 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5715 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5718 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5720 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5723 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5725 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5728 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5730 struct scsi_qla_host *ha = data;
5735 case ISCSI_BOOT_ETH_FLAGS:
5736 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5738 case ISCSI_BOOT_ETH_INDEX:
5739 rc = sprintf(str, "0\n");
5741 case ISCSI_BOOT_ETH_MAC:
5742 rc = sysfs_format_mac(str, ha->my_mac,
5752 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5757 case ISCSI_BOOT_ETH_FLAGS:
5758 case ISCSI_BOOT_ETH_MAC:
5759 case ISCSI_BOOT_ETH_INDEX:
5769 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5771 struct scsi_qla_host *ha = data;
5776 case ISCSI_BOOT_INI_INITIATOR_NAME:
5777 rc = sprintf(str, "%s\n", ha->name_string);
5786 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5791 case ISCSI_BOOT_INI_INITIATOR_NAME:
5802 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5805 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5810 case ISCSI_BOOT_TGT_NAME:
5811 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5813 case ISCSI_BOOT_TGT_IP_ADDR:
5814 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5815 rc = sprintf(buf, "%pI4\n",
5816 &boot_conn->dest_ipaddr.ip_address);
5818 rc = sprintf(str, "%pI6\n",
5819 &boot_conn->dest_ipaddr.ip_address);
5821 case ISCSI_BOOT_TGT_PORT:
5822 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5824 case ISCSI_BOOT_TGT_CHAP_NAME:
5825 rc = sprintf(str, "%.*s\n",
5826 boot_conn->chap.target_chap_name_length,
5827 (char *)&boot_conn->chap.target_chap_name);
5829 case ISCSI_BOOT_TGT_CHAP_SECRET:
5830 rc = sprintf(str, "%.*s\n",
5831 boot_conn->chap.target_secret_length,
5832 (char *)&boot_conn->chap.target_secret);
5834 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5835 rc = sprintf(str, "%.*s\n",
5836 boot_conn->chap.intr_chap_name_length,
5837 (char *)&boot_conn->chap.intr_chap_name);
5839 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5840 rc = sprintf(str, "%.*s\n",
5841 boot_conn->chap.intr_secret_length,
5842 (char *)&boot_conn->chap.intr_secret);
5844 case ISCSI_BOOT_TGT_FLAGS:
5845 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5847 case ISCSI_BOOT_TGT_NIC_ASSOC:
5848 rc = sprintf(str, "0\n");
5857 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5859 struct scsi_qla_host *ha = data;
5860 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5862 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5865 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5867 struct scsi_qla_host *ha = data;
5868 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5870 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5873 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5878 case ISCSI_BOOT_TGT_NAME:
5879 case ISCSI_BOOT_TGT_IP_ADDR:
5880 case ISCSI_BOOT_TGT_PORT:
5881 case ISCSI_BOOT_TGT_CHAP_NAME:
5882 case ISCSI_BOOT_TGT_CHAP_SECRET:
5883 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5884 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5885 case ISCSI_BOOT_TGT_NIC_ASSOC:
5886 case ISCSI_BOOT_TGT_FLAGS:
5896 static void qla4xxx_boot_release(void *data)
5898 struct scsi_qla_host *ha = data;
5900 scsi_host_put(ha->host);
5903 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5906 uint32_t addr, pri_addr, sec_addr;
5910 uint8_t *buf = NULL;
5911 size_t size = 13 * sizeof(uint8_t);
5912 int ret = QLA_SUCCESS;
5914 func_num = PCI_FUNC(ha->pdev->devfn);
5916 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5917 __func__, ha->pdev->device, func_num);
5919 if (is_qla40XX(ha)) {
5920 if (func_num == 1) {
5921 addr = NVRAM_PORT0_BOOT_MODE;
5922 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5923 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5924 } else if (func_num == 3) {
5925 addr = NVRAM_PORT1_BOOT_MODE;
5926 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5927 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5930 goto exit_boot_info;
5933 /* Check Boot Mode */
5934 val = rd_nvram_byte(ha, addr);
5935 if (!(val & 0x07)) {
5936 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5937 "options : 0x%x\n", __func__, val));
5939 goto exit_boot_info;
5942 /* get primary valid target index */
5943 val = rd_nvram_byte(ha, pri_addr);
5945 ddb_index[0] = (val & 0x7f);
5947 /* get secondary valid target index */
5948 val = rd_nvram_byte(ha, sec_addr);
5950 ddb_index[1] = (val & 0x7f);
5951 goto exit_boot_info;
5952 } else if (is_qla80XX(ha)) {
5953 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5954 &buf_dma, GFP_KERNEL);
5956 DEBUG2(ql4_printk(KERN_ERR, ha,
5957 "%s: Unable to allocate dma buffer\n",
5960 goto exit_boot_info;
5963 if (ha->port_num == 0)
5964 offset = BOOT_PARAM_OFFSET_PORT0;
5965 else if (ha->port_num == 1)
5966 offset = BOOT_PARAM_OFFSET_PORT1;
5969 goto exit_boot_info_free;
5971 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5973 if (qla4xxx_get_flash(ha, buf_dma, addr,
5974 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5975 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5976 " failed\n", ha->host_no, __func__));
5978 goto exit_boot_info_free;
5980 /* Check Boot Mode */
5981 if (!(buf[1] & 0x07)) {
5982 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5983 " : 0x%x\n", buf[1]));
5985 goto exit_boot_info_free;
5988 /* get primary valid target index */
5990 ddb_index[0] = buf[2] & 0x7f;
5992 /* get secondary valid target index */
5993 if (buf[11] & BIT_7)
5994 ddb_index[1] = buf[11] & 0x7f;
5997 goto exit_boot_info;
6000 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
6001 " target ID %d\n", __func__, ddb_index[0],
6004 exit_boot_info_free:
6005 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
6007 ha->pri_ddb_idx = ddb_index[0];
6008 ha->sec_ddb_idx = ddb_index[1];
6013 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
6014 * @ha: pointer to adapter structure
6015 * @username: CHAP username to be returned
6016 * @password: CHAP password to be returned
6018 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6019 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6020 * So from the CHAP cache find the first BIDI CHAP entry and set it
6021 * to the boot record in sysfs.
6023 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6026 int i, ret = -EINVAL;
6027 int max_chap_entries = 0;
6028 struct ql4_chap_table *chap_table;
6031 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6032 sizeof(struct ql4_chap_table);
6034 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6036 if (!ha->chap_list) {
6037 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6041 mutex_lock(&ha->chap_sem);
6042 for (i = 0; i < max_chap_entries; i++) {
6043 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6044 if (chap_table->cookie !=
6045 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6049 if (chap_table->flags & BIT_7) /* local */
6052 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6055 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6056 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6060 mutex_unlock(&ha->chap_sem);
6066 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6067 struct ql4_boot_session_info *boot_sess,
6070 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6071 struct dev_db_entry *fw_ddb_entry;
6072 dma_addr_t fw_ddb_entry_dma;
6075 int ret = QLA_SUCCESS;
6077 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6078 &fw_ddb_entry_dma, GFP_KERNEL);
6079 if (!fw_ddb_entry) {
6080 DEBUG2(ql4_printk(KERN_ERR, ha,
6081 "%s: Unable to allocate dma buffer.\n",
6087 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6088 fw_ddb_entry_dma, ddb_index)) {
6089 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6090 "index [%d]\n", __func__, ddb_index));
6092 goto exit_boot_target;
6095 /* Update target name and IP from DDB */
6096 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6097 min(sizeof(boot_sess->target_name),
6098 sizeof(fw_ddb_entry->iscsi_name)));
6100 options = le16_to_cpu(fw_ddb_entry->options);
6101 if (options & DDB_OPT_IPV6_DEVICE) {
6102 memcpy(&boot_conn->dest_ipaddr.ip_address,
6103 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6105 boot_conn->dest_ipaddr.ip_type = 0x1;
6106 memcpy(&boot_conn->dest_ipaddr.ip_address,
6107 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6110 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6112 /* update chap information */
6113 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6115 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6117 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6119 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6121 (char *)&boot_conn->chap.target_secret,
6124 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6126 goto exit_boot_target;
6129 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6130 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6133 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6135 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6137 ret = qla4xxx_get_bidi_chap(ha,
6138 (char *)&boot_conn->chap.intr_chap_name,
6139 (char *)&boot_conn->chap.intr_secret);
6142 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6144 goto exit_boot_target;
6147 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6148 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6152 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6153 fw_ddb_entry, fw_ddb_entry_dma);
6157 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6159 uint16_t ddb_index[2];
6160 int ret = QLA_ERROR;
6163 memset(ddb_index, 0, sizeof(ddb_index));
6164 ddb_index[0] = 0xffff;
6165 ddb_index[1] = 0xffff;
6166 ret = get_fw_boot_info(ha, ddb_index);
6167 if (ret != QLA_SUCCESS) {
6168 DEBUG2(ql4_printk(KERN_INFO, ha,
6169 "%s: No boot target configured.\n", __func__));
6173 if (ql4xdisablesysfsboot)
6176 if (ddb_index[0] == 0xffff)
6179 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6181 if (rval != QLA_SUCCESS) {
6182 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6183 "configured\n", __func__));
6188 if (ddb_index[1] == 0xffff)
6189 goto exit_get_boot_info;
6191 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6193 if (rval != QLA_SUCCESS) {
6194 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6195 " configured\n", __func__));
6203 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6205 struct iscsi_boot_kobj *boot_kobj;
6207 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6210 if (ql4xdisablesysfsboot) {
6211 ql4_printk(KERN_INFO, ha,
6212 "%s: syfsboot disabled - driver will trigger login "
6213 "and publish session for discovery .\n", __func__);
6218 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6222 if (!scsi_host_get(ha->host))
6224 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6225 qla4xxx_show_boot_tgt_pri_info,
6226 qla4xxx_tgt_get_attr_visibility,
6227 qla4xxx_boot_release);
6231 if (!scsi_host_get(ha->host))
6233 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6234 qla4xxx_show_boot_tgt_sec_info,
6235 qla4xxx_tgt_get_attr_visibility,
6236 qla4xxx_boot_release);
6240 if (!scsi_host_get(ha->host))
6242 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6243 qla4xxx_show_boot_ini_info,
6244 qla4xxx_ini_get_attr_visibility,
6245 qla4xxx_boot_release);
6249 if (!scsi_host_get(ha->host))
6251 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6252 qla4xxx_show_boot_eth_info,
6253 qla4xxx_eth_get_attr_visibility,
6254 qla4xxx_boot_release);
6261 scsi_host_put(ha->host);
6263 iscsi_boot_destroy_kset(ha->boot_kset);
6268 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6269 struct ql4_tuple_ddb *tddb)
6271 struct scsi_qla_host *ha;
6272 struct iscsi_cls_session *cls_sess;
6273 struct iscsi_cls_conn *cls_conn;
6274 struct iscsi_session *sess;
6275 struct iscsi_conn *conn;
6277 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6279 cls_sess = ddb_entry->sess;
6280 sess = cls_sess->dd_data;
6281 cls_conn = ddb_entry->conn;
6282 conn = cls_conn->dd_data;
6284 tddb->tpgt = sess->tpgt;
6285 tddb->port = conn->persistent_port;
6286 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6287 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6290 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6291 struct ql4_tuple_ddb *tddb,
6292 uint8_t *flash_isid)
6294 uint16_t options = 0;
6296 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6297 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6298 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6300 options = le16_to_cpu(fw_ddb_entry->options);
6301 if (options & DDB_OPT_IPV6_DEVICE)
6302 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6304 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6306 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6308 if (flash_isid == NULL)
6309 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6310 sizeof(tddb->isid));
6312 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6315 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6316 struct ql4_tuple_ddb *old_tddb,
6317 struct ql4_tuple_ddb *new_tddb,
6318 uint8_t is_isid_compare)
6320 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6323 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6326 if (old_tddb->port != new_tddb->port)
6329 /* For multi sessions, driver generates the ISID, so do not compare
6330 * ISID in reset path since it would be a comparison between the
6331 * driver generated ISID and firmware generated ISID. This could
6332 * lead to adding duplicated DDBs in the list as driver generated
6333 * ISID would not match firmware generated ISID.
6335 if (is_isid_compare) {
6336 DEBUG2(ql4_printk(KERN_INFO, ha,
6337 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6338 __func__, old_tddb->isid, new_tddb->isid));
6340 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6341 sizeof(old_tddb->isid)))
6345 DEBUG2(ql4_printk(KERN_INFO, ha,
6346 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6347 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6348 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6349 new_tddb->ip_addr, new_tddb->iscsi_name));
6354 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6355 struct dev_db_entry *fw_ddb_entry,
6358 struct ddb_entry *ddb_entry;
6359 struct ql4_tuple_ddb *fw_tddb = NULL;
6360 struct ql4_tuple_ddb *tmp_tddb = NULL;
6362 int ret = QLA_ERROR;
6364 fw_tddb = vzalloc(sizeof(*fw_tddb));
6366 DEBUG2(ql4_printk(KERN_WARNING, ha,
6367 "Memory Allocation failed.\n"));
6372 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6374 DEBUG2(ql4_printk(KERN_WARNING, ha,
6375 "Memory Allocation failed.\n"));
6380 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6382 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6383 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6384 if (ddb_entry == NULL)
6387 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6388 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6389 ret = QLA_SUCCESS; /* found */
6405 * qla4xxx_check_existing_isid - check if target with same isid exist
6407 * @list_nt: list of target
6408 * @isid: isid to check
6410 * This routine return QLA_SUCCESS if target with same isid exist
6412 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6414 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6415 struct dev_db_entry *fw_ddb_entry;
6417 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6418 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6420 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6421 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6429 * qla4xxx_update_isid - compare ddbs and updated isid
6430 * @ha: Pointer to host adapter structure.
6431 * @list_nt: list of nt target
6432 * @fw_ddb_entry: firmware ddb entry
6434 * This routine update isid if ddbs have same iqn, same isid and
6435 * different IP addr.
6436 * Return QLA_SUCCESS if isid is updated.
6438 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6439 struct list_head *list_nt,
6440 struct dev_db_entry *fw_ddb_entry)
6442 uint8_t base_value, i;
6444 base_value = fw_ddb_entry->isid[1] & 0x1f;
6445 for (i = 0; i < 8; i++) {
6446 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6447 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6451 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6458 * qla4xxx_should_update_isid - check if isid need to update
6459 * @ha: Pointer to host adapter structure.
6460 * @old_tddb: ddb tuple
6461 * @new_tddb: ddb tuple
6463 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6466 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6467 struct ql4_tuple_ddb *old_tddb,
6468 struct ql4_tuple_ddb *new_tddb)
6470 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6472 if (old_tddb->port == new_tddb->port)
6476 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6480 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6481 sizeof(old_tddb->isid)))
6482 /* different isid */
6489 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6490 * @ha: Pointer to host adapter structure.
6491 * @list_nt: list of nt target.
6492 * @fw_ddb_entry: firmware ddb entry.
6494 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6495 * duplicate ddb in list_nt.
6496 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6497 * Note: This function also update isid of DDB if required.
6500 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6501 struct list_head *list_nt,
6502 struct dev_db_entry *fw_ddb_entry)
6504 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6505 struct ql4_tuple_ddb *fw_tddb = NULL;
6506 struct ql4_tuple_ddb *tmp_tddb = NULL;
6507 int rval, ret = QLA_ERROR;
6509 fw_tddb = vzalloc(sizeof(*fw_tddb));
6511 DEBUG2(ql4_printk(KERN_WARNING, ha,
6512 "Memory Allocation failed.\n"));
6517 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6519 DEBUG2(ql4_printk(KERN_WARNING, ha,
6520 "Memory Allocation failed.\n"));
6525 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6527 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6528 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6529 nt_ddb_idx->flash_isid);
6530 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6531 /* found duplicate ddb */
6532 if (ret == QLA_SUCCESS)
6536 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6537 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6539 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6540 if (ret == QLA_SUCCESS) {
6541 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6542 if (rval == QLA_SUCCESS)
6559 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6561 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6563 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6564 list_del_init(&ddb_idx->list);
6569 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6570 struct dev_db_entry *fw_ddb_entry)
6572 struct iscsi_endpoint *ep;
6573 struct sockaddr_in *addr;
6574 struct sockaddr_in6 *addr6;
6575 struct sockaddr *t_addr;
6576 struct sockaddr_storage *dst_addr;
6579 /* TODO: need to destroy on unload iscsi_endpoint*/
6580 dst_addr = vmalloc(sizeof(*dst_addr));
6584 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6585 t_addr = (struct sockaddr *)dst_addr;
6586 t_addr->sa_family = AF_INET6;
6587 addr6 = (struct sockaddr_in6 *)dst_addr;
6588 ip = (char *)&addr6->sin6_addr;
6589 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6590 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6593 t_addr = (struct sockaddr *)dst_addr;
6594 t_addr->sa_family = AF_INET;
6595 addr = (struct sockaddr_in *)dst_addr;
6596 ip = (char *)&addr->sin_addr;
6597 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6598 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6601 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6606 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6608 if (ql4xdisablesysfsboot)
6610 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6615 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6616 struct ddb_entry *ddb_entry,
6619 uint16_t def_timeout;
6621 ddb_entry->ddb_type = FLASH_DDB;
6622 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6623 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6625 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6626 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6627 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6629 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6630 atomic_set(&ddb_entry->relogin_timer, 0);
6631 atomic_set(&ddb_entry->relogin_retry_count, 0);
6632 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6633 ddb_entry->default_relogin_timeout =
6634 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6635 def_timeout : LOGIN_TOV;
6636 ddb_entry->default_time2wait =
6637 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6639 if (ql4xdisablesysfsboot &&
6640 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6641 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6644 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6647 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6648 uint32_t sts[MBOX_REG_COUNT];
6650 unsigned long wtime;
6653 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6655 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6656 if (ip_idx[idx] == -1)
6659 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6661 if (ret == QLA_ERROR) {
6666 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6668 DEBUG2(ql4_printk(KERN_INFO, ha,
6669 "Waiting for IP state for idx = %d, state = 0x%x\n",
6670 ip_idx[idx], ip_state));
6671 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6672 ip_state == IP_ADDRSTATE_INVALID ||
6673 ip_state == IP_ADDRSTATE_PREFERRED ||
6674 ip_state == IP_ADDRSTATE_DEPRICATED ||
6675 ip_state == IP_ADDRSTATE_DISABLING)
6679 /* Break if all IP states checked */
6680 if ((ip_idx[0] == -1) &&
6681 (ip_idx[1] == -1) &&
6682 (ip_idx[2] == -1) &&
6685 schedule_timeout_uninterruptible(HZ);
6686 } while (time_after(wtime, jiffies));
6689 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6690 struct dev_db_entry *flash_ddb_entry)
6692 uint16_t options = 0;
6693 size_t ip_len = IP_ADDR_LEN;
6695 options = le16_to_cpu(fw_ddb_entry->options);
6696 if (options & DDB_OPT_IPV6_DEVICE)
6697 ip_len = IPv6_ADDR_LEN;
6699 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6702 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6703 sizeof(fw_ddb_entry->isid)))
6706 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6707 sizeof(fw_ddb_entry->port)))
6713 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6714 struct dev_db_entry *fw_ddb_entry,
6715 uint32_t fw_idx, uint32_t *flash_index)
6717 struct dev_db_entry *flash_ddb_entry;
6718 dma_addr_t flash_ddb_entry_dma;
6721 int ret = QLA_ERROR, status;
6723 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6726 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6727 &flash_ddb_entry_dma);
6728 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6729 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6730 goto exit_find_st_idx;
6733 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6734 flash_ddb_entry_dma, fw_idx);
6735 if (status == QLA_SUCCESS) {
6736 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6737 if (status == QLA_SUCCESS) {
6738 *flash_index = fw_idx;
6740 goto exit_find_st_idx;
6744 for (idx = 0; idx < max_ddbs; idx++) {
6745 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6746 flash_ddb_entry_dma, idx);
6747 if (status == QLA_ERROR)
6750 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6751 if (status == QLA_SUCCESS) {
6754 goto exit_find_st_idx;
6758 if (idx == max_ddbs)
6759 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6763 if (flash_ddb_entry)
6764 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6765 flash_ddb_entry_dma);
6770 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6771 struct list_head *list_st)
6773 struct qla_ddb_index *st_ddb_idx;
6776 struct dev_db_entry *fw_ddb_entry;
6777 dma_addr_t fw_ddb_dma;
6779 uint32_t idx = 0, next_idx = 0;
6780 uint32_t state = 0, conn_err = 0;
6781 uint32_t flash_index = -1;
6782 uint16_t conn_id = 0;
6784 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6786 if (fw_ddb_entry == NULL) {
6787 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6791 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6793 fw_idx_size = sizeof(struct qla_ddb_index);
6795 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6796 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6797 NULL, &next_idx, &state,
6798 &conn_err, NULL, &conn_id);
6799 if (ret == QLA_ERROR)
6802 /* Ignore DDB if invalid state (unassigned) */
6803 if (state == DDB_DS_UNASSIGNED)
6804 goto continue_next_st;
6806 /* Check if ST, add to the list_st */
6807 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6808 goto continue_next_st;
6810 st_ddb_idx = vzalloc(fw_idx_size);
6814 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6816 if (ret == QLA_ERROR) {
6817 ql4_printk(KERN_ERR, ha,
6818 "No flash entry for ST at idx [%d]\n", idx);
6819 st_ddb_idx->flash_ddb_idx = idx;
6821 ql4_printk(KERN_INFO, ha,
6822 "ST at idx [%d] is stored at flash [%d]\n",
6824 st_ddb_idx->flash_ddb_idx = flash_index;
6827 st_ddb_idx->fw_ddb_idx = idx;
6829 list_add_tail(&st_ddb_idx->list, list_st);
6837 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6841 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6842 * @ha: pointer to adapter structure
6843 * @list_ddb: List from which failed ddb to be removed
6845 * Iterate over the list of DDBs and find and remove DDBs that are either in
6846 * no connection active state or failed state
6848 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6849 struct list_head *list_ddb)
6851 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6852 uint32_t next_idx = 0;
6853 uint32_t state = 0, conn_err = 0;
6856 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6857 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6858 NULL, 0, NULL, &next_idx, &state,
6859 &conn_err, NULL, NULL);
6860 if (ret == QLA_ERROR)
6863 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6864 state == DDB_DS_SESSION_FAILED) {
6865 list_del_init(&ddb_idx->list);
6871 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6872 struct ddb_entry *ddb_entry,
6873 struct dev_db_entry *fw_ddb_entry)
6875 struct iscsi_cls_session *cls_sess;
6876 struct iscsi_session *sess;
6877 uint32_t max_ddbs = 0;
6878 uint16_t ddb_link = -1;
6880 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6883 cls_sess = ddb_entry->sess;
6884 sess = cls_sess->dd_data;
6886 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6887 if (ddb_link < max_ddbs)
6888 sess->discovery_parent_idx = ddb_link;
6890 sess->discovery_parent_idx = DDB_NO_LINK;
6893 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6894 struct dev_db_entry *fw_ddb_entry,
6895 int is_reset, uint16_t idx)
6897 struct iscsi_cls_session *cls_sess;
6898 struct iscsi_session *sess;
6899 struct iscsi_cls_conn *cls_conn;
6900 struct iscsi_endpoint *ep;
6901 uint16_t cmds_max = 32;
6902 uint16_t conn_id = 0;
6903 uint32_t initial_cmdsn = 0;
6904 int ret = QLA_SUCCESS;
6906 struct ddb_entry *ddb_entry = NULL;
6908 /* Create session object, with INVALID_ENTRY,
6909 * the targer_id would get set when we issue the login
6911 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6912 cmds_max, sizeof(struct ddb_entry),
6913 sizeof(struct ql4_task_data),
6914 initial_cmdsn, INVALID_ENTRY);
6921 * so calling module_put function to decrement the
6924 module_put(qla4xxx_iscsi_transport.owner);
6925 sess = cls_sess->dd_data;
6926 ddb_entry = sess->dd_data;
6927 ddb_entry->sess = cls_sess;
6929 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6930 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6931 sizeof(struct dev_db_entry));
6933 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6935 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6942 ddb_entry->conn = cls_conn;
6944 /* Setup ep, for displaying attributes in sysfs */
6945 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6947 ep->conn = cls_conn;
6950 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6955 /* Update sess/conn params */
6956 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6957 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6959 if (is_reset == RESET_ADAPTER) {
6960 iscsi_block_session(cls_sess);
6961 /* Use the relogin path to discover new devices
6962 * by short-circuting the logic of setting
6963 * timer to relogin - instead set the flags
6964 * to initiate login right away.
6966 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6967 set_bit(DF_RELOGIN, &ddb_entry->flags);
6974 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6975 struct list_head *list_ddb,
6976 struct dev_db_entry *fw_ddb_entry)
6978 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6981 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6983 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6984 if (ddb_idx->fw_ddb_idx == ddb_link) {
6985 DEBUG2(ql4_printk(KERN_INFO, ha,
6986 "Updating NT parent idx from [%d] to [%d]\n",
6987 ddb_link, ddb_idx->flash_ddb_idx));
6988 fw_ddb_entry->ddb_link =
6989 cpu_to_le16(ddb_idx->flash_ddb_idx);
6995 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6996 struct list_head *list_nt,
6997 struct list_head *list_st,
7000 struct dev_db_entry *fw_ddb_entry;
7001 struct ddb_entry *ddb_entry = NULL;
7002 dma_addr_t fw_ddb_dma;
7006 uint32_t idx = 0, next_idx = 0;
7007 uint32_t state = 0, conn_err = 0;
7008 uint32_t ddb_idx = -1;
7009 uint16_t conn_id = 0;
7010 uint16_t ddb_link = -1;
7011 struct qla_ddb_index *nt_ddb_idx;
7013 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7015 if (fw_ddb_entry == NULL) {
7016 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7019 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7021 fw_idx_size = sizeof(struct qla_ddb_index);
7023 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7024 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7025 NULL, &next_idx, &state,
7026 &conn_err, NULL, &conn_id);
7027 if (ret == QLA_ERROR)
7030 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7031 goto continue_next_nt;
7033 /* Check if NT, then add to list it */
7034 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7035 goto continue_next_nt;
7037 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7038 if (ddb_link < max_ddbs)
7039 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7041 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7042 state == DDB_DS_SESSION_FAILED) &&
7043 (is_reset == INIT_ADAPTER))
7044 goto continue_next_nt;
7046 DEBUG2(ql4_printk(KERN_INFO, ha,
7047 "Adding DDB to session = 0x%x\n", idx));
7049 if (is_reset == INIT_ADAPTER) {
7050 nt_ddb_idx = vmalloc(fw_idx_size);
7054 nt_ddb_idx->fw_ddb_idx = idx;
7056 /* Copy original isid as it may get updated in function
7057 * qla4xxx_update_isid(). We need original isid in
7058 * function qla4xxx_compare_tuple_ddb to find duplicate
7060 memcpy(&nt_ddb_idx->flash_isid[0],
7061 &fw_ddb_entry->isid[0],
7062 sizeof(nt_ddb_idx->flash_isid));
7064 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7066 if (ret == QLA_SUCCESS) {
7067 /* free nt_ddb_idx and do not add to list_nt */
7069 goto continue_next_nt;
7072 /* Copy updated isid */
7073 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7074 sizeof(struct dev_db_entry));
7076 list_add_tail(&nt_ddb_idx->list, list_nt);
7077 } else if (is_reset == RESET_ADAPTER) {
7078 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7080 if (ret == QLA_SUCCESS) {
7081 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7083 if (ddb_entry != NULL)
7084 qla4xxx_update_sess_disc_idx(ha,
7087 goto continue_next_nt;
7091 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7092 if (ret == QLA_ERROR)
7102 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7105 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7106 struct list_head *list_nt,
7109 struct dev_db_entry *fw_ddb_entry;
7110 dma_addr_t fw_ddb_dma;
7114 uint32_t idx = 0, next_idx = 0;
7115 uint32_t state = 0, conn_err = 0;
7116 uint16_t conn_id = 0;
7117 struct qla_ddb_index *nt_ddb_idx;
7119 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7121 if (fw_ddb_entry == NULL) {
7122 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7123 goto exit_new_nt_list;
7125 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7127 fw_idx_size = sizeof(struct qla_ddb_index);
7129 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7130 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7131 NULL, &next_idx, &state,
7132 &conn_err, NULL, &conn_id);
7133 if (ret == QLA_ERROR)
7136 /* Check if NT, then add it to list */
7137 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7138 goto continue_next_new_nt;
7140 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7141 goto continue_next_new_nt;
7143 DEBUG2(ql4_printk(KERN_INFO, ha,
7144 "Adding DDB to session = 0x%x\n", idx));
7146 nt_ddb_idx = vmalloc(fw_idx_size);
7150 nt_ddb_idx->fw_ddb_idx = idx;
7152 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7153 if (ret == QLA_SUCCESS) {
7154 /* free nt_ddb_idx and do not add to list_nt */
7156 goto continue_next_new_nt;
7159 if (target_id < max_ddbs)
7160 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7162 list_add_tail(&nt_ddb_idx->list, list_nt);
7164 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7166 if (ret == QLA_ERROR)
7167 goto exit_new_nt_list;
7169 continue_next_new_nt:
7176 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7180 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7181 * @dev: dev associated with the sysfs entry
7182 * @data: pointer to flashnode session object
7185 * 1: if flashnode entry is non-persistent
7186 * 0: if flashnode entry is persistent
7188 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7190 struct iscsi_bus_flash_session *fnode_sess;
7192 if (!iscsi_flashnode_bus_match(dev, NULL))
7195 fnode_sess = iscsi_dev_to_flash_session(dev);
7197 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7201 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7202 * @ha: pointer to host
7203 * @fw_ddb_entry: flash ddb data
7204 * @idx: target index
7205 * @user: if set then this call is made from userland else from kernel
7208 * On sucess: QLA_SUCCESS
7209 * On failure: QLA_ERROR
7211 * This create separate sysfs entries for session and connection attributes of
7212 * the given fw ddb entry.
7213 * If this is invoked as a result of a userspace call then the entry is marked
7214 * as nonpersistent using flash_state field.
7216 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7217 struct dev_db_entry *fw_ddb_entry,
7218 uint16_t *idx, int user)
7220 struct iscsi_bus_flash_session *fnode_sess = NULL;
7221 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7224 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7225 &qla4xxx_iscsi_transport, 0);
7227 ql4_printk(KERN_ERR, ha,
7228 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7229 __func__, *idx, ha->host_no);
7230 goto exit_tgt_create;
7233 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7234 &qla4xxx_iscsi_transport, 0);
7236 ql4_printk(KERN_ERR, ha,
7237 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7238 __func__, *idx, ha->host_no);
7243 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7245 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7247 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7248 fnode_sess->is_boot_target = 1;
7250 fnode_sess->is_boot_target = 0;
7253 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7258 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7259 __func__, fnode_sess->dev.kobj.name);
7261 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7262 __func__, fnode_conn->dev.kobj.name);
7267 iscsi_destroy_flashnode_sess(fnode_sess);
7274 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7275 * @shost: pointer to host
7276 * @buf: type of ddb entry (ipv4/ipv6)
7277 * @len: length of buf
7279 * This creates new ddb entry in the flash by finding first free index and
7280 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7282 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7285 struct scsi_qla_host *ha = to_qla_host(shost);
7286 struct dev_db_entry *fw_ddb_entry = NULL;
7287 dma_addr_t fw_ddb_entry_dma;
7290 uint16_t max_ddbs = 0;
7291 uint32_t options = 0;
7292 uint32_t rval = QLA_ERROR;
7294 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7295 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7296 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7301 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7304 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7305 &fw_ddb_entry_dma, GFP_KERNEL);
7306 if (!fw_ddb_entry) {
7307 DEBUG2(ql4_printk(KERN_ERR, ha,
7308 "%s: Unable to allocate dma buffer\n",
7313 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7314 qla4xxx_sysfs_ddb_is_non_persistent);
7316 ql4_printk(KERN_ERR, ha,
7317 "%s: A non-persistent entry %s found\n",
7318 __func__, dev->kobj.name);
7323 /* Index 0 and 1 are reserved for boot target entries */
7324 for (idx = 2; idx < max_ddbs; idx++) {
7325 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7326 fw_ddb_entry_dma, idx))
7330 if (idx == max_ddbs)
7333 if (!strncasecmp("ipv6", buf, 4))
7334 options |= IPV6_DEFAULT_DDB_ENTRY;
7336 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7337 if (rval == QLA_ERROR)
7340 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7344 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7345 fw_ddb_entry, fw_ddb_entry_dma);
7346 if (rval == QLA_SUCCESS)
7353 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7354 * @fnode_sess: pointer to session attrs of flash ddb entry
7355 * @fnode_conn: pointer to connection attrs of flash ddb entry
7357 * This writes the contents of target ddb buffer to Flash with a valid cookie
7358 * value in order to make the ddb entry persistent.
7360 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7361 struct iscsi_bus_flash_conn *fnode_conn)
7363 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7364 struct scsi_qla_host *ha = to_qla_host(shost);
7365 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7366 struct dev_db_entry *fw_ddb_entry = NULL;
7367 dma_addr_t fw_ddb_entry_dma;
7368 uint32_t options = 0;
7371 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7372 &fw_ddb_entry_dma, GFP_KERNEL);
7373 if (!fw_ddb_entry) {
7374 DEBUG2(ql4_printk(KERN_ERR, ha,
7375 "%s: Unable to allocate dma buffer\n",
7378 goto exit_ddb_apply;
7381 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7382 options |= IPV6_DEFAULT_DDB_ENTRY;
7384 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7385 if (rval == QLA_ERROR)
7386 goto exit_ddb_apply;
7388 dev_db_start_offset += (fnode_sess->target_id *
7389 sizeof(*fw_ddb_entry));
7391 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7392 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7394 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7395 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7397 if (rval == QLA_SUCCESS) {
7398 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7399 ql4_printk(KERN_INFO, ha,
7400 "%s: flash node %u of host %lu written to flash\n",
7401 __func__, fnode_sess->target_id, ha->host_no);
7404 ql4_printk(KERN_ERR, ha,
7405 "%s: Error while writing flash node %u of host %lu to flash\n",
7406 __func__, fnode_sess->target_id, ha->host_no);
7411 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7412 fw_ddb_entry, fw_ddb_entry_dma);
7416 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7417 struct dev_db_entry *fw_ddb_entry,
7420 struct dev_db_entry *ddb_entry = NULL;
7421 dma_addr_t ddb_entry_dma;
7422 unsigned long wtime;
7423 uint32_t mbx_sts = 0;
7424 uint32_t state = 0, conn_err = 0;
7428 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7429 &ddb_entry_dma, GFP_KERNEL);
7431 DEBUG2(ql4_printk(KERN_ERR, ha,
7432 "%s: Unable to allocate dma buffer\n",
7437 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7439 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7440 if (ret != QLA_SUCCESS) {
7441 DEBUG2(ql4_printk(KERN_ERR, ha,
7442 "%s: Unable to set ddb entry for index %d\n",
7444 goto exit_ddb_conn_open;
7447 qla4xxx_conn_open(ha, idx);
7449 /* To ensure that sendtargets is done, wait for at least 12 secs */
7450 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7451 (ha->def_timeout < LOGIN_TOV * 10) ?
7452 ha->def_timeout : LOGIN_TOV);
7454 DEBUG2(ql4_printk(KERN_INFO, ha,
7455 "Default time to wait for login to ddb %d\n", tmo));
7457 wtime = jiffies + (HZ * tmo);
7459 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7460 NULL, &state, &conn_err, NULL,
7462 if (ret == QLA_ERROR)
7465 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7466 state == DDB_DS_SESSION_FAILED)
7469 schedule_timeout_uninterruptible(HZ / 10);
7470 } while (time_after(wtime, jiffies));
7474 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7475 ddb_entry, ddb_entry_dma);
7479 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7480 struct dev_db_entry *fw_ddb_entry,
7483 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7484 struct list_head list_nt;
7488 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7489 ql4_printk(KERN_WARNING, ha,
7490 "%s: A discovery already in progress!\n", __func__);
7494 INIT_LIST_HEAD(&list_nt);
7496 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7498 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7499 if (ret == QLA_ERROR)
7500 goto exit_login_st_clr_bit;
7502 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7503 if (ret == QLA_ERROR)
7506 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7508 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7509 list_del_init(&ddb_idx->list);
7510 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7515 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7516 ql4_printk(KERN_ERR, ha,
7517 "Unable to clear DDB index = 0x%x\n", ddb_index);
7520 clear_bit(ddb_index, ha->ddb_idx_map);
7522 exit_login_st_clr_bit:
7523 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7527 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7528 struct dev_db_entry *fw_ddb_entry,
7531 int ret = QLA_ERROR;
7533 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7534 if (ret != QLA_SUCCESS)
7535 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7544 * qla4xxx_sysfs_ddb_login - Login to the specified target
7545 * @fnode_sess: pointer to session attrs of flash ddb entry
7546 * @fnode_conn: pointer to connection attrs of flash ddb entry
7548 * This logs in to the specified target
7550 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7551 struct iscsi_bus_flash_conn *fnode_conn)
7553 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7554 struct scsi_qla_host *ha = to_qla_host(shost);
7555 struct dev_db_entry *fw_ddb_entry = NULL;
7556 dma_addr_t fw_ddb_entry_dma;
7557 uint32_t options = 0;
7560 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7561 ql4_printk(KERN_ERR, ha,
7562 "%s: Target info is not persistent\n", __func__);
7564 goto exit_ddb_login;
7567 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7568 &fw_ddb_entry_dma, GFP_KERNEL);
7569 if (!fw_ddb_entry) {
7570 DEBUG2(ql4_printk(KERN_ERR, ha,
7571 "%s: Unable to allocate dma buffer\n",
7574 goto exit_ddb_login;
7577 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7578 options |= IPV6_DEFAULT_DDB_ENTRY;
7580 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7581 if (ret == QLA_ERROR)
7582 goto exit_ddb_login;
7584 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7585 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7587 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7588 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7589 fnode_sess->target_id);
7591 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7592 fnode_sess->target_id);
7599 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7600 fw_ddb_entry, fw_ddb_entry_dma);
7605 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7606 * @cls_sess: pointer to session to be logged out
7608 * This performs session log out from the specified target
7610 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7612 struct iscsi_session *sess;
7613 struct ddb_entry *ddb_entry = NULL;
7614 struct scsi_qla_host *ha;
7615 struct dev_db_entry *fw_ddb_entry = NULL;
7616 dma_addr_t fw_ddb_entry_dma;
7617 unsigned long flags;
7618 unsigned long wtime;
7623 sess = cls_sess->dd_data;
7624 ddb_entry = sess->dd_data;
7627 if (ddb_entry->ddb_type != FLASH_DDB) {
7628 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7631 goto exit_ddb_logout;
7634 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7635 ql4_printk(KERN_ERR, ha,
7636 "%s: Logout from boot target entry is not permitted.\n",
7639 goto exit_ddb_logout;
7642 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7643 &fw_ddb_entry_dma, GFP_KERNEL);
7644 if (!fw_ddb_entry) {
7645 ql4_printk(KERN_ERR, ha,
7646 "%s: Unable to allocate dma buffer\n", __func__);
7648 goto exit_ddb_logout;
7651 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7652 goto ddb_logout_init;
7654 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7655 fw_ddb_entry, fw_ddb_entry_dma,
7656 NULL, NULL, &ddb_state, NULL,
7658 if (ret == QLA_ERROR)
7659 goto ddb_logout_init;
7661 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7662 goto ddb_logout_init;
7664 /* wait until next relogin is triggered using DF_RELOGIN and
7665 * clear DF_RELOGIN to avoid invocation of further relogin
7667 wtime = jiffies + (HZ * RELOGIN_TOV);
7669 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7670 goto ddb_logout_init;
7672 schedule_timeout_uninterruptible(HZ);
7673 } while ((time_after(wtime, jiffies)));
7676 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7677 atomic_set(&ddb_entry->relogin_timer, 0);
7679 options = LOGOUT_OPTION_CLOSE_SESSION;
7680 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7682 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7683 wtime = jiffies + (HZ * LOGOUT_TOV);
7685 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7686 fw_ddb_entry, fw_ddb_entry_dma,
7687 NULL, NULL, &ddb_state, NULL,
7689 if (ret == QLA_ERROR)
7690 goto ddb_logout_clr_sess;
7692 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7693 (ddb_state == DDB_DS_SESSION_FAILED))
7694 goto ddb_logout_clr_sess;
7696 schedule_timeout_uninterruptible(HZ);
7697 } while ((time_after(wtime, jiffies)));
7699 ddb_logout_clr_sess:
7700 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7702 * we have decremented the reference count of the driver
7703 * when we setup the session to have the driver unload
7704 * to be seamless without actually destroying the
7707 try_module_get(qla4xxx_iscsi_transport.owner);
7708 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7710 spin_lock_irqsave(&ha->hardware_lock, flags);
7711 qla4xxx_free_ddb(ha, ddb_entry);
7712 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7715 iscsi_session_teardown(ddb_entry->sess);
7717 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7722 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7723 fw_ddb_entry, fw_ddb_entry_dma);
7728 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7729 * @fnode_sess: pointer to session attrs of flash ddb entry
7730 * @fnode_conn: pointer to connection attrs of flash ddb entry
7732 * This performs log out from the specified target
7734 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7735 struct iscsi_bus_flash_conn *fnode_conn)
7737 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7738 struct scsi_qla_host *ha = to_qla_host(shost);
7739 struct ql4_tuple_ddb *flash_tddb = NULL;
7740 struct ql4_tuple_ddb *tmp_tddb = NULL;
7741 struct dev_db_entry *fw_ddb_entry = NULL;
7742 struct ddb_entry *ddb_entry = NULL;
7743 dma_addr_t fw_ddb_dma;
7744 uint32_t next_idx = 0;
7745 uint32_t state = 0, conn_err = 0;
7746 uint16_t conn_id = 0;
7748 int status, ret = 0;
7750 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7752 if (fw_ddb_entry == NULL) {
7753 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7755 goto exit_ddb_logout;
7758 flash_tddb = vzalloc(sizeof(*flash_tddb));
7760 ql4_printk(KERN_WARNING, ha,
7761 "%s:Memory Allocation failed.\n", __func__);
7763 goto exit_ddb_logout;
7766 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7768 ql4_printk(KERN_WARNING, ha,
7769 "%s:Memory Allocation failed.\n", __func__);
7771 goto exit_ddb_logout;
7774 if (!fnode_sess->targetname) {
7775 ql4_printk(KERN_ERR, ha,
7776 "%s:Cannot logout from SendTarget entry\n",
7779 goto exit_ddb_logout;
7782 if (fnode_sess->is_boot_target) {
7783 ql4_printk(KERN_ERR, ha,
7784 "%s: Logout from boot target entry is not permitted.\n",
7787 goto exit_ddb_logout;
7790 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7793 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7794 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7796 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7798 flash_tddb->tpgt = fnode_sess->tpgt;
7799 flash_tddb->port = fnode_conn->port;
7801 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7803 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7804 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7805 if (ddb_entry == NULL)
7808 if (ddb_entry->ddb_type != FLASH_DDB)
7811 index = ddb_entry->sess->target_id;
7812 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7813 fw_ddb_dma, NULL, &next_idx,
7814 &state, &conn_err, NULL,
7816 if (status == QLA_ERROR) {
7821 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7823 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7825 if (status == QLA_SUCCESS) {
7826 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7831 if (idx == MAX_DDB_ENTRIES)
7840 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7846 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7847 int param, char *buf)
7849 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7850 struct scsi_qla_host *ha = to_qla_host(shost);
7851 struct iscsi_bus_flash_conn *fnode_conn;
7852 struct ql4_chap_table chap_tbl;
7857 dev = iscsi_find_flashnode_conn(fnode_sess);
7861 fnode_conn = iscsi_dev_to_flash_conn(dev);
7864 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7865 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7867 case ISCSI_FLASHNODE_PORTAL_TYPE:
7868 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7870 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7871 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7873 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7874 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7876 case ISCSI_FLASHNODE_ENTRY_EN:
7877 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7879 case ISCSI_FLASHNODE_HDR_DGST_EN:
7880 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7882 case ISCSI_FLASHNODE_DATA_DGST_EN:
7883 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7885 case ISCSI_FLASHNODE_IMM_DATA_EN:
7886 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7888 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7889 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7891 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7892 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7894 case ISCSI_FLASHNODE_PDU_INORDER:
7895 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7897 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7898 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7900 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7901 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7903 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7904 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7906 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7907 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7909 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7910 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7912 case ISCSI_FLASHNODE_ERL:
7913 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7915 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7916 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7918 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7919 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7921 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7922 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7924 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7925 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7927 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7928 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7930 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7931 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7933 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7934 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7936 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7937 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7939 case ISCSI_FLASHNODE_FIRST_BURST:
7940 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7942 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7943 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7945 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7946 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7948 case ISCSI_FLASHNODE_MAX_R2T:
7949 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7951 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7952 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7954 case ISCSI_FLASHNODE_ISID:
7955 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7957 case ISCSI_FLASHNODE_TSID:
7958 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7960 case ISCSI_FLASHNODE_PORT:
7961 rc = sprintf(buf, "%d\n", fnode_conn->port);
7963 case ISCSI_FLASHNODE_MAX_BURST:
7964 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7966 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7967 rc = sprintf(buf, "%u\n",
7968 fnode_sess->default_taskmgmt_timeout);
7970 case ISCSI_FLASHNODE_IPADDR:
7971 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7972 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7974 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7976 case ISCSI_FLASHNODE_ALIAS:
7977 if (fnode_sess->targetalias)
7978 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7980 rc = sprintf(buf, "\n");
7982 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7983 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7984 rc = sprintf(buf, "%pI6\n",
7985 fnode_conn->redirect_ipaddr);
7987 rc = sprintf(buf, "%pI4\n",
7988 fnode_conn->redirect_ipaddr);
7990 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7991 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7993 case ISCSI_FLASHNODE_LOCAL_PORT:
7994 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7996 case ISCSI_FLASHNODE_IPV4_TOS:
7997 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7999 case ISCSI_FLASHNODE_IPV6_TC:
8000 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8001 rc = sprintf(buf, "%u\n",
8002 fnode_conn->ipv6_traffic_class);
8004 rc = sprintf(buf, "\n");
8006 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8007 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8009 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8010 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8011 rc = sprintf(buf, "%pI6\n",
8012 fnode_conn->link_local_ipv6_addr);
8014 rc = sprintf(buf, "\n");
8016 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8017 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8019 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8020 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8021 parent_type = ISCSI_DISC_PARENT_ISNS;
8022 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8023 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8024 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8025 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8027 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8029 rc = sprintf(buf, "%s\n",
8030 iscsi_get_discovery_parent_name(parent_type));
8032 case ISCSI_FLASHNODE_NAME:
8033 if (fnode_sess->targetname)
8034 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8036 rc = sprintf(buf, "\n");
8038 case ISCSI_FLASHNODE_TPGT:
8039 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8041 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8042 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8044 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8045 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8047 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8048 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8050 case ISCSI_FLASHNODE_USERNAME:
8051 if (fnode_sess->chap_auth_en) {
8052 qla4xxx_get_uni_chap_at_index(ha,
8055 fnode_sess->chap_out_idx);
8056 rc = sprintf(buf, "%s\n", chap_tbl.name);
8058 rc = sprintf(buf, "\n");
8061 case ISCSI_FLASHNODE_PASSWORD:
8062 if (fnode_sess->chap_auth_en) {
8063 qla4xxx_get_uni_chap_at_index(ha,
8066 fnode_sess->chap_out_idx);
8067 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8069 rc = sprintf(buf, "\n");
8072 case ISCSI_FLASHNODE_STATSN:
8073 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8075 case ISCSI_FLASHNODE_EXP_STATSN:
8076 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8078 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8079 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8091 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8092 * @fnode_sess: pointer to session attrs of flash ddb entry
8093 * @fnode_conn: pointer to connection attrs of flash ddb entry
8094 * @data: Parameters and their values to update
8097 * This sets the parameter of flash ddb entry and writes them to flash
8100 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8101 struct iscsi_bus_flash_conn *fnode_conn,
8102 void *data, int len)
8104 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8105 struct scsi_qla_host *ha = to_qla_host(shost);
8106 struct iscsi_flashnode_param_info *fnode_param;
8107 struct ql4_chap_table chap_tbl;
8108 struct nlattr *attr;
8109 uint16_t chap_out_idx = INVALID_ENTRY;
8113 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8114 nla_for_each_attr(attr, data, len, rem) {
8115 if (nla_len(attr) < sizeof(*fnode_param)) {
8117 goto exit_set_param;
8120 fnode_param = nla_data(attr);
8122 switch (fnode_param->param) {
8123 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8124 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8126 case ISCSI_FLASHNODE_PORTAL_TYPE:
8127 memcpy(fnode_sess->portal_type, fnode_param->value,
8128 strlen(fnode_sess->portal_type));
8130 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8131 fnode_sess->auto_snd_tgt_disable =
8132 fnode_param->value[0];
8134 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8135 fnode_sess->discovery_sess = fnode_param->value[0];
8137 case ISCSI_FLASHNODE_ENTRY_EN:
8138 fnode_sess->entry_state = fnode_param->value[0];
8140 case ISCSI_FLASHNODE_HDR_DGST_EN:
8141 fnode_conn->hdrdgst_en = fnode_param->value[0];
8143 case ISCSI_FLASHNODE_DATA_DGST_EN:
8144 fnode_conn->datadgst_en = fnode_param->value[0];
8146 case ISCSI_FLASHNODE_IMM_DATA_EN:
8147 fnode_sess->imm_data_en = fnode_param->value[0];
8149 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8150 fnode_sess->initial_r2t_en = fnode_param->value[0];
8152 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8153 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8155 case ISCSI_FLASHNODE_PDU_INORDER:
8156 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8158 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8159 fnode_sess->chap_auth_en = fnode_param->value[0];
8160 /* Invalidate chap index if chap auth is disabled */
8161 if (!fnode_sess->chap_auth_en)
8162 fnode_sess->chap_out_idx = INVALID_ENTRY;
8165 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8166 fnode_conn->snack_req_en = fnode_param->value[0];
8168 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8169 fnode_sess->discovery_logout_en = fnode_param->value[0];
8171 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8172 fnode_sess->bidi_chap_en = fnode_param->value[0];
8174 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8175 fnode_sess->discovery_auth_optional =
8176 fnode_param->value[0];
8178 case ISCSI_FLASHNODE_ERL:
8179 fnode_sess->erl = fnode_param->value[0];
8181 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8182 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8184 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8185 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8187 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8188 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8190 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8191 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8193 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8194 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8196 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8197 fnode_conn->fragment_disable = fnode_param->value[0];
8199 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8200 fnode_conn->max_recv_dlength =
8201 *(unsigned *)fnode_param->value;
8203 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8204 fnode_conn->max_xmit_dlength =
8205 *(unsigned *)fnode_param->value;
8207 case ISCSI_FLASHNODE_FIRST_BURST:
8208 fnode_sess->first_burst =
8209 *(unsigned *)fnode_param->value;
8211 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8212 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8214 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8215 fnode_sess->time2retain =
8216 *(uint16_t *)fnode_param->value;
8218 case ISCSI_FLASHNODE_MAX_R2T:
8219 fnode_sess->max_r2t =
8220 *(uint16_t *)fnode_param->value;
8222 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8223 fnode_conn->keepalive_timeout =
8224 *(uint16_t *)fnode_param->value;
8226 case ISCSI_FLASHNODE_ISID:
8227 memcpy(fnode_sess->isid, fnode_param->value,
8228 sizeof(fnode_sess->isid));
8230 case ISCSI_FLASHNODE_TSID:
8231 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8233 case ISCSI_FLASHNODE_PORT:
8234 fnode_conn->port = *(uint16_t *)fnode_param->value;
8236 case ISCSI_FLASHNODE_MAX_BURST:
8237 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8239 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8240 fnode_sess->default_taskmgmt_timeout =
8241 *(uint16_t *)fnode_param->value;
8243 case ISCSI_FLASHNODE_IPADDR:
8244 memcpy(fnode_conn->ipaddress, fnode_param->value,
8247 case ISCSI_FLASHNODE_ALIAS:
8248 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8249 (char *)fnode_param->value);
8251 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8252 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8255 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8256 fnode_conn->max_segment_size =
8257 *(unsigned *)fnode_param->value;
8259 case ISCSI_FLASHNODE_LOCAL_PORT:
8260 fnode_conn->local_port =
8261 *(uint16_t *)fnode_param->value;
8263 case ISCSI_FLASHNODE_IPV4_TOS:
8264 fnode_conn->ipv4_tos = fnode_param->value[0];
8266 case ISCSI_FLASHNODE_IPV6_TC:
8267 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8269 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8270 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8272 case ISCSI_FLASHNODE_NAME:
8273 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8274 (char *)fnode_param->value);
8276 case ISCSI_FLASHNODE_TPGT:
8277 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8279 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8280 memcpy(fnode_conn->link_local_ipv6_addr,
8281 fnode_param->value, IPv6_ADDR_LEN);
8283 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8284 fnode_sess->discovery_parent_idx =
8285 *(uint16_t *)fnode_param->value;
8287 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8288 fnode_conn->tcp_xmit_wsf =
8289 *(uint8_t *)fnode_param->value;
8291 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8292 fnode_conn->tcp_recv_wsf =
8293 *(uint8_t *)fnode_param->value;
8295 case ISCSI_FLASHNODE_STATSN:
8296 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8298 case ISCSI_FLASHNODE_EXP_STATSN:
8299 fnode_conn->exp_statsn =
8300 *(uint32_t *)fnode_param->value;
8302 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8303 chap_out_idx = *(uint16_t *)fnode_param->value;
8304 if (!qla4xxx_get_uni_chap_at_index(ha,
8308 fnode_sess->chap_out_idx = chap_out_idx;
8309 /* Enable chap auth if chap index is valid */
8310 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8314 ql4_printk(KERN_ERR, ha,
8315 "%s: No such sysfs attribute\n", __func__);
8317 goto exit_set_param;
8321 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8328 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8329 * @fnode_sess: pointer to session attrs of flash ddb entry
8331 * This invalidates the flash ddb entry at the given index
8333 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8335 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8336 struct scsi_qla_host *ha = to_qla_host(shost);
8337 uint32_t dev_db_start_offset;
8338 uint32_t dev_db_end_offset;
8339 struct dev_db_entry *fw_ddb_entry = NULL;
8340 dma_addr_t fw_ddb_entry_dma;
8341 uint16_t *ddb_cookie = NULL;
8342 size_t ddb_size = 0;
8347 if (fnode_sess->is_boot_target) {
8349 DEBUG2(ql4_printk(KERN_ERR, ha,
8350 "%s: Deletion of boot target entry is not permitted.\n",
8355 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8358 if (is_qla40XX(ha)) {
8359 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8360 dev_db_end_offset = FLASH_OFFSET_DB_END;
8361 dev_db_start_offset += (fnode_sess->target_id *
8362 sizeof(*fw_ddb_entry));
8363 ddb_size = sizeof(*fw_ddb_entry);
8365 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8366 (ha->hw.flt_region_ddb << 2);
8367 /* flt_ddb_size is DDB table size for both ports
8368 * so divide it by 2 to calculate the offset for second port
8370 if (ha->port_num == 1)
8371 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8373 dev_db_end_offset = dev_db_start_offset +
8374 (ha->hw.flt_ddb_size / 2);
8376 dev_db_start_offset += (fnode_sess->target_id *
8377 sizeof(*fw_ddb_entry));
8378 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8380 ddb_size = sizeof(*ddb_cookie);
8383 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8384 __func__, dev_db_start_offset, dev_db_end_offset));
8386 if (dev_db_start_offset > dev_db_end_offset) {
8388 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8389 __func__, fnode_sess->target_id));
8393 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8394 &fw_ddb_entry_dma, GFP_KERNEL);
8397 DEBUG2(ql4_printk(KERN_ERR, ha,
8398 "%s: Unable to allocate dma buffer\n",
8403 if (is_qla40XX(ha)) {
8404 fw_ddb_entry = pddb;
8405 memset(fw_ddb_entry, 0, ddb_size);
8406 ddb_cookie = &fw_ddb_entry->cookie;
8411 /* invalidate the cookie */
8412 *ddb_cookie = 0xFFEE;
8413 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8414 ddb_size, FLASH_OPT_RMW_COMMIT);
8417 target_id = fnode_sess->target_id;
8418 iscsi_destroy_flashnode_sess(fnode_sess);
8419 ql4_printk(KERN_INFO, ha,
8420 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8421 __func__, target_id, ha->host_no);
8424 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8430 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8431 * @ha: pointer to adapter structure
8433 * Export the firmware DDB for all send targets and normal targets to sysfs.
8435 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8437 struct dev_db_entry *fw_ddb_entry = NULL;
8438 dma_addr_t fw_ddb_entry_dma;
8441 int ret = QLA_SUCCESS;
8443 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8444 sizeof(*fw_ddb_entry),
8445 &fw_ddb_entry_dma, GFP_KERNEL);
8446 if (!fw_ddb_entry) {
8447 DEBUG2(ql4_printk(KERN_ERR, ha,
8448 "%s: Unable to allocate dma buffer\n",
8453 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8456 for (idx = 0; idx < max_ddbs; idx++) {
8457 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8461 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8468 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8474 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8476 iscsi_destroy_all_flashnode(ha->host);
8480 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8481 * @ha: pointer to adapter structure
8482 * @is_reset: Is this init path or reset path
8484 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8485 * using connection open, then create the list of normal targets (nt)
8486 * from firmware DDBs. Based on the list of nt setup session and connection
8489 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8492 struct list_head list_st, list_nt;
8493 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8494 unsigned long wtime;
8496 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8497 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8498 ha->is_reset = is_reset;
8502 INIT_LIST_HEAD(&list_st);
8503 INIT_LIST_HEAD(&list_nt);
8505 qla4xxx_build_st_list(ha, &list_st);
8507 /* Before issuing conn open mbox, ensure all IPs states are configured
8508 * Note, conn open fails if IPs are not configured
8510 qla4xxx_wait_for_ip_configuration(ha);
8512 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8513 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8514 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8517 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8518 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8519 (ha->def_timeout < LOGIN_TOV * 10) ?
8520 ha->def_timeout : LOGIN_TOV);
8522 DEBUG2(ql4_printk(KERN_INFO, ha,
8523 "Default time to wait for build ddb %d\n", tmo));
8525 wtime = jiffies + (HZ * tmo);
8527 if (list_empty(&list_st))
8530 qla4xxx_remove_failed_ddb(ha, &list_st);
8531 schedule_timeout_uninterruptible(HZ / 10);
8532 } while (time_after(wtime, jiffies));
8535 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8537 qla4xxx_free_ddb_list(&list_st);
8538 qla4xxx_free_ddb_list(&list_nt);
8540 qla4xxx_free_ddb_index(ha);
8544 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8546 * @ha: pointer to adapter structure
8548 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8549 * set in DDB and we will wait for login response of boot targets during
8552 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8554 struct ddb_entry *ddb_entry;
8555 struct dev_db_entry *fw_ddb_entry = NULL;
8556 dma_addr_t fw_ddb_entry_dma;
8557 unsigned long wtime;
8559 int max_ddbs, idx, ret;
8561 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8564 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8565 &fw_ddb_entry_dma, GFP_KERNEL);
8566 if (!fw_ddb_entry) {
8567 ql4_printk(KERN_ERR, ha,
8568 "%s: Unable to allocate dma buffer\n", __func__);
8569 goto exit_login_resp;
8572 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8574 for (idx = 0; idx < max_ddbs; idx++) {
8575 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8576 if (ddb_entry == NULL)
8579 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8580 DEBUG2(ql4_printk(KERN_INFO, ha,
8581 "%s: DDB index [%d]\n", __func__,
8582 ddb_entry->fw_ddb_index));
8584 ret = qla4xxx_get_fwddb_entry(ha,
8585 ddb_entry->fw_ddb_index,
8586 fw_ddb_entry, fw_ddb_entry_dma,
8587 NULL, NULL, &ddb_state, NULL,
8589 if (ret == QLA_ERROR)
8590 goto exit_login_resp;
8592 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8593 (ddb_state == DDB_DS_SESSION_FAILED))
8596 schedule_timeout_uninterruptible(HZ);
8598 } while ((time_after(wtime, jiffies)));
8600 if (!time_after(wtime, jiffies)) {
8601 DEBUG2(ql4_printk(KERN_INFO, ha,
8602 "%s: Login response wait timer expired\n",
8604 goto exit_login_resp;
8611 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8612 fw_ddb_entry, fw_ddb_entry_dma);
8616 * qla4xxx_probe_adapter - callback function to probe HBA
8617 * @pdev: pointer to pci_dev structure
8618 * @pci_device_id: pointer to pci_device entry
8620 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8621 * It returns zero if successful. It also initializes all data necessary for
8624 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8625 const struct pci_device_id *ent)
8627 int ret = -ENODEV, status;
8628 struct Scsi_Host *host;
8629 struct scsi_qla_host *ha;
8630 uint8_t init_retry_count = 0;
8632 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8635 if (pci_enable_device(pdev))
8638 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8641 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8642 goto probe_disable_device;
8645 /* Clear our data area */
8646 ha = to_qla_host(host);
8647 memset(ha, 0, sizeof(*ha));
8649 /* Save the information from PCI BIOS. */
8652 ha->host_no = host->host_no;
8653 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8655 pci_enable_pcie_error_reporting(pdev);
8657 /* Setup Runtime configurable options */
8658 if (is_qla8022(ha)) {
8659 ha->isp_ops = &qla4_82xx_isp_ops;
8660 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8661 ha->qdr_sn_window = -1;
8662 ha->ddr_mn_window = -1;
8663 ha->curr_window = 255;
8664 nx_legacy_intr = &legacy_intr[ha->func_num];
8665 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8666 ha->nx_legacy_intr.tgt_status_reg =
8667 nx_legacy_intr->tgt_status_reg;
8668 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8669 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8670 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8671 ha->isp_ops = &qla4_83xx_isp_ops;
8672 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8674 ha->isp_ops = &qla4xxx_isp_ops;
8677 if (is_qla80XX(ha)) {
8678 rwlock_init(&ha->hw_lock);
8679 ha->pf_bit = ha->func_num << 16;
8680 /* Set EEH reset type to fundamental if required by hba */
8681 pdev->needs_freset = 1;
8684 /* Configure PCI I/O space. */
8685 ret = ha->isp_ops->iospace_config(ha);
8687 goto probe_failed_ioconfig;
8689 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8690 pdev->device, pdev->irq, ha->reg);
8692 qla4xxx_config_dma_addressing(ha);
8694 /* Initialize lists and spinlocks. */
8695 INIT_LIST_HEAD(&ha->free_srb_q);
8697 mutex_init(&ha->mbox_sem);
8698 mutex_init(&ha->chap_sem);
8699 init_completion(&ha->mbx_intr_comp);
8700 init_completion(&ha->disable_acb_comp);
8701 init_completion(&ha->idc_comp);
8702 init_completion(&ha->link_up_comp);
8704 spin_lock_init(&ha->hardware_lock);
8705 spin_lock_init(&ha->work_lock);
8707 /* Initialize work list */
8708 INIT_LIST_HEAD(&ha->work_list);
8710 /* Allocate dma buffers */
8711 if (qla4xxx_mem_alloc(ha)) {
8712 ql4_printk(KERN_WARNING, ha,
8713 "[ERROR] Failed to allocate memory for adapter\n");
8719 host->cmd_per_lun = 3;
8720 host->max_channel = 0;
8721 host->max_lun = MAX_LUNS - 1;
8722 host->max_id = MAX_TARGETS;
8723 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8724 host->can_queue = MAX_SRBS ;
8725 host->transportt = qla4xxx_scsi_transport;
8727 pci_set_drvdata(pdev, ha);
8729 ret = scsi_add_host(host, &pdev->dev);
8734 qla4_8xxx_get_flash_info(ha);
8736 if (is_qla8032(ha) || is_qla8042(ha)) {
8737 qla4_83xx_read_reset_template(ha);
8739 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8740 * If DONRESET_BIT0 is set, drivers should not set dev_state
8741 * to NEED_RESET. But if NEED_RESET is set, drivers should
8742 * should honor the reset.
8744 if (ql4xdontresethba == 1)
8745 qla4_83xx_set_idc_dontreset(ha);
8749 * Initialize the Host adapter request/response queues and
8751 * NOTE: interrupts enabled upon successful completion
8753 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8755 /* Dont retry adapter initialization if IRQ allocation failed */
8756 if (is_qla80XX(ha) && (status == QLA_ERROR))
8757 goto skip_retry_init;
8759 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8760 init_retry_count++ < MAX_INIT_RETRIES) {
8762 if (is_qla80XX(ha)) {
8763 ha->isp_ops->idc_lock(ha);
8764 dev_state = qla4_8xxx_rd_direct(ha,
8765 QLA8XXX_CRB_DEV_STATE);
8766 ha->isp_ops->idc_unlock(ha);
8767 if (dev_state == QLA8XXX_DEV_FAILED) {
8768 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8769 "initialize adapter. H/W is in failed state\n",
8774 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8775 "(%d)\n", __func__, init_retry_count));
8777 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8780 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8781 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8782 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8783 goto skip_retry_init;
8788 if (!test_bit(AF_ONLINE, &ha->flags)) {
8789 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8791 if ((is_qla8022(ha) && ql4xdontresethba) ||
8792 ((is_qla8032(ha) || is_qla8042(ha)) &&
8793 qla4_83xx_idc_dontreset(ha))) {
8794 /* Put the device in failed state. */
8795 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8796 ha->isp_ops->idc_lock(ha);
8797 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8798 QLA8XXX_DEV_FAILED);
8799 ha->isp_ops->idc_unlock(ha);
8805 /* Startup the kernel thread for this host adapter. */
8806 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8807 "qla4xxx_dpc\n", __func__));
8808 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8809 ha->dpc_thread = create_singlethread_workqueue(buf);
8810 if (!ha->dpc_thread) {
8811 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8815 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8817 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8820 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8826 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8827 * (which is called indirectly by qla4xxx_initialize_adapter),
8828 * so that irqs will be registered after crbinit but before
8831 if (is_qla40XX(ha)) {
8832 ret = qla4xxx_request_irqs(ha);
8834 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8835 "interrupt %d already in use.\n", pdev->irq);
8840 pci_save_state(ha->pdev);
8841 ha->isp_ops->enable_intrs(ha);
8843 /* Start timer thread. */
8844 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
8846 set_bit(AF_INIT_DONE, &ha->flags);
8848 qla4_8xxx_alloc_sysfs_attr(ha);
8851 " QLogic iSCSI HBA Driver version: %s\n"
8852 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8853 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8854 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8855 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8857 /* Set the driver version */
8859 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8861 if (qla4xxx_setup_boot_info(ha))
8862 ql4_printk(KERN_ERR, ha,
8863 "%s: No iSCSI boot target configured\n", __func__);
8865 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8866 /* Perform the build ddb list and login to each */
8867 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8868 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8869 qla4xxx_wait_login_resp_boot_tgt(ha);
8871 qla4xxx_create_chap_list(ha);
8873 qla4xxx_create_ifaces(ha);
8877 scsi_remove_host(ha->host);
8880 qla4xxx_free_adapter(ha);
8882 probe_failed_ioconfig:
8883 pci_disable_pcie_error_reporting(pdev);
8884 scsi_host_put(ha->host);
8886 probe_disable_device:
8887 pci_disable_device(pdev);
8893 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8894 * @ha: pointer to adapter structure
8896 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8897 * so that the other port will not re-initialize while in the process of
8898 * removing the ha due to driver unload or hba hotplug.
8900 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8902 struct scsi_qla_host *other_ha = NULL;
8903 struct pci_dev *other_pdev = NULL;
8904 int fn = ISP4XXX_PCI_FN_2;
8906 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8907 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8908 fn = ISP4XXX_PCI_FN_1;
8911 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8912 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8915 /* Get other_ha if other_pdev is valid and state is enable*/
8917 if (atomic_read(&other_pdev->enable_cnt)) {
8918 other_ha = pci_get_drvdata(other_pdev);
8920 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8921 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8922 "Prevent %s reinit\n", __func__,
8923 dev_name(&other_ha->pdev->dev)));
8926 pci_dev_put(other_pdev);
8930 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8931 struct ddb_entry *ddb_entry)
8933 struct dev_db_entry *fw_ddb_entry = NULL;
8934 dma_addr_t fw_ddb_entry_dma;
8935 unsigned long wtime;
8940 options = LOGOUT_OPTION_CLOSE_SESSION;
8941 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8942 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8946 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8947 &fw_ddb_entry_dma, GFP_KERNEL);
8948 if (!fw_ddb_entry) {
8949 ql4_printk(KERN_ERR, ha,
8950 "%s: Unable to allocate dma buffer\n", __func__);
8954 wtime = jiffies + (HZ * LOGOUT_TOV);
8956 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8957 fw_ddb_entry, fw_ddb_entry_dma,
8958 NULL, NULL, &ddb_state, NULL,
8960 if (status == QLA_ERROR)
8963 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8964 (ddb_state == DDB_DS_SESSION_FAILED))
8967 schedule_timeout_uninterruptible(HZ);
8968 } while ((time_after(wtime, jiffies)));
8971 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8972 fw_ddb_entry, fw_ddb_entry_dma);
8974 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8977 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8979 struct ddb_entry *ddb_entry;
8982 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8984 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8985 if ((ddb_entry != NULL) &&
8986 (ddb_entry->ddb_type == FLASH_DDB)) {
8988 qla4xxx_destroy_ddb(ha, ddb_entry);
8990 * we have decremented the reference count of the driver
8991 * when we setup the session to have the driver unload
8992 * to be seamless without actually destroying the
8995 try_module_get(qla4xxx_iscsi_transport.owner);
8996 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8997 qla4xxx_free_ddb(ha, ddb_entry);
8998 iscsi_session_teardown(ddb_entry->sess);
9003 * qla4xxx_remove_adapter - callback function to remove adapter.
9004 * @pci_dev: PCI device pointer
9006 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
9008 struct scsi_qla_host *ha;
9011 * If the PCI device is disabled then it means probe_adapter had
9012 * failed and resources already cleaned up on probe_adapter exit.
9014 if (!pci_is_enabled(pdev))
9017 ha = pci_get_drvdata(pdev);
9020 qla4xxx_prevent_other_port_reinit(ha);
9022 /* destroy iface from sysfs */
9023 qla4xxx_destroy_ifaces(ha);
9025 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9026 iscsi_boot_destroy_kset(ha->boot_kset);
9028 qla4xxx_destroy_fw_ddb_session(ha);
9029 qla4_8xxx_free_sysfs_attr(ha);
9031 qla4xxx_sysfs_ddb_remove(ha);
9032 scsi_remove_host(ha->host);
9034 qla4xxx_free_adapter(ha);
9036 scsi_host_put(ha->host);
9038 pci_disable_pcie_error_reporting(pdev);
9039 pci_disable_device(pdev);
9043 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9046 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
9047 * supported addressing method.
9049 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9053 /* Update our PCI device dma_mask for full 64 bit mask */
9054 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
9055 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
9056 dev_dbg(&ha->pdev->dev,
9057 "Failed to set 64 bit PCI consistent mask; "
9059 retval = pci_set_consistent_dma_mask(ha->pdev,
9063 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
9066 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9068 struct iscsi_cls_session *cls_sess;
9069 struct iscsi_session *sess;
9070 struct ddb_entry *ddb;
9071 int queue_depth = QL4_DEF_QDEPTH;
9073 cls_sess = starget_to_session(sdev->sdev_target);
9074 sess = cls_sess->dd_data;
9075 ddb = sess->dd_data;
9077 sdev->hostdata = ddb;
9079 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9080 queue_depth = ql4xmaxqdepth;
9082 scsi_change_queue_depth(sdev, queue_depth);
9087 * qla4xxx_del_from_active_array - returns an active srb
9088 * @ha: Pointer to host adapter structure.
9089 * @index: index into the active_array
9091 * This routine removes and returns the srb at the specified index
9093 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9096 struct srb *srb = NULL;
9097 struct scsi_cmnd *cmd = NULL;
9099 cmd = scsi_host_find_tag(ha->host, index);
9103 srb = (struct srb *)CMD_SP(cmd);
9107 /* update counters */
9108 if (srb->flags & SRB_DMA_VALID) {
9109 ha->iocb_cnt -= srb->iocb_cnt;
9111 srb->cmd->host_scribble =
9112 (unsigned char *)(unsigned long) MAX_SRBS;
9118 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9119 * @ha: Pointer to host adapter structure.
9120 * @cmd: Scsi Command to wait on.
9122 * This routine waits for the command to be returned by the Firmware
9123 * for some max time.
9125 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9126 struct scsi_cmnd *cmd)
9130 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9133 /* Dont wait on command if PCI error is being handled
9136 if (unlikely(pci_channel_offline(ha->pdev)) ||
9137 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9138 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9139 ha->host_no, __func__);
9144 /* Checking to see if its returned to OS */
9145 rp = (struct srb *) CMD_SP(cmd);
9152 } while (max_wait_time--);
9158 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9159 * @ha: Pointer to host adapter structure
9161 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9163 unsigned long wait_online;
9165 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9166 while (time_before(jiffies, wait_online)) {
9178 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9179 * @ha: pointer to HBA
9183 * This function waits for all outstanding commands to a lun to complete. It
9184 * returns 0 if all pending commands are returned and 1 otherwise.
9186 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9187 struct scsi_target *stgt,
9188 struct scsi_device *sdev)
9192 struct scsi_cmnd *cmd;
9195 * Waiting for all commands for the designated target or dev
9196 * in the active array
9198 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9199 cmd = scsi_host_find_tag(ha->host, cnt);
9200 if (cmd && stgt == scsi_target(cmd->device) &&
9201 (!sdev || sdev == cmd->device)) {
9202 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9212 * qla4xxx_eh_abort - callback for abort task.
9213 * @cmd: Pointer to Linux's SCSI command structure
9215 * This routine is called by the Linux OS to abort the specified
9218 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9220 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9221 unsigned int id = cmd->device->id;
9222 uint64_t lun = cmd->device->lun;
9223 unsigned long flags;
9224 struct srb *srb = NULL;
9229 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9230 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9232 rval = qla4xxx_isp_check_reg(ha);
9233 if (rval != QLA_SUCCESS) {
9234 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9238 spin_lock_irqsave(&ha->hardware_lock, flags);
9239 srb = (struct srb *) CMD_SP(cmd);
9241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9242 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9243 ha->host_no, id, lun);
9246 kref_get(&srb->srb_ref);
9247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9249 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9250 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9251 ha->host_no, id, lun));
9254 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9255 ha->host_no, id, lun));
9259 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9261 /* Wait for command to complete */
9263 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9264 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9265 ha->host_no, id, lun));
9270 ql4_printk(KERN_INFO, ha,
9271 "scsi%ld:%d:%llu: Abort command - %s\n",
9272 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9278 * qla4xxx_eh_device_reset - callback for target reset.
9279 * @cmd: Pointer to Linux's SCSI command structure
9281 * This routine is called by the Linux OS to reset all luns on the
9284 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9286 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9287 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9288 int ret = FAILED, stat;
9294 ret = iscsi_block_scsi_eh(cmd);
9299 ql4_printk(KERN_INFO, ha,
9300 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9301 cmd->device->channel, cmd->device->id, cmd->device->lun);
9303 DEBUG2(printk(KERN_INFO
9304 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9305 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9306 cmd, jiffies, cmd->request->timeout / HZ,
9307 ha->dpc_flags, cmd->result, cmd->allowed));
9309 rval = qla4xxx_isp_check_reg(ha);
9310 if (rval != QLA_SUCCESS) {
9311 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9315 /* FIXME: wait for hba to go online */
9316 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9317 if (stat != QLA_SUCCESS) {
9318 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9319 goto eh_dev_reset_done;
9322 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9324 ql4_printk(KERN_INFO, ha,
9325 "DEVICE RESET FAILED - waiting for "
9327 goto eh_dev_reset_done;
9331 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9332 MM_LUN_RESET) != QLA_SUCCESS)
9333 goto eh_dev_reset_done;
9335 ql4_printk(KERN_INFO, ha,
9336 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9337 ha->host_no, cmd->device->channel, cmd->device->id,
9348 * qla4xxx_eh_target_reset - callback for target reset.
9349 * @cmd: Pointer to Linux's SCSI command structure
9351 * This routine is called by the Linux OS to reset the target.
9353 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9355 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9356 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9363 ret = iscsi_block_scsi_eh(cmd);
9367 starget_printk(KERN_INFO, scsi_target(cmd->device),
9368 "WARM TARGET RESET ISSUED.\n");
9370 DEBUG2(printk(KERN_INFO
9371 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9372 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9373 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9374 ha->dpc_flags, cmd->result, cmd->allowed));
9376 rval = qla4xxx_isp_check_reg(ha);
9377 if (rval != QLA_SUCCESS) {
9378 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9382 stat = qla4xxx_reset_target(ha, ddb_entry);
9383 if (stat != QLA_SUCCESS) {
9384 starget_printk(KERN_INFO, scsi_target(cmd->device),
9385 "WARM TARGET RESET FAILED.\n");
9389 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9391 starget_printk(KERN_INFO, scsi_target(cmd->device),
9392 "WARM TARGET DEVICE RESET FAILED - "
9393 "waiting for commands.\n");
9398 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9399 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9400 starget_printk(KERN_INFO, scsi_target(cmd->device),
9401 "WARM TARGET DEVICE RESET FAILED - "
9402 "marker iocb failed.\n");
9406 starget_printk(KERN_INFO, scsi_target(cmd->device),
9407 "WARM TARGET RESET SUCCEEDED.\n");
9412 * qla4xxx_is_eh_active - check if error handler is running
9413 * @shost: Pointer to SCSI Host struct
9415 * This routine finds that if reset host is called in EH
9416 * scenario or from some application like sg_reset
9418 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9420 if (shost->shost_state == SHOST_RECOVERY)
9426 * qla4xxx_eh_host_reset - kernel callback
9427 * @cmd: Pointer to Linux's SCSI command structure
9429 * This routine is invoked by the Linux kernel to perform fatal error
9430 * recovery on the specified adapter.
9432 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9434 int return_status = FAILED;
9435 struct scsi_qla_host *ha;
9438 ha = to_qla_host(cmd->device->host);
9440 rval = qla4xxx_isp_check_reg(ha);
9441 if (rval != QLA_SUCCESS) {
9442 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9446 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9447 qla4_83xx_set_idc_dontreset(ha);
9450 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9451 * protocol drivers, we should not set device_state to NEED_RESET
9453 if (ql4xdontresethba ||
9454 ((is_qla8032(ha) || is_qla8042(ha)) &&
9455 qla4_83xx_idc_dontreset(ha))) {
9456 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9457 ha->host_no, __func__));
9459 /* Clear outstanding srb in queues */
9460 if (qla4xxx_is_eh_active(cmd->device->host))
9461 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9466 ql4_printk(KERN_INFO, ha,
9467 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9468 cmd->device->channel, cmd->device->id, cmd->device->lun);
9470 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9471 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9472 "DEAD.\n", ha->host_no, cmd->device->channel,
9478 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9480 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9482 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9485 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9486 return_status = SUCCESS;
9488 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9489 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9491 return return_status;
9494 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9496 uint32_t mbox_cmd[MBOX_REG_COUNT];
9497 uint32_t mbox_sts[MBOX_REG_COUNT];
9498 struct addr_ctrl_blk_def *acb = NULL;
9499 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9500 int rval = QLA_SUCCESS;
9503 acb = dma_alloc_coherent(&ha->pdev->dev,
9504 sizeof(struct addr_ctrl_blk_def),
9505 &acb_dma, GFP_KERNEL);
9507 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9510 goto exit_port_reset;
9513 memset(acb, 0, acb_len);
9515 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9516 if (rval != QLA_SUCCESS) {
9521 rval = qla4xxx_disable_acb(ha);
9522 if (rval != QLA_SUCCESS) {
9527 wait_for_completion_timeout(&ha->disable_acb_comp,
9528 DISABLE_ACB_TOV * HZ);
9530 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9531 if (rval != QLA_SUCCESS) {
9537 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9540 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9541 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9545 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9547 struct scsi_qla_host *ha = to_qla_host(shost);
9548 int rval = QLA_SUCCESS;
9551 if (ql4xdontresethba) {
9552 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9555 goto exit_host_reset;
9558 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9559 goto recover_adapter;
9561 switch (reset_type) {
9562 case SCSI_ADAPTER_RESET:
9563 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9565 case SCSI_FIRMWARE_RESET:
9566 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9568 /* set firmware context reset */
9569 set_bit(DPC_RESET_HA_FW_CONTEXT,
9572 rval = qla4xxx_context_reset(ha);
9573 goto exit_host_reset;
9580 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9581 * reset is issued by application */
9582 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9583 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9584 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9585 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9586 (idc_ctrl | GRACEFUL_RESET_BIT1));
9589 rval = qla4xxx_recover_adapter(ha);
9590 if (rval != QLA_SUCCESS) {
9591 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9600 /* PCI AER driver recovers from all correctable errors w/o
9601 * driver intervention. For uncorrectable errors PCI AER
9602 * driver calls the following device driver's callbacks
9604 * - Fatal Errors - link_reset
9605 * - Non-Fatal Errors - driver's error_detected() which
9606 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9608 * PCI AER driver calls
9609 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9610 * returns RECOVERED or NEED_RESET if fw_hung
9611 * NEED_RESET - driver's slot_reset()
9612 * DISCONNECT - device is dead & cannot recover
9613 * RECOVERED - driver's resume()
9615 static pci_ers_result_t
9616 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9618 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9620 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9621 ha->host_no, __func__, state);
9623 if (!is_aer_supported(ha))
9624 return PCI_ERS_RESULT_NONE;
9627 case pci_channel_io_normal:
9628 clear_bit(AF_EEH_BUSY, &ha->flags);
9629 return PCI_ERS_RESULT_CAN_RECOVER;
9630 case pci_channel_io_frozen:
9631 set_bit(AF_EEH_BUSY, &ha->flags);
9632 qla4xxx_mailbox_premature_completion(ha);
9633 qla4xxx_free_irqs(ha);
9634 pci_disable_device(pdev);
9635 /* Return back all IOs */
9636 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9637 return PCI_ERS_RESULT_NEED_RESET;
9638 case pci_channel_io_perm_failure:
9639 set_bit(AF_EEH_BUSY, &ha->flags);
9640 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9641 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9642 return PCI_ERS_RESULT_DISCONNECT;
9644 return PCI_ERS_RESULT_NEED_RESET;
9648 * qla4xxx_pci_mmio_enabled() gets called if
9649 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9650 * and read/write to the device still works.
9652 static pci_ers_result_t
9653 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9655 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9657 if (!is_aer_supported(ha))
9658 return PCI_ERS_RESULT_NONE;
9660 return PCI_ERS_RESULT_RECOVERED;
9663 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9665 uint32_t rval = QLA_ERROR;
9667 struct pci_dev *other_pdev = NULL;
9669 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9671 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9673 if (test_bit(AF_ONLINE, &ha->flags)) {
9674 clear_bit(AF_ONLINE, &ha->flags);
9675 clear_bit(AF_LINK_UP, &ha->flags);
9676 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9677 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9680 fn = PCI_FUNC(ha->pdev->devfn);
9681 if (is_qla8022(ha)) {
9684 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9685 ha->host_no, __func__, fn);
9686 /* Get the pci device given the domain, bus,
9687 * slot/function number */
9688 other_pdev = pci_get_domain_bus_and_slot(
9689 pci_domain_nr(ha->pdev->bus),
9690 ha->pdev->bus->number,
9691 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9697 if (atomic_read(&other_pdev->enable_cnt)) {
9698 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9699 ha->host_no, __func__, fn);
9700 pci_dev_put(other_pdev);
9703 pci_dev_put(other_pdev);
9706 /* this case is meant for ISP83xx/ISP84xx only */
9707 if (qla4_83xx_can_perform_reset(ha)) {
9708 /* reset fn as iSCSI is going to perform the reset */
9713 /* The first function on the card, the reset owner will
9714 * start & initialize the firmware. The other functions
9715 * on the card will reset the firmware context
9718 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9719 "0x%x is the owner\n", ha->host_no, __func__,
9722 ha->isp_ops->idc_lock(ha);
9723 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9725 ha->isp_ops->idc_unlock(ha);
9727 rval = qla4_8xxx_update_idc_reg(ha);
9728 if (rval == QLA_ERROR) {
9729 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9730 ha->host_no, __func__);
9731 ha->isp_ops->idc_lock(ha);
9732 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9733 QLA8XXX_DEV_FAILED);
9734 ha->isp_ops->idc_unlock(ha);
9735 goto exit_error_recovery;
9738 clear_bit(AF_FW_RECOVERY, &ha->flags);
9739 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9741 if (rval != QLA_SUCCESS) {
9742 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9743 "FAILED\n", ha->host_no, __func__);
9744 qla4xxx_free_irqs(ha);
9745 ha->isp_ops->idc_lock(ha);
9746 qla4_8xxx_clear_drv_active(ha);
9747 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9748 QLA8XXX_DEV_FAILED);
9749 ha->isp_ops->idc_unlock(ha);
9751 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9752 "READY\n", ha->host_no, __func__);
9753 ha->isp_ops->idc_lock(ha);
9754 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9756 /* Clear driver state register */
9757 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9758 qla4_8xxx_set_drv_active(ha);
9759 ha->isp_ops->idc_unlock(ha);
9760 ha->isp_ops->enable_intrs(ha);
9763 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9764 "the reset owner\n", ha->host_no, __func__,
9766 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9767 QLA8XXX_DEV_READY)) {
9768 clear_bit(AF_FW_RECOVERY, &ha->flags);
9769 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9770 if (rval == QLA_SUCCESS)
9771 ha->isp_ops->enable_intrs(ha);
9773 qla4xxx_free_irqs(ha);
9775 ha->isp_ops->idc_lock(ha);
9776 qla4_8xxx_set_drv_active(ha);
9777 ha->isp_ops->idc_unlock(ha);
9780 exit_error_recovery:
9781 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9785 static pci_ers_result_t
9786 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9788 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9789 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9792 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9793 ha->host_no, __func__);
9795 if (!is_aer_supported(ha))
9796 return PCI_ERS_RESULT_NONE;
9798 /* Restore the saved state of PCIe device -
9799 * BAR registers, PCI Config space, PCIX, MSI,
9802 pci_restore_state(pdev);
9804 /* pci_restore_state() clears the saved_state flag of the device
9805 * save restored state which resets saved_state flag
9807 pci_save_state(pdev);
9809 /* Initialize device or resume if in suspended state */
9810 rc = pci_enable_device(pdev);
9812 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9813 "device after reset\n", ha->host_no, __func__);
9814 goto exit_slot_reset;
9817 ha->isp_ops->disable_intrs(ha);
9819 if (is_qla80XX(ha)) {
9820 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9821 ret = PCI_ERS_RESULT_RECOVERED;
9822 goto exit_slot_reset;
9824 goto exit_slot_reset;
9828 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9829 "device after reset\n", ha->host_no, __func__, ret);
9834 qla4xxx_pci_resume(struct pci_dev *pdev)
9836 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9839 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9840 ha->host_no, __func__);
9842 ret = qla4xxx_wait_for_hba_online(ha);
9843 if (ret != QLA_SUCCESS) {
9844 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9845 "resume I/O from slot/link_reset\n", ha->host_no,
9849 pci_cleanup_aer_uncorrect_error_status(pdev);
9850 clear_bit(AF_EEH_BUSY, &ha->flags);
9853 static const struct pci_error_handlers qla4xxx_err_handler = {
9854 .error_detected = qla4xxx_pci_error_detected,
9855 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9856 .slot_reset = qla4xxx_pci_slot_reset,
9857 .resume = qla4xxx_pci_resume,
9860 static struct pci_device_id qla4xxx_pci_tbl[] = {
9862 .vendor = PCI_VENDOR_ID_QLOGIC,
9863 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9864 .subvendor = PCI_ANY_ID,
9865 .subdevice = PCI_ANY_ID,
9868 .vendor = PCI_VENDOR_ID_QLOGIC,
9869 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9870 .subvendor = PCI_ANY_ID,
9871 .subdevice = PCI_ANY_ID,
9874 .vendor = PCI_VENDOR_ID_QLOGIC,
9875 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9876 .subvendor = PCI_ANY_ID,
9877 .subdevice = PCI_ANY_ID,
9880 .vendor = PCI_VENDOR_ID_QLOGIC,
9881 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9882 .subvendor = PCI_ANY_ID,
9883 .subdevice = PCI_ANY_ID,
9886 .vendor = PCI_VENDOR_ID_QLOGIC,
9887 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9888 .subvendor = PCI_ANY_ID,
9889 .subdevice = PCI_ANY_ID,
9892 .vendor = PCI_VENDOR_ID_QLOGIC,
9893 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9894 .subvendor = PCI_ANY_ID,
9895 .subdevice = PCI_ANY_ID,
9899 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9901 static struct pci_driver qla4xxx_pci_driver = {
9902 .name = DRIVER_NAME,
9903 .id_table = qla4xxx_pci_tbl,
9904 .probe = qla4xxx_probe_adapter,
9905 .remove = qla4xxx_remove_adapter,
9906 .err_handler = &qla4xxx_err_handler,
9909 static int __init qla4xxx_module_init(void)
9913 if (ql4xqfulltracking)
9914 qla4xxx_driver_template.track_queue_depth = 1;
9916 /* Allocate cache for SRBs. */
9917 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9918 SLAB_HWCACHE_ALIGN, NULL);
9919 if (srb_cachep == NULL) {
9921 "%s: Unable to allocate SRB cache..."
9922 "Failing load!\n", DRIVER_NAME);
9927 /* Derive version string. */
9928 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9929 if (ql4xextended_error_logging)
9930 strcat(qla4xxx_version_str, "-debug");
9932 qla4xxx_scsi_transport =
9933 iscsi_register_transport(&qla4xxx_iscsi_transport);
9934 if (!qla4xxx_scsi_transport){
9936 goto release_srb_cache;
9939 ret = pci_register_driver(&qla4xxx_pci_driver);
9941 goto unregister_transport;
9943 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9946 unregister_transport:
9947 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9949 kmem_cache_destroy(srb_cachep);
9954 static void __exit qla4xxx_module_exit(void)
9956 pci_unregister_driver(&qla4xxx_pci_driver);
9957 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9958 kmem_cache_destroy(srb_cachep);
9961 module_init(qla4xxx_module_init);
9962 module_exit(qla4xxx_module_exit);
9964 MODULE_AUTHOR("QLogic Corporation");
9965 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9966 MODULE_LICENSE("GPL");
9967 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);