1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic iSCSI HBA Driver
4 * Copyright (c) 2003-2013 QLogic Corporation
6 #include <linux/moduleparam.h>
7 #include <linux/slab.h>
8 #include <linux/blkdev.h>
9 #include <linux/iscsi_boot_sysfs.h>
10 #include <linux/inet.h>
12 #include <scsi/scsi_tcq.h>
13 #include <scsi/scsicam.h>
16 #include "ql4_version.h"
19 #include "ql4_inline.h"
25 static char qla4xxx_version_str[40];
28 * SRB allocation cache
30 static struct kmem_cache *srb_cachep;
33 * Module parameter information and variables
35 static int ql4xdisablesysfsboot = 1;
36 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
37 MODULE_PARM_DESC(ql4xdisablesysfsboot,
38 " Set to disable exporting boot targets to sysfs.\n"
39 "\t\t 0 - Export boot targets\n"
40 "\t\t 1 - Do not export boot targets (Default)");
43 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
44 MODULE_PARM_DESC(ql4xdontresethba,
45 " Don't reset the HBA for driver recovery.\n"
46 "\t\t 0 - It will reset HBA (Default)\n"
47 "\t\t 1 - It will NOT reset HBA");
49 int ql4xextended_error_logging;
50 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
51 MODULE_PARM_DESC(ql4xextended_error_logging,
52 " Option to enable extended error logging.\n"
53 "\t\t 0 - no logging (Default)\n"
54 "\t\t 2 - debug logging");
56 int ql4xenablemsix = 1;
57 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql4xenablemsix,
59 " Set to enable MSI or MSI-X interrupt mechanism.\n"
60 "\t\t 0 = enable INTx interrupt mechanism.\n"
61 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
62 "\t\t 2 = enable MSI interrupt mechanism.");
64 #define QL4_DEF_QDEPTH 32
65 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
66 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
67 MODULE_PARM_DESC(ql4xmaxqdepth,
68 " Maximum queue depth to report for target devices.\n"
71 static int ql4xqfulltracking = 1;
72 module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
73 MODULE_PARM_DESC(ql4xqfulltracking,
74 " Enable or disable dynamic tracking and adjustment of\n"
75 "\t\t scsi device queue depth.\n"
77 "\t\t 1 - Enable. (Default)");
79 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
80 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
81 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
82 " Target Session Recovery Timeout.\n"
83 "\t\t Default: 120 sec.");
85 int ql4xmdcapmask = 0;
86 module_param(ql4xmdcapmask, int, S_IRUGO);
87 MODULE_PARM_DESC(ql4xmdcapmask,
88 " Set the Minidump driver capture mask level.\n"
89 "\t\t Default is 0 (firmware default capture mask)\n"
90 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
93 module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
94 MODULE_PARM_DESC(ql4xenablemd,
95 " Set to enable minidump.\n"
96 "\t\t 0 - disable minidump\n"
97 "\t\t 1 - enable minidump (Default)");
99 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
101 * SCSI host template entry points
103 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
106 * iSCSI template entry points
108 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
109 enum iscsi_param param, char *buf);
110 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
111 enum iscsi_param param, char *buf);
112 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
113 enum iscsi_host_param param, char *buf);
114 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
116 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
117 enum iscsi_param_type param_type,
118 int param, char *buf);
119 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
120 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
121 struct sockaddr *dst_addr,
123 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
124 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
125 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
126 enum iscsi_param param, char *buf);
127 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
128 static struct iscsi_cls_conn *
129 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
130 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
131 struct iscsi_cls_conn *cls_conn,
132 uint64_t transport_fd, int is_leading);
133 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
134 static struct iscsi_cls_session *
135 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
136 uint16_t qdepth, uint32_t initial_cmdsn);
137 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
138 static void qla4xxx_task_work(struct work_struct *wdata);
139 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
140 static int qla4xxx_task_xmit(struct iscsi_task *);
141 static void qla4xxx_task_cleanup(struct iscsi_task *);
142 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
143 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
144 struct iscsi_stats *stats);
145 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
146 uint32_t iface_type, uint32_t payload_size,
147 uint32_t pid, struct sockaddr *dst_addr);
148 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
149 uint32_t *num_entries, char *buf);
150 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
151 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
153 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
156 * SCSI host template entry points
158 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
159 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
161 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
162 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
163 static int qla4xxx_slave_alloc(struct scsi_device *device);
164 static umode_t qla4_attr_is_visible(int param_type, int param);
165 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
168 * iSCSI Flash DDB sysfs entry points
171 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
172 struct iscsi_bus_flash_conn *fnode_conn,
173 void *data, int len);
175 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
176 int param, char *buf);
177 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
180 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
181 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
182 struct iscsi_bus_flash_conn *fnode_conn);
183 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
184 struct iscsi_bus_flash_conn *fnode_conn);
185 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
187 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
188 QLA82XX_LEGACY_INTR_CONFIG;
190 static const uint32_t qla4_82xx_reg_tbl[] = {
191 QLA82XX_PEG_HALT_STATUS1,
192 QLA82XX_PEG_HALT_STATUS2,
193 QLA82XX_PEG_ALIVE_COUNTER,
194 QLA82XX_CRB_DRV_ACTIVE,
195 QLA82XX_CRB_DEV_STATE,
196 QLA82XX_CRB_DRV_STATE,
197 QLA82XX_CRB_DRV_SCRATCH,
198 QLA82XX_CRB_DEV_PART_INFO,
199 QLA82XX_CRB_DRV_IDC_VERSION,
200 QLA82XX_FW_VERSION_MAJOR,
201 QLA82XX_FW_VERSION_MINOR,
202 QLA82XX_FW_VERSION_SUB,
207 static const uint32_t qla4_83xx_reg_tbl[] = {
208 QLA83XX_PEG_HALT_STATUS1,
209 QLA83XX_PEG_HALT_STATUS2,
210 QLA83XX_PEG_ALIVE_COUNTER,
211 QLA83XX_CRB_DRV_ACTIVE,
212 QLA83XX_CRB_DEV_STATE,
213 QLA83XX_CRB_DRV_STATE,
214 QLA83XX_CRB_DRV_SCRATCH,
215 QLA83XX_CRB_DEV_PART_INFO1,
216 QLA83XX_CRB_IDC_VER_MAJOR,
217 QLA83XX_FW_VER_MAJOR,
218 QLA83XX_FW_VER_MINOR,
220 QLA83XX_CMDPEG_STATE,
224 static struct scsi_host_template qla4xxx_driver_template = {
225 .module = THIS_MODULE,
227 .proc_name = DRIVER_NAME,
228 .queuecommand = qla4xxx_queuecommand,
229 .cmd_size = sizeof(struct qla4xxx_cmd_priv),
231 .eh_abort_handler = qla4xxx_eh_abort,
232 .eh_device_reset_handler = qla4xxx_eh_device_reset,
233 .eh_target_reset_handler = qla4xxx_eh_target_reset,
234 .eh_host_reset_handler = qla4xxx_eh_host_reset,
235 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
237 .slave_alloc = qla4xxx_slave_alloc,
238 .change_queue_depth = scsi_change_queue_depth,
242 .sg_tablesize = SG_ALL,
244 .max_sectors = 0xFFFF,
245 .shost_groups = qla4xxx_host_groups,
246 .host_reset = qla4xxx_host_reset,
247 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
250 static struct iscsi_transport qla4xxx_iscsi_transport = {
251 .owner = THIS_MODULE,
253 .caps = CAP_TEXT_NEGO |
254 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
255 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
257 .attr_is_visible = qla4_attr_is_visible,
258 .create_session = qla4xxx_session_create,
259 .destroy_session = qla4xxx_session_destroy,
260 .start_conn = qla4xxx_conn_start,
261 .create_conn = qla4xxx_conn_create,
262 .bind_conn = qla4xxx_conn_bind,
263 .unbind_conn = iscsi_conn_unbind,
264 .stop_conn = iscsi_conn_stop,
265 .destroy_conn = qla4xxx_conn_destroy,
266 .set_param = iscsi_set_param,
267 .get_conn_param = qla4xxx_conn_get_param,
268 .get_session_param = qla4xxx_session_get_param,
269 .get_ep_param = qla4xxx_get_ep_param,
270 .ep_connect = qla4xxx_ep_connect,
271 .ep_poll = qla4xxx_ep_poll,
272 .ep_disconnect = qla4xxx_ep_disconnect,
273 .get_stats = qla4xxx_conn_get_stats,
274 .send_pdu = iscsi_conn_send_pdu,
275 .xmit_task = qla4xxx_task_xmit,
276 .cleanup_task = qla4xxx_task_cleanup,
277 .alloc_pdu = qla4xxx_alloc_pdu,
279 .get_host_param = qla4xxx_host_get_param,
280 .set_iface_param = qla4xxx_iface_set_param,
281 .get_iface_param = qla4xxx_get_iface_param,
282 .bsg_request = qla4xxx_bsg_request,
283 .send_ping = qla4xxx_send_ping,
284 .get_chap = qla4xxx_get_chap_list,
285 .delete_chap = qla4xxx_delete_chap,
286 .set_chap = qla4xxx_set_chap_entry,
287 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
288 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
289 .new_flashnode = qla4xxx_sysfs_ddb_add,
290 .del_flashnode = qla4xxx_sysfs_ddb_delete,
291 .login_flashnode = qla4xxx_sysfs_ddb_login,
292 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
293 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
294 .get_host_stats = qla4xxx_get_host_stats,
297 static struct scsi_transport_template *qla4xxx_scsi_transport;
299 static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
302 int rval = QLA_SUCCESS;
305 reg_val = readl(&ha->qla4_82xx_reg->host_status);
306 else if (is_qla8032(ha) || is_qla8042(ha))
307 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
309 reg_val = readw(&ha->reg->ctrl_status);
311 if (reg_val == QL4_ISP_REG_DISCONNECT)
317 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
318 uint32_t iface_type, uint32_t payload_size,
319 uint32_t pid, struct sockaddr *dst_addr)
321 struct scsi_qla_host *ha = to_qla_host(shost);
322 struct sockaddr_in *addr;
323 struct sockaddr_in6 *addr6;
324 uint32_t options = 0;
325 uint8_t ipaddr[IPv6_ADDR_LEN];
328 memset(ipaddr, 0, IPv6_ADDR_LEN);
330 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
331 (dst_addr->sa_family == AF_INET)) {
332 addr = (struct sockaddr_in *)dst_addr;
333 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
334 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
335 "dest: %pI4\n", __func__,
336 &ha->ip_config.ip_address, ipaddr));
337 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
341 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
342 (dst_addr->sa_family == AF_INET6)) {
344 addr6 = (struct sockaddr_in6 *)dst_addr;
345 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
347 options |= PING_IPV6_PROTOCOL_ENABLE;
349 /* Ping using LinkLocal address */
350 if ((iface_num == 0) || (iface_num == 1)) {
351 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
352 "src: %pI6 dest: %pI6\n", __func__,
353 &ha->ip_config.ipv6_link_local_addr,
355 options |= PING_IPV6_LINKLOCAL_ADDR;
356 rval = qla4xxx_ping_iocb(ha, options, payload_size,
359 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
360 "not supported\n", __func__, iface_num);
366 * If ping using LinkLocal address fails, try ping using
369 if (rval != QLA_SUCCESS) {
370 options &= ~PING_IPV6_LINKLOCAL_ADDR;
371 if (iface_num == 0) {
372 options |= PING_IPV6_ADDR0;
373 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
375 "dest: %pI6\n", __func__,
376 &ha->ip_config.ipv6_addr0,
378 } else if (iface_num == 1) {
379 options |= PING_IPV6_ADDR1;
380 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
382 "dest: %pI6\n", __func__,
383 &ha->ip_config.ipv6_addr1,
386 rval = qla4xxx_ping_iocb(ha, options, payload_size,
397 static umode_t qla4_attr_is_visible(int param_type, int param)
399 switch (param_type) {
400 case ISCSI_HOST_PARAM:
402 case ISCSI_HOST_PARAM_HWADDRESS:
403 case ISCSI_HOST_PARAM_IPADDRESS:
404 case ISCSI_HOST_PARAM_INITIATOR_NAME:
405 case ISCSI_HOST_PARAM_PORT_STATE:
406 case ISCSI_HOST_PARAM_PORT_SPEED:
413 case ISCSI_PARAM_PERSISTENT_ADDRESS:
414 case ISCSI_PARAM_PERSISTENT_PORT:
415 case ISCSI_PARAM_CONN_ADDRESS:
416 case ISCSI_PARAM_CONN_PORT:
417 case ISCSI_PARAM_TARGET_NAME:
418 case ISCSI_PARAM_TPGT:
419 case ISCSI_PARAM_TARGET_ALIAS:
420 case ISCSI_PARAM_MAX_BURST:
421 case ISCSI_PARAM_MAX_R2T:
422 case ISCSI_PARAM_FIRST_BURST:
423 case ISCSI_PARAM_MAX_RECV_DLENGTH:
424 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
425 case ISCSI_PARAM_IFACE_NAME:
426 case ISCSI_PARAM_CHAP_OUT_IDX:
427 case ISCSI_PARAM_CHAP_IN_IDX:
428 case ISCSI_PARAM_USERNAME:
429 case ISCSI_PARAM_PASSWORD:
430 case ISCSI_PARAM_USERNAME_IN:
431 case ISCSI_PARAM_PASSWORD_IN:
432 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
433 case ISCSI_PARAM_DISCOVERY_SESS:
434 case ISCSI_PARAM_PORTAL_TYPE:
435 case ISCSI_PARAM_CHAP_AUTH_EN:
436 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
437 case ISCSI_PARAM_BIDI_CHAP_EN:
438 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
439 case ISCSI_PARAM_DEF_TIME2WAIT:
440 case ISCSI_PARAM_DEF_TIME2RETAIN:
441 case ISCSI_PARAM_HDRDGST_EN:
442 case ISCSI_PARAM_DATADGST_EN:
443 case ISCSI_PARAM_INITIAL_R2T_EN:
444 case ISCSI_PARAM_IMM_DATA_EN:
445 case ISCSI_PARAM_PDU_INORDER_EN:
446 case ISCSI_PARAM_DATASEQ_INORDER_EN:
447 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
448 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
449 case ISCSI_PARAM_TCP_WSF_DISABLE:
450 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
451 case ISCSI_PARAM_TCP_TIMER_SCALE:
452 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
453 case ISCSI_PARAM_TCP_XMIT_WSF:
454 case ISCSI_PARAM_TCP_RECV_WSF:
455 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
456 case ISCSI_PARAM_IPV4_TOS:
457 case ISCSI_PARAM_IPV6_TC:
458 case ISCSI_PARAM_IPV6_FLOW_LABEL:
459 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
460 case ISCSI_PARAM_KEEPALIVE_TMO:
461 case ISCSI_PARAM_LOCAL_PORT:
462 case ISCSI_PARAM_ISID:
463 case ISCSI_PARAM_TSID:
464 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
465 case ISCSI_PARAM_ERL:
466 case ISCSI_PARAM_STATSN:
467 case ISCSI_PARAM_EXP_STATSN:
468 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
469 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
470 case ISCSI_PARAM_LOCAL_IPADDR:
475 case ISCSI_NET_PARAM:
477 case ISCSI_NET_PARAM_IPV4_ADDR:
478 case ISCSI_NET_PARAM_IPV4_SUBNET:
479 case ISCSI_NET_PARAM_IPV4_GW:
480 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
481 case ISCSI_NET_PARAM_IFACE_ENABLE:
482 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
483 case ISCSI_NET_PARAM_IPV6_ADDR:
484 case ISCSI_NET_PARAM_IPV6_ROUTER:
485 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
486 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
487 case ISCSI_NET_PARAM_VLAN_ID:
488 case ISCSI_NET_PARAM_VLAN_PRIORITY:
489 case ISCSI_NET_PARAM_VLAN_ENABLED:
490 case ISCSI_NET_PARAM_MTU:
491 case ISCSI_NET_PARAM_PORT:
492 case ISCSI_NET_PARAM_IPADDR_STATE:
493 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
494 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
495 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
496 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
497 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
498 case ISCSI_NET_PARAM_TCP_WSF:
499 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
500 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
501 case ISCSI_NET_PARAM_CACHE_ID:
502 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
503 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
504 case ISCSI_NET_PARAM_IPV4_TOS_EN:
505 case ISCSI_NET_PARAM_IPV4_TOS:
506 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
507 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
508 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
509 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
510 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
511 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
512 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
513 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
514 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
515 case ISCSI_NET_PARAM_REDIRECT_EN:
516 case ISCSI_NET_PARAM_IPV4_TTL:
517 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
518 case ISCSI_NET_PARAM_IPV6_MLD_EN:
519 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
520 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
521 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
522 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
523 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
524 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
525 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
526 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
531 case ISCSI_IFACE_PARAM:
533 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
534 case ISCSI_IFACE_PARAM_HDRDGST_EN:
535 case ISCSI_IFACE_PARAM_DATADGST_EN:
536 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
537 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
538 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
539 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
540 case ISCSI_IFACE_PARAM_ERL:
541 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
542 case ISCSI_IFACE_PARAM_FIRST_BURST:
543 case ISCSI_IFACE_PARAM_MAX_R2T:
544 case ISCSI_IFACE_PARAM_MAX_BURST:
545 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
546 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
547 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
548 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
549 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
550 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
555 case ISCSI_FLASHNODE_PARAM:
557 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
558 case ISCSI_FLASHNODE_PORTAL_TYPE:
559 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
560 case ISCSI_FLASHNODE_DISCOVERY_SESS:
561 case ISCSI_FLASHNODE_ENTRY_EN:
562 case ISCSI_FLASHNODE_HDR_DGST_EN:
563 case ISCSI_FLASHNODE_DATA_DGST_EN:
564 case ISCSI_FLASHNODE_IMM_DATA_EN:
565 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
566 case ISCSI_FLASHNODE_DATASEQ_INORDER:
567 case ISCSI_FLASHNODE_PDU_INORDER:
568 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
569 case ISCSI_FLASHNODE_SNACK_REQ_EN:
570 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
571 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
572 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
573 case ISCSI_FLASHNODE_ERL:
574 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
575 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
576 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
577 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
578 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
579 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
580 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
581 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
582 case ISCSI_FLASHNODE_FIRST_BURST:
583 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
584 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
585 case ISCSI_FLASHNODE_MAX_R2T:
586 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
587 case ISCSI_FLASHNODE_ISID:
588 case ISCSI_FLASHNODE_TSID:
589 case ISCSI_FLASHNODE_PORT:
590 case ISCSI_FLASHNODE_MAX_BURST:
591 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
592 case ISCSI_FLASHNODE_IPADDR:
593 case ISCSI_FLASHNODE_ALIAS:
594 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
595 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
596 case ISCSI_FLASHNODE_LOCAL_PORT:
597 case ISCSI_FLASHNODE_IPV4_TOS:
598 case ISCSI_FLASHNODE_IPV6_TC:
599 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
600 case ISCSI_FLASHNODE_NAME:
601 case ISCSI_FLASHNODE_TPGT:
602 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
603 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
604 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
605 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
606 case ISCSI_FLASHNODE_TCP_RECV_WSF:
607 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
608 case ISCSI_FLASHNODE_USERNAME:
609 case ISCSI_FLASHNODE_PASSWORD:
610 case ISCSI_FLASHNODE_STATSN:
611 case ISCSI_FLASHNODE_EXP_STATSN:
612 case ISCSI_FLASHNODE_IS_BOOT_TGT:
623 * qla4xxx_create_chap_list - Create CHAP list from FLASH
624 * @ha: pointer to adapter structure
626 * Read flash and make a list of CHAP entries, during login when a CHAP entry
627 * is received, it will be checked in this list. If entry exist then the CHAP
628 * entry index is set in the DDB. If CHAP entry does not exist in this list
629 * then a new entry is added in FLASH in CHAP table and the index obtained is
632 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
635 uint8_t *chap_flash_data = NULL;
638 uint32_t chap_size = 0;
641 chap_size = MAX_CHAP_ENTRIES_40XX *
642 sizeof(struct ql4_chap_table);
643 else /* Single region contains CHAP info for both
644 * ports which is divided into half for each port.
646 chap_size = ha->hw.flt_chap_size / 2;
648 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
649 &chap_dma, GFP_KERNEL);
650 if (!chap_flash_data) {
651 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
655 if (is_qla40XX(ha)) {
656 offset = FLASH_CHAP_OFFSET;
658 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
659 if (ha->port_num == 1)
663 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
664 if (rval != QLA_SUCCESS)
667 if (ha->chap_list == NULL)
668 ha->chap_list = vmalloc(chap_size);
669 if (ha->chap_list == NULL) {
670 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
674 memcpy(ha->chap_list, chap_flash_data, chap_size);
677 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
680 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
682 struct ql4_chap_table **chap_entry)
684 int rval = QLA_ERROR;
685 int max_chap_entries;
687 if (!ha->chap_list) {
688 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
693 max_chap_entries = (ha->hw.flt_chap_size / 2) /
694 sizeof(struct ql4_chap_table);
696 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
698 if (chap_index > max_chap_entries) {
699 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
703 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
704 if ((*chap_entry)->cookie !=
705 cpu_to_le16(CHAP_VALID_COOKIE)) {
716 * qla4xxx_find_free_chap_index - Find the first free chap index
717 * @ha: pointer to adapter structure
718 * @chap_index: CHAP index to be returned
720 * Find the first free chap index available in the chap table
722 * Note: Caller should acquire the chap lock before getting here.
724 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
725 uint16_t *chap_index)
729 int max_chap_entries = 0;
730 struct ql4_chap_table *chap_table;
733 max_chap_entries = (ha->hw.flt_chap_size / 2) /
734 sizeof(struct ql4_chap_table);
736 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
738 if (!ha->chap_list) {
739 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
744 for (i = 0; i < max_chap_entries; i++) {
745 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
747 if ((chap_table->cookie !=
748 cpu_to_le16(CHAP_VALID_COOKIE)) &&
749 (i > MAX_RESRV_CHAP_IDX)) {
755 if (free_index != -1) {
756 *chap_index = free_index;
766 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
767 uint32_t *num_entries, char *buf)
769 struct scsi_qla_host *ha = to_qla_host(shost);
770 struct ql4_chap_table *chap_table;
771 struct iscsi_chap_rec *chap_rec;
772 int max_chap_entries = 0;
773 int valid_chap_entries = 0;
777 max_chap_entries = (ha->hw.flt_chap_size / 2) /
778 sizeof(struct ql4_chap_table);
780 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
782 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
783 __func__, *num_entries, chap_tbl_idx);
787 goto exit_get_chap_list;
790 qla4xxx_create_chap_list(ha);
792 chap_rec = (struct iscsi_chap_rec *) buf;
793 mutex_lock(&ha->chap_sem);
794 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
795 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
796 if (chap_table->cookie !=
797 cpu_to_le16(CHAP_VALID_COOKIE))
800 chap_rec->chap_tbl_idx = i;
801 strlcpy(chap_rec->username, chap_table->name,
802 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
803 strlcpy(chap_rec->password, chap_table->secret,
804 QL4_CHAP_MAX_SECRET_LEN);
805 chap_rec->password_length = chap_table->secret_len;
807 if (chap_table->flags & BIT_7) /* local */
808 chap_rec->chap_type = CHAP_TYPE_OUT;
810 if (chap_table->flags & BIT_6) /* peer */
811 chap_rec->chap_type = CHAP_TYPE_IN;
815 valid_chap_entries++;
816 if (valid_chap_entries == *num_entries)
819 mutex_unlock(&ha->chap_sem);
822 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
823 __func__, valid_chap_entries);
824 *num_entries = valid_chap_entries;
828 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
831 uint16_t *chap_tbl_idx = (uint16_t *) data;
832 struct iscsi_cls_session *cls_session;
833 struct iscsi_session *sess;
834 struct ddb_entry *ddb_entry;
836 if (!iscsi_is_session_dev(dev))
837 goto exit_is_chap_active;
839 cls_session = iscsi_dev_to_session(dev);
840 sess = cls_session->dd_data;
841 ddb_entry = sess->dd_data;
843 if (iscsi_is_session_online(cls_session))
844 goto exit_is_chap_active;
846 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
853 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
854 uint16_t chap_tbl_idx)
858 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
859 __qla4xxx_is_chap_active);
864 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
866 struct scsi_qla_host *ha = to_qla_host(shost);
867 struct ql4_chap_table *chap_table;
869 int max_chap_entries = 0;
874 chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
875 if (chap_table == NULL)
879 max_chap_entries = (ha->hw.flt_chap_size / 2) /
880 sizeof(struct ql4_chap_table);
882 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
884 if (chap_tbl_idx > max_chap_entries) {
886 goto exit_delete_chap;
889 /* Check if chap index is in use.
890 * If chap is in use don't delet chap entry */
891 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
893 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
894 "delete from flash\n", chap_tbl_idx);
896 goto exit_delete_chap;
899 chap_size = sizeof(struct ql4_chap_table);
901 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
903 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
904 /* flt_chap_size is CHAP table size for both ports
905 * so divide it by 2 to calculate the offset for second port
907 if (ha->port_num == 1)
908 offset += (ha->hw.flt_chap_size / 2);
909 offset += (chap_tbl_idx * chap_size);
912 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
913 if (ret != QLA_SUCCESS) {
915 goto exit_delete_chap;
918 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
919 __le16_to_cpu(chap_table->cookie)));
921 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
922 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
923 goto exit_delete_chap;
926 chap_table->cookie = cpu_to_le16(0xFFFF);
928 offset = FLASH_CHAP_OFFSET |
929 (chap_tbl_idx * sizeof(struct ql4_chap_table));
930 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
931 FLASH_OPT_RMW_COMMIT);
932 if (ret == QLA_SUCCESS && ha->chap_list) {
933 mutex_lock(&ha->chap_sem);
934 /* Update ha chap_list cache */
935 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
936 chap_table, sizeof(struct ql4_chap_table));
937 mutex_unlock(&ha->chap_sem);
939 if (ret != QLA_SUCCESS)
943 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
948 * qla4xxx_set_chap_entry - Make chap entry with given information
949 * @shost: pointer to host
950 * @data: chap info - credentials, index and type to make chap entry
951 * @len: length of data
953 * Add or update chap entry with the given information
955 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
957 struct scsi_qla_host *ha = to_qla_host(shost);
958 struct iscsi_chap_rec chap_rec;
959 struct ql4_chap_table *chap_entry = NULL;
960 struct iscsi_param_info *param_info;
962 int max_chap_entries = 0;
968 memset(&chap_rec, 0, sizeof(chap_rec));
970 nla_for_each_attr(attr, data, len, rem) {
971 param_info = nla_data(attr);
973 switch (param_info->param) {
974 case ISCSI_CHAP_PARAM_INDEX:
975 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
977 case ISCSI_CHAP_PARAM_CHAP_TYPE:
978 chap_rec.chap_type = param_info->value[0];
980 case ISCSI_CHAP_PARAM_USERNAME:
981 size = min_t(size_t, sizeof(chap_rec.username),
983 memcpy(chap_rec.username, param_info->value, size);
985 case ISCSI_CHAP_PARAM_PASSWORD:
986 size = min_t(size_t, sizeof(chap_rec.password),
988 memcpy(chap_rec.password, param_info->value, size);
990 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
991 chap_rec.password_length = param_info->value[0];
994 ql4_printk(KERN_ERR, ha,
995 "%s: No such sysfs attribute\n", __func__);
1001 if (chap_rec.chap_type == CHAP_TYPE_IN)
1007 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1008 sizeof(struct ql4_chap_table);
1010 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1012 mutex_lock(&ha->chap_sem);
1013 if (chap_rec.chap_tbl_idx < max_chap_entries) {
1014 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
1017 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
1018 ql4_printk(KERN_INFO, ha,
1019 "Type mismatch for CHAP entry %d\n",
1020 chap_rec.chap_tbl_idx);
1022 goto exit_unlock_chap;
1025 /* If chap index is in use then don't modify it */
1026 rc = qla4xxx_is_chap_active(shost,
1027 chap_rec.chap_tbl_idx);
1029 ql4_printk(KERN_INFO, ha,
1030 "CHAP entry %d is in use\n",
1031 chap_rec.chap_tbl_idx);
1033 goto exit_unlock_chap;
1037 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1039 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1041 goto exit_unlock_chap;
1045 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1046 chap_rec.chap_tbl_idx, type);
1049 mutex_unlock(&ha->chap_sem);
1056 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1058 struct scsi_qla_host *ha = to_qla_host(shost);
1059 struct iscsi_offload_host_stats *host_stats = NULL;
1060 int host_stats_size;
1063 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1065 dma_addr_t iscsi_stats_dma;
1067 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1069 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1071 if (host_stats_size != len) {
1072 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1073 __func__, len, host_stats_size);
1075 goto exit_host_stats;
1077 host_stats = (struct iscsi_offload_host_stats *)buf;
1081 goto exit_host_stats;
1084 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1086 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1087 &iscsi_stats_dma, GFP_KERNEL);
1088 if (!ql_iscsi_stats) {
1089 ql4_printk(KERN_ERR, ha,
1090 "Unable to allocate memory for iscsi stats\n");
1092 goto exit_host_stats;
1095 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1097 if (ret != QLA_SUCCESS) {
1098 ql4_printk(KERN_ERR, ha,
1099 "Unable to retrieve iscsi stats\n");
1101 goto exit_host_stats;
1103 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1104 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1105 host_stats->mactx_multicast_frames =
1106 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1107 host_stats->mactx_broadcast_frames =
1108 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1109 host_stats->mactx_pause_frames =
1110 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1111 host_stats->mactx_control_frames =
1112 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1113 host_stats->mactx_deferral =
1114 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1115 host_stats->mactx_excess_deferral =
1116 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1117 host_stats->mactx_late_collision =
1118 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1119 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1120 host_stats->mactx_single_collision =
1121 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1122 host_stats->mactx_multiple_collision =
1123 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1124 host_stats->mactx_collision =
1125 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1126 host_stats->mactx_frames_dropped =
1127 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1128 host_stats->mactx_jumbo_frames =
1129 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1130 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1131 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1132 host_stats->macrx_unknown_control_frames =
1133 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1134 host_stats->macrx_pause_frames =
1135 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1136 host_stats->macrx_control_frames =
1137 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1138 host_stats->macrx_dribble =
1139 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1140 host_stats->macrx_frame_length_error =
1141 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1142 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1143 host_stats->macrx_carrier_sense_error =
1144 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1145 host_stats->macrx_frame_discarded =
1146 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1147 host_stats->macrx_frames_dropped =
1148 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1149 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1150 host_stats->mac_encoding_error =
1151 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1152 host_stats->macrx_length_error_large =
1153 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1154 host_stats->macrx_length_error_small =
1155 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1156 host_stats->macrx_multicast_frames =
1157 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1158 host_stats->macrx_broadcast_frames =
1159 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1160 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1161 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1162 host_stats->iptx_fragments =
1163 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1164 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1165 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1166 host_stats->iprx_fragments =
1167 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1168 host_stats->ip_datagram_reassembly =
1169 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1170 host_stats->ip_invalid_address_error =
1171 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1172 host_stats->ip_error_packets =
1173 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1174 host_stats->ip_fragrx_overlap =
1175 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1176 host_stats->ip_fragrx_outoforder =
1177 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1178 host_stats->ip_datagram_reassembly_timeout =
1179 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1180 host_stats->ipv6tx_packets =
1181 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1182 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1183 host_stats->ipv6tx_fragments =
1184 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1185 host_stats->ipv6rx_packets =
1186 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1187 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1188 host_stats->ipv6rx_fragments =
1189 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1190 host_stats->ipv6_datagram_reassembly =
1191 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1192 host_stats->ipv6_invalid_address_error =
1193 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1194 host_stats->ipv6_error_packets =
1195 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1196 host_stats->ipv6_fragrx_overlap =
1197 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1198 host_stats->ipv6_fragrx_outoforder =
1199 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1200 host_stats->ipv6_datagram_reassembly_timeout =
1201 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1202 host_stats->tcptx_segments =
1203 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1204 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1205 host_stats->tcprx_segments =
1206 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1207 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1208 host_stats->tcp_duplicate_ack_retx =
1209 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1210 host_stats->tcp_retx_timer_expired =
1211 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1212 host_stats->tcprx_duplicate_ack =
1213 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1214 host_stats->tcprx_pure_ackr =
1215 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1216 host_stats->tcptx_delayed_ack =
1217 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1218 host_stats->tcptx_pure_ack =
1219 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1220 host_stats->tcprx_segment_error =
1221 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1222 host_stats->tcprx_segment_outoforder =
1223 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1224 host_stats->tcprx_window_probe =
1225 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1226 host_stats->tcprx_window_update =
1227 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1228 host_stats->tcptx_window_probe_persist =
1229 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1230 host_stats->ecc_error_correction =
1231 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1232 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1233 host_stats->iscsi_data_bytes_tx =
1234 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1235 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1236 host_stats->iscsi_data_bytes_rx =
1237 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1238 host_stats->iscsi_io_completed =
1239 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1240 host_stats->iscsi_unexpected_io_rx =
1241 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1242 host_stats->iscsi_format_error =
1243 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1244 host_stats->iscsi_hdr_digest_error =
1245 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1246 host_stats->iscsi_data_digest_error =
1247 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1248 host_stats->iscsi_sequence_error =
1249 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1252 dma_free_coherent(&ha->pdev->dev, stats_size,
1253 ql_iscsi_stats, iscsi_stats_dma);
1255 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1260 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1261 enum iscsi_param_type param_type,
1262 int param, char *buf)
1264 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1265 struct scsi_qla_host *ha = to_qla_host(shost);
1270 if (param_type == ISCSI_NET_PARAM) {
1272 case ISCSI_NET_PARAM_IPV4_ADDR:
1273 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1275 case ISCSI_NET_PARAM_IPV4_SUBNET:
1276 len = sprintf(buf, "%pI4\n",
1277 &ha->ip_config.subnet_mask);
1279 case ISCSI_NET_PARAM_IPV4_GW:
1280 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1282 case ISCSI_NET_PARAM_IFACE_ENABLE:
1283 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1284 OP_STATE(ha->ip_config.ipv4_options,
1285 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1287 OP_STATE(ha->ip_config.ipv6_options,
1288 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1291 len = sprintf(buf, "%s\n", pval);
1293 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1294 len = sprintf(buf, "%s\n",
1295 (ha->ip_config.tcp_options &
1296 TCPOPT_DHCP_ENABLE) ?
1299 case ISCSI_NET_PARAM_IPV6_ADDR:
1300 if (iface->iface_num == 0)
1301 len = sprintf(buf, "%pI6\n",
1302 &ha->ip_config.ipv6_addr0);
1303 if (iface->iface_num == 1)
1304 len = sprintf(buf, "%pI6\n",
1305 &ha->ip_config.ipv6_addr1);
1307 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1308 len = sprintf(buf, "%pI6\n",
1309 &ha->ip_config.ipv6_link_local_addr);
1311 case ISCSI_NET_PARAM_IPV6_ROUTER:
1312 len = sprintf(buf, "%pI6\n",
1313 &ha->ip_config.ipv6_default_router_addr);
1315 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1316 pval = (ha->ip_config.ipv6_addl_options &
1317 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1320 len = sprintf(buf, "%s\n", pval);
1322 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1323 pval = (ha->ip_config.ipv6_addl_options &
1324 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1327 len = sprintf(buf, "%s\n", pval);
1329 case ISCSI_NET_PARAM_VLAN_ID:
1330 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1331 ival = ha->ip_config.ipv4_vlan_tag &
1334 ival = ha->ip_config.ipv6_vlan_tag &
1337 len = sprintf(buf, "%d\n", ival);
1339 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1340 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1341 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1342 ISCSI_MAX_VLAN_PRIORITY;
1344 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1345 ISCSI_MAX_VLAN_PRIORITY;
1347 len = sprintf(buf, "%d\n", ival);
1349 case ISCSI_NET_PARAM_VLAN_ENABLED:
1350 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1351 OP_STATE(ha->ip_config.ipv4_options,
1352 IPOPT_VLAN_TAGGING_ENABLE, pval);
1354 OP_STATE(ha->ip_config.ipv6_options,
1355 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1357 len = sprintf(buf, "%s\n", pval);
1359 case ISCSI_NET_PARAM_MTU:
1360 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1362 case ISCSI_NET_PARAM_PORT:
1363 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1364 len = sprintf(buf, "%d\n",
1365 ha->ip_config.ipv4_port);
1367 len = sprintf(buf, "%d\n",
1368 ha->ip_config.ipv6_port);
1370 case ISCSI_NET_PARAM_IPADDR_STATE:
1371 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1372 pval = iscsi_get_ipaddress_state_name(
1373 ha->ip_config.ipv4_addr_state);
1375 if (iface->iface_num == 0)
1376 pval = iscsi_get_ipaddress_state_name(
1377 ha->ip_config.ipv6_addr0_state);
1378 else if (iface->iface_num == 1)
1379 pval = iscsi_get_ipaddress_state_name(
1380 ha->ip_config.ipv6_addr1_state);
1383 len = sprintf(buf, "%s\n", pval);
1385 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1386 pval = iscsi_get_ipaddress_state_name(
1387 ha->ip_config.ipv6_link_local_state);
1388 len = sprintf(buf, "%s\n", pval);
1390 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1391 pval = iscsi_get_router_state_name(
1392 ha->ip_config.ipv6_default_router_state);
1393 len = sprintf(buf, "%s\n", pval);
1395 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1396 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1397 OP_STATE(~ha->ip_config.tcp_options,
1398 TCPOPT_DELAYED_ACK_DISABLE, pval);
1400 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1401 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1403 len = sprintf(buf, "%s\n", pval);
1405 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1406 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1407 OP_STATE(~ha->ip_config.tcp_options,
1408 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1410 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1411 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1413 len = sprintf(buf, "%s\n", pval);
1415 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1416 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1417 OP_STATE(~ha->ip_config.tcp_options,
1418 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1420 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1421 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1424 len = sprintf(buf, "%s\n", pval);
1426 case ISCSI_NET_PARAM_TCP_WSF:
1427 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1428 len = sprintf(buf, "%d\n",
1429 ha->ip_config.tcp_wsf);
1431 len = sprintf(buf, "%d\n",
1432 ha->ip_config.ipv6_tcp_wsf);
1434 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1435 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1436 ival = (ha->ip_config.tcp_options &
1437 TCPOPT_TIMER_SCALE) >> 1;
1439 ival = (ha->ip_config.ipv6_tcp_options &
1440 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1442 len = sprintf(buf, "%d\n", ival);
1444 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1445 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1446 OP_STATE(ha->ip_config.tcp_options,
1447 TCPOPT_TIMESTAMP_ENABLE, pval);
1449 OP_STATE(ha->ip_config.ipv6_tcp_options,
1450 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1452 len = sprintf(buf, "%s\n", pval);
1454 case ISCSI_NET_PARAM_CACHE_ID:
1455 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1456 len = sprintf(buf, "%d\n",
1457 ha->ip_config.ipv4_cache_id);
1459 len = sprintf(buf, "%d\n",
1460 ha->ip_config.ipv6_cache_id);
1462 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1463 OP_STATE(ha->ip_config.tcp_options,
1464 TCPOPT_DNS_SERVER_IP_EN, pval);
1466 len = sprintf(buf, "%s\n", pval);
1468 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1469 OP_STATE(ha->ip_config.tcp_options,
1470 TCPOPT_SLP_DA_INFO_EN, pval);
1472 len = sprintf(buf, "%s\n", pval);
1474 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1475 OP_STATE(ha->ip_config.ipv4_options,
1476 IPOPT_IPV4_TOS_EN, pval);
1478 len = sprintf(buf, "%s\n", pval);
1480 case ISCSI_NET_PARAM_IPV4_TOS:
1481 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1483 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1484 OP_STATE(ha->ip_config.ipv4_options,
1485 IPOPT_GRAT_ARP_EN, pval);
1487 len = sprintf(buf, "%s\n", pval);
1489 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1490 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1493 len = sprintf(buf, "%s\n", pval);
1495 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1496 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1497 (char *)ha->ip_config.ipv4_alt_cid : "";
1499 len = sprintf(buf, "%s\n", pval);
1501 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1502 OP_STATE(ha->ip_config.ipv4_options,
1503 IPOPT_REQ_VID_EN, pval);
1505 len = sprintf(buf, "%s\n", pval);
1507 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1508 OP_STATE(ha->ip_config.ipv4_options,
1509 IPOPT_USE_VID_EN, pval);
1511 len = sprintf(buf, "%s\n", pval);
1513 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1514 pval = (ha->ip_config.ipv4_vid_len) ?
1515 (char *)ha->ip_config.ipv4_vid : "";
1517 len = sprintf(buf, "%s\n", pval);
1519 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1520 OP_STATE(ha->ip_config.ipv4_options,
1521 IPOPT_LEARN_IQN_EN, pval);
1523 len = sprintf(buf, "%s\n", pval);
1525 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1526 OP_STATE(~ha->ip_config.ipv4_options,
1527 IPOPT_FRAGMENTATION_DISABLE, pval);
1529 len = sprintf(buf, "%s\n", pval);
1531 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1532 OP_STATE(ha->ip_config.ipv4_options,
1533 IPOPT_IN_FORWARD_EN, pval);
1535 len = sprintf(buf, "%s\n", pval);
1537 case ISCSI_NET_PARAM_REDIRECT_EN:
1538 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1539 OP_STATE(ha->ip_config.ipv4_options,
1540 IPOPT_ARP_REDIRECT_EN, pval);
1542 OP_STATE(ha->ip_config.ipv6_options,
1543 IPV6_OPT_REDIRECT_EN, pval);
1545 len = sprintf(buf, "%s\n", pval);
1547 case ISCSI_NET_PARAM_IPV4_TTL:
1548 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1550 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1551 OP_STATE(ha->ip_config.ipv6_options,
1552 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1554 len = sprintf(buf, "%s\n", pval);
1556 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1557 OP_STATE(ha->ip_config.ipv6_addl_options,
1558 IPV6_ADDOPT_MLD_EN, pval);
1560 len = sprintf(buf, "%s\n", pval);
1562 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1563 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1565 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1566 len = sprintf(buf, "%d\n",
1567 ha->ip_config.ipv6_traffic_class);
1569 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1570 len = sprintf(buf, "%d\n",
1571 ha->ip_config.ipv6_hop_limit);
1573 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1574 len = sprintf(buf, "%d\n",
1575 ha->ip_config.ipv6_nd_reach_time);
1577 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1578 len = sprintf(buf, "%d\n",
1579 ha->ip_config.ipv6_nd_rexmit_timer);
1581 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1582 len = sprintf(buf, "%d\n",
1583 ha->ip_config.ipv6_nd_stale_timeout);
1585 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1586 len = sprintf(buf, "%d\n",
1587 ha->ip_config.ipv6_dup_addr_detect_count);
1589 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1590 len = sprintf(buf, "%d\n",
1591 ha->ip_config.ipv6_gw_advrt_mtu);
1596 } else if (param_type == ISCSI_IFACE_PARAM) {
1598 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1599 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1601 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1602 OP_STATE(ha->ip_config.iscsi_options,
1603 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1605 len = sprintf(buf, "%s\n", pval);
1607 case ISCSI_IFACE_PARAM_DATADGST_EN:
1608 OP_STATE(ha->ip_config.iscsi_options,
1609 ISCSIOPTS_DATA_DIGEST_EN, pval);
1611 len = sprintf(buf, "%s\n", pval);
1613 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1614 OP_STATE(ha->ip_config.iscsi_options,
1615 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1617 len = sprintf(buf, "%s\n", pval);
1619 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1620 OP_STATE(ha->ip_config.iscsi_options,
1621 ISCSIOPTS_INITIAL_R2T_EN, pval);
1623 len = sprintf(buf, "%s\n", pval);
1625 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1626 OP_STATE(ha->ip_config.iscsi_options,
1627 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1629 len = sprintf(buf, "%s\n", pval);
1631 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1632 OP_STATE(ha->ip_config.iscsi_options,
1633 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1635 len = sprintf(buf, "%s\n", pval);
1637 case ISCSI_IFACE_PARAM_ERL:
1638 len = sprintf(buf, "%d\n",
1639 (ha->ip_config.iscsi_options &
1642 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1643 len = sprintf(buf, "%u\n",
1644 ha->ip_config.iscsi_max_pdu_size *
1647 case ISCSI_IFACE_PARAM_FIRST_BURST:
1648 len = sprintf(buf, "%u\n",
1649 ha->ip_config.iscsi_first_burst_len *
1652 case ISCSI_IFACE_PARAM_MAX_R2T:
1653 len = sprintf(buf, "%d\n",
1654 ha->ip_config.iscsi_max_outstnd_r2t);
1656 case ISCSI_IFACE_PARAM_MAX_BURST:
1657 len = sprintf(buf, "%u\n",
1658 ha->ip_config.iscsi_max_burst_len *
1661 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1662 OP_STATE(ha->ip_config.iscsi_options,
1663 ISCSIOPTS_CHAP_AUTH_EN, pval);
1665 len = sprintf(buf, "%s\n", pval);
1667 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1668 OP_STATE(ha->ip_config.iscsi_options,
1669 ISCSIOPTS_BIDI_CHAP_EN, pval);
1671 len = sprintf(buf, "%s\n", pval);
1673 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1674 OP_STATE(ha->ip_config.iscsi_options,
1675 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1677 len = sprintf(buf, "%s\n", pval);
1679 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1680 OP_STATE(ha->ip_config.iscsi_options,
1681 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1683 len = sprintf(buf, "%s\n", pval);
1685 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1686 OP_STATE(ha->ip_config.iscsi_options,
1687 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1689 len = sprintf(buf, "%s\n", pval);
1691 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1692 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1702 static struct iscsi_endpoint *
1703 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1707 struct iscsi_endpoint *ep;
1708 struct qla_endpoint *qla_ep;
1709 struct scsi_qla_host *ha;
1710 struct sockaddr_in *addr;
1711 struct sockaddr_in6 *addr6;
1715 pr_err("%s: shost is NULL\n", __func__);
1716 return ERR_PTR(ret);
1719 ha = iscsi_host_priv(shost);
1720 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1723 return ERR_PTR(ret);
1726 qla_ep = ep->dd_data;
1727 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1728 if (dst_addr->sa_family == AF_INET) {
1729 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1730 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1731 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1732 (char *)&addr->sin_addr));
1733 } else if (dst_addr->sa_family == AF_INET6) {
1734 memcpy(&qla_ep->dst_addr, dst_addr,
1735 sizeof(struct sockaddr_in6));
1736 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1737 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1738 (char *)&addr6->sin6_addr));
1740 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1744 qla_ep->host = shost;
1749 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1751 struct qla_endpoint *qla_ep;
1752 struct scsi_qla_host *ha;
1755 qla_ep = ep->dd_data;
1756 ha = to_qla_host(qla_ep->host);
1757 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1759 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1765 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1767 struct qla_endpoint *qla_ep;
1768 struct scsi_qla_host *ha;
1770 qla_ep = ep->dd_data;
1771 ha = to_qla_host(qla_ep->host);
1772 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1774 iscsi_destroy_endpoint(ep);
1777 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1778 enum iscsi_param param,
1781 struct qla_endpoint *qla_ep = ep->dd_data;
1782 struct sockaddr *dst_addr;
1783 struct scsi_qla_host *ha;
1788 ha = to_qla_host(qla_ep->host);
1789 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1793 case ISCSI_PARAM_CONN_PORT:
1794 case ISCSI_PARAM_CONN_ADDRESS:
1795 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1799 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1800 &qla_ep->dst_addr, param, buf);
1806 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1807 struct iscsi_stats *stats)
1809 struct iscsi_session *sess;
1810 struct iscsi_cls_session *cls_sess;
1811 struct ddb_entry *ddb_entry;
1812 struct scsi_qla_host *ha;
1813 struct ql_iscsi_stats *ql_iscsi_stats;
1816 dma_addr_t iscsi_stats_dma;
1818 cls_sess = iscsi_conn_to_session(cls_conn);
1819 sess = cls_sess->dd_data;
1820 ddb_entry = sess->dd_data;
1823 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1825 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1826 /* Allocate memory */
1827 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1828 &iscsi_stats_dma, GFP_KERNEL);
1829 if (!ql_iscsi_stats) {
1830 ql4_printk(KERN_ERR, ha,
1831 "Unable to allocate memory for iscsi stats\n");
1832 goto exit_get_stats;
1835 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1837 if (ret != QLA_SUCCESS) {
1838 ql4_printk(KERN_ERR, ha,
1839 "Unable to retrieve iscsi stats\n");
1844 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1845 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1847 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1848 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1849 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1850 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1851 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1852 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1853 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1854 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1856 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1857 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1858 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1859 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1860 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1861 stats->logoutrsp_pdus =
1862 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1863 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1864 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1865 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1868 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1874 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1876 struct iscsi_cls_session *session;
1877 unsigned long flags;
1878 enum blk_eh_timer_return ret = BLK_EH_DONE;
1880 session = starget_to_session(scsi_target(sc->device));
1882 spin_lock_irqsave(&session->lock, flags);
1883 if (session->state == ISCSI_SESSION_FAILED)
1884 ret = BLK_EH_RESET_TIMER;
1885 spin_unlock_irqrestore(&session->lock, flags);
1890 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1892 struct scsi_qla_host *ha = to_qla_host(shost);
1893 struct iscsi_cls_host *ihost = shost->shost_data;
1894 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1896 qla4xxx_get_firmware_state(ha);
1898 switch (ha->addl_fw_state & 0x0F00) {
1899 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1900 speed = ISCSI_PORT_SPEED_10MBPS;
1902 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1903 speed = ISCSI_PORT_SPEED_100MBPS;
1905 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1906 speed = ISCSI_PORT_SPEED_1GBPS;
1908 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1909 speed = ISCSI_PORT_SPEED_10GBPS;
1912 ihost->port_speed = speed;
1915 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1917 struct scsi_qla_host *ha = to_qla_host(shost);
1918 struct iscsi_cls_host *ihost = shost->shost_data;
1919 uint32_t state = ISCSI_PORT_STATE_DOWN;
1921 if (test_bit(AF_LINK_UP, &ha->flags))
1922 state = ISCSI_PORT_STATE_UP;
1924 ihost->port_state = state;
1927 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1928 enum iscsi_host_param param, char *buf)
1930 struct scsi_qla_host *ha = to_qla_host(shost);
1934 case ISCSI_HOST_PARAM_HWADDRESS:
1935 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1937 case ISCSI_HOST_PARAM_IPADDRESS:
1938 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1940 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1941 len = sprintf(buf, "%s\n", ha->name_string);
1943 case ISCSI_HOST_PARAM_PORT_STATE:
1944 qla4xxx_set_port_state(shost);
1945 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1947 case ISCSI_HOST_PARAM_PORT_SPEED:
1948 qla4xxx_set_port_speed(shost);
1949 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1958 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1964 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1965 &qla4xxx_iscsi_transport,
1966 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1967 if (!ha->iface_ipv4)
1968 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1972 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1974 if (!ha->iface_ipv6_0)
1976 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1977 &qla4xxx_iscsi_transport,
1978 ISCSI_IFACE_TYPE_IPV6, 0,
1980 if (!ha->iface_ipv6_0)
1981 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1984 if (!ha->iface_ipv6_1)
1986 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1987 &qla4xxx_iscsi_transport,
1988 ISCSI_IFACE_TYPE_IPV6, 1,
1990 if (!ha->iface_ipv6_1)
1991 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1995 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1997 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1998 qla4xxx_create_ipv4_iface(ha);
2000 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
2001 qla4xxx_create_ipv6_iface(ha);
2004 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
2006 if (ha->iface_ipv4) {
2007 iscsi_destroy_iface(ha->iface_ipv4);
2008 ha->iface_ipv4 = NULL;
2012 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
2014 if (ha->iface_ipv6_0) {
2015 iscsi_destroy_iface(ha->iface_ipv6_0);
2016 ha->iface_ipv6_0 = NULL;
2018 if (ha->iface_ipv6_1) {
2019 iscsi_destroy_iface(ha->iface_ipv6_1);
2020 ha->iface_ipv6_1 = NULL;
2024 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
2026 qla4xxx_destroy_ipv4_iface(ha);
2027 qla4xxx_destroy_ipv6_iface(ha);
2030 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2031 struct iscsi_iface_param_info *iface_param,
2032 struct addr_ctrl_blk *init_fw_cb)
2035 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2036 * iface_num 1 is valid only for IPv6 Addr.
2038 switch (iface_param->param) {
2039 case ISCSI_NET_PARAM_IPV6_ADDR:
2040 if (iface_param->iface_num & 0x1)
2042 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2043 sizeof(init_fw_cb->ipv6_addr1));
2046 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2047 sizeof(init_fw_cb->ipv6_addr0));
2049 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2050 if (iface_param->iface_num & 0x1)
2052 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2053 sizeof(init_fw_cb->ipv6_if_id));
2055 case ISCSI_NET_PARAM_IPV6_ROUTER:
2056 if (iface_param->iface_num & 0x1)
2058 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2059 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2061 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2062 /* Autocfg applies to even interface */
2063 if (iface_param->iface_num & 0x1)
2066 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2067 init_fw_cb->ipv6_addtl_opts &=
2069 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2070 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2071 init_fw_cb->ipv6_addtl_opts |=
2073 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2075 ql4_printk(KERN_ERR, ha,
2076 "Invalid autocfg setting for IPv6 addr\n");
2078 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2079 /* Autocfg applies to even interface */
2080 if (iface_param->iface_num & 0x1)
2083 if (iface_param->value[0] ==
2084 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2085 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2086 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2087 else if (iface_param->value[0] ==
2088 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2089 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2090 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2092 ql4_printk(KERN_ERR, ha,
2093 "Invalid autocfg setting for IPv6 linklocal addr\n");
2095 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2096 /* Autocfg applies to even interface */
2097 if (iface_param->iface_num & 0x1)
2100 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2101 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2102 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2104 case ISCSI_NET_PARAM_IFACE_ENABLE:
2105 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2106 init_fw_cb->ipv6_opts |=
2107 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2108 qla4xxx_create_ipv6_iface(ha);
2110 init_fw_cb->ipv6_opts &=
2111 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2113 qla4xxx_destroy_ipv6_iface(ha);
2116 case ISCSI_NET_PARAM_VLAN_TAG:
2117 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2119 init_fw_cb->ipv6_vlan_tag =
2120 cpu_to_be16(*(uint16_t *)iface_param->value);
2122 case ISCSI_NET_PARAM_VLAN_ENABLED:
2123 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2124 init_fw_cb->ipv6_opts |=
2125 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2127 init_fw_cb->ipv6_opts &=
2128 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2130 case ISCSI_NET_PARAM_MTU:
2131 init_fw_cb->eth_mtu_size =
2132 cpu_to_le16(*(uint16_t *)iface_param->value);
2134 case ISCSI_NET_PARAM_PORT:
2135 /* Autocfg applies to even interface */
2136 if (iface_param->iface_num & 0x1)
2139 init_fw_cb->ipv6_port =
2140 cpu_to_le16(*(uint16_t *)iface_param->value);
2142 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2143 if (iface_param->iface_num & 0x1)
2145 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2146 init_fw_cb->ipv6_tcp_opts |=
2147 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2149 init_fw_cb->ipv6_tcp_opts &=
2150 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2153 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2154 if (iface_param->iface_num & 0x1)
2156 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2157 init_fw_cb->ipv6_tcp_opts |=
2158 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2160 init_fw_cb->ipv6_tcp_opts &=
2161 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2163 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2164 if (iface_param->iface_num & 0x1)
2166 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2167 init_fw_cb->ipv6_tcp_opts |=
2168 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2170 init_fw_cb->ipv6_tcp_opts &=
2171 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2173 case ISCSI_NET_PARAM_TCP_WSF:
2174 if (iface_param->iface_num & 0x1)
2176 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2178 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2179 if (iface_param->iface_num & 0x1)
2181 init_fw_cb->ipv6_tcp_opts &=
2182 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2183 init_fw_cb->ipv6_tcp_opts |=
2184 cpu_to_le16((iface_param->value[0] << 1) &
2185 IPV6_TCPOPT_TIMER_SCALE);
2187 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2188 if (iface_param->iface_num & 0x1)
2190 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2191 init_fw_cb->ipv6_tcp_opts |=
2192 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2194 init_fw_cb->ipv6_tcp_opts &=
2195 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2197 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2198 if (iface_param->iface_num & 0x1)
2200 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2201 init_fw_cb->ipv6_opts |=
2202 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2204 init_fw_cb->ipv6_opts &=
2205 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2207 case ISCSI_NET_PARAM_REDIRECT_EN:
2208 if (iface_param->iface_num & 0x1)
2210 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2211 init_fw_cb->ipv6_opts |=
2212 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2214 init_fw_cb->ipv6_opts &=
2215 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2217 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2218 if (iface_param->iface_num & 0x1)
2220 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2221 init_fw_cb->ipv6_addtl_opts |=
2222 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2224 init_fw_cb->ipv6_addtl_opts &=
2225 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2227 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2228 if (iface_param->iface_num & 0x1)
2230 init_fw_cb->ipv6_flow_lbl =
2231 cpu_to_le16(*(uint16_t *)iface_param->value);
2233 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2234 if (iface_param->iface_num & 0x1)
2236 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2238 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2239 if (iface_param->iface_num & 0x1)
2241 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2243 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2244 if (iface_param->iface_num & 0x1)
2246 init_fw_cb->ipv6_nd_reach_time =
2247 cpu_to_le32(*(uint32_t *)iface_param->value);
2249 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2250 if (iface_param->iface_num & 0x1)
2252 init_fw_cb->ipv6_nd_rexmit_timer =
2253 cpu_to_le32(*(uint32_t *)iface_param->value);
2255 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2256 if (iface_param->iface_num & 0x1)
2258 init_fw_cb->ipv6_nd_stale_timeout =
2259 cpu_to_le32(*(uint32_t *)iface_param->value);
2261 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2262 if (iface_param->iface_num & 0x1)
2264 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2266 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2267 if (iface_param->iface_num & 0x1)
2269 init_fw_cb->ipv6_gw_advrt_mtu =
2270 cpu_to_le32(*(uint32_t *)iface_param->value);
2273 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2274 iface_param->param);
2279 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2280 struct iscsi_iface_param_info *iface_param,
2281 struct addr_ctrl_blk *init_fw_cb)
2283 switch (iface_param->param) {
2284 case ISCSI_NET_PARAM_IPV4_ADDR:
2285 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2286 sizeof(init_fw_cb->ipv4_addr));
2288 case ISCSI_NET_PARAM_IPV4_SUBNET:
2289 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2290 sizeof(init_fw_cb->ipv4_subnet));
2292 case ISCSI_NET_PARAM_IPV4_GW:
2293 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2294 sizeof(init_fw_cb->ipv4_gw_addr));
2296 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2297 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2298 init_fw_cb->ipv4_tcp_opts |=
2299 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2300 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2301 init_fw_cb->ipv4_tcp_opts &=
2302 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2304 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2306 case ISCSI_NET_PARAM_IFACE_ENABLE:
2307 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2308 init_fw_cb->ipv4_ip_opts |=
2309 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2310 qla4xxx_create_ipv4_iface(ha);
2312 init_fw_cb->ipv4_ip_opts &=
2313 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2315 qla4xxx_destroy_ipv4_iface(ha);
2318 case ISCSI_NET_PARAM_VLAN_TAG:
2319 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2321 init_fw_cb->ipv4_vlan_tag =
2322 cpu_to_be16(*(uint16_t *)iface_param->value);
2324 case ISCSI_NET_PARAM_VLAN_ENABLED:
2325 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2326 init_fw_cb->ipv4_ip_opts |=
2327 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2329 init_fw_cb->ipv4_ip_opts &=
2330 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2332 case ISCSI_NET_PARAM_MTU:
2333 init_fw_cb->eth_mtu_size =
2334 cpu_to_le16(*(uint16_t *)iface_param->value);
2336 case ISCSI_NET_PARAM_PORT:
2337 init_fw_cb->ipv4_port =
2338 cpu_to_le16(*(uint16_t *)iface_param->value);
2340 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2341 if (iface_param->iface_num & 0x1)
2343 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2344 init_fw_cb->ipv4_tcp_opts |=
2345 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2347 init_fw_cb->ipv4_tcp_opts &=
2348 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2351 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2352 if (iface_param->iface_num & 0x1)
2354 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2355 init_fw_cb->ipv4_tcp_opts |=
2356 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2358 init_fw_cb->ipv4_tcp_opts &=
2359 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2361 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2362 if (iface_param->iface_num & 0x1)
2364 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2365 init_fw_cb->ipv4_tcp_opts |=
2366 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2368 init_fw_cb->ipv4_tcp_opts &=
2369 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2371 case ISCSI_NET_PARAM_TCP_WSF:
2372 if (iface_param->iface_num & 0x1)
2374 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2376 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2377 if (iface_param->iface_num & 0x1)
2379 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2380 init_fw_cb->ipv4_tcp_opts |=
2381 cpu_to_le16((iface_param->value[0] << 1) &
2382 TCPOPT_TIMER_SCALE);
2384 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2385 if (iface_param->iface_num & 0x1)
2387 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2388 init_fw_cb->ipv4_tcp_opts |=
2389 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2391 init_fw_cb->ipv4_tcp_opts &=
2392 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2394 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2395 if (iface_param->iface_num & 0x1)
2397 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2398 init_fw_cb->ipv4_tcp_opts |=
2399 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2401 init_fw_cb->ipv4_tcp_opts &=
2402 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2404 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2405 if (iface_param->iface_num & 0x1)
2407 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2408 init_fw_cb->ipv4_tcp_opts |=
2409 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2411 init_fw_cb->ipv4_tcp_opts &=
2412 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2414 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2415 if (iface_param->iface_num & 0x1)
2417 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2418 init_fw_cb->ipv4_ip_opts |=
2419 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2421 init_fw_cb->ipv4_ip_opts &=
2422 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2424 case ISCSI_NET_PARAM_IPV4_TOS:
2425 if (iface_param->iface_num & 0x1)
2427 init_fw_cb->ipv4_tos = iface_param->value[0];
2429 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2430 if (iface_param->iface_num & 0x1)
2432 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2433 init_fw_cb->ipv4_ip_opts |=
2434 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2436 init_fw_cb->ipv4_ip_opts &=
2437 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2439 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2440 if (iface_param->iface_num & 0x1)
2442 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2443 init_fw_cb->ipv4_ip_opts |=
2444 cpu_to_le16(IPOPT_ALT_CID_EN);
2446 init_fw_cb->ipv4_ip_opts &=
2447 cpu_to_le16(~IPOPT_ALT_CID_EN);
2449 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2450 if (iface_param->iface_num & 0x1)
2452 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2453 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2454 init_fw_cb->ipv4_dhcp_alt_cid_len =
2455 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2457 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2458 if (iface_param->iface_num & 0x1)
2460 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2461 init_fw_cb->ipv4_ip_opts |=
2462 cpu_to_le16(IPOPT_REQ_VID_EN);
2464 init_fw_cb->ipv4_ip_opts &=
2465 cpu_to_le16(~IPOPT_REQ_VID_EN);
2467 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2468 if (iface_param->iface_num & 0x1)
2470 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2471 init_fw_cb->ipv4_ip_opts |=
2472 cpu_to_le16(IPOPT_USE_VID_EN);
2474 init_fw_cb->ipv4_ip_opts &=
2475 cpu_to_le16(~IPOPT_USE_VID_EN);
2477 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2478 if (iface_param->iface_num & 0x1)
2480 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2481 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2482 init_fw_cb->ipv4_dhcp_vid_len =
2483 strlen(init_fw_cb->ipv4_dhcp_vid);
2485 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2486 if (iface_param->iface_num & 0x1)
2488 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2489 init_fw_cb->ipv4_ip_opts |=
2490 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2492 init_fw_cb->ipv4_ip_opts &=
2493 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2495 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2496 if (iface_param->iface_num & 0x1)
2498 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2499 init_fw_cb->ipv4_ip_opts |=
2500 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2502 init_fw_cb->ipv4_ip_opts &=
2503 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2505 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2506 if (iface_param->iface_num & 0x1)
2508 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2509 init_fw_cb->ipv4_ip_opts |=
2510 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2512 init_fw_cb->ipv4_ip_opts &=
2513 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2515 case ISCSI_NET_PARAM_REDIRECT_EN:
2516 if (iface_param->iface_num & 0x1)
2518 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2519 init_fw_cb->ipv4_ip_opts |=
2520 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2522 init_fw_cb->ipv4_ip_opts &=
2523 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2525 case ISCSI_NET_PARAM_IPV4_TTL:
2526 if (iface_param->iface_num & 0x1)
2528 init_fw_cb->ipv4_ttl = iface_param->value[0];
2531 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2532 iface_param->param);
2537 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2538 struct iscsi_iface_param_info *iface_param,
2539 struct addr_ctrl_blk *init_fw_cb)
2541 switch (iface_param->param) {
2542 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2543 if (iface_param->iface_num & 0x1)
2545 init_fw_cb->def_timeout =
2546 cpu_to_le16(*(uint16_t *)iface_param->value);
2548 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2549 if (iface_param->iface_num & 0x1)
2551 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2552 init_fw_cb->iscsi_opts |=
2553 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2555 init_fw_cb->iscsi_opts &=
2556 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2558 case ISCSI_IFACE_PARAM_DATADGST_EN:
2559 if (iface_param->iface_num & 0x1)
2561 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2562 init_fw_cb->iscsi_opts |=
2563 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2565 init_fw_cb->iscsi_opts &=
2566 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2568 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2569 if (iface_param->iface_num & 0x1)
2571 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2572 init_fw_cb->iscsi_opts |=
2573 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2575 init_fw_cb->iscsi_opts &=
2576 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2578 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2579 if (iface_param->iface_num & 0x1)
2581 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2582 init_fw_cb->iscsi_opts |=
2583 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2585 init_fw_cb->iscsi_opts &=
2586 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2588 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2589 if (iface_param->iface_num & 0x1)
2591 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2592 init_fw_cb->iscsi_opts |=
2593 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2595 init_fw_cb->iscsi_opts &=
2596 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2598 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2599 if (iface_param->iface_num & 0x1)
2601 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2602 init_fw_cb->iscsi_opts |=
2603 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2605 init_fw_cb->iscsi_opts &=
2606 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2608 case ISCSI_IFACE_PARAM_ERL:
2609 if (iface_param->iface_num & 0x1)
2611 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2612 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2615 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2616 if (iface_param->iface_num & 0x1)
2618 init_fw_cb->iscsi_max_pdu_size =
2619 cpu_to_le32(*(uint32_t *)iface_param->value) /
2622 case ISCSI_IFACE_PARAM_FIRST_BURST:
2623 if (iface_param->iface_num & 0x1)
2625 init_fw_cb->iscsi_fburst_len =
2626 cpu_to_le32(*(uint32_t *)iface_param->value) /
2629 case ISCSI_IFACE_PARAM_MAX_R2T:
2630 if (iface_param->iface_num & 0x1)
2632 init_fw_cb->iscsi_max_outstnd_r2t =
2633 cpu_to_le16(*(uint16_t *)iface_param->value);
2635 case ISCSI_IFACE_PARAM_MAX_BURST:
2636 if (iface_param->iface_num & 0x1)
2638 init_fw_cb->iscsi_max_burst_len =
2639 cpu_to_le32(*(uint32_t *)iface_param->value) /
2642 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2643 if (iface_param->iface_num & 0x1)
2645 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2646 init_fw_cb->iscsi_opts |=
2647 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2649 init_fw_cb->iscsi_opts &=
2650 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2652 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2653 if (iface_param->iface_num & 0x1)
2655 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2656 init_fw_cb->iscsi_opts |=
2657 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2659 init_fw_cb->iscsi_opts &=
2660 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2662 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2663 if (iface_param->iface_num & 0x1)
2665 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2666 init_fw_cb->iscsi_opts |=
2667 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2669 init_fw_cb->iscsi_opts &=
2670 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2672 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2673 if (iface_param->iface_num & 0x1)
2675 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2676 init_fw_cb->iscsi_opts |=
2677 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2679 init_fw_cb->iscsi_opts &=
2680 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2682 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2683 if (iface_param->iface_num & 0x1)
2685 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2686 init_fw_cb->iscsi_opts |=
2687 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2689 init_fw_cb->iscsi_opts &=
2690 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2693 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2694 iface_param->param);
2700 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2702 struct addr_ctrl_blk_def *acb;
2703 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2704 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2705 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2706 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2707 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2708 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2709 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2710 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2711 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2712 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2713 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2714 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2715 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2716 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2717 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2718 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2722 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2724 struct scsi_qla_host *ha = to_qla_host(shost);
2726 struct iscsi_iface_param_info *iface_param = NULL;
2727 struct addr_ctrl_blk *init_fw_cb = NULL;
2728 dma_addr_t init_fw_cb_dma;
2729 uint32_t mbox_cmd[MBOX_REG_COUNT];
2730 uint32_t mbox_sts[MBOX_REG_COUNT];
2732 struct nlattr *attr;
2734 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2735 sizeof(struct addr_ctrl_blk),
2736 &init_fw_cb_dma, GFP_KERNEL);
2738 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2743 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2744 memset(&mbox_sts, 0, sizeof(mbox_sts));
2746 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2747 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2749 goto exit_init_fw_cb;
2752 nla_for_each_attr(attr, data, len, rem) {
2753 iface_param = nla_data(attr);
2755 if (iface_param->param_type == ISCSI_NET_PARAM) {
2756 switch (iface_param->iface_type) {
2757 case ISCSI_IFACE_TYPE_IPV4:
2758 switch (iface_param->iface_num) {
2760 qla4xxx_set_ipv4(ha, iface_param,
2764 /* Cannot have more than one IPv4 interface */
2765 ql4_printk(KERN_ERR, ha,
2766 "Invalid IPv4 iface number = %d\n",
2767 iface_param->iface_num);
2771 case ISCSI_IFACE_TYPE_IPV6:
2772 switch (iface_param->iface_num) {
2775 qla4xxx_set_ipv6(ha, iface_param,
2779 /* Cannot have more than two IPv6 interface */
2780 ql4_printk(KERN_ERR, ha,
2781 "Invalid IPv6 iface number = %d\n",
2782 iface_param->iface_num);
2787 ql4_printk(KERN_ERR, ha,
2788 "Invalid iface type\n");
2791 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2792 qla4xxx_set_iscsi_param(ha, iface_param,
2799 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2801 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2802 sizeof(struct addr_ctrl_blk),
2803 FLASH_OPT_RMW_COMMIT);
2804 if (rval != QLA_SUCCESS) {
2805 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2808 goto exit_init_fw_cb;
2811 rval = qla4xxx_disable_acb(ha);
2812 if (rval != QLA_SUCCESS) {
2813 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2816 goto exit_init_fw_cb;
2819 wait_for_completion_timeout(&ha->disable_acb_comp,
2820 DISABLE_ACB_TOV * HZ);
2822 qla4xxx_initcb_to_acb(init_fw_cb);
2824 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2825 if (rval != QLA_SUCCESS) {
2826 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2829 goto exit_init_fw_cb;
2832 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2833 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2837 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2838 init_fw_cb, init_fw_cb_dma);
2843 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2844 enum iscsi_param param, char *buf)
2846 struct iscsi_session *sess = cls_sess->dd_data;
2847 struct ddb_entry *ddb_entry = sess->dd_data;
2848 struct scsi_qla_host *ha = ddb_entry->ha;
2849 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2850 struct ql4_chap_table chap_tbl;
2854 memset(&chap_tbl, 0, sizeof(chap_tbl));
2856 case ISCSI_PARAM_CHAP_IN_IDX:
2857 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2858 sess->password_in, BIDI_CHAP,
2861 len = sprintf(buf, "\n");
2863 len = sprintf(buf, "%hu\n", idx);
2865 case ISCSI_PARAM_CHAP_OUT_IDX:
2866 if (ddb_entry->ddb_type == FLASH_DDB) {
2867 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2868 idx = ddb_entry->chap_tbl_idx;
2874 rval = qla4xxx_get_chap_index(ha, sess->username,
2879 len = sprintf(buf, "\n");
2881 len = sprintf(buf, "%hu\n", idx);
2883 case ISCSI_PARAM_USERNAME:
2884 case ISCSI_PARAM_PASSWORD:
2885 /* First, populate session username and password for FLASH DDB,
2886 * if not already done. This happens when session login fails
2889 if (ddb_entry->ddb_type == FLASH_DDB &&
2890 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2891 !sess->username && !sess->password) {
2892 idx = ddb_entry->chap_tbl_idx;
2893 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2897 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2898 (char *)chap_tbl.name,
2899 strlen((char *)chap_tbl.name));
2900 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2901 (char *)chap_tbl.secret,
2902 chap_tbl.secret_len);
2907 return iscsi_session_get_param(cls_sess, param, buf);
2913 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2914 enum iscsi_param param, char *buf)
2916 struct iscsi_conn *conn;
2917 struct qla_conn *qla_conn;
2918 struct sockaddr *dst_addr;
2920 conn = cls_conn->dd_data;
2921 qla_conn = conn->dd_data;
2922 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2925 case ISCSI_PARAM_CONN_PORT:
2926 case ISCSI_PARAM_CONN_ADDRESS:
2927 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2928 dst_addr, param, buf);
2930 return iscsi_conn_get_param(cls_conn, param, buf);
2934 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2936 uint32_t mbx_sts = 0;
2937 uint16_t tmp_ddb_index;
2941 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2943 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2944 DEBUG2(ql4_printk(KERN_INFO, ha,
2945 "Free DDB index not available\n"));
2947 goto exit_get_ddb_index;
2950 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2953 DEBUG2(ql4_printk(KERN_INFO, ha,
2954 "Found a free DDB index at %d\n", tmp_ddb_index));
2955 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2956 if (ret == QLA_ERROR) {
2957 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2958 ql4_printk(KERN_INFO, ha,
2959 "DDB index = %d not available trying next\n",
2963 DEBUG2(ql4_printk(KERN_INFO, ha,
2964 "Free FW DDB not available\n"));
2967 *ddb_index = tmp_ddb_index;
2973 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2974 struct ddb_entry *ddb_entry,
2975 char *existing_ipaddr,
2978 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2979 char formatted_ipaddr[DDB_IPADDR_LEN];
2980 int status = QLA_SUCCESS, ret = 0;
2982 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2983 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2989 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2991 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2997 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
3000 if (strcmp(existing_ipaddr, formatted_ipaddr))
3007 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
3008 struct iscsi_cls_conn *cls_conn)
3010 int idx = 0, max_ddbs, rval;
3011 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3012 struct iscsi_session *sess, *existing_sess;
3013 struct iscsi_conn *conn, *existing_conn;
3014 struct ddb_entry *ddb_entry;
3016 sess = cls_sess->dd_data;
3017 conn = cls_conn->dd_data;
3019 if (sess->targetname == NULL ||
3020 conn->persistent_address == NULL ||
3021 conn->persistent_port == 0)
3024 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3027 for (idx = 0; idx < max_ddbs; idx++) {
3028 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3029 if (ddb_entry == NULL)
3032 if (ddb_entry->ddb_type != FLASH_DDB)
3035 existing_sess = ddb_entry->sess->dd_data;
3036 existing_conn = ddb_entry->conn->dd_data;
3038 if (existing_sess->targetname == NULL ||
3039 existing_conn->persistent_address == NULL ||
3040 existing_conn->persistent_port == 0)
3043 DEBUG2(ql4_printk(KERN_INFO, ha,
3044 "IQN = %s User IQN = %s\n",
3045 existing_sess->targetname,
3048 DEBUG2(ql4_printk(KERN_INFO, ha,
3049 "IP = %s User IP = %s\n",
3050 existing_conn->persistent_address,
3051 conn->persistent_address));
3053 DEBUG2(ql4_printk(KERN_INFO, ha,
3054 "Port = %d User Port = %d\n",
3055 existing_conn->persistent_port,
3056 conn->persistent_port));
3058 if (strcmp(existing_sess->targetname, sess->targetname))
3060 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3061 existing_conn->persistent_address,
3062 conn->persistent_address);
3063 if (rval == QLA_ERROR)
3065 if (existing_conn->persistent_port != conn->persistent_port)
3070 if (idx == max_ddbs)
3073 DEBUG2(ql4_printk(KERN_INFO, ha,
3074 "Match found in fwdb sessions\n"));
3078 static struct iscsi_cls_session *
3079 qla4xxx_session_create(struct iscsi_endpoint *ep,
3080 uint16_t cmds_max, uint16_t qdepth,
3081 uint32_t initial_cmdsn)
3083 struct iscsi_cls_session *cls_sess;
3084 struct scsi_qla_host *ha;
3085 struct qla_endpoint *qla_ep;
3086 struct ddb_entry *ddb_entry;
3088 struct iscsi_session *sess;
3092 printk(KERN_ERR "qla4xxx: missing ep.\n");
3096 qla_ep = ep->dd_data;
3097 ha = to_qla_host(qla_ep->host);
3098 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3101 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3102 if (ret == QLA_ERROR)
3105 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3106 cmds_max, sizeof(struct ddb_entry),
3107 sizeof(struct ql4_task_data),
3108 initial_cmdsn, ddb_index);
3112 sess = cls_sess->dd_data;
3113 ddb_entry = sess->dd_data;
3114 ddb_entry->fw_ddb_index = ddb_index;
3115 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3117 ddb_entry->sess = cls_sess;
3118 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3119 ddb_entry->ddb_change = qla4xxx_ddb_change;
3120 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3121 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3122 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3128 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3130 struct iscsi_session *sess;
3131 struct ddb_entry *ddb_entry;
3132 struct scsi_qla_host *ha;
3133 unsigned long flags, wtime;
3134 struct dev_db_entry *fw_ddb_entry = NULL;
3135 dma_addr_t fw_ddb_entry_dma;
3139 sess = cls_sess->dd_data;
3140 ddb_entry = sess->dd_data;
3142 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3145 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3146 &fw_ddb_entry_dma, GFP_KERNEL);
3147 if (!fw_ddb_entry) {
3148 ql4_printk(KERN_ERR, ha,
3149 "%s: Unable to allocate dma buffer\n", __func__);
3150 goto destroy_session;
3153 wtime = jiffies + (HZ * LOGOUT_TOV);
3155 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3156 fw_ddb_entry, fw_ddb_entry_dma,
3157 NULL, NULL, &ddb_state, NULL,
3159 if (ret == QLA_ERROR)
3160 goto destroy_session;
3162 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3163 (ddb_state == DDB_DS_SESSION_FAILED))
3164 goto destroy_session;
3166 schedule_timeout_uninterruptible(HZ);
3167 } while ((time_after(wtime, jiffies)));
3170 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3171 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3172 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3173 spin_lock_irqsave(&ha->hardware_lock, flags);
3174 qla4xxx_free_ddb(ha, ddb_entry);
3175 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3177 iscsi_session_teardown(cls_sess);
3180 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3181 fw_ddb_entry, fw_ddb_entry_dma);
3184 static struct iscsi_cls_conn *
3185 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3187 struct iscsi_cls_conn *cls_conn;
3188 struct iscsi_session *sess;
3189 struct ddb_entry *ddb_entry;
3190 struct scsi_qla_host *ha;
3192 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3195 pr_info("%s: Can not create connection for conn_idx = %u\n",
3196 __func__, conn_idx);
3200 sess = cls_sess->dd_data;
3201 ddb_entry = sess->dd_data;
3202 ddb_entry->conn = cls_conn;
3205 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3210 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3211 struct iscsi_cls_conn *cls_conn,
3212 uint64_t transport_fd, int is_leading)
3214 struct iscsi_conn *conn;
3215 struct qla_conn *qla_conn;
3216 struct iscsi_endpoint *ep;
3217 struct ddb_entry *ddb_entry;
3218 struct scsi_qla_host *ha;
3219 struct iscsi_session *sess;
3221 sess = cls_session->dd_data;
3222 ddb_entry = sess->dd_data;
3225 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3226 cls_session->sid, cls_conn->cid));
3228 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3230 ep = iscsi_lookup_endpoint(transport_fd);
3233 conn = cls_conn->dd_data;
3234 qla_conn = conn->dd_data;
3235 qla_conn->qla_ep = ep->dd_data;
3236 iscsi_put_endpoint(ep);
3240 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3242 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3243 struct iscsi_session *sess;
3244 struct ddb_entry *ddb_entry;
3245 struct scsi_qla_host *ha;
3246 struct dev_db_entry *fw_ddb_entry = NULL;
3247 dma_addr_t fw_ddb_entry_dma;
3248 uint32_t mbx_sts = 0;
3250 int status = QLA_SUCCESS;
3252 sess = cls_sess->dd_data;
3253 ddb_entry = sess->dd_data;
3255 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3256 cls_sess->sid, cls_conn->cid));
3258 /* Check if we have matching FW DDB, if yes then do not
3259 * login to this target. This could cause target to logout previous
3262 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3263 if (ret == QLA_SUCCESS) {
3264 ql4_printk(KERN_INFO, ha,
3265 "Session already exist in FW.\n");
3267 goto exit_conn_start;
3270 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3271 &fw_ddb_entry_dma, GFP_KERNEL);
3272 if (!fw_ddb_entry) {
3273 ql4_printk(KERN_ERR, ha,
3274 "%s: Unable to allocate dma buffer\n", __func__);
3276 goto exit_conn_start;
3279 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3281 /* If iscsid is stopped and started then no need to do
3282 * set param again since ddb state will be already
3283 * active and FW does not allow set ddb to an
3287 if (ddb_entry->fw_ddb_device_state ==
3288 DDB_DS_SESSION_ACTIVE) {
3289 ddb_entry->unblock_sess(ddb_entry->sess);
3290 goto exit_set_param;
3293 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3294 __func__, ddb_entry->fw_ddb_index);
3295 goto exit_conn_start;
3298 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3299 if (status == QLA_ERROR) {
3300 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3303 goto exit_conn_start;
3306 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3307 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3309 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3310 ddb_entry->fw_ddb_device_state));
3317 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3318 fw_ddb_entry, fw_ddb_entry_dma);
3322 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3324 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3325 struct iscsi_session *sess;
3326 struct scsi_qla_host *ha;
3327 struct ddb_entry *ddb_entry;
3330 sess = cls_sess->dd_data;
3331 ddb_entry = sess->dd_data;
3333 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3336 options = LOGOUT_OPTION_CLOSE_SESSION;
3337 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3338 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3341 static void qla4xxx_task_work(struct work_struct *wdata)
3343 struct ql4_task_data *task_data;
3344 struct scsi_qla_host *ha;
3345 struct passthru_status *sts;
3346 struct iscsi_task *task;
3347 struct iscsi_hdr *hdr;
3350 struct iscsi_conn *conn;
3354 task_data = container_of(wdata, struct ql4_task_data, task_work);
3356 task = task_data->task;
3357 sts = &task_data->sts;
3358 hdr_len = sizeof(struct iscsi_hdr);
3360 DEBUG3(printk(KERN_INFO "Status returned\n"));
3361 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3362 DEBUG3(printk(KERN_INFO "Response buffer"));
3363 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3367 switch (sts->completionStatus) {
3368 case PASSTHRU_STATUS_COMPLETE:
3369 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3370 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3373 data = task_data->resp_buffer + hdr_len;
3374 data_len = task_data->resp_len - hdr_len;
3375 iscsi_complete_pdu(conn, hdr, data, data_len);
3378 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3379 sts->completionStatus);
3385 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3387 struct ql4_task_data *task_data;
3388 struct iscsi_session *sess;
3389 struct ddb_entry *ddb_entry;
3390 struct scsi_qla_host *ha;
3393 sess = task->conn->session;
3394 ddb_entry = sess->dd_data;
3396 task_data = task->dd_data;
3397 memset(task_data, 0, sizeof(struct ql4_task_data));
3400 ql4_printk(KERN_INFO, ha,
3401 "%s: SCSI Commands not implemented\n", __func__);
3405 hdr_len = sizeof(struct iscsi_hdr);
3407 task_data->task = task;
3409 if (task->data_count) {
3410 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3415 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3416 __func__, task->conn->max_recv_dlength, hdr_len));
3418 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3419 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3420 task_data->resp_len,
3421 &task_data->resp_dma,
3423 if (!task_data->resp_buffer)
3424 goto exit_alloc_pdu;
3426 task_data->req_len = task->data_count + hdr_len;
3427 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3429 &task_data->req_dma,
3431 if (!task_data->req_buffer)
3432 goto exit_alloc_pdu;
3434 task->hdr = task_data->req_buffer;
3436 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3441 if (task_data->resp_buffer)
3442 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3443 task_data->resp_buffer, task_data->resp_dma);
3445 if (task_data->req_buffer)
3446 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3447 task_data->req_buffer, task_data->req_dma);
3451 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3453 struct ql4_task_data *task_data;
3454 struct iscsi_session *sess;
3455 struct ddb_entry *ddb_entry;
3456 struct scsi_qla_host *ha;
3459 hdr_len = sizeof(struct iscsi_hdr);
3460 sess = task->conn->session;
3461 ddb_entry = sess->dd_data;
3463 task_data = task->dd_data;
3465 if (task->data_count) {
3466 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3467 task->data_count, DMA_TO_DEVICE);
3470 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3471 __func__, task->conn->max_recv_dlength, hdr_len));
3473 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3474 task_data->resp_buffer, task_data->resp_dma);
3475 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3476 task_data->req_buffer, task_data->req_dma);
3480 static int qla4xxx_task_xmit(struct iscsi_task *task)
3482 struct scsi_cmnd *sc = task->sc;
3483 struct iscsi_session *sess = task->conn->session;
3484 struct ddb_entry *ddb_entry = sess->dd_data;
3485 struct scsi_qla_host *ha = ddb_entry->ha;
3488 return qla4xxx_send_passthru0(task);
3490 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3495 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3496 struct iscsi_bus_flash_conn *conn,
3497 struct dev_db_entry *fw_ddb_entry)
3499 unsigned long options = 0;
3502 options = le16_to_cpu(fw_ddb_entry->options);
3503 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3504 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3505 rc = iscsi_switch_str_param(&sess->portal_type,
3510 rc = iscsi_switch_str_param(&sess->portal_type,
3516 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3518 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3519 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3521 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3522 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3523 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3524 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3525 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3526 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3528 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3529 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3530 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3531 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3533 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3534 sess->discovery_auth_optional =
3535 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3536 if (test_bit(ISCSIOPT_ERL1, &options))
3538 if (test_bit(ISCSIOPT_ERL0, &options))
3541 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3542 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3543 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3544 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3545 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3546 conn->tcp_timer_scale |= BIT_3;
3547 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3548 conn->tcp_timer_scale |= BIT_2;
3549 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3550 conn->tcp_timer_scale |= BIT_1;
3552 conn->tcp_timer_scale >>= 1;
3553 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3555 options = le16_to_cpu(fw_ddb_entry->ip_options);
3556 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3558 conn->max_recv_dlength = BYTE_UNITS *
3559 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3560 conn->max_xmit_dlength = BYTE_UNITS *
3561 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3562 sess->first_burst = BYTE_UNITS *
3563 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3564 sess->max_burst = BYTE_UNITS *
3565 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3566 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3567 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3568 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3569 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3570 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3571 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3572 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3573 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3574 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3575 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3576 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3577 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3578 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3579 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3580 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3581 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3583 sess->default_taskmgmt_timeout =
3584 le16_to_cpu(fw_ddb_entry->def_timeout);
3585 conn->port = le16_to_cpu(fw_ddb_entry->port);
3587 options = le16_to_cpu(fw_ddb_entry->options);
3588 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3589 if (!conn->ipaddress) {
3594 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3595 if (!conn->redirect_ipaddr) {
3600 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3601 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3603 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3604 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3606 conn->link_local_ipv6_addr = kmemdup(
3607 fw_ddb_entry->link_local_ipv6_addr,
3608 IPv6_ADDR_LEN, GFP_KERNEL);
3609 if (!conn->link_local_ipv6_addr) {
3614 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3617 if (fw_ddb_entry->iscsi_name[0]) {
3618 rc = iscsi_switch_str_param(&sess->targetname,
3619 (char *)fw_ddb_entry->iscsi_name);
3624 if (fw_ddb_entry->iscsi_alias[0]) {
3625 rc = iscsi_switch_str_param(&sess->targetalias,
3626 (char *)fw_ddb_entry->iscsi_alias);
3631 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3637 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3638 struct iscsi_bus_flash_conn *conn,
3639 struct dev_db_entry *fw_ddb_entry)
3643 options = le16_to_cpu(fw_ddb_entry->options);
3644 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3645 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3650 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3651 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3652 SET_BITVAL(sess->entry_state, options, BIT_3);
3653 fw_ddb_entry->options = cpu_to_le16(options);
3655 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3656 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3657 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3658 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3659 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3660 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3661 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3662 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3663 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3664 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3665 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3666 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3667 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3668 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3669 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3671 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3672 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3673 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3674 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3675 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3676 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3677 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3678 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3679 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3681 options = le16_to_cpu(fw_ddb_entry->ip_options);
3682 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3683 fw_ddb_entry->ip_options = cpu_to_le16(options);
3685 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3686 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3687 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3688 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3689 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3690 fw_ddb_entry->iscsi_first_burst_len =
3691 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3692 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3694 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3695 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3696 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3697 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3698 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3699 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3700 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3701 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3702 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3703 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3704 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3705 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3706 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3707 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3708 fw_ddb_entry->port = cpu_to_le16(conn->port);
3709 fw_ddb_entry->def_timeout =
3710 cpu_to_le16(sess->default_taskmgmt_timeout);
3712 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3713 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3715 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3717 if (conn->ipaddress)
3718 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3719 sizeof(fw_ddb_entry->ip_addr));
3721 if (conn->redirect_ipaddr)
3722 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3723 sizeof(fw_ddb_entry->tgt_addr));
3725 if (conn->link_local_ipv6_addr)
3726 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3727 conn->link_local_ipv6_addr,
3728 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3730 if (sess->targetname)
3731 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3732 sizeof(fw_ddb_entry->iscsi_name));
3734 if (sess->targetalias)
3735 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3736 sizeof(fw_ddb_entry->iscsi_alias));
3738 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3743 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3744 struct iscsi_session *sess,
3745 struct dev_db_entry *fw_ddb_entry)
3747 unsigned long options = 0;
3749 uint16_t disc_parent;
3750 char ip_addr[DDB_IPADDR_LEN];
3752 options = le16_to_cpu(fw_ddb_entry->options);
3753 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3754 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3756 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3758 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3759 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3760 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3761 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3762 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3763 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3765 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3766 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3767 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3769 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3770 sess->discovery_auth_optional =
3771 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3772 if (test_bit(ISCSIOPT_ERL1, &options))
3774 if (test_bit(ISCSIOPT_ERL0, &options))
3777 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3778 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3779 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3780 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3781 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3782 conn->tcp_timer_scale |= BIT_3;
3783 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3784 conn->tcp_timer_scale |= BIT_2;
3785 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3786 conn->tcp_timer_scale |= BIT_1;
3788 conn->tcp_timer_scale >>= 1;
3789 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3791 options = le16_to_cpu(fw_ddb_entry->ip_options);
3792 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3794 conn->max_recv_dlength = BYTE_UNITS *
3795 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3796 conn->max_xmit_dlength = BYTE_UNITS *
3797 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3798 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3799 sess->first_burst = BYTE_UNITS *
3800 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3801 sess->max_burst = BYTE_UNITS *
3802 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3803 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3804 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3805 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3806 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3807 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3808 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3809 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3810 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3811 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3812 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3813 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3814 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3815 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3817 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3818 if (ddb_link == DDB_ISNS)
3819 disc_parent = ISCSI_DISC_PARENT_ISNS;
3820 else if (ddb_link == DDB_NO_LINK)
3821 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3822 else if (ddb_link < MAX_DDB_ENTRIES)
3823 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3825 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3827 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3828 iscsi_get_discovery_parent_name(disc_parent), 0);
3830 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3831 (char *)fw_ddb_entry->iscsi_alias, 0);
3833 options = le16_to_cpu(fw_ddb_entry->options);
3834 if (options & DDB_OPT_IPV6_DEVICE) {
3835 memset(ip_addr, 0, sizeof(ip_addr));
3836 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3837 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3838 (char *)ip_addr, 0);
3842 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3843 struct dev_db_entry *fw_ddb_entry,
3844 struct iscsi_cls_session *cls_sess,
3845 struct iscsi_cls_conn *cls_conn)
3848 struct iscsi_session *sess;
3849 struct ddb_entry *ddb_entry;
3850 struct ql4_chap_table chap_tbl;
3851 struct iscsi_conn *conn;
3852 char ip_addr[DDB_IPADDR_LEN];
3853 uint16_t options = 0;
3855 sess = cls_sess->dd_data;
3856 ddb_entry = sess->dd_data;
3857 conn = cls_conn->dd_data;
3858 memset(&chap_tbl, 0, sizeof(chap_tbl));
3860 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3862 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3864 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3865 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3867 memset(ip_addr, 0, sizeof(ip_addr));
3868 options = le16_to_cpu(fw_ddb_entry->options);
3869 if (options & DDB_OPT_IPV6_DEVICE) {
3870 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3872 memset(ip_addr, 0, sizeof(ip_addr));
3873 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3875 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3876 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3879 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3880 (char *)ip_addr, buflen);
3881 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3882 (char *)fw_ddb_entry->iscsi_name, buflen);
3883 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3884 (char *)ha->name_string, buflen);
3886 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3887 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3889 ddb_entry->chap_tbl_idx)) {
3890 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3891 (char *)chap_tbl.name,
3892 strlen((char *)chap_tbl.name));
3893 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3894 (char *)chap_tbl.secret,
3895 chap_tbl.secret_len);
3900 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3901 struct ddb_entry *ddb_entry)
3903 struct iscsi_cls_session *cls_sess;
3904 struct iscsi_cls_conn *cls_conn;
3906 dma_addr_t fw_ddb_entry_dma;
3907 struct dev_db_entry *fw_ddb_entry;
3909 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3910 &fw_ddb_entry_dma, GFP_KERNEL);
3911 if (!fw_ddb_entry) {
3912 ql4_printk(KERN_ERR, ha,
3913 "%s: Unable to allocate dma buffer\n", __func__);
3914 goto exit_session_conn_fwddb_param;
3917 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3918 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3919 NULL, NULL, NULL) == QLA_ERROR) {
3920 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3921 "get_ddb_entry for fw_ddb_index %d\n",
3922 ha->host_no, __func__,
3923 ddb_entry->fw_ddb_index));
3924 goto exit_session_conn_fwddb_param;
3927 cls_sess = ddb_entry->sess;
3929 cls_conn = ddb_entry->conn;
3932 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3934 exit_session_conn_fwddb_param:
3936 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3937 fw_ddb_entry, fw_ddb_entry_dma);
3940 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3941 struct ddb_entry *ddb_entry)
3943 struct iscsi_cls_session *cls_sess;
3944 struct iscsi_cls_conn *cls_conn;
3945 struct iscsi_session *sess;
3946 struct iscsi_conn *conn;
3948 dma_addr_t fw_ddb_entry_dma;
3949 struct dev_db_entry *fw_ddb_entry;
3951 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3952 &fw_ddb_entry_dma, GFP_KERNEL);
3953 if (!fw_ddb_entry) {
3954 ql4_printk(KERN_ERR, ha,
3955 "%s: Unable to allocate dma buffer\n", __func__);
3956 goto exit_session_conn_param;
3959 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3960 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3961 NULL, NULL, NULL) == QLA_ERROR) {
3962 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3963 "get_ddb_entry for fw_ddb_index %d\n",
3964 ha->host_no, __func__,
3965 ddb_entry->fw_ddb_index));
3966 goto exit_session_conn_param;
3969 cls_sess = ddb_entry->sess;
3970 sess = cls_sess->dd_data;
3972 cls_conn = ddb_entry->conn;
3973 conn = cls_conn->dd_data;
3975 /* Update timers after login */
3976 ddb_entry->default_relogin_timeout =
3977 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3978 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3979 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3980 ddb_entry->default_time2wait =
3981 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3984 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3985 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3987 memcpy(sess->initiatorname, ha->name_string,
3988 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3990 exit_session_conn_param:
3992 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3993 fw_ddb_entry, fw_ddb_entry_dma);
3999 static void qla4xxx_timer(struct timer_list *t);
4001 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
4002 unsigned long interval)
4004 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
4005 __func__, ha->host->host_no));
4006 timer_setup(&ha->timer, qla4xxx_timer, 0);
4007 ha->timer.expires = jiffies + interval * HZ;
4008 add_timer(&ha->timer);
4009 ha->timer_active = 1;
4012 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4014 del_timer_sync(&ha->timer);
4015 ha->timer_active = 0;
4019 * qla4xxx_mark_device_missing - blocks the session
4020 * @cls_session: Pointer to the session to be blocked
4021 * @ddb_entry: Pointer to device database entry
4023 * This routine marks a device missing and close connection.
4025 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4027 iscsi_block_session(cls_session);
4031 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4032 * @ha: Pointer to host adapter structure.
4034 * This routine marks a device missing and resets the relogin retry count.
4036 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4038 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4041 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4042 struct ddb_entry *ddb_entry,
4043 struct scsi_cmnd *cmd)
4047 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4051 kref_init(&srb->srb_ref);
4053 srb->ddb = ddb_entry;
4056 qla4xxx_cmd_priv(cmd)->srb = srb;
4061 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4063 struct scsi_cmnd *cmd = srb->cmd;
4065 if (srb->flags & SRB_DMA_VALID) {
4066 scsi_dma_unmap(cmd);
4067 srb->flags &= ~SRB_DMA_VALID;
4069 qla4xxx_cmd_priv(cmd)->srb = NULL;
4072 void qla4xxx_srb_compl(struct kref *ref)
4074 struct srb *srb = container_of(ref, struct srb, srb_ref);
4075 struct scsi_cmnd *cmd = srb->cmd;
4076 struct scsi_qla_host *ha = srb->ha;
4078 qla4xxx_srb_free_dma(ha, srb);
4080 mempool_free(srb, ha->srb_mempool);
4086 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4088 * @cmd: Pointer to Linux's SCSI command structure
4091 * This routine is invoked by Linux to send a SCSI command to the driver.
4092 * The mid-level driver tries to ensure that queuecommand never gets
4093 * invoked concurrently with itself or the interrupt handler (although
4094 * the interrupt handler may call this routine as part of request-
4095 * completion handling). Unfortunely, it sometimes calls the scheduler
4096 * in interrupt context which is a big NO! NO!.
4098 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4100 struct scsi_qla_host *ha = to_qla_host(host);
4101 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4102 struct iscsi_cls_session *sess = ddb_entry->sess;
4106 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4107 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4108 cmd->result = DID_NO_CONNECT << 16;
4110 cmd->result = DID_REQUEUE << 16;
4111 goto qc_fail_command;
4115 cmd->result = DID_IMM_RETRY << 16;
4116 goto qc_fail_command;
4119 rval = iscsi_session_chkready(sess);
4122 goto qc_fail_command;
4125 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4126 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4127 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4128 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4129 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4130 !test_bit(AF_ONLINE, &ha->flags) ||
4131 !test_bit(AF_LINK_UP, &ha->flags) ||
4132 test_bit(AF_LOOPBACK, &ha->flags) ||
4133 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4134 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4135 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4138 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4142 rval = qla4xxx_send_command_to_isp(ha, srb);
4143 if (rval != QLA_SUCCESS)
4144 goto qc_host_busy_free_sp;
4148 qc_host_busy_free_sp:
4149 qla4xxx_srb_free_dma(ha, srb);
4150 mempool_free(srb, ha->srb_mempool);
4153 return SCSI_MLQUEUE_HOST_BUSY;
4162 * qla4xxx_mem_free - frees memory allocated to adapter
4163 * @ha: Pointer to host adapter structure.
4165 * Frees memory previously allocated by qla4xxx_mem_alloc
4167 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4170 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4178 ha->request_ring = NULL;
4179 ha->request_dma = 0;
4180 ha->response_ring = NULL;
4181 ha->response_dma = 0;
4182 ha->shadow_regs = NULL;
4183 ha->shadow_regs_dma = 0;
4185 ha->fw_dump_size = 0;
4187 /* Free srb pool. */
4188 mempool_destroy(ha->srb_mempool);
4189 ha->srb_mempool = NULL;
4191 dma_pool_destroy(ha->chap_dma_pool);
4193 vfree(ha->chap_list);
4194 ha->chap_list = NULL;
4196 dma_pool_destroy(ha->fw_ddb_dma_pool);
4198 /* release io space registers */
4199 if (is_qla8022(ha)) {
4202 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4203 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4206 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4207 } else if (ha->reg) {
4211 vfree(ha->reset_tmplt.buff);
4213 pci_release_regions(ha->pdev);
4217 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4218 * @ha: Pointer to host adapter structure
4220 * Allocates DMA memory for request and response queues. Also allocates memory
4223 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4225 unsigned long align;
4227 /* Allocate contiguous block of DMA memory for queues. */
4228 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4229 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4230 sizeof(struct shadow_regs) +
4232 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4233 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4234 &ha->queues_dma, GFP_KERNEL);
4235 if (ha->queues == NULL) {
4236 ql4_printk(KERN_WARNING, ha,
4237 "Memory Allocation failed - queues.\n");
4239 goto mem_alloc_error_exit;
4243 * As per RISC alignment requirements -- the bus-address must be a
4244 * multiple of the request-ring size (in bytes).
4247 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4248 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4249 (MEM_ALIGN_VALUE - 1));
4251 /* Update request and response queue pointers. */
4252 ha->request_dma = ha->queues_dma + align;
4253 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4254 ha->response_dma = ha->queues_dma + align +
4255 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4256 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4257 (REQUEST_QUEUE_DEPTH *
4259 ha->shadow_regs_dma = ha->queues_dma + align +
4260 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4261 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4262 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4263 (REQUEST_QUEUE_DEPTH *
4265 (RESPONSE_QUEUE_DEPTH *
4268 /* Allocate memory for srb pool. */
4269 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4270 mempool_free_slab, srb_cachep);
4271 if (ha->srb_mempool == NULL) {
4272 ql4_printk(KERN_WARNING, ha,
4273 "Memory Allocation failed - SRB Pool.\n");
4275 goto mem_alloc_error_exit;
4278 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4279 CHAP_DMA_BLOCK_SIZE, 8, 0);
4281 if (ha->chap_dma_pool == NULL) {
4282 ql4_printk(KERN_WARNING, ha,
4283 "%s: chap_dma_pool allocation failed..\n", __func__);
4284 goto mem_alloc_error_exit;
4287 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4288 DDB_DMA_BLOCK_SIZE, 8, 0);
4290 if (ha->fw_ddb_dma_pool == NULL) {
4291 ql4_printk(KERN_WARNING, ha,
4292 "%s: fw_ddb_dma_pool allocation failed..\n",
4294 goto mem_alloc_error_exit;
4299 mem_alloc_error_exit:
4304 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4305 * @ha: adapter block pointer.
4307 * Note: The caller should not hold the idc lock.
4309 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4311 uint32_t temp, temp_state, temp_val;
4312 int status = QLA_SUCCESS;
4314 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4316 temp_state = qla82xx_get_temp_state(temp);
4317 temp_val = qla82xx_get_temp_val(temp);
4319 if (temp_state == QLA82XX_TEMP_PANIC) {
4320 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4321 " exceeds maximum allowed. Hardware has been shut"
4322 " down.\n", temp_val);
4324 } else if (temp_state == QLA82XX_TEMP_WARN) {
4325 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4326 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4327 " degrees C exceeds operating range."
4328 " Immediate action needed.\n", temp_val);
4330 if (ha->temperature == QLA82XX_TEMP_WARN)
4331 ql4_printk(KERN_INFO, ha, "Device temperature is"
4332 " now %d degrees C in normal range.\n",
4335 ha->temperature = temp_state;
4340 * qla4_8xxx_check_fw_alive - Check firmware health
4341 * @ha: Pointer to host adapter structure.
4343 * Context: Interrupt
4345 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4347 uint32_t fw_heartbeat_counter;
4348 int status = QLA_SUCCESS;
4350 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4351 QLA8XXX_PEG_ALIVE_COUNTER);
4352 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4353 if (fw_heartbeat_counter == 0xffffffff) {
4354 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4355 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4356 ha->host_no, __func__));
4360 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4361 ha->seconds_since_last_heartbeat++;
4362 /* FW not alive after 2 seconds */
4363 if (ha->seconds_since_last_heartbeat == 2) {
4364 ha->seconds_since_last_heartbeat = 0;
4365 qla4_8xxx_dump_peg_reg(ha);
4369 ha->seconds_since_last_heartbeat = 0;
4371 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4375 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4377 uint32_t halt_status;
4378 int halt_status_unrecoverable = 0;
4380 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4382 if (is_qla8022(ha)) {
4383 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4385 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4386 CRB_NIU_XG_PAUSE_CTL_P0 |
4387 CRB_NIU_XG_PAUSE_CTL_P1);
4389 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4390 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4392 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4393 halt_status_unrecoverable = 1;
4394 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4395 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4396 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4398 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4399 halt_status_unrecoverable = 1;
4403 * Since we cannot change dev_state in interrupt context,
4404 * set appropriate DPC flag then wakeup DPC
4406 if (halt_status_unrecoverable) {
4407 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4409 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4411 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4413 qla4xxx_mailbox_premature_completion(ha);
4414 qla4xxx_wake_dpc(ha);
4418 * qla4_8xxx_watchdog - Poll dev state
4419 * @ha: Pointer to host adapter structure.
4421 * Context: Interrupt
4423 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4428 if (is_qla8032(ha) &&
4429 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4430 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4431 __func__, ha->func_num);
4433 /* don't poll if reset is going on */
4434 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4435 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4436 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4437 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4439 if (qla4_8xxx_check_temp(ha)) {
4440 if (is_qla8022(ha)) {
4441 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4442 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4443 CRB_NIU_XG_PAUSE_CTL_P0 |
4444 CRB_NIU_XG_PAUSE_CTL_P1);
4446 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4447 qla4xxx_wake_dpc(ha);
4448 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4449 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4451 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4454 if (is_qla8032(ha) || is_qla8042(ha)) {
4455 idc_ctrl = qla4_83xx_rd_reg(ha,
4456 QLA83XX_IDC_DRV_CTRL);
4457 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4458 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4460 qla4xxx_mailbox_premature_completion(
4465 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4466 (is_qla8022(ha) && !ql4xdontresethba)) {
4467 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4468 qla4xxx_wake_dpc(ha);
4470 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4471 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4472 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4474 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4475 qla4xxx_wake_dpc(ha);
4477 /* Check firmware health */
4478 if (qla4_8xxx_check_fw_alive(ha))
4479 qla4_8xxx_process_fw_error(ha);
4484 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4486 struct iscsi_session *sess;
4487 struct ddb_entry *ddb_entry;
4488 struct scsi_qla_host *ha;
4490 sess = cls_sess->dd_data;
4491 ddb_entry = sess->dd_data;
4494 if (!(ddb_entry->ddb_type == FLASH_DDB))
4497 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4498 !iscsi_is_session_online(cls_sess)) {
4499 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4501 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4503 atomic_set(&ddb_entry->retry_relogin_timer,
4505 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4506 set_bit(DF_RELOGIN, &ddb_entry->flags);
4507 DEBUG2(ql4_printk(KERN_INFO, ha,
4508 "%s: index [%d] login device\n",
4509 __func__, ddb_entry->fw_ddb_index));
4511 atomic_dec(&ddb_entry->retry_relogin_timer);
4515 /* Wait for relogin to timeout */
4516 if (atomic_read(&ddb_entry->relogin_timer) &&
4517 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4519 * If the relogin times out and the device is
4520 * still NOT ONLINE then try and relogin again.
4522 if (!iscsi_is_session_online(cls_sess)) {
4523 /* Reset retry relogin timer */
4524 atomic_inc(&ddb_entry->relogin_retry_count);
4525 DEBUG2(ql4_printk(KERN_INFO, ha,
4526 "%s: index[%d] relogin timed out-retrying"
4527 " relogin (%d), retry (%d)\n", __func__,
4528 ddb_entry->fw_ddb_index,
4529 atomic_read(&ddb_entry->relogin_retry_count),
4530 ddb_entry->default_time2wait + 4));
4531 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4532 atomic_set(&ddb_entry->retry_relogin_timer,
4533 ddb_entry->default_time2wait + 4);
4539 * qla4xxx_timer - checks every second for work to do.
4540 * @t: Context to obtain pointer to host adapter structure.
4542 static void qla4xxx_timer(struct timer_list *t)
4544 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4548 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4550 /* If we are in the middle of AER/EEH processing
4551 * skip any processing and reschedule the timer
4553 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4554 mod_timer(&ha->timer, jiffies + HZ);
4558 /* Hardware read to trigger an EEH error during mailbox waits. */
4559 if (!pci_channel_offline(ha->pdev))
4560 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4563 qla4_8xxx_watchdog(ha);
4565 if (is_qla40XX(ha)) {
4566 /* Check for heartbeat interval. */
4567 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4568 ha->heartbeat_interval != 0) {
4569 ha->seconds_since_last_heartbeat++;
4570 if (ha->seconds_since_last_heartbeat >
4571 ha->heartbeat_interval + 2)
4572 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4576 /* Process any deferred work. */
4577 if (!list_empty(&ha->work_list))
4580 /* Wakeup the dpc routine for this adapter, if needed. */
4582 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4583 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4584 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4585 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4586 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4587 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4588 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4589 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4590 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4591 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4592 test_bit(DPC_AEN, &ha->dpc_flags)) {
4593 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4594 " - dpc flags = 0x%lx\n",
4595 ha->host_no, __func__, ha->dpc_flags));
4596 qla4xxx_wake_dpc(ha);
4599 /* Reschedule timer thread to call us back in one second */
4600 mod_timer(&ha->timer, jiffies + HZ);
4602 DEBUG2(ha->seconds_since_last_intr++);
4606 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4607 * @ha: Pointer to host adapter structure.
4609 * This routine stalls the driver until all outstanding commands are returned.
4610 * Caller must release the Hardware Lock prior to calling this routine.
4612 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4615 unsigned long flags;
4616 struct scsi_cmnd *cmd;
4617 unsigned long wtime;
4621 wtmo = WAIT_CMD_TOV;
4623 wtmo = ha->nx_reset_timeout / 2;
4625 wtime = jiffies + (wtmo * HZ);
4627 DEBUG2(ql4_printk(KERN_INFO, ha,
4628 "Wait up to %u seconds for cmds to complete\n",
4631 while (!time_after_eq(jiffies, wtime)) {
4632 spin_lock_irqsave(&ha->hardware_lock, flags);
4633 /* Find a command that hasn't completed. */
4634 for (index = 0; index < ha->host->can_queue; index++) {
4635 cmd = scsi_host_find_tag(ha->host, index);
4637 * We cannot just check if the index is valid,
4638 * becase if we are run from the scsi eh, then
4639 * the scsi/block layer is going to prevent
4640 * the tag from being released.
4642 if (cmd != NULL && qla4xxx_cmd_priv(cmd)->srb)
4645 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4647 /* If No Commands are pending, wait is complete */
4648 if (index == ha->host->can_queue)
4653 /* If we timed out on waiting for commands to come back
4658 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4660 uint32_t ctrl_status;
4661 unsigned long flags = 0;
4663 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4665 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4668 spin_lock_irqsave(&ha->hardware_lock, flags);
4671 * If the SCSI Reset Interrupt bit is set, clear it.
4672 * Otherwise, the Soft Reset won't work.
4674 ctrl_status = readw(&ha->reg->ctrl_status);
4675 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4676 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4678 /* Issue Soft Reset */
4679 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4680 readl(&ha->reg->ctrl_status);
4682 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4687 * qla4xxx_soft_reset - performs soft reset.
4688 * @ha: Pointer to host adapter structure.
4690 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4692 uint32_t max_wait_time;
4693 unsigned long flags = 0;
4695 uint32_t ctrl_status;
4697 status = qla4xxx_hw_reset(ha);
4698 if (status != QLA_SUCCESS)
4702 /* Wait until the Network Reset Intr bit is cleared */
4703 max_wait_time = RESET_INTR_TOV;
4705 spin_lock_irqsave(&ha->hardware_lock, flags);
4706 ctrl_status = readw(&ha->reg->ctrl_status);
4707 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4709 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4713 } while ((--max_wait_time));
4715 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4716 DEBUG2(printk(KERN_WARNING
4717 "scsi%ld: Network Reset Intr not cleared by "
4718 "Network function, clearing it now!\n",
4720 spin_lock_irqsave(&ha->hardware_lock, flags);
4721 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4722 readl(&ha->reg->ctrl_status);
4723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4726 /* Wait until the firmware tells us the Soft Reset is done */
4727 max_wait_time = SOFT_RESET_TOV;
4729 spin_lock_irqsave(&ha->hardware_lock, flags);
4730 ctrl_status = readw(&ha->reg->ctrl_status);
4731 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4733 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4734 status = QLA_SUCCESS;
4739 } while ((--max_wait_time));
4742 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4743 * after the soft reset has taken place.
4745 spin_lock_irqsave(&ha->hardware_lock, flags);
4746 ctrl_status = readw(&ha->reg->ctrl_status);
4747 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4748 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4749 readl(&ha->reg->ctrl_status);
4751 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4753 /* If soft reset fails then most probably the bios on other
4754 * function is also enabled.
4755 * Since the initialization is sequential the other fn
4756 * wont be able to acknowledge the soft reset.
4757 * Issue a force soft reset to workaround this scenario.
4759 if (max_wait_time == 0) {
4760 /* Issue Force Soft Reset */
4761 spin_lock_irqsave(&ha->hardware_lock, flags);
4762 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4763 readl(&ha->reg->ctrl_status);
4764 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4765 /* Wait until the firmware tells us the Soft Reset is done */
4766 max_wait_time = SOFT_RESET_TOV;
4768 spin_lock_irqsave(&ha->hardware_lock, flags);
4769 ctrl_status = readw(&ha->reg->ctrl_status);
4770 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4772 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4773 status = QLA_SUCCESS;
4778 } while ((--max_wait_time));
4785 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4786 * @ha: Pointer to host adapter structure.
4787 * @res: returned scsi status
4789 * This routine is called just prior to a HARD RESET to return all
4790 * outstanding commands back to the Operating System.
4791 * Caller should make sure that the following locks are released
4792 * before this calling routine: Hardware lock, and io_request_lock.
4794 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4798 unsigned long flags;
4800 spin_lock_irqsave(&ha->hardware_lock, flags);
4801 for (i = 0; i < ha->host->can_queue; i++) {
4802 srb = qla4xxx_del_from_active_array(ha, i);
4804 srb->cmd->result = res;
4805 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4808 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4811 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4813 clear_bit(AF_ONLINE, &ha->flags);
4815 /* Disable the board */
4816 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4818 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4819 qla4xxx_mark_all_devices_missing(ha);
4820 clear_bit(AF_INIT_DONE, &ha->flags);
4823 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4825 struct iscsi_session *sess;
4826 struct ddb_entry *ddb_entry;
4828 sess = cls_session->dd_data;
4829 ddb_entry = sess->dd_data;
4830 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4832 if (ddb_entry->ddb_type == FLASH_DDB)
4833 iscsi_block_session(ddb_entry->sess);
4835 iscsi_session_failure(cls_session->dd_data,
4836 ISCSI_ERR_CONN_FAILED);
4840 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4841 * @ha: Pointer to host adapter structure.
4843 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4845 int status = QLA_ERROR;
4846 uint8_t reset_chip = 0;
4850 /* Stall incoming I/O until we are done */
4851 scsi_block_requests(ha->host);
4852 clear_bit(AF_ONLINE, &ha->flags);
4853 clear_bit(AF_LINK_UP, &ha->flags);
4855 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4857 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4859 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4860 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4861 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4863 /* disable pause frame for ISP83xx */
4864 qla4_83xx_disable_pause(ha);
4867 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4869 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4872 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4873 * do not reset adapter, jump to initialize_adapter */
4874 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4875 status = QLA_SUCCESS;
4876 goto recover_ha_init_adapter;
4879 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4880 * from eh_host_reset or ioctl module */
4881 if (is_qla80XX(ha) && !reset_chip &&
4882 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4884 DEBUG2(ql4_printk(KERN_INFO, ha,
4885 "scsi%ld: %s - Performing stop_firmware...\n",
4886 ha->host_no, __func__));
4887 status = ha->isp_ops->reset_firmware(ha);
4888 if (status == QLA_SUCCESS) {
4889 ha->isp_ops->disable_intrs(ha);
4890 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4891 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4893 /* If the stop_firmware fails then
4894 * reset the entire chip */
4896 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4897 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4901 /* Issue full chip reset if recovering from a catastrophic error,
4902 * or if stop_firmware fails for ISP-8xxx.
4903 * This is the default case for ISP-4xxx */
4904 if (is_qla40XX(ha) || reset_chip) {
4908 /* Check if 8XXX firmware is alive or not
4909 * We may have arrived here from NEED_RESET
4911 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4914 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4915 while (time_before(jiffies, wait)) {
4916 if (qla4_8xxx_check_fw_alive(ha)) {
4917 qla4xxx_mailbox_premature_completion(ha);
4921 set_current_state(TASK_UNINTERRUPTIBLE);
4922 schedule_timeout(HZ);
4925 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4926 qla4xxx_cmd_wait(ha);
4928 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4929 DEBUG2(ql4_printk(KERN_INFO, ha,
4930 "scsi%ld: %s - Performing chip reset..\n",
4931 ha->host_no, __func__));
4932 status = ha->isp_ops->reset_chip(ha);
4933 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4936 /* Flush any pending ddb changed AENs */
4937 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4939 recover_ha_init_adapter:
4940 /* Upon successful firmware/chip reset, re-initialize the adapter */
4941 if (status == QLA_SUCCESS) {
4942 /* For ISP-4xxx, force function 1 to always initialize
4943 * before function 3 to prevent both funcions from
4944 * stepping on top of the other */
4945 if (is_qla40XX(ha) && (ha->mac_index == 3))
4948 /* NOTE: AF_ONLINE flag set upon successful completion of
4949 * qla4xxx_initialize_adapter */
4950 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4951 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4952 status = qla4_8xxx_check_init_adapter_retry(ha);
4953 if (status == QLA_ERROR) {
4954 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4955 ha->host_no, __func__);
4956 qla4xxx_dead_adapter_cleanup(ha);
4957 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4958 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4959 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4966 /* Retry failed adapter initialization, if necessary
4967 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4968 * case to prevent ping-pong resets between functions */
4969 if (!test_bit(AF_ONLINE, &ha->flags) &&
4970 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4971 /* Adapter initialization failed, see if we can retry
4973 * Since we don't want to block the DPC for too long
4974 * with multiple resets in the same thread,
4975 * utilize DPC to retry */
4976 if (is_qla80XX(ha)) {
4977 ha->isp_ops->idc_lock(ha);
4978 dev_state = qla4_8xxx_rd_direct(ha,
4979 QLA8XXX_CRB_DEV_STATE);
4980 ha->isp_ops->idc_unlock(ha);
4981 if (dev_state == QLA8XXX_DEV_FAILED) {
4982 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4983 "recover adapter. H/W is in Failed "
4984 "state\n", __func__);
4985 qla4xxx_dead_adapter_cleanup(ha);
4986 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4987 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4988 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4996 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4997 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4998 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4999 "(%d) more times\n", ha->host_no,
5000 ha->retry_reset_ha_cnt));
5001 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5004 if (ha->retry_reset_ha_cnt > 0) {
5005 /* Schedule another Reset HA--DPC will retry */
5006 ha->retry_reset_ha_cnt--;
5007 DEBUG2(printk("scsi%ld: recover adapter - "
5008 "retry remaining %d\n",
5010 ha->retry_reset_ha_cnt));
5014 if (ha->retry_reset_ha_cnt == 0) {
5015 /* Recover adapter retries have been exhausted.
5017 DEBUG2(printk("scsi%ld: recover adapter "
5018 "failed - board disabled\n",
5020 qla4xxx_dead_adapter_cleanup(ha);
5021 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5022 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5023 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5029 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5030 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5031 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5035 ha->adapter_error_count++;
5037 if (test_bit(AF_ONLINE, &ha->flags))
5038 ha->isp_ops->enable_intrs(ha);
5040 scsi_unblock_requests(ha->host);
5042 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5043 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5044 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5049 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5051 struct iscsi_session *sess;
5052 struct ddb_entry *ddb_entry;
5053 struct scsi_qla_host *ha;
5055 sess = cls_session->dd_data;
5056 ddb_entry = sess->dd_data;
5058 if (!iscsi_is_session_online(cls_session)) {
5059 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5060 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5061 " unblock session\n", ha->host_no, __func__,
5062 ddb_entry->fw_ddb_index);
5063 iscsi_unblock_session(ddb_entry->sess);
5065 /* Trigger relogin */
5066 if (ddb_entry->ddb_type == FLASH_DDB) {
5067 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5068 test_bit(DF_DISABLE_RELOGIN,
5069 &ddb_entry->flags)))
5070 qla4xxx_arm_relogin_timer(ddb_entry);
5072 iscsi_session_failure(cls_session->dd_data,
5073 ISCSI_ERR_CONN_FAILED);
5078 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5080 struct iscsi_session *sess;
5081 struct ddb_entry *ddb_entry;
5082 struct scsi_qla_host *ha;
5084 sess = cls_session->dd_data;
5085 ddb_entry = sess->dd_data;
5087 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5088 " unblock session\n", ha->host_no, __func__,
5089 ddb_entry->fw_ddb_index);
5091 iscsi_unblock_session(ddb_entry->sess);
5093 /* Start scan target */
5094 if (test_bit(AF_ONLINE, &ha->flags)) {
5095 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5096 " start scan\n", ha->host_no, __func__,
5097 ddb_entry->fw_ddb_index);
5098 queue_work(ddb_entry->sess->workq, &ddb_entry->sess->scan_work);
5103 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5105 struct iscsi_session *sess;
5106 struct ddb_entry *ddb_entry;
5107 struct scsi_qla_host *ha;
5108 int status = QLA_SUCCESS;
5110 sess = cls_session->dd_data;
5111 ddb_entry = sess->dd_data;
5113 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5114 " unblock user space session\n", ha->host_no, __func__,
5115 ddb_entry->fw_ddb_index);
5117 if (!iscsi_is_session_online(cls_session)) {
5118 iscsi_conn_start(ddb_entry->conn);
5119 iscsi_conn_login_event(ddb_entry->conn,
5120 ISCSI_CONN_STATE_LOGGED_IN);
5122 ql4_printk(KERN_INFO, ha,
5123 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5124 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5132 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5134 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5137 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5139 uint16_t relogin_timer;
5140 struct iscsi_session *sess;
5141 struct ddb_entry *ddb_entry;
5142 struct scsi_qla_host *ha;
5144 sess = cls_sess->dd_data;
5145 ddb_entry = sess->dd_data;
5148 relogin_timer = max(ddb_entry->default_relogin_timeout,
5149 (uint16_t)RELOGIN_TOV);
5150 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5152 DEBUG2(ql4_printk(KERN_INFO, ha,
5153 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5154 ddb_entry->fw_ddb_index, relogin_timer));
5156 qla4xxx_login_flash_ddb(cls_sess);
5159 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5161 struct iscsi_session *sess;
5162 struct ddb_entry *ddb_entry;
5163 struct scsi_qla_host *ha;
5165 sess = cls_sess->dd_data;
5166 ddb_entry = sess->dd_data;
5169 if (!(ddb_entry->ddb_type == FLASH_DDB))
5172 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5175 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5176 !iscsi_is_session_online(cls_sess)) {
5177 DEBUG2(ql4_printk(KERN_INFO, ha,
5178 "relogin issued\n"));
5179 qla4xxx_relogin_flash_ddb(cls_sess);
5183 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5186 queue_work(ha->dpc_thread, &ha->dpc_work);
5189 static struct qla4_work_evt *
5190 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5191 enum qla4_work_type type)
5193 struct qla4_work_evt *e;
5194 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5196 e = kzalloc(size, GFP_ATOMIC);
5200 INIT_LIST_HEAD(&e->list);
5205 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5206 struct qla4_work_evt *e)
5208 unsigned long flags;
5210 spin_lock_irqsave(&ha->work_lock, flags);
5211 list_add_tail(&e->list, &ha->work_list);
5212 spin_unlock_irqrestore(&ha->work_lock, flags);
5213 qla4xxx_wake_dpc(ha);
5216 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5217 enum iscsi_host_event_code aen_code,
5218 uint32_t data_size, uint8_t *data)
5220 struct qla4_work_evt *e;
5222 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5226 e->u.aen.code = aen_code;
5227 e->u.aen.data_size = data_size;
5228 memcpy(e->u.aen.data, data, data_size);
5230 qla4xxx_post_work(ha, e);
5235 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5236 uint32_t status, uint32_t pid,
5237 uint32_t data_size, uint8_t *data)
5239 struct qla4_work_evt *e;
5241 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5245 e->u.ping.status = status;
5246 e->u.ping.pid = pid;
5247 e->u.ping.data_size = data_size;
5248 memcpy(e->u.ping.data, data, data_size);
5250 qla4xxx_post_work(ha, e);
5255 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5257 struct qla4_work_evt *e, *tmp;
5258 unsigned long flags;
5261 spin_lock_irqsave(&ha->work_lock, flags);
5262 list_splice_init(&ha->work_list, &work);
5263 spin_unlock_irqrestore(&ha->work_lock, flags);
5265 list_for_each_entry_safe(e, tmp, &work, list) {
5266 list_del_init(&e->list);
5269 case QLA4_EVENT_AEN:
5270 iscsi_post_host_event(ha->host_no,
5271 &qla4xxx_iscsi_transport,
5276 case QLA4_EVENT_PING_STATUS:
5277 iscsi_ping_comp_event(ha->host_no,
5278 &qla4xxx_iscsi_transport,
5281 e->u.ping.data_size,
5285 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5286 "supported", e->type);
5293 * qla4xxx_do_dpc - dpc routine
5294 * @work: Context to obtain pointer to host adapter structure.
5296 * This routine is a task that is schedule by the interrupt handler
5297 * to perform the background processing for interrupts. We put it
5298 * on a task queue that is consumed whenever the scheduler runs; that's
5299 * so you can do anything (i.e. put the process to sleep etc). In fact,
5300 * the mid-level tries to sleep when it reaches the driver threshold
5301 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5303 static void qla4xxx_do_dpc(struct work_struct *work)
5305 struct scsi_qla_host *ha =
5306 container_of(work, struct scsi_qla_host, dpc_work);
5307 int status = QLA_ERROR;
5309 DEBUG2(ql4_printk(KERN_INFO, ha,
5310 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5311 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5313 /* Initialization not yet finished. Don't do anything yet. */
5314 if (!test_bit(AF_INIT_DONE, &ha->flags))
5317 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5318 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5319 ha->host_no, __func__, ha->flags));
5323 /* post events to application */
5324 qla4xxx_do_work(ha);
5326 if (is_qla80XX(ha)) {
5327 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5328 if (is_qla8032(ha) || is_qla8042(ha)) {
5329 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5331 /* disable pause frame for ISP83xx */
5332 qla4_83xx_disable_pause(ha);
5335 ha->isp_ops->idc_lock(ha);
5336 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5337 QLA8XXX_DEV_FAILED);
5338 ha->isp_ops->idc_unlock(ha);
5339 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5340 qla4_8xxx_device_state_handler(ha);
5343 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5344 if (is_qla8042(ha)) {
5345 if (ha->idc_info.info2 &
5346 ENABLE_INTERNAL_LOOPBACK) {
5347 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5349 status = qla4_84xx_config_acb(ha,
5350 ACB_CONFIG_DISABLE);
5351 if (status != QLA_SUCCESS) {
5352 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5357 qla4_83xx_post_idc_ack(ha);
5358 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5361 if (is_qla8042(ha) &&
5362 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5363 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5365 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5367 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5370 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5373 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5374 qla4_8xxx_need_qsnt_handler(ha);
5378 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5379 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5380 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5381 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5382 if ((is_qla8022(ha) && ql4xdontresethba) ||
5383 ((is_qla8032(ha) || is_qla8042(ha)) &&
5384 qla4_83xx_idc_dontreset(ha))) {
5385 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5386 ha->host_no, __func__));
5387 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5388 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5389 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5390 goto dpc_post_reset_ha;
5392 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5393 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5394 qla4xxx_recover_adapter(ha);
5396 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5397 uint8_t wait_time = RESET_INTR_TOV;
5399 while ((readw(&ha->reg->ctrl_status) &
5400 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5401 if (--wait_time == 0)
5406 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5407 "bit not cleared-- resetting\n",
5408 ha->host_no, __func__));
5409 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5410 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5411 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5412 status = qla4xxx_recover_adapter(ha);
5414 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5415 if (status == QLA_SUCCESS)
5416 ha->isp_ops->enable_intrs(ha);
5421 /* ---- process AEN? --- */
5422 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5423 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5425 /* ---- Get DHCP IP Address? --- */
5426 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5427 qla4xxx_get_dhcp_ip_address(ha);
5429 /* ---- relogin device? --- */
5430 if (adapter_up(ha) &&
5431 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5432 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5435 /* ---- link change? --- */
5436 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5437 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5438 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5439 /* ---- link down? --- */
5440 qla4xxx_mark_all_devices_missing(ha);
5442 /* ---- link up? --- *
5443 * F/W will auto login to all devices ONLY ONCE after
5444 * link up during driver initialization and runtime
5445 * fatal error recovery. Therefore, the driver must
5446 * manually relogin to devices when recovering from
5447 * connection failures, logouts, expired KATO, etc. */
5448 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5449 qla4xxx_build_ddb_list(ha, ha->is_reset);
5450 iscsi_host_for_each_session(ha->host,
5451 qla4xxx_login_flash_ddb);
5453 qla4xxx_relogin_all_devices(ha);
5456 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5457 if (qla4xxx_sysfs_ddb_export(ha))
5458 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5464 * qla4xxx_free_adapter - release the adapter
5465 * @ha: pointer to adapter structure
5467 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5469 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5471 /* Turn-off interrupts on the card. */
5472 ha->isp_ops->disable_intrs(ha);
5474 if (is_qla40XX(ha)) {
5475 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5476 &ha->reg->ctrl_status);
5477 readl(&ha->reg->ctrl_status);
5478 } else if (is_qla8022(ha)) {
5479 writel(0, &ha->qla4_82xx_reg->host_int);
5480 readl(&ha->qla4_82xx_reg->host_int);
5481 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5482 writel(0, &ha->qla4_83xx_reg->risc_intr);
5483 readl(&ha->qla4_83xx_reg->risc_intr);
5486 /* Remove timer thread, if present */
5487 if (ha->timer_active)
5488 qla4xxx_stop_timer(ha);
5490 /* Kill the kernel thread for this host */
5492 destroy_workqueue(ha->dpc_thread);
5494 /* Kill the kernel thread for this host */
5496 destroy_workqueue(ha->task_wq);
5498 /* Put firmware in known state */
5499 ha->isp_ops->reset_firmware(ha);
5501 if (is_qla80XX(ha)) {
5502 ha->isp_ops->idc_lock(ha);
5503 qla4_8xxx_clear_drv_active(ha);
5504 ha->isp_ops->idc_unlock(ha);
5507 /* Detach interrupts */
5508 qla4xxx_free_irqs(ha);
5510 /* free extra memory */
5511 qla4xxx_mem_free(ha);
5514 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5517 unsigned long mem_base, mem_len;
5518 struct pci_dev *pdev = ha->pdev;
5520 status = pci_request_regions(pdev, DRIVER_NAME);
5523 "scsi(%ld) Failed to reserve PIO regions (%s) "
5524 "status=%d\n", ha->host_no, pci_name(pdev), status);
5525 goto iospace_error_exit;
5528 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5529 __func__, pdev->revision));
5530 ha->revision_id = pdev->revision;
5532 /* remap phys address */
5533 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5534 mem_len = pci_resource_len(pdev, 0);
5535 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5536 __func__, mem_base, mem_len));
5538 /* mapping of pcibase pointer */
5539 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5540 if (!ha->nx_pcibase) {
5542 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5543 pci_release_regions(ha->pdev);
5544 goto iospace_error_exit;
5547 /* Mapping of IO base pointer, door bell read and write pointer */
5549 /* mapping of IO base pointer */
5550 if (is_qla8022(ha)) {
5551 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5552 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5553 (ha->pdev->devfn << 11));
5554 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5555 QLA82XX_CAM_RAM_DB2);
5556 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5557 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5558 ((uint8_t *)ha->nx_pcibase);
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", (char)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", (char)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 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 iscsi_cls_session *cls_sess;
6272 struct iscsi_cls_conn *cls_conn;
6273 struct iscsi_session *sess;
6274 struct iscsi_conn *conn;
6276 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6277 cls_sess = ddb_entry->sess;
6278 sess = cls_sess->dd_data;
6279 cls_conn = ddb_entry->conn;
6280 conn = cls_conn->dd_data;
6282 tddb->tpgt = sess->tpgt;
6283 tddb->port = conn->persistent_port;
6284 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6285 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6288 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6289 struct ql4_tuple_ddb *tddb,
6290 uint8_t *flash_isid)
6292 uint16_t options = 0;
6294 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6295 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6296 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6298 options = le16_to_cpu(fw_ddb_entry->options);
6299 if (options & DDB_OPT_IPV6_DEVICE)
6300 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6302 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6304 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6306 if (flash_isid == NULL)
6307 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6308 sizeof(tddb->isid));
6310 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6313 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6314 struct ql4_tuple_ddb *old_tddb,
6315 struct ql4_tuple_ddb *new_tddb,
6316 uint8_t is_isid_compare)
6318 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6321 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6324 if (old_tddb->port != new_tddb->port)
6327 /* For multi sessions, driver generates the ISID, so do not compare
6328 * ISID in reset path since it would be a comparison between the
6329 * driver generated ISID and firmware generated ISID. This could
6330 * lead to adding duplicated DDBs in the list as driver generated
6331 * ISID would not match firmware generated ISID.
6333 if (is_isid_compare) {
6334 DEBUG2(ql4_printk(KERN_INFO, ha,
6335 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6336 __func__, old_tddb->isid, new_tddb->isid));
6338 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6339 sizeof(old_tddb->isid)))
6343 DEBUG2(ql4_printk(KERN_INFO, ha,
6344 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6345 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6346 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6347 new_tddb->ip_addr, new_tddb->iscsi_name));
6352 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6353 struct dev_db_entry *fw_ddb_entry,
6356 struct ddb_entry *ddb_entry;
6357 struct ql4_tuple_ddb *fw_tddb = NULL;
6358 struct ql4_tuple_ddb *tmp_tddb = NULL;
6360 int ret = QLA_ERROR;
6362 fw_tddb = vzalloc(sizeof(*fw_tddb));
6364 DEBUG2(ql4_printk(KERN_WARNING, ha,
6365 "Memory Allocation failed.\n"));
6370 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6372 DEBUG2(ql4_printk(KERN_WARNING, ha,
6373 "Memory Allocation failed.\n"));
6378 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6380 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6381 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6382 if (ddb_entry == NULL)
6385 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6386 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6387 ret = QLA_SUCCESS; /* found */
6401 * qla4xxx_check_existing_isid - check if target with same isid exist
6403 * @list_nt: list of target
6404 * @isid: isid to check
6406 * This routine return QLA_SUCCESS if target with same isid exist
6408 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6410 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6411 struct dev_db_entry *fw_ddb_entry;
6413 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6414 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6416 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6417 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6425 * qla4xxx_update_isid - compare ddbs and updated isid
6426 * @ha: Pointer to host adapter structure.
6427 * @list_nt: list of nt target
6428 * @fw_ddb_entry: firmware ddb entry
6430 * This routine update isid if ddbs have same iqn, same isid and
6431 * different IP addr.
6432 * Return QLA_SUCCESS if isid is updated.
6434 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6435 struct list_head *list_nt,
6436 struct dev_db_entry *fw_ddb_entry)
6438 uint8_t base_value, i;
6440 base_value = fw_ddb_entry->isid[1] & 0x1f;
6441 for (i = 0; i < 8; i++) {
6442 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6443 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6447 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6454 * qla4xxx_should_update_isid - check if isid need to update
6455 * @ha: Pointer to host adapter structure.
6456 * @old_tddb: ddb tuple
6457 * @new_tddb: ddb tuple
6459 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6462 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6463 struct ql4_tuple_ddb *old_tddb,
6464 struct ql4_tuple_ddb *new_tddb)
6466 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6468 if (old_tddb->port == new_tddb->port)
6472 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6476 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6477 sizeof(old_tddb->isid)))
6478 /* different isid */
6485 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6486 * @ha: Pointer to host adapter structure.
6487 * @list_nt: list of nt target.
6488 * @fw_ddb_entry: firmware ddb entry.
6490 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6491 * duplicate ddb in list_nt.
6492 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6493 * Note: This function also update isid of DDB if required.
6496 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6497 struct list_head *list_nt,
6498 struct dev_db_entry *fw_ddb_entry)
6500 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6501 struct ql4_tuple_ddb *fw_tddb = NULL;
6502 struct ql4_tuple_ddb *tmp_tddb = NULL;
6503 int rval, ret = QLA_ERROR;
6505 fw_tddb = vzalloc(sizeof(*fw_tddb));
6507 DEBUG2(ql4_printk(KERN_WARNING, ha,
6508 "Memory Allocation failed.\n"));
6513 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6515 DEBUG2(ql4_printk(KERN_WARNING, ha,
6516 "Memory Allocation failed.\n"));
6521 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6523 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6524 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6525 nt_ddb_idx->flash_isid);
6526 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6527 /* found duplicate ddb */
6528 if (ret == QLA_SUCCESS)
6532 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6533 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6535 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6536 if (ret == QLA_SUCCESS) {
6537 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6538 if (rval == QLA_SUCCESS)
6553 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6555 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6557 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6558 list_del_init(&ddb_idx->list);
6563 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6564 struct dev_db_entry *fw_ddb_entry)
6566 struct iscsi_endpoint *ep;
6567 struct sockaddr_in *addr;
6568 struct sockaddr_in6 *addr6;
6569 struct sockaddr *t_addr;
6570 struct sockaddr_storage *dst_addr;
6573 /* TODO: need to destroy on unload iscsi_endpoint*/
6574 dst_addr = vmalloc(sizeof(*dst_addr));
6578 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6579 t_addr = (struct sockaddr *)dst_addr;
6580 t_addr->sa_family = AF_INET6;
6581 addr6 = (struct sockaddr_in6 *)dst_addr;
6582 ip = (char *)&addr6->sin6_addr;
6583 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6584 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6587 t_addr = (struct sockaddr *)dst_addr;
6588 t_addr->sa_family = AF_INET;
6589 addr = (struct sockaddr_in *)dst_addr;
6590 ip = (char *)&addr->sin_addr;
6591 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6592 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6595 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6600 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6602 if (ql4xdisablesysfsboot)
6604 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6609 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6610 struct ddb_entry *ddb_entry,
6613 uint16_t def_timeout;
6615 ddb_entry->ddb_type = FLASH_DDB;
6616 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6617 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6619 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6620 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6621 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6623 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6624 atomic_set(&ddb_entry->relogin_timer, 0);
6625 atomic_set(&ddb_entry->relogin_retry_count, 0);
6626 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6627 ddb_entry->default_relogin_timeout =
6628 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6629 def_timeout : LOGIN_TOV;
6630 ddb_entry->default_time2wait =
6631 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6633 if (ql4xdisablesysfsboot &&
6634 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6635 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6638 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6641 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6642 uint32_t sts[MBOX_REG_COUNT];
6644 unsigned long wtime;
6647 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6649 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6650 if (ip_idx[idx] == -1)
6653 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6655 if (ret == QLA_ERROR) {
6660 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6662 DEBUG2(ql4_printk(KERN_INFO, ha,
6663 "Waiting for IP state for idx = %d, state = 0x%x\n",
6664 ip_idx[idx], ip_state));
6665 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6666 ip_state == IP_ADDRSTATE_INVALID ||
6667 ip_state == IP_ADDRSTATE_PREFERRED ||
6668 ip_state == IP_ADDRSTATE_DEPRICATED ||
6669 ip_state == IP_ADDRSTATE_DISABLING)
6673 /* Break if all IP states checked */
6674 if ((ip_idx[0] == -1) &&
6675 (ip_idx[1] == -1) &&
6676 (ip_idx[2] == -1) &&
6679 schedule_timeout_uninterruptible(HZ);
6680 } while (time_after(wtime, jiffies));
6683 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6684 struct dev_db_entry *flash_ddb_entry)
6686 uint16_t options = 0;
6687 size_t ip_len = IP_ADDR_LEN;
6689 options = le16_to_cpu(fw_ddb_entry->options);
6690 if (options & DDB_OPT_IPV6_DEVICE)
6691 ip_len = IPv6_ADDR_LEN;
6693 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6696 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6697 sizeof(fw_ddb_entry->isid)))
6700 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6701 sizeof(fw_ddb_entry->port)))
6707 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6708 struct dev_db_entry *fw_ddb_entry,
6709 uint32_t fw_idx, uint32_t *flash_index)
6711 struct dev_db_entry *flash_ddb_entry;
6712 dma_addr_t flash_ddb_entry_dma;
6715 int ret = QLA_ERROR, status;
6717 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6720 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6721 &flash_ddb_entry_dma);
6722 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6723 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6724 goto exit_find_st_idx;
6727 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6728 flash_ddb_entry_dma, fw_idx);
6729 if (status == QLA_SUCCESS) {
6730 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6731 if (status == QLA_SUCCESS) {
6732 *flash_index = fw_idx;
6734 goto exit_find_st_idx;
6738 for (idx = 0; idx < max_ddbs; idx++) {
6739 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6740 flash_ddb_entry_dma, idx);
6741 if (status == QLA_ERROR)
6744 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6745 if (status == QLA_SUCCESS) {
6748 goto exit_find_st_idx;
6752 if (idx == max_ddbs)
6753 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6757 if (flash_ddb_entry)
6758 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6759 flash_ddb_entry_dma);
6764 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6765 struct list_head *list_st)
6767 struct qla_ddb_index *st_ddb_idx;
6770 struct dev_db_entry *fw_ddb_entry;
6771 dma_addr_t fw_ddb_dma;
6773 uint32_t idx = 0, next_idx = 0;
6774 uint32_t state = 0, conn_err = 0;
6775 uint32_t flash_index = -1;
6776 uint16_t conn_id = 0;
6778 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6780 if (fw_ddb_entry == NULL) {
6781 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6785 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6787 fw_idx_size = sizeof(struct qla_ddb_index);
6789 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6790 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6791 NULL, &next_idx, &state,
6792 &conn_err, NULL, &conn_id);
6793 if (ret == QLA_ERROR)
6796 /* Ignore DDB if invalid state (unassigned) */
6797 if (state == DDB_DS_UNASSIGNED)
6798 goto continue_next_st;
6800 /* Check if ST, add to the list_st */
6801 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6802 goto continue_next_st;
6804 st_ddb_idx = vzalloc(fw_idx_size);
6808 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6810 if (ret == QLA_ERROR) {
6811 ql4_printk(KERN_ERR, ha,
6812 "No flash entry for ST at idx [%d]\n", idx);
6813 st_ddb_idx->flash_ddb_idx = idx;
6815 ql4_printk(KERN_INFO, ha,
6816 "ST at idx [%d] is stored at flash [%d]\n",
6818 st_ddb_idx->flash_ddb_idx = flash_index;
6821 st_ddb_idx->fw_ddb_idx = idx;
6823 list_add_tail(&st_ddb_idx->list, list_st);
6831 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6835 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6836 * @ha: pointer to adapter structure
6837 * @list_ddb: List from which failed ddb to be removed
6839 * Iterate over the list of DDBs and find and remove DDBs that are either in
6840 * no connection active state or failed state
6842 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6843 struct list_head *list_ddb)
6845 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6846 uint32_t next_idx = 0;
6847 uint32_t state = 0, conn_err = 0;
6850 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6851 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6852 NULL, 0, NULL, &next_idx, &state,
6853 &conn_err, NULL, NULL);
6854 if (ret == QLA_ERROR)
6857 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6858 state == DDB_DS_SESSION_FAILED) {
6859 list_del_init(&ddb_idx->list);
6865 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6866 struct ddb_entry *ddb_entry,
6867 struct dev_db_entry *fw_ddb_entry)
6869 struct iscsi_cls_session *cls_sess;
6870 struct iscsi_session *sess;
6871 uint32_t max_ddbs = 0;
6872 uint16_t ddb_link = -1;
6874 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6877 cls_sess = ddb_entry->sess;
6878 sess = cls_sess->dd_data;
6880 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6881 if (ddb_link < max_ddbs)
6882 sess->discovery_parent_idx = ddb_link;
6884 sess->discovery_parent_idx = DDB_NO_LINK;
6887 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6888 struct dev_db_entry *fw_ddb_entry,
6889 int is_reset, uint16_t idx)
6891 struct iscsi_cls_session *cls_sess;
6892 struct iscsi_session *sess;
6893 struct iscsi_cls_conn *cls_conn;
6894 struct iscsi_endpoint *ep;
6895 uint16_t cmds_max = 32;
6896 uint16_t conn_id = 0;
6897 uint32_t initial_cmdsn = 0;
6898 int ret = QLA_SUCCESS;
6900 struct ddb_entry *ddb_entry = NULL;
6902 /* Create session object, with INVALID_ENTRY,
6903 * the targer_id would get set when we issue the login
6905 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6906 cmds_max, sizeof(struct ddb_entry),
6907 sizeof(struct ql4_task_data),
6908 initial_cmdsn, INVALID_ENTRY);
6915 * so calling module_put function to decrement the
6918 module_put(qla4xxx_iscsi_transport.owner);
6919 sess = cls_sess->dd_data;
6920 ddb_entry = sess->dd_data;
6921 ddb_entry->sess = cls_sess;
6923 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6924 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6925 sizeof(struct dev_db_entry));
6927 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6929 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6936 ddb_entry->conn = cls_conn;
6938 /* Setup ep, for displaying attributes in sysfs */
6939 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6941 ep->conn = cls_conn;
6944 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6949 /* Update sess/conn params */
6950 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6951 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6953 if (is_reset == RESET_ADAPTER) {
6954 iscsi_block_session(cls_sess);
6955 /* Use the relogin path to discover new devices
6956 * by short-circuiting the logic of setting
6957 * timer to relogin - instead set the flags
6958 * to initiate login right away.
6960 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6961 set_bit(DF_RELOGIN, &ddb_entry->flags);
6968 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6969 struct list_head *list_ddb,
6970 struct dev_db_entry *fw_ddb_entry)
6972 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6975 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6977 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6978 if (ddb_idx->fw_ddb_idx == ddb_link) {
6979 DEBUG2(ql4_printk(KERN_INFO, ha,
6980 "Updating NT parent idx from [%d] to [%d]\n",
6981 ddb_link, ddb_idx->flash_ddb_idx));
6982 fw_ddb_entry->ddb_link =
6983 cpu_to_le16(ddb_idx->flash_ddb_idx);
6989 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6990 struct list_head *list_nt,
6991 struct list_head *list_st,
6994 struct dev_db_entry *fw_ddb_entry;
6995 struct ddb_entry *ddb_entry = NULL;
6996 dma_addr_t fw_ddb_dma;
7000 uint32_t idx = 0, next_idx = 0;
7001 uint32_t state = 0, conn_err = 0;
7002 uint32_t ddb_idx = -1;
7003 uint16_t conn_id = 0;
7004 uint16_t ddb_link = -1;
7005 struct qla_ddb_index *nt_ddb_idx;
7007 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7009 if (fw_ddb_entry == NULL) {
7010 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7013 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7015 fw_idx_size = sizeof(struct qla_ddb_index);
7017 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7018 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7019 NULL, &next_idx, &state,
7020 &conn_err, NULL, &conn_id);
7021 if (ret == QLA_ERROR)
7024 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7025 goto continue_next_nt;
7027 /* Check if NT, then add to list it */
7028 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7029 goto continue_next_nt;
7031 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7032 if (ddb_link < max_ddbs)
7033 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7035 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7036 state == DDB_DS_SESSION_FAILED) &&
7037 (is_reset == INIT_ADAPTER))
7038 goto continue_next_nt;
7040 DEBUG2(ql4_printk(KERN_INFO, ha,
7041 "Adding DDB to session = 0x%x\n", idx));
7043 if (is_reset == INIT_ADAPTER) {
7044 nt_ddb_idx = vmalloc(fw_idx_size);
7048 nt_ddb_idx->fw_ddb_idx = idx;
7050 /* Copy original isid as it may get updated in function
7051 * qla4xxx_update_isid(). We need original isid in
7052 * function qla4xxx_compare_tuple_ddb to find duplicate
7054 memcpy(&nt_ddb_idx->flash_isid[0],
7055 &fw_ddb_entry->isid[0],
7056 sizeof(nt_ddb_idx->flash_isid));
7058 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7060 if (ret == QLA_SUCCESS) {
7061 /* free nt_ddb_idx and do not add to list_nt */
7063 goto continue_next_nt;
7066 /* Copy updated isid */
7067 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7068 sizeof(struct dev_db_entry));
7070 list_add_tail(&nt_ddb_idx->list, list_nt);
7071 } else if (is_reset == RESET_ADAPTER) {
7072 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7074 if (ret == QLA_SUCCESS) {
7075 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7077 if (ddb_entry != NULL)
7078 qla4xxx_update_sess_disc_idx(ha,
7081 goto continue_next_nt;
7085 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7086 if (ret == QLA_ERROR)
7096 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7099 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7100 struct list_head *list_nt,
7103 struct dev_db_entry *fw_ddb_entry;
7104 dma_addr_t fw_ddb_dma;
7108 uint32_t idx = 0, next_idx = 0;
7109 uint32_t state = 0, conn_err = 0;
7110 uint16_t conn_id = 0;
7111 struct qla_ddb_index *nt_ddb_idx;
7113 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7115 if (fw_ddb_entry == NULL) {
7116 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7117 goto exit_new_nt_list;
7119 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7121 fw_idx_size = sizeof(struct qla_ddb_index);
7123 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7124 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7125 NULL, &next_idx, &state,
7126 &conn_err, NULL, &conn_id);
7127 if (ret == QLA_ERROR)
7130 /* Check if NT, then add it to list */
7131 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7132 goto continue_next_new_nt;
7134 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7135 goto continue_next_new_nt;
7137 DEBUG2(ql4_printk(KERN_INFO, ha,
7138 "Adding DDB to session = 0x%x\n", idx));
7140 nt_ddb_idx = vmalloc(fw_idx_size);
7144 nt_ddb_idx->fw_ddb_idx = idx;
7146 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7147 if (ret == QLA_SUCCESS) {
7148 /* free nt_ddb_idx and do not add to list_nt */
7150 goto continue_next_new_nt;
7153 if (target_id < max_ddbs)
7154 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7156 list_add_tail(&nt_ddb_idx->list, list_nt);
7158 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7160 if (ret == QLA_ERROR)
7161 goto exit_new_nt_list;
7163 continue_next_new_nt:
7170 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7174 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7175 * @dev: dev associated with the sysfs entry
7176 * @data: pointer to flashnode session object
7179 * 1: if flashnode entry is non-persistent
7180 * 0: if flashnode entry is persistent
7182 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7184 struct iscsi_bus_flash_session *fnode_sess;
7186 if (!iscsi_flashnode_bus_match(dev, NULL))
7189 fnode_sess = iscsi_dev_to_flash_session(dev);
7191 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7195 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7196 * @ha: pointer to host
7197 * @fw_ddb_entry: flash ddb data
7198 * @idx: target index
7199 * @user: if set then this call is made from userland else from kernel
7202 * On sucess: QLA_SUCCESS
7203 * On failure: QLA_ERROR
7205 * This create separate sysfs entries for session and connection attributes of
7206 * the given fw ddb entry.
7207 * If this is invoked as a result of a userspace call then the entry is marked
7208 * as nonpersistent using flash_state field.
7210 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7211 struct dev_db_entry *fw_ddb_entry,
7212 uint16_t *idx, int user)
7214 struct iscsi_bus_flash_session *fnode_sess = NULL;
7215 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7218 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7219 &qla4xxx_iscsi_transport, 0);
7221 ql4_printk(KERN_ERR, ha,
7222 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7223 __func__, *idx, ha->host_no);
7224 goto exit_tgt_create;
7227 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7228 &qla4xxx_iscsi_transport, 0);
7230 ql4_printk(KERN_ERR, ha,
7231 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7232 __func__, *idx, ha->host_no);
7237 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7239 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7241 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7242 fnode_sess->is_boot_target = 1;
7244 fnode_sess->is_boot_target = 0;
7247 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7252 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7253 __func__, fnode_sess->dev.kobj.name);
7255 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7256 __func__, fnode_conn->dev.kobj.name);
7261 iscsi_destroy_flashnode_sess(fnode_sess);
7268 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7269 * @shost: pointer to host
7270 * @buf: type of ddb entry (ipv4/ipv6)
7271 * @len: length of buf
7273 * This creates new ddb entry in the flash by finding first free index and
7274 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7276 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7279 struct scsi_qla_host *ha = to_qla_host(shost);
7280 struct dev_db_entry *fw_ddb_entry = NULL;
7281 dma_addr_t fw_ddb_entry_dma;
7284 uint16_t max_ddbs = 0;
7285 uint32_t options = 0;
7286 uint32_t rval = QLA_ERROR;
7288 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7289 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7290 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7295 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7298 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7299 &fw_ddb_entry_dma, GFP_KERNEL);
7300 if (!fw_ddb_entry) {
7301 DEBUG2(ql4_printk(KERN_ERR, ha,
7302 "%s: Unable to allocate dma buffer\n",
7307 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7308 qla4xxx_sysfs_ddb_is_non_persistent);
7310 ql4_printk(KERN_ERR, ha,
7311 "%s: A non-persistent entry %s found\n",
7312 __func__, dev->kobj.name);
7317 /* Index 0 and 1 are reserved for boot target entries */
7318 for (idx = 2; idx < max_ddbs; idx++) {
7319 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7320 fw_ddb_entry_dma, idx))
7324 if (idx == max_ddbs)
7327 if (!strncasecmp("ipv6", buf, 4))
7328 options |= IPV6_DEFAULT_DDB_ENTRY;
7330 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7331 if (rval == QLA_ERROR)
7334 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7338 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7339 fw_ddb_entry, fw_ddb_entry_dma);
7340 if (rval == QLA_SUCCESS)
7347 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7348 * @fnode_sess: pointer to session attrs of flash ddb entry
7349 * @fnode_conn: pointer to connection attrs of flash ddb entry
7351 * This writes the contents of target ddb buffer to Flash with a valid cookie
7352 * value in order to make the ddb entry persistent.
7354 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7355 struct iscsi_bus_flash_conn *fnode_conn)
7357 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7358 struct scsi_qla_host *ha = to_qla_host(shost);
7359 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7360 struct dev_db_entry *fw_ddb_entry = NULL;
7361 dma_addr_t fw_ddb_entry_dma;
7362 uint32_t options = 0;
7365 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7366 &fw_ddb_entry_dma, GFP_KERNEL);
7367 if (!fw_ddb_entry) {
7368 DEBUG2(ql4_printk(KERN_ERR, ha,
7369 "%s: Unable to allocate dma buffer\n",
7372 goto exit_ddb_apply;
7375 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7376 options |= IPV6_DEFAULT_DDB_ENTRY;
7378 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7379 if (rval == QLA_ERROR)
7380 goto exit_ddb_apply;
7382 dev_db_start_offset += (fnode_sess->target_id *
7383 sizeof(*fw_ddb_entry));
7385 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7386 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7388 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7389 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7391 if (rval == QLA_SUCCESS) {
7392 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7393 ql4_printk(KERN_INFO, ha,
7394 "%s: flash node %u of host %lu written to flash\n",
7395 __func__, fnode_sess->target_id, ha->host_no);
7398 ql4_printk(KERN_ERR, ha,
7399 "%s: Error while writing flash node %u of host %lu to flash\n",
7400 __func__, fnode_sess->target_id, ha->host_no);
7405 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7406 fw_ddb_entry, fw_ddb_entry_dma);
7410 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7411 struct dev_db_entry *fw_ddb_entry,
7414 struct dev_db_entry *ddb_entry = NULL;
7415 dma_addr_t ddb_entry_dma;
7416 unsigned long wtime;
7417 uint32_t mbx_sts = 0;
7418 uint32_t state = 0, conn_err = 0;
7422 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7423 &ddb_entry_dma, GFP_KERNEL);
7425 DEBUG2(ql4_printk(KERN_ERR, ha,
7426 "%s: Unable to allocate dma buffer\n",
7431 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7433 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7434 if (ret != QLA_SUCCESS) {
7435 DEBUG2(ql4_printk(KERN_ERR, ha,
7436 "%s: Unable to set ddb entry for index %d\n",
7438 goto exit_ddb_conn_open;
7441 qla4xxx_conn_open(ha, idx);
7443 /* To ensure that sendtargets is done, wait for at least 12 secs */
7444 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7445 (ha->def_timeout < LOGIN_TOV * 10) ?
7446 ha->def_timeout : LOGIN_TOV);
7448 DEBUG2(ql4_printk(KERN_INFO, ha,
7449 "Default time to wait for login to ddb %d\n", tmo));
7451 wtime = jiffies + (HZ * tmo);
7453 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7454 NULL, &state, &conn_err, NULL,
7456 if (ret == QLA_ERROR)
7459 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7460 state == DDB_DS_SESSION_FAILED)
7463 schedule_timeout_uninterruptible(HZ / 10);
7464 } while (time_after(wtime, jiffies));
7468 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7469 ddb_entry, ddb_entry_dma);
7473 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7474 struct dev_db_entry *fw_ddb_entry,
7477 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7478 struct list_head list_nt;
7482 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7483 ql4_printk(KERN_WARNING, ha,
7484 "%s: A discovery already in progress!\n", __func__);
7488 INIT_LIST_HEAD(&list_nt);
7490 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7492 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7493 if (ret == QLA_ERROR)
7494 goto exit_login_st_clr_bit;
7496 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7497 if (ret == QLA_ERROR)
7500 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7502 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7503 list_del_init(&ddb_idx->list);
7504 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7509 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7510 ql4_printk(KERN_ERR, ha,
7511 "Unable to clear DDB index = 0x%x\n", ddb_index);
7514 clear_bit(ddb_index, ha->ddb_idx_map);
7516 exit_login_st_clr_bit:
7517 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7521 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7522 struct dev_db_entry *fw_ddb_entry,
7525 int ret = QLA_ERROR;
7527 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7528 if (ret != QLA_SUCCESS)
7529 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7538 * qla4xxx_sysfs_ddb_login - Login to the specified target
7539 * @fnode_sess: pointer to session attrs of flash ddb entry
7540 * @fnode_conn: pointer to connection attrs of flash ddb entry
7542 * This logs in to the specified target
7544 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7545 struct iscsi_bus_flash_conn *fnode_conn)
7547 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7548 struct scsi_qla_host *ha = to_qla_host(shost);
7549 struct dev_db_entry *fw_ddb_entry = NULL;
7550 dma_addr_t fw_ddb_entry_dma;
7551 uint32_t options = 0;
7554 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7555 ql4_printk(KERN_ERR, ha,
7556 "%s: Target info is not persistent\n", __func__);
7558 goto exit_ddb_login;
7561 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7562 &fw_ddb_entry_dma, GFP_KERNEL);
7563 if (!fw_ddb_entry) {
7564 DEBUG2(ql4_printk(KERN_ERR, ha,
7565 "%s: Unable to allocate dma buffer\n",
7568 goto exit_ddb_login;
7571 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7572 options |= IPV6_DEFAULT_DDB_ENTRY;
7574 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7575 if (ret == QLA_ERROR)
7576 goto exit_ddb_login;
7578 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7579 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7581 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7582 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7583 fnode_sess->target_id);
7585 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7586 fnode_sess->target_id);
7593 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7594 fw_ddb_entry, fw_ddb_entry_dma);
7599 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7600 * @cls_sess: pointer to session to be logged out
7602 * This performs session log out from the specified target
7604 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7606 struct iscsi_session *sess;
7607 struct ddb_entry *ddb_entry = NULL;
7608 struct scsi_qla_host *ha;
7609 struct dev_db_entry *fw_ddb_entry = NULL;
7610 dma_addr_t fw_ddb_entry_dma;
7611 unsigned long flags;
7612 unsigned long wtime;
7617 sess = cls_sess->dd_data;
7618 ddb_entry = sess->dd_data;
7621 if (ddb_entry->ddb_type != FLASH_DDB) {
7622 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7625 goto exit_ddb_logout;
7628 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7629 ql4_printk(KERN_ERR, ha,
7630 "%s: Logout from boot target entry is not permitted.\n",
7633 goto exit_ddb_logout;
7636 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7637 &fw_ddb_entry_dma, GFP_KERNEL);
7638 if (!fw_ddb_entry) {
7639 ql4_printk(KERN_ERR, ha,
7640 "%s: Unable to allocate dma buffer\n", __func__);
7642 goto exit_ddb_logout;
7645 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7646 goto ddb_logout_init;
7648 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7649 fw_ddb_entry, fw_ddb_entry_dma,
7650 NULL, NULL, &ddb_state, NULL,
7652 if (ret == QLA_ERROR)
7653 goto ddb_logout_init;
7655 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7656 goto ddb_logout_init;
7658 /* wait until next relogin is triggered using DF_RELOGIN and
7659 * clear DF_RELOGIN to avoid invocation of further relogin
7661 wtime = jiffies + (HZ * RELOGIN_TOV);
7663 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7664 goto ddb_logout_init;
7666 schedule_timeout_uninterruptible(HZ);
7667 } while ((time_after(wtime, jiffies)));
7670 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7671 atomic_set(&ddb_entry->relogin_timer, 0);
7673 options = LOGOUT_OPTION_CLOSE_SESSION;
7674 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7676 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7677 wtime = jiffies + (HZ * LOGOUT_TOV);
7679 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7680 fw_ddb_entry, fw_ddb_entry_dma,
7681 NULL, NULL, &ddb_state, NULL,
7683 if (ret == QLA_ERROR)
7684 goto ddb_logout_clr_sess;
7686 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7687 (ddb_state == DDB_DS_SESSION_FAILED))
7688 goto ddb_logout_clr_sess;
7690 schedule_timeout_uninterruptible(HZ);
7691 } while ((time_after(wtime, jiffies)));
7693 ddb_logout_clr_sess:
7694 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7696 * we have decremented the reference count of the driver
7697 * when we setup the session to have the driver unload
7698 * to be seamless without actually destroying the
7701 try_module_get(qla4xxx_iscsi_transport.owner);
7702 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7704 spin_lock_irqsave(&ha->hardware_lock, flags);
7705 qla4xxx_free_ddb(ha, ddb_entry);
7706 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7707 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7709 iscsi_session_teardown(ddb_entry->sess);
7711 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7716 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7717 fw_ddb_entry, fw_ddb_entry_dma);
7722 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7723 * @fnode_sess: pointer to session attrs of flash ddb entry
7724 * @fnode_conn: pointer to connection attrs of flash ddb entry
7726 * This performs log out from the specified target
7728 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7729 struct iscsi_bus_flash_conn *fnode_conn)
7731 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7732 struct scsi_qla_host *ha = to_qla_host(shost);
7733 struct ql4_tuple_ddb *flash_tddb = NULL;
7734 struct ql4_tuple_ddb *tmp_tddb = NULL;
7735 struct dev_db_entry *fw_ddb_entry = NULL;
7736 struct ddb_entry *ddb_entry = NULL;
7737 dma_addr_t fw_ddb_dma;
7738 uint32_t next_idx = 0;
7739 uint32_t state = 0, conn_err = 0;
7740 uint16_t conn_id = 0;
7742 int status, ret = 0;
7744 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7746 if (fw_ddb_entry == NULL) {
7747 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7749 goto exit_ddb_logout;
7752 flash_tddb = vzalloc(sizeof(*flash_tddb));
7754 ql4_printk(KERN_WARNING, ha,
7755 "%s:Memory Allocation failed.\n", __func__);
7757 goto exit_ddb_logout;
7760 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7762 ql4_printk(KERN_WARNING, ha,
7763 "%s:Memory Allocation failed.\n", __func__);
7765 goto exit_ddb_logout;
7768 if (!fnode_sess->targetname) {
7769 ql4_printk(KERN_ERR, ha,
7770 "%s:Cannot logout from SendTarget entry\n",
7773 goto exit_ddb_logout;
7776 if (fnode_sess->is_boot_target) {
7777 ql4_printk(KERN_ERR, ha,
7778 "%s: Logout from boot target entry is not permitted.\n",
7781 goto exit_ddb_logout;
7784 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7787 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7788 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7790 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7792 flash_tddb->tpgt = fnode_sess->tpgt;
7793 flash_tddb->port = fnode_conn->port;
7795 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7797 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7798 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7799 if (ddb_entry == NULL)
7802 if (ddb_entry->ddb_type != FLASH_DDB)
7805 index = ddb_entry->sess->target_id;
7806 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7807 fw_ddb_dma, NULL, &next_idx,
7808 &state, &conn_err, NULL,
7810 if (status == QLA_ERROR) {
7815 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7817 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7819 if (status == QLA_SUCCESS) {
7820 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7825 if (idx == MAX_DDB_ENTRIES)
7832 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7838 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7839 int param, char *buf)
7841 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7842 struct scsi_qla_host *ha = to_qla_host(shost);
7843 struct iscsi_bus_flash_conn *fnode_conn;
7844 struct ql4_chap_table chap_tbl;
7849 dev = iscsi_find_flashnode_conn(fnode_sess);
7853 fnode_conn = iscsi_dev_to_flash_conn(dev);
7856 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7857 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7859 case ISCSI_FLASHNODE_PORTAL_TYPE:
7860 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7862 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7863 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7865 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7866 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7868 case ISCSI_FLASHNODE_ENTRY_EN:
7869 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7871 case ISCSI_FLASHNODE_HDR_DGST_EN:
7872 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7874 case ISCSI_FLASHNODE_DATA_DGST_EN:
7875 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7877 case ISCSI_FLASHNODE_IMM_DATA_EN:
7878 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7880 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7881 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7883 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7884 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7886 case ISCSI_FLASHNODE_PDU_INORDER:
7887 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7889 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7890 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7892 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7893 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7895 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7896 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7898 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7899 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7901 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7902 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7904 case ISCSI_FLASHNODE_ERL:
7905 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7907 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7908 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7910 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7911 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7913 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7914 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7916 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7917 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7919 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7920 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7922 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7923 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7925 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7926 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7928 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7929 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7931 case ISCSI_FLASHNODE_FIRST_BURST:
7932 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7934 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7935 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7937 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7938 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7940 case ISCSI_FLASHNODE_MAX_R2T:
7941 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7943 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7944 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7946 case ISCSI_FLASHNODE_ISID:
7947 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7949 case ISCSI_FLASHNODE_TSID:
7950 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7952 case ISCSI_FLASHNODE_PORT:
7953 rc = sprintf(buf, "%d\n", fnode_conn->port);
7955 case ISCSI_FLASHNODE_MAX_BURST:
7956 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7958 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7959 rc = sprintf(buf, "%u\n",
7960 fnode_sess->default_taskmgmt_timeout);
7962 case ISCSI_FLASHNODE_IPADDR:
7963 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7964 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7966 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7968 case ISCSI_FLASHNODE_ALIAS:
7969 if (fnode_sess->targetalias)
7970 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7972 rc = sprintf(buf, "\n");
7974 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7975 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7976 rc = sprintf(buf, "%pI6\n",
7977 fnode_conn->redirect_ipaddr);
7979 rc = sprintf(buf, "%pI4\n",
7980 fnode_conn->redirect_ipaddr);
7982 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7983 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7985 case ISCSI_FLASHNODE_LOCAL_PORT:
7986 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7988 case ISCSI_FLASHNODE_IPV4_TOS:
7989 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7991 case ISCSI_FLASHNODE_IPV6_TC:
7992 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7993 rc = sprintf(buf, "%u\n",
7994 fnode_conn->ipv6_traffic_class);
7996 rc = sprintf(buf, "\n");
7998 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7999 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8001 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8002 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8003 rc = sprintf(buf, "%pI6\n",
8004 fnode_conn->link_local_ipv6_addr);
8006 rc = sprintf(buf, "\n");
8008 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8009 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8011 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8012 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8013 parent_type = ISCSI_DISC_PARENT_ISNS;
8014 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8015 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8016 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8017 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8019 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8021 rc = sprintf(buf, "%s\n",
8022 iscsi_get_discovery_parent_name(parent_type));
8024 case ISCSI_FLASHNODE_NAME:
8025 if (fnode_sess->targetname)
8026 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8028 rc = sprintf(buf, "\n");
8030 case ISCSI_FLASHNODE_TPGT:
8031 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8033 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8034 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8036 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8037 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8039 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8040 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8042 case ISCSI_FLASHNODE_USERNAME:
8043 if (fnode_sess->chap_auth_en) {
8044 qla4xxx_get_uni_chap_at_index(ha,
8047 fnode_sess->chap_out_idx);
8048 rc = sprintf(buf, "%s\n", chap_tbl.name);
8050 rc = sprintf(buf, "\n");
8053 case ISCSI_FLASHNODE_PASSWORD:
8054 if (fnode_sess->chap_auth_en) {
8055 qla4xxx_get_uni_chap_at_index(ha,
8058 fnode_sess->chap_out_idx);
8059 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8061 rc = sprintf(buf, "\n");
8064 case ISCSI_FLASHNODE_STATSN:
8065 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8067 case ISCSI_FLASHNODE_EXP_STATSN:
8068 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8070 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8071 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8083 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8084 * @fnode_sess: pointer to session attrs of flash ddb entry
8085 * @fnode_conn: pointer to connection attrs of flash ddb entry
8086 * @data: Parameters and their values to update
8089 * This sets the parameter of flash ddb entry and writes them to flash
8092 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8093 struct iscsi_bus_flash_conn *fnode_conn,
8094 void *data, int len)
8096 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8097 struct scsi_qla_host *ha = to_qla_host(shost);
8098 struct iscsi_flashnode_param_info *fnode_param;
8099 struct ql4_chap_table chap_tbl;
8100 struct nlattr *attr;
8101 uint16_t chap_out_idx = INVALID_ENTRY;
8105 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8106 nla_for_each_attr(attr, data, len, rem) {
8107 fnode_param = nla_data(attr);
8109 switch (fnode_param->param) {
8110 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8111 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8113 case ISCSI_FLASHNODE_PORTAL_TYPE:
8114 memcpy(fnode_sess->portal_type, fnode_param->value,
8115 strlen(fnode_sess->portal_type));
8117 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8118 fnode_sess->auto_snd_tgt_disable =
8119 fnode_param->value[0];
8121 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8122 fnode_sess->discovery_sess = fnode_param->value[0];
8124 case ISCSI_FLASHNODE_ENTRY_EN:
8125 fnode_sess->entry_state = fnode_param->value[0];
8127 case ISCSI_FLASHNODE_HDR_DGST_EN:
8128 fnode_conn->hdrdgst_en = fnode_param->value[0];
8130 case ISCSI_FLASHNODE_DATA_DGST_EN:
8131 fnode_conn->datadgst_en = fnode_param->value[0];
8133 case ISCSI_FLASHNODE_IMM_DATA_EN:
8134 fnode_sess->imm_data_en = fnode_param->value[0];
8136 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8137 fnode_sess->initial_r2t_en = fnode_param->value[0];
8139 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8140 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8142 case ISCSI_FLASHNODE_PDU_INORDER:
8143 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8145 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8146 fnode_sess->chap_auth_en = fnode_param->value[0];
8147 /* Invalidate chap index if chap auth is disabled */
8148 if (!fnode_sess->chap_auth_en)
8149 fnode_sess->chap_out_idx = INVALID_ENTRY;
8152 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8153 fnode_conn->snack_req_en = fnode_param->value[0];
8155 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8156 fnode_sess->discovery_logout_en = fnode_param->value[0];
8158 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8159 fnode_sess->bidi_chap_en = fnode_param->value[0];
8161 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8162 fnode_sess->discovery_auth_optional =
8163 fnode_param->value[0];
8165 case ISCSI_FLASHNODE_ERL:
8166 fnode_sess->erl = fnode_param->value[0];
8168 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8169 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8171 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8172 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8174 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8175 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8177 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8178 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8180 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8181 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8183 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8184 fnode_conn->fragment_disable = fnode_param->value[0];
8186 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8187 fnode_conn->max_recv_dlength =
8188 *(unsigned *)fnode_param->value;
8190 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8191 fnode_conn->max_xmit_dlength =
8192 *(unsigned *)fnode_param->value;
8194 case ISCSI_FLASHNODE_FIRST_BURST:
8195 fnode_sess->first_burst =
8196 *(unsigned *)fnode_param->value;
8198 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8199 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8201 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8202 fnode_sess->time2retain =
8203 *(uint16_t *)fnode_param->value;
8205 case ISCSI_FLASHNODE_MAX_R2T:
8206 fnode_sess->max_r2t =
8207 *(uint16_t *)fnode_param->value;
8209 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8210 fnode_conn->keepalive_timeout =
8211 *(uint16_t *)fnode_param->value;
8213 case ISCSI_FLASHNODE_ISID:
8214 memcpy(fnode_sess->isid, fnode_param->value,
8215 sizeof(fnode_sess->isid));
8217 case ISCSI_FLASHNODE_TSID:
8218 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8220 case ISCSI_FLASHNODE_PORT:
8221 fnode_conn->port = *(uint16_t *)fnode_param->value;
8223 case ISCSI_FLASHNODE_MAX_BURST:
8224 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8226 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8227 fnode_sess->default_taskmgmt_timeout =
8228 *(uint16_t *)fnode_param->value;
8230 case ISCSI_FLASHNODE_IPADDR:
8231 memcpy(fnode_conn->ipaddress, fnode_param->value,
8234 case ISCSI_FLASHNODE_ALIAS:
8235 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8236 (char *)fnode_param->value);
8238 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8239 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8242 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8243 fnode_conn->max_segment_size =
8244 *(unsigned *)fnode_param->value;
8246 case ISCSI_FLASHNODE_LOCAL_PORT:
8247 fnode_conn->local_port =
8248 *(uint16_t *)fnode_param->value;
8250 case ISCSI_FLASHNODE_IPV4_TOS:
8251 fnode_conn->ipv4_tos = fnode_param->value[0];
8253 case ISCSI_FLASHNODE_IPV6_TC:
8254 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8256 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8257 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8259 case ISCSI_FLASHNODE_NAME:
8260 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8261 (char *)fnode_param->value);
8263 case ISCSI_FLASHNODE_TPGT:
8264 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8266 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8267 memcpy(fnode_conn->link_local_ipv6_addr,
8268 fnode_param->value, IPv6_ADDR_LEN);
8270 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8271 fnode_sess->discovery_parent_idx =
8272 *(uint16_t *)fnode_param->value;
8274 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8275 fnode_conn->tcp_xmit_wsf =
8276 *(uint8_t *)fnode_param->value;
8278 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8279 fnode_conn->tcp_recv_wsf =
8280 *(uint8_t *)fnode_param->value;
8282 case ISCSI_FLASHNODE_STATSN:
8283 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8285 case ISCSI_FLASHNODE_EXP_STATSN:
8286 fnode_conn->exp_statsn =
8287 *(uint32_t *)fnode_param->value;
8289 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8290 chap_out_idx = *(uint16_t *)fnode_param->value;
8291 if (!qla4xxx_get_uni_chap_at_index(ha,
8295 fnode_sess->chap_out_idx = chap_out_idx;
8296 /* Enable chap auth if chap index is valid */
8297 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8301 ql4_printk(KERN_ERR, ha,
8302 "%s: No such sysfs attribute\n", __func__);
8304 goto exit_set_param;
8308 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8315 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8316 * @fnode_sess: pointer to session attrs of flash ddb entry
8318 * This invalidates the flash ddb entry at the given index
8320 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8322 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8323 struct scsi_qla_host *ha = to_qla_host(shost);
8324 uint32_t dev_db_start_offset;
8325 uint32_t dev_db_end_offset;
8326 struct dev_db_entry *fw_ddb_entry = NULL;
8327 dma_addr_t fw_ddb_entry_dma;
8328 uint16_t *ddb_cookie = NULL;
8329 size_t ddb_size = 0;
8334 if (fnode_sess->is_boot_target) {
8336 DEBUG2(ql4_printk(KERN_ERR, ha,
8337 "%s: Deletion of boot target entry is not permitted.\n",
8342 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8345 if (is_qla40XX(ha)) {
8346 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8347 dev_db_end_offset = FLASH_OFFSET_DB_END;
8348 dev_db_start_offset += (fnode_sess->target_id *
8349 sizeof(*fw_ddb_entry));
8350 ddb_size = sizeof(*fw_ddb_entry);
8352 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8353 (ha->hw.flt_region_ddb << 2);
8354 /* flt_ddb_size is DDB table size for both ports
8355 * so divide it by 2 to calculate the offset for second port
8357 if (ha->port_num == 1)
8358 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8360 dev_db_end_offset = dev_db_start_offset +
8361 (ha->hw.flt_ddb_size / 2);
8363 dev_db_start_offset += (fnode_sess->target_id *
8364 sizeof(*fw_ddb_entry));
8365 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8367 ddb_size = sizeof(*ddb_cookie);
8370 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8371 __func__, dev_db_start_offset, dev_db_end_offset));
8373 if (dev_db_start_offset > dev_db_end_offset) {
8375 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8376 __func__, fnode_sess->target_id));
8380 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8381 &fw_ddb_entry_dma, GFP_KERNEL);
8384 DEBUG2(ql4_printk(KERN_ERR, ha,
8385 "%s: Unable to allocate dma buffer\n",
8390 if (is_qla40XX(ha)) {
8391 fw_ddb_entry = pddb;
8392 memset(fw_ddb_entry, 0, ddb_size);
8393 ddb_cookie = &fw_ddb_entry->cookie;
8398 /* invalidate the cookie */
8399 *ddb_cookie = 0xFFEE;
8400 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8401 ddb_size, FLASH_OPT_RMW_COMMIT);
8404 target_id = fnode_sess->target_id;
8405 iscsi_destroy_flashnode_sess(fnode_sess);
8406 ql4_printk(KERN_INFO, ha,
8407 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8408 __func__, target_id, ha->host_no);
8411 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8417 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8418 * @ha: pointer to adapter structure
8420 * Export the firmware DDB for all send targets and normal targets to sysfs.
8422 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8424 struct dev_db_entry *fw_ddb_entry = NULL;
8425 dma_addr_t fw_ddb_entry_dma;
8428 int ret = QLA_SUCCESS;
8430 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8431 sizeof(*fw_ddb_entry),
8432 &fw_ddb_entry_dma, GFP_KERNEL);
8433 if (!fw_ddb_entry) {
8434 DEBUG2(ql4_printk(KERN_ERR, ha,
8435 "%s: Unable to allocate dma buffer\n",
8440 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8443 for (idx = 0; idx < max_ddbs; idx++) {
8444 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8448 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8455 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8461 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8463 iscsi_destroy_all_flashnode(ha->host);
8467 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8468 * @ha: pointer to adapter structure
8469 * @is_reset: Is this init path or reset path
8471 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8472 * using connection open, then create the list of normal targets (nt)
8473 * from firmware DDBs. Based on the list of nt setup session and connection
8476 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8479 struct list_head list_st, list_nt;
8480 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8481 unsigned long wtime;
8483 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8484 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8485 ha->is_reset = is_reset;
8489 INIT_LIST_HEAD(&list_st);
8490 INIT_LIST_HEAD(&list_nt);
8492 qla4xxx_build_st_list(ha, &list_st);
8494 /* Before issuing conn open mbox, ensure all IPs states are configured
8495 * Note, conn open fails if IPs are not configured
8497 qla4xxx_wait_for_ip_configuration(ha);
8499 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8500 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8501 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8504 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8505 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8506 (ha->def_timeout < LOGIN_TOV * 10) ?
8507 ha->def_timeout : LOGIN_TOV);
8509 DEBUG2(ql4_printk(KERN_INFO, ha,
8510 "Default time to wait for build ddb %d\n", tmo));
8512 wtime = jiffies + (HZ * tmo);
8514 if (list_empty(&list_st))
8517 qla4xxx_remove_failed_ddb(ha, &list_st);
8518 schedule_timeout_uninterruptible(HZ / 10);
8519 } while (time_after(wtime, jiffies));
8522 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8524 qla4xxx_free_ddb_list(&list_st);
8525 qla4xxx_free_ddb_list(&list_nt);
8527 qla4xxx_free_ddb_index(ha);
8531 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8533 * @ha: pointer to adapter structure
8535 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8536 * set in DDB and we will wait for login response of boot targets during
8539 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8541 struct ddb_entry *ddb_entry;
8542 struct dev_db_entry *fw_ddb_entry = NULL;
8543 dma_addr_t fw_ddb_entry_dma;
8544 unsigned long wtime;
8546 int max_ddbs, idx, ret;
8548 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8551 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8552 &fw_ddb_entry_dma, GFP_KERNEL);
8553 if (!fw_ddb_entry) {
8554 ql4_printk(KERN_ERR, ha,
8555 "%s: Unable to allocate dma buffer\n", __func__);
8556 goto exit_login_resp;
8559 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8561 for (idx = 0; idx < max_ddbs; idx++) {
8562 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8563 if (ddb_entry == NULL)
8566 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8567 DEBUG2(ql4_printk(KERN_INFO, ha,
8568 "%s: DDB index [%d]\n", __func__,
8569 ddb_entry->fw_ddb_index));
8571 ret = qla4xxx_get_fwddb_entry(ha,
8572 ddb_entry->fw_ddb_index,
8573 fw_ddb_entry, fw_ddb_entry_dma,
8574 NULL, NULL, &ddb_state, NULL,
8576 if (ret == QLA_ERROR)
8577 goto exit_login_resp;
8579 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8580 (ddb_state == DDB_DS_SESSION_FAILED))
8583 schedule_timeout_uninterruptible(HZ);
8585 } while ((time_after(wtime, jiffies)));
8587 if (!time_after(wtime, jiffies)) {
8588 DEBUG2(ql4_printk(KERN_INFO, ha,
8589 "%s: Login response wait timer expired\n",
8591 goto exit_login_resp;
8598 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8599 fw_ddb_entry, fw_ddb_entry_dma);
8603 * qla4xxx_probe_adapter - callback function to probe HBA
8604 * @pdev: pointer to pci_dev structure
8605 * @ent: pointer to pci_device entry
8607 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8608 * It returns zero if successful. It also initializes all data necessary for
8611 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8612 const struct pci_device_id *ent)
8614 int ret = -ENODEV, status;
8615 struct Scsi_Host *host;
8616 struct scsi_qla_host *ha;
8617 uint8_t init_retry_count = 0;
8619 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8622 if (pci_enable_device(pdev))
8625 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8628 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8629 goto probe_disable_device;
8632 /* Clear our data area */
8633 ha = to_qla_host(host);
8634 memset(ha, 0, sizeof(*ha));
8636 /* Save the information from PCI BIOS. */
8639 ha->host_no = host->host_no;
8640 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8642 pci_enable_pcie_error_reporting(pdev);
8644 /* Setup Runtime configurable options */
8645 if (is_qla8022(ha)) {
8646 ha->isp_ops = &qla4_82xx_isp_ops;
8647 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8648 ha->qdr_sn_window = -1;
8649 ha->ddr_mn_window = -1;
8650 ha->curr_window = 255;
8651 nx_legacy_intr = &legacy_intr[ha->func_num];
8652 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8653 ha->nx_legacy_intr.tgt_status_reg =
8654 nx_legacy_intr->tgt_status_reg;
8655 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8656 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8657 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8658 ha->isp_ops = &qla4_83xx_isp_ops;
8659 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8661 ha->isp_ops = &qla4xxx_isp_ops;
8664 if (is_qla80XX(ha)) {
8665 rwlock_init(&ha->hw_lock);
8666 ha->pf_bit = ha->func_num << 16;
8667 /* Set EEH reset type to fundamental if required by hba */
8668 pdev->needs_freset = 1;
8671 /* Configure PCI I/O space. */
8672 ret = ha->isp_ops->iospace_config(ha);
8674 goto probe_failed_ioconfig;
8676 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8677 pdev->device, pdev->irq, ha->reg);
8679 qla4xxx_config_dma_addressing(ha);
8681 /* Initialize lists and spinlocks. */
8682 INIT_LIST_HEAD(&ha->free_srb_q);
8684 mutex_init(&ha->mbox_sem);
8685 mutex_init(&ha->chap_sem);
8686 init_completion(&ha->mbx_intr_comp);
8687 init_completion(&ha->disable_acb_comp);
8688 init_completion(&ha->idc_comp);
8689 init_completion(&ha->link_up_comp);
8691 spin_lock_init(&ha->hardware_lock);
8692 spin_lock_init(&ha->work_lock);
8694 /* Initialize work list */
8695 INIT_LIST_HEAD(&ha->work_list);
8697 /* Allocate dma buffers */
8698 if (qla4xxx_mem_alloc(ha)) {
8699 ql4_printk(KERN_WARNING, ha,
8700 "[ERROR] Failed to allocate memory for adapter\n");
8706 host->cmd_per_lun = 3;
8707 host->max_channel = 0;
8708 host->max_lun = MAX_LUNS - 1;
8709 host->max_id = MAX_TARGETS;
8710 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8711 host->can_queue = MAX_SRBS ;
8712 host->transportt = qla4xxx_scsi_transport;
8714 pci_set_drvdata(pdev, ha);
8716 ret = scsi_add_host(host, &pdev->dev);
8721 qla4_8xxx_get_flash_info(ha);
8723 if (is_qla8032(ha) || is_qla8042(ha)) {
8724 qla4_83xx_read_reset_template(ha);
8726 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8727 * If DONRESET_BIT0 is set, drivers should not set dev_state
8728 * to NEED_RESET. But if NEED_RESET is set, drivers should
8729 * should honor the reset.
8731 if (ql4xdontresethba == 1)
8732 qla4_83xx_set_idc_dontreset(ha);
8736 * Initialize the Host adapter request/response queues and
8738 * NOTE: interrupts enabled upon successful completion
8740 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8742 /* Dont retry adapter initialization if IRQ allocation failed */
8743 if (is_qla80XX(ha) && (status == QLA_ERROR))
8744 goto skip_retry_init;
8746 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8747 init_retry_count++ < MAX_INIT_RETRIES) {
8749 if (is_qla80XX(ha)) {
8750 ha->isp_ops->idc_lock(ha);
8751 dev_state = qla4_8xxx_rd_direct(ha,
8752 QLA8XXX_CRB_DEV_STATE);
8753 ha->isp_ops->idc_unlock(ha);
8754 if (dev_state == QLA8XXX_DEV_FAILED) {
8755 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8756 "initialize adapter. H/W is in failed state\n",
8761 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8762 "(%d)\n", __func__, init_retry_count));
8764 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8767 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8768 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8769 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8770 goto skip_retry_init;
8775 if (!test_bit(AF_ONLINE, &ha->flags)) {
8776 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8778 if ((is_qla8022(ha) && ql4xdontresethba) ||
8779 ((is_qla8032(ha) || is_qla8042(ha)) &&
8780 qla4_83xx_idc_dontreset(ha))) {
8781 /* Put the device in failed state. */
8782 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8783 ha->isp_ops->idc_lock(ha);
8784 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8785 QLA8XXX_DEV_FAILED);
8786 ha->isp_ops->idc_unlock(ha);
8792 /* Startup the kernel thread for this host adapter. */
8793 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8794 "qla4xxx_dpc\n", __func__));
8795 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8796 ha->dpc_thread = create_singlethread_workqueue(buf);
8797 if (!ha->dpc_thread) {
8798 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8802 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8804 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8807 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8813 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8814 * (which is called indirectly by qla4xxx_initialize_adapter),
8815 * so that irqs will be registered after crbinit but before
8818 if (is_qla40XX(ha)) {
8819 ret = qla4xxx_request_irqs(ha);
8821 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8822 "interrupt %d already in use.\n", pdev->irq);
8827 pci_save_state(ha->pdev);
8828 ha->isp_ops->enable_intrs(ha);
8830 /* Start timer thread. */
8831 qla4xxx_start_timer(ha, 1);
8833 set_bit(AF_INIT_DONE, &ha->flags);
8835 qla4_8xxx_alloc_sysfs_attr(ha);
8838 " QLogic iSCSI HBA Driver version: %s\n"
8839 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8840 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8841 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8842 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8844 /* Set the driver version */
8846 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8848 if (qla4xxx_setup_boot_info(ha))
8849 ql4_printk(KERN_ERR, ha,
8850 "%s: No iSCSI boot target configured\n", __func__);
8852 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8853 /* Perform the build ddb list and login to each */
8854 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8855 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8856 qla4xxx_wait_login_resp_boot_tgt(ha);
8858 qla4xxx_create_chap_list(ha);
8860 qla4xxx_create_ifaces(ha);
8864 scsi_remove_host(ha->host);
8867 qla4xxx_free_adapter(ha);
8869 probe_failed_ioconfig:
8870 pci_disable_pcie_error_reporting(pdev);
8871 scsi_host_put(ha->host);
8873 probe_disable_device:
8874 pci_disable_device(pdev);
8880 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8881 * @ha: pointer to adapter structure
8883 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8884 * so that the other port will not re-initialize while in the process of
8885 * removing the ha due to driver unload or hba hotplug.
8887 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8889 struct scsi_qla_host *other_ha = NULL;
8890 struct pci_dev *other_pdev = NULL;
8891 int fn = ISP4XXX_PCI_FN_2;
8893 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8894 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8895 fn = ISP4XXX_PCI_FN_1;
8898 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8899 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8902 /* Get other_ha if other_pdev is valid and state is enable*/
8904 if (atomic_read(&other_pdev->enable_cnt)) {
8905 other_ha = pci_get_drvdata(other_pdev);
8907 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8908 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8909 "Prevent %s reinit\n", __func__,
8910 dev_name(&other_ha->pdev->dev)));
8913 pci_dev_put(other_pdev);
8917 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8918 struct ddb_entry *ddb_entry)
8920 struct dev_db_entry *fw_ddb_entry = NULL;
8921 dma_addr_t fw_ddb_entry_dma;
8922 unsigned long wtime;
8927 options = LOGOUT_OPTION_CLOSE_SESSION;
8928 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8929 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8933 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8934 &fw_ddb_entry_dma, GFP_KERNEL);
8935 if (!fw_ddb_entry) {
8936 ql4_printk(KERN_ERR, ha,
8937 "%s: Unable to allocate dma buffer\n", __func__);
8941 wtime = jiffies + (HZ * LOGOUT_TOV);
8943 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8944 fw_ddb_entry, fw_ddb_entry_dma,
8945 NULL, NULL, &ddb_state, NULL,
8947 if (status == QLA_ERROR)
8950 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8951 (ddb_state == DDB_DS_SESSION_FAILED))
8954 schedule_timeout_uninterruptible(HZ);
8955 } while ((time_after(wtime, jiffies)));
8958 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8959 fw_ddb_entry, fw_ddb_entry_dma);
8961 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8964 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8966 struct ddb_entry *ddb_entry;
8969 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8971 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8972 if ((ddb_entry != NULL) &&
8973 (ddb_entry->ddb_type == FLASH_DDB)) {
8975 qla4xxx_destroy_ddb(ha, ddb_entry);
8977 * we have decremented the reference count of the driver
8978 * when we setup the session to have the driver unload
8979 * to be seamless without actually destroying the
8982 try_module_get(qla4xxx_iscsi_transport.owner);
8983 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8984 qla4xxx_free_ddb(ha, ddb_entry);
8985 iscsi_session_teardown(ddb_entry->sess);
8990 * qla4xxx_remove_adapter - callback function to remove adapter.
8991 * @pdev: PCI device pointer
8993 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
8995 struct scsi_qla_host *ha;
8998 * If the PCI device is disabled then it means probe_adapter had
8999 * failed and resources already cleaned up on probe_adapter exit.
9001 if (!pci_is_enabled(pdev))
9004 ha = pci_get_drvdata(pdev);
9007 qla4xxx_prevent_other_port_reinit(ha);
9009 /* destroy iface from sysfs */
9010 qla4xxx_destroy_ifaces(ha);
9012 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9013 iscsi_boot_destroy_kset(ha->boot_kset);
9015 qla4xxx_destroy_fw_ddb_session(ha);
9016 qla4_8xxx_free_sysfs_attr(ha);
9018 qla4xxx_sysfs_ddb_remove(ha);
9019 scsi_remove_host(ha->host);
9021 qla4xxx_free_adapter(ha);
9023 scsi_host_put(ha->host);
9025 pci_disable_pcie_error_reporting(pdev);
9026 pci_disable_device(pdev);
9030 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9033 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9035 /* Update our PCI device dma_mask for full 64 bit mask */
9036 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9037 dev_dbg(&ha->pdev->dev,
9038 "Failed to set 64 bit PCI consistent mask; "
9040 dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9044 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9046 struct iscsi_cls_session *cls_sess;
9047 struct iscsi_session *sess;
9048 struct ddb_entry *ddb;
9049 int queue_depth = QL4_DEF_QDEPTH;
9051 cls_sess = starget_to_session(sdev->sdev_target);
9052 sess = cls_sess->dd_data;
9053 ddb = sess->dd_data;
9055 sdev->hostdata = ddb;
9057 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9058 queue_depth = ql4xmaxqdepth;
9060 scsi_change_queue_depth(sdev, queue_depth);
9065 * qla4xxx_del_from_active_array - returns an active srb
9066 * @ha: Pointer to host adapter structure.
9067 * @index: index into the active_array
9069 * This routine removes and returns the srb at the specified index
9071 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9074 struct srb *srb = NULL;
9075 struct scsi_cmnd *cmd = NULL;
9077 cmd = scsi_host_find_tag(ha->host, index);
9081 srb = qla4xxx_cmd_priv(cmd)->srb;
9085 /* update counters */
9086 if (srb->flags & SRB_DMA_VALID) {
9087 ha->iocb_cnt -= srb->iocb_cnt;
9089 srb->cmd->host_scribble =
9090 (unsigned char *)(unsigned long) MAX_SRBS;
9096 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9097 * @ha: Pointer to host adapter structure.
9098 * @cmd: Scsi Command to wait on.
9100 * This routine waits for the command to be returned by the Firmware
9101 * for some max time.
9103 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9104 struct scsi_cmnd *cmd)
9108 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9111 /* Dont wait on command if PCI error is being handled
9114 if (unlikely(pci_channel_offline(ha->pdev)) ||
9115 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9116 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9117 ha->host_no, __func__);
9122 /* Checking to see if its returned to OS */
9123 rp = qla4xxx_cmd_priv(cmd)->srb;
9130 } while (max_wait_time--);
9136 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9137 * @ha: Pointer to host adapter structure
9139 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9141 unsigned long wait_online;
9143 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9144 while (time_before(jiffies, wait_online)) {
9156 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9157 * @ha: pointer to HBA
9158 * @stgt: pointer to SCSI target
9159 * @sdev: pointer to SCSI device
9161 * This function waits for all outstanding commands to a lun to complete. It
9162 * returns 0 if all pending commands are returned and 1 otherwise.
9164 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9165 struct scsi_target *stgt,
9166 struct scsi_device *sdev)
9170 struct scsi_cmnd *cmd;
9173 * Waiting for all commands for the designated target or dev
9174 * in the active array
9176 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9177 cmd = scsi_host_find_tag(ha->host, cnt);
9178 if (cmd && stgt == scsi_target(cmd->device) &&
9179 (!sdev || sdev == cmd->device)) {
9180 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9190 * qla4xxx_eh_abort - callback for abort task.
9191 * @cmd: Pointer to Linux's SCSI command structure
9193 * This routine is called by the Linux OS to abort the specified
9196 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9198 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9199 unsigned int id = cmd->device->id;
9200 uint64_t lun = cmd->device->lun;
9201 unsigned long flags;
9202 struct srb *srb = NULL;
9207 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9208 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9210 rval = qla4xxx_isp_check_reg(ha);
9211 if (rval != QLA_SUCCESS) {
9212 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9216 spin_lock_irqsave(&ha->hardware_lock, flags);
9217 srb = qla4xxx_cmd_priv(cmd)->srb;
9219 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9220 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9221 ha->host_no, id, lun);
9224 kref_get(&srb->srb_ref);
9225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9227 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9228 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9229 ha->host_no, id, lun));
9232 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9233 ha->host_no, id, lun));
9237 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9239 /* Wait for command to complete */
9241 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9242 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9243 ha->host_no, id, lun));
9248 ql4_printk(KERN_INFO, ha,
9249 "scsi%ld:%d:%llu: Abort command - %s\n",
9250 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9256 * qla4xxx_eh_device_reset - callback for target reset.
9257 * @cmd: Pointer to Linux's SCSI command structure
9259 * This routine is called by the Linux OS to reset all luns on the
9262 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9264 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9265 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9266 int ret = FAILED, stat;
9272 ret = iscsi_block_scsi_eh(cmd);
9277 ql4_printk(KERN_INFO, ha,
9278 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9279 cmd->device->channel, cmd->device->id, cmd->device->lun);
9281 DEBUG2(printk(KERN_INFO
9282 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9283 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9284 cmd, jiffies, scsi_cmd_to_rq(cmd)->timeout / HZ,
9285 ha->dpc_flags, cmd->result, cmd->allowed));
9287 rval = qla4xxx_isp_check_reg(ha);
9288 if (rval != QLA_SUCCESS) {
9289 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9293 /* FIXME: wait for hba to go online */
9294 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9295 if (stat != QLA_SUCCESS) {
9296 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9297 goto eh_dev_reset_done;
9300 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9302 ql4_printk(KERN_INFO, ha,
9303 "DEVICE RESET FAILED - waiting for "
9305 goto eh_dev_reset_done;
9309 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9310 MM_LUN_RESET) != QLA_SUCCESS)
9311 goto eh_dev_reset_done;
9313 ql4_printk(KERN_INFO, ha,
9314 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9315 ha->host_no, cmd->device->channel, cmd->device->id,
9326 * qla4xxx_eh_target_reset - callback for target reset.
9327 * @cmd: Pointer to Linux's SCSI command structure
9329 * This routine is called by the Linux OS to reset the target.
9331 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9333 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9334 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9341 ret = iscsi_block_scsi_eh(cmd);
9345 starget_printk(KERN_INFO, scsi_target(cmd->device),
9346 "WARM TARGET RESET ISSUED.\n");
9348 DEBUG2(printk(KERN_INFO
9349 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9350 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9351 ha->host_no, cmd, jiffies, scsi_cmd_to_rq(cmd)->timeout / HZ,
9352 ha->dpc_flags, cmd->result, cmd->allowed));
9354 rval = qla4xxx_isp_check_reg(ha);
9355 if (rval != QLA_SUCCESS) {
9356 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9360 stat = qla4xxx_reset_target(ha, ddb_entry);
9361 if (stat != QLA_SUCCESS) {
9362 starget_printk(KERN_INFO, scsi_target(cmd->device),
9363 "WARM TARGET RESET FAILED.\n");
9367 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9369 starget_printk(KERN_INFO, scsi_target(cmd->device),
9370 "WARM TARGET DEVICE RESET FAILED - "
9371 "waiting for commands.\n");
9376 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9377 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9378 starget_printk(KERN_INFO, scsi_target(cmd->device),
9379 "WARM TARGET DEVICE RESET FAILED - "
9380 "marker iocb failed.\n");
9384 starget_printk(KERN_INFO, scsi_target(cmd->device),
9385 "WARM TARGET RESET SUCCEEDED.\n");
9390 * qla4xxx_is_eh_active - check if error handler is running
9391 * @shost: Pointer to SCSI Host struct
9393 * This routine finds that if reset host is called in EH
9394 * scenario or from some application like sg_reset
9396 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9398 if (shost->shost_state == SHOST_RECOVERY)
9404 * qla4xxx_eh_host_reset - kernel callback
9405 * @cmd: Pointer to Linux's SCSI command structure
9407 * This routine is invoked by the Linux kernel to perform fatal error
9408 * recovery on the specified adapter.
9410 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9412 int return_status = FAILED;
9413 struct scsi_qla_host *ha;
9416 ha = to_qla_host(cmd->device->host);
9418 rval = qla4xxx_isp_check_reg(ha);
9419 if (rval != QLA_SUCCESS) {
9420 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9424 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9425 qla4_83xx_set_idc_dontreset(ha);
9428 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9429 * protocol drivers, we should not set device_state to NEED_RESET
9431 if (ql4xdontresethba ||
9432 ((is_qla8032(ha) || is_qla8042(ha)) &&
9433 qla4_83xx_idc_dontreset(ha))) {
9434 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9435 ha->host_no, __func__));
9437 /* Clear outstanding srb in queues */
9438 if (qla4xxx_is_eh_active(cmd->device->host))
9439 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9444 ql4_printk(KERN_INFO, ha,
9445 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9446 cmd->device->channel, cmd->device->id, cmd->device->lun);
9448 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9449 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9450 "DEAD.\n", ha->host_no, cmd->device->channel,
9456 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9458 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9460 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9463 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9464 return_status = SUCCESS;
9466 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9467 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9469 return return_status;
9472 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9474 uint32_t mbox_cmd[MBOX_REG_COUNT];
9475 uint32_t mbox_sts[MBOX_REG_COUNT];
9476 struct addr_ctrl_blk_def *acb = NULL;
9477 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9478 int rval = QLA_SUCCESS;
9481 acb = dma_alloc_coherent(&ha->pdev->dev,
9482 sizeof(struct addr_ctrl_blk_def),
9483 &acb_dma, GFP_KERNEL);
9485 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9488 goto exit_port_reset;
9491 memset(acb, 0, acb_len);
9493 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9494 if (rval != QLA_SUCCESS) {
9499 rval = qla4xxx_disable_acb(ha);
9500 if (rval != QLA_SUCCESS) {
9505 wait_for_completion_timeout(&ha->disable_acb_comp,
9506 DISABLE_ACB_TOV * HZ);
9508 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9509 if (rval != QLA_SUCCESS) {
9515 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9518 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9519 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9523 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9525 struct scsi_qla_host *ha = to_qla_host(shost);
9526 int rval = QLA_SUCCESS;
9529 if (ql4xdontresethba) {
9530 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9533 goto exit_host_reset;
9536 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9537 goto recover_adapter;
9539 switch (reset_type) {
9540 case SCSI_ADAPTER_RESET:
9541 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9543 case SCSI_FIRMWARE_RESET:
9544 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9546 /* set firmware context reset */
9547 set_bit(DPC_RESET_HA_FW_CONTEXT,
9550 rval = qla4xxx_context_reset(ha);
9551 goto exit_host_reset;
9558 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9559 * reset is issued by application */
9560 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9561 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9562 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9563 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9564 (idc_ctrl | GRACEFUL_RESET_BIT1));
9567 rval = qla4xxx_recover_adapter(ha);
9568 if (rval != QLA_SUCCESS) {
9569 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9578 /* PCI AER driver recovers from all correctable errors w/o
9579 * driver intervention. For uncorrectable errors PCI AER
9580 * driver calls the following device driver's callbacks
9582 * - Fatal Errors - link_reset
9583 * - Non-Fatal Errors - driver's error_detected() which
9584 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9586 * PCI AER driver calls
9587 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9588 * returns RECOVERED or NEED_RESET if fw_hung
9589 * NEED_RESET - driver's slot_reset()
9590 * DISCONNECT - device is dead & cannot recover
9591 * RECOVERED - driver's resume()
9593 static pci_ers_result_t
9594 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9596 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9598 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9599 ha->host_no, __func__, state);
9601 if (!is_aer_supported(ha))
9602 return PCI_ERS_RESULT_NONE;
9605 case pci_channel_io_normal:
9606 clear_bit(AF_EEH_BUSY, &ha->flags);
9607 return PCI_ERS_RESULT_CAN_RECOVER;
9608 case pci_channel_io_frozen:
9609 set_bit(AF_EEH_BUSY, &ha->flags);
9610 qla4xxx_mailbox_premature_completion(ha);
9611 qla4xxx_free_irqs(ha);
9612 pci_disable_device(pdev);
9613 /* Return back all IOs */
9614 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9615 return PCI_ERS_RESULT_NEED_RESET;
9616 case pci_channel_io_perm_failure:
9617 set_bit(AF_EEH_BUSY, &ha->flags);
9618 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9619 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9620 return PCI_ERS_RESULT_DISCONNECT;
9622 return PCI_ERS_RESULT_NEED_RESET;
9626 * qla4xxx_pci_mmio_enabled() - gets called if
9627 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9628 * and read/write to the device still works.
9629 * @pdev: PCI device pointer
9631 static pci_ers_result_t
9632 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9634 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9636 if (!is_aer_supported(ha))
9637 return PCI_ERS_RESULT_NONE;
9639 return PCI_ERS_RESULT_RECOVERED;
9642 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9644 uint32_t rval = QLA_ERROR;
9646 struct pci_dev *other_pdev = NULL;
9648 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9650 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9652 if (test_bit(AF_ONLINE, &ha->flags)) {
9653 clear_bit(AF_ONLINE, &ha->flags);
9654 clear_bit(AF_LINK_UP, &ha->flags);
9655 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9656 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9659 fn = PCI_FUNC(ha->pdev->devfn);
9660 if (is_qla8022(ha)) {
9663 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9664 ha->host_no, __func__, fn);
9665 /* Get the pci device given the domain, bus,
9666 * slot/function number */
9667 other_pdev = pci_get_domain_bus_and_slot(
9668 pci_domain_nr(ha->pdev->bus),
9669 ha->pdev->bus->number,
9670 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9676 if (atomic_read(&other_pdev->enable_cnt)) {
9677 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9678 ha->host_no, __func__, fn);
9679 pci_dev_put(other_pdev);
9682 pci_dev_put(other_pdev);
9685 /* this case is meant for ISP83xx/ISP84xx only */
9686 if (qla4_83xx_can_perform_reset(ha)) {
9687 /* reset fn as iSCSI is going to perform the reset */
9692 /* The first function on the card, the reset owner will
9693 * start & initialize the firmware. The other functions
9694 * on the card will reset the firmware context
9697 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9698 "0x%x is the owner\n", ha->host_no, __func__,
9701 ha->isp_ops->idc_lock(ha);
9702 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9704 ha->isp_ops->idc_unlock(ha);
9706 rval = qla4_8xxx_update_idc_reg(ha);
9707 if (rval == QLA_ERROR) {
9708 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9709 ha->host_no, __func__);
9710 ha->isp_ops->idc_lock(ha);
9711 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9712 QLA8XXX_DEV_FAILED);
9713 ha->isp_ops->idc_unlock(ha);
9714 goto exit_error_recovery;
9717 clear_bit(AF_FW_RECOVERY, &ha->flags);
9718 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9720 if (rval != QLA_SUCCESS) {
9721 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9722 "FAILED\n", ha->host_no, __func__);
9723 qla4xxx_free_irqs(ha);
9724 ha->isp_ops->idc_lock(ha);
9725 qla4_8xxx_clear_drv_active(ha);
9726 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9727 QLA8XXX_DEV_FAILED);
9728 ha->isp_ops->idc_unlock(ha);
9730 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9731 "READY\n", ha->host_no, __func__);
9732 ha->isp_ops->idc_lock(ha);
9733 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9735 /* Clear driver state register */
9736 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9737 qla4_8xxx_set_drv_active(ha);
9738 ha->isp_ops->idc_unlock(ha);
9739 ha->isp_ops->enable_intrs(ha);
9742 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9743 "the reset owner\n", ha->host_no, __func__,
9745 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9746 QLA8XXX_DEV_READY)) {
9747 clear_bit(AF_FW_RECOVERY, &ha->flags);
9748 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9749 if (rval == QLA_SUCCESS)
9750 ha->isp_ops->enable_intrs(ha);
9752 qla4xxx_free_irqs(ha);
9754 ha->isp_ops->idc_lock(ha);
9755 qla4_8xxx_set_drv_active(ha);
9756 ha->isp_ops->idc_unlock(ha);
9759 exit_error_recovery:
9760 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9764 static pci_ers_result_t
9765 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9767 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9768 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9771 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9772 ha->host_no, __func__);
9774 if (!is_aer_supported(ha))
9775 return PCI_ERS_RESULT_NONE;
9777 /* Restore the saved state of PCIe device -
9778 * BAR registers, PCI Config space, PCIX, MSI,
9781 pci_restore_state(pdev);
9783 /* pci_restore_state() clears the saved_state flag of the device
9784 * save restored state which resets saved_state flag
9786 pci_save_state(pdev);
9788 /* Initialize device or resume if in suspended state */
9789 rc = pci_enable_device(pdev);
9791 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9792 "device after reset\n", ha->host_no, __func__);
9793 goto exit_slot_reset;
9796 ha->isp_ops->disable_intrs(ha);
9798 if (is_qla80XX(ha)) {
9799 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9800 ret = PCI_ERS_RESULT_RECOVERED;
9801 goto exit_slot_reset;
9803 goto exit_slot_reset;
9807 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9808 "device after reset\n", ha->host_no, __func__, ret);
9813 qla4xxx_pci_resume(struct pci_dev *pdev)
9815 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9818 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9819 ha->host_no, __func__);
9821 ret = qla4xxx_wait_for_hba_online(ha);
9822 if (ret != QLA_SUCCESS) {
9823 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9824 "resume I/O from slot/link_reset\n", ha->host_no,
9828 clear_bit(AF_EEH_BUSY, &ha->flags);
9831 static const struct pci_error_handlers qla4xxx_err_handler = {
9832 .error_detected = qla4xxx_pci_error_detected,
9833 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9834 .slot_reset = qla4xxx_pci_slot_reset,
9835 .resume = qla4xxx_pci_resume,
9838 static struct pci_device_id qla4xxx_pci_tbl[] = {
9840 .vendor = PCI_VENDOR_ID_QLOGIC,
9841 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9842 .subvendor = PCI_ANY_ID,
9843 .subdevice = PCI_ANY_ID,
9846 .vendor = PCI_VENDOR_ID_QLOGIC,
9847 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9848 .subvendor = PCI_ANY_ID,
9849 .subdevice = PCI_ANY_ID,
9852 .vendor = PCI_VENDOR_ID_QLOGIC,
9853 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9854 .subvendor = PCI_ANY_ID,
9855 .subdevice = PCI_ANY_ID,
9858 .vendor = PCI_VENDOR_ID_QLOGIC,
9859 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9860 .subvendor = PCI_ANY_ID,
9861 .subdevice = PCI_ANY_ID,
9864 .vendor = PCI_VENDOR_ID_QLOGIC,
9865 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9866 .subvendor = PCI_ANY_ID,
9867 .subdevice = PCI_ANY_ID,
9870 .vendor = PCI_VENDOR_ID_QLOGIC,
9871 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9872 .subvendor = PCI_ANY_ID,
9873 .subdevice = PCI_ANY_ID,
9877 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9879 static struct pci_driver qla4xxx_pci_driver = {
9880 .name = DRIVER_NAME,
9881 .id_table = qla4xxx_pci_tbl,
9882 .probe = qla4xxx_probe_adapter,
9883 .remove = qla4xxx_remove_adapter,
9884 .err_handler = &qla4xxx_err_handler,
9887 static int __init qla4xxx_module_init(void)
9891 if (ql4xqfulltracking)
9892 qla4xxx_driver_template.track_queue_depth = 1;
9894 /* Allocate cache for SRBs. */
9895 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9896 SLAB_HWCACHE_ALIGN, NULL);
9897 if (srb_cachep == NULL) {
9899 "%s: Unable to allocate SRB cache..."
9900 "Failing load!\n", DRIVER_NAME);
9905 /* Derive version string. */
9906 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9907 if (ql4xextended_error_logging)
9908 strcat(qla4xxx_version_str, "-debug");
9910 qla4xxx_scsi_transport =
9911 iscsi_register_transport(&qla4xxx_iscsi_transport);
9912 if (!qla4xxx_scsi_transport){
9914 goto release_srb_cache;
9917 ret = pci_register_driver(&qla4xxx_pci_driver);
9919 goto unregister_transport;
9921 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9924 unregister_transport:
9925 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9927 kmem_cache_destroy(srb_cachep);
9932 static void __exit qla4xxx_module_exit(void)
9934 pci_unregister_driver(&qla4xxx_pci_driver);
9935 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9936 kmem_cache_destroy(srb_cachep);
9939 module_init(qla4xxx_module_init);
9940 module_exit(qla4xxx_module_exit);
9942 MODULE_AUTHOR("QLogic Corporation");
9943 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9944 MODULE_LICENSE("GPL");
9945 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);