2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/blkdev.h>
10 #include <linux/iscsi_boot_sysfs.h>
11 #include <linux/inet.h>
13 #include <scsi/scsi_tcq.h>
14 #include <scsi/scsicam.h>
17 #include "ql4_version.h"
20 #include "ql4_inline.h"
26 static char qla4xxx_version_str[40];
29 * SRB allocation cache
31 static struct kmem_cache *srb_cachep;
34 * Module parameter information and variables
36 static int ql4xdisablesysfsboot = 1;
37 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
38 MODULE_PARM_DESC(ql4xdisablesysfsboot,
39 " Set to disable exporting boot targets to sysfs.\n"
40 "\t\t 0 - Export boot targets\n"
41 "\t\t 1 - Do not export boot targets (Default)");
44 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql4xdontresethba,
46 " Don't reset the HBA for driver recovery.\n"
47 "\t\t 0 - It will reset HBA (Default)\n"
48 "\t\t 1 - It will NOT reset HBA");
50 int ql4xextended_error_logging;
51 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
52 MODULE_PARM_DESC(ql4xextended_error_logging,
53 " Option to enable extended error logging.\n"
54 "\t\t 0 - no logging (Default)\n"
55 "\t\t 2 - debug logging");
57 int ql4xenablemsix = 1;
58 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
59 MODULE_PARM_DESC(ql4xenablemsix,
60 " Set to enable MSI or MSI-X interrupt mechanism.\n"
61 "\t\t 0 = enable INTx interrupt mechanism.\n"
62 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
63 "\t\t 2 = enable MSI interrupt mechanism.");
65 #define QL4_DEF_QDEPTH 32
66 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
67 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
68 MODULE_PARM_DESC(ql4xmaxqdepth,
69 " Maximum queue depth to report for target devices.\n"
72 static int ql4xqfulltracking = 1;
73 module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
74 MODULE_PARM_DESC(ql4xqfulltracking,
75 " Enable or disable dynamic tracking and adjustment of\n"
76 "\t\t scsi device queue depth.\n"
78 "\t\t 1 - Enable. (Default)");
80 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
81 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
82 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
83 " Target Session Recovery Timeout.\n"
84 "\t\t Default: 120 sec.");
86 int ql4xmdcapmask = 0;
87 module_param(ql4xmdcapmask, int, S_IRUGO);
88 MODULE_PARM_DESC(ql4xmdcapmask,
89 " Set the Minidump driver capture mask level.\n"
90 "\t\t Default is 0 (firmware default capture mask)\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
94 module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
95 MODULE_PARM_DESC(ql4xenablemd,
96 " Set to enable minidump.\n"
97 "\t\t 0 - disable minidump\n"
98 "\t\t 1 - enable minidump (Default)");
100 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
102 * SCSI host template entry points
104 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
107 * iSCSI template entry points
109 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
110 enum iscsi_param param, char *buf);
111 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
112 enum iscsi_param param, char *buf);
113 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
114 enum iscsi_host_param param, char *buf);
115 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
117 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
118 enum iscsi_param_type param_type,
119 int param, char *buf);
120 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
121 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
122 struct sockaddr *dst_addr,
124 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
125 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
126 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
127 enum iscsi_param param, char *buf);
128 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
129 static struct iscsi_cls_conn *
130 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
131 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
132 struct iscsi_cls_conn *cls_conn,
133 uint64_t transport_fd, int is_leading);
134 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
135 static struct iscsi_cls_session *
136 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
137 uint16_t qdepth, uint32_t initial_cmdsn);
138 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
139 static void qla4xxx_task_work(struct work_struct *wdata);
140 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
141 static int qla4xxx_task_xmit(struct iscsi_task *);
142 static void qla4xxx_task_cleanup(struct iscsi_task *);
143 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
144 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
145 struct iscsi_stats *stats);
146 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
147 uint32_t iface_type, uint32_t payload_size,
148 uint32_t pid, struct sockaddr *dst_addr);
149 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
150 uint32_t *num_entries, char *buf);
151 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
152 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
154 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
157 * SCSI host template entry points
159 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
161 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
162 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
163 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164 static int qla4xxx_slave_alloc(struct scsi_device *device);
165 static umode_t qla4_attr_is_visible(int param_type, int param);
166 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
169 * iSCSI Flash DDB sysfs entry points
172 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
173 struct iscsi_bus_flash_conn *fnode_conn,
174 void *data, int len);
176 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
177 int param, char *buf);
178 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
181 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
182 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
183 struct iscsi_bus_flash_conn *fnode_conn);
184 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
185 struct iscsi_bus_flash_conn *fnode_conn);
186 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
188 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
189 QLA82XX_LEGACY_INTR_CONFIG;
191 static struct scsi_host_template qla4xxx_driver_template = {
192 .module = THIS_MODULE,
194 .proc_name = DRIVER_NAME,
195 .queuecommand = qla4xxx_queuecommand,
197 .eh_abort_handler = qla4xxx_eh_abort,
198 .eh_device_reset_handler = qla4xxx_eh_device_reset,
199 .eh_target_reset_handler = qla4xxx_eh_target_reset,
200 .eh_host_reset_handler = qla4xxx_eh_host_reset,
201 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
203 .slave_alloc = qla4xxx_slave_alloc,
204 .change_queue_depth = scsi_change_queue_depth,
208 .use_clustering = ENABLE_CLUSTERING,
209 .sg_tablesize = SG_ALL,
211 .max_sectors = 0xFFFF,
212 .shost_attrs = qla4xxx_host_attrs,
213 .host_reset = qla4xxx_host_reset,
214 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
217 static struct iscsi_transport qla4xxx_iscsi_transport = {
218 .owner = THIS_MODULE,
220 .caps = CAP_TEXT_NEGO |
221 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
222 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
224 .attr_is_visible = qla4_attr_is_visible,
225 .create_session = qla4xxx_session_create,
226 .destroy_session = qla4xxx_session_destroy,
227 .start_conn = qla4xxx_conn_start,
228 .create_conn = qla4xxx_conn_create,
229 .bind_conn = qla4xxx_conn_bind,
230 .stop_conn = iscsi_conn_stop,
231 .destroy_conn = qla4xxx_conn_destroy,
232 .set_param = iscsi_set_param,
233 .get_conn_param = qla4xxx_conn_get_param,
234 .get_session_param = qla4xxx_session_get_param,
235 .get_ep_param = qla4xxx_get_ep_param,
236 .ep_connect = qla4xxx_ep_connect,
237 .ep_poll = qla4xxx_ep_poll,
238 .ep_disconnect = qla4xxx_ep_disconnect,
239 .get_stats = qla4xxx_conn_get_stats,
240 .send_pdu = iscsi_conn_send_pdu,
241 .xmit_task = qla4xxx_task_xmit,
242 .cleanup_task = qla4xxx_task_cleanup,
243 .alloc_pdu = qla4xxx_alloc_pdu,
245 .get_host_param = qla4xxx_host_get_param,
246 .set_iface_param = qla4xxx_iface_set_param,
247 .get_iface_param = qla4xxx_get_iface_param,
248 .bsg_request = qla4xxx_bsg_request,
249 .send_ping = qla4xxx_send_ping,
250 .get_chap = qla4xxx_get_chap_list,
251 .delete_chap = qla4xxx_delete_chap,
252 .set_chap = qla4xxx_set_chap_entry,
253 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
254 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
255 .new_flashnode = qla4xxx_sysfs_ddb_add,
256 .del_flashnode = qla4xxx_sysfs_ddb_delete,
257 .login_flashnode = qla4xxx_sysfs_ddb_login,
258 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
259 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
260 .get_host_stats = qla4xxx_get_host_stats,
263 static struct scsi_transport_template *qla4xxx_scsi_transport;
265 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
266 uint32_t iface_type, uint32_t payload_size,
267 uint32_t pid, struct sockaddr *dst_addr)
269 struct scsi_qla_host *ha = to_qla_host(shost);
270 struct sockaddr_in *addr;
271 struct sockaddr_in6 *addr6;
272 uint32_t options = 0;
273 uint8_t ipaddr[IPv6_ADDR_LEN];
276 memset(ipaddr, 0, IPv6_ADDR_LEN);
278 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
279 (dst_addr->sa_family == AF_INET)) {
280 addr = (struct sockaddr_in *)dst_addr;
281 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
282 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
283 "dest: %pI4\n", __func__,
284 &ha->ip_config.ip_address, ipaddr));
285 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
289 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
290 (dst_addr->sa_family == AF_INET6)) {
292 addr6 = (struct sockaddr_in6 *)dst_addr;
293 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
295 options |= PING_IPV6_PROTOCOL_ENABLE;
297 /* Ping using LinkLocal address */
298 if ((iface_num == 0) || (iface_num == 1)) {
299 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
300 "src: %pI6 dest: %pI6\n", __func__,
301 &ha->ip_config.ipv6_link_local_addr,
303 options |= PING_IPV6_LINKLOCAL_ADDR;
304 rval = qla4xxx_ping_iocb(ha, options, payload_size,
307 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
308 "not supported\n", __func__, iface_num);
314 * If ping using LinkLocal address fails, try ping using
317 if (rval != QLA_SUCCESS) {
318 options &= ~PING_IPV6_LINKLOCAL_ADDR;
319 if (iface_num == 0) {
320 options |= PING_IPV6_ADDR0;
321 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
323 "dest: %pI6\n", __func__,
324 &ha->ip_config.ipv6_addr0,
326 } else if (iface_num == 1) {
327 options |= PING_IPV6_ADDR1;
328 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
330 "dest: %pI6\n", __func__,
331 &ha->ip_config.ipv6_addr1,
334 rval = qla4xxx_ping_iocb(ha, options, payload_size,
345 static umode_t qla4_attr_is_visible(int param_type, int param)
347 switch (param_type) {
348 case ISCSI_HOST_PARAM:
350 case ISCSI_HOST_PARAM_HWADDRESS:
351 case ISCSI_HOST_PARAM_IPADDRESS:
352 case ISCSI_HOST_PARAM_INITIATOR_NAME:
353 case ISCSI_HOST_PARAM_PORT_STATE:
354 case ISCSI_HOST_PARAM_PORT_SPEED:
361 case ISCSI_PARAM_PERSISTENT_ADDRESS:
362 case ISCSI_PARAM_PERSISTENT_PORT:
363 case ISCSI_PARAM_CONN_ADDRESS:
364 case ISCSI_PARAM_CONN_PORT:
365 case ISCSI_PARAM_TARGET_NAME:
366 case ISCSI_PARAM_TPGT:
367 case ISCSI_PARAM_TARGET_ALIAS:
368 case ISCSI_PARAM_MAX_BURST:
369 case ISCSI_PARAM_MAX_R2T:
370 case ISCSI_PARAM_FIRST_BURST:
371 case ISCSI_PARAM_MAX_RECV_DLENGTH:
372 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
373 case ISCSI_PARAM_IFACE_NAME:
374 case ISCSI_PARAM_CHAP_OUT_IDX:
375 case ISCSI_PARAM_CHAP_IN_IDX:
376 case ISCSI_PARAM_USERNAME:
377 case ISCSI_PARAM_PASSWORD:
378 case ISCSI_PARAM_USERNAME_IN:
379 case ISCSI_PARAM_PASSWORD_IN:
380 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
381 case ISCSI_PARAM_DISCOVERY_SESS:
382 case ISCSI_PARAM_PORTAL_TYPE:
383 case ISCSI_PARAM_CHAP_AUTH_EN:
384 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
385 case ISCSI_PARAM_BIDI_CHAP_EN:
386 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
387 case ISCSI_PARAM_DEF_TIME2WAIT:
388 case ISCSI_PARAM_DEF_TIME2RETAIN:
389 case ISCSI_PARAM_HDRDGST_EN:
390 case ISCSI_PARAM_DATADGST_EN:
391 case ISCSI_PARAM_INITIAL_R2T_EN:
392 case ISCSI_PARAM_IMM_DATA_EN:
393 case ISCSI_PARAM_PDU_INORDER_EN:
394 case ISCSI_PARAM_DATASEQ_INORDER_EN:
395 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
396 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
397 case ISCSI_PARAM_TCP_WSF_DISABLE:
398 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
399 case ISCSI_PARAM_TCP_TIMER_SCALE:
400 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
401 case ISCSI_PARAM_TCP_XMIT_WSF:
402 case ISCSI_PARAM_TCP_RECV_WSF:
403 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
404 case ISCSI_PARAM_IPV4_TOS:
405 case ISCSI_PARAM_IPV6_TC:
406 case ISCSI_PARAM_IPV6_FLOW_LABEL:
407 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
408 case ISCSI_PARAM_KEEPALIVE_TMO:
409 case ISCSI_PARAM_LOCAL_PORT:
410 case ISCSI_PARAM_ISID:
411 case ISCSI_PARAM_TSID:
412 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
413 case ISCSI_PARAM_ERL:
414 case ISCSI_PARAM_STATSN:
415 case ISCSI_PARAM_EXP_STATSN:
416 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
417 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
418 case ISCSI_PARAM_LOCAL_IPADDR:
423 case ISCSI_NET_PARAM:
425 case ISCSI_NET_PARAM_IPV4_ADDR:
426 case ISCSI_NET_PARAM_IPV4_SUBNET:
427 case ISCSI_NET_PARAM_IPV4_GW:
428 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
429 case ISCSI_NET_PARAM_IFACE_ENABLE:
430 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
431 case ISCSI_NET_PARAM_IPV6_ADDR:
432 case ISCSI_NET_PARAM_IPV6_ROUTER:
433 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
434 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
435 case ISCSI_NET_PARAM_VLAN_ID:
436 case ISCSI_NET_PARAM_VLAN_PRIORITY:
437 case ISCSI_NET_PARAM_VLAN_ENABLED:
438 case ISCSI_NET_PARAM_MTU:
439 case ISCSI_NET_PARAM_PORT:
440 case ISCSI_NET_PARAM_IPADDR_STATE:
441 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
442 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
443 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
444 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
445 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
446 case ISCSI_NET_PARAM_TCP_WSF:
447 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
448 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
449 case ISCSI_NET_PARAM_CACHE_ID:
450 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
451 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
452 case ISCSI_NET_PARAM_IPV4_TOS_EN:
453 case ISCSI_NET_PARAM_IPV4_TOS:
454 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
455 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
456 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
457 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
458 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
459 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
460 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
461 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
462 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
463 case ISCSI_NET_PARAM_REDIRECT_EN:
464 case ISCSI_NET_PARAM_IPV4_TTL:
465 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
466 case ISCSI_NET_PARAM_IPV6_MLD_EN:
467 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
468 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
469 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
470 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
471 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
472 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
473 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
474 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
479 case ISCSI_IFACE_PARAM:
481 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
482 case ISCSI_IFACE_PARAM_HDRDGST_EN:
483 case ISCSI_IFACE_PARAM_DATADGST_EN:
484 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
485 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
486 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
487 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
488 case ISCSI_IFACE_PARAM_ERL:
489 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
490 case ISCSI_IFACE_PARAM_FIRST_BURST:
491 case ISCSI_IFACE_PARAM_MAX_R2T:
492 case ISCSI_IFACE_PARAM_MAX_BURST:
493 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
494 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
495 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
496 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
497 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
498 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
503 case ISCSI_FLASHNODE_PARAM:
505 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
506 case ISCSI_FLASHNODE_PORTAL_TYPE:
507 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
508 case ISCSI_FLASHNODE_DISCOVERY_SESS:
509 case ISCSI_FLASHNODE_ENTRY_EN:
510 case ISCSI_FLASHNODE_HDR_DGST_EN:
511 case ISCSI_FLASHNODE_DATA_DGST_EN:
512 case ISCSI_FLASHNODE_IMM_DATA_EN:
513 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
514 case ISCSI_FLASHNODE_DATASEQ_INORDER:
515 case ISCSI_FLASHNODE_PDU_INORDER:
516 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
517 case ISCSI_FLASHNODE_SNACK_REQ_EN:
518 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
519 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
520 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
521 case ISCSI_FLASHNODE_ERL:
522 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
523 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
524 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
525 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
526 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
527 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
528 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
529 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
530 case ISCSI_FLASHNODE_FIRST_BURST:
531 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
532 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
533 case ISCSI_FLASHNODE_MAX_R2T:
534 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
535 case ISCSI_FLASHNODE_ISID:
536 case ISCSI_FLASHNODE_TSID:
537 case ISCSI_FLASHNODE_PORT:
538 case ISCSI_FLASHNODE_MAX_BURST:
539 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
540 case ISCSI_FLASHNODE_IPADDR:
541 case ISCSI_FLASHNODE_ALIAS:
542 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
543 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
544 case ISCSI_FLASHNODE_LOCAL_PORT:
545 case ISCSI_FLASHNODE_IPV4_TOS:
546 case ISCSI_FLASHNODE_IPV6_TC:
547 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
548 case ISCSI_FLASHNODE_NAME:
549 case ISCSI_FLASHNODE_TPGT:
550 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
551 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
552 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
553 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
554 case ISCSI_FLASHNODE_TCP_RECV_WSF:
555 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
556 case ISCSI_FLASHNODE_USERNAME:
557 case ISCSI_FLASHNODE_PASSWORD:
558 case ISCSI_FLASHNODE_STATSN:
559 case ISCSI_FLASHNODE_EXP_STATSN:
560 case ISCSI_FLASHNODE_IS_BOOT_TGT:
571 * qla4xxx_create chap_list - Create CHAP list from FLASH
572 * @ha: pointer to adapter structure
574 * Read flash and make a list of CHAP entries, during login when a CHAP entry
575 * is received, it will be checked in this list. If entry exist then the CHAP
576 * entry index is set in the DDB. If CHAP entry does not exist in this list
577 * then a new entry is added in FLASH in CHAP table and the index obtained is
580 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
583 uint8_t *chap_flash_data = NULL;
586 uint32_t chap_size = 0;
589 chap_size = MAX_CHAP_ENTRIES_40XX *
590 sizeof(struct ql4_chap_table);
591 else /* Single region contains CHAP info for both
592 * ports which is divided into half for each port.
594 chap_size = ha->hw.flt_chap_size / 2;
596 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
597 &chap_dma, GFP_KERNEL);
598 if (!chap_flash_data) {
599 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
603 if (is_qla40XX(ha)) {
604 offset = FLASH_CHAP_OFFSET;
606 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
607 if (ha->port_num == 1)
611 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
612 if (rval != QLA_SUCCESS)
615 if (ha->chap_list == NULL)
616 ha->chap_list = vmalloc(chap_size);
617 if (ha->chap_list == NULL) {
618 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
622 memset(ha->chap_list, 0, chap_size);
623 memcpy(ha->chap_list, chap_flash_data, chap_size);
626 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
629 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
631 struct ql4_chap_table **chap_entry)
633 int rval = QLA_ERROR;
634 int max_chap_entries;
636 if (!ha->chap_list) {
637 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
643 max_chap_entries = (ha->hw.flt_chap_size / 2) /
644 sizeof(struct ql4_chap_table);
646 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
648 if (chap_index > max_chap_entries) {
649 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
654 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
655 if ((*chap_entry)->cookie !=
656 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
668 * qla4xxx_find_free_chap_index - Find the first free chap index
669 * @ha: pointer to adapter structure
670 * @chap_index: CHAP index to be returned
672 * Find the first free chap index available in the chap table
674 * Note: Caller should acquire the chap lock before getting here.
676 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
677 uint16_t *chap_index)
681 int max_chap_entries = 0;
682 struct ql4_chap_table *chap_table;
685 max_chap_entries = (ha->hw.flt_chap_size / 2) /
686 sizeof(struct ql4_chap_table);
688 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
690 if (!ha->chap_list) {
691 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
696 for (i = 0; i < max_chap_entries; i++) {
697 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
699 if ((chap_table->cookie !=
700 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
701 (i > MAX_RESRV_CHAP_IDX)) {
707 if (free_index != -1) {
708 *chap_index = free_index;
718 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
719 uint32_t *num_entries, char *buf)
721 struct scsi_qla_host *ha = to_qla_host(shost);
722 struct ql4_chap_table *chap_table;
723 struct iscsi_chap_rec *chap_rec;
724 int max_chap_entries = 0;
725 int valid_chap_entries = 0;
729 max_chap_entries = (ha->hw.flt_chap_size / 2) /
730 sizeof(struct ql4_chap_table);
732 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
734 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
735 __func__, *num_entries, chap_tbl_idx);
739 goto exit_get_chap_list;
742 qla4xxx_create_chap_list(ha);
744 chap_rec = (struct iscsi_chap_rec *) buf;
745 mutex_lock(&ha->chap_sem);
746 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
747 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
748 if (chap_table->cookie !=
749 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
752 chap_rec->chap_tbl_idx = i;
753 strlcpy(chap_rec->username, chap_table->name,
754 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
755 strlcpy(chap_rec->password, chap_table->secret,
756 QL4_CHAP_MAX_SECRET_LEN);
757 chap_rec->password_length = chap_table->secret_len;
759 if (chap_table->flags & BIT_7) /* local */
760 chap_rec->chap_type = CHAP_TYPE_OUT;
762 if (chap_table->flags & BIT_6) /* peer */
763 chap_rec->chap_type = CHAP_TYPE_IN;
767 valid_chap_entries++;
768 if (valid_chap_entries == *num_entries)
773 mutex_unlock(&ha->chap_sem);
776 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
777 __func__, valid_chap_entries);
778 *num_entries = valid_chap_entries;
782 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
785 uint16_t *chap_tbl_idx = (uint16_t *) data;
786 struct iscsi_cls_session *cls_session;
787 struct iscsi_session *sess;
788 struct ddb_entry *ddb_entry;
790 if (!iscsi_is_session_dev(dev))
791 goto exit_is_chap_active;
793 cls_session = iscsi_dev_to_session(dev);
794 sess = cls_session->dd_data;
795 ddb_entry = sess->dd_data;
797 if (iscsi_session_chkready(cls_session))
798 goto exit_is_chap_active;
800 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
807 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
808 uint16_t chap_tbl_idx)
812 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
813 __qla4xxx_is_chap_active);
818 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
820 struct scsi_qla_host *ha = to_qla_host(shost);
821 struct ql4_chap_table *chap_table;
823 int max_chap_entries = 0;
828 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
829 if (chap_table == NULL)
832 memset(chap_table, 0, sizeof(struct ql4_chap_table));
835 max_chap_entries = (ha->hw.flt_chap_size / 2) /
836 sizeof(struct ql4_chap_table);
838 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
840 if (chap_tbl_idx > max_chap_entries) {
842 goto exit_delete_chap;
845 /* Check if chap index is in use.
846 * If chap is in use don't delet chap entry */
847 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
849 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
850 "delete from flash\n", chap_tbl_idx);
852 goto exit_delete_chap;
855 chap_size = sizeof(struct ql4_chap_table);
857 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
859 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
860 /* flt_chap_size is CHAP table size for both ports
861 * so divide it by 2 to calculate the offset for second port
863 if (ha->port_num == 1)
864 offset += (ha->hw.flt_chap_size / 2);
865 offset += (chap_tbl_idx * chap_size);
868 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
869 if (ret != QLA_SUCCESS) {
871 goto exit_delete_chap;
874 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
875 __le16_to_cpu(chap_table->cookie)));
877 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
878 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
879 goto exit_delete_chap;
882 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
884 offset = FLASH_CHAP_OFFSET |
885 (chap_tbl_idx * sizeof(struct ql4_chap_table));
886 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
887 FLASH_OPT_RMW_COMMIT);
888 if (ret == QLA_SUCCESS && ha->chap_list) {
889 mutex_lock(&ha->chap_sem);
890 /* Update ha chap_list cache */
891 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
892 chap_table, sizeof(struct ql4_chap_table));
893 mutex_unlock(&ha->chap_sem);
895 if (ret != QLA_SUCCESS)
899 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
904 * qla4xxx_set_chap_entry - Make chap entry with given information
905 * @shost: pointer to host
906 * @data: chap info - credentials, index and type to make chap entry
907 * @len: length of data
909 * Add or update chap entry with the given information
911 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
913 struct scsi_qla_host *ha = to_qla_host(shost);
914 struct iscsi_chap_rec chap_rec;
915 struct ql4_chap_table *chap_entry = NULL;
916 struct iscsi_param_info *param_info;
918 int max_chap_entries = 0;
924 memset(&chap_rec, 0, sizeof(chap_rec));
926 nla_for_each_attr(attr, data, len, rem) {
927 param_info = nla_data(attr);
929 switch (param_info->param) {
930 case ISCSI_CHAP_PARAM_INDEX:
931 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
933 case ISCSI_CHAP_PARAM_CHAP_TYPE:
934 chap_rec.chap_type = param_info->value[0];
936 case ISCSI_CHAP_PARAM_USERNAME:
937 size = min_t(size_t, sizeof(chap_rec.username),
939 memcpy(chap_rec.username, param_info->value, size);
941 case ISCSI_CHAP_PARAM_PASSWORD:
942 size = min_t(size_t, sizeof(chap_rec.password),
944 memcpy(chap_rec.password, param_info->value, size);
946 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
947 chap_rec.password_length = param_info->value[0];
950 ql4_printk(KERN_ERR, ha,
951 "%s: No such sysfs attribute\n", __func__);
957 if (chap_rec.chap_type == CHAP_TYPE_IN)
963 max_chap_entries = (ha->hw.flt_chap_size / 2) /
964 sizeof(struct ql4_chap_table);
966 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
968 mutex_lock(&ha->chap_sem);
969 if (chap_rec.chap_tbl_idx < max_chap_entries) {
970 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
973 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
974 ql4_printk(KERN_INFO, ha,
975 "Type mismatch for CHAP entry %d\n",
976 chap_rec.chap_tbl_idx);
978 goto exit_unlock_chap;
981 /* If chap index is in use then don't modify it */
982 rc = qla4xxx_is_chap_active(shost,
983 chap_rec.chap_tbl_idx);
985 ql4_printk(KERN_INFO, ha,
986 "CHAP entry %d is in use\n",
987 chap_rec.chap_tbl_idx);
989 goto exit_unlock_chap;
993 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
995 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
997 goto exit_unlock_chap;
1001 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1002 chap_rec.chap_tbl_idx, type);
1005 mutex_unlock(&ha->chap_sem);
1012 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1014 struct scsi_qla_host *ha = to_qla_host(shost);
1015 struct iscsi_offload_host_stats *host_stats = NULL;
1016 int host_stats_size;
1019 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1021 dma_addr_t iscsi_stats_dma;
1023 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1025 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1027 if (host_stats_size != len) {
1028 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1029 __func__, len, host_stats_size);
1031 goto exit_host_stats;
1033 host_stats = (struct iscsi_offload_host_stats *)buf;
1037 goto exit_host_stats;
1040 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1042 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1043 &iscsi_stats_dma, GFP_KERNEL);
1044 if (!ql_iscsi_stats) {
1045 ql4_printk(KERN_ERR, ha,
1046 "Unable to allocate memory for iscsi stats\n");
1048 goto exit_host_stats;
1051 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1053 if (ret != QLA_SUCCESS) {
1054 ql4_printk(KERN_ERR, ha,
1055 "Unable to retrieve iscsi stats\n");
1057 goto exit_host_stats;
1059 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1060 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1061 host_stats->mactx_multicast_frames =
1062 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1063 host_stats->mactx_broadcast_frames =
1064 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1065 host_stats->mactx_pause_frames =
1066 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1067 host_stats->mactx_control_frames =
1068 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1069 host_stats->mactx_deferral =
1070 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1071 host_stats->mactx_excess_deferral =
1072 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1073 host_stats->mactx_late_collision =
1074 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1075 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1076 host_stats->mactx_single_collision =
1077 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1078 host_stats->mactx_multiple_collision =
1079 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1080 host_stats->mactx_collision =
1081 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1082 host_stats->mactx_frames_dropped =
1083 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1084 host_stats->mactx_jumbo_frames =
1085 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1086 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1087 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1088 host_stats->macrx_unknown_control_frames =
1089 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1090 host_stats->macrx_pause_frames =
1091 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1092 host_stats->macrx_control_frames =
1093 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1094 host_stats->macrx_dribble =
1095 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1096 host_stats->macrx_frame_length_error =
1097 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1098 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1099 host_stats->macrx_carrier_sense_error =
1100 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1101 host_stats->macrx_frame_discarded =
1102 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1103 host_stats->macrx_frames_dropped =
1104 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1105 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1106 host_stats->mac_encoding_error =
1107 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1108 host_stats->macrx_length_error_large =
1109 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1110 host_stats->macrx_length_error_small =
1111 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1112 host_stats->macrx_multicast_frames =
1113 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1114 host_stats->macrx_broadcast_frames =
1115 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1116 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1117 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1118 host_stats->iptx_fragments =
1119 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1120 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1121 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1122 host_stats->iprx_fragments =
1123 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1124 host_stats->ip_datagram_reassembly =
1125 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1126 host_stats->ip_invalid_address_error =
1127 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1128 host_stats->ip_error_packets =
1129 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1130 host_stats->ip_fragrx_overlap =
1131 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1132 host_stats->ip_fragrx_outoforder =
1133 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1134 host_stats->ip_datagram_reassembly_timeout =
1135 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1136 host_stats->ipv6tx_packets =
1137 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1138 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1139 host_stats->ipv6tx_fragments =
1140 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1141 host_stats->ipv6rx_packets =
1142 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1143 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1144 host_stats->ipv6rx_fragments =
1145 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1146 host_stats->ipv6_datagram_reassembly =
1147 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1148 host_stats->ipv6_invalid_address_error =
1149 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1150 host_stats->ipv6_error_packets =
1151 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1152 host_stats->ipv6_fragrx_overlap =
1153 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1154 host_stats->ipv6_fragrx_outoforder =
1155 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1156 host_stats->ipv6_datagram_reassembly_timeout =
1157 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1158 host_stats->tcptx_segments =
1159 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1160 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1161 host_stats->tcprx_segments =
1162 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1163 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1164 host_stats->tcp_duplicate_ack_retx =
1165 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1166 host_stats->tcp_retx_timer_expired =
1167 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1168 host_stats->tcprx_duplicate_ack =
1169 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1170 host_stats->tcprx_pure_ackr =
1171 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1172 host_stats->tcptx_delayed_ack =
1173 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1174 host_stats->tcptx_pure_ack =
1175 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1176 host_stats->tcprx_segment_error =
1177 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1178 host_stats->tcprx_segment_outoforder =
1179 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1180 host_stats->tcprx_window_probe =
1181 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1182 host_stats->tcprx_window_update =
1183 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1184 host_stats->tcptx_window_probe_persist =
1185 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1186 host_stats->ecc_error_correction =
1187 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1188 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1189 host_stats->iscsi_data_bytes_tx =
1190 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1191 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1192 host_stats->iscsi_data_bytes_rx =
1193 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1194 host_stats->iscsi_io_completed =
1195 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1196 host_stats->iscsi_unexpected_io_rx =
1197 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1198 host_stats->iscsi_format_error =
1199 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1200 host_stats->iscsi_hdr_digest_error =
1201 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1202 host_stats->iscsi_data_digest_error =
1203 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1204 host_stats->iscsi_sequence_error =
1205 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1208 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1209 ql_iscsi_stats, iscsi_stats_dma);
1211 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1216 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1217 enum iscsi_param_type param_type,
1218 int param, char *buf)
1220 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1221 struct scsi_qla_host *ha = to_qla_host(shost);
1226 if (param_type == ISCSI_NET_PARAM) {
1228 case ISCSI_NET_PARAM_IPV4_ADDR:
1229 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1231 case ISCSI_NET_PARAM_IPV4_SUBNET:
1232 len = sprintf(buf, "%pI4\n",
1233 &ha->ip_config.subnet_mask);
1235 case ISCSI_NET_PARAM_IPV4_GW:
1236 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1238 case ISCSI_NET_PARAM_IFACE_ENABLE:
1239 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1240 OP_STATE(ha->ip_config.ipv4_options,
1241 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1243 OP_STATE(ha->ip_config.ipv6_options,
1244 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1247 len = sprintf(buf, "%s\n", pval);
1249 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1250 len = sprintf(buf, "%s\n",
1251 (ha->ip_config.tcp_options &
1252 TCPOPT_DHCP_ENABLE) ?
1255 case ISCSI_NET_PARAM_IPV6_ADDR:
1256 if (iface->iface_num == 0)
1257 len = sprintf(buf, "%pI6\n",
1258 &ha->ip_config.ipv6_addr0);
1259 if (iface->iface_num == 1)
1260 len = sprintf(buf, "%pI6\n",
1261 &ha->ip_config.ipv6_addr1);
1263 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1264 len = sprintf(buf, "%pI6\n",
1265 &ha->ip_config.ipv6_link_local_addr);
1267 case ISCSI_NET_PARAM_IPV6_ROUTER:
1268 len = sprintf(buf, "%pI6\n",
1269 &ha->ip_config.ipv6_default_router_addr);
1271 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1272 pval = (ha->ip_config.ipv6_addl_options &
1273 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1276 len = sprintf(buf, "%s\n", pval);
1278 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1279 pval = (ha->ip_config.ipv6_addl_options &
1280 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1283 len = sprintf(buf, "%s\n", pval);
1285 case ISCSI_NET_PARAM_VLAN_ID:
1286 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1287 ival = ha->ip_config.ipv4_vlan_tag &
1290 ival = ha->ip_config.ipv6_vlan_tag &
1293 len = sprintf(buf, "%d\n", ival);
1295 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1296 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1297 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1298 ISCSI_MAX_VLAN_PRIORITY;
1300 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1301 ISCSI_MAX_VLAN_PRIORITY;
1303 len = sprintf(buf, "%d\n", ival);
1305 case ISCSI_NET_PARAM_VLAN_ENABLED:
1306 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1307 OP_STATE(ha->ip_config.ipv4_options,
1308 IPOPT_VLAN_TAGGING_ENABLE, pval);
1310 OP_STATE(ha->ip_config.ipv6_options,
1311 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1313 len = sprintf(buf, "%s\n", pval);
1315 case ISCSI_NET_PARAM_MTU:
1316 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1318 case ISCSI_NET_PARAM_PORT:
1319 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1320 len = sprintf(buf, "%d\n",
1321 ha->ip_config.ipv4_port);
1323 len = sprintf(buf, "%d\n",
1324 ha->ip_config.ipv6_port);
1326 case ISCSI_NET_PARAM_IPADDR_STATE:
1327 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1328 pval = iscsi_get_ipaddress_state_name(
1329 ha->ip_config.ipv4_addr_state);
1331 if (iface->iface_num == 0)
1332 pval = iscsi_get_ipaddress_state_name(
1333 ha->ip_config.ipv6_addr0_state);
1334 else if (iface->iface_num == 1)
1335 pval = iscsi_get_ipaddress_state_name(
1336 ha->ip_config.ipv6_addr1_state);
1339 len = sprintf(buf, "%s\n", pval);
1341 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1342 pval = iscsi_get_ipaddress_state_name(
1343 ha->ip_config.ipv6_link_local_state);
1344 len = sprintf(buf, "%s\n", pval);
1346 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1347 pval = iscsi_get_router_state_name(
1348 ha->ip_config.ipv6_default_router_state);
1349 len = sprintf(buf, "%s\n", pval);
1351 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1352 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1353 OP_STATE(~ha->ip_config.tcp_options,
1354 TCPOPT_DELAYED_ACK_DISABLE, pval);
1356 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1357 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1359 len = sprintf(buf, "%s\n", pval);
1361 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1362 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1363 OP_STATE(~ha->ip_config.tcp_options,
1364 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1366 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1367 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1369 len = sprintf(buf, "%s\n", pval);
1371 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1372 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1373 OP_STATE(~ha->ip_config.tcp_options,
1374 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1376 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1377 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1380 len = sprintf(buf, "%s\n", pval);
1382 case ISCSI_NET_PARAM_TCP_WSF:
1383 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1384 len = sprintf(buf, "%d\n",
1385 ha->ip_config.tcp_wsf);
1387 len = sprintf(buf, "%d\n",
1388 ha->ip_config.ipv6_tcp_wsf);
1390 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1391 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1392 ival = (ha->ip_config.tcp_options &
1393 TCPOPT_TIMER_SCALE) >> 1;
1395 ival = (ha->ip_config.ipv6_tcp_options &
1396 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1398 len = sprintf(buf, "%d\n", ival);
1400 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1401 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1402 OP_STATE(ha->ip_config.tcp_options,
1403 TCPOPT_TIMESTAMP_ENABLE, pval);
1405 OP_STATE(ha->ip_config.ipv6_tcp_options,
1406 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1408 len = sprintf(buf, "%s\n", pval);
1410 case ISCSI_NET_PARAM_CACHE_ID:
1411 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1412 len = sprintf(buf, "%d\n",
1413 ha->ip_config.ipv4_cache_id);
1415 len = sprintf(buf, "%d\n",
1416 ha->ip_config.ipv6_cache_id);
1418 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1419 OP_STATE(ha->ip_config.tcp_options,
1420 TCPOPT_DNS_SERVER_IP_EN, pval);
1422 len = sprintf(buf, "%s\n", pval);
1424 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1425 OP_STATE(ha->ip_config.tcp_options,
1426 TCPOPT_SLP_DA_INFO_EN, pval);
1428 len = sprintf(buf, "%s\n", pval);
1430 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1431 OP_STATE(ha->ip_config.ipv4_options,
1432 IPOPT_IPV4_TOS_EN, pval);
1434 len = sprintf(buf, "%s\n", pval);
1436 case ISCSI_NET_PARAM_IPV4_TOS:
1437 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1439 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1440 OP_STATE(ha->ip_config.ipv4_options,
1441 IPOPT_GRAT_ARP_EN, pval);
1443 len = sprintf(buf, "%s\n", pval);
1445 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1446 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1449 len = sprintf(buf, "%s\n", pval);
1451 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1452 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1453 (char *)ha->ip_config.ipv4_alt_cid : "";
1455 len = sprintf(buf, "%s\n", pval);
1457 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1458 OP_STATE(ha->ip_config.ipv4_options,
1459 IPOPT_REQ_VID_EN, pval);
1461 len = sprintf(buf, "%s\n", pval);
1463 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1464 OP_STATE(ha->ip_config.ipv4_options,
1465 IPOPT_USE_VID_EN, pval);
1467 len = sprintf(buf, "%s\n", pval);
1469 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1470 pval = (ha->ip_config.ipv4_vid_len) ?
1471 (char *)ha->ip_config.ipv4_vid : "";
1473 len = sprintf(buf, "%s\n", pval);
1475 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1476 OP_STATE(ha->ip_config.ipv4_options,
1477 IPOPT_LEARN_IQN_EN, pval);
1479 len = sprintf(buf, "%s\n", pval);
1481 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1482 OP_STATE(~ha->ip_config.ipv4_options,
1483 IPOPT_FRAGMENTATION_DISABLE, pval);
1485 len = sprintf(buf, "%s\n", pval);
1487 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1488 OP_STATE(ha->ip_config.ipv4_options,
1489 IPOPT_IN_FORWARD_EN, pval);
1491 len = sprintf(buf, "%s\n", pval);
1493 case ISCSI_NET_PARAM_REDIRECT_EN:
1494 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1495 OP_STATE(ha->ip_config.ipv4_options,
1496 IPOPT_ARP_REDIRECT_EN, pval);
1498 OP_STATE(ha->ip_config.ipv6_options,
1499 IPV6_OPT_REDIRECT_EN, pval);
1501 len = sprintf(buf, "%s\n", pval);
1503 case ISCSI_NET_PARAM_IPV4_TTL:
1504 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1506 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1507 OP_STATE(ha->ip_config.ipv6_options,
1508 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1510 len = sprintf(buf, "%s\n", pval);
1512 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1513 OP_STATE(ha->ip_config.ipv6_addl_options,
1514 IPV6_ADDOPT_MLD_EN, pval);
1516 len = sprintf(buf, "%s\n", pval);
1518 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1519 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1521 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1522 len = sprintf(buf, "%d\n",
1523 ha->ip_config.ipv6_traffic_class);
1525 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1526 len = sprintf(buf, "%d\n",
1527 ha->ip_config.ipv6_hop_limit);
1529 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1530 len = sprintf(buf, "%d\n",
1531 ha->ip_config.ipv6_nd_reach_time);
1533 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1534 len = sprintf(buf, "%d\n",
1535 ha->ip_config.ipv6_nd_rexmit_timer);
1537 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1538 len = sprintf(buf, "%d\n",
1539 ha->ip_config.ipv6_nd_stale_timeout);
1541 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1542 len = sprintf(buf, "%d\n",
1543 ha->ip_config.ipv6_dup_addr_detect_count);
1545 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1546 len = sprintf(buf, "%d\n",
1547 ha->ip_config.ipv6_gw_advrt_mtu);
1552 } else if (param_type == ISCSI_IFACE_PARAM) {
1554 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1555 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1557 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1558 OP_STATE(ha->ip_config.iscsi_options,
1559 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1561 len = sprintf(buf, "%s\n", pval);
1563 case ISCSI_IFACE_PARAM_DATADGST_EN:
1564 OP_STATE(ha->ip_config.iscsi_options,
1565 ISCSIOPTS_DATA_DIGEST_EN, pval);
1567 len = sprintf(buf, "%s\n", pval);
1569 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1570 OP_STATE(ha->ip_config.iscsi_options,
1571 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1573 len = sprintf(buf, "%s\n", pval);
1575 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1576 OP_STATE(ha->ip_config.iscsi_options,
1577 ISCSIOPTS_INITIAL_R2T_EN, pval);
1579 len = sprintf(buf, "%s\n", pval);
1581 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1582 OP_STATE(ha->ip_config.iscsi_options,
1583 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1585 len = sprintf(buf, "%s\n", pval);
1587 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1588 OP_STATE(ha->ip_config.iscsi_options,
1589 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1591 len = sprintf(buf, "%s\n", pval);
1593 case ISCSI_IFACE_PARAM_ERL:
1594 len = sprintf(buf, "%d\n",
1595 (ha->ip_config.iscsi_options &
1598 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1599 len = sprintf(buf, "%u\n",
1600 ha->ip_config.iscsi_max_pdu_size *
1603 case ISCSI_IFACE_PARAM_FIRST_BURST:
1604 len = sprintf(buf, "%u\n",
1605 ha->ip_config.iscsi_first_burst_len *
1608 case ISCSI_IFACE_PARAM_MAX_R2T:
1609 len = sprintf(buf, "%d\n",
1610 ha->ip_config.iscsi_max_outstnd_r2t);
1612 case ISCSI_IFACE_PARAM_MAX_BURST:
1613 len = sprintf(buf, "%u\n",
1614 ha->ip_config.iscsi_max_burst_len *
1617 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1618 OP_STATE(ha->ip_config.iscsi_options,
1619 ISCSIOPTS_CHAP_AUTH_EN, pval);
1621 len = sprintf(buf, "%s\n", pval);
1623 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1624 OP_STATE(ha->ip_config.iscsi_options,
1625 ISCSIOPTS_BIDI_CHAP_EN, pval);
1627 len = sprintf(buf, "%s\n", pval);
1629 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1630 OP_STATE(ha->ip_config.iscsi_options,
1631 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1633 len = sprintf(buf, "%s\n", pval);
1635 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1636 OP_STATE(ha->ip_config.iscsi_options,
1637 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1639 len = sprintf(buf, "%s\n", pval);
1641 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1642 OP_STATE(ha->ip_config.iscsi_options,
1643 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1645 len = sprintf(buf, "%s\n", pval);
1647 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1648 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1658 static struct iscsi_endpoint *
1659 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1663 struct iscsi_endpoint *ep;
1664 struct qla_endpoint *qla_ep;
1665 struct scsi_qla_host *ha;
1666 struct sockaddr_in *addr;
1667 struct sockaddr_in6 *addr6;
1671 pr_err("%s: shost is NULL\n", __func__);
1672 return ERR_PTR(ret);
1675 ha = iscsi_host_priv(shost);
1676 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1679 return ERR_PTR(ret);
1682 qla_ep = ep->dd_data;
1683 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1684 if (dst_addr->sa_family == AF_INET) {
1685 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1686 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1687 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1688 (char *)&addr->sin_addr));
1689 } else if (dst_addr->sa_family == AF_INET6) {
1690 memcpy(&qla_ep->dst_addr, dst_addr,
1691 sizeof(struct sockaddr_in6));
1692 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1693 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1694 (char *)&addr6->sin6_addr));
1696 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1700 qla_ep->host = shost;
1705 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1707 struct qla_endpoint *qla_ep;
1708 struct scsi_qla_host *ha;
1711 qla_ep = ep->dd_data;
1712 ha = to_qla_host(qla_ep->host);
1713 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1715 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1721 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1723 struct qla_endpoint *qla_ep;
1724 struct scsi_qla_host *ha;
1726 qla_ep = ep->dd_data;
1727 ha = to_qla_host(qla_ep->host);
1728 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1730 iscsi_destroy_endpoint(ep);
1733 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1734 enum iscsi_param param,
1737 struct qla_endpoint *qla_ep = ep->dd_data;
1738 struct sockaddr *dst_addr;
1739 struct scsi_qla_host *ha;
1744 ha = to_qla_host(qla_ep->host);
1745 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1749 case ISCSI_PARAM_CONN_PORT:
1750 case ISCSI_PARAM_CONN_ADDRESS:
1751 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1755 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1756 &qla_ep->dst_addr, param, buf);
1762 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1763 struct iscsi_stats *stats)
1765 struct iscsi_session *sess;
1766 struct iscsi_cls_session *cls_sess;
1767 struct ddb_entry *ddb_entry;
1768 struct scsi_qla_host *ha;
1769 struct ql_iscsi_stats *ql_iscsi_stats;
1772 dma_addr_t iscsi_stats_dma;
1774 cls_sess = iscsi_conn_to_session(cls_conn);
1775 sess = cls_sess->dd_data;
1776 ddb_entry = sess->dd_data;
1779 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1781 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1782 /* Allocate memory */
1783 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1784 &iscsi_stats_dma, GFP_KERNEL);
1785 if (!ql_iscsi_stats) {
1786 ql4_printk(KERN_ERR, ha,
1787 "Unable to allocate memory for iscsi stats\n");
1788 goto exit_get_stats;
1791 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1793 if (ret != QLA_SUCCESS) {
1794 ql4_printk(KERN_ERR, ha,
1795 "Unable to retrieve iscsi stats\n");
1800 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1801 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1803 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1804 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1805 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1806 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1807 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1808 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1809 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1810 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1812 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1813 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1814 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1815 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1816 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1817 stats->logoutrsp_pdus =
1818 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1819 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1820 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1821 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1824 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1830 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1832 struct iscsi_cls_session *session;
1833 struct iscsi_session *sess;
1834 unsigned long flags;
1835 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
1837 session = starget_to_session(scsi_target(sc->device));
1838 sess = session->dd_data;
1840 spin_lock_irqsave(&session->lock, flags);
1841 if (session->state == ISCSI_SESSION_FAILED)
1842 ret = BLK_EH_RESET_TIMER;
1843 spin_unlock_irqrestore(&session->lock, flags);
1848 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1850 struct scsi_qla_host *ha = to_qla_host(shost);
1851 struct iscsi_cls_host *ihost = shost->shost_data;
1852 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1854 qla4xxx_get_firmware_state(ha);
1856 switch (ha->addl_fw_state & 0x0F00) {
1857 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1858 speed = ISCSI_PORT_SPEED_10MBPS;
1860 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1861 speed = ISCSI_PORT_SPEED_100MBPS;
1863 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1864 speed = ISCSI_PORT_SPEED_1GBPS;
1866 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1867 speed = ISCSI_PORT_SPEED_10GBPS;
1870 ihost->port_speed = speed;
1873 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1875 struct scsi_qla_host *ha = to_qla_host(shost);
1876 struct iscsi_cls_host *ihost = shost->shost_data;
1877 uint32_t state = ISCSI_PORT_STATE_DOWN;
1879 if (test_bit(AF_LINK_UP, &ha->flags))
1880 state = ISCSI_PORT_STATE_UP;
1882 ihost->port_state = state;
1885 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1886 enum iscsi_host_param param, char *buf)
1888 struct scsi_qla_host *ha = to_qla_host(shost);
1892 case ISCSI_HOST_PARAM_HWADDRESS:
1893 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1895 case ISCSI_HOST_PARAM_IPADDRESS:
1896 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1898 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1899 len = sprintf(buf, "%s\n", ha->name_string);
1901 case ISCSI_HOST_PARAM_PORT_STATE:
1902 qla4xxx_set_port_state(shost);
1903 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1905 case ISCSI_HOST_PARAM_PORT_SPEED:
1906 qla4xxx_set_port_speed(shost);
1907 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1916 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1922 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1923 &qla4xxx_iscsi_transport,
1924 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1925 if (!ha->iface_ipv4)
1926 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1930 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1932 if (!ha->iface_ipv6_0)
1934 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1935 &qla4xxx_iscsi_transport,
1936 ISCSI_IFACE_TYPE_IPV6, 0,
1938 if (!ha->iface_ipv6_0)
1939 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1942 if (!ha->iface_ipv6_1)
1944 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1945 &qla4xxx_iscsi_transport,
1946 ISCSI_IFACE_TYPE_IPV6, 1,
1948 if (!ha->iface_ipv6_1)
1949 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1953 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1955 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1956 qla4xxx_create_ipv4_iface(ha);
1958 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1959 qla4xxx_create_ipv6_iface(ha);
1962 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1964 if (ha->iface_ipv4) {
1965 iscsi_destroy_iface(ha->iface_ipv4);
1966 ha->iface_ipv4 = NULL;
1970 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1972 if (ha->iface_ipv6_0) {
1973 iscsi_destroy_iface(ha->iface_ipv6_0);
1974 ha->iface_ipv6_0 = NULL;
1976 if (ha->iface_ipv6_1) {
1977 iscsi_destroy_iface(ha->iface_ipv6_1);
1978 ha->iface_ipv6_1 = NULL;
1982 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1984 qla4xxx_destroy_ipv4_iface(ha);
1985 qla4xxx_destroy_ipv6_iface(ha);
1988 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1989 struct iscsi_iface_param_info *iface_param,
1990 struct addr_ctrl_blk *init_fw_cb)
1993 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1994 * iface_num 1 is valid only for IPv6 Addr.
1996 switch (iface_param->param) {
1997 case ISCSI_NET_PARAM_IPV6_ADDR:
1998 if (iface_param->iface_num & 0x1)
2000 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2001 sizeof(init_fw_cb->ipv6_addr1));
2004 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2005 sizeof(init_fw_cb->ipv6_addr0));
2007 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2008 if (iface_param->iface_num & 0x1)
2010 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2011 sizeof(init_fw_cb->ipv6_if_id));
2013 case ISCSI_NET_PARAM_IPV6_ROUTER:
2014 if (iface_param->iface_num & 0x1)
2016 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2017 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2019 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2020 /* Autocfg applies to even interface */
2021 if (iface_param->iface_num & 0x1)
2024 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2025 init_fw_cb->ipv6_addtl_opts &=
2027 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2028 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2029 init_fw_cb->ipv6_addtl_opts |=
2031 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2033 ql4_printk(KERN_ERR, ha,
2034 "Invalid autocfg setting for IPv6 addr\n");
2036 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2037 /* Autocfg applies to even interface */
2038 if (iface_param->iface_num & 0x1)
2041 if (iface_param->value[0] ==
2042 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2043 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2044 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2045 else if (iface_param->value[0] ==
2046 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2047 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2048 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2050 ql4_printk(KERN_ERR, ha,
2051 "Invalid autocfg setting for IPv6 linklocal addr\n");
2053 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2054 /* Autocfg applies to even interface */
2055 if (iface_param->iface_num & 0x1)
2058 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2059 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2060 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2062 case ISCSI_NET_PARAM_IFACE_ENABLE:
2063 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2064 init_fw_cb->ipv6_opts |=
2065 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2066 qla4xxx_create_ipv6_iface(ha);
2068 init_fw_cb->ipv6_opts &=
2069 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2071 qla4xxx_destroy_ipv6_iface(ha);
2074 case ISCSI_NET_PARAM_VLAN_TAG:
2075 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2077 init_fw_cb->ipv6_vlan_tag =
2078 cpu_to_be16(*(uint16_t *)iface_param->value);
2080 case ISCSI_NET_PARAM_VLAN_ENABLED:
2081 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2082 init_fw_cb->ipv6_opts |=
2083 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2085 init_fw_cb->ipv6_opts &=
2086 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2088 case ISCSI_NET_PARAM_MTU:
2089 init_fw_cb->eth_mtu_size =
2090 cpu_to_le16(*(uint16_t *)iface_param->value);
2092 case ISCSI_NET_PARAM_PORT:
2093 /* Autocfg applies to even interface */
2094 if (iface_param->iface_num & 0x1)
2097 init_fw_cb->ipv6_port =
2098 cpu_to_le16(*(uint16_t *)iface_param->value);
2100 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2101 if (iface_param->iface_num & 0x1)
2103 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2104 init_fw_cb->ipv6_tcp_opts |=
2105 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2107 init_fw_cb->ipv6_tcp_opts &=
2108 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2111 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2112 if (iface_param->iface_num & 0x1)
2114 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2115 init_fw_cb->ipv6_tcp_opts |=
2116 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2118 init_fw_cb->ipv6_tcp_opts &=
2119 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2121 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2122 if (iface_param->iface_num & 0x1)
2124 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2125 init_fw_cb->ipv6_tcp_opts |=
2126 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2128 init_fw_cb->ipv6_tcp_opts &=
2129 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2131 case ISCSI_NET_PARAM_TCP_WSF:
2132 if (iface_param->iface_num & 0x1)
2134 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2136 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2137 if (iface_param->iface_num & 0x1)
2139 init_fw_cb->ipv6_tcp_opts &=
2140 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2141 init_fw_cb->ipv6_tcp_opts |=
2142 cpu_to_le16((iface_param->value[0] << 1) &
2143 IPV6_TCPOPT_TIMER_SCALE);
2145 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2146 if (iface_param->iface_num & 0x1)
2148 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2149 init_fw_cb->ipv6_tcp_opts |=
2150 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2152 init_fw_cb->ipv6_tcp_opts &=
2153 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2155 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2156 if (iface_param->iface_num & 0x1)
2158 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2159 init_fw_cb->ipv6_opts |=
2160 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2162 init_fw_cb->ipv6_opts &=
2163 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2165 case ISCSI_NET_PARAM_REDIRECT_EN:
2166 if (iface_param->iface_num & 0x1)
2168 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2169 init_fw_cb->ipv6_opts |=
2170 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2172 init_fw_cb->ipv6_opts &=
2173 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2175 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2176 if (iface_param->iface_num & 0x1)
2178 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2179 init_fw_cb->ipv6_addtl_opts |=
2180 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2182 init_fw_cb->ipv6_addtl_opts &=
2183 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2185 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2186 if (iface_param->iface_num & 0x1)
2188 init_fw_cb->ipv6_flow_lbl =
2189 cpu_to_le16(*(uint16_t *)iface_param->value);
2191 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2192 if (iface_param->iface_num & 0x1)
2194 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2196 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2197 if (iface_param->iface_num & 0x1)
2199 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2201 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2202 if (iface_param->iface_num & 0x1)
2204 init_fw_cb->ipv6_nd_reach_time =
2205 cpu_to_le32(*(uint32_t *)iface_param->value);
2207 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2208 if (iface_param->iface_num & 0x1)
2210 init_fw_cb->ipv6_nd_rexmit_timer =
2211 cpu_to_le32(*(uint32_t *)iface_param->value);
2213 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2214 if (iface_param->iface_num & 0x1)
2216 init_fw_cb->ipv6_nd_stale_timeout =
2217 cpu_to_le32(*(uint32_t *)iface_param->value);
2219 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2220 if (iface_param->iface_num & 0x1)
2222 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2224 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2225 if (iface_param->iface_num & 0x1)
2227 init_fw_cb->ipv6_gw_advrt_mtu =
2228 cpu_to_le32(*(uint32_t *)iface_param->value);
2231 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2232 iface_param->param);
2237 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2238 struct iscsi_iface_param_info *iface_param,
2239 struct addr_ctrl_blk *init_fw_cb)
2241 switch (iface_param->param) {
2242 case ISCSI_NET_PARAM_IPV4_ADDR:
2243 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2244 sizeof(init_fw_cb->ipv4_addr));
2246 case ISCSI_NET_PARAM_IPV4_SUBNET:
2247 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2248 sizeof(init_fw_cb->ipv4_subnet));
2250 case ISCSI_NET_PARAM_IPV4_GW:
2251 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2252 sizeof(init_fw_cb->ipv4_gw_addr));
2254 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2255 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2256 init_fw_cb->ipv4_tcp_opts |=
2257 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2258 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2259 init_fw_cb->ipv4_tcp_opts &=
2260 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2262 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2264 case ISCSI_NET_PARAM_IFACE_ENABLE:
2265 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2266 init_fw_cb->ipv4_ip_opts |=
2267 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2268 qla4xxx_create_ipv4_iface(ha);
2270 init_fw_cb->ipv4_ip_opts &=
2271 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2273 qla4xxx_destroy_ipv4_iface(ha);
2276 case ISCSI_NET_PARAM_VLAN_TAG:
2277 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2279 init_fw_cb->ipv4_vlan_tag =
2280 cpu_to_be16(*(uint16_t *)iface_param->value);
2282 case ISCSI_NET_PARAM_VLAN_ENABLED:
2283 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2284 init_fw_cb->ipv4_ip_opts |=
2285 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2287 init_fw_cb->ipv4_ip_opts &=
2288 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2290 case ISCSI_NET_PARAM_MTU:
2291 init_fw_cb->eth_mtu_size =
2292 cpu_to_le16(*(uint16_t *)iface_param->value);
2294 case ISCSI_NET_PARAM_PORT:
2295 init_fw_cb->ipv4_port =
2296 cpu_to_le16(*(uint16_t *)iface_param->value);
2298 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2299 if (iface_param->iface_num & 0x1)
2301 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2302 init_fw_cb->ipv4_tcp_opts |=
2303 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2305 init_fw_cb->ipv4_tcp_opts &=
2306 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2309 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2310 if (iface_param->iface_num & 0x1)
2312 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2313 init_fw_cb->ipv4_tcp_opts |=
2314 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2316 init_fw_cb->ipv4_tcp_opts &=
2317 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2319 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2320 if (iface_param->iface_num & 0x1)
2322 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2323 init_fw_cb->ipv4_tcp_opts |=
2324 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2326 init_fw_cb->ipv4_tcp_opts &=
2327 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2329 case ISCSI_NET_PARAM_TCP_WSF:
2330 if (iface_param->iface_num & 0x1)
2332 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2334 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2335 if (iface_param->iface_num & 0x1)
2337 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2338 init_fw_cb->ipv4_tcp_opts |=
2339 cpu_to_le16((iface_param->value[0] << 1) &
2340 TCPOPT_TIMER_SCALE);
2342 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2343 if (iface_param->iface_num & 0x1)
2345 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2346 init_fw_cb->ipv4_tcp_opts |=
2347 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2349 init_fw_cb->ipv4_tcp_opts &=
2350 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2352 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2353 if (iface_param->iface_num & 0x1)
2355 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2356 init_fw_cb->ipv4_tcp_opts |=
2357 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2359 init_fw_cb->ipv4_tcp_opts &=
2360 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2362 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2363 if (iface_param->iface_num & 0x1)
2365 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2366 init_fw_cb->ipv4_tcp_opts |=
2367 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2369 init_fw_cb->ipv4_tcp_opts &=
2370 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2372 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2373 if (iface_param->iface_num & 0x1)
2375 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2376 init_fw_cb->ipv4_ip_opts |=
2377 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2379 init_fw_cb->ipv4_ip_opts &=
2380 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2382 case ISCSI_NET_PARAM_IPV4_TOS:
2383 if (iface_param->iface_num & 0x1)
2385 init_fw_cb->ipv4_tos = iface_param->value[0];
2387 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2388 if (iface_param->iface_num & 0x1)
2390 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2391 init_fw_cb->ipv4_ip_opts |=
2392 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2394 init_fw_cb->ipv4_ip_opts &=
2395 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2397 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2398 if (iface_param->iface_num & 0x1)
2400 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2401 init_fw_cb->ipv4_ip_opts |=
2402 cpu_to_le16(IPOPT_ALT_CID_EN);
2404 init_fw_cb->ipv4_ip_opts &=
2405 cpu_to_le16(~IPOPT_ALT_CID_EN);
2407 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2408 if (iface_param->iface_num & 0x1)
2410 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2411 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2412 init_fw_cb->ipv4_dhcp_alt_cid_len =
2413 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2415 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2416 if (iface_param->iface_num & 0x1)
2418 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2419 init_fw_cb->ipv4_ip_opts |=
2420 cpu_to_le16(IPOPT_REQ_VID_EN);
2422 init_fw_cb->ipv4_ip_opts &=
2423 cpu_to_le16(~IPOPT_REQ_VID_EN);
2425 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2426 if (iface_param->iface_num & 0x1)
2428 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2429 init_fw_cb->ipv4_ip_opts |=
2430 cpu_to_le16(IPOPT_USE_VID_EN);
2432 init_fw_cb->ipv4_ip_opts &=
2433 cpu_to_le16(~IPOPT_USE_VID_EN);
2435 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2436 if (iface_param->iface_num & 0x1)
2438 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2439 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2440 init_fw_cb->ipv4_dhcp_vid_len =
2441 strlen(init_fw_cb->ipv4_dhcp_vid);
2443 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2444 if (iface_param->iface_num & 0x1)
2446 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2447 init_fw_cb->ipv4_ip_opts |=
2448 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2450 init_fw_cb->ipv4_ip_opts &=
2451 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2453 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2454 if (iface_param->iface_num & 0x1)
2456 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2457 init_fw_cb->ipv4_ip_opts |=
2458 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2460 init_fw_cb->ipv4_ip_opts &=
2461 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2463 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2464 if (iface_param->iface_num & 0x1)
2466 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2467 init_fw_cb->ipv4_ip_opts |=
2468 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2470 init_fw_cb->ipv4_ip_opts &=
2471 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2473 case ISCSI_NET_PARAM_REDIRECT_EN:
2474 if (iface_param->iface_num & 0x1)
2476 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2477 init_fw_cb->ipv4_ip_opts |=
2478 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2480 init_fw_cb->ipv4_ip_opts &=
2481 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2483 case ISCSI_NET_PARAM_IPV4_TTL:
2484 if (iface_param->iface_num & 0x1)
2486 init_fw_cb->ipv4_ttl = iface_param->value[0];
2489 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2490 iface_param->param);
2495 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2496 struct iscsi_iface_param_info *iface_param,
2497 struct addr_ctrl_blk *init_fw_cb)
2499 switch (iface_param->param) {
2500 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2501 if (iface_param->iface_num & 0x1)
2503 init_fw_cb->def_timeout =
2504 cpu_to_le16(*(uint16_t *)iface_param->value);
2506 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2507 if (iface_param->iface_num & 0x1)
2509 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2510 init_fw_cb->iscsi_opts |=
2511 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2513 init_fw_cb->iscsi_opts &=
2514 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2516 case ISCSI_IFACE_PARAM_DATADGST_EN:
2517 if (iface_param->iface_num & 0x1)
2519 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2520 init_fw_cb->iscsi_opts |=
2521 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2523 init_fw_cb->iscsi_opts &=
2524 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2526 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2527 if (iface_param->iface_num & 0x1)
2529 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2530 init_fw_cb->iscsi_opts |=
2531 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2533 init_fw_cb->iscsi_opts &=
2534 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2536 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2537 if (iface_param->iface_num & 0x1)
2539 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2540 init_fw_cb->iscsi_opts |=
2541 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2543 init_fw_cb->iscsi_opts &=
2544 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2546 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2547 if (iface_param->iface_num & 0x1)
2549 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2550 init_fw_cb->iscsi_opts |=
2551 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2553 init_fw_cb->iscsi_opts &=
2554 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2556 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2557 if (iface_param->iface_num & 0x1)
2559 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2560 init_fw_cb->iscsi_opts |=
2561 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2563 init_fw_cb->iscsi_opts &=
2564 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2566 case ISCSI_IFACE_PARAM_ERL:
2567 if (iface_param->iface_num & 0x1)
2569 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2570 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2573 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2574 if (iface_param->iface_num & 0x1)
2576 init_fw_cb->iscsi_max_pdu_size =
2577 cpu_to_le32(*(uint32_t *)iface_param->value) /
2580 case ISCSI_IFACE_PARAM_FIRST_BURST:
2581 if (iface_param->iface_num & 0x1)
2583 init_fw_cb->iscsi_fburst_len =
2584 cpu_to_le32(*(uint32_t *)iface_param->value) /
2587 case ISCSI_IFACE_PARAM_MAX_R2T:
2588 if (iface_param->iface_num & 0x1)
2590 init_fw_cb->iscsi_max_outstnd_r2t =
2591 cpu_to_le16(*(uint16_t *)iface_param->value);
2593 case ISCSI_IFACE_PARAM_MAX_BURST:
2594 if (iface_param->iface_num & 0x1)
2596 init_fw_cb->iscsi_max_burst_len =
2597 cpu_to_le32(*(uint32_t *)iface_param->value) /
2600 case ISCSI_IFACE_PARAM_CHAP_AUTH_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_CHAP_AUTH_EN);
2607 init_fw_cb->iscsi_opts &=
2608 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2610 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2611 if (iface_param->iface_num & 0x1)
2613 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2614 init_fw_cb->iscsi_opts |=
2615 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2617 init_fw_cb->iscsi_opts &=
2618 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2620 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2621 if (iface_param->iface_num & 0x1)
2623 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2624 init_fw_cb->iscsi_opts |=
2625 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2627 init_fw_cb->iscsi_opts &=
2628 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2630 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2631 if (iface_param->iface_num & 0x1)
2633 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2634 init_fw_cb->iscsi_opts |=
2635 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2637 init_fw_cb->iscsi_opts &=
2638 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2640 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2641 if (iface_param->iface_num & 0x1)
2643 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2644 init_fw_cb->iscsi_opts |=
2645 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2647 init_fw_cb->iscsi_opts &=
2648 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2651 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2652 iface_param->param);
2658 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2660 struct addr_ctrl_blk_def *acb;
2661 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2662 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2663 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2664 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2665 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2666 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2667 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2668 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2669 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2670 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2671 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2672 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2673 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2674 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2675 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2676 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2680 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2682 struct scsi_qla_host *ha = to_qla_host(shost);
2684 struct iscsi_iface_param_info *iface_param = NULL;
2685 struct addr_ctrl_blk *init_fw_cb = NULL;
2686 dma_addr_t init_fw_cb_dma;
2687 uint32_t mbox_cmd[MBOX_REG_COUNT];
2688 uint32_t mbox_sts[MBOX_REG_COUNT];
2690 struct nlattr *attr;
2692 init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
2693 sizeof(struct addr_ctrl_blk),
2694 &init_fw_cb_dma, GFP_KERNEL);
2696 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2701 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2702 memset(&mbox_sts, 0, sizeof(mbox_sts));
2704 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2705 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2707 goto exit_init_fw_cb;
2710 nla_for_each_attr(attr, data, len, rem) {
2711 iface_param = nla_data(attr);
2713 if (iface_param->param_type == ISCSI_NET_PARAM) {
2714 switch (iface_param->iface_type) {
2715 case ISCSI_IFACE_TYPE_IPV4:
2716 switch (iface_param->iface_num) {
2718 qla4xxx_set_ipv4(ha, iface_param,
2722 /* Cannot have more than one IPv4 interface */
2723 ql4_printk(KERN_ERR, ha,
2724 "Invalid IPv4 iface number = %d\n",
2725 iface_param->iface_num);
2729 case ISCSI_IFACE_TYPE_IPV6:
2730 switch (iface_param->iface_num) {
2733 qla4xxx_set_ipv6(ha, iface_param,
2737 /* Cannot have more than two IPv6 interface */
2738 ql4_printk(KERN_ERR, ha,
2739 "Invalid IPv6 iface number = %d\n",
2740 iface_param->iface_num);
2745 ql4_printk(KERN_ERR, ha,
2746 "Invalid iface type\n");
2749 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2750 qla4xxx_set_iscsi_param(ha, iface_param,
2757 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2759 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2760 sizeof(struct addr_ctrl_blk),
2761 FLASH_OPT_RMW_COMMIT);
2762 if (rval != QLA_SUCCESS) {
2763 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2766 goto exit_init_fw_cb;
2769 rval = qla4xxx_disable_acb(ha);
2770 if (rval != QLA_SUCCESS) {
2771 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2774 goto exit_init_fw_cb;
2777 wait_for_completion_timeout(&ha->disable_acb_comp,
2778 DISABLE_ACB_TOV * HZ);
2780 qla4xxx_initcb_to_acb(init_fw_cb);
2782 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2783 if (rval != QLA_SUCCESS) {
2784 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2787 goto exit_init_fw_cb;
2790 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2791 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2795 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2796 init_fw_cb, init_fw_cb_dma);
2801 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2802 enum iscsi_param param, char *buf)
2804 struct iscsi_session *sess = cls_sess->dd_data;
2805 struct ddb_entry *ddb_entry = sess->dd_data;
2806 struct scsi_qla_host *ha = ddb_entry->ha;
2807 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2808 struct ql4_chap_table chap_tbl;
2812 memset(&chap_tbl, 0, sizeof(chap_tbl));
2814 case ISCSI_PARAM_CHAP_IN_IDX:
2815 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2816 sess->password_in, BIDI_CHAP,
2819 len = sprintf(buf, "\n");
2821 len = sprintf(buf, "%hu\n", idx);
2823 case ISCSI_PARAM_CHAP_OUT_IDX:
2824 if (ddb_entry->ddb_type == FLASH_DDB) {
2825 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2826 idx = ddb_entry->chap_tbl_idx;
2832 rval = qla4xxx_get_chap_index(ha, sess->username,
2837 len = sprintf(buf, "\n");
2839 len = sprintf(buf, "%hu\n", idx);
2841 case ISCSI_PARAM_USERNAME:
2842 case ISCSI_PARAM_PASSWORD:
2843 /* First, populate session username and password for FLASH DDB,
2844 * if not already done. This happens when session login fails
2847 if (ddb_entry->ddb_type == FLASH_DDB &&
2848 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2849 !sess->username && !sess->password) {
2850 idx = ddb_entry->chap_tbl_idx;
2851 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2855 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2856 (char *)chap_tbl.name,
2857 strlen((char *)chap_tbl.name));
2858 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2859 (char *)chap_tbl.secret,
2860 chap_tbl.secret_len);
2863 /* allow fall-through */
2865 return iscsi_session_get_param(cls_sess, param, buf);
2871 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2872 enum iscsi_param param, char *buf)
2874 struct iscsi_conn *conn;
2875 struct qla_conn *qla_conn;
2876 struct sockaddr *dst_addr;
2878 conn = cls_conn->dd_data;
2879 qla_conn = conn->dd_data;
2880 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2883 case ISCSI_PARAM_CONN_PORT:
2884 case ISCSI_PARAM_CONN_ADDRESS:
2885 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2886 dst_addr, param, buf);
2888 return iscsi_conn_get_param(cls_conn, param, buf);
2892 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2894 uint32_t mbx_sts = 0;
2895 uint16_t tmp_ddb_index;
2899 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2901 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2902 DEBUG2(ql4_printk(KERN_INFO, ha,
2903 "Free DDB index not available\n"));
2905 goto exit_get_ddb_index;
2908 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2911 DEBUG2(ql4_printk(KERN_INFO, ha,
2912 "Found a free DDB index at %d\n", tmp_ddb_index));
2913 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2914 if (ret == QLA_ERROR) {
2915 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2916 ql4_printk(KERN_INFO, ha,
2917 "DDB index = %d not available trying next\n",
2921 DEBUG2(ql4_printk(KERN_INFO, ha,
2922 "Free FW DDB not available\n"));
2925 *ddb_index = tmp_ddb_index;
2931 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2932 struct ddb_entry *ddb_entry,
2933 char *existing_ipaddr,
2936 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2937 char formatted_ipaddr[DDB_IPADDR_LEN];
2938 int status = QLA_SUCCESS, ret = 0;
2940 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2941 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2947 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2949 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2955 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2958 if (strcmp(existing_ipaddr, formatted_ipaddr))
2965 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2966 struct iscsi_cls_conn *cls_conn)
2968 int idx = 0, max_ddbs, rval;
2969 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2970 struct iscsi_session *sess, *existing_sess;
2971 struct iscsi_conn *conn, *existing_conn;
2972 struct ddb_entry *ddb_entry;
2974 sess = cls_sess->dd_data;
2975 conn = cls_conn->dd_data;
2977 if (sess->targetname == NULL ||
2978 conn->persistent_address == NULL ||
2979 conn->persistent_port == 0)
2982 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
2985 for (idx = 0; idx < max_ddbs; idx++) {
2986 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
2987 if (ddb_entry == NULL)
2990 if (ddb_entry->ddb_type != FLASH_DDB)
2993 existing_sess = ddb_entry->sess->dd_data;
2994 existing_conn = ddb_entry->conn->dd_data;
2996 if (existing_sess->targetname == NULL ||
2997 existing_conn->persistent_address == NULL ||
2998 existing_conn->persistent_port == 0)
3001 DEBUG2(ql4_printk(KERN_INFO, ha,
3002 "IQN = %s User IQN = %s\n",
3003 existing_sess->targetname,
3006 DEBUG2(ql4_printk(KERN_INFO, ha,
3007 "IP = %s User IP = %s\n",
3008 existing_conn->persistent_address,
3009 conn->persistent_address));
3011 DEBUG2(ql4_printk(KERN_INFO, ha,
3012 "Port = %d User Port = %d\n",
3013 existing_conn->persistent_port,
3014 conn->persistent_port));
3016 if (strcmp(existing_sess->targetname, sess->targetname))
3018 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3019 existing_conn->persistent_address,
3020 conn->persistent_address);
3021 if (rval == QLA_ERROR)
3023 if (existing_conn->persistent_port != conn->persistent_port)
3028 if (idx == max_ddbs)
3031 DEBUG2(ql4_printk(KERN_INFO, ha,
3032 "Match found in fwdb sessions\n"));
3036 static struct iscsi_cls_session *
3037 qla4xxx_session_create(struct iscsi_endpoint *ep,
3038 uint16_t cmds_max, uint16_t qdepth,
3039 uint32_t initial_cmdsn)
3041 struct iscsi_cls_session *cls_sess;
3042 struct scsi_qla_host *ha;
3043 struct qla_endpoint *qla_ep;
3044 struct ddb_entry *ddb_entry;
3046 struct iscsi_session *sess;
3047 struct sockaddr *dst_addr;
3051 printk(KERN_ERR "qla4xxx: missing ep.\n");
3055 qla_ep = ep->dd_data;
3056 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3057 ha = to_qla_host(qla_ep->host);
3058 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3061 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3062 if (ret == QLA_ERROR)
3065 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3066 cmds_max, sizeof(struct ddb_entry),
3067 sizeof(struct ql4_task_data),
3068 initial_cmdsn, ddb_index);
3072 sess = cls_sess->dd_data;
3073 ddb_entry = sess->dd_data;
3074 ddb_entry->fw_ddb_index = ddb_index;
3075 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3077 ddb_entry->sess = cls_sess;
3078 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3079 ddb_entry->ddb_change = qla4xxx_ddb_change;
3080 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3081 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3082 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3088 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3090 struct iscsi_session *sess;
3091 struct ddb_entry *ddb_entry;
3092 struct scsi_qla_host *ha;
3093 unsigned long flags, wtime;
3094 struct dev_db_entry *fw_ddb_entry = NULL;
3095 dma_addr_t fw_ddb_entry_dma;
3099 sess = cls_sess->dd_data;
3100 ddb_entry = sess->dd_data;
3102 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3105 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3106 &fw_ddb_entry_dma, GFP_KERNEL);
3107 if (!fw_ddb_entry) {
3108 ql4_printk(KERN_ERR, ha,
3109 "%s: Unable to allocate dma buffer\n", __func__);
3110 goto destroy_session;
3113 wtime = jiffies + (HZ * LOGOUT_TOV);
3115 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3116 fw_ddb_entry, fw_ddb_entry_dma,
3117 NULL, NULL, &ddb_state, NULL,
3119 if (ret == QLA_ERROR)
3120 goto destroy_session;
3122 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3123 (ddb_state == DDB_DS_SESSION_FAILED))
3124 goto destroy_session;
3126 schedule_timeout_uninterruptible(HZ);
3127 } while ((time_after(wtime, jiffies)));
3130 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3131 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3132 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3133 spin_lock_irqsave(&ha->hardware_lock, flags);
3134 qla4xxx_free_ddb(ha, ddb_entry);
3135 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3137 iscsi_session_teardown(cls_sess);
3140 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3141 fw_ddb_entry, fw_ddb_entry_dma);
3144 static struct iscsi_cls_conn *
3145 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3147 struct iscsi_cls_conn *cls_conn;
3148 struct iscsi_session *sess;
3149 struct ddb_entry *ddb_entry;
3150 struct scsi_qla_host *ha;
3152 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3155 pr_info("%s: Can not create connection for conn_idx = %u\n",
3156 __func__, conn_idx);
3160 sess = cls_sess->dd_data;
3161 ddb_entry = sess->dd_data;
3162 ddb_entry->conn = cls_conn;
3165 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3170 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3171 struct iscsi_cls_conn *cls_conn,
3172 uint64_t transport_fd, int is_leading)
3174 struct iscsi_conn *conn;
3175 struct qla_conn *qla_conn;
3176 struct iscsi_endpoint *ep;
3177 struct ddb_entry *ddb_entry;
3178 struct scsi_qla_host *ha;
3179 struct iscsi_session *sess;
3181 sess = cls_session->dd_data;
3182 ddb_entry = sess->dd_data;
3185 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3186 cls_session->sid, cls_conn->cid));
3188 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3190 ep = iscsi_lookup_endpoint(transport_fd);
3191 conn = cls_conn->dd_data;
3192 qla_conn = conn->dd_data;
3193 qla_conn->qla_ep = ep->dd_data;
3197 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3199 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3200 struct iscsi_session *sess;
3201 struct ddb_entry *ddb_entry;
3202 struct scsi_qla_host *ha;
3203 struct dev_db_entry *fw_ddb_entry = NULL;
3204 dma_addr_t fw_ddb_entry_dma;
3205 uint32_t mbx_sts = 0;
3207 int status = QLA_SUCCESS;
3209 sess = cls_sess->dd_data;
3210 ddb_entry = sess->dd_data;
3212 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3213 cls_sess->sid, cls_conn->cid));
3215 /* Check if we have matching FW DDB, if yes then do not
3216 * login to this target. This could cause target to logout previous
3219 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3220 if (ret == QLA_SUCCESS) {
3221 ql4_printk(KERN_INFO, ha,
3222 "Session already exist in FW.\n");
3224 goto exit_conn_start;
3227 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3228 &fw_ddb_entry_dma, GFP_KERNEL);
3229 if (!fw_ddb_entry) {
3230 ql4_printk(KERN_ERR, ha,
3231 "%s: Unable to allocate dma buffer\n", __func__);
3233 goto exit_conn_start;
3236 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3238 /* If iscsid is stopped and started then no need to do
3239 * set param again since ddb state will be already
3240 * active and FW does not allow set ddb to an
3244 if (ddb_entry->fw_ddb_device_state ==
3245 DDB_DS_SESSION_ACTIVE) {
3246 ddb_entry->unblock_sess(ddb_entry->sess);
3247 goto exit_set_param;
3250 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3251 __func__, ddb_entry->fw_ddb_index);
3252 goto exit_conn_start;
3255 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3256 if (status == QLA_ERROR) {
3257 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3260 goto exit_conn_start;
3263 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3264 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3266 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3267 ddb_entry->fw_ddb_device_state));
3274 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3275 fw_ddb_entry, fw_ddb_entry_dma);
3279 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3281 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3282 struct iscsi_session *sess;
3283 struct scsi_qla_host *ha;
3284 struct ddb_entry *ddb_entry;
3287 sess = cls_sess->dd_data;
3288 ddb_entry = sess->dd_data;
3290 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3293 options = LOGOUT_OPTION_CLOSE_SESSION;
3294 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3295 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3298 static void qla4xxx_task_work(struct work_struct *wdata)
3300 struct ql4_task_data *task_data;
3301 struct scsi_qla_host *ha;
3302 struct passthru_status *sts;
3303 struct iscsi_task *task;
3304 struct iscsi_hdr *hdr;
3307 struct iscsi_conn *conn;
3311 task_data = container_of(wdata, struct ql4_task_data, task_work);
3313 task = task_data->task;
3314 sts = &task_data->sts;
3315 hdr_len = sizeof(struct iscsi_hdr);
3317 DEBUG3(printk(KERN_INFO "Status returned\n"));
3318 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3319 DEBUG3(printk(KERN_INFO "Response buffer"));
3320 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3324 switch (sts->completionStatus) {
3325 case PASSTHRU_STATUS_COMPLETE:
3326 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3327 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3330 data = task_data->resp_buffer + hdr_len;
3331 data_len = task_data->resp_len - hdr_len;
3332 iscsi_complete_pdu(conn, hdr, data, data_len);
3335 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3336 sts->completionStatus);
3342 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3344 struct ql4_task_data *task_data;
3345 struct iscsi_session *sess;
3346 struct ddb_entry *ddb_entry;
3347 struct scsi_qla_host *ha;
3350 sess = task->conn->session;
3351 ddb_entry = sess->dd_data;
3353 task_data = task->dd_data;
3354 memset(task_data, 0, sizeof(struct ql4_task_data));
3357 ql4_printk(KERN_INFO, ha,
3358 "%s: SCSI Commands not implemented\n", __func__);
3362 hdr_len = sizeof(struct iscsi_hdr);
3364 task_data->task = task;
3366 if (task->data_count) {
3367 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3372 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3373 __func__, task->conn->max_recv_dlength, hdr_len));
3375 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3376 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3377 task_data->resp_len,
3378 &task_data->resp_dma,
3380 if (!task_data->resp_buffer)
3381 goto exit_alloc_pdu;
3383 task_data->req_len = task->data_count + hdr_len;
3384 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3386 &task_data->req_dma,
3388 if (!task_data->req_buffer)
3389 goto exit_alloc_pdu;
3391 task->hdr = task_data->req_buffer;
3393 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3398 if (task_data->resp_buffer)
3399 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3400 task_data->resp_buffer, task_data->resp_dma);
3402 if (task_data->req_buffer)
3403 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3404 task_data->req_buffer, task_data->req_dma);
3408 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3410 struct ql4_task_data *task_data;
3411 struct iscsi_session *sess;
3412 struct ddb_entry *ddb_entry;
3413 struct scsi_qla_host *ha;
3416 hdr_len = sizeof(struct iscsi_hdr);
3417 sess = task->conn->session;
3418 ddb_entry = sess->dd_data;
3420 task_data = task->dd_data;
3422 if (task->data_count) {
3423 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3424 task->data_count, PCI_DMA_TODEVICE);
3427 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3428 __func__, task->conn->max_recv_dlength, hdr_len));
3430 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3431 task_data->resp_buffer, task_data->resp_dma);
3432 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3433 task_data->req_buffer, task_data->req_dma);
3437 static int qla4xxx_task_xmit(struct iscsi_task *task)
3439 struct scsi_cmnd *sc = task->sc;
3440 struct iscsi_session *sess = task->conn->session;
3441 struct ddb_entry *ddb_entry = sess->dd_data;
3442 struct scsi_qla_host *ha = ddb_entry->ha;
3445 return qla4xxx_send_passthru0(task);
3447 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3452 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3453 struct iscsi_bus_flash_conn *conn,
3454 struct dev_db_entry *fw_ddb_entry)
3456 unsigned long options = 0;
3459 options = le16_to_cpu(fw_ddb_entry->options);
3460 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3461 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3462 rc = iscsi_switch_str_param(&sess->portal_type,
3467 rc = iscsi_switch_str_param(&sess->portal_type,
3473 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3475 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3476 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3478 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3479 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3480 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3481 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3482 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3483 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3485 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3486 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3487 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3488 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3490 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3491 sess->discovery_auth_optional =
3492 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3493 if (test_bit(ISCSIOPT_ERL1, &options))
3495 if (test_bit(ISCSIOPT_ERL0, &options))
3498 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3499 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3500 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3501 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3502 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3503 conn->tcp_timer_scale |= BIT_3;
3504 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3505 conn->tcp_timer_scale |= BIT_2;
3506 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3507 conn->tcp_timer_scale |= BIT_1;
3509 conn->tcp_timer_scale >>= 1;
3510 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3512 options = le16_to_cpu(fw_ddb_entry->ip_options);
3513 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3515 conn->max_recv_dlength = BYTE_UNITS *
3516 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3517 conn->max_xmit_dlength = BYTE_UNITS *
3518 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3519 sess->first_burst = BYTE_UNITS *
3520 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3521 sess->max_burst = BYTE_UNITS *
3522 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3523 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3524 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3525 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3526 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3527 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3528 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3529 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3530 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3531 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3532 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3533 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3534 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3535 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3536 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3537 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3538 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3540 sess->default_taskmgmt_timeout =
3541 le16_to_cpu(fw_ddb_entry->def_timeout);
3542 conn->port = le16_to_cpu(fw_ddb_entry->port);
3544 options = le16_to_cpu(fw_ddb_entry->options);
3545 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3546 if (!conn->ipaddress) {
3551 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3552 if (!conn->redirect_ipaddr) {
3557 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3558 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3560 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3561 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3563 conn->link_local_ipv6_addr = kmemdup(
3564 fw_ddb_entry->link_local_ipv6_addr,
3565 IPv6_ADDR_LEN, GFP_KERNEL);
3566 if (!conn->link_local_ipv6_addr) {
3571 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3574 if (fw_ddb_entry->iscsi_name[0]) {
3575 rc = iscsi_switch_str_param(&sess->targetname,
3576 (char *)fw_ddb_entry->iscsi_name);
3581 if (fw_ddb_entry->iscsi_alias[0]) {
3582 rc = iscsi_switch_str_param(&sess->targetalias,
3583 (char *)fw_ddb_entry->iscsi_alias);
3588 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3594 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3595 struct iscsi_bus_flash_conn *conn,
3596 struct dev_db_entry *fw_ddb_entry)
3601 options = le16_to_cpu(fw_ddb_entry->options);
3602 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3603 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3608 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3609 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3610 SET_BITVAL(sess->entry_state, options, BIT_3);
3611 fw_ddb_entry->options = cpu_to_le16(options);
3613 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3614 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3615 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3616 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3617 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3618 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3619 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3620 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3621 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3622 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3623 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3624 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3625 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3626 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3627 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3629 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3630 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3631 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3632 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3633 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3634 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3635 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3636 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3637 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3639 options = le16_to_cpu(fw_ddb_entry->ip_options);
3640 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3641 fw_ddb_entry->ip_options = cpu_to_le16(options);
3643 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3644 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3645 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3646 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3647 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3648 fw_ddb_entry->iscsi_first_burst_len =
3649 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3650 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3652 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3653 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3654 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3655 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3656 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3657 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3658 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3659 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3660 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3661 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3662 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3663 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3664 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3665 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3666 fw_ddb_entry->port = cpu_to_le16(conn->port);
3667 fw_ddb_entry->def_timeout =
3668 cpu_to_le16(sess->default_taskmgmt_timeout);
3670 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3671 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3673 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3675 if (conn->ipaddress)
3676 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3677 sizeof(fw_ddb_entry->ip_addr));
3679 if (conn->redirect_ipaddr)
3680 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3681 sizeof(fw_ddb_entry->tgt_addr));
3683 if (conn->link_local_ipv6_addr)
3684 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3685 conn->link_local_ipv6_addr,
3686 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3688 if (sess->targetname)
3689 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3690 sizeof(fw_ddb_entry->iscsi_name));
3692 if (sess->targetalias)
3693 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3694 sizeof(fw_ddb_entry->iscsi_alias));
3696 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3701 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3702 struct iscsi_session *sess,
3703 struct dev_db_entry *fw_ddb_entry)
3705 unsigned long options = 0;
3707 uint16_t disc_parent;
3708 char ip_addr[DDB_IPADDR_LEN];
3710 options = le16_to_cpu(fw_ddb_entry->options);
3711 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3712 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3714 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3716 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3717 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3718 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3719 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3720 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3721 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3723 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3724 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3725 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3727 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3728 sess->discovery_auth_optional =
3729 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3730 if (test_bit(ISCSIOPT_ERL1, &options))
3732 if (test_bit(ISCSIOPT_ERL0, &options))
3735 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3736 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3737 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3738 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3739 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3740 conn->tcp_timer_scale |= BIT_3;
3741 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3742 conn->tcp_timer_scale |= BIT_2;
3743 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3744 conn->tcp_timer_scale |= BIT_1;
3746 conn->tcp_timer_scale >>= 1;
3747 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3749 options = le16_to_cpu(fw_ddb_entry->ip_options);
3750 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3752 conn->max_recv_dlength = BYTE_UNITS *
3753 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3754 conn->max_xmit_dlength = BYTE_UNITS *
3755 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3756 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3757 sess->first_burst = BYTE_UNITS *
3758 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3759 sess->max_burst = BYTE_UNITS *
3760 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3761 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3762 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3763 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3764 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3765 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3766 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3767 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3768 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3769 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3770 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3771 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3772 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3773 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3775 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3776 if (ddb_link == DDB_ISNS)
3777 disc_parent = ISCSI_DISC_PARENT_ISNS;
3778 else if (ddb_link == DDB_NO_LINK)
3779 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3780 else if (ddb_link < MAX_DDB_ENTRIES)
3781 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3783 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3785 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3786 iscsi_get_discovery_parent_name(disc_parent), 0);
3788 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3789 (char *)fw_ddb_entry->iscsi_alias, 0);
3791 options = le16_to_cpu(fw_ddb_entry->options);
3792 if (options & DDB_OPT_IPV6_DEVICE) {
3793 memset(ip_addr, 0, sizeof(ip_addr));
3794 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3795 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3796 (char *)ip_addr, 0);
3800 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3801 struct dev_db_entry *fw_ddb_entry,
3802 struct iscsi_cls_session *cls_sess,
3803 struct iscsi_cls_conn *cls_conn)
3806 struct iscsi_session *sess;
3807 struct ddb_entry *ddb_entry;
3808 struct ql4_chap_table chap_tbl;
3809 struct iscsi_conn *conn;
3810 char ip_addr[DDB_IPADDR_LEN];
3811 uint16_t options = 0;
3813 sess = cls_sess->dd_data;
3814 ddb_entry = sess->dd_data;
3815 conn = cls_conn->dd_data;
3816 memset(&chap_tbl, 0, sizeof(chap_tbl));
3818 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3820 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3822 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3823 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3825 memset(ip_addr, 0, sizeof(ip_addr));
3826 options = le16_to_cpu(fw_ddb_entry->options);
3827 if (options & DDB_OPT_IPV6_DEVICE) {
3828 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3830 memset(ip_addr, 0, sizeof(ip_addr));
3831 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3833 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3834 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3837 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3838 (char *)ip_addr, buflen);
3839 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3840 (char *)fw_ddb_entry->iscsi_name, buflen);
3841 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3842 (char *)ha->name_string, buflen);
3844 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3845 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3847 ddb_entry->chap_tbl_idx)) {
3848 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3849 (char *)chap_tbl.name,
3850 strlen((char *)chap_tbl.name));
3851 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3852 (char *)chap_tbl.secret,
3853 chap_tbl.secret_len);
3858 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3859 struct ddb_entry *ddb_entry)
3861 struct iscsi_cls_session *cls_sess;
3862 struct iscsi_cls_conn *cls_conn;
3864 dma_addr_t fw_ddb_entry_dma;
3865 struct dev_db_entry *fw_ddb_entry;
3867 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3868 &fw_ddb_entry_dma, GFP_KERNEL);
3869 if (!fw_ddb_entry) {
3870 ql4_printk(KERN_ERR, ha,
3871 "%s: Unable to allocate dma buffer\n", __func__);
3872 goto exit_session_conn_fwddb_param;
3875 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3876 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3877 NULL, NULL, NULL) == QLA_ERROR) {
3878 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3879 "get_ddb_entry for fw_ddb_index %d\n",
3880 ha->host_no, __func__,
3881 ddb_entry->fw_ddb_index));
3882 goto exit_session_conn_fwddb_param;
3885 cls_sess = ddb_entry->sess;
3887 cls_conn = ddb_entry->conn;
3890 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3892 exit_session_conn_fwddb_param:
3894 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3895 fw_ddb_entry, fw_ddb_entry_dma);
3898 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3899 struct ddb_entry *ddb_entry)
3901 struct iscsi_cls_session *cls_sess;
3902 struct iscsi_cls_conn *cls_conn;
3903 struct iscsi_session *sess;
3904 struct iscsi_conn *conn;
3906 dma_addr_t fw_ddb_entry_dma;
3907 struct dev_db_entry *fw_ddb_entry;
3909 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3910 &fw_ddb_entry_dma, GFP_KERNEL);
3911 if (!fw_ddb_entry) {
3912 ql4_printk(KERN_ERR, ha,
3913 "%s: Unable to allocate dma buffer\n", __func__);
3914 goto exit_session_conn_param;
3917 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3918 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3919 NULL, NULL, NULL) == QLA_ERROR) {
3920 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3921 "get_ddb_entry for fw_ddb_index %d\n",
3922 ha->host_no, __func__,
3923 ddb_entry->fw_ddb_index));
3924 goto exit_session_conn_param;
3927 cls_sess = ddb_entry->sess;
3928 sess = cls_sess->dd_data;
3930 cls_conn = ddb_entry->conn;
3931 conn = cls_conn->dd_data;
3933 /* Update timers after login */
3934 ddb_entry->default_relogin_timeout =
3935 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3936 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3937 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3938 ddb_entry->default_time2wait =
3939 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3942 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3943 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3945 memcpy(sess->initiatorname, ha->name_string,
3946 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3948 exit_session_conn_param:
3950 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3951 fw_ddb_entry, fw_ddb_entry_dma);
3957 static void qla4xxx_timer(struct timer_list *t);
3959 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
3960 unsigned long interval)
3962 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3963 __func__, ha->host->host_no));
3964 timer_setup(&ha->timer, qla4xxx_timer, 0);
3965 ha->timer.expires = jiffies + interval * HZ;
3966 add_timer(&ha->timer);
3967 ha->timer_active = 1;
3970 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3972 del_timer_sync(&ha->timer);
3973 ha->timer_active = 0;
3977 * qla4xxx_mark_device_missing - blocks the session
3978 * @cls_session: Pointer to the session to be blocked
3979 * @ddb_entry: Pointer to device database entry
3981 * This routine marks a device missing and close connection.
3983 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
3985 iscsi_block_session(cls_session);
3989 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
3990 * @ha: Pointer to host adapter structure.
3992 * This routine marks a device missing and resets the relogin retry count.
3994 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
3996 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
3999 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4000 struct ddb_entry *ddb_entry,
4001 struct scsi_cmnd *cmd)
4005 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4009 kref_init(&srb->srb_ref);
4011 srb->ddb = ddb_entry;
4014 CMD_SP(cmd) = (void *)srb;
4019 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4021 struct scsi_cmnd *cmd = srb->cmd;
4023 if (srb->flags & SRB_DMA_VALID) {
4024 scsi_dma_unmap(cmd);
4025 srb->flags &= ~SRB_DMA_VALID;
4030 void qla4xxx_srb_compl(struct kref *ref)
4032 struct srb *srb = container_of(ref, struct srb, srb_ref);
4033 struct scsi_cmnd *cmd = srb->cmd;
4034 struct scsi_qla_host *ha = srb->ha;
4036 qla4xxx_srb_free_dma(ha, srb);
4038 mempool_free(srb, ha->srb_mempool);
4040 cmd->scsi_done(cmd);
4044 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4046 * @cmd: Pointer to Linux's SCSI command structure
4049 * This routine is invoked by Linux to send a SCSI command to the driver.
4050 * The mid-level driver tries to ensure that queuecommand never gets
4051 * invoked concurrently with itself or the interrupt handler (although
4052 * the interrupt handler may call this routine as part of request-
4053 * completion handling). Unfortunely, it sometimes calls the scheduler
4054 * in interrupt context which is a big NO! NO!.
4056 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4058 struct scsi_qla_host *ha = to_qla_host(host);
4059 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4060 struct iscsi_cls_session *sess = ddb_entry->sess;
4064 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4065 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4066 cmd->result = DID_NO_CONNECT << 16;
4068 cmd->result = DID_REQUEUE << 16;
4069 goto qc_fail_command;
4073 cmd->result = DID_IMM_RETRY << 16;
4074 goto qc_fail_command;
4077 rval = iscsi_session_chkready(sess);
4080 goto qc_fail_command;
4083 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4084 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4085 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4086 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4087 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4088 !test_bit(AF_ONLINE, &ha->flags) ||
4089 !test_bit(AF_LINK_UP, &ha->flags) ||
4090 test_bit(AF_LOOPBACK, &ha->flags) ||
4091 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4092 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4093 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4096 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4100 rval = qla4xxx_send_command_to_isp(ha, srb);
4101 if (rval != QLA_SUCCESS)
4102 goto qc_host_busy_free_sp;
4106 qc_host_busy_free_sp:
4107 qla4xxx_srb_free_dma(ha, srb);
4108 mempool_free(srb, ha->srb_mempool);
4111 return SCSI_MLQUEUE_HOST_BUSY;
4114 cmd->scsi_done(cmd);
4120 * qla4xxx_mem_free - frees memory allocated to adapter
4121 * @ha: Pointer to host adapter structure.
4123 * Frees memory previously allocated by qla4xxx_mem_alloc
4125 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4128 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4137 ha->request_ring = NULL;
4138 ha->request_dma = 0;
4139 ha->response_ring = NULL;
4140 ha->response_dma = 0;
4141 ha->shadow_regs = NULL;
4142 ha->shadow_regs_dma = 0;
4144 ha->fw_dump_size = 0;
4146 /* Free srb pool. */
4147 if (ha->srb_mempool)
4148 mempool_destroy(ha->srb_mempool);
4150 ha->srb_mempool = NULL;
4152 if (ha->chap_dma_pool)
4153 dma_pool_destroy(ha->chap_dma_pool);
4156 vfree(ha->chap_list);
4157 ha->chap_list = NULL;
4159 if (ha->fw_ddb_dma_pool)
4160 dma_pool_destroy(ha->fw_ddb_dma_pool);
4162 /* release io space registers */
4163 if (is_qla8022(ha)) {
4166 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4167 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4170 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4171 } else if (ha->reg) {
4175 if (ha->reset_tmplt.buff)
4176 vfree(ha->reset_tmplt.buff);
4178 pci_release_regions(ha->pdev);
4182 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4183 * @ha: Pointer to host adapter structure
4185 * Allocates DMA memory for request and response queues. Also allocates memory
4188 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4190 unsigned long align;
4192 /* Allocate contiguous block of DMA memory for queues. */
4193 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4194 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4195 sizeof(struct shadow_regs) +
4197 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4198 ha->queues = dma_zalloc_coherent(&ha->pdev->dev, ha->queues_len,
4199 &ha->queues_dma, GFP_KERNEL);
4200 if (ha->queues == NULL) {
4201 ql4_printk(KERN_WARNING, ha,
4202 "Memory Allocation failed - queues.\n");
4204 goto mem_alloc_error_exit;
4208 * As per RISC alignment requirements -- the bus-address must be a
4209 * multiple of the request-ring size (in bytes).
4212 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4213 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4214 (MEM_ALIGN_VALUE - 1));
4216 /* Update request and response queue pointers. */
4217 ha->request_dma = ha->queues_dma + align;
4218 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4219 ha->response_dma = ha->queues_dma + align +
4220 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4221 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4222 (REQUEST_QUEUE_DEPTH *
4224 ha->shadow_regs_dma = ha->queues_dma + align +
4225 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4226 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4227 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4228 (REQUEST_QUEUE_DEPTH *
4230 (RESPONSE_QUEUE_DEPTH *
4233 /* Allocate memory for srb pool. */
4234 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4235 mempool_free_slab, srb_cachep);
4236 if (ha->srb_mempool == NULL) {
4237 ql4_printk(KERN_WARNING, ha,
4238 "Memory Allocation failed - SRB Pool.\n");
4240 goto mem_alloc_error_exit;
4243 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4244 CHAP_DMA_BLOCK_SIZE, 8, 0);
4246 if (ha->chap_dma_pool == NULL) {
4247 ql4_printk(KERN_WARNING, ha,
4248 "%s: chap_dma_pool allocation failed..\n", __func__);
4249 goto mem_alloc_error_exit;
4252 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4253 DDB_DMA_BLOCK_SIZE, 8, 0);
4255 if (ha->fw_ddb_dma_pool == NULL) {
4256 ql4_printk(KERN_WARNING, ha,
4257 "%s: fw_ddb_dma_pool allocation failed..\n",
4259 goto mem_alloc_error_exit;
4264 mem_alloc_error_exit:
4265 qla4xxx_mem_free(ha);
4270 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4271 * @ha: adapter block pointer.
4273 * Note: The caller should not hold the idc lock.
4275 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4277 uint32_t temp, temp_state, temp_val;
4278 int status = QLA_SUCCESS;
4280 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4282 temp_state = qla82xx_get_temp_state(temp);
4283 temp_val = qla82xx_get_temp_val(temp);
4285 if (temp_state == QLA82XX_TEMP_PANIC) {
4286 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4287 " exceeds maximum allowed. Hardware has been shut"
4288 " down.\n", temp_val);
4290 } else if (temp_state == QLA82XX_TEMP_WARN) {
4291 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4292 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4293 " degrees C exceeds operating range."
4294 " Immediate action needed.\n", temp_val);
4296 if (ha->temperature == QLA82XX_TEMP_WARN)
4297 ql4_printk(KERN_INFO, ha, "Device temperature is"
4298 " now %d degrees C in normal range.\n",
4301 ha->temperature = temp_state;
4306 * qla4_8xxx_check_fw_alive - Check firmware health
4307 * @ha: Pointer to host adapter structure.
4309 * Context: Interrupt
4311 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4313 uint32_t fw_heartbeat_counter;
4314 int status = QLA_SUCCESS;
4316 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4317 QLA8XXX_PEG_ALIVE_COUNTER);
4318 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4319 if (fw_heartbeat_counter == 0xffffffff) {
4320 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4321 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4322 ha->host_no, __func__));
4326 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4327 ha->seconds_since_last_heartbeat++;
4328 /* FW not alive after 2 seconds */
4329 if (ha->seconds_since_last_heartbeat == 2) {
4330 ha->seconds_since_last_heartbeat = 0;
4331 qla4_8xxx_dump_peg_reg(ha);
4335 ha->seconds_since_last_heartbeat = 0;
4337 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4341 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4343 uint32_t halt_status;
4344 int halt_status_unrecoverable = 0;
4346 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4348 if (is_qla8022(ha)) {
4349 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4351 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4352 CRB_NIU_XG_PAUSE_CTL_P0 |
4353 CRB_NIU_XG_PAUSE_CTL_P1);
4355 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4356 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4358 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4359 halt_status_unrecoverable = 1;
4360 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4361 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4362 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4364 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4365 halt_status_unrecoverable = 1;
4369 * Since we cannot change dev_state in interrupt context,
4370 * set appropriate DPC flag then wakeup DPC
4372 if (halt_status_unrecoverable) {
4373 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4375 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4377 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4379 qla4xxx_mailbox_premature_completion(ha);
4380 qla4xxx_wake_dpc(ha);
4384 * qla4_8xxx_watchdog - Poll dev state
4385 * @ha: Pointer to host adapter structure.
4387 * Context: Interrupt
4389 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4394 if (is_qla8032(ha) &&
4395 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4396 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4397 __func__, ha->func_num);
4399 /* don't poll if reset is going on */
4400 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4401 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4402 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4403 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4405 if (qla4_8xxx_check_temp(ha)) {
4406 if (is_qla8022(ha)) {
4407 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4408 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4409 CRB_NIU_XG_PAUSE_CTL_P0 |
4410 CRB_NIU_XG_PAUSE_CTL_P1);
4412 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4413 qla4xxx_wake_dpc(ha);
4414 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4415 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4417 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4420 if (is_qla8032(ha) || is_qla8042(ha)) {
4421 idc_ctrl = qla4_83xx_rd_reg(ha,
4422 QLA83XX_IDC_DRV_CTRL);
4423 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4424 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4426 qla4xxx_mailbox_premature_completion(
4431 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4432 (is_qla8022(ha) && !ql4xdontresethba)) {
4433 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4434 qla4xxx_wake_dpc(ha);
4436 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4437 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4438 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4440 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4441 qla4xxx_wake_dpc(ha);
4443 /* Check firmware health */
4444 if (qla4_8xxx_check_fw_alive(ha))
4445 qla4_8xxx_process_fw_error(ha);
4450 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4452 struct iscsi_session *sess;
4453 struct ddb_entry *ddb_entry;
4454 struct scsi_qla_host *ha;
4456 sess = cls_sess->dd_data;
4457 ddb_entry = sess->dd_data;
4460 if (!(ddb_entry->ddb_type == FLASH_DDB))
4463 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4464 !iscsi_is_session_online(cls_sess)) {
4465 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4467 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4469 atomic_set(&ddb_entry->retry_relogin_timer,
4471 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4472 set_bit(DF_RELOGIN, &ddb_entry->flags);
4473 DEBUG2(ql4_printk(KERN_INFO, ha,
4474 "%s: index [%d] login device\n",
4475 __func__, ddb_entry->fw_ddb_index));
4477 atomic_dec(&ddb_entry->retry_relogin_timer);
4481 /* Wait for relogin to timeout */
4482 if (atomic_read(&ddb_entry->relogin_timer) &&
4483 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4485 * If the relogin times out and the device is
4486 * still NOT ONLINE then try and relogin again.
4488 if (!iscsi_is_session_online(cls_sess)) {
4489 /* Reset retry relogin timer */
4490 atomic_inc(&ddb_entry->relogin_retry_count);
4491 DEBUG2(ql4_printk(KERN_INFO, ha,
4492 "%s: index[%d] relogin timed out-retrying"
4493 " relogin (%d), retry (%d)\n", __func__,
4494 ddb_entry->fw_ddb_index,
4495 atomic_read(&ddb_entry->relogin_retry_count),
4496 ddb_entry->default_time2wait + 4));
4497 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4498 atomic_set(&ddb_entry->retry_relogin_timer,
4499 ddb_entry->default_time2wait + 4);
4505 * qla4xxx_timer - checks every second for work to do.
4506 * @ha: Pointer to host adapter structure.
4508 static void qla4xxx_timer(struct timer_list *t)
4510 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4514 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4516 /* If we are in the middle of AER/EEH processing
4517 * skip any processing and reschedule the timer
4519 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4520 mod_timer(&ha->timer, jiffies + HZ);
4524 /* Hardware read to trigger an EEH error during mailbox waits. */
4525 if (!pci_channel_offline(ha->pdev))
4526 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4529 qla4_8xxx_watchdog(ha);
4531 if (is_qla40XX(ha)) {
4532 /* Check for heartbeat interval. */
4533 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4534 ha->heartbeat_interval != 0) {
4535 ha->seconds_since_last_heartbeat++;
4536 if (ha->seconds_since_last_heartbeat >
4537 ha->heartbeat_interval + 2)
4538 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4542 /* Process any deferred work. */
4543 if (!list_empty(&ha->work_list))
4546 /* Wakeup the dpc routine for this adapter, if needed. */
4548 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4549 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4550 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4551 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4552 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4553 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4554 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4555 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4556 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4557 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4558 test_bit(DPC_AEN, &ha->dpc_flags)) {
4559 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4560 " - dpc flags = 0x%lx\n",
4561 ha->host_no, __func__, ha->dpc_flags));
4562 qla4xxx_wake_dpc(ha);
4565 /* Reschedule timer thread to call us back in one second */
4566 mod_timer(&ha->timer, jiffies + HZ);
4568 DEBUG2(ha->seconds_since_last_intr++);
4572 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4573 * @ha: Pointer to host adapter structure.
4575 * This routine stalls the driver until all outstanding commands are returned.
4576 * Caller must release the Hardware Lock prior to calling this routine.
4578 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4581 unsigned long flags;
4582 struct scsi_cmnd *cmd;
4583 unsigned long wtime;
4587 wtmo = WAIT_CMD_TOV;
4589 wtmo = ha->nx_reset_timeout / 2;
4591 wtime = jiffies + (wtmo * HZ);
4593 DEBUG2(ql4_printk(KERN_INFO, ha,
4594 "Wait up to %u seconds for cmds to complete\n",
4597 while (!time_after_eq(jiffies, wtime)) {
4598 spin_lock_irqsave(&ha->hardware_lock, flags);
4599 /* Find a command that hasn't completed. */
4600 for (index = 0; index < ha->host->can_queue; index++) {
4601 cmd = scsi_host_find_tag(ha->host, index);
4603 * We cannot just check if the index is valid,
4604 * becase if we are run from the scsi eh, then
4605 * the scsi/block layer is going to prevent
4606 * the tag from being released.
4608 if (cmd != NULL && CMD_SP(cmd))
4611 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4613 /* If No Commands are pending, wait is complete */
4614 if (index == ha->host->can_queue)
4619 /* If we timed out on waiting for commands to come back
4624 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4626 uint32_t ctrl_status;
4627 unsigned long flags = 0;
4629 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4631 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4634 spin_lock_irqsave(&ha->hardware_lock, flags);
4637 * If the SCSI Reset Interrupt bit is set, clear it.
4638 * Otherwise, the Soft Reset won't work.
4640 ctrl_status = readw(&ha->reg->ctrl_status);
4641 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4642 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4644 /* Issue Soft Reset */
4645 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4646 readl(&ha->reg->ctrl_status);
4648 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4653 * qla4xxx_soft_reset - performs soft reset.
4654 * @ha: Pointer to host adapter structure.
4656 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4658 uint32_t max_wait_time;
4659 unsigned long flags = 0;
4661 uint32_t ctrl_status;
4663 status = qla4xxx_hw_reset(ha);
4664 if (status != QLA_SUCCESS)
4668 /* Wait until the Network Reset Intr bit is cleared */
4669 max_wait_time = RESET_INTR_TOV;
4671 spin_lock_irqsave(&ha->hardware_lock, flags);
4672 ctrl_status = readw(&ha->reg->ctrl_status);
4673 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4675 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4679 } while ((--max_wait_time));
4681 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4682 DEBUG2(printk(KERN_WARNING
4683 "scsi%ld: Network Reset Intr not cleared by "
4684 "Network function, clearing it now!\n",
4686 spin_lock_irqsave(&ha->hardware_lock, flags);
4687 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4688 readl(&ha->reg->ctrl_status);
4689 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4692 /* Wait until the firmware tells us the Soft Reset is done */
4693 max_wait_time = SOFT_RESET_TOV;
4695 spin_lock_irqsave(&ha->hardware_lock, flags);
4696 ctrl_status = readw(&ha->reg->ctrl_status);
4697 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4699 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4700 status = QLA_SUCCESS;
4705 } while ((--max_wait_time));
4708 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4709 * after the soft reset has taken place.
4711 spin_lock_irqsave(&ha->hardware_lock, flags);
4712 ctrl_status = readw(&ha->reg->ctrl_status);
4713 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4714 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4715 readl(&ha->reg->ctrl_status);
4717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4719 /* If soft reset fails then most probably the bios on other
4720 * function is also enabled.
4721 * Since the initialization is sequential the other fn
4722 * wont be able to acknowledge the soft reset.
4723 * Issue a force soft reset to workaround this scenario.
4725 if (max_wait_time == 0) {
4726 /* Issue Force Soft Reset */
4727 spin_lock_irqsave(&ha->hardware_lock, flags);
4728 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4729 readl(&ha->reg->ctrl_status);
4730 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4731 /* Wait until the firmware tells us the Soft Reset is done */
4732 max_wait_time = SOFT_RESET_TOV;
4734 spin_lock_irqsave(&ha->hardware_lock, flags);
4735 ctrl_status = readw(&ha->reg->ctrl_status);
4736 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4738 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4739 status = QLA_SUCCESS;
4744 } while ((--max_wait_time));
4751 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4752 * @ha: Pointer to host adapter structure.
4753 * @res: returned scsi status
4755 * This routine is called just prior to a HARD RESET to return all
4756 * outstanding commands back to the Operating System.
4757 * Caller should make sure that the following locks are released
4758 * before this calling routine: Hardware lock, and io_request_lock.
4760 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4764 unsigned long flags;
4766 spin_lock_irqsave(&ha->hardware_lock, flags);
4767 for (i = 0; i < ha->host->can_queue; i++) {
4768 srb = qla4xxx_del_from_active_array(ha, i);
4770 srb->cmd->result = res;
4771 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4777 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4779 clear_bit(AF_ONLINE, &ha->flags);
4781 /* Disable the board */
4782 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4784 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4785 qla4xxx_mark_all_devices_missing(ha);
4786 clear_bit(AF_INIT_DONE, &ha->flags);
4789 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4791 struct iscsi_session *sess;
4792 struct ddb_entry *ddb_entry;
4794 sess = cls_session->dd_data;
4795 ddb_entry = sess->dd_data;
4796 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4798 if (ddb_entry->ddb_type == FLASH_DDB)
4799 iscsi_block_session(ddb_entry->sess);
4801 iscsi_session_failure(cls_session->dd_data,
4802 ISCSI_ERR_CONN_FAILED);
4806 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4807 * @ha: Pointer to host adapter structure.
4809 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4811 int status = QLA_ERROR;
4812 uint8_t reset_chip = 0;
4816 /* Stall incoming I/O until we are done */
4817 scsi_block_requests(ha->host);
4818 clear_bit(AF_ONLINE, &ha->flags);
4819 clear_bit(AF_LINK_UP, &ha->flags);
4821 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4823 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4825 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4826 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4827 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4829 /* disable pause frame for ISP83xx */
4830 qla4_83xx_disable_pause(ha);
4833 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4835 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4838 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4839 * do not reset adapter, jump to initialize_adapter */
4840 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4841 status = QLA_SUCCESS;
4842 goto recover_ha_init_adapter;
4845 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4846 * from eh_host_reset or ioctl module */
4847 if (is_qla80XX(ha) && !reset_chip &&
4848 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4850 DEBUG2(ql4_printk(KERN_INFO, ha,
4851 "scsi%ld: %s - Performing stop_firmware...\n",
4852 ha->host_no, __func__));
4853 status = ha->isp_ops->reset_firmware(ha);
4854 if (status == QLA_SUCCESS) {
4855 ha->isp_ops->disable_intrs(ha);
4856 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4857 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4859 /* If the stop_firmware fails then
4860 * reset the entire chip */
4862 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4863 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4867 /* Issue full chip reset if recovering from a catastrophic error,
4868 * or if stop_firmware fails for ISP-8xxx.
4869 * This is the default case for ISP-4xxx */
4870 if (is_qla40XX(ha) || reset_chip) {
4874 /* Check if 8XXX firmware is alive or not
4875 * We may have arrived here from NEED_RESET
4877 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4880 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4881 while (time_before(jiffies, wait)) {
4882 if (qla4_8xxx_check_fw_alive(ha)) {
4883 qla4xxx_mailbox_premature_completion(ha);
4887 set_current_state(TASK_UNINTERRUPTIBLE);
4888 schedule_timeout(HZ);
4891 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4892 qla4xxx_cmd_wait(ha);
4894 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4895 DEBUG2(ql4_printk(KERN_INFO, ha,
4896 "scsi%ld: %s - Performing chip reset..\n",
4897 ha->host_no, __func__));
4898 status = ha->isp_ops->reset_chip(ha);
4899 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4902 /* Flush any pending ddb changed AENs */
4903 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4905 recover_ha_init_adapter:
4906 /* Upon successful firmware/chip reset, re-initialize the adapter */
4907 if (status == QLA_SUCCESS) {
4908 /* For ISP-4xxx, force function 1 to always initialize
4909 * before function 3 to prevent both funcions from
4910 * stepping on top of the other */
4911 if (is_qla40XX(ha) && (ha->mac_index == 3))
4914 /* NOTE: AF_ONLINE flag set upon successful completion of
4915 * qla4xxx_initialize_adapter */
4916 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4917 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4918 status = qla4_8xxx_check_init_adapter_retry(ha);
4919 if (status == QLA_ERROR) {
4920 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4921 ha->host_no, __func__);
4922 qla4xxx_dead_adapter_cleanup(ha);
4923 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4924 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4925 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4932 /* Retry failed adapter initialization, if necessary
4933 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4934 * case to prevent ping-pong resets between functions */
4935 if (!test_bit(AF_ONLINE, &ha->flags) &&
4936 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4937 /* Adapter initialization failed, see if we can retry
4939 * Since we don't want to block the DPC for too long
4940 * with multiple resets in the same thread,
4941 * utilize DPC to retry */
4942 if (is_qla80XX(ha)) {
4943 ha->isp_ops->idc_lock(ha);
4944 dev_state = qla4_8xxx_rd_direct(ha,
4945 QLA8XXX_CRB_DEV_STATE);
4946 ha->isp_ops->idc_unlock(ha);
4947 if (dev_state == QLA8XXX_DEV_FAILED) {
4948 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4949 "recover adapter. H/W is in Failed "
4950 "state\n", __func__);
4951 qla4xxx_dead_adapter_cleanup(ha);
4952 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4953 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4954 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4962 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4963 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4964 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4965 "(%d) more times\n", ha->host_no,
4966 ha->retry_reset_ha_cnt));
4967 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4970 if (ha->retry_reset_ha_cnt > 0) {
4971 /* Schedule another Reset HA--DPC will retry */
4972 ha->retry_reset_ha_cnt--;
4973 DEBUG2(printk("scsi%ld: recover adapter - "
4974 "retry remaining %d\n",
4976 ha->retry_reset_ha_cnt));
4980 if (ha->retry_reset_ha_cnt == 0) {
4981 /* Recover adapter retries have been exhausted.
4983 DEBUG2(printk("scsi%ld: recover adapter "
4984 "failed - board disabled\n",
4986 qla4xxx_dead_adapter_cleanup(ha);
4987 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4988 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4989 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4995 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4996 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4997 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5001 ha->adapter_error_count++;
5003 if (test_bit(AF_ONLINE, &ha->flags))
5004 ha->isp_ops->enable_intrs(ha);
5006 scsi_unblock_requests(ha->host);
5008 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5009 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5010 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5015 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5017 struct iscsi_session *sess;
5018 struct ddb_entry *ddb_entry;
5019 struct scsi_qla_host *ha;
5021 sess = cls_session->dd_data;
5022 ddb_entry = sess->dd_data;
5024 if (!iscsi_is_session_online(cls_session)) {
5025 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5026 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5027 " unblock session\n", ha->host_no, __func__,
5028 ddb_entry->fw_ddb_index);
5029 iscsi_unblock_session(ddb_entry->sess);
5031 /* Trigger relogin */
5032 if (ddb_entry->ddb_type == FLASH_DDB) {
5033 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5034 test_bit(DF_DISABLE_RELOGIN,
5035 &ddb_entry->flags)))
5036 qla4xxx_arm_relogin_timer(ddb_entry);
5038 iscsi_session_failure(cls_session->dd_data,
5039 ISCSI_ERR_CONN_FAILED);
5044 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5046 struct iscsi_session *sess;
5047 struct ddb_entry *ddb_entry;
5048 struct scsi_qla_host *ha;
5050 sess = cls_session->dd_data;
5051 ddb_entry = sess->dd_data;
5053 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5054 " unblock session\n", ha->host_no, __func__,
5055 ddb_entry->fw_ddb_index);
5057 iscsi_unblock_session(ddb_entry->sess);
5059 /* Start scan target */
5060 if (test_bit(AF_ONLINE, &ha->flags)) {
5061 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5062 " start scan\n", ha->host_no, __func__,
5063 ddb_entry->fw_ddb_index);
5064 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5069 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5071 struct iscsi_session *sess;
5072 struct ddb_entry *ddb_entry;
5073 struct scsi_qla_host *ha;
5074 int status = QLA_SUCCESS;
5076 sess = cls_session->dd_data;
5077 ddb_entry = sess->dd_data;
5079 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5080 " unblock user space session\n", ha->host_no, __func__,
5081 ddb_entry->fw_ddb_index);
5083 if (!iscsi_is_session_online(cls_session)) {
5084 iscsi_conn_start(ddb_entry->conn);
5085 iscsi_conn_login_event(ddb_entry->conn,
5086 ISCSI_CONN_STATE_LOGGED_IN);
5088 ql4_printk(KERN_INFO, ha,
5089 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5090 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5098 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5100 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5103 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5105 uint16_t relogin_timer;
5106 struct iscsi_session *sess;
5107 struct ddb_entry *ddb_entry;
5108 struct scsi_qla_host *ha;
5110 sess = cls_sess->dd_data;
5111 ddb_entry = sess->dd_data;
5114 relogin_timer = max(ddb_entry->default_relogin_timeout,
5115 (uint16_t)RELOGIN_TOV);
5116 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5118 DEBUG2(ql4_printk(KERN_INFO, ha,
5119 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5120 ddb_entry->fw_ddb_index, relogin_timer));
5122 qla4xxx_login_flash_ddb(cls_sess);
5125 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5127 struct iscsi_session *sess;
5128 struct ddb_entry *ddb_entry;
5129 struct scsi_qla_host *ha;
5131 sess = cls_sess->dd_data;
5132 ddb_entry = sess->dd_data;
5135 if (!(ddb_entry->ddb_type == FLASH_DDB))
5138 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5141 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5142 !iscsi_is_session_online(cls_sess)) {
5143 DEBUG2(ql4_printk(KERN_INFO, ha,
5144 "relogin issued\n"));
5145 qla4xxx_relogin_flash_ddb(cls_sess);
5149 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5152 queue_work(ha->dpc_thread, &ha->dpc_work);
5155 static struct qla4_work_evt *
5156 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5157 enum qla4_work_type type)
5159 struct qla4_work_evt *e;
5160 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5162 e = kzalloc(size, GFP_ATOMIC);
5166 INIT_LIST_HEAD(&e->list);
5171 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5172 struct qla4_work_evt *e)
5174 unsigned long flags;
5176 spin_lock_irqsave(&ha->work_lock, flags);
5177 list_add_tail(&e->list, &ha->work_list);
5178 spin_unlock_irqrestore(&ha->work_lock, flags);
5179 qla4xxx_wake_dpc(ha);
5182 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5183 enum iscsi_host_event_code aen_code,
5184 uint32_t data_size, uint8_t *data)
5186 struct qla4_work_evt *e;
5188 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5192 e->u.aen.code = aen_code;
5193 e->u.aen.data_size = data_size;
5194 memcpy(e->u.aen.data, data, data_size);
5196 qla4xxx_post_work(ha, e);
5201 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5202 uint32_t status, uint32_t pid,
5203 uint32_t data_size, uint8_t *data)
5205 struct qla4_work_evt *e;
5207 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5211 e->u.ping.status = status;
5212 e->u.ping.pid = pid;
5213 e->u.ping.data_size = data_size;
5214 memcpy(e->u.ping.data, data, data_size);
5216 qla4xxx_post_work(ha, e);
5221 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5223 struct qla4_work_evt *e, *tmp;
5224 unsigned long flags;
5227 spin_lock_irqsave(&ha->work_lock, flags);
5228 list_splice_init(&ha->work_list, &work);
5229 spin_unlock_irqrestore(&ha->work_lock, flags);
5231 list_for_each_entry_safe(e, tmp, &work, list) {
5232 list_del_init(&e->list);
5235 case QLA4_EVENT_AEN:
5236 iscsi_post_host_event(ha->host_no,
5237 &qla4xxx_iscsi_transport,
5242 case QLA4_EVENT_PING_STATUS:
5243 iscsi_ping_comp_event(ha->host_no,
5244 &qla4xxx_iscsi_transport,
5247 e->u.ping.data_size,
5251 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5252 "supported", e->type);
5259 * qla4xxx_do_dpc - dpc routine
5260 * @data: in our case pointer to adapter structure
5262 * This routine is a task that is schedule by the interrupt handler
5263 * to perform the background processing for interrupts. We put it
5264 * on a task queue that is consumed whenever the scheduler runs; that's
5265 * so you can do anything (i.e. put the process to sleep etc). In fact,
5266 * the mid-level tries to sleep when it reaches the driver threshold
5267 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5269 static void qla4xxx_do_dpc(struct work_struct *work)
5271 struct scsi_qla_host *ha =
5272 container_of(work, struct scsi_qla_host, dpc_work);
5273 int status = QLA_ERROR;
5275 DEBUG2(ql4_printk(KERN_INFO, ha,
5276 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5277 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5279 /* Initialization not yet finished. Don't do anything yet. */
5280 if (!test_bit(AF_INIT_DONE, &ha->flags))
5283 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5284 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5285 ha->host_no, __func__, ha->flags));
5289 /* post events to application */
5290 qla4xxx_do_work(ha);
5292 if (is_qla80XX(ha)) {
5293 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5294 if (is_qla8032(ha) || is_qla8042(ha)) {
5295 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5297 /* disable pause frame for ISP83xx */
5298 qla4_83xx_disable_pause(ha);
5301 ha->isp_ops->idc_lock(ha);
5302 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5303 QLA8XXX_DEV_FAILED);
5304 ha->isp_ops->idc_unlock(ha);
5305 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5306 qla4_8xxx_device_state_handler(ha);
5309 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5310 if (is_qla8042(ha)) {
5311 if (ha->idc_info.info2 &
5312 ENABLE_INTERNAL_LOOPBACK) {
5313 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5315 status = qla4_84xx_config_acb(ha,
5316 ACB_CONFIG_DISABLE);
5317 if (status != QLA_SUCCESS) {
5318 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5323 qla4_83xx_post_idc_ack(ha);
5324 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5327 if (is_qla8042(ha) &&
5328 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5329 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5331 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5333 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5336 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5339 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5340 qla4_8xxx_need_qsnt_handler(ha);
5344 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5345 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5346 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5347 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5348 if ((is_qla8022(ha) && ql4xdontresethba) ||
5349 ((is_qla8032(ha) || is_qla8042(ha)) &&
5350 qla4_83xx_idc_dontreset(ha))) {
5351 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5352 ha->host_no, __func__));
5353 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5354 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5355 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5356 goto dpc_post_reset_ha;
5358 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5359 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5360 qla4xxx_recover_adapter(ha);
5362 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5363 uint8_t wait_time = RESET_INTR_TOV;
5365 while ((readw(&ha->reg->ctrl_status) &
5366 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5367 if (--wait_time == 0)
5372 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5373 "bit not cleared-- resetting\n",
5374 ha->host_no, __func__));
5375 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5376 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5377 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5378 status = qla4xxx_recover_adapter(ha);
5380 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5381 if (status == QLA_SUCCESS)
5382 ha->isp_ops->enable_intrs(ha);
5387 /* ---- process AEN? --- */
5388 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5389 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5391 /* ---- Get DHCP IP Address? --- */
5392 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5393 qla4xxx_get_dhcp_ip_address(ha);
5395 /* ---- relogin device? --- */
5396 if (adapter_up(ha) &&
5397 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5398 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5401 /* ---- link change? --- */
5402 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5403 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5404 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5405 /* ---- link down? --- */
5406 qla4xxx_mark_all_devices_missing(ha);
5408 /* ---- link up? --- *
5409 * F/W will auto login to all devices ONLY ONCE after
5410 * link up during driver initialization and runtime
5411 * fatal error recovery. Therefore, the driver must
5412 * manually relogin to devices when recovering from
5413 * connection failures, logouts, expired KATO, etc. */
5414 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5415 qla4xxx_build_ddb_list(ha, ha->is_reset);
5416 iscsi_host_for_each_session(ha->host,
5417 qla4xxx_login_flash_ddb);
5419 qla4xxx_relogin_all_devices(ha);
5422 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5423 if (qla4xxx_sysfs_ddb_export(ha))
5424 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5430 * qla4xxx_free_adapter - release the adapter
5431 * @ha: pointer to adapter structure
5433 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5435 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5437 /* Turn-off interrupts on the card. */
5438 ha->isp_ops->disable_intrs(ha);
5440 if (is_qla40XX(ha)) {
5441 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5442 &ha->reg->ctrl_status);
5443 readl(&ha->reg->ctrl_status);
5444 } else if (is_qla8022(ha)) {
5445 writel(0, &ha->qla4_82xx_reg->host_int);
5446 readl(&ha->qla4_82xx_reg->host_int);
5447 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5448 writel(0, &ha->qla4_83xx_reg->risc_intr);
5449 readl(&ha->qla4_83xx_reg->risc_intr);
5452 /* Remove timer thread, if present */
5453 if (ha->timer_active)
5454 qla4xxx_stop_timer(ha);
5456 /* Kill the kernel thread for this host */
5458 destroy_workqueue(ha->dpc_thread);
5460 /* Kill the kernel thread for this host */
5462 destroy_workqueue(ha->task_wq);
5464 /* Put firmware in known state */
5465 ha->isp_ops->reset_firmware(ha);
5467 if (is_qla80XX(ha)) {
5468 ha->isp_ops->idc_lock(ha);
5469 qla4_8xxx_clear_drv_active(ha);
5470 ha->isp_ops->idc_unlock(ha);
5473 /* Detach interrupts */
5474 qla4xxx_free_irqs(ha);
5476 /* free extra memory */
5477 qla4xxx_mem_free(ha);
5480 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5483 unsigned long mem_base, mem_len, db_base, db_len;
5484 struct pci_dev *pdev = ha->pdev;
5486 status = pci_request_regions(pdev, DRIVER_NAME);
5489 "scsi(%ld) Failed to reserve PIO regions (%s) "
5490 "status=%d\n", ha->host_no, pci_name(pdev), status);
5491 goto iospace_error_exit;
5494 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5495 __func__, pdev->revision));
5496 ha->revision_id = pdev->revision;
5498 /* remap phys address */
5499 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5500 mem_len = pci_resource_len(pdev, 0);
5501 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5502 __func__, mem_base, mem_len));
5504 /* mapping of pcibase pointer */
5505 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5506 if (!ha->nx_pcibase) {
5508 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5509 pci_release_regions(ha->pdev);
5510 goto iospace_error_exit;
5513 /* Mapping of IO base pointer, door bell read and write pointer */
5515 /* mapping of IO base pointer */
5516 if (is_qla8022(ha)) {
5517 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5518 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5519 (ha->pdev->devfn << 11));
5520 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5521 QLA82XX_CAM_RAM_DB2);
5522 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5523 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5524 ((uint8_t *)ha->nx_pcibase);
5527 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5528 db_len = pci_resource_len(pdev, 4);
5536 * qla4xxx_iospace_config - maps registers
5537 * @ha: pointer to adapter structure
5539 * This routines maps HBA's registers from the pci address space
5540 * into the kernel virtual address space for memory mapped i/o.
5542 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5544 unsigned long pio, pio_len, pio_flags;
5545 unsigned long mmio, mmio_len, mmio_flags;
5547 pio = pci_resource_start(ha->pdev, 0);
5548 pio_len = pci_resource_len(ha->pdev, 0);
5549 pio_flags = pci_resource_flags(ha->pdev, 0);
5550 if (pio_flags & IORESOURCE_IO) {
5551 if (pio_len < MIN_IOBASE_LEN) {
5552 ql4_printk(KERN_WARNING, ha,
5553 "Invalid PCI I/O region size\n");
5557 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5561 /* Use MMIO operations for all accesses. */
5562 mmio = pci_resource_start(ha->pdev, 1);
5563 mmio_len = pci_resource_len(ha->pdev, 1);
5564 mmio_flags = pci_resource_flags(ha->pdev, 1);
5566 if (!(mmio_flags & IORESOURCE_MEM)) {
5567 ql4_printk(KERN_ERR, ha,
5568 "region #0 not an MMIO resource, aborting\n");
5570 goto iospace_error_exit;
5573 if (mmio_len < MIN_IOBASE_LEN) {
5574 ql4_printk(KERN_ERR, ha,
5575 "Invalid PCI mem region size, aborting\n");
5576 goto iospace_error_exit;
5579 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5580 ql4_printk(KERN_WARNING, ha,
5581 "Failed to reserve PIO/MMIO regions\n");
5583 goto iospace_error_exit;
5586 ha->pio_address = pio;
5587 ha->pio_length = pio_len;
5588 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5590 ql4_printk(KERN_ERR, ha,
5591 "cannot remap MMIO, aborting\n");
5593 goto iospace_error_exit;
5602 static struct isp_operations qla4xxx_isp_ops = {
5603 .iospace_config = qla4xxx_iospace_config,
5604 .pci_config = qla4xxx_pci_config,
5605 .disable_intrs = qla4xxx_disable_intrs,
5606 .enable_intrs = qla4xxx_enable_intrs,
5607 .start_firmware = qla4xxx_start_firmware,
5608 .intr_handler = qla4xxx_intr_handler,
5609 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5610 .reset_chip = qla4xxx_soft_reset,
5611 .reset_firmware = qla4xxx_hw_reset,
5612 .queue_iocb = qla4xxx_queue_iocb,
5613 .complete_iocb = qla4xxx_complete_iocb,
5614 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5615 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5616 .get_sys_info = qla4xxx_get_sys_info,
5617 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5618 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5621 static struct isp_operations qla4_82xx_isp_ops = {
5622 .iospace_config = qla4_8xxx_iospace_config,
5623 .pci_config = qla4_8xxx_pci_config,
5624 .disable_intrs = qla4_82xx_disable_intrs,
5625 .enable_intrs = qla4_82xx_enable_intrs,
5626 .start_firmware = qla4_8xxx_load_risc,
5627 .restart_firmware = qla4_82xx_try_start_fw,
5628 .intr_handler = qla4_82xx_intr_handler,
5629 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5630 .need_reset = qla4_8xxx_need_reset,
5631 .reset_chip = qla4_82xx_isp_reset,
5632 .reset_firmware = qla4_8xxx_stop_firmware,
5633 .queue_iocb = qla4_82xx_queue_iocb,
5634 .complete_iocb = qla4_82xx_complete_iocb,
5635 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5636 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5637 .get_sys_info = qla4_8xxx_get_sys_info,
5638 .rd_reg_direct = qla4_82xx_rd_32,
5639 .wr_reg_direct = qla4_82xx_wr_32,
5640 .rd_reg_indirect = qla4_82xx_md_rd_32,
5641 .wr_reg_indirect = qla4_82xx_md_wr_32,
5642 .idc_lock = qla4_82xx_idc_lock,
5643 .idc_unlock = qla4_82xx_idc_unlock,
5644 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5645 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5646 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5649 static struct isp_operations qla4_83xx_isp_ops = {
5650 .iospace_config = qla4_8xxx_iospace_config,
5651 .pci_config = qla4_8xxx_pci_config,
5652 .disable_intrs = qla4_83xx_disable_intrs,
5653 .enable_intrs = qla4_83xx_enable_intrs,
5654 .start_firmware = qla4_8xxx_load_risc,
5655 .restart_firmware = qla4_83xx_start_firmware,
5656 .intr_handler = qla4_83xx_intr_handler,
5657 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5658 .need_reset = qla4_8xxx_need_reset,
5659 .reset_chip = qla4_83xx_isp_reset,
5660 .reset_firmware = qla4_8xxx_stop_firmware,
5661 .queue_iocb = qla4_83xx_queue_iocb,
5662 .complete_iocb = qla4_83xx_complete_iocb,
5663 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5664 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5665 .get_sys_info = qla4_8xxx_get_sys_info,
5666 .rd_reg_direct = qla4_83xx_rd_reg,
5667 .wr_reg_direct = qla4_83xx_wr_reg,
5668 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5669 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5670 .idc_lock = qla4_83xx_drv_lock,
5671 .idc_unlock = qla4_83xx_drv_unlock,
5672 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5673 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5674 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5677 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5679 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5682 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5684 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5687 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5689 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5692 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5694 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5697 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5699 struct scsi_qla_host *ha = data;
5704 case ISCSI_BOOT_ETH_FLAGS:
5705 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5707 case ISCSI_BOOT_ETH_INDEX:
5708 rc = sprintf(str, "0\n");
5710 case ISCSI_BOOT_ETH_MAC:
5711 rc = sysfs_format_mac(str, ha->my_mac,
5721 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5726 case ISCSI_BOOT_ETH_FLAGS:
5727 case ISCSI_BOOT_ETH_MAC:
5728 case ISCSI_BOOT_ETH_INDEX:
5738 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5740 struct scsi_qla_host *ha = data;
5745 case ISCSI_BOOT_INI_INITIATOR_NAME:
5746 rc = sprintf(str, "%s\n", ha->name_string);
5755 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5760 case ISCSI_BOOT_INI_INITIATOR_NAME:
5771 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5774 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5779 case ISCSI_BOOT_TGT_NAME:
5780 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5782 case ISCSI_BOOT_TGT_IP_ADDR:
5783 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5784 rc = sprintf(buf, "%pI4\n",
5785 &boot_conn->dest_ipaddr.ip_address);
5787 rc = sprintf(str, "%pI6\n",
5788 &boot_conn->dest_ipaddr.ip_address);
5790 case ISCSI_BOOT_TGT_PORT:
5791 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5793 case ISCSI_BOOT_TGT_CHAP_NAME:
5794 rc = sprintf(str, "%.*s\n",
5795 boot_conn->chap.target_chap_name_length,
5796 (char *)&boot_conn->chap.target_chap_name);
5798 case ISCSI_BOOT_TGT_CHAP_SECRET:
5799 rc = sprintf(str, "%.*s\n",
5800 boot_conn->chap.target_secret_length,
5801 (char *)&boot_conn->chap.target_secret);
5803 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5804 rc = sprintf(str, "%.*s\n",
5805 boot_conn->chap.intr_chap_name_length,
5806 (char *)&boot_conn->chap.intr_chap_name);
5808 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5809 rc = sprintf(str, "%.*s\n",
5810 boot_conn->chap.intr_secret_length,
5811 (char *)&boot_conn->chap.intr_secret);
5813 case ISCSI_BOOT_TGT_FLAGS:
5814 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5816 case ISCSI_BOOT_TGT_NIC_ASSOC:
5817 rc = sprintf(str, "0\n");
5826 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5828 struct scsi_qla_host *ha = data;
5829 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5831 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5834 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5836 struct scsi_qla_host *ha = data;
5837 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5839 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5842 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5847 case ISCSI_BOOT_TGT_NAME:
5848 case ISCSI_BOOT_TGT_IP_ADDR:
5849 case ISCSI_BOOT_TGT_PORT:
5850 case ISCSI_BOOT_TGT_CHAP_NAME:
5851 case ISCSI_BOOT_TGT_CHAP_SECRET:
5852 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5853 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5854 case ISCSI_BOOT_TGT_NIC_ASSOC:
5855 case ISCSI_BOOT_TGT_FLAGS:
5865 static void qla4xxx_boot_release(void *data)
5867 struct scsi_qla_host *ha = data;
5869 scsi_host_put(ha->host);
5872 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5875 uint32_t addr, pri_addr, sec_addr;
5879 uint8_t *buf = NULL;
5880 size_t size = 13 * sizeof(uint8_t);
5881 int ret = QLA_SUCCESS;
5883 func_num = PCI_FUNC(ha->pdev->devfn);
5885 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5886 __func__, ha->pdev->device, func_num);
5888 if (is_qla40XX(ha)) {
5889 if (func_num == 1) {
5890 addr = NVRAM_PORT0_BOOT_MODE;
5891 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5892 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5893 } else if (func_num == 3) {
5894 addr = NVRAM_PORT1_BOOT_MODE;
5895 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5896 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5899 goto exit_boot_info;
5902 /* Check Boot Mode */
5903 val = rd_nvram_byte(ha, addr);
5904 if (!(val & 0x07)) {
5905 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5906 "options : 0x%x\n", __func__, val));
5908 goto exit_boot_info;
5911 /* get primary valid target index */
5912 val = rd_nvram_byte(ha, pri_addr);
5914 ddb_index[0] = (val & 0x7f);
5916 /* get secondary valid target index */
5917 val = rd_nvram_byte(ha, sec_addr);
5919 ddb_index[1] = (val & 0x7f);
5921 } else if (is_qla80XX(ha)) {
5922 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5923 &buf_dma, GFP_KERNEL);
5925 DEBUG2(ql4_printk(KERN_ERR, ha,
5926 "%s: Unable to allocate dma buffer\n",
5929 goto exit_boot_info;
5932 if (ha->port_num == 0)
5933 offset = BOOT_PARAM_OFFSET_PORT0;
5934 else if (ha->port_num == 1)
5935 offset = BOOT_PARAM_OFFSET_PORT1;
5938 goto exit_boot_info_free;
5940 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5942 if (qla4xxx_get_flash(ha, buf_dma, addr,
5943 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5944 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5945 " failed\n", ha->host_no, __func__));
5947 goto exit_boot_info_free;
5949 /* Check Boot Mode */
5950 if (!(buf[1] & 0x07)) {
5951 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5952 " : 0x%x\n", buf[1]));
5954 goto exit_boot_info_free;
5957 /* get primary valid target index */
5959 ddb_index[0] = buf[2] & 0x7f;
5961 /* get secondary valid target index */
5962 if (buf[11] & BIT_7)
5963 ddb_index[1] = buf[11] & 0x7f;
5966 goto exit_boot_info;
5969 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5970 " target ID %d\n", __func__, ddb_index[0],
5973 exit_boot_info_free:
5974 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5976 ha->pri_ddb_idx = ddb_index[0];
5977 ha->sec_ddb_idx = ddb_index[1];
5982 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5983 * @ha: pointer to adapter structure
5984 * @username: CHAP username to be returned
5985 * @password: CHAP password to be returned
5987 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
5988 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
5989 * So from the CHAP cache find the first BIDI CHAP entry and set it
5990 * to the boot record in sysfs.
5992 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
5995 int i, ret = -EINVAL;
5996 int max_chap_entries = 0;
5997 struct ql4_chap_table *chap_table;
6000 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6001 sizeof(struct ql4_chap_table);
6003 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6005 if (!ha->chap_list) {
6006 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6010 mutex_lock(&ha->chap_sem);
6011 for (i = 0; i < max_chap_entries; i++) {
6012 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6013 if (chap_table->cookie !=
6014 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6018 if (chap_table->flags & BIT_7) /* local */
6021 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6024 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6025 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6029 mutex_unlock(&ha->chap_sem);
6035 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6036 struct ql4_boot_session_info *boot_sess,
6039 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6040 struct dev_db_entry *fw_ddb_entry;
6041 dma_addr_t fw_ddb_entry_dma;
6044 int ret = QLA_SUCCESS;
6046 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6047 &fw_ddb_entry_dma, GFP_KERNEL);
6048 if (!fw_ddb_entry) {
6049 DEBUG2(ql4_printk(KERN_ERR, ha,
6050 "%s: Unable to allocate dma buffer.\n",
6056 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6057 fw_ddb_entry_dma, ddb_index)) {
6058 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6059 "index [%d]\n", __func__, ddb_index));
6061 goto exit_boot_target;
6064 /* Update target name and IP from DDB */
6065 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6066 min(sizeof(boot_sess->target_name),
6067 sizeof(fw_ddb_entry->iscsi_name)));
6069 options = le16_to_cpu(fw_ddb_entry->options);
6070 if (options & DDB_OPT_IPV6_DEVICE) {
6071 memcpy(&boot_conn->dest_ipaddr.ip_address,
6072 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6074 boot_conn->dest_ipaddr.ip_type = 0x1;
6075 memcpy(&boot_conn->dest_ipaddr.ip_address,
6076 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6079 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6081 /* update chap information */
6082 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6084 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6086 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6088 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6090 (char *)&boot_conn->chap.target_secret,
6093 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6095 goto exit_boot_target;
6098 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6099 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6102 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6104 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6106 ret = qla4xxx_get_bidi_chap(ha,
6107 (char *)&boot_conn->chap.intr_chap_name,
6108 (char *)&boot_conn->chap.intr_secret);
6111 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6113 goto exit_boot_target;
6116 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6117 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6121 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6122 fw_ddb_entry, fw_ddb_entry_dma);
6126 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6128 uint16_t ddb_index[2];
6129 int ret = QLA_ERROR;
6132 memset(ddb_index, 0, sizeof(ddb_index));
6133 ddb_index[0] = 0xffff;
6134 ddb_index[1] = 0xffff;
6135 ret = get_fw_boot_info(ha, ddb_index);
6136 if (ret != QLA_SUCCESS) {
6137 DEBUG2(ql4_printk(KERN_INFO, ha,
6138 "%s: No boot target configured.\n", __func__));
6142 if (ql4xdisablesysfsboot)
6145 if (ddb_index[0] == 0xffff)
6148 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6150 if (rval != QLA_SUCCESS) {
6151 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6152 "configured\n", __func__));
6157 if (ddb_index[1] == 0xffff)
6158 goto exit_get_boot_info;
6160 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6162 if (rval != QLA_SUCCESS) {
6163 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6164 " configured\n", __func__));
6172 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6174 struct iscsi_boot_kobj *boot_kobj;
6176 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6179 if (ql4xdisablesysfsboot) {
6180 ql4_printk(KERN_INFO, ha,
6181 "%s: syfsboot disabled - driver will trigger login "
6182 "and publish session for discovery .\n", __func__);
6187 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6191 if (!scsi_host_get(ha->host))
6193 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6194 qla4xxx_show_boot_tgt_pri_info,
6195 qla4xxx_tgt_get_attr_visibility,
6196 qla4xxx_boot_release);
6200 if (!scsi_host_get(ha->host))
6202 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6203 qla4xxx_show_boot_tgt_sec_info,
6204 qla4xxx_tgt_get_attr_visibility,
6205 qla4xxx_boot_release);
6209 if (!scsi_host_get(ha->host))
6211 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6212 qla4xxx_show_boot_ini_info,
6213 qla4xxx_ini_get_attr_visibility,
6214 qla4xxx_boot_release);
6218 if (!scsi_host_get(ha->host))
6220 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6221 qla4xxx_show_boot_eth_info,
6222 qla4xxx_eth_get_attr_visibility,
6223 qla4xxx_boot_release);
6230 scsi_host_put(ha->host);
6232 iscsi_boot_destroy_kset(ha->boot_kset);
6237 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6238 struct ql4_tuple_ddb *tddb)
6240 struct scsi_qla_host *ha;
6241 struct iscsi_cls_session *cls_sess;
6242 struct iscsi_cls_conn *cls_conn;
6243 struct iscsi_session *sess;
6244 struct iscsi_conn *conn;
6246 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6248 cls_sess = ddb_entry->sess;
6249 sess = cls_sess->dd_data;
6250 cls_conn = ddb_entry->conn;
6251 conn = cls_conn->dd_data;
6253 tddb->tpgt = sess->tpgt;
6254 tddb->port = conn->persistent_port;
6255 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6256 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6259 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6260 struct ql4_tuple_ddb *tddb,
6261 uint8_t *flash_isid)
6263 uint16_t options = 0;
6265 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6266 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6267 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6269 options = le16_to_cpu(fw_ddb_entry->options);
6270 if (options & DDB_OPT_IPV6_DEVICE)
6271 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6273 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6275 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6277 if (flash_isid == NULL)
6278 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6279 sizeof(tddb->isid));
6281 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6284 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6285 struct ql4_tuple_ddb *old_tddb,
6286 struct ql4_tuple_ddb *new_tddb,
6287 uint8_t is_isid_compare)
6289 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6292 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6295 if (old_tddb->port != new_tddb->port)
6298 /* For multi sessions, driver generates the ISID, so do not compare
6299 * ISID in reset path since it would be a comparison between the
6300 * driver generated ISID and firmware generated ISID. This could
6301 * lead to adding duplicated DDBs in the list as driver generated
6302 * ISID would not match firmware generated ISID.
6304 if (is_isid_compare) {
6305 DEBUG2(ql4_printk(KERN_INFO, ha,
6306 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6307 __func__, old_tddb->isid, new_tddb->isid));
6309 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6310 sizeof(old_tddb->isid)))
6314 DEBUG2(ql4_printk(KERN_INFO, ha,
6315 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6316 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6317 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6318 new_tddb->ip_addr, new_tddb->iscsi_name));
6323 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6324 struct dev_db_entry *fw_ddb_entry,
6327 struct ddb_entry *ddb_entry;
6328 struct ql4_tuple_ddb *fw_tddb = NULL;
6329 struct ql4_tuple_ddb *tmp_tddb = NULL;
6331 int ret = QLA_ERROR;
6333 fw_tddb = vzalloc(sizeof(*fw_tddb));
6335 DEBUG2(ql4_printk(KERN_WARNING, ha,
6336 "Memory Allocation failed.\n"));
6341 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6343 DEBUG2(ql4_printk(KERN_WARNING, ha,
6344 "Memory Allocation failed.\n"));
6349 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6351 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6352 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6353 if (ddb_entry == NULL)
6356 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6357 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6358 ret = QLA_SUCCESS; /* found */
6374 * qla4xxx_check_existing_isid - check if target with same isid exist
6376 * @list_nt: list of target
6377 * @isid: isid to check
6379 * This routine return QLA_SUCCESS if target with same isid exist
6381 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6383 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6384 struct dev_db_entry *fw_ddb_entry;
6386 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6387 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6389 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6390 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6398 * qla4xxx_update_isid - compare ddbs and updated isid
6399 * @ha: Pointer to host adapter structure.
6400 * @list_nt: list of nt target
6401 * @fw_ddb_entry: firmware ddb entry
6403 * This routine update isid if ddbs have same iqn, same isid and
6404 * different IP addr.
6405 * Return QLA_SUCCESS if isid is updated.
6407 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6408 struct list_head *list_nt,
6409 struct dev_db_entry *fw_ddb_entry)
6411 uint8_t base_value, i;
6413 base_value = fw_ddb_entry->isid[1] & 0x1f;
6414 for (i = 0; i < 8; i++) {
6415 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6416 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6420 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6427 * qla4xxx_should_update_isid - check if isid need to update
6428 * @ha: Pointer to host adapter structure.
6429 * @old_tddb: ddb tuple
6430 * @new_tddb: ddb tuple
6432 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6435 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6436 struct ql4_tuple_ddb *old_tddb,
6437 struct ql4_tuple_ddb *new_tddb)
6439 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6441 if (old_tddb->port == new_tddb->port)
6445 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6449 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6450 sizeof(old_tddb->isid)))
6451 /* different isid */
6458 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6459 * @ha: Pointer to host adapter structure.
6460 * @list_nt: list of nt target.
6461 * @fw_ddb_entry: firmware ddb entry.
6463 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6464 * duplicate ddb in list_nt.
6465 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6466 * Note: This function also update isid of DDB if required.
6469 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6470 struct list_head *list_nt,
6471 struct dev_db_entry *fw_ddb_entry)
6473 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6474 struct ql4_tuple_ddb *fw_tddb = NULL;
6475 struct ql4_tuple_ddb *tmp_tddb = NULL;
6476 int rval, ret = QLA_ERROR;
6478 fw_tddb = vzalloc(sizeof(*fw_tddb));
6480 DEBUG2(ql4_printk(KERN_WARNING, ha,
6481 "Memory Allocation failed.\n"));
6486 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6488 DEBUG2(ql4_printk(KERN_WARNING, ha,
6489 "Memory Allocation failed.\n"));
6494 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6496 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6497 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6498 nt_ddb_idx->flash_isid);
6499 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6500 /* found duplicate ddb */
6501 if (ret == QLA_SUCCESS)
6505 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6506 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6508 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6509 if (ret == QLA_SUCCESS) {
6510 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6511 if (rval == QLA_SUCCESS)
6528 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6530 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6532 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6533 list_del_init(&ddb_idx->list);
6538 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6539 struct dev_db_entry *fw_ddb_entry)
6541 struct iscsi_endpoint *ep;
6542 struct sockaddr_in *addr;
6543 struct sockaddr_in6 *addr6;
6544 struct sockaddr *t_addr;
6545 struct sockaddr_storage *dst_addr;
6548 /* TODO: need to destroy on unload iscsi_endpoint*/
6549 dst_addr = vmalloc(sizeof(*dst_addr));
6553 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6554 t_addr = (struct sockaddr *)dst_addr;
6555 t_addr->sa_family = AF_INET6;
6556 addr6 = (struct sockaddr_in6 *)dst_addr;
6557 ip = (char *)&addr6->sin6_addr;
6558 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6559 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6562 t_addr = (struct sockaddr *)dst_addr;
6563 t_addr->sa_family = AF_INET;
6564 addr = (struct sockaddr_in *)dst_addr;
6565 ip = (char *)&addr->sin_addr;
6566 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6567 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6570 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6575 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6577 if (ql4xdisablesysfsboot)
6579 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6584 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6585 struct ddb_entry *ddb_entry,
6588 uint16_t def_timeout;
6590 ddb_entry->ddb_type = FLASH_DDB;
6591 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6592 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6594 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6595 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6596 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6598 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6599 atomic_set(&ddb_entry->relogin_timer, 0);
6600 atomic_set(&ddb_entry->relogin_retry_count, 0);
6601 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6602 ddb_entry->default_relogin_timeout =
6603 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6604 def_timeout : LOGIN_TOV;
6605 ddb_entry->default_time2wait =
6606 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6608 if (ql4xdisablesysfsboot &&
6609 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6610 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6613 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6616 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6617 uint32_t sts[MBOX_REG_COUNT];
6619 unsigned long wtime;
6622 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6624 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6625 if (ip_idx[idx] == -1)
6628 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6630 if (ret == QLA_ERROR) {
6635 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6637 DEBUG2(ql4_printk(KERN_INFO, ha,
6638 "Waiting for IP state for idx = %d, state = 0x%x\n",
6639 ip_idx[idx], ip_state));
6640 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6641 ip_state == IP_ADDRSTATE_INVALID ||
6642 ip_state == IP_ADDRSTATE_PREFERRED ||
6643 ip_state == IP_ADDRSTATE_DEPRICATED ||
6644 ip_state == IP_ADDRSTATE_DISABLING)
6648 /* Break if all IP states checked */
6649 if ((ip_idx[0] == -1) &&
6650 (ip_idx[1] == -1) &&
6651 (ip_idx[2] == -1) &&
6654 schedule_timeout_uninterruptible(HZ);
6655 } while (time_after(wtime, jiffies));
6658 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6659 struct dev_db_entry *flash_ddb_entry)
6661 uint16_t options = 0;
6662 size_t ip_len = IP_ADDR_LEN;
6664 options = le16_to_cpu(fw_ddb_entry->options);
6665 if (options & DDB_OPT_IPV6_DEVICE)
6666 ip_len = IPv6_ADDR_LEN;
6668 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6671 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6672 sizeof(fw_ddb_entry->isid)))
6675 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6676 sizeof(fw_ddb_entry->port)))
6682 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6683 struct dev_db_entry *fw_ddb_entry,
6684 uint32_t fw_idx, uint32_t *flash_index)
6686 struct dev_db_entry *flash_ddb_entry;
6687 dma_addr_t flash_ddb_entry_dma;
6690 int ret = QLA_ERROR, status;
6692 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6695 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6696 &flash_ddb_entry_dma);
6697 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6698 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6699 goto exit_find_st_idx;
6702 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6703 flash_ddb_entry_dma, fw_idx);
6704 if (status == QLA_SUCCESS) {
6705 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6706 if (status == QLA_SUCCESS) {
6707 *flash_index = fw_idx;
6709 goto exit_find_st_idx;
6713 for (idx = 0; idx < max_ddbs; idx++) {
6714 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6715 flash_ddb_entry_dma, idx);
6716 if (status == QLA_ERROR)
6719 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6720 if (status == QLA_SUCCESS) {
6723 goto exit_find_st_idx;
6727 if (idx == max_ddbs)
6728 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6732 if (flash_ddb_entry)
6733 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6734 flash_ddb_entry_dma);
6739 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6740 struct list_head *list_st)
6742 struct qla_ddb_index *st_ddb_idx;
6745 struct dev_db_entry *fw_ddb_entry;
6746 dma_addr_t fw_ddb_dma;
6748 uint32_t idx = 0, next_idx = 0;
6749 uint32_t state = 0, conn_err = 0;
6750 uint32_t flash_index = -1;
6751 uint16_t conn_id = 0;
6753 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6755 if (fw_ddb_entry == NULL) {
6756 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6760 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6762 fw_idx_size = sizeof(struct qla_ddb_index);
6764 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6765 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6766 NULL, &next_idx, &state,
6767 &conn_err, NULL, &conn_id);
6768 if (ret == QLA_ERROR)
6771 /* Ignore DDB if invalid state (unassigned) */
6772 if (state == DDB_DS_UNASSIGNED)
6773 goto continue_next_st;
6775 /* Check if ST, add to the list_st */
6776 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6777 goto continue_next_st;
6779 st_ddb_idx = vzalloc(fw_idx_size);
6783 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6785 if (ret == QLA_ERROR) {
6786 ql4_printk(KERN_ERR, ha,
6787 "No flash entry for ST at idx [%d]\n", idx);
6788 st_ddb_idx->flash_ddb_idx = idx;
6790 ql4_printk(KERN_INFO, ha,
6791 "ST at idx [%d] is stored at flash [%d]\n",
6793 st_ddb_idx->flash_ddb_idx = flash_index;
6796 st_ddb_idx->fw_ddb_idx = idx;
6798 list_add_tail(&st_ddb_idx->list, list_st);
6806 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6810 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6811 * @ha: pointer to adapter structure
6812 * @list_ddb: List from which failed ddb to be removed
6814 * Iterate over the list of DDBs and find and remove DDBs that are either in
6815 * no connection active state or failed state
6817 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6818 struct list_head *list_ddb)
6820 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6821 uint32_t next_idx = 0;
6822 uint32_t state = 0, conn_err = 0;
6825 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6826 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6827 NULL, 0, NULL, &next_idx, &state,
6828 &conn_err, NULL, NULL);
6829 if (ret == QLA_ERROR)
6832 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6833 state == DDB_DS_SESSION_FAILED) {
6834 list_del_init(&ddb_idx->list);
6840 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6841 struct ddb_entry *ddb_entry,
6842 struct dev_db_entry *fw_ddb_entry)
6844 struct iscsi_cls_session *cls_sess;
6845 struct iscsi_session *sess;
6846 uint32_t max_ddbs = 0;
6847 uint16_t ddb_link = -1;
6849 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6852 cls_sess = ddb_entry->sess;
6853 sess = cls_sess->dd_data;
6855 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6856 if (ddb_link < max_ddbs)
6857 sess->discovery_parent_idx = ddb_link;
6859 sess->discovery_parent_idx = DDB_NO_LINK;
6862 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6863 struct dev_db_entry *fw_ddb_entry,
6864 int is_reset, uint16_t idx)
6866 struct iscsi_cls_session *cls_sess;
6867 struct iscsi_session *sess;
6868 struct iscsi_cls_conn *cls_conn;
6869 struct iscsi_endpoint *ep;
6870 uint16_t cmds_max = 32;
6871 uint16_t conn_id = 0;
6872 uint32_t initial_cmdsn = 0;
6873 int ret = QLA_SUCCESS;
6875 struct ddb_entry *ddb_entry = NULL;
6877 /* Create session object, with INVALID_ENTRY,
6878 * the targer_id would get set when we issue the login
6880 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6881 cmds_max, sizeof(struct ddb_entry),
6882 sizeof(struct ql4_task_data),
6883 initial_cmdsn, INVALID_ENTRY);
6890 * so calling module_put function to decrement the
6893 module_put(qla4xxx_iscsi_transport.owner);
6894 sess = cls_sess->dd_data;
6895 ddb_entry = sess->dd_data;
6896 ddb_entry->sess = cls_sess;
6898 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6899 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6900 sizeof(struct dev_db_entry));
6902 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6904 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6911 ddb_entry->conn = cls_conn;
6913 /* Setup ep, for displaying attributes in sysfs */
6914 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6916 ep->conn = cls_conn;
6919 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6924 /* Update sess/conn params */
6925 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6926 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6928 if (is_reset == RESET_ADAPTER) {
6929 iscsi_block_session(cls_sess);
6930 /* Use the relogin path to discover new devices
6931 * by short-circuting the logic of setting
6932 * timer to relogin - instead set the flags
6933 * to initiate login right away.
6935 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6936 set_bit(DF_RELOGIN, &ddb_entry->flags);
6943 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6944 struct list_head *list_ddb,
6945 struct dev_db_entry *fw_ddb_entry)
6947 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6950 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6952 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6953 if (ddb_idx->fw_ddb_idx == ddb_link) {
6954 DEBUG2(ql4_printk(KERN_INFO, ha,
6955 "Updating NT parent idx from [%d] to [%d]\n",
6956 ddb_link, ddb_idx->flash_ddb_idx));
6957 fw_ddb_entry->ddb_link =
6958 cpu_to_le16(ddb_idx->flash_ddb_idx);
6964 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6965 struct list_head *list_nt,
6966 struct list_head *list_st,
6969 struct dev_db_entry *fw_ddb_entry;
6970 struct ddb_entry *ddb_entry = NULL;
6971 dma_addr_t fw_ddb_dma;
6975 uint32_t idx = 0, next_idx = 0;
6976 uint32_t state = 0, conn_err = 0;
6977 uint32_t ddb_idx = -1;
6978 uint16_t conn_id = 0;
6979 uint16_t ddb_link = -1;
6980 struct qla_ddb_index *nt_ddb_idx;
6982 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6984 if (fw_ddb_entry == NULL) {
6985 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6988 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6990 fw_idx_size = sizeof(struct qla_ddb_index);
6992 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6993 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6994 NULL, &next_idx, &state,
6995 &conn_err, NULL, &conn_id);
6996 if (ret == QLA_ERROR)
6999 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7000 goto continue_next_nt;
7002 /* Check if NT, then add to list it */
7003 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7004 goto continue_next_nt;
7006 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7007 if (ddb_link < max_ddbs)
7008 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7010 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7011 state == DDB_DS_SESSION_FAILED) &&
7012 (is_reset == INIT_ADAPTER))
7013 goto continue_next_nt;
7015 DEBUG2(ql4_printk(KERN_INFO, ha,
7016 "Adding DDB to session = 0x%x\n", idx));
7018 if (is_reset == INIT_ADAPTER) {
7019 nt_ddb_idx = vmalloc(fw_idx_size);
7023 nt_ddb_idx->fw_ddb_idx = idx;
7025 /* Copy original isid as it may get updated in function
7026 * qla4xxx_update_isid(). We need original isid in
7027 * function qla4xxx_compare_tuple_ddb to find duplicate
7029 memcpy(&nt_ddb_idx->flash_isid[0],
7030 &fw_ddb_entry->isid[0],
7031 sizeof(nt_ddb_idx->flash_isid));
7033 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7035 if (ret == QLA_SUCCESS) {
7036 /* free nt_ddb_idx and do not add to list_nt */
7038 goto continue_next_nt;
7041 /* Copy updated isid */
7042 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7043 sizeof(struct dev_db_entry));
7045 list_add_tail(&nt_ddb_idx->list, list_nt);
7046 } else if (is_reset == RESET_ADAPTER) {
7047 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7049 if (ret == QLA_SUCCESS) {
7050 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7052 if (ddb_entry != NULL)
7053 qla4xxx_update_sess_disc_idx(ha,
7056 goto continue_next_nt;
7060 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7061 if (ret == QLA_ERROR)
7071 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7074 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7075 struct list_head *list_nt,
7078 struct dev_db_entry *fw_ddb_entry;
7079 dma_addr_t fw_ddb_dma;
7083 uint32_t idx = 0, next_idx = 0;
7084 uint32_t state = 0, conn_err = 0;
7085 uint16_t conn_id = 0;
7086 struct qla_ddb_index *nt_ddb_idx;
7088 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7090 if (fw_ddb_entry == NULL) {
7091 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7092 goto exit_new_nt_list;
7094 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7096 fw_idx_size = sizeof(struct qla_ddb_index);
7098 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7099 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7100 NULL, &next_idx, &state,
7101 &conn_err, NULL, &conn_id);
7102 if (ret == QLA_ERROR)
7105 /* Check if NT, then add it to list */
7106 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7107 goto continue_next_new_nt;
7109 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7110 goto continue_next_new_nt;
7112 DEBUG2(ql4_printk(KERN_INFO, ha,
7113 "Adding DDB to session = 0x%x\n", idx));
7115 nt_ddb_idx = vmalloc(fw_idx_size);
7119 nt_ddb_idx->fw_ddb_idx = idx;
7121 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7122 if (ret == QLA_SUCCESS) {
7123 /* free nt_ddb_idx and do not add to list_nt */
7125 goto continue_next_new_nt;
7128 if (target_id < max_ddbs)
7129 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7131 list_add_tail(&nt_ddb_idx->list, list_nt);
7133 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7135 if (ret == QLA_ERROR)
7136 goto exit_new_nt_list;
7138 continue_next_new_nt:
7145 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7149 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7150 * @dev: dev associated with the sysfs entry
7151 * @data: pointer to flashnode session object
7154 * 1: if flashnode entry is non-persistent
7155 * 0: if flashnode entry is persistent
7157 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7159 struct iscsi_bus_flash_session *fnode_sess;
7161 if (!iscsi_flashnode_bus_match(dev, NULL))
7164 fnode_sess = iscsi_dev_to_flash_session(dev);
7166 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7170 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7171 * @ha: pointer to host
7172 * @fw_ddb_entry: flash ddb data
7173 * @idx: target index
7174 * @user: if set then this call is made from userland else from kernel
7177 * On sucess: QLA_SUCCESS
7178 * On failure: QLA_ERROR
7180 * This create separate sysfs entries for session and connection attributes of
7181 * the given fw ddb entry.
7182 * If this is invoked as a result of a userspace call then the entry is marked
7183 * as nonpersistent using flash_state field.
7185 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7186 struct dev_db_entry *fw_ddb_entry,
7187 uint16_t *idx, int user)
7189 struct iscsi_bus_flash_session *fnode_sess = NULL;
7190 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7193 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7194 &qla4xxx_iscsi_transport, 0);
7196 ql4_printk(KERN_ERR, ha,
7197 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7198 __func__, *idx, ha->host_no);
7199 goto exit_tgt_create;
7202 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7203 &qla4xxx_iscsi_transport, 0);
7205 ql4_printk(KERN_ERR, ha,
7206 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7207 __func__, *idx, ha->host_no);
7212 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7214 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7216 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7217 fnode_sess->is_boot_target = 1;
7219 fnode_sess->is_boot_target = 0;
7222 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7225 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7226 __func__, fnode_sess->dev.kobj.name);
7228 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7229 __func__, fnode_conn->dev.kobj.name);
7234 iscsi_destroy_flashnode_sess(fnode_sess);
7241 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7242 * @shost: pointer to host
7243 * @buf: type of ddb entry (ipv4/ipv6)
7244 * @len: length of buf
7246 * This creates new ddb entry in the flash by finding first free index and
7247 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7249 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7252 struct scsi_qla_host *ha = to_qla_host(shost);
7253 struct dev_db_entry *fw_ddb_entry = NULL;
7254 dma_addr_t fw_ddb_entry_dma;
7257 uint16_t max_ddbs = 0;
7258 uint32_t options = 0;
7259 uint32_t rval = QLA_ERROR;
7261 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7262 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7263 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7268 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7271 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7272 &fw_ddb_entry_dma, GFP_KERNEL);
7273 if (!fw_ddb_entry) {
7274 DEBUG2(ql4_printk(KERN_ERR, ha,
7275 "%s: Unable to allocate dma buffer\n",
7280 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7281 qla4xxx_sysfs_ddb_is_non_persistent);
7283 ql4_printk(KERN_ERR, ha,
7284 "%s: A non-persistent entry %s found\n",
7285 __func__, dev->kobj.name);
7290 /* Index 0 and 1 are reserved for boot target entries */
7291 for (idx = 2; idx < max_ddbs; idx++) {
7292 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7293 fw_ddb_entry_dma, idx))
7297 if (idx == max_ddbs)
7300 if (!strncasecmp("ipv6", buf, 4))
7301 options |= IPV6_DEFAULT_DDB_ENTRY;
7303 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7304 if (rval == QLA_ERROR)
7307 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7311 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7312 fw_ddb_entry, fw_ddb_entry_dma);
7313 if (rval == QLA_SUCCESS)
7320 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7321 * @fnode_sess: pointer to session attrs of flash ddb entry
7322 * @fnode_conn: pointer to connection attrs of flash ddb entry
7324 * This writes the contents of target ddb buffer to Flash with a valid cookie
7325 * value in order to make the ddb entry persistent.
7327 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7328 struct iscsi_bus_flash_conn *fnode_conn)
7330 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7331 struct scsi_qla_host *ha = to_qla_host(shost);
7332 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7333 struct dev_db_entry *fw_ddb_entry = NULL;
7334 dma_addr_t fw_ddb_entry_dma;
7335 uint32_t options = 0;
7338 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7339 &fw_ddb_entry_dma, GFP_KERNEL);
7340 if (!fw_ddb_entry) {
7341 DEBUG2(ql4_printk(KERN_ERR, ha,
7342 "%s: Unable to allocate dma buffer\n",
7345 goto exit_ddb_apply;
7348 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7349 options |= IPV6_DEFAULT_DDB_ENTRY;
7351 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7352 if (rval == QLA_ERROR)
7353 goto exit_ddb_apply;
7355 dev_db_start_offset += (fnode_sess->target_id *
7356 sizeof(*fw_ddb_entry));
7358 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7359 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7361 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7362 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7364 if (rval == QLA_SUCCESS) {
7365 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7366 ql4_printk(KERN_INFO, ha,
7367 "%s: flash node %u of host %lu written to flash\n",
7368 __func__, fnode_sess->target_id, ha->host_no);
7371 ql4_printk(KERN_ERR, ha,
7372 "%s: Error while writing flash node %u of host %lu to flash\n",
7373 __func__, fnode_sess->target_id, ha->host_no);
7378 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7379 fw_ddb_entry, fw_ddb_entry_dma);
7383 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7384 struct dev_db_entry *fw_ddb_entry,
7387 struct dev_db_entry *ddb_entry = NULL;
7388 dma_addr_t ddb_entry_dma;
7389 unsigned long wtime;
7390 uint32_t mbx_sts = 0;
7391 uint32_t state = 0, conn_err = 0;
7395 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7396 &ddb_entry_dma, GFP_KERNEL);
7398 DEBUG2(ql4_printk(KERN_ERR, ha,
7399 "%s: Unable to allocate dma buffer\n",
7404 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7406 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7407 if (ret != QLA_SUCCESS) {
7408 DEBUG2(ql4_printk(KERN_ERR, ha,
7409 "%s: Unable to set ddb entry for index %d\n",
7411 goto exit_ddb_conn_open;
7414 qla4xxx_conn_open(ha, idx);
7416 /* To ensure that sendtargets is done, wait for at least 12 secs */
7417 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7418 (ha->def_timeout < LOGIN_TOV * 10) ?
7419 ha->def_timeout : LOGIN_TOV);
7421 DEBUG2(ql4_printk(KERN_INFO, ha,
7422 "Default time to wait for login to ddb %d\n", tmo));
7424 wtime = jiffies + (HZ * tmo);
7426 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7427 NULL, &state, &conn_err, NULL,
7429 if (ret == QLA_ERROR)
7432 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7433 state == DDB_DS_SESSION_FAILED)
7436 schedule_timeout_uninterruptible(HZ / 10);
7437 } while (time_after(wtime, jiffies));
7441 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7442 ddb_entry, ddb_entry_dma);
7446 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7447 struct dev_db_entry *fw_ddb_entry,
7450 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7451 struct list_head list_nt;
7455 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7456 ql4_printk(KERN_WARNING, ha,
7457 "%s: A discovery already in progress!\n", __func__);
7461 INIT_LIST_HEAD(&list_nt);
7463 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7465 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7466 if (ret == QLA_ERROR)
7467 goto exit_login_st_clr_bit;
7469 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7470 if (ret == QLA_ERROR)
7473 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7475 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7476 list_del_init(&ddb_idx->list);
7477 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7482 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7483 ql4_printk(KERN_ERR, ha,
7484 "Unable to clear DDB index = 0x%x\n", ddb_index);
7487 clear_bit(ddb_index, ha->ddb_idx_map);
7489 exit_login_st_clr_bit:
7490 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7494 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7495 struct dev_db_entry *fw_ddb_entry,
7498 int ret = QLA_ERROR;
7500 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7501 if (ret != QLA_SUCCESS)
7502 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7511 * qla4xxx_sysfs_ddb_login - Login to the specified target
7512 * @fnode_sess: pointer to session attrs of flash ddb entry
7513 * @fnode_conn: pointer to connection attrs of flash ddb entry
7515 * This logs in to the specified target
7517 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7518 struct iscsi_bus_flash_conn *fnode_conn)
7520 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7521 struct scsi_qla_host *ha = to_qla_host(shost);
7522 struct dev_db_entry *fw_ddb_entry = NULL;
7523 dma_addr_t fw_ddb_entry_dma;
7524 uint32_t options = 0;
7527 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7528 ql4_printk(KERN_ERR, ha,
7529 "%s: Target info is not persistent\n", __func__);
7531 goto exit_ddb_login;
7534 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7535 &fw_ddb_entry_dma, GFP_KERNEL);
7536 if (!fw_ddb_entry) {
7537 DEBUG2(ql4_printk(KERN_ERR, ha,
7538 "%s: Unable to allocate dma buffer\n",
7541 goto exit_ddb_login;
7544 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7545 options |= IPV6_DEFAULT_DDB_ENTRY;
7547 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7548 if (ret == QLA_ERROR)
7549 goto exit_ddb_login;
7551 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7552 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7554 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7555 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7556 fnode_sess->target_id);
7558 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7559 fnode_sess->target_id);
7566 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7567 fw_ddb_entry, fw_ddb_entry_dma);
7572 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7573 * @cls_sess: pointer to session to be logged out
7575 * This performs session log out from the specified target
7577 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7579 struct iscsi_session *sess;
7580 struct ddb_entry *ddb_entry = NULL;
7581 struct scsi_qla_host *ha;
7582 struct dev_db_entry *fw_ddb_entry = NULL;
7583 dma_addr_t fw_ddb_entry_dma;
7584 unsigned long flags;
7585 unsigned long wtime;
7590 sess = cls_sess->dd_data;
7591 ddb_entry = sess->dd_data;
7594 if (ddb_entry->ddb_type != FLASH_DDB) {
7595 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7598 goto exit_ddb_logout;
7601 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7602 ql4_printk(KERN_ERR, ha,
7603 "%s: Logout from boot target entry is not permitted.\n",
7606 goto exit_ddb_logout;
7609 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7610 &fw_ddb_entry_dma, GFP_KERNEL);
7611 if (!fw_ddb_entry) {
7612 ql4_printk(KERN_ERR, ha,
7613 "%s: Unable to allocate dma buffer\n", __func__);
7615 goto exit_ddb_logout;
7618 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7619 goto ddb_logout_init;
7621 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7622 fw_ddb_entry, fw_ddb_entry_dma,
7623 NULL, NULL, &ddb_state, NULL,
7625 if (ret == QLA_ERROR)
7626 goto ddb_logout_init;
7628 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7629 goto ddb_logout_init;
7631 /* wait until next relogin is triggered using DF_RELOGIN and
7632 * clear DF_RELOGIN to avoid invocation of further relogin
7634 wtime = jiffies + (HZ * RELOGIN_TOV);
7636 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7637 goto ddb_logout_init;
7639 schedule_timeout_uninterruptible(HZ);
7640 } while ((time_after(wtime, jiffies)));
7643 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7644 atomic_set(&ddb_entry->relogin_timer, 0);
7646 options = LOGOUT_OPTION_CLOSE_SESSION;
7647 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7649 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7650 wtime = jiffies + (HZ * LOGOUT_TOV);
7652 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7653 fw_ddb_entry, fw_ddb_entry_dma,
7654 NULL, NULL, &ddb_state, NULL,
7656 if (ret == QLA_ERROR)
7657 goto ddb_logout_clr_sess;
7659 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7660 (ddb_state == DDB_DS_SESSION_FAILED))
7661 goto ddb_logout_clr_sess;
7663 schedule_timeout_uninterruptible(HZ);
7664 } while ((time_after(wtime, jiffies)));
7666 ddb_logout_clr_sess:
7667 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7669 * we have decremented the reference count of the driver
7670 * when we setup the session to have the driver unload
7671 * to be seamless without actually destroying the
7674 try_module_get(qla4xxx_iscsi_transport.owner);
7675 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7677 spin_lock_irqsave(&ha->hardware_lock, flags);
7678 qla4xxx_free_ddb(ha, ddb_entry);
7679 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7680 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7682 iscsi_session_teardown(ddb_entry->sess);
7684 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7689 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7690 fw_ddb_entry, fw_ddb_entry_dma);
7695 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7696 * @fnode_sess: pointer to session attrs of flash ddb entry
7697 * @fnode_conn: pointer to connection attrs of flash ddb entry
7699 * This performs log out from the specified target
7701 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7702 struct iscsi_bus_flash_conn *fnode_conn)
7704 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7705 struct scsi_qla_host *ha = to_qla_host(shost);
7706 struct ql4_tuple_ddb *flash_tddb = NULL;
7707 struct ql4_tuple_ddb *tmp_tddb = NULL;
7708 struct dev_db_entry *fw_ddb_entry = NULL;
7709 struct ddb_entry *ddb_entry = NULL;
7710 dma_addr_t fw_ddb_dma;
7711 uint32_t next_idx = 0;
7712 uint32_t state = 0, conn_err = 0;
7713 uint16_t conn_id = 0;
7715 int status, ret = 0;
7717 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7719 if (fw_ddb_entry == NULL) {
7720 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7722 goto exit_ddb_logout;
7725 flash_tddb = vzalloc(sizeof(*flash_tddb));
7727 ql4_printk(KERN_WARNING, ha,
7728 "%s:Memory Allocation failed.\n", __func__);
7730 goto exit_ddb_logout;
7733 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7735 ql4_printk(KERN_WARNING, ha,
7736 "%s:Memory Allocation failed.\n", __func__);
7738 goto exit_ddb_logout;
7741 if (!fnode_sess->targetname) {
7742 ql4_printk(KERN_ERR, ha,
7743 "%s:Cannot logout from SendTarget entry\n",
7746 goto exit_ddb_logout;
7749 if (fnode_sess->is_boot_target) {
7750 ql4_printk(KERN_ERR, ha,
7751 "%s: Logout from boot target entry is not permitted.\n",
7754 goto exit_ddb_logout;
7757 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7760 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7761 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7763 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7765 flash_tddb->tpgt = fnode_sess->tpgt;
7766 flash_tddb->port = fnode_conn->port;
7768 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7770 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7771 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7772 if (ddb_entry == NULL)
7775 if (ddb_entry->ddb_type != FLASH_DDB)
7778 index = ddb_entry->sess->target_id;
7779 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7780 fw_ddb_dma, NULL, &next_idx,
7781 &state, &conn_err, NULL,
7783 if (status == QLA_ERROR) {
7788 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7790 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7792 if (status == QLA_SUCCESS) {
7793 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7798 if (idx == MAX_DDB_ENTRIES)
7807 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7813 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7814 int param, char *buf)
7816 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7817 struct scsi_qla_host *ha = to_qla_host(shost);
7818 struct iscsi_bus_flash_conn *fnode_conn;
7819 struct ql4_chap_table chap_tbl;
7824 dev = iscsi_find_flashnode_conn(fnode_sess);
7828 fnode_conn = iscsi_dev_to_flash_conn(dev);
7831 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7832 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7834 case ISCSI_FLASHNODE_PORTAL_TYPE:
7835 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7837 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7838 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7840 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7841 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7843 case ISCSI_FLASHNODE_ENTRY_EN:
7844 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7846 case ISCSI_FLASHNODE_HDR_DGST_EN:
7847 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7849 case ISCSI_FLASHNODE_DATA_DGST_EN:
7850 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7852 case ISCSI_FLASHNODE_IMM_DATA_EN:
7853 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7855 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7856 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7858 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7859 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7861 case ISCSI_FLASHNODE_PDU_INORDER:
7862 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7864 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7865 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7867 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7868 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7870 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7871 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7873 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7874 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7876 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7877 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7879 case ISCSI_FLASHNODE_ERL:
7880 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7882 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7883 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7885 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7886 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7888 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7889 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7891 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7892 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7894 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7895 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7897 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7898 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7900 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7901 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7903 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7904 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7906 case ISCSI_FLASHNODE_FIRST_BURST:
7907 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7909 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7910 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7912 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7913 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7915 case ISCSI_FLASHNODE_MAX_R2T:
7916 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7918 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7919 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7921 case ISCSI_FLASHNODE_ISID:
7922 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7924 case ISCSI_FLASHNODE_TSID:
7925 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7927 case ISCSI_FLASHNODE_PORT:
7928 rc = sprintf(buf, "%d\n", fnode_conn->port);
7930 case ISCSI_FLASHNODE_MAX_BURST:
7931 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7933 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7934 rc = sprintf(buf, "%u\n",
7935 fnode_sess->default_taskmgmt_timeout);
7937 case ISCSI_FLASHNODE_IPADDR:
7938 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7939 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7941 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7943 case ISCSI_FLASHNODE_ALIAS:
7944 if (fnode_sess->targetalias)
7945 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7947 rc = sprintf(buf, "\n");
7949 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7950 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7951 rc = sprintf(buf, "%pI6\n",
7952 fnode_conn->redirect_ipaddr);
7954 rc = sprintf(buf, "%pI4\n",
7955 fnode_conn->redirect_ipaddr);
7957 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7958 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7960 case ISCSI_FLASHNODE_LOCAL_PORT:
7961 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7963 case ISCSI_FLASHNODE_IPV4_TOS:
7964 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7966 case ISCSI_FLASHNODE_IPV6_TC:
7967 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7968 rc = sprintf(buf, "%u\n",
7969 fnode_conn->ipv6_traffic_class);
7971 rc = sprintf(buf, "\n");
7973 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7974 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7976 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
7977 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7978 rc = sprintf(buf, "%pI6\n",
7979 fnode_conn->link_local_ipv6_addr);
7981 rc = sprintf(buf, "\n");
7983 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
7984 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
7986 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
7987 if (fnode_sess->discovery_parent_type == DDB_ISNS)
7988 parent_type = ISCSI_DISC_PARENT_ISNS;
7989 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
7990 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
7991 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
7992 parent_type = ISCSI_DISC_PARENT_SENDTGT;
7994 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
7996 rc = sprintf(buf, "%s\n",
7997 iscsi_get_discovery_parent_name(parent_type));
7999 case ISCSI_FLASHNODE_NAME:
8000 if (fnode_sess->targetname)
8001 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8003 rc = sprintf(buf, "\n");
8005 case ISCSI_FLASHNODE_TPGT:
8006 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8008 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8009 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8011 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8012 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8014 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8015 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8017 case ISCSI_FLASHNODE_USERNAME:
8018 if (fnode_sess->chap_auth_en) {
8019 qla4xxx_get_uni_chap_at_index(ha,
8022 fnode_sess->chap_out_idx);
8023 rc = sprintf(buf, "%s\n", chap_tbl.name);
8025 rc = sprintf(buf, "\n");
8028 case ISCSI_FLASHNODE_PASSWORD:
8029 if (fnode_sess->chap_auth_en) {
8030 qla4xxx_get_uni_chap_at_index(ha,
8033 fnode_sess->chap_out_idx);
8034 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8036 rc = sprintf(buf, "\n");
8039 case ISCSI_FLASHNODE_STATSN:
8040 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8042 case ISCSI_FLASHNODE_EXP_STATSN:
8043 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8045 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8046 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8058 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8059 * @fnode_sess: pointer to session attrs of flash ddb entry
8060 * @fnode_conn: pointer to connection attrs of flash ddb entry
8061 * @data: Parameters and their values to update
8064 * This sets the parameter of flash ddb entry and writes them to flash
8067 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8068 struct iscsi_bus_flash_conn *fnode_conn,
8069 void *data, int len)
8071 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8072 struct scsi_qla_host *ha = to_qla_host(shost);
8073 struct iscsi_flashnode_param_info *fnode_param;
8074 struct ql4_chap_table chap_tbl;
8075 struct nlattr *attr;
8076 uint16_t chap_out_idx = INVALID_ENTRY;
8080 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8081 nla_for_each_attr(attr, data, len, rem) {
8082 fnode_param = nla_data(attr);
8084 switch (fnode_param->param) {
8085 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8086 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8088 case ISCSI_FLASHNODE_PORTAL_TYPE:
8089 memcpy(fnode_sess->portal_type, fnode_param->value,
8090 strlen(fnode_sess->portal_type));
8092 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8093 fnode_sess->auto_snd_tgt_disable =
8094 fnode_param->value[0];
8096 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8097 fnode_sess->discovery_sess = fnode_param->value[0];
8099 case ISCSI_FLASHNODE_ENTRY_EN:
8100 fnode_sess->entry_state = fnode_param->value[0];
8102 case ISCSI_FLASHNODE_HDR_DGST_EN:
8103 fnode_conn->hdrdgst_en = fnode_param->value[0];
8105 case ISCSI_FLASHNODE_DATA_DGST_EN:
8106 fnode_conn->datadgst_en = fnode_param->value[0];
8108 case ISCSI_FLASHNODE_IMM_DATA_EN:
8109 fnode_sess->imm_data_en = fnode_param->value[0];
8111 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8112 fnode_sess->initial_r2t_en = fnode_param->value[0];
8114 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8115 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8117 case ISCSI_FLASHNODE_PDU_INORDER:
8118 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8120 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8121 fnode_sess->chap_auth_en = fnode_param->value[0];
8122 /* Invalidate chap index if chap auth is disabled */
8123 if (!fnode_sess->chap_auth_en)
8124 fnode_sess->chap_out_idx = INVALID_ENTRY;
8127 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8128 fnode_conn->snack_req_en = fnode_param->value[0];
8130 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8131 fnode_sess->discovery_logout_en = fnode_param->value[0];
8133 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8134 fnode_sess->bidi_chap_en = fnode_param->value[0];
8136 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8137 fnode_sess->discovery_auth_optional =
8138 fnode_param->value[0];
8140 case ISCSI_FLASHNODE_ERL:
8141 fnode_sess->erl = fnode_param->value[0];
8143 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8144 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8146 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8147 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8149 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8150 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8152 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8153 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8155 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8156 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8158 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8159 fnode_conn->fragment_disable = fnode_param->value[0];
8161 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8162 fnode_conn->max_recv_dlength =
8163 *(unsigned *)fnode_param->value;
8165 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8166 fnode_conn->max_xmit_dlength =
8167 *(unsigned *)fnode_param->value;
8169 case ISCSI_FLASHNODE_FIRST_BURST:
8170 fnode_sess->first_burst =
8171 *(unsigned *)fnode_param->value;
8173 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8174 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8176 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8177 fnode_sess->time2retain =
8178 *(uint16_t *)fnode_param->value;
8180 case ISCSI_FLASHNODE_MAX_R2T:
8181 fnode_sess->max_r2t =
8182 *(uint16_t *)fnode_param->value;
8184 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8185 fnode_conn->keepalive_timeout =
8186 *(uint16_t *)fnode_param->value;
8188 case ISCSI_FLASHNODE_ISID:
8189 memcpy(fnode_sess->isid, fnode_param->value,
8190 sizeof(fnode_sess->isid));
8192 case ISCSI_FLASHNODE_TSID:
8193 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8195 case ISCSI_FLASHNODE_PORT:
8196 fnode_conn->port = *(uint16_t *)fnode_param->value;
8198 case ISCSI_FLASHNODE_MAX_BURST:
8199 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8201 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8202 fnode_sess->default_taskmgmt_timeout =
8203 *(uint16_t *)fnode_param->value;
8205 case ISCSI_FLASHNODE_IPADDR:
8206 memcpy(fnode_conn->ipaddress, fnode_param->value,
8209 case ISCSI_FLASHNODE_ALIAS:
8210 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8211 (char *)fnode_param->value);
8213 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8214 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8217 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8218 fnode_conn->max_segment_size =
8219 *(unsigned *)fnode_param->value;
8221 case ISCSI_FLASHNODE_LOCAL_PORT:
8222 fnode_conn->local_port =
8223 *(uint16_t *)fnode_param->value;
8225 case ISCSI_FLASHNODE_IPV4_TOS:
8226 fnode_conn->ipv4_tos = fnode_param->value[0];
8228 case ISCSI_FLASHNODE_IPV6_TC:
8229 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8231 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8232 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8234 case ISCSI_FLASHNODE_NAME:
8235 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8236 (char *)fnode_param->value);
8238 case ISCSI_FLASHNODE_TPGT:
8239 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8241 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8242 memcpy(fnode_conn->link_local_ipv6_addr,
8243 fnode_param->value, IPv6_ADDR_LEN);
8245 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8246 fnode_sess->discovery_parent_idx =
8247 *(uint16_t *)fnode_param->value;
8249 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8250 fnode_conn->tcp_xmit_wsf =
8251 *(uint8_t *)fnode_param->value;
8253 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8254 fnode_conn->tcp_recv_wsf =
8255 *(uint8_t *)fnode_param->value;
8257 case ISCSI_FLASHNODE_STATSN:
8258 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8260 case ISCSI_FLASHNODE_EXP_STATSN:
8261 fnode_conn->exp_statsn =
8262 *(uint32_t *)fnode_param->value;
8264 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8265 chap_out_idx = *(uint16_t *)fnode_param->value;
8266 if (!qla4xxx_get_uni_chap_at_index(ha,
8270 fnode_sess->chap_out_idx = chap_out_idx;
8271 /* Enable chap auth if chap index is valid */
8272 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8276 ql4_printk(KERN_ERR, ha,
8277 "%s: No such sysfs attribute\n", __func__);
8279 goto exit_set_param;
8283 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8290 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8291 * @fnode_sess: pointer to session attrs of flash ddb entry
8293 * This invalidates the flash ddb entry at the given index
8295 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8297 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8298 struct scsi_qla_host *ha = to_qla_host(shost);
8299 uint32_t dev_db_start_offset;
8300 uint32_t dev_db_end_offset;
8301 struct dev_db_entry *fw_ddb_entry = NULL;
8302 dma_addr_t fw_ddb_entry_dma;
8303 uint16_t *ddb_cookie = NULL;
8304 size_t ddb_size = 0;
8309 if (fnode_sess->is_boot_target) {
8311 DEBUG2(ql4_printk(KERN_ERR, ha,
8312 "%s: Deletion of boot target entry is not permitted.\n",
8317 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8320 if (is_qla40XX(ha)) {
8321 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8322 dev_db_end_offset = FLASH_OFFSET_DB_END;
8323 dev_db_start_offset += (fnode_sess->target_id *
8324 sizeof(*fw_ddb_entry));
8325 ddb_size = sizeof(*fw_ddb_entry);
8327 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8328 (ha->hw.flt_region_ddb << 2);
8329 /* flt_ddb_size is DDB table size for both ports
8330 * so divide it by 2 to calculate the offset for second port
8332 if (ha->port_num == 1)
8333 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8335 dev_db_end_offset = dev_db_start_offset +
8336 (ha->hw.flt_ddb_size / 2);
8338 dev_db_start_offset += (fnode_sess->target_id *
8339 sizeof(*fw_ddb_entry));
8340 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8342 ddb_size = sizeof(*ddb_cookie);
8345 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8346 __func__, dev_db_start_offset, dev_db_end_offset));
8348 if (dev_db_start_offset > dev_db_end_offset) {
8350 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8351 __func__, fnode_sess->target_id));
8355 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8356 &fw_ddb_entry_dma, GFP_KERNEL);
8359 DEBUG2(ql4_printk(KERN_ERR, ha,
8360 "%s: Unable to allocate dma buffer\n",
8365 if (is_qla40XX(ha)) {
8366 fw_ddb_entry = pddb;
8367 memset(fw_ddb_entry, 0, ddb_size);
8368 ddb_cookie = &fw_ddb_entry->cookie;
8373 /* invalidate the cookie */
8374 *ddb_cookie = 0xFFEE;
8375 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8376 ddb_size, FLASH_OPT_RMW_COMMIT);
8379 target_id = fnode_sess->target_id;
8380 iscsi_destroy_flashnode_sess(fnode_sess);
8381 ql4_printk(KERN_INFO, ha,
8382 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8383 __func__, target_id, ha->host_no);
8386 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8392 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8393 * @ha: pointer to adapter structure
8395 * Export the firmware DDB for all send targets and normal targets to sysfs.
8397 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8399 struct dev_db_entry *fw_ddb_entry = NULL;
8400 dma_addr_t fw_ddb_entry_dma;
8403 int ret = QLA_SUCCESS;
8405 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8406 sizeof(*fw_ddb_entry),
8407 &fw_ddb_entry_dma, GFP_KERNEL);
8408 if (!fw_ddb_entry) {
8409 DEBUG2(ql4_printk(KERN_ERR, ha,
8410 "%s: Unable to allocate dma buffer\n",
8415 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8418 for (idx = 0; idx < max_ddbs; idx++) {
8419 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8423 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8430 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8436 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8438 iscsi_destroy_all_flashnode(ha->host);
8442 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8443 * @ha: pointer to adapter structure
8444 * @is_reset: Is this init path or reset path
8446 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8447 * using connection open, then create the list of normal targets (nt)
8448 * from firmware DDBs. Based on the list of nt setup session and connection
8451 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8454 struct list_head list_st, list_nt;
8455 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8456 unsigned long wtime;
8458 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8459 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8460 ha->is_reset = is_reset;
8464 INIT_LIST_HEAD(&list_st);
8465 INIT_LIST_HEAD(&list_nt);
8467 qla4xxx_build_st_list(ha, &list_st);
8469 /* Before issuing conn open mbox, ensure all IPs states are configured
8470 * Note, conn open fails if IPs are not configured
8472 qla4xxx_wait_for_ip_configuration(ha);
8474 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8475 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8476 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8479 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8480 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8481 (ha->def_timeout < LOGIN_TOV * 10) ?
8482 ha->def_timeout : LOGIN_TOV);
8484 DEBUG2(ql4_printk(KERN_INFO, ha,
8485 "Default time to wait for build ddb %d\n", tmo));
8487 wtime = jiffies + (HZ * tmo);
8489 if (list_empty(&list_st))
8492 qla4xxx_remove_failed_ddb(ha, &list_st);
8493 schedule_timeout_uninterruptible(HZ / 10);
8494 } while (time_after(wtime, jiffies));
8497 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8499 qla4xxx_free_ddb_list(&list_st);
8500 qla4xxx_free_ddb_list(&list_nt);
8502 qla4xxx_free_ddb_index(ha);
8506 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8508 * @ha: pointer to adapter structure
8510 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8511 * set in DDB and we will wait for login response of boot targets during
8514 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8516 struct ddb_entry *ddb_entry;
8517 struct dev_db_entry *fw_ddb_entry = NULL;
8518 dma_addr_t fw_ddb_entry_dma;
8519 unsigned long wtime;
8521 int max_ddbs, idx, ret;
8523 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8526 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8527 &fw_ddb_entry_dma, GFP_KERNEL);
8528 if (!fw_ddb_entry) {
8529 ql4_printk(KERN_ERR, ha,
8530 "%s: Unable to allocate dma buffer\n", __func__);
8531 goto exit_login_resp;
8534 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8536 for (idx = 0; idx < max_ddbs; idx++) {
8537 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8538 if (ddb_entry == NULL)
8541 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8542 DEBUG2(ql4_printk(KERN_INFO, ha,
8543 "%s: DDB index [%d]\n", __func__,
8544 ddb_entry->fw_ddb_index));
8546 ret = qla4xxx_get_fwddb_entry(ha,
8547 ddb_entry->fw_ddb_index,
8548 fw_ddb_entry, fw_ddb_entry_dma,
8549 NULL, NULL, &ddb_state, NULL,
8551 if (ret == QLA_ERROR)
8552 goto exit_login_resp;
8554 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8555 (ddb_state == DDB_DS_SESSION_FAILED))
8558 schedule_timeout_uninterruptible(HZ);
8560 } while ((time_after(wtime, jiffies)));
8562 if (!time_after(wtime, jiffies)) {
8563 DEBUG2(ql4_printk(KERN_INFO, ha,
8564 "%s: Login response wait timer expired\n",
8566 goto exit_login_resp;
8573 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8574 fw_ddb_entry, fw_ddb_entry_dma);
8578 * qla4xxx_probe_adapter - callback function to probe HBA
8579 * @pdev: pointer to pci_dev structure
8580 * @pci_device_id: pointer to pci_device entry
8582 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8583 * It returns zero if successful. It also initializes all data necessary for
8586 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8587 const struct pci_device_id *ent)
8589 int ret = -ENODEV, status;
8590 struct Scsi_Host *host;
8591 struct scsi_qla_host *ha;
8592 uint8_t init_retry_count = 0;
8594 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8597 if (pci_enable_device(pdev))
8600 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8603 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8604 goto probe_disable_device;
8607 /* Clear our data area */
8608 ha = to_qla_host(host);
8609 memset(ha, 0, sizeof(*ha));
8611 /* Save the information from PCI BIOS. */
8614 ha->host_no = host->host_no;
8615 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8617 pci_enable_pcie_error_reporting(pdev);
8619 /* Setup Runtime configurable options */
8620 if (is_qla8022(ha)) {
8621 ha->isp_ops = &qla4_82xx_isp_ops;
8622 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8623 ha->qdr_sn_window = -1;
8624 ha->ddr_mn_window = -1;
8625 ha->curr_window = 255;
8626 nx_legacy_intr = &legacy_intr[ha->func_num];
8627 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8628 ha->nx_legacy_intr.tgt_status_reg =
8629 nx_legacy_intr->tgt_status_reg;
8630 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8631 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8632 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8633 ha->isp_ops = &qla4_83xx_isp_ops;
8634 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8636 ha->isp_ops = &qla4xxx_isp_ops;
8639 if (is_qla80XX(ha)) {
8640 rwlock_init(&ha->hw_lock);
8641 ha->pf_bit = ha->func_num << 16;
8642 /* Set EEH reset type to fundamental if required by hba */
8643 pdev->needs_freset = 1;
8646 /* Configure PCI I/O space. */
8647 ret = ha->isp_ops->iospace_config(ha);
8649 goto probe_failed_ioconfig;
8651 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8652 pdev->device, pdev->irq, ha->reg);
8654 qla4xxx_config_dma_addressing(ha);
8656 /* Initialize lists and spinlocks. */
8657 INIT_LIST_HEAD(&ha->free_srb_q);
8659 mutex_init(&ha->mbox_sem);
8660 mutex_init(&ha->chap_sem);
8661 init_completion(&ha->mbx_intr_comp);
8662 init_completion(&ha->disable_acb_comp);
8663 init_completion(&ha->idc_comp);
8664 init_completion(&ha->link_up_comp);
8666 spin_lock_init(&ha->hardware_lock);
8667 spin_lock_init(&ha->work_lock);
8669 /* Initialize work list */
8670 INIT_LIST_HEAD(&ha->work_list);
8672 /* Allocate dma buffers */
8673 if (qla4xxx_mem_alloc(ha)) {
8674 ql4_printk(KERN_WARNING, ha,
8675 "[ERROR] Failed to allocate memory for adapter\n");
8681 host->cmd_per_lun = 3;
8682 host->max_channel = 0;
8683 host->max_lun = MAX_LUNS - 1;
8684 host->max_id = MAX_TARGETS;
8685 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8686 host->can_queue = MAX_SRBS ;
8687 host->transportt = qla4xxx_scsi_transport;
8689 pci_set_drvdata(pdev, ha);
8691 ret = scsi_add_host(host, &pdev->dev);
8696 qla4_8xxx_get_flash_info(ha);
8698 if (is_qla8032(ha) || is_qla8042(ha)) {
8699 qla4_83xx_read_reset_template(ha);
8701 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8702 * If DONRESET_BIT0 is set, drivers should not set dev_state
8703 * to NEED_RESET. But if NEED_RESET is set, drivers should
8704 * should honor the reset.
8706 if (ql4xdontresethba == 1)
8707 qla4_83xx_set_idc_dontreset(ha);
8711 * Initialize the Host adapter request/response queues and
8713 * NOTE: interrupts enabled upon successful completion
8715 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8717 /* Dont retry adapter initialization if IRQ allocation failed */
8718 if (is_qla80XX(ha) && (status == QLA_ERROR))
8719 goto skip_retry_init;
8721 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8722 init_retry_count++ < MAX_INIT_RETRIES) {
8724 if (is_qla80XX(ha)) {
8725 ha->isp_ops->idc_lock(ha);
8726 dev_state = qla4_8xxx_rd_direct(ha,
8727 QLA8XXX_CRB_DEV_STATE);
8728 ha->isp_ops->idc_unlock(ha);
8729 if (dev_state == QLA8XXX_DEV_FAILED) {
8730 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8731 "initialize adapter. H/W is in failed state\n",
8736 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8737 "(%d)\n", __func__, init_retry_count));
8739 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8742 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8743 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8744 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8745 goto skip_retry_init;
8750 if (!test_bit(AF_ONLINE, &ha->flags)) {
8751 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8753 if ((is_qla8022(ha) && ql4xdontresethba) ||
8754 ((is_qla8032(ha) || is_qla8042(ha)) &&
8755 qla4_83xx_idc_dontreset(ha))) {
8756 /* Put the device in failed state. */
8757 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8758 ha->isp_ops->idc_lock(ha);
8759 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8760 QLA8XXX_DEV_FAILED);
8761 ha->isp_ops->idc_unlock(ha);
8767 /* Startup the kernel thread for this host adapter. */
8768 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8769 "qla4xxx_dpc\n", __func__));
8770 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8771 ha->dpc_thread = create_singlethread_workqueue(buf);
8772 if (!ha->dpc_thread) {
8773 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8777 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8779 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8782 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8788 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8789 * (which is called indirectly by qla4xxx_initialize_adapter),
8790 * so that irqs will be registered after crbinit but before
8793 if (is_qla40XX(ha)) {
8794 ret = qla4xxx_request_irqs(ha);
8796 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8797 "interrupt %d already in use.\n", pdev->irq);
8802 pci_save_state(ha->pdev);
8803 ha->isp_ops->enable_intrs(ha);
8805 /* Start timer thread. */
8806 qla4xxx_start_timer(ha, 1);
8808 set_bit(AF_INIT_DONE, &ha->flags);
8810 qla4_8xxx_alloc_sysfs_attr(ha);
8813 " QLogic iSCSI HBA Driver version: %s\n"
8814 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8815 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8816 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8817 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8819 /* Set the driver version */
8821 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8823 if (qla4xxx_setup_boot_info(ha))
8824 ql4_printk(KERN_ERR, ha,
8825 "%s: No iSCSI boot target configured\n", __func__);
8827 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8828 /* Perform the build ddb list and login to each */
8829 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8830 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8831 qla4xxx_wait_login_resp_boot_tgt(ha);
8833 qla4xxx_create_chap_list(ha);
8835 qla4xxx_create_ifaces(ha);
8839 scsi_remove_host(ha->host);
8842 qla4xxx_free_adapter(ha);
8844 probe_failed_ioconfig:
8845 pci_disable_pcie_error_reporting(pdev);
8846 scsi_host_put(ha->host);
8848 probe_disable_device:
8849 pci_disable_device(pdev);
8855 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8856 * @ha: pointer to adapter structure
8858 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8859 * so that the other port will not re-initialize while in the process of
8860 * removing the ha due to driver unload or hba hotplug.
8862 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8864 struct scsi_qla_host *other_ha = NULL;
8865 struct pci_dev *other_pdev = NULL;
8866 int fn = ISP4XXX_PCI_FN_2;
8868 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8869 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8870 fn = ISP4XXX_PCI_FN_1;
8873 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8874 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8877 /* Get other_ha if other_pdev is valid and state is enable*/
8879 if (atomic_read(&other_pdev->enable_cnt)) {
8880 other_ha = pci_get_drvdata(other_pdev);
8882 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8883 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8884 "Prevent %s reinit\n", __func__,
8885 dev_name(&other_ha->pdev->dev)));
8888 pci_dev_put(other_pdev);
8892 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8893 struct ddb_entry *ddb_entry)
8895 struct dev_db_entry *fw_ddb_entry = NULL;
8896 dma_addr_t fw_ddb_entry_dma;
8897 unsigned long wtime;
8902 options = LOGOUT_OPTION_CLOSE_SESSION;
8903 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8904 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8908 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8909 &fw_ddb_entry_dma, GFP_KERNEL);
8910 if (!fw_ddb_entry) {
8911 ql4_printk(KERN_ERR, ha,
8912 "%s: Unable to allocate dma buffer\n", __func__);
8916 wtime = jiffies + (HZ * LOGOUT_TOV);
8918 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8919 fw_ddb_entry, fw_ddb_entry_dma,
8920 NULL, NULL, &ddb_state, NULL,
8922 if (status == QLA_ERROR)
8925 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8926 (ddb_state == DDB_DS_SESSION_FAILED))
8929 schedule_timeout_uninterruptible(HZ);
8930 } while ((time_after(wtime, jiffies)));
8933 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8934 fw_ddb_entry, fw_ddb_entry_dma);
8936 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8939 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8941 struct ddb_entry *ddb_entry;
8944 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8946 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8947 if ((ddb_entry != NULL) &&
8948 (ddb_entry->ddb_type == FLASH_DDB)) {
8950 qla4xxx_destroy_ddb(ha, ddb_entry);
8952 * we have decremented the reference count of the driver
8953 * when we setup the session to have the driver unload
8954 * to be seamless without actually destroying the
8957 try_module_get(qla4xxx_iscsi_transport.owner);
8958 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8959 qla4xxx_free_ddb(ha, ddb_entry);
8960 iscsi_session_teardown(ddb_entry->sess);
8965 * qla4xxx_remove_adapter - callback function to remove adapter.
8966 * @pci_dev: PCI device pointer
8968 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
8970 struct scsi_qla_host *ha;
8973 * If the PCI device is disabled then it means probe_adapter had
8974 * failed and resources already cleaned up on probe_adapter exit.
8976 if (!pci_is_enabled(pdev))
8979 ha = pci_get_drvdata(pdev);
8982 qla4xxx_prevent_other_port_reinit(ha);
8984 /* destroy iface from sysfs */
8985 qla4xxx_destroy_ifaces(ha);
8987 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
8988 iscsi_boot_destroy_kset(ha->boot_kset);
8990 qla4xxx_destroy_fw_ddb_session(ha);
8991 qla4_8xxx_free_sysfs_attr(ha);
8993 qla4xxx_sysfs_ddb_remove(ha);
8994 scsi_remove_host(ha->host);
8996 qla4xxx_free_adapter(ha);
8998 scsi_host_put(ha->host);
9000 pci_disable_pcie_error_reporting(pdev);
9001 pci_disable_device(pdev);
9005 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9008 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
9009 * supported addressing method.
9011 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9015 /* Update our PCI device dma_mask for full 64 bit mask */
9016 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
9017 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
9018 dev_dbg(&ha->pdev->dev,
9019 "Failed to set 64 bit PCI consistent mask; "
9021 retval = pci_set_consistent_dma_mask(ha->pdev,
9025 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
9028 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9030 struct iscsi_cls_session *cls_sess;
9031 struct iscsi_session *sess;
9032 struct ddb_entry *ddb;
9033 int queue_depth = QL4_DEF_QDEPTH;
9035 cls_sess = starget_to_session(sdev->sdev_target);
9036 sess = cls_sess->dd_data;
9037 ddb = sess->dd_data;
9039 sdev->hostdata = ddb;
9041 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9042 queue_depth = ql4xmaxqdepth;
9044 scsi_change_queue_depth(sdev, queue_depth);
9049 * qla4xxx_del_from_active_array - returns an active srb
9050 * @ha: Pointer to host adapter structure.
9051 * @index: index into the active_array
9053 * This routine removes and returns the srb at the specified index
9055 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9058 struct srb *srb = NULL;
9059 struct scsi_cmnd *cmd = NULL;
9061 cmd = scsi_host_find_tag(ha->host, index);
9065 srb = (struct srb *)CMD_SP(cmd);
9069 /* update counters */
9070 if (srb->flags & SRB_DMA_VALID) {
9071 ha->iocb_cnt -= srb->iocb_cnt;
9073 srb->cmd->host_scribble =
9074 (unsigned char *)(unsigned long) MAX_SRBS;
9080 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9081 * @ha: Pointer to host adapter structure.
9082 * @cmd: Scsi Command to wait on.
9084 * This routine waits for the command to be returned by the Firmware
9085 * for some max time.
9087 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9088 struct scsi_cmnd *cmd)
9092 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9095 /* Dont wait on command if PCI error is being handled
9098 if (unlikely(pci_channel_offline(ha->pdev)) ||
9099 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9100 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9101 ha->host_no, __func__);
9106 /* Checking to see if its returned to OS */
9107 rp = (struct srb *) CMD_SP(cmd);
9114 } while (max_wait_time--);
9120 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9121 * @ha: Pointer to host adapter structure
9123 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9125 unsigned long wait_online;
9127 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9128 while (time_before(jiffies, wait_online)) {
9140 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9141 * @ha: pointer to HBA
9145 * This function waits for all outstanding commands to a lun to complete. It
9146 * returns 0 if all pending commands are returned and 1 otherwise.
9148 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9149 struct scsi_target *stgt,
9150 struct scsi_device *sdev)
9154 struct scsi_cmnd *cmd;
9157 * Waiting for all commands for the designated target or dev
9158 * in the active array
9160 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9161 cmd = scsi_host_find_tag(ha->host, cnt);
9162 if (cmd && stgt == scsi_target(cmd->device) &&
9163 (!sdev || sdev == cmd->device)) {
9164 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9174 * qla4xxx_eh_abort - callback for abort task.
9175 * @cmd: Pointer to Linux's SCSI command structure
9177 * This routine is called by the Linux OS to abort the specified
9180 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9182 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9183 unsigned int id = cmd->device->id;
9184 uint64_t lun = cmd->device->lun;
9185 unsigned long flags;
9186 struct srb *srb = NULL;
9190 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9191 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9193 spin_lock_irqsave(&ha->hardware_lock, flags);
9194 srb = (struct srb *) CMD_SP(cmd);
9196 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9197 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9198 ha->host_no, id, lun);
9201 kref_get(&srb->srb_ref);
9202 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9204 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9205 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9206 ha->host_no, id, lun));
9209 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9210 ha->host_no, id, lun));
9214 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9216 /* Wait for command to complete */
9218 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9219 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9220 ha->host_no, id, lun));
9225 ql4_printk(KERN_INFO, ha,
9226 "scsi%ld:%d:%llu: Abort command - %s\n",
9227 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9233 * qla4xxx_eh_device_reset - callback for target reset.
9234 * @cmd: Pointer to Linux's SCSI command structure
9236 * This routine is called by the Linux OS to reset all luns on the
9239 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9241 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9242 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9243 int ret = FAILED, stat;
9248 ret = iscsi_block_scsi_eh(cmd);
9253 ql4_printk(KERN_INFO, ha,
9254 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9255 cmd->device->channel, cmd->device->id, cmd->device->lun);
9257 DEBUG2(printk(KERN_INFO
9258 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9259 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9260 cmd, jiffies, cmd->request->timeout / HZ,
9261 ha->dpc_flags, cmd->result, cmd->allowed));
9263 /* FIXME: wait for hba to go online */
9264 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9265 if (stat != QLA_SUCCESS) {
9266 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9267 goto eh_dev_reset_done;
9270 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9272 ql4_printk(KERN_INFO, ha,
9273 "DEVICE RESET FAILED - waiting for "
9275 goto eh_dev_reset_done;
9279 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9280 MM_LUN_RESET) != QLA_SUCCESS)
9281 goto eh_dev_reset_done;
9283 ql4_printk(KERN_INFO, ha,
9284 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9285 ha->host_no, cmd->device->channel, cmd->device->id,
9296 * qla4xxx_eh_target_reset - callback for target reset.
9297 * @cmd: Pointer to Linux's SCSI command structure
9299 * This routine is called by the Linux OS to reset the target.
9301 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9303 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9304 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9310 ret = iscsi_block_scsi_eh(cmd);
9314 starget_printk(KERN_INFO, scsi_target(cmd->device),
9315 "WARM TARGET RESET ISSUED.\n");
9317 DEBUG2(printk(KERN_INFO
9318 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9319 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9320 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9321 ha->dpc_flags, cmd->result, cmd->allowed));
9323 stat = qla4xxx_reset_target(ha, ddb_entry);
9324 if (stat != QLA_SUCCESS) {
9325 starget_printk(KERN_INFO, scsi_target(cmd->device),
9326 "WARM TARGET RESET FAILED.\n");
9330 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9332 starget_printk(KERN_INFO, scsi_target(cmd->device),
9333 "WARM TARGET DEVICE RESET FAILED - "
9334 "waiting for commands.\n");
9339 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9340 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9341 starget_printk(KERN_INFO, scsi_target(cmd->device),
9342 "WARM TARGET DEVICE RESET FAILED - "
9343 "marker iocb failed.\n");
9347 starget_printk(KERN_INFO, scsi_target(cmd->device),
9348 "WARM TARGET RESET SUCCEEDED.\n");
9353 * qla4xxx_is_eh_active - check if error handler is running
9354 * @shost: Pointer to SCSI Host struct
9356 * This routine finds that if reset host is called in EH
9357 * scenario or from some application like sg_reset
9359 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9361 if (shost->shost_state == SHOST_RECOVERY)
9367 * qla4xxx_eh_host_reset - kernel callback
9368 * @cmd: Pointer to Linux's SCSI command structure
9370 * This routine is invoked by the Linux kernel to perform fatal error
9371 * recovery on the specified adapter.
9373 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9375 int return_status = FAILED;
9376 struct scsi_qla_host *ha;
9378 ha = to_qla_host(cmd->device->host);
9380 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9381 qla4_83xx_set_idc_dontreset(ha);
9384 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9385 * protocol drivers, we should not set device_state to NEED_RESET
9387 if (ql4xdontresethba ||
9388 ((is_qla8032(ha) || is_qla8042(ha)) &&
9389 qla4_83xx_idc_dontreset(ha))) {
9390 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9391 ha->host_no, __func__));
9393 /* Clear outstanding srb in queues */
9394 if (qla4xxx_is_eh_active(cmd->device->host))
9395 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9400 ql4_printk(KERN_INFO, ha,
9401 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9402 cmd->device->channel, cmd->device->id, cmd->device->lun);
9404 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9405 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9406 "DEAD.\n", ha->host_no, cmd->device->channel,
9412 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9414 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9416 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9419 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9420 return_status = SUCCESS;
9422 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9423 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9425 return return_status;
9428 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9430 uint32_t mbox_cmd[MBOX_REG_COUNT];
9431 uint32_t mbox_sts[MBOX_REG_COUNT];
9432 struct addr_ctrl_blk_def *acb = NULL;
9433 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9434 int rval = QLA_SUCCESS;
9437 acb = dma_alloc_coherent(&ha->pdev->dev,
9438 sizeof(struct addr_ctrl_blk_def),
9439 &acb_dma, GFP_KERNEL);
9441 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9444 goto exit_port_reset;
9447 memset(acb, 0, acb_len);
9449 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9450 if (rval != QLA_SUCCESS) {
9455 rval = qla4xxx_disable_acb(ha);
9456 if (rval != QLA_SUCCESS) {
9461 wait_for_completion_timeout(&ha->disable_acb_comp,
9462 DISABLE_ACB_TOV * HZ);
9464 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9465 if (rval != QLA_SUCCESS) {
9471 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9474 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9475 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9479 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9481 struct scsi_qla_host *ha = to_qla_host(shost);
9482 int rval = QLA_SUCCESS;
9485 if (ql4xdontresethba) {
9486 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9489 goto exit_host_reset;
9492 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9493 goto recover_adapter;
9495 switch (reset_type) {
9496 case SCSI_ADAPTER_RESET:
9497 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9499 case SCSI_FIRMWARE_RESET:
9500 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9502 /* set firmware context reset */
9503 set_bit(DPC_RESET_HA_FW_CONTEXT,
9506 rval = qla4xxx_context_reset(ha);
9507 goto exit_host_reset;
9514 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9515 * reset is issued by application */
9516 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9517 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9518 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9519 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9520 (idc_ctrl | GRACEFUL_RESET_BIT1));
9523 rval = qla4xxx_recover_adapter(ha);
9524 if (rval != QLA_SUCCESS) {
9525 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9534 /* PCI AER driver recovers from all correctable errors w/o
9535 * driver intervention. For uncorrectable errors PCI AER
9536 * driver calls the following device driver's callbacks
9538 * - Fatal Errors - link_reset
9539 * - Non-Fatal Errors - driver's error_detected() which
9540 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9542 * PCI AER driver calls
9543 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9544 * returns RECOVERED or NEED_RESET if fw_hung
9545 * NEED_RESET - driver's slot_reset()
9546 * DISCONNECT - device is dead & cannot recover
9547 * RECOVERED - driver's resume()
9549 static pci_ers_result_t
9550 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9552 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9554 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9555 ha->host_no, __func__, state);
9557 if (!is_aer_supported(ha))
9558 return PCI_ERS_RESULT_NONE;
9561 case pci_channel_io_normal:
9562 clear_bit(AF_EEH_BUSY, &ha->flags);
9563 return PCI_ERS_RESULT_CAN_RECOVER;
9564 case pci_channel_io_frozen:
9565 set_bit(AF_EEH_BUSY, &ha->flags);
9566 qla4xxx_mailbox_premature_completion(ha);
9567 qla4xxx_free_irqs(ha);
9568 pci_disable_device(pdev);
9569 /* Return back all IOs */
9570 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9571 return PCI_ERS_RESULT_NEED_RESET;
9572 case pci_channel_io_perm_failure:
9573 set_bit(AF_EEH_BUSY, &ha->flags);
9574 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9575 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9576 return PCI_ERS_RESULT_DISCONNECT;
9578 return PCI_ERS_RESULT_NEED_RESET;
9582 * qla4xxx_pci_mmio_enabled() gets called if
9583 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9584 * and read/write to the device still works.
9586 static pci_ers_result_t
9587 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9589 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9591 if (!is_aer_supported(ha))
9592 return PCI_ERS_RESULT_NONE;
9594 return PCI_ERS_RESULT_RECOVERED;
9597 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9599 uint32_t rval = QLA_ERROR;
9601 struct pci_dev *other_pdev = NULL;
9603 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9605 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9607 if (test_bit(AF_ONLINE, &ha->flags)) {
9608 clear_bit(AF_ONLINE, &ha->flags);
9609 clear_bit(AF_LINK_UP, &ha->flags);
9610 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9611 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9614 fn = PCI_FUNC(ha->pdev->devfn);
9615 if (is_qla8022(ha)) {
9618 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9619 ha->host_no, __func__, fn);
9620 /* Get the pci device given the domain, bus,
9621 * slot/function number */
9622 other_pdev = pci_get_domain_bus_and_slot(
9623 pci_domain_nr(ha->pdev->bus),
9624 ha->pdev->bus->number,
9625 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9631 if (atomic_read(&other_pdev->enable_cnt)) {
9632 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9633 ha->host_no, __func__, fn);
9634 pci_dev_put(other_pdev);
9637 pci_dev_put(other_pdev);
9640 /* this case is meant for ISP83xx/ISP84xx only */
9641 if (qla4_83xx_can_perform_reset(ha)) {
9642 /* reset fn as iSCSI is going to perform the reset */
9647 /* The first function on the card, the reset owner will
9648 * start & initialize the firmware. The other functions
9649 * on the card will reset the firmware context
9652 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9653 "0x%x is the owner\n", ha->host_no, __func__,
9656 ha->isp_ops->idc_lock(ha);
9657 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9659 ha->isp_ops->idc_unlock(ha);
9661 rval = qla4_8xxx_update_idc_reg(ha);
9662 if (rval == QLA_ERROR) {
9663 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9664 ha->host_no, __func__);
9665 ha->isp_ops->idc_lock(ha);
9666 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9667 QLA8XXX_DEV_FAILED);
9668 ha->isp_ops->idc_unlock(ha);
9669 goto exit_error_recovery;
9672 clear_bit(AF_FW_RECOVERY, &ha->flags);
9673 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9675 if (rval != QLA_SUCCESS) {
9676 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9677 "FAILED\n", ha->host_no, __func__);
9678 qla4xxx_free_irqs(ha);
9679 ha->isp_ops->idc_lock(ha);
9680 qla4_8xxx_clear_drv_active(ha);
9681 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9682 QLA8XXX_DEV_FAILED);
9683 ha->isp_ops->idc_unlock(ha);
9685 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9686 "READY\n", ha->host_no, __func__);
9687 ha->isp_ops->idc_lock(ha);
9688 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9690 /* Clear driver state register */
9691 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9692 qla4_8xxx_set_drv_active(ha);
9693 ha->isp_ops->idc_unlock(ha);
9694 ha->isp_ops->enable_intrs(ha);
9697 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9698 "the reset owner\n", ha->host_no, __func__,
9700 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9701 QLA8XXX_DEV_READY)) {
9702 clear_bit(AF_FW_RECOVERY, &ha->flags);
9703 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9704 if (rval == QLA_SUCCESS)
9705 ha->isp_ops->enable_intrs(ha);
9707 qla4xxx_free_irqs(ha);
9709 ha->isp_ops->idc_lock(ha);
9710 qla4_8xxx_set_drv_active(ha);
9711 ha->isp_ops->idc_unlock(ha);
9714 exit_error_recovery:
9715 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9719 static pci_ers_result_t
9720 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9722 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9723 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9726 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9727 ha->host_no, __func__);
9729 if (!is_aer_supported(ha))
9730 return PCI_ERS_RESULT_NONE;
9732 /* Restore the saved state of PCIe device -
9733 * BAR registers, PCI Config space, PCIX, MSI,
9736 pci_restore_state(pdev);
9738 /* pci_restore_state() clears the saved_state flag of the device
9739 * save restored state which resets saved_state flag
9741 pci_save_state(pdev);
9743 /* Initialize device or resume if in suspended state */
9744 rc = pci_enable_device(pdev);
9746 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9747 "device after reset\n", ha->host_no, __func__);
9748 goto exit_slot_reset;
9751 ha->isp_ops->disable_intrs(ha);
9753 if (is_qla80XX(ha)) {
9754 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9755 ret = PCI_ERS_RESULT_RECOVERED;
9756 goto exit_slot_reset;
9758 goto exit_slot_reset;
9762 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9763 "device after reset\n", ha->host_no, __func__, ret);
9768 qla4xxx_pci_resume(struct pci_dev *pdev)
9770 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9773 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9774 ha->host_no, __func__);
9776 ret = qla4xxx_wait_for_hba_online(ha);
9777 if (ret != QLA_SUCCESS) {
9778 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9779 "resume I/O from slot/link_reset\n", ha->host_no,
9783 pci_cleanup_aer_uncorrect_error_status(pdev);
9784 clear_bit(AF_EEH_BUSY, &ha->flags);
9787 static const struct pci_error_handlers qla4xxx_err_handler = {
9788 .error_detected = qla4xxx_pci_error_detected,
9789 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9790 .slot_reset = qla4xxx_pci_slot_reset,
9791 .resume = qla4xxx_pci_resume,
9794 static struct pci_device_id qla4xxx_pci_tbl[] = {
9796 .vendor = PCI_VENDOR_ID_QLOGIC,
9797 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9798 .subvendor = PCI_ANY_ID,
9799 .subdevice = PCI_ANY_ID,
9802 .vendor = PCI_VENDOR_ID_QLOGIC,
9803 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9804 .subvendor = PCI_ANY_ID,
9805 .subdevice = PCI_ANY_ID,
9808 .vendor = PCI_VENDOR_ID_QLOGIC,
9809 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9810 .subvendor = PCI_ANY_ID,
9811 .subdevice = PCI_ANY_ID,
9814 .vendor = PCI_VENDOR_ID_QLOGIC,
9815 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9816 .subvendor = PCI_ANY_ID,
9817 .subdevice = PCI_ANY_ID,
9820 .vendor = PCI_VENDOR_ID_QLOGIC,
9821 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9822 .subvendor = PCI_ANY_ID,
9823 .subdevice = PCI_ANY_ID,
9826 .vendor = PCI_VENDOR_ID_QLOGIC,
9827 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9828 .subvendor = PCI_ANY_ID,
9829 .subdevice = PCI_ANY_ID,
9833 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9835 static struct pci_driver qla4xxx_pci_driver = {
9836 .name = DRIVER_NAME,
9837 .id_table = qla4xxx_pci_tbl,
9838 .probe = qla4xxx_probe_adapter,
9839 .remove = qla4xxx_remove_adapter,
9840 .err_handler = &qla4xxx_err_handler,
9843 static int __init qla4xxx_module_init(void)
9847 if (ql4xqfulltracking)
9848 qla4xxx_driver_template.track_queue_depth = 1;
9850 /* Allocate cache for SRBs. */
9851 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9852 SLAB_HWCACHE_ALIGN, NULL);
9853 if (srb_cachep == NULL) {
9855 "%s: Unable to allocate SRB cache..."
9856 "Failing load!\n", DRIVER_NAME);
9861 /* Derive version string. */
9862 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9863 if (ql4xextended_error_logging)
9864 strcat(qla4xxx_version_str, "-debug");
9866 qla4xxx_scsi_transport =
9867 iscsi_register_transport(&qla4xxx_iscsi_transport);
9868 if (!qla4xxx_scsi_transport){
9870 goto release_srb_cache;
9873 ret = pci_register_driver(&qla4xxx_pci_driver);
9875 goto unregister_transport;
9877 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9880 unregister_transport:
9881 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9883 kmem_cache_destroy(srb_cachep);
9888 static void __exit qla4xxx_module_exit(void)
9890 pci_unregister_driver(&qla4xxx_pci_driver);
9891 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9892 kmem_cache_destroy(srb_cachep);
9895 module_init(qla4xxx_module_init);
9896 module_exit(qla4xxx_module_exit);
9898 MODULE_AUTHOR("QLogic Corporation");
9899 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9900 MODULE_LICENSE("GPL");
9901 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);