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,
230 .eh_abort_handler = qla4xxx_eh_abort,
231 .eh_device_reset_handler = qla4xxx_eh_device_reset,
232 .eh_target_reset_handler = qla4xxx_eh_target_reset,
233 .eh_host_reset_handler = qla4xxx_eh_host_reset,
234 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
236 .slave_alloc = qla4xxx_slave_alloc,
237 .change_queue_depth = scsi_change_queue_depth,
241 .sg_tablesize = SG_ALL,
243 .max_sectors = 0xFFFF,
244 .shost_groups = qla4xxx_host_groups,
245 .host_reset = qla4xxx_host_reset,
246 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
249 static struct iscsi_transport qla4xxx_iscsi_transport = {
250 .owner = THIS_MODULE,
252 .caps = CAP_TEXT_NEGO |
253 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
254 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
256 .attr_is_visible = qla4_attr_is_visible,
257 .create_session = qla4xxx_session_create,
258 .destroy_session = qla4xxx_session_destroy,
259 .start_conn = qla4xxx_conn_start,
260 .create_conn = qla4xxx_conn_create,
261 .bind_conn = qla4xxx_conn_bind,
262 .unbind_conn = iscsi_conn_unbind,
263 .stop_conn = iscsi_conn_stop,
264 .destroy_conn = qla4xxx_conn_destroy,
265 .set_param = iscsi_set_param,
266 .get_conn_param = qla4xxx_conn_get_param,
267 .get_session_param = qla4xxx_session_get_param,
268 .get_ep_param = qla4xxx_get_ep_param,
269 .ep_connect = qla4xxx_ep_connect,
270 .ep_poll = qla4xxx_ep_poll,
271 .ep_disconnect = qla4xxx_ep_disconnect,
272 .get_stats = qla4xxx_conn_get_stats,
273 .send_pdu = iscsi_conn_send_pdu,
274 .xmit_task = qla4xxx_task_xmit,
275 .cleanup_task = qla4xxx_task_cleanup,
276 .alloc_pdu = qla4xxx_alloc_pdu,
278 .get_host_param = qla4xxx_host_get_param,
279 .set_iface_param = qla4xxx_iface_set_param,
280 .get_iface_param = qla4xxx_get_iface_param,
281 .bsg_request = qla4xxx_bsg_request,
282 .send_ping = qla4xxx_send_ping,
283 .get_chap = qla4xxx_get_chap_list,
284 .delete_chap = qla4xxx_delete_chap,
285 .set_chap = qla4xxx_set_chap_entry,
286 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
287 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
288 .new_flashnode = qla4xxx_sysfs_ddb_add,
289 .del_flashnode = qla4xxx_sysfs_ddb_delete,
290 .login_flashnode = qla4xxx_sysfs_ddb_login,
291 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
292 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
293 .get_host_stats = qla4xxx_get_host_stats,
296 static struct scsi_transport_template *qla4xxx_scsi_transport;
298 static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
301 int rval = QLA_SUCCESS;
304 reg_val = readl(&ha->qla4_82xx_reg->host_status);
305 else if (is_qla8032(ha) || is_qla8042(ha))
306 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
308 reg_val = readw(&ha->reg->ctrl_status);
310 if (reg_val == QL4_ISP_REG_DISCONNECT)
316 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
317 uint32_t iface_type, uint32_t payload_size,
318 uint32_t pid, struct sockaddr *dst_addr)
320 struct scsi_qla_host *ha = to_qla_host(shost);
321 struct sockaddr_in *addr;
322 struct sockaddr_in6 *addr6;
323 uint32_t options = 0;
324 uint8_t ipaddr[IPv6_ADDR_LEN];
327 memset(ipaddr, 0, IPv6_ADDR_LEN);
329 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
330 (dst_addr->sa_family == AF_INET)) {
331 addr = (struct sockaddr_in *)dst_addr;
332 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
333 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
334 "dest: %pI4\n", __func__,
335 &ha->ip_config.ip_address, ipaddr));
336 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
340 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
341 (dst_addr->sa_family == AF_INET6)) {
343 addr6 = (struct sockaddr_in6 *)dst_addr;
344 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
346 options |= PING_IPV6_PROTOCOL_ENABLE;
348 /* Ping using LinkLocal address */
349 if ((iface_num == 0) || (iface_num == 1)) {
350 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
351 "src: %pI6 dest: %pI6\n", __func__,
352 &ha->ip_config.ipv6_link_local_addr,
354 options |= PING_IPV6_LINKLOCAL_ADDR;
355 rval = qla4xxx_ping_iocb(ha, options, payload_size,
358 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
359 "not supported\n", __func__, iface_num);
365 * If ping using LinkLocal address fails, try ping using
368 if (rval != QLA_SUCCESS) {
369 options &= ~PING_IPV6_LINKLOCAL_ADDR;
370 if (iface_num == 0) {
371 options |= PING_IPV6_ADDR0;
372 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
374 "dest: %pI6\n", __func__,
375 &ha->ip_config.ipv6_addr0,
377 } else if (iface_num == 1) {
378 options |= PING_IPV6_ADDR1;
379 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
381 "dest: %pI6\n", __func__,
382 &ha->ip_config.ipv6_addr1,
385 rval = qla4xxx_ping_iocb(ha, options, payload_size,
396 static umode_t qla4_attr_is_visible(int param_type, int param)
398 switch (param_type) {
399 case ISCSI_HOST_PARAM:
401 case ISCSI_HOST_PARAM_HWADDRESS:
402 case ISCSI_HOST_PARAM_IPADDRESS:
403 case ISCSI_HOST_PARAM_INITIATOR_NAME:
404 case ISCSI_HOST_PARAM_PORT_STATE:
405 case ISCSI_HOST_PARAM_PORT_SPEED:
412 case ISCSI_PARAM_PERSISTENT_ADDRESS:
413 case ISCSI_PARAM_PERSISTENT_PORT:
414 case ISCSI_PARAM_CONN_ADDRESS:
415 case ISCSI_PARAM_CONN_PORT:
416 case ISCSI_PARAM_TARGET_NAME:
417 case ISCSI_PARAM_TPGT:
418 case ISCSI_PARAM_TARGET_ALIAS:
419 case ISCSI_PARAM_MAX_BURST:
420 case ISCSI_PARAM_MAX_R2T:
421 case ISCSI_PARAM_FIRST_BURST:
422 case ISCSI_PARAM_MAX_RECV_DLENGTH:
423 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
424 case ISCSI_PARAM_IFACE_NAME:
425 case ISCSI_PARAM_CHAP_OUT_IDX:
426 case ISCSI_PARAM_CHAP_IN_IDX:
427 case ISCSI_PARAM_USERNAME:
428 case ISCSI_PARAM_PASSWORD:
429 case ISCSI_PARAM_USERNAME_IN:
430 case ISCSI_PARAM_PASSWORD_IN:
431 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
432 case ISCSI_PARAM_DISCOVERY_SESS:
433 case ISCSI_PARAM_PORTAL_TYPE:
434 case ISCSI_PARAM_CHAP_AUTH_EN:
435 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
436 case ISCSI_PARAM_BIDI_CHAP_EN:
437 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
438 case ISCSI_PARAM_DEF_TIME2WAIT:
439 case ISCSI_PARAM_DEF_TIME2RETAIN:
440 case ISCSI_PARAM_HDRDGST_EN:
441 case ISCSI_PARAM_DATADGST_EN:
442 case ISCSI_PARAM_INITIAL_R2T_EN:
443 case ISCSI_PARAM_IMM_DATA_EN:
444 case ISCSI_PARAM_PDU_INORDER_EN:
445 case ISCSI_PARAM_DATASEQ_INORDER_EN:
446 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
447 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
448 case ISCSI_PARAM_TCP_WSF_DISABLE:
449 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
450 case ISCSI_PARAM_TCP_TIMER_SCALE:
451 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
452 case ISCSI_PARAM_TCP_XMIT_WSF:
453 case ISCSI_PARAM_TCP_RECV_WSF:
454 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
455 case ISCSI_PARAM_IPV4_TOS:
456 case ISCSI_PARAM_IPV6_TC:
457 case ISCSI_PARAM_IPV6_FLOW_LABEL:
458 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
459 case ISCSI_PARAM_KEEPALIVE_TMO:
460 case ISCSI_PARAM_LOCAL_PORT:
461 case ISCSI_PARAM_ISID:
462 case ISCSI_PARAM_TSID:
463 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
464 case ISCSI_PARAM_ERL:
465 case ISCSI_PARAM_STATSN:
466 case ISCSI_PARAM_EXP_STATSN:
467 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
468 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
469 case ISCSI_PARAM_LOCAL_IPADDR:
474 case ISCSI_NET_PARAM:
476 case ISCSI_NET_PARAM_IPV4_ADDR:
477 case ISCSI_NET_PARAM_IPV4_SUBNET:
478 case ISCSI_NET_PARAM_IPV4_GW:
479 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
480 case ISCSI_NET_PARAM_IFACE_ENABLE:
481 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
482 case ISCSI_NET_PARAM_IPV6_ADDR:
483 case ISCSI_NET_PARAM_IPV6_ROUTER:
484 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
485 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
486 case ISCSI_NET_PARAM_VLAN_ID:
487 case ISCSI_NET_PARAM_VLAN_PRIORITY:
488 case ISCSI_NET_PARAM_VLAN_ENABLED:
489 case ISCSI_NET_PARAM_MTU:
490 case ISCSI_NET_PARAM_PORT:
491 case ISCSI_NET_PARAM_IPADDR_STATE:
492 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
493 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
494 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
495 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
496 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
497 case ISCSI_NET_PARAM_TCP_WSF:
498 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
499 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
500 case ISCSI_NET_PARAM_CACHE_ID:
501 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
502 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
503 case ISCSI_NET_PARAM_IPV4_TOS_EN:
504 case ISCSI_NET_PARAM_IPV4_TOS:
505 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
506 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
507 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
508 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
509 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
510 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
511 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
512 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
513 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
514 case ISCSI_NET_PARAM_REDIRECT_EN:
515 case ISCSI_NET_PARAM_IPV4_TTL:
516 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
517 case ISCSI_NET_PARAM_IPV6_MLD_EN:
518 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
519 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
520 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
521 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
522 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
523 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
524 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
525 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
530 case ISCSI_IFACE_PARAM:
532 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
533 case ISCSI_IFACE_PARAM_HDRDGST_EN:
534 case ISCSI_IFACE_PARAM_DATADGST_EN:
535 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
536 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
537 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
538 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
539 case ISCSI_IFACE_PARAM_ERL:
540 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
541 case ISCSI_IFACE_PARAM_FIRST_BURST:
542 case ISCSI_IFACE_PARAM_MAX_R2T:
543 case ISCSI_IFACE_PARAM_MAX_BURST:
544 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
545 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
546 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
547 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
548 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
549 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
554 case ISCSI_FLASHNODE_PARAM:
556 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
557 case ISCSI_FLASHNODE_PORTAL_TYPE:
558 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
559 case ISCSI_FLASHNODE_DISCOVERY_SESS:
560 case ISCSI_FLASHNODE_ENTRY_EN:
561 case ISCSI_FLASHNODE_HDR_DGST_EN:
562 case ISCSI_FLASHNODE_DATA_DGST_EN:
563 case ISCSI_FLASHNODE_IMM_DATA_EN:
564 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
565 case ISCSI_FLASHNODE_DATASEQ_INORDER:
566 case ISCSI_FLASHNODE_PDU_INORDER:
567 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
568 case ISCSI_FLASHNODE_SNACK_REQ_EN:
569 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
570 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
571 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
572 case ISCSI_FLASHNODE_ERL:
573 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
574 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
575 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
576 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
577 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
578 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
579 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
580 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
581 case ISCSI_FLASHNODE_FIRST_BURST:
582 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
583 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
584 case ISCSI_FLASHNODE_MAX_R2T:
585 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
586 case ISCSI_FLASHNODE_ISID:
587 case ISCSI_FLASHNODE_TSID:
588 case ISCSI_FLASHNODE_PORT:
589 case ISCSI_FLASHNODE_MAX_BURST:
590 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
591 case ISCSI_FLASHNODE_IPADDR:
592 case ISCSI_FLASHNODE_ALIAS:
593 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
594 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
595 case ISCSI_FLASHNODE_LOCAL_PORT:
596 case ISCSI_FLASHNODE_IPV4_TOS:
597 case ISCSI_FLASHNODE_IPV6_TC:
598 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
599 case ISCSI_FLASHNODE_NAME:
600 case ISCSI_FLASHNODE_TPGT:
601 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
602 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
603 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
604 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
605 case ISCSI_FLASHNODE_TCP_RECV_WSF:
606 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
607 case ISCSI_FLASHNODE_USERNAME:
608 case ISCSI_FLASHNODE_PASSWORD:
609 case ISCSI_FLASHNODE_STATSN:
610 case ISCSI_FLASHNODE_EXP_STATSN:
611 case ISCSI_FLASHNODE_IS_BOOT_TGT:
622 * qla4xxx_create_chap_list - Create CHAP list from FLASH
623 * @ha: pointer to adapter structure
625 * Read flash and make a list of CHAP entries, during login when a CHAP entry
626 * is received, it will be checked in this list. If entry exist then the CHAP
627 * entry index is set in the DDB. If CHAP entry does not exist in this list
628 * then a new entry is added in FLASH in CHAP table and the index obtained is
631 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
634 uint8_t *chap_flash_data = NULL;
637 uint32_t chap_size = 0;
640 chap_size = MAX_CHAP_ENTRIES_40XX *
641 sizeof(struct ql4_chap_table);
642 else /* Single region contains CHAP info for both
643 * ports which is divided into half for each port.
645 chap_size = ha->hw.flt_chap_size / 2;
647 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
648 &chap_dma, GFP_KERNEL);
649 if (!chap_flash_data) {
650 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
654 if (is_qla40XX(ha)) {
655 offset = FLASH_CHAP_OFFSET;
657 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
658 if (ha->port_num == 1)
662 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
663 if (rval != QLA_SUCCESS)
666 if (ha->chap_list == NULL)
667 ha->chap_list = vmalloc(chap_size);
668 if (ha->chap_list == NULL) {
669 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
673 memset(ha->chap_list, 0, chap_size);
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)
3644 options = le16_to_cpu(fw_ddb_entry->options);
3645 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3646 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3651 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3652 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3653 SET_BITVAL(sess->entry_state, options, BIT_3);
3654 fw_ddb_entry->options = cpu_to_le16(options);
3656 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3657 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3658 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3659 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3660 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3661 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3662 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3663 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3664 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3665 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3666 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3667 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3668 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3669 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3670 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3672 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3673 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3674 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3675 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3676 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3677 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3678 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3679 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3680 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3682 options = le16_to_cpu(fw_ddb_entry->ip_options);
3683 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3684 fw_ddb_entry->ip_options = cpu_to_le16(options);
3686 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3687 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3688 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3689 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3690 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3691 fw_ddb_entry->iscsi_first_burst_len =
3692 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3693 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3695 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3696 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3697 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3698 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3699 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3700 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3701 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3702 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3703 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3704 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3705 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3706 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3707 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3708 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3709 fw_ddb_entry->port = cpu_to_le16(conn->port);
3710 fw_ddb_entry->def_timeout =
3711 cpu_to_le16(sess->default_taskmgmt_timeout);
3713 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3714 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3716 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3718 if (conn->ipaddress)
3719 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3720 sizeof(fw_ddb_entry->ip_addr));
3722 if (conn->redirect_ipaddr)
3723 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3724 sizeof(fw_ddb_entry->tgt_addr));
3726 if (conn->link_local_ipv6_addr)
3727 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3728 conn->link_local_ipv6_addr,
3729 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3731 if (sess->targetname)
3732 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3733 sizeof(fw_ddb_entry->iscsi_name));
3735 if (sess->targetalias)
3736 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3737 sizeof(fw_ddb_entry->iscsi_alias));
3739 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3744 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3745 struct iscsi_session *sess,
3746 struct dev_db_entry *fw_ddb_entry)
3748 unsigned long options = 0;
3750 uint16_t disc_parent;
3751 char ip_addr[DDB_IPADDR_LEN];
3753 options = le16_to_cpu(fw_ddb_entry->options);
3754 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3755 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3757 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3759 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3760 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3761 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3762 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3763 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3764 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3766 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3767 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3768 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3770 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3771 sess->discovery_auth_optional =
3772 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3773 if (test_bit(ISCSIOPT_ERL1, &options))
3775 if (test_bit(ISCSIOPT_ERL0, &options))
3778 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3779 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3780 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3781 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3782 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3783 conn->tcp_timer_scale |= BIT_3;
3784 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3785 conn->tcp_timer_scale |= BIT_2;
3786 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3787 conn->tcp_timer_scale |= BIT_1;
3789 conn->tcp_timer_scale >>= 1;
3790 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3792 options = le16_to_cpu(fw_ddb_entry->ip_options);
3793 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3795 conn->max_recv_dlength = BYTE_UNITS *
3796 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3797 conn->max_xmit_dlength = BYTE_UNITS *
3798 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3799 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3800 sess->first_burst = BYTE_UNITS *
3801 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3802 sess->max_burst = BYTE_UNITS *
3803 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3804 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3805 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3806 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3807 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3808 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3809 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3810 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3811 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3812 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3813 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3814 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3815 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3816 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3818 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3819 if (ddb_link == DDB_ISNS)
3820 disc_parent = ISCSI_DISC_PARENT_ISNS;
3821 else if (ddb_link == DDB_NO_LINK)
3822 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3823 else if (ddb_link < MAX_DDB_ENTRIES)
3824 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3826 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3828 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3829 iscsi_get_discovery_parent_name(disc_parent), 0);
3831 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3832 (char *)fw_ddb_entry->iscsi_alias, 0);
3834 options = le16_to_cpu(fw_ddb_entry->options);
3835 if (options & DDB_OPT_IPV6_DEVICE) {
3836 memset(ip_addr, 0, sizeof(ip_addr));
3837 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3838 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3839 (char *)ip_addr, 0);
3843 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3844 struct dev_db_entry *fw_ddb_entry,
3845 struct iscsi_cls_session *cls_sess,
3846 struct iscsi_cls_conn *cls_conn)
3849 struct iscsi_session *sess;
3850 struct ddb_entry *ddb_entry;
3851 struct ql4_chap_table chap_tbl;
3852 struct iscsi_conn *conn;
3853 char ip_addr[DDB_IPADDR_LEN];
3854 uint16_t options = 0;
3856 sess = cls_sess->dd_data;
3857 ddb_entry = sess->dd_data;
3858 conn = cls_conn->dd_data;
3859 memset(&chap_tbl, 0, sizeof(chap_tbl));
3861 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3863 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3865 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3866 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3868 memset(ip_addr, 0, sizeof(ip_addr));
3869 options = le16_to_cpu(fw_ddb_entry->options);
3870 if (options & DDB_OPT_IPV6_DEVICE) {
3871 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3873 memset(ip_addr, 0, sizeof(ip_addr));
3874 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3876 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3877 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3880 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3881 (char *)ip_addr, buflen);
3882 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3883 (char *)fw_ddb_entry->iscsi_name, buflen);
3884 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3885 (char *)ha->name_string, buflen);
3887 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3888 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3890 ddb_entry->chap_tbl_idx)) {
3891 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3892 (char *)chap_tbl.name,
3893 strlen((char *)chap_tbl.name));
3894 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3895 (char *)chap_tbl.secret,
3896 chap_tbl.secret_len);
3901 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3902 struct ddb_entry *ddb_entry)
3904 struct iscsi_cls_session *cls_sess;
3905 struct iscsi_cls_conn *cls_conn;
3907 dma_addr_t fw_ddb_entry_dma;
3908 struct dev_db_entry *fw_ddb_entry;
3910 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3911 &fw_ddb_entry_dma, GFP_KERNEL);
3912 if (!fw_ddb_entry) {
3913 ql4_printk(KERN_ERR, ha,
3914 "%s: Unable to allocate dma buffer\n", __func__);
3915 goto exit_session_conn_fwddb_param;
3918 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3919 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3920 NULL, NULL, NULL) == QLA_ERROR) {
3921 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3922 "get_ddb_entry for fw_ddb_index %d\n",
3923 ha->host_no, __func__,
3924 ddb_entry->fw_ddb_index));
3925 goto exit_session_conn_fwddb_param;
3928 cls_sess = ddb_entry->sess;
3930 cls_conn = ddb_entry->conn;
3933 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3935 exit_session_conn_fwddb_param:
3937 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3938 fw_ddb_entry, fw_ddb_entry_dma);
3941 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3942 struct ddb_entry *ddb_entry)
3944 struct iscsi_cls_session *cls_sess;
3945 struct iscsi_cls_conn *cls_conn;
3946 struct iscsi_session *sess;
3947 struct iscsi_conn *conn;
3949 dma_addr_t fw_ddb_entry_dma;
3950 struct dev_db_entry *fw_ddb_entry;
3952 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3953 &fw_ddb_entry_dma, GFP_KERNEL);
3954 if (!fw_ddb_entry) {
3955 ql4_printk(KERN_ERR, ha,
3956 "%s: Unable to allocate dma buffer\n", __func__);
3957 goto exit_session_conn_param;
3960 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3961 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3962 NULL, NULL, NULL) == QLA_ERROR) {
3963 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3964 "get_ddb_entry for fw_ddb_index %d\n",
3965 ha->host_no, __func__,
3966 ddb_entry->fw_ddb_index));
3967 goto exit_session_conn_param;
3970 cls_sess = ddb_entry->sess;
3971 sess = cls_sess->dd_data;
3973 cls_conn = ddb_entry->conn;
3974 conn = cls_conn->dd_data;
3976 /* Update timers after login */
3977 ddb_entry->default_relogin_timeout =
3978 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3979 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3980 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3981 ddb_entry->default_time2wait =
3982 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3985 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3986 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3988 memcpy(sess->initiatorname, ha->name_string,
3989 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3991 exit_session_conn_param:
3993 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3994 fw_ddb_entry, fw_ddb_entry_dma);
4000 static void qla4xxx_timer(struct timer_list *t);
4002 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
4003 unsigned long interval)
4005 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
4006 __func__, ha->host->host_no));
4007 timer_setup(&ha->timer, qla4xxx_timer, 0);
4008 ha->timer.expires = jiffies + interval * HZ;
4009 add_timer(&ha->timer);
4010 ha->timer_active = 1;
4013 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4015 del_timer_sync(&ha->timer);
4016 ha->timer_active = 0;
4020 * qla4xxx_mark_device_missing - blocks the session
4021 * @cls_session: Pointer to the session to be blocked
4022 * @ddb_entry: Pointer to device database entry
4024 * This routine marks a device missing and close connection.
4026 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4028 iscsi_block_session(cls_session);
4032 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4033 * @ha: Pointer to host adapter structure.
4035 * This routine marks a device missing and resets the relogin retry count.
4037 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4039 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4042 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4043 struct ddb_entry *ddb_entry,
4044 struct scsi_cmnd *cmd)
4048 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4052 kref_init(&srb->srb_ref);
4054 srb->ddb = ddb_entry;
4057 CMD_SP(cmd) = (void *)srb;
4062 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4064 struct scsi_cmnd *cmd = srb->cmd;
4066 if (srb->flags & SRB_DMA_VALID) {
4067 scsi_dma_unmap(cmd);
4068 srb->flags &= ~SRB_DMA_VALID;
4073 void qla4xxx_srb_compl(struct kref *ref)
4075 struct srb *srb = container_of(ref, struct srb, srb_ref);
4076 struct scsi_cmnd *cmd = srb->cmd;
4077 struct scsi_qla_host *ha = srb->ha;
4079 qla4xxx_srb_free_dma(ha, srb);
4081 mempool_free(srb, ha->srb_mempool);
4087 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4089 * @cmd: Pointer to Linux's SCSI command structure
4092 * This routine is invoked by Linux to send a SCSI command to the driver.
4093 * The mid-level driver tries to ensure that queuecommand never gets
4094 * invoked concurrently with itself or the interrupt handler (although
4095 * the interrupt handler may call this routine as part of request-
4096 * completion handling). Unfortunely, it sometimes calls the scheduler
4097 * in interrupt context which is a big NO! NO!.
4099 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4101 struct scsi_qla_host *ha = to_qla_host(host);
4102 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4103 struct iscsi_cls_session *sess = ddb_entry->sess;
4107 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4108 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4109 cmd->result = DID_NO_CONNECT << 16;
4111 cmd->result = DID_REQUEUE << 16;
4112 goto qc_fail_command;
4116 cmd->result = DID_IMM_RETRY << 16;
4117 goto qc_fail_command;
4120 rval = iscsi_session_chkready(sess);
4123 goto qc_fail_command;
4126 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4127 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4128 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4129 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4130 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4131 !test_bit(AF_ONLINE, &ha->flags) ||
4132 !test_bit(AF_LINK_UP, &ha->flags) ||
4133 test_bit(AF_LOOPBACK, &ha->flags) ||
4134 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4135 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4136 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4139 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4143 rval = qla4xxx_send_command_to_isp(ha, srb);
4144 if (rval != QLA_SUCCESS)
4145 goto qc_host_busy_free_sp;
4149 qc_host_busy_free_sp:
4150 qla4xxx_srb_free_dma(ha, srb);
4151 mempool_free(srb, ha->srb_mempool);
4154 return SCSI_MLQUEUE_HOST_BUSY;
4163 * qla4xxx_mem_free - frees memory allocated to adapter
4164 * @ha: Pointer to host adapter structure.
4166 * Frees memory previously allocated by qla4xxx_mem_alloc
4168 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4171 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4179 ha->request_ring = NULL;
4180 ha->request_dma = 0;
4181 ha->response_ring = NULL;
4182 ha->response_dma = 0;
4183 ha->shadow_regs = NULL;
4184 ha->shadow_regs_dma = 0;
4186 ha->fw_dump_size = 0;
4188 /* Free srb pool. */
4189 mempool_destroy(ha->srb_mempool);
4190 ha->srb_mempool = NULL;
4192 dma_pool_destroy(ha->chap_dma_pool);
4194 vfree(ha->chap_list);
4195 ha->chap_list = NULL;
4197 dma_pool_destroy(ha->fw_ddb_dma_pool);
4199 /* release io space registers */
4200 if (is_qla8022(ha)) {
4203 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4204 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4207 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4208 } else if (ha->reg) {
4212 vfree(ha->reset_tmplt.buff);
4214 pci_release_regions(ha->pdev);
4218 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4219 * @ha: Pointer to host adapter structure
4221 * Allocates DMA memory for request and response queues. Also allocates memory
4224 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4226 unsigned long align;
4228 /* Allocate contiguous block of DMA memory for queues. */
4229 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4230 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4231 sizeof(struct shadow_regs) +
4233 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4234 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4235 &ha->queues_dma, GFP_KERNEL);
4236 if (ha->queues == NULL) {
4237 ql4_printk(KERN_WARNING, ha,
4238 "Memory Allocation failed - queues.\n");
4240 goto mem_alloc_error_exit;
4244 * As per RISC alignment requirements -- the bus-address must be a
4245 * multiple of the request-ring size (in bytes).
4248 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4249 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4250 (MEM_ALIGN_VALUE - 1));
4252 /* Update request and response queue pointers. */
4253 ha->request_dma = ha->queues_dma + align;
4254 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4255 ha->response_dma = ha->queues_dma + align +
4256 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4257 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4258 (REQUEST_QUEUE_DEPTH *
4260 ha->shadow_regs_dma = ha->queues_dma + align +
4261 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4262 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4263 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4264 (REQUEST_QUEUE_DEPTH *
4266 (RESPONSE_QUEUE_DEPTH *
4269 /* Allocate memory for srb pool. */
4270 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4271 mempool_free_slab, srb_cachep);
4272 if (ha->srb_mempool == NULL) {
4273 ql4_printk(KERN_WARNING, ha,
4274 "Memory Allocation failed - SRB Pool.\n");
4276 goto mem_alloc_error_exit;
4279 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4280 CHAP_DMA_BLOCK_SIZE, 8, 0);
4282 if (ha->chap_dma_pool == NULL) {
4283 ql4_printk(KERN_WARNING, ha,
4284 "%s: chap_dma_pool allocation failed..\n", __func__);
4285 goto mem_alloc_error_exit;
4288 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4289 DDB_DMA_BLOCK_SIZE, 8, 0);
4291 if (ha->fw_ddb_dma_pool == NULL) {
4292 ql4_printk(KERN_WARNING, ha,
4293 "%s: fw_ddb_dma_pool allocation failed..\n",
4295 goto mem_alloc_error_exit;
4300 mem_alloc_error_exit:
4305 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4306 * @ha: adapter block pointer.
4308 * Note: The caller should not hold the idc lock.
4310 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4312 uint32_t temp, temp_state, temp_val;
4313 int status = QLA_SUCCESS;
4315 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4317 temp_state = qla82xx_get_temp_state(temp);
4318 temp_val = qla82xx_get_temp_val(temp);
4320 if (temp_state == QLA82XX_TEMP_PANIC) {
4321 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4322 " exceeds maximum allowed. Hardware has been shut"
4323 " down.\n", temp_val);
4325 } else if (temp_state == QLA82XX_TEMP_WARN) {
4326 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4327 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4328 " degrees C exceeds operating range."
4329 " Immediate action needed.\n", temp_val);
4331 if (ha->temperature == QLA82XX_TEMP_WARN)
4332 ql4_printk(KERN_INFO, ha, "Device temperature is"
4333 " now %d degrees C in normal range.\n",
4336 ha->temperature = temp_state;
4341 * qla4_8xxx_check_fw_alive - Check firmware health
4342 * @ha: Pointer to host adapter structure.
4344 * Context: Interrupt
4346 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4348 uint32_t fw_heartbeat_counter;
4349 int status = QLA_SUCCESS;
4351 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4352 QLA8XXX_PEG_ALIVE_COUNTER);
4353 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4354 if (fw_heartbeat_counter == 0xffffffff) {
4355 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4356 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4357 ha->host_no, __func__));
4361 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4362 ha->seconds_since_last_heartbeat++;
4363 /* FW not alive after 2 seconds */
4364 if (ha->seconds_since_last_heartbeat == 2) {
4365 ha->seconds_since_last_heartbeat = 0;
4366 qla4_8xxx_dump_peg_reg(ha);
4370 ha->seconds_since_last_heartbeat = 0;
4372 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4376 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4378 uint32_t halt_status;
4379 int halt_status_unrecoverable = 0;
4381 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4383 if (is_qla8022(ha)) {
4384 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4386 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4387 CRB_NIU_XG_PAUSE_CTL_P0 |
4388 CRB_NIU_XG_PAUSE_CTL_P1);
4390 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4391 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4393 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4394 halt_status_unrecoverable = 1;
4395 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4396 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4397 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4399 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4400 halt_status_unrecoverable = 1;
4404 * Since we cannot change dev_state in interrupt context,
4405 * set appropriate DPC flag then wakeup DPC
4407 if (halt_status_unrecoverable) {
4408 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4410 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4412 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4414 qla4xxx_mailbox_premature_completion(ha);
4415 qla4xxx_wake_dpc(ha);
4419 * qla4_8xxx_watchdog - Poll dev state
4420 * @ha: Pointer to host adapter structure.
4422 * Context: Interrupt
4424 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4429 if (is_qla8032(ha) &&
4430 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4431 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4432 __func__, ha->func_num);
4434 /* don't poll if reset is going on */
4435 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4436 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4437 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4438 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4440 if (qla4_8xxx_check_temp(ha)) {
4441 if (is_qla8022(ha)) {
4442 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4443 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4444 CRB_NIU_XG_PAUSE_CTL_P0 |
4445 CRB_NIU_XG_PAUSE_CTL_P1);
4447 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4448 qla4xxx_wake_dpc(ha);
4449 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4450 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4452 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4455 if (is_qla8032(ha) || is_qla8042(ha)) {
4456 idc_ctrl = qla4_83xx_rd_reg(ha,
4457 QLA83XX_IDC_DRV_CTRL);
4458 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4459 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4461 qla4xxx_mailbox_premature_completion(
4466 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4467 (is_qla8022(ha) && !ql4xdontresethba)) {
4468 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4469 qla4xxx_wake_dpc(ha);
4471 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4472 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4473 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4475 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4476 qla4xxx_wake_dpc(ha);
4478 /* Check firmware health */
4479 if (qla4_8xxx_check_fw_alive(ha))
4480 qla4_8xxx_process_fw_error(ha);
4485 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4487 struct iscsi_session *sess;
4488 struct ddb_entry *ddb_entry;
4489 struct scsi_qla_host *ha;
4491 sess = cls_sess->dd_data;
4492 ddb_entry = sess->dd_data;
4495 if (!(ddb_entry->ddb_type == FLASH_DDB))
4498 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4499 !iscsi_is_session_online(cls_sess)) {
4500 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4502 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4504 atomic_set(&ddb_entry->retry_relogin_timer,
4506 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4507 set_bit(DF_RELOGIN, &ddb_entry->flags);
4508 DEBUG2(ql4_printk(KERN_INFO, ha,
4509 "%s: index [%d] login device\n",
4510 __func__, ddb_entry->fw_ddb_index));
4512 atomic_dec(&ddb_entry->retry_relogin_timer);
4516 /* Wait for relogin to timeout */
4517 if (atomic_read(&ddb_entry->relogin_timer) &&
4518 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4520 * If the relogin times out and the device is
4521 * still NOT ONLINE then try and relogin again.
4523 if (!iscsi_is_session_online(cls_sess)) {
4524 /* Reset retry relogin timer */
4525 atomic_inc(&ddb_entry->relogin_retry_count);
4526 DEBUG2(ql4_printk(KERN_INFO, ha,
4527 "%s: index[%d] relogin timed out-retrying"
4528 " relogin (%d), retry (%d)\n", __func__,
4529 ddb_entry->fw_ddb_index,
4530 atomic_read(&ddb_entry->relogin_retry_count),
4531 ddb_entry->default_time2wait + 4));
4532 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4533 atomic_set(&ddb_entry->retry_relogin_timer,
4534 ddb_entry->default_time2wait + 4);
4540 * qla4xxx_timer - checks every second for work to do.
4541 * @t: Context to obtain pointer to host adapter structure.
4543 static void qla4xxx_timer(struct timer_list *t)
4545 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4549 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4551 /* If we are in the middle of AER/EEH processing
4552 * skip any processing and reschedule the timer
4554 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4555 mod_timer(&ha->timer, jiffies + HZ);
4559 /* Hardware read to trigger an EEH error during mailbox waits. */
4560 if (!pci_channel_offline(ha->pdev))
4561 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4564 qla4_8xxx_watchdog(ha);
4566 if (is_qla40XX(ha)) {
4567 /* Check for heartbeat interval. */
4568 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4569 ha->heartbeat_interval != 0) {
4570 ha->seconds_since_last_heartbeat++;
4571 if (ha->seconds_since_last_heartbeat >
4572 ha->heartbeat_interval + 2)
4573 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4577 /* Process any deferred work. */
4578 if (!list_empty(&ha->work_list))
4581 /* Wakeup the dpc routine for this adapter, if needed. */
4583 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4584 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4585 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4586 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4587 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4588 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4589 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4590 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4591 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4592 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4593 test_bit(DPC_AEN, &ha->dpc_flags)) {
4594 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4595 " - dpc flags = 0x%lx\n",
4596 ha->host_no, __func__, ha->dpc_flags));
4597 qla4xxx_wake_dpc(ha);
4600 /* Reschedule timer thread to call us back in one second */
4601 mod_timer(&ha->timer, jiffies + HZ);
4603 DEBUG2(ha->seconds_since_last_intr++);
4607 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4608 * @ha: Pointer to host adapter structure.
4610 * This routine stalls the driver until all outstanding commands are returned.
4611 * Caller must release the Hardware Lock prior to calling this routine.
4613 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4616 unsigned long flags;
4617 struct scsi_cmnd *cmd;
4618 unsigned long wtime;
4622 wtmo = WAIT_CMD_TOV;
4624 wtmo = ha->nx_reset_timeout / 2;
4626 wtime = jiffies + (wtmo * HZ);
4628 DEBUG2(ql4_printk(KERN_INFO, ha,
4629 "Wait up to %u seconds for cmds to complete\n",
4632 while (!time_after_eq(jiffies, wtime)) {
4633 spin_lock_irqsave(&ha->hardware_lock, flags);
4634 /* Find a command that hasn't completed. */
4635 for (index = 0; index < ha->host->can_queue; index++) {
4636 cmd = scsi_host_find_tag(ha->host, index);
4638 * We cannot just check if the index is valid,
4639 * becase if we are run from the scsi eh, then
4640 * the scsi/block layer is going to prevent
4641 * the tag from being released.
4643 if (cmd != NULL && CMD_SP(cmd))
4646 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4648 /* If No Commands are pending, wait is complete */
4649 if (index == ha->host->can_queue)
4654 /* If we timed out on waiting for commands to come back
4659 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4661 uint32_t ctrl_status;
4662 unsigned long flags = 0;
4664 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4666 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4669 spin_lock_irqsave(&ha->hardware_lock, flags);
4672 * If the SCSI Reset Interrupt bit is set, clear it.
4673 * Otherwise, the Soft Reset won't work.
4675 ctrl_status = readw(&ha->reg->ctrl_status);
4676 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4677 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4679 /* Issue Soft Reset */
4680 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4681 readl(&ha->reg->ctrl_status);
4683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4688 * qla4xxx_soft_reset - performs soft reset.
4689 * @ha: Pointer to host adapter structure.
4691 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4693 uint32_t max_wait_time;
4694 unsigned long flags = 0;
4696 uint32_t ctrl_status;
4698 status = qla4xxx_hw_reset(ha);
4699 if (status != QLA_SUCCESS)
4703 /* Wait until the Network Reset Intr bit is cleared */
4704 max_wait_time = RESET_INTR_TOV;
4706 spin_lock_irqsave(&ha->hardware_lock, flags);
4707 ctrl_status = readw(&ha->reg->ctrl_status);
4708 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4710 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4714 } while ((--max_wait_time));
4716 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4717 DEBUG2(printk(KERN_WARNING
4718 "scsi%ld: Network Reset Intr not cleared by "
4719 "Network function, clearing it now!\n",
4721 spin_lock_irqsave(&ha->hardware_lock, flags);
4722 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4723 readl(&ha->reg->ctrl_status);
4724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4727 /* Wait until the firmware tells us the Soft Reset is done */
4728 max_wait_time = SOFT_RESET_TOV;
4730 spin_lock_irqsave(&ha->hardware_lock, flags);
4731 ctrl_status = readw(&ha->reg->ctrl_status);
4732 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4734 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4735 status = QLA_SUCCESS;
4740 } while ((--max_wait_time));
4743 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4744 * after the soft reset has taken place.
4746 spin_lock_irqsave(&ha->hardware_lock, flags);
4747 ctrl_status = readw(&ha->reg->ctrl_status);
4748 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4749 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4750 readl(&ha->reg->ctrl_status);
4752 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4754 /* If soft reset fails then most probably the bios on other
4755 * function is also enabled.
4756 * Since the initialization is sequential the other fn
4757 * wont be able to acknowledge the soft reset.
4758 * Issue a force soft reset to workaround this scenario.
4760 if (max_wait_time == 0) {
4761 /* Issue Force Soft Reset */
4762 spin_lock_irqsave(&ha->hardware_lock, flags);
4763 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4764 readl(&ha->reg->ctrl_status);
4765 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4766 /* Wait until the firmware tells us the Soft Reset is done */
4767 max_wait_time = SOFT_RESET_TOV;
4769 spin_lock_irqsave(&ha->hardware_lock, flags);
4770 ctrl_status = readw(&ha->reg->ctrl_status);
4771 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4773 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4774 status = QLA_SUCCESS;
4779 } while ((--max_wait_time));
4786 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4787 * @ha: Pointer to host adapter structure.
4788 * @res: returned scsi status
4790 * This routine is called just prior to a HARD RESET to return all
4791 * outstanding commands back to the Operating System.
4792 * Caller should make sure that the following locks are released
4793 * before this calling routine: Hardware lock, and io_request_lock.
4795 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4799 unsigned long flags;
4801 spin_lock_irqsave(&ha->hardware_lock, flags);
4802 for (i = 0; i < ha->host->can_queue; i++) {
4803 srb = qla4xxx_del_from_active_array(ha, i);
4805 srb->cmd->result = res;
4806 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4809 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4812 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4814 clear_bit(AF_ONLINE, &ha->flags);
4816 /* Disable the board */
4817 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4819 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4820 qla4xxx_mark_all_devices_missing(ha);
4821 clear_bit(AF_INIT_DONE, &ha->flags);
4824 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4826 struct iscsi_session *sess;
4827 struct ddb_entry *ddb_entry;
4829 sess = cls_session->dd_data;
4830 ddb_entry = sess->dd_data;
4831 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4833 if (ddb_entry->ddb_type == FLASH_DDB)
4834 iscsi_block_session(ddb_entry->sess);
4836 iscsi_session_failure(cls_session->dd_data,
4837 ISCSI_ERR_CONN_FAILED);
4841 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4842 * @ha: Pointer to host adapter structure.
4844 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4846 int status = QLA_ERROR;
4847 uint8_t reset_chip = 0;
4851 /* Stall incoming I/O until we are done */
4852 scsi_block_requests(ha->host);
4853 clear_bit(AF_ONLINE, &ha->flags);
4854 clear_bit(AF_LINK_UP, &ha->flags);
4856 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4858 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4860 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4861 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4862 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4864 /* disable pause frame for ISP83xx */
4865 qla4_83xx_disable_pause(ha);
4868 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4870 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4873 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4874 * do not reset adapter, jump to initialize_adapter */
4875 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4876 status = QLA_SUCCESS;
4877 goto recover_ha_init_adapter;
4880 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4881 * from eh_host_reset or ioctl module */
4882 if (is_qla80XX(ha) && !reset_chip &&
4883 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4885 DEBUG2(ql4_printk(KERN_INFO, ha,
4886 "scsi%ld: %s - Performing stop_firmware...\n",
4887 ha->host_no, __func__));
4888 status = ha->isp_ops->reset_firmware(ha);
4889 if (status == QLA_SUCCESS) {
4890 ha->isp_ops->disable_intrs(ha);
4891 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4892 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4894 /* If the stop_firmware fails then
4895 * reset the entire chip */
4897 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4898 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4902 /* Issue full chip reset if recovering from a catastrophic error,
4903 * or if stop_firmware fails for ISP-8xxx.
4904 * This is the default case for ISP-4xxx */
4905 if (is_qla40XX(ha) || reset_chip) {
4909 /* Check if 8XXX firmware is alive or not
4910 * We may have arrived here from NEED_RESET
4912 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4915 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4916 while (time_before(jiffies, wait)) {
4917 if (qla4_8xxx_check_fw_alive(ha)) {
4918 qla4xxx_mailbox_premature_completion(ha);
4922 set_current_state(TASK_UNINTERRUPTIBLE);
4923 schedule_timeout(HZ);
4926 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4927 qla4xxx_cmd_wait(ha);
4929 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4930 DEBUG2(ql4_printk(KERN_INFO, ha,
4931 "scsi%ld: %s - Performing chip reset..\n",
4932 ha->host_no, __func__));
4933 status = ha->isp_ops->reset_chip(ha);
4934 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4937 /* Flush any pending ddb changed AENs */
4938 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4940 recover_ha_init_adapter:
4941 /* Upon successful firmware/chip reset, re-initialize the adapter */
4942 if (status == QLA_SUCCESS) {
4943 /* For ISP-4xxx, force function 1 to always initialize
4944 * before function 3 to prevent both funcions from
4945 * stepping on top of the other */
4946 if (is_qla40XX(ha) && (ha->mac_index == 3))
4949 /* NOTE: AF_ONLINE flag set upon successful completion of
4950 * qla4xxx_initialize_adapter */
4951 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4952 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4953 status = qla4_8xxx_check_init_adapter_retry(ha);
4954 if (status == QLA_ERROR) {
4955 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4956 ha->host_no, __func__);
4957 qla4xxx_dead_adapter_cleanup(ha);
4958 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4959 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4960 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4967 /* Retry failed adapter initialization, if necessary
4968 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4969 * case to prevent ping-pong resets between functions */
4970 if (!test_bit(AF_ONLINE, &ha->flags) &&
4971 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4972 /* Adapter initialization failed, see if we can retry
4974 * Since we don't want to block the DPC for too long
4975 * with multiple resets in the same thread,
4976 * utilize DPC to retry */
4977 if (is_qla80XX(ha)) {
4978 ha->isp_ops->idc_lock(ha);
4979 dev_state = qla4_8xxx_rd_direct(ha,
4980 QLA8XXX_CRB_DEV_STATE);
4981 ha->isp_ops->idc_unlock(ha);
4982 if (dev_state == QLA8XXX_DEV_FAILED) {
4983 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4984 "recover adapter. H/W is in Failed "
4985 "state\n", __func__);
4986 qla4xxx_dead_adapter_cleanup(ha);
4987 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4988 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4989 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4997 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4998 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4999 DEBUG2(printk("scsi%ld: recover adapter - retrying "
5000 "(%d) more times\n", ha->host_no,
5001 ha->retry_reset_ha_cnt));
5002 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5005 if (ha->retry_reset_ha_cnt > 0) {
5006 /* Schedule another Reset HA--DPC will retry */
5007 ha->retry_reset_ha_cnt--;
5008 DEBUG2(printk("scsi%ld: recover adapter - "
5009 "retry remaining %d\n",
5011 ha->retry_reset_ha_cnt));
5015 if (ha->retry_reset_ha_cnt == 0) {
5016 /* Recover adapter retries have been exhausted.
5018 DEBUG2(printk("scsi%ld: recover adapter "
5019 "failed - board disabled\n",
5021 qla4xxx_dead_adapter_cleanup(ha);
5022 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5023 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5024 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5030 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5031 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5032 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5036 ha->adapter_error_count++;
5038 if (test_bit(AF_ONLINE, &ha->flags))
5039 ha->isp_ops->enable_intrs(ha);
5041 scsi_unblock_requests(ha->host);
5043 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5044 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5045 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5050 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5052 struct iscsi_session *sess;
5053 struct ddb_entry *ddb_entry;
5054 struct scsi_qla_host *ha;
5056 sess = cls_session->dd_data;
5057 ddb_entry = sess->dd_data;
5059 if (!iscsi_is_session_online(cls_session)) {
5060 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5061 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5062 " unblock session\n", ha->host_no, __func__,
5063 ddb_entry->fw_ddb_index);
5064 iscsi_unblock_session(ddb_entry->sess);
5066 /* Trigger relogin */
5067 if (ddb_entry->ddb_type == FLASH_DDB) {
5068 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5069 test_bit(DF_DISABLE_RELOGIN,
5070 &ddb_entry->flags)))
5071 qla4xxx_arm_relogin_timer(ddb_entry);
5073 iscsi_session_failure(cls_session->dd_data,
5074 ISCSI_ERR_CONN_FAILED);
5079 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5081 struct iscsi_session *sess;
5082 struct ddb_entry *ddb_entry;
5083 struct scsi_qla_host *ha;
5085 sess = cls_session->dd_data;
5086 ddb_entry = sess->dd_data;
5088 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5089 " unblock session\n", ha->host_no, __func__,
5090 ddb_entry->fw_ddb_index);
5092 iscsi_unblock_session(ddb_entry->sess);
5094 /* Start scan target */
5095 if (test_bit(AF_ONLINE, &ha->flags)) {
5096 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5097 " start scan\n", ha->host_no, __func__,
5098 ddb_entry->fw_ddb_index);
5099 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5104 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5106 struct iscsi_session *sess;
5107 struct ddb_entry *ddb_entry;
5108 struct scsi_qla_host *ha;
5109 int status = QLA_SUCCESS;
5111 sess = cls_session->dd_data;
5112 ddb_entry = sess->dd_data;
5114 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5115 " unblock user space session\n", ha->host_no, __func__,
5116 ddb_entry->fw_ddb_index);
5118 if (!iscsi_is_session_online(cls_session)) {
5119 iscsi_conn_start(ddb_entry->conn);
5120 iscsi_conn_login_event(ddb_entry->conn,
5121 ISCSI_CONN_STATE_LOGGED_IN);
5123 ql4_printk(KERN_INFO, ha,
5124 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5125 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5133 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5135 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5138 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5140 uint16_t relogin_timer;
5141 struct iscsi_session *sess;
5142 struct ddb_entry *ddb_entry;
5143 struct scsi_qla_host *ha;
5145 sess = cls_sess->dd_data;
5146 ddb_entry = sess->dd_data;
5149 relogin_timer = max(ddb_entry->default_relogin_timeout,
5150 (uint16_t)RELOGIN_TOV);
5151 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5153 DEBUG2(ql4_printk(KERN_INFO, ha,
5154 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5155 ddb_entry->fw_ddb_index, relogin_timer));
5157 qla4xxx_login_flash_ddb(cls_sess);
5160 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5162 struct iscsi_session *sess;
5163 struct ddb_entry *ddb_entry;
5164 struct scsi_qla_host *ha;
5166 sess = cls_sess->dd_data;
5167 ddb_entry = sess->dd_data;
5170 if (!(ddb_entry->ddb_type == FLASH_DDB))
5173 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5176 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5177 !iscsi_is_session_online(cls_sess)) {
5178 DEBUG2(ql4_printk(KERN_INFO, ha,
5179 "relogin issued\n"));
5180 qla4xxx_relogin_flash_ddb(cls_sess);
5184 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5187 queue_work(ha->dpc_thread, &ha->dpc_work);
5190 static struct qla4_work_evt *
5191 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5192 enum qla4_work_type type)
5194 struct qla4_work_evt *e;
5195 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5197 e = kzalloc(size, GFP_ATOMIC);
5201 INIT_LIST_HEAD(&e->list);
5206 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5207 struct qla4_work_evt *e)
5209 unsigned long flags;
5211 spin_lock_irqsave(&ha->work_lock, flags);
5212 list_add_tail(&e->list, &ha->work_list);
5213 spin_unlock_irqrestore(&ha->work_lock, flags);
5214 qla4xxx_wake_dpc(ha);
5217 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5218 enum iscsi_host_event_code aen_code,
5219 uint32_t data_size, uint8_t *data)
5221 struct qla4_work_evt *e;
5223 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5227 e->u.aen.code = aen_code;
5228 e->u.aen.data_size = data_size;
5229 memcpy(e->u.aen.data, data, data_size);
5231 qla4xxx_post_work(ha, e);
5236 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5237 uint32_t status, uint32_t pid,
5238 uint32_t data_size, uint8_t *data)
5240 struct qla4_work_evt *e;
5242 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5246 e->u.ping.status = status;
5247 e->u.ping.pid = pid;
5248 e->u.ping.data_size = data_size;
5249 memcpy(e->u.ping.data, data, data_size);
5251 qla4xxx_post_work(ha, e);
5256 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5258 struct qla4_work_evt *e, *tmp;
5259 unsigned long flags;
5262 spin_lock_irqsave(&ha->work_lock, flags);
5263 list_splice_init(&ha->work_list, &work);
5264 spin_unlock_irqrestore(&ha->work_lock, flags);
5266 list_for_each_entry_safe(e, tmp, &work, list) {
5267 list_del_init(&e->list);
5270 case QLA4_EVENT_AEN:
5271 iscsi_post_host_event(ha->host_no,
5272 &qla4xxx_iscsi_transport,
5277 case QLA4_EVENT_PING_STATUS:
5278 iscsi_ping_comp_event(ha->host_no,
5279 &qla4xxx_iscsi_transport,
5282 e->u.ping.data_size,
5286 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5287 "supported", e->type);
5294 * qla4xxx_do_dpc - dpc routine
5295 * @work: Context to obtain pointer to host adapter structure.
5297 * This routine is a task that is schedule by the interrupt handler
5298 * to perform the background processing for interrupts. We put it
5299 * on a task queue that is consumed whenever the scheduler runs; that's
5300 * so you can do anything (i.e. put the process to sleep etc). In fact,
5301 * the mid-level tries to sleep when it reaches the driver threshold
5302 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5304 static void qla4xxx_do_dpc(struct work_struct *work)
5306 struct scsi_qla_host *ha =
5307 container_of(work, struct scsi_qla_host, dpc_work);
5308 int status = QLA_ERROR;
5310 DEBUG2(ql4_printk(KERN_INFO, ha,
5311 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5312 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5314 /* Initialization not yet finished. Don't do anything yet. */
5315 if (!test_bit(AF_INIT_DONE, &ha->flags))
5318 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5319 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5320 ha->host_no, __func__, ha->flags));
5324 /* post events to application */
5325 qla4xxx_do_work(ha);
5327 if (is_qla80XX(ha)) {
5328 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5329 if (is_qla8032(ha) || is_qla8042(ha)) {
5330 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5332 /* disable pause frame for ISP83xx */
5333 qla4_83xx_disable_pause(ha);
5336 ha->isp_ops->idc_lock(ha);
5337 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5338 QLA8XXX_DEV_FAILED);
5339 ha->isp_ops->idc_unlock(ha);
5340 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5341 qla4_8xxx_device_state_handler(ha);
5344 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5345 if (is_qla8042(ha)) {
5346 if (ha->idc_info.info2 &
5347 ENABLE_INTERNAL_LOOPBACK) {
5348 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5350 status = qla4_84xx_config_acb(ha,
5351 ACB_CONFIG_DISABLE);
5352 if (status != QLA_SUCCESS) {
5353 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5358 qla4_83xx_post_idc_ack(ha);
5359 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5362 if (is_qla8042(ha) &&
5363 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5364 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5366 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5368 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5371 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5374 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5375 qla4_8xxx_need_qsnt_handler(ha);
5379 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5380 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5381 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5382 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5383 if ((is_qla8022(ha) && ql4xdontresethba) ||
5384 ((is_qla8032(ha) || is_qla8042(ha)) &&
5385 qla4_83xx_idc_dontreset(ha))) {
5386 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5387 ha->host_no, __func__));
5388 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5389 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5390 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5391 goto dpc_post_reset_ha;
5393 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5394 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5395 qla4xxx_recover_adapter(ha);
5397 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5398 uint8_t wait_time = RESET_INTR_TOV;
5400 while ((readw(&ha->reg->ctrl_status) &
5401 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5402 if (--wait_time == 0)
5407 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5408 "bit not cleared-- resetting\n",
5409 ha->host_no, __func__));
5410 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5411 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5412 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5413 status = qla4xxx_recover_adapter(ha);
5415 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5416 if (status == QLA_SUCCESS)
5417 ha->isp_ops->enable_intrs(ha);
5422 /* ---- process AEN? --- */
5423 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5424 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5426 /* ---- Get DHCP IP Address? --- */
5427 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5428 qla4xxx_get_dhcp_ip_address(ha);
5430 /* ---- relogin device? --- */
5431 if (adapter_up(ha) &&
5432 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5433 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5436 /* ---- link change? --- */
5437 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5438 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5439 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5440 /* ---- link down? --- */
5441 qla4xxx_mark_all_devices_missing(ha);
5443 /* ---- link up? --- *
5444 * F/W will auto login to all devices ONLY ONCE after
5445 * link up during driver initialization and runtime
5446 * fatal error recovery. Therefore, the driver must
5447 * manually relogin to devices when recovering from
5448 * connection failures, logouts, expired KATO, etc. */
5449 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5450 qla4xxx_build_ddb_list(ha, ha->is_reset);
5451 iscsi_host_for_each_session(ha->host,
5452 qla4xxx_login_flash_ddb);
5454 qla4xxx_relogin_all_devices(ha);
5457 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5458 if (qla4xxx_sysfs_ddb_export(ha))
5459 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5465 * qla4xxx_free_adapter - release the adapter
5466 * @ha: pointer to adapter structure
5468 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5470 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5472 /* Turn-off interrupts on the card. */
5473 ha->isp_ops->disable_intrs(ha);
5475 if (is_qla40XX(ha)) {
5476 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5477 &ha->reg->ctrl_status);
5478 readl(&ha->reg->ctrl_status);
5479 } else if (is_qla8022(ha)) {
5480 writel(0, &ha->qla4_82xx_reg->host_int);
5481 readl(&ha->qla4_82xx_reg->host_int);
5482 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5483 writel(0, &ha->qla4_83xx_reg->risc_intr);
5484 readl(&ha->qla4_83xx_reg->risc_intr);
5487 /* Remove timer thread, if present */
5488 if (ha->timer_active)
5489 qla4xxx_stop_timer(ha);
5491 /* Kill the kernel thread for this host */
5493 destroy_workqueue(ha->dpc_thread);
5495 /* Kill the kernel thread for this host */
5497 destroy_workqueue(ha->task_wq);
5499 /* Put firmware in known state */
5500 ha->isp_ops->reset_firmware(ha);
5502 if (is_qla80XX(ha)) {
5503 ha->isp_ops->idc_lock(ha);
5504 qla4_8xxx_clear_drv_active(ha);
5505 ha->isp_ops->idc_unlock(ha);
5508 /* Detach interrupts */
5509 qla4xxx_free_irqs(ha);
5511 /* free extra memory */
5512 qla4xxx_mem_free(ha);
5515 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5518 unsigned long mem_base, mem_len;
5519 struct pci_dev *pdev = ha->pdev;
5521 status = pci_request_regions(pdev, DRIVER_NAME);
5524 "scsi(%ld) Failed to reserve PIO regions (%s) "
5525 "status=%d\n", ha->host_no, pci_name(pdev), status);
5526 goto iospace_error_exit;
5529 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5530 __func__, pdev->revision));
5531 ha->revision_id = pdev->revision;
5533 /* remap phys address */
5534 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5535 mem_len = pci_resource_len(pdev, 0);
5536 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5537 __func__, mem_base, mem_len));
5539 /* mapping of pcibase pointer */
5540 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5541 if (!ha->nx_pcibase) {
5543 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5544 pci_release_regions(ha->pdev);
5545 goto iospace_error_exit;
5548 /* Mapping of IO base pointer, door bell read and write pointer */
5550 /* mapping of IO base pointer */
5551 if (is_qla8022(ha)) {
5552 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5553 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5554 (ha->pdev->devfn << 11));
5555 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5556 QLA82XX_CAM_RAM_DB2);
5557 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5558 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5559 ((uint8_t *)ha->nx_pcibase);
5568 * qla4xxx_iospace_config - maps registers
5569 * @ha: pointer to adapter structure
5571 * This routines maps HBA's registers from the pci address space
5572 * into the kernel virtual address space for memory mapped i/o.
5574 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5576 unsigned long pio, pio_len, pio_flags;
5577 unsigned long mmio, mmio_len, mmio_flags;
5579 pio = pci_resource_start(ha->pdev, 0);
5580 pio_len = pci_resource_len(ha->pdev, 0);
5581 pio_flags = pci_resource_flags(ha->pdev, 0);
5582 if (pio_flags & IORESOURCE_IO) {
5583 if (pio_len < MIN_IOBASE_LEN) {
5584 ql4_printk(KERN_WARNING, ha,
5585 "Invalid PCI I/O region size\n");
5589 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5593 /* Use MMIO operations for all accesses. */
5594 mmio = pci_resource_start(ha->pdev, 1);
5595 mmio_len = pci_resource_len(ha->pdev, 1);
5596 mmio_flags = pci_resource_flags(ha->pdev, 1);
5598 if (!(mmio_flags & IORESOURCE_MEM)) {
5599 ql4_printk(KERN_ERR, ha,
5600 "region #0 not an MMIO resource, aborting\n");
5602 goto iospace_error_exit;
5605 if (mmio_len < MIN_IOBASE_LEN) {
5606 ql4_printk(KERN_ERR, ha,
5607 "Invalid PCI mem region size, aborting\n");
5608 goto iospace_error_exit;
5611 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5612 ql4_printk(KERN_WARNING, ha,
5613 "Failed to reserve PIO/MMIO regions\n");
5615 goto iospace_error_exit;
5618 ha->pio_address = pio;
5619 ha->pio_length = pio_len;
5620 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5622 ql4_printk(KERN_ERR, ha,
5623 "cannot remap MMIO, aborting\n");
5625 goto iospace_error_exit;
5634 static struct isp_operations qla4xxx_isp_ops = {
5635 .iospace_config = qla4xxx_iospace_config,
5636 .pci_config = qla4xxx_pci_config,
5637 .disable_intrs = qla4xxx_disable_intrs,
5638 .enable_intrs = qla4xxx_enable_intrs,
5639 .start_firmware = qla4xxx_start_firmware,
5640 .intr_handler = qla4xxx_intr_handler,
5641 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5642 .reset_chip = qla4xxx_soft_reset,
5643 .reset_firmware = qla4xxx_hw_reset,
5644 .queue_iocb = qla4xxx_queue_iocb,
5645 .complete_iocb = qla4xxx_complete_iocb,
5646 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5647 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5648 .get_sys_info = qla4xxx_get_sys_info,
5649 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5650 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5653 static struct isp_operations qla4_82xx_isp_ops = {
5654 .iospace_config = qla4_8xxx_iospace_config,
5655 .pci_config = qla4_8xxx_pci_config,
5656 .disable_intrs = qla4_82xx_disable_intrs,
5657 .enable_intrs = qla4_82xx_enable_intrs,
5658 .start_firmware = qla4_8xxx_load_risc,
5659 .restart_firmware = qla4_82xx_try_start_fw,
5660 .intr_handler = qla4_82xx_intr_handler,
5661 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5662 .need_reset = qla4_8xxx_need_reset,
5663 .reset_chip = qla4_82xx_isp_reset,
5664 .reset_firmware = qla4_8xxx_stop_firmware,
5665 .queue_iocb = qla4_82xx_queue_iocb,
5666 .complete_iocb = qla4_82xx_complete_iocb,
5667 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5668 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5669 .get_sys_info = qla4_8xxx_get_sys_info,
5670 .rd_reg_direct = qla4_82xx_rd_32,
5671 .wr_reg_direct = qla4_82xx_wr_32,
5672 .rd_reg_indirect = qla4_82xx_md_rd_32,
5673 .wr_reg_indirect = qla4_82xx_md_wr_32,
5674 .idc_lock = qla4_82xx_idc_lock,
5675 .idc_unlock = qla4_82xx_idc_unlock,
5676 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5677 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5678 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5681 static struct isp_operations qla4_83xx_isp_ops = {
5682 .iospace_config = qla4_8xxx_iospace_config,
5683 .pci_config = qla4_8xxx_pci_config,
5684 .disable_intrs = qla4_83xx_disable_intrs,
5685 .enable_intrs = qla4_83xx_enable_intrs,
5686 .start_firmware = qla4_8xxx_load_risc,
5687 .restart_firmware = qla4_83xx_start_firmware,
5688 .intr_handler = qla4_83xx_intr_handler,
5689 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5690 .need_reset = qla4_8xxx_need_reset,
5691 .reset_chip = qla4_83xx_isp_reset,
5692 .reset_firmware = qla4_8xxx_stop_firmware,
5693 .queue_iocb = qla4_83xx_queue_iocb,
5694 .complete_iocb = qla4_83xx_complete_iocb,
5695 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5696 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5697 .get_sys_info = qla4_8xxx_get_sys_info,
5698 .rd_reg_direct = qla4_83xx_rd_reg,
5699 .wr_reg_direct = qla4_83xx_wr_reg,
5700 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5701 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5702 .idc_lock = qla4_83xx_drv_lock,
5703 .idc_unlock = qla4_83xx_drv_unlock,
5704 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5705 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5706 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5709 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5711 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5714 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5716 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5719 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5721 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5724 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5726 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5729 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5731 struct scsi_qla_host *ha = data;
5736 case ISCSI_BOOT_ETH_FLAGS:
5737 rc = sprintf(str, "%d\n", (char)SYSFS_FLAG_FW_SEL_BOOT);
5739 case ISCSI_BOOT_ETH_INDEX:
5740 rc = sprintf(str, "0\n");
5742 case ISCSI_BOOT_ETH_MAC:
5743 rc = sysfs_format_mac(str, ha->my_mac,
5753 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5758 case ISCSI_BOOT_ETH_FLAGS:
5759 case ISCSI_BOOT_ETH_MAC:
5760 case ISCSI_BOOT_ETH_INDEX:
5770 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5772 struct scsi_qla_host *ha = data;
5777 case ISCSI_BOOT_INI_INITIATOR_NAME:
5778 rc = sprintf(str, "%s\n", ha->name_string);
5787 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5792 case ISCSI_BOOT_INI_INITIATOR_NAME:
5803 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5806 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5811 case ISCSI_BOOT_TGT_NAME:
5812 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5814 case ISCSI_BOOT_TGT_IP_ADDR:
5815 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5816 rc = sprintf(buf, "%pI4\n",
5817 &boot_conn->dest_ipaddr.ip_address);
5819 rc = sprintf(str, "%pI6\n",
5820 &boot_conn->dest_ipaddr.ip_address);
5822 case ISCSI_BOOT_TGT_PORT:
5823 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5825 case ISCSI_BOOT_TGT_CHAP_NAME:
5826 rc = sprintf(str, "%.*s\n",
5827 boot_conn->chap.target_chap_name_length,
5828 (char *)&boot_conn->chap.target_chap_name);
5830 case ISCSI_BOOT_TGT_CHAP_SECRET:
5831 rc = sprintf(str, "%.*s\n",
5832 boot_conn->chap.target_secret_length,
5833 (char *)&boot_conn->chap.target_secret);
5835 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5836 rc = sprintf(str, "%.*s\n",
5837 boot_conn->chap.intr_chap_name_length,
5838 (char *)&boot_conn->chap.intr_chap_name);
5840 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5841 rc = sprintf(str, "%.*s\n",
5842 boot_conn->chap.intr_secret_length,
5843 (char *)&boot_conn->chap.intr_secret);
5845 case ISCSI_BOOT_TGT_FLAGS:
5846 rc = sprintf(str, "%d\n", (char)SYSFS_FLAG_FW_SEL_BOOT);
5848 case ISCSI_BOOT_TGT_NIC_ASSOC:
5849 rc = sprintf(str, "0\n");
5858 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5860 struct scsi_qla_host *ha = data;
5861 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5863 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5866 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5868 struct scsi_qla_host *ha = data;
5869 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5871 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5874 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5879 case ISCSI_BOOT_TGT_NAME:
5880 case ISCSI_BOOT_TGT_IP_ADDR:
5881 case ISCSI_BOOT_TGT_PORT:
5882 case ISCSI_BOOT_TGT_CHAP_NAME:
5883 case ISCSI_BOOT_TGT_CHAP_SECRET:
5884 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5885 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5886 case ISCSI_BOOT_TGT_NIC_ASSOC:
5887 case ISCSI_BOOT_TGT_FLAGS:
5897 static void qla4xxx_boot_release(void *data)
5899 struct scsi_qla_host *ha = data;
5901 scsi_host_put(ha->host);
5904 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5907 uint32_t addr, pri_addr, sec_addr;
5911 uint8_t *buf = NULL;
5912 size_t size = 13 * sizeof(uint8_t);
5913 int ret = QLA_SUCCESS;
5915 func_num = PCI_FUNC(ha->pdev->devfn);
5917 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5918 __func__, ha->pdev->device, func_num);
5920 if (is_qla40XX(ha)) {
5921 if (func_num == 1) {
5922 addr = NVRAM_PORT0_BOOT_MODE;
5923 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5924 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5925 } else if (func_num == 3) {
5926 addr = NVRAM_PORT1_BOOT_MODE;
5927 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5928 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5931 goto exit_boot_info;
5934 /* Check Boot Mode */
5935 val = rd_nvram_byte(ha, addr);
5936 if (!(val & 0x07)) {
5937 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5938 "options : 0x%x\n", __func__, val));
5940 goto exit_boot_info;
5943 /* get primary valid target index */
5944 val = rd_nvram_byte(ha, pri_addr);
5946 ddb_index[0] = (val & 0x7f);
5948 /* get secondary valid target index */
5949 val = rd_nvram_byte(ha, sec_addr);
5951 ddb_index[1] = (val & 0x7f);
5952 goto exit_boot_info;
5953 } else if (is_qla80XX(ha)) {
5954 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5955 &buf_dma, GFP_KERNEL);
5957 DEBUG2(ql4_printk(KERN_ERR, ha,
5958 "%s: Unable to allocate dma buffer\n",
5961 goto exit_boot_info;
5964 if (ha->port_num == 0)
5965 offset = BOOT_PARAM_OFFSET_PORT0;
5966 else if (ha->port_num == 1)
5967 offset = BOOT_PARAM_OFFSET_PORT1;
5970 goto exit_boot_info_free;
5972 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5974 if (qla4xxx_get_flash(ha, buf_dma, addr,
5975 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5976 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5977 " failed\n", ha->host_no, __func__));
5979 goto exit_boot_info_free;
5981 /* Check Boot Mode */
5982 if (!(buf[1] & 0x07)) {
5983 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5984 " : 0x%x\n", buf[1]));
5986 goto exit_boot_info_free;
5989 /* get primary valid target index */
5991 ddb_index[0] = buf[2] & 0x7f;
5993 /* get secondary valid target index */
5994 if (buf[11] & BIT_7)
5995 ddb_index[1] = buf[11] & 0x7f;
5998 goto exit_boot_info;
6001 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
6002 " target ID %d\n", __func__, ddb_index[0],
6005 exit_boot_info_free:
6006 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
6008 ha->pri_ddb_idx = ddb_index[0];
6009 ha->sec_ddb_idx = ddb_index[1];
6014 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
6015 * @ha: pointer to adapter structure
6016 * @username: CHAP username to be returned
6017 * @password: CHAP password to be returned
6019 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6020 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6021 * So from the CHAP cache find the first BIDI CHAP entry and set it
6022 * to the boot record in sysfs.
6024 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6027 int i, ret = -EINVAL;
6028 int max_chap_entries = 0;
6029 struct ql4_chap_table *chap_table;
6032 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6033 sizeof(struct ql4_chap_table);
6035 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6037 if (!ha->chap_list) {
6038 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6042 mutex_lock(&ha->chap_sem);
6043 for (i = 0; i < max_chap_entries; i++) {
6044 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6045 if (chap_table->cookie !=
6046 cpu_to_le16(CHAP_VALID_COOKIE)) {
6050 if (chap_table->flags & BIT_7) /* local */
6053 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6056 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6057 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6061 mutex_unlock(&ha->chap_sem);
6067 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6068 struct ql4_boot_session_info *boot_sess,
6071 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6072 struct dev_db_entry *fw_ddb_entry;
6073 dma_addr_t fw_ddb_entry_dma;
6076 int ret = QLA_SUCCESS;
6078 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6079 &fw_ddb_entry_dma, GFP_KERNEL);
6080 if (!fw_ddb_entry) {
6081 DEBUG2(ql4_printk(KERN_ERR, ha,
6082 "%s: Unable to allocate dma buffer.\n",
6088 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6089 fw_ddb_entry_dma, ddb_index)) {
6090 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6091 "index [%d]\n", __func__, ddb_index));
6093 goto exit_boot_target;
6096 /* Update target name and IP from DDB */
6097 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6098 min(sizeof(boot_sess->target_name),
6099 sizeof(fw_ddb_entry->iscsi_name)));
6101 options = le16_to_cpu(fw_ddb_entry->options);
6102 if (options & DDB_OPT_IPV6_DEVICE) {
6103 memcpy(&boot_conn->dest_ipaddr.ip_address,
6104 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6106 boot_conn->dest_ipaddr.ip_type = 0x1;
6107 memcpy(&boot_conn->dest_ipaddr.ip_address,
6108 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6111 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6113 /* update chap information */
6114 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6116 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6118 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6120 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6122 (char *)&boot_conn->chap.target_secret,
6125 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6127 goto exit_boot_target;
6130 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6131 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6134 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6136 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6138 ret = qla4xxx_get_bidi_chap(ha,
6139 (char *)&boot_conn->chap.intr_chap_name,
6140 (char *)&boot_conn->chap.intr_secret);
6143 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6145 goto exit_boot_target;
6148 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6149 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6153 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6154 fw_ddb_entry, fw_ddb_entry_dma);
6158 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6160 uint16_t ddb_index[2];
6161 int ret = QLA_ERROR;
6164 memset(ddb_index, 0, sizeof(ddb_index));
6165 ddb_index[0] = 0xffff;
6166 ddb_index[1] = 0xffff;
6167 ret = get_fw_boot_info(ha, ddb_index);
6168 if (ret != QLA_SUCCESS) {
6169 DEBUG2(ql4_printk(KERN_INFO, ha,
6170 "%s: No boot target configured.\n", __func__));
6174 if (ql4xdisablesysfsboot)
6177 if (ddb_index[0] == 0xffff)
6180 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6182 if (rval != QLA_SUCCESS) {
6183 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6184 "configured\n", __func__));
6189 if (ddb_index[1] == 0xffff)
6190 goto exit_get_boot_info;
6192 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6194 if (rval != QLA_SUCCESS) {
6195 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6196 " configured\n", __func__));
6204 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6206 struct iscsi_boot_kobj *boot_kobj;
6208 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6211 if (ql4xdisablesysfsboot) {
6212 ql4_printk(KERN_INFO, ha,
6213 "%s: syfsboot disabled - driver will trigger login "
6214 "and publish session for discovery .\n", __func__);
6219 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6223 if (!scsi_host_get(ha->host))
6225 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6226 qla4xxx_show_boot_tgt_pri_info,
6227 qla4xxx_tgt_get_attr_visibility,
6228 qla4xxx_boot_release);
6232 if (!scsi_host_get(ha->host))
6234 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6235 qla4xxx_show_boot_tgt_sec_info,
6236 qla4xxx_tgt_get_attr_visibility,
6237 qla4xxx_boot_release);
6241 if (!scsi_host_get(ha->host))
6243 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6244 qla4xxx_show_boot_ini_info,
6245 qla4xxx_ini_get_attr_visibility,
6246 qla4xxx_boot_release);
6250 if (!scsi_host_get(ha->host))
6252 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6253 qla4xxx_show_boot_eth_info,
6254 qla4xxx_eth_get_attr_visibility,
6255 qla4xxx_boot_release);
6262 scsi_host_put(ha->host);
6264 iscsi_boot_destroy_kset(ha->boot_kset);
6269 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6270 struct ql4_tuple_ddb *tddb)
6272 struct iscsi_cls_session *cls_sess;
6273 struct iscsi_cls_conn *cls_conn;
6274 struct iscsi_session *sess;
6275 struct iscsi_conn *conn;
6277 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6278 cls_sess = ddb_entry->sess;
6279 sess = cls_sess->dd_data;
6280 cls_conn = ddb_entry->conn;
6281 conn = cls_conn->dd_data;
6283 tddb->tpgt = sess->tpgt;
6284 tddb->port = conn->persistent_port;
6285 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6286 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6289 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6290 struct ql4_tuple_ddb *tddb,
6291 uint8_t *flash_isid)
6293 uint16_t options = 0;
6295 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6296 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6297 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6299 options = le16_to_cpu(fw_ddb_entry->options);
6300 if (options & DDB_OPT_IPV6_DEVICE)
6301 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6303 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6305 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6307 if (flash_isid == NULL)
6308 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6309 sizeof(tddb->isid));
6311 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6314 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6315 struct ql4_tuple_ddb *old_tddb,
6316 struct ql4_tuple_ddb *new_tddb,
6317 uint8_t is_isid_compare)
6319 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6322 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6325 if (old_tddb->port != new_tddb->port)
6328 /* For multi sessions, driver generates the ISID, so do not compare
6329 * ISID in reset path since it would be a comparison between the
6330 * driver generated ISID and firmware generated ISID. This could
6331 * lead to adding duplicated DDBs in the list as driver generated
6332 * ISID would not match firmware generated ISID.
6334 if (is_isid_compare) {
6335 DEBUG2(ql4_printk(KERN_INFO, ha,
6336 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6337 __func__, old_tddb->isid, new_tddb->isid));
6339 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6340 sizeof(old_tddb->isid)))
6344 DEBUG2(ql4_printk(KERN_INFO, ha,
6345 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6346 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6347 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6348 new_tddb->ip_addr, new_tddb->iscsi_name));
6353 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6354 struct dev_db_entry *fw_ddb_entry,
6357 struct ddb_entry *ddb_entry;
6358 struct ql4_tuple_ddb *fw_tddb = NULL;
6359 struct ql4_tuple_ddb *tmp_tddb = NULL;
6361 int ret = QLA_ERROR;
6363 fw_tddb = vzalloc(sizeof(*fw_tddb));
6365 DEBUG2(ql4_printk(KERN_WARNING, ha,
6366 "Memory Allocation failed.\n"));
6371 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6373 DEBUG2(ql4_printk(KERN_WARNING, ha,
6374 "Memory Allocation failed.\n"));
6379 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6381 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6382 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6383 if (ddb_entry == NULL)
6386 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6387 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6388 ret = QLA_SUCCESS; /* found */
6402 * qla4xxx_check_existing_isid - check if target with same isid exist
6404 * @list_nt: list of target
6405 * @isid: isid to check
6407 * This routine return QLA_SUCCESS if target with same isid exist
6409 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6411 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6412 struct dev_db_entry *fw_ddb_entry;
6414 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6415 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6417 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6418 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6426 * qla4xxx_update_isid - compare ddbs and updated isid
6427 * @ha: Pointer to host adapter structure.
6428 * @list_nt: list of nt target
6429 * @fw_ddb_entry: firmware ddb entry
6431 * This routine update isid if ddbs have same iqn, same isid and
6432 * different IP addr.
6433 * Return QLA_SUCCESS if isid is updated.
6435 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6436 struct list_head *list_nt,
6437 struct dev_db_entry *fw_ddb_entry)
6439 uint8_t base_value, i;
6441 base_value = fw_ddb_entry->isid[1] & 0x1f;
6442 for (i = 0; i < 8; i++) {
6443 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6444 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6448 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6455 * qla4xxx_should_update_isid - check if isid need to update
6456 * @ha: Pointer to host adapter structure.
6457 * @old_tddb: ddb tuple
6458 * @new_tddb: ddb tuple
6460 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6463 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6464 struct ql4_tuple_ddb *old_tddb,
6465 struct ql4_tuple_ddb *new_tddb)
6467 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6469 if (old_tddb->port == new_tddb->port)
6473 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6477 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6478 sizeof(old_tddb->isid)))
6479 /* different isid */
6486 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6487 * @ha: Pointer to host adapter structure.
6488 * @list_nt: list of nt target.
6489 * @fw_ddb_entry: firmware ddb entry.
6491 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6492 * duplicate ddb in list_nt.
6493 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6494 * Note: This function also update isid of DDB if required.
6497 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6498 struct list_head *list_nt,
6499 struct dev_db_entry *fw_ddb_entry)
6501 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6502 struct ql4_tuple_ddb *fw_tddb = NULL;
6503 struct ql4_tuple_ddb *tmp_tddb = NULL;
6504 int rval, ret = QLA_ERROR;
6506 fw_tddb = vzalloc(sizeof(*fw_tddb));
6508 DEBUG2(ql4_printk(KERN_WARNING, ha,
6509 "Memory Allocation failed.\n"));
6514 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6516 DEBUG2(ql4_printk(KERN_WARNING, ha,
6517 "Memory Allocation failed.\n"));
6522 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6524 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6525 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6526 nt_ddb_idx->flash_isid);
6527 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6528 /* found duplicate ddb */
6529 if (ret == QLA_SUCCESS)
6533 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6534 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6536 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6537 if (ret == QLA_SUCCESS) {
6538 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6539 if (rval == QLA_SUCCESS)
6554 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6556 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6558 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6559 list_del_init(&ddb_idx->list);
6564 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6565 struct dev_db_entry *fw_ddb_entry)
6567 struct iscsi_endpoint *ep;
6568 struct sockaddr_in *addr;
6569 struct sockaddr_in6 *addr6;
6570 struct sockaddr *t_addr;
6571 struct sockaddr_storage *dst_addr;
6574 /* TODO: need to destroy on unload iscsi_endpoint*/
6575 dst_addr = vmalloc(sizeof(*dst_addr));
6579 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6580 t_addr = (struct sockaddr *)dst_addr;
6581 t_addr->sa_family = AF_INET6;
6582 addr6 = (struct sockaddr_in6 *)dst_addr;
6583 ip = (char *)&addr6->sin6_addr;
6584 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6585 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6588 t_addr = (struct sockaddr *)dst_addr;
6589 t_addr->sa_family = AF_INET;
6590 addr = (struct sockaddr_in *)dst_addr;
6591 ip = (char *)&addr->sin_addr;
6592 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6593 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6596 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6601 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6603 if (ql4xdisablesysfsboot)
6605 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6610 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6611 struct ddb_entry *ddb_entry,
6614 uint16_t def_timeout;
6616 ddb_entry->ddb_type = FLASH_DDB;
6617 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6618 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6620 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6621 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6622 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6624 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6625 atomic_set(&ddb_entry->relogin_timer, 0);
6626 atomic_set(&ddb_entry->relogin_retry_count, 0);
6627 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6628 ddb_entry->default_relogin_timeout =
6629 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6630 def_timeout : LOGIN_TOV;
6631 ddb_entry->default_time2wait =
6632 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6634 if (ql4xdisablesysfsboot &&
6635 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6636 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6639 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6642 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6643 uint32_t sts[MBOX_REG_COUNT];
6645 unsigned long wtime;
6648 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6650 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6651 if (ip_idx[idx] == -1)
6654 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6656 if (ret == QLA_ERROR) {
6661 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6663 DEBUG2(ql4_printk(KERN_INFO, ha,
6664 "Waiting for IP state for idx = %d, state = 0x%x\n",
6665 ip_idx[idx], ip_state));
6666 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6667 ip_state == IP_ADDRSTATE_INVALID ||
6668 ip_state == IP_ADDRSTATE_PREFERRED ||
6669 ip_state == IP_ADDRSTATE_DEPRICATED ||
6670 ip_state == IP_ADDRSTATE_DISABLING)
6674 /* Break if all IP states checked */
6675 if ((ip_idx[0] == -1) &&
6676 (ip_idx[1] == -1) &&
6677 (ip_idx[2] == -1) &&
6680 schedule_timeout_uninterruptible(HZ);
6681 } while (time_after(wtime, jiffies));
6684 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6685 struct dev_db_entry *flash_ddb_entry)
6687 uint16_t options = 0;
6688 size_t ip_len = IP_ADDR_LEN;
6690 options = le16_to_cpu(fw_ddb_entry->options);
6691 if (options & DDB_OPT_IPV6_DEVICE)
6692 ip_len = IPv6_ADDR_LEN;
6694 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6697 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6698 sizeof(fw_ddb_entry->isid)))
6701 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6702 sizeof(fw_ddb_entry->port)))
6708 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6709 struct dev_db_entry *fw_ddb_entry,
6710 uint32_t fw_idx, uint32_t *flash_index)
6712 struct dev_db_entry *flash_ddb_entry;
6713 dma_addr_t flash_ddb_entry_dma;
6716 int ret = QLA_ERROR, status;
6718 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6721 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6722 &flash_ddb_entry_dma);
6723 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6724 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6725 goto exit_find_st_idx;
6728 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6729 flash_ddb_entry_dma, fw_idx);
6730 if (status == QLA_SUCCESS) {
6731 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6732 if (status == QLA_SUCCESS) {
6733 *flash_index = fw_idx;
6735 goto exit_find_st_idx;
6739 for (idx = 0; idx < max_ddbs; idx++) {
6740 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6741 flash_ddb_entry_dma, idx);
6742 if (status == QLA_ERROR)
6745 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6746 if (status == QLA_SUCCESS) {
6749 goto exit_find_st_idx;
6753 if (idx == max_ddbs)
6754 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6758 if (flash_ddb_entry)
6759 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6760 flash_ddb_entry_dma);
6765 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6766 struct list_head *list_st)
6768 struct qla_ddb_index *st_ddb_idx;
6771 struct dev_db_entry *fw_ddb_entry;
6772 dma_addr_t fw_ddb_dma;
6774 uint32_t idx = 0, next_idx = 0;
6775 uint32_t state = 0, conn_err = 0;
6776 uint32_t flash_index = -1;
6777 uint16_t conn_id = 0;
6779 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6781 if (fw_ddb_entry == NULL) {
6782 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6786 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6788 fw_idx_size = sizeof(struct qla_ddb_index);
6790 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6791 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6792 NULL, &next_idx, &state,
6793 &conn_err, NULL, &conn_id);
6794 if (ret == QLA_ERROR)
6797 /* Ignore DDB if invalid state (unassigned) */
6798 if (state == DDB_DS_UNASSIGNED)
6799 goto continue_next_st;
6801 /* Check if ST, add to the list_st */
6802 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6803 goto continue_next_st;
6805 st_ddb_idx = vzalloc(fw_idx_size);
6809 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6811 if (ret == QLA_ERROR) {
6812 ql4_printk(KERN_ERR, ha,
6813 "No flash entry for ST at idx [%d]\n", idx);
6814 st_ddb_idx->flash_ddb_idx = idx;
6816 ql4_printk(KERN_INFO, ha,
6817 "ST at idx [%d] is stored at flash [%d]\n",
6819 st_ddb_idx->flash_ddb_idx = flash_index;
6822 st_ddb_idx->fw_ddb_idx = idx;
6824 list_add_tail(&st_ddb_idx->list, list_st);
6832 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6836 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6837 * @ha: pointer to adapter structure
6838 * @list_ddb: List from which failed ddb to be removed
6840 * Iterate over the list of DDBs and find and remove DDBs that are either in
6841 * no connection active state or failed state
6843 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6844 struct list_head *list_ddb)
6846 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6847 uint32_t next_idx = 0;
6848 uint32_t state = 0, conn_err = 0;
6851 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6852 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6853 NULL, 0, NULL, &next_idx, &state,
6854 &conn_err, NULL, NULL);
6855 if (ret == QLA_ERROR)
6858 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6859 state == DDB_DS_SESSION_FAILED) {
6860 list_del_init(&ddb_idx->list);
6866 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6867 struct ddb_entry *ddb_entry,
6868 struct dev_db_entry *fw_ddb_entry)
6870 struct iscsi_cls_session *cls_sess;
6871 struct iscsi_session *sess;
6872 uint32_t max_ddbs = 0;
6873 uint16_t ddb_link = -1;
6875 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6878 cls_sess = ddb_entry->sess;
6879 sess = cls_sess->dd_data;
6881 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6882 if (ddb_link < max_ddbs)
6883 sess->discovery_parent_idx = ddb_link;
6885 sess->discovery_parent_idx = DDB_NO_LINK;
6888 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6889 struct dev_db_entry *fw_ddb_entry,
6890 int is_reset, uint16_t idx)
6892 struct iscsi_cls_session *cls_sess;
6893 struct iscsi_session *sess;
6894 struct iscsi_cls_conn *cls_conn;
6895 struct iscsi_endpoint *ep;
6896 uint16_t cmds_max = 32;
6897 uint16_t conn_id = 0;
6898 uint32_t initial_cmdsn = 0;
6899 int ret = QLA_SUCCESS;
6901 struct ddb_entry *ddb_entry = NULL;
6903 /* Create session object, with INVALID_ENTRY,
6904 * the targer_id would get set when we issue the login
6906 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6907 cmds_max, sizeof(struct ddb_entry),
6908 sizeof(struct ql4_task_data),
6909 initial_cmdsn, INVALID_ENTRY);
6916 * so calling module_put function to decrement the
6919 module_put(qla4xxx_iscsi_transport.owner);
6920 sess = cls_sess->dd_data;
6921 ddb_entry = sess->dd_data;
6922 ddb_entry->sess = cls_sess;
6924 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6925 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6926 sizeof(struct dev_db_entry));
6928 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6930 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6937 ddb_entry->conn = cls_conn;
6939 /* Setup ep, for displaying attributes in sysfs */
6940 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6942 ep->conn = cls_conn;
6945 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6950 /* Update sess/conn params */
6951 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6952 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6954 if (is_reset == RESET_ADAPTER) {
6955 iscsi_block_session(cls_sess);
6956 /* Use the relogin path to discover new devices
6957 * by short-circuiting the logic of setting
6958 * timer to relogin - instead set the flags
6959 * to initiate login right away.
6961 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6962 set_bit(DF_RELOGIN, &ddb_entry->flags);
6969 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6970 struct list_head *list_ddb,
6971 struct dev_db_entry *fw_ddb_entry)
6973 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6976 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6978 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6979 if (ddb_idx->fw_ddb_idx == ddb_link) {
6980 DEBUG2(ql4_printk(KERN_INFO, ha,
6981 "Updating NT parent idx from [%d] to [%d]\n",
6982 ddb_link, ddb_idx->flash_ddb_idx));
6983 fw_ddb_entry->ddb_link =
6984 cpu_to_le16(ddb_idx->flash_ddb_idx);
6990 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6991 struct list_head *list_nt,
6992 struct list_head *list_st,
6995 struct dev_db_entry *fw_ddb_entry;
6996 struct ddb_entry *ddb_entry = NULL;
6997 dma_addr_t fw_ddb_dma;
7001 uint32_t idx = 0, next_idx = 0;
7002 uint32_t state = 0, conn_err = 0;
7003 uint32_t ddb_idx = -1;
7004 uint16_t conn_id = 0;
7005 uint16_t ddb_link = -1;
7006 struct qla_ddb_index *nt_ddb_idx;
7008 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7010 if (fw_ddb_entry == NULL) {
7011 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7014 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7016 fw_idx_size = sizeof(struct qla_ddb_index);
7018 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7019 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7020 NULL, &next_idx, &state,
7021 &conn_err, NULL, &conn_id);
7022 if (ret == QLA_ERROR)
7025 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7026 goto continue_next_nt;
7028 /* Check if NT, then add to list it */
7029 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7030 goto continue_next_nt;
7032 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7033 if (ddb_link < max_ddbs)
7034 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7036 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7037 state == DDB_DS_SESSION_FAILED) &&
7038 (is_reset == INIT_ADAPTER))
7039 goto continue_next_nt;
7041 DEBUG2(ql4_printk(KERN_INFO, ha,
7042 "Adding DDB to session = 0x%x\n", idx));
7044 if (is_reset == INIT_ADAPTER) {
7045 nt_ddb_idx = vmalloc(fw_idx_size);
7049 nt_ddb_idx->fw_ddb_idx = idx;
7051 /* Copy original isid as it may get updated in function
7052 * qla4xxx_update_isid(). We need original isid in
7053 * function qla4xxx_compare_tuple_ddb to find duplicate
7055 memcpy(&nt_ddb_idx->flash_isid[0],
7056 &fw_ddb_entry->isid[0],
7057 sizeof(nt_ddb_idx->flash_isid));
7059 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7061 if (ret == QLA_SUCCESS) {
7062 /* free nt_ddb_idx and do not add to list_nt */
7064 goto continue_next_nt;
7067 /* Copy updated isid */
7068 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7069 sizeof(struct dev_db_entry));
7071 list_add_tail(&nt_ddb_idx->list, list_nt);
7072 } else if (is_reset == RESET_ADAPTER) {
7073 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7075 if (ret == QLA_SUCCESS) {
7076 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7078 if (ddb_entry != NULL)
7079 qla4xxx_update_sess_disc_idx(ha,
7082 goto continue_next_nt;
7086 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7087 if (ret == QLA_ERROR)
7097 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7100 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7101 struct list_head *list_nt,
7104 struct dev_db_entry *fw_ddb_entry;
7105 dma_addr_t fw_ddb_dma;
7109 uint32_t idx = 0, next_idx = 0;
7110 uint32_t state = 0, conn_err = 0;
7111 uint16_t conn_id = 0;
7112 struct qla_ddb_index *nt_ddb_idx;
7114 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7116 if (fw_ddb_entry == NULL) {
7117 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7118 goto exit_new_nt_list;
7120 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7122 fw_idx_size = sizeof(struct qla_ddb_index);
7124 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7125 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7126 NULL, &next_idx, &state,
7127 &conn_err, NULL, &conn_id);
7128 if (ret == QLA_ERROR)
7131 /* Check if NT, then add it to list */
7132 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7133 goto continue_next_new_nt;
7135 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7136 goto continue_next_new_nt;
7138 DEBUG2(ql4_printk(KERN_INFO, ha,
7139 "Adding DDB to session = 0x%x\n", idx));
7141 nt_ddb_idx = vmalloc(fw_idx_size);
7145 nt_ddb_idx->fw_ddb_idx = idx;
7147 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7148 if (ret == QLA_SUCCESS) {
7149 /* free nt_ddb_idx and do not add to list_nt */
7151 goto continue_next_new_nt;
7154 if (target_id < max_ddbs)
7155 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7157 list_add_tail(&nt_ddb_idx->list, list_nt);
7159 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7161 if (ret == QLA_ERROR)
7162 goto exit_new_nt_list;
7164 continue_next_new_nt:
7171 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7175 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7176 * @dev: dev associated with the sysfs entry
7177 * @data: pointer to flashnode session object
7180 * 1: if flashnode entry is non-persistent
7181 * 0: if flashnode entry is persistent
7183 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7185 struct iscsi_bus_flash_session *fnode_sess;
7187 if (!iscsi_flashnode_bus_match(dev, NULL))
7190 fnode_sess = iscsi_dev_to_flash_session(dev);
7192 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7196 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7197 * @ha: pointer to host
7198 * @fw_ddb_entry: flash ddb data
7199 * @idx: target index
7200 * @user: if set then this call is made from userland else from kernel
7203 * On sucess: QLA_SUCCESS
7204 * On failure: QLA_ERROR
7206 * This create separate sysfs entries for session and connection attributes of
7207 * the given fw ddb entry.
7208 * If this is invoked as a result of a userspace call then the entry is marked
7209 * as nonpersistent using flash_state field.
7211 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7212 struct dev_db_entry *fw_ddb_entry,
7213 uint16_t *idx, int user)
7215 struct iscsi_bus_flash_session *fnode_sess = NULL;
7216 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7219 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7220 &qla4xxx_iscsi_transport, 0);
7222 ql4_printk(KERN_ERR, ha,
7223 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7224 __func__, *idx, ha->host_no);
7225 goto exit_tgt_create;
7228 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7229 &qla4xxx_iscsi_transport, 0);
7231 ql4_printk(KERN_ERR, ha,
7232 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7233 __func__, *idx, ha->host_no);
7238 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7240 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7242 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7243 fnode_sess->is_boot_target = 1;
7245 fnode_sess->is_boot_target = 0;
7248 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7253 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7254 __func__, fnode_sess->dev.kobj.name);
7256 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7257 __func__, fnode_conn->dev.kobj.name);
7262 iscsi_destroy_flashnode_sess(fnode_sess);
7269 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7270 * @shost: pointer to host
7271 * @buf: type of ddb entry (ipv4/ipv6)
7272 * @len: length of buf
7274 * This creates new ddb entry in the flash by finding first free index and
7275 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7277 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7280 struct scsi_qla_host *ha = to_qla_host(shost);
7281 struct dev_db_entry *fw_ddb_entry = NULL;
7282 dma_addr_t fw_ddb_entry_dma;
7285 uint16_t max_ddbs = 0;
7286 uint32_t options = 0;
7287 uint32_t rval = QLA_ERROR;
7289 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7290 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7291 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7296 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7299 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7300 &fw_ddb_entry_dma, GFP_KERNEL);
7301 if (!fw_ddb_entry) {
7302 DEBUG2(ql4_printk(KERN_ERR, ha,
7303 "%s: Unable to allocate dma buffer\n",
7308 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7309 qla4xxx_sysfs_ddb_is_non_persistent);
7311 ql4_printk(KERN_ERR, ha,
7312 "%s: A non-persistent entry %s found\n",
7313 __func__, dev->kobj.name);
7318 /* Index 0 and 1 are reserved for boot target entries */
7319 for (idx = 2; idx < max_ddbs; idx++) {
7320 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7321 fw_ddb_entry_dma, idx))
7325 if (idx == max_ddbs)
7328 if (!strncasecmp("ipv6", buf, 4))
7329 options |= IPV6_DEFAULT_DDB_ENTRY;
7331 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7332 if (rval == QLA_ERROR)
7335 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7339 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7340 fw_ddb_entry, fw_ddb_entry_dma);
7341 if (rval == QLA_SUCCESS)
7348 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7349 * @fnode_sess: pointer to session attrs of flash ddb entry
7350 * @fnode_conn: pointer to connection attrs of flash ddb entry
7352 * This writes the contents of target ddb buffer to Flash with a valid cookie
7353 * value in order to make the ddb entry persistent.
7355 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7356 struct iscsi_bus_flash_conn *fnode_conn)
7358 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7359 struct scsi_qla_host *ha = to_qla_host(shost);
7360 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7361 struct dev_db_entry *fw_ddb_entry = NULL;
7362 dma_addr_t fw_ddb_entry_dma;
7363 uint32_t options = 0;
7366 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7367 &fw_ddb_entry_dma, GFP_KERNEL);
7368 if (!fw_ddb_entry) {
7369 DEBUG2(ql4_printk(KERN_ERR, ha,
7370 "%s: Unable to allocate dma buffer\n",
7373 goto exit_ddb_apply;
7376 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7377 options |= IPV6_DEFAULT_DDB_ENTRY;
7379 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7380 if (rval == QLA_ERROR)
7381 goto exit_ddb_apply;
7383 dev_db_start_offset += (fnode_sess->target_id *
7384 sizeof(*fw_ddb_entry));
7386 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7387 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7389 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7390 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7392 if (rval == QLA_SUCCESS) {
7393 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7394 ql4_printk(KERN_INFO, ha,
7395 "%s: flash node %u of host %lu written to flash\n",
7396 __func__, fnode_sess->target_id, ha->host_no);
7399 ql4_printk(KERN_ERR, ha,
7400 "%s: Error while writing flash node %u of host %lu to flash\n",
7401 __func__, fnode_sess->target_id, ha->host_no);
7406 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7407 fw_ddb_entry, fw_ddb_entry_dma);
7411 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7412 struct dev_db_entry *fw_ddb_entry,
7415 struct dev_db_entry *ddb_entry = NULL;
7416 dma_addr_t ddb_entry_dma;
7417 unsigned long wtime;
7418 uint32_t mbx_sts = 0;
7419 uint32_t state = 0, conn_err = 0;
7423 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7424 &ddb_entry_dma, GFP_KERNEL);
7426 DEBUG2(ql4_printk(KERN_ERR, ha,
7427 "%s: Unable to allocate dma buffer\n",
7432 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7434 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7435 if (ret != QLA_SUCCESS) {
7436 DEBUG2(ql4_printk(KERN_ERR, ha,
7437 "%s: Unable to set ddb entry for index %d\n",
7439 goto exit_ddb_conn_open;
7442 qla4xxx_conn_open(ha, idx);
7444 /* To ensure that sendtargets is done, wait for at least 12 secs */
7445 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7446 (ha->def_timeout < LOGIN_TOV * 10) ?
7447 ha->def_timeout : LOGIN_TOV);
7449 DEBUG2(ql4_printk(KERN_INFO, ha,
7450 "Default time to wait for login to ddb %d\n", tmo));
7452 wtime = jiffies + (HZ * tmo);
7454 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7455 NULL, &state, &conn_err, NULL,
7457 if (ret == QLA_ERROR)
7460 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7461 state == DDB_DS_SESSION_FAILED)
7464 schedule_timeout_uninterruptible(HZ / 10);
7465 } while (time_after(wtime, jiffies));
7469 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7470 ddb_entry, ddb_entry_dma);
7474 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7475 struct dev_db_entry *fw_ddb_entry,
7478 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7479 struct list_head list_nt;
7483 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7484 ql4_printk(KERN_WARNING, ha,
7485 "%s: A discovery already in progress!\n", __func__);
7489 INIT_LIST_HEAD(&list_nt);
7491 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7493 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7494 if (ret == QLA_ERROR)
7495 goto exit_login_st_clr_bit;
7497 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7498 if (ret == QLA_ERROR)
7501 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7503 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7504 list_del_init(&ddb_idx->list);
7505 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7510 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7511 ql4_printk(KERN_ERR, ha,
7512 "Unable to clear DDB index = 0x%x\n", ddb_index);
7515 clear_bit(ddb_index, ha->ddb_idx_map);
7517 exit_login_st_clr_bit:
7518 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7522 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7523 struct dev_db_entry *fw_ddb_entry,
7526 int ret = QLA_ERROR;
7528 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7529 if (ret != QLA_SUCCESS)
7530 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7539 * qla4xxx_sysfs_ddb_login - Login to the specified target
7540 * @fnode_sess: pointer to session attrs of flash ddb entry
7541 * @fnode_conn: pointer to connection attrs of flash ddb entry
7543 * This logs in to the specified target
7545 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7546 struct iscsi_bus_flash_conn *fnode_conn)
7548 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7549 struct scsi_qla_host *ha = to_qla_host(shost);
7550 struct dev_db_entry *fw_ddb_entry = NULL;
7551 dma_addr_t fw_ddb_entry_dma;
7552 uint32_t options = 0;
7555 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7556 ql4_printk(KERN_ERR, ha,
7557 "%s: Target info is not persistent\n", __func__);
7559 goto exit_ddb_login;
7562 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7563 &fw_ddb_entry_dma, GFP_KERNEL);
7564 if (!fw_ddb_entry) {
7565 DEBUG2(ql4_printk(KERN_ERR, ha,
7566 "%s: Unable to allocate dma buffer\n",
7569 goto exit_ddb_login;
7572 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7573 options |= IPV6_DEFAULT_DDB_ENTRY;
7575 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7576 if (ret == QLA_ERROR)
7577 goto exit_ddb_login;
7579 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7580 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7582 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7583 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7584 fnode_sess->target_id);
7586 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7587 fnode_sess->target_id);
7594 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7595 fw_ddb_entry, fw_ddb_entry_dma);
7600 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7601 * @cls_sess: pointer to session to be logged out
7603 * This performs session log out from the specified target
7605 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7607 struct iscsi_session *sess;
7608 struct ddb_entry *ddb_entry = NULL;
7609 struct scsi_qla_host *ha;
7610 struct dev_db_entry *fw_ddb_entry = NULL;
7611 dma_addr_t fw_ddb_entry_dma;
7612 unsigned long flags;
7613 unsigned long wtime;
7618 sess = cls_sess->dd_data;
7619 ddb_entry = sess->dd_data;
7622 if (ddb_entry->ddb_type != FLASH_DDB) {
7623 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7626 goto exit_ddb_logout;
7629 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7630 ql4_printk(KERN_ERR, ha,
7631 "%s: Logout from boot target entry is not permitted.\n",
7634 goto exit_ddb_logout;
7637 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7638 &fw_ddb_entry_dma, GFP_KERNEL);
7639 if (!fw_ddb_entry) {
7640 ql4_printk(KERN_ERR, ha,
7641 "%s: Unable to allocate dma buffer\n", __func__);
7643 goto exit_ddb_logout;
7646 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7647 goto ddb_logout_init;
7649 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7650 fw_ddb_entry, fw_ddb_entry_dma,
7651 NULL, NULL, &ddb_state, NULL,
7653 if (ret == QLA_ERROR)
7654 goto ddb_logout_init;
7656 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7657 goto ddb_logout_init;
7659 /* wait until next relogin is triggered using DF_RELOGIN and
7660 * clear DF_RELOGIN to avoid invocation of further relogin
7662 wtime = jiffies + (HZ * RELOGIN_TOV);
7664 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7665 goto ddb_logout_init;
7667 schedule_timeout_uninterruptible(HZ);
7668 } while ((time_after(wtime, jiffies)));
7671 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7672 atomic_set(&ddb_entry->relogin_timer, 0);
7674 options = LOGOUT_OPTION_CLOSE_SESSION;
7675 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7677 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7678 wtime = jiffies + (HZ * LOGOUT_TOV);
7680 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7681 fw_ddb_entry, fw_ddb_entry_dma,
7682 NULL, NULL, &ddb_state, NULL,
7684 if (ret == QLA_ERROR)
7685 goto ddb_logout_clr_sess;
7687 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7688 (ddb_state == DDB_DS_SESSION_FAILED))
7689 goto ddb_logout_clr_sess;
7691 schedule_timeout_uninterruptible(HZ);
7692 } while ((time_after(wtime, jiffies)));
7694 ddb_logout_clr_sess:
7695 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7697 * we have decremented the reference count of the driver
7698 * when we setup the session to have the driver unload
7699 * to be seamless without actually destroying the
7702 try_module_get(qla4xxx_iscsi_transport.owner);
7703 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7705 spin_lock_irqsave(&ha->hardware_lock, flags);
7706 qla4xxx_free_ddb(ha, ddb_entry);
7707 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7708 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7710 iscsi_session_teardown(ddb_entry->sess);
7712 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7717 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7718 fw_ddb_entry, fw_ddb_entry_dma);
7723 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7724 * @fnode_sess: pointer to session attrs of flash ddb entry
7725 * @fnode_conn: pointer to connection attrs of flash ddb entry
7727 * This performs log out from the specified target
7729 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7730 struct iscsi_bus_flash_conn *fnode_conn)
7732 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7733 struct scsi_qla_host *ha = to_qla_host(shost);
7734 struct ql4_tuple_ddb *flash_tddb = NULL;
7735 struct ql4_tuple_ddb *tmp_tddb = NULL;
7736 struct dev_db_entry *fw_ddb_entry = NULL;
7737 struct ddb_entry *ddb_entry = NULL;
7738 dma_addr_t fw_ddb_dma;
7739 uint32_t next_idx = 0;
7740 uint32_t state = 0, conn_err = 0;
7741 uint16_t conn_id = 0;
7743 int status, ret = 0;
7745 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7747 if (fw_ddb_entry == NULL) {
7748 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7750 goto exit_ddb_logout;
7753 flash_tddb = vzalloc(sizeof(*flash_tddb));
7755 ql4_printk(KERN_WARNING, ha,
7756 "%s:Memory Allocation failed.\n", __func__);
7758 goto exit_ddb_logout;
7761 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7763 ql4_printk(KERN_WARNING, ha,
7764 "%s:Memory Allocation failed.\n", __func__);
7766 goto exit_ddb_logout;
7769 if (!fnode_sess->targetname) {
7770 ql4_printk(KERN_ERR, ha,
7771 "%s:Cannot logout from SendTarget entry\n",
7774 goto exit_ddb_logout;
7777 if (fnode_sess->is_boot_target) {
7778 ql4_printk(KERN_ERR, ha,
7779 "%s: Logout from boot target entry is not permitted.\n",
7782 goto exit_ddb_logout;
7785 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7788 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7789 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7791 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7793 flash_tddb->tpgt = fnode_sess->tpgt;
7794 flash_tddb->port = fnode_conn->port;
7796 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7798 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7799 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7800 if (ddb_entry == NULL)
7803 if (ddb_entry->ddb_type != FLASH_DDB)
7806 index = ddb_entry->sess->target_id;
7807 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7808 fw_ddb_dma, NULL, &next_idx,
7809 &state, &conn_err, NULL,
7811 if (status == QLA_ERROR) {
7816 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7818 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7820 if (status == QLA_SUCCESS) {
7821 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7826 if (idx == MAX_DDB_ENTRIES)
7833 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7839 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7840 int param, char *buf)
7842 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7843 struct scsi_qla_host *ha = to_qla_host(shost);
7844 struct iscsi_bus_flash_conn *fnode_conn;
7845 struct ql4_chap_table chap_tbl;
7850 dev = iscsi_find_flashnode_conn(fnode_sess);
7854 fnode_conn = iscsi_dev_to_flash_conn(dev);
7857 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7858 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7860 case ISCSI_FLASHNODE_PORTAL_TYPE:
7861 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7863 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7864 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7866 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7867 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7869 case ISCSI_FLASHNODE_ENTRY_EN:
7870 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7872 case ISCSI_FLASHNODE_HDR_DGST_EN:
7873 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7875 case ISCSI_FLASHNODE_DATA_DGST_EN:
7876 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7878 case ISCSI_FLASHNODE_IMM_DATA_EN:
7879 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7881 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7882 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7884 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7885 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7887 case ISCSI_FLASHNODE_PDU_INORDER:
7888 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7890 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7891 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7893 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7894 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7896 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7897 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7899 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7900 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7902 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7903 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7905 case ISCSI_FLASHNODE_ERL:
7906 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7908 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7909 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7911 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7912 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7914 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7915 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7917 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7918 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7920 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7921 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7923 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7924 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7926 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7927 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7929 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7930 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7932 case ISCSI_FLASHNODE_FIRST_BURST:
7933 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7935 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7936 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7938 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7939 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7941 case ISCSI_FLASHNODE_MAX_R2T:
7942 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7944 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7945 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7947 case ISCSI_FLASHNODE_ISID:
7948 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7950 case ISCSI_FLASHNODE_TSID:
7951 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7953 case ISCSI_FLASHNODE_PORT:
7954 rc = sprintf(buf, "%d\n", fnode_conn->port);
7956 case ISCSI_FLASHNODE_MAX_BURST:
7957 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7959 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7960 rc = sprintf(buf, "%u\n",
7961 fnode_sess->default_taskmgmt_timeout);
7963 case ISCSI_FLASHNODE_IPADDR:
7964 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7965 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7967 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7969 case ISCSI_FLASHNODE_ALIAS:
7970 if (fnode_sess->targetalias)
7971 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7973 rc = sprintf(buf, "\n");
7975 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7976 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7977 rc = sprintf(buf, "%pI6\n",
7978 fnode_conn->redirect_ipaddr);
7980 rc = sprintf(buf, "%pI4\n",
7981 fnode_conn->redirect_ipaddr);
7983 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7984 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7986 case ISCSI_FLASHNODE_LOCAL_PORT:
7987 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7989 case ISCSI_FLASHNODE_IPV4_TOS:
7990 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7992 case ISCSI_FLASHNODE_IPV6_TC:
7993 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7994 rc = sprintf(buf, "%u\n",
7995 fnode_conn->ipv6_traffic_class);
7997 rc = sprintf(buf, "\n");
7999 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8000 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8002 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8003 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8004 rc = sprintf(buf, "%pI6\n",
8005 fnode_conn->link_local_ipv6_addr);
8007 rc = sprintf(buf, "\n");
8009 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8010 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8012 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8013 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8014 parent_type = ISCSI_DISC_PARENT_ISNS;
8015 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8016 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8017 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8018 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8020 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8022 rc = sprintf(buf, "%s\n",
8023 iscsi_get_discovery_parent_name(parent_type));
8025 case ISCSI_FLASHNODE_NAME:
8026 if (fnode_sess->targetname)
8027 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8029 rc = sprintf(buf, "\n");
8031 case ISCSI_FLASHNODE_TPGT:
8032 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8034 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8035 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8037 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8038 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8040 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8041 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8043 case ISCSI_FLASHNODE_USERNAME:
8044 if (fnode_sess->chap_auth_en) {
8045 qla4xxx_get_uni_chap_at_index(ha,
8048 fnode_sess->chap_out_idx);
8049 rc = sprintf(buf, "%s\n", chap_tbl.name);
8051 rc = sprintf(buf, "\n");
8054 case ISCSI_FLASHNODE_PASSWORD:
8055 if (fnode_sess->chap_auth_en) {
8056 qla4xxx_get_uni_chap_at_index(ha,
8059 fnode_sess->chap_out_idx);
8060 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8062 rc = sprintf(buf, "\n");
8065 case ISCSI_FLASHNODE_STATSN:
8066 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8068 case ISCSI_FLASHNODE_EXP_STATSN:
8069 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8071 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8072 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8084 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8085 * @fnode_sess: pointer to session attrs of flash ddb entry
8086 * @fnode_conn: pointer to connection attrs of flash ddb entry
8087 * @data: Parameters and their values to update
8090 * This sets the parameter of flash ddb entry and writes them to flash
8093 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8094 struct iscsi_bus_flash_conn *fnode_conn,
8095 void *data, int len)
8097 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8098 struct scsi_qla_host *ha = to_qla_host(shost);
8099 struct iscsi_flashnode_param_info *fnode_param;
8100 struct ql4_chap_table chap_tbl;
8101 struct nlattr *attr;
8102 uint16_t chap_out_idx = INVALID_ENTRY;
8106 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8107 nla_for_each_attr(attr, data, len, rem) {
8108 fnode_param = nla_data(attr);
8110 switch (fnode_param->param) {
8111 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8112 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8114 case ISCSI_FLASHNODE_PORTAL_TYPE:
8115 memcpy(fnode_sess->portal_type, fnode_param->value,
8116 strlen(fnode_sess->portal_type));
8118 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8119 fnode_sess->auto_snd_tgt_disable =
8120 fnode_param->value[0];
8122 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8123 fnode_sess->discovery_sess = fnode_param->value[0];
8125 case ISCSI_FLASHNODE_ENTRY_EN:
8126 fnode_sess->entry_state = fnode_param->value[0];
8128 case ISCSI_FLASHNODE_HDR_DGST_EN:
8129 fnode_conn->hdrdgst_en = fnode_param->value[0];
8131 case ISCSI_FLASHNODE_DATA_DGST_EN:
8132 fnode_conn->datadgst_en = fnode_param->value[0];
8134 case ISCSI_FLASHNODE_IMM_DATA_EN:
8135 fnode_sess->imm_data_en = fnode_param->value[0];
8137 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8138 fnode_sess->initial_r2t_en = fnode_param->value[0];
8140 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8141 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8143 case ISCSI_FLASHNODE_PDU_INORDER:
8144 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8146 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8147 fnode_sess->chap_auth_en = fnode_param->value[0];
8148 /* Invalidate chap index if chap auth is disabled */
8149 if (!fnode_sess->chap_auth_en)
8150 fnode_sess->chap_out_idx = INVALID_ENTRY;
8153 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8154 fnode_conn->snack_req_en = fnode_param->value[0];
8156 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8157 fnode_sess->discovery_logout_en = fnode_param->value[0];
8159 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8160 fnode_sess->bidi_chap_en = fnode_param->value[0];
8162 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8163 fnode_sess->discovery_auth_optional =
8164 fnode_param->value[0];
8166 case ISCSI_FLASHNODE_ERL:
8167 fnode_sess->erl = fnode_param->value[0];
8169 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8170 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8172 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8173 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8175 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8176 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8178 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8179 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8181 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8182 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8184 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8185 fnode_conn->fragment_disable = fnode_param->value[0];
8187 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8188 fnode_conn->max_recv_dlength =
8189 *(unsigned *)fnode_param->value;
8191 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8192 fnode_conn->max_xmit_dlength =
8193 *(unsigned *)fnode_param->value;
8195 case ISCSI_FLASHNODE_FIRST_BURST:
8196 fnode_sess->first_burst =
8197 *(unsigned *)fnode_param->value;
8199 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8200 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8202 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8203 fnode_sess->time2retain =
8204 *(uint16_t *)fnode_param->value;
8206 case ISCSI_FLASHNODE_MAX_R2T:
8207 fnode_sess->max_r2t =
8208 *(uint16_t *)fnode_param->value;
8210 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8211 fnode_conn->keepalive_timeout =
8212 *(uint16_t *)fnode_param->value;
8214 case ISCSI_FLASHNODE_ISID:
8215 memcpy(fnode_sess->isid, fnode_param->value,
8216 sizeof(fnode_sess->isid));
8218 case ISCSI_FLASHNODE_TSID:
8219 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8221 case ISCSI_FLASHNODE_PORT:
8222 fnode_conn->port = *(uint16_t *)fnode_param->value;
8224 case ISCSI_FLASHNODE_MAX_BURST:
8225 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8227 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8228 fnode_sess->default_taskmgmt_timeout =
8229 *(uint16_t *)fnode_param->value;
8231 case ISCSI_FLASHNODE_IPADDR:
8232 memcpy(fnode_conn->ipaddress, fnode_param->value,
8235 case ISCSI_FLASHNODE_ALIAS:
8236 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8237 (char *)fnode_param->value);
8239 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8240 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8243 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8244 fnode_conn->max_segment_size =
8245 *(unsigned *)fnode_param->value;
8247 case ISCSI_FLASHNODE_LOCAL_PORT:
8248 fnode_conn->local_port =
8249 *(uint16_t *)fnode_param->value;
8251 case ISCSI_FLASHNODE_IPV4_TOS:
8252 fnode_conn->ipv4_tos = fnode_param->value[0];
8254 case ISCSI_FLASHNODE_IPV6_TC:
8255 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8257 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8258 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8260 case ISCSI_FLASHNODE_NAME:
8261 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8262 (char *)fnode_param->value);
8264 case ISCSI_FLASHNODE_TPGT:
8265 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8267 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8268 memcpy(fnode_conn->link_local_ipv6_addr,
8269 fnode_param->value, IPv6_ADDR_LEN);
8271 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8272 fnode_sess->discovery_parent_idx =
8273 *(uint16_t *)fnode_param->value;
8275 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8276 fnode_conn->tcp_xmit_wsf =
8277 *(uint8_t *)fnode_param->value;
8279 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8280 fnode_conn->tcp_recv_wsf =
8281 *(uint8_t *)fnode_param->value;
8283 case ISCSI_FLASHNODE_STATSN:
8284 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8286 case ISCSI_FLASHNODE_EXP_STATSN:
8287 fnode_conn->exp_statsn =
8288 *(uint32_t *)fnode_param->value;
8290 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8291 chap_out_idx = *(uint16_t *)fnode_param->value;
8292 if (!qla4xxx_get_uni_chap_at_index(ha,
8296 fnode_sess->chap_out_idx = chap_out_idx;
8297 /* Enable chap auth if chap index is valid */
8298 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8302 ql4_printk(KERN_ERR, ha,
8303 "%s: No such sysfs attribute\n", __func__);
8305 goto exit_set_param;
8309 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8316 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8317 * @fnode_sess: pointer to session attrs of flash ddb entry
8319 * This invalidates the flash ddb entry at the given index
8321 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8323 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8324 struct scsi_qla_host *ha = to_qla_host(shost);
8325 uint32_t dev_db_start_offset;
8326 uint32_t dev_db_end_offset;
8327 struct dev_db_entry *fw_ddb_entry = NULL;
8328 dma_addr_t fw_ddb_entry_dma;
8329 uint16_t *ddb_cookie = NULL;
8330 size_t ddb_size = 0;
8335 if (fnode_sess->is_boot_target) {
8337 DEBUG2(ql4_printk(KERN_ERR, ha,
8338 "%s: Deletion of boot target entry is not permitted.\n",
8343 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8346 if (is_qla40XX(ha)) {
8347 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8348 dev_db_end_offset = FLASH_OFFSET_DB_END;
8349 dev_db_start_offset += (fnode_sess->target_id *
8350 sizeof(*fw_ddb_entry));
8351 ddb_size = sizeof(*fw_ddb_entry);
8353 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8354 (ha->hw.flt_region_ddb << 2);
8355 /* flt_ddb_size is DDB table size for both ports
8356 * so divide it by 2 to calculate the offset for second port
8358 if (ha->port_num == 1)
8359 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8361 dev_db_end_offset = dev_db_start_offset +
8362 (ha->hw.flt_ddb_size / 2);
8364 dev_db_start_offset += (fnode_sess->target_id *
8365 sizeof(*fw_ddb_entry));
8366 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8368 ddb_size = sizeof(*ddb_cookie);
8371 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8372 __func__, dev_db_start_offset, dev_db_end_offset));
8374 if (dev_db_start_offset > dev_db_end_offset) {
8376 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8377 __func__, fnode_sess->target_id));
8381 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8382 &fw_ddb_entry_dma, GFP_KERNEL);
8385 DEBUG2(ql4_printk(KERN_ERR, ha,
8386 "%s: Unable to allocate dma buffer\n",
8391 if (is_qla40XX(ha)) {
8392 fw_ddb_entry = pddb;
8393 memset(fw_ddb_entry, 0, ddb_size);
8394 ddb_cookie = &fw_ddb_entry->cookie;
8399 /* invalidate the cookie */
8400 *ddb_cookie = 0xFFEE;
8401 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8402 ddb_size, FLASH_OPT_RMW_COMMIT);
8405 target_id = fnode_sess->target_id;
8406 iscsi_destroy_flashnode_sess(fnode_sess);
8407 ql4_printk(KERN_INFO, ha,
8408 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8409 __func__, target_id, ha->host_no);
8412 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8418 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8419 * @ha: pointer to adapter structure
8421 * Export the firmware DDB for all send targets and normal targets to sysfs.
8423 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8425 struct dev_db_entry *fw_ddb_entry = NULL;
8426 dma_addr_t fw_ddb_entry_dma;
8429 int ret = QLA_SUCCESS;
8431 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8432 sizeof(*fw_ddb_entry),
8433 &fw_ddb_entry_dma, GFP_KERNEL);
8434 if (!fw_ddb_entry) {
8435 DEBUG2(ql4_printk(KERN_ERR, ha,
8436 "%s: Unable to allocate dma buffer\n",
8441 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8444 for (idx = 0; idx < max_ddbs; idx++) {
8445 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8449 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8456 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8462 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8464 iscsi_destroy_all_flashnode(ha->host);
8468 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8469 * @ha: pointer to adapter structure
8470 * @is_reset: Is this init path or reset path
8472 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8473 * using connection open, then create the list of normal targets (nt)
8474 * from firmware DDBs. Based on the list of nt setup session and connection
8477 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8480 struct list_head list_st, list_nt;
8481 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8482 unsigned long wtime;
8484 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8485 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8486 ha->is_reset = is_reset;
8490 INIT_LIST_HEAD(&list_st);
8491 INIT_LIST_HEAD(&list_nt);
8493 qla4xxx_build_st_list(ha, &list_st);
8495 /* Before issuing conn open mbox, ensure all IPs states are configured
8496 * Note, conn open fails if IPs are not configured
8498 qla4xxx_wait_for_ip_configuration(ha);
8500 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8501 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8502 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8505 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8506 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8507 (ha->def_timeout < LOGIN_TOV * 10) ?
8508 ha->def_timeout : LOGIN_TOV);
8510 DEBUG2(ql4_printk(KERN_INFO, ha,
8511 "Default time to wait for build ddb %d\n", tmo));
8513 wtime = jiffies + (HZ * tmo);
8515 if (list_empty(&list_st))
8518 qla4xxx_remove_failed_ddb(ha, &list_st);
8519 schedule_timeout_uninterruptible(HZ / 10);
8520 } while (time_after(wtime, jiffies));
8523 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8525 qla4xxx_free_ddb_list(&list_st);
8526 qla4xxx_free_ddb_list(&list_nt);
8528 qla4xxx_free_ddb_index(ha);
8532 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8534 * @ha: pointer to adapter structure
8536 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8537 * set in DDB and we will wait for login response of boot targets during
8540 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8542 struct ddb_entry *ddb_entry;
8543 struct dev_db_entry *fw_ddb_entry = NULL;
8544 dma_addr_t fw_ddb_entry_dma;
8545 unsigned long wtime;
8547 int max_ddbs, idx, ret;
8549 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8552 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8553 &fw_ddb_entry_dma, GFP_KERNEL);
8554 if (!fw_ddb_entry) {
8555 ql4_printk(KERN_ERR, ha,
8556 "%s: Unable to allocate dma buffer\n", __func__);
8557 goto exit_login_resp;
8560 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8562 for (idx = 0; idx < max_ddbs; idx++) {
8563 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8564 if (ddb_entry == NULL)
8567 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8568 DEBUG2(ql4_printk(KERN_INFO, ha,
8569 "%s: DDB index [%d]\n", __func__,
8570 ddb_entry->fw_ddb_index));
8572 ret = qla4xxx_get_fwddb_entry(ha,
8573 ddb_entry->fw_ddb_index,
8574 fw_ddb_entry, fw_ddb_entry_dma,
8575 NULL, NULL, &ddb_state, NULL,
8577 if (ret == QLA_ERROR)
8578 goto exit_login_resp;
8580 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8581 (ddb_state == DDB_DS_SESSION_FAILED))
8584 schedule_timeout_uninterruptible(HZ);
8586 } while ((time_after(wtime, jiffies)));
8588 if (!time_after(wtime, jiffies)) {
8589 DEBUG2(ql4_printk(KERN_INFO, ha,
8590 "%s: Login response wait timer expired\n",
8592 goto exit_login_resp;
8599 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8600 fw_ddb_entry, fw_ddb_entry_dma);
8604 * qla4xxx_probe_adapter - callback function to probe HBA
8605 * @pdev: pointer to pci_dev structure
8606 * @ent: pointer to pci_device entry
8608 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8609 * It returns zero if successful. It also initializes all data necessary for
8612 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8613 const struct pci_device_id *ent)
8615 int ret = -ENODEV, status;
8616 struct Scsi_Host *host;
8617 struct scsi_qla_host *ha;
8618 uint8_t init_retry_count = 0;
8620 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8623 if (pci_enable_device(pdev))
8626 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8629 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8630 goto probe_disable_device;
8633 /* Clear our data area */
8634 ha = to_qla_host(host);
8635 memset(ha, 0, sizeof(*ha));
8637 /* Save the information from PCI BIOS. */
8640 ha->host_no = host->host_no;
8641 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8643 pci_enable_pcie_error_reporting(pdev);
8645 /* Setup Runtime configurable options */
8646 if (is_qla8022(ha)) {
8647 ha->isp_ops = &qla4_82xx_isp_ops;
8648 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8649 ha->qdr_sn_window = -1;
8650 ha->ddr_mn_window = -1;
8651 ha->curr_window = 255;
8652 nx_legacy_intr = &legacy_intr[ha->func_num];
8653 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8654 ha->nx_legacy_intr.tgt_status_reg =
8655 nx_legacy_intr->tgt_status_reg;
8656 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8657 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8658 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8659 ha->isp_ops = &qla4_83xx_isp_ops;
8660 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8662 ha->isp_ops = &qla4xxx_isp_ops;
8665 if (is_qla80XX(ha)) {
8666 rwlock_init(&ha->hw_lock);
8667 ha->pf_bit = ha->func_num << 16;
8668 /* Set EEH reset type to fundamental if required by hba */
8669 pdev->needs_freset = 1;
8672 /* Configure PCI I/O space. */
8673 ret = ha->isp_ops->iospace_config(ha);
8675 goto probe_failed_ioconfig;
8677 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8678 pdev->device, pdev->irq, ha->reg);
8680 qla4xxx_config_dma_addressing(ha);
8682 /* Initialize lists and spinlocks. */
8683 INIT_LIST_HEAD(&ha->free_srb_q);
8685 mutex_init(&ha->mbox_sem);
8686 mutex_init(&ha->chap_sem);
8687 init_completion(&ha->mbx_intr_comp);
8688 init_completion(&ha->disable_acb_comp);
8689 init_completion(&ha->idc_comp);
8690 init_completion(&ha->link_up_comp);
8692 spin_lock_init(&ha->hardware_lock);
8693 spin_lock_init(&ha->work_lock);
8695 /* Initialize work list */
8696 INIT_LIST_HEAD(&ha->work_list);
8698 /* Allocate dma buffers */
8699 if (qla4xxx_mem_alloc(ha)) {
8700 ql4_printk(KERN_WARNING, ha,
8701 "[ERROR] Failed to allocate memory for adapter\n");
8707 host->cmd_per_lun = 3;
8708 host->max_channel = 0;
8709 host->max_lun = MAX_LUNS - 1;
8710 host->max_id = MAX_TARGETS;
8711 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8712 host->can_queue = MAX_SRBS ;
8713 host->transportt = qla4xxx_scsi_transport;
8715 pci_set_drvdata(pdev, ha);
8717 ret = scsi_add_host(host, &pdev->dev);
8722 qla4_8xxx_get_flash_info(ha);
8724 if (is_qla8032(ha) || is_qla8042(ha)) {
8725 qla4_83xx_read_reset_template(ha);
8727 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8728 * If DONRESET_BIT0 is set, drivers should not set dev_state
8729 * to NEED_RESET. But if NEED_RESET is set, drivers should
8730 * should honor the reset.
8732 if (ql4xdontresethba == 1)
8733 qla4_83xx_set_idc_dontreset(ha);
8737 * Initialize the Host adapter request/response queues and
8739 * NOTE: interrupts enabled upon successful completion
8741 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8743 /* Dont retry adapter initialization if IRQ allocation failed */
8744 if (is_qla80XX(ha) && (status == QLA_ERROR))
8745 goto skip_retry_init;
8747 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8748 init_retry_count++ < MAX_INIT_RETRIES) {
8750 if (is_qla80XX(ha)) {
8751 ha->isp_ops->idc_lock(ha);
8752 dev_state = qla4_8xxx_rd_direct(ha,
8753 QLA8XXX_CRB_DEV_STATE);
8754 ha->isp_ops->idc_unlock(ha);
8755 if (dev_state == QLA8XXX_DEV_FAILED) {
8756 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8757 "initialize adapter. H/W is in failed state\n",
8762 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8763 "(%d)\n", __func__, init_retry_count));
8765 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8768 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8769 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8770 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8771 goto skip_retry_init;
8776 if (!test_bit(AF_ONLINE, &ha->flags)) {
8777 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8779 if ((is_qla8022(ha) && ql4xdontresethba) ||
8780 ((is_qla8032(ha) || is_qla8042(ha)) &&
8781 qla4_83xx_idc_dontreset(ha))) {
8782 /* Put the device in failed state. */
8783 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8784 ha->isp_ops->idc_lock(ha);
8785 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8786 QLA8XXX_DEV_FAILED);
8787 ha->isp_ops->idc_unlock(ha);
8793 /* Startup the kernel thread for this host adapter. */
8794 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8795 "qla4xxx_dpc\n", __func__));
8796 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8797 ha->dpc_thread = create_singlethread_workqueue(buf);
8798 if (!ha->dpc_thread) {
8799 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8803 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8805 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8808 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8814 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8815 * (which is called indirectly by qla4xxx_initialize_adapter),
8816 * so that irqs will be registered after crbinit but before
8819 if (is_qla40XX(ha)) {
8820 ret = qla4xxx_request_irqs(ha);
8822 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8823 "interrupt %d already in use.\n", pdev->irq);
8828 pci_save_state(ha->pdev);
8829 ha->isp_ops->enable_intrs(ha);
8831 /* Start timer thread. */
8832 qla4xxx_start_timer(ha, 1);
8834 set_bit(AF_INIT_DONE, &ha->flags);
8836 qla4_8xxx_alloc_sysfs_attr(ha);
8839 " QLogic iSCSI HBA Driver version: %s\n"
8840 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8841 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8842 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8843 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8845 /* Set the driver version */
8847 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8849 if (qla4xxx_setup_boot_info(ha))
8850 ql4_printk(KERN_ERR, ha,
8851 "%s: No iSCSI boot target configured\n", __func__);
8853 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8854 /* Perform the build ddb list and login to each */
8855 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8856 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8857 qla4xxx_wait_login_resp_boot_tgt(ha);
8859 qla4xxx_create_chap_list(ha);
8861 qla4xxx_create_ifaces(ha);
8865 scsi_remove_host(ha->host);
8868 qla4xxx_free_adapter(ha);
8870 probe_failed_ioconfig:
8871 pci_disable_pcie_error_reporting(pdev);
8872 scsi_host_put(ha->host);
8874 probe_disable_device:
8875 pci_disable_device(pdev);
8881 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8882 * @ha: pointer to adapter structure
8884 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8885 * so that the other port will not re-initialize while in the process of
8886 * removing the ha due to driver unload or hba hotplug.
8888 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8890 struct scsi_qla_host *other_ha = NULL;
8891 struct pci_dev *other_pdev = NULL;
8892 int fn = ISP4XXX_PCI_FN_2;
8894 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8895 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8896 fn = ISP4XXX_PCI_FN_1;
8899 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8900 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8903 /* Get other_ha if other_pdev is valid and state is enable*/
8905 if (atomic_read(&other_pdev->enable_cnt)) {
8906 other_ha = pci_get_drvdata(other_pdev);
8908 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8909 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8910 "Prevent %s reinit\n", __func__,
8911 dev_name(&other_ha->pdev->dev)));
8914 pci_dev_put(other_pdev);
8918 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8919 struct ddb_entry *ddb_entry)
8921 struct dev_db_entry *fw_ddb_entry = NULL;
8922 dma_addr_t fw_ddb_entry_dma;
8923 unsigned long wtime;
8928 options = LOGOUT_OPTION_CLOSE_SESSION;
8929 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8930 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8934 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8935 &fw_ddb_entry_dma, GFP_KERNEL);
8936 if (!fw_ddb_entry) {
8937 ql4_printk(KERN_ERR, ha,
8938 "%s: Unable to allocate dma buffer\n", __func__);
8942 wtime = jiffies + (HZ * LOGOUT_TOV);
8944 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8945 fw_ddb_entry, fw_ddb_entry_dma,
8946 NULL, NULL, &ddb_state, NULL,
8948 if (status == QLA_ERROR)
8951 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8952 (ddb_state == DDB_DS_SESSION_FAILED))
8955 schedule_timeout_uninterruptible(HZ);
8956 } while ((time_after(wtime, jiffies)));
8959 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8960 fw_ddb_entry, fw_ddb_entry_dma);
8962 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8965 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8967 struct ddb_entry *ddb_entry;
8970 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8972 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8973 if ((ddb_entry != NULL) &&
8974 (ddb_entry->ddb_type == FLASH_DDB)) {
8976 qla4xxx_destroy_ddb(ha, ddb_entry);
8978 * we have decremented the reference count of the driver
8979 * when we setup the session to have the driver unload
8980 * to be seamless without actually destroying the
8983 try_module_get(qla4xxx_iscsi_transport.owner);
8984 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8985 qla4xxx_free_ddb(ha, ddb_entry);
8986 iscsi_session_teardown(ddb_entry->sess);
8991 * qla4xxx_remove_adapter - callback function to remove adapter.
8992 * @pdev: PCI device pointer
8994 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
8996 struct scsi_qla_host *ha;
8999 * If the PCI device is disabled then it means probe_adapter had
9000 * failed and resources already cleaned up on probe_adapter exit.
9002 if (!pci_is_enabled(pdev))
9005 ha = pci_get_drvdata(pdev);
9008 qla4xxx_prevent_other_port_reinit(ha);
9010 /* destroy iface from sysfs */
9011 qla4xxx_destroy_ifaces(ha);
9013 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9014 iscsi_boot_destroy_kset(ha->boot_kset);
9016 qla4xxx_destroy_fw_ddb_session(ha);
9017 qla4_8xxx_free_sysfs_attr(ha);
9019 qla4xxx_sysfs_ddb_remove(ha);
9020 scsi_remove_host(ha->host);
9022 qla4xxx_free_adapter(ha);
9024 scsi_host_put(ha->host);
9026 pci_disable_pcie_error_reporting(pdev);
9027 pci_disable_device(pdev);
9031 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9034 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9036 /* Update our PCI device dma_mask for full 64 bit mask */
9037 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9038 dev_dbg(&ha->pdev->dev,
9039 "Failed to set 64 bit PCI consistent mask; "
9041 dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9045 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9047 struct iscsi_cls_session *cls_sess;
9048 struct iscsi_session *sess;
9049 struct ddb_entry *ddb;
9050 int queue_depth = QL4_DEF_QDEPTH;
9052 cls_sess = starget_to_session(sdev->sdev_target);
9053 sess = cls_sess->dd_data;
9054 ddb = sess->dd_data;
9056 sdev->hostdata = ddb;
9058 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9059 queue_depth = ql4xmaxqdepth;
9061 scsi_change_queue_depth(sdev, queue_depth);
9066 * qla4xxx_del_from_active_array - returns an active srb
9067 * @ha: Pointer to host adapter structure.
9068 * @index: index into the active_array
9070 * This routine removes and returns the srb at the specified index
9072 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9075 struct srb *srb = NULL;
9076 struct scsi_cmnd *cmd = NULL;
9078 cmd = scsi_host_find_tag(ha->host, index);
9082 srb = (struct srb *)CMD_SP(cmd);
9086 /* update counters */
9087 if (srb->flags & SRB_DMA_VALID) {
9088 ha->iocb_cnt -= srb->iocb_cnt;
9090 srb->cmd->host_scribble =
9091 (unsigned char *)(unsigned long) MAX_SRBS;
9097 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9098 * @ha: Pointer to host adapter structure.
9099 * @cmd: Scsi Command to wait on.
9101 * This routine waits for the command to be returned by the Firmware
9102 * for some max time.
9104 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9105 struct scsi_cmnd *cmd)
9109 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9112 /* Dont wait on command if PCI error is being handled
9115 if (unlikely(pci_channel_offline(ha->pdev)) ||
9116 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9117 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9118 ha->host_no, __func__);
9123 /* Checking to see if its returned to OS */
9124 rp = (struct srb *) CMD_SP(cmd);
9131 } while (max_wait_time--);
9137 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9138 * @ha: Pointer to host adapter structure
9140 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9142 unsigned long wait_online;
9144 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9145 while (time_before(jiffies, wait_online)) {
9157 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9158 * @ha: pointer to HBA
9159 * @stgt: pointer to SCSI target
9160 * @sdev: pointer to SCSI device
9162 * This function waits for all outstanding commands to a lun to complete. It
9163 * returns 0 if all pending commands are returned and 1 otherwise.
9165 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9166 struct scsi_target *stgt,
9167 struct scsi_device *sdev)
9171 struct scsi_cmnd *cmd;
9174 * Waiting for all commands for the designated target or dev
9175 * in the active array
9177 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9178 cmd = scsi_host_find_tag(ha->host, cnt);
9179 if (cmd && stgt == scsi_target(cmd->device) &&
9180 (!sdev || sdev == cmd->device)) {
9181 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9191 * qla4xxx_eh_abort - callback for abort task.
9192 * @cmd: Pointer to Linux's SCSI command structure
9194 * This routine is called by the Linux OS to abort the specified
9197 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9199 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9200 unsigned int id = cmd->device->id;
9201 uint64_t lun = cmd->device->lun;
9202 unsigned long flags;
9203 struct srb *srb = NULL;
9208 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9209 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9211 rval = qla4xxx_isp_check_reg(ha);
9212 if (rval != QLA_SUCCESS) {
9213 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9217 spin_lock_irqsave(&ha->hardware_lock, flags);
9218 srb = (struct srb *) CMD_SP(cmd);
9220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9221 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9222 ha->host_no, id, lun);
9225 kref_get(&srb->srb_ref);
9226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9228 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9229 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9230 ha->host_no, id, lun));
9233 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9234 ha->host_no, id, lun));
9238 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9240 /* Wait for command to complete */
9242 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9243 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9244 ha->host_no, id, lun));
9249 ql4_printk(KERN_INFO, ha,
9250 "scsi%ld:%d:%llu: Abort command - %s\n",
9251 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9257 * qla4xxx_eh_device_reset - callback for target reset.
9258 * @cmd: Pointer to Linux's SCSI command structure
9260 * This routine is called by the Linux OS to reset all luns on the
9263 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9265 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9266 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9267 int ret = FAILED, stat;
9273 ret = iscsi_block_scsi_eh(cmd);
9278 ql4_printk(KERN_INFO, ha,
9279 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9280 cmd->device->channel, cmd->device->id, cmd->device->lun);
9282 DEBUG2(printk(KERN_INFO
9283 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9284 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9285 cmd, jiffies, scsi_cmd_to_rq(cmd)->timeout / HZ,
9286 ha->dpc_flags, cmd->result, cmd->allowed));
9288 rval = qla4xxx_isp_check_reg(ha);
9289 if (rval != QLA_SUCCESS) {
9290 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9294 /* FIXME: wait for hba to go online */
9295 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9296 if (stat != QLA_SUCCESS) {
9297 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9298 goto eh_dev_reset_done;
9301 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9303 ql4_printk(KERN_INFO, ha,
9304 "DEVICE RESET FAILED - waiting for "
9306 goto eh_dev_reset_done;
9310 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9311 MM_LUN_RESET) != QLA_SUCCESS)
9312 goto eh_dev_reset_done;
9314 ql4_printk(KERN_INFO, ha,
9315 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9316 ha->host_no, cmd->device->channel, cmd->device->id,
9327 * qla4xxx_eh_target_reset - callback for target reset.
9328 * @cmd: Pointer to Linux's SCSI command structure
9330 * This routine is called by the Linux OS to reset the target.
9332 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9334 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9335 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9342 ret = iscsi_block_scsi_eh(cmd);
9346 starget_printk(KERN_INFO, scsi_target(cmd->device),
9347 "WARM TARGET RESET ISSUED.\n");
9349 DEBUG2(printk(KERN_INFO
9350 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9351 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9352 ha->host_no, cmd, jiffies, scsi_cmd_to_rq(cmd)->timeout / HZ,
9353 ha->dpc_flags, cmd->result, cmd->allowed));
9355 rval = qla4xxx_isp_check_reg(ha);
9356 if (rval != QLA_SUCCESS) {
9357 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9361 stat = qla4xxx_reset_target(ha, ddb_entry);
9362 if (stat != QLA_SUCCESS) {
9363 starget_printk(KERN_INFO, scsi_target(cmd->device),
9364 "WARM TARGET RESET FAILED.\n");
9368 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9370 starget_printk(KERN_INFO, scsi_target(cmd->device),
9371 "WARM TARGET DEVICE RESET FAILED - "
9372 "waiting for commands.\n");
9377 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9378 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9379 starget_printk(KERN_INFO, scsi_target(cmd->device),
9380 "WARM TARGET DEVICE RESET FAILED - "
9381 "marker iocb failed.\n");
9385 starget_printk(KERN_INFO, scsi_target(cmd->device),
9386 "WARM TARGET RESET SUCCEEDED.\n");
9391 * qla4xxx_is_eh_active - check if error handler is running
9392 * @shost: Pointer to SCSI Host struct
9394 * This routine finds that if reset host is called in EH
9395 * scenario or from some application like sg_reset
9397 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9399 if (shost->shost_state == SHOST_RECOVERY)
9405 * qla4xxx_eh_host_reset - kernel callback
9406 * @cmd: Pointer to Linux's SCSI command structure
9408 * This routine is invoked by the Linux kernel to perform fatal error
9409 * recovery on the specified adapter.
9411 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9413 int return_status = FAILED;
9414 struct scsi_qla_host *ha;
9417 ha = to_qla_host(cmd->device->host);
9419 rval = qla4xxx_isp_check_reg(ha);
9420 if (rval != QLA_SUCCESS) {
9421 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9425 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9426 qla4_83xx_set_idc_dontreset(ha);
9429 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9430 * protocol drivers, we should not set device_state to NEED_RESET
9432 if (ql4xdontresethba ||
9433 ((is_qla8032(ha) || is_qla8042(ha)) &&
9434 qla4_83xx_idc_dontreset(ha))) {
9435 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9436 ha->host_no, __func__));
9438 /* Clear outstanding srb in queues */
9439 if (qla4xxx_is_eh_active(cmd->device->host))
9440 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9445 ql4_printk(KERN_INFO, ha,
9446 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9447 cmd->device->channel, cmd->device->id, cmd->device->lun);
9449 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9450 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9451 "DEAD.\n", ha->host_no, cmd->device->channel,
9457 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9459 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9461 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9464 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9465 return_status = SUCCESS;
9467 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9468 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9470 return return_status;
9473 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9475 uint32_t mbox_cmd[MBOX_REG_COUNT];
9476 uint32_t mbox_sts[MBOX_REG_COUNT];
9477 struct addr_ctrl_blk_def *acb = NULL;
9478 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9479 int rval = QLA_SUCCESS;
9482 acb = dma_alloc_coherent(&ha->pdev->dev,
9483 sizeof(struct addr_ctrl_blk_def),
9484 &acb_dma, GFP_KERNEL);
9486 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9489 goto exit_port_reset;
9492 memset(acb, 0, acb_len);
9494 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9495 if (rval != QLA_SUCCESS) {
9500 rval = qla4xxx_disable_acb(ha);
9501 if (rval != QLA_SUCCESS) {
9506 wait_for_completion_timeout(&ha->disable_acb_comp,
9507 DISABLE_ACB_TOV * HZ);
9509 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9510 if (rval != QLA_SUCCESS) {
9516 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9519 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9520 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9524 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9526 struct scsi_qla_host *ha = to_qla_host(shost);
9527 int rval = QLA_SUCCESS;
9530 if (ql4xdontresethba) {
9531 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9534 goto exit_host_reset;
9537 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9538 goto recover_adapter;
9540 switch (reset_type) {
9541 case SCSI_ADAPTER_RESET:
9542 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9544 case SCSI_FIRMWARE_RESET:
9545 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9547 /* set firmware context reset */
9548 set_bit(DPC_RESET_HA_FW_CONTEXT,
9551 rval = qla4xxx_context_reset(ha);
9552 goto exit_host_reset;
9559 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9560 * reset is issued by application */
9561 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9562 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9563 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9564 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9565 (idc_ctrl | GRACEFUL_RESET_BIT1));
9568 rval = qla4xxx_recover_adapter(ha);
9569 if (rval != QLA_SUCCESS) {
9570 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9579 /* PCI AER driver recovers from all correctable errors w/o
9580 * driver intervention. For uncorrectable errors PCI AER
9581 * driver calls the following device driver's callbacks
9583 * - Fatal Errors - link_reset
9584 * - Non-Fatal Errors - driver's error_detected() which
9585 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9587 * PCI AER driver calls
9588 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9589 * returns RECOVERED or NEED_RESET if fw_hung
9590 * NEED_RESET - driver's slot_reset()
9591 * DISCONNECT - device is dead & cannot recover
9592 * RECOVERED - driver's resume()
9594 static pci_ers_result_t
9595 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9597 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9599 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9600 ha->host_no, __func__, state);
9602 if (!is_aer_supported(ha))
9603 return PCI_ERS_RESULT_NONE;
9606 case pci_channel_io_normal:
9607 clear_bit(AF_EEH_BUSY, &ha->flags);
9608 return PCI_ERS_RESULT_CAN_RECOVER;
9609 case pci_channel_io_frozen:
9610 set_bit(AF_EEH_BUSY, &ha->flags);
9611 qla4xxx_mailbox_premature_completion(ha);
9612 qla4xxx_free_irqs(ha);
9613 pci_disable_device(pdev);
9614 /* Return back all IOs */
9615 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9616 return PCI_ERS_RESULT_NEED_RESET;
9617 case pci_channel_io_perm_failure:
9618 set_bit(AF_EEH_BUSY, &ha->flags);
9619 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9620 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9621 return PCI_ERS_RESULT_DISCONNECT;
9623 return PCI_ERS_RESULT_NEED_RESET;
9627 * qla4xxx_pci_mmio_enabled() - gets called if
9628 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9629 * and read/write to the device still works.
9630 * @pdev: PCI device pointer
9632 static pci_ers_result_t
9633 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9635 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9637 if (!is_aer_supported(ha))
9638 return PCI_ERS_RESULT_NONE;
9640 return PCI_ERS_RESULT_RECOVERED;
9643 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9645 uint32_t rval = QLA_ERROR;
9647 struct pci_dev *other_pdev = NULL;
9649 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9651 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9653 if (test_bit(AF_ONLINE, &ha->flags)) {
9654 clear_bit(AF_ONLINE, &ha->flags);
9655 clear_bit(AF_LINK_UP, &ha->flags);
9656 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9657 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9660 fn = PCI_FUNC(ha->pdev->devfn);
9661 if (is_qla8022(ha)) {
9664 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9665 ha->host_no, __func__, fn);
9666 /* Get the pci device given the domain, bus,
9667 * slot/function number */
9668 other_pdev = pci_get_domain_bus_and_slot(
9669 pci_domain_nr(ha->pdev->bus),
9670 ha->pdev->bus->number,
9671 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9677 if (atomic_read(&other_pdev->enable_cnt)) {
9678 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9679 ha->host_no, __func__, fn);
9680 pci_dev_put(other_pdev);
9683 pci_dev_put(other_pdev);
9686 /* this case is meant for ISP83xx/ISP84xx only */
9687 if (qla4_83xx_can_perform_reset(ha)) {
9688 /* reset fn as iSCSI is going to perform the reset */
9693 /* The first function on the card, the reset owner will
9694 * start & initialize the firmware. The other functions
9695 * on the card will reset the firmware context
9698 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9699 "0x%x is the owner\n", ha->host_no, __func__,
9702 ha->isp_ops->idc_lock(ha);
9703 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9705 ha->isp_ops->idc_unlock(ha);
9707 rval = qla4_8xxx_update_idc_reg(ha);
9708 if (rval == QLA_ERROR) {
9709 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9710 ha->host_no, __func__);
9711 ha->isp_ops->idc_lock(ha);
9712 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9713 QLA8XXX_DEV_FAILED);
9714 ha->isp_ops->idc_unlock(ha);
9715 goto exit_error_recovery;
9718 clear_bit(AF_FW_RECOVERY, &ha->flags);
9719 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9721 if (rval != QLA_SUCCESS) {
9722 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9723 "FAILED\n", ha->host_no, __func__);
9724 qla4xxx_free_irqs(ha);
9725 ha->isp_ops->idc_lock(ha);
9726 qla4_8xxx_clear_drv_active(ha);
9727 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9728 QLA8XXX_DEV_FAILED);
9729 ha->isp_ops->idc_unlock(ha);
9731 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9732 "READY\n", ha->host_no, __func__);
9733 ha->isp_ops->idc_lock(ha);
9734 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9736 /* Clear driver state register */
9737 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9738 qla4_8xxx_set_drv_active(ha);
9739 ha->isp_ops->idc_unlock(ha);
9740 ha->isp_ops->enable_intrs(ha);
9743 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9744 "the reset owner\n", ha->host_no, __func__,
9746 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9747 QLA8XXX_DEV_READY)) {
9748 clear_bit(AF_FW_RECOVERY, &ha->flags);
9749 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9750 if (rval == QLA_SUCCESS)
9751 ha->isp_ops->enable_intrs(ha);
9753 qla4xxx_free_irqs(ha);
9755 ha->isp_ops->idc_lock(ha);
9756 qla4_8xxx_set_drv_active(ha);
9757 ha->isp_ops->idc_unlock(ha);
9760 exit_error_recovery:
9761 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9765 static pci_ers_result_t
9766 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9768 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9769 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9772 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9773 ha->host_no, __func__);
9775 if (!is_aer_supported(ha))
9776 return PCI_ERS_RESULT_NONE;
9778 /* Restore the saved state of PCIe device -
9779 * BAR registers, PCI Config space, PCIX, MSI,
9782 pci_restore_state(pdev);
9784 /* pci_restore_state() clears the saved_state flag of the device
9785 * save restored state which resets saved_state flag
9787 pci_save_state(pdev);
9789 /* Initialize device or resume if in suspended state */
9790 rc = pci_enable_device(pdev);
9792 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9793 "device after reset\n", ha->host_no, __func__);
9794 goto exit_slot_reset;
9797 ha->isp_ops->disable_intrs(ha);
9799 if (is_qla80XX(ha)) {
9800 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9801 ret = PCI_ERS_RESULT_RECOVERED;
9802 goto exit_slot_reset;
9804 goto exit_slot_reset;
9808 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9809 "device after reset\n", ha->host_no, __func__, ret);
9814 qla4xxx_pci_resume(struct pci_dev *pdev)
9816 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9819 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9820 ha->host_no, __func__);
9822 ret = qla4xxx_wait_for_hba_online(ha);
9823 if (ret != QLA_SUCCESS) {
9824 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9825 "resume I/O from slot/link_reset\n", ha->host_no,
9829 clear_bit(AF_EEH_BUSY, &ha->flags);
9832 static const struct pci_error_handlers qla4xxx_err_handler = {
9833 .error_detected = qla4xxx_pci_error_detected,
9834 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9835 .slot_reset = qla4xxx_pci_slot_reset,
9836 .resume = qla4xxx_pci_resume,
9839 static struct pci_device_id qla4xxx_pci_tbl[] = {
9841 .vendor = PCI_VENDOR_ID_QLOGIC,
9842 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9843 .subvendor = PCI_ANY_ID,
9844 .subdevice = PCI_ANY_ID,
9847 .vendor = PCI_VENDOR_ID_QLOGIC,
9848 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9849 .subvendor = PCI_ANY_ID,
9850 .subdevice = PCI_ANY_ID,
9853 .vendor = PCI_VENDOR_ID_QLOGIC,
9854 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9855 .subvendor = PCI_ANY_ID,
9856 .subdevice = PCI_ANY_ID,
9859 .vendor = PCI_VENDOR_ID_QLOGIC,
9860 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9861 .subvendor = PCI_ANY_ID,
9862 .subdevice = PCI_ANY_ID,
9865 .vendor = PCI_VENDOR_ID_QLOGIC,
9866 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9867 .subvendor = PCI_ANY_ID,
9868 .subdevice = PCI_ANY_ID,
9871 .vendor = PCI_VENDOR_ID_QLOGIC,
9872 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9873 .subvendor = PCI_ANY_ID,
9874 .subdevice = PCI_ANY_ID,
9878 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9880 static struct pci_driver qla4xxx_pci_driver = {
9881 .name = DRIVER_NAME,
9882 .id_table = qla4xxx_pci_tbl,
9883 .probe = qla4xxx_probe_adapter,
9884 .remove = qla4xxx_remove_adapter,
9885 .err_handler = &qla4xxx_err_handler,
9888 static int __init qla4xxx_module_init(void)
9892 if (ql4xqfulltracking)
9893 qla4xxx_driver_template.track_queue_depth = 1;
9895 /* Allocate cache for SRBs. */
9896 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9897 SLAB_HWCACHE_ALIGN, NULL);
9898 if (srb_cachep == NULL) {
9900 "%s: Unable to allocate SRB cache..."
9901 "Failing load!\n", DRIVER_NAME);
9906 /* Derive version string. */
9907 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9908 if (ql4xextended_error_logging)
9909 strcat(qla4xxx_version_str, "-debug");
9911 qla4xxx_scsi_transport =
9912 iscsi_register_transport(&qla4xxx_iscsi_transport);
9913 if (!qla4xxx_scsi_transport){
9915 goto release_srb_cache;
9918 ret = pci_register_driver(&qla4xxx_pci_driver);
9920 goto unregister_transport;
9922 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9925 unregister_transport:
9926 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9928 kmem_cache_destroy(srb_cachep);
9933 static void __exit qla4xxx_module_exit(void)
9935 pci_unregister_driver(&qla4xxx_pci_driver);
9936 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9937 kmem_cache_destroy(srb_cachep);
9940 module_init(qla4xxx_module_init);
9941 module_exit(qla4xxx_module_exit);
9943 MODULE_AUTHOR("QLogic Corporation");
9944 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9945 MODULE_LICENSE("GPL");
9946 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);