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 int qla4xxx_slave_configure(struct scsi_device *device);
166 static umode_t qla4_attr_is_visible(int param_type, int param);
167 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
168 static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
172 * iSCSI Flash DDB sysfs entry points
175 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
176 struct iscsi_bus_flash_conn *fnode_conn,
177 void *data, int len);
179 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
180 int param, char *buf);
181 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
184 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
185 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
186 struct iscsi_bus_flash_conn *fnode_conn);
187 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
188 struct iscsi_bus_flash_conn *fnode_conn);
189 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
191 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
192 QLA82XX_LEGACY_INTR_CONFIG;
194 static struct scsi_host_template qla4xxx_driver_template = {
195 .module = THIS_MODULE,
197 .proc_name = DRIVER_NAME,
198 .queuecommand = qla4xxx_queuecommand,
200 .eh_abort_handler = qla4xxx_eh_abort,
201 .eh_device_reset_handler = qla4xxx_eh_device_reset,
202 .eh_target_reset_handler = qla4xxx_eh_target_reset,
203 .eh_host_reset_handler = qla4xxx_eh_host_reset,
204 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
206 .slave_configure = qla4xxx_slave_configure,
207 .slave_alloc = qla4xxx_slave_alloc,
208 .change_queue_depth = qla4xxx_change_queue_depth,
212 .use_clustering = ENABLE_CLUSTERING,
213 .sg_tablesize = SG_ALL,
215 .max_sectors = 0xFFFF,
216 .shost_attrs = qla4xxx_host_attrs,
217 .host_reset = qla4xxx_host_reset,
218 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
222 static struct iscsi_transport qla4xxx_iscsi_transport = {
223 .owner = THIS_MODULE,
225 .caps = CAP_TEXT_NEGO |
226 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
227 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
229 .attr_is_visible = qla4_attr_is_visible,
230 .create_session = qla4xxx_session_create,
231 .destroy_session = qla4xxx_session_destroy,
232 .start_conn = qla4xxx_conn_start,
233 .create_conn = qla4xxx_conn_create,
234 .bind_conn = qla4xxx_conn_bind,
235 .stop_conn = iscsi_conn_stop,
236 .destroy_conn = qla4xxx_conn_destroy,
237 .set_param = iscsi_set_param,
238 .get_conn_param = qla4xxx_conn_get_param,
239 .get_session_param = qla4xxx_session_get_param,
240 .get_ep_param = qla4xxx_get_ep_param,
241 .ep_connect = qla4xxx_ep_connect,
242 .ep_poll = qla4xxx_ep_poll,
243 .ep_disconnect = qla4xxx_ep_disconnect,
244 .get_stats = qla4xxx_conn_get_stats,
245 .send_pdu = iscsi_conn_send_pdu,
246 .xmit_task = qla4xxx_task_xmit,
247 .cleanup_task = qla4xxx_task_cleanup,
248 .alloc_pdu = qla4xxx_alloc_pdu,
250 .get_host_param = qla4xxx_host_get_param,
251 .set_iface_param = qla4xxx_iface_set_param,
252 .get_iface_param = qla4xxx_get_iface_param,
253 .bsg_request = qla4xxx_bsg_request,
254 .send_ping = qla4xxx_send_ping,
255 .get_chap = qla4xxx_get_chap_list,
256 .delete_chap = qla4xxx_delete_chap,
257 .set_chap = qla4xxx_set_chap_entry,
258 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
259 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
260 .new_flashnode = qla4xxx_sysfs_ddb_add,
261 .del_flashnode = qla4xxx_sysfs_ddb_delete,
262 .login_flashnode = qla4xxx_sysfs_ddb_login,
263 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
264 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
265 .get_host_stats = qla4xxx_get_host_stats,
268 static struct scsi_transport_template *qla4xxx_scsi_transport;
270 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
271 uint32_t iface_type, uint32_t payload_size,
272 uint32_t pid, struct sockaddr *dst_addr)
274 struct scsi_qla_host *ha = to_qla_host(shost);
275 struct sockaddr_in *addr;
276 struct sockaddr_in6 *addr6;
277 uint32_t options = 0;
278 uint8_t ipaddr[IPv6_ADDR_LEN];
281 memset(ipaddr, 0, IPv6_ADDR_LEN);
283 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
284 (dst_addr->sa_family == AF_INET)) {
285 addr = (struct sockaddr_in *)dst_addr;
286 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
287 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
288 "dest: %pI4\n", __func__,
289 &ha->ip_config.ip_address, ipaddr));
290 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
294 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
295 (dst_addr->sa_family == AF_INET6)) {
297 addr6 = (struct sockaddr_in6 *)dst_addr;
298 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
300 options |= PING_IPV6_PROTOCOL_ENABLE;
302 /* Ping using LinkLocal address */
303 if ((iface_num == 0) || (iface_num == 1)) {
304 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
305 "src: %pI6 dest: %pI6\n", __func__,
306 &ha->ip_config.ipv6_link_local_addr,
308 options |= PING_IPV6_LINKLOCAL_ADDR;
309 rval = qla4xxx_ping_iocb(ha, options, payload_size,
312 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
313 "not supported\n", __func__, iface_num);
319 * If ping using LinkLocal address fails, try ping using
322 if (rval != QLA_SUCCESS) {
323 options &= ~PING_IPV6_LINKLOCAL_ADDR;
324 if (iface_num == 0) {
325 options |= PING_IPV6_ADDR0;
326 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
328 "dest: %pI6\n", __func__,
329 &ha->ip_config.ipv6_addr0,
331 } else if (iface_num == 1) {
332 options |= PING_IPV6_ADDR1;
333 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
335 "dest: %pI6\n", __func__,
336 &ha->ip_config.ipv6_addr1,
339 rval = qla4xxx_ping_iocb(ha, options, payload_size,
350 static umode_t qla4_attr_is_visible(int param_type, int param)
352 switch (param_type) {
353 case ISCSI_HOST_PARAM:
355 case ISCSI_HOST_PARAM_HWADDRESS:
356 case ISCSI_HOST_PARAM_IPADDRESS:
357 case ISCSI_HOST_PARAM_INITIATOR_NAME:
358 case ISCSI_HOST_PARAM_PORT_STATE:
359 case ISCSI_HOST_PARAM_PORT_SPEED:
366 case ISCSI_PARAM_PERSISTENT_ADDRESS:
367 case ISCSI_PARAM_PERSISTENT_PORT:
368 case ISCSI_PARAM_CONN_ADDRESS:
369 case ISCSI_PARAM_CONN_PORT:
370 case ISCSI_PARAM_TARGET_NAME:
371 case ISCSI_PARAM_TPGT:
372 case ISCSI_PARAM_TARGET_ALIAS:
373 case ISCSI_PARAM_MAX_BURST:
374 case ISCSI_PARAM_MAX_R2T:
375 case ISCSI_PARAM_FIRST_BURST:
376 case ISCSI_PARAM_MAX_RECV_DLENGTH:
377 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
378 case ISCSI_PARAM_IFACE_NAME:
379 case ISCSI_PARAM_CHAP_OUT_IDX:
380 case ISCSI_PARAM_CHAP_IN_IDX:
381 case ISCSI_PARAM_USERNAME:
382 case ISCSI_PARAM_PASSWORD:
383 case ISCSI_PARAM_USERNAME_IN:
384 case ISCSI_PARAM_PASSWORD_IN:
385 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
386 case ISCSI_PARAM_DISCOVERY_SESS:
387 case ISCSI_PARAM_PORTAL_TYPE:
388 case ISCSI_PARAM_CHAP_AUTH_EN:
389 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
390 case ISCSI_PARAM_BIDI_CHAP_EN:
391 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
392 case ISCSI_PARAM_DEF_TIME2WAIT:
393 case ISCSI_PARAM_DEF_TIME2RETAIN:
394 case ISCSI_PARAM_HDRDGST_EN:
395 case ISCSI_PARAM_DATADGST_EN:
396 case ISCSI_PARAM_INITIAL_R2T_EN:
397 case ISCSI_PARAM_IMM_DATA_EN:
398 case ISCSI_PARAM_PDU_INORDER_EN:
399 case ISCSI_PARAM_DATASEQ_INORDER_EN:
400 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
401 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
402 case ISCSI_PARAM_TCP_WSF_DISABLE:
403 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
404 case ISCSI_PARAM_TCP_TIMER_SCALE:
405 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
406 case ISCSI_PARAM_TCP_XMIT_WSF:
407 case ISCSI_PARAM_TCP_RECV_WSF:
408 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
409 case ISCSI_PARAM_IPV4_TOS:
410 case ISCSI_PARAM_IPV6_TC:
411 case ISCSI_PARAM_IPV6_FLOW_LABEL:
412 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
413 case ISCSI_PARAM_KEEPALIVE_TMO:
414 case ISCSI_PARAM_LOCAL_PORT:
415 case ISCSI_PARAM_ISID:
416 case ISCSI_PARAM_TSID:
417 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
418 case ISCSI_PARAM_ERL:
419 case ISCSI_PARAM_STATSN:
420 case ISCSI_PARAM_EXP_STATSN:
421 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
422 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
423 case ISCSI_PARAM_LOCAL_IPADDR:
428 case ISCSI_NET_PARAM:
430 case ISCSI_NET_PARAM_IPV4_ADDR:
431 case ISCSI_NET_PARAM_IPV4_SUBNET:
432 case ISCSI_NET_PARAM_IPV4_GW:
433 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
434 case ISCSI_NET_PARAM_IFACE_ENABLE:
435 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
436 case ISCSI_NET_PARAM_IPV6_ADDR:
437 case ISCSI_NET_PARAM_IPV6_ROUTER:
438 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
439 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
440 case ISCSI_NET_PARAM_VLAN_ID:
441 case ISCSI_NET_PARAM_VLAN_PRIORITY:
442 case ISCSI_NET_PARAM_VLAN_ENABLED:
443 case ISCSI_NET_PARAM_MTU:
444 case ISCSI_NET_PARAM_PORT:
445 case ISCSI_NET_PARAM_IPADDR_STATE:
446 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
447 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
448 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
449 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
450 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
451 case ISCSI_NET_PARAM_TCP_WSF:
452 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
453 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
454 case ISCSI_NET_PARAM_CACHE_ID:
455 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
456 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
457 case ISCSI_NET_PARAM_IPV4_TOS_EN:
458 case ISCSI_NET_PARAM_IPV4_TOS:
459 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
460 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
461 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
462 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
463 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
464 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
465 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
466 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
467 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
468 case ISCSI_NET_PARAM_REDIRECT_EN:
469 case ISCSI_NET_PARAM_IPV4_TTL:
470 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
471 case ISCSI_NET_PARAM_IPV6_MLD_EN:
472 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
473 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
474 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
475 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
476 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
477 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
478 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
479 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
484 case ISCSI_IFACE_PARAM:
486 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
487 case ISCSI_IFACE_PARAM_HDRDGST_EN:
488 case ISCSI_IFACE_PARAM_DATADGST_EN:
489 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
490 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
491 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
492 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
493 case ISCSI_IFACE_PARAM_ERL:
494 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
495 case ISCSI_IFACE_PARAM_FIRST_BURST:
496 case ISCSI_IFACE_PARAM_MAX_R2T:
497 case ISCSI_IFACE_PARAM_MAX_BURST:
498 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
499 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
500 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
501 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
502 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
503 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
508 case ISCSI_FLASHNODE_PARAM:
510 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
511 case ISCSI_FLASHNODE_PORTAL_TYPE:
512 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
513 case ISCSI_FLASHNODE_DISCOVERY_SESS:
514 case ISCSI_FLASHNODE_ENTRY_EN:
515 case ISCSI_FLASHNODE_HDR_DGST_EN:
516 case ISCSI_FLASHNODE_DATA_DGST_EN:
517 case ISCSI_FLASHNODE_IMM_DATA_EN:
518 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
519 case ISCSI_FLASHNODE_DATASEQ_INORDER:
520 case ISCSI_FLASHNODE_PDU_INORDER:
521 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
522 case ISCSI_FLASHNODE_SNACK_REQ_EN:
523 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
524 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
525 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
526 case ISCSI_FLASHNODE_ERL:
527 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
528 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
529 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
530 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
531 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
532 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
533 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
534 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
535 case ISCSI_FLASHNODE_FIRST_BURST:
536 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
537 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
538 case ISCSI_FLASHNODE_MAX_R2T:
539 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
540 case ISCSI_FLASHNODE_ISID:
541 case ISCSI_FLASHNODE_TSID:
542 case ISCSI_FLASHNODE_PORT:
543 case ISCSI_FLASHNODE_MAX_BURST:
544 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
545 case ISCSI_FLASHNODE_IPADDR:
546 case ISCSI_FLASHNODE_ALIAS:
547 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
548 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
549 case ISCSI_FLASHNODE_LOCAL_PORT:
550 case ISCSI_FLASHNODE_IPV4_TOS:
551 case ISCSI_FLASHNODE_IPV6_TC:
552 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
553 case ISCSI_FLASHNODE_NAME:
554 case ISCSI_FLASHNODE_TPGT:
555 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
556 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
557 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
558 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
559 case ISCSI_FLASHNODE_TCP_RECV_WSF:
560 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
561 case ISCSI_FLASHNODE_USERNAME:
562 case ISCSI_FLASHNODE_PASSWORD:
563 case ISCSI_FLASHNODE_STATSN:
564 case ISCSI_FLASHNODE_EXP_STATSN:
565 case ISCSI_FLASHNODE_IS_BOOT_TGT:
576 * qla4xxx_create chap_list - Create CHAP list from FLASH
577 * @ha: pointer to adapter structure
579 * Read flash and make a list of CHAP entries, during login when a CHAP entry
580 * is received, it will be checked in this list. If entry exist then the CHAP
581 * entry index is set in the DDB. If CHAP entry does not exist in this list
582 * then a new entry is added in FLASH in CHAP table and the index obtained is
585 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
588 uint8_t *chap_flash_data = NULL;
591 uint32_t chap_size = 0;
594 chap_size = MAX_CHAP_ENTRIES_40XX *
595 sizeof(struct ql4_chap_table);
596 else /* Single region contains CHAP info for both
597 * ports which is divided into half for each port.
599 chap_size = ha->hw.flt_chap_size / 2;
601 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
602 &chap_dma, GFP_KERNEL);
603 if (!chap_flash_data) {
604 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
608 if (is_qla40XX(ha)) {
609 offset = FLASH_CHAP_OFFSET;
611 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
612 if (ha->port_num == 1)
616 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
617 if (rval != QLA_SUCCESS)
620 if (ha->chap_list == NULL)
621 ha->chap_list = vmalloc(chap_size);
622 if (ha->chap_list == NULL) {
623 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
627 memset(ha->chap_list, 0, chap_size);
628 memcpy(ha->chap_list, chap_flash_data, chap_size);
631 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
634 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
636 struct ql4_chap_table **chap_entry)
638 int rval = QLA_ERROR;
639 int max_chap_entries;
641 if (!ha->chap_list) {
642 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
648 max_chap_entries = (ha->hw.flt_chap_size / 2) /
649 sizeof(struct ql4_chap_table);
651 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
653 if (chap_index > max_chap_entries) {
654 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
659 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
660 if ((*chap_entry)->cookie !=
661 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
673 * qla4xxx_find_free_chap_index - Find the first free chap index
674 * @ha: pointer to adapter structure
675 * @chap_index: CHAP index to be returned
677 * Find the first free chap index available in the chap table
679 * Note: Caller should acquire the chap lock before getting here.
681 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
682 uint16_t *chap_index)
686 int max_chap_entries = 0;
687 struct ql4_chap_table *chap_table;
690 max_chap_entries = (ha->hw.flt_chap_size / 2) /
691 sizeof(struct ql4_chap_table);
693 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
695 if (!ha->chap_list) {
696 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
701 for (i = 0; i < max_chap_entries; i++) {
702 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
704 if ((chap_table->cookie !=
705 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
706 (i > MAX_RESRV_CHAP_IDX)) {
712 if (free_index != -1) {
713 *chap_index = free_index;
723 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
724 uint32_t *num_entries, char *buf)
726 struct scsi_qla_host *ha = to_qla_host(shost);
727 struct ql4_chap_table *chap_table;
728 struct iscsi_chap_rec *chap_rec;
729 int max_chap_entries = 0;
730 int valid_chap_entries = 0;
734 max_chap_entries = (ha->hw.flt_chap_size / 2) /
735 sizeof(struct ql4_chap_table);
737 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
739 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
740 __func__, *num_entries, chap_tbl_idx);
744 goto exit_get_chap_list;
747 qla4xxx_create_chap_list(ha);
749 chap_rec = (struct iscsi_chap_rec *) buf;
750 mutex_lock(&ha->chap_sem);
751 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
752 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
753 if (chap_table->cookie !=
754 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
757 chap_rec->chap_tbl_idx = i;
758 strlcpy(chap_rec->username, chap_table->name,
759 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
760 strlcpy(chap_rec->password, chap_table->secret,
761 QL4_CHAP_MAX_SECRET_LEN);
762 chap_rec->password_length = chap_table->secret_len;
764 if (chap_table->flags & BIT_7) /* local */
765 chap_rec->chap_type = CHAP_TYPE_OUT;
767 if (chap_table->flags & BIT_6) /* peer */
768 chap_rec->chap_type = CHAP_TYPE_IN;
772 valid_chap_entries++;
773 if (valid_chap_entries == *num_entries)
778 mutex_unlock(&ha->chap_sem);
781 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
782 __func__, valid_chap_entries);
783 *num_entries = valid_chap_entries;
787 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
790 uint16_t *chap_tbl_idx = (uint16_t *) data;
791 struct iscsi_cls_session *cls_session;
792 struct iscsi_session *sess;
793 struct ddb_entry *ddb_entry;
795 if (!iscsi_is_session_dev(dev))
796 goto exit_is_chap_active;
798 cls_session = iscsi_dev_to_session(dev);
799 sess = cls_session->dd_data;
800 ddb_entry = sess->dd_data;
802 if (iscsi_session_chkready(cls_session))
803 goto exit_is_chap_active;
805 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
812 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
813 uint16_t chap_tbl_idx)
817 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
818 __qla4xxx_is_chap_active);
823 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
825 struct scsi_qla_host *ha = to_qla_host(shost);
826 struct ql4_chap_table *chap_table;
828 int max_chap_entries = 0;
833 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
834 if (chap_table == NULL)
837 memset(chap_table, 0, sizeof(struct ql4_chap_table));
840 max_chap_entries = (ha->hw.flt_chap_size / 2) /
841 sizeof(struct ql4_chap_table);
843 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
845 if (chap_tbl_idx > max_chap_entries) {
847 goto exit_delete_chap;
850 /* Check if chap index is in use.
851 * If chap is in use don't delet chap entry */
852 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
854 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
855 "delete from flash\n", chap_tbl_idx);
857 goto exit_delete_chap;
860 chap_size = sizeof(struct ql4_chap_table);
862 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
864 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
865 /* flt_chap_size is CHAP table size for both ports
866 * so divide it by 2 to calculate the offset for second port
868 if (ha->port_num == 1)
869 offset += (ha->hw.flt_chap_size / 2);
870 offset += (chap_tbl_idx * chap_size);
873 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
874 if (ret != QLA_SUCCESS) {
876 goto exit_delete_chap;
879 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
880 __le16_to_cpu(chap_table->cookie)));
882 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
883 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
884 goto exit_delete_chap;
887 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
889 offset = FLASH_CHAP_OFFSET |
890 (chap_tbl_idx * sizeof(struct ql4_chap_table));
891 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
892 FLASH_OPT_RMW_COMMIT);
893 if (ret == QLA_SUCCESS && ha->chap_list) {
894 mutex_lock(&ha->chap_sem);
895 /* Update ha chap_list cache */
896 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
897 chap_table, sizeof(struct ql4_chap_table));
898 mutex_unlock(&ha->chap_sem);
900 if (ret != QLA_SUCCESS)
904 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
909 * qla4xxx_set_chap_entry - Make chap entry with given information
910 * @shost: pointer to host
911 * @data: chap info - credentials, index and type to make chap entry
912 * @len: length of data
914 * Add or update chap entry with the given information
916 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
918 struct scsi_qla_host *ha = to_qla_host(shost);
919 struct iscsi_chap_rec chap_rec;
920 struct ql4_chap_table *chap_entry = NULL;
921 struct iscsi_param_info *param_info;
923 int max_chap_entries = 0;
929 memset(&chap_rec, 0, sizeof(chap_rec));
931 nla_for_each_attr(attr, data, len, rem) {
932 param_info = nla_data(attr);
934 switch (param_info->param) {
935 case ISCSI_CHAP_PARAM_INDEX:
936 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
938 case ISCSI_CHAP_PARAM_CHAP_TYPE:
939 chap_rec.chap_type = param_info->value[0];
941 case ISCSI_CHAP_PARAM_USERNAME:
942 size = min_t(size_t, sizeof(chap_rec.username),
944 memcpy(chap_rec.username, param_info->value, size);
946 case ISCSI_CHAP_PARAM_PASSWORD:
947 size = min_t(size_t, sizeof(chap_rec.password),
949 memcpy(chap_rec.password, param_info->value, size);
951 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
952 chap_rec.password_length = param_info->value[0];
955 ql4_printk(KERN_ERR, ha,
956 "%s: No such sysfs attribute\n", __func__);
962 if (chap_rec.chap_type == CHAP_TYPE_IN)
968 max_chap_entries = (ha->hw.flt_chap_size / 2) /
969 sizeof(struct ql4_chap_table);
971 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
973 mutex_lock(&ha->chap_sem);
974 if (chap_rec.chap_tbl_idx < max_chap_entries) {
975 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
978 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
979 ql4_printk(KERN_INFO, ha,
980 "Type mismatch for CHAP entry %d\n",
981 chap_rec.chap_tbl_idx);
983 goto exit_unlock_chap;
986 /* If chap index is in use then don't modify it */
987 rc = qla4xxx_is_chap_active(shost,
988 chap_rec.chap_tbl_idx);
990 ql4_printk(KERN_INFO, ha,
991 "CHAP entry %d is in use\n",
992 chap_rec.chap_tbl_idx);
994 goto exit_unlock_chap;
998 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1000 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1002 goto exit_unlock_chap;
1006 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1007 chap_rec.chap_tbl_idx, type);
1010 mutex_unlock(&ha->chap_sem);
1017 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1019 struct scsi_qla_host *ha = to_qla_host(shost);
1020 struct iscsi_offload_host_stats *host_stats = NULL;
1021 int host_stats_size;
1024 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1026 dma_addr_t iscsi_stats_dma;
1028 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1030 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1032 if (host_stats_size != len) {
1033 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1034 __func__, len, host_stats_size);
1036 goto exit_host_stats;
1038 host_stats = (struct iscsi_offload_host_stats *)buf;
1042 goto exit_host_stats;
1045 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1047 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1048 &iscsi_stats_dma, GFP_KERNEL);
1049 if (!ql_iscsi_stats) {
1050 ql4_printk(KERN_ERR, ha,
1051 "Unable to allocate memory for iscsi stats\n");
1053 goto exit_host_stats;
1056 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1058 if (ret != QLA_SUCCESS) {
1059 ql4_printk(KERN_ERR, ha,
1060 "Unable to retrieve iscsi stats\n");
1062 goto exit_host_stats;
1064 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1065 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1066 host_stats->mactx_multicast_frames =
1067 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1068 host_stats->mactx_broadcast_frames =
1069 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1070 host_stats->mactx_pause_frames =
1071 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1072 host_stats->mactx_control_frames =
1073 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1074 host_stats->mactx_deferral =
1075 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1076 host_stats->mactx_excess_deferral =
1077 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1078 host_stats->mactx_late_collision =
1079 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1080 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1081 host_stats->mactx_single_collision =
1082 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1083 host_stats->mactx_multiple_collision =
1084 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1085 host_stats->mactx_collision =
1086 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1087 host_stats->mactx_frames_dropped =
1088 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1089 host_stats->mactx_jumbo_frames =
1090 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1091 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1092 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1093 host_stats->macrx_unknown_control_frames =
1094 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1095 host_stats->macrx_pause_frames =
1096 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1097 host_stats->macrx_control_frames =
1098 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1099 host_stats->macrx_dribble =
1100 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1101 host_stats->macrx_frame_length_error =
1102 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1103 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1104 host_stats->macrx_carrier_sense_error =
1105 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1106 host_stats->macrx_frame_discarded =
1107 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1108 host_stats->macrx_frames_dropped =
1109 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1110 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1111 host_stats->mac_encoding_error =
1112 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1113 host_stats->macrx_length_error_large =
1114 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1115 host_stats->macrx_length_error_small =
1116 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1117 host_stats->macrx_multicast_frames =
1118 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1119 host_stats->macrx_broadcast_frames =
1120 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1121 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1122 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1123 host_stats->iptx_fragments =
1124 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1125 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1126 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1127 host_stats->iprx_fragments =
1128 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1129 host_stats->ip_datagram_reassembly =
1130 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1131 host_stats->ip_invalid_address_error =
1132 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1133 host_stats->ip_error_packets =
1134 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1135 host_stats->ip_fragrx_overlap =
1136 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1137 host_stats->ip_fragrx_outoforder =
1138 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1139 host_stats->ip_datagram_reassembly_timeout =
1140 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1141 host_stats->ipv6tx_packets =
1142 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1143 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1144 host_stats->ipv6tx_fragments =
1145 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1146 host_stats->ipv6rx_packets =
1147 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1148 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1149 host_stats->ipv6rx_fragments =
1150 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1151 host_stats->ipv6_datagram_reassembly =
1152 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1153 host_stats->ipv6_invalid_address_error =
1154 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1155 host_stats->ipv6_error_packets =
1156 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1157 host_stats->ipv6_fragrx_overlap =
1158 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1159 host_stats->ipv6_fragrx_outoforder =
1160 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1161 host_stats->ipv6_datagram_reassembly_timeout =
1162 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1163 host_stats->tcptx_segments =
1164 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1165 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1166 host_stats->tcprx_segments =
1167 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1168 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1169 host_stats->tcp_duplicate_ack_retx =
1170 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1171 host_stats->tcp_retx_timer_expired =
1172 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1173 host_stats->tcprx_duplicate_ack =
1174 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1175 host_stats->tcprx_pure_ackr =
1176 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1177 host_stats->tcptx_delayed_ack =
1178 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1179 host_stats->tcptx_pure_ack =
1180 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1181 host_stats->tcprx_segment_error =
1182 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1183 host_stats->tcprx_segment_outoforder =
1184 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1185 host_stats->tcprx_window_probe =
1186 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1187 host_stats->tcprx_window_update =
1188 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1189 host_stats->tcptx_window_probe_persist =
1190 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1191 host_stats->ecc_error_correction =
1192 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1193 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1194 host_stats->iscsi_data_bytes_tx =
1195 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1196 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1197 host_stats->iscsi_data_bytes_rx =
1198 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1199 host_stats->iscsi_io_completed =
1200 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1201 host_stats->iscsi_unexpected_io_rx =
1202 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1203 host_stats->iscsi_format_error =
1204 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1205 host_stats->iscsi_hdr_digest_error =
1206 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1207 host_stats->iscsi_data_digest_error =
1208 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1209 host_stats->iscsi_sequence_error =
1210 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1213 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1214 ql_iscsi_stats, iscsi_stats_dma);
1216 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1221 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1222 enum iscsi_param_type param_type,
1223 int param, char *buf)
1225 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1226 struct scsi_qla_host *ha = to_qla_host(shost);
1231 if (param_type == ISCSI_NET_PARAM) {
1233 case ISCSI_NET_PARAM_IPV4_ADDR:
1234 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1236 case ISCSI_NET_PARAM_IPV4_SUBNET:
1237 len = sprintf(buf, "%pI4\n",
1238 &ha->ip_config.subnet_mask);
1240 case ISCSI_NET_PARAM_IPV4_GW:
1241 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1243 case ISCSI_NET_PARAM_IFACE_ENABLE:
1244 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1245 OP_STATE(ha->ip_config.ipv4_options,
1246 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1248 OP_STATE(ha->ip_config.ipv6_options,
1249 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1252 len = sprintf(buf, "%s\n", pval);
1254 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1255 len = sprintf(buf, "%s\n",
1256 (ha->ip_config.tcp_options &
1257 TCPOPT_DHCP_ENABLE) ?
1260 case ISCSI_NET_PARAM_IPV6_ADDR:
1261 if (iface->iface_num == 0)
1262 len = sprintf(buf, "%pI6\n",
1263 &ha->ip_config.ipv6_addr0);
1264 if (iface->iface_num == 1)
1265 len = sprintf(buf, "%pI6\n",
1266 &ha->ip_config.ipv6_addr1);
1268 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1269 len = sprintf(buf, "%pI6\n",
1270 &ha->ip_config.ipv6_link_local_addr);
1272 case ISCSI_NET_PARAM_IPV6_ROUTER:
1273 len = sprintf(buf, "%pI6\n",
1274 &ha->ip_config.ipv6_default_router_addr);
1276 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1277 pval = (ha->ip_config.ipv6_addl_options &
1278 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1281 len = sprintf(buf, "%s\n", pval);
1283 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1284 pval = (ha->ip_config.ipv6_addl_options &
1285 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1288 len = sprintf(buf, "%s\n", pval);
1290 case ISCSI_NET_PARAM_VLAN_ID:
1291 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1292 ival = ha->ip_config.ipv4_vlan_tag &
1295 ival = ha->ip_config.ipv6_vlan_tag &
1298 len = sprintf(buf, "%d\n", ival);
1300 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1301 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1302 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1303 ISCSI_MAX_VLAN_PRIORITY;
1305 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1306 ISCSI_MAX_VLAN_PRIORITY;
1308 len = sprintf(buf, "%d\n", ival);
1310 case ISCSI_NET_PARAM_VLAN_ENABLED:
1311 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1312 OP_STATE(ha->ip_config.ipv4_options,
1313 IPOPT_VLAN_TAGGING_ENABLE, pval);
1315 OP_STATE(ha->ip_config.ipv6_options,
1316 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1318 len = sprintf(buf, "%s\n", pval);
1320 case ISCSI_NET_PARAM_MTU:
1321 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1323 case ISCSI_NET_PARAM_PORT:
1324 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1325 len = sprintf(buf, "%d\n",
1326 ha->ip_config.ipv4_port);
1328 len = sprintf(buf, "%d\n",
1329 ha->ip_config.ipv6_port);
1331 case ISCSI_NET_PARAM_IPADDR_STATE:
1332 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1333 pval = iscsi_get_ipaddress_state_name(
1334 ha->ip_config.ipv4_addr_state);
1336 if (iface->iface_num == 0)
1337 pval = iscsi_get_ipaddress_state_name(
1338 ha->ip_config.ipv6_addr0_state);
1339 else if (iface->iface_num == 1)
1340 pval = iscsi_get_ipaddress_state_name(
1341 ha->ip_config.ipv6_addr1_state);
1344 len = sprintf(buf, "%s\n", pval);
1346 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1347 pval = iscsi_get_ipaddress_state_name(
1348 ha->ip_config.ipv6_link_local_state);
1349 len = sprintf(buf, "%s\n", pval);
1351 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1352 pval = iscsi_get_router_state_name(
1353 ha->ip_config.ipv6_default_router_state);
1354 len = sprintf(buf, "%s\n", pval);
1356 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1357 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1358 OP_STATE(~ha->ip_config.tcp_options,
1359 TCPOPT_DELAYED_ACK_DISABLE, pval);
1361 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1362 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1364 len = sprintf(buf, "%s\n", pval);
1366 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1367 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1368 OP_STATE(~ha->ip_config.tcp_options,
1369 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1371 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1372 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1374 len = sprintf(buf, "%s\n", pval);
1376 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1377 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1378 OP_STATE(~ha->ip_config.tcp_options,
1379 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1381 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1382 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1385 len = sprintf(buf, "%s\n", pval);
1387 case ISCSI_NET_PARAM_TCP_WSF:
1388 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1389 len = sprintf(buf, "%d\n",
1390 ha->ip_config.tcp_wsf);
1392 len = sprintf(buf, "%d\n",
1393 ha->ip_config.ipv6_tcp_wsf);
1395 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1396 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1397 ival = (ha->ip_config.tcp_options &
1398 TCPOPT_TIMER_SCALE) >> 1;
1400 ival = (ha->ip_config.ipv6_tcp_options &
1401 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1403 len = sprintf(buf, "%d\n", ival);
1405 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1406 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1407 OP_STATE(ha->ip_config.tcp_options,
1408 TCPOPT_TIMESTAMP_ENABLE, pval);
1410 OP_STATE(ha->ip_config.ipv6_tcp_options,
1411 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1413 len = sprintf(buf, "%s\n", pval);
1415 case ISCSI_NET_PARAM_CACHE_ID:
1416 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1417 len = sprintf(buf, "%d\n",
1418 ha->ip_config.ipv4_cache_id);
1420 len = sprintf(buf, "%d\n",
1421 ha->ip_config.ipv6_cache_id);
1423 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1424 OP_STATE(ha->ip_config.tcp_options,
1425 TCPOPT_DNS_SERVER_IP_EN, pval);
1427 len = sprintf(buf, "%s\n", pval);
1429 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1430 OP_STATE(ha->ip_config.tcp_options,
1431 TCPOPT_SLP_DA_INFO_EN, pval);
1433 len = sprintf(buf, "%s\n", pval);
1435 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1436 OP_STATE(ha->ip_config.ipv4_options,
1437 IPOPT_IPV4_TOS_EN, pval);
1439 len = sprintf(buf, "%s\n", pval);
1441 case ISCSI_NET_PARAM_IPV4_TOS:
1442 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1444 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1445 OP_STATE(ha->ip_config.ipv4_options,
1446 IPOPT_GRAT_ARP_EN, pval);
1448 len = sprintf(buf, "%s\n", pval);
1450 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1451 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1454 len = sprintf(buf, "%s\n", pval);
1456 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1457 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1458 (char *)ha->ip_config.ipv4_alt_cid : "";
1460 len = sprintf(buf, "%s\n", pval);
1462 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1463 OP_STATE(ha->ip_config.ipv4_options,
1464 IPOPT_REQ_VID_EN, pval);
1466 len = sprintf(buf, "%s\n", pval);
1468 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1469 OP_STATE(ha->ip_config.ipv4_options,
1470 IPOPT_USE_VID_EN, pval);
1472 len = sprintf(buf, "%s\n", pval);
1474 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1475 pval = (ha->ip_config.ipv4_vid_len) ?
1476 (char *)ha->ip_config.ipv4_vid : "";
1478 len = sprintf(buf, "%s\n", pval);
1480 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1481 OP_STATE(ha->ip_config.ipv4_options,
1482 IPOPT_LEARN_IQN_EN, pval);
1484 len = sprintf(buf, "%s\n", pval);
1486 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1487 OP_STATE(~ha->ip_config.ipv4_options,
1488 IPOPT_FRAGMENTATION_DISABLE, pval);
1490 len = sprintf(buf, "%s\n", pval);
1492 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1493 OP_STATE(ha->ip_config.ipv4_options,
1494 IPOPT_IN_FORWARD_EN, pval);
1496 len = sprintf(buf, "%s\n", pval);
1498 case ISCSI_NET_PARAM_REDIRECT_EN:
1499 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1500 OP_STATE(ha->ip_config.ipv4_options,
1501 IPOPT_ARP_REDIRECT_EN, pval);
1503 OP_STATE(ha->ip_config.ipv6_options,
1504 IPV6_OPT_REDIRECT_EN, pval);
1506 len = sprintf(buf, "%s\n", pval);
1508 case ISCSI_NET_PARAM_IPV4_TTL:
1509 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1511 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1512 OP_STATE(ha->ip_config.ipv6_options,
1513 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1515 len = sprintf(buf, "%s\n", pval);
1517 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1518 OP_STATE(ha->ip_config.ipv6_addl_options,
1519 IPV6_ADDOPT_MLD_EN, pval);
1521 len = sprintf(buf, "%s\n", pval);
1523 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1524 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1526 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1527 len = sprintf(buf, "%d\n",
1528 ha->ip_config.ipv6_traffic_class);
1530 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1531 len = sprintf(buf, "%d\n",
1532 ha->ip_config.ipv6_hop_limit);
1534 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1535 len = sprintf(buf, "%d\n",
1536 ha->ip_config.ipv6_nd_reach_time);
1538 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1539 len = sprintf(buf, "%d\n",
1540 ha->ip_config.ipv6_nd_rexmit_timer);
1542 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1543 len = sprintf(buf, "%d\n",
1544 ha->ip_config.ipv6_nd_stale_timeout);
1546 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1547 len = sprintf(buf, "%d\n",
1548 ha->ip_config.ipv6_dup_addr_detect_count);
1550 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1551 len = sprintf(buf, "%d\n",
1552 ha->ip_config.ipv6_gw_advrt_mtu);
1557 } else if (param_type == ISCSI_IFACE_PARAM) {
1559 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1560 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1562 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1563 OP_STATE(ha->ip_config.iscsi_options,
1564 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1566 len = sprintf(buf, "%s\n", pval);
1568 case ISCSI_IFACE_PARAM_DATADGST_EN:
1569 OP_STATE(ha->ip_config.iscsi_options,
1570 ISCSIOPTS_DATA_DIGEST_EN, pval);
1572 len = sprintf(buf, "%s\n", pval);
1574 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1575 OP_STATE(ha->ip_config.iscsi_options,
1576 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1578 len = sprintf(buf, "%s\n", pval);
1580 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1581 OP_STATE(ha->ip_config.iscsi_options,
1582 ISCSIOPTS_INITIAL_R2T_EN, pval);
1584 len = sprintf(buf, "%s\n", pval);
1586 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1587 OP_STATE(ha->ip_config.iscsi_options,
1588 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1590 len = sprintf(buf, "%s\n", pval);
1592 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1593 OP_STATE(ha->ip_config.iscsi_options,
1594 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1596 len = sprintf(buf, "%s\n", pval);
1598 case ISCSI_IFACE_PARAM_ERL:
1599 len = sprintf(buf, "%d\n",
1600 (ha->ip_config.iscsi_options &
1603 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1604 len = sprintf(buf, "%u\n",
1605 ha->ip_config.iscsi_max_pdu_size *
1608 case ISCSI_IFACE_PARAM_FIRST_BURST:
1609 len = sprintf(buf, "%u\n",
1610 ha->ip_config.iscsi_first_burst_len *
1613 case ISCSI_IFACE_PARAM_MAX_R2T:
1614 len = sprintf(buf, "%d\n",
1615 ha->ip_config.iscsi_max_outstnd_r2t);
1617 case ISCSI_IFACE_PARAM_MAX_BURST:
1618 len = sprintf(buf, "%u\n",
1619 ha->ip_config.iscsi_max_burst_len *
1622 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1623 OP_STATE(ha->ip_config.iscsi_options,
1624 ISCSIOPTS_CHAP_AUTH_EN, pval);
1626 len = sprintf(buf, "%s\n", pval);
1628 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1629 OP_STATE(ha->ip_config.iscsi_options,
1630 ISCSIOPTS_BIDI_CHAP_EN, pval);
1632 len = sprintf(buf, "%s\n", pval);
1634 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1635 OP_STATE(ha->ip_config.iscsi_options,
1636 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1638 len = sprintf(buf, "%s\n", pval);
1640 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1641 OP_STATE(ha->ip_config.iscsi_options,
1642 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1644 len = sprintf(buf, "%s\n", pval);
1646 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1647 OP_STATE(ha->ip_config.iscsi_options,
1648 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1650 len = sprintf(buf, "%s\n", pval);
1652 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1653 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1663 static struct iscsi_endpoint *
1664 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1668 struct iscsi_endpoint *ep;
1669 struct qla_endpoint *qla_ep;
1670 struct scsi_qla_host *ha;
1671 struct sockaddr_in *addr;
1672 struct sockaddr_in6 *addr6;
1676 pr_err("%s: shost is NULL\n", __func__);
1677 return ERR_PTR(ret);
1680 ha = iscsi_host_priv(shost);
1681 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1684 return ERR_PTR(ret);
1687 qla_ep = ep->dd_data;
1688 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1689 if (dst_addr->sa_family == AF_INET) {
1690 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1691 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1692 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1693 (char *)&addr->sin_addr));
1694 } else if (dst_addr->sa_family == AF_INET6) {
1695 memcpy(&qla_ep->dst_addr, dst_addr,
1696 sizeof(struct sockaddr_in6));
1697 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1698 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1699 (char *)&addr6->sin6_addr));
1701 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1705 qla_ep->host = shost;
1710 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1712 struct qla_endpoint *qla_ep;
1713 struct scsi_qla_host *ha;
1716 qla_ep = ep->dd_data;
1717 ha = to_qla_host(qla_ep->host);
1718 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1720 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1726 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1728 struct qla_endpoint *qla_ep;
1729 struct scsi_qla_host *ha;
1731 qla_ep = ep->dd_data;
1732 ha = to_qla_host(qla_ep->host);
1733 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1735 iscsi_destroy_endpoint(ep);
1738 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1739 enum iscsi_param param,
1742 struct qla_endpoint *qla_ep = ep->dd_data;
1743 struct sockaddr *dst_addr;
1744 struct scsi_qla_host *ha;
1749 ha = to_qla_host(qla_ep->host);
1750 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1754 case ISCSI_PARAM_CONN_PORT:
1755 case ISCSI_PARAM_CONN_ADDRESS:
1756 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1760 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1761 &qla_ep->dst_addr, param, buf);
1767 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1768 struct iscsi_stats *stats)
1770 struct iscsi_session *sess;
1771 struct iscsi_cls_session *cls_sess;
1772 struct ddb_entry *ddb_entry;
1773 struct scsi_qla_host *ha;
1774 struct ql_iscsi_stats *ql_iscsi_stats;
1777 dma_addr_t iscsi_stats_dma;
1779 cls_sess = iscsi_conn_to_session(cls_conn);
1780 sess = cls_sess->dd_data;
1781 ddb_entry = sess->dd_data;
1784 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1786 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1787 /* Allocate memory */
1788 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1789 &iscsi_stats_dma, GFP_KERNEL);
1790 if (!ql_iscsi_stats) {
1791 ql4_printk(KERN_ERR, ha,
1792 "Unable to allocate memory for iscsi stats\n");
1793 goto exit_get_stats;
1796 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1798 if (ret != QLA_SUCCESS) {
1799 ql4_printk(KERN_ERR, ha,
1800 "Unable to retrieve iscsi stats\n");
1805 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1806 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1808 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1809 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1810 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1811 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1812 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1813 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1814 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1815 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1817 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1818 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1819 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1820 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1821 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1822 stats->logoutrsp_pdus =
1823 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1824 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1825 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1826 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1829 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1835 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1837 struct iscsi_cls_session *session;
1838 struct iscsi_session *sess;
1839 unsigned long flags;
1840 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
1842 session = starget_to_session(scsi_target(sc->device));
1843 sess = session->dd_data;
1845 spin_lock_irqsave(&session->lock, flags);
1846 if (session->state == ISCSI_SESSION_FAILED)
1847 ret = BLK_EH_RESET_TIMER;
1848 spin_unlock_irqrestore(&session->lock, flags);
1853 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1855 struct scsi_qla_host *ha = to_qla_host(shost);
1856 struct iscsi_cls_host *ihost = shost->shost_data;
1857 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1859 qla4xxx_get_firmware_state(ha);
1861 switch (ha->addl_fw_state & 0x0F00) {
1862 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1863 speed = ISCSI_PORT_SPEED_10MBPS;
1865 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1866 speed = ISCSI_PORT_SPEED_100MBPS;
1868 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1869 speed = ISCSI_PORT_SPEED_1GBPS;
1871 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1872 speed = ISCSI_PORT_SPEED_10GBPS;
1875 ihost->port_speed = speed;
1878 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1880 struct scsi_qla_host *ha = to_qla_host(shost);
1881 struct iscsi_cls_host *ihost = shost->shost_data;
1882 uint32_t state = ISCSI_PORT_STATE_DOWN;
1884 if (test_bit(AF_LINK_UP, &ha->flags))
1885 state = ISCSI_PORT_STATE_UP;
1887 ihost->port_state = state;
1890 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1891 enum iscsi_host_param param, char *buf)
1893 struct scsi_qla_host *ha = to_qla_host(shost);
1897 case ISCSI_HOST_PARAM_HWADDRESS:
1898 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1900 case ISCSI_HOST_PARAM_IPADDRESS:
1901 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1903 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1904 len = sprintf(buf, "%s\n", ha->name_string);
1906 case ISCSI_HOST_PARAM_PORT_STATE:
1907 qla4xxx_set_port_state(shost);
1908 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1910 case ISCSI_HOST_PARAM_PORT_SPEED:
1911 qla4xxx_set_port_speed(shost);
1912 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1921 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1927 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1928 &qla4xxx_iscsi_transport,
1929 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1930 if (!ha->iface_ipv4)
1931 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1935 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1937 if (!ha->iface_ipv6_0)
1939 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1940 &qla4xxx_iscsi_transport,
1941 ISCSI_IFACE_TYPE_IPV6, 0,
1943 if (!ha->iface_ipv6_0)
1944 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1947 if (!ha->iface_ipv6_1)
1949 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1950 &qla4xxx_iscsi_transport,
1951 ISCSI_IFACE_TYPE_IPV6, 1,
1953 if (!ha->iface_ipv6_1)
1954 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1958 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1960 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1961 qla4xxx_create_ipv4_iface(ha);
1963 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1964 qla4xxx_create_ipv6_iface(ha);
1967 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1969 if (ha->iface_ipv4) {
1970 iscsi_destroy_iface(ha->iface_ipv4);
1971 ha->iface_ipv4 = NULL;
1975 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1977 if (ha->iface_ipv6_0) {
1978 iscsi_destroy_iface(ha->iface_ipv6_0);
1979 ha->iface_ipv6_0 = NULL;
1981 if (ha->iface_ipv6_1) {
1982 iscsi_destroy_iface(ha->iface_ipv6_1);
1983 ha->iface_ipv6_1 = NULL;
1987 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1989 qla4xxx_destroy_ipv4_iface(ha);
1990 qla4xxx_destroy_ipv6_iface(ha);
1993 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1994 struct iscsi_iface_param_info *iface_param,
1995 struct addr_ctrl_blk *init_fw_cb)
1998 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1999 * iface_num 1 is valid only for IPv6 Addr.
2001 switch (iface_param->param) {
2002 case ISCSI_NET_PARAM_IPV6_ADDR:
2003 if (iface_param->iface_num & 0x1)
2005 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2006 sizeof(init_fw_cb->ipv6_addr1));
2009 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2010 sizeof(init_fw_cb->ipv6_addr0));
2012 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2013 if (iface_param->iface_num & 0x1)
2015 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2016 sizeof(init_fw_cb->ipv6_if_id));
2018 case ISCSI_NET_PARAM_IPV6_ROUTER:
2019 if (iface_param->iface_num & 0x1)
2021 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2022 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2024 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2025 /* Autocfg applies to even interface */
2026 if (iface_param->iface_num & 0x1)
2029 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2030 init_fw_cb->ipv6_addtl_opts &=
2032 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2033 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2034 init_fw_cb->ipv6_addtl_opts |=
2036 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2038 ql4_printk(KERN_ERR, ha,
2039 "Invalid autocfg setting for IPv6 addr\n");
2041 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2042 /* Autocfg applies to even interface */
2043 if (iface_param->iface_num & 0x1)
2046 if (iface_param->value[0] ==
2047 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2048 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2049 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2050 else if (iface_param->value[0] ==
2051 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2052 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2053 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2055 ql4_printk(KERN_ERR, ha,
2056 "Invalid autocfg setting for IPv6 linklocal addr\n");
2058 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2059 /* Autocfg applies to even interface */
2060 if (iface_param->iface_num & 0x1)
2063 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2064 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2065 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2067 case ISCSI_NET_PARAM_IFACE_ENABLE:
2068 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2069 init_fw_cb->ipv6_opts |=
2070 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2071 qla4xxx_create_ipv6_iface(ha);
2073 init_fw_cb->ipv6_opts &=
2074 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2076 qla4xxx_destroy_ipv6_iface(ha);
2079 case ISCSI_NET_PARAM_VLAN_TAG:
2080 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2082 init_fw_cb->ipv6_vlan_tag =
2083 cpu_to_be16(*(uint16_t *)iface_param->value);
2085 case ISCSI_NET_PARAM_VLAN_ENABLED:
2086 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2087 init_fw_cb->ipv6_opts |=
2088 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2090 init_fw_cb->ipv6_opts &=
2091 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2093 case ISCSI_NET_PARAM_MTU:
2094 init_fw_cb->eth_mtu_size =
2095 cpu_to_le16(*(uint16_t *)iface_param->value);
2097 case ISCSI_NET_PARAM_PORT:
2098 /* Autocfg applies to even interface */
2099 if (iface_param->iface_num & 0x1)
2102 init_fw_cb->ipv6_port =
2103 cpu_to_le16(*(uint16_t *)iface_param->value);
2105 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2106 if (iface_param->iface_num & 0x1)
2108 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2109 init_fw_cb->ipv6_tcp_opts |=
2110 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2112 init_fw_cb->ipv6_tcp_opts &=
2113 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2116 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2117 if (iface_param->iface_num & 0x1)
2119 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2120 init_fw_cb->ipv6_tcp_opts |=
2121 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2123 init_fw_cb->ipv6_tcp_opts &=
2124 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2126 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2127 if (iface_param->iface_num & 0x1)
2129 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2130 init_fw_cb->ipv6_tcp_opts |=
2131 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2133 init_fw_cb->ipv6_tcp_opts &=
2134 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2136 case ISCSI_NET_PARAM_TCP_WSF:
2137 if (iface_param->iface_num & 0x1)
2139 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2141 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2142 if (iface_param->iface_num & 0x1)
2144 init_fw_cb->ipv6_tcp_opts &=
2145 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2146 init_fw_cb->ipv6_tcp_opts |=
2147 cpu_to_le16((iface_param->value[0] << 1) &
2148 IPV6_TCPOPT_TIMER_SCALE);
2150 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2151 if (iface_param->iface_num & 0x1)
2153 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2154 init_fw_cb->ipv6_tcp_opts |=
2155 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2157 init_fw_cb->ipv6_tcp_opts &=
2158 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2160 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2161 if (iface_param->iface_num & 0x1)
2163 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2164 init_fw_cb->ipv6_opts |=
2165 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2167 init_fw_cb->ipv6_opts &=
2168 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2170 case ISCSI_NET_PARAM_REDIRECT_EN:
2171 if (iface_param->iface_num & 0x1)
2173 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2174 init_fw_cb->ipv6_opts |=
2175 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2177 init_fw_cb->ipv6_opts &=
2178 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2180 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2181 if (iface_param->iface_num & 0x1)
2183 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2184 init_fw_cb->ipv6_addtl_opts |=
2185 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2187 init_fw_cb->ipv6_addtl_opts &=
2188 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2190 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2191 if (iface_param->iface_num & 0x1)
2193 init_fw_cb->ipv6_flow_lbl =
2194 cpu_to_le16(*(uint16_t *)iface_param->value);
2196 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2197 if (iface_param->iface_num & 0x1)
2199 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2201 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2202 if (iface_param->iface_num & 0x1)
2204 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2206 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2207 if (iface_param->iface_num & 0x1)
2209 init_fw_cb->ipv6_nd_reach_time =
2210 cpu_to_le32(*(uint32_t *)iface_param->value);
2212 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2213 if (iface_param->iface_num & 0x1)
2215 init_fw_cb->ipv6_nd_rexmit_timer =
2216 cpu_to_le32(*(uint32_t *)iface_param->value);
2218 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2219 if (iface_param->iface_num & 0x1)
2221 init_fw_cb->ipv6_nd_stale_timeout =
2222 cpu_to_le32(*(uint32_t *)iface_param->value);
2224 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2225 if (iface_param->iface_num & 0x1)
2227 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2229 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2230 if (iface_param->iface_num & 0x1)
2232 init_fw_cb->ipv6_gw_advrt_mtu =
2233 cpu_to_le32(*(uint32_t *)iface_param->value);
2236 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2237 iface_param->param);
2242 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2243 struct iscsi_iface_param_info *iface_param,
2244 struct addr_ctrl_blk *init_fw_cb)
2246 switch (iface_param->param) {
2247 case ISCSI_NET_PARAM_IPV4_ADDR:
2248 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2249 sizeof(init_fw_cb->ipv4_addr));
2251 case ISCSI_NET_PARAM_IPV4_SUBNET:
2252 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2253 sizeof(init_fw_cb->ipv4_subnet));
2255 case ISCSI_NET_PARAM_IPV4_GW:
2256 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2257 sizeof(init_fw_cb->ipv4_gw_addr));
2259 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2260 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2261 init_fw_cb->ipv4_tcp_opts |=
2262 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2263 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2264 init_fw_cb->ipv4_tcp_opts &=
2265 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2267 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2269 case ISCSI_NET_PARAM_IFACE_ENABLE:
2270 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2271 init_fw_cb->ipv4_ip_opts |=
2272 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2273 qla4xxx_create_ipv4_iface(ha);
2275 init_fw_cb->ipv4_ip_opts &=
2276 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2278 qla4xxx_destroy_ipv4_iface(ha);
2281 case ISCSI_NET_PARAM_VLAN_TAG:
2282 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2284 init_fw_cb->ipv4_vlan_tag =
2285 cpu_to_be16(*(uint16_t *)iface_param->value);
2287 case ISCSI_NET_PARAM_VLAN_ENABLED:
2288 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2289 init_fw_cb->ipv4_ip_opts |=
2290 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2292 init_fw_cb->ipv4_ip_opts &=
2293 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2295 case ISCSI_NET_PARAM_MTU:
2296 init_fw_cb->eth_mtu_size =
2297 cpu_to_le16(*(uint16_t *)iface_param->value);
2299 case ISCSI_NET_PARAM_PORT:
2300 init_fw_cb->ipv4_port =
2301 cpu_to_le16(*(uint16_t *)iface_param->value);
2303 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2304 if (iface_param->iface_num & 0x1)
2306 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2307 init_fw_cb->ipv4_tcp_opts |=
2308 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2310 init_fw_cb->ipv4_tcp_opts &=
2311 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2314 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2315 if (iface_param->iface_num & 0x1)
2317 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2318 init_fw_cb->ipv4_tcp_opts |=
2319 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2321 init_fw_cb->ipv4_tcp_opts &=
2322 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2324 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2325 if (iface_param->iface_num & 0x1)
2327 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2328 init_fw_cb->ipv4_tcp_opts |=
2329 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2331 init_fw_cb->ipv4_tcp_opts &=
2332 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2334 case ISCSI_NET_PARAM_TCP_WSF:
2335 if (iface_param->iface_num & 0x1)
2337 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2339 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2340 if (iface_param->iface_num & 0x1)
2342 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2343 init_fw_cb->ipv4_tcp_opts |=
2344 cpu_to_le16((iface_param->value[0] << 1) &
2345 TCPOPT_TIMER_SCALE);
2347 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2348 if (iface_param->iface_num & 0x1)
2350 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2351 init_fw_cb->ipv4_tcp_opts |=
2352 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2354 init_fw_cb->ipv4_tcp_opts &=
2355 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2357 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2358 if (iface_param->iface_num & 0x1)
2360 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2361 init_fw_cb->ipv4_tcp_opts |=
2362 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2364 init_fw_cb->ipv4_tcp_opts &=
2365 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2367 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2368 if (iface_param->iface_num & 0x1)
2370 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2371 init_fw_cb->ipv4_tcp_opts |=
2372 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2374 init_fw_cb->ipv4_tcp_opts &=
2375 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2377 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2378 if (iface_param->iface_num & 0x1)
2380 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2381 init_fw_cb->ipv4_ip_opts |=
2382 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2384 init_fw_cb->ipv4_ip_opts &=
2385 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2387 case ISCSI_NET_PARAM_IPV4_TOS:
2388 if (iface_param->iface_num & 0x1)
2390 init_fw_cb->ipv4_tos = iface_param->value[0];
2392 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2393 if (iface_param->iface_num & 0x1)
2395 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2396 init_fw_cb->ipv4_ip_opts |=
2397 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2399 init_fw_cb->ipv4_ip_opts &=
2400 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2402 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2403 if (iface_param->iface_num & 0x1)
2405 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2406 init_fw_cb->ipv4_ip_opts |=
2407 cpu_to_le16(IPOPT_ALT_CID_EN);
2409 init_fw_cb->ipv4_ip_opts &=
2410 cpu_to_le16(~IPOPT_ALT_CID_EN);
2412 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2413 if (iface_param->iface_num & 0x1)
2415 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2416 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2417 init_fw_cb->ipv4_dhcp_alt_cid_len =
2418 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2420 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2421 if (iface_param->iface_num & 0x1)
2423 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2424 init_fw_cb->ipv4_ip_opts |=
2425 cpu_to_le16(IPOPT_REQ_VID_EN);
2427 init_fw_cb->ipv4_ip_opts &=
2428 cpu_to_le16(~IPOPT_REQ_VID_EN);
2430 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2431 if (iface_param->iface_num & 0x1)
2433 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2434 init_fw_cb->ipv4_ip_opts |=
2435 cpu_to_le16(IPOPT_USE_VID_EN);
2437 init_fw_cb->ipv4_ip_opts &=
2438 cpu_to_le16(~IPOPT_USE_VID_EN);
2440 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2441 if (iface_param->iface_num & 0x1)
2443 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2444 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2445 init_fw_cb->ipv4_dhcp_vid_len =
2446 strlen(init_fw_cb->ipv4_dhcp_vid);
2448 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2449 if (iface_param->iface_num & 0x1)
2451 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2452 init_fw_cb->ipv4_ip_opts |=
2453 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2455 init_fw_cb->ipv4_ip_opts &=
2456 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2458 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2459 if (iface_param->iface_num & 0x1)
2461 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2462 init_fw_cb->ipv4_ip_opts |=
2463 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2465 init_fw_cb->ipv4_ip_opts &=
2466 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2468 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2469 if (iface_param->iface_num & 0x1)
2471 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2472 init_fw_cb->ipv4_ip_opts |=
2473 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2475 init_fw_cb->ipv4_ip_opts &=
2476 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2478 case ISCSI_NET_PARAM_REDIRECT_EN:
2479 if (iface_param->iface_num & 0x1)
2481 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2482 init_fw_cb->ipv4_ip_opts |=
2483 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2485 init_fw_cb->ipv4_ip_opts &=
2486 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2488 case ISCSI_NET_PARAM_IPV4_TTL:
2489 if (iface_param->iface_num & 0x1)
2491 init_fw_cb->ipv4_ttl = iface_param->value[0];
2494 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2495 iface_param->param);
2500 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2501 struct iscsi_iface_param_info *iface_param,
2502 struct addr_ctrl_blk *init_fw_cb)
2504 switch (iface_param->param) {
2505 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2506 if (iface_param->iface_num & 0x1)
2508 init_fw_cb->def_timeout =
2509 cpu_to_le16(*(uint16_t *)iface_param->value);
2511 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2512 if (iface_param->iface_num & 0x1)
2514 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2515 init_fw_cb->iscsi_opts |=
2516 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2518 init_fw_cb->iscsi_opts &=
2519 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2521 case ISCSI_IFACE_PARAM_DATADGST_EN:
2522 if (iface_param->iface_num & 0x1)
2524 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2525 init_fw_cb->iscsi_opts |=
2526 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2528 init_fw_cb->iscsi_opts &=
2529 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2531 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2532 if (iface_param->iface_num & 0x1)
2534 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2535 init_fw_cb->iscsi_opts |=
2536 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2538 init_fw_cb->iscsi_opts &=
2539 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2541 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2542 if (iface_param->iface_num & 0x1)
2544 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2545 init_fw_cb->iscsi_opts |=
2546 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2548 init_fw_cb->iscsi_opts &=
2549 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2551 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2552 if (iface_param->iface_num & 0x1)
2554 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2555 init_fw_cb->iscsi_opts |=
2556 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2558 init_fw_cb->iscsi_opts &=
2559 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2561 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2562 if (iface_param->iface_num & 0x1)
2564 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2565 init_fw_cb->iscsi_opts |=
2566 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2568 init_fw_cb->iscsi_opts &=
2569 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2571 case ISCSI_IFACE_PARAM_ERL:
2572 if (iface_param->iface_num & 0x1)
2574 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2575 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2578 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2579 if (iface_param->iface_num & 0x1)
2581 init_fw_cb->iscsi_max_pdu_size =
2582 cpu_to_le32(*(uint32_t *)iface_param->value) /
2585 case ISCSI_IFACE_PARAM_FIRST_BURST:
2586 if (iface_param->iface_num & 0x1)
2588 init_fw_cb->iscsi_fburst_len =
2589 cpu_to_le32(*(uint32_t *)iface_param->value) /
2592 case ISCSI_IFACE_PARAM_MAX_R2T:
2593 if (iface_param->iface_num & 0x1)
2595 init_fw_cb->iscsi_max_outstnd_r2t =
2596 cpu_to_le16(*(uint16_t *)iface_param->value);
2598 case ISCSI_IFACE_PARAM_MAX_BURST:
2599 if (iface_param->iface_num & 0x1)
2601 init_fw_cb->iscsi_max_burst_len =
2602 cpu_to_le32(*(uint32_t *)iface_param->value) /
2605 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2606 if (iface_param->iface_num & 0x1)
2608 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2609 init_fw_cb->iscsi_opts |=
2610 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2612 init_fw_cb->iscsi_opts &=
2613 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2615 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2616 if (iface_param->iface_num & 0x1)
2618 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2619 init_fw_cb->iscsi_opts |=
2620 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2622 init_fw_cb->iscsi_opts &=
2623 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2625 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2626 if (iface_param->iface_num & 0x1)
2628 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2629 init_fw_cb->iscsi_opts |=
2630 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2632 init_fw_cb->iscsi_opts &=
2633 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2635 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2636 if (iface_param->iface_num & 0x1)
2638 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2639 init_fw_cb->iscsi_opts |=
2640 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2642 init_fw_cb->iscsi_opts &=
2643 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2645 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2646 if (iface_param->iface_num & 0x1)
2648 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2649 init_fw_cb->iscsi_opts |=
2650 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2652 init_fw_cb->iscsi_opts &=
2653 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2656 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2657 iface_param->param);
2663 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2665 struct addr_ctrl_blk_def *acb;
2666 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2667 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2668 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2669 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2670 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2671 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2672 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2673 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2674 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2675 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2676 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2677 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2678 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2679 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2680 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2681 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2685 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2687 struct scsi_qla_host *ha = to_qla_host(shost);
2689 struct iscsi_iface_param_info *iface_param = NULL;
2690 struct addr_ctrl_blk *init_fw_cb = NULL;
2691 dma_addr_t init_fw_cb_dma;
2692 uint32_t mbox_cmd[MBOX_REG_COUNT];
2693 uint32_t mbox_sts[MBOX_REG_COUNT];
2695 struct nlattr *attr;
2697 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2698 sizeof(struct addr_ctrl_blk),
2699 &init_fw_cb_dma, GFP_KERNEL);
2701 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2706 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2707 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2708 memset(&mbox_sts, 0, sizeof(mbox_sts));
2710 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2711 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2713 goto exit_init_fw_cb;
2716 nla_for_each_attr(attr, data, len, rem) {
2717 iface_param = nla_data(attr);
2719 if (iface_param->param_type == ISCSI_NET_PARAM) {
2720 switch (iface_param->iface_type) {
2721 case ISCSI_IFACE_TYPE_IPV4:
2722 switch (iface_param->iface_num) {
2724 qla4xxx_set_ipv4(ha, iface_param,
2728 /* Cannot have more than one IPv4 interface */
2729 ql4_printk(KERN_ERR, ha,
2730 "Invalid IPv4 iface number = %d\n",
2731 iface_param->iface_num);
2735 case ISCSI_IFACE_TYPE_IPV6:
2736 switch (iface_param->iface_num) {
2739 qla4xxx_set_ipv6(ha, iface_param,
2743 /* Cannot have more than two IPv6 interface */
2744 ql4_printk(KERN_ERR, ha,
2745 "Invalid IPv6 iface number = %d\n",
2746 iface_param->iface_num);
2751 ql4_printk(KERN_ERR, ha,
2752 "Invalid iface type\n");
2755 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2756 qla4xxx_set_iscsi_param(ha, iface_param,
2763 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2765 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2766 sizeof(struct addr_ctrl_blk),
2767 FLASH_OPT_RMW_COMMIT);
2768 if (rval != QLA_SUCCESS) {
2769 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2772 goto exit_init_fw_cb;
2775 rval = qla4xxx_disable_acb(ha);
2776 if (rval != QLA_SUCCESS) {
2777 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2780 goto exit_init_fw_cb;
2783 wait_for_completion_timeout(&ha->disable_acb_comp,
2784 DISABLE_ACB_TOV * HZ);
2786 qla4xxx_initcb_to_acb(init_fw_cb);
2788 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2789 if (rval != QLA_SUCCESS) {
2790 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2793 goto exit_init_fw_cb;
2796 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2797 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2801 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2802 init_fw_cb, init_fw_cb_dma);
2807 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2808 enum iscsi_param param, char *buf)
2810 struct iscsi_session *sess = cls_sess->dd_data;
2811 struct ddb_entry *ddb_entry = sess->dd_data;
2812 struct scsi_qla_host *ha = ddb_entry->ha;
2813 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2814 struct ql4_chap_table chap_tbl;
2818 memset(&chap_tbl, 0, sizeof(chap_tbl));
2820 case ISCSI_PARAM_CHAP_IN_IDX:
2821 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2822 sess->password_in, BIDI_CHAP,
2825 len = sprintf(buf, "\n");
2827 len = sprintf(buf, "%hu\n", idx);
2829 case ISCSI_PARAM_CHAP_OUT_IDX:
2830 if (ddb_entry->ddb_type == FLASH_DDB) {
2831 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2832 idx = ddb_entry->chap_tbl_idx;
2838 rval = qla4xxx_get_chap_index(ha, sess->username,
2843 len = sprintf(buf, "\n");
2845 len = sprintf(buf, "%hu\n", idx);
2847 case ISCSI_PARAM_USERNAME:
2848 case ISCSI_PARAM_PASSWORD:
2849 /* First, populate session username and password for FLASH DDB,
2850 * if not already done. This happens when session login fails
2853 if (ddb_entry->ddb_type == FLASH_DDB &&
2854 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2855 !sess->username && !sess->password) {
2856 idx = ddb_entry->chap_tbl_idx;
2857 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2861 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2862 (char *)chap_tbl.name,
2863 strlen((char *)chap_tbl.name));
2864 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2865 (char *)chap_tbl.secret,
2866 chap_tbl.secret_len);
2869 /* allow fall-through */
2871 return iscsi_session_get_param(cls_sess, param, buf);
2877 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2878 enum iscsi_param param, char *buf)
2880 struct iscsi_conn *conn;
2881 struct qla_conn *qla_conn;
2882 struct sockaddr *dst_addr;
2884 conn = cls_conn->dd_data;
2885 qla_conn = conn->dd_data;
2886 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2889 case ISCSI_PARAM_CONN_PORT:
2890 case ISCSI_PARAM_CONN_ADDRESS:
2891 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2892 dst_addr, param, buf);
2894 return iscsi_conn_get_param(cls_conn, param, buf);
2898 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2900 uint32_t mbx_sts = 0;
2901 uint16_t tmp_ddb_index;
2905 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2907 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2908 DEBUG2(ql4_printk(KERN_INFO, ha,
2909 "Free DDB index not available\n"));
2911 goto exit_get_ddb_index;
2914 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2917 DEBUG2(ql4_printk(KERN_INFO, ha,
2918 "Found a free DDB index at %d\n", tmp_ddb_index));
2919 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2920 if (ret == QLA_ERROR) {
2921 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2922 ql4_printk(KERN_INFO, ha,
2923 "DDB index = %d not available trying next\n",
2927 DEBUG2(ql4_printk(KERN_INFO, ha,
2928 "Free FW DDB not available\n"));
2931 *ddb_index = tmp_ddb_index;
2937 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2938 struct ddb_entry *ddb_entry,
2939 char *existing_ipaddr,
2942 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2943 char formatted_ipaddr[DDB_IPADDR_LEN];
2944 int status = QLA_SUCCESS, ret = 0;
2946 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2947 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2953 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2955 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2961 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
2964 if (strcmp(existing_ipaddr, formatted_ipaddr))
2971 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
2972 struct iscsi_cls_conn *cls_conn)
2974 int idx = 0, max_ddbs, rval;
2975 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
2976 struct iscsi_session *sess, *existing_sess;
2977 struct iscsi_conn *conn, *existing_conn;
2978 struct ddb_entry *ddb_entry;
2980 sess = cls_sess->dd_data;
2981 conn = cls_conn->dd_data;
2983 if (sess->targetname == NULL ||
2984 conn->persistent_address == NULL ||
2985 conn->persistent_port == 0)
2988 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
2991 for (idx = 0; idx < max_ddbs; idx++) {
2992 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
2993 if (ddb_entry == NULL)
2996 if (ddb_entry->ddb_type != FLASH_DDB)
2999 existing_sess = ddb_entry->sess->dd_data;
3000 existing_conn = ddb_entry->conn->dd_data;
3002 if (existing_sess->targetname == NULL ||
3003 existing_conn->persistent_address == NULL ||
3004 existing_conn->persistent_port == 0)
3007 DEBUG2(ql4_printk(KERN_INFO, ha,
3008 "IQN = %s User IQN = %s\n",
3009 existing_sess->targetname,
3012 DEBUG2(ql4_printk(KERN_INFO, ha,
3013 "IP = %s User IP = %s\n",
3014 existing_conn->persistent_address,
3015 conn->persistent_address));
3017 DEBUG2(ql4_printk(KERN_INFO, ha,
3018 "Port = %d User Port = %d\n",
3019 existing_conn->persistent_port,
3020 conn->persistent_port));
3022 if (strcmp(existing_sess->targetname, sess->targetname))
3024 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3025 existing_conn->persistent_address,
3026 conn->persistent_address);
3027 if (rval == QLA_ERROR)
3029 if (existing_conn->persistent_port != conn->persistent_port)
3034 if (idx == max_ddbs)
3037 DEBUG2(ql4_printk(KERN_INFO, ha,
3038 "Match found in fwdb sessions\n"));
3042 static struct iscsi_cls_session *
3043 qla4xxx_session_create(struct iscsi_endpoint *ep,
3044 uint16_t cmds_max, uint16_t qdepth,
3045 uint32_t initial_cmdsn)
3047 struct iscsi_cls_session *cls_sess;
3048 struct scsi_qla_host *ha;
3049 struct qla_endpoint *qla_ep;
3050 struct ddb_entry *ddb_entry;
3052 struct iscsi_session *sess;
3053 struct sockaddr *dst_addr;
3057 printk(KERN_ERR "qla4xxx: missing ep.\n");
3061 qla_ep = ep->dd_data;
3062 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
3063 ha = to_qla_host(qla_ep->host);
3064 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3067 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3068 if (ret == QLA_ERROR)
3071 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3072 cmds_max, sizeof(struct ddb_entry),
3073 sizeof(struct ql4_task_data),
3074 initial_cmdsn, ddb_index);
3078 sess = cls_sess->dd_data;
3079 ddb_entry = sess->dd_data;
3080 ddb_entry->fw_ddb_index = ddb_index;
3081 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3083 ddb_entry->sess = cls_sess;
3084 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3085 ddb_entry->ddb_change = qla4xxx_ddb_change;
3086 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3087 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3088 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3094 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3096 struct iscsi_session *sess;
3097 struct ddb_entry *ddb_entry;
3098 struct scsi_qla_host *ha;
3099 unsigned long flags, wtime;
3100 struct dev_db_entry *fw_ddb_entry = NULL;
3101 dma_addr_t fw_ddb_entry_dma;
3105 sess = cls_sess->dd_data;
3106 ddb_entry = sess->dd_data;
3108 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3111 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3112 &fw_ddb_entry_dma, GFP_KERNEL);
3113 if (!fw_ddb_entry) {
3114 ql4_printk(KERN_ERR, ha,
3115 "%s: Unable to allocate dma buffer\n", __func__);
3116 goto destroy_session;
3119 wtime = jiffies + (HZ * LOGOUT_TOV);
3121 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3122 fw_ddb_entry, fw_ddb_entry_dma,
3123 NULL, NULL, &ddb_state, NULL,
3125 if (ret == QLA_ERROR)
3126 goto destroy_session;
3128 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3129 (ddb_state == DDB_DS_SESSION_FAILED))
3130 goto destroy_session;
3132 schedule_timeout_uninterruptible(HZ);
3133 } while ((time_after(wtime, jiffies)));
3136 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3137 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3138 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3139 spin_lock_irqsave(&ha->hardware_lock, flags);
3140 qla4xxx_free_ddb(ha, ddb_entry);
3141 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3143 iscsi_session_teardown(cls_sess);
3146 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3147 fw_ddb_entry, fw_ddb_entry_dma);
3150 static struct iscsi_cls_conn *
3151 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3153 struct iscsi_cls_conn *cls_conn;
3154 struct iscsi_session *sess;
3155 struct ddb_entry *ddb_entry;
3156 struct scsi_qla_host *ha;
3158 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3161 pr_info("%s: Can not create connection for conn_idx = %u\n",
3162 __func__, conn_idx);
3166 sess = cls_sess->dd_data;
3167 ddb_entry = sess->dd_data;
3168 ddb_entry->conn = cls_conn;
3171 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3176 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3177 struct iscsi_cls_conn *cls_conn,
3178 uint64_t transport_fd, int is_leading)
3180 struct iscsi_conn *conn;
3181 struct qla_conn *qla_conn;
3182 struct iscsi_endpoint *ep;
3183 struct ddb_entry *ddb_entry;
3184 struct scsi_qla_host *ha;
3185 struct iscsi_session *sess;
3187 sess = cls_session->dd_data;
3188 ddb_entry = sess->dd_data;
3191 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3192 cls_session->sid, cls_conn->cid));
3194 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3196 ep = iscsi_lookup_endpoint(transport_fd);
3197 conn = cls_conn->dd_data;
3198 qla_conn = conn->dd_data;
3199 qla_conn->qla_ep = ep->dd_data;
3203 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3205 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3206 struct iscsi_session *sess;
3207 struct ddb_entry *ddb_entry;
3208 struct scsi_qla_host *ha;
3209 struct dev_db_entry *fw_ddb_entry = NULL;
3210 dma_addr_t fw_ddb_entry_dma;
3211 uint32_t mbx_sts = 0;
3213 int status = QLA_SUCCESS;
3215 sess = cls_sess->dd_data;
3216 ddb_entry = sess->dd_data;
3218 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3219 cls_sess->sid, cls_conn->cid));
3221 /* Check if we have matching FW DDB, if yes then do not
3222 * login to this target. This could cause target to logout previous
3225 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3226 if (ret == QLA_SUCCESS) {
3227 ql4_printk(KERN_INFO, ha,
3228 "Session already exist in FW.\n");
3230 goto exit_conn_start;
3233 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3234 &fw_ddb_entry_dma, GFP_KERNEL);
3235 if (!fw_ddb_entry) {
3236 ql4_printk(KERN_ERR, ha,
3237 "%s: Unable to allocate dma buffer\n", __func__);
3239 goto exit_conn_start;
3242 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3244 /* If iscsid is stopped and started then no need to do
3245 * set param again since ddb state will be already
3246 * active and FW does not allow set ddb to an
3250 if (ddb_entry->fw_ddb_device_state ==
3251 DDB_DS_SESSION_ACTIVE) {
3252 ddb_entry->unblock_sess(ddb_entry->sess);
3253 goto exit_set_param;
3256 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3257 __func__, ddb_entry->fw_ddb_index);
3258 goto exit_conn_start;
3261 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3262 if (status == QLA_ERROR) {
3263 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3266 goto exit_conn_start;
3269 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3270 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3272 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3273 ddb_entry->fw_ddb_device_state));
3280 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3281 fw_ddb_entry, fw_ddb_entry_dma);
3285 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3287 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3288 struct iscsi_session *sess;
3289 struct scsi_qla_host *ha;
3290 struct ddb_entry *ddb_entry;
3293 sess = cls_sess->dd_data;
3294 ddb_entry = sess->dd_data;
3296 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3299 options = LOGOUT_OPTION_CLOSE_SESSION;
3300 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3301 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3304 static void qla4xxx_task_work(struct work_struct *wdata)
3306 struct ql4_task_data *task_data;
3307 struct scsi_qla_host *ha;
3308 struct passthru_status *sts;
3309 struct iscsi_task *task;
3310 struct iscsi_hdr *hdr;
3313 struct iscsi_conn *conn;
3317 task_data = container_of(wdata, struct ql4_task_data, task_work);
3319 task = task_data->task;
3320 sts = &task_data->sts;
3321 hdr_len = sizeof(struct iscsi_hdr);
3323 DEBUG3(printk(KERN_INFO "Status returned\n"));
3324 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3325 DEBUG3(printk(KERN_INFO "Response buffer"));
3326 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3330 switch (sts->completionStatus) {
3331 case PASSTHRU_STATUS_COMPLETE:
3332 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3333 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3336 data = task_data->resp_buffer + hdr_len;
3337 data_len = task_data->resp_len - hdr_len;
3338 iscsi_complete_pdu(conn, hdr, data, data_len);
3341 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3342 sts->completionStatus);
3348 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3350 struct ql4_task_data *task_data;
3351 struct iscsi_session *sess;
3352 struct ddb_entry *ddb_entry;
3353 struct scsi_qla_host *ha;
3356 sess = task->conn->session;
3357 ddb_entry = sess->dd_data;
3359 task_data = task->dd_data;
3360 memset(task_data, 0, sizeof(struct ql4_task_data));
3363 ql4_printk(KERN_INFO, ha,
3364 "%s: SCSI Commands not implemented\n", __func__);
3368 hdr_len = sizeof(struct iscsi_hdr);
3370 task_data->task = task;
3372 if (task->data_count) {
3373 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3378 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3379 __func__, task->conn->max_recv_dlength, hdr_len));
3381 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3382 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3383 task_data->resp_len,
3384 &task_data->resp_dma,
3386 if (!task_data->resp_buffer)
3387 goto exit_alloc_pdu;
3389 task_data->req_len = task->data_count + hdr_len;
3390 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3392 &task_data->req_dma,
3394 if (!task_data->req_buffer)
3395 goto exit_alloc_pdu;
3397 task->hdr = task_data->req_buffer;
3399 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3404 if (task_data->resp_buffer)
3405 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3406 task_data->resp_buffer, task_data->resp_dma);
3408 if (task_data->req_buffer)
3409 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3410 task_data->req_buffer, task_data->req_dma);
3414 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3416 struct ql4_task_data *task_data;
3417 struct iscsi_session *sess;
3418 struct ddb_entry *ddb_entry;
3419 struct scsi_qla_host *ha;
3422 hdr_len = sizeof(struct iscsi_hdr);
3423 sess = task->conn->session;
3424 ddb_entry = sess->dd_data;
3426 task_data = task->dd_data;
3428 if (task->data_count) {
3429 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3430 task->data_count, PCI_DMA_TODEVICE);
3433 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3434 __func__, task->conn->max_recv_dlength, hdr_len));
3436 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3437 task_data->resp_buffer, task_data->resp_dma);
3438 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3439 task_data->req_buffer, task_data->req_dma);
3443 static int qla4xxx_task_xmit(struct iscsi_task *task)
3445 struct scsi_cmnd *sc = task->sc;
3446 struct iscsi_session *sess = task->conn->session;
3447 struct ddb_entry *ddb_entry = sess->dd_data;
3448 struct scsi_qla_host *ha = ddb_entry->ha;
3451 return qla4xxx_send_passthru0(task);
3453 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3458 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3459 struct iscsi_bus_flash_conn *conn,
3460 struct dev_db_entry *fw_ddb_entry)
3462 unsigned long options = 0;
3465 options = le16_to_cpu(fw_ddb_entry->options);
3466 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3467 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3468 rc = iscsi_switch_str_param(&sess->portal_type,
3473 rc = iscsi_switch_str_param(&sess->portal_type,
3479 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3481 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3482 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3484 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3485 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3486 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3487 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3488 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3489 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3491 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3492 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3493 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3494 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3496 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3497 sess->discovery_auth_optional =
3498 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3499 if (test_bit(ISCSIOPT_ERL1, &options))
3501 if (test_bit(ISCSIOPT_ERL0, &options))
3504 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3505 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3506 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3507 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3508 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3509 conn->tcp_timer_scale |= BIT_3;
3510 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3511 conn->tcp_timer_scale |= BIT_2;
3512 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3513 conn->tcp_timer_scale |= BIT_1;
3515 conn->tcp_timer_scale >>= 1;
3516 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3518 options = le16_to_cpu(fw_ddb_entry->ip_options);
3519 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3521 conn->max_recv_dlength = BYTE_UNITS *
3522 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3523 conn->max_xmit_dlength = BYTE_UNITS *
3524 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3525 sess->first_burst = BYTE_UNITS *
3526 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3527 sess->max_burst = BYTE_UNITS *
3528 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3529 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3530 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3531 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3532 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3533 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3534 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3535 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3536 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3537 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3538 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3539 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3540 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3541 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3542 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3543 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3544 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3546 sess->default_taskmgmt_timeout =
3547 le16_to_cpu(fw_ddb_entry->def_timeout);
3548 conn->port = le16_to_cpu(fw_ddb_entry->port);
3550 options = le16_to_cpu(fw_ddb_entry->options);
3551 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3552 if (!conn->ipaddress) {
3557 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3558 if (!conn->redirect_ipaddr) {
3563 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3564 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3566 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3567 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3569 conn->link_local_ipv6_addr = kmemdup(
3570 fw_ddb_entry->link_local_ipv6_addr,
3571 IPv6_ADDR_LEN, GFP_KERNEL);
3572 if (!conn->link_local_ipv6_addr) {
3577 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3580 if (fw_ddb_entry->iscsi_name[0]) {
3581 rc = iscsi_switch_str_param(&sess->targetname,
3582 (char *)fw_ddb_entry->iscsi_name);
3587 if (fw_ddb_entry->iscsi_alias[0]) {
3588 rc = iscsi_switch_str_param(&sess->targetalias,
3589 (char *)fw_ddb_entry->iscsi_alias);
3594 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3600 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3601 struct iscsi_bus_flash_conn *conn,
3602 struct dev_db_entry *fw_ddb_entry)
3607 options = le16_to_cpu(fw_ddb_entry->options);
3608 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3609 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3614 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3615 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3616 SET_BITVAL(sess->entry_state, options, BIT_3);
3617 fw_ddb_entry->options = cpu_to_le16(options);
3619 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3620 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3621 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3622 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3623 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3624 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3625 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3626 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3627 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3628 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3629 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3630 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3631 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3632 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3633 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3635 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3636 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3637 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3638 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3639 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3640 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3641 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3642 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3643 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3645 options = le16_to_cpu(fw_ddb_entry->ip_options);
3646 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3647 fw_ddb_entry->ip_options = cpu_to_le16(options);
3649 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3650 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3651 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3652 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3653 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3654 fw_ddb_entry->iscsi_first_burst_len =
3655 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3656 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3658 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3659 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3660 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3661 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3662 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3663 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3664 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3665 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3666 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3667 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3668 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3669 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3670 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3671 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3672 fw_ddb_entry->port = cpu_to_le16(conn->port);
3673 fw_ddb_entry->def_timeout =
3674 cpu_to_le16(sess->default_taskmgmt_timeout);
3676 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3677 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3679 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3681 if (conn->ipaddress)
3682 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3683 sizeof(fw_ddb_entry->ip_addr));
3685 if (conn->redirect_ipaddr)
3686 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3687 sizeof(fw_ddb_entry->tgt_addr));
3689 if (conn->link_local_ipv6_addr)
3690 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3691 conn->link_local_ipv6_addr,
3692 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3694 if (sess->targetname)
3695 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3696 sizeof(fw_ddb_entry->iscsi_name));
3698 if (sess->targetalias)
3699 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3700 sizeof(fw_ddb_entry->iscsi_alias));
3702 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3707 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3708 struct iscsi_session *sess,
3709 struct dev_db_entry *fw_ddb_entry)
3711 unsigned long options = 0;
3713 uint16_t disc_parent;
3714 char ip_addr[DDB_IPADDR_LEN];
3716 options = le16_to_cpu(fw_ddb_entry->options);
3717 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3718 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3720 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3722 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3723 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3724 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3725 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3726 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3727 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3729 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3730 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3731 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3733 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3734 sess->discovery_auth_optional =
3735 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3736 if (test_bit(ISCSIOPT_ERL1, &options))
3738 if (test_bit(ISCSIOPT_ERL0, &options))
3741 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3742 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3743 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3744 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3745 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3746 conn->tcp_timer_scale |= BIT_3;
3747 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3748 conn->tcp_timer_scale |= BIT_2;
3749 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3750 conn->tcp_timer_scale |= BIT_1;
3752 conn->tcp_timer_scale >>= 1;
3753 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3755 options = le16_to_cpu(fw_ddb_entry->ip_options);
3756 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3758 conn->max_recv_dlength = BYTE_UNITS *
3759 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3760 conn->max_xmit_dlength = BYTE_UNITS *
3761 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3762 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3763 sess->first_burst = BYTE_UNITS *
3764 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3765 sess->max_burst = BYTE_UNITS *
3766 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3767 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3768 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3769 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3770 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3771 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3772 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3773 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3774 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3775 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3776 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3777 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3778 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3779 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3781 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3782 if (ddb_link == DDB_ISNS)
3783 disc_parent = ISCSI_DISC_PARENT_ISNS;
3784 else if (ddb_link == DDB_NO_LINK)
3785 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3786 else if (ddb_link < MAX_DDB_ENTRIES)
3787 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3789 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3791 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3792 iscsi_get_discovery_parent_name(disc_parent), 0);
3794 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3795 (char *)fw_ddb_entry->iscsi_alias, 0);
3797 options = le16_to_cpu(fw_ddb_entry->options);
3798 if (options & DDB_OPT_IPV6_DEVICE) {
3799 memset(ip_addr, 0, sizeof(ip_addr));
3800 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3801 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3802 (char *)ip_addr, 0);
3806 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3807 struct dev_db_entry *fw_ddb_entry,
3808 struct iscsi_cls_session *cls_sess,
3809 struct iscsi_cls_conn *cls_conn)
3812 struct iscsi_session *sess;
3813 struct ddb_entry *ddb_entry;
3814 struct ql4_chap_table chap_tbl;
3815 struct iscsi_conn *conn;
3816 char ip_addr[DDB_IPADDR_LEN];
3817 uint16_t options = 0;
3819 sess = cls_sess->dd_data;
3820 ddb_entry = sess->dd_data;
3821 conn = cls_conn->dd_data;
3822 memset(&chap_tbl, 0, sizeof(chap_tbl));
3824 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3826 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3828 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3829 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3831 memset(ip_addr, 0, sizeof(ip_addr));
3832 options = le16_to_cpu(fw_ddb_entry->options);
3833 if (options & DDB_OPT_IPV6_DEVICE) {
3834 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3836 memset(ip_addr, 0, sizeof(ip_addr));
3837 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3839 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3840 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3843 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3844 (char *)ip_addr, buflen);
3845 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3846 (char *)fw_ddb_entry->iscsi_name, buflen);
3847 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3848 (char *)ha->name_string, buflen);
3850 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3851 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3853 ddb_entry->chap_tbl_idx)) {
3854 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3855 (char *)chap_tbl.name,
3856 strlen((char *)chap_tbl.name));
3857 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3858 (char *)chap_tbl.secret,
3859 chap_tbl.secret_len);
3864 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3865 struct ddb_entry *ddb_entry)
3867 struct iscsi_cls_session *cls_sess;
3868 struct iscsi_cls_conn *cls_conn;
3870 dma_addr_t fw_ddb_entry_dma;
3871 struct dev_db_entry *fw_ddb_entry;
3873 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3874 &fw_ddb_entry_dma, GFP_KERNEL);
3875 if (!fw_ddb_entry) {
3876 ql4_printk(KERN_ERR, ha,
3877 "%s: Unable to allocate dma buffer\n", __func__);
3878 goto exit_session_conn_fwddb_param;
3881 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3882 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3883 NULL, NULL, NULL) == QLA_ERROR) {
3884 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3885 "get_ddb_entry for fw_ddb_index %d\n",
3886 ha->host_no, __func__,
3887 ddb_entry->fw_ddb_index));
3888 goto exit_session_conn_fwddb_param;
3891 cls_sess = ddb_entry->sess;
3893 cls_conn = ddb_entry->conn;
3896 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3898 exit_session_conn_fwddb_param:
3900 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3901 fw_ddb_entry, fw_ddb_entry_dma);
3904 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3905 struct ddb_entry *ddb_entry)
3907 struct iscsi_cls_session *cls_sess;
3908 struct iscsi_cls_conn *cls_conn;
3909 struct iscsi_session *sess;
3910 struct iscsi_conn *conn;
3912 dma_addr_t fw_ddb_entry_dma;
3913 struct dev_db_entry *fw_ddb_entry;
3915 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3916 &fw_ddb_entry_dma, GFP_KERNEL);
3917 if (!fw_ddb_entry) {
3918 ql4_printk(KERN_ERR, ha,
3919 "%s: Unable to allocate dma buffer\n", __func__);
3920 goto exit_session_conn_param;
3923 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3924 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3925 NULL, NULL, NULL) == QLA_ERROR) {
3926 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3927 "get_ddb_entry for fw_ddb_index %d\n",
3928 ha->host_no, __func__,
3929 ddb_entry->fw_ddb_index));
3930 goto exit_session_conn_param;
3933 cls_sess = ddb_entry->sess;
3934 sess = cls_sess->dd_data;
3936 cls_conn = ddb_entry->conn;
3937 conn = cls_conn->dd_data;
3939 /* Update timers after login */
3940 ddb_entry->default_relogin_timeout =
3941 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3942 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3943 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3944 ddb_entry->default_time2wait =
3945 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3948 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3949 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3951 memcpy(sess->initiatorname, ha->name_string,
3952 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3954 exit_session_conn_param:
3956 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3957 fw_ddb_entry, fw_ddb_entry_dma);
3964 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
3965 unsigned long interval)
3967 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
3968 __func__, ha->host->host_no));
3969 init_timer(&ha->timer);
3970 ha->timer.expires = jiffies + interval * HZ;
3971 ha->timer.data = (unsigned long)ha;
3972 ha->timer.function = (void (*)(unsigned long))func;
3973 add_timer(&ha->timer);
3974 ha->timer_active = 1;
3977 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
3979 del_timer_sync(&ha->timer);
3980 ha->timer_active = 0;
3984 * qla4xxx_mark_device_missing - blocks the session
3985 * @cls_session: Pointer to the session to be blocked
3986 * @ddb_entry: Pointer to device database entry
3988 * This routine marks a device missing and close connection.
3990 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
3992 iscsi_block_session(cls_session);
3996 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
3997 * @ha: Pointer to host adapter structure.
3999 * This routine marks a device missing and resets the relogin retry count.
4001 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4003 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4006 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4007 struct ddb_entry *ddb_entry,
4008 struct scsi_cmnd *cmd)
4012 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4016 kref_init(&srb->srb_ref);
4018 srb->ddb = ddb_entry;
4021 CMD_SP(cmd) = (void *)srb;
4026 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4028 struct scsi_cmnd *cmd = srb->cmd;
4030 if (srb->flags & SRB_DMA_VALID) {
4031 scsi_dma_unmap(cmd);
4032 srb->flags &= ~SRB_DMA_VALID;
4037 void qla4xxx_srb_compl(struct kref *ref)
4039 struct srb *srb = container_of(ref, struct srb, srb_ref);
4040 struct scsi_cmnd *cmd = srb->cmd;
4041 struct scsi_qla_host *ha = srb->ha;
4043 qla4xxx_srb_free_dma(ha, srb);
4045 mempool_free(srb, ha->srb_mempool);
4047 cmd->scsi_done(cmd);
4051 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4053 * @cmd: Pointer to Linux's SCSI command structure
4056 * This routine is invoked by Linux to send a SCSI command to the driver.
4057 * The mid-level driver tries to ensure that queuecommand never gets
4058 * invoked concurrently with itself or the interrupt handler (although
4059 * the interrupt handler may call this routine as part of request-
4060 * completion handling). Unfortunely, it sometimes calls the scheduler
4061 * in interrupt context which is a big NO! NO!.
4063 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4065 struct scsi_qla_host *ha = to_qla_host(host);
4066 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4067 struct iscsi_cls_session *sess = ddb_entry->sess;
4071 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4072 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4073 cmd->result = DID_NO_CONNECT << 16;
4075 cmd->result = DID_REQUEUE << 16;
4076 goto qc_fail_command;
4080 cmd->result = DID_IMM_RETRY << 16;
4081 goto qc_fail_command;
4084 rval = iscsi_session_chkready(sess);
4087 goto qc_fail_command;
4090 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4091 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4092 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4093 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4094 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4095 !test_bit(AF_ONLINE, &ha->flags) ||
4096 !test_bit(AF_LINK_UP, &ha->flags) ||
4097 test_bit(AF_LOOPBACK, &ha->flags) ||
4098 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4099 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4100 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4103 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4107 rval = qla4xxx_send_command_to_isp(ha, srb);
4108 if (rval != QLA_SUCCESS)
4109 goto qc_host_busy_free_sp;
4113 qc_host_busy_free_sp:
4114 qla4xxx_srb_free_dma(ha, srb);
4115 mempool_free(srb, ha->srb_mempool);
4118 return SCSI_MLQUEUE_HOST_BUSY;
4121 cmd->scsi_done(cmd);
4127 * qla4xxx_mem_free - frees memory allocated to adapter
4128 * @ha: Pointer to host adapter structure.
4130 * Frees memory previously allocated by qla4xxx_mem_alloc
4132 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4135 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4144 ha->request_ring = NULL;
4145 ha->request_dma = 0;
4146 ha->response_ring = NULL;
4147 ha->response_dma = 0;
4148 ha->shadow_regs = NULL;
4149 ha->shadow_regs_dma = 0;
4151 ha->fw_dump_size = 0;
4153 /* Free srb pool. */
4154 if (ha->srb_mempool)
4155 mempool_destroy(ha->srb_mempool);
4157 ha->srb_mempool = NULL;
4159 if (ha->chap_dma_pool)
4160 dma_pool_destroy(ha->chap_dma_pool);
4163 vfree(ha->chap_list);
4164 ha->chap_list = NULL;
4166 if (ha->fw_ddb_dma_pool)
4167 dma_pool_destroy(ha->fw_ddb_dma_pool);
4169 /* release io space registers */
4170 if (is_qla8022(ha)) {
4173 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4174 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4177 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4178 } else if (ha->reg) {
4182 if (ha->reset_tmplt.buff)
4183 vfree(ha->reset_tmplt.buff);
4185 pci_release_regions(ha->pdev);
4189 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4190 * @ha: Pointer to host adapter structure
4192 * Allocates DMA memory for request and response queues. Also allocates memory
4195 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4197 unsigned long align;
4199 /* Allocate contiguous block of DMA memory for queues. */
4200 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4201 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4202 sizeof(struct shadow_regs) +
4204 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4205 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4206 &ha->queues_dma, GFP_KERNEL);
4207 if (ha->queues == NULL) {
4208 ql4_printk(KERN_WARNING, ha,
4209 "Memory Allocation failed - queues.\n");
4211 goto mem_alloc_error_exit;
4213 memset(ha->queues, 0, ha->queues_len);
4216 * As per RISC alignment requirements -- the bus-address must be a
4217 * multiple of the request-ring size (in bytes).
4220 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4221 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4222 (MEM_ALIGN_VALUE - 1));
4224 /* Update request and response queue pointers. */
4225 ha->request_dma = ha->queues_dma + align;
4226 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4227 ha->response_dma = ha->queues_dma + align +
4228 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4229 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4230 (REQUEST_QUEUE_DEPTH *
4232 ha->shadow_regs_dma = ha->queues_dma + align +
4233 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4234 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4235 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4236 (REQUEST_QUEUE_DEPTH *
4238 (RESPONSE_QUEUE_DEPTH *
4241 /* Allocate memory for srb pool. */
4242 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4243 mempool_free_slab, srb_cachep);
4244 if (ha->srb_mempool == NULL) {
4245 ql4_printk(KERN_WARNING, ha,
4246 "Memory Allocation failed - SRB Pool.\n");
4248 goto mem_alloc_error_exit;
4251 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4252 CHAP_DMA_BLOCK_SIZE, 8, 0);
4254 if (ha->chap_dma_pool == NULL) {
4255 ql4_printk(KERN_WARNING, ha,
4256 "%s: chap_dma_pool allocation failed..\n", __func__);
4257 goto mem_alloc_error_exit;
4260 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4261 DDB_DMA_BLOCK_SIZE, 8, 0);
4263 if (ha->fw_ddb_dma_pool == NULL) {
4264 ql4_printk(KERN_WARNING, ha,
4265 "%s: fw_ddb_dma_pool allocation failed..\n",
4267 goto mem_alloc_error_exit;
4272 mem_alloc_error_exit:
4273 qla4xxx_mem_free(ha);
4278 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4279 * @ha: adapter block pointer.
4281 * Note: The caller should not hold the idc lock.
4283 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4285 uint32_t temp, temp_state, temp_val;
4286 int status = QLA_SUCCESS;
4288 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4290 temp_state = qla82xx_get_temp_state(temp);
4291 temp_val = qla82xx_get_temp_val(temp);
4293 if (temp_state == QLA82XX_TEMP_PANIC) {
4294 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4295 " exceeds maximum allowed. Hardware has been shut"
4296 " down.\n", temp_val);
4298 } else if (temp_state == QLA82XX_TEMP_WARN) {
4299 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4300 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4301 " degrees C exceeds operating range."
4302 " Immediate action needed.\n", temp_val);
4304 if (ha->temperature == QLA82XX_TEMP_WARN)
4305 ql4_printk(KERN_INFO, ha, "Device temperature is"
4306 " now %d degrees C in normal range.\n",
4309 ha->temperature = temp_state;
4314 * qla4_8xxx_check_fw_alive - Check firmware health
4315 * @ha: Pointer to host adapter structure.
4317 * Context: Interrupt
4319 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4321 uint32_t fw_heartbeat_counter;
4322 int status = QLA_SUCCESS;
4324 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4325 QLA8XXX_PEG_ALIVE_COUNTER);
4326 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4327 if (fw_heartbeat_counter == 0xffffffff) {
4328 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4329 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4330 ha->host_no, __func__));
4334 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4335 ha->seconds_since_last_heartbeat++;
4336 /* FW not alive after 2 seconds */
4337 if (ha->seconds_since_last_heartbeat == 2) {
4338 ha->seconds_since_last_heartbeat = 0;
4339 qla4_8xxx_dump_peg_reg(ha);
4343 ha->seconds_since_last_heartbeat = 0;
4345 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4349 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4351 uint32_t halt_status;
4352 int halt_status_unrecoverable = 0;
4354 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4356 if (is_qla8022(ha)) {
4357 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4359 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4360 CRB_NIU_XG_PAUSE_CTL_P0 |
4361 CRB_NIU_XG_PAUSE_CTL_P1);
4363 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4364 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4366 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4367 halt_status_unrecoverable = 1;
4368 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4369 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4370 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4372 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4373 halt_status_unrecoverable = 1;
4377 * Since we cannot change dev_state in interrupt context,
4378 * set appropriate DPC flag then wakeup DPC
4380 if (halt_status_unrecoverable) {
4381 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4383 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4385 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4387 qla4xxx_mailbox_premature_completion(ha);
4388 qla4xxx_wake_dpc(ha);
4392 * qla4_8xxx_watchdog - Poll dev state
4393 * @ha: Pointer to host adapter structure.
4395 * Context: Interrupt
4397 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4402 if (is_qla8032(ha) &&
4403 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4404 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4405 __func__, ha->func_num);
4407 /* don't poll if reset is going on */
4408 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4409 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4410 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4411 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4413 if (qla4_8xxx_check_temp(ha)) {
4414 if (is_qla8022(ha)) {
4415 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4416 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4417 CRB_NIU_XG_PAUSE_CTL_P0 |
4418 CRB_NIU_XG_PAUSE_CTL_P1);
4420 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4421 qla4xxx_wake_dpc(ha);
4422 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4423 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4425 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4428 if (is_qla8032(ha) || is_qla8042(ha)) {
4429 idc_ctrl = qla4_83xx_rd_reg(ha,
4430 QLA83XX_IDC_DRV_CTRL);
4431 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4432 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4434 qla4xxx_mailbox_premature_completion(
4439 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4440 (is_qla8022(ha) && !ql4xdontresethba)) {
4441 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4442 qla4xxx_wake_dpc(ha);
4444 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4445 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4446 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4448 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4449 qla4xxx_wake_dpc(ha);
4451 /* Check firmware health */
4452 if (qla4_8xxx_check_fw_alive(ha))
4453 qla4_8xxx_process_fw_error(ha);
4458 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4460 struct iscsi_session *sess;
4461 struct ddb_entry *ddb_entry;
4462 struct scsi_qla_host *ha;
4464 sess = cls_sess->dd_data;
4465 ddb_entry = sess->dd_data;
4468 if (!(ddb_entry->ddb_type == FLASH_DDB))
4471 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4472 !iscsi_is_session_online(cls_sess)) {
4473 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4475 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4477 atomic_set(&ddb_entry->retry_relogin_timer,
4479 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4480 set_bit(DF_RELOGIN, &ddb_entry->flags);
4481 DEBUG2(ql4_printk(KERN_INFO, ha,
4482 "%s: index [%d] login device\n",
4483 __func__, ddb_entry->fw_ddb_index));
4485 atomic_dec(&ddb_entry->retry_relogin_timer);
4489 /* Wait for relogin to timeout */
4490 if (atomic_read(&ddb_entry->relogin_timer) &&
4491 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4493 * If the relogin times out and the device is
4494 * still NOT ONLINE then try and relogin again.
4496 if (!iscsi_is_session_online(cls_sess)) {
4497 /* Reset retry relogin timer */
4498 atomic_inc(&ddb_entry->relogin_retry_count);
4499 DEBUG2(ql4_printk(KERN_INFO, ha,
4500 "%s: index[%d] relogin timed out-retrying"
4501 " relogin (%d), retry (%d)\n", __func__,
4502 ddb_entry->fw_ddb_index,
4503 atomic_read(&ddb_entry->relogin_retry_count),
4504 ddb_entry->default_time2wait + 4));
4505 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4506 atomic_set(&ddb_entry->retry_relogin_timer,
4507 ddb_entry->default_time2wait + 4);
4513 * qla4xxx_timer - checks every second for work to do.
4514 * @ha: Pointer to host adapter structure.
4516 static void qla4xxx_timer(struct scsi_qla_host *ha)
4521 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4523 /* If we are in the middle of AER/EEH processing
4524 * skip any processing and reschedule the timer
4526 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4527 mod_timer(&ha->timer, jiffies + HZ);
4531 /* Hardware read to trigger an EEH error during mailbox waits. */
4532 if (!pci_channel_offline(ha->pdev))
4533 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4536 qla4_8xxx_watchdog(ha);
4538 if (is_qla40XX(ha)) {
4539 /* Check for heartbeat interval. */
4540 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4541 ha->heartbeat_interval != 0) {
4542 ha->seconds_since_last_heartbeat++;
4543 if (ha->seconds_since_last_heartbeat >
4544 ha->heartbeat_interval + 2)
4545 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4549 /* Process any deferred work. */
4550 if (!list_empty(&ha->work_list))
4553 /* Wakeup the dpc routine for this adapter, if needed. */
4555 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4556 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4557 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4558 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4559 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4560 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4561 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4562 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4563 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4564 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4565 test_bit(DPC_AEN, &ha->dpc_flags)) {
4566 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4567 " - dpc flags = 0x%lx\n",
4568 ha->host_no, __func__, ha->dpc_flags));
4569 qla4xxx_wake_dpc(ha);
4572 /* Reschedule timer thread to call us back in one second */
4573 mod_timer(&ha->timer, jiffies + HZ);
4575 DEBUG2(ha->seconds_since_last_intr++);
4579 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4580 * @ha: Pointer to host adapter structure.
4582 * This routine stalls the driver until all outstanding commands are returned.
4583 * Caller must release the Hardware Lock prior to calling this routine.
4585 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4588 unsigned long flags;
4589 struct scsi_cmnd *cmd;
4590 unsigned long wtime;
4594 wtmo = WAIT_CMD_TOV;
4596 wtmo = ha->nx_reset_timeout / 2;
4598 wtime = jiffies + (wtmo * HZ);
4600 DEBUG2(ql4_printk(KERN_INFO, ha,
4601 "Wait up to %u seconds for cmds to complete\n",
4604 while (!time_after_eq(jiffies, wtime)) {
4605 spin_lock_irqsave(&ha->hardware_lock, flags);
4606 /* Find a command that hasn't completed. */
4607 for (index = 0; index < ha->host->can_queue; index++) {
4608 cmd = scsi_host_find_tag(ha->host, index);
4610 * We cannot just check if the index is valid,
4611 * becase if we are run from the scsi eh, then
4612 * the scsi/block layer is going to prevent
4613 * the tag from being released.
4615 if (cmd != NULL && CMD_SP(cmd))
4618 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4620 /* If No Commands are pending, wait is complete */
4621 if (index == ha->host->can_queue)
4626 /* If we timed out on waiting for commands to come back
4631 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4633 uint32_t ctrl_status;
4634 unsigned long flags = 0;
4636 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4638 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4641 spin_lock_irqsave(&ha->hardware_lock, flags);
4644 * If the SCSI Reset Interrupt bit is set, clear it.
4645 * Otherwise, the Soft Reset won't work.
4647 ctrl_status = readw(&ha->reg->ctrl_status);
4648 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4649 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4651 /* Issue Soft Reset */
4652 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4653 readl(&ha->reg->ctrl_status);
4655 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4660 * qla4xxx_soft_reset - performs soft reset.
4661 * @ha: Pointer to host adapter structure.
4663 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4665 uint32_t max_wait_time;
4666 unsigned long flags = 0;
4668 uint32_t ctrl_status;
4670 status = qla4xxx_hw_reset(ha);
4671 if (status != QLA_SUCCESS)
4675 /* Wait until the Network Reset Intr bit is cleared */
4676 max_wait_time = RESET_INTR_TOV;
4678 spin_lock_irqsave(&ha->hardware_lock, flags);
4679 ctrl_status = readw(&ha->reg->ctrl_status);
4680 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4682 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4686 } while ((--max_wait_time));
4688 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4689 DEBUG2(printk(KERN_WARNING
4690 "scsi%ld: Network Reset Intr not cleared by "
4691 "Network function, clearing it now!\n",
4693 spin_lock_irqsave(&ha->hardware_lock, flags);
4694 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4695 readl(&ha->reg->ctrl_status);
4696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4699 /* Wait until the firmware tells us the Soft Reset is done */
4700 max_wait_time = SOFT_RESET_TOV;
4702 spin_lock_irqsave(&ha->hardware_lock, flags);
4703 ctrl_status = readw(&ha->reg->ctrl_status);
4704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4706 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4707 status = QLA_SUCCESS;
4712 } while ((--max_wait_time));
4715 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4716 * after the soft reset has taken place.
4718 spin_lock_irqsave(&ha->hardware_lock, flags);
4719 ctrl_status = readw(&ha->reg->ctrl_status);
4720 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4721 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4722 readl(&ha->reg->ctrl_status);
4724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4726 /* If soft reset fails then most probably the bios on other
4727 * function is also enabled.
4728 * Since the initialization is sequential the other fn
4729 * wont be able to acknowledge the soft reset.
4730 * Issue a force soft reset to workaround this scenario.
4732 if (max_wait_time == 0) {
4733 /* Issue Force Soft Reset */
4734 spin_lock_irqsave(&ha->hardware_lock, flags);
4735 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4736 readl(&ha->reg->ctrl_status);
4737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4738 /* Wait until the firmware tells us the Soft Reset is done */
4739 max_wait_time = SOFT_RESET_TOV;
4741 spin_lock_irqsave(&ha->hardware_lock, flags);
4742 ctrl_status = readw(&ha->reg->ctrl_status);
4743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4745 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4746 status = QLA_SUCCESS;
4751 } while ((--max_wait_time));
4758 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4759 * @ha: Pointer to host adapter structure.
4760 * @res: returned scsi status
4762 * This routine is called just prior to a HARD RESET to return all
4763 * outstanding commands back to the Operating System.
4764 * Caller should make sure that the following locks are released
4765 * before this calling routine: Hardware lock, and io_request_lock.
4767 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4771 unsigned long flags;
4773 spin_lock_irqsave(&ha->hardware_lock, flags);
4774 for (i = 0; i < ha->host->can_queue; i++) {
4775 srb = qla4xxx_del_from_active_array(ha, i);
4777 srb->cmd->result = res;
4778 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4784 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4786 clear_bit(AF_ONLINE, &ha->flags);
4788 /* Disable the board */
4789 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4791 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4792 qla4xxx_mark_all_devices_missing(ha);
4793 clear_bit(AF_INIT_DONE, &ha->flags);
4796 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4798 struct iscsi_session *sess;
4799 struct ddb_entry *ddb_entry;
4801 sess = cls_session->dd_data;
4802 ddb_entry = sess->dd_data;
4803 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4805 if (ddb_entry->ddb_type == FLASH_DDB)
4806 iscsi_block_session(ddb_entry->sess);
4808 iscsi_session_failure(cls_session->dd_data,
4809 ISCSI_ERR_CONN_FAILED);
4813 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4814 * @ha: Pointer to host adapter structure.
4816 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4818 int status = QLA_ERROR;
4819 uint8_t reset_chip = 0;
4823 /* Stall incoming I/O until we are done */
4824 scsi_block_requests(ha->host);
4825 clear_bit(AF_ONLINE, &ha->flags);
4826 clear_bit(AF_LINK_UP, &ha->flags);
4828 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4830 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4832 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4833 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4834 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4836 /* disable pause frame for ISP83xx */
4837 qla4_83xx_disable_pause(ha);
4840 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4842 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4845 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4846 * do not reset adapter, jump to initialize_adapter */
4847 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4848 status = QLA_SUCCESS;
4849 goto recover_ha_init_adapter;
4852 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4853 * from eh_host_reset or ioctl module */
4854 if (is_qla80XX(ha) && !reset_chip &&
4855 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4857 DEBUG2(ql4_printk(KERN_INFO, ha,
4858 "scsi%ld: %s - Performing stop_firmware...\n",
4859 ha->host_no, __func__));
4860 status = ha->isp_ops->reset_firmware(ha);
4861 if (status == QLA_SUCCESS) {
4862 ha->isp_ops->disable_intrs(ha);
4863 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4864 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4866 /* If the stop_firmware fails then
4867 * reset the entire chip */
4869 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4870 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4874 /* Issue full chip reset if recovering from a catastrophic error,
4875 * or if stop_firmware fails for ISP-8xxx.
4876 * This is the default case for ISP-4xxx */
4877 if (is_qla40XX(ha) || reset_chip) {
4881 /* Check if 8XXX firmware is alive or not
4882 * We may have arrived here from NEED_RESET
4884 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4887 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4888 while (time_before(jiffies, wait)) {
4889 if (qla4_8xxx_check_fw_alive(ha)) {
4890 qla4xxx_mailbox_premature_completion(ha);
4894 set_current_state(TASK_UNINTERRUPTIBLE);
4895 schedule_timeout(HZ);
4898 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4899 qla4xxx_cmd_wait(ha);
4901 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4902 DEBUG2(ql4_printk(KERN_INFO, ha,
4903 "scsi%ld: %s - Performing chip reset..\n",
4904 ha->host_no, __func__));
4905 status = ha->isp_ops->reset_chip(ha);
4906 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4909 /* Flush any pending ddb changed AENs */
4910 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4912 recover_ha_init_adapter:
4913 /* Upon successful firmware/chip reset, re-initialize the adapter */
4914 if (status == QLA_SUCCESS) {
4915 /* For ISP-4xxx, force function 1 to always initialize
4916 * before function 3 to prevent both funcions from
4917 * stepping on top of the other */
4918 if (is_qla40XX(ha) && (ha->mac_index == 3))
4921 /* NOTE: AF_ONLINE flag set upon successful completion of
4922 * qla4xxx_initialize_adapter */
4923 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4924 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4925 status = qla4_8xxx_check_init_adapter_retry(ha);
4926 if (status == QLA_ERROR) {
4927 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4928 ha->host_no, __func__);
4929 qla4xxx_dead_adapter_cleanup(ha);
4930 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4931 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4932 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4939 /* Retry failed adapter initialization, if necessary
4940 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4941 * case to prevent ping-pong resets between functions */
4942 if (!test_bit(AF_ONLINE, &ha->flags) &&
4943 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4944 /* Adapter initialization failed, see if we can retry
4946 * Since we don't want to block the DPC for too long
4947 * with multiple resets in the same thread,
4948 * utilize DPC to retry */
4949 if (is_qla80XX(ha)) {
4950 ha->isp_ops->idc_lock(ha);
4951 dev_state = qla4_8xxx_rd_direct(ha,
4952 QLA8XXX_CRB_DEV_STATE);
4953 ha->isp_ops->idc_unlock(ha);
4954 if (dev_state == QLA8XXX_DEV_FAILED) {
4955 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4956 "recover adapter. H/W is in Failed "
4957 "state\n", __func__);
4958 qla4xxx_dead_adapter_cleanup(ha);
4959 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4960 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4961 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4969 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
4970 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
4971 DEBUG2(printk("scsi%ld: recover adapter - retrying "
4972 "(%d) more times\n", ha->host_no,
4973 ha->retry_reset_ha_cnt));
4974 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4977 if (ha->retry_reset_ha_cnt > 0) {
4978 /* Schedule another Reset HA--DPC will retry */
4979 ha->retry_reset_ha_cnt--;
4980 DEBUG2(printk("scsi%ld: recover adapter - "
4981 "retry remaining %d\n",
4983 ha->retry_reset_ha_cnt));
4987 if (ha->retry_reset_ha_cnt == 0) {
4988 /* Recover adapter retries have been exhausted.
4990 DEBUG2(printk("scsi%ld: recover adapter "
4991 "failed - board disabled\n",
4993 qla4xxx_dead_adapter_cleanup(ha);
4994 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4995 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4996 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5002 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5003 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5004 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5008 ha->adapter_error_count++;
5010 if (test_bit(AF_ONLINE, &ha->flags))
5011 ha->isp_ops->enable_intrs(ha);
5013 scsi_unblock_requests(ha->host);
5015 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5016 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5017 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5022 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5024 struct iscsi_session *sess;
5025 struct ddb_entry *ddb_entry;
5026 struct scsi_qla_host *ha;
5028 sess = cls_session->dd_data;
5029 ddb_entry = sess->dd_data;
5031 if (!iscsi_is_session_online(cls_session)) {
5032 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5033 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5034 " unblock session\n", ha->host_no, __func__,
5035 ddb_entry->fw_ddb_index);
5036 iscsi_unblock_session(ddb_entry->sess);
5038 /* Trigger relogin */
5039 if (ddb_entry->ddb_type == FLASH_DDB) {
5040 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5041 test_bit(DF_DISABLE_RELOGIN,
5042 &ddb_entry->flags)))
5043 qla4xxx_arm_relogin_timer(ddb_entry);
5045 iscsi_session_failure(cls_session->dd_data,
5046 ISCSI_ERR_CONN_FAILED);
5051 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5053 struct iscsi_session *sess;
5054 struct ddb_entry *ddb_entry;
5055 struct scsi_qla_host *ha;
5057 sess = cls_session->dd_data;
5058 ddb_entry = sess->dd_data;
5060 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5061 " unblock session\n", ha->host_no, __func__,
5062 ddb_entry->fw_ddb_index);
5064 iscsi_unblock_session(ddb_entry->sess);
5066 /* Start scan target */
5067 if (test_bit(AF_ONLINE, &ha->flags)) {
5068 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5069 " start scan\n", ha->host_no, __func__,
5070 ddb_entry->fw_ddb_index);
5071 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5076 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5078 struct iscsi_session *sess;
5079 struct ddb_entry *ddb_entry;
5080 struct scsi_qla_host *ha;
5081 int status = QLA_SUCCESS;
5083 sess = cls_session->dd_data;
5084 ddb_entry = sess->dd_data;
5086 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5087 " unblock user space session\n", ha->host_no, __func__,
5088 ddb_entry->fw_ddb_index);
5090 if (!iscsi_is_session_online(cls_session)) {
5091 iscsi_conn_start(ddb_entry->conn);
5092 iscsi_conn_login_event(ddb_entry->conn,
5093 ISCSI_CONN_STATE_LOGGED_IN);
5095 ql4_printk(KERN_INFO, ha,
5096 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5097 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5105 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5107 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5110 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5112 uint16_t relogin_timer;
5113 struct iscsi_session *sess;
5114 struct ddb_entry *ddb_entry;
5115 struct scsi_qla_host *ha;
5117 sess = cls_sess->dd_data;
5118 ddb_entry = sess->dd_data;
5121 relogin_timer = max(ddb_entry->default_relogin_timeout,
5122 (uint16_t)RELOGIN_TOV);
5123 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5125 DEBUG2(ql4_printk(KERN_INFO, ha,
5126 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5127 ddb_entry->fw_ddb_index, relogin_timer));
5129 qla4xxx_login_flash_ddb(cls_sess);
5132 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5134 struct iscsi_session *sess;
5135 struct ddb_entry *ddb_entry;
5136 struct scsi_qla_host *ha;
5138 sess = cls_sess->dd_data;
5139 ddb_entry = sess->dd_data;
5142 if (!(ddb_entry->ddb_type == FLASH_DDB))
5145 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5148 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5149 !iscsi_is_session_online(cls_sess)) {
5150 DEBUG2(ql4_printk(KERN_INFO, ha,
5151 "relogin issued\n"));
5152 qla4xxx_relogin_flash_ddb(cls_sess);
5156 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5159 queue_work(ha->dpc_thread, &ha->dpc_work);
5162 static struct qla4_work_evt *
5163 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5164 enum qla4_work_type type)
5166 struct qla4_work_evt *e;
5167 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5169 e = kzalloc(size, GFP_ATOMIC);
5173 INIT_LIST_HEAD(&e->list);
5178 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5179 struct qla4_work_evt *e)
5181 unsigned long flags;
5183 spin_lock_irqsave(&ha->work_lock, flags);
5184 list_add_tail(&e->list, &ha->work_list);
5185 spin_unlock_irqrestore(&ha->work_lock, flags);
5186 qla4xxx_wake_dpc(ha);
5189 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5190 enum iscsi_host_event_code aen_code,
5191 uint32_t data_size, uint8_t *data)
5193 struct qla4_work_evt *e;
5195 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5199 e->u.aen.code = aen_code;
5200 e->u.aen.data_size = data_size;
5201 memcpy(e->u.aen.data, data, data_size);
5203 qla4xxx_post_work(ha, e);
5208 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5209 uint32_t status, uint32_t pid,
5210 uint32_t data_size, uint8_t *data)
5212 struct qla4_work_evt *e;
5214 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5218 e->u.ping.status = status;
5219 e->u.ping.pid = pid;
5220 e->u.ping.data_size = data_size;
5221 memcpy(e->u.ping.data, data, data_size);
5223 qla4xxx_post_work(ha, e);
5228 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5230 struct qla4_work_evt *e, *tmp;
5231 unsigned long flags;
5234 spin_lock_irqsave(&ha->work_lock, flags);
5235 list_splice_init(&ha->work_list, &work);
5236 spin_unlock_irqrestore(&ha->work_lock, flags);
5238 list_for_each_entry_safe(e, tmp, &work, list) {
5239 list_del_init(&e->list);
5242 case QLA4_EVENT_AEN:
5243 iscsi_post_host_event(ha->host_no,
5244 &qla4xxx_iscsi_transport,
5249 case QLA4_EVENT_PING_STATUS:
5250 iscsi_ping_comp_event(ha->host_no,
5251 &qla4xxx_iscsi_transport,
5254 e->u.ping.data_size,
5258 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5259 "supported", e->type);
5266 * qla4xxx_do_dpc - dpc routine
5267 * @data: in our case pointer to adapter structure
5269 * This routine is a task that is schedule by the interrupt handler
5270 * to perform the background processing for interrupts. We put it
5271 * on a task queue that is consumed whenever the scheduler runs; that's
5272 * so you can do anything (i.e. put the process to sleep etc). In fact,
5273 * the mid-level tries to sleep when it reaches the driver threshold
5274 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5276 static void qla4xxx_do_dpc(struct work_struct *work)
5278 struct scsi_qla_host *ha =
5279 container_of(work, struct scsi_qla_host, dpc_work);
5280 int status = QLA_ERROR;
5282 DEBUG2(ql4_printk(KERN_INFO, ha,
5283 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5284 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5286 /* Initialization not yet finished. Don't do anything yet. */
5287 if (!test_bit(AF_INIT_DONE, &ha->flags))
5290 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5291 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5292 ha->host_no, __func__, ha->flags));
5296 /* post events to application */
5297 qla4xxx_do_work(ha);
5299 if (is_qla80XX(ha)) {
5300 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5301 if (is_qla8032(ha) || is_qla8042(ha)) {
5302 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5304 /* disable pause frame for ISP83xx */
5305 qla4_83xx_disable_pause(ha);
5308 ha->isp_ops->idc_lock(ha);
5309 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5310 QLA8XXX_DEV_FAILED);
5311 ha->isp_ops->idc_unlock(ha);
5312 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5313 qla4_8xxx_device_state_handler(ha);
5316 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5317 if (is_qla8042(ha)) {
5318 if (ha->idc_info.info2 &
5319 ENABLE_INTERNAL_LOOPBACK) {
5320 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5322 status = qla4_84xx_config_acb(ha,
5323 ACB_CONFIG_DISABLE);
5324 if (status != QLA_SUCCESS) {
5325 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5330 qla4_83xx_post_idc_ack(ha);
5331 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5334 if (is_qla8042(ha) &&
5335 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5336 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5338 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5340 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5343 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5346 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5347 qla4_8xxx_need_qsnt_handler(ha);
5351 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5352 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5353 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5354 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5355 if ((is_qla8022(ha) && ql4xdontresethba) ||
5356 ((is_qla8032(ha) || is_qla8042(ha)) &&
5357 qla4_83xx_idc_dontreset(ha))) {
5358 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5359 ha->host_no, __func__));
5360 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5361 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5362 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5363 goto dpc_post_reset_ha;
5365 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5366 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5367 qla4xxx_recover_adapter(ha);
5369 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5370 uint8_t wait_time = RESET_INTR_TOV;
5372 while ((readw(&ha->reg->ctrl_status) &
5373 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5374 if (--wait_time == 0)
5379 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5380 "bit not cleared-- resetting\n",
5381 ha->host_no, __func__));
5382 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5383 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5384 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5385 status = qla4xxx_recover_adapter(ha);
5387 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5388 if (status == QLA_SUCCESS)
5389 ha->isp_ops->enable_intrs(ha);
5394 /* ---- process AEN? --- */
5395 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5396 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5398 /* ---- Get DHCP IP Address? --- */
5399 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5400 qla4xxx_get_dhcp_ip_address(ha);
5402 /* ---- relogin device? --- */
5403 if (adapter_up(ha) &&
5404 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5405 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5408 /* ---- link change? --- */
5409 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5410 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5411 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5412 /* ---- link down? --- */
5413 qla4xxx_mark_all_devices_missing(ha);
5415 /* ---- link up? --- *
5416 * F/W will auto login to all devices ONLY ONCE after
5417 * link up during driver initialization and runtime
5418 * fatal error recovery. Therefore, the driver must
5419 * manually relogin to devices when recovering from
5420 * connection failures, logouts, expired KATO, etc. */
5421 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5422 qla4xxx_build_ddb_list(ha, ha->is_reset);
5423 iscsi_host_for_each_session(ha->host,
5424 qla4xxx_login_flash_ddb);
5426 qla4xxx_relogin_all_devices(ha);
5429 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5430 if (qla4xxx_sysfs_ddb_export(ha))
5431 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5437 * qla4xxx_free_adapter - release the adapter
5438 * @ha: pointer to adapter structure
5440 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5442 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5444 /* Turn-off interrupts on the card. */
5445 ha->isp_ops->disable_intrs(ha);
5447 if (is_qla40XX(ha)) {
5448 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5449 &ha->reg->ctrl_status);
5450 readl(&ha->reg->ctrl_status);
5451 } else if (is_qla8022(ha)) {
5452 writel(0, &ha->qla4_82xx_reg->host_int);
5453 readl(&ha->qla4_82xx_reg->host_int);
5454 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5455 writel(0, &ha->qla4_83xx_reg->risc_intr);
5456 readl(&ha->qla4_83xx_reg->risc_intr);
5459 /* Remove timer thread, if present */
5460 if (ha->timer_active)
5461 qla4xxx_stop_timer(ha);
5463 /* Kill the kernel thread for this host */
5465 destroy_workqueue(ha->dpc_thread);
5467 /* Kill the kernel thread for this host */
5469 destroy_workqueue(ha->task_wq);
5471 /* Put firmware in known state */
5472 ha->isp_ops->reset_firmware(ha);
5474 if (is_qla80XX(ha)) {
5475 ha->isp_ops->idc_lock(ha);
5476 qla4_8xxx_clear_drv_active(ha);
5477 ha->isp_ops->idc_unlock(ha);
5480 /* Detach interrupts */
5481 qla4xxx_free_irqs(ha);
5483 /* free extra memory */
5484 qla4xxx_mem_free(ha);
5487 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5490 unsigned long mem_base, mem_len, db_base, db_len;
5491 struct pci_dev *pdev = ha->pdev;
5493 status = pci_request_regions(pdev, DRIVER_NAME);
5496 "scsi(%ld) Failed to reserve PIO regions (%s) "
5497 "status=%d\n", ha->host_no, pci_name(pdev), status);
5498 goto iospace_error_exit;
5501 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5502 __func__, pdev->revision));
5503 ha->revision_id = pdev->revision;
5505 /* remap phys address */
5506 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5507 mem_len = pci_resource_len(pdev, 0);
5508 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5509 __func__, mem_base, mem_len));
5511 /* mapping of pcibase pointer */
5512 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5513 if (!ha->nx_pcibase) {
5515 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5516 pci_release_regions(ha->pdev);
5517 goto iospace_error_exit;
5520 /* Mapping of IO base pointer, door bell read and write pointer */
5522 /* mapping of IO base pointer */
5523 if (is_qla8022(ha)) {
5524 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5525 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5526 (ha->pdev->devfn << 11));
5527 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5528 QLA82XX_CAM_RAM_DB2);
5529 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5530 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5531 ((uint8_t *)ha->nx_pcibase);
5534 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5535 db_len = pci_resource_len(pdev, 4);
5543 * qla4xxx_iospace_config - maps registers
5544 * @ha: pointer to adapter structure
5546 * This routines maps HBA's registers from the pci address space
5547 * into the kernel virtual address space for memory mapped i/o.
5549 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5551 unsigned long pio, pio_len, pio_flags;
5552 unsigned long mmio, mmio_len, mmio_flags;
5554 pio = pci_resource_start(ha->pdev, 0);
5555 pio_len = pci_resource_len(ha->pdev, 0);
5556 pio_flags = pci_resource_flags(ha->pdev, 0);
5557 if (pio_flags & IORESOURCE_IO) {
5558 if (pio_len < MIN_IOBASE_LEN) {
5559 ql4_printk(KERN_WARNING, ha,
5560 "Invalid PCI I/O region size\n");
5564 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5568 /* Use MMIO operations for all accesses. */
5569 mmio = pci_resource_start(ha->pdev, 1);
5570 mmio_len = pci_resource_len(ha->pdev, 1);
5571 mmio_flags = pci_resource_flags(ha->pdev, 1);
5573 if (!(mmio_flags & IORESOURCE_MEM)) {
5574 ql4_printk(KERN_ERR, ha,
5575 "region #0 not an MMIO resource, aborting\n");
5577 goto iospace_error_exit;
5580 if (mmio_len < MIN_IOBASE_LEN) {
5581 ql4_printk(KERN_ERR, ha,
5582 "Invalid PCI mem region size, aborting\n");
5583 goto iospace_error_exit;
5586 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5587 ql4_printk(KERN_WARNING, ha,
5588 "Failed to reserve PIO/MMIO regions\n");
5590 goto iospace_error_exit;
5593 ha->pio_address = pio;
5594 ha->pio_length = pio_len;
5595 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5597 ql4_printk(KERN_ERR, ha,
5598 "cannot remap MMIO, aborting\n");
5600 goto iospace_error_exit;
5609 static struct isp_operations qla4xxx_isp_ops = {
5610 .iospace_config = qla4xxx_iospace_config,
5611 .pci_config = qla4xxx_pci_config,
5612 .disable_intrs = qla4xxx_disable_intrs,
5613 .enable_intrs = qla4xxx_enable_intrs,
5614 .start_firmware = qla4xxx_start_firmware,
5615 .intr_handler = qla4xxx_intr_handler,
5616 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5617 .reset_chip = qla4xxx_soft_reset,
5618 .reset_firmware = qla4xxx_hw_reset,
5619 .queue_iocb = qla4xxx_queue_iocb,
5620 .complete_iocb = qla4xxx_complete_iocb,
5621 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5622 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5623 .get_sys_info = qla4xxx_get_sys_info,
5624 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5625 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5628 static struct isp_operations qla4_82xx_isp_ops = {
5629 .iospace_config = qla4_8xxx_iospace_config,
5630 .pci_config = qla4_8xxx_pci_config,
5631 .disable_intrs = qla4_82xx_disable_intrs,
5632 .enable_intrs = qla4_82xx_enable_intrs,
5633 .start_firmware = qla4_8xxx_load_risc,
5634 .restart_firmware = qla4_82xx_try_start_fw,
5635 .intr_handler = qla4_82xx_intr_handler,
5636 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5637 .need_reset = qla4_8xxx_need_reset,
5638 .reset_chip = qla4_82xx_isp_reset,
5639 .reset_firmware = qla4_8xxx_stop_firmware,
5640 .queue_iocb = qla4_82xx_queue_iocb,
5641 .complete_iocb = qla4_82xx_complete_iocb,
5642 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5643 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5644 .get_sys_info = qla4_8xxx_get_sys_info,
5645 .rd_reg_direct = qla4_82xx_rd_32,
5646 .wr_reg_direct = qla4_82xx_wr_32,
5647 .rd_reg_indirect = qla4_82xx_md_rd_32,
5648 .wr_reg_indirect = qla4_82xx_md_wr_32,
5649 .idc_lock = qla4_82xx_idc_lock,
5650 .idc_unlock = qla4_82xx_idc_unlock,
5651 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5652 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5653 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5656 static struct isp_operations qla4_83xx_isp_ops = {
5657 .iospace_config = qla4_8xxx_iospace_config,
5658 .pci_config = qla4_8xxx_pci_config,
5659 .disable_intrs = qla4_83xx_disable_intrs,
5660 .enable_intrs = qla4_83xx_enable_intrs,
5661 .start_firmware = qla4_8xxx_load_risc,
5662 .restart_firmware = qla4_83xx_start_firmware,
5663 .intr_handler = qla4_83xx_intr_handler,
5664 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5665 .need_reset = qla4_8xxx_need_reset,
5666 .reset_chip = qla4_83xx_isp_reset,
5667 .reset_firmware = qla4_8xxx_stop_firmware,
5668 .queue_iocb = qla4_83xx_queue_iocb,
5669 .complete_iocb = qla4_83xx_complete_iocb,
5670 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5671 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5672 .get_sys_info = qla4_8xxx_get_sys_info,
5673 .rd_reg_direct = qla4_83xx_rd_reg,
5674 .wr_reg_direct = qla4_83xx_wr_reg,
5675 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5676 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5677 .idc_lock = qla4_83xx_drv_lock,
5678 .idc_unlock = qla4_83xx_drv_unlock,
5679 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5680 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5681 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5684 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5686 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5689 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5691 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5694 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5696 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5699 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5701 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5704 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5706 struct scsi_qla_host *ha = data;
5711 case ISCSI_BOOT_ETH_FLAGS:
5712 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5714 case ISCSI_BOOT_ETH_INDEX:
5715 rc = sprintf(str, "0\n");
5717 case ISCSI_BOOT_ETH_MAC:
5718 rc = sysfs_format_mac(str, ha->my_mac,
5728 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5733 case ISCSI_BOOT_ETH_FLAGS:
5734 case ISCSI_BOOT_ETH_MAC:
5735 case ISCSI_BOOT_ETH_INDEX:
5745 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5747 struct scsi_qla_host *ha = data;
5752 case ISCSI_BOOT_INI_INITIATOR_NAME:
5753 rc = sprintf(str, "%s\n", ha->name_string);
5762 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5767 case ISCSI_BOOT_INI_INITIATOR_NAME:
5778 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5781 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5786 case ISCSI_BOOT_TGT_NAME:
5787 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5789 case ISCSI_BOOT_TGT_IP_ADDR:
5790 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5791 rc = sprintf(buf, "%pI4\n",
5792 &boot_conn->dest_ipaddr.ip_address);
5794 rc = sprintf(str, "%pI6\n",
5795 &boot_conn->dest_ipaddr.ip_address);
5797 case ISCSI_BOOT_TGT_PORT:
5798 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5800 case ISCSI_BOOT_TGT_CHAP_NAME:
5801 rc = sprintf(str, "%.*s\n",
5802 boot_conn->chap.target_chap_name_length,
5803 (char *)&boot_conn->chap.target_chap_name);
5805 case ISCSI_BOOT_TGT_CHAP_SECRET:
5806 rc = sprintf(str, "%.*s\n",
5807 boot_conn->chap.target_secret_length,
5808 (char *)&boot_conn->chap.target_secret);
5810 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5811 rc = sprintf(str, "%.*s\n",
5812 boot_conn->chap.intr_chap_name_length,
5813 (char *)&boot_conn->chap.intr_chap_name);
5815 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5816 rc = sprintf(str, "%.*s\n",
5817 boot_conn->chap.intr_secret_length,
5818 (char *)&boot_conn->chap.intr_secret);
5820 case ISCSI_BOOT_TGT_FLAGS:
5821 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5823 case ISCSI_BOOT_TGT_NIC_ASSOC:
5824 rc = sprintf(str, "0\n");
5833 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5835 struct scsi_qla_host *ha = data;
5836 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5838 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5841 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5843 struct scsi_qla_host *ha = data;
5844 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5846 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5849 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5854 case ISCSI_BOOT_TGT_NAME:
5855 case ISCSI_BOOT_TGT_IP_ADDR:
5856 case ISCSI_BOOT_TGT_PORT:
5857 case ISCSI_BOOT_TGT_CHAP_NAME:
5858 case ISCSI_BOOT_TGT_CHAP_SECRET:
5859 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5860 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5861 case ISCSI_BOOT_TGT_NIC_ASSOC:
5862 case ISCSI_BOOT_TGT_FLAGS:
5872 static void qla4xxx_boot_release(void *data)
5874 struct scsi_qla_host *ha = data;
5876 scsi_host_put(ha->host);
5879 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5882 uint32_t addr, pri_addr, sec_addr;
5886 uint8_t *buf = NULL;
5887 size_t size = 13 * sizeof(uint8_t);
5888 int ret = QLA_SUCCESS;
5890 func_num = PCI_FUNC(ha->pdev->devfn);
5892 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5893 __func__, ha->pdev->device, func_num);
5895 if (is_qla40XX(ha)) {
5896 if (func_num == 1) {
5897 addr = NVRAM_PORT0_BOOT_MODE;
5898 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5899 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5900 } else if (func_num == 3) {
5901 addr = NVRAM_PORT1_BOOT_MODE;
5902 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5903 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5906 goto exit_boot_info;
5909 /* Check Boot Mode */
5910 val = rd_nvram_byte(ha, addr);
5911 if (!(val & 0x07)) {
5912 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5913 "options : 0x%x\n", __func__, val));
5915 goto exit_boot_info;
5918 /* get primary valid target index */
5919 val = rd_nvram_byte(ha, pri_addr);
5921 ddb_index[0] = (val & 0x7f);
5923 /* get secondary valid target index */
5924 val = rd_nvram_byte(ha, sec_addr);
5926 ddb_index[1] = (val & 0x7f);
5928 } else if (is_qla80XX(ha)) {
5929 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5930 &buf_dma, GFP_KERNEL);
5932 DEBUG2(ql4_printk(KERN_ERR, ha,
5933 "%s: Unable to allocate dma buffer\n",
5936 goto exit_boot_info;
5939 if (ha->port_num == 0)
5940 offset = BOOT_PARAM_OFFSET_PORT0;
5941 else if (ha->port_num == 1)
5942 offset = BOOT_PARAM_OFFSET_PORT1;
5945 goto exit_boot_info_free;
5947 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5949 if (qla4xxx_get_flash(ha, buf_dma, addr,
5950 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5951 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5952 " failed\n", ha->host_no, __func__));
5954 goto exit_boot_info_free;
5956 /* Check Boot Mode */
5957 if (!(buf[1] & 0x07)) {
5958 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5959 " : 0x%x\n", buf[1]));
5961 goto exit_boot_info_free;
5964 /* get primary valid target index */
5966 ddb_index[0] = buf[2] & 0x7f;
5968 /* get secondary valid target index */
5969 if (buf[11] & BIT_7)
5970 ddb_index[1] = buf[11] & 0x7f;
5973 goto exit_boot_info;
5976 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
5977 " target ID %d\n", __func__, ddb_index[0],
5980 exit_boot_info_free:
5981 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
5983 ha->pri_ddb_idx = ddb_index[0];
5984 ha->sec_ddb_idx = ddb_index[1];
5989 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
5990 * @ha: pointer to adapter structure
5991 * @username: CHAP username to be returned
5992 * @password: CHAP password to be returned
5994 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
5995 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
5996 * So from the CHAP cache find the first BIDI CHAP entry and set it
5997 * to the boot record in sysfs.
5999 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6002 int i, ret = -EINVAL;
6003 int max_chap_entries = 0;
6004 struct ql4_chap_table *chap_table;
6007 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6008 sizeof(struct ql4_chap_table);
6010 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6012 if (!ha->chap_list) {
6013 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6017 mutex_lock(&ha->chap_sem);
6018 for (i = 0; i < max_chap_entries; i++) {
6019 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6020 if (chap_table->cookie !=
6021 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6025 if (chap_table->flags & BIT_7) /* local */
6028 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6031 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6032 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6036 mutex_unlock(&ha->chap_sem);
6042 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6043 struct ql4_boot_session_info *boot_sess,
6046 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6047 struct dev_db_entry *fw_ddb_entry;
6048 dma_addr_t fw_ddb_entry_dma;
6051 int ret = QLA_SUCCESS;
6053 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6054 &fw_ddb_entry_dma, GFP_KERNEL);
6055 if (!fw_ddb_entry) {
6056 DEBUG2(ql4_printk(KERN_ERR, ha,
6057 "%s: Unable to allocate dma buffer.\n",
6063 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6064 fw_ddb_entry_dma, ddb_index)) {
6065 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6066 "index [%d]\n", __func__, ddb_index));
6068 goto exit_boot_target;
6071 /* Update target name and IP from DDB */
6072 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6073 min(sizeof(boot_sess->target_name),
6074 sizeof(fw_ddb_entry->iscsi_name)));
6076 options = le16_to_cpu(fw_ddb_entry->options);
6077 if (options & DDB_OPT_IPV6_DEVICE) {
6078 memcpy(&boot_conn->dest_ipaddr.ip_address,
6079 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6081 boot_conn->dest_ipaddr.ip_type = 0x1;
6082 memcpy(&boot_conn->dest_ipaddr.ip_address,
6083 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6086 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6088 /* update chap information */
6089 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6091 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6093 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6095 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6097 (char *)&boot_conn->chap.target_secret,
6100 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6102 goto exit_boot_target;
6105 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6106 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6109 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6111 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6113 ret = qla4xxx_get_bidi_chap(ha,
6114 (char *)&boot_conn->chap.intr_chap_name,
6115 (char *)&boot_conn->chap.intr_secret);
6118 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6120 goto exit_boot_target;
6123 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6124 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6128 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6129 fw_ddb_entry, fw_ddb_entry_dma);
6133 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6135 uint16_t ddb_index[2];
6136 int ret = QLA_ERROR;
6139 memset(ddb_index, 0, sizeof(ddb_index));
6140 ddb_index[0] = 0xffff;
6141 ddb_index[1] = 0xffff;
6142 ret = get_fw_boot_info(ha, ddb_index);
6143 if (ret != QLA_SUCCESS) {
6144 DEBUG2(ql4_printk(KERN_INFO, ha,
6145 "%s: No boot target configured.\n", __func__));
6149 if (ql4xdisablesysfsboot)
6152 if (ddb_index[0] == 0xffff)
6155 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6157 if (rval != QLA_SUCCESS) {
6158 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6159 "configured\n", __func__));
6164 if (ddb_index[1] == 0xffff)
6165 goto exit_get_boot_info;
6167 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6169 if (rval != QLA_SUCCESS) {
6170 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6171 " configured\n", __func__));
6179 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6181 struct iscsi_boot_kobj *boot_kobj;
6183 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6186 if (ql4xdisablesysfsboot) {
6187 ql4_printk(KERN_INFO, ha,
6188 "%s: syfsboot disabled - driver will trigger login "
6189 "and publish session for discovery .\n", __func__);
6194 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6198 if (!scsi_host_get(ha->host))
6200 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6201 qla4xxx_show_boot_tgt_pri_info,
6202 qla4xxx_tgt_get_attr_visibility,
6203 qla4xxx_boot_release);
6207 if (!scsi_host_get(ha->host))
6209 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6210 qla4xxx_show_boot_tgt_sec_info,
6211 qla4xxx_tgt_get_attr_visibility,
6212 qla4xxx_boot_release);
6216 if (!scsi_host_get(ha->host))
6218 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6219 qla4xxx_show_boot_ini_info,
6220 qla4xxx_ini_get_attr_visibility,
6221 qla4xxx_boot_release);
6225 if (!scsi_host_get(ha->host))
6227 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6228 qla4xxx_show_boot_eth_info,
6229 qla4xxx_eth_get_attr_visibility,
6230 qla4xxx_boot_release);
6237 scsi_host_put(ha->host);
6239 iscsi_boot_destroy_kset(ha->boot_kset);
6244 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6245 struct ql4_tuple_ddb *tddb)
6247 struct scsi_qla_host *ha;
6248 struct iscsi_cls_session *cls_sess;
6249 struct iscsi_cls_conn *cls_conn;
6250 struct iscsi_session *sess;
6251 struct iscsi_conn *conn;
6253 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6255 cls_sess = ddb_entry->sess;
6256 sess = cls_sess->dd_data;
6257 cls_conn = ddb_entry->conn;
6258 conn = cls_conn->dd_data;
6260 tddb->tpgt = sess->tpgt;
6261 tddb->port = conn->persistent_port;
6262 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6263 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6266 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6267 struct ql4_tuple_ddb *tddb,
6268 uint8_t *flash_isid)
6270 uint16_t options = 0;
6272 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6273 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6274 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6276 options = le16_to_cpu(fw_ddb_entry->options);
6277 if (options & DDB_OPT_IPV6_DEVICE)
6278 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6280 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6282 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6284 if (flash_isid == NULL)
6285 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6286 sizeof(tddb->isid));
6288 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6291 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6292 struct ql4_tuple_ddb *old_tddb,
6293 struct ql4_tuple_ddb *new_tddb,
6294 uint8_t is_isid_compare)
6296 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6299 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6302 if (old_tddb->port != new_tddb->port)
6305 /* For multi sessions, driver generates the ISID, so do not compare
6306 * ISID in reset path since it would be a comparison between the
6307 * driver generated ISID and firmware generated ISID. This could
6308 * lead to adding duplicated DDBs in the list as driver generated
6309 * ISID would not match firmware generated ISID.
6311 if (is_isid_compare) {
6312 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
6313 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
6314 __func__, old_tddb->isid[5], old_tddb->isid[4],
6315 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
6316 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
6317 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
6318 new_tddb->isid[0]));
6320 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6321 sizeof(old_tddb->isid)))
6325 DEBUG2(ql4_printk(KERN_INFO, ha,
6326 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6327 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6328 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6329 new_tddb->ip_addr, new_tddb->iscsi_name));
6334 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6335 struct dev_db_entry *fw_ddb_entry,
6338 struct ddb_entry *ddb_entry;
6339 struct ql4_tuple_ddb *fw_tddb = NULL;
6340 struct ql4_tuple_ddb *tmp_tddb = NULL;
6342 int ret = QLA_ERROR;
6344 fw_tddb = vzalloc(sizeof(*fw_tddb));
6346 DEBUG2(ql4_printk(KERN_WARNING, ha,
6347 "Memory Allocation failed.\n"));
6352 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6354 DEBUG2(ql4_printk(KERN_WARNING, ha,
6355 "Memory Allocation failed.\n"));
6360 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6362 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6363 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6364 if (ddb_entry == NULL)
6367 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6368 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6369 ret = QLA_SUCCESS; /* found */
6385 * qla4xxx_check_existing_isid - check if target with same isid exist
6387 * @list_nt: list of target
6388 * @isid: isid to check
6390 * This routine return QLA_SUCCESS if target with same isid exist
6392 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6394 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6395 struct dev_db_entry *fw_ddb_entry;
6397 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6398 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6400 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6401 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6409 * qla4xxx_update_isid - compare ddbs and updated isid
6410 * @ha: Pointer to host adapter structure.
6411 * @list_nt: list of nt target
6412 * @fw_ddb_entry: firmware ddb entry
6414 * This routine update isid if ddbs have same iqn, same isid and
6415 * different IP addr.
6416 * Return QLA_SUCCESS if isid is updated.
6418 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6419 struct list_head *list_nt,
6420 struct dev_db_entry *fw_ddb_entry)
6422 uint8_t base_value, i;
6424 base_value = fw_ddb_entry->isid[1] & 0x1f;
6425 for (i = 0; i < 8; i++) {
6426 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6427 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6431 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6438 * qla4xxx_should_update_isid - check if isid need to update
6439 * @ha: Pointer to host adapter structure.
6440 * @old_tddb: ddb tuple
6441 * @new_tddb: ddb tuple
6443 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6446 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6447 struct ql4_tuple_ddb *old_tddb,
6448 struct ql4_tuple_ddb *new_tddb)
6450 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6452 if (old_tddb->port == new_tddb->port)
6456 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6460 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6461 sizeof(old_tddb->isid)))
6462 /* different isid */
6469 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6470 * @ha: Pointer to host adapter structure.
6471 * @list_nt: list of nt target.
6472 * @fw_ddb_entry: firmware ddb entry.
6474 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6475 * duplicate ddb in list_nt.
6476 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6477 * Note: This function also update isid of DDB if required.
6480 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6481 struct list_head *list_nt,
6482 struct dev_db_entry *fw_ddb_entry)
6484 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6485 struct ql4_tuple_ddb *fw_tddb = NULL;
6486 struct ql4_tuple_ddb *tmp_tddb = NULL;
6487 int rval, ret = QLA_ERROR;
6489 fw_tddb = vzalloc(sizeof(*fw_tddb));
6491 DEBUG2(ql4_printk(KERN_WARNING, ha,
6492 "Memory Allocation failed.\n"));
6497 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6499 DEBUG2(ql4_printk(KERN_WARNING, ha,
6500 "Memory Allocation failed.\n"));
6505 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6507 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6508 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6509 nt_ddb_idx->flash_isid);
6510 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6511 /* found duplicate ddb */
6512 if (ret == QLA_SUCCESS)
6516 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6517 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6519 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6520 if (ret == QLA_SUCCESS) {
6521 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6522 if (rval == QLA_SUCCESS)
6539 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6541 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6543 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6544 list_del_init(&ddb_idx->list);
6549 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6550 struct dev_db_entry *fw_ddb_entry)
6552 struct iscsi_endpoint *ep;
6553 struct sockaddr_in *addr;
6554 struct sockaddr_in6 *addr6;
6555 struct sockaddr *t_addr;
6556 struct sockaddr_storage *dst_addr;
6559 /* TODO: need to destroy on unload iscsi_endpoint*/
6560 dst_addr = vmalloc(sizeof(*dst_addr));
6564 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6565 t_addr = (struct sockaddr *)dst_addr;
6566 t_addr->sa_family = AF_INET6;
6567 addr6 = (struct sockaddr_in6 *)dst_addr;
6568 ip = (char *)&addr6->sin6_addr;
6569 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6570 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6573 t_addr = (struct sockaddr *)dst_addr;
6574 t_addr->sa_family = AF_INET;
6575 addr = (struct sockaddr_in *)dst_addr;
6576 ip = (char *)&addr->sin_addr;
6577 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6578 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6581 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6586 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6588 if (ql4xdisablesysfsboot)
6590 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6595 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6596 struct ddb_entry *ddb_entry,
6599 uint16_t def_timeout;
6601 ddb_entry->ddb_type = FLASH_DDB;
6602 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6603 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6605 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6606 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6607 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6609 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6610 atomic_set(&ddb_entry->relogin_timer, 0);
6611 atomic_set(&ddb_entry->relogin_retry_count, 0);
6612 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6613 ddb_entry->default_relogin_timeout =
6614 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6615 def_timeout : LOGIN_TOV;
6616 ddb_entry->default_time2wait =
6617 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6619 if (ql4xdisablesysfsboot &&
6620 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6621 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6624 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6627 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6628 uint32_t sts[MBOX_REG_COUNT];
6630 unsigned long wtime;
6633 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6635 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6636 if (ip_idx[idx] == -1)
6639 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6641 if (ret == QLA_ERROR) {
6646 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6648 DEBUG2(ql4_printk(KERN_INFO, ha,
6649 "Waiting for IP state for idx = %d, state = 0x%x\n",
6650 ip_idx[idx], ip_state));
6651 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6652 ip_state == IP_ADDRSTATE_INVALID ||
6653 ip_state == IP_ADDRSTATE_PREFERRED ||
6654 ip_state == IP_ADDRSTATE_DEPRICATED ||
6655 ip_state == IP_ADDRSTATE_DISABLING)
6659 /* Break if all IP states checked */
6660 if ((ip_idx[0] == -1) &&
6661 (ip_idx[1] == -1) &&
6662 (ip_idx[2] == -1) &&
6665 schedule_timeout_uninterruptible(HZ);
6666 } while (time_after(wtime, jiffies));
6669 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6670 struct dev_db_entry *flash_ddb_entry)
6672 uint16_t options = 0;
6673 size_t ip_len = IP_ADDR_LEN;
6675 options = le16_to_cpu(fw_ddb_entry->options);
6676 if (options & DDB_OPT_IPV6_DEVICE)
6677 ip_len = IPv6_ADDR_LEN;
6679 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6682 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6683 sizeof(fw_ddb_entry->isid)))
6686 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6687 sizeof(fw_ddb_entry->port)))
6693 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6694 struct dev_db_entry *fw_ddb_entry,
6695 uint32_t fw_idx, uint32_t *flash_index)
6697 struct dev_db_entry *flash_ddb_entry;
6698 dma_addr_t flash_ddb_entry_dma;
6701 int ret = QLA_ERROR, status;
6703 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6706 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6707 &flash_ddb_entry_dma);
6708 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6709 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6710 goto exit_find_st_idx;
6713 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6714 flash_ddb_entry_dma, fw_idx);
6715 if (status == QLA_SUCCESS) {
6716 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6717 if (status == QLA_SUCCESS) {
6718 *flash_index = fw_idx;
6720 goto exit_find_st_idx;
6724 for (idx = 0; idx < max_ddbs; idx++) {
6725 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6726 flash_ddb_entry_dma, idx);
6727 if (status == QLA_ERROR)
6730 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6731 if (status == QLA_SUCCESS) {
6734 goto exit_find_st_idx;
6738 if (idx == max_ddbs)
6739 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6743 if (flash_ddb_entry)
6744 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6745 flash_ddb_entry_dma);
6750 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6751 struct list_head *list_st)
6753 struct qla_ddb_index *st_ddb_idx;
6756 struct dev_db_entry *fw_ddb_entry;
6757 dma_addr_t fw_ddb_dma;
6759 uint32_t idx = 0, next_idx = 0;
6760 uint32_t state = 0, conn_err = 0;
6761 uint32_t flash_index = -1;
6762 uint16_t conn_id = 0;
6764 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6766 if (fw_ddb_entry == NULL) {
6767 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6771 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6773 fw_idx_size = sizeof(struct qla_ddb_index);
6775 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6776 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6777 NULL, &next_idx, &state,
6778 &conn_err, NULL, &conn_id);
6779 if (ret == QLA_ERROR)
6782 /* Ignore DDB if invalid state (unassigned) */
6783 if (state == DDB_DS_UNASSIGNED)
6784 goto continue_next_st;
6786 /* Check if ST, add to the list_st */
6787 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6788 goto continue_next_st;
6790 st_ddb_idx = vzalloc(fw_idx_size);
6794 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6796 if (ret == QLA_ERROR) {
6797 ql4_printk(KERN_ERR, ha,
6798 "No flash entry for ST at idx [%d]\n", idx);
6799 st_ddb_idx->flash_ddb_idx = idx;
6801 ql4_printk(KERN_INFO, ha,
6802 "ST at idx [%d] is stored at flash [%d]\n",
6804 st_ddb_idx->flash_ddb_idx = flash_index;
6807 st_ddb_idx->fw_ddb_idx = idx;
6809 list_add_tail(&st_ddb_idx->list, list_st);
6817 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6821 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6822 * @ha: pointer to adapter structure
6823 * @list_ddb: List from which failed ddb to be removed
6825 * Iterate over the list of DDBs and find and remove DDBs that are either in
6826 * no connection active state or failed state
6828 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6829 struct list_head *list_ddb)
6831 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6832 uint32_t next_idx = 0;
6833 uint32_t state = 0, conn_err = 0;
6836 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6837 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6838 NULL, 0, NULL, &next_idx, &state,
6839 &conn_err, NULL, NULL);
6840 if (ret == QLA_ERROR)
6843 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6844 state == DDB_DS_SESSION_FAILED) {
6845 list_del_init(&ddb_idx->list);
6851 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6852 struct ddb_entry *ddb_entry,
6853 struct dev_db_entry *fw_ddb_entry)
6855 struct iscsi_cls_session *cls_sess;
6856 struct iscsi_session *sess;
6857 uint32_t max_ddbs = 0;
6858 uint16_t ddb_link = -1;
6860 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6863 cls_sess = ddb_entry->sess;
6864 sess = cls_sess->dd_data;
6866 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6867 if (ddb_link < max_ddbs)
6868 sess->discovery_parent_idx = ddb_link;
6870 sess->discovery_parent_idx = DDB_NO_LINK;
6873 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6874 struct dev_db_entry *fw_ddb_entry,
6875 int is_reset, uint16_t idx)
6877 struct iscsi_cls_session *cls_sess;
6878 struct iscsi_session *sess;
6879 struct iscsi_cls_conn *cls_conn;
6880 struct iscsi_endpoint *ep;
6881 uint16_t cmds_max = 32;
6882 uint16_t conn_id = 0;
6883 uint32_t initial_cmdsn = 0;
6884 int ret = QLA_SUCCESS;
6886 struct ddb_entry *ddb_entry = NULL;
6888 /* Create session object, with INVALID_ENTRY,
6889 * the targer_id would get set when we issue the login
6891 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6892 cmds_max, sizeof(struct ddb_entry),
6893 sizeof(struct ql4_task_data),
6894 initial_cmdsn, INVALID_ENTRY);
6901 * so calling module_put function to decrement the
6904 module_put(qla4xxx_iscsi_transport.owner);
6905 sess = cls_sess->dd_data;
6906 ddb_entry = sess->dd_data;
6907 ddb_entry->sess = cls_sess;
6909 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6910 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6911 sizeof(struct dev_db_entry));
6913 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6915 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6922 ddb_entry->conn = cls_conn;
6924 /* Setup ep, for displaying attributes in sysfs */
6925 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6927 ep->conn = cls_conn;
6930 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6935 /* Update sess/conn params */
6936 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6937 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6939 if (is_reset == RESET_ADAPTER) {
6940 iscsi_block_session(cls_sess);
6941 /* Use the relogin path to discover new devices
6942 * by short-circuting the logic of setting
6943 * timer to relogin - instead set the flags
6944 * to initiate login right away.
6946 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6947 set_bit(DF_RELOGIN, &ddb_entry->flags);
6954 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6955 struct list_head *list_ddb,
6956 struct dev_db_entry *fw_ddb_entry)
6958 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6961 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6963 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6964 if (ddb_idx->fw_ddb_idx == ddb_link) {
6965 DEBUG2(ql4_printk(KERN_INFO, ha,
6966 "Updating NT parent idx from [%d] to [%d]\n",
6967 ddb_link, ddb_idx->flash_ddb_idx));
6968 fw_ddb_entry->ddb_link =
6969 cpu_to_le16(ddb_idx->flash_ddb_idx);
6975 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
6976 struct list_head *list_nt,
6977 struct list_head *list_st,
6980 struct dev_db_entry *fw_ddb_entry;
6981 struct ddb_entry *ddb_entry = NULL;
6982 dma_addr_t fw_ddb_dma;
6986 uint32_t idx = 0, next_idx = 0;
6987 uint32_t state = 0, conn_err = 0;
6988 uint32_t ddb_idx = -1;
6989 uint16_t conn_id = 0;
6990 uint16_t ddb_link = -1;
6991 struct qla_ddb_index *nt_ddb_idx;
6993 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6995 if (fw_ddb_entry == NULL) {
6996 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6999 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7001 fw_idx_size = sizeof(struct qla_ddb_index);
7003 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7004 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7005 NULL, &next_idx, &state,
7006 &conn_err, NULL, &conn_id);
7007 if (ret == QLA_ERROR)
7010 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7011 goto continue_next_nt;
7013 /* Check if NT, then add to list it */
7014 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7015 goto continue_next_nt;
7017 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7018 if (ddb_link < max_ddbs)
7019 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7021 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7022 state == DDB_DS_SESSION_FAILED) &&
7023 (is_reset == INIT_ADAPTER))
7024 goto continue_next_nt;
7026 DEBUG2(ql4_printk(KERN_INFO, ha,
7027 "Adding DDB to session = 0x%x\n", idx));
7029 if (is_reset == INIT_ADAPTER) {
7030 nt_ddb_idx = vmalloc(fw_idx_size);
7034 nt_ddb_idx->fw_ddb_idx = idx;
7036 /* Copy original isid as it may get updated in function
7037 * qla4xxx_update_isid(). We need original isid in
7038 * function qla4xxx_compare_tuple_ddb to find duplicate
7040 memcpy(&nt_ddb_idx->flash_isid[0],
7041 &fw_ddb_entry->isid[0],
7042 sizeof(nt_ddb_idx->flash_isid));
7044 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7046 if (ret == QLA_SUCCESS) {
7047 /* free nt_ddb_idx and do not add to list_nt */
7049 goto continue_next_nt;
7052 /* Copy updated isid */
7053 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7054 sizeof(struct dev_db_entry));
7056 list_add_tail(&nt_ddb_idx->list, list_nt);
7057 } else if (is_reset == RESET_ADAPTER) {
7058 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7060 if (ret == QLA_SUCCESS) {
7061 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7063 if (ddb_entry != NULL)
7064 qla4xxx_update_sess_disc_idx(ha,
7067 goto continue_next_nt;
7071 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7072 if (ret == QLA_ERROR)
7082 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7085 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7086 struct list_head *list_nt,
7089 struct dev_db_entry *fw_ddb_entry;
7090 dma_addr_t fw_ddb_dma;
7094 uint32_t idx = 0, next_idx = 0;
7095 uint32_t state = 0, conn_err = 0;
7096 uint16_t conn_id = 0;
7097 struct qla_ddb_index *nt_ddb_idx;
7099 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7101 if (fw_ddb_entry == NULL) {
7102 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7103 goto exit_new_nt_list;
7105 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7107 fw_idx_size = sizeof(struct qla_ddb_index);
7109 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7110 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7111 NULL, &next_idx, &state,
7112 &conn_err, NULL, &conn_id);
7113 if (ret == QLA_ERROR)
7116 /* Check if NT, then add it to list */
7117 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7118 goto continue_next_new_nt;
7120 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7121 goto continue_next_new_nt;
7123 DEBUG2(ql4_printk(KERN_INFO, ha,
7124 "Adding DDB to session = 0x%x\n", idx));
7126 nt_ddb_idx = vmalloc(fw_idx_size);
7130 nt_ddb_idx->fw_ddb_idx = idx;
7132 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7133 if (ret == QLA_SUCCESS) {
7134 /* free nt_ddb_idx and do not add to list_nt */
7136 goto continue_next_new_nt;
7139 if (target_id < max_ddbs)
7140 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7142 list_add_tail(&nt_ddb_idx->list, list_nt);
7144 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7146 if (ret == QLA_ERROR)
7147 goto exit_new_nt_list;
7149 continue_next_new_nt:
7156 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7160 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7161 * @dev: dev associated with the sysfs entry
7162 * @data: pointer to flashnode session object
7165 * 1: if flashnode entry is non-persistent
7166 * 0: if flashnode entry is persistent
7168 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7170 struct iscsi_bus_flash_session *fnode_sess;
7172 if (!iscsi_flashnode_bus_match(dev, NULL))
7175 fnode_sess = iscsi_dev_to_flash_session(dev);
7177 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7181 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7182 * @ha: pointer to host
7183 * @fw_ddb_entry: flash ddb data
7184 * @idx: target index
7185 * @user: if set then this call is made from userland else from kernel
7188 * On sucess: QLA_SUCCESS
7189 * On failure: QLA_ERROR
7191 * This create separate sysfs entries for session and connection attributes of
7192 * the given fw ddb entry.
7193 * If this is invoked as a result of a userspace call then the entry is marked
7194 * as nonpersistent using flash_state field.
7196 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7197 struct dev_db_entry *fw_ddb_entry,
7198 uint16_t *idx, int user)
7200 struct iscsi_bus_flash_session *fnode_sess = NULL;
7201 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7204 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7205 &qla4xxx_iscsi_transport, 0);
7207 ql4_printk(KERN_ERR, ha,
7208 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7209 __func__, *idx, ha->host_no);
7210 goto exit_tgt_create;
7213 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7214 &qla4xxx_iscsi_transport, 0);
7216 ql4_printk(KERN_ERR, ha,
7217 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7218 __func__, *idx, ha->host_no);
7223 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7225 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7227 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7228 fnode_sess->is_boot_target = 1;
7230 fnode_sess->is_boot_target = 0;
7233 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7236 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7237 __func__, fnode_sess->dev.kobj.name);
7239 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7240 __func__, fnode_conn->dev.kobj.name);
7245 iscsi_destroy_flashnode_sess(fnode_sess);
7252 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7253 * @shost: pointer to host
7254 * @buf: type of ddb entry (ipv4/ipv6)
7255 * @len: length of buf
7257 * This creates new ddb entry in the flash by finding first free index and
7258 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7260 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7263 struct scsi_qla_host *ha = to_qla_host(shost);
7264 struct dev_db_entry *fw_ddb_entry = NULL;
7265 dma_addr_t fw_ddb_entry_dma;
7268 uint16_t max_ddbs = 0;
7269 uint32_t options = 0;
7270 uint32_t rval = QLA_ERROR;
7272 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7273 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7274 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7279 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7282 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7283 &fw_ddb_entry_dma, GFP_KERNEL);
7284 if (!fw_ddb_entry) {
7285 DEBUG2(ql4_printk(KERN_ERR, ha,
7286 "%s: Unable to allocate dma buffer\n",
7291 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7292 qla4xxx_sysfs_ddb_is_non_persistent);
7294 ql4_printk(KERN_ERR, ha,
7295 "%s: A non-persistent entry %s found\n",
7296 __func__, dev->kobj.name);
7301 /* Index 0 and 1 are reserved for boot target entries */
7302 for (idx = 2; idx < max_ddbs; idx++) {
7303 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7304 fw_ddb_entry_dma, idx))
7308 if (idx == max_ddbs)
7311 if (!strncasecmp("ipv6", buf, 4))
7312 options |= IPV6_DEFAULT_DDB_ENTRY;
7314 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7315 if (rval == QLA_ERROR)
7318 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7322 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7323 fw_ddb_entry, fw_ddb_entry_dma);
7324 if (rval == QLA_SUCCESS)
7331 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7332 * @fnode_sess: pointer to session attrs of flash ddb entry
7333 * @fnode_conn: pointer to connection attrs of flash ddb entry
7335 * This writes the contents of target ddb buffer to Flash with a valid cookie
7336 * value in order to make the ddb entry persistent.
7338 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7339 struct iscsi_bus_flash_conn *fnode_conn)
7341 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7342 struct scsi_qla_host *ha = to_qla_host(shost);
7343 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7344 struct dev_db_entry *fw_ddb_entry = NULL;
7345 dma_addr_t fw_ddb_entry_dma;
7346 uint32_t options = 0;
7349 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7350 &fw_ddb_entry_dma, GFP_KERNEL);
7351 if (!fw_ddb_entry) {
7352 DEBUG2(ql4_printk(KERN_ERR, ha,
7353 "%s: Unable to allocate dma buffer\n",
7356 goto exit_ddb_apply;
7359 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7360 options |= IPV6_DEFAULT_DDB_ENTRY;
7362 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7363 if (rval == QLA_ERROR)
7364 goto exit_ddb_apply;
7366 dev_db_start_offset += (fnode_sess->target_id *
7367 sizeof(*fw_ddb_entry));
7369 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7370 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7372 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7373 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7375 if (rval == QLA_SUCCESS) {
7376 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7377 ql4_printk(KERN_INFO, ha,
7378 "%s: flash node %u of host %lu written to flash\n",
7379 __func__, fnode_sess->target_id, ha->host_no);
7382 ql4_printk(KERN_ERR, ha,
7383 "%s: Error while writing flash node %u of host %lu to flash\n",
7384 __func__, fnode_sess->target_id, ha->host_no);
7389 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7390 fw_ddb_entry, fw_ddb_entry_dma);
7394 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7395 struct dev_db_entry *fw_ddb_entry,
7398 struct dev_db_entry *ddb_entry = NULL;
7399 dma_addr_t ddb_entry_dma;
7400 unsigned long wtime;
7401 uint32_t mbx_sts = 0;
7402 uint32_t state = 0, conn_err = 0;
7406 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7407 &ddb_entry_dma, GFP_KERNEL);
7409 DEBUG2(ql4_printk(KERN_ERR, ha,
7410 "%s: Unable to allocate dma buffer\n",
7415 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7417 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7418 if (ret != QLA_SUCCESS) {
7419 DEBUG2(ql4_printk(KERN_ERR, ha,
7420 "%s: Unable to set ddb entry for index %d\n",
7422 goto exit_ddb_conn_open;
7425 qla4xxx_conn_open(ha, idx);
7427 /* To ensure that sendtargets is done, wait for at least 12 secs */
7428 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7429 (ha->def_timeout < LOGIN_TOV * 10) ?
7430 ha->def_timeout : LOGIN_TOV);
7432 DEBUG2(ql4_printk(KERN_INFO, ha,
7433 "Default time to wait for login to ddb %d\n", tmo));
7435 wtime = jiffies + (HZ * tmo);
7437 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7438 NULL, &state, &conn_err, NULL,
7440 if (ret == QLA_ERROR)
7443 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7444 state == DDB_DS_SESSION_FAILED)
7447 schedule_timeout_uninterruptible(HZ / 10);
7448 } while (time_after(wtime, jiffies));
7452 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7453 ddb_entry, ddb_entry_dma);
7457 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7458 struct dev_db_entry *fw_ddb_entry,
7461 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7462 struct list_head list_nt;
7466 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7467 ql4_printk(KERN_WARNING, ha,
7468 "%s: A discovery already in progress!\n", __func__);
7472 INIT_LIST_HEAD(&list_nt);
7474 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7476 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7477 if (ret == QLA_ERROR)
7478 goto exit_login_st_clr_bit;
7480 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7481 if (ret == QLA_ERROR)
7484 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7486 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7487 list_del_init(&ddb_idx->list);
7488 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7493 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7494 ql4_printk(KERN_ERR, ha,
7495 "Unable to clear DDB index = 0x%x\n", ddb_index);
7498 clear_bit(ddb_index, ha->ddb_idx_map);
7500 exit_login_st_clr_bit:
7501 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7505 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7506 struct dev_db_entry *fw_ddb_entry,
7509 int ret = QLA_ERROR;
7511 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7512 if (ret != QLA_SUCCESS)
7513 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7522 * qla4xxx_sysfs_ddb_login - Login to the specified target
7523 * @fnode_sess: pointer to session attrs of flash ddb entry
7524 * @fnode_conn: pointer to connection attrs of flash ddb entry
7526 * This logs in to the specified target
7528 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7529 struct iscsi_bus_flash_conn *fnode_conn)
7531 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7532 struct scsi_qla_host *ha = to_qla_host(shost);
7533 struct dev_db_entry *fw_ddb_entry = NULL;
7534 dma_addr_t fw_ddb_entry_dma;
7535 uint32_t options = 0;
7538 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7539 ql4_printk(KERN_ERR, ha,
7540 "%s: Target info is not persistent\n", __func__);
7542 goto exit_ddb_login;
7545 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7546 &fw_ddb_entry_dma, GFP_KERNEL);
7547 if (!fw_ddb_entry) {
7548 DEBUG2(ql4_printk(KERN_ERR, ha,
7549 "%s: Unable to allocate dma buffer\n",
7552 goto exit_ddb_login;
7555 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7556 options |= IPV6_DEFAULT_DDB_ENTRY;
7558 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7559 if (ret == QLA_ERROR)
7560 goto exit_ddb_login;
7562 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7563 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7565 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7566 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7567 fnode_sess->target_id);
7569 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7570 fnode_sess->target_id);
7577 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7578 fw_ddb_entry, fw_ddb_entry_dma);
7583 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7584 * @cls_sess: pointer to session to be logged out
7586 * This performs session log out from the specified target
7588 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7590 struct iscsi_session *sess;
7591 struct ddb_entry *ddb_entry = NULL;
7592 struct scsi_qla_host *ha;
7593 struct dev_db_entry *fw_ddb_entry = NULL;
7594 dma_addr_t fw_ddb_entry_dma;
7595 unsigned long flags;
7596 unsigned long wtime;
7601 sess = cls_sess->dd_data;
7602 ddb_entry = sess->dd_data;
7605 if (ddb_entry->ddb_type != FLASH_DDB) {
7606 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7609 goto exit_ddb_logout;
7612 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7613 ql4_printk(KERN_ERR, ha,
7614 "%s: Logout from boot target entry is not permitted.\n",
7617 goto exit_ddb_logout;
7620 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7621 &fw_ddb_entry_dma, GFP_KERNEL);
7622 if (!fw_ddb_entry) {
7623 ql4_printk(KERN_ERR, ha,
7624 "%s: Unable to allocate dma buffer\n", __func__);
7626 goto exit_ddb_logout;
7629 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7630 goto ddb_logout_init;
7632 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7633 fw_ddb_entry, fw_ddb_entry_dma,
7634 NULL, NULL, &ddb_state, NULL,
7636 if (ret == QLA_ERROR)
7637 goto ddb_logout_init;
7639 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7640 goto ddb_logout_init;
7642 /* wait until next relogin is triggered using DF_RELOGIN and
7643 * clear DF_RELOGIN to avoid invocation of further relogin
7645 wtime = jiffies + (HZ * RELOGIN_TOV);
7647 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7648 goto ddb_logout_init;
7650 schedule_timeout_uninterruptible(HZ);
7651 } while ((time_after(wtime, jiffies)));
7654 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7655 atomic_set(&ddb_entry->relogin_timer, 0);
7657 options = LOGOUT_OPTION_CLOSE_SESSION;
7658 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7660 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7661 wtime = jiffies + (HZ * LOGOUT_TOV);
7663 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7664 fw_ddb_entry, fw_ddb_entry_dma,
7665 NULL, NULL, &ddb_state, NULL,
7667 if (ret == QLA_ERROR)
7668 goto ddb_logout_clr_sess;
7670 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7671 (ddb_state == DDB_DS_SESSION_FAILED))
7672 goto ddb_logout_clr_sess;
7674 schedule_timeout_uninterruptible(HZ);
7675 } while ((time_after(wtime, jiffies)));
7677 ddb_logout_clr_sess:
7678 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7680 * we have decremented the reference count of the driver
7681 * when we setup the session to have the driver unload
7682 * to be seamless without actually destroying the
7685 try_module_get(qla4xxx_iscsi_transport.owner);
7686 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7688 spin_lock_irqsave(&ha->hardware_lock, flags);
7689 qla4xxx_free_ddb(ha, ddb_entry);
7690 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7691 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7693 iscsi_session_teardown(ddb_entry->sess);
7695 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7700 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7701 fw_ddb_entry, fw_ddb_entry_dma);
7706 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7707 * @fnode_sess: pointer to session attrs of flash ddb entry
7708 * @fnode_conn: pointer to connection attrs of flash ddb entry
7710 * This performs log out from the specified target
7712 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7713 struct iscsi_bus_flash_conn *fnode_conn)
7715 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7716 struct scsi_qla_host *ha = to_qla_host(shost);
7717 struct ql4_tuple_ddb *flash_tddb = NULL;
7718 struct ql4_tuple_ddb *tmp_tddb = NULL;
7719 struct dev_db_entry *fw_ddb_entry = NULL;
7720 struct ddb_entry *ddb_entry = NULL;
7721 dma_addr_t fw_ddb_dma;
7722 uint32_t next_idx = 0;
7723 uint32_t state = 0, conn_err = 0;
7724 uint16_t conn_id = 0;
7726 int status, ret = 0;
7728 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7730 if (fw_ddb_entry == NULL) {
7731 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7733 goto exit_ddb_logout;
7736 flash_tddb = vzalloc(sizeof(*flash_tddb));
7738 ql4_printk(KERN_WARNING, ha,
7739 "%s:Memory Allocation failed.\n", __func__);
7741 goto exit_ddb_logout;
7744 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7746 ql4_printk(KERN_WARNING, ha,
7747 "%s:Memory Allocation failed.\n", __func__);
7749 goto exit_ddb_logout;
7752 if (!fnode_sess->targetname) {
7753 ql4_printk(KERN_ERR, ha,
7754 "%s:Cannot logout from SendTarget entry\n",
7757 goto exit_ddb_logout;
7760 if (fnode_sess->is_boot_target) {
7761 ql4_printk(KERN_ERR, ha,
7762 "%s: Logout from boot target entry is not permitted.\n",
7765 goto exit_ddb_logout;
7768 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7771 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7772 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7774 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7776 flash_tddb->tpgt = fnode_sess->tpgt;
7777 flash_tddb->port = fnode_conn->port;
7779 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7781 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7782 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7783 if (ddb_entry == NULL)
7786 if (ddb_entry->ddb_type != FLASH_DDB)
7789 index = ddb_entry->sess->target_id;
7790 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7791 fw_ddb_dma, NULL, &next_idx,
7792 &state, &conn_err, NULL,
7794 if (status == QLA_ERROR) {
7799 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7801 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7803 if (status == QLA_SUCCESS) {
7804 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7809 if (idx == MAX_DDB_ENTRIES)
7818 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7824 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7825 int param, char *buf)
7827 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7828 struct scsi_qla_host *ha = to_qla_host(shost);
7829 struct iscsi_bus_flash_conn *fnode_conn;
7830 struct ql4_chap_table chap_tbl;
7835 dev = iscsi_find_flashnode_conn(fnode_sess);
7839 fnode_conn = iscsi_dev_to_flash_conn(dev);
7842 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7843 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7845 case ISCSI_FLASHNODE_PORTAL_TYPE:
7846 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7848 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7849 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7851 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7852 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7854 case ISCSI_FLASHNODE_ENTRY_EN:
7855 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7857 case ISCSI_FLASHNODE_HDR_DGST_EN:
7858 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7860 case ISCSI_FLASHNODE_DATA_DGST_EN:
7861 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7863 case ISCSI_FLASHNODE_IMM_DATA_EN:
7864 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7866 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7867 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7869 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7870 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7872 case ISCSI_FLASHNODE_PDU_INORDER:
7873 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7875 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7876 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7878 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7879 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7881 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7882 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7884 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7885 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7887 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7888 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7890 case ISCSI_FLASHNODE_ERL:
7891 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7893 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7894 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7896 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7897 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7899 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7900 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7902 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7903 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7905 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7906 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7908 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7909 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7911 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7912 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7914 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7915 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7917 case ISCSI_FLASHNODE_FIRST_BURST:
7918 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7920 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7921 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7923 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7924 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7926 case ISCSI_FLASHNODE_MAX_R2T:
7927 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7929 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7930 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7932 case ISCSI_FLASHNODE_ISID:
7933 rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
7934 fnode_sess->isid[0], fnode_sess->isid[1],
7935 fnode_sess->isid[2], fnode_sess->isid[3],
7936 fnode_sess->isid[4], fnode_sess->isid[5]);
7938 case ISCSI_FLASHNODE_TSID:
7939 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7941 case ISCSI_FLASHNODE_PORT:
7942 rc = sprintf(buf, "%d\n", fnode_conn->port);
7944 case ISCSI_FLASHNODE_MAX_BURST:
7945 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7947 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7948 rc = sprintf(buf, "%u\n",
7949 fnode_sess->default_taskmgmt_timeout);
7951 case ISCSI_FLASHNODE_IPADDR:
7952 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7953 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7955 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7957 case ISCSI_FLASHNODE_ALIAS:
7958 if (fnode_sess->targetalias)
7959 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7961 rc = sprintf(buf, "\n");
7963 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7964 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7965 rc = sprintf(buf, "%pI6\n",
7966 fnode_conn->redirect_ipaddr);
7968 rc = sprintf(buf, "%pI4\n",
7969 fnode_conn->redirect_ipaddr);
7971 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7972 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7974 case ISCSI_FLASHNODE_LOCAL_PORT:
7975 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
7977 case ISCSI_FLASHNODE_IPV4_TOS:
7978 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
7980 case ISCSI_FLASHNODE_IPV6_TC:
7981 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7982 rc = sprintf(buf, "%u\n",
7983 fnode_conn->ipv6_traffic_class);
7985 rc = sprintf(buf, "\n");
7987 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
7988 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
7990 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
7991 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7992 rc = sprintf(buf, "%pI6\n",
7993 fnode_conn->link_local_ipv6_addr);
7995 rc = sprintf(buf, "\n");
7997 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
7998 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8000 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8001 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8002 parent_type = ISCSI_DISC_PARENT_ISNS;
8003 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8004 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8005 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8006 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8008 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8010 rc = sprintf(buf, "%s\n",
8011 iscsi_get_discovery_parent_name(parent_type));
8013 case ISCSI_FLASHNODE_NAME:
8014 if (fnode_sess->targetname)
8015 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8017 rc = sprintf(buf, "\n");
8019 case ISCSI_FLASHNODE_TPGT:
8020 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8022 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8023 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8025 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8026 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8028 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8029 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8031 case ISCSI_FLASHNODE_USERNAME:
8032 if (fnode_sess->chap_auth_en) {
8033 qla4xxx_get_uni_chap_at_index(ha,
8036 fnode_sess->chap_out_idx);
8037 rc = sprintf(buf, "%s\n", chap_tbl.name);
8039 rc = sprintf(buf, "\n");
8042 case ISCSI_FLASHNODE_PASSWORD:
8043 if (fnode_sess->chap_auth_en) {
8044 qla4xxx_get_uni_chap_at_index(ha,
8047 fnode_sess->chap_out_idx);
8048 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8050 rc = sprintf(buf, "\n");
8053 case ISCSI_FLASHNODE_STATSN:
8054 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8056 case ISCSI_FLASHNODE_EXP_STATSN:
8057 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8059 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8060 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8072 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8073 * @fnode_sess: pointer to session attrs of flash ddb entry
8074 * @fnode_conn: pointer to connection attrs of flash ddb entry
8075 * @data: Parameters and their values to update
8078 * This sets the parameter of flash ddb entry and writes them to flash
8081 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8082 struct iscsi_bus_flash_conn *fnode_conn,
8083 void *data, int len)
8085 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8086 struct scsi_qla_host *ha = to_qla_host(shost);
8087 struct iscsi_flashnode_param_info *fnode_param;
8088 struct ql4_chap_table chap_tbl;
8089 struct nlattr *attr;
8090 uint16_t chap_out_idx = INVALID_ENTRY;
8094 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8095 nla_for_each_attr(attr, data, len, rem) {
8096 fnode_param = nla_data(attr);
8098 switch (fnode_param->param) {
8099 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8100 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8102 case ISCSI_FLASHNODE_PORTAL_TYPE:
8103 memcpy(fnode_sess->portal_type, fnode_param->value,
8104 strlen(fnode_sess->portal_type));
8106 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8107 fnode_sess->auto_snd_tgt_disable =
8108 fnode_param->value[0];
8110 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8111 fnode_sess->discovery_sess = fnode_param->value[0];
8113 case ISCSI_FLASHNODE_ENTRY_EN:
8114 fnode_sess->entry_state = fnode_param->value[0];
8116 case ISCSI_FLASHNODE_HDR_DGST_EN:
8117 fnode_conn->hdrdgst_en = fnode_param->value[0];
8119 case ISCSI_FLASHNODE_DATA_DGST_EN:
8120 fnode_conn->datadgst_en = fnode_param->value[0];
8122 case ISCSI_FLASHNODE_IMM_DATA_EN:
8123 fnode_sess->imm_data_en = fnode_param->value[0];
8125 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8126 fnode_sess->initial_r2t_en = fnode_param->value[0];
8128 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8129 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8131 case ISCSI_FLASHNODE_PDU_INORDER:
8132 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8134 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8135 fnode_sess->chap_auth_en = fnode_param->value[0];
8136 /* Invalidate chap index if chap auth is disabled */
8137 if (!fnode_sess->chap_auth_en)
8138 fnode_sess->chap_out_idx = INVALID_ENTRY;
8141 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8142 fnode_conn->snack_req_en = fnode_param->value[0];
8144 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8145 fnode_sess->discovery_logout_en = fnode_param->value[0];
8147 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8148 fnode_sess->bidi_chap_en = fnode_param->value[0];
8150 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8151 fnode_sess->discovery_auth_optional =
8152 fnode_param->value[0];
8154 case ISCSI_FLASHNODE_ERL:
8155 fnode_sess->erl = fnode_param->value[0];
8157 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8158 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8160 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8161 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8163 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8164 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8166 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8167 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8169 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8170 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8172 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8173 fnode_conn->fragment_disable = fnode_param->value[0];
8175 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8176 fnode_conn->max_recv_dlength =
8177 *(unsigned *)fnode_param->value;
8179 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8180 fnode_conn->max_xmit_dlength =
8181 *(unsigned *)fnode_param->value;
8183 case ISCSI_FLASHNODE_FIRST_BURST:
8184 fnode_sess->first_burst =
8185 *(unsigned *)fnode_param->value;
8187 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8188 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8190 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8191 fnode_sess->time2retain =
8192 *(uint16_t *)fnode_param->value;
8194 case ISCSI_FLASHNODE_MAX_R2T:
8195 fnode_sess->max_r2t =
8196 *(uint16_t *)fnode_param->value;
8198 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8199 fnode_conn->keepalive_timeout =
8200 *(uint16_t *)fnode_param->value;
8202 case ISCSI_FLASHNODE_ISID:
8203 memcpy(fnode_sess->isid, fnode_param->value,
8204 sizeof(fnode_sess->isid));
8206 case ISCSI_FLASHNODE_TSID:
8207 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8209 case ISCSI_FLASHNODE_PORT:
8210 fnode_conn->port = *(uint16_t *)fnode_param->value;
8212 case ISCSI_FLASHNODE_MAX_BURST:
8213 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8215 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8216 fnode_sess->default_taskmgmt_timeout =
8217 *(uint16_t *)fnode_param->value;
8219 case ISCSI_FLASHNODE_IPADDR:
8220 memcpy(fnode_conn->ipaddress, fnode_param->value,
8223 case ISCSI_FLASHNODE_ALIAS:
8224 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8225 (char *)fnode_param->value);
8227 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8228 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8231 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8232 fnode_conn->max_segment_size =
8233 *(unsigned *)fnode_param->value;
8235 case ISCSI_FLASHNODE_LOCAL_PORT:
8236 fnode_conn->local_port =
8237 *(uint16_t *)fnode_param->value;
8239 case ISCSI_FLASHNODE_IPV4_TOS:
8240 fnode_conn->ipv4_tos = fnode_param->value[0];
8242 case ISCSI_FLASHNODE_IPV6_TC:
8243 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8245 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8246 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8248 case ISCSI_FLASHNODE_NAME:
8249 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8250 (char *)fnode_param->value);
8252 case ISCSI_FLASHNODE_TPGT:
8253 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8255 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8256 memcpy(fnode_conn->link_local_ipv6_addr,
8257 fnode_param->value, IPv6_ADDR_LEN);
8259 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8260 fnode_sess->discovery_parent_idx =
8261 *(uint16_t *)fnode_param->value;
8263 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8264 fnode_conn->tcp_xmit_wsf =
8265 *(uint8_t *)fnode_param->value;
8267 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8268 fnode_conn->tcp_recv_wsf =
8269 *(uint8_t *)fnode_param->value;
8271 case ISCSI_FLASHNODE_STATSN:
8272 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8274 case ISCSI_FLASHNODE_EXP_STATSN:
8275 fnode_conn->exp_statsn =
8276 *(uint32_t *)fnode_param->value;
8278 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8279 chap_out_idx = *(uint16_t *)fnode_param->value;
8280 if (!qla4xxx_get_uni_chap_at_index(ha,
8284 fnode_sess->chap_out_idx = chap_out_idx;
8285 /* Enable chap auth if chap index is valid */
8286 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8290 ql4_printk(KERN_ERR, ha,
8291 "%s: No such sysfs attribute\n", __func__);
8293 goto exit_set_param;
8297 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8304 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8305 * @fnode_sess: pointer to session attrs of flash ddb entry
8307 * This invalidates the flash ddb entry at the given index
8309 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8311 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8312 struct scsi_qla_host *ha = to_qla_host(shost);
8313 uint32_t dev_db_start_offset;
8314 uint32_t dev_db_end_offset;
8315 struct dev_db_entry *fw_ddb_entry = NULL;
8316 dma_addr_t fw_ddb_entry_dma;
8317 uint16_t *ddb_cookie = NULL;
8318 size_t ddb_size = 0;
8323 if (fnode_sess->is_boot_target) {
8325 DEBUG2(ql4_printk(KERN_ERR, ha,
8326 "%s: Deletion of boot target entry is not permitted.\n",
8331 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8334 if (is_qla40XX(ha)) {
8335 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8336 dev_db_end_offset = FLASH_OFFSET_DB_END;
8337 dev_db_start_offset += (fnode_sess->target_id *
8338 sizeof(*fw_ddb_entry));
8339 ddb_size = sizeof(*fw_ddb_entry);
8341 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8342 (ha->hw.flt_region_ddb << 2);
8343 /* flt_ddb_size is DDB table size for both ports
8344 * so divide it by 2 to calculate the offset for second port
8346 if (ha->port_num == 1)
8347 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8349 dev_db_end_offset = dev_db_start_offset +
8350 (ha->hw.flt_ddb_size / 2);
8352 dev_db_start_offset += (fnode_sess->target_id *
8353 sizeof(*fw_ddb_entry));
8354 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8356 ddb_size = sizeof(*ddb_cookie);
8359 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8360 __func__, dev_db_start_offset, dev_db_end_offset));
8362 if (dev_db_start_offset > dev_db_end_offset) {
8364 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8365 __func__, fnode_sess->target_id));
8369 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8370 &fw_ddb_entry_dma, GFP_KERNEL);
8373 DEBUG2(ql4_printk(KERN_ERR, ha,
8374 "%s: Unable to allocate dma buffer\n",
8379 if (is_qla40XX(ha)) {
8380 fw_ddb_entry = pddb;
8381 memset(fw_ddb_entry, 0, ddb_size);
8382 ddb_cookie = &fw_ddb_entry->cookie;
8387 /* invalidate the cookie */
8388 *ddb_cookie = 0xFFEE;
8389 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8390 ddb_size, FLASH_OPT_RMW_COMMIT);
8393 target_id = fnode_sess->target_id;
8394 iscsi_destroy_flashnode_sess(fnode_sess);
8395 ql4_printk(KERN_INFO, ha,
8396 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8397 __func__, target_id, ha->host_no);
8400 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8406 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8407 * @ha: pointer to adapter structure
8409 * Export the firmware DDB for all send targets and normal targets to sysfs.
8411 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8413 struct dev_db_entry *fw_ddb_entry = NULL;
8414 dma_addr_t fw_ddb_entry_dma;
8417 int ret = QLA_SUCCESS;
8419 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8420 sizeof(*fw_ddb_entry),
8421 &fw_ddb_entry_dma, GFP_KERNEL);
8422 if (!fw_ddb_entry) {
8423 DEBUG2(ql4_printk(KERN_ERR, ha,
8424 "%s: Unable to allocate dma buffer\n",
8429 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8432 for (idx = 0; idx < max_ddbs; idx++) {
8433 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8437 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8444 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8450 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8452 iscsi_destroy_all_flashnode(ha->host);
8456 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8457 * @ha: pointer to adapter structure
8458 * @is_reset: Is this init path or reset path
8460 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8461 * using connection open, then create the list of normal targets (nt)
8462 * from firmware DDBs. Based on the list of nt setup session and connection
8465 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8468 struct list_head list_st, list_nt;
8469 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8470 unsigned long wtime;
8472 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8473 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8474 ha->is_reset = is_reset;
8478 INIT_LIST_HEAD(&list_st);
8479 INIT_LIST_HEAD(&list_nt);
8481 qla4xxx_build_st_list(ha, &list_st);
8483 /* Before issuing conn open mbox, ensure all IPs states are configured
8484 * Note, conn open fails if IPs are not configured
8486 qla4xxx_wait_for_ip_configuration(ha);
8488 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8489 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8490 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8493 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8494 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8495 (ha->def_timeout < LOGIN_TOV * 10) ?
8496 ha->def_timeout : LOGIN_TOV);
8498 DEBUG2(ql4_printk(KERN_INFO, ha,
8499 "Default time to wait for build ddb %d\n", tmo));
8501 wtime = jiffies + (HZ * tmo);
8503 if (list_empty(&list_st))
8506 qla4xxx_remove_failed_ddb(ha, &list_st);
8507 schedule_timeout_uninterruptible(HZ / 10);
8508 } while (time_after(wtime, jiffies));
8511 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8513 qla4xxx_free_ddb_list(&list_st);
8514 qla4xxx_free_ddb_list(&list_nt);
8516 qla4xxx_free_ddb_index(ha);
8520 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8522 * @ha: pointer to adapter structure
8524 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8525 * set in DDB and we will wait for login response of boot targets during
8528 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8530 struct ddb_entry *ddb_entry;
8531 struct dev_db_entry *fw_ddb_entry = NULL;
8532 dma_addr_t fw_ddb_entry_dma;
8533 unsigned long wtime;
8535 int max_ddbs, idx, ret;
8537 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8540 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8541 &fw_ddb_entry_dma, GFP_KERNEL);
8542 if (!fw_ddb_entry) {
8543 ql4_printk(KERN_ERR, ha,
8544 "%s: Unable to allocate dma buffer\n", __func__);
8545 goto exit_login_resp;
8548 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8550 for (idx = 0; idx < max_ddbs; idx++) {
8551 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8552 if (ddb_entry == NULL)
8555 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8556 DEBUG2(ql4_printk(KERN_INFO, ha,
8557 "%s: DDB index [%d]\n", __func__,
8558 ddb_entry->fw_ddb_index));
8560 ret = qla4xxx_get_fwddb_entry(ha,
8561 ddb_entry->fw_ddb_index,
8562 fw_ddb_entry, fw_ddb_entry_dma,
8563 NULL, NULL, &ddb_state, NULL,
8565 if (ret == QLA_ERROR)
8566 goto exit_login_resp;
8568 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8569 (ddb_state == DDB_DS_SESSION_FAILED))
8572 schedule_timeout_uninterruptible(HZ);
8574 } while ((time_after(wtime, jiffies)));
8576 if (!time_after(wtime, jiffies)) {
8577 DEBUG2(ql4_printk(KERN_INFO, ha,
8578 "%s: Login response wait timer expired\n",
8580 goto exit_login_resp;
8587 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8588 fw_ddb_entry, fw_ddb_entry_dma);
8592 * qla4xxx_probe_adapter - callback function to probe HBA
8593 * @pdev: pointer to pci_dev structure
8594 * @pci_device_id: pointer to pci_device entry
8596 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8597 * It returns zero if successful. It also initializes all data necessary for
8600 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8601 const struct pci_device_id *ent)
8603 int ret = -ENODEV, status;
8604 struct Scsi_Host *host;
8605 struct scsi_qla_host *ha;
8606 uint8_t init_retry_count = 0;
8608 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8611 if (pci_enable_device(pdev))
8614 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8617 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8618 goto probe_disable_device;
8621 /* Clear our data area */
8622 ha = to_qla_host(host);
8623 memset(ha, 0, sizeof(*ha));
8625 /* Save the information from PCI BIOS. */
8628 ha->host_no = host->host_no;
8629 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8631 pci_enable_pcie_error_reporting(pdev);
8633 /* Setup Runtime configurable options */
8634 if (is_qla8022(ha)) {
8635 ha->isp_ops = &qla4_82xx_isp_ops;
8636 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8637 ha->qdr_sn_window = -1;
8638 ha->ddr_mn_window = -1;
8639 ha->curr_window = 255;
8640 nx_legacy_intr = &legacy_intr[ha->func_num];
8641 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8642 ha->nx_legacy_intr.tgt_status_reg =
8643 nx_legacy_intr->tgt_status_reg;
8644 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8645 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8646 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8647 ha->isp_ops = &qla4_83xx_isp_ops;
8648 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8650 ha->isp_ops = &qla4xxx_isp_ops;
8653 if (is_qla80XX(ha)) {
8654 rwlock_init(&ha->hw_lock);
8655 ha->pf_bit = ha->func_num << 16;
8656 /* Set EEH reset type to fundamental if required by hba */
8657 pdev->needs_freset = 1;
8660 /* Configure PCI I/O space. */
8661 ret = ha->isp_ops->iospace_config(ha);
8663 goto probe_failed_ioconfig;
8665 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8666 pdev->device, pdev->irq, ha->reg);
8668 qla4xxx_config_dma_addressing(ha);
8670 /* Initialize lists and spinlocks. */
8671 INIT_LIST_HEAD(&ha->free_srb_q);
8673 mutex_init(&ha->mbox_sem);
8674 mutex_init(&ha->chap_sem);
8675 init_completion(&ha->mbx_intr_comp);
8676 init_completion(&ha->disable_acb_comp);
8677 init_completion(&ha->idc_comp);
8678 init_completion(&ha->link_up_comp);
8679 init_completion(&ha->disable_acb_comp);
8681 spin_lock_init(&ha->hardware_lock);
8682 spin_lock_init(&ha->work_lock);
8684 /* Initialize work list */
8685 INIT_LIST_HEAD(&ha->work_list);
8687 /* Allocate dma buffers */
8688 if (qla4xxx_mem_alloc(ha)) {
8689 ql4_printk(KERN_WARNING, ha,
8690 "[ERROR] Failed to allocate memory for adapter\n");
8696 host->cmd_per_lun = 3;
8697 host->max_channel = 0;
8698 host->max_lun = MAX_LUNS - 1;
8699 host->max_id = MAX_TARGETS;
8700 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8701 host->can_queue = MAX_SRBS ;
8702 host->transportt = qla4xxx_scsi_transport;
8704 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
8706 ql4_printk(KERN_WARNING, ha,
8707 "%s: scsi_init_shared_tag_map failed\n", __func__);
8711 pci_set_drvdata(pdev, ha);
8713 ret = scsi_add_host(host, &pdev->dev);
8718 qla4_8xxx_get_flash_info(ha);
8720 if (is_qla8032(ha) || is_qla8042(ha)) {
8721 qla4_83xx_read_reset_template(ha);
8723 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8724 * If DONRESET_BIT0 is set, drivers should not set dev_state
8725 * to NEED_RESET. But if NEED_RESET is set, drivers should
8726 * should honor the reset.
8728 if (ql4xdontresethba == 1)
8729 qla4_83xx_set_idc_dontreset(ha);
8733 * Initialize the Host adapter request/response queues and
8735 * NOTE: interrupts enabled upon successful completion
8737 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8739 /* Dont retry adapter initialization if IRQ allocation failed */
8740 if (is_qla80XX(ha) && (status == QLA_ERROR))
8741 goto skip_retry_init;
8743 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8744 init_retry_count++ < MAX_INIT_RETRIES) {
8746 if (is_qla80XX(ha)) {
8747 ha->isp_ops->idc_lock(ha);
8748 dev_state = qla4_8xxx_rd_direct(ha,
8749 QLA8XXX_CRB_DEV_STATE);
8750 ha->isp_ops->idc_unlock(ha);
8751 if (dev_state == QLA8XXX_DEV_FAILED) {
8752 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8753 "initialize adapter. H/W is in failed state\n",
8758 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8759 "(%d)\n", __func__, init_retry_count));
8761 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8764 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8765 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8766 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8767 goto skip_retry_init;
8772 if (!test_bit(AF_ONLINE, &ha->flags)) {
8773 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8775 if ((is_qla8022(ha) && ql4xdontresethba) ||
8776 ((is_qla8032(ha) || is_qla8042(ha)) &&
8777 qla4_83xx_idc_dontreset(ha))) {
8778 /* Put the device in failed state. */
8779 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8780 ha->isp_ops->idc_lock(ha);
8781 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8782 QLA8XXX_DEV_FAILED);
8783 ha->isp_ops->idc_unlock(ha);
8789 /* Startup the kernel thread for this host adapter. */
8790 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8791 "qla4xxx_dpc\n", __func__));
8792 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8793 ha->dpc_thread = create_singlethread_workqueue(buf);
8794 if (!ha->dpc_thread) {
8795 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8799 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8801 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8804 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8810 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8811 * (which is called indirectly by qla4xxx_initialize_adapter),
8812 * so that irqs will be registered after crbinit but before
8815 if (is_qla40XX(ha)) {
8816 ret = qla4xxx_request_irqs(ha);
8818 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8819 "interrupt %d already in use.\n", pdev->irq);
8824 pci_save_state(ha->pdev);
8825 ha->isp_ops->enable_intrs(ha);
8827 /* Start timer thread. */
8828 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
8830 set_bit(AF_INIT_DONE, &ha->flags);
8832 qla4_8xxx_alloc_sysfs_attr(ha);
8835 " QLogic iSCSI HBA Driver version: %s\n"
8836 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8837 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8838 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8839 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8841 /* Set the driver version */
8843 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8845 if (qla4xxx_setup_boot_info(ha))
8846 ql4_printk(KERN_ERR, ha,
8847 "%s: No iSCSI boot target configured\n", __func__);
8849 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8850 /* Perform the build ddb list and login to each */
8851 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8852 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8853 qla4xxx_wait_login_resp_boot_tgt(ha);
8855 qla4xxx_create_chap_list(ha);
8857 qla4xxx_create_ifaces(ha);
8861 scsi_remove_host(ha->host);
8864 qla4xxx_free_adapter(ha);
8866 probe_failed_ioconfig:
8867 pci_disable_pcie_error_reporting(pdev);
8868 scsi_host_put(ha->host);
8870 probe_disable_device:
8871 pci_disable_device(pdev);
8877 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8878 * @ha: pointer to adapter structure
8880 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8881 * so that the other port will not re-initialize while in the process of
8882 * removing the ha due to driver unload or hba hotplug.
8884 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8886 struct scsi_qla_host *other_ha = NULL;
8887 struct pci_dev *other_pdev = NULL;
8888 int fn = ISP4XXX_PCI_FN_2;
8890 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8891 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8892 fn = ISP4XXX_PCI_FN_1;
8895 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8896 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8899 /* Get other_ha if other_pdev is valid and state is enable*/
8901 if (atomic_read(&other_pdev->enable_cnt)) {
8902 other_ha = pci_get_drvdata(other_pdev);
8904 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8905 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8906 "Prevent %s reinit\n", __func__,
8907 dev_name(&other_ha->pdev->dev)));
8910 pci_dev_put(other_pdev);
8914 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8915 struct ddb_entry *ddb_entry)
8917 struct dev_db_entry *fw_ddb_entry = NULL;
8918 dma_addr_t fw_ddb_entry_dma;
8919 unsigned long wtime;
8924 options = LOGOUT_OPTION_CLOSE_SESSION;
8925 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8926 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8930 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8931 &fw_ddb_entry_dma, GFP_KERNEL);
8932 if (!fw_ddb_entry) {
8933 ql4_printk(KERN_ERR, ha,
8934 "%s: Unable to allocate dma buffer\n", __func__);
8938 wtime = jiffies + (HZ * LOGOUT_TOV);
8940 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8941 fw_ddb_entry, fw_ddb_entry_dma,
8942 NULL, NULL, &ddb_state, NULL,
8944 if (status == QLA_ERROR)
8947 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8948 (ddb_state == DDB_DS_SESSION_FAILED))
8951 schedule_timeout_uninterruptible(HZ);
8952 } while ((time_after(wtime, jiffies)));
8955 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8956 fw_ddb_entry, fw_ddb_entry_dma);
8958 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8961 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8963 struct ddb_entry *ddb_entry;
8966 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8968 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8969 if ((ddb_entry != NULL) &&
8970 (ddb_entry->ddb_type == FLASH_DDB)) {
8972 qla4xxx_destroy_ddb(ha, ddb_entry);
8974 * we have decremented the reference count of the driver
8975 * when we setup the session to have the driver unload
8976 * to be seamless without actually destroying the
8979 try_module_get(qla4xxx_iscsi_transport.owner);
8980 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8981 qla4xxx_free_ddb(ha, ddb_entry);
8982 iscsi_session_teardown(ddb_entry->sess);
8987 * qla4xxx_remove_adapter - callback function to remove adapter.
8988 * @pci_dev: PCI device pointer
8990 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
8992 struct scsi_qla_host *ha;
8995 * If the PCI device is disabled then it means probe_adapter had
8996 * failed and resources already cleaned up on probe_adapter exit.
8998 if (!pci_is_enabled(pdev))
9001 ha = pci_get_drvdata(pdev);
9004 qla4xxx_prevent_other_port_reinit(ha);
9006 /* destroy iface from sysfs */
9007 qla4xxx_destroy_ifaces(ha);
9009 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9010 iscsi_boot_destroy_kset(ha->boot_kset);
9012 qla4xxx_destroy_fw_ddb_session(ha);
9013 qla4_8xxx_free_sysfs_attr(ha);
9015 qla4xxx_sysfs_ddb_remove(ha);
9016 scsi_remove_host(ha->host);
9018 qla4xxx_free_adapter(ha);
9020 scsi_host_put(ha->host);
9022 pci_disable_pcie_error_reporting(pdev);
9023 pci_disable_device(pdev);
9027 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9030 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
9031 * supported addressing method.
9033 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9037 /* Update our PCI device dma_mask for full 64 bit mask */
9038 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
9039 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
9040 dev_dbg(&ha->pdev->dev,
9041 "Failed to set 64 bit PCI consistent mask; "
9043 retval = pci_set_consistent_dma_mask(ha->pdev,
9047 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
9050 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9052 struct iscsi_cls_session *cls_sess;
9053 struct iscsi_session *sess;
9054 struct ddb_entry *ddb;
9055 int queue_depth = QL4_DEF_QDEPTH;
9057 cls_sess = starget_to_session(sdev->sdev_target);
9058 sess = cls_sess->dd_data;
9059 ddb = sess->dd_data;
9061 sdev->hostdata = ddb;
9062 sdev->tagged_supported = 1;
9064 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9065 queue_depth = ql4xmaxqdepth;
9067 scsi_adjust_queue_depth(sdev, 0, queue_depth);
9071 static int qla4xxx_slave_configure(struct scsi_device *sdev)
9073 sdev->tagged_supported = 1;
9077 static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
9080 if (!ql4xqfulltracking)
9083 return iscsi_change_queue_depth(sdev, qdepth, reason);
9087 * qla4xxx_del_from_active_array - returns an active srb
9088 * @ha: Pointer to host adapter structure.
9089 * @index: index into the active_array
9091 * This routine removes and returns the srb at the specified index
9093 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9096 struct srb *srb = NULL;
9097 struct scsi_cmnd *cmd = NULL;
9099 cmd = scsi_host_find_tag(ha->host, index);
9103 srb = (struct srb *)CMD_SP(cmd);
9107 /* update counters */
9108 if (srb->flags & SRB_DMA_VALID) {
9109 ha->iocb_cnt -= srb->iocb_cnt;
9111 srb->cmd->host_scribble =
9112 (unsigned char *)(unsigned long) MAX_SRBS;
9118 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9119 * @ha: Pointer to host adapter structure.
9120 * @cmd: Scsi Command to wait on.
9122 * This routine waits for the command to be returned by the Firmware
9123 * for some max time.
9125 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9126 struct scsi_cmnd *cmd)
9130 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9133 /* Dont wait on command if PCI error is being handled
9136 if (unlikely(pci_channel_offline(ha->pdev)) ||
9137 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9138 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9139 ha->host_no, __func__);
9144 /* Checking to see if its returned to OS */
9145 rp = (struct srb *) CMD_SP(cmd);
9152 } while (max_wait_time--);
9158 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9159 * @ha: Pointer to host adapter structure
9161 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9163 unsigned long wait_online;
9165 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9166 while (time_before(jiffies, wait_online)) {
9178 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9179 * @ha: pointer to HBA
9183 * This function waits for all outstanding commands to a lun to complete. It
9184 * returns 0 if all pending commands are returned and 1 otherwise.
9186 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9187 struct scsi_target *stgt,
9188 struct scsi_device *sdev)
9192 struct scsi_cmnd *cmd;
9195 * Waiting for all commands for the designated target or dev
9196 * in the active array
9198 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9199 cmd = scsi_host_find_tag(ha->host, cnt);
9200 if (cmd && stgt == scsi_target(cmd->device) &&
9201 (!sdev || sdev == cmd->device)) {
9202 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9212 * qla4xxx_eh_abort - callback for abort task.
9213 * @cmd: Pointer to Linux's SCSI command structure
9215 * This routine is called by the Linux OS to abort the specified
9218 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9220 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9221 unsigned int id = cmd->device->id;
9222 uint64_t lun = cmd->device->lun;
9223 unsigned long flags;
9224 struct srb *srb = NULL;
9228 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9229 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9231 spin_lock_irqsave(&ha->hardware_lock, flags);
9232 srb = (struct srb *) CMD_SP(cmd);
9234 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9235 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9236 ha->host_no, id, lun);
9239 kref_get(&srb->srb_ref);
9240 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9242 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9243 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9244 ha->host_no, id, lun));
9247 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9248 ha->host_no, id, lun));
9252 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9254 /* Wait for command to complete */
9256 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9257 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9258 ha->host_no, id, lun));
9263 ql4_printk(KERN_INFO, ha,
9264 "scsi%ld:%d:%llu: Abort command - %s\n",
9265 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9271 * qla4xxx_eh_device_reset - callback for target reset.
9272 * @cmd: Pointer to Linux's SCSI command structure
9274 * This routine is called by the Linux OS to reset all luns on the
9277 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9279 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9280 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9281 int ret = FAILED, stat;
9286 ret = iscsi_block_scsi_eh(cmd);
9291 ql4_printk(KERN_INFO, ha,
9292 "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
9293 cmd->device->channel, cmd->device->id, cmd->device->lun);
9295 DEBUG2(printk(KERN_INFO
9296 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
9297 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
9298 cmd, jiffies, cmd->request->timeout / HZ,
9299 ha->dpc_flags, cmd->result, cmd->allowed));
9301 /* FIXME: wait for hba to go online */
9302 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9303 if (stat != QLA_SUCCESS) {
9304 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9305 goto eh_dev_reset_done;
9308 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9310 ql4_printk(KERN_INFO, ha,
9311 "DEVICE RESET FAILED - waiting for "
9313 goto eh_dev_reset_done;
9317 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9318 MM_LUN_RESET) != QLA_SUCCESS)
9319 goto eh_dev_reset_done;
9321 ql4_printk(KERN_INFO, ha,
9322 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9323 ha->host_no, cmd->device->channel, cmd->device->id,
9334 * qla4xxx_eh_target_reset - callback for target reset.
9335 * @cmd: Pointer to Linux's SCSI command structure
9337 * This routine is called by the Linux OS to reset the target.
9339 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9341 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9342 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9348 ret = iscsi_block_scsi_eh(cmd);
9352 starget_printk(KERN_INFO, scsi_target(cmd->device),
9353 "WARM TARGET RESET ISSUED.\n");
9355 DEBUG2(printk(KERN_INFO
9356 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9357 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9358 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9359 ha->dpc_flags, cmd->result, cmd->allowed));
9361 stat = qla4xxx_reset_target(ha, ddb_entry);
9362 if (stat != QLA_SUCCESS) {
9363 starget_printk(KERN_INFO, scsi_target(cmd->device),
9364 "WARM TARGET RESET FAILED.\n");
9368 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9370 starget_printk(KERN_INFO, scsi_target(cmd->device),
9371 "WARM TARGET DEVICE RESET FAILED - "
9372 "waiting for commands.\n");
9377 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9378 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9379 starget_printk(KERN_INFO, scsi_target(cmd->device),
9380 "WARM TARGET DEVICE RESET FAILED - "
9381 "marker iocb failed.\n");
9385 starget_printk(KERN_INFO, scsi_target(cmd->device),
9386 "WARM TARGET RESET SUCCEEDED.\n");
9391 * qla4xxx_is_eh_active - check if error handler is running
9392 * @shost: Pointer to SCSI Host struct
9394 * This routine finds that if reset host is called in EH
9395 * scenario or from some application like sg_reset
9397 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9399 if (shost->shost_state == SHOST_RECOVERY)
9405 * qla4xxx_eh_host_reset - kernel callback
9406 * @cmd: Pointer to Linux's SCSI command structure
9408 * This routine is invoked by the Linux kernel to perform fatal error
9409 * recovery on the specified adapter.
9411 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9413 int return_status = FAILED;
9414 struct scsi_qla_host *ha;
9416 ha = to_qla_host(cmd->device->host);
9418 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9419 qla4_83xx_set_idc_dontreset(ha);
9422 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9423 * protocol drivers, we should not set device_state to NEED_RESET
9425 if (ql4xdontresethba ||
9426 ((is_qla8032(ha) || is_qla8042(ha)) &&
9427 qla4_83xx_idc_dontreset(ha))) {
9428 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9429 ha->host_no, __func__));
9431 /* Clear outstanding srb in queues */
9432 if (qla4xxx_is_eh_active(cmd->device->host))
9433 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9438 ql4_printk(KERN_INFO, ha,
9439 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9440 cmd->device->channel, cmd->device->id, cmd->device->lun);
9442 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9443 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9444 "DEAD.\n", ha->host_no, cmd->device->channel,
9450 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9452 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9454 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9457 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9458 return_status = SUCCESS;
9460 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9461 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9463 return return_status;
9466 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9468 uint32_t mbox_cmd[MBOX_REG_COUNT];
9469 uint32_t mbox_sts[MBOX_REG_COUNT];
9470 struct addr_ctrl_blk_def *acb = NULL;
9471 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9472 int rval = QLA_SUCCESS;
9475 acb = dma_alloc_coherent(&ha->pdev->dev,
9476 sizeof(struct addr_ctrl_blk_def),
9477 &acb_dma, GFP_KERNEL);
9479 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9482 goto exit_port_reset;
9485 memset(acb, 0, acb_len);
9487 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9488 if (rval != QLA_SUCCESS) {
9493 rval = qla4xxx_disable_acb(ha);
9494 if (rval != QLA_SUCCESS) {
9499 wait_for_completion_timeout(&ha->disable_acb_comp,
9500 DISABLE_ACB_TOV * HZ);
9502 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9503 if (rval != QLA_SUCCESS) {
9509 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9512 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9513 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9517 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9519 struct scsi_qla_host *ha = to_qla_host(shost);
9520 int rval = QLA_SUCCESS;
9523 if (ql4xdontresethba) {
9524 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9527 goto exit_host_reset;
9530 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9531 goto recover_adapter;
9533 switch (reset_type) {
9534 case SCSI_ADAPTER_RESET:
9535 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9537 case SCSI_FIRMWARE_RESET:
9538 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9540 /* set firmware context reset */
9541 set_bit(DPC_RESET_HA_FW_CONTEXT,
9544 rval = qla4xxx_context_reset(ha);
9545 goto exit_host_reset;
9552 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9553 * reset is issued by application */
9554 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9555 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9556 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9557 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9558 (idc_ctrl | GRACEFUL_RESET_BIT1));
9561 rval = qla4xxx_recover_adapter(ha);
9562 if (rval != QLA_SUCCESS) {
9563 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9572 /* PCI AER driver recovers from all correctable errors w/o
9573 * driver intervention. For uncorrectable errors PCI AER
9574 * driver calls the following device driver's callbacks
9576 * - Fatal Errors - link_reset
9577 * - Non-Fatal Errors - driver's pci_error_detected() which
9578 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9580 * PCI AER driver calls
9581 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
9582 * returns RECOVERED or NEED_RESET if fw_hung
9583 * NEED_RESET - driver's slot_reset()
9584 * DISCONNECT - device is dead & cannot recover
9585 * RECOVERED - driver's pci_resume()
9587 static pci_ers_result_t
9588 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9590 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9592 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9593 ha->host_no, __func__, state);
9595 if (!is_aer_supported(ha))
9596 return PCI_ERS_RESULT_NONE;
9599 case pci_channel_io_normal:
9600 clear_bit(AF_EEH_BUSY, &ha->flags);
9601 return PCI_ERS_RESULT_CAN_RECOVER;
9602 case pci_channel_io_frozen:
9603 set_bit(AF_EEH_BUSY, &ha->flags);
9604 qla4xxx_mailbox_premature_completion(ha);
9605 qla4xxx_free_irqs(ha);
9606 pci_disable_device(pdev);
9607 /* Return back all IOs */
9608 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9609 return PCI_ERS_RESULT_NEED_RESET;
9610 case pci_channel_io_perm_failure:
9611 set_bit(AF_EEH_BUSY, &ha->flags);
9612 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9613 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9614 return PCI_ERS_RESULT_DISCONNECT;
9616 return PCI_ERS_RESULT_NEED_RESET;
9620 * qla4xxx_pci_mmio_enabled() gets called if
9621 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9622 * and read/write to the device still works.
9624 static pci_ers_result_t
9625 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9627 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9629 if (!is_aer_supported(ha))
9630 return PCI_ERS_RESULT_NONE;
9632 return PCI_ERS_RESULT_RECOVERED;
9635 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9637 uint32_t rval = QLA_ERROR;
9639 struct pci_dev *other_pdev = NULL;
9641 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9643 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9645 if (test_bit(AF_ONLINE, &ha->flags)) {
9646 clear_bit(AF_ONLINE, &ha->flags);
9647 clear_bit(AF_LINK_UP, &ha->flags);
9648 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9649 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9652 fn = PCI_FUNC(ha->pdev->devfn);
9653 if (is_qla8022(ha)) {
9656 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9657 ha->host_no, __func__, fn);
9658 /* Get the pci device given the domain, bus,
9659 * slot/function number */
9660 other_pdev = pci_get_domain_bus_and_slot(
9661 pci_domain_nr(ha->pdev->bus),
9662 ha->pdev->bus->number,
9663 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9669 if (atomic_read(&other_pdev->enable_cnt)) {
9670 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9671 ha->host_no, __func__, fn);
9672 pci_dev_put(other_pdev);
9675 pci_dev_put(other_pdev);
9678 /* this case is meant for ISP83xx/ISP84xx only */
9679 if (qla4_83xx_can_perform_reset(ha)) {
9680 /* reset fn as iSCSI is going to perform the reset */
9685 /* The first function on the card, the reset owner will
9686 * start & initialize the firmware. The other functions
9687 * on the card will reset the firmware context
9690 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9691 "0x%x is the owner\n", ha->host_no, __func__,
9694 ha->isp_ops->idc_lock(ha);
9695 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9697 ha->isp_ops->idc_unlock(ha);
9699 rval = qla4_8xxx_update_idc_reg(ha);
9700 if (rval == QLA_ERROR) {
9701 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9702 ha->host_no, __func__);
9703 ha->isp_ops->idc_lock(ha);
9704 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9705 QLA8XXX_DEV_FAILED);
9706 ha->isp_ops->idc_unlock(ha);
9707 goto exit_error_recovery;
9710 clear_bit(AF_FW_RECOVERY, &ha->flags);
9711 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9713 if (rval != QLA_SUCCESS) {
9714 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9715 "FAILED\n", ha->host_no, __func__);
9716 qla4xxx_free_irqs(ha);
9717 ha->isp_ops->idc_lock(ha);
9718 qla4_8xxx_clear_drv_active(ha);
9719 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9720 QLA8XXX_DEV_FAILED);
9721 ha->isp_ops->idc_unlock(ha);
9723 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9724 "READY\n", ha->host_no, __func__);
9725 ha->isp_ops->idc_lock(ha);
9726 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9728 /* Clear driver state register */
9729 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9730 qla4_8xxx_set_drv_active(ha);
9731 ha->isp_ops->idc_unlock(ha);
9732 ha->isp_ops->enable_intrs(ha);
9735 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9736 "the reset owner\n", ha->host_no, __func__,
9738 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9739 QLA8XXX_DEV_READY)) {
9740 clear_bit(AF_FW_RECOVERY, &ha->flags);
9741 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9742 if (rval == QLA_SUCCESS)
9743 ha->isp_ops->enable_intrs(ha);
9745 qla4xxx_free_irqs(ha);
9747 ha->isp_ops->idc_lock(ha);
9748 qla4_8xxx_set_drv_active(ha);
9749 ha->isp_ops->idc_unlock(ha);
9752 exit_error_recovery:
9753 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9757 static pci_ers_result_t
9758 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9760 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9761 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9764 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9765 ha->host_no, __func__);
9767 if (!is_aer_supported(ha))
9768 return PCI_ERS_RESULT_NONE;
9770 /* Restore the saved state of PCIe device -
9771 * BAR registers, PCI Config space, PCIX, MSI,
9774 pci_restore_state(pdev);
9776 /* pci_restore_state() clears the saved_state flag of the device
9777 * save restored state which resets saved_state flag
9779 pci_save_state(pdev);
9781 /* Initialize device or resume if in suspended state */
9782 rc = pci_enable_device(pdev);
9784 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9785 "device after reset\n", ha->host_no, __func__);
9786 goto exit_slot_reset;
9789 ha->isp_ops->disable_intrs(ha);
9791 if (is_qla80XX(ha)) {
9792 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9793 ret = PCI_ERS_RESULT_RECOVERED;
9794 goto exit_slot_reset;
9796 goto exit_slot_reset;
9800 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9801 "device after reset\n", ha->host_no, __func__, ret);
9806 qla4xxx_pci_resume(struct pci_dev *pdev)
9808 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9811 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9812 ha->host_no, __func__);
9814 ret = qla4xxx_wait_for_hba_online(ha);
9815 if (ret != QLA_SUCCESS) {
9816 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9817 "resume I/O from slot/link_reset\n", ha->host_no,
9821 pci_cleanup_aer_uncorrect_error_status(pdev);
9822 clear_bit(AF_EEH_BUSY, &ha->flags);
9825 static const struct pci_error_handlers qla4xxx_err_handler = {
9826 .error_detected = qla4xxx_pci_error_detected,
9827 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9828 .slot_reset = qla4xxx_pci_slot_reset,
9829 .resume = qla4xxx_pci_resume,
9832 static struct pci_device_id qla4xxx_pci_tbl[] = {
9834 .vendor = PCI_VENDOR_ID_QLOGIC,
9835 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9836 .subvendor = PCI_ANY_ID,
9837 .subdevice = PCI_ANY_ID,
9840 .vendor = PCI_VENDOR_ID_QLOGIC,
9841 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9842 .subvendor = PCI_ANY_ID,
9843 .subdevice = PCI_ANY_ID,
9846 .vendor = PCI_VENDOR_ID_QLOGIC,
9847 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9848 .subvendor = PCI_ANY_ID,
9849 .subdevice = PCI_ANY_ID,
9852 .vendor = PCI_VENDOR_ID_QLOGIC,
9853 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9854 .subvendor = PCI_ANY_ID,
9855 .subdevice = PCI_ANY_ID,
9858 .vendor = PCI_VENDOR_ID_QLOGIC,
9859 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9860 .subvendor = PCI_ANY_ID,
9861 .subdevice = PCI_ANY_ID,
9864 .vendor = PCI_VENDOR_ID_QLOGIC,
9865 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9866 .subvendor = PCI_ANY_ID,
9867 .subdevice = PCI_ANY_ID,
9871 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9873 static struct pci_driver qla4xxx_pci_driver = {
9874 .name = DRIVER_NAME,
9875 .id_table = qla4xxx_pci_tbl,
9876 .probe = qla4xxx_probe_adapter,
9877 .remove = qla4xxx_remove_adapter,
9878 .err_handler = &qla4xxx_err_handler,
9881 static int __init qla4xxx_module_init(void)
9885 /* Allocate cache for SRBs. */
9886 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9887 SLAB_HWCACHE_ALIGN, NULL);
9888 if (srb_cachep == NULL) {
9890 "%s: Unable to allocate SRB cache..."
9891 "Failing load!\n", DRIVER_NAME);
9896 /* Derive version string. */
9897 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9898 if (ql4xextended_error_logging)
9899 strcat(qla4xxx_version_str, "-debug");
9901 qla4xxx_scsi_transport =
9902 iscsi_register_transport(&qla4xxx_iscsi_transport);
9903 if (!qla4xxx_scsi_transport){
9905 goto release_srb_cache;
9908 ret = pci_register_driver(&qla4xxx_pci_driver);
9910 goto unregister_transport;
9912 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9915 unregister_transport:
9916 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9918 kmem_cache_destroy(srb_cachep);
9923 static void __exit qla4xxx_module_exit(void)
9925 pci_unregister_driver(&qla4xxx_pci_driver);
9926 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9927 kmem_cache_destroy(srb_cachep);
9930 module_init(qla4xxx_module_init);
9931 module_exit(qla4xxx_module_exit);
9933 MODULE_AUTHOR("QLogic Corporation");
9934 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9935 MODULE_LICENSE("GPL");
9936 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);