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_attrs = qla4xxx_host_attrs,
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 __constant_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 __constant_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 __constant_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)
821 mutex_unlock(&ha->chap_sem);
824 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
825 __func__, valid_chap_entries);
826 *num_entries = valid_chap_entries;
830 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
833 uint16_t *chap_tbl_idx = (uint16_t *) data;
834 struct iscsi_cls_session *cls_session;
835 struct iscsi_session *sess;
836 struct ddb_entry *ddb_entry;
838 if (!iscsi_is_session_dev(dev))
839 goto exit_is_chap_active;
841 cls_session = iscsi_dev_to_session(dev);
842 sess = cls_session->dd_data;
843 ddb_entry = sess->dd_data;
845 if (iscsi_is_session_online(cls_session))
846 goto exit_is_chap_active;
848 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
855 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
856 uint16_t chap_tbl_idx)
860 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
861 __qla4xxx_is_chap_active);
866 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
868 struct scsi_qla_host *ha = to_qla_host(shost);
869 struct ql4_chap_table *chap_table;
871 int max_chap_entries = 0;
876 chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
877 if (chap_table == NULL)
881 max_chap_entries = (ha->hw.flt_chap_size / 2) /
882 sizeof(struct ql4_chap_table);
884 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
886 if (chap_tbl_idx > max_chap_entries) {
888 goto exit_delete_chap;
891 /* Check if chap index is in use.
892 * If chap is in use don't delet chap entry */
893 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
895 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
896 "delete from flash\n", chap_tbl_idx);
898 goto exit_delete_chap;
901 chap_size = sizeof(struct ql4_chap_table);
903 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
905 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
906 /* flt_chap_size is CHAP table size for both ports
907 * so divide it by 2 to calculate the offset for second port
909 if (ha->port_num == 1)
910 offset += (ha->hw.flt_chap_size / 2);
911 offset += (chap_tbl_idx * chap_size);
914 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
915 if (ret != QLA_SUCCESS) {
917 goto exit_delete_chap;
920 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
921 __le16_to_cpu(chap_table->cookie)));
923 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
924 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
925 goto exit_delete_chap;
928 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
930 offset = FLASH_CHAP_OFFSET |
931 (chap_tbl_idx * sizeof(struct ql4_chap_table));
932 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
933 FLASH_OPT_RMW_COMMIT);
934 if (ret == QLA_SUCCESS && ha->chap_list) {
935 mutex_lock(&ha->chap_sem);
936 /* Update ha chap_list cache */
937 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
938 chap_table, sizeof(struct ql4_chap_table));
939 mutex_unlock(&ha->chap_sem);
941 if (ret != QLA_SUCCESS)
945 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
950 * qla4xxx_set_chap_entry - Make chap entry with given information
951 * @shost: pointer to host
952 * @data: chap info - credentials, index and type to make chap entry
953 * @len: length of data
955 * Add or update chap entry with the given information
957 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
959 struct scsi_qla_host *ha = to_qla_host(shost);
960 struct iscsi_chap_rec chap_rec;
961 struct ql4_chap_table *chap_entry = NULL;
962 struct iscsi_param_info *param_info;
964 int max_chap_entries = 0;
970 memset(&chap_rec, 0, sizeof(chap_rec));
972 nla_for_each_attr(attr, data, len, rem) {
973 param_info = nla_data(attr);
975 switch (param_info->param) {
976 case ISCSI_CHAP_PARAM_INDEX:
977 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
979 case ISCSI_CHAP_PARAM_CHAP_TYPE:
980 chap_rec.chap_type = param_info->value[0];
982 case ISCSI_CHAP_PARAM_USERNAME:
983 size = min_t(size_t, sizeof(chap_rec.username),
985 memcpy(chap_rec.username, param_info->value, size);
987 case ISCSI_CHAP_PARAM_PASSWORD:
988 size = min_t(size_t, sizeof(chap_rec.password),
990 memcpy(chap_rec.password, param_info->value, size);
992 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
993 chap_rec.password_length = param_info->value[0];
996 ql4_printk(KERN_ERR, ha,
997 "%s: No such sysfs attribute\n", __func__);
1003 if (chap_rec.chap_type == CHAP_TYPE_IN)
1009 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1010 sizeof(struct ql4_chap_table);
1012 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1014 mutex_lock(&ha->chap_sem);
1015 if (chap_rec.chap_tbl_idx < max_chap_entries) {
1016 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
1019 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
1020 ql4_printk(KERN_INFO, ha,
1021 "Type mismatch for CHAP entry %d\n",
1022 chap_rec.chap_tbl_idx);
1024 goto exit_unlock_chap;
1027 /* If chap index is in use then don't modify it */
1028 rc = qla4xxx_is_chap_active(shost,
1029 chap_rec.chap_tbl_idx);
1031 ql4_printk(KERN_INFO, ha,
1032 "CHAP entry %d is in use\n",
1033 chap_rec.chap_tbl_idx);
1035 goto exit_unlock_chap;
1039 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1041 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1043 goto exit_unlock_chap;
1047 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1048 chap_rec.chap_tbl_idx, type);
1051 mutex_unlock(&ha->chap_sem);
1058 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1060 struct scsi_qla_host *ha = to_qla_host(shost);
1061 struct iscsi_offload_host_stats *host_stats = NULL;
1062 int host_stats_size;
1065 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1067 dma_addr_t iscsi_stats_dma;
1069 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1071 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1073 if (host_stats_size != len) {
1074 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1075 __func__, len, host_stats_size);
1077 goto exit_host_stats;
1079 host_stats = (struct iscsi_offload_host_stats *)buf;
1083 goto exit_host_stats;
1086 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1088 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1089 &iscsi_stats_dma, GFP_KERNEL);
1090 if (!ql_iscsi_stats) {
1091 ql4_printk(KERN_ERR, ha,
1092 "Unable to allocate memory for iscsi stats\n");
1094 goto exit_host_stats;
1097 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1099 if (ret != QLA_SUCCESS) {
1100 ql4_printk(KERN_ERR, ha,
1101 "Unable to retrieve iscsi stats\n");
1103 goto exit_host_stats;
1105 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1106 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1107 host_stats->mactx_multicast_frames =
1108 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1109 host_stats->mactx_broadcast_frames =
1110 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1111 host_stats->mactx_pause_frames =
1112 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1113 host_stats->mactx_control_frames =
1114 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1115 host_stats->mactx_deferral =
1116 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1117 host_stats->mactx_excess_deferral =
1118 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1119 host_stats->mactx_late_collision =
1120 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1121 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1122 host_stats->mactx_single_collision =
1123 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1124 host_stats->mactx_multiple_collision =
1125 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1126 host_stats->mactx_collision =
1127 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1128 host_stats->mactx_frames_dropped =
1129 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1130 host_stats->mactx_jumbo_frames =
1131 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1132 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1133 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1134 host_stats->macrx_unknown_control_frames =
1135 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1136 host_stats->macrx_pause_frames =
1137 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1138 host_stats->macrx_control_frames =
1139 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1140 host_stats->macrx_dribble =
1141 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1142 host_stats->macrx_frame_length_error =
1143 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1144 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1145 host_stats->macrx_carrier_sense_error =
1146 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1147 host_stats->macrx_frame_discarded =
1148 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1149 host_stats->macrx_frames_dropped =
1150 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1151 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1152 host_stats->mac_encoding_error =
1153 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1154 host_stats->macrx_length_error_large =
1155 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1156 host_stats->macrx_length_error_small =
1157 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1158 host_stats->macrx_multicast_frames =
1159 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1160 host_stats->macrx_broadcast_frames =
1161 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1162 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1163 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1164 host_stats->iptx_fragments =
1165 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1166 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1167 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1168 host_stats->iprx_fragments =
1169 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1170 host_stats->ip_datagram_reassembly =
1171 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1172 host_stats->ip_invalid_address_error =
1173 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1174 host_stats->ip_error_packets =
1175 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1176 host_stats->ip_fragrx_overlap =
1177 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1178 host_stats->ip_fragrx_outoforder =
1179 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1180 host_stats->ip_datagram_reassembly_timeout =
1181 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1182 host_stats->ipv6tx_packets =
1183 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1184 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1185 host_stats->ipv6tx_fragments =
1186 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1187 host_stats->ipv6rx_packets =
1188 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1189 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1190 host_stats->ipv6rx_fragments =
1191 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1192 host_stats->ipv6_datagram_reassembly =
1193 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1194 host_stats->ipv6_invalid_address_error =
1195 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1196 host_stats->ipv6_error_packets =
1197 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1198 host_stats->ipv6_fragrx_overlap =
1199 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1200 host_stats->ipv6_fragrx_outoforder =
1201 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1202 host_stats->ipv6_datagram_reassembly_timeout =
1203 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1204 host_stats->tcptx_segments =
1205 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1206 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1207 host_stats->tcprx_segments =
1208 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1209 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1210 host_stats->tcp_duplicate_ack_retx =
1211 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1212 host_stats->tcp_retx_timer_expired =
1213 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1214 host_stats->tcprx_duplicate_ack =
1215 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1216 host_stats->tcprx_pure_ackr =
1217 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1218 host_stats->tcptx_delayed_ack =
1219 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1220 host_stats->tcptx_pure_ack =
1221 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1222 host_stats->tcprx_segment_error =
1223 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1224 host_stats->tcprx_segment_outoforder =
1225 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1226 host_stats->tcprx_window_probe =
1227 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1228 host_stats->tcprx_window_update =
1229 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1230 host_stats->tcptx_window_probe_persist =
1231 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1232 host_stats->ecc_error_correction =
1233 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1234 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1235 host_stats->iscsi_data_bytes_tx =
1236 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1237 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1238 host_stats->iscsi_data_bytes_rx =
1239 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1240 host_stats->iscsi_io_completed =
1241 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1242 host_stats->iscsi_unexpected_io_rx =
1243 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1244 host_stats->iscsi_format_error =
1245 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1246 host_stats->iscsi_hdr_digest_error =
1247 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1248 host_stats->iscsi_data_digest_error =
1249 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1250 host_stats->iscsi_sequence_error =
1251 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1254 dma_free_coherent(&ha->pdev->dev, stats_size,
1255 ql_iscsi_stats, iscsi_stats_dma);
1257 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1262 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1263 enum iscsi_param_type param_type,
1264 int param, char *buf)
1266 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1267 struct scsi_qla_host *ha = to_qla_host(shost);
1272 if (param_type == ISCSI_NET_PARAM) {
1274 case ISCSI_NET_PARAM_IPV4_ADDR:
1275 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1277 case ISCSI_NET_PARAM_IPV4_SUBNET:
1278 len = sprintf(buf, "%pI4\n",
1279 &ha->ip_config.subnet_mask);
1281 case ISCSI_NET_PARAM_IPV4_GW:
1282 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1284 case ISCSI_NET_PARAM_IFACE_ENABLE:
1285 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1286 OP_STATE(ha->ip_config.ipv4_options,
1287 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1289 OP_STATE(ha->ip_config.ipv6_options,
1290 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1293 len = sprintf(buf, "%s\n", pval);
1295 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1296 len = sprintf(buf, "%s\n",
1297 (ha->ip_config.tcp_options &
1298 TCPOPT_DHCP_ENABLE) ?
1301 case ISCSI_NET_PARAM_IPV6_ADDR:
1302 if (iface->iface_num == 0)
1303 len = sprintf(buf, "%pI6\n",
1304 &ha->ip_config.ipv6_addr0);
1305 if (iface->iface_num == 1)
1306 len = sprintf(buf, "%pI6\n",
1307 &ha->ip_config.ipv6_addr1);
1309 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1310 len = sprintf(buf, "%pI6\n",
1311 &ha->ip_config.ipv6_link_local_addr);
1313 case ISCSI_NET_PARAM_IPV6_ROUTER:
1314 len = sprintf(buf, "%pI6\n",
1315 &ha->ip_config.ipv6_default_router_addr);
1317 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1318 pval = (ha->ip_config.ipv6_addl_options &
1319 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1322 len = sprintf(buf, "%s\n", pval);
1324 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1325 pval = (ha->ip_config.ipv6_addl_options &
1326 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1329 len = sprintf(buf, "%s\n", pval);
1331 case ISCSI_NET_PARAM_VLAN_ID:
1332 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1333 ival = ha->ip_config.ipv4_vlan_tag &
1336 ival = ha->ip_config.ipv6_vlan_tag &
1339 len = sprintf(buf, "%d\n", ival);
1341 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1342 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1343 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1344 ISCSI_MAX_VLAN_PRIORITY;
1346 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1347 ISCSI_MAX_VLAN_PRIORITY;
1349 len = sprintf(buf, "%d\n", ival);
1351 case ISCSI_NET_PARAM_VLAN_ENABLED:
1352 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1353 OP_STATE(ha->ip_config.ipv4_options,
1354 IPOPT_VLAN_TAGGING_ENABLE, pval);
1356 OP_STATE(ha->ip_config.ipv6_options,
1357 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1359 len = sprintf(buf, "%s\n", pval);
1361 case ISCSI_NET_PARAM_MTU:
1362 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1364 case ISCSI_NET_PARAM_PORT:
1365 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1366 len = sprintf(buf, "%d\n",
1367 ha->ip_config.ipv4_port);
1369 len = sprintf(buf, "%d\n",
1370 ha->ip_config.ipv6_port);
1372 case ISCSI_NET_PARAM_IPADDR_STATE:
1373 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1374 pval = iscsi_get_ipaddress_state_name(
1375 ha->ip_config.ipv4_addr_state);
1377 if (iface->iface_num == 0)
1378 pval = iscsi_get_ipaddress_state_name(
1379 ha->ip_config.ipv6_addr0_state);
1380 else if (iface->iface_num == 1)
1381 pval = iscsi_get_ipaddress_state_name(
1382 ha->ip_config.ipv6_addr1_state);
1385 len = sprintf(buf, "%s\n", pval);
1387 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1388 pval = iscsi_get_ipaddress_state_name(
1389 ha->ip_config.ipv6_link_local_state);
1390 len = sprintf(buf, "%s\n", pval);
1392 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1393 pval = iscsi_get_router_state_name(
1394 ha->ip_config.ipv6_default_router_state);
1395 len = sprintf(buf, "%s\n", pval);
1397 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1398 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1399 OP_STATE(~ha->ip_config.tcp_options,
1400 TCPOPT_DELAYED_ACK_DISABLE, pval);
1402 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1403 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1405 len = sprintf(buf, "%s\n", pval);
1407 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1408 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1409 OP_STATE(~ha->ip_config.tcp_options,
1410 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1412 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1413 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1415 len = sprintf(buf, "%s\n", pval);
1417 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1418 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1419 OP_STATE(~ha->ip_config.tcp_options,
1420 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1422 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1423 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1426 len = sprintf(buf, "%s\n", pval);
1428 case ISCSI_NET_PARAM_TCP_WSF:
1429 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1430 len = sprintf(buf, "%d\n",
1431 ha->ip_config.tcp_wsf);
1433 len = sprintf(buf, "%d\n",
1434 ha->ip_config.ipv6_tcp_wsf);
1436 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1437 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1438 ival = (ha->ip_config.tcp_options &
1439 TCPOPT_TIMER_SCALE) >> 1;
1441 ival = (ha->ip_config.ipv6_tcp_options &
1442 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1444 len = sprintf(buf, "%d\n", ival);
1446 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1447 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1448 OP_STATE(ha->ip_config.tcp_options,
1449 TCPOPT_TIMESTAMP_ENABLE, pval);
1451 OP_STATE(ha->ip_config.ipv6_tcp_options,
1452 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1454 len = sprintf(buf, "%s\n", pval);
1456 case ISCSI_NET_PARAM_CACHE_ID:
1457 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1458 len = sprintf(buf, "%d\n",
1459 ha->ip_config.ipv4_cache_id);
1461 len = sprintf(buf, "%d\n",
1462 ha->ip_config.ipv6_cache_id);
1464 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1465 OP_STATE(ha->ip_config.tcp_options,
1466 TCPOPT_DNS_SERVER_IP_EN, pval);
1468 len = sprintf(buf, "%s\n", pval);
1470 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1471 OP_STATE(ha->ip_config.tcp_options,
1472 TCPOPT_SLP_DA_INFO_EN, pval);
1474 len = sprintf(buf, "%s\n", pval);
1476 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1477 OP_STATE(ha->ip_config.ipv4_options,
1478 IPOPT_IPV4_TOS_EN, pval);
1480 len = sprintf(buf, "%s\n", pval);
1482 case ISCSI_NET_PARAM_IPV4_TOS:
1483 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1485 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1486 OP_STATE(ha->ip_config.ipv4_options,
1487 IPOPT_GRAT_ARP_EN, pval);
1489 len = sprintf(buf, "%s\n", pval);
1491 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1492 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1495 len = sprintf(buf, "%s\n", pval);
1497 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1498 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1499 (char *)ha->ip_config.ipv4_alt_cid : "";
1501 len = sprintf(buf, "%s\n", pval);
1503 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1504 OP_STATE(ha->ip_config.ipv4_options,
1505 IPOPT_REQ_VID_EN, pval);
1507 len = sprintf(buf, "%s\n", pval);
1509 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1510 OP_STATE(ha->ip_config.ipv4_options,
1511 IPOPT_USE_VID_EN, pval);
1513 len = sprintf(buf, "%s\n", pval);
1515 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1516 pval = (ha->ip_config.ipv4_vid_len) ?
1517 (char *)ha->ip_config.ipv4_vid : "";
1519 len = sprintf(buf, "%s\n", pval);
1521 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1522 OP_STATE(ha->ip_config.ipv4_options,
1523 IPOPT_LEARN_IQN_EN, pval);
1525 len = sprintf(buf, "%s\n", pval);
1527 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1528 OP_STATE(~ha->ip_config.ipv4_options,
1529 IPOPT_FRAGMENTATION_DISABLE, pval);
1531 len = sprintf(buf, "%s\n", pval);
1533 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1534 OP_STATE(ha->ip_config.ipv4_options,
1535 IPOPT_IN_FORWARD_EN, pval);
1537 len = sprintf(buf, "%s\n", pval);
1539 case ISCSI_NET_PARAM_REDIRECT_EN:
1540 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1541 OP_STATE(ha->ip_config.ipv4_options,
1542 IPOPT_ARP_REDIRECT_EN, pval);
1544 OP_STATE(ha->ip_config.ipv6_options,
1545 IPV6_OPT_REDIRECT_EN, pval);
1547 len = sprintf(buf, "%s\n", pval);
1549 case ISCSI_NET_PARAM_IPV4_TTL:
1550 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1552 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1553 OP_STATE(ha->ip_config.ipv6_options,
1554 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1556 len = sprintf(buf, "%s\n", pval);
1558 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1559 OP_STATE(ha->ip_config.ipv6_addl_options,
1560 IPV6_ADDOPT_MLD_EN, pval);
1562 len = sprintf(buf, "%s\n", pval);
1564 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1565 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1567 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1568 len = sprintf(buf, "%d\n",
1569 ha->ip_config.ipv6_traffic_class);
1571 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1572 len = sprintf(buf, "%d\n",
1573 ha->ip_config.ipv6_hop_limit);
1575 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1576 len = sprintf(buf, "%d\n",
1577 ha->ip_config.ipv6_nd_reach_time);
1579 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1580 len = sprintf(buf, "%d\n",
1581 ha->ip_config.ipv6_nd_rexmit_timer);
1583 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1584 len = sprintf(buf, "%d\n",
1585 ha->ip_config.ipv6_nd_stale_timeout);
1587 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1588 len = sprintf(buf, "%d\n",
1589 ha->ip_config.ipv6_dup_addr_detect_count);
1591 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1592 len = sprintf(buf, "%d\n",
1593 ha->ip_config.ipv6_gw_advrt_mtu);
1598 } else if (param_type == ISCSI_IFACE_PARAM) {
1600 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1601 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1603 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1604 OP_STATE(ha->ip_config.iscsi_options,
1605 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1607 len = sprintf(buf, "%s\n", pval);
1609 case ISCSI_IFACE_PARAM_DATADGST_EN:
1610 OP_STATE(ha->ip_config.iscsi_options,
1611 ISCSIOPTS_DATA_DIGEST_EN, pval);
1613 len = sprintf(buf, "%s\n", pval);
1615 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1616 OP_STATE(ha->ip_config.iscsi_options,
1617 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1619 len = sprintf(buf, "%s\n", pval);
1621 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1622 OP_STATE(ha->ip_config.iscsi_options,
1623 ISCSIOPTS_INITIAL_R2T_EN, pval);
1625 len = sprintf(buf, "%s\n", pval);
1627 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1628 OP_STATE(ha->ip_config.iscsi_options,
1629 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1631 len = sprintf(buf, "%s\n", pval);
1633 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1634 OP_STATE(ha->ip_config.iscsi_options,
1635 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1637 len = sprintf(buf, "%s\n", pval);
1639 case ISCSI_IFACE_PARAM_ERL:
1640 len = sprintf(buf, "%d\n",
1641 (ha->ip_config.iscsi_options &
1644 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1645 len = sprintf(buf, "%u\n",
1646 ha->ip_config.iscsi_max_pdu_size *
1649 case ISCSI_IFACE_PARAM_FIRST_BURST:
1650 len = sprintf(buf, "%u\n",
1651 ha->ip_config.iscsi_first_burst_len *
1654 case ISCSI_IFACE_PARAM_MAX_R2T:
1655 len = sprintf(buf, "%d\n",
1656 ha->ip_config.iscsi_max_outstnd_r2t);
1658 case ISCSI_IFACE_PARAM_MAX_BURST:
1659 len = sprintf(buf, "%u\n",
1660 ha->ip_config.iscsi_max_burst_len *
1663 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1664 OP_STATE(ha->ip_config.iscsi_options,
1665 ISCSIOPTS_CHAP_AUTH_EN, pval);
1667 len = sprintf(buf, "%s\n", pval);
1669 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1670 OP_STATE(ha->ip_config.iscsi_options,
1671 ISCSIOPTS_BIDI_CHAP_EN, pval);
1673 len = sprintf(buf, "%s\n", pval);
1675 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1676 OP_STATE(ha->ip_config.iscsi_options,
1677 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1679 len = sprintf(buf, "%s\n", pval);
1681 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1682 OP_STATE(ha->ip_config.iscsi_options,
1683 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1685 len = sprintf(buf, "%s\n", pval);
1687 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1688 OP_STATE(ha->ip_config.iscsi_options,
1689 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1691 len = sprintf(buf, "%s\n", pval);
1693 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1694 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1704 static struct iscsi_endpoint *
1705 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1709 struct iscsi_endpoint *ep;
1710 struct qla_endpoint *qla_ep;
1711 struct scsi_qla_host *ha;
1712 struct sockaddr_in *addr;
1713 struct sockaddr_in6 *addr6;
1717 pr_err("%s: shost is NULL\n", __func__);
1718 return ERR_PTR(ret);
1721 ha = iscsi_host_priv(shost);
1722 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1725 return ERR_PTR(ret);
1728 qla_ep = ep->dd_data;
1729 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1730 if (dst_addr->sa_family == AF_INET) {
1731 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1732 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1733 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1734 (char *)&addr->sin_addr));
1735 } else if (dst_addr->sa_family == AF_INET6) {
1736 memcpy(&qla_ep->dst_addr, dst_addr,
1737 sizeof(struct sockaddr_in6));
1738 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1739 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1740 (char *)&addr6->sin6_addr));
1742 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1746 qla_ep->host = shost;
1751 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1753 struct qla_endpoint *qla_ep;
1754 struct scsi_qla_host *ha;
1757 qla_ep = ep->dd_data;
1758 ha = to_qla_host(qla_ep->host);
1759 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1761 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1767 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1769 struct qla_endpoint *qla_ep;
1770 struct scsi_qla_host *ha;
1772 qla_ep = ep->dd_data;
1773 ha = to_qla_host(qla_ep->host);
1774 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1776 iscsi_destroy_endpoint(ep);
1779 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1780 enum iscsi_param param,
1783 struct qla_endpoint *qla_ep = ep->dd_data;
1784 struct sockaddr *dst_addr;
1785 struct scsi_qla_host *ha;
1790 ha = to_qla_host(qla_ep->host);
1791 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1795 case ISCSI_PARAM_CONN_PORT:
1796 case ISCSI_PARAM_CONN_ADDRESS:
1797 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1801 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1802 &qla_ep->dst_addr, param, buf);
1808 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1809 struct iscsi_stats *stats)
1811 struct iscsi_session *sess;
1812 struct iscsi_cls_session *cls_sess;
1813 struct ddb_entry *ddb_entry;
1814 struct scsi_qla_host *ha;
1815 struct ql_iscsi_stats *ql_iscsi_stats;
1818 dma_addr_t iscsi_stats_dma;
1820 cls_sess = iscsi_conn_to_session(cls_conn);
1821 sess = cls_sess->dd_data;
1822 ddb_entry = sess->dd_data;
1825 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1827 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1828 /* Allocate memory */
1829 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1830 &iscsi_stats_dma, GFP_KERNEL);
1831 if (!ql_iscsi_stats) {
1832 ql4_printk(KERN_ERR, ha,
1833 "Unable to allocate memory for iscsi stats\n");
1834 goto exit_get_stats;
1837 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1839 if (ret != QLA_SUCCESS) {
1840 ql4_printk(KERN_ERR, ha,
1841 "Unable to retrieve iscsi stats\n");
1846 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1847 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1849 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1850 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1851 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1852 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1853 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1854 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1855 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1856 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1858 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1859 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1860 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1861 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1862 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1863 stats->logoutrsp_pdus =
1864 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1865 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1866 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1867 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1870 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1876 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1878 struct iscsi_cls_session *session;
1879 unsigned long flags;
1880 enum blk_eh_timer_return ret = BLK_EH_DONE;
1882 session = starget_to_session(scsi_target(sc->device));
1884 spin_lock_irqsave(&session->lock, flags);
1885 if (session->state == ISCSI_SESSION_FAILED)
1886 ret = BLK_EH_RESET_TIMER;
1887 spin_unlock_irqrestore(&session->lock, flags);
1892 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1894 struct scsi_qla_host *ha = to_qla_host(shost);
1895 struct iscsi_cls_host *ihost = shost->shost_data;
1896 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1898 qla4xxx_get_firmware_state(ha);
1900 switch (ha->addl_fw_state & 0x0F00) {
1901 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1902 speed = ISCSI_PORT_SPEED_10MBPS;
1904 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1905 speed = ISCSI_PORT_SPEED_100MBPS;
1907 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1908 speed = ISCSI_PORT_SPEED_1GBPS;
1910 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1911 speed = ISCSI_PORT_SPEED_10GBPS;
1914 ihost->port_speed = speed;
1917 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1919 struct scsi_qla_host *ha = to_qla_host(shost);
1920 struct iscsi_cls_host *ihost = shost->shost_data;
1921 uint32_t state = ISCSI_PORT_STATE_DOWN;
1923 if (test_bit(AF_LINK_UP, &ha->flags))
1924 state = ISCSI_PORT_STATE_UP;
1926 ihost->port_state = state;
1929 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1930 enum iscsi_host_param param, char *buf)
1932 struct scsi_qla_host *ha = to_qla_host(shost);
1936 case ISCSI_HOST_PARAM_HWADDRESS:
1937 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1939 case ISCSI_HOST_PARAM_IPADDRESS:
1940 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1942 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1943 len = sprintf(buf, "%s\n", ha->name_string);
1945 case ISCSI_HOST_PARAM_PORT_STATE:
1946 qla4xxx_set_port_state(shost);
1947 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1949 case ISCSI_HOST_PARAM_PORT_SPEED:
1950 qla4xxx_set_port_speed(shost);
1951 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1960 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1966 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1967 &qla4xxx_iscsi_transport,
1968 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1969 if (!ha->iface_ipv4)
1970 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1974 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1976 if (!ha->iface_ipv6_0)
1978 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1979 &qla4xxx_iscsi_transport,
1980 ISCSI_IFACE_TYPE_IPV6, 0,
1982 if (!ha->iface_ipv6_0)
1983 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1986 if (!ha->iface_ipv6_1)
1988 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1989 &qla4xxx_iscsi_transport,
1990 ISCSI_IFACE_TYPE_IPV6, 1,
1992 if (!ha->iface_ipv6_1)
1993 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1997 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1999 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
2000 qla4xxx_create_ipv4_iface(ha);
2002 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
2003 qla4xxx_create_ipv6_iface(ha);
2006 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
2008 if (ha->iface_ipv4) {
2009 iscsi_destroy_iface(ha->iface_ipv4);
2010 ha->iface_ipv4 = NULL;
2014 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
2016 if (ha->iface_ipv6_0) {
2017 iscsi_destroy_iface(ha->iface_ipv6_0);
2018 ha->iface_ipv6_0 = NULL;
2020 if (ha->iface_ipv6_1) {
2021 iscsi_destroy_iface(ha->iface_ipv6_1);
2022 ha->iface_ipv6_1 = NULL;
2026 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
2028 qla4xxx_destroy_ipv4_iface(ha);
2029 qla4xxx_destroy_ipv6_iface(ha);
2032 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2033 struct iscsi_iface_param_info *iface_param,
2034 struct addr_ctrl_blk *init_fw_cb)
2037 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2038 * iface_num 1 is valid only for IPv6 Addr.
2040 switch (iface_param->param) {
2041 case ISCSI_NET_PARAM_IPV6_ADDR:
2042 if (iface_param->iface_num & 0x1)
2044 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2045 sizeof(init_fw_cb->ipv6_addr1));
2048 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2049 sizeof(init_fw_cb->ipv6_addr0));
2051 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2052 if (iface_param->iface_num & 0x1)
2054 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2055 sizeof(init_fw_cb->ipv6_if_id));
2057 case ISCSI_NET_PARAM_IPV6_ROUTER:
2058 if (iface_param->iface_num & 0x1)
2060 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2061 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2063 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2064 /* Autocfg applies to even interface */
2065 if (iface_param->iface_num & 0x1)
2068 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2069 init_fw_cb->ipv6_addtl_opts &=
2071 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2072 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2073 init_fw_cb->ipv6_addtl_opts |=
2075 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2077 ql4_printk(KERN_ERR, ha,
2078 "Invalid autocfg setting for IPv6 addr\n");
2080 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2081 /* Autocfg applies to even interface */
2082 if (iface_param->iface_num & 0x1)
2085 if (iface_param->value[0] ==
2086 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2087 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2088 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2089 else if (iface_param->value[0] ==
2090 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2091 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2092 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2094 ql4_printk(KERN_ERR, ha,
2095 "Invalid autocfg setting for IPv6 linklocal addr\n");
2097 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2098 /* Autocfg applies to even interface */
2099 if (iface_param->iface_num & 0x1)
2102 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2103 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2104 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2106 case ISCSI_NET_PARAM_IFACE_ENABLE:
2107 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2108 init_fw_cb->ipv6_opts |=
2109 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2110 qla4xxx_create_ipv6_iface(ha);
2112 init_fw_cb->ipv6_opts &=
2113 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2115 qla4xxx_destroy_ipv6_iface(ha);
2118 case ISCSI_NET_PARAM_VLAN_TAG:
2119 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2121 init_fw_cb->ipv6_vlan_tag =
2122 cpu_to_be16(*(uint16_t *)iface_param->value);
2124 case ISCSI_NET_PARAM_VLAN_ENABLED:
2125 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2126 init_fw_cb->ipv6_opts |=
2127 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2129 init_fw_cb->ipv6_opts &=
2130 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2132 case ISCSI_NET_PARAM_MTU:
2133 init_fw_cb->eth_mtu_size =
2134 cpu_to_le16(*(uint16_t *)iface_param->value);
2136 case ISCSI_NET_PARAM_PORT:
2137 /* Autocfg applies to even interface */
2138 if (iface_param->iface_num & 0x1)
2141 init_fw_cb->ipv6_port =
2142 cpu_to_le16(*(uint16_t *)iface_param->value);
2144 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2145 if (iface_param->iface_num & 0x1)
2147 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2148 init_fw_cb->ipv6_tcp_opts |=
2149 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2151 init_fw_cb->ipv6_tcp_opts &=
2152 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2155 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2156 if (iface_param->iface_num & 0x1)
2158 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2159 init_fw_cb->ipv6_tcp_opts |=
2160 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2162 init_fw_cb->ipv6_tcp_opts &=
2163 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2165 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2166 if (iface_param->iface_num & 0x1)
2168 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2169 init_fw_cb->ipv6_tcp_opts |=
2170 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2172 init_fw_cb->ipv6_tcp_opts &=
2173 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2175 case ISCSI_NET_PARAM_TCP_WSF:
2176 if (iface_param->iface_num & 0x1)
2178 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2180 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2181 if (iface_param->iface_num & 0x1)
2183 init_fw_cb->ipv6_tcp_opts &=
2184 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2185 init_fw_cb->ipv6_tcp_opts |=
2186 cpu_to_le16((iface_param->value[0] << 1) &
2187 IPV6_TCPOPT_TIMER_SCALE);
2189 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2190 if (iface_param->iface_num & 0x1)
2192 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2193 init_fw_cb->ipv6_tcp_opts |=
2194 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2196 init_fw_cb->ipv6_tcp_opts &=
2197 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2199 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2200 if (iface_param->iface_num & 0x1)
2202 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2203 init_fw_cb->ipv6_opts |=
2204 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2206 init_fw_cb->ipv6_opts &=
2207 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2209 case ISCSI_NET_PARAM_REDIRECT_EN:
2210 if (iface_param->iface_num & 0x1)
2212 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2213 init_fw_cb->ipv6_opts |=
2214 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2216 init_fw_cb->ipv6_opts &=
2217 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2219 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2220 if (iface_param->iface_num & 0x1)
2222 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2223 init_fw_cb->ipv6_addtl_opts |=
2224 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2226 init_fw_cb->ipv6_addtl_opts &=
2227 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2229 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2230 if (iface_param->iface_num & 0x1)
2232 init_fw_cb->ipv6_flow_lbl =
2233 cpu_to_le16(*(uint16_t *)iface_param->value);
2235 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2236 if (iface_param->iface_num & 0x1)
2238 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2240 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2241 if (iface_param->iface_num & 0x1)
2243 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2245 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2246 if (iface_param->iface_num & 0x1)
2248 init_fw_cb->ipv6_nd_reach_time =
2249 cpu_to_le32(*(uint32_t *)iface_param->value);
2251 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2252 if (iface_param->iface_num & 0x1)
2254 init_fw_cb->ipv6_nd_rexmit_timer =
2255 cpu_to_le32(*(uint32_t *)iface_param->value);
2257 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2258 if (iface_param->iface_num & 0x1)
2260 init_fw_cb->ipv6_nd_stale_timeout =
2261 cpu_to_le32(*(uint32_t *)iface_param->value);
2263 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2264 if (iface_param->iface_num & 0x1)
2266 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2268 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2269 if (iface_param->iface_num & 0x1)
2271 init_fw_cb->ipv6_gw_advrt_mtu =
2272 cpu_to_le32(*(uint32_t *)iface_param->value);
2275 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2276 iface_param->param);
2281 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2282 struct iscsi_iface_param_info *iface_param,
2283 struct addr_ctrl_blk *init_fw_cb)
2285 switch (iface_param->param) {
2286 case ISCSI_NET_PARAM_IPV4_ADDR:
2287 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2288 sizeof(init_fw_cb->ipv4_addr));
2290 case ISCSI_NET_PARAM_IPV4_SUBNET:
2291 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2292 sizeof(init_fw_cb->ipv4_subnet));
2294 case ISCSI_NET_PARAM_IPV4_GW:
2295 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2296 sizeof(init_fw_cb->ipv4_gw_addr));
2298 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2299 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2300 init_fw_cb->ipv4_tcp_opts |=
2301 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2302 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2303 init_fw_cb->ipv4_tcp_opts &=
2304 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2306 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2308 case ISCSI_NET_PARAM_IFACE_ENABLE:
2309 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2310 init_fw_cb->ipv4_ip_opts |=
2311 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2312 qla4xxx_create_ipv4_iface(ha);
2314 init_fw_cb->ipv4_ip_opts &=
2315 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2317 qla4xxx_destroy_ipv4_iface(ha);
2320 case ISCSI_NET_PARAM_VLAN_TAG:
2321 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2323 init_fw_cb->ipv4_vlan_tag =
2324 cpu_to_be16(*(uint16_t *)iface_param->value);
2326 case ISCSI_NET_PARAM_VLAN_ENABLED:
2327 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2328 init_fw_cb->ipv4_ip_opts |=
2329 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2331 init_fw_cb->ipv4_ip_opts &=
2332 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2334 case ISCSI_NET_PARAM_MTU:
2335 init_fw_cb->eth_mtu_size =
2336 cpu_to_le16(*(uint16_t *)iface_param->value);
2338 case ISCSI_NET_PARAM_PORT:
2339 init_fw_cb->ipv4_port =
2340 cpu_to_le16(*(uint16_t *)iface_param->value);
2342 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2343 if (iface_param->iface_num & 0x1)
2345 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2346 init_fw_cb->ipv4_tcp_opts |=
2347 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2349 init_fw_cb->ipv4_tcp_opts &=
2350 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2353 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2354 if (iface_param->iface_num & 0x1)
2356 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2357 init_fw_cb->ipv4_tcp_opts |=
2358 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2360 init_fw_cb->ipv4_tcp_opts &=
2361 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2363 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2364 if (iface_param->iface_num & 0x1)
2366 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2367 init_fw_cb->ipv4_tcp_opts |=
2368 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2370 init_fw_cb->ipv4_tcp_opts &=
2371 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2373 case ISCSI_NET_PARAM_TCP_WSF:
2374 if (iface_param->iface_num & 0x1)
2376 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2378 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2379 if (iface_param->iface_num & 0x1)
2381 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2382 init_fw_cb->ipv4_tcp_opts |=
2383 cpu_to_le16((iface_param->value[0] << 1) &
2384 TCPOPT_TIMER_SCALE);
2386 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2387 if (iface_param->iface_num & 0x1)
2389 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2390 init_fw_cb->ipv4_tcp_opts |=
2391 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2393 init_fw_cb->ipv4_tcp_opts &=
2394 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2396 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2397 if (iface_param->iface_num & 0x1)
2399 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2400 init_fw_cb->ipv4_tcp_opts |=
2401 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2403 init_fw_cb->ipv4_tcp_opts &=
2404 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2406 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2407 if (iface_param->iface_num & 0x1)
2409 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2410 init_fw_cb->ipv4_tcp_opts |=
2411 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2413 init_fw_cb->ipv4_tcp_opts &=
2414 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2416 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2417 if (iface_param->iface_num & 0x1)
2419 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2420 init_fw_cb->ipv4_ip_opts |=
2421 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2423 init_fw_cb->ipv4_ip_opts &=
2424 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2426 case ISCSI_NET_PARAM_IPV4_TOS:
2427 if (iface_param->iface_num & 0x1)
2429 init_fw_cb->ipv4_tos = iface_param->value[0];
2431 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2432 if (iface_param->iface_num & 0x1)
2434 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2435 init_fw_cb->ipv4_ip_opts |=
2436 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2438 init_fw_cb->ipv4_ip_opts &=
2439 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2441 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2442 if (iface_param->iface_num & 0x1)
2444 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2445 init_fw_cb->ipv4_ip_opts |=
2446 cpu_to_le16(IPOPT_ALT_CID_EN);
2448 init_fw_cb->ipv4_ip_opts &=
2449 cpu_to_le16(~IPOPT_ALT_CID_EN);
2451 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2452 if (iface_param->iface_num & 0x1)
2454 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2455 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2456 init_fw_cb->ipv4_dhcp_alt_cid_len =
2457 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2459 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2460 if (iface_param->iface_num & 0x1)
2462 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2463 init_fw_cb->ipv4_ip_opts |=
2464 cpu_to_le16(IPOPT_REQ_VID_EN);
2466 init_fw_cb->ipv4_ip_opts &=
2467 cpu_to_le16(~IPOPT_REQ_VID_EN);
2469 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2470 if (iface_param->iface_num & 0x1)
2472 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2473 init_fw_cb->ipv4_ip_opts |=
2474 cpu_to_le16(IPOPT_USE_VID_EN);
2476 init_fw_cb->ipv4_ip_opts &=
2477 cpu_to_le16(~IPOPT_USE_VID_EN);
2479 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2480 if (iface_param->iface_num & 0x1)
2482 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2483 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2484 init_fw_cb->ipv4_dhcp_vid_len =
2485 strlen(init_fw_cb->ipv4_dhcp_vid);
2487 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2488 if (iface_param->iface_num & 0x1)
2490 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2491 init_fw_cb->ipv4_ip_opts |=
2492 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2494 init_fw_cb->ipv4_ip_opts &=
2495 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2497 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2498 if (iface_param->iface_num & 0x1)
2500 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2501 init_fw_cb->ipv4_ip_opts |=
2502 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2504 init_fw_cb->ipv4_ip_opts &=
2505 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2507 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2508 if (iface_param->iface_num & 0x1)
2510 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2511 init_fw_cb->ipv4_ip_opts |=
2512 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2514 init_fw_cb->ipv4_ip_opts &=
2515 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2517 case ISCSI_NET_PARAM_REDIRECT_EN:
2518 if (iface_param->iface_num & 0x1)
2520 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2521 init_fw_cb->ipv4_ip_opts |=
2522 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2524 init_fw_cb->ipv4_ip_opts &=
2525 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2527 case ISCSI_NET_PARAM_IPV4_TTL:
2528 if (iface_param->iface_num & 0x1)
2530 init_fw_cb->ipv4_ttl = iface_param->value[0];
2533 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2534 iface_param->param);
2539 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2540 struct iscsi_iface_param_info *iface_param,
2541 struct addr_ctrl_blk *init_fw_cb)
2543 switch (iface_param->param) {
2544 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2545 if (iface_param->iface_num & 0x1)
2547 init_fw_cb->def_timeout =
2548 cpu_to_le16(*(uint16_t *)iface_param->value);
2550 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2551 if (iface_param->iface_num & 0x1)
2553 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2554 init_fw_cb->iscsi_opts |=
2555 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2557 init_fw_cb->iscsi_opts &=
2558 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2560 case ISCSI_IFACE_PARAM_DATADGST_EN:
2561 if (iface_param->iface_num & 0x1)
2563 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2564 init_fw_cb->iscsi_opts |=
2565 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2567 init_fw_cb->iscsi_opts &=
2568 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2570 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2571 if (iface_param->iface_num & 0x1)
2573 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2574 init_fw_cb->iscsi_opts |=
2575 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2577 init_fw_cb->iscsi_opts &=
2578 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2580 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2581 if (iface_param->iface_num & 0x1)
2583 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2584 init_fw_cb->iscsi_opts |=
2585 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2587 init_fw_cb->iscsi_opts &=
2588 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2590 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2591 if (iface_param->iface_num & 0x1)
2593 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2594 init_fw_cb->iscsi_opts |=
2595 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2597 init_fw_cb->iscsi_opts &=
2598 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2600 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2601 if (iface_param->iface_num & 0x1)
2603 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2604 init_fw_cb->iscsi_opts |=
2605 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2607 init_fw_cb->iscsi_opts &=
2608 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2610 case ISCSI_IFACE_PARAM_ERL:
2611 if (iface_param->iface_num & 0x1)
2613 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2614 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2617 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2618 if (iface_param->iface_num & 0x1)
2620 init_fw_cb->iscsi_max_pdu_size =
2621 cpu_to_le32(*(uint32_t *)iface_param->value) /
2624 case ISCSI_IFACE_PARAM_FIRST_BURST:
2625 if (iface_param->iface_num & 0x1)
2627 init_fw_cb->iscsi_fburst_len =
2628 cpu_to_le32(*(uint32_t *)iface_param->value) /
2631 case ISCSI_IFACE_PARAM_MAX_R2T:
2632 if (iface_param->iface_num & 0x1)
2634 init_fw_cb->iscsi_max_outstnd_r2t =
2635 cpu_to_le16(*(uint16_t *)iface_param->value);
2637 case ISCSI_IFACE_PARAM_MAX_BURST:
2638 if (iface_param->iface_num & 0x1)
2640 init_fw_cb->iscsi_max_burst_len =
2641 cpu_to_le32(*(uint32_t *)iface_param->value) /
2644 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2645 if (iface_param->iface_num & 0x1)
2647 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2648 init_fw_cb->iscsi_opts |=
2649 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2651 init_fw_cb->iscsi_opts &=
2652 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2654 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2655 if (iface_param->iface_num & 0x1)
2657 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2658 init_fw_cb->iscsi_opts |=
2659 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2661 init_fw_cb->iscsi_opts &=
2662 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2664 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2665 if (iface_param->iface_num & 0x1)
2667 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2668 init_fw_cb->iscsi_opts |=
2669 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2671 init_fw_cb->iscsi_opts &=
2672 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2674 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2675 if (iface_param->iface_num & 0x1)
2677 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2678 init_fw_cb->iscsi_opts |=
2679 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2681 init_fw_cb->iscsi_opts &=
2682 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2684 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2685 if (iface_param->iface_num & 0x1)
2687 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2688 init_fw_cb->iscsi_opts |=
2689 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2691 init_fw_cb->iscsi_opts &=
2692 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2695 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2696 iface_param->param);
2702 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2704 struct addr_ctrl_blk_def *acb;
2705 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2706 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2707 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2708 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2709 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2710 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2711 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2712 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2713 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2714 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2715 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2716 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2717 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2718 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2719 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2720 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2724 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2726 struct scsi_qla_host *ha = to_qla_host(shost);
2728 struct iscsi_iface_param_info *iface_param = NULL;
2729 struct addr_ctrl_blk *init_fw_cb = NULL;
2730 dma_addr_t init_fw_cb_dma;
2731 uint32_t mbox_cmd[MBOX_REG_COUNT];
2732 uint32_t mbox_sts[MBOX_REG_COUNT];
2734 struct nlattr *attr;
2736 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2737 sizeof(struct addr_ctrl_blk),
2738 &init_fw_cb_dma, GFP_KERNEL);
2740 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2745 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2746 memset(&mbox_sts, 0, sizeof(mbox_sts));
2748 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2749 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2751 goto exit_init_fw_cb;
2754 nla_for_each_attr(attr, data, len, rem) {
2755 iface_param = nla_data(attr);
2757 if (iface_param->param_type == ISCSI_NET_PARAM) {
2758 switch (iface_param->iface_type) {
2759 case ISCSI_IFACE_TYPE_IPV4:
2760 switch (iface_param->iface_num) {
2762 qla4xxx_set_ipv4(ha, iface_param,
2766 /* Cannot have more than one IPv4 interface */
2767 ql4_printk(KERN_ERR, ha,
2768 "Invalid IPv4 iface number = %d\n",
2769 iface_param->iface_num);
2773 case ISCSI_IFACE_TYPE_IPV6:
2774 switch (iface_param->iface_num) {
2777 qla4xxx_set_ipv6(ha, iface_param,
2781 /* Cannot have more than two IPv6 interface */
2782 ql4_printk(KERN_ERR, ha,
2783 "Invalid IPv6 iface number = %d\n",
2784 iface_param->iface_num);
2789 ql4_printk(KERN_ERR, ha,
2790 "Invalid iface type\n");
2793 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2794 qla4xxx_set_iscsi_param(ha, iface_param,
2801 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2803 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2804 sizeof(struct addr_ctrl_blk),
2805 FLASH_OPT_RMW_COMMIT);
2806 if (rval != QLA_SUCCESS) {
2807 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2810 goto exit_init_fw_cb;
2813 rval = qla4xxx_disable_acb(ha);
2814 if (rval != QLA_SUCCESS) {
2815 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2818 goto exit_init_fw_cb;
2821 wait_for_completion_timeout(&ha->disable_acb_comp,
2822 DISABLE_ACB_TOV * HZ);
2824 qla4xxx_initcb_to_acb(init_fw_cb);
2826 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2827 if (rval != QLA_SUCCESS) {
2828 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2831 goto exit_init_fw_cb;
2834 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2835 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2839 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2840 init_fw_cb, init_fw_cb_dma);
2845 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2846 enum iscsi_param param, char *buf)
2848 struct iscsi_session *sess = cls_sess->dd_data;
2849 struct ddb_entry *ddb_entry = sess->dd_data;
2850 struct scsi_qla_host *ha = ddb_entry->ha;
2851 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2852 struct ql4_chap_table chap_tbl;
2856 memset(&chap_tbl, 0, sizeof(chap_tbl));
2858 case ISCSI_PARAM_CHAP_IN_IDX:
2859 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2860 sess->password_in, BIDI_CHAP,
2863 len = sprintf(buf, "\n");
2865 len = sprintf(buf, "%hu\n", idx);
2867 case ISCSI_PARAM_CHAP_OUT_IDX:
2868 if (ddb_entry->ddb_type == FLASH_DDB) {
2869 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2870 idx = ddb_entry->chap_tbl_idx;
2876 rval = qla4xxx_get_chap_index(ha, sess->username,
2881 len = sprintf(buf, "\n");
2883 len = sprintf(buf, "%hu\n", idx);
2885 case ISCSI_PARAM_USERNAME:
2886 case ISCSI_PARAM_PASSWORD:
2887 /* First, populate session username and password for FLASH DDB,
2888 * if not already done. This happens when session login fails
2891 if (ddb_entry->ddb_type == FLASH_DDB &&
2892 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2893 !sess->username && !sess->password) {
2894 idx = ddb_entry->chap_tbl_idx;
2895 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2899 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2900 (char *)chap_tbl.name,
2901 strlen((char *)chap_tbl.name));
2902 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2903 (char *)chap_tbl.secret,
2904 chap_tbl.secret_len);
2909 return iscsi_session_get_param(cls_sess, param, buf);
2915 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2916 enum iscsi_param param, char *buf)
2918 struct iscsi_conn *conn;
2919 struct qla_conn *qla_conn;
2920 struct sockaddr *dst_addr;
2922 conn = cls_conn->dd_data;
2923 qla_conn = conn->dd_data;
2924 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2927 case ISCSI_PARAM_CONN_PORT:
2928 case ISCSI_PARAM_CONN_ADDRESS:
2929 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2930 dst_addr, param, buf);
2932 return iscsi_conn_get_param(cls_conn, param, buf);
2936 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2938 uint32_t mbx_sts = 0;
2939 uint16_t tmp_ddb_index;
2943 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2945 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2946 DEBUG2(ql4_printk(KERN_INFO, ha,
2947 "Free DDB index not available\n"));
2949 goto exit_get_ddb_index;
2952 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2955 DEBUG2(ql4_printk(KERN_INFO, ha,
2956 "Found a free DDB index at %d\n", tmp_ddb_index));
2957 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2958 if (ret == QLA_ERROR) {
2959 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2960 ql4_printk(KERN_INFO, ha,
2961 "DDB index = %d not available trying next\n",
2965 DEBUG2(ql4_printk(KERN_INFO, ha,
2966 "Free FW DDB not available\n"));
2969 *ddb_index = tmp_ddb_index;
2975 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2976 struct ddb_entry *ddb_entry,
2977 char *existing_ipaddr,
2980 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2981 char formatted_ipaddr[DDB_IPADDR_LEN];
2982 int status = QLA_SUCCESS, ret = 0;
2984 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2985 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2991 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2993 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2999 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
3002 if (strcmp(existing_ipaddr, formatted_ipaddr))
3009 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
3010 struct iscsi_cls_conn *cls_conn)
3012 int idx = 0, max_ddbs, rval;
3013 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3014 struct iscsi_session *sess, *existing_sess;
3015 struct iscsi_conn *conn, *existing_conn;
3016 struct ddb_entry *ddb_entry;
3018 sess = cls_sess->dd_data;
3019 conn = cls_conn->dd_data;
3021 if (sess->targetname == NULL ||
3022 conn->persistent_address == NULL ||
3023 conn->persistent_port == 0)
3026 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3029 for (idx = 0; idx < max_ddbs; idx++) {
3030 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3031 if (ddb_entry == NULL)
3034 if (ddb_entry->ddb_type != FLASH_DDB)
3037 existing_sess = ddb_entry->sess->dd_data;
3038 existing_conn = ddb_entry->conn->dd_data;
3040 if (existing_sess->targetname == NULL ||
3041 existing_conn->persistent_address == NULL ||
3042 existing_conn->persistent_port == 0)
3045 DEBUG2(ql4_printk(KERN_INFO, ha,
3046 "IQN = %s User IQN = %s\n",
3047 existing_sess->targetname,
3050 DEBUG2(ql4_printk(KERN_INFO, ha,
3051 "IP = %s User IP = %s\n",
3052 existing_conn->persistent_address,
3053 conn->persistent_address));
3055 DEBUG2(ql4_printk(KERN_INFO, ha,
3056 "Port = %d User Port = %d\n",
3057 existing_conn->persistent_port,
3058 conn->persistent_port));
3060 if (strcmp(existing_sess->targetname, sess->targetname))
3062 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3063 existing_conn->persistent_address,
3064 conn->persistent_address);
3065 if (rval == QLA_ERROR)
3067 if (existing_conn->persistent_port != conn->persistent_port)
3072 if (idx == max_ddbs)
3075 DEBUG2(ql4_printk(KERN_INFO, ha,
3076 "Match found in fwdb sessions\n"));
3080 static struct iscsi_cls_session *
3081 qla4xxx_session_create(struct iscsi_endpoint *ep,
3082 uint16_t cmds_max, uint16_t qdepth,
3083 uint32_t initial_cmdsn)
3085 struct iscsi_cls_session *cls_sess;
3086 struct scsi_qla_host *ha;
3087 struct qla_endpoint *qla_ep;
3088 struct ddb_entry *ddb_entry;
3090 struct iscsi_session *sess;
3094 printk(KERN_ERR "qla4xxx: missing ep.\n");
3098 qla_ep = ep->dd_data;
3099 ha = to_qla_host(qla_ep->host);
3100 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3103 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3104 if (ret == QLA_ERROR)
3107 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3108 cmds_max, sizeof(struct ddb_entry),
3109 sizeof(struct ql4_task_data),
3110 initial_cmdsn, ddb_index);
3114 sess = cls_sess->dd_data;
3115 ddb_entry = sess->dd_data;
3116 ddb_entry->fw_ddb_index = ddb_index;
3117 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3119 ddb_entry->sess = cls_sess;
3120 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3121 ddb_entry->ddb_change = qla4xxx_ddb_change;
3122 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3123 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3124 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3130 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3132 struct iscsi_session *sess;
3133 struct ddb_entry *ddb_entry;
3134 struct scsi_qla_host *ha;
3135 unsigned long flags, wtime;
3136 struct dev_db_entry *fw_ddb_entry = NULL;
3137 dma_addr_t fw_ddb_entry_dma;
3141 sess = cls_sess->dd_data;
3142 ddb_entry = sess->dd_data;
3144 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3147 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3148 &fw_ddb_entry_dma, GFP_KERNEL);
3149 if (!fw_ddb_entry) {
3150 ql4_printk(KERN_ERR, ha,
3151 "%s: Unable to allocate dma buffer\n", __func__);
3152 goto destroy_session;
3155 wtime = jiffies + (HZ * LOGOUT_TOV);
3157 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3158 fw_ddb_entry, fw_ddb_entry_dma,
3159 NULL, NULL, &ddb_state, NULL,
3161 if (ret == QLA_ERROR)
3162 goto destroy_session;
3164 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3165 (ddb_state == DDB_DS_SESSION_FAILED))
3166 goto destroy_session;
3168 schedule_timeout_uninterruptible(HZ);
3169 } while ((time_after(wtime, jiffies)));
3172 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3173 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3174 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3175 spin_lock_irqsave(&ha->hardware_lock, flags);
3176 qla4xxx_free_ddb(ha, ddb_entry);
3177 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3179 iscsi_session_teardown(cls_sess);
3182 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3183 fw_ddb_entry, fw_ddb_entry_dma);
3186 static struct iscsi_cls_conn *
3187 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3189 struct iscsi_cls_conn *cls_conn;
3190 struct iscsi_session *sess;
3191 struct ddb_entry *ddb_entry;
3192 struct scsi_qla_host *ha;
3194 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3197 pr_info("%s: Can not create connection for conn_idx = %u\n",
3198 __func__, conn_idx);
3202 sess = cls_sess->dd_data;
3203 ddb_entry = sess->dd_data;
3204 ddb_entry->conn = cls_conn;
3207 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3212 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3213 struct iscsi_cls_conn *cls_conn,
3214 uint64_t transport_fd, int is_leading)
3216 struct iscsi_conn *conn;
3217 struct qla_conn *qla_conn;
3218 struct iscsi_endpoint *ep;
3219 struct ddb_entry *ddb_entry;
3220 struct scsi_qla_host *ha;
3221 struct iscsi_session *sess;
3223 sess = cls_session->dd_data;
3224 ddb_entry = sess->dd_data;
3227 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3228 cls_session->sid, cls_conn->cid));
3230 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3232 ep = iscsi_lookup_endpoint(transport_fd);
3235 conn = cls_conn->dd_data;
3236 qla_conn = conn->dd_data;
3237 qla_conn->qla_ep = ep->dd_data;
3241 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3243 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3244 struct iscsi_session *sess;
3245 struct ddb_entry *ddb_entry;
3246 struct scsi_qla_host *ha;
3247 struct dev_db_entry *fw_ddb_entry = NULL;
3248 dma_addr_t fw_ddb_entry_dma;
3249 uint32_t mbx_sts = 0;
3251 int status = QLA_SUCCESS;
3253 sess = cls_sess->dd_data;
3254 ddb_entry = sess->dd_data;
3256 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3257 cls_sess->sid, cls_conn->cid));
3259 /* Check if we have matching FW DDB, if yes then do not
3260 * login to this target. This could cause target to logout previous
3263 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3264 if (ret == QLA_SUCCESS) {
3265 ql4_printk(KERN_INFO, ha,
3266 "Session already exist in FW.\n");
3268 goto exit_conn_start;
3271 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3272 &fw_ddb_entry_dma, GFP_KERNEL);
3273 if (!fw_ddb_entry) {
3274 ql4_printk(KERN_ERR, ha,
3275 "%s: Unable to allocate dma buffer\n", __func__);
3277 goto exit_conn_start;
3280 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3282 /* If iscsid is stopped and started then no need to do
3283 * set param again since ddb state will be already
3284 * active and FW does not allow set ddb to an
3288 if (ddb_entry->fw_ddb_device_state ==
3289 DDB_DS_SESSION_ACTIVE) {
3290 ddb_entry->unblock_sess(ddb_entry->sess);
3291 goto exit_set_param;
3294 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3295 __func__, ddb_entry->fw_ddb_index);
3296 goto exit_conn_start;
3299 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3300 if (status == QLA_ERROR) {
3301 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3304 goto exit_conn_start;
3307 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3308 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3310 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3311 ddb_entry->fw_ddb_device_state));
3318 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3319 fw_ddb_entry, fw_ddb_entry_dma);
3323 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3325 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3326 struct iscsi_session *sess;
3327 struct scsi_qla_host *ha;
3328 struct ddb_entry *ddb_entry;
3331 sess = cls_sess->dd_data;
3332 ddb_entry = sess->dd_data;
3334 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3337 options = LOGOUT_OPTION_CLOSE_SESSION;
3338 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3339 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3342 static void qla4xxx_task_work(struct work_struct *wdata)
3344 struct ql4_task_data *task_data;
3345 struct scsi_qla_host *ha;
3346 struct passthru_status *sts;
3347 struct iscsi_task *task;
3348 struct iscsi_hdr *hdr;
3351 struct iscsi_conn *conn;
3355 task_data = container_of(wdata, struct ql4_task_data, task_work);
3357 task = task_data->task;
3358 sts = &task_data->sts;
3359 hdr_len = sizeof(struct iscsi_hdr);
3361 DEBUG3(printk(KERN_INFO "Status returned\n"));
3362 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3363 DEBUG3(printk(KERN_INFO "Response buffer"));
3364 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3368 switch (sts->completionStatus) {
3369 case PASSTHRU_STATUS_COMPLETE:
3370 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3371 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3374 data = task_data->resp_buffer + hdr_len;
3375 data_len = task_data->resp_len - hdr_len;
3376 iscsi_complete_pdu(conn, hdr, data, data_len);
3379 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3380 sts->completionStatus);
3386 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3388 struct ql4_task_data *task_data;
3389 struct iscsi_session *sess;
3390 struct ddb_entry *ddb_entry;
3391 struct scsi_qla_host *ha;
3394 sess = task->conn->session;
3395 ddb_entry = sess->dd_data;
3397 task_data = task->dd_data;
3398 memset(task_data, 0, sizeof(struct ql4_task_data));
3401 ql4_printk(KERN_INFO, ha,
3402 "%s: SCSI Commands not implemented\n", __func__);
3406 hdr_len = sizeof(struct iscsi_hdr);
3408 task_data->task = task;
3410 if (task->data_count) {
3411 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3416 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3417 __func__, task->conn->max_recv_dlength, hdr_len));
3419 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3420 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3421 task_data->resp_len,
3422 &task_data->resp_dma,
3424 if (!task_data->resp_buffer)
3425 goto exit_alloc_pdu;
3427 task_data->req_len = task->data_count + hdr_len;
3428 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3430 &task_data->req_dma,
3432 if (!task_data->req_buffer)
3433 goto exit_alloc_pdu;
3435 task->hdr = task_data->req_buffer;
3437 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3442 if (task_data->resp_buffer)
3443 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3444 task_data->resp_buffer, task_data->resp_dma);
3446 if (task_data->req_buffer)
3447 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3448 task_data->req_buffer, task_data->req_dma);
3452 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3454 struct ql4_task_data *task_data;
3455 struct iscsi_session *sess;
3456 struct ddb_entry *ddb_entry;
3457 struct scsi_qla_host *ha;
3460 hdr_len = sizeof(struct iscsi_hdr);
3461 sess = task->conn->session;
3462 ddb_entry = sess->dd_data;
3464 task_data = task->dd_data;
3466 if (task->data_count) {
3467 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3468 task->data_count, DMA_TO_DEVICE);
3471 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3472 __func__, task->conn->max_recv_dlength, hdr_len));
3474 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3475 task_data->resp_buffer, task_data->resp_dma);
3476 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3477 task_data->req_buffer, task_data->req_dma);
3481 static int qla4xxx_task_xmit(struct iscsi_task *task)
3483 struct scsi_cmnd *sc = task->sc;
3484 struct iscsi_session *sess = task->conn->session;
3485 struct ddb_entry *ddb_entry = sess->dd_data;
3486 struct scsi_qla_host *ha = ddb_entry->ha;
3489 return qla4xxx_send_passthru0(task);
3491 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3496 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3497 struct iscsi_bus_flash_conn *conn,
3498 struct dev_db_entry *fw_ddb_entry)
3500 unsigned long options = 0;
3503 options = le16_to_cpu(fw_ddb_entry->options);
3504 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3505 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3506 rc = iscsi_switch_str_param(&sess->portal_type,
3511 rc = iscsi_switch_str_param(&sess->portal_type,
3517 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3519 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3520 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3522 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3523 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3524 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3525 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3526 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3527 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3529 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3530 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3531 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3532 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3534 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3535 sess->discovery_auth_optional =
3536 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3537 if (test_bit(ISCSIOPT_ERL1, &options))
3539 if (test_bit(ISCSIOPT_ERL0, &options))
3542 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3543 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3544 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3545 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3546 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3547 conn->tcp_timer_scale |= BIT_3;
3548 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3549 conn->tcp_timer_scale |= BIT_2;
3550 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3551 conn->tcp_timer_scale |= BIT_1;
3553 conn->tcp_timer_scale >>= 1;
3554 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3556 options = le16_to_cpu(fw_ddb_entry->ip_options);
3557 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3559 conn->max_recv_dlength = BYTE_UNITS *
3560 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3561 conn->max_xmit_dlength = BYTE_UNITS *
3562 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3563 sess->first_burst = BYTE_UNITS *
3564 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3565 sess->max_burst = BYTE_UNITS *
3566 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3567 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3568 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3569 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3570 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3571 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3572 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3573 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3574 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3575 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3576 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3577 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3578 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3579 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3580 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3581 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3582 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3584 sess->default_taskmgmt_timeout =
3585 le16_to_cpu(fw_ddb_entry->def_timeout);
3586 conn->port = le16_to_cpu(fw_ddb_entry->port);
3588 options = le16_to_cpu(fw_ddb_entry->options);
3589 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3590 if (!conn->ipaddress) {
3595 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3596 if (!conn->redirect_ipaddr) {
3601 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3602 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3604 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3605 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3607 conn->link_local_ipv6_addr = kmemdup(
3608 fw_ddb_entry->link_local_ipv6_addr,
3609 IPv6_ADDR_LEN, GFP_KERNEL);
3610 if (!conn->link_local_ipv6_addr) {
3615 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3618 if (fw_ddb_entry->iscsi_name[0]) {
3619 rc = iscsi_switch_str_param(&sess->targetname,
3620 (char *)fw_ddb_entry->iscsi_name);
3625 if (fw_ddb_entry->iscsi_alias[0]) {
3626 rc = iscsi_switch_str_param(&sess->targetalias,
3627 (char *)fw_ddb_entry->iscsi_alias);
3632 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3638 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3639 struct iscsi_bus_flash_conn *conn,
3640 struct dev_db_entry *fw_ddb_entry)
3645 options = le16_to_cpu(fw_ddb_entry->options);
3646 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3647 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3652 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3653 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3654 SET_BITVAL(sess->entry_state, options, BIT_3);
3655 fw_ddb_entry->options = cpu_to_le16(options);
3657 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3658 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3659 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3660 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3661 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3662 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3663 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3664 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3665 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3666 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3667 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3668 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3669 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3670 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3671 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3673 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3674 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3675 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3676 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3677 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3678 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3679 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3680 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3681 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3683 options = le16_to_cpu(fw_ddb_entry->ip_options);
3684 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3685 fw_ddb_entry->ip_options = cpu_to_le16(options);
3687 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3688 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3689 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3690 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3691 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3692 fw_ddb_entry->iscsi_first_burst_len =
3693 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3694 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3696 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3697 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3698 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3699 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3700 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3701 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3702 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3703 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3704 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3705 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3706 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3707 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3708 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3709 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3710 fw_ddb_entry->port = cpu_to_le16(conn->port);
3711 fw_ddb_entry->def_timeout =
3712 cpu_to_le16(sess->default_taskmgmt_timeout);
3714 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3715 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3717 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3719 if (conn->ipaddress)
3720 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3721 sizeof(fw_ddb_entry->ip_addr));
3723 if (conn->redirect_ipaddr)
3724 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3725 sizeof(fw_ddb_entry->tgt_addr));
3727 if (conn->link_local_ipv6_addr)
3728 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3729 conn->link_local_ipv6_addr,
3730 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3732 if (sess->targetname)
3733 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3734 sizeof(fw_ddb_entry->iscsi_name));
3736 if (sess->targetalias)
3737 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3738 sizeof(fw_ddb_entry->iscsi_alias));
3740 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3745 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3746 struct iscsi_session *sess,
3747 struct dev_db_entry *fw_ddb_entry)
3749 unsigned long options = 0;
3751 uint16_t disc_parent;
3752 char ip_addr[DDB_IPADDR_LEN];
3754 options = le16_to_cpu(fw_ddb_entry->options);
3755 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3756 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3758 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3760 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3761 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3762 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3763 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3764 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3765 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3767 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3768 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3769 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3771 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3772 sess->discovery_auth_optional =
3773 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3774 if (test_bit(ISCSIOPT_ERL1, &options))
3776 if (test_bit(ISCSIOPT_ERL0, &options))
3779 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3780 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3781 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3782 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3783 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3784 conn->tcp_timer_scale |= BIT_3;
3785 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3786 conn->tcp_timer_scale |= BIT_2;
3787 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3788 conn->tcp_timer_scale |= BIT_1;
3790 conn->tcp_timer_scale >>= 1;
3791 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3793 options = le16_to_cpu(fw_ddb_entry->ip_options);
3794 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3796 conn->max_recv_dlength = BYTE_UNITS *
3797 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3798 conn->max_xmit_dlength = BYTE_UNITS *
3799 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3800 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3801 sess->first_burst = BYTE_UNITS *
3802 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3803 sess->max_burst = BYTE_UNITS *
3804 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3805 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3806 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3807 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3808 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3809 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3810 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3811 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3812 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3813 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3814 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3815 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3816 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3817 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3819 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3820 if (ddb_link == DDB_ISNS)
3821 disc_parent = ISCSI_DISC_PARENT_ISNS;
3822 else if (ddb_link == DDB_NO_LINK)
3823 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3824 else if (ddb_link < MAX_DDB_ENTRIES)
3825 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3827 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3829 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3830 iscsi_get_discovery_parent_name(disc_parent), 0);
3832 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3833 (char *)fw_ddb_entry->iscsi_alias, 0);
3835 options = le16_to_cpu(fw_ddb_entry->options);
3836 if (options & DDB_OPT_IPV6_DEVICE) {
3837 memset(ip_addr, 0, sizeof(ip_addr));
3838 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3839 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3840 (char *)ip_addr, 0);
3844 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3845 struct dev_db_entry *fw_ddb_entry,
3846 struct iscsi_cls_session *cls_sess,
3847 struct iscsi_cls_conn *cls_conn)
3850 struct iscsi_session *sess;
3851 struct ddb_entry *ddb_entry;
3852 struct ql4_chap_table chap_tbl;
3853 struct iscsi_conn *conn;
3854 char ip_addr[DDB_IPADDR_LEN];
3855 uint16_t options = 0;
3857 sess = cls_sess->dd_data;
3858 ddb_entry = sess->dd_data;
3859 conn = cls_conn->dd_data;
3860 memset(&chap_tbl, 0, sizeof(chap_tbl));
3862 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3864 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3866 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3867 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3869 memset(ip_addr, 0, sizeof(ip_addr));
3870 options = le16_to_cpu(fw_ddb_entry->options);
3871 if (options & DDB_OPT_IPV6_DEVICE) {
3872 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3874 memset(ip_addr, 0, sizeof(ip_addr));
3875 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3877 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3878 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3881 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3882 (char *)ip_addr, buflen);
3883 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3884 (char *)fw_ddb_entry->iscsi_name, buflen);
3885 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3886 (char *)ha->name_string, buflen);
3888 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3889 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3891 ddb_entry->chap_tbl_idx)) {
3892 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3893 (char *)chap_tbl.name,
3894 strlen((char *)chap_tbl.name));
3895 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3896 (char *)chap_tbl.secret,
3897 chap_tbl.secret_len);
3902 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3903 struct ddb_entry *ddb_entry)
3905 struct iscsi_cls_session *cls_sess;
3906 struct iscsi_cls_conn *cls_conn;
3908 dma_addr_t fw_ddb_entry_dma;
3909 struct dev_db_entry *fw_ddb_entry;
3911 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3912 &fw_ddb_entry_dma, GFP_KERNEL);
3913 if (!fw_ddb_entry) {
3914 ql4_printk(KERN_ERR, ha,
3915 "%s: Unable to allocate dma buffer\n", __func__);
3916 goto exit_session_conn_fwddb_param;
3919 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3920 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3921 NULL, NULL, NULL) == QLA_ERROR) {
3922 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3923 "get_ddb_entry for fw_ddb_index %d\n",
3924 ha->host_no, __func__,
3925 ddb_entry->fw_ddb_index));
3926 goto exit_session_conn_fwddb_param;
3929 cls_sess = ddb_entry->sess;
3931 cls_conn = ddb_entry->conn;
3934 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3936 exit_session_conn_fwddb_param:
3938 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3939 fw_ddb_entry, fw_ddb_entry_dma);
3942 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3943 struct ddb_entry *ddb_entry)
3945 struct iscsi_cls_session *cls_sess;
3946 struct iscsi_cls_conn *cls_conn;
3947 struct iscsi_session *sess;
3948 struct iscsi_conn *conn;
3950 dma_addr_t fw_ddb_entry_dma;
3951 struct dev_db_entry *fw_ddb_entry;
3953 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3954 &fw_ddb_entry_dma, GFP_KERNEL);
3955 if (!fw_ddb_entry) {
3956 ql4_printk(KERN_ERR, ha,
3957 "%s: Unable to allocate dma buffer\n", __func__);
3958 goto exit_session_conn_param;
3961 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3962 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3963 NULL, NULL, NULL) == QLA_ERROR) {
3964 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3965 "get_ddb_entry for fw_ddb_index %d\n",
3966 ha->host_no, __func__,
3967 ddb_entry->fw_ddb_index));
3968 goto exit_session_conn_param;
3971 cls_sess = ddb_entry->sess;
3972 sess = cls_sess->dd_data;
3974 cls_conn = ddb_entry->conn;
3975 conn = cls_conn->dd_data;
3977 /* Update timers after login */
3978 ddb_entry->default_relogin_timeout =
3979 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3980 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3981 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3982 ddb_entry->default_time2wait =
3983 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3986 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3987 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3989 memcpy(sess->initiatorname, ha->name_string,
3990 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3992 exit_session_conn_param:
3994 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3995 fw_ddb_entry, fw_ddb_entry_dma);
4001 static void qla4xxx_timer(struct timer_list *t);
4003 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
4004 unsigned long interval)
4006 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
4007 __func__, ha->host->host_no));
4008 timer_setup(&ha->timer, qla4xxx_timer, 0);
4009 ha->timer.expires = jiffies + interval * HZ;
4010 add_timer(&ha->timer);
4011 ha->timer_active = 1;
4014 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4016 del_timer_sync(&ha->timer);
4017 ha->timer_active = 0;
4021 * qla4xxx_mark_device_missing - blocks the session
4022 * @cls_session: Pointer to the session to be blocked
4023 * @ddb_entry: Pointer to device database entry
4025 * This routine marks a device missing and close connection.
4027 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4029 iscsi_block_session(cls_session);
4033 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4034 * @ha: Pointer to host adapter structure.
4036 * This routine marks a device missing and resets the relogin retry count.
4038 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4040 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4043 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4044 struct ddb_entry *ddb_entry,
4045 struct scsi_cmnd *cmd)
4049 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4053 kref_init(&srb->srb_ref);
4055 srb->ddb = ddb_entry;
4058 CMD_SP(cmd) = (void *)srb;
4063 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4065 struct scsi_cmnd *cmd = srb->cmd;
4067 if (srb->flags & SRB_DMA_VALID) {
4068 scsi_dma_unmap(cmd);
4069 srb->flags &= ~SRB_DMA_VALID;
4074 void qla4xxx_srb_compl(struct kref *ref)
4076 struct srb *srb = container_of(ref, struct srb, srb_ref);
4077 struct scsi_cmnd *cmd = srb->cmd;
4078 struct scsi_qla_host *ha = srb->ha;
4080 qla4xxx_srb_free_dma(ha, srb);
4082 mempool_free(srb, ha->srb_mempool);
4084 cmd->scsi_done(cmd);
4088 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4090 * @cmd: Pointer to Linux's SCSI command structure
4093 * This routine is invoked by Linux to send a SCSI command to the driver.
4094 * The mid-level driver tries to ensure that queuecommand never gets
4095 * invoked concurrently with itself or the interrupt handler (although
4096 * the interrupt handler may call this routine as part of request-
4097 * completion handling). Unfortunely, it sometimes calls the scheduler
4098 * in interrupt context which is a big NO! NO!.
4100 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4102 struct scsi_qla_host *ha = to_qla_host(host);
4103 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4104 struct iscsi_cls_session *sess = ddb_entry->sess;
4108 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4109 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4110 cmd->result = DID_NO_CONNECT << 16;
4112 cmd->result = DID_REQUEUE << 16;
4113 goto qc_fail_command;
4117 cmd->result = DID_IMM_RETRY << 16;
4118 goto qc_fail_command;
4121 rval = iscsi_session_chkready(sess);
4124 goto qc_fail_command;
4127 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4128 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4129 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4130 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4131 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4132 !test_bit(AF_ONLINE, &ha->flags) ||
4133 !test_bit(AF_LINK_UP, &ha->flags) ||
4134 test_bit(AF_LOOPBACK, &ha->flags) ||
4135 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4136 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4137 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4140 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4144 rval = qla4xxx_send_command_to_isp(ha, srb);
4145 if (rval != QLA_SUCCESS)
4146 goto qc_host_busy_free_sp;
4150 qc_host_busy_free_sp:
4151 qla4xxx_srb_free_dma(ha, srb);
4152 mempool_free(srb, ha->srb_mempool);
4155 return SCSI_MLQUEUE_HOST_BUSY;
4158 cmd->scsi_done(cmd);
4164 * qla4xxx_mem_free - frees memory allocated to adapter
4165 * @ha: Pointer to host adapter structure.
4167 * Frees memory previously allocated by qla4xxx_mem_alloc
4169 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4172 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4180 ha->request_ring = NULL;
4181 ha->request_dma = 0;
4182 ha->response_ring = NULL;
4183 ha->response_dma = 0;
4184 ha->shadow_regs = NULL;
4185 ha->shadow_regs_dma = 0;
4187 ha->fw_dump_size = 0;
4189 /* Free srb pool. */
4190 mempool_destroy(ha->srb_mempool);
4191 ha->srb_mempool = NULL;
4193 dma_pool_destroy(ha->chap_dma_pool);
4195 vfree(ha->chap_list);
4196 ha->chap_list = NULL;
4198 dma_pool_destroy(ha->fw_ddb_dma_pool);
4200 /* release io space registers */
4201 if (is_qla8022(ha)) {
4204 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4205 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4208 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4209 } else if (ha->reg) {
4213 vfree(ha->reset_tmplt.buff);
4215 pci_release_regions(ha->pdev);
4219 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4220 * @ha: Pointer to host adapter structure
4222 * Allocates DMA memory for request and response queues. Also allocates memory
4225 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4227 unsigned long align;
4229 /* Allocate contiguous block of DMA memory for queues. */
4230 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4231 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4232 sizeof(struct shadow_regs) +
4234 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4235 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4236 &ha->queues_dma, GFP_KERNEL);
4237 if (ha->queues == NULL) {
4238 ql4_printk(KERN_WARNING, ha,
4239 "Memory Allocation failed - queues.\n");
4241 goto mem_alloc_error_exit;
4245 * As per RISC alignment requirements -- the bus-address must be a
4246 * multiple of the request-ring size (in bytes).
4249 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4250 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4251 (MEM_ALIGN_VALUE - 1));
4253 /* Update request and response queue pointers. */
4254 ha->request_dma = ha->queues_dma + align;
4255 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4256 ha->response_dma = ha->queues_dma + align +
4257 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4258 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4259 (REQUEST_QUEUE_DEPTH *
4261 ha->shadow_regs_dma = ha->queues_dma + align +
4262 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4263 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4264 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4265 (REQUEST_QUEUE_DEPTH *
4267 (RESPONSE_QUEUE_DEPTH *
4270 /* Allocate memory for srb pool. */
4271 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4272 mempool_free_slab, srb_cachep);
4273 if (ha->srb_mempool == NULL) {
4274 ql4_printk(KERN_WARNING, ha,
4275 "Memory Allocation failed - SRB Pool.\n");
4277 goto mem_alloc_error_exit;
4280 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4281 CHAP_DMA_BLOCK_SIZE, 8, 0);
4283 if (ha->chap_dma_pool == NULL) {
4284 ql4_printk(KERN_WARNING, ha,
4285 "%s: chap_dma_pool allocation failed..\n", __func__);
4286 goto mem_alloc_error_exit;
4289 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4290 DDB_DMA_BLOCK_SIZE, 8, 0);
4292 if (ha->fw_ddb_dma_pool == NULL) {
4293 ql4_printk(KERN_WARNING, ha,
4294 "%s: fw_ddb_dma_pool allocation failed..\n",
4296 goto mem_alloc_error_exit;
4301 mem_alloc_error_exit:
4306 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4307 * @ha: adapter block pointer.
4309 * Note: The caller should not hold the idc lock.
4311 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4313 uint32_t temp, temp_state, temp_val;
4314 int status = QLA_SUCCESS;
4316 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4318 temp_state = qla82xx_get_temp_state(temp);
4319 temp_val = qla82xx_get_temp_val(temp);
4321 if (temp_state == QLA82XX_TEMP_PANIC) {
4322 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4323 " exceeds maximum allowed. Hardware has been shut"
4324 " down.\n", temp_val);
4326 } else if (temp_state == QLA82XX_TEMP_WARN) {
4327 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4328 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4329 " degrees C exceeds operating range."
4330 " Immediate action needed.\n", temp_val);
4332 if (ha->temperature == QLA82XX_TEMP_WARN)
4333 ql4_printk(KERN_INFO, ha, "Device temperature is"
4334 " now %d degrees C in normal range.\n",
4337 ha->temperature = temp_state;
4342 * qla4_8xxx_check_fw_alive - Check firmware health
4343 * @ha: Pointer to host adapter structure.
4345 * Context: Interrupt
4347 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4349 uint32_t fw_heartbeat_counter;
4350 int status = QLA_SUCCESS;
4352 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4353 QLA8XXX_PEG_ALIVE_COUNTER);
4354 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4355 if (fw_heartbeat_counter == 0xffffffff) {
4356 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4357 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4358 ha->host_no, __func__));
4362 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4363 ha->seconds_since_last_heartbeat++;
4364 /* FW not alive after 2 seconds */
4365 if (ha->seconds_since_last_heartbeat == 2) {
4366 ha->seconds_since_last_heartbeat = 0;
4367 qla4_8xxx_dump_peg_reg(ha);
4371 ha->seconds_since_last_heartbeat = 0;
4373 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4377 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4379 uint32_t halt_status;
4380 int halt_status_unrecoverable = 0;
4382 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4384 if (is_qla8022(ha)) {
4385 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4387 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4388 CRB_NIU_XG_PAUSE_CTL_P0 |
4389 CRB_NIU_XG_PAUSE_CTL_P1);
4391 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4392 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4394 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4395 halt_status_unrecoverable = 1;
4396 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4397 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4398 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4400 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4401 halt_status_unrecoverable = 1;
4405 * Since we cannot change dev_state in interrupt context,
4406 * set appropriate DPC flag then wakeup DPC
4408 if (halt_status_unrecoverable) {
4409 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4411 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4413 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4415 qla4xxx_mailbox_premature_completion(ha);
4416 qla4xxx_wake_dpc(ha);
4420 * qla4_8xxx_watchdog - Poll dev state
4421 * @ha: Pointer to host adapter structure.
4423 * Context: Interrupt
4425 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4430 if (is_qla8032(ha) &&
4431 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4432 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4433 __func__, ha->func_num);
4435 /* don't poll if reset is going on */
4436 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4437 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4438 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4439 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4441 if (qla4_8xxx_check_temp(ha)) {
4442 if (is_qla8022(ha)) {
4443 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4444 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4445 CRB_NIU_XG_PAUSE_CTL_P0 |
4446 CRB_NIU_XG_PAUSE_CTL_P1);
4448 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4449 qla4xxx_wake_dpc(ha);
4450 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4451 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4453 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4456 if (is_qla8032(ha) || is_qla8042(ha)) {
4457 idc_ctrl = qla4_83xx_rd_reg(ha,
4458 QLA83XX_IDC_DRV_CTRL);
4459 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4460 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4462 qla4xxx_mailbox_premature_completion(
4467 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4468 (is_qla8022(ha) && !ql4xdontresethba)) {
4469 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4470 qla4xxx_wake_dpc(ha);
4472 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4473 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4474 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4476 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4477 qla4xxx_wake_dpc(ha);
4479 /* Check firmware health */
4480 if (qla4_8xxx_check_fw_alive(ha))
4481 qla4_8xxx_process_fw_error(ha);
4486 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4488 struct iscsi_session *sess;
4489 struct ddb_entry *ddb_entry;
4490 struct scsi_qla_host *ha;
4492 sess = cls_sess->dd_data;
4493 ddb_entry = sess->dd_data;
4496 if (!(ddb_entry->ddb_type == FLASH_DDB))
4499 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4500 !iscsi_is_session_online(cls_sess)) {
4501 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4503 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4505 atomic_set(&ddb_entry->retry_relogin_timer,
4507 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4508 set_bit(DF_RELOGIN, &ddb_entry->flags);
4509 DEBUG2(ql4_printk(KERN_INFO, ha,
4510 "%s: index [%d] login device\n",
4511 __func__, ddb_entry->fw_ddb_index));
4513 atomic_dec(&ddb_entry->retry_relogin_timer);
4517 /* Wait for relogin to timeout */
4518 if (atomic_read(&ddb_entry->relogin_timer) &&
4519 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4521 * If the relogin times out and the device is
4522 * still NOT ONLINE then try and relogin again.
4524 if (!iscsi_is_session_online(cls_sess)) {
4525 /* Reset retry relogin timer */
4526 atomic_inc(&ddb_entry->relogin_retry_count);
4527 DEBUG2(ql4_printk(KERN_INFO, ha,
4528 "%s: index[%d] relogin timed out-retrying"
4529 " relogin (%d), retry (%d)\n", __func__,
4530 ddb_entry->fw_ddb_index,
4531 atomic_read(&ddb_entry->relogin_retry_count),
4532 ddb_entry->default_time2wait + 4));
4533 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4534 atomic_set(&ddb_entry->retry_relogin_timer,
4535 ddb_entry->default_time2wait + 4);
4541 * qla4xxx_timer - checks every second for work to do.
4542 * @t: Context to obtain pointer to host adapter structure.
4544 static void qla4xxx_timer(struct timer_list *t)
4546 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4550 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4552 /* If we are in the middle of AER/EEH processing
4553 * skip any processing and reschedule the timer
4555 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4556 mod_timer(&ha->timer, jiffies + HZ);
4560 /* Hardware read to trigger an EEH error during mailbox waits. */
4561 if (!pci_channel_offline(ha->pdev))
4562 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4565 qla4_8xxx_watchdog(ha);
4567 if (is_qla40XX(ha)) {
4568 /* Check for heartbeat interval. */
4569 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4570 ha->heartbeat_interval != 0) {
4571 ha->seconds_since_last_heartbeat++;
4572 if (ha->seconds_since_last_heartbeat >
4573 ha->heartbeat_interval + 2)
4574 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4578 /* Process any deferred work. */
4579 if (!list_empty(&ha->work_list))
4582 /* Wakeup the dpc routine for this adapter, if needed. */
4584 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4585 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4586 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4587 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4588 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4589 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4590 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4591 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4592 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4593 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4594 test_bit(DPC_AEN, &ha->dpc_flags)) {
4595 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4596 " - dpc flags = 0x%lx\n",
4597 ha->host_no, __func__, ha->dpc_flags));
4598 qla4xxx_wake_dpc(ha);
4601 /* Reschedule timer thread to call us back in one second */
4602 mod_timer(&ha->timer, jiffies + HZ);
4604 DEBUG2(ha->seconds_since_last_intr++);
4608 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4609 * @ha: Pointer to host adapter structure.
4611 * This routine stalls the driver until all outstanding commands are returned.
4612 * Caller must release the Hardware Lock prior to calling this routine.
4614 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4617 unsigned long flags;
4618 struct scsi_cmnd *cmd;
4619 unsigned long wtime;
4623 wtmo = WAIT_CMD_TOV;
4625 wtmo = ha->nx_reset_timeout / 2;
4627 wtime = jiffies + (wtmo * HZ);
4629 DEBUG2(ql4_printk(KERN_INFO, ha,
4630 "Wait up to %u seconds for cmds to complete\n",
4633 while (!time_after_eq(jiffies, wtime)) {
4634 spin_lock_irqsave(&ha->hardware_lock, flags);
4635 /* Find a command that hasn't completed. */
4636 for (index = 0; index < ha->host->can_queue; index++) {
4637 cmd = scsi_host_find_tag(ha->host, index);
4639 * We cannot just check if the index is valid,
4640 * becase if we are run from the scsi eh, then
4641 * the scsi/block layer is going to prevent
4642 * the tag from being released.
4644 if (cmd != NULL && CMD_SP(cmd))
4647 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4649 /* If No Commands are pending, wait is complete */
4650 if (index == ha->host->can_queue)
4655 /* If we timed out on waiting for commands to come back
4660 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4662 uint32_t ctrl_status;
4663 unsigned long flags = 0;
4665 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4667 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4670 spin_lock_irqsave(&ha->hardware_lock, flags);
4673 * If the SCSI Reset Interrupt bit is set, clear it.
4674 * Otherwise, the Soft Reset won't work.
4676 ctrl_status = readw(&ha->reg->ctrl_status);
4677 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4678 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4680 /* Issue Soft Reset */
4681 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4682 readl(&ha->reg->ctrl_status);
4684 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4689 * qla4xxx_soft_reset - performs soft reset.
4690 * @ha: Pointer to host adapter structure.
4692 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4694 uint32_t max_wait_time;
4695 unsigned long flags = 0;
4697 uint32_t ctrl_status;
4699 status = qla4xxx_hw_reset(ha);
4700 if (status != QLA_SUCCESS)
4704 /* Wait until the Network Reset Intr bit is cleared */
4705 max_wait_time = RESET_INTR_TOV;
4707 spin_lock_irqsave(&ha->hardware_lock, flags);
4708 ctrl_status = readw(&ha->reg->ctrl_status);
4709 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4711 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4715 } while ((--max_wait_time));
4717 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4718 DEBUG2(printk(KERN_WARNING
4719 "scsi%ld: Network Reset Intr not cleared by "
4720 "Network function, clearing it now!\n",
4722 spin_lock_irqsave(&ha->hardware_lock, flags);
4723 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4724 readl(&ha->reg->ctrl_status);
4725 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4728 /* Wait until the firmware tells us the Soft Reset is done */
4729 max_wait_time = SOFT_RESET_TOV;
4731 spin_lock_irqsave(&ha->hardware_lock, flags);
4732 ctrl_status = readw(&ha->reg->ctrl_status);
4733 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4735 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4736 status = QLA_SUCCESS;
4741 } while ((--max_wait_time));
4744 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4745 * after the soft reset has taken place.
4747 spin_lock_irqsave(&ha->hardware_lock, flags);
4748 ctrl_status = readw(&ha->reg->ctrl_status);
4749 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4750 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4751 readl(&ha->reg->ctrl_status);
4753 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4755 /* If soft reset fails then most probably the bios on other
4756 * function is also enabled.
4757 * Since the initialization is sequential the other fn
4758 * wont be able to acknowledge the soft reset.
4759 * Issue a force soft reset to workaround this scenario.
4761 if (max_wait_time == 0) {
4762 /* Issue Force Soft Reset */
4763 spin_lock_irqsave(&ha->hardware_lock, flags);
4764 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4765 readl(&ha->reg->ctrl_status);
4766 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4767 /* Wait until the firmware tells us the Soft Reset is done */
4768 max_wait_time = SOFT_RESET_TOV;
4770 spin_lock_irqsave(&ha->hardware_lock, flags);
4771 ctrl_status = readw(&ha->reg->ctrl_status);
4772 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4774 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4775 status = QLA_SUCCESS;
4780 } while ((--max_wait_time));
4787 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4788 * @ha: Pointer to host adapter structure.
4789 * @res: returned scsi status
4791 * This routine is called just prior to a HARD RESET to return all
4792 * outstanding commands back to the Operating System.
4793 * Caller should make sure that the following locks are released
4794 * before this calling routine: Hardware lock, and io_request_lock.
4796 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4800 unsigned long flags;
4802 spin_lock_irqsave(&ha->hardware_lock, flags);
4803 for (i = 0; i < ha->host->can_queue; i++) {
4804 srb = qla4xxx_del_from_active_array(ha, i);
4806 srb->cmd->result = res;
4807 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4810 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4813 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4815 clear_bit(AF_ONLINE, &ha->flags);
4817 /* Disable the board */
4818 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4820 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4821 qla4xxx_mark_all_devices_missing(ha);
4822 clear_bit(AF_INIT_DONE, &ha->flags);
4825 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4827 struct iscsi_session *sess;
4828 struct ddb_entry *ddb_entry;
4830 sess = cls_session->dd_data;
4831 ddb_entry = sess->dd_data;
4832 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4834 if (ddb_entry->ddb_type == FLASH_DDB)
4835 iscsi_block_session(ddb_entry->sess);
4837 iscsi_session_failure(cls_session->dd_data,
4838 ISCSI_ERR_CONN_FAILED);
4842 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4843 * @ha: Pointer to host adapter structure.
4845 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4847 int status = QLA_ERROR;
4848 uint8_t reset_chip = 0;
4852 /* Stall incoming I/O until we are done */
4853 scsi_block_requests(ha->host);
4854 clear_bit(AF_ONLINE, &ha->flags);
4855 clear_bit(AF_LINK_UP, &ha->flags);
4857 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4859 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4861 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4862 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4863 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4865 /* disable pause frame for ISP83xx */
4866 qla4_83xx_disable_pause(ha);
4869 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4871 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4874 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4875 * do not reset adapter, jump to initialize_adapter */
4876 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4877 status = QLA_SUCCESS;
4878 goto recover_ha_init_adapter;
4881 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4882 * from eh_host_reset or ioctl module */
4883 if (is_qla80XX(ha) && !reset_chip &&
4884 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4886 DEBUG2(ql4_printk(KERN_INFO, ha,
4887 "scsi%ld: %s - Performing stop_firmware...\n",
4888 ha->host_no, __func__));
4889 status = ha->isp_ops->reset_firmware(ha);
4890 if (status == QLA_SUCCESS) {
4891 ha->isp_ops->disable_intrs(ha);
4892 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4893 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4895 /* If the stop_firmware fails then
4896 * reset the entire chip */
4898 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4899 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4903 /* Issue full chip reset if recovering from a catastrophic error,
4904 * or if stop_firmware fails for ISP-8xxx.
4905 * This is the default case for ISP-4xxx */
4906 if (is_qla40XX(ha) || reset_chip) {
4910 /* Check if 8XXX firmware is alive or not
4911 * We may have arrived here from NEED_RESET
4913 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4916 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4917 while (time_before(jiffies, wait)) {
4918 if (qla4_8xxx_check_fw_alive(ha)) {
4919 qla4xxx_mailbox_premature_completion(ha);
4923 set_current_state(TASK_UNINTERRUPTIBLE);
4924 schedule_timeout(HZ);
4927 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4928 qla4xxx_cmd_wait(ha);
4930 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4931 DEBUG2(ql4_printk(KERN_INFO, ha,
4932 "scsi%ld: %s - Performing chip reset..\n",
4933 ha->host_no, __func__));
4934 status = ha->isp_ops->reset_chip(ha);
4935 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4938 /* Flush any pending ddb changed AENs */
4939 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4941 recover_ha_init_adapter:
4942 /* Upon successful firmware/chip reset, re-initialize the adapter */
4943 if (status == QLA_SUCCESS) {
4944 /* For ISP-4xxx, force function 1 to always initialize
4945 * before function 3 to prevent both funcions from
4946 * stepping on top of the other */
4947 if (is_qla40XX(ha) && (ha->mac_index == 3))
4950 /* NOTE: AF_ONLINE flag set upon successful completion of
4951 * qla4xxx_initialize_adapter */
4952 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4953 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4954 status = qla4_8xxx_check_init_adapter_retry(ha);
4955 if (status == QLA_ERROR) {
4956 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4957 ha->host_no, __func__);
4958 qla4xxx_dead_adapter_cleanup(ha);
4959 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4960 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4961 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4968 /* Retry failed adapter initialization, if necessary
4969 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4970 * case to prevent ping-pong resets between functions */
4971 if (!test_bit(AF_ONLINE, &ha->flags) &&
4972 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4973 /* Adapter initialization failed, see if we can retry
4975 * Since we don't want to block the DPC for too long
4976 * with multiple resets in the same thread,
4977 * utilize DPC to retry */
4978 if (is_qla80XX(ha)) {
4979 ha->isp_ops->idc_lock(ha);
4980 dev_state = qla4_8xxx_rd_direct(ha,
4981 QLA8XXX_CRB_DEV_STATE);
4982 ha->isp_ops->idc_unlock(ha);
4983 if (dev_state == QLA8XXX_DEV_FAILED) {
4984 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4985 "recover adapter. H/W is in Failed "
4986 "state\n", __func__);
4987 qla4xxx_dead_adapter_cleanup(ha);
4988 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4989 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4990 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4998 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4999 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
5000 DEBUG2(printk("scsi%ld: recover adapter - retrying "
5001 "(%d) more times\n", ha->host_no,
5002 ha->retry_reset_ha_cnt));
5003 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5006 if (ha->retry_reset_ha_cnt > 0) {
5007 /* Schedule another Reset HA--DPC will retry */
5008 ha->retry_reset_ha_cnt--;
5009 DEBUG2(printk("scsi%ld: recover adapter - "
5010 "retry remaining %d\n",
5012 ha->retry_reset_ha_cnt));
5016 if (ha->retry_reset_ha_cnt == 0) {
5017 /* Recover adapter retries have been exhausted.
5019 DEBUG2(printk("scsi%ld: recover adapter "
5020 "failed - board disabled\n",
5022 qla4xxx_dead_adapter_cleanup(ha);
5023 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5024 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5025 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5031 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5032 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5033 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5037 ha->adapter_error_count++;
5039 if (test_bit(AF_ONLINE, &ha->flags))
5040 ha->isp_ops->enable_intrs(ha);
5042 scsi_unblock_requests(ha->host);
5044 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5045 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5046 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5051 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5053 struct iscsi_session *sess;
5054 struct ddb_entry *ddb_entry;
5055 struct scsi_qla_host *ha;
5057 sess = cls_session->dd_data;
5058 ddb_entry = sess->dd_data;
5060 if (!iscsi_is_session_online(cls_session)) {
5061 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5062 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5063 " unblock session\n", ha->host_no, __func__,
5064 ddb_entry->fw_ddb_index);
5065 iscsi_unblock_session(ddb_entry->sess);
5067 /* Trigger relogin */
5068 if (ddb_entry->ddb_type == FLASH_DDB) {
5069 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5070 test_bit(DF_DISABLE_RELOGIN,
5071 &ddb_entry->flags)))
5072 qla4xxx_arm_relogin_timer(ddb_entry);
5074 iscsi_session_failure(cls_session->dd_data,
5075 ISCSI_ERR_CONN_FAILED);
5080 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5082 struct iscsi_session *sess;
5083 struct ddb_entry *ddb_entry;
5084 struct scsi_qla_host *ha;
5086 sess = cls_session->dd_data;
5087 ddb_entry = sess->dd_data;
5089 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5090 " unblock session\n", ha->host_no, __func__,
5091 ddb_entry->fw_ddb_index);
5093 iscsi_unblock_session(ddb_entry->sess);
5095 /* Start scan target */
5096 if (test_bit(AF_ONLINE, &ha->flags)) {
5097 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5098 " start scan\n", ha->host_no, __func__,
5099 ddb_entry->fw_ddb_index);
5100 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5105 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5107 struct iscsi_session *sess;
5108 struct ddb_entry *ddb_entry;
5109 struct scsi_qla_host *ha;
5110 int status = QLA_SUCCESS;
5112 sess = cls_session->dd_data;
5113 ddb_entry = sess->dd_data;
5115 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5116 " unblock user space session\n", ha->host_no, __func__,
5117 ddb_entry->fw_ddb_index);
5119 if (!iscsi_is_session_online(cls_session)) {
5120 iscsi_conn_start(ddb_entry->conn);
5121 iscsi_conn_login_event(ddb_entry->conn,
5122 ISCSI_CONN_STATE_LOGGED_IN);
5124 ql4_printk(KERN_INFO, ha,
5125 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5126 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5134 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5136 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5139 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5141 uint16_t relogin_timer;
5142 struct iscsi_session *sess;
5143 struct ddb_entry *ddb_entry;
5144 struct scsi_qla_host *ha;
5146 sess = cls_sess->dd_data;
5147 ddb_entry = sess->dd_data;
5150 relogin_timer = max(ddb_entry->default_relogin_timeout,
5151 (uint16_t)RELOGIN_TOV);
5152 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5154 DEBUG2(ql4_printk(KERN_INFO, ha,
5155 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5156 ddb_entry->fw_ddb_index, relogin_timer));
5158 qla4xxx_login_flash_ddb(cls_sess);
5161 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5163 struct iscsi_session *sess;
5164 struct ddb_entry *ddb_entry;
5165 struct scsi_qla_host *ha;
5167 sess = cls_sess->dd_data;
5168 ddb_entry = sess->dd_data;
5171 if (!(ddb_entry->ddb_type == FLASH_DDB))
5174 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5177 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5178 !iscsi_is_session_online(cls_sess)) {
5179 DEBUG2(ql4_printk(KERN_INFO, ha,
5180 "relogin issued\n"));
5181 qla4xxx_relogin_flash_ddb(cls_sess);
5185 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5188 queue_work(ha->dpc_thread, &ha->dpc_work);
5191 static struct qla4_work_evt *
5192 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5193 enum qla4_work_type type)
5195 struct qla4_work_evt *e;
5196 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5198 e = kzalloc(size, GFP_ATOMIC);
5202 INIT_LIST_HEAD(&e->list);
5207 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5208 struct qla4_work_evt *e)
5210 unsigned long flags;
5212 spin_lock_irqsave(&ha->work_lock, flags);
5213 list_add_tail(&e->list, &ha->work_list);
5214 spin_unlock_irqrestore(&ha->work_lock, flags);
5215 qla4xxx_wake_dpc(ha);
5218 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5219 enum iscsi_host_event_code aen_code,
5220 uint32_t data_size, uint8_t *data)
5222 struct qla4_work_evt *e;
5224 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5228 e->u.aen.code = aen_code;
5229 e->u.aen.data_size = data_size;
5230 memcpy(e->u.aen.data, data, data_size);
5232 qla4xxx_post_work(ha, e);
5237 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5238 uint32_t status, uint32_t pid,
5239 uint32_t data_size, uint8_t *data)
5241 struct qla4_work_evt *e;
5243 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5247 e->u.ping.status = status;
5248 e->u.ping.pid = pid;
5249 e->u.ping.data_size = data_size;
5250 memcpy(e->u.ping.data, data, data_size);
5252 qla4xxx_post_work(ha, e);
5257 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5259 struct qla4_work_evt *e, *tmp;
5260 unsigned long flags;
5263 spin_lock_irqsave(&ha->work_lock, flags);
5264 list_splice_init(&ha->work_list, &work);
5265 spin_unlock_irqrestore(&ha->work_lock, flags);
5267 list_for_each_entry_safe(e, tmp, &work, list) {
5268 list_del_init(&e->list);
5271 case QLA4_EVENT_AEN:
5272 iscsi_post_host_event(ha->host_no,
5273 &qla4xxx_iscsi_transport,
5278 case QLA4_EVENT_PING_STATUS:
5279 iscsi_ping_comp_event(ha->host_no,
5280 &qla4xxx_iscsi_transport,
5283 e->u.ping.data_size,
5287 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5288 "supported", e->type);
5295 * qla4xxx_do_dpc - dpc routine
5296 * @work: Context to obtain pointer to host adapter structure.
5298 * This routine is a task that is schedule by the interrupt handler
5299 * to perform the background processing for interrupts. We put it
5300 * on a task queue that is consumed whenever the scheduler runs; that's
5301 * so you can do anything (i.e. put the process to sleep etc). In fact,
5302 * the mid-level tries to sleep when it reaches the driver threshold
5303 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5305 static void qla4xxx_do_dpc(struct work_struct *work)
5307 struct scsi_qla_host *ha =
5308 container_of(work, struct scsi_qla_host, dpc_work);
5309 int status = QLA_ERROR;
5311 DEBUG2(ql4_printk(KERN_INFO, ha,
5312 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5313 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5315 /* Initialization not yet finished. Don't do anything yet. */
5316 if (!test_bit(AF_INIT_DONE, &ha->flags))
5319 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5320 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5321 ha->host_no, __func__, ha->flags));
5325 /* post events to application */
5326 qla4xxx_do_work(ha);
5328 if (is_qla80XX(ha)) {
5329 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5330 if (is_qla8032(ha) || is_qla8042(ha)) {
5331 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5333 /* disable pause frame for ISP83xx */
5334 qla4_83xx_disable_pause(ha);
5337 ha->isp_ops->idc_lock(ha);
5338 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5339 QLA8XXX_DEV_FAILED);
5340 ha->isp_ops->idc_unlock(ha);
5341 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5342 qla4_8xxx_device_state_handler(ha);
5345 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5346 if (is_qla8042(ha)) {
5347 if (ha->idc_info.info2 &
5348 ENABLE_INTERNAL_LOOPBACK) {
5349 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5351 status = qla4_84xx_config_acb(ha,
5352 ACB_CONFIG_DISABLE);
5353 if (status != QLA_SUCCESS) {
5354 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5359 qla4_83xx_post_idc_ack(ha);
5360 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5363 if (is_qla8042(ha) &&
5364 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5365 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5367 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5369 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5372 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5375 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5376 qla4_8xxx_need_qsnt_handler(ha);
5380 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5381 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5382 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5383 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5384 if ((is_qla8022(ha) && ql4xdontresethba) ||
5385 ((is_qla8032(ha) || is_qla8042(ha)) &&
5386 qla4_83xx_idc_dontreset(ha))) {
5387 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5388 ha->host_no, __func__));
5389 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5390 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5391 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5392 goto dpc_post_reset_ha;
5394 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5395 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5396 qla4xxx_recover_adapter(ha);
5398 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5399 uint8_t wait_time = RESET_INTR_TOV;
5401 while ((readw(&ha->reg->ctrl_status) &
5402 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5403 if (--wait_time == 0)
5408 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5409 "bit not cleared-- resetting\n",
5410 ha->host_no, __func__));
5411 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5412 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5413 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5414 status = qla4xxx_recover_adapter(ha);
5416 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5417 if (status == QLA_SUCCESS)
5418 ha->isp_ops->enable_intrs(ha);
5423 /* ---- process AEN? --- */
5424 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5425 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5427 /* ---- Get DHCP IP Address? --- */
5428 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5429 qla4xxx_get_dhcp_ip_address(ha);
5431 /* ---- relogin device? --- */
5432 if (adapter_up(ha) &&
5433 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5434 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5437 /* ---- link change? --- */
5438 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5439 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5440 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5441 /* ---- link down? --- */
5442 qla4xxx_mark_all_devices_missing(ha);
5444 /* ---- link up? --- *
5445 * F/W will auto login to all devices ONLY ONCE after
5446 * link up during driver initialization and runtime
5447 * fatal error recovery. Therefore, the driver must
5448 * manually relogin to devices when recovering from
5449 * connection failures, logouts, expired KATO, etc. */
5450 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5451 qla4xxx_build_ddb_list(ha, ha->is_reset);
5452 iscsi_host_for_each_session(ha->host,
5453 qla4xxx_login_flash_ddb);
5455 qla4xxx_relogin_all_devices(ha);
5458 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5459 if (qla4xxx_sysfs_ddb_export(ha))
5460 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5466 * qla4xxx_free_adapter - release the adapter
5467 * @ha: pointer to adapter structure
5469 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5471 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5473 /* Turn-off interrupts on the card. */
5474 ha->isp_ops->disable_intrs(ha);
5476 if (is_qla40XX(ha)) {
5477 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5478 &ha->reg->ctrl_status);
5479 readl(&ha->reg->ctrl_status);
5480 } else if (is_qla8022(ha)) {
5481 writel(0, &ha->qla4_82xx_reg->host_int);
5482 readl(&ha->qla4_82xx_reg->host_int);
5483 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5484 writel(0, &ha->qla4_83xx_reg->risc_intr);
5485 readl(&ha->qla4_83xx_reg->risc_intr);
5488 /* Remove timer thread, if present */
5489 if (ha->timer_active)
5490 qla4xxx_stop_timer(ha);
5492 /* Kill the kernel thread for this host */
5494 destroy_workqueue(ha->dpc_thread);
5496 /* Kill the kernel thread for this host */
5498 destroy_workqueue(ha->task_wq);
5500 /* Put firmware in known state */
5501 ha->isp_ops->reset_firmware(ha);
5503 if (is_qla80XX(ha)) {
5504 ha->isp_ops->idc_lock(ha);
5505 qla4_8xxx_clear_drv_active(ha);
5506 ha->isp_ops->idc_unlock(ha);
5509 /* Detach interrupts */
5510 qla4xxx_free_irqs(ha);
5512 /* free extra memory */
5513 qla4xxx_mem_free(ha);
5516 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5519 unsigned long mem_base, mem_len;
5520 struct pci_dev *pdev = ha->pdev;
5522 status = pci_request_regions(pdev, DRIVER_NAME);
5525 "scsi(%ld) Failed to reserve PIO regions (%s) "
5526 "status=%d\n", ha->host_no, pci_name(pdev), status);
5527 goto iospace_error_exit;
5530 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5531 __func__, pdev->revision));
5532 ha->revision_id = pdev->revision;
5534 /* remap phys address */
5535 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5536 mem_len = pci_resource_len(pdev, 0);
5537 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5538 __func__, mem_base, mem_len));
5540 /* mapping of pcibase pointer */
5541 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5542 if (!ha->nx_pcibase) {
5544 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5545 pci_release_regions(ha->pdev);
5546 goto iospace_error_exit;
5549 /* Mapping of IO base pointer, door bell read and write pointer */
5551 /* mapping of IO base pointer */
5552 if (is_qla8022(ha)) {
5553 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5554 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5555 (ha->pdev->devfn << 11));
5556 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5557 QLA82XX_CAM_RAM_DB2);
5558 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5559 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5560 ((uint8_t *)ha->nx_pcibase);
5569 * qla4xxx_iospace_config - maps registers
5570 * @ha: pointer to adapter structure
5572 * This routines maps HBA's registers from the pci address space
5573 * into the kernel virtual address space for memory mapped i/o.
5575 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5577 unsigned long pio, pio_len, pio_flags;
5578 unsigned long mmio, mmio_len, mmio_flags;
5580 pio = pci_resource_start(ha->pdev, 0);
5581 pio_len = pci_resource_len(ha->pdev, 0);
5582 pio_flags = pci_resource_flags(ha->pdev, 0);
5583 if (pio_flags & IORESOURCE_IO) {
5584 if (pio_len < MIN_IOBASE_LEN) {
5585 ql4_printk(KERN_WARNING, ha,
5586 "Invalid PCI I/O region size\n");
5590 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5594 /* Use MMIO operations for all accesses. */
5595 mmio = pci_resource_start(ha->pdev, 1);
5596 mmio_len = pci_resource_len(ha->pdev, 1);
5597 mmio_flags = pci_resource_flags(ha->pdev, 1);
5599 if (!(mmio_flags & IORESOURCE_MEM)) {
5600 ql4_printk(KERN_ERR, ha,
5601 "region #0 not an MMIO resource, aborting\n");
5603 goto iospace_error_exit;
5606 if (mmio_len < MIN_IOBASE_LEN) {
5607 ql4_printk(KERN_ERR, ha,
5608 "Invalid PCI mem region size, aborting\n");
5609 goto iospace_error_exit;
5612 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5613 ql4_printk(KERN_WARNING, ha,
5614 "Failed to reserve PIO/MMIO regions\n");
5616 goto iospace_error_exit;
5619 ha->pio_address = pio;
5620 ha->pio_length = pio_len;
5621 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5623 ql4_printk(KERN_ERR, ha,
5624 "cannot remap MMIO, aborting\n");
5626 goto iospace_error_exit;
5635 static struct isp_operations qla4xxx_isp_ops = {
5636 .iospace_config = qla4xxx_iospace_config,
5637 .pci_config = qla4xxx_pci_config,
5638 .disable_intrs = qla4xxx_disable_intrs,
5639 .enable_intrs = qla4xxx_enable_intrs,
5640 .start_firmware = qla4xxx_start_firmware,
5641 .intr_handler = qla4xxx_intr_handler,
5642 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5643 .reset_chip = qla4xxx_soft_reset,
5644 .reset_firmware = qla4xxx_hw_reset,
5645 .queue_iocb = qla4xxx_queue_iocb,
5646 .complete_iocb = qla4xxx_complete_iocb,
5647 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5648 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5649 .get_sys_info = qla4xxx_get_sys_info,
5650 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5651 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5654 static struct isp_operations qla4_82xx_isp_ops = {
5655 .iospace_config = qla4_8xxx_iospace_config,
5656 .pci_config = qla4_8xxx_pci_config,
5657 .disable_intrs = qla4_82xx_disable_intrs,
5658 .enable_intrs = qla4_82xx_enable_intrs,
5659 .start_firmware = qla4_8xxx_load_risc,
5660 .restart_firmware = qla4_82xx_try_start_fw,
5661 .intr_handler = qla4_82xx_intr_handler,
5662 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5663 .need_reset = qla4_8xxx_need_reset,
5664 .reset_chip = qla4_82xx_isp_reset,
5665 .reset_firmware = qla4_8xxx_stop_firmware,
5666 .queue_iocb = qla4_82xx_queue_iocb,
5667 .complete_iocb = qla4_82xx_complete_iocb,
5668 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5669 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5670 .get_sys_info = qla4_8xxx_get_sys_info,
5671 .rd_reg_direct = qla4_82xx_rd_32,
5672 .wr_reg_direct = qla4_82xx_wr_32,
5673 .rd_reg_indirect = qla4_82xx_md_rd_32,
5674 .wr_reg_indirect = qla4_82xx_md_wr_32,
5675 .idc_lock = qla4_82xx_idc_lock,
5676 .idc_unlock = qla4_82xx_idc_unlock,
5677 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5678 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5679 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5682 static struct isp_operations qla4_83xx_isp_ops = {
5683 .iospace_config = qla4_8xxx_iospace_config,
5684 .pci_config = qla4_8xxx_pci_config,
5685 .disable_intrs = qla4_83xx_disable_intrs,
5686 .enable_intrs = qla4_83xx_enable_intrs,
5687 .start_firmware = qla4_8xxx_load_risc,
5688 .restart_firmware = qla4_83xx_start_firmware,
5689 .intr_handler = qla4_83xx_intr_handler,
5690 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5691 .need_reset = qla4_8xxx_need_reset,
5692 .reset_chip = qla4_83xx_isp_reset,
5693 .reset_firmware = qla4_8xxx_stop_firmware,
5694 .queue_iocb = qla4_83xx_queue_iocb,
5695 .complete_iocb = qla4_83xx_complete_iocb,
5696 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5697 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5698 .get_sys_info = qla4_8xxx_get_sys_info,
5699 .rd_reg_direct = qla4_83xx_rd_reg,
5700 .wr_reg_direct = qla4_83xx_wr_reg,
5701 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5702 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5703 .idc_lock = qla4_83xx_drv_lock,
5704 .idc_unlock = qla4_83xx_drv_unlock,
5705 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5706 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5707 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5710 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5712 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5715 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5717 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5720 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5722 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5725 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5727 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5730 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5732 struct scsi_qla_host *ha = data;
5737 case ISCSI_BOOT_ETH_FLAGS:
5738 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5740 case ISCSI_BOOT_ETH_INDEX:
5741 rc = sprintf(str, "0\n");
5743 case ISCSI_BOOT_ETH_MAC:
5744 rc = sysfs_format_mac(str, ha->my_mac,
5754 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5759 case ISCSI_BOOT_ETH_FLAGS:
5760 case ISCSI_BOOT_ETH_MAC:
5761 case ISCSI_BOOT_ETH_INDEX:
5771 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5773 struct scsi_qla_host *ha = data;
5778 case ISCSI_BOOT_INI_INITIATOR_NAME:
5779 rc = sprintf(str, "%s\n", ha->name_string);
5788 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5793 case ISCSI_BOOT_INI_INITIATOR_NAME:
5804 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5807 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5812 case ISCSI_BOOT_TGT_NAME:
5813 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5815 case ISCSI_BOOT_TGT_IP_ADDR:
5816 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5817 rc = sprintf(buf, "%pI4\n",
5818 &boot_conn->dest_ipaddr.ip_address);
5820 rc = sprintf(str, "%pI6\n",
5821 &boot_conn->dest_ipaddr.ip_address);
5823 case ISCSI_BOOT_TGT_PORT:
5824 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5826 case ISCSI_BOOT_TGT_CHAP_NAME:
5827 rc = sprintf(str, "%.*s\n",
5828 boot_conn->chap.target_chap_name_length,
5829 (char *)&boot_conn->chap.target_chap_name);
5831 case ISCSI_BOOT_TGT_CHAP_SECRET:
5832 rc = sprintf(str, "%.*s\n",
5833 boot_conn->chap.target_secret_length,
5834 (char *)&boot_conn->chap.target_secret);
5836 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5837 rc = sprintf(str, "%.*s\n",
5838 boot_conn->chap.intr_chap_name_length,
5839 (char *)&boot_conn->chap.intr_chap_name);
5841 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5842 rc = sprintf(str, "%.*s\n",
5843 boot_conn->chap.intr_secret_length,
5844 (char *)&boot_conn->chap.intr_secret);
5846 case ISCSI_BOOT_TGT_FLAGS:
5847 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5849 case ISCSI_BOOT_TGT_NIC_ASSOC:
5850 rc = sprintf(str, "0\n");
5859 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5861 struct scsi_qla_host *ha = data;
5862 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5864 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5867 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5869 struct scsi_qla_host *ha = data;
5870 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5872 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5875 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5880 case ISCSI_BOOT_TGT_NAME:
5881 case ISCSI_BOOT_TGT_IP_ADDR:
5882 case ISCSI_BOOT_TGT_PORT:
5883 case ISCSI_BOOT_TGT_CHAP_NAME:
5884 case ISCSI_BOOT_TGT_CHAP_SECRET:
5885 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5886 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5887 case ISCSI_BOOT_TGT_NIC_ASSOC:
5888 case ISCSI_BOOT_TGT_FLAGS:
5898 static void qla4xxx_boot_release(void *data)
5900 struct scsi_qla_host *ha = data;
5902 scsi_host_put(ha->host);
5905 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5908 uint32_t addr, pri_addr, sec_addr;
5912 uint8_t *buf = NULL;
5913 size_t size = 13 * sizeof(uint8_t);
5914 int ret = QLA_SUCCESS;
5916 func_num = PCI_FUNC(ha->pdev->devfn);
5918 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5919 __func__, ha->pdev->device, func_num);
5921 if (is_qla40XX(ha)) {
5922 if (func_num == 1) {
5923 addr = NVRAM_PORT0_BOOT_MODE;
5924 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5925 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5926 } else if (func_num == 3) {
5927 addr = NVRAM_PORT1_BOOT_MODE;
5928 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5929 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5932 goto exit_boot_info;
5935 /* Check Boot Mode */
5936 val = rd_nvram_byte(ha, addr);
5937 if (!(val & 0x07)) {
5938 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5939 "options : 0x%x\n", __func__, val));
5941 goto exit_boot_info;
5944 /* get primary valid target index */
5945 val = rd_nvram_byte(ha, pri_addr);
5947 ddb_index[0] = (val & 0x7f);
5949 /* get secondary valid target index */
5950 val = rd_nvram_byte(ha, sec_addr);
5952 ddb_index[1] = (val & 0x7f);
5953 goto exit_boot_info;
5954 } else if (is_qla80XX(ha)) {
5955 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5956 &buf_dma, GFP_KERNEL);
5958 DEBUG2(ql4_printk(KERN_ERR, ha,
5959 "%s: Unable to allocate dma buffer\n",
5962 goto exit_boot_info;
5965 if (ha->port_num == 0)
5966 offset = BOOT_PARAM_OFFSET_PORT0;
5967 else if (ha->port_num == 1)
5968 offset = BOOT_PARAM_OFFSET_PORT1;
5971 goto exit_boot_info_free;
5973 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5975 if (qla4xxx_get_flash(ha, buf_dma, addr,
5976 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5977 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5978 " failed\n", ha->host_no, __func__));
5980 goto exit_boot_info_free;
5982 /* Check Boot Mode */
5983 if (!(buf[1] & 0x07)) {
5984 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5985 " : 0x%x\n", buf[1]));
5987 goto exit_boot_info_free;
5990 /* get primary valid target index */
5992 ddb_index[0] = buf[2] & 0x7f;
5994 /* get secondary valid target index */
5995 if (buf[11] & BIT_7)
5996 ddb_index[1] = buf[11] & 0x7f;
5999 goto exit_boot_info;
6002 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
6003 " target ID %d\n", __func__, ddb_index[0],
6006 exit_boot_info_free:
6007 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
6009 ha->pri_ddb_idx = ddb_index[0];
6010 ha->sec_ddb_idx = ddb_index[1];
6015 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
6016 * @ha: pointer to adapter structure
6017 * @username: CHAP username to be returned
6018 * @password: CHAP password to be returned
6020 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6021 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6022 * So from the CHAP cache find the first BIDI CHAP entry and set it
6023 * to the boot record in sysfs.
6025 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6028 int i, ret = -EINVAL;
6029 int max_chap_entries = 0;
6030 struct ql4_chap_table *chap_table;
6033 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6034 sizeof(struct ql4_chap_table);
6036 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6038 if (!ha->chap_list) {
6039 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6043 mutex_lock(&ha->chap_sem);
6044 for (i = 0; i < max_chap_entries; i++) {
6045 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6046 if (chap_table->cookie !=
6047 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6051 if (chap_table->flags & BIT_7) /* local */
6054 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6057 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6058 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6062 mutex_unlock(&ha->chap_sem);
6068 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6069 struct ql4_boot_session_info *boot_sess,
6072 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6073 struct dev_db_entry *fw_ddb_entry;
6074 dma_addr_t fw_ddb_entry_dma;
6077 int ret = QLA_SUCCESS;
6079 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6080 &fw_ddb_entry_dma, GFP_KERNEL);
6081 if (!fw_ddb_entry) {
6082 DEBUG2(ql4_printk(KERN_ERR, ha,
6083 "%s: Unable to allocate dma buffer.\n",
6089 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6090 fw_ddb_entry_dma, ddb_index)) {
6091 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6092 "index [%d]\n", __func__, ddb_index));
6094 goto exit_boot_target;
6097 /* Update target name and IP from DDB */
6098 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6099 min(sizeof(boot_sess->target_name),
6100 sizeof(fw_ddb_entry->iscsi_name)));
6102 options = le16_to_cpu(fw_ddb_entry->options);
6103 if (options & DDB_OPT_IPV6_DEVICE) {
6104 memcpy(&boot_conn->dest_ipaddr.ip_address,
6105 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6107 boot_conn->dest_ipaddr.ip_type = 0x1;
6108 memcpy(&boot_conn->dest_ipaddr.ip_address,
6109 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6112 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6114 /* update chap information */
6115 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6117 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6119 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6121 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6123 (char *)&boot_conn->chap.target_secret,
6126 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6128 goto exit_boot_target;
6131 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6132 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6135 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6137 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6139 ret = qla4xxx_get_bidi_chap(ha,
6140 (char *)&boot_conn->chap.intr_chap_name,
6141 (char *)&boot_conn->chap.intr_secret);
6144 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6146 goto exit_boot_target;
6149 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6150 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6154 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6155 fw_ddb_entry, fw_ddb_entry_dma);
6159 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6161 uint16_t ddb_index[2];
6162 int ret = QLA_ERROR;
6165 memset(ddb_index, 0, sizeof(ddb_index));
6166 ddb_index[0] = 0xffff;
6167 ddb_index[1] = 0xffff;
6168 ret = get_fw_boot_info(ha, ddb_index);
6169 if (ret != QLA_SUCCESS) {
6170 DEBUG2(ql4_printk(KERN_INFO, ha,
6171 "%s: No boot target configured.\n", __func__));
6175 if (ql4xdisablesysfsboot)
6178 if (ddb_index[0] == 0xffff)
6181 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6183 if (rval != QLA_SUCCESS) {
6184 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6185 "configured\n", __func__));
6190 if (ddb_index[1] == 0xffff)
6191 goto exit_get_boot_info;
6193 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6195 if (rval != QLA_SUCCESS) {
6196 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6197 " configured\n", __func__));
6205 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6207 struct iscsi_boot_kobj *boot_kobj;
6209 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6212 if (ql4xdisablesysfsboot) {
6213 ql4_printk(KERN_INFO, ha,
6214 "%s: syfsboot disabled - driver will trigger login "
6215 "and publish session for discovery .\n", __func__);
6220 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6224 if (!scsi_host_get(ha->host))
6226 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6227 qla4xxx_show_boot_tgt_pri_info,
6228 qla4xxx_tgt_get_attr_visibility,
6229 qla4xxx_boot_release);
6233 if (!scsi_host_get(ha->host))
6235 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6236 qla4xxx_show_boot_tgt_sec_info,
6237 qla4xxx_tgt_get_attr_visibility,
6238 qla4xxx_boot_release);
6242 if (!scsi_host_get(ha->host))
6244 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6245 qla4xxx_show_boot_ini_info,
6246 qla4xxx_ini_get_attr_visibility,
6247 qla4xxx_boot_release);
6251 if (!scsi_host_get(ha->host))
6253 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6254 qla4xxx_show_boot_eth_info,
6255 qla4xxx_eth_get_attr_visibility,
6256 qla4xxx_boot_release);
6263 scsi_host_put(ha->host);
6265 iscsi_boot_destroy_kset(ha->boot_kset);
6270 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6271 struct ql4_tuple_ddb *tddb)
6273 struct iscsi_cls_session *cls_sess;
6274 struct iscsi_cls_conn *cls_conn;
6275 struct iscsi_session *sess;
6276 struct iscsi_conn *conn;
6278 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6279 cls_sess = ddb_entry->sess;
6280 sess = cls_sess->dd_data;
6281 cls_conn = ddb_entry->conn;
6282 conn = cls_conn->dd_data;
6284 tddb->tpgt = sess->tpgt;
6285 tddb->port = conn->persistent_port;
6286 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6287 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6290 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6291 struct ql4_tuple_ddb *tddb,
6292 uint8_t *flash_isid)
6294 uint16_t options = 0;
6296 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6297 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6298 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6300 options = le16_to_cpu(fw_ddb_entry->options);
6301 if (options & DDB_OPT_IPV6_DEVICE)
6302 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6304 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6306 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6308 if (flash_isid == NULL)
6309 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6310 sizeof(tddb->isid));
6312 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6315 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6316 struct ql4_tuple_ddb *old_tddb,
6317 struct ql4_tuple_ddb *new_tddb,
6318 uint8_t is_isid_compare)
6320 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6323 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6326 if (old_tddb->port != new_tddb->port)
6329 /* For multi sessions, driver generates the ISID, so do not compare
6330 * ISID in reset path since it would be a comparison between the
6331 * driver generated ISID and firmware generated ISID. This could
6332 * lead to adding duplicated DDBs in the list as driver generated
6333 * ISID would not match firmware generated ISID.
6335 if (is_isid_compare) {
6336 DEBUG2(ql4_printk(KERN_INFO, ha,
6337 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6338 __func__, old_tddb->isid, new_tddb->isid));
6340 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6341 sizeof(old_tddb->isid)))
6345 DEBUG2(ql4_printk(KERN_INFO, ha,
6346 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6347 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6348 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6349 new_tddb->ip_addr, new_tddb->iscsi_name));
6354 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6355 struct dev_db_entry *fw_ddb_entry,
6358 struct ddb_entry *ddb_entry;
6359 struct ql4_tuple_ddb *fw_tddb = NULL;
6360 struct ql4_tuple_ddb *tmp_tddb = NULL;
6362 int ret = QLA_ERROR;
6364 fw_tddb = vzalloc(sizeof(*fw_tddb));
6366 DEBUG2(ql4_printk(KERN_WARNING, ha,
6367 "Memory Allocation failed.\n"));
6372 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6374 DEBUG2(ql4_printk(KERN_WARNING, ha,
6375 "Memory Allocation failed.\n"));
6380 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6382 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6383 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6384 if (ddb_entry == NULL)
6387 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6388 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6389 ret = QLA_SUCCESS; /* found */
6403 * qla4xxx_check_existing_isid - check if target with same isid exist
6405 * @list_nt: list of target
6406 * @isid: isid to check
6408 * This routine return QLA_SUCCESS if target with same isid exist
6410 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6412 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6413 struct dev_db_entry *fw_ddb_entry;
6415 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6416 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6418 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6419 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6427 * qla4xxx_update_isid - compare ddbs and updated isid
6428 * @ha: Pointer to host adapter structure.
6429 * @list_nt: list of nt target
6430 * @fw_ddb_entry: firmware ddb entry
6432 * This routine update isid if ddbs have same iqn, same isid and
6433 * different IP addr.
6434 * Return QLA_SUCCESS if isid is updated.
6436 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6437 struct list_head *list_nt,
6438 struct dev_db_entry *fw_ddb_entry)
6440 uint8_t base_value, i;
6442 base_value = fw_ddb_entry->isid[1] & 0x1f;
6443 for (i = 0; i < 8; i++) {
6444 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6445 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6449 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6456 * qla4xxx_should_update_isid - check if isid need to update
6457 * @ha: Pointer to host adapter structure.
6458 * @old_tddb: ddb tuple
6459 * @new_tddb: ddb tuple
6461 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6464 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6465 struct ql4_tuple_ddb *old_tddb,
6466 struct ql4_tuple_ddb *new_tddb)
6468 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6470 if (old_tddb->port == new_tddb->port)
6474 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6478 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6479 sizeof(old_tddb->isid)))
6480 /* different isid */
6487 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6488 * @ha: Pointer to host adapter structure.
6489 * @list_nt: list of nt target.
6490 * @fw_ddb_entry: firmware ddb entry.
6492 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6493 * duplicate ddb in list_nt.
6494 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6495 * Note: This function also update isid of DDB if required.
6498 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6499 struct list_head *list_nt,
6500 struct dev_db_entry *fw_ddb_entry)
6502 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6503 struct ql4_tuple_ddb *fw_tddb = NULL;
6504 struct ql4_tuple_ddb *tmp_tddb = NULL;
6505 int rval, ret = QLA_ERROR;
6507 fw_tddb = vzalloc(sizeof(*fw_tddb));
6509 DEBUG2(ql4_printk(KERN_WARNING, ha,
6510 "Memory Allocation failed.\n"));
6515 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6517 DEBUG2(ql4_printk(KERN_WARNING, ha,
6518 "Memory Allocation failed.\n"));
6523 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6525 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6526 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6527 nt_ddb_idx->flash_isid);
6528 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6529 /* found duplicate ddb */
6530 if (ret == QLA_SUCCESS)
6534 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6535 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6537 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6538 if (ret == QLA_SUCCESS) {
6539 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6540 if (rval == QLA_SUCCESS)
6555 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6557 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6559 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6560 list_del_init(&ddb_idx->list);
6565 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6566 struct dev_db_entry *fw_ddb_entry)
6568 struct iscsi_endpoint *ep;
6569 struct sockaddr_in *addr;
6570 struct sockaddr_in6 *addr6;
6571 struct sockaddr *t_addr;
6572 struct sockaddr_storage *dst_addr;
6575 /* TODO: need to destroy on unload iscsi_endpoint*/
6576 dst_addr = vmalloc(sizeof(*dst_addr));
6580 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6581 t_addr = (struct sockaddr *)dst_addr;
6582 t_addr->sa_family = AF_INET6;
6583 addr6 = (struct sockaddr_in6 *)dst_addr;
6584 ip = (char *)&addr6->sin6_addr;
6585 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6586 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6589 t_addr = (struct sockaddr *)dst_addr;
6590 t_addr->sa_family = AF_INET;
6591 addr = (struct sockaddr_in *)dst_addr;
6592 ip = (char *)&addr->sin_addr;
6593 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6594 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6597 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6602 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6604 if (ql4xdisablesysfsboot)
6606 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6611 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6612 struct ddb_entry *ddb_entry,
6615 uint16_t def_timeout;
6617 ddb_entry->ddb_type = FLASH_DDB;
6618 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6619 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6621 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6622 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6623 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6625 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6626 atomic_set(&ddb_entry->relogin_timer, 0);
6627 atomic_set(&ddb_entry->relogin_retry_count, 0);
6628 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6629 ddb_entry->default_relogin_timeout =
6630 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6631 def_timeout : LOGIN_TOV;
6632 ddb_entry->default_time2wait =
6633 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6635 if (ql4xdisablesysfsboot &&
6636 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6637 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6640 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6643 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6644 uint32_t sts[MBOX_REG_COUNT];
6646 unsigned long wtime;
6649 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6651 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6652 if (ip_idx[idx] == -1)
6655 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6657 if (ret == QLA_ERROR) {
6662 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6664 DEBUG2(ql4_printk(KERN_INFO, ha,
6665 "Waiting for IP state for idx = %d, state = 0x%x\n",
6666 ip_idx[idx], ip_state));
6667 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6668 ip_state == IP_ADDRSTATE_INVALID ||
6669 ip_state == IP_ADDRSTATE_PREFERRED ||
6670 ip_state == IP_ADDRSTATE_DEPRICATED ||
6671 ip_state == IP_ADDRSTATE_DISABLING)
6675 /* Break if all IP states checked */
6676 if ((ip_idx[0] == -1) &&
6677 (ip_idx[1] == -1) &&
6678 (ip_idx[2] == -1) &&
6681 schedule_timeout_uninterruptible(HZ);
6682 } while (time_after(wtime, jiffies));
6685 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6686 struct dev_db_entry *flash_ddb_entry)
6688 uint16_t options = 0;
6689 size_t ip_len = IP_ADDR_LEN;
6691 options = le16_to_cpu(fw_ddb_entry->options);
6692 if (options & DDB_OPT_IPV6_DEVICE)
6693 ip_len = IPv6_ADDR_LEN;
6695 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6698 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6699 sizeof(fw_ddb_entry->isid)))
6702 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6703 sizeof(fw_ddb_entry->port)))
6709 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6710 struct dev_db_entry *fw_ddb_entry,
6711 uint32_t fw_idx, uint32_t *flash_index)
6713 struct dev_db_entry *flash_ddb_entry;
6714 dma_addr_t flash_ddb_entry_dma;
6717 int ret = QLA_ERROR, status;
6719 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6722 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6723 &flash_ddb_entry_dma);
6724 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6725 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6726 goto exit_find_st_idx;
6729 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6730 flash_ddb_entry_dma, fw_idx);
6731 if (status == QLA_SUCCESS) {
6732 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6733 if (status == QLA_SUCCESS) {
6734 *flash_index = fw_idx;
6736 goto exit_find_st_idx;
6740 for (idx = 0; idx < max_ddbs; idx++) {
6741 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6742 flash_ddb_entry_dma, idx);
6743 if (status == QLA_ERROR)
6746 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6747 if (status == QLA_SUCCESS) {
6750 goto exit_find_st_idx;
6754 if (idx == max_ddbs)
6755 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6759 if (flash_ddb_entry)
6760 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6761 flash_ddb_entry_dma);
6766 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6767 struct list_head *list_st)
6769 struct qla_ddb_index *st_ddb_idx;
6772 struct dev_db_entry *fw_ddb_entry;
6773 dma_addr_t fw_ddb_dma;
6775 uint32_t idx = 0, next_idx = 0;
6776 uint32_t state = 0, conn_err = 0;
6777 uint32_t flash_index = -1;
6778 uint16_t conn_id = 0;
6780 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6782 if (fw_ddb_entry == NULL) {
6783 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6787 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6789 fw_idx_size = sizeof(struct qla_ddb_index);
6791 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6792 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6793 NULL, &next_idx, &state,
6794 &conn_err, NULL, &conn_id);
6795 if (ret == QLA_ERROR)
6798 /* Ignore DDB if invalid state (unassigned) */
6799 if (state == DDB_DS_UNASSIGNED)
6800 goto continue_next_st;
6802 /* Check if ST, add to the list_st */
6803 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6804 goto continue_next_st;
6806 st_ddb_idx = vzalloc(fw_idx_size);
6810 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6812 if (ret == QLA_ERROR) {
6813 ql4_printk(KERN_ERR, ha,
6814 "No flash entry for ST at idx [%d]\n", idx);
6815 st_ddb_idx->flash_ddb_idx = idx;
6817 ql4_printk(KERN_INFO, ha,
6818 "ST at idx [%d] is stored at flash [%d]\n",
6820 st_ddb_idx->flash_ddb_idx = flash_index;
6823 st_ddb_idx->fw_ddb_idx = idx;
6825 list_add_tail(&st_ddb_idx->list, list_st);
6833 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6837 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6838 * @ha: pointer to adapter structure
6839 * @list_ddb: List from which failed ddb to be removed
6841 * Iterate over the list of DDBs and find and remove DDBs that are either in
6842 * no connection active state or failed state
6844 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6845 struct list_head *list_ddb)
6847 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6848 uint32_t next_idx = 0;
6849 uint32_t state = 0, conn_err = 0;
6852 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6853 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6854 NULL, 0, NULL, &next_idx, &state,
6855 &conn_err, NULL, NULL);
6856 if (ret == QLA_ERROR)
6859 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6860 state == DDB_DS_SESSION_FAILED) {
6861 list_del_init(&ddb_idx->list);
6867 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6868 struct ddb_entry *ddb_entry,
6869 struct dev_db_entry *fw_ddb_entry)
6871 struct iscsi_cls_session *cls_sess;
6872 struct iscsi_session *sess;
6873 uint32_t max_ddbs = 0;
6874 uint16_t ddb_link = -1;
6876 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6879 cls_sess = ddb_entry->sess;
6880 sess = cls_sess->dd_data;
6882 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6883 if (ddb_link < max_ddbs)
6884 sess->discovery_parent_idx = ddb_link;
6886 sess->discovery_parent_idx = DDB_NO_LINK;
6889 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6890 struct dev_db_entry *fw_ddb_entry,
6891 int is_reset, uint16_t idx)
6893 struct iscsi_cls_session *cls_sess;
6894 struct iscsi_session *sess;
6895 struct iscsi_cls_conn *cls_conn;
6896 struct iscsi_endpoint *ep;
6897 uint16_t cmds_max = 32;
6898 uint16_t conn_id = 0;
6899 uint32_t initial_cmdsn = 0;
6900 int ret = QLA_SUCCESS;
6902 struct ddb_entry *ddb_entry = NULL;
6904 /* Create session object, with INVALID_ENTRY,
6905 * the targer_id would get set when we issue the login
6907 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6908 cmds_max, sizeof(struct ddb_entry),
6909 sizeof(struct ql4_task_data),
6910 initial_cmdsn, INVALID_ENTRY);
6917 * so calling module_put function to decrement the
6920 module_put(qla4xxx_iscsi_transport.owner);
6921 sess = cls_sess->dd_data;
6922 ddb_entry = sess->dd_data;
6923 ddb_entry->sess = cls_sess;
6925 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6926 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6927 sizeof(struct dev_db_entry));
6929 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6931 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6938 ddb_entry->conn = cls_conn;
6940 /* Setup ep, for displaying attributes in sysfs */
6941 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6943 ep->conn = cls_conn;
6946 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6951 /* Update sess/conn params */
6952 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6953 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6955 if (is_reset == RESET_ADAPTER) {
6956 iscsi_block_session(cls_sess);
6957 /* Use the relogin path to discover new devices
6958 * by short-circuiting the logic of setting
6959 * timer to relogin - instead set the flags
6960 * to initiate login right away.
6962 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6963 set_bit(DF_RELOGIN, &ddb_entry->flags);
6970 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6971 struct list_head *list_ddb,
6972 struct dev_db_entry *fw_ddb_entry)
6974 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6977 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6979 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6980 if (ddb_idx->fw_ddb_idx == ddb_link) {
6981 DEBUG2(ql4_printk(KERN_INFO, ha,
6982 "Updating NT parent idx from [%d] to [%d]\n",
6983 ddb_link, ddb_idx->flash_ddb_idx));
6984 fw_ddb_entry->ddb_link =
6985 cpu_to_le16(ddb_idx->flash_ddb_idx);
6991 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6992 struct list_head *list_nt,
6993 struct list_head *list_st,
6996 struct dev_db_entry *fw_ddb_entry;
6997 struct ddb_entry *ddb_entry = NULL;
6998 dma_addr_t fw_ddb_dma;
7002 uint32_t idx = 0, next_idx = 0;
7003 uint32_t state = 0, conn_err = 0;
7004 uint32_t ddb_idx = -1;
7005 uint16_t conn_id = 0;
7006 uint16_t ddb_link = -1;
7007 struct qla_ddb_index *nt_ddb_idx;
7009 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7011 if (fw_ddb_entry == NULL) {
7012 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7015 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7017 fw_idx_size = sizeof(struct qla_ddb_index);
7019 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7020 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7021 NULL, &next_idx, &state,
7022 &conn_err, NULL, &conn_id);
7023 if (ret == QLA_ERROR)
7026 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7027 goto continue_next_nt;
7029 /* Check if NT, then add to list it */
7030 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7031 goto continue_next_nt;
7033 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7034 if (ddb_link < max_ddbs)
7035 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7037 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7038 state == DDB_DS_SESSION_FAILED) &&
7039 (is_reset == INIT_ADAPTER))
7040 goto continue_next_nt;
7042 DEBUG2(ql4_printk(KERN_INFO, ha,
7043 "Adding DDB to session = 0x%x\n", idx));
7045 if (is_reset == INIT_ADAPTER) {
7046 nt_ddb_idx = vmalloc(fw_idx_size);
7050 nt_ddb_idx->fw_ddb_idx = idx;
7052 /* Copy original isid as it may get updated in function
7053 * qla4xxx_update_isid(). We need original isid in
7054 * function qla4xxx_compare_tuple_ddb to find duplicate
7056 memcpy(&nt_ddb_idx->flash_isid[0],
7057 &fw_ddb_entry->isid[0],
7058 sizeof(nt_ddb_idx->flash_isid));
7060 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7062 if (ret == QLA_SUCCESS) {
7063 /* free nt_ddb_idx and do not add to list_nt */
7065 goto continue_next_nt;
7068 /* Copy updated isid */
7069 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7070 sizeof(struct dev_db_entry));
7072 list_add_tail(&nt_ddb_idx->list, list_nt);
7073 } else if (is_reset == RESET_ADAPTER) {
7074 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7076 if (ret == QLA_SUCCESS) {
7077 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7079 if (ddb_entry != NULL)
7080 qla4xxx_update_sess_disc_idx(ha,
7083 goto continue_next_nt;
7087 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7088 if (ret == QLA_ERROR)
7098 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7101 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7102 struct list_head *list_nt,
7105 struct dev_db_entry *fw_ddb_entry;
7106 dma_addr_t fw_ddb_dma;
7110 uint32_t idx = 0, next_idx = 0;
7111 uint32_t state = 0, conn_err = 0;
7112 uint16_t conn_id = 0;
7113 struct qla_ddb_index *nt_ddb_idx;
7115 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7117 if (fw_ddb_entry == NULL) {
7118 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7119 goto exit_new_nt_list;
7121 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7123 fw_idx_size = sizeof(struct qla_ddb_index);
7125 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7126 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7127 NULL, &next_idx, &state,
7128 &conn_err, NULL, &conn_id);
7129 if (ret == QLA_ERROR)
7132 /* Check if NT, then add it to list */
7133 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7134 goto continue_next_new_nt;
7136 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7137 goto continue_next_new_nt;
7139 DEBUG2(ql4_printk(KERN_INFO, ha,
7140 "Adding DDB to session = 0x%x\n", idx));
7142 nt_ddb_idx = vmalloc(fw_idx_size);
7146 nt_ddb_idx->fw_ddb_idx = idx;
7148 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7149 if (ret == QLA_SUCCESS) {
7150 /* free nt_ddb_idx and do not add to list_nt */
7152 goto continue_next_new_nt;
7155 if (target_id < max_ddbs)
7156 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7158 list_add_tail(&nt_ddb_idx->list, list_nt);
7160 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7162 if (ret == QLA_ERROR)
7163 goto exit_new_nt_list;
7165 continue_next_new_nt:
7172 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7176 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7177 * @dev: dev associated with the sysfs entry
7178 * @data: pointer to flashnode session object
7181 * 1: if flashnode entry is non-persistent
7182 * 0: if flashnode entry is persistent
7184 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7186 struct iscsi_bus_flash_session *fnode_sess;
7188 if (!iscsi_flashnode_bus_match(dev, NULL))
7191 fnode_sess = iscsi_dev_to_flash_session(dev);
7193 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7197 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7198 * @ha: pointer to host
7199 * @fw_ddb_entry: flash ddb data
7200 * @idx: target index
7201 * @user: if set then this call is made from userland else from kernel
7204 * On sucess: QLA_SUCCESS
7205 * On failure: QLA_ERROR
7207 * This create separate sysfs entries for session and connection attributes of
7208 * the given fw ddb entry.
7209 * If this is invoked as a result of a userspace call then the entry is marked
7210 * as nonpersistent using flash_state field.
7212 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7213 struct dev_db_entry *fw_ddb_entry,
7214 uint16_t *idx, int user)
7216 struct iscsi_bus_flash_session *fnode_sess = NULL;
7217 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7220 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7221 &qla4xxx_iscsi_transport, 0);
7223 ql4_printk(KERN_ERR, ha,
7224 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7225 __func__, *idx, ha->host_no);
7226 goto exit_tgt_create;
7229 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7230 &qla4xxx_iscsi_transport, 0);
7232 ql4_printk(KERN_ERR, ha,
7233 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7234 __func__, *idx, ha->host_no);
7239 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7241 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7243 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7244 fnode_sess->is_boot_target = 1;
7246 fnode_sess->is_boot_target = 0;
7249 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7254 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7255 __func__, fnode_sess->dev.kobj.name);
7257 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7258 __func__, fnode_conn->dev.kobj.name);
7263 iscsi_destroy_flashnode_sess(fnode_sess);
7270 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7271 * @shost: pointer to host
7272 * @buf: type of ddb entry (ipv4/ipv6)
7273 * @len: length of buf
7275 * This creates new ddb entry in the flash by finding first free index and
7276 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7278 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7281 struct scsi_qla_host *ha = to_qla_host(shost);
7282 struct dev_db_entry *fw_ddb_entry = NULL;
7283 dma_addr_t fw_ddb_entry_dma;
7286 uint16_t max_ddbs = 0;
7287 uint32_t options = 0;
7288 uint32_t rval = QLA_ERROR;
7290 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7291 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7292 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7297 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7300 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7301 &fw_ddb_entry_dma, GFP_KERNEL);
7302 if (!fw_ddb_entry) {
7303 DEBUG2(ql4_printk(KERN_ERR, ha,
7304 "%s: Unable to allocate dma buffer\n",
7309 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7310 qla4xxx_sysfs_ddb_is_non_persistent);
7312 ql4_printk(KERN_ERR, ha,
7313 "%s: A non-persistent entry %s found\n",
7314 __func__, dev->kobj.name);
7319 /* Index 0 and 1 are reserved for boot target entries */
7320 for (idx = 2; idx < max_ddbs; idx++) {
7321 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7322 fw_ddb_entry_dma, idx))
7326 if (idx == max_ddbs)
7329 if (!strncasecmp("ipv6", buf, 4))
7330 options |= IPV6_DEFAULT_DDB_ENTRY;
7332 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7333 if (rval == QLA_ERROR)
7336 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7340 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7341 fw_ddb_entry, fw_ddb_entry_dma);
7342 if (rval == QLA_SUCCESS)
7349 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7350 * @fnode_sess: pointer to session attrs of flash ddb entry
7351 * @fnode_conn: pointer to connection attrs of flash ddb entry
7353 * This writes the contents of target ddb buffer to Flash with a valid cookie
7354 * value in order to make the ddb entry persistent.
7356 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7357 struct iscsi_bus_flash_conn *fnode_conn)
7359 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7360 struct scsi_qla_host *ha = to_qla_host(shost);
7361 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7362 struct dev_db_entry *fw_ddb_entry = NULL;
7363 dma_addr_t fw_ddb_entry_dma;
7364 uint32_t options = 0;
7367 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7368 &fw_ddb_entry_dma, GFP_KERNEL);
7369 if (!fw_ddb_entry) {
7370 DEBUG2(ql4_printk(KERN_ERR, ha,
7371 "%s: Unable to allocate dma buffer\n",
7374 goto exit_ddb_apply;
7377 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7378 options |= IPV6_DEFAULT_DDB_ENTRY;
7380 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7381 if (rval == QLA_ERROR)
7382 goto exit_ddb_apply;
7384 dev_db_start_offset += (fnode_sess->target_id *
7385 sizeof(*fw_ddb_entry));
7387 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7388 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7390 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7391 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7393 if (rval == QLA_SUCCESS) {
7394 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7395 ql4_printk(KERN_INFO, ha,
7396 "%s: flash node %u of host %lu written to flash\n",
7397 __func__, fnode_sess->target_id, ha->host_no);
7400 ql4_printk(KERN_ERR, ha,
7401 "%s: Error while writing flash node %u of host %lu to flash\n",
7402 __func__, fnode_sess->target_id, ha->host_no);
7407 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7408 fw_ddb_entry, fw_ddb_entry_dma);
7412 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7413 struct dev_db_entry *fw_ddb_entry,
7416 struct dev_db_entry *ddb_entry = NULL;
7417 dma_addr_t ddb_entry_dma;
7418 unsigned long wtime;
7419 uint32_t mbx_sts = 0;
7420 uint32_t state = 0, conn_err = 0;
7424 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7425 &ddb_entry_dma, GFP_KERNEL);
7427 DEBUG2(ql4_printk(KERN_ERR, ha,
7428 "%s: Unable to allocate dma buffer\n",
7433 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7435 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7436 if (ret != QLA_SUCCESS) {
7437 DEBUG2(ql4_printk(KERN_ERR, ha,
7438 "%s: Unable to set ddb entry for index %d\n",
7440 goto exit_ddb_conn_open;
7443 qla4xxx_conn_open(ha, idx);
7445 /* To ensure that sendtargets is done, wait for at least 12 secs */
7446 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7447 (ha->def_timeout < LOGIN_TOV * 10) ?
7448 ha->def_timeout : LOGIN_TOV);
7450 DEBUG2(ql4_printk(KERN_INFO, ha,
7451 "Default time to wait for login to ddb %d\n", tmo));
7453 wtime = jiffies + (HZ * tmo);
7455 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7456 NULL, &state, &conn_err, NULL,
7458 if (ret == QLA_ERROR)
7461 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7462 state == DDB_DS_SESSION_FAILED)
7465 schedule_timeout_uninterruptible(HZ / 10);
7466 } while (time_after(wtime, jiffies));
7470 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7471 ddb_entry, ddb_entry_dma);
7475 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7476 struct dev_db_entry *fw_ddb_entry,
7479 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7480 struct list_head list_nt;
7484 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7485 ql4_printk(KERN_WARNING, ha,
7486 "%s: A discovery already in progress!\n", __func__);
7490 INIT_LIST_HEAD(&list_nt);
7492 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7494 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7495 if (ret == QLA_ERROR)
7496 goto exit_login_st_clr_bit;
7498 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7499 if (ret == QLA_ERROR)
7502 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7504 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7505 list_del_init(&ddb_idx->list);
7506 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7511 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7512 ql4_printk(KERN_ERR, ha,
7513 "Unable to clear DDB index = 0x%x\n", ddb_index);
7516 clear_bit(ddb_index, ha->ddb_idx_map);
7518 exit_login_st_clr_bit:
7519 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7523 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7524 struct dev_db_entry *fw_ddb_entry,
7527 int ret = QLA_ERROR;
7529 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7530 if (ret != QLA_SUCCESS)
7531 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7540 * qla4xxx_sysfs_ddb_login - Login to the specified target
7541 * @fnode_sess: pointer to session attrs of flash ddb entry
7542 * @fnode_conn: pointer to connection attrs of flash ddb entry
7544 * This logs in to the specified target
7546 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7547 struct iscsi_bus_flash_conn *fnode_conn)
7549 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7550 struct scsi_qla_host *ha = to_qla_host(shost);
7551 struct dev_db_entry *fw_ddb_entry = NULL;
7552 dma_addr_t fw_ddb_entry_dma;
7553 uint32_t options = 0;
7556 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7557 ql4_printk(KERN_ERR, ha,
7558 "%s: Target info is not persistent\n", __func__);
7560 goto exit_ddb_login;
7563 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7564 &fw_ddb_entry_dma, GFP_KERNEL);
7565 if (!fw_ddb_entry) {
7566 DEBUG2(ql4_printk(KERN_ERR, ha,
7567 "%s: Unable to allocate dma buffer\n",
7570 goto exit_ddb_login;
7573 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7574 options |= IPV6_DEFAULT_DDB_ENTRY;
7576 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7577 if (ret == QLA_ERROR)
7578 goto exit_ddb_login;
7580 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7581 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7583 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7584 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7585 fnode_sess->target_id);
7587 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7588 fnode_sess->target_id);
7595 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7596 fw_ddb_entry, fw_ddb_entry_dma);
7601 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7602 * @cls_sess: pointer to session to be logged out
7604 * This performs session log out from the specified target
7606 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7608 struct iscsi_session *sess;
7609 struct ddb_entry *ddb_entry = NULL;
7610 struct scsi_qla_host *ha;
7611 struct dev_db_entry *fw_ddb_entry = NULL;
7612 dma_addr_t fw_ddb_entry_dma;
7613 unsigned long flags;
7614 unsigned long wtime;
7619 sess = cls_sess->dd_data;
7620 ddb_entry = sess->dd_data;
7623 if (ddb_entry->ddb_type != FLASH_DDB) {
7624 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7627 goto exit_ddb_logout;
7630 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7631 ql4_printk(KERN_ERR, ha,
7632 "%s: Logout from boot target entry is not permitted.\n",
7635 goto exit_ddb_logout;
7638 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7639 &fw_ddb_entry_dma, GFP_KERNEL);
7640 if (!fw_ddb_entry) {
7641 ql4_printk(KERN_ERR, ha,
7642 "%s: Unable to allocate dma buffer\n", __func__);
7644 goto exit_ddb_logout;
7647 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7648 goto ddb_logout_init;
7650 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7651 fw_ddb_entry, fw_ddb_entry_dma,
7652 NULL, NULL, &ddb_state, NULL,
7654 if (ret == QLA_ERROR)
7655 goto ddb_logout_init;
7657 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7658 goto ddb_logout_init;
7660 /* wait until next relogin is triggered using DF_RELOGIN and
7661 * clear DF_RELOGIN to avoid invocation of further relogin
7663 wtime = jiffies + (HZ * RELOGIN_TOV);
7665 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7666 goto ddb_logout_init;
7668 schedule_timeout_uninterruptible(HZ);
7669 } while ((time_after(wtime, jiffies)));
7672 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7673 atomic_set(&ddb_entry->relogin_timer, 0);
7675 options = LOGOUT_OPTION_CLOSE_SESSION;
7676 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7678 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7679 wtime = jiffies + (HZ * LOGOUT_TOV);
7681 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7682 fw_ddb_entry, fw_ddb_entry_dma,
7683 NULL, NULL, &ddb_state, NULL,
7685 if (ret == QLA_ERROR)
7686 goto ddb_logout_clr_sess;
7688 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7689 (ddb_state == DDB_DS_SESSION_FAILED))
7690 goto ddb_logout_clr_sess;
7692 schedule_timeout_uninterruptible(HZ);
7693 } while ((time_after(wtime, jiffies)));
7695 ddb_logout_clr_sess:
7696 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7698 * we have decremented the reference count of the driver
7699 * when we setup the session to have the driver unload
7700 * to be seamless without actually destroying the
7703 try_module_get(qla4xxx_iscsi_transport.owner);
7704 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7706 spin_lock_irqsave(&ha->hardware_lock, flags);
7707 qla4xxx_free_ddb(ha, ddb_entry);
7708 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7709 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7711 iscsi_session_teardown(ddb_entry->sess);
7713 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7718 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7719 fw_ddb_entry, fw_ddb_entry_dma);
7724 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7725 * @fnode_sess: pointer to session attrs of flash ddb entry
7726 * @fnode_conn: pointer to connection attrs of flash ddb entry
7728 * This performs log out from the specified target
7730 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7731 struct iscsi_bus_flash_conn *fnode_conn)
7733 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7734 struct scsi_qla_host *ha = to_qla_host(shost);
7735 struct ql4_tuple_ddb *flash_tddb = NULL;
7736 struct ql4_tuple_ddb *tmp_tddb = NULL;
7737 struct dev_db_entry *fw_ddb_entry = NULL;
7738 struct ddb_entry *ddb_entry = NULL;
7739 dma_addr_t fw_ddb_dma;
7740 uint32_t next_idx = 0;
7741 uint32_t state = 0, conn_err = 0;
7742 uint16_t conn_id = 0;
7744 int status, ret = 0;
7746 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7748 if (fw_ddb_entry == NULL) {
7749 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7751 goto exit_ddb_logout;
7754 flash_tddb = vzalloc(sizeof(*flash_tddb));
7756 ql4_printk(KERN_WARNING, ha,
7757 "%s:Memory Allocation failed.\n", __func__);
7759 goto exit_ddb_logout;
7762 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7764 ql4_printk(KERN_WARNING, ha,
7765 "%s:Memory Allocation failed.\n", __func__);
7767 goto exit_ddb_logout;
7770 if (!fnode_sess->targetname) {
7771 ql4_printk(KERN_ERR, ha,
7772 "%s:Cannot logout from SendTarget entry\n",
7775 goto exit_ddb_logout;
7778 if (fnode_sess->is_boot_target) {
7779 ql4_printk(KERN_ERR, ha,
7780 "%s: Logout from boot target entry is not permitted.\n",
7783 goto exit_ddb_logout;
7786 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7789 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7790 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7792 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7794 flash_tddb->tpgt = fnode_sess->tpgt;
7795 flash_tddb->port = fnode_conn->port;
7797 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7799 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7800 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7801 if (ddb_entry == NULL)
7804 if (ddb_entry->ddb_type != FLASH_DDB)
7807 index = ddb_entry->sess->target_id;
7808 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7809 fw_ddb_dma, NULL, &next_idx,
7810 &state, &conn_err, NULL,
7812 if (status == QLA_ERROR) {
7817 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7819 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7821 if (status == QLA_SUCCESS) {
7822 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7827 if (idx == MAX_DDB_ENTRIES)
7834 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7840 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7841 int param, char *buf)
7843 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7844 struct scsi_qla_host *ha = to_qla_host(shost);
7845 struct iscsi_bus_flash_conn *fnode_conn;
7846 struct ql4_chap_table chap_tbl;
7851 dev = iscsi_find_flashnode_conn(fnode_sess);
7855 fnode_conn = iscsi_dev_to_flash_conn(dev);
7858 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7859 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7861 case ISCSI_FLASHNODE_PORTAL_TYPE:
7862 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7864 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7865 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7867 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7868 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7870 case ISCSI_FLASHNODE_ENTRY_EN:
7871 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7873 case ISCSI_FLASHNODE_HDR_DGST_EN:
7874 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7876 case ISCSI_FLASHNODE_DATA_DGST_EN:
7877 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7879 case ISCSI_FLASHNODE_IMM_DATA_EN:
7880 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7882 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7883 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7885 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7886 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7888 case ISCSI_FLASHNODE_PDU_INORDER:
7889 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7891 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7892 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7894 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7895 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7897 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7898 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7900 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7901 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7903 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7904 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7906 case ISCSI_FLASHNODE_ERL:
7907 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7909 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7910 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7912 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7913 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7915 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7916 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7918 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7919 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7921 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7922 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7924 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7925 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7927 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7928 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7930 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7931 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7933 case ISCSI_FLASHNODE_FIRST_BURST:
7934 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7936 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7937 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7939 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7940 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7942 case ISCSI_FLASHNODE_MAX_R2T:
7943 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7945 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7946 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7948 case ISCSI_FLASHNODE_ISID:
7949 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7951 case ISCSI_FLASHNODE_TSID:
7952 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7954 case ISCSI_FLASHNODE_PORT:
7955 rc = sprintf(buf, "%d\n", fnode_conn->port);
7957 case ISCSI_FLASHNODE_MAX_BURST:
7958 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7960 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7961 rc = sprintf(buf, "%u\n",
7962 fnode_sess->default_taskmgmt_timeout);
7964 case ISCSI_FLASHNODE_IPADDR:
7965 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7966 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7968 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7970 case ISCSI_FLASHNODE_ALIAS:
7971 if (fnode_sess->targetalias)
7972 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7974 rc = sprintf(buf, "\n");
7976 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7977 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7978 rc = sprintf(buf, "%pI6\n",
7979 fnode_conn->redirect_ipaddr);
7981 rc = sprintf(buf, "%pI4\n",
7982 fnode_conn->redirect_ipaddr);
7984 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7985 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7987 case ISCSI_FLASHNODE_LOCAL_PORT:
7988 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7990 case ISCSI_FLASHNODE_IPV4_TOS:
7991 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7993 case ISCSI_FLASHNODE_IPV6_TC:
7994 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7995 rc = sprintf(buf, "%u\n",
7996 fnode_conn->ipv6_traffic_class);
7998 rc = sprintf(buf, "\n");
8000 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8001 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8003 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8004 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8005 rc = sprintf(buf, "%pI6\n",
8006 fnode_conn->link_local_ipv6_addr);
8008 rc = sprintf(buf, "\n");
8010 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8011 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8013 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8014 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8015 parent_type = ISCSI_DISC_PARENT_ISNS;
8016 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8017 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8018 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8019 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8021 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8023 rc = sprintf(buf, "%s\n",
8024 iscsi_get_discovery_parent_name(parent_type));
8026 case ISCSI_FLASHNODE_NAME:
8027 if (fnode_sess->targetname)
8028 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8030 rc = sprintf(buf, "\n");
8032 case ISCSI_FLASHNODE_TPGT:
8033 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8035 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8036 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8038 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8039 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8041 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8042 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8044 case ISCSI_FLASHNODE_USERNAME:
8045 if (fnode_sess->chap_auth_en) {
8046 qla4xxx_get_uni_chap_at_index(ha,
8049 fnode_sess->chap_out_idx);
8050 rc = sprintf(buf, "%s\n", chap_tbl.name);
8052 rc = sprintf(buf, "\n");
8055 case ISCSI_FLASHNODE_PASSWORD:
8056 if (fnode_sess->chap_auth_en) {
8057 qla4xxx_get_uni_chap_at_index(ha,
8060 fnode_sess->chap_out_idx);
8061 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8063 rc = sprintf(buf, "\n");
8066 case ISCSI_FLASHNODE_STATSN:
8067 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8069 case ISCSI_FLASHNODE_EXP_STATSN:
8070 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8072 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8073 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8085 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8086 * @fnode_sess: pointer to session attrs of flash ddb entry
8087 * @fnode_conn: pointer to connection attrs of flash ddb entry
8088 * @data: Parameters and their values to update
8091 * This sets the parameter of flash ddb entry and writes them to flash
8094 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8095 struct iscsi_bus_flash_conn *fnode_conn,
8096 void *data, int len)
8098 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8099 struct scsi_qla_host *ha = to_qla_host(shost);
8100 struct iscsi_flashnode_param_info *fnode_param;
8101 struct ql4_chap_table chap_tbl;
8102 struct nlattr *attr;
8103 uint16_t chap_out_idx = INVALID_ENTRY;
8107 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8108 nla_for_each_attr(attr, data, len, rem) {
8109 fnode_param = nla_data(attr);
8111 switch (fnode_param->param) {
8112 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8113 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8115 case ISCSI_FLASHNODE_PORTAL_TYPE:
8116 memcpy(fnode_sess->portal_type, fnode_param->value,
8117 strlen(fnode_sess->portal_type));
8119 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8120 fnode_sess->auto_snd_tgt_disable =
8121 fnode_param->value[0];
8123 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8124 fnode_sess->discovery_sess = fnode_param->value[0];
8126 case ISCSI_FLASHNODE_ENTRY_EN:
8127 fnode_sess->entry_state = fnode_param->value[0];
8129 case ISCSI_FLASHNODE_HDR_DGST_EN:
8130 fnode_conn->hdrdgst_en = fnode_param->value[0];
8132 case ISCSI_FLASHNODE_DATA_DGST_EN:
8133 fnode_conn->datadgst_en = fnode_param->value[0];
8135 case ISCSI_FLASHNODE_IMM_DATA_EN:
8136 fnode_sess->imm_data_en = fnode_param->value[0];
8138 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8139 fnode_sess->initial_r2t_en = fnode_param->value[0];
8141 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8142 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8144 case ISCSI_FLASHNODE_PDU_INORDER:
8145 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8147 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8148 fnode_sess->chap_auth_en = fnode_param->value[0];
8149 /* Invalidate chap index if chap auth is disabled */
8150 if (!fnode_sess->chap_auth_en)
8151 fnode_sess->chap_out_idx = INVALID_ENTRY;
8154 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8155 fnode_conn->snack_req_en = fnode_param->value[0];
8157 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8158 fnode_sess->discovery_logout_en = fnode_param->value[0];
8160 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8161 fnode_sess->bidi_chap_en = fnode_param->value[0];
8163 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8164 fnode_sess->discovery_auth_optional =
8165 fnode_param->value[0];
8167 case ISCSI_FLASHNODE_ERL:
8168 fnode_sess->erl = fnode_param->value[0];
8170 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8171 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8173 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8174 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8176 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8177 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8179 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8180 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8182 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8183 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8185 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8186 fnode_conn->fragment_disable = fnode_param->value[0];
8188 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8189 fnode_conn->max_recv_dlength =
8190 *(unsigned *)fnode_param->value;
8192 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8193 fnode_conn->max_xmit_dlength =
8194 *(unsigned *)fnode_param->value;
8196 case ISCSI_FLASHNODE_FIRST_BURST:
8197 fnode_sess->first_burst =
8198 *(unsigned *)fnode_param->value;
8200 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8201 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8203 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8204 fnode_sess->time2retain =
8205 *(uint16_t *)fnode_param->value;
8207 case ISCSI_FLASHNODE_MAX_R2T:
8208 fnode_sess->max_r2t =
8209 *(uint16_t *)fnode_param->value;
8211 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8212 fnode_conn->keepalive_timeout =
8213 *(uint16_t *)fnode_param->value;
8215 case ISCSI_FLASHNODE_ISID:
8216 memcpy(fnode_sess->isid, fnode_param->value,
8217 sizeof(fnode_sess->isid));
8219 case ISCSI_FLASHNODE_TSID:
8220 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8222 case ISCSI_FLASHNODE_PORT:
8223 fnode_conn->port = *(uint16_t *)fnode_param->value;
8225 case ISCSI_FLASHNODE_MAX_BURST:
8226 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8228 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8229 fnode_sess->default_taskmgmt_timeout =
8230 *(uint16_t *)fnode_param->value;
8232 case ISCSI_FLASHNODE_IPADDR:
8233 memcpy(fnode_conn->ipaddress, fnode_param->value,
8236 case ISCSI_FLASHNODE_ALIAS:
8237 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8238 (char *)fnode_param->value);
8240 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8241 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8244 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8245 fnode_conn->max_segment_size =
8246 *(unsigned *)fnode_param->value;
8248 case ISCSI_FLASHNODE_LOCAL_PORT:
8249 fnode_conn->local_port =
8250 *(uint16_t *)fnode_param->value;
8252 case ISCSI_FLASHNODE_IPV4_TOS:
8253 fnode_conn->ipv4_tos = fnode_param->value[0];
8255 case ISCSI_FLASHNODE_IPV6_TC:
8256 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8258 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8259 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8261 case ISCSI_FLASHNODE_NAME:
8262 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8263 (char *)fnode_param->value);
8265 case ISCSI_FLASHNODE_TPGT:
8266 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8268 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8269 memcpy(fnode_conn->link_local_ipv6_addr,
8270 fnode_param->value, IPv6_ADDR_LEN);
8272 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8273 fnode_sess->discovery_parent_idx =
8274 *(uint16_t *)fnode_param->value;
8276 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8277 fnode_conn->tcp_xmit_wsf =
8278 *(uint8_t *)fnode_param->value;
8280 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8281 fnode_conn->tcp_recv_wsf =
8282 *(uint8_t *)fnode_param->value;
8284 case ISCSI_FLASHNODE_STATSN:
8285 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8287 case ISCSI_FLASHNODE_EXP_STATSN:
8288 fnode_conn->exp_statsn =
8289 *(uint32_t *)fnode_param->value;
8291 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8292 chap_out_idx = *(uint16_t *)fnode_param->value;
8293 if (!qla4xxx_get_uni_chap_at_index(ha,
8297 fnode_sess->chap_out_idx = chap_out_idx;
8298 /* Enable chap auth if chap index is valid */
8299 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8303 ql4_printk(KERN_ERR, ha,
8304 "%s: No such sysfs attribute\n", __func__);
8306 goto exit_set_param;
8310 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8317 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8318 * @fnode_sess: pointer to session attrs of flash ddb entry
8320 * This invalidates the flash ddb entry at the given index
8322 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8324 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8325 struct scsi_qla_host *ha = to_qla_host(shost);
8326 uint32_t dev_db_start_offset;
8327 uint32_t dev_db_end_offset;
8328 struct dev_db_entry *fw_ddb_entry = NULL;
8329 dma_addr_t fw_ddb_entry_dma;
8330 uint16_t *ddb_cookie = NULL;
8331 size_t ddb_size = 0;
8336 if (fnode_sess->is_boot_target) {
8338 DEBUG2(ql4_printk(KERN_ERR, ha,
8339 "%s: Deletion of boot target entry is not permitted.\n",
8344 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8347 if (is_qla40XX(ha)) {
8348 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8349 dev_db_end_offset = FLASH_OFFSET_DB_END;
8350 dev_db_start_offset += (fnode_sess->target_id *
8351 sizeof(*fw_ddb_entry));
8352 ddb_size = sizeof(*fw_ddb_entry);
8354 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8355 (ha->hw.flt_region_ddb << 2);
8356 /* flt_ddb_size is DDB table size for both ports
8357 * so divide it by 2 to calculate the offset for second port
8359 if (ha->port_num == 1)
8360 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8362 dev_db_end_offset = dev_db_start_offset +
8363 (ha->hw.flt_ddb_size / 2);
8365 dev_db_start_offset += (fnode_sess->target_id *
8366 sizeof(*fw_ddb_entry));
8367 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8369 ddb_size = sizeof(*ddb_cookie);
8372 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8373 __func__, dev_db_start_offset, dev_db_end_offset));
8375 if (dev_db_start_offset > dev_db_end_offset) {
8377 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8378 __func__, fnode_sess->target_id));
8382 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8383 &fw_ddb_entry_dma, GFP_KERNEL);
8386 DEBUG2(ql4_printk(KERN_ERR, ha,
8387 "%s: Unable to allocate dma buffer\n",
8392 if (is_qla40XX(ha)) {
8393 fw_ddb_entry = pddb;
8394 memset(fw_ddb_entry, 0, ddb_size);
8395 ddb_cookie = &fw_ddb_entry->cookie;
8400 /* invalidate the cookie */
8401 *ddb_cookie = 0xFFEE;
8402 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8403 ddb_size, FLASH_OPT_RMW_COMMIT);
8406 target_id = fnode_sess->target_id;
8407 iscsi_destroy_flashnode_sess(fnode_sess);
8408 ql4_printk(KERN_INFO, ha,
8409 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8410 __func__, target_id, ha->host_no);
8413 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8419 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8420 * @ha: pointer to adapter structure
8422 * Export the firmware DDB for all send targets and normal targets to sysfs.
8424 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8426 struct dev_db_entry *fw_ddb_entry = NULL;
8427 dma_addr_t fw_ddb_entry_dma;
8430 int ret = QLA_SUCCESS;
8432 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8433 sizeof(*fw_ddb_entry),
8434 &fw_ddb_entry_dma, GFP_KERNEL);
8435 if (!fw_ddb_entry) {
8436 DEBUG2(ql4_printk(KERN_ERR, ha,
8437 "%s: Unable to allocate dma buffer\n",
8442 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8445 for (idx = 0; idx < max_ddbs; idx++) {
8446 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8450 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8457 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8463 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8465 iscsi_destroy_all_flashnode(ha->host);
8469 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8470 * @ha: pointer to adapter structure
8471 * @is_reset: Is this init path or reset path
8473 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8474 * using connection open, then create the list of normal targets (nt)
8475 * from firmware DDBs. Based on the list of nt setup session and connection
8478 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8481 struct list_head list_st, list_nt;
8482 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8483 unsigned long wtime;
8485 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8486 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8487 ha->is_reset = is_reset;
8491 INIT_LIST_HEAD(&list_st);
8492 INIT_LIST_HEAD(&list_nt);
8494 qla4xxx_build_st_list(ha, &list_st);
8496 /* Before issuing conn open mbox, ensure all IPs states are configured
8497 * Note, conn open fails if IPs are not configured
8499 qla4xxx_wait_for_ip_configuration(ha);
8501 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8502 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8503 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8506 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8507 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8508 (ha->def_timeout < LOGIN_TOV * 10) ?
8509 ha->def_timeout : LOGIN_TOV);
8511 DEBUG2(ql4_printk(KERN_INFO, ha,
8512 "Default time to wait for build ddb %d\n", tmo));
8514 wtime = jiffies + (HZ * tmo);
8516 if (list_empty(&list_st))
8519 qla4xxx_remove_failed_ddb(ha, &list_st);
8520 schedule_timeout_uninterruptible(HZ / 10);
8521 } while (time_after(wtime, jiffies));
8524 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8526 qla4xxx_free_ddb_list(&list_st);
8527 qla4xxx_free_ddb_list(&list_nt);
8529 qla4xxx_free_ddb_index(ha);
8533 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8535 * @ha: pointer to adapter structure
8537 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8538 * set in DDB and we will wait for login response of boot targets during
8541 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8543 struct ddb_entry *ddb_entry;
8544 struct dev_db_entry *fw_ddb_entry = NULL;
8545 dma_addr_t fw_ddb_entry_dma;
8546 unsigned long wtime;
8548 int max_ddbs, idx, ret;
8550 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8553 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8554 &fw_ddb_entry_dma, GFP_KERNEL);
8555 if (!fw_ddb_entry) {
8556 ql4_printk(KERN_ERR, ha,
8557 "%s: Unable to allocate dma buffer\n", __func__);
8558 goto exit_login_resp;
8561 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8563 for (idx = 0; idx < max_ddbs; idx++) {
8564 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8565 if (ddb_entry == NULL)
8568 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8569 DEBUG2(ql4_printk(KERN_INFO, ha,
8570 "%s: DDB index [%d]\n", __func__,
8571 ddb_entry->fw_ddb_index));
8573 ret = qla4xxx_get_fwddb_entry(ha,
8574 ddb_entry->fw_ddb_index,
8575 fw_ddb_entry, fw_ddb_entry_dma,
8576 NULL, NULL, &ddb_state, NULL,
8578 if (ret == QLA_ERROR)
8579 goto exit_login_resp;
8581 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8582 (ddb_state == DDB_DS_SESSION_FAILED))
8585 schedule_timeout_uninterruptible(HZ);
8587 } while ((time_after(wtime, jiffies)));
8589 if (!time_after(wtime, jiffies)) {
8590 DEBUG2(ql4_printk(KERN_INFO, ha,
8591 "%s: Login response wait timer expired\n",
8593 goto exit_login_resp;
8600 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8601 fw_ddb_entry, fw_ddb_entry_dma);
8605 * qla4xxx_probe_adapter - callback function to probe HBA
8606 * @pdev: pointer to pci_dev structure
8607 * @ent: pointer to pci_device entry
8609 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8610 * It returns zero if successful. It also initializes all data necessary for
8613 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8614 const struct pci_device_id *ent)
8616 int ret = -ENODEV, status;
8617 struct Scsi_Host *host;
8618 struct scsi_qla_host *ha;
8619 uint8_t init_retry_count = 0;
8621 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8624 if (pci_enable_device(pdev))
8627 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8630 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8631 goto probe_disable_device;
8634 /* Clear our data area */
8635 ha = to_qla_host(host);
8636 memset(ha, 0, sizeof(*ha));
8638 /* Save the information from PCI BIOS. */
8641 ha->host_no = host->host_no;
8642 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8644 pci_enable_pcie_error_reporting(pdev);
8646 /* Setup Runtime configurable options */
8647 if (is_qla8022(ha)) {
8648 ha->isp_ops = &qla4_82xx_isp_ops;
8649 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8650 ha->qdr_sn_window = -1;
8651 ha->ddr_mn_window = -1;
8652 ha->curr_window = 255;
8653 nx_legacy_intr = &legacy_intr[ha->func_num];
8654 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8655 ha->nx_legacy_intr.tgt_status_reg =
8656 nx_legacy_intr->tgt_status_reg;
8657 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8658 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8659 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8660 ha->isp_ops = &qla4_83xx_isp_ops;
8661 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8663 ha->isp_ops = &qla4xxx_isp_ops;
8666 if (is_qla80XX(ha)) {
8667 rwlock_init(&ha->hw_lock);
8668 ha->pf_bit = ha->func_num << 16;
8669 /* Set EEH reset type to fundamental if required by hba */
8670 pdev->needs_freset = 1;
8673 /* Configure PCI I/O space. */
8674 ret = ha->isp_ops->iospace_config(ha);
8676 goto probe_failed_ioconfig;
8678 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8679 pdev->device, pdev->irq, ha->reg);
8681 qla4xxx_config_dma_addressing(ha);
8683 /* Initialize lists and spinlocks. */
8684 INIT_LIST_HEAD(&ha->free_srb_q);
8686 mutex_init(&ha->mbox_sem);
8687 mutex_init(&ha->chap_sem);
8688 init_completion(&ha->mbx_intr_comp);
8689 init_completion(&ha->disable_acb_comp);
8690 init_completion(&ha->idc_comp);
8691 init_completion(&ha->link_up_comp);
8693 spin_lock_init(&ha->hardware_lock);
8694 spin_lock_init(&ha->work_lock);
8696 /* Initialize work list */
8697 INIT_LIST_HEAD(&ha->work_list);
8699 /* Allocate dma buffers */
8700 if (qla4xxx_mem_alloc(ha)) {
8701 ql4_printk(KERN_WARNING, ha,
8702 "[ERROR] Failed to allocate memory for adapter\n");
8708 host->cmd_per_lun = 3;
8709 host->max_channel = 0;
8710 host->max_lun = MAX_LUNS - 1;
8711 host->max_id = MAX_TARGETS;
8712 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8713 host->can_queue = MAX_SRBS ;
8714 host->transportt = qla4xxx_scsi_transport;
8716 pci_set_drvdata(pdev, ha);
8718 ret = scsi_add_host(host, &pdev->dev);
8723 qla4_8xxx_get_flash_info(ha);
8725 if (is_qla8032(ha) || is_qla8042(ha)) {
8726 qla4_83xx_read_reset_template(ha);
8728 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8729 * If DONRESET_BIT0 is set, drivers should not set dev_state
8730 * to NEED_RESET. But if NEED_RESET is set, drivers should
8731 * should honor the reset.
8733 if (ql4xdontresethba == 1)
8734 qla4_83xx_set_idc_dontreset(ha);
8738 * Initialize the Host adapter request/response queues and
8740 * NOTE: interrupts enabled upon successful completion
8742 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8744 /* Dont retry adapter initialization if IRQ allocation failed */
8745 if (is_qla80XX(ha) && (status == QLA_ERROR))
8746 goto skip_retry_init;
8748 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8749 init_retry_count++ < MAX_INIT_RETRIES) {
8751 if (is_qla80XX(ha)) {
8752 ha->isp_ops->idc_lock(ha);
8753 dev_state = qla4_8xxx_rd_direct(ha,
8754 QLA8XXX_CRB_DEV_STATE);
8755 ha->isp_ops->idc_unlock(ha);
8756 if (dev_state == QLA8XXX_DEV_FAILED) {
8757 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8758 "initialize adapter. H/W is in failed state\n",
8763 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8764 "(%d)\n", __func__, init_retry_count));
8766 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8769 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8770 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8771 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8772 goto skip_retry_init;
8777 if (!test_bit(AF_ONLINE, &ha->flags)) {
8778 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8780 if ((is_qla8022(ha) && ql4xdontresethba) ||
8781 ((is_qla8032(ha) || is_qla8042(ha)) &&
8782 qla4_83xx_idc_dontreset(ha))) {
8783 /* Put the device in failed state. */
8784 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8785 ha->isp_ops->idc_lock(ha);
8786 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8787 QLA8XXX_DEV_FAILED);
8788 ha->isp_ops->idc_unlock(ha);
8794 /* Startup the kernel thread for this host adapter. */
8795 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8796 "qla4xxx_dpc\n", __func__));
8797 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8798 ha->dpc_thread = create_singlethread_workqueue(buf);
8799 if (!ha->dpc_thread) {
8800 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8804 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8806 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8809 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8815 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8816 * (which is called indirectly by qla4xxx_initialize_adapter),
8817 * so that irqs will be registered after crbinit but before
8820 if (is_qla40XX(ha)) {
8821 ret = qla4xxx_request_irqs(ha);
8823 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8824 "interrupt %d already in use.\n", pdev->irq);
8829 pci_save_state(ha->pdev);
8830 ha->isp_ops->enable_intrs(ha);
8832 /* Start timer thread. */
8833 qla4xxx_start_timer(ha, 1);
8835 set_bit(AF_INIT_DONE, &ha->flags);
8837 qla4_8xxx_alloc_sysfs_attr(ha);
8840 " QLogic iSCSI HBA Driver version: %s\n"
8841 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8842 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8843 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8844 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8846 /* Set the driver version */
8848 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8850 if (qla4xxx_setup_boot_info(ha))
8851 ql4_printk(KERN_ERR, ha,
8852 "%s: No iSCSI boot target configured\n", __func__);
8854 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8855 /* Perform the build ddb list and login to each */
8856 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8857 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8858 qla4xxx_wait_login_resp_boot_tgt(ha);
8860 qla4xxx_create_chap_list(ha);
8862 qla4xxx_create_ifaces(ha);
8866 scsi_remove_host(ha->host);
8869 qla4xxx_free_adapter(ha);
8871 probe_failed_ioconfig:
8872 pci_disable_pcie_error_reporting(pdev);
8873 scsi_host_put(ha->host);
8875 probe_disable_device:
8876 pci_disable_device(pdev);
8882 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8883 * @ha: pointer to adapter structure
8885 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8886 * so that the other port will not re-initialize while in the process of
8887 * removing the ha due to driver unload or hba hotplug.
8889 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8891 struct scsi_qla_host *other_ha = NULL;
8892 struct pci_dev *other_pdev = NULL;
8893 int fn = ISP4XXX_PCI_FN_2;
8895 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8896 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8897 fn = ISP4XXX_PCI_FN_1;
8900 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8901 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8904 /* Get other_ha if other_pdev is valid and state is enable*/
8906 if (atomic_read(&other_pdev->enable_cnt)) {
8907 other_ha = pci_get_drvdata(other_pdev);
8909 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8910 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8911 "Prevent %s reinit\n", __func__,
8912 dev_name(&other_ha->pdev->dev)));
8915 pci_dev_put(other_pdev);
8919 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8920 struct ddb_entry *ddb_entry)
8922 struct dev_db_entry *fw_ddb_entry = NULL;
8923 dma_addr_t fw_ddb_entry_dma;
8924 unsigned long wtime;
8929 options = LOGOUT_OPTION_CLOSE_SESSION;
8930 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8931 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8935 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8936 &fw_ddb_entry_dma, GFP_KERNEL);
8937 if (!fw_ddb_entry) {
8938 ql4_printk(KERN_ERR, ha,
8939 "%s: Unable to allocate dma buffer\n", __func__);
8943 wtime = jiffies + (HZ * LOGOUT_TOV);
8945 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8946 fw_ddb_entry, fw_ddb_entry_dma,
8947 NULL, NULL, &ddb_state, NULL,
8949 if (status == QLA_ERROR)
8952 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8953 (ddb_state == DDB_DS_SESSION_FAILED))
8956 schedule_timeout_uninterruptible(HZ);
8957 } while ((time_after(wtime, jiffies)));
8960 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8961 fw_ddb_entry, fw_ddb_entry_dma);
8963 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8966 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8968 struct ddb_entry *ddb_entry;
8971 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8973 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8974 if ((ddb_entry != NULL) &&
8975 (ddb_entry->ddb_type == FLASH_DDB)) {
8977 qla4xxx_destroy_ddb(ha, ddb_entry);
8979 * we have decremented the reference count of the driver
8980 * when we setup the session to have the driver unload
8981 * to be seamless without actually destroying the
8984 try_module_get(qla4xxx_iscsi_transport.owner);
8985 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8986 qla4xxx_free_ddb(ha, ddb_entry);
8987 iscsi_session_teardown(ddb_entry->sess);
8992 * qla4xxx_remove_adapter - callback function to remove adapter.
8993 * @pdev: PCI device pointer
8995 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
8997 struct scsi_qla_host *ha;
9000 * If the PCI device is disabled then it means probe_adapter had
9001 * failed and resources already cleaned up on probe_adapter exit.
9003 if (!pci_is_enabled(pdev))
9006 ha = pci_get_drvdata(pdev);
9009 qla4xxx_prevent_other_port_reinit(ha);
9011 /* destroy iface from sysfs */
9012 qla4xxx_destroy_ifaces(ha);
9014 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9015 iscsi_boot_destroy_kset(ha->boot_kset);
9017 qla4xxx_destroy_fw_ddb_session(ha);
9018 qla4_8xxx_free_sysfs_attr(ha);
9020 qla4xxx_sysfs_ddb_remove(ha);
9021 scsi_remove_host(ha->host);
9023 qla4xxx_free_adapter(ha);
9025 scsi_host_put(ha->host);
9027 pci_disable_pcie_error_reporting(pdev);
9028 pci_disable_device(pdev);
9032 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9035 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9037 /* Update our PCI device dma_mask for full 64 bit mask */
9038 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9039 dev_dbg(&ha->pdev->dev,
9040 "Failed to set 64 bit PCI consistent mask; "
9042 dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9046 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9048 struct iscsi_cls_session *cls_sess;
9049 struct iscsi_session *sess;
9050 struct ddb_entry *ddb;
9051 int queue_depth = QL4_DEF_QDEPTH;
9053 cls_sess = starget_to_session(sdev->sdev_target);
9054 sess = cls_sess->dd_data;
9055 ddb = sess->dd_data;
9057 sdev->hostdata = ddb;
9059 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9060 queue_depth = ql4xmaxqdepth;
9062 scsi_change_queue_depth(sdev, queue_depth);
9067 * qla4xxx_del_from_active_array - returns an active srb
9068 * @ha: Pointer to host adapter structure.
9069 * @index: index into the active_array
9071 * This routine removes and returns the srb at the specified index
9073 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9076 struct srb *srb = NULL;
9077 struct scsi_cmnd *cmd = NULL;
9079 cmd = scsi_host_find_tag(ha->host, index);
9083 srb = (struct srb *)CMD_SP(cmd);
9087 /* update counters */
9088 if (srb->flags & SRB_DMA_VALID) {
9089 ha->iocb_cnt -= srb->iocb_cnt;
9091 srb->cmd->host_scribble =
9092 (unsigned char *)(unsigned long) MAX_SRBS;
9098 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9099 * @ha: Pointer to host adapter structure.
9100 * @cmd: Scsi Command to wait on.
9102 * This routine waits for the command to be returned by the Firmware
9103 * for some max time.
9105 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9106 struct scsi_cmnd *cmd)
9110 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9113 /* Dont wait on command if PCI error is being handled
9116 if (unlikely(pci_channel_offline(ha->pdev)) ||
9117 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9118 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9119 ha->host_no, __func__);
9124 /* Checking to see if its returned to OS */
9125 rp = (struct srb *) CMD_SP(cmd);
9132 } while (max_wait_time--);
9138 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9139 * @ha: Pointer to host adapter structure
9141 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9143 unsigned long wait_online;
9145 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9146 while (time_before(jiffies, wait_online)) {
9158 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9159 * @ha: pointer to HBA
9160 * @stgt: pointer to SCSI target
9161 * @sdev: pointer to SCSI device
9163 * This function waits for all outstanding commands to a lun to complete. It
9164 * returns 0 if all pending commands are returned and 1 otherwise.
9166 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9167 struct scsi_target *stgt,
9168 struct scsi_device *sdev)
9172 struct scsi_cmnd *cmd;
9175 * Waiting for all commands for the designated target or dev
9176 * in the active array
9178 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9179 cmd = scsi_host_find_tag(ha->host, cnt);
9180 if (cmd && stgt == scsi_target(cmd->device) &&
9181 (!sdev || sdev == cmd->device)) {
9182 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9192 * qla4xxx_eh_abort - callback for abort task.
9193 * @cmd: Pointer to Linux's SCSI command structure
9195 * This routine is called by the Linux OS to abort the specified
9198 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9200 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9201 unsigned int id = cmd->device->id;
9202 uint64_t lun = cmd->device->lun;
9203 unsigned long flags;
9204 struct srb *srb = NULL;
9209 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9210 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9212 rval = qla4xxx_isp_check_reg(ha);
9213 if (rval != QLA_SUCCESS) {
9214 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9218 spin_lock_irqsave(&ha->hardware_lock, flags);
9219 srb = (struct srb *) CMD_SP(cmd);
9221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9222 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9223 ha->host_no, id, lun);
9226 kref_get(&srb->srb_ref);
9227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9229 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9230 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9231 ha->host_no, id, lun));
9234 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9235 ha->host_no, id, lun));
9239 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9241 /* Wait for command to complete */
9243 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9244 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9245 ha->host_no, id, lun));
9250 ql4_printk(KERN_INFO, ha,
9251 "scsi%ld:%d:%llu: Abort command - %s\n",
9252 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9258 * qla4xxx_eh_device_reset - callback for target reset.
9259 * @cmd: Pointer to Linux's SCSI command structure
9261 * This routine is called by the Linux OS to reset all luns on the
9264 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9266 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9267 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9268 int ret = FAILED, stat;
9274 ret = iscsi_block_scsi_eh(cmd);
9279 ql4_printk(KERN_INFO, ha,
9280 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9281 cmd->device->channel, cmd->device->id, cmd->device->lun);
9283 DEBUG2(printk(KERN_INFO
9284 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9285 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9286 cmd, jiffies, cmd->request->timeout / HZ,
9287 ha->dpc_flags, cmd->result, cmd->allowed));
9289 rval = qla4xxx_isp_check_reg(ha);
9290 if (rval != QLA_SUCCESS) {
9291 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9295 /* FIXME: wait for hba to go online */
9296 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9297 if (stat != QLA_SUCCESS) {
9298 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9299 goto eh_dev_reset_done;
9302 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9304 ql4_printk(KERN_INFO, ha,
9305 "DEVICE RESET FAILED - waiting for "
9307 goto eh_dev_reset_done;
9311 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9312 MM_LUN_RESET) != QLA_SUCCESS)
9313 goto eh_dev_reset_done;
9315 ql4_printk(KERN_INFO, ha,
9316 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9317 ha->host_no, cmd->device->channel, cmd->device->id,
9328 * qla4xxx_eh_target_reset - callback for target reset.
9329 * @cmd: Pointer to Linux's SCSI command structure
9331 * This routine is called by the Linux OS to reset the target.
9333 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9335 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9336 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9343 ret = iscsi_block_scsi_eh(cmd);
9347 starget_printk(KERN_INFO, scsi_target(cmd->device),
9348 "WARM TARGET RESET ISSUED.\n");
9350 DEBUG2(printk(KERN_INFO
9351 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9352 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9353 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9354 ha->dpc_flags, cmd->result, cmd->allowed));
9356 rval = qla4xxx_isp_check_reg(ha);
9357 if (rval != QLA_SUCCESS) {
9358 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9362 stat = qla4xxx_reset_target(ha, ddb_entry);
9363 if (stat != QLA_SUCCESS) {
9364 starget_printk(KERN_INFO, scsi_target(cmd->device),
9365 "WARM TARGET RESET FAILED.\n");
9369 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9371 starget_printk(KERN_INFO, scsi_target(cmd->device),
9372 "WARM TARGET DEVICE RESET FAILED - "
9373 "waiting for commands.\n");
9378 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9379 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9380 starget_printk(KERN_INFO, scsi_target(cmd->device),
9381 "WARM TARGET DEVICE RESET FAILED - "
9382 "marker iocb failed.\n");
9386 starget_printk(KERN_INFO, scsi_target(cmd->device),
9387 "WARM TARGET RESET SUCCEEDED.\n");
9392 * qla4xxx_is_eh_active - check if error handler is running
9393 * @shost: Pointer to SCSI Host struct
9395 * This routine finds that if reset host is called in EH
9396 * scenario or from some application like sg_reset
9398 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9400 if (shost->shost_state == SHOST_RECOVERY)
9406 * qla4xxx_eh_host_reset - kernel callback
9407 * @cmd: Pointer to Linux's SCSI command structure
9409 * This routine is invoked by the Linux kernel to perform fatal error
9410 * recovery on the specified adapter.
9412 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9414 int return_status = FAILED;
9415 struct scsi_qla_host *ha;
9418 ha = to_qla_host(cmd->device->host);
9420 rval = qla4xxx_isp_check_reg(ha);
9421 if (rval != QLA_SUCCESS) {
9422 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9426 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9427 qla4_83xx_set_idc_dontreset(ha);
9430 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9431 * protocol drivers, we should not set device_state to NEED_RESET
9433 if (ql4xdontresethba ||
9434 ((is_qla8032(ha) || is_qla8042(ha)) &&
9435 qla4_83xx_idc_dontreset(ha))) {
9436 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9437 ha->host_no, __func__));
9439 /* Clear outstanding srb in queues */
9440 if (qla4xxx_is_eh_active(cmd->device->host))
9441 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9446 ql4_printk(KERN_INFO, ha,
9447 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9448 cmd->device->channel, cmd->device->id, cmd->device->lun);
9450 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9451 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9452 "DEAD.\n", ha->host_no, cmd->device->channel,
9458 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9460 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9462 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9465 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9466 return_status = SUCCESS;
9468 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9469 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9471 return return_status;
9474 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9476 uint32_t mbox_cmd[MBOX_REG_COUNT];
9477 uint32_t mbox_sts[MBOX_REG_COUNT];
9478 struct addr_ctrl_blk_def *acb = NULL;
9479 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9480 int rval = QLA_SUCCESS;
9483 acb = dma_alloc_coherent(&ha->pdev->dev,
9484 sizeof(struct addr_ctrl_blk_def),
9485 &acb_dma, GFP_KERNEL);
9487 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9490 goto exit_port_reset;
9493 memset(acb, 0, acb_len);
9495 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9496 if (rval != QLA_SUCCESS) {
9501 rval = qla4xxx_disable_acb(ha);
9502 if (rval != QLA_SUCCESS) {
9507 wait_for_completion_timeout(&ha->disable_acb_comp,
9508 DISABLE_ACB_TOV * HZ);
9510 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9511 if (rval != QLA_SUCCESS) {
9517 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9520 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9521 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9525 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9527 struct scsi_qla_host *ha = to_qla_host(shost);
9528 int rval = QLA_SUCCESS;
9531 if (ql4xdontresethba) {
9532 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9535 goto exit_host_reset;
9538 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9539 goto recover_adapter;
9541 switch (reset_type) {
9542 case SCSI_ADAPTER_RESET:
9543 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9545 case SCSI_FIRMWARE_RESET:
9546 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9548 /* set firmware context reset */
9549 set_bit(DPC_RESET_HA_FW_CONTEXT,
9552 rval = qla4xxx_context_reset(ha);
9553 goto exit_host_reset;
9560 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9561 * reset is issued by application */
9562 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9563 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9564 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9565 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9566 (idc_ctrl | GRACEFUL_RESET_BIT1));
9569 rval = qla4xxx_recover_adapter(ha);
9570 if (rval != QLA_SUCCESS) {
9571 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9580 /* PCI AER driver recovers from all correctable errors w/o
9581 * driver intervention. For uncorrectable errors PCI AER
9582 * driver calls the following device driver's callbacks
9584 * - Fatal Errors - link_reset
9585 * - Non-Fatal Errors - driver's error_detected() which
9586 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9588 * PCI AER driver calls
9589 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9590 * returns RECOVERED or NEED_RESET if fw_hung
9591 * NEED_RESET - driver's slot_reset()
9592 * DISCONNECT - device is dead & cannot recover
9593 * RECOVERED - driver's resume()
9595 static pci_ers_result_t
9596 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9598 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9600 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9601 ha->host_no, __func__, state);
9603 if (!is_aer_supported(ha))
9604 return PCI_ERS_RESULT_NONE;
9607 case pci_channel_io_normal:
9608 clear_bit(AF_EEH_BUSY, &ha->flags);
9609 return PCI_ERS_RESULT_CAN_RECOVER;
9610 case pci_channel_io_frozen:
9611 set_bit(AF_EEH_BUSY, &ha->flags);
9612 qla4xxx_mailbox_premature_completion(ha);
9613 qla4xxx_free_irqs(ha);
9614 pci_disable_device(pdev);
9615 /* Return back all IOs */
9616 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9617 return PCI_ERS_RESULT_NEED_RESET;
9618 case pci_channel_io_perm_failure:
9619 set_bit(AF_EEH_BUSY, &ha->flags);
9620 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9621 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9622 return PCI_ERS_RESULT_DISCONNECT;
9624 return PCI_ERS_RESULT_NEED_RESET;
9628 * qla4xxx_pci_mmio_enabled() - gets called if
9629 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9630 * and read/write to the device still works.
9631 * @pdev: PCI device pointer
9633 static pci_ers_result_t
9634 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9636 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9638 if (!is_aer_supported(ha))
9639 return PCI_ERS_RESULT_NONE;
9641 return PCI_ERS_RESULT_RECOVERED;
9644 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9646 uint32_t rval = QLA_ERROR;
9648 struct pci_dev *other_pdev = NULL;
9650 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9652 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9654 if (test_bit(AF_ONLINE, &ha->flags)) {
9655 clear_bit(AF_ONLINE, &ha->flags);
9656 clear_bit(AF_LINK_UP, &ha->flags);
9657 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9658 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9661 fn = PCI_FUNC(ha->pdev->devfn);
9662 if (is_qla8022(ha)) {
9665 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9666 ha->host_no, __func__, fn);
9667 /* Get the pci device given the domain, bus,
9668 * slot/function number */
9669 other_pdev = pci_get_domain_bus_and_slot(
9670 pci_domain_nr(ha->pdev->bus),
9671 ha->pdev->bus->number,
9672 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9678 if (atomic_read(&other_pdev->enable_cnt)) {
9679 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9680 ha->host_no, __func__, fn);
9681 pci_dev_put(other_pdev);
9684 pci_dev_put(other_pdev);
9687 /* this case is meant for ISP83xx/ISP84xx only */
9688 if (qla4_83xx_can_perform_reset(ha)) {
9689 /* reset fn as iSCSI is going to perform the reset */
9694 /* The first function on the card, the reset owner will
9695 * start & initialize the firmware. The other functions
9696 * on the card will reset the firmware context
9699 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9700 "0x%x is the owner\n", ha->host_no, __func__,
9703 ha->isp_ops->idc_lock(ha);
9704 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9706 ha->isp_ops->idc_unlock(ha);
9708 rval = qla4_8xxx_update_idc_reg(ha);
9709 if (rval == QLA_ERROR) {
9710 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9711 ha->host_no, __func__);
9712 ha->isp_ops->idc_lock(ha);
9713 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9714 QLA8XXX_DEV_FAILED);
9715 ha->isp_ops->idc_unlock(ha);
9716 goto exit_error_recovery;
9719 clear_bit(AF_FW_RECOVERY, &ha->flags);
9720 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9722 if (rval != QLA_SUCCESS) {
9723 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9724 "FAILED\n", ha->host_no, __func__);
9725 qla4xxx_free_irqs(ha);
9726 ha->isp_ops->idc_lock(ha);
9727 qla4_8xxx_clear_drv_active(ha);
9728 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9729 QLA8XXX_DEV_FAILED);
9730 ha->isp_ops->idc_unlock(ha);
9732 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9733 "READY\n", ha->host_no, __func__);
9734 ha->isp_ops->idc_lock(ha);
9735 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9737 /* Clear driver state register */
9738 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9739 qla4_8xxx_set_drv_active(ha);
9740 ha->isp_ops->idc_unlock(ha);
9741 ha->isp_ops->enable_intrs(ha);
9744 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9745 "the reset owner\n", ha->host_no, __func__,
9747 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9748 QLA8XXX_DEV_READY)) {
9749 clear_bit(AF_FW_RECOVERY, &ha->flags);
9750 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9751 if (rval == QLA_SUCCESS)
9752 ha->isp_ops->enable_intrs(ha);
9754 qla4xxx_free_irqs(ha);
9756 ha->isp_ops->idc_lock(ha);
9757 qla4_8xxx_set_drv_active(ha);
9758 ha->isp_ops->idc_unlock(ha);
9761 exit_error_recovery:
9762 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9766 static pci_ers_result_t
9767 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9769 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9770 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9773 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9774 ha->host_no, __func__);
9776 if (!is_aer_supported(ha))
9777 return PCI_ERS_RESULT_NONE;
9779 /* Restore the saved state of PCIe device -
9780 * BAR registers, PCI Config space, PCIX, MSI,
9783 pci_restore_state(pdev);
9785 /* pci_restore_state() clears the saved_state flag of the device
9786 * save restored state which resets saved_state flag
9788 pci_save_state(pdev);
9790 /* Initialize device or resume if in suspended state */
9791 rc = pci_enable_device(pdev);
9793 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9794 "device after reset\n", ha->host_no, __func__);
9795 goto exit_slot_reset;
9798 ha->isp_ops->disable_intrs(ha);
9800 if (is_qla80XX(ha)) {
9801 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9802 ret = PCI_ERS_RESULT_RECOVERED;
9803 goto exit_slot_reset;
9805 goto exit_slot_reset;
9809 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9810 "device after reset\n", ha->host_no, __func__, ret);
9815 qla4xxx_pci_resume(struct pci_dev *pdev)
9817 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9820 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9821 ha->host_no, __func__);
9823 ret = qla4xxx_wait_for_hba_online(ha);
9824 if (ret != QLA_SUCCESS) {
9825 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9826 "resume I/O from slot/link_reset\n", ha->host_no,
9830 clear_bit(AF_EEH_BUSY, &ha->flags);
9833 static const struct pci_error_handlers qla4xxx_err_handler = {
9834 .error_detected = qla4xxx_pci_error_detected,
9835 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9836 .slot_reset = qla4xxx_pci_slot_reset,
9837 .resume = qla4xxx_pci_resume,
9840 static struct pci_device_id qla4xxx_pci_tbl[] = {
9842 .vendor = PCI_VENDOR_ID_QLOGIC,
9843 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9844 .subvendor = PCI_ANY_ID,
9845 .subdevice = PCI_ANY_ID,
9848 .vendor = PCI_VENDOR_ID_QLOGIC,
9849 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9850 .subvendor = PCI_ANY_ID,
9851 .subdevice = PCI_ANY_ID,
9854 .vendor = PCI_VENDOR_ID_QLOGIC,
9855 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9856 .subvendor = PCI_ANY_ID,
9857 .subdevice = PCI_ANY_ID,
9860 .vendor = PCI_VENDOR_ID_QLOGIC,
9861 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9862 .subvendor = PCI_ANY_ID,
9863 .subdevice = PCI_ANY_ID,
9866 .vendor = PCI_VENDOR_ID_QLOGIC,
9867 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9868 .subvendor = PCI_ANY_ID,
9869 .subdevice = PCI_ANY_ID,
9872 .vendor = PCI_VENDOR_ID_QLOGIC,
9873 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9874 .subvendor = PCI_ANY_ID,
9875 .subdevice = PCI_ANY_ID,
9879 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9881 static struct pci_driver qla4xxx_pci_driver = {
9882 .name = DRIVER_NAME,
9883 .id_table = qla4xxx_pci_tbl,
9884 .probe = qla4xxx_probe_adapter,
9885 .remove = qla4xxx_remove_adapter,
9886 .err_handler = &qla4xxx_err_handler,
9889 static int __init qla4xxx_module_init(void)
9893 if (ql4xqfulltracking)
9894 qla4xxx_driver_template.track_queue_depth = 1;
9896 /* Allocate cache for SRBs. */
9897 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9898 SLAB_HWCACHE_ALIGN, NULL);
9899 if (srb_cachep == NULL) {
9901 "%s: Unable to allocate SRB cache..."
9902 "Failing load!\n", DRIVER_NAME);
9907 /* Derive version string. */
9908 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9909 if (ql4xextended_error_logging)
9910 strcat(qla4xxx_version_str, "-debug");
9912 qla4xxx_scsi_transport =
9913 iscsi_register_transport(&qla4xxx_iscsi_transport);
9914 if (!qla4xxx_scsi_transport){
9916 goto release_srb_cache;
9919 ret = pci_register_driver(&qla4xxx_pci_driver);
9921 goto unregister_transport;
9923 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9926 unregister_transport:
9927 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9929 kmem_cache_destroy(srb_cachep);
9934 static void __exit qla4xxx_module_exit(void)
9936 pci_unregister_driver(&qla4xxx_pci_driver);
9937 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9938 kmem_cache_destroy(srb_cachep);
9941 module_init(qla4xxx_module_init);
9942 module_exit(qla4xxx_module_exit);
9944 MODULE_AUTHOR("QLogic Corporation");
9945 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9946 MODULE_LICENSE("GPL");
9947 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);