2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2013 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/blkdev.h>
10 #include <linux/iscsi_boot_sysfs.h>
11 #include <linux/inet.h>
13 #include <scsi/scsi_tcq.h>
14 #include <scsi/scsicam.h>
17 #include "ql4_version.h"
20 #include "ql4_inline.h"
26 static char qla4xxx_version_str[40];
29 * SRB allocation cache
31 static struct kmem_cache *srb_cachep;
34 * Module parameter information and variables
36 static int ql4xdisablesysfsboot = 1;
37 module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
38 MODULE_PARM_DESC(ql4xdisablesysfsboot,
39 " Set to disable exporting boot targets to sysfs.\n"
40 "\t\t 0 - Export boot targets\n"
41 "\t\t 1 - Do not export boot targets (Default)");
44 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql4xdontresethba,
46 " Don't reset the HBA for driver recovery.\n"
47 "\t\t 0 - It will reset HBA (Default)\n"
48 "\t\t 1 - It will NOT reset HBA");
50 int ql4xextended_error_logging;
51 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
52 MODULE_PARM_DESC(ql4xextended_error_logging,
53 " Option to enable extended error logging.\n"
54 "\t\t 0 - no logging (Default)\n"
55 "\t\t 2 - debug logging");
57 int ql4xenablemsix = 1;
58 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
59 MODULE_PARM_DESC(ql4xenablemsix,
60 " Set to enable MSI or MSI-X interrupt mechanism.\n"
61 "\t\t 0 = enable INTx interrupt mechanism.\n"
62 "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
63 "\t\t 2 = enable MSI interrupt mechanism.");
65 #define QL4_DEF_QDEPTH 32
66 static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
67 module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
68 MODULE_PARM_DESC(ql4xmaxqdepth,
69 " Maximum queue depth to report for target devices.\n"
72 static int ql4xqfulltracking = 1;
73 module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
74 MODULE_PARM_DESC(ql4xqfulltracking,
75 " Enable or disable dynamic tracking and adjustment of\n"
76 "\t\t scsi device queue depth.\n"
78 "\t\t 1 - Enable. (Default)");
80 static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
81 module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
82 MODULE_PARM_DESC(ql4xsess_recovery_tmo,
83 " Target Session Recovery Timeout.\n"
84 "\t\t Default: 120 sec.");
86 int ql4xmdcapmask = 0;
87 module_param(ql4xmdcapmask, int, S_IRUGO);
88 MODULE_PARM_DESC(ql4xmdcapmask,
89 " Set the Minidump driver capture mask level.\n"
90 "\t\t Default is 0 (firmware default capture mask)\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
94 module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
95 MODULE_PARM_DESC(ql4xenablemd,
96 " Set to enable minidump.\n"
97 "\t\t 0 - disable minidump\n"
98 "\t\t 1 - enable minidump (Default)");
100 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
102 * SCSI host template entry points
104 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
107 * iSCSI template entry points
109 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
110 enum iscsi_param param, char *buf);
111 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
112 enum iscsi_param param, char *buf);
113 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
114 enum iscsi_host_param param, char *buf);
115 static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
117 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
118 enum iscsi_param_type param_type,
119 int param, char *buf);
120 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
121 static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
122 struct sockaddr *dst_addr,
124 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
125 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
126 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
127 enum iscsi_param param, char *buf);
128 static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
129 static struct iscsi_cls_conn *
130 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
131 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
132 struct iscsi_cls_conn *cls_conn,
133 uint64_t transport_fd, int is_leading);
134 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
135 static struct iscsi_cls_session *
136 qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
137 uint16_t qdepth, uint32_t initial_cmdsn);
138 static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
139 static void qla4xxx_task_work(struct work_struct *wdata);
140 static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
141 static int qla4xxx_task_xmit(struct iscsi_task *);
142 static void qla4xxx_task_cleanup(struct iscsi_task *);
143 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
144 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
145 struct iscsi_stats *stats);
146 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
147 uint32_t iface_type, uint32_t payload_size,
148 uint32_t pid, struct sockaddr *dst_addr);
149 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
150 uint32_t *num_entries, char *buf);
151 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
152 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
154 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
157 * SCSI host template entry points
159 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
161 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
162 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
163 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164 static int qla4xxx_slave_alloc(struct scsi_device *device);
165 static umode_t qla4_attr_is_visible(int param_type, int param);
166 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
169 * iSCSI Flash DDB sysfs entry points
172 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
173 struct iscsi_bus_flash_conn *fnode_conn,
174 void *data, int len);
176 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
177 int param, char *buf);
178 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
181 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
182 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
183 struct iscsi_bus_flash_conn *fnode_conn);
184 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
185 struct iscsi_bus_flash_conn *fnode_conn);
186 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
188 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
189 QLA82XX_LEGACY_INTR_CONFIG;
191 static const uint32_t qla4_82xx_reg_tbl[] = {
192 QLA82XX_PEG_HALT_STATUS1,
193 QLA82XX_PEG_HALT_STATUS2,
194 QLA82XX_PEG_ALIVE_COUNTER,
195 QLA82XX_CRB_DRV_ACTIVE,
196 QLA82XX_CRB_DEV_STATE,
197 QLA82XX_CRB_DRV_STATE,
198 QLA82XX_CRB_DRV_SCRATCH,
199 QLA82XX_CRB_DEV_PART_INFO,
200 QLA82XX_CRB_DRV_IDC_VERSION,
201 QLA82XX_FW_VERSION_MAJOR,
202 QLA82XX_FW_VERSION_MINOR,
203 QLA82XX_FW_VERSION_SUB,
208 static const uint32_t qla4_83xx_reg_tbl[] = {
209 QLA83XX_PEG_HALT_STATUS1,
210 QLA83XX_PEG_HALT_STATUS2,
211 QLA83XX_PEG_ALIVE_COUNTER,
212 QLA83XX_CRB_DRV_ACTIVE,
213 QLA83XX_CRB_DEV_STATE,
214 QLA83XX_CRB_DRV_STATE,
215 QLA83XX_CRB_DRV_SCRATCH,
216 QLA83XX_CRB_DEV_PART_INFO1,
217 QLA83XX_CRB_IDC_VER_MAJOR,
218 QLA83XX_FW_VER_MAJOR,
219 QLA83XX_FW_VER_MINOR,
221 QLA83XX_CMDPEG_STATE,
225 static struct scsi_host_template qla4xxx_driver_template = {
226 .module = THIS_MODULE,
228 .proc_name = DRIVER_NAME,
229 .queuecommand = qla4xxx_queuecommand,
231 .eh_abort_handler = qla4xxx_eh_abort,
232 .eh_device_reset_handler = qla4xxx_eh_device_reset,
233 .eh_target_reset_handler = qla4xxx_eh_target_reset,
234 .eh_host_reset_handler = qla4xxx_eh_host_reset,
235 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
237 .slave_alloc = qla4xxx_slave_alloc,
238 .change_queue_depth = scsi_change_queue_depth,
242 .sg_tablesize = SG_ALL,
244 .max_sectors = 0xFFFF,
245 .shost_attrs = qla4xxx_host_attrs,
246 .host_reset = qla4xxx_host_reset,
247 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
250 static struct iscsi_transport qla4xxx_iscsi_transport = {
251 .owner = THIS_MODULE,
253 .caps = CAP_TEXT_NEGO |
254 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
255 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
257 .attr_is_visible = qla4_attr_is_visible,
258 .create_session = qla4xxx_session_create,
259 .destroy_session = qla4xxx_session_destroy,
260 .start_conn = qla4xxx_conn_start,
261 .create_conn = qla4xxx_conn_create,
262 .bind_conn = qla4xxx_conn_bind,
263 .stop_conn = iscsi_conn_stop,
264 .destroy_conn = qla4xxx_conn_destroy,
265 .set_param = iscsi_set_param,
266 .get_conn_param = qla4xxx_conn_get_param,
267 .get_session_param = qla4xxx_session_get_param,
268 .get_ep_param = qla4xxx_get_ep_param,
269 .ep_connect = qla4xxx_ep_connect,
270 .ep_poll = qla4xxx_ep_poll,
271 .ep_disconnect = qla4xxx_ep_disconnect,
272 .get_stats = qla4xxx_conn_get_stats,
273 .send_pdu = iscsi_conn_send_pdu,
274 .xmit_task = qla4xxx_task_xmit,
275 .cleanup_task = qla4xxx_task_cleanup,
276 .alloc_pdu = qla4xxx_alloc_pdu,
278 .get_host_param = qla4xxx_host_get_param,
279 .set_iface_param = qla4xxx_iface_set_param,
280 .get_iface_param = qla4xxx_get_iface_param,
281 .bsg_request = qla4xxx_bsg_request,
282 .send_ping = qla4xxx_send_ping,
283 .get_chap = qla4xxx_get_chap_list,
284 .delete_chap = qla4xxx_delete_chap,
285 .set_chap = qla4xxx_set_chap_entry,
286 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
287 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
288 .new_flashnode = qla4xxx_sysfs_ddb_add,
289 .del_flashnode = qla4xxx_sysfs_ddb_delete,
290 .login_flashnode = qla4xxx_sysfs_ddb_login,
291 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
292 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
293 .get_host_stats = qla4xxx_get_host_stats,
296 static struct scsi_transport_template *qla4xxx_scsi_transport;
298 static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
301 int rval = QLA_SUCCESS;
304 reg_val = readl(&ha->qla4_82xx_reg->host_status);
305 else if (is_qla8032(ha) || is_qla8042(ha))
306 reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
308 reg_val = readw(&ha->reg->ctrl_status);
310 if (reg_val == QL4_ISP_REG_DISCONNECT)
316 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
317 uint32_t iface_type, uint32_t payload_size,
318 uint32_t pid, struct sockaddr *dst_addr)
320 struct scsi_qla_host *ha = to_qla_host(shost);
321 struct sockaddr_in *addr;
322 struct sockaddr_in6 *addr6;
323 uint32_t options = 0;
324 uint8_t ipaddr[IPv6_ADDR_LEN];
327 memset(ipaddr, 0, IPv6_ADDR_LEN);
329 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
330 (dst_addr->sa_family == AF_INET)) {
331 addr = (struct sockaddr_in *)dst_addr;
332 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
333 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
334 "dest: %pI4\n", __func__,
335 &ha->ip_config.ip_address, ipaddr));
336 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
340 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
341 (dst_addr->sa_family == AF_INET6)) {
343 addr6 = (struct sockaddr_in6 *)dst_addr;
344 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
346 options |= PING_IPV6_PROTOCOL_ENABLE;
348 /* Ping using LinkLocal address */
349 if ((iface_num == 0) || (iface_num == 1)) {
350 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
351 "src: %pI6 dest: %pI6\n", __func__,
352 &ha->ip_config.ipv6_link_local_addr,
354 options |= PING_IPV6_LINKLOCAL_ADDR;
355 rval = qla4xxx_ping_iocb(ha, options, payload_size,
358 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
359 "not supported\n", __func__, iface_num);
365 * If ping using LinkLocal address fails, try ping using
368 if (rval != QLA_SUCCESS) {
369 options &= ~PING_IPV6_LINKLOCAL_ADDR;
370 if (iface_num == 0) {
371 options |= PING_IPV6_ADDR0;
372 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
374 "dest: %pI6\n", __func__,
375 &ha->ip_config.ipv6_addr0,
377 } else if (iface_num == 1) {
378 options |= PING_IPV6_ADDR1;
379 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
381 "dest: %pI6\n", __func__,
382 &ha->ip_config.ipv6_addr1,
385 rval = qla4xxx_ping_iocb(ha, options, payload_size,
396 static umode_t qla4_attr_is_visible(int param_type, int param)
398 switch (param_type) {
399 case ISCSI_HOST_PARAM:
401 case ISCSI_HOST_PARAM_HWADDRESS:
402 case ISCSI_HOST_PARAM_IPADDRESS:
403 case ISCSI_HOST_PARAM_INITIATOR_NAME:
404 case ISCSI_HOST_PARAM_PORT_STATE:
405 case ISCSI_HOST_PARAM_PORT_SPEED:
412 case ISCSI_PARAM_PERSISTENT_ADDRESS:
413 case ISCSI_PARAM_PERSISTENT_PORT:
414 case ISCSI_PARAM_CONN_ADDRESS:
415 case ISCSI_PARAM_CONN_PORT:
416 case ISCSI_PARAM_TARGET_NAME:
417 case ISCSI_PARAM_TPGT:
418 case ISCSI_PARAM_TARGET_ALIAS:
419 case ISCSI_PARAM_MAX_BURST:
420 case ISCSI_PARAM_MAX_R2T:
421 case ISCSI_PARAM_FIRST_BURST:
422 case ISCSI_PARAM_MAX_RECV_DLENGTH:
423 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
424 case ISCSI_PARAM_IFACE_NAME:
425 case ISCSI_PARAM_CHAP_OUT_IDX:
426 case ISCSI_PARAM_CHAP_IN_IDX:
427 case ISCSI_PARAM_USERNAME:
428 case ISCSI_PARAM_PASSWORD:
429 case ISCSI_PARAM_USERNAME_IN:
430 case ISCSI_PARAM_PASSWORD_IN:
431 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
432 case ISCSI_PARAM_DISCOVERY_SESS:
433 case ISCSI_PARAM_PORTAL_TYPE:
434 case ISCSI_PARAM_CHAP_AUTH_EN:
435 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
436 case ISCSI_PARAM_BIDI_CHAP_EN:
437 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
438 case ISCSI_PARAM_DEF_TIME2WAIT:
439 case ISCSI_PARAM_DEF_TIME2RETAIN:
440 case ISCSI_PARAM_HDRDGST_EN:
441 case ISCSI_PARAM_DATADGST_EN:
442 case ISCSI_PARAM_INITIAL_R2T_EN:
443 case ISCSI_PARAM_IMM_DATA_EN:
444 case ISCSI_PARAM_PDU_INORDER_EN:
445 case ISCSI_PARAM_DATASEQ_INORDER_EN:
446 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
447 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
448 case ISCSI_PARAM_TCP_WSF_DISABLE:
449 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
450 case ISCSI_PARAM_TCP_TIMER_SCALE:
451 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
452 case ISCSI_PARAM_TCP_XMIT_WSF:
453 case ISCSI_PARAM_TCP_RECV_WSF:
454 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
455 case ISCSI_PARAM_IPV4_TOS:
456 case ISCSI_PARAM_IPV6_TC:
457 case ISCSI_PARAM_IPV6_FLOW_LABEL:
458 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
459 case ISCSI_PARAM_KEEPALIVE_TMO:
460 case ISCSI_PARAM_LOCAL_PORT:
461 case ISCSI_PARAM_ISID:
462 case ISCSI_PARAM_TSID:
463 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
464 case ISCSI_PARAM_ERL:
465 case ISCSI_PARAM_STATSN:
466 case ISCSI_PARAM_EXP_STATSN:
467 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
468 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
469 case ISCSI_PARAM_LOCAL_IPADDR:
474 case ISCSI_NET_PARAM:
476 case ISCSI_NET_PARAM_IPV4_ADDR:
477 case ISCSI_NET_PARAM_IPV4_SUBNET:
478 case ISCSI_NET_PARAM_IPV4_GW:
479 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
480 case ISCSI_NET_PARAM_IFACE_ENABLE:
481 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
482 case ISCSI_NET_PARAM_IPV6_ADDR:
483 case ISCSI_NET_PARAM_IPV6_ROUTER:
484 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
485 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
486 case ISCSI_NET_PARAM_VLAN_ID:
487 case ISCSI_NET_PARAM_VLAN_PRIORITY:
488 case ISCSI_NET_PARAM_VLAN_ENABLED:
489 case ISCSI_NET_PARAM_MTU:
490 case ISCSI_NET_PARAM_PORT:
491 case ISCSI_NET_PARAM_IPADDR_STATE:
492 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
493 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
494 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
495 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
496 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
497 case ISCSI_NET_PARAM_TCP_WSF:
498 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
499 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
500 case ISCSI_NET_PARAM_CACHE_ID:
501 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
502 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
503 case ISCSI_NET_PARAM_IPV4_TOS_EN:
504 case ISCSI_NET_PARAM_IPV4_TOS:
505 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
506 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
507 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
508 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
509 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
510 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
511 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
512 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
513 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
514 case ISCSI_NET_PARAM_REDIRECT_EN:
515 case ISCSI_NET_PARAM_IPV4_TTL:
516 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
517 case ISCSI_NET_PARAM_IPV6_MLD_EN:
518 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
519 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
520 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
521 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
522 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
523 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
524 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
525 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
530 case ISCSI_IFACE_PARAM:
532 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
533 case ISCSI_IFACE_PARAM_HDRDGST_EN:
534 case ISCSI_IFACE_PARAM_DATADGST_EN:
535 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
536 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
537 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
538 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
539 case ISCSI_IFACE_PARAM_ERL:
540 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
541 case ISCSI_IFACE_PARAM_FIRST_BURST:
542 case ISCSI_IFACE_PARAM_MAX_R2T:
543 case ISCSI_IFACE_PARAM_MAX_BURST:
544 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
545 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
546 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
547 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
548 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
549 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
554 case ISCSI_FLASHNODE_PARAM:
556 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
557 case ISCSI_FLASHNODE_PORTAL_TYPE:
558 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
559 case ISCSI_FLASHNODE_DISCOVERY_SESS:
560 case ISCSI_FLASHNODE_ENTRY_EN:
561 case ISCSI_FLASHNODE_HDR_DGST_EN:
562 case ISCSI_FLASHNODE_DATA_DGST_EN:
563 case ISCSI_FLASHNODE_IMM_DATA_EN:
564 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
565 case ISCSI_FLASHNODE_DATASEQ_INORDER:
566 case ISCSI_FLASHNODE_PDU_INORDER:
567 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
568 case ISCSI_FLASHNODE_SNACK_REQ_EN:
569 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
570 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
571 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
572 case ISCSI_FLASHNODE_ERL:
573 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
574 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
575 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
576 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
577 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
578 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
579 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
580 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
581 case ISCSI_FLASHNODE_FIRST_BURST:
582 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
583 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
584 case ISCSI_FLASHNODE_MAX_R2T:
585 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
586 case ISCSI_FLASHNODE_ISID:
587 case ISCSI_FLASHNODE_TSID:
588 case ISCSI_FLASHNODE_PORT:
589 case ISCSI_FLASHNODE_MAX_BURST:
590 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
591 case ISCSI_FLASHNODE_IPADDR:
592 case ISCSI_FLASHNODE_ALIAS:
593 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
594 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
595 case ISCSI_FLASHNODE_LOCAL_PORT:
596 case ISCSI_FLASHNODE_IPV4_TOS:
597 case ISCSI_FLASHNODE_IPV6_TC:
598 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
599 case ISCSI_FLASHNODE_NAME:
600 case ISCSI_FLASHNODE_TPGT:
601 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
602 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
603 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
604 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
605 case ISCSI_FLASHNODE_TCP_RECV_WSF:
606 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
607 case ISCSI_FLASHNODE_USERNAME:
608 case ISCSI_FLASHNODE_PASSWORD:
609 case ISCSI_FLASHNODE_STATSN:
610 case ISCSI_FLASHNODE_EXP_STATSN:
611 case ISCSI_FLASHNODE_IS_BOOT_TGT:
622 * qla4xxx_create chap_list - Create CHAP list from FLASH
623 * @ha: pointer to adapter structure
625 * Read flash and make a list of CHAP entries, during login when a CHAP entry
626 * is received, it will be checked in this list. If entry exist then the CHAP
627 * entry index is set in the DDB. If CHAP entry does not exist in this list
628 * then a new entry is added in FLASH in CHAP table and the index obtained is
631 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
634 uint8_t *chap_flash_data = NULL;
637 uint32_t chap_size = 0;
640 chap_size = MAX_CHAP_ENTRIES_40XX *
641 sizeof(struct ql4_chap_table);
642 else /* Single region contains CHAP info for both
643 * ports which is divided into half for each port.
645 chap_size = ha->hw.flt_chap_size / 2;
647 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
648 &chap_dma, GFP_KERNEL);
649 if (!chap_flash_data) {
650 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
654 if (is_qla40XX(ha)) {
655 offset = FLASH_CHAP_OFFSET;
657 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
658 if (ha->port_num == 1)
662 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
663 if (rval != QLA_SUCCESS)
666 if (ha->chap_list == NULL)
667 ha->chap_list = vmalloc(chap_size);
668 if (ha->chap_list == NULL) {
669 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
673 memset(ha->chap_list, 0, chap_size);
674 memcpy(ha->chap_list, chap_flash_data, chap_size);
677 dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
680 static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
682 struct ql4_chap_table **chap_entry)
684 int rval = QLA_ERROR;
685 int max_chap_entries;
687 if (!ha->chap_list) {
688 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
694 max_chap_entries = (ha->hw.flt_chap_size / 2) /
695 sizeof(struct ql4_chap_table);
697 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
699 if (chap_index > max_chap_entries) {
700 ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
705 *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
706 if ((*chap_entry)->cookie !=
707 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
719 * qla4xxx_find_free_chap_index - Find the first free chap index
720 * @ha: pointer to adapter structure
721 * @chap_index: CHAP index to be returned
723 * Find the first free chap index available in the chap table
725 * Note: Caller should acquire the chap lock before getting here.
727 static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
728 uint16_t *chap_index)
732 int max_chap_entries = 0;
733 struct ql4_chap_table *chap_table;
736 max_chap_entries = (ha->hw.flt_chap_size / 2) /
737 sizeof(struct ql4_chap_table);
739 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
741 if (!ha->chap_list) {
742 ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
747 for (i = 0; i < max_chap_entries; i++) {
748 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
750 if ((chap_table->cookie !=
751 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
752 (i > MAX_RESRV_CHAP_IDX)) {
758 if (free_index != -1) {
759 *chap_index = free_index;
769 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
770 uint32_t *num_entries, char *buf)
772 struct scsi_qla_host *ha = to_qla_host(shost);
773 struct ql4_chap_table *chap_table;
774 struct iscsi_chap_rec *chap_rec;
775 int max_chap_entries = 0;
776 int valid_chap_entries = 0;
780 max_chap_entries = (ha->hw.flt_chap_size / 2) /
781 sizeof(struct ql4_chap_table);
783 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
785 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
786 __func__, *num_entries, chap_tbl_idx);
790 goto exit_get_chap_list;
793 qla4xxx_create_chap_list(ha);
795 chap_rec = (struct iscsi_chap_rec *) buf;
796 mutex_lock(&ha->chap_sem);
797 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
798 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
799 if (chap_table->cookie !=
800 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
803 chap_rec->chap_tbl_idx = i;
804 strlcpy(chap_rec->username, chap_table->name,
805 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
806 strlcpy(chap_rec->password, chap_table->secret,
807 QL4_CHAP_MAX_SECRET_LEN);
808 chap_rec->password_length = chap_table->secret_len;
810 if (chap_table->flags & BIT_7) /* local */
811 chap_rec->chap_type = CHAP_TYPE_OUT;
813 if (chap_table->flags & BIT_6) /* peer */
814 chap_rec->chap_type = CHAP_TYPE_IN;
818 valid_chap_entries++;
819 if (valid_chap_entries == *num_entries)
824 mutex_unlock(&ha->chap_sem);
827 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
828 __func__, valid_chap_entries);
829 *num_entries = valid_chap_entries;
833 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
836 uint16_t *chap_tbl_idx = (uint16_t *) data;
837 struct iscsi_cls_session *cls_session;
838 struct iscsi_session *sess;
839 struct ddb_entry *ddb_entry;
841 if (!iscsi_is_session_dev(dev))
842 goto exit_is_chap_active;
844 cls_session = iscsi_dev_to_session(dev);
845 sess = cls_session->dd_data;
846 ddb_entry = sess->dd_data;
848 if (iscsi_session_chkready(cls_session))
849 goto exit_is_chap_active;
851 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
858 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
859 uint16_t chap_tbl_idx)
863 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
864 __qla4xxx_is_chap_active);
869 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
871 struct scsi_qla_host *ha = to_qla_host(shost);
872 struct ql4_chap_table *chap_table;
874 int max_chap_entries = 0;
879 chap_table = dma_pool_zalloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
880 if (chap_table == NULL)
884 max_chap_entries = (ha->hw.flt_chap_size / 2) /
885 sizeof(struct ql4_chap_table);
887 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
889 if (chap_tbl_idx > max_chap_entries) {
891 goto exit_delete_chap;
894 /* Check if chap index is in use.
895 * If chap is in use don't delet chap entry */
896 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
898 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
899 "delete from flash\n", chap_tbl_idx);
901 goto exit_delete_chap;
904 chap_size = sizeof(struct ql4_chap_table);
906 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
908 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
909 /* flt_chap_size is CHAP table size for both ports
910 * so divide it by 2 to calculate the offset for second port
912 if (ha->port_num == 1)
913 offset += (ha->hw.flt_chap_size / 2);
914 offset += (chap_tbl_idx * chap_size);
917 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
918 if (ret != QLA_SUCCESS) {
920 goto exit_delete_chap;
923 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
924 __le16_to_cpu(chap_table->cookie)));
926 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
927 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
928 goto exit_delete_chap;
931 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
933 offset = FLASH_CHAP_OFFSET |
934 (chap_tbl_idx * sizeof(struct ql4_chap_table));
935 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
936 FLASH_OPT_RMW_COMMIT);
937 if (ret == QLA_SUCCESS && ha->chap_list) {
938 mutex_lock(&ha->chap_sem);
939 /* Update ha chap_list cache */
940 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
941 chap_table, sizeof(struct ql4_chap_table));
942 mutex_unlock(&ha->chap_sem);
944 if (ret != QLA_SUCCESS)
948 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
953 * qla4xxx_set_chap_entry - Make chap entry with given information
954 * @shost: pointer to host
955 * @data: chap info - credentials, index and type to make chap entry
956 * @len: length of data
958 * Add or update chap entry with the given information
960 static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
962 struct scsi_qla_host *ha = to_qla_host(shost);
963 struct iscsi_chap_rec chap_rec;
964 struct ql4_chap_table *chap_entry = NULL;
965 struct iscsi_param_info *param_info;
967 int max_chap_entries = 0;
973 memset(&chap_rec, 0, sizeof(chap_rec));
975 nla_for_each_attr(attr, data, len, rem) {
976 param_info = nla_data(attr);
978 switch (param_info->param) {
979 case ISCSI_CHAP_PARAM_INDEX:
980 chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
982 case ISCSI_CHAP_PARAM_CHAP_TYPE:
983 chap_rec.chap_type = param_info->value[0];
985 case ISCSI_CHAP_PARAM_USERNAME:
986 size = min_t(size_t, sizeof(chap_rec.username),
988 memcpy(chap_rec.username, param_info->value, size);
990 case ISCSI_CHAP_PARAM_PASSWORD:
991 size = min_t(size_t, sizeof(chap_rec.password),
993 memcpy(chap_rec.password, param_info->value, size);
995 case ISCSI_CHAP_PARAM_PASSWORD_LEN:
996 chap_rec.password_length = param_info->value[0];
999 ql4_printk(KERN_ERR, ha,
1000 "%s: No such sysfs attribute\n", __func__);
1006 if (chap_rec.chap_type == CHAP_TYPE_IN)
1012 max_chap_entries = (ha->hw.flt_chap_size / 2) /
1013 sizeof(struct ql4_chap_table);
1015 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
1017 mutex_lock(&ha->chap_sem);
1018 if (chap_rec.chap_tbl_idx < max_chap_entries) {
1019 rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
1022 if (!(type == qla4xxx_get_chap_type(chap_entry))) {
1023 ql4_printk(KERN_INFO, ha,
1024 "Type mismatch for CHAP entry %d\n",
1025 chap_rec.chap_tbl_idx);
1027 goto exit_unlock_chap;
1030 /* If chap index is in use then don't modify it */
1031 rc = qla4xxx_is_chap_active(shost,
1032 chap_rec.chap_tbl_idx);
1034 ql4_printk(KERN_INFO, ha,
1035 "CHAP entry %d is in use\n",
1036 chap_rec.chap_tbl_idx);
1038 goto exit_unlock_chap;
1042 rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
1044 ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
1046 goto exit_unlock_chap;
1050 rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
1051 chap_rec.chap_tbl_idx, type);
1054 mutex_unlock(&ha->chap_sem);
1061 static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
1063 struct scsi_qla_host *ha = to_qla_host(shost);
1064 struct iscsi_offload_host_stats *host_stats = NULL;
1065 int host_stats_size;
1068 struct ql_iscsi_stats *ql_iscsi_stats = NULL;
1070 dma_addr_t iscsi_stats_dma;
1072 DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
1074 host_stats_size = sizeof(struct iscsi_offload_host_stats);
1076 if (host_stats_size != len) {
1077 ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
1078 __func__, len, host_stats_size);
1080 goto exit_host_stats;
1082 host_stats = (struct iscsi_offload_host_stats *)buf;
1086 goto exit_host_stats;
1089 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1091 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1092 &iscsi_stats_dma, GFP_KERNEL);
1093 if (!ql_iscsi_stats) {
1094 ql4_printk(KERN_ERR, ha,
1095 "Unable to allocate memory for iscsi stats\n");
1097 goto exit_host_stats;
1100 ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
1102 if (ret != QLA_SUCCESS) {
1103 ql4_printk(KERN_ERR, ha,
1104 "Unable to retrieve iscsi stats\n");
1106 goto exit_host_stats;
1108 host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
1109 host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
1110 host_stats->mactx_multicast_frames =
1111 le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
1112 host_stats->mactx_broadcast_frames =
1113 le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
1114 host_stats->mactx_pause_frames =
1115 le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
1116 host_stats->mactx_control_frames =
1117 le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
1118 host_stats->mactx_deferral =
1119 le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
1120 host_stats->mactx_excess_deferral =
1121 le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
1122 host_stats->mactx_late_collision =
1123 le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
1124 host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
1125 host_stats->mactx_single_collision =
1126 le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
1127 host_stats->mactx_multiple_collision =
1128 le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
1129 host_stats->mactx_collision =
1130 le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
1131 host_stats->mactx_frames_dropped =
1132 le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
1133 host_stats->mactx_jumbo_frames =
1134 le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
1135 host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
1136 host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
1137 host_stats->macrx_unknown_control_frames =
1138 le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
1139 host_stats->macrx_pause_frames =
1140 le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
1141 host_stats->macrx_control_frames =
1142 le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
1143 host_stats->macrx_dribble =
1144 le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
1145 host_stats->macrx_frame_length_error =
1146 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
1147 host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
1148 host_stats->macrx_carrier_sense_error =
1149 le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
1150 host_stats->macrx_frame_discarded =
1151 le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
1152 host_stats->macrx_frames_dropped =
1153 le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
1154 host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
1155 host_stats->mac_encoding_error =
1156 le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
1157 host_stats->macrx_length_error_large =
1158 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
1159 host_stats->macrx_length_error_small =
1160 le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
1161 host_stats->macrx_multicast_frames =
1162 le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
1163 host_stats->macrx_broadcast_frames =
1164 le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
1165 host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
1166 host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
1167 host_stats->iptx_fragments =
1168 le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
1169 host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
1170 host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
1171 host_stats->iprx_fragments =
1172 le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
1173 host_stats->ip_datagram_reassembly =
1174 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
1175 host_stats->ip_invalid_address_error =
1176 le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
1177 host_stats->ip_error_packets =
1178 le64_to_cpu(ql_iscsi_stats->ip_error_packets);
1179 host_stats->ip_fragrx_overlap =
1180 le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
1181 host_stats->ip_fragrx_outoforder =
1182 le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
1183 host_stats->ip_datagram_reassembly_timeout =
1184 le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
1185 host_stats->ipv6tx_packets =
1186 le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
1187 host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
1188 host_stats->ipv6tx_fragments =
1189 le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
1190 host_stats->ipv6rx_packets =
1191 le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
1192 host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
1193 host_stats->ipv6rx_fragments =
1194 le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
1195 host_stats->ipv6_datagram_reassembly =
1196 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
1197 host_stats->ipv6_invalid_address_error =
1198 le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
1199 host_stats->ipv6_error_packets =
1200 le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
1201 host_stats->ipv6_fragrx_overlap =
1202 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
1203 host_stats->ipv6_fragrx_outoforder =
1204 le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
1205 host_stats->ipv6_datagram_reassembly_timeout =
1206 le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
1207 host_stats->tcptx_segments =
1208 le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
1209 host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
1210 host_stats->tcprx_segments =
1211 le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
1212 host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
1213 host_stats->tcp_duplicate_ack_retx =
1214 le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
1215 host_stats->tcp_retx_timer_expired =
1216 le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
1217 host_stats->tcprx_duplicate_ack =
1218 le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
1219 host_stats->tcprx_pure_ackr =
1220 le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
1221 host_stats->tcptx_delayed_ack =
1222 le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
1223 host_stats->tcptx_pure_ack =
1224 le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
1225 host_stats->tcprx_segment_error =
1226 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
1227 host_stats->tcprx_segment_outoforder =
1228 le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
1229 host_stats->tcprx_window_probe =
1230 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
1231 host_stats->tcprx_window_update =
1232 le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
1233 host_stats->tcptx_window_probe_persist =
1234 le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
1235 host_stats->ecc_error_correction =
1236 le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
1237 host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
1238 host_stats->iscsi_data_bytes_tx =
1239 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
1240 host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
1241 host_stats->iscsi_data_bytes_rx =
1242 le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
1243 host_stats->iscsi_io_completed =
1244 le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
1245 host_stats->iscsi_unexpected_io_rx =
1246 le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
1247 host_stats->iscsi_format_error =
1248 le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
1249 host_stats->iscsi_hdr_digest_error =
1250 le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
1251 host_stats->iscsi_data_digest_error =
1252 le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
1253 host_stats->iscsi_sequence_error =
1254 le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
1257 dma_free_coherent(&ha->pdev->dev, host_stats_size,
1258 ql_iscsi_stats, iscsi_stats_dma);
1260 ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
1265 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
1266 enum iscsi_param_type param_type,
1267 int param, char *buf)
1269 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
1270 struct scsi_qla_host *ha = to_qla_host(shost);
1275 if (param_type == ISCSI_NET_PARAM) {
1277 case ISCSI_NET_PARAM_IPV4_ADDR:
1278 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1280 case ISCSI_NET_PARAM_IPV4_SUBNET:
1281 len = sprintf(buf, "%pI4\n",
1282 &ha->ip_config.subnet_mask);
1284 case ISCSI_NET_PARAM_IPV4_GW:
1285 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
1287 case ISCSI_NET_PARAM_IFACE_ENABLE:
1288 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1289 OP_STATE(ha->ip_config.ipv4_options,
1290 IPOPT_IPV4_PROTOCOL_ENABLE, pval);
1292 OP_STATE(ha->ip_config.ipv6_options,
1293 IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
1296 len = sprintf(buf, "%s\n", pval);
1298 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1299 len = sprintf(buf, "%s\n",
1300 (ha->ip_config.tcp_options &
1301 TCPOPT_DHCP_ENABLE) ?
1304 case ISCSI_NET_PARAM_IPV6_ADDR:
1305 if (iface->iface_num == 0)
1306 len = sprintf(buf, "%pI6\n",
1307 &ha->ip_config.ipv6_addr0);
1308 if (iface->iface_num == 1)
1309 len = sprintf(buf, "%pI6\n",
1310 &ha->ip_config.ipv6_addr1);
1312 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1313 len = sprintf(buf, "%pI6\n",
1314 &ha->ip_config.ipv6_link_local_addr);
1316 case ISCSI_NET_PARAM_IPV6_ROUTER:
1317 len = sprintf(buf, "%pI6\n",
1318 &ha->ip_config.ipv6_default_router_addr);
1320 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1321 pval = (ha->ip_config.ipv6_addl_options &
1322 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
1325 len = sprintf(buf, "%s\n", pval);
1327 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1328 pval = (ha->ip_config.ipv6_addl_options &
1329 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
1332 len = sprintf(buf, "%s\n", pval);
1334 case ISCSI_NET_PARAM_VLAN_ID:
1335 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1336 ival = ha->ip_config.ipv4_vlan_tag &
1339 ival = ha->ip_config.ipv6_vlan_tag &
1342 len = sprintf(buf, "%d\n", ival);
1344 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1345 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1346 ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
1347 ISCSI_MAX_VLAN_PRIORITY;
1349 ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
1350 ISCSI_MAX_VLAN_PRIORITY;
1352 len = sprintf(buf, "%d\n", ival);
1354 case ISCSI_NET_PARAM_VLAN_ENABLED:
1355 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1356 OP_STATE(ha->ip_config.ipv4_options,
1357 IPOPT_VLAN_TAGGING_ENABLE, pval);
1359 OP_STATE(ha->ip_config.ipv6_options,
1360 IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
1362 len = sprintf(buf, "%s\n", pval);
1364 case ISCSI_NET_PARAM_MTU:
1365 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
1367 case ISCSI_NET_PARAM_PORT:
1368 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1369 len = sprintf(buf, "%d\n",
1370 ha->ip_config.ipv4_port);
1372 len = sprintf(buf, "%d\n",
1373 ha->ip_config.ipv6_port);
1375 case ISCSI_NET_PARAM_IPADDR_STATE:
1376 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1377 pval = iscsi_get_ipaddress_state_name(
1378 ha->ip_config.ipv4_addr_state);
1380 if (iface->iface_num == 0)
1381 pval = iscsi_get_ipaddress_state_name(
1382 ha->ip_config.ipv6_addr0_state);
1383 else if (iface->iface_num == 1)
1384 pval = iscsi_get_ipaddress_state_name(
1385 ha->ip_config.ipv6_addr1_state);
1388 len = sprintf(buf, "%s\n", pval);
1390 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
1391 pval = iscsi_get_ipaddress_state_name(
1392 ha->ip_config.ipv6_link_local_state);
1393 len = sprintf(buf, "%s\n", pval);
1395 case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
1396 pval = iscsi_get_router_state_name(
1397 ha->ip_config.ipv6_default_router_state);
1398 len = sprintf(buf, "%s\n", pval);
1400 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
1401 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1402 OP_STATE(~ha->ip_config.tcp_options,
1403 TCPOPT_DELAYED_ACK_DISABLE, pval);
1405 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1406 IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
1408 len = sprintf(buf, "%s\n", pval);
1410 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
1411 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1412 OP_STATE(~ha->ip_config.tcp_options,
1413 TCPOPT_NAGLE_ALGO_DISABLE, pval);
1415 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1416 IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
1418 len = sprintf(buf, "%s\n", pval);
1420 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
1421 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1422 OP_STATE(~ha->ip_config.tcp_options,
1423 TCPOPT_WINDOW_SCALE_DISABLE, pval);
1425 OP_STATE(~ha->ip_config.ipv6_tcp_options,
1426 IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
1429 len = sprintf(buf, "%s\n", pval);
1431 case ISCSI_NET_PARAM_TCP_WSF:
1432 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1433 len = sprintf(buf, "%d\n",
1434 ha->ip_config.tcp_wsf);
1436 len = sprintf(buf, "%d\n",
1437 ha->ip_config.ipv6_tcp_wsf);
1439 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
1440 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1441 ival = (ha->ip_config.tcp_options &
1442 TCPOPT_TIMER_SCALE) >> 1;
1444 ival = (ha->ip_config.ipv6_tcp_options &
1445 IPV6_TCPOPT_TIMER_SCALE) >> 1;
1447 len = sprintf(buf, "%d\n", ival);
1449 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
1450 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1451 OP_STATE(ha->ip_config.tcp_options,
1452 TCPOPT_TIMESTAMP_ENABLE, pval);
1454 OP_STATE(ha->ip_config.ipv6_tcp_options,
1455 IPV6_TCPOPT_TIMESTAMP_EN, pval);
1457 len = sprintf(buf, "%s\n", pval);
1459 case ISCSI_NET_PARAM_CACHE_ID:
1460 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
1461 len = sprintf(buf, "%d\n",
1462 ha->ip_config.ipv4_cache_id);
1464 len = sprintf(buf, "%d\n",
1465 ha->ip_config.ipv6_cache_id);
1467 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
1468 OP_STATE(ha->ip_config.tcp_options,
1469 TCPOPT_DNS_SERVER_IP_EN, pval);
1471 len = sprintf(buf, "%s\n", pval);
1473 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
1474 OP_STATE(ha->ip_config.tcp_options,
1475 TCPOPT_SLP_DA_INFO_EN, pval);
1477 len = sprintf(buf, "%s\n", pval);
1479 case ISCSI_NET_PARAM_IPV4_TOS_EN:
1480 OP_STATE(ha->ip_config.ipv4_options,
1481 IPOPT_IPV4_TOS_EN, pval);
1483 len = sprintf(buf, "%s\n", pval);
1485 case ISCSI_NET_PARAM_IPV4_TOS:
1486 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
1488 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
1489 OP_STATE(ha->ip_config.ipv4_options,
1490 IPOPT_GRAT_ARP_EN, pval);
1492 len = sprintf(buf, "%s\n", pval);
1494 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
1495 OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
1498 len = sprintf(buf, "%s\n", pval);
1500 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
1501 pval = (ha->ip_config.ipv4_alt_cid_len) ?
1502 (char *)ha->ip_config.ipv4_alt_cid : "";
1504 len = sprintf(buf, "%s\n", pval);
1506 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
1507 OP_STATE(ha->ip_config.ipv4_options,
1508 IPOPT_REQ_VID_EN, pval);
1510 len = sprintf(buf, "%s\n", pval);
1512 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
1513 OP_STATE(ha->ip_config.ipv4_options,
1514 IPOPT_USE_VID_EN, pval);
1516 len = sprintf(buf, "%s\n", pval);
1518 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
1519 pval = (ha->ip_config.ipv4_vid_len) ?
1520 (char *)ha->ip_config.ipv4_vid : "";
1522 len = sprintf(buf, "%s\n", pval);
1524 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
1525 OP_STATE(ha->ip_config.ipv4_options,
1526 IPOPT_LEARN_IQN_EN, pval);
1528 len = sprintf(buf, "%s\n", pval);
1530 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
1531 OP_STATE(~ha->ip_config.ipv4_options,
1532 IPOPT_FRAGMENTATION_DISABLE, pval);
1534 len = sprintf(buf, "%s\n", pval);
1536 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
1537 OP_STATE(ha->ip_config.ipv4_options,
1538 IPOPT_IN_FORWARD_EN, pval);
1540 len = sprintf(buf, "%s\n", pval);
1542 case ISCSI_NET_PARAM_REDIRECT_EN:
1543 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
1544 OP_STATE(ha->ip_config.ipv4_options,
1545 IPOPT_ARP_REDIRECT_EN, pval);
1547 OP_STATE(ha->ip_config.ipv6_options,
1548 IPV6_OPT_REDIRECT_EN, pval);
1550 len = sprintf(buf, "%s\n", pval);
1552 case ISCSI_NET_PARAM_IPV4_TTL:
1553 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
1555 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
1556 OP_STATE(ha->ip_config.ipv6_options,
1557 IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
1559 len = sprintf(buf, "%s\n", pval);
1561 case ISCSI_NET_PARAM_IPV6_MLD_EN:
1562 OP_STATE(ha->ip_config.ipv6_addl_options,
1563 IPV6_ADDOPT_MLD_EN, pval);
1565 len = sprintf(buf, "%s\n", pval);
1567 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
1568 len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
1570 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
1571 len = sprintf(buf, "%d\n",
1572 ha->ip_config.ipv6_traffic_class);
1574 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
1575 len = sprintf(buf, "%d\n",
1576 ha->ip_config.ipv6_hop_limit);
1578 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
1579 len = sprintf(buf, "%d\n",
1580 ha->ip_config.ipv6_nd_reach_time);
1582 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
1583 len = sprintf(buf, "%d\n",
1584 ha->ip_config.ipv6_nd_rexmit_timer);
1586 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
1587 len = sprintf(buf, "%d\n",
1588 ha->ip_config.ipv6_nd_stale_timeout);
1590 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
1591 len = sprintf(buf, "%d\n",
1592 ha->ip_config.ipv6_dup_addr_detect_count);
1594 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
1595 len = sprintf(buf, "%d\n",
1596 ha->ip_config.ipv6_gw_advrt_mtu);
1601 } else if (param_type == ISCSI_IFACE_PARAM) {
1603 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
1604 len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
1606 case ISCSI_IFACE_PARAM_HDRDGST_EN:
1607 OP_STATE(ha->ip_config.iscsi_options,
1608 ISCSIOPTS_HEADER_DIGEST_EN, pval);
1610 len = sprintf(buf, "%s\n", pval);
1612 case ISCSI_IFACE_PARAM_DATADGST_EN:
1613 OP_STATE(ha->ip_config.iscsi_options,
1614 ISCSIOPTS_DATA_DIGEST_EN, pval);
1616 len = sprintf(buf, "%s\n", pval);
1618 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
1619 OP_STATE(ha->ip_config.iscsi_options,
1620 ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
1622 len = sprintf(buf, "%s\n", pval);
1624 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
1625 OP_STATE(ha->ip_config.iscsi_options,
1626 ISCSIOPTS_INITIAL_R2T_EN, pval);
1628 len = sprintf(buf, "%s\n", pval);
1630 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
1631 OP_STATE(ha->ip_config.iscsi_options,
1632 ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
1634 len = sprintf(buf, "%s\n", pval);
1636 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
1637 OP_STATE(ha->ip_config.iscsi_options,
1638 ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
1640 len = sprintf(buf, "%s\n", pval);
1642 case ISCSI_IFACE_PARAM_ERL:
1643 len = sprintf(buf, "%d\n",
1644 (ha->ip_config.iscsi_options &
1647 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
1648 len = sprintf(buf, "%u\n",
1649 ha->ip_config.iscsi_max_pdu_size *
1652 case ISCSI_IFACE_PARAM_FIRST_BURST:
1653 len = sprintf(buf, "%u\n",
1654 ha->ip_config.iscsi_first_burst_len *
1657 case ISCSI_IFACE_PARAM_MAX_R2T:
1658 len = sprintf(buf, "%d\n",
1659 ha->ip_config.iscsi_max_outstnd_r2t);
1661 case ISCSI_IFACE_PARAM_MAX_BURST:
1662 len = sprintf(buf, "%u\n",
1663 ha->ip_config.iscsi_max_burst_len *
1666 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
1667 OP_STATE(ha->ip_config.iscsi_options,
1668 ISCSIOPTS_CHAP_AUTH_EN, pval);
1670 len = sprintf(buf, "%s\n", pval);
1672 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
1673 OP_STATE(ha->ip_config.iscsi_options,
1674 ISCSIOPTS_BIDI_CHAP_EN, pval);
1676 len = sprintf(buf, "%s\n", pval);
1678 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
1679 OP_STATE(ha->ip_config.iscsi_options,
1680 ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
1682 len = sprintf(buf, "%s\n", pval);
1684 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
1685 OP_STATE(ha->ip_config.iscsi_options,
1686 ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
1688 len = sprintf(buf, "%s\n", pval);
1690 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
1691 OP_STATE(ha->ip_config.iscsi_options,
1692 ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
1694 len = sprintf(buf, "%s\n", pval);
1696 case ISCSI_IFACE_PARAM_INITIATOR_NAME:
1697 len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
1707 static struct iscsi_endpoint *
1708 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1712 struct iscsi_endpoint *ep;
1713 struct qla_endpoint *qla_ep;
1714 struct scsi_qla_host *ha;
1715 struct sockaddr_in *addr;
1716 struct sockaddr_in6 *addr6;
1720 pr_err("%s: shost is NULL\n", __func__);
1721 return ERR_PTR(ret);
1724 ha = iscsi_host_priv(shost);
1725 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
1728 return ERR_PTR(ret);
1731 qla_ep = ep->dd_data;
1732 memset(qla_ep, 0, sizeof(struct qla_endpoint));
1733 if (dst_addr->sa_family == AF_INET) {
1734 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
1735 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
1736 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
1737 (char *)&addr->sin_addr));
1738 } else if (dst_addr->sa_family == AF_INET6) {
1739 memcpy(&qla_ep->dst_addr, dst_addr,
1740 sizeof(struct sockaddr_in6));
1741 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
1742 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
1743 (char *)&addr6->sin6_addr));
1745 ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
1749 qla_ep->host = shost;
1754 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1756 struct qla_endpoint *qla_ep;
1757 struct scsi_qla_host *ha;
1760 qla_ep = ep->dd_data;
1761 ha = to_qla_host(qla_ep->host);
1762 DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
1764 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
1770 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
1772 struct qla_endpoint *qla_ep;
1773 struct scsi_qla_host *ha;
1775 qla_ep = ep->dd_data;
1776 ha = to_qla_host(qla_ep->host);
1777 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1779 iscsi_destroy_endpoint(ep);
1782 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
1783 enum iscsi_param param,
1786 struct qla_endpoint *qla_ep = ep->dd_data;
1787 struct sockaddr *dst_addr;
1788 struct scsi_qla_host *ha;
1793 ha = to_qla_host(qla_ep->host);
1794 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1798 case ISCSI_PARAM_CONN_PORT:
1799 case ISCSI_PARAM_CONN_ADDRESS:
1800 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1804 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1805 &qla_ep->dst_addr, param, buf);
1811 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
1812 struct iscsi_stats *stats)
1814 struct iscsi_session *sess;
1815 struct iscsi_cls_session *cls_sess;
1816 struct ddb_entry *ddb_entry;
1817 struct scsi_qla_host *ha;
1818 struct ql_iscsi_stats *ql_iscsi_stats;
1821 dma_addr_t iscsi_stats_dma;
1823 cls_sess = iscsi_conn_to_session(cls_conn);
1824 sess = cls_sess->dd_data;
1825 ddb_entry = sess->dd_data;
1828 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
1830 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
1831 /* Allocate memory */
1832 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
1833 &iscsi_stats_dma, GFP_KERNEL);
1834 if (!ql_iscsi_stats) {
1835 ql4_printk(KERN_ERR, ha,
1836 "Unable to allocate memory for iscsi stats\n");
1837 goto exit_get_stats;
1840 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
1842 if (ret != QLA_SUCCESS) {
1843 ql4_printk(KERN_ERR, ha,
1844 "Unable to retrieve iscsi stats\n");
1849 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
1850 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
1852 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
1853 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
1854 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
1855 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
1856 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
1857 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
1858 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
1859 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
1861 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
1862 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
1863 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
1864 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
1865 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
1866 stats->logoutrsp_pdus =
1867 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
1868 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
1869 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
1870 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
1873 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
1879 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
1881 struct iscsi_cls_session *session;
1882 unsigned long flags;
1883 enum blk_eh_timer_return ret = BLK_EH_DONE;
1885 session = starget_to_session(scsi_target(sc->device));
1887 spin_lock_irqsave(&session->lock, flags);
1888 if (session->state == ISCSI_SESSION_FAILED)
1889 ret = BLK_EH_RESET_TIMER;
1890 spin_unlock_irqrestore(&session->lock, flags);
1895 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
1897 struct scsi_qla_host *ha = to_qla_host(shost);
1898 struct iscsi_cls_host *ihost = shost->shost_data;
1899 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
1901 qla4xxx_get_firmware_state(ha);
1903 switch (ha->addl_fw_state & 0x0F00) {
1904 case FW_ADDSTATE_LINK_SPEED_10MBPS:
1905 speed = ISCSI_PORT_SPEED_10MBPS;
1907 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1908 speed = ISCSI_PORT_SPEED_100MBPS;
1910 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1911 speed = ISCSI_PORT_SPEED_1GBPS;
1913 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1914 speed = ISCSI_PORT_SPEED_10GBPS;
1917 ihost->port_speed = speed;
1920 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1922 struct scsi_qla_host *ha = to_qla_host(shost);
1923 struct iscsi_cls_host *ihost = shost->shost_data;
1924 uint32_t state = ISCSI_PORT_STATE_DOWN;
1926 if (test_bit(AF_LINK_UP, &ha->flags))
1927 state = ISCSI_PORT_STATE_UP;
1929 ihost->port_state = state;
1932 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1933 enum iscsi_host_param param, char *buf)
1935 struct scsi_qla_host *ha = to_qla_host(shost);
1939 case ISCSI_HOST_PARAM_HWADDRESS:
1940 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1942 case ISCSI_HOST_PARAM_IPADDRESS:
1943 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1945 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1946 len = sprintf(buf, "%s\n", ha->name_string);
1948 case ISCSI_HOST_PARAM_PORT_STATE:
1949 qla4xxx_set_port_state(shost);
1950 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1952 case ISCSI_HOST_PARAM_PORT_SPEED:
1953 qla4xxx_set_port_speed(shost);
1954 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1963 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1969 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1970 &qla4xxx_iscsi_transport,
1971 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1972 if (!ha->iface_ipv4)
1973 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1977 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1979 if (!ha->iface_ipv6_0)
1981 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1982 &qla4xxx_iscsi_transport,
1983 ISCSI_IFACE_TYPE_IPV6, 0,
1985 if (!ha->iface_ipv6_0)
1986 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1989 if (!ha->iface_ipv6_1)
1991 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1992 &qla4xxx_iscsi_transport,
1993 ISCSI_IFACE_TYPE_IPV6, 1,
1995 if (!ha->iface_ipv6_1)
1996 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
2000 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
2002 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
2003 qla4xxx_create_ipv4_iface(ha);
2005 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
2006 qla4xxx_create_ipv6_iface(ha);
2009 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
2011 if (ha->iface_ipv4) {
2012 iscsi_destroy_iface(ha->iface_ipv4);
2013 ha->iface_ipv4 = NULL;
2017 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
2019 if (ha->iface_ipv6_0) {
2020 iscsi_destroy_iface(ha->iface_ipv6_0);
2021 ha->iface_ipv6_0 = NULL;
2023 if (ha->iface_ipv6_1) {
2024 iscsi_destroy_iface(ha->iface_ipv6_1);
2025 ha->iface_ipv6_1 = NULL;
2029 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
2031 qla4xxx_destroy_ipv4_iface(ha);
2032 qla4xxx_destroy_ipv6_iface(ha);
2035 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
2036 struct iscsi_iface_param_info *iface_param,
2037 struct addr_ctrl_blk *init_fw_cb)
2040 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
2041 * iface_num 1 is valid only for IPv6 Addr.
2043 switch (iface_param->param) {
2044 case ISCSI_NET_PARAM_IPV6_ADDR:
2045 if (iface_param->iface_num & 0x1)
2047 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
2048 sizeof(init_fw_cb->ipv6_addr1));
2051 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
2052 sizeof(init_fw_cb->ipv6_addr0));
2054 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
2055 if (iface_param->iface_num & 0x1)
2057 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
2058 sizeof(init_fw_cb->ipv6_if_id));
2060 case ISCSI_NET_PARAM_IPV6_ROUTER:
2061 if (iface_param->iface_num & 0x1)
2063 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
2064 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2066 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
2067 /* Autocfg applies to even interface */
2068 if (iface_param->iface_num & 0x1)
2071 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
2072 init_fw_cb->ipv6_addtl_opts &=
2074 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2075 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
2076 init_fw_cb->ipv6_addtl_opts |=
2078 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
2080 ql4_printk(KERN_ERR, ha,
2081 "Invalid autocfg setting for IPv6 addr\n");
2083 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
2084 /* Autocfg applies to even interface */
2085 if (iface_param->iface_num & 0x1)
2088 if (iface_param->value[0] ==
2089 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
2090 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
2091 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2092 else if (iface_param->value[0] ==
2093 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
2094 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
2095 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
2097 ql4_printk(KERN_ERR, ha,
2098 "Invalid autocfg setting for IPv6 linklocal addr\n");
2100 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
2101 /* Autocfg applies to even interface */
2102 if (iface_param->iface_num & 0x1)
2105 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
2106 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
2107 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
2109 case ISCSI_NET_PARAM_IFACE_ENABLE:
2110 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2111 init_fw_cb->ipv6_opts |=
2112 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
2113 qla4xxx_create_ipv6_iface(ha);
2115 init_fw_cb->ipv6_opts &=
2116 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
2118 qla4xxx_destroy_ipv6_iface(ha);
2121 case ISCSI_NET_PARAM_VLAN_TAG:
2122 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
2124 init_fw_cb->ipv6_vlan_tag =
2125 cpu_to_be16(*(uint16_t *)iface_param->value);
2127 case ISCSI_NET_PARAM_VLAN_ENABLED:
2128 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2129 init_fw_cb->ipv6_opts |=
2130 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
2132 init_fw_cb->ipv6_opts &=
2133 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
2135 case ISCSI_NET_PARAM_MTU:
2136 init_fw_cb->eth_mtu_size =
2137 cpu_to_le16(*(uint16_t *)iface_param->value);
2139 case ISCSI_NET_PARAM_PORT:
2140 /* Autocfg applies to even interface */
2141 if (iface_param->iface_num & 0x1)
2144 init_fw_cb->ipv6_port =
2145 cpu_to_le16(*(uint16_t *)iface_param->value);
2147 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2148 if (iface_param->iface_num & 0x1)
2150 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2151 init_fw_cb->ipv6_tcp_opts |=
2152 cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
2154 init_fw_cb->ipv6_tcp_opts &=
2155 cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
2158 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2159 if (iface_param->iface_num & 0x1)
2161 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2162 init_fw_cb->ipv6_tcp_opts |=
2163 cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2165 init_fw_cb->ipv6_tcp_opts &=
2166 cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
2168 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2169 if (iface_param->iface_num & 0x1)
2171 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2172 init_fw_cb->ipv6_tcp_opts |=
2173 cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2175 init_fw_cb->ipv6_tcp_opts &=
2176 cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
2178 case ISCSI_NET_PARAM_TCP_WSF:
2179 if (iface_param->iface_num & 0x1)
2181 init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
2183 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2184 if (iface_param->iface_num & 0x1)
2186 init_fw_cb->ipv6_tcp_opts &=
2187 cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
2188 init_fw_cb->ipv6_tcp_opts |=
2189 cpu_to_le16((iface_param->value[0] << 1) &
2190 IPV6_TCPOPT_TIMER_SCALE);
2192 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2193 if (iface_param->iface_num & 0x1)
2195 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2196 init_fw_cb->ipv6_tcp_opts |=
2197 cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
2199 init_fw_cb->ipv6_tcp_opts &=
2200 cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
2202 case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
2203 if (iface_param->iface_num & 0x1)
2205 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2206 init_fw_cb->ipv6_opts |=
2207 cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2209 init_fw_cb->ipv6_opts &=
2210 cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
2212 case ISCSI_NET_PARAM_REDIRECT_EN:
2213 if (iface_param->iface_num & 0x1)
2215 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2216 init_fw_cb->ipv6_opts |=
2217 cpu_to_le16(IPV6_OPT_REDIRECT_EN);
2219 init_fw_cb->ipv6_opts &=
2220 cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
2222 case ISCSI_NET_PARAM_IPV6_MLD_EN:
2223 if (iface_param->iface_num & 0x1)
2225 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2226 init_fw_cb->ipv6_addtl_opts |=
2227 cpu_to_le16(IPV6_ADDOPT_MLD_EN);
2229 init_fw_cb->ipv6_addtl_opts &=
2230 cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
2232 case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
2233 if (iface_param->iface_num & 0x1)
2235 init_fw_cb->ipv6_flow_lbl =
2236 cpu_to_le16(*(uint16_t *)iface_param->value);
2238 case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
2239 if (iface_param->iface_num & 0x1)
2241 init_fw_cb->ipv6_traffic_class = iface_param->value[0];
2243 case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
2244 if (iface_param->iface_num & 0x1)
2246 init_fw_cb->ipv6_hop_limit = iface_param->value[0];
2248 case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
2249 if (iface_param->iface_num & 0x1)
2251 init_fw_cb->ipv6_nd_reach_time =
2252 cpu_to_le32(*(uint32_t *)iface_param->value);
2254 case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
2255 if (iface_param->iface_num & 0x1)
2257 init_fw_cb->ipv6_nd_rexmit_timer =
2258 cpu_to_le32(*(uint32_t *)iface_param->value);
2260 case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
2261 if (iface_param->iface_num & 0x1)
2263 init_fw_cb->ipv6_nd_stale_timeout =
2264 cpu_to_le32(*(uint32_t *)iface_param->value);
2266 case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
2267 if (iface_param->iface_num & 0x1)
2269 init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
2271 case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
2272 if (iface_param->iface_num & 0x1)
2274 init_fw_cb->ipv6_gw_advrt_mtu =
2275 cpu_to_le32(*(uint32_t *)iface_param->value);
2278 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
2279 iface_param->param);
2284 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
2285 struct iscsi_iface_param_info *iface_param,
2286 struct addr_ctrl_blk *init_fw_cb)
2288 switch (iface_param->param) {
2289 case ISCSI_NET_PARAM_IPV4_ADDR:
2290 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
2291 sizeof(init_fw_cb->ipv4_addr));
2293 case ISCSI_NET_PARAM_IPV4_SUBNET:
2294 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
2295 sizeof(init_fw_cb->ipv4_subnet));
2297 case ISCSI_NET_PARAM_IPV4_GW:
2298 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
2299 sizeof(init_fw_cb->ipv4_gw_addr));
2301 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
2302 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
2303 init_fw_cb->ipv4_tcp_opts |=
2304 cpu_to_le16(TCPOPT_DHCP_ENABLE);
2305 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
2306 init_fw_cb->ipv4_tcp_opts &=
2307 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
2309 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
2311 case ISCSI_NET_PARAM_IFACE_ENABLE:
2312 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
2313 init_fw_cb->ipv4_ip_opts |=
2314 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
2315 qla4xxx_create_ipv4_iface(ha);
2317 init_fw_cb->ipv4_ip_opts &=
2318 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
2320 qla4xxx_destroy_ipv4_iface(ha);
2323 case ISCSI_NET_PARAM_VLAN_TAG:
2324 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
2326 init_fw_cb->ipv4_vlan_tag =
2327 cpu_to_be16(*(uint16_t *)iface_param->value);
2329 case ISCSI_NET_PARAM_VLAN_ENABLED:
2330 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
2331 init_fw_cb->ipv4_ip_opts |=
2332 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
2334 init_fw_cb->ipv4_ip_opts &=
2335 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
2337 case ISCSI_NET_PARAM_MTU:
2338 init_fw_cb->eth_mtu_size =
2339 cpu_to_le16(*(uint16_t *)iface_param->value);
2341 case ISCSI_NET_PARAM_PORT:
2342 init_fw_cb->ipv4_port =
2343 cpu_to_le16(*(uint16_t *)iface_param->value);
2345 case ISCSI_NET_PARAM_DELAYED_ACK_EN:
2346 if (iface_param->iface_num & 0x1)
2348 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2349 init_fw_cb->ipv4_tcp_opts |=
2350 cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
2352 init_fw_cb->ipv4_tcp_opts &=
2353 cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
2356 case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
2357 if (iface_param->iface_num & 0x1)
2359 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2360 init_fw_cb->ipv4_tcp_opts |=
2361 cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
2363 init_fw_cb->ipv4_tcp_opts &=
2364 cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
2366 case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
2367 if (iface_param->iface_num & 0x1)
2369 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2370 init_fw_cb->ipv4_tcp_opts |=
2371 cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
2373 init_fw_cb->ipv4_tcp_opts &=
2374 cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
2376 case ISCSI_NET_PARAM_TCP_WSF:
2377 if (iface_param->iface_num & 0x1)
2379 init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
2381 case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
2382 if (iface_param->iface_num & 0x1)
2384 init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
2385 init_fw_cb->ipv4_tcp_opts |=
2386 cpu_to_le16((iface_param->value[0] << 1) &
2387 TCPOPT_TIMER_SCALE);
2389 case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
2390 if (iface_param->iface_num & 0x1)
2392 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2393 init_fw_cb->ipv4_tcp_opts |=
2394 cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
2396 init_fw_cb->ipv4_tcp_opts &=
2397 cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
2399 case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
2400 if (iface_param->iface_num & 0x1)
2402 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2403 init_fw_cb->ipv4_tcp_opts |=
2404 cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
2406 init_fw_cb->ipv4_tcp_opts &=
2407 cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
2409 case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
2410 if (iface_param->iface_num & 0x1)
2412 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2413 init_fw_cb->ipv4_tcp_opts |=
2414 cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
2416 init_fw_cb->ipv4_tcp_opts &=
2417 cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
2419 case ISCSI_NET_PARAM_IPV4_TOS_EN:
2420 if (iface_param->iface_num & 0x1)
2422 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2423 init_fw_cb->ipv4_ip_opts |=
2424 cpu_to_le16(IPOPT_IPV4_TOS_EN);
2426 init_fw_cb->ipv4_ip_opts &=
2427 cpu_to_le16(~IPOPT_IPV4_TOS_EN);
2429 case ISCSI_NET_PARAM_IPV4_TOS:
2430 if (iface_param->iface_num & 0x1)
2432 init_fw_cb->ipv4_tos = iface_param->value[0];
2434 case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
2435 if (iface_param->iface_num & 0x1)
2437 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2438 init_fw_cb->ipv4_ip_opts |=
2439 cpu_to_le16(IPOPT_GRAT_ARP_EN);
2441 init_fw_cb->ipv4_ip_opts &=
2442 cpu_to_le16(~IPOPT_GRAT_ARP_EN);
2444 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
2445 if (iface_param->iface_num & 0x1)
2447 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2448 init_fw_cb->ipv4_ip_opts |=
2449 cpu_to_le16(IPOPT_ALT_CID_EN);
2451 init_fw_cb->ipv4_ip_opts &=
2452 cpu_to_le16(~IPOPT_ALT_CID_EN);
2454 case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
2455 if (iface_param->iface_num & 0x1)
2457 memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
2458 (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
2459 init_fw_cb->ipv4_dhcp_alt_cid_len =
2460 strlen(init_fw_cb->ipv4_dhcp_alt_cid);
2462 case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
2463 if (iface_param->iface_num & 0x1)
2465 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2466 init_fw_cb->ipv4_ip_opts |=
2467 cpu_to_le16(IPOPT_REQ_VID_EN);
2469 init_fw_cb->ipv4_ip_opts &=
2470 cpu_to_le16(~IPOPT_REQ_VID_EN);
2472 case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
2473 if (iface_param->iface_num & 0x1)
2475 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2476 init_fw_cb->ipv4_ip_opts |=
2477 cpu_to_le16(IPOPT_USE_VID_EN);
2479 init_fw_cb->ipv4_ip_opts &=
2480 cpu_to_le16(~IPOPT_USE_VID_EN);
2482 case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
2483 if (iface_param->iface_num & 0x1)
2485 memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
2486 (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
2487 init_fw_cb->ipv4_dhcp_vid_len =
2488 strlen(init_fw_cb->ipv4_dhcp_vid);
2490 case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
2491 if (iface_param->iface_num & 0x1)
2493 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2494 init_fw_cb->ipv4_ip_opts |=
2495 cpu_to_le16(IPOPT_LEARN_IQN_EN);
2497 init_fw_cb->ipv4_ip_opts &=
2498 cpu_to_le16(~IPOPT_LEARN_IQN_EN);
2500 case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
2501 if (iface_param->iface_num & 0x1)
2503 if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
2504 init_fw_cb->ipv4_ip_opts |=
2505 cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
2507 init_fw_cb->ipv4_ip_opts &=
2508 cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
2510 case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
2511 if (iface_param->iface_num & 0x1)
2513 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2514 init_fw_cb->ipv4_ip_opts |=
2515 cpu_to_le16(IPOPT_IN_FORWARD_EN);
2517 init_fw_cb->ipv4_ip_opts &=
2518 cpu_to_le16(~IPOPT_IN_FORWARD_EN);
2520 case ISCSI_NET_PARAM_REDIRECT_EN:
2521 if (iface_param->iface_num & 0x1)
2523 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2524 init_fw_cb->ipv4_ip_opts |=
2525 cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
2527 init_fw_cb->ipv4_ip_opts &=
2528 cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
2530 case ISCSI_NET_PARAM_IPV4_TTL:
2531 if (iface_param->iface_num & 0x1)
2533 init_fw_cb->ipv4_ttl = iface_param->value[0];
2536 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
2537 iface_param->param);
2542 static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
2543 struct iscsi_iface_param_info *iface_param,
2544 struct addr_ctrl_blk *init_fw_cb)
2546 switch (iface_param->param) {
2547 case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
2548 if (iface_param->iface_num & 0x1)
2550 init_fw_cb->def_timeout =
2551 cpu_to_le16(*(uint16_t *)iface_param->value);
2553 case ISCSI_IFACE_PARAM_HDRDGST_EN:
2554 if (iface_param->iface_num & 0x1)
2556 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2557 init_fw_cb->iscsi_opts |=
2558 cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
2560 init_fw_cb->iscsi_opts &=
2561 cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
2563 case ISCSI_IFACE_PARAM_DATADGST_EN:
2564 if (iface_param->iface_num & 0x1)
2566 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2567 init_fw_cb->iscsi_opts |=
2568 cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
2570 init_fw_cb->iscsi_opts &=
2571 cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
2573 case ISCSI_IFACE_PARAM_IMM_DATA_EN:
2574 if (iface_param->iface_num & 0x1)
2576 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2577 init_fw_cb->iscsi_opts |=
2578 cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
2580 init_fw_cb->iscsi_opts &=
2581 cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
2583 case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
2584 if (iface_param->iface_num & 0x1)
2586 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2587 init_fw_cb->iscsi_opts |=
2588 cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
2590 init_fw_cb->iscsi_opts &=
2591 cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
2593 case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
2594 if (iface_param->iface_num & 0x1)
2596 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2597 init_fw_cb->iscsi_opts |=
2598 cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
2600 init_fw_cb->iscsi_opts &=
2601 cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
2603 case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
2604 if (iface_param->iface_num & 0x1)
2606 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2607 init_fw_cb->iscsi_opts |=
2608 cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
2610 init_fw_cb->iscsi_opts &=
2611 cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
2613 case ISCSI_IFACE_PARAM_ERL:
2614 if (iface_param->iface_num & 0x1)
2616 init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
2617 init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
2620 case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
2621 if (iface_param->iface_num & 0x1)
2623 init_fw_cb->iscsi_max_pdu_size =
2624 cpu_to_le32(*(uint32_t *)iface_param->value) /
2627 case ISCSI_IFACE_PARAM_FIRST_BURST:
2628 if (iface_param->iface_num & 0x1)
2630 init_fw_cb->iscsi_fburst_len =
2631 cpu_to_le32(*(uint32_t *)iface_param->value) /
2634 case ISCSI_IFACE_PARAM_MAX_R2T:
2635 if (iface_param->iface_num & 0x1)
2637 init_fw_cb->iscsi_max_outstnd_r2t =
2638 cpu_to_le16(*(uint16_t *)iface_param->value);
2640 case ISCSI_IFACE_PARAM_MAX_BURST:
2641 if (iface_param->iface_num & 0x1)
2643 init_fw_cb->iscsi_max_burst_len =
2644 cpu_to_le32(*(uint32_t *)iface_param->value) /
2647 case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
2648 if (iface_param->iface_num & 0x1)
2650 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2651 init_fw_cb->iscsi_opts |=
2652 cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
2654 init_fw_cb->iscsi_opts &=
2655 cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
2657 case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
2658 if (iface_param->iface_num & 0x1)
2660 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2661 init_fw_cb->iscsi_opts |=
2662 cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
2664 init_fw_cb->iscsi_opts &=
2665 cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
2667 case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
2668 if (iface_param->iface_num & 0x1)
2670 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2671 init_fw_cb->iscsi_opts |=
2672 cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
2674 init_fw_cb->iscsi_opts &=
2675 cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
2677 case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
2678 if (iface_param->iface_num & 0x1)
2680 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2681 init_fw_cb->iscsi_opts |=
2682 cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2684 init_fw_cb->iscsi_opts &=
2685 cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
2687 case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
2688 if (iface_param->iface_num & 0x1)
2690 if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
2691 init_fw_cb->iscsi_opts |=
2692 cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2694 init_fw_cb->iscsi_opts &=
2695 cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
2698 ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
2699 iface_param->param);
2705 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
2707 struct addr_ctrl_blk_def *acb;
2708 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
2709 memset(acb->reserved1, 0, sizeof(acb->reserved1));
2710 memset(acb->reserved2, 0, sizeof(acb->reserved2));
2711 memset(acb->reserved3, 0, sizeof(acb->reserved3));
2712 memset(acb->reserved4, 0, sizeof(acb->reserved4));
2713 memset(acb->reserved5, 0, sizeof(acb->reserved5));
2714 memset(acb->reserved6, 0, sizeof(acb->reserved6));
2715 memset(acb->reserved7, 0, sizeof(acb->reserved7));
2716 memset(acb->reserved8, 0, sizeof(acb->reserved8));
2717 memset(acb->reserved9, 0, sizeof(acb->reserved9));
2718 memset(acb->reserved10, 0, sizeof(acb->reserved10));
2719 memset(acb->reserved11, 0, sizeof(acb->reserved11));
2720 memset(acb->reserved12, 0, sizeof(acb->reserved12));
2721 memset(acb->reserved13, 0, sizeof(acb->reserved13));
2722 memset(acb->reserved14, 0, sizeof(acb->reserved14));
2723 memset(acb->reserved15, 0, sizeof(acb->reserved15));
2727 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
2729 struct scsi_qla_host *ha = to_qla_host(shost);
2731 struct iscsi_iface_param_info *iface_param = NULL;
2732 struct addr_ctrl_blk *init_fw_cb = NULL;
2733 dma_addr_t init_fw_cb_dma;
2734 uint32_t mbox_cmd[MBOX_REG_COUNT];
2735 uint32_t mbox_sts[MBOX_REG_COUNT];
2737 struct nlattr *attr;
2739 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2740 sizeof(struct addr_ctrl_blk),
2741 &init_fw_cb_dma, GFP_KERNEL);
2743 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
2748 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2749 memset(&mbox_sts, 0, sizeof(mbox_sts));
2751 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
2752 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
2754 goto exit_init_fw_cb;
2757 nla_for_each_attr(attr, data, len, rem) {
2758 iface_param = nla_data(attr);
2760 if (iface_param->param_type == ISCSI_NET_PARAM) {
2761 switch (iface_param->iface_type) {
2762 case ISCSI_IFACE_TYPE_IPV4:
2763 switch (iface_param->iface_num) {
2765 qla4xxx_set_ipv4(ha, iface_param,
2769 /* Cannot have more than one IPv4 interface */
2770 ql4_printk(KERN_ERR, ha,
2771 "Invalid IPv4 iface number = %d\n",
2772 iface_param->iface_num);
2776 case ISCSI_IFACE_TYPE_IPV6:
2777 switch (iface_param->iface_num) {
2780 qla4xxx_set_ipv6(ha, iface_param,
2784 /* Cannot have more than two IPv6 interface */
2785 ql4_printk(KERN_ERR, ha,
2786 "Invalid IPv6 iface number = %d\n",
2787 iface_param->iface_num);
2792 ql4_printk(KERN_ERR, ha,
2793 "Invalid iface type\n");
2796 } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
2797 qla4xxx_set_iscsi_param(ha, iface_param,
2804 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
2806 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
2807 sizeof(struct addr_ctrl_blk),
2808 FLASH_OPT_RMW_COMMIT);
2809 if (rval != QLA_SUCCESS) {
2810 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
2813 goto exit_init_fw_cb;
2816 rval = qla4xxx_disable_acb(ha);
2817 if (rval != QLA_SUCCESS) {
2818 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
2821 goto exit_init_fw_cb;
2824 wait_for_completion_timeout(&ha->disable_acb_comp,
2825 DISABLE_ACB_TOV * HZ);
2827 qla4xxx_initcb_to_acb(init_fw_cb);
2829 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
2830 if (rval != QLA_SUCCESS) {
2831 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
2834 goto exit_init_fw_cb;
2837 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
2838 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
2842 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
2843 init_fw_cb, init_fw_cb_dma);
2848 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
2849 enum iscsi_param param, char *buf)
2851 struct iscsi_session *sess = cls_sess->dd_data;
2852 struct ddb_entry *ddb_entry = sess->dd_data;
2853 struct scsi_qla_host *ha = ddb_entry->ha;
2854 struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
2855 struct ql4_chap_table chap_tbl;
2859 memset(&chap_tbl, 0, sizeof(chap_tbl));
2861 case ISCSI_PARAM_CHAP_IN_IDX:
2862 rval = qla4xxx_get_chap_index(ha, sess->username_in,
2863 sess->password_in, BIDI_CHAP,
2866 len = sprintf(buf, "\n");
2868 len = sprintf(buf, "%hu\n", idx);
2870 case ISCSI_PARAM_CHAP_OUT_IDX:
2871 if (ddb_entry->ddb_type == FLASH_DDB) {
2872 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
2873 idx = ddb_entry->chap_tbl_idx;
2879 rval = qla4xxx_get_chap_index(ha, sess->username,
2884 len = sprintf(buf, "\n");
2886 len = sprintf(buf, "%hu\n", idx);
2888 case ISCSI_PARAM_USERNAME:
2889 case ISCSI_PARAM_PASSWORD:
2890 /* First, populate session username and password for FLASH DDB,
2891 * if not already done. This happens when session login fails
2894 if (ddb_entry->ddb_type == FLASH_DDB &&
2895 ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
2896 !sess->username && !sess->password) {
2897 idx = ddb_entry->chap_tbl_idx;
2898 rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
2902 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
2903 (char *)chap_tbl.name,
2904 strlen((char *)chap_tbl.name));
2905 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
2906 (char *)chap_tbl.secret,
2907 chap_tbl.secret_len);
2912 return iscsi_session_get_param(cls_sess, param, buf);
2918 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
2919 enum iscsi_param param, char *buf)
2921 struct iscsi_conn *conn;
2922 struct qla_conn *qla_conn;
2923 struct sockaddr *dst_addr;
2925 conn = cls_conn->dd_data;
2926 qla_conn = conn->dd_data;
2927 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
2930 case ISCSI_PARAM_CONN_PORT:
2931 case ISCSI_PARAM_CONN_ADDRESS:
2932 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
2933 dst_addr, param, buf);
2935 return iscsi_conn_get_param(cls_conn, param, buf);
2939 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
2941 uint32_t mbx_sts = 0;
2942 uint16_t tmp_ddb_index;
2946 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
2948 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
2949 DEBUG2(ql4_printk(KERN_INFO, ha,
2950 "Free DDB index not available\n"));
2952 goto exit_get_ddb_index;
2955 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
2958 DEBUG2(ql4_printk(KERN_INFO, ha,
2959 "Found a free DDB index at %d\n", tmp_ddb_index));
2960 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
2961 if (ret == QLA_ERROR) {
2962 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
2963 ql4_printk(KERN_INFO, ha,
2964 "DDB index = %d not available trying next\n",
2968 DEBUG2(ql4_printk(KERN_INFO, ha,
2969 "Free FW DDB not available\n"));
2972 *ddb_index = tmp_ddb_index;
2978 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
2979 struct ddb_entry *ddb_entry,
2980 char *existing_ipaddr,
2983 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
2984 char formatted_ipaddr[DDB_IPADDR_LEN];
2985 int status = QLA_SUCCESS, ret = 0;
2987 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
2988 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
2994 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
2996 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
3002 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
3005 if (strcmp(existing_ipaddr, formatted_ipaddr))
3012 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
3013 struct iscsi_cls_conn *cls_conn)
3015 int idx = 0, max_ddbs, rval;
3016 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3017 struct iscsi_session *sess, *existing_sess;
3018 struct iscsi_conn *conn, *existing_conn;
3019 struct ddb_entry *ddb_entry;
3021 sess = cls_sess->dd_data;
3022 conn = cls_conn->dd_data;
3024 if (sess->targetname == NULL ||
3025 conn->persistent_address == NULL ||
3026 conn->persistent_port == 0)
3029 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
3032 for (idx = 0; idx < max_ddbs; idx++) {
3033 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3034 if (ddb_entry == NULL)
3037 if (ddb_entry->ddb_type != FLASH_DDB)
3040 existing_sess = ddb_entry->sess->dd_data;
3041 existing_conn = ddb_entry->conn->dd_data;
3043 if (existing_sess->targetname == NULL ||
3044 existing_conn->persistent_address == NULL ||
3045 existing_conn->persistent_port == 0)
3048 DEBUG2(ql4_printk(KERN_INFO, ha,
3049 "IQN = %s User IQN = %s\n",
3050 existing_sess->targetname,
3053 DEBUG2(ql4_printk(KERN_INFO, ha,
3054 "IP = %s User IP = %s\n",
3055 existing_conn->persistent_address,
3056 conn->persistent_address));
3058 DEBUG2(ql4_printk(KERN_INFO, ha,
3059 "Port = %d User Port = %d\n",
3060 existing_conn->persistent_port,
3061 conn->persistent_port));
3063 if (strcmp(existing_sess->targetname, sess->targetname))
3065 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
3066 existing_conn->persistent_address,
3067 conn->persistent_address);
3068 if (rval == QLA_ERROR)
3070 if (existing_conn->persistent_port != conn->persistent_port)
3075 if (idx == max_ddbs)
3078 DEBUG2(ql4_printk(KERN_INFO, ha,
3079 "Match found in fwdb sessions\n"));
3083 static struct iscsi_cls_session *
3084 qla4xxx_session_create(struct iscsi_endpoint *ep,
3085 uint16_t cmds_max, uint16_t qdepth,
3086 uint32_t initial_cmdsn)
3088 struct iscsi_cls_session *cls_sess;
3089 struct scsi_qla_host *ha;
3090 struct qla_endpoint *qla_ep;
3091 struct ddb_entry *ddb_entry;
3093 struct iscsi_session *sess;
3097 printk(KERN_ERR "qla4xxx: missing ep.\n");
3101 qla_ep = ep->dd_data;
3102 ha = to_qla_host(qla_ep->host);
3103 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3106 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
3107 if (ret == QLA_ERROR)
3110 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
3111 cmds_max, sizeof(struct ddb_entry),
3112 sizeof(struct ql4_task_data),
3113 initial_cmdsn, ddb_index);
3117 sess = cls_sess->dd_data;
3118 ddb_entry = sess->dd_data;
3119 ddb_entry->fw_ddb_index = ddb_index;
3120 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3122 ddb_entry->sess = cls_sess;
3123 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
3124 ddb_entry->ddb_change = qla4xxx_ddb_change;
3125 clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
3126 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
3127 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
3133 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
3135 struct iscsi_session *sess;
3136 struct ddb_entry *ddb_entry;
3137 struct scsi_qla_host *ha;
3138 unsigned long flags, wtime;
3139 struct dev_db_entry *fw_ddb_entry = NULL;
3140 dma_addr_t fw_ddb_entry_dma;
3144 sess = cls_sess->dd_data;
3145 ddb_entry = sess->dd_data;
3147 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
3150 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3151 &fw_ddb_entry_dma, GFP_KERNEL);
3152 if (!fw_ddb_entry) {
3153 ql4_printk(KERN_ERR, ha,
3154 "%s: Unable to allocate dma buffer\n", __func__);
3155 goto destroy_session;
3158 wtime = jiffies + (HZ * LOGOUT_TOV);
3160 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
3161 fw_ddb_entry, fw_ddb_entry_dma,
3162 NULL, NULL, &ddb_state, NULL,
3164 if (ret == QLA_ERROR)
3165 goto destroy_session;
3167 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
3168 (ddb_state == DDB_DS_SESSION_FAILED))
3169 goto destroy_session;
3171 schedule_timeout_uninterruptible(HZ);
3172 } while ((time_after(wtime, jiffies)));
3175 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
3176 if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
3177 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
3178 spin_lock_irqsave(&ha->hardware_lock, flags);
3179 qla4xxx_free_ddb(ha, ddb_entry);
3180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3182 iscsi_session_teardown(cls_sess);
3185 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3186 fw_ddb_entry, fw_ddb_entry_dma);
3189 static struct iscsi_cls_conn *
3190 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
3192 struct iscsi_cls_conn *cls_conn;
3193 struct iscsi_session *sess;
3194 struct ddb_entry *ddb_entry;
3195 struct scsi_qla_host *ha;
3197 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
3200 pr_info("%s: Can not create connection for conn_idx = %u\n",
3201 __func__, conn_idx);
3205 sess = cls_sess->dd_data;
3206 ddb_entry = sess->dd_data;
3207 ddb_entry->conn = cls_conn;
3210 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
3215 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
3216 struct iscsi_cls_conn *cls_conn,
3217 uint64_t transport_fd, int is_leading)
3219 struct iscsi_conn *conn;
3220 struct qla_conn *qla_conn;
3221 struct iscsi_endpoint *ep;
3222 struct ddb_entry *ddb_entry;
3223 struct scsi_qla_host *ha;
3224 struct iscsi_session *sess;
3226 sess = cls_session->dd_data;
3227 ddb_entry = sess->dd_data;
3230 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3231 cls_session->sid, cls_conn->cid));
3233 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
3235 ep = iscsi_lookup_endpoint(transport_fd);
3238 conn = cls_conn->dd_data;
3239 qla_conn = conn->dd_data;
3240 qla_conn->qla_ep = ep->dd_data;
3244 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
3246 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3247 struct iscsi_session *sess;
3248 struct ddb_entry *ddb_entry;
3249 struct scsi_qla_host *ha;
3250 struct dev_db_entry *fw_ddb_entry = NULL;
3251 dma_addr_t fw_ddb_entry_dma;
3252 uint32_t mbx_sts = 0;
3254 int status = QLA_SUCCESS;
3256 sess = cls_sess->dd_data;
3257 ddb_entry = sess->dd_data;
3259 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
3260 cls_sess->sid, cls_conn->cid));
3262 /* Check if we have matching FW DDB, if yes then do not
3263 * login to this target. This could cause target to logout previous
3266 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
3267 if (ret == QLA_SUCCESS) {
3268 ql4_printk(KERN_INFO, ha,
3269 "Session already exist in FW.\n");
3271 goto exit_conn_start;
3274 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3275 &fw_ddb_entry_dma, GFP_KERNEL);
3276 if (!fw_ddb_entry) {
3277 ql4_printk(KERN_ERR, ha,
3278 "%s: Unable to allocate dma buffer\n", __func__);
3280 goto exit_conn_start;
3283 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
3285 /* If iscsid is stopped and started then no need to do
3286 * set param again since ddb state will be already
3287 * active and FW does not allow set ddb to an
3291 if (ddb_entry->fw_ddb_device_state ==
3292 DDB_DS_SESSION_ACTIVE) {
3293 ddb_entry->unblock_sess(ddb_entry->sess);
3294 goto exit_set_param;
3297 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
3298 __func__, ddb_entry->fw_ddb_index);
3299 goto exit_conn_start;
3302 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
3303 if (status == QLA_ERROR) {
3304 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
3307 goto exit_conn_start;
3310 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
3311 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
3313 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
3314 ddb_entry->fw_ddb_device_state));
3321 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3322 fw_ddb_entry, fw_ddb_entry_dma);
3326 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
3328 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
3329 struct iscsi_session *sess;
3330 struct scsi_qla_host *ha;
3331 struct ddb_entry *ddb_entry;
3334 sess = cls_sess->dd_data;
3335 ddb_entry = sess->dd_data;
3337 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
3340 options = LOGOUT_OPTION_CLOSE_SESSION;
3341 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
3342 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
3345 static void qla4xxx_task_work(struct work_struct *wdata)
3347 struct ql4_task_data *task_data;
3348 struct scsi_qla_host *ha;
3349 struct passthru_status *sts;
3350 struct iscsi_task *task;
3351 struct iscsi_hdr *hdr;
3354 struct iscsi_conn *conn;
3358 task_data = container_of(wdata, struct ql4_task_data, task_work);
3360 task = task_data->task;
3361 sts = &task_data->sts;
3362 hdr_len = sizeof(struct iscsi_hdr);
3364 DEBUG3(printk(KERN_INFO "Status returned\n"));
3365 DEBUG3(qla4xxx_dump_buffer(sts, 64));
3366 DEBUG3(printk(KERN_INFO "Response buffer"));
3367 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
3371 switch (sts->completionStatus) {
3372 case PASSTHRU_STATUS_COMPLETE:
3373 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
3374 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
3377 data = task_data->resp_buffer + hdr_len;
3378 data_len = task_data->resp_len - hdr_len;
3379 iscsi_complete_pdu(conn, hdr, data, data_len);
3382 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
3383 sts->completionStatus);
3389 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3391 struct ql4_task_data *task_data;
3392 struct iscsi_session *sess;
3393 struct ddb_entry *ddb_entry;
3394 struct scsi_qla_host *ha;
3397 sess = task->conn->session;
3398 ddb_entry = sess->dd_data;
3400 task_data = task->dd_data;
3401 memset(task_data, 0, sizeof(struct ql4_task_data));
3404 ql4_printk(KERN_INFO, ha,
3405 "%s: SCSI Commands not implemented\n", __func__);
3409 hdr_len = sizeof(struct iscsi_hdr);
3411 task_data->task = task;
3413 if (task->data_count) {
3414 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
3419 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3420 __func__, task->conn->max_recv_dlength, hdr_len));
3422 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
3423 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
3424 task_data->resp_len,
3425 &task_data->resp_dma,
3427 if (!task_data->resp_buffer)
3428 goto exit_alloc_pdu;
3430 task_data->req_len = task->data_count + hdr_len;
3431 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
3433 &task_data->req_dma,
3435 if (!task_data->req_buffer)
3436 goto exit_alloc_pdu;
3438 task->hdr = task_data->req_buffer;
3440 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
3445 if (task_data->resp_buffer)
3446 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3447 task_data->resp_buffer, task_data->resp_dma);
3449 if (task_data->req_buffer)
3450 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3451 task_data->req_buffer, task_data->req_dma);
3455 static void qla4xxx_task_cleanup(struct iscsi_task *task)
3457 struct ql4_task_data *task_data;
3458 struct iscsi_session *sess;
3459 struct ddb_entry *ddb_entry;
3460 struct scsi_qla_host *ha;
3463 hdr_len = sizeof(struct iscsi_hdr);
3464 sess = task->conn->session;
3465 ddb_entry = sess->dd_data;
3467 task_data = task->dd_data;
3469 if (task->data_count) {
3470 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3471 task->data_count, DMA_TO_DEVICE);
3474 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
3475 __func__, task->conn->max_recv_dlength, hdr_len));
3477 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
3478 task_data->resp_buffer, task_data->resp_dma);
3479 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
3480 task_data->req_buffer, task_data->req_dma);
3484 static int qla4xxx_task_xmit(struct iscsi_task *task)
3486 struct scsi_cmnd *sc = task->sc;
3487 struct iscsi_session *sess = task->conn->session;
3488 struct ddb_entry *ddb_entry = sess->dd_data;
3489 struct scsi_qla_host *ha = ddb_entry->ha;
3492 return qla4xxx_send_passthru0(task);
3494 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
3499 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
3500 struct iscsi_bus_flash_conn *conn,
3501 struct dev_db_entry *fw_ddb_entry)
3503 unsigned long options = 0;
3506 options = le16_to_cpu(fw_ddb_entry->options);
3507 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3508 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3509 rc = iscsi_switch_str_param(&sess->portal_type,
3514 rc = iscsi_switch_str_param(&sess->portal_type,
3520 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3522 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3523 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
3525 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3526 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3527 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3528 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3529 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3530 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3532 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3533 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3534 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
3535 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3537 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3538 sess->discovery_auth_optional =
3539 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3540 if (test_bit(ISCSIOPT_ERL1, &options))
3542 if (test_bit(ISCSIOPT_ERL0, &options))
3545 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3546 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3547 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3548 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3549 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3550 conn->tcp_timer_scale |= BIT_3;
3551 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3552 conn->tcp_timer_scale |= BIT_2;
3553 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3554 conn->tcp_timer_scale |= BIT_1;
3556 conn->tcp_timer_scale >>= 1;
3557 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3559 options = le16_to_cpu(fw_ddb_entry->ip_options);
3560 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3562 conn->max_recv_dlength = BYTE_UNITS *
3563 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3564 conn->max_xmit_dlength = BYTE_UNITS *
3565 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3566 sess->first_burst = BYTE_UNITS *
3567 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3568 sess->max_burst = BYTE_UNITS *
3569 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3570 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3571 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3572 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3573 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3574 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3575 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3576 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3577 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
3578 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
3579 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3580 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3581 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3582 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
3583 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
3584 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3585 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3587 sess->default_taskmgmt_timeout =
3588 le16_to_cpu(fw_ddb_entry->def_timeout);
3589 conn->port = le16_to_cpu(fw_ddb_entry->port);
3591 options = le16_to_cpu(fw_ddb_entry->options);
3592 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3593 if (!conn->ipaddress) {
3598 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
3599 if (!conn->redirect_ipaddr) {
3604 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3605 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
3607 if (test_bit(OPT_IPV6_DEVICE, &options)) {
3608 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
3610 conn->link_local_ipv6_addr = kmemdup(
3611 fw_ddb_entry->link_local_ipv6_addr,
3612 IPv6_ADDR_LEN, GFP_KERNEL);
3613 if (!conn->link_local_ipv6_addr) {
3618 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3621 if (fw_ddb_entry->iscsi_name[0]) {
3622 rc = iscsi_switch_str_param(&sess->targetname,
3623 (char *)fw_ddb_entry->iscsi_name);
3628 if (fw_ddb_entry->iscsi_alias[0]) {
3629 rc = iscsi_switch_str_param(&sess->targetalias,
3630 (char *)fw_ddb_entry->iscsi_alias);
3635 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3641 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
3642 struct iscsi_bus_flash_conn *conn,
3643 struct dev_db_entry *fw_ddb_entry)
3648 options = le16_to_cpu(fw_ddb_entry->options);
3649 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
3650 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3655 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
3656 SET_BITVAL(sess->discovery_sess, options, BIT_4);
3657 SET_BITVAL(sess->entry_state, options, BIT_3);
3658 fw_ddb_entry->options = cpu_to_le16(options);
3660 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3661 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
3662 SET_BITVAL(conn->datadgst_en, options, BIT_12);
3663 SET_BITVAL(sess->imm_data_en, options, BIT_11);
3664 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
3665 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
3666 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
3667 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
3668 SET_BITVAL(conn->snack_req_en, options, BIT_6);
3669 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
3670 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
3671 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
3672 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
3673 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
3674 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
3676 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3677 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
3678 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
3679 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
3680 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
3681 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
3682 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
3683 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
3684 fw_ddb_entry->tcp_options = cpu_to_le16(options);
3686 options = le16_to_cpu(fw_ddb_entry->ip_options);
3687 SET_BITVAL(conn->fragment_disable, options, BIT_4);
3688 fw_ddb_entry->ip_options = cpu_to_le16(options);
3690 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
3691 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
3692 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
3693 fw_ddb_entry->iscsi_max_snd_data_seg_len =
3694 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
3695 fw_ddb_entry->iscsi_first_burst_len =
3696 cpu_to_le16(sess->first_burst / BYTE_UNITS);
3697 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
3699 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
3700 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
3701 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
3702 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
3703 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
3704 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
3705 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
3706 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
3707 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
3708 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
3709 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
3710 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
3711 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
3712 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
3713 fw_ddb_entry->port = cpu_to_le16(conn->port);
3714 fw_ddb_entry->def_timeout =
3715 cpu_to_le16(sess->default_taskmgmt_timeout);
3717 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
3718 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
3720 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
3722 if (conn->ipaddress)
3723 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
3724 sizeof(fw_ddb_entry->ip_addr));
3726 if (conn->redirect_ipaddr)
3727 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
3728 sizeof(fw_ddb_entry->tgt_addr));
3730 if (conn->link_local_ipv6_addr)
3731 memcpy(fw_ddb_entry->link_local_ipv6_addr,
3732 conn->link_local_ipv6_addr,
3733 sizeof(fw_ddb_entry->link_local_ipv6_addr));
3735 if (sess->targetname)
3736 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
3737 sizeof(fw_ddb_entry->iscsi_name));
3739 if (sess->targetalias)
3740 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
3741 sizeof(fw_ddb_entry->iscsi_alias));
3743 COPY_ISID(fw_ddb_entry->isid, sess->isid);
3748 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
3749 struct iscsi_session *sess,
3750 struct dev_db_entry *fw_ddb_entry)
3752 unsigned long options = 0;
3754 uint16_t disc_parent;
3755 char ip_addr[DDB_IPADDR_LEN];
3757 options = le16_to_cpu(fw_ddb_entry->options);
3758 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
3759 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
3761 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
3763 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
3764 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
3765 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
3766 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
3767 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
3768 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
3770 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
3771 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
3772 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
3774 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
3775 sess->discovery_auth_optional =
3776 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
3777 if (test_bit(ISCSIOPT_ERL1, &options))
3779 if (test_bit(ISCSIOPT_ERL0, &options))
3782 options = le16_to_cpu(fw_ddb_entry->tcp_options);
3783 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
3784 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
3785 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
3786 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
3787 conn->tcp_timer_scale |= BIT_3;
3788 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
3789 conn->tcp_timer_scale |= BIT_2;
3790 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
3791 conn->tcp_timer_scale |= BIT_1;
3793 conn->tcp_timer_scale >>= 1;
3794 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
3796 options = le16_to_cpu(fw_ddb_entry->ip_options);
3797 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
3799 conn->max_recv_dlength = BYTE_UNITS *
3800 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
3801 conn->max_xmit_dlength = BYTE_UNITS *
3802 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
3803 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
3804 sess->first_burst = BYTE_UNITS *
3805 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
3806 sess->max_burst = BYTE_UNITS *
3807 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
3808 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3809 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
3810 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3811 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
3812 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
3813 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
3814 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
3815 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
3816 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
3817 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
3818 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
3819 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
3820 COPY_ISID(sess->isid, fw_ddb_entry->isid);
3822 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
3823 if (ddb_link == DDB_ISNS)
3824 disc_parent = ISCSI_DISC_PARENT_ISNS;
3825 else if (ddb_link == DDB_NO_LINK)
3826 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3827 else if (ddb_link < MAX_DDB_ENTRIES)
3828 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
3830 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
3832 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
3833 iscsi_get_discovery_parent_name(disc_parent), 0);
3835 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
3836 (char *)fw_ddb_entry->iscsi_alias, 0);
3838 options = le16_to_cpu(fw_ddb_entry->options);
3839 if (options & DDB_OPT_IPV6_DEVICE) {
3840 memset(ip_addr, 0, sizeof(ip_addr));
3841 sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
3842 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
3843 (char *)ip_addr, 0);
3847 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
3848 struct dev_db_entry *fw_ddb_entry,
3849 struct iscsi_cls_session *cls_sess,
3850 struct iscsi_cls_conn *cls_conn)
3853 struct iscsi_session *sess;
3854 struct ddb_entry *ddb_entry;
3855 struct ql4_chap_table chap_tbl;
3856 struct iscsi_conn *conn;
3857 char ip_addr[DDB_IPADDR_LEN];
3858 uint16_t options = 0;
3860 sess = cls_sess->dd_data;
3861 ddb_entry = sess->dd_data;
3862 conn = cls_conn->dd_data;
3863 memset(&chap_tbl, 0, sizeof(chap_tbl));
3865 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3867 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3869 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
3870 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
3872 memset(ip_addr, 0, sizeof(ip_addr));
3873 options = le16_to_cpu(fw_ddb_entry->options);
3874 if (options & DDB_OPT_IPV6_DEVICE) {
3875 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
3877 memset(ip_addr, 0, sizeof(ip_addr));
3878 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3880 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
3881 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3884 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
3885 (char *)ip_addr, buflen);
3886 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
3887 (char *)fw_ddb_entry->iscsi_name, buflen);
3888 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
3889 (char *)ha->name_string, buflen);
3891 if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
3892 if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
3894 ddb_entry->chap_tbl_idx)) {
3895 iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
3896 (char *)chap_tbl.name,
3897 strlen((char *)chap_tbl.name));
3898 iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
3899 (char *)chap_tbl.secret,
3900 chap_tbl.secret_len);
3905 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
3906 struct ddb_entry *ddb_entry)
3908 struct iscsi_cls_session *cls_sess;
3909 struct iscsi_cls_conn *cls_conn;
3911 dma_addr_t fw_ddb_entry_dma;
3912 struct dev_db_entry *fw_ddb_entry;
3914 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3915 &fw_ddb_entry_dma, GFP_KERNEL);
3916 if (!fw_ddb_entry) {
3917 ql4_printk(KERN_ERR, ha,
3918 "%s: Unable to allocate dma buffer\n", __func__);
3919 goto exit_session_conn_fwddb_param;
3922 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3923 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3924 NULL, NULL, NULL) == QLA_ERROR) {
3925 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3926 "get_ddb_entry for fw_ddb_index %d\n",
3927 ha->host_no, __func__,
3928 ddb_entry->fw_ddb_index));
3929 goto exit_session_conn_fwddb_param;
3932 cls_sess = ddb_entry->sess;
3934 cls_conn = ddb_entry->conn;
3937 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
3939 exit_session_conn_fwddb_param:
3941 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3942 fw_ddb_entry, fw_ddb_entry_dma);
3945 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
3946 struct ddb_entry *ddb_entry)
3948 struct iscsi_cls_session *cls_sess;
3949 struct iscsi_cls_conn *cls_conn;
3950 struct iscsi_session *sess;
3951 struct iscsi_conn *conn;
3953 dma_addr_t fw_ddb_entry_dma;
3954 struct dev_db_entry *fw_ddb_entry;
3956 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3957 &fw_ddb_entry_dma, GFP_KERNEL);
3958 if (!fw_ddb_entry) {
3959 ql4_printk(KERN_ERR, ha,
3960 "%s: Unable to allocate dma buffer\n", __func__);
3961 goto exit_session_conn_param;
3964 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
3965 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
3966 NULL, NULL, NULL) == QLA_ERROR) {
3967 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
3968 "get_ddb_entry for fw_ddb_index %d\n",
3969 ha->host_no, __func__,
3970 ddb_entry->fw_ddb_index));
3971 goto exit_session_conn_param;
3974 cls_sess = ddb_entry->sess;
3975 sess = cls_sess->dd_data;
3977 cls_conn = ddb_entry->conn;
3978 conn = cls_conn->dd_data;
3980 /* Update timers after login */
3981 ddb_entry->default_relogin_timeout =
3982 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
3983 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
3984 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
3985 ddb_entry->default_time2wait =
3986 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
3989 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3990 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
3992 memcpy(sess->initiatorname, ha->name_string,
3993 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
3995 exit_session_conn_param:
3997 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3998 fw_ddb_entry, fw_ddb_entry_dma);
4004 static void qla4xxx_timer(struct timer_list *t);
4006 static void qla4xxx_start_timer(struct scsi_qla_host *ha,
4007 unsigned long interval)
4009 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
4010 __func__, ha->host->host_no));
4011 timer_setup(&ha->timer, qla4xxx_timer, 0);
4012 ha->timer.expires = jiffies + interval * HZ;
4013 add_timer(&ha->timer);
4014 ha->timer_active = 1;
4017 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
4019 del_timer_sync(&ha->timer);
4020 ha->timer_active = 0;
4024 * qla4xxx_mark_device_missing - blocks the session
4025 * @cls_session: Pointer to the session to be blocked
4026 * @ddb_entry: Pointer to device database entry
4028 * This routine marks a device missing and close connection.
4030 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
4032 iscsi_block_session(cls_session);
4036 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
4037 * @ha: Pointer to host adapter structure.
4039 * This routine marks a device missing and resets the relogin retry count.
4041 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
4043 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
4046 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
4047 struct ddb_entry *ddb_entry,
4048 struct scsi_cmnd *cmd)
4052 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
4056 kref_init(&srb->srb_ref);
4058 srb->ddb = ddb_entry;
4061 CMD_SP(cmd) = (void *)srb;
4066 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
4068 struct scsi_cmnd *cmd = srb->cmd;
4070 if (srb->flags & SRB_DMA_VALID) {
4071 scsi_dma_unmap(cmd);
4072 srb->flags &= ~SRB_DMA_VALID;
4077 void qla4xxx_srb_compl(struct kref *ref)
4079 struct srb *srb = container_of(ref, struct srb, srb_ref);
4080 struct scsi_cmnd *cmd = srb->cmd;
4081 struct scsi_qla_host *ha = srb->ha;
4083 qla4xxx_srb_free_dma(ha, srb);
4085 mempool_free(srb, ha->srb_mempool);
4087 cmd->scsi_done(cmd);
4091 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
4093 * @cmd: Pointer to Linux's SCSI command structure
4096 * This routine is invoked by Linux to send a SCSI command to the driver.
4097 * The mid-level driver tries to ensure that queuecommand never gets
4098 * invoked concurrently with itself or the interrupt handler (although
4099 * the interrupt handler may call this routine as part of request-
4100 * completion handling). Unfortunely, it sometimes calls the scheduler
4101 * in interrupt context which is a big NO! NO!.
4103 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
4105 struct scsi_qla_host *ha = to_qla_host(host);
4106 struct ddb_entry *ddb_entry = cmd->device->hostdata;
4107 struct iscsi_cls_session *sess = ddb_entry->sess;
4111 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4112 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
4113 cmd->result = DID_NO_CONNECT << 16;
4115 cmd->result = DID_REQUEUE << 16;
4116 goto qc_fail_command;
4120 cmd->result = DID_IMM_RETRY << 16;
4121 goto qc_fail_command;
4124 rval = iscsi_session_chkready(sess);
4127 goto qc_fail_command;
4130 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4131 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4132 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4133 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4134 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4135 !test_bit(AF_ONLINE, &ha->flags) ||
4136 !test_bit(AF_LINK_UP, &ha->flags) ||
4137 test_bit(AF_LOOPBACK, &ha->flags) ||
4138 test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
4139 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
4140 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
4143 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
4147 rval = qla4xxx_send_command_to_isp(ha, srb);
4148 if (rval != QLA_SUCCESS)
4149 goto qc_host_busy_free_sp;
4153 qc_host_busy_free_sp:
4154 qla4xxx_srb_free_dma(ha, srb);
4155 mempool_free(srb, ha->srb_mempool);
4158 return SCSI_MLQUEUE_HOST_BUSY;
4161 cmd->scsi_done(cmd);
4167 * qla4xxx_mem_free - frees memory allocated to adapter
4168 * @ha: Pointer to host adapter structure.
4170 * Frees memory previously allocated by qla4xxx_mem_alloc
4172 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
4175 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
4184 ha->request_ring = NULL;
4185 ha->request_dma = 0;
4186 ha->response_ring = NULL;
4187 ha->response_dma = 0;
4188 ha->shadow_regs = NULL;
4189 ha->shadow_regs_dma = 0;
4191 ha->fw_dump_size = 0;
4193 /* Free srb pool. */
4194 mempool_destroy(ha->srb_mempool);
4195 ha->srb_mempool = NULL;
4197 dma_pool_destroy(ha->chap_dma_pool);
4200 vfree(ha->chap_list);
4201 ha->chap_list = NULL;
4203 dma_pool_destroy(ha->fw_ddb_dma_pool);
4205 /* release io space registers */
4206 if (is_qla8022(ha)) {
4209 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
4210 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4213 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
4214 } else if (ha->reg) {
4218 if (ha->reset_tmplt.buff)
4219 vfree(ha->reset_tmplt.buff);
4221 pci_release_regions(ha->pdev);
4225 * qla4xxx_mem_alloc - allocates memory for use by adapter.
4226 * @ha: Pointer to host adapter structure
4228 * Allocates DMA memory for request and response queues. Also allocates memory
4231 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
4233 unsigned long align;
4235 /* Allocate contiguous block of DMA memory for queues. */
4236 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4237 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
4238 sizeof(struct shadow_regs) +
4240 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4241 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4242 &ha->queues_dma, GFP_KERNEL);
4243 if (ha->queues == NULL) {
4244 ql4_printk(KERN_WARNING, ha,
4245 "Memory Allocation failed - queues.\n");
4247 goto mem_alloc_error_exit;
4251 * As per RISC alignment requirements -- the bus-address must be a
4252 * multiple of the request-ring size (in bytes).
4255 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
4256 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
4257 (MEM_ALIGN_VALUE - 1));
4259 /* Update request and response queue pointers. */
4260 ha->request_dma = ha->queues_dma + align;
4261 ha->request_ring = (struct queue_entry *) (ha->queues + align);
4262 ha->response_dma = ha->queues_dma + align +
4263 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
4264 ha->response_ring = (struct queue_entry *) (ha->queues + align +
4265 (REQUEST_QUEUE_DEPTH *
4267 ha->shadow_regs_dma = ha->queues_dma + align +
4268 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
4269 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
4270 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
4271 (REQUEST_QUEUE_DEPTH *
4273 (RESPONSE_QUEUE_DEPTH *
4276 /* Allocate memory for srb pool. */
4277 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
4278 mempool_free_slab, srb_cachep);
4279 if (ha->srb_mempool == NULL) {
4280 ql4_printk(KERN_WARNING, ha,
4281 "Memory Allocation failed - SRB Pool.\n");
4283 goto mem_alloc_error_exit;
4286 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
4287 CHAP_DMA_BLOCK_SIZE, 8, 0);
4289 if (ha->chap_dma_pool == NULL) {
4290 ql4_printk(KERN_WARNING, ha,
4291 "%s: chap_dma_pool allocation failed..\n", __func__);
4292 goto mem_alloc_error_exit;
4295 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
4296 DDB_DMA_BLOCK_SIZE, 8, 0);
4298 if (ha->fw_ddb_dma_pool == NULL) {
4299 ql4_printk(KERN_WARNING, ha,
4300 "%s: fw_ddb_dma_pool allocation failed..\n",
4302 goto mem_alloc_error_exit;
4307 mem_alloc_error_exit:
4312 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
4313 * @ha: adapter block pointer.
4315 * Note: The caller should not hold the idc lock.
4317 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
4319 uint32_t temp, temp_state, temp_val;
4320 int status = QLA_SUCCESS;
4322 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
4324 temp_state = qla82xx_get_temp_state(temp);
4325 temp_val = qla82xx_get_temp_val(temp);
4327 if (temp_state == QLA82XX_TEMP_PANIC) {
4328 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
4329 " exceeds maximum allowed. Hardware has been shut"
4330 " down.\n", temp_val);
4332 } else if (temp_state == QLA82XX_TEMP_WARN) {
4333 if (ha->temperature == QLA82XX_TEMP_NORMAL)
4334 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
4335 " degrees C exceeds operating range."
4336 " Immediate action needed.\n", temp_val);
4338 if (ha->temperature == QLA82XX_TEMP_WARN)
4339 ql4_printk(KERN_INFO, ha, "Device temperature is"
4340 " now %d degrees C in normal range.\n",
4343 ha->temperature = temp_state;
4348 * qla4_8xxx_check_fw_alive - Check firmware health
4349 * @ha: Pointer to host adapter structure.
4351 * Context: Interrupt
4353 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
4355 uint32_t fw_heartbeat_counter;
4356 int status = QLA_SUCCESS;
4358 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
4359 QLA8XXX_PEG_ALIVE_COUNTER);
4360 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
4361 if (fw_heartbeat_counter == 0xffffffff) {
4362 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
4363 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
4364 ha->host_no, __func__));
4368 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
4369 ha->seconds_since_last_heartbeat++;
4370 /* FW not alive after 2 seconds */
4371 if (ha->seconds_since_last_heartbeat == 2) {
4372 ha->seconds_since_last_heartbeat = 0;
4373 qla4_8xxx_dump_peg_reg(ha);
4377 ha->seconds_since_last_heartbeat = 0;
4379 ha->fw_heartbeat_counter = fw_heartbeat_counter;
4383 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
4385 uint32_t halt_status;
4386 int halt_status_unrecoverable = 0;
4388 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
4390 if (is_qla8022(ha)) {
4391 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4393 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4394 CRB_NIU_XG_PAUSE_CTL_P0 |
4395 CRB_NIU_XG_PAUSE_CTL_P1);
4397 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
4398 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
4400 if (halt_status & HALT_STATUS_UNRECOVERABLE)
4401 halt_status_unrecoverable = 1;
4402 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4403 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
4404 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
4406 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
4407 halt_status_unrecoverable = 1;
4411 * Since we cannot change dev_state in interrupt context,
4412 * set appropriate DPC flag then wakeup DPC
4414 if (halt_status_unrecoverable) {
4415 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4417 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
4419 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4421 qla4xxx_mailbox_premature_completion(ha);
4422 qla4xxx_wake_dpc(ha);
4426 * qla4_8xxx_watchdog - Poll dev state
4427 * @ha: Pointer to host adapter structure.
4429 * Context: Interrupt
4431 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
4436 if (is_qla8032(ha) &&
4437 (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
4438 WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
4439 __func__, ha->func_num);
4441 /* don't poll if reset is going on */
4442 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
4443 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4444 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
4445 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
4447 if (qla4_8xxx_check_temp(ha)) {
4448 if (is_qla8022(ha)) {
4449 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
4450 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
4451 CRB_NIU_XG_PAUSE_CTL_P0 |
4452 CRB_NIU_XG_PAUSE_CTL_P1);
4454 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
4455 qla4xxx_wake_dpc(ha);
4456 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
4457 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
4459 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
4462 if (is_qla8032(ha) || is_qla8042(ha)) {
4463 idc_ctrl = qla4_83xx_rd_reg(ha,
4464 QLA83XX_IDC_DRV_CTRL);
4465 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
4466 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
4468 qla4xxx_mailbox_premature_completion(
4473 if ((is_qla8032(ha) || is_qla8042(ha)) ||
4474 (is_qla8022(ha) && !ql4xdontresethba)) {
4475 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4476 qla4xxx_wake_dpc(ha);
4478 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
4479 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
4480 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
4482 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
4483 qla4xxx_wake_dpc(ha);
4485 /* Check firmware health */
4486 if (qla4_8xxx_check_fw_alive(ha))
4487 qla4_8xxx_process_fw_error(ha);
4492 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
4494 struct iscsi_session *sess;
4495 struct ddb_entry *ddb_entry;
4496 struct scsi_qla_host *ha;
4498 sess = cls_sess->dd_data;
4499 ddb_entry = sess->dd_data;
4502 if (!(ddb_entry->ddb_type == FLASH_DDB))
4505 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
4506 !iscsi_is_session_online(cls_sess)) {
4507 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
4509 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
4511 atomic_set(&ddb_entry->retry_relogin_timer,
4513 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4514 set_bit(DF_RELOGIN, &ddb_entry->flags);
4515 DEBUG2(ql4_printk(KERN_INFO, ha,
4516 "%s: index [%d] login device\n",
4517 __func__, ddb_entry->fw_ddb_index));
4519 atomic_dec(&ddb_entry->retry_relogin_timer);
4523 /* Wait for relogin to timeout */
4524 if (atomic_read(&ddb_entry->relogin_timer) &&
4525 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
4527 * If the relogin times out and the device is
4528 * still NOT ONLINE then try and relogin again.
4530 if (!iscsi_is_session_online(cls_sess)) {
4531 /* Reset retry relogin timer */
4532 atomic_inc(&ddb_entry->relogin_retry_count);
4533 DEBUG2(ql4_printk(KERN_INFO, ha,
4534 "%s: index[%d] relogin timed out-retrying"
4535 " relogin (%d), retry (%d)\n", __func__,
4536 ddb_entry->fw_ddb_index,
4537 atomic_read(&ddb_entry->relogin_retry_count),
4538 ddb_entry->default_time2wait + 4));
4539 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4540 atomic_set(&ddb_entry->retry_relogin_timer,
4541 ddb_entry->default_time2wait + 4);
4547 * qla4xxx_timer - checks every second for work to do.
4548 * @t: Context to obtain pointer to host adapter structure.
4550 static void qla4xxx_timer(struct timer_list *t)
4552 struct scsi_qla_host *ha = from_timer(ha, t, timer);
4556 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
4558 /* If we are in the middle of AER/EEH processing
4559 * skip any processing and reschedule the timer
4561 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
4562 mod_timer(&ha->timer, jiffies + HZ);
4566 /* Hardware read to trigger an EEH error during mailbox waits. */
4567 if (!pci_channel_offline(ha->pdev))
4568 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
4571 qla4_8xxx_watchdog(ha);
4573 if (is_qla40XX(ha)) {
4574 /* Check for heartbeat interval. */
4575 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
4576 ha->heartbeat_interval != 0) {
4577 ha->seconds_since_last_heartbeat++;
4578 if (ha->seconds_since_last_heartbeat >
4579 ha->heartbeat_interval + 2)
4580 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4584 /* Process any deferred work. */
4585 if (!list_empty(&ha->work_list))
4588 /* Wakeup the dpc routine for this adapter, if needed. */
4590 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
4591 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
4592 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
4593 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
4594 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
4595 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
4596 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
4597 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
4598 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
4599 test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
4600 test_bit(DPC_AEN, &ha->dpc_flags)) {
4601 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
4602 " - dpc flags = 0x%lx\n",
4603 ha->host_no, __func__, ha->dpc_flags));
4604 qla4xxx_wake_dpc(ha);
4607 /* Reschedule timer thread to call us back in one second */
4608 mod_timer(&ha->timer, jiffies + HZ);
4610 DEBUG2(ha->seconds_since_last_intr++);
4614 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
4615 * @ha: Pointer to host adapter structure.
4617 * This routine stalls the driver until all outstanding commands are returned.
4618 * Caller must release the Hardware Lock prior to calling this routine.
4620 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
4623 unsigned long flags;
4624 struct scsi_cmnd *cmd;
4625 unsigned long wtime;
4629 wtmo = WAIT_CMD_TOV;
4631 wtmo = ha->nx_reset_timeout / 2;
4633 wtime = jiffies + (wtmo * HZ);
4635 DEBUG2(ql4_printk(KERN_INFO, ha,
4636 "Wait up to %u seconds for cmds to complete\n",
4639 while (!time_after_eq(jiffies, wtime)) {
4640 spin_lock_irqsave(&ha->hardware_lock, flags);
4641 /* Find a command that hasn't completed. */
4642 for (index = 0; index < ha->host->can_queue; index++) {
4643 cmd = scsi_host_find_tag(ha->host, index);
4645 * We cannot just check if the index is valid,
4646 * becase if we are run from the scsi eh, then
4647 * the scsi/block layer is going to prevent
4648 * the tag from being released.
4650 if (cmd != NULL && CMD_SP(cmd))
4653 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4655 /* If No Commands are pending, wait is complete */
4656 if (index == ha->host->can_queue)
4661 /* If we timed out on waiting for commands to come back
4666 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
4668 uint32_t ctrl_status;
4669 unsigned long flags = 0;
4671 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
4673 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
4676 spin_lock_irqsave(&ha->hardware_lock, flags);
4679 * If the SCSI Reset Interrupt bit is set, clear it.
4680 * Otherwise, the Soft Reset won't work.
4682 ctrl_status = readw(&ha->reg->ctrl_status);
4683 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
4684 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4686 /* Issue Soft Reset */
4687 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
4688 readl(&ha->reg->ctrl_status);
4690 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4695 * qla4xxx_soft_reset - performs soft reset.
4696 * @ha: Pointer to host adapter structure.
4698 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
4700 uint32_t max_wait_time;
4701 unsigned long flags = 0;
4703 uint32_t ctrl_status;
4705 status = qla4xxx_hw_reset(ha);
4706 if (status != QLA_SUCCESS)
4710 /* Wait until the Network Reset Intr bit is cleared */
4711 max_wait_time = RESET_INTR_TOV;
4713 spin_lock_irqsave(&ha->hardware_lock, flags);
4714 ctrl_status = readw(&ha->reg->ctrl_status);
4715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4717 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
4721 } while ((--max_wait_time));
4723 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
4724 DEBUG2(printk(KERN_WARNING
4725 "scsi%ld: Network Reset Intr not cleared by "
4726 "Network function, clearing it now!\n",
4728 spin_lock_irqsave(&ha->hardware_lock, flags);
4729 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
4730 readl(&ha->reg->ctrl_status);
4731 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4734 /* Wait until the firmware tells us the Soft Reset is done */
4735 max_wait_time = SOFT_RESET_TOV;
4737 spin_lock_irqsave(&ha->hardware_lock, flags);
4738 ctrl_status = readw(&ha->reg->ctrl_status);
4739 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4741 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
4742 status = QLA_SUCCESS;
4747 } while ((--max_wait_time));
4750 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
4751 * after the soft reset has taken place.
4753 spin_lock_irqsave(&ha->hardware_lock, flags);
4754 ctrl_status = readw(&ha->reg->ctrl_status);
4755 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
4756 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
4757 readl(&ha->reg->ctrl_status);
4759 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4761 /* If soft reset fails then most probably the bios on other
4762 * function is also enabled.
4763 * Since the initialization is sequential the other fn
4764 * wont be able to acknowledge the soft reset.
4765 * Issue a force soft reset to workaround this scenario.
4767 if (max_wait_time == 0) {
4768 /* Issue Force Soft Reset */
4769 spin_lock_irqsave(&ha->hardware_lock, flags);
4770 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
4771 readl(&ha->reg->ctrl_status);
4772 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4773 /* Wait until the firmware tells us the Soft Reset is done */
4774 max_wait_time = SOFT_RESET_TOV;
4776 spin_lock_irqsave(&ha->hardware_lock, flags);
4777 ctrl_status = readw(&ha->reg->ctrl_status);
4778 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4780 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
4781 status = QLA_SUCCESS;
4786 } while ((--max_wait_time));
4793 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
4794 * @ha: Pointer to host adapter structure.
4795 * @res: returned scsi status
4797 * This routine is called just prior to a HARD RESET to return all
4798 * outstanding commands back to the Operating System.
4799 * Caller should make sure that the following locks are released
4800 * before this calling routine: Hardware lock, and io_request_lock.
4802 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
4806 unsigned long flags;
4808 spin_lock_irqsave(&ha->hardware_lock, flags);
4809 for (i = 0; i < ha->host->can_queue; i++) {
4810 srb = qla4xxx_del_from_active_array(ha, i);
4812 srb->cmd->result = res;
4813 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4816 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4819 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
4821 clear_bit(AF_ONLINE, &ha->flags);
4823 /* Disable the board */
4824 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
4826 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
4827 qla4xxx_mark_all_devices_missing(ha);
4828 clear_bit(AF_INIT_DONE, &ha->flags);
4831 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
4833 struct iscsi_session *sess;
4834 struct ddb_entry *ddb_entry;
4836 sess = cls_session->dd_data;
4837 ddb_entry = sess->dd_data;
4838 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
4840 if (ddb_entry->ddb_type == FLASH_DDB)
4841 iscsi_block_session(ddb_entry->sess);
4843 iscsi_session_failure(cls_session->dd_data,
4844 ISCSI_ERR_CONN_FAILED);
4848 * qla4xxx_recover_adapter - recovers adapter after a fatal error
4849 * @ha: Pointer to host adapter structure.
4851 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
4853 int status = QLA_ERROR;
4854 uint8_t reset_chip = 0;
4858 /* Stall incoming I/O until we are done */
4859 scsi_block_requests(ha->host);
4860 clear_bit(AF_ONLINE, &ha->flags);
4861 clear_bit(AF_LINK_UP, &ha->flags);
4863 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
4865 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
4867 if ((is_qla8032(ha) || is_qla8042(ha)) &&
4868 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4869 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
4871 /* disable pause frame for ISP83xx */
4872 qla4_83xx_disable_pause(ha);
4875 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
4877 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
4880 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
4881 * do not reset adapter, jump to initialize_adapter */
4882 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4883 status = QLA_SUCCESS;
4884 goto recover_ha_init_adapter;
4887 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
4888 * from eh_host_reset or ioctl module */
4889 if (is_qla80XX(ha) && !reset_chip &&
4890 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
4892 DEBUG2(ql4_printk(KERN_INFO, ha,
4893 "scsi%ld: %s - Performing stop_firmware...\n",
4894 ha->host_no, __func__));
4895 status = ha->isp_ops->reset_firmware(ha);
4896 if (status == QLA_SUCCESS) {
4897 ha->isp_ops->disable_intrs(ha);
4898 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4899 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4901 /* If the stop_firmware fails then
4902 * reset the entire chip */
4904 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
4905 set_bit(DPC_RESET_HA, &ha->dpc_flags);
4909 /* Issue full chip reset if recovering from a catastrophic error,
4910 * or if stop_firmware fails for ISP-8xxx.
4911 * This is the default case for ISP-4xxx */
4912 if (is_qla40XX(ha) || reset_chip) {
4916 /* Check if 8XXX firmware is alive or not
4917 * We may have arrived here from NEED_RESET
4919 if (test_bit(AF_FW_RECOVERY, &ha->flags))
4922 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
4923 while (time_before(jiffies, wait)) {
4924 if (qla4_8xxx_check_fw_alive(ha)) {
4925 qla4xxx_mailbox_premature_completion(ha);
4929 set_current_state(TASK_UNINTERRUPTIBLE);
4930 schedule_timeout(HZ);
4933 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
4934 qla4xxx_cmd_wait(ha);
4936 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4937 DEBUG2(ql4_printk(KERN_INFO, ha,
4938 "scsi%ld: %s - Performing chip reset..\n",
4939 ha->host_no, __func__));
4940 status = ha->isp_ops->reset_chip(ha);
4941 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
4944 /* Flush any pending ddb changed AENs */
4945 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
4947 recover_ha_init_adapter:
4948 /* Upon successful firmware/chip reset, re-initialize the adapter */
4949 if (status == QLA_SUCCESS) {
4950 /* For ISP-4xxx, force function 1 to always initialize
4951 * before function 3 to prevent both funcions from
4952 * stepping on top of the other */
4953 if (is_qla40XX(ha) && (ha->mac_index == 3))
4956 /* NOTE: AF_ONLINE flag set upon successful completion of
4957 * qla4xxx_initialize_adapter */
4958 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
4959 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
4960 status = qla4_8xxx_check_init_adapter_retry(ha);
4961 if (status == QLA_ERROR) {
4962 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
4963 ha->host_no, __func__);
4964 qla4xxx_dead_adapter_cleanup(ha);
4965 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
4966 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
4967 clear_bit(DPC_RESET_HA_FW_CONTEXT,
4974 /* Retry failed adapter initialization, if necessary
4975 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
4976 * case to prevent ping-pong resets between functions */
4977 if (!test_bit(AF_ONLINE, &ha->flags) &&
4978 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
4979 /* Adapter initialization failed, see if we can retry
4981 * Since we don't want to block the DPC for too long
4982 * with multiple resets in the same thread,
4983 * utilize DPC to retry */
4984 if (is_qla80XX(ha)) {
4985 ha->isp_ops->idc_lock(ha);
4986 dev_state = qla4_8xxx_rd_direct(ha,
4987 QLA8XXX_CRB_DEV_STATE);
4988 ha->isp_ops->idc_unlock(ha);
4989 if (dev_state == QLA8XXX_DEV_FAILED) {
4990 ql4_printk(KERN_INFO, ha, "%s: don't retry "
4991 "recover adapter. H/W is in Failed "
4992 "state\n", __func__);
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,
5004 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
5005 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
5006 DEBUG2(printk("scsi%ld: recover adapter - retrying "
5007 "(%d) more times\n", ha->host_no,
5008 ha->retry_reset_ha_cnt));
5009 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5012 if (ha->retry_reset_ha_cnt > 0) {
5013 /* Schedule another Reset HA--DPC will retry */
5014 ha->retry_reset_ha_cnt--;
5015 DEBUG2(printk("scsi%ld: recover adapter - "
5016 "retry remaining %d\n",
5018 ha->retry_reset_ha_cnt));
5022 if (ha->retry_reset_ha_cnt == 0) {
5023 /* Recover adapter retries have been exhausted.
5025 DEBUG2(printk("scsi%ld: recover adapter "
5026 "failed - board disabled\n",
5028 qla4xxx_dead_adapter_cleanup(ha);
5029 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5030 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5031 clear_bit(DPC_RESET_HA_FW_CONTEXT,
5037 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5038 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5039 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
5043 ha->adapter_error_count++;
5045 if (test_bit(AF_ONLINE, &ha->flags))
5046 ha->isp_ops->enable_intrs(ha);
5048 scsi_unblock_requests(ha->host);
5050 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5051 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
5052 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
5057 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
5059 struct iscsi_session *sess;
5060 struct ddb_entry *ddb_entry;
5061 struct scsi_qla_host *ha;
5063 sess = cls_session->dd_data;
5064 ddb_entry = sess->dd_data;
5066 if (!iscsi_is_session_online(cls_session)) {
5067 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
5068 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5069 " unblock session\n", ha->host_no, __func__,
5070 ddb_entry->fw_ddb_index);
5071 iscsi_unblock_session(ddb_entry->sess);
5073 /* Trigger relogin */
5074 if (ddb_entry->ddb_type == FLASH_DDB) {
5075 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
5076 test_bit(DF_DISABLE_RELOGIN,
5077 &ddb_entry->flags)))
5078 qla4xxx_arm_relogin_timer(ddb_entry);
5080 iscsi_session_failure(cls_session->dd_data,
5081 ISCSI_ERR_CONN_FAILED);
5086 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
5088 struct iscsi_session *sess;
5089 struct ddb_entry *ddb_entry;
5090 struct scsi_qla_host *ha;
5092 sess = cls_session->dd_data;
5093 ddb_entry = sess->dd_data;
5095 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5096 " unblock session\n", ha->host_no, __func__,
5097 ddb_entry->fw_ddb_index);
5099 iscsi_unblock_session(ddb_entry->sess);
5101 /* Start scan target */
5102 if (test_bit(AF_ONLINE, &ha->flags)) {
5103 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5104 " start scan\n", ha->host_no, __func__,
5105 ddb_entry->fw_ddb_index);
5106 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
5111 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
5113 struct iscsi_session *sess;
5114 struct ddb_entry *ddb_entry;
5115 struct scsi_qla_host *ha;
5116 int status = QLA_SUCCESS;
5118 sess = cls_session->dd_data;
5119 ddb_entry = sess->dd_data;
5121 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
5122 " unblock user space session\n", ha->host_no, __func__,
5123 ddb_entry->fw_ddb_index);
5125 if (!iscsi_is_session_online(cls_session)) {
5126 iscsi_conn_start(ddb_entry->conn);
5127 iscsi_conn_login_event(ddb_entry->conn,
5128 ISCSI_CONN_STATE_LOGGED_IN);
5130 ql4_printk(KERN_INFO, ha,
5131 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
5132 ha->host_no, __func__, ddb_entry->fw_ddb_index,
5140 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
5142 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
5145 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
5147 uint16_t relogin_timer;
5148 struct iscsi_session *sess;
5149 struct ddb_entry *ddb_entry;
5150 struct scsi_qla_host *ha;
5152 sess = cls_sess->dd_data;
5153 ddb_entry = sess->dd_data;
5156 relogin_timer = max(ddb_entry->default_relogin_timeout,
5157 (uint16_t)RELOGIN_TOV);
5158 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
5160 DEBUG2(ql4_printk(KERN_INFO, ha,
5161 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
5162 ddb_entry->fw_ddb_index, relogin_timer));
5164 qla4xxx_login_flash_ddb(cls_sess);
5167 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
5169 struct iscsi_session *sess;
5170 struct ddb_entry *ddb_entry;
5171 struct scsi_qla_host *ha;
5173 sess = cls_sess->dd_data;
5174 ddb_entry = sess->dd_data;
5177 if (!(ddb_entry->ddb_type == FLASH_DDB))
5180 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
5183 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
5184 !iscsi_is_session_online(cls_sess)) {
5185 DEBUG2(ql4_printk(KERN_INFO, ha,
5186 "relogin issued\n"));
5187 qla4xxx_relogin_flash_ddb(cls_sess);
5191 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
5194 queue_work(ha->dpc_thread, &ha->dpc_work);
5197 static struct qla4_work_evt *
5198 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
5199 enum qla4_work_type type)
5201 struct qla4_work_evt *e;
5202 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
5204 e = kzalloc(size, GFP_ATOMIC);
5208 INIT_LIST_HEAD(&e->list);
5213 static void qla4xxx_post_work(struct scsi_qla_host *ha,
5214 struct qla4_work_evt *e)
5216 unsigned long flags;
5218 spin_lock_irqsave(&ha->work_lock, flags);
5219 list_add_tail(&e->list, &ha->work_list);
5220 spin_unlock_irqrestore(&ha->work_lock, flags);
5221 qla4xxx_wake_dpc(ha);
5224 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
5225 enum iscsi_host_event_code aen_code,
5226 uint32_t data_size, uint8_t *data)
5228 struct qla4_work_evt *e;
5230 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
5234 e->u.aen.code = aen_code;
5235 e->u.aen.data_size = data_size;
5236 memcpy(e->u.aen.data, data, data_size);
5238 qla4xxx_post_work(ha, e);
5243 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
5244 uint32_t status, uint32_t pid,
5245 uint32_t data_size, uint8_t *data)
5247 struct qla4_work_evt *e;
5249 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
5253 e->u.ping.status = status;
5254 e->u.ping.pid = pid;
5255 e->u.ping.data_size = data_size;
5256 memcpy(e->u.ping.data, data, data_size);
5258 qla4xxx_post_work(ha, e);
5263 static void qla4xxx_do_work(struct scsi_qla_host *ha)
5265 struct qla4_work_evt *e, *tmp;
5266 unsigned long flags;
5269 spin_lock_irqsave(&ha->work_lock, flags);
5270 list_splice_init(&ha->work_list, &work);
5271 spin_unlock_irqrestore(&ha->work_lock, flags);
5273 list_for_each_entry_safe(e, tmp, &work, list) {
5274 list_del_init(&e->list);
5277 case QLA4_EVENT_AEN:
5278 iscsi_post_host_event(ha->host_no,
5279 &qla4xxx_iscsi_transport,
5284 case QLA4_EVENT_PING_STATUS:
5285 iscsi_ping_comp_event(ha->host_no,
5286 &qla4xxx_iscsi_transport,
5289 e->u.ping.data_size,
5293 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
5294 "supported", e->type);
5301 * qla4xxx_do_dpc - dpc routine
5302 * @work: Context to obtain pointer to host adapter structure.
5304 * This routine is a task that is schedule by the interrupt handler
5305 * to perform the background processing for interrupts. We put it
5306 * on a task queue that is consumed whenever the scheduler runs; that's
5307 * so you can do anything (i.e. put the process to sleep etc). In fact,
5308 * the mid-level tries to sleep when it reaches the driver threshold
5309 * "host->can_queue". This can cause a panic if we were in our interrupt code.
5311 static void qla4xxx_do_dpc(struct work_struct *work)
5313 struct scsi_qla_host *ha =
5314 container_of(work, struct scsi_qla_host, dpc_work);
5315 int status = QLA_ERROR;
5317 DEBUG2(ql4_printk(KERN_INFO, ha,
5318 "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
5319 ha->host_no, __func__, ha->flags, ha->dpc_flags));
5321 /* Initialization not yet finished. Don't do anything yet. */
5322 if (!test_bit(AF_INIT_DONE, &ha->flags))
5325 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
5326 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
5327 ha->host_no, __func__, ha->flags));
5331 /* post events to application */
5332 qla4xxx_do_work(ha);
5334 if (is_qla80XX(ha)) {
5335 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
5336 if (is_qla8032(ha) || is_qla8042(ha)) {
5337 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
5339 /* disable pause frame for ISP83xx */
5340 qla4_83xx_disable_pause(ha);
5343 ha->isp_ops->idc_lock(ha);
5344 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
5345 QLA8XXX_DEV_FAILED);
5346 ha->isp_ops->idc_unlock(ha);
5347 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
5348 qla4_8xxx_device_state_handler(ha);
5351 if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
5352 if (is_qla8042(ha)) {
5353 if (ha->idc_info.info2 &
5354 ENABLE_INTERNAL_LOOPBACK) {
5355 ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
5357 status = qla4_84xx_config_acb(ha,
5358 ACB_CONFIG_DISABLE);
5359 if (status != QLA_SUCCESS) {
5360 ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
5365 qla4_83xx_post_idc_ack(ha);
5366 clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
5369 if (is_qla8042(ha) &&
5370 test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
5371 ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
5373 if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
5375 ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
5378 clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
5381 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
5382 qla4_8xxx_need_qsnt_handler(ha);
5386 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
5387 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
5388 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
5389 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
5390 if ((is_qla8022(ha) && ql4xdontresethba) ||
5391 ((is_qla8032(ha) || is_qla8042(ha)) &&
5392 qla4_83xx_idc_dontreset(ha))) {
5393 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5394 ha->host_no, __func__));
5395 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
5396 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5397 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5398 goto dpc_post_reset_ha;
5400 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
5401 test_bit(DPC_RESET_HA, &ha->dpc_flags))
5402 qla4xxx_recover_adapter(ha);
5404 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
5405 uint8_t wait_time = RESET_INTR_TOV;
5407 while ((readw(&ha->reg->ctrl_status) &
5408 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
5409 if (--wait_time == 0)
5414 DEBUG2(printk("scsi%ld: %s: SR|FSR "
5415 "bit not cleared-- resetting\n",
5416 ha->host_no, __func__));
5417 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
5418 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
5419 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
5420 status = qla4xxx_recover_adapter(ha);
5422 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
5423 if (status == QLA_SUCCESS)
5424 ha->isp_ops->enable_intrs(ha);
5429 /* ---- process AEN? --- */
5430 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
5431 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
5433 /* ---- Get DHCP IP Address? --- */
5434 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
5435 qla4xxx_get_dhcp_ip_address(ha);
5437 /* ---- relogin device? --- */
5438 if (adapter_up(ha) &&
5439 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
5440 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
5443 /* ---- link change? --- */
5444 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
5445 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
5446 if (!test_bit(AF_LINK_UP, &ha->flags)) {
5447 /* ---- link down? --- */
5448 qla4xxx_mark_all_devices_missing(ha);
5450 /* ---- link up? --- *
5451 * F/W will auto login to all devices ONLY ONCE after
5452 * link up during driver initialization and runtime
5453 * fatal error recovery. Therefore, the driver must
5454 * manually relogin to devices when recovering from
5455 * connection failures, logouts, expired KATO, etc. */
5456 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
5457 qla4xxx_build_ddb_list(ha, ha->is_reset);
5458 iscsi_host_for_each_session(ha->host,
5459 qla4xxx_login_flash_ddb);
5461 qla4xxx_relogin_all_devices(ha);
5464 if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
5465 if (qla4xxx_sysfs_ddb_export(ha))
5466 ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
5472 * qla4xxx_free_adapter - release the adapter
5473 * @ha: pointer to adapter structure
5475 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
5477 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5479 /* Turn-off interrupts on the card. */
5480 ha->isp_ops->disable_intrs(ha);
5482 if (is_qla40XX(ha)) {
5483 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
5484 &ha->reg->ctrl_status);
5485 readl(&ha->reg->ctrl_status);
5486 } else if (is_qla8022(ha)) {
5487 writel(0, &ha->qla4_82xx_reg->host_int);
5488 readl(&ha->qla4_82xx_reg->host_int);
5489 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5490 writel(0, &ha->qla4_83xx_reg->risc_intr);
5491 readl(&ha->qla4_83xx_reg->risc_intr);
5494 /* Remove timer thread, if present */
5495 if (ha->timer_active)
5496 qla4xxx_stop_timer(ha);
5498 /* Kill the kernel thread for this host */
5500 destroy_workqueue(ha->dpc_thread);
5502 /* Kill the kernel thread for this host */
5504 destroy_workqueue(ha->task_wq);
5506 /* Put firmware in known state */
5507 ha->isp_ops->reset_firmware(ha);
5509 if (is_qla80XX(ha)) {
5510 ha->isp_ops->idc_lock(ha);
5511 qla4_8xxx_clear_drv_active(ha);
5512 ha->isp_ops->idc_unlock(ha);
5515 /* Detach interrupts */
5516 qla4xxx_free_irqs(ha);
5518 /* free extra memory */
5519 qla4xxx_mem_free(ha);
5522 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
5525 unsigned long mem_base, mem_len;
5526 struct pci_dev *pdev = ha->pdev;
5528 status = pci_request_regions(pdev, DRIVER_NAME);
5531 "scsi(%ld) Failed to reserve PIO regions (%s) "
5532 "status=%d\n", ha->host_no, pci_name(pdev), status);
5533 goto iospace_error_exit;
5536 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
5537 __func__, pdev->revision));
5538 ha->revision_id = pdev->revision;
5540 /* remap phys address */
5541 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
5542 mem_len = pci_resource_len(pdev, 0);
5543 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
5544 __func__, mem_base, mem_len));
5546 /* mapping of pcibase pointer */
5547 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
5548 if (!ha->nx_pcibase) {
5550 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
5551 pci_release_regions(ha->pdev);
5552 goto iospace_error_exit;
5555 /* Mapping of IO base pointer, door bell read and write pointer */
5557 /* mapping of IO base pointer */
5558 if (is_qla8022(ha)) {
5559 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
5560 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
5561 (ha->pdev->devfn << 11));
5562 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
5563 QLA82XX_CAM_RAM_DB2);
5564 } else if (is_qla8032(ha) || is_qla8042(ha)) {
5565 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
5566 ((uint8_t *)ha->nx_pcibase);
5575 * qla4xxx_iospace_config - maps registers
5576 * @ha: pointer to adapter structure
5578 * This routines maps HBA's registers from the pci address space
5579 * into the kernel virtual address space for memory mapped i/o.
5581 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
5583 unsigned long pio, pio_len, pio_flags;
5584 unsigned long mmio, mmio_len, mmio_flags;
5586 pio = pci_resource_start(ha->pdev, 0);
5587 pio_len = pci_resource_len(ha->pdev, 0);
5588 pio_flags = pci_resource_flags(ha->pdev, 0);
5589 if (pio_flags & IORESOURCE_IO) {
5590 if (pio_len < MIN_IOBASE_LEN) {
5591 ql4_printk(KERN_WARNING, ha,
5592 "Invalid PCI I/O region size\n");
5596 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
5600 /* Use MMIO operations for all accesses. */
5601 mmio = pci_resource_start(ha->pdev, 1);
5602 mmio_len = pci_resource_len(ha->pdev, 1);
5603 mmio_flags = pci_resource_flags(ha->pdev, 1);
5605 if (!(mmio_flags & IORESOURCE_MEM)) {
5606 ql4_printk(KERN_ERR, ha,
5607 "region #0 not an MMIO resource, aborting\n");
5609 goto iospace_error_exit;
5612 if (mmio_len < MIN_IOBASE_LEN) {
5613 ql4_printk(KERN_ERR, ha,
5614 "Invalid PCI mem region size, aborting\n");
5615 goto iospace_error_exit;
5618 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
5619 ql4_printk(KERN_WARNING, ha,
5620 "Failed to reserve PIO/MMIO regions\n");
5622 goto iospace_error_exit;
5625 ha->pio_address = pio;
5626 ha->pio_length = pio_len;
5627 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
5629 ql4_printk(KERN_ERR, ha,
5630 "cannot remap MMIO, aborting\n");
5632 goto iospace_error_exit;
5641 static struct isp_operations qla4xxx_isp_ops = {
5642 .iospace_config = qla4xxx_iospace_config,
5643 .pci_config = qla4xxx_pci_config,
5644 .disable_intrs = qla4xxx_disable_intrs,
5645 .enable_intrs = qla4xxx_enable_intrs,
5646 .start_firmware = qla4xxx_start_firmware,
5647 .intr_handler = qla4xxx_intr_handler,
5648 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
5649 .reset_chip = qla4xxx_soft_reset,
5650 .reset_firmware = qla4xxx_hw_reset,
5651 .queue_iocb = qla4xxx_queue_iocb,
5652 .complete_iocb = qla4xxx_complete_iocb,
5653 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5654 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5655 .get_sys_info = qla4xxx_get_sys_info,
5656 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
5657 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
5660 static struct isp_operations qla4_82xx_isp_ops = {
5661 .iospace_config = qla4_8xxx_iospace_config,
5662 .pci_config = qla4_8xxx_pci_config,
5663 .disable_intrs = qla4_82xx_disable_intrs,
5664 .enable_intrs = qla4_82xx_enable_intrs,
5665 .start_firmware = qla4_8xxx_load_risc,
5666 .restart_firmware = qla4_82xx_try_start_fw,
5667 .intr_handler = qla4_82xx_intr_handler,
5668 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
5669 .need_reset = qla4_8xxx_need_reset,
5670 .reset_chip = qla4_82xx_isp_reset,
5671 .reset_firmware = qla4_8xxx_stop_firmware,
5672 .queue_iocb = qla4_82xx_queue_iocb,
5673 .complete_iocb = qla4_82xx_complete_iocb,
5674 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
5675 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
5676 .get_sys_info = qla4_8xxx_get_sys_info,
5677 .rd_reg_direct = qla4_82xx_rd_32,
5678 .wr_reg_direct = qla4_82xx_wr_32,
5679 .rd_reg_indirect = qla4_82xx_md_rd_32,
5680 .wr_reg_indirect = qla4_82xx_md_wr_32,
5681 .idc_lock = qla4_82xx_idc_lock,
5682 .idc_unlock = qla4_82xx_idc_unlock,
5683 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
5684 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
5685 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
5688 static struct isp_operations qla4_83xx_isp_ops = {
5689 .iospace_config = qla4_8xxx_iospace_config,
5690 .pci_config = qla4_8xxx_pci_config,
5691 .disable_intrs = qla4_83xx_disable_intrs,
5692 .enable_intrs = qla4_83xx_enable_intrs,
5693 .start_firmware = qla4_8xxx_load_risc,
5694 .restart_firmware = qla4_83xx_start_firmware,
5695 .intr_handler = qla4_83xx_intr_handler,
5696 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
5697 .need_reset = qla4_8xxx_need_reset,
5698 .reset_chip = qla4_83xx_isp_reset,
5699 .reset_firmware = qla4_8xxx_stop_firmware,
5700 .queue_iocb = qla4_83xx_queue_iocb,
5701 .complete_iocb = qla4_83xx_complete_iocb,
5702 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
5703 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
5704 .get_sys_info = qla4_8xxx_get_sys_info,
5705 .rd_reg_direct = qla4_83xx_rd_reg,
5706 .wr_reg_direct = qla4_83xx_wr_reg,
5707 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
5708 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
5709 .idc_lock = qla4_83xx_drv_lock,
5710 .idc_unlock = qla4_83xx_drv_unlock,
5711 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
5712 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
5713 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
5716 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5718 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
5721 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
5723 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
5726 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5728 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
5731 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
5733 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
5736 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
5738 struct scsi_qla_host *ha = data;
5743 case ISCSI_BOOT_ETH_FLAGS:
5744 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5746 case ISCSI_BOOT_ETH_INDEX:
5747 rc = sprintf(str, "0\n");
5749 case ISCSI_BOOT_ETH_MAC:
5750 rc = sysfs_format_mac(str, ha->my_mac,
5760 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
5765 case ISCSI_BOOT_ETH_FLAGS:
5766 case ISCSI_BOOT_ETH_MAC:
5767 case ISCSI_BOOT_ETH_INDEX:
5777 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
5779 struct scsi_qla_host *ha = data;
5784 case ISCSI_BOOT_INI_INITIATOR_NAME:
5785 rc = sprintf(str, "%s\n", ha->name_string);
5794 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
5799 case ISCSI_BOOT_INI_INITIATOR_NAME:
5810 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
5813 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
5818 case ISCSI_BOOT_TGT_NAME:
5819 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
5821 case ISCSI_BOOT_TGT_IP_ADDR:
5822 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
5823 rc = sprintf(buf, "%pI4\n",
5824 &boot_conn->dest_ipaddr.ip_address);
5826 rc = sprintf(str, "%pI6\n",
5827 &boot_conn->dest_ipaddr.ip_address);
5829 case ISCSI_BOOT_TGT_PORT:
5830 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5832 case ISCSI_BOOT_TGT_CHAP_NAME:
5833 rc = sprintf(str, "%.*s\n",
5834 boot_conn->chap.target_chap_name_length,
5835 (char *)&boot_conn->chap.target_chap_name);
5837 case ISCSI_BOOT_TGT_CHAP_SECRET:
5838 rc = sprintf(str, "%.*s\n",
5839 boot_conn->chap.target_secret_length,
5840 (char *)&boot_conn->chap.target_secret);
5842 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5843 rc = sprintf(str, "%.*s\n",
5844 boot_conn->chap.intr_chap_name_length,
5845 (char *)&boot_conn->chap.intr_chap_name);
5847 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5848 rc = sprintf(str, "%.*s\n",
5849 boot_conn->chap.intr_secret_length,
5850 (char *)&boot_conn->chap.intr_secret);
5852 case ISCSI_BOOT_TGT_FLAGS:
5853 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
5855 case ISCSI_BOOT_TGT_NIC_ASSOC:
5856 rc = sprintf(str, "0\n");
5865 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
5867 struct scsi_qla_host *ha = data;
5868 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
5870 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5873 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
5875 struct scsi_qla_host *ha = data;
5876 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
5878 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
5881 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
5886 case ISCSI_BOOT_TGT_NAME:
5887 case ISCSI_BOOT_TGT_IP_ADDR:
5888 case ISCSI_BOOT_TGT_PORT:
5889 case ISCSI_BOOT_TGT_CHAP_NAME:
5890 case ISCSI_BOOT_TGT_CHAP_SECRET:
5891 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5892 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5893 case ISCSI_BOOT_TGT_NIC_ASSOC:
5894 case ISCSI_BOOT_TGT_FLAGS:
5904 static void qla4xxx_boot_release(void *data)
5906 struct scsi_qla_host *ha = data;
5908 scsi_host_put(ha->host);
5911 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
5914 uint32_t addr, pri_addr, sec_addr;
5918 uint8_t *buf = NULL;
5919 size_t size = 13 * sizeof(uint8_t);
5920 int ret = QLA_SUCCESS;
5922 func_num = PCI_FUNC(ha->pdev->devfn);
5924 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
5925 __func__, ha->pdev->device, func_num);
5927 if (is_qla40XX(ha)) {
5928 if (func_num == 1) {
5929 addr = NVRAM_PORT0_BOOT_MODE;
5930 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
5931 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
5932 } else if (func_num == 3) {
5933 addr = NVRAM_PORT1_BOOT_MODE;
5934 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
5935 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
5938 goto exit_boot_info;
5941 /* Check Boot Mode */
5942 val = rd_nvram_byte(ha, addr);
5943 if (!(val & 0x07)) {
5944 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
5945 "options : 0x%x\n", __func__, val));
5947 goto exit_boot_info;
5950 /* get primary valid target index */
5951 val = rd_nvram_byte(ha, pri_addr);
5953 ddb_index[0] = (val & 0x7f);
5955 /* get secondary valid target index */
5956 val = rd_nvram_byte(ha, sec_addr);
5958 ddb_index[1] = (val & 0x7f);
5959 goto exit_boot_info;
5960 } else if (is_qla80XX(ha)) {
5961 buf = dma_alloc_coherent(&ha->pdev->dev, size,
5962 &buf_dma, GFP_KERNEL);
5964 DEBUG2(ql4_printk(KERN_ERR, ha,
5965 "%s: Unable to allocate dma buffer\n",
5968 goto exit_boot_info;
5971 if (ha->port_num == 0)
5972 offset = BOOT_PARAM_OFFSET_PORT0;
5973 else if (ha->port_num == 1)
5974 offset = BOOT_PARAM_OFFSET_PORT1;
5977 goto exit_boot_info_free;
5979 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
5981 if (qla4xxx_get_flash(ha, buf_dma, addr,
5982 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
5983 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
5984 " failed\n", ha->host_no, __func__));
5986 goto exit_boot_info_free;
5988 /* Check Boot Mode */
5989 if (!(buf[1] & 0x07)) {
5990 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
5991 " : 0x%x\n", buf[1]));
5993 goto exit_boot_info_free;
5996 /* get primary valid target index */
5998 ddb_index[0] = buf[2] & 0x7f;
6000 /* get secondary valid target index */
6001 if (buf[11] & BIT_7)
6002 ddb_index[1] = buf[11] & 0x7f;
6005 goto exit_boot_info;
6008 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
6009 " target ID %d\n", __func__, ddb_index[0],
6012 exit_boot_info_free:
6013 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
6015 ha->pri_ddb_idx = ddb_index[0];
6016 ha->sec_ddb_idx = ddb_index[1];
6021 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
6022 * @ha: pointer to adapter structure
6023 * @username: CHAP username to be returned
6024 * @password: CHAP password to be returned
6026 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
6027 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
6028 * So from the CHAP cache find the first BIDI CHAP entry and set it
6029 * to the boot record in sysfs.
6031 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
6034 int i, ret = -EINVAL;
6035 int max_chap_entries = 0;
6036 struct ql4_chap_table *chap_table;
6039 max_chap_entries = (ha->hw.flt_chap_size / 2) /
6040 sizeof(struct ql4_chap_table);
6042 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
6044 if (!ha->chap_list) {
6045 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
6049 mutex_lock(&ha->chap_sem);
6050 for (i = 0; i < max_chap_entries; i++) {
6051 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
6052 if (chap_table->cookie !=
6053 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
6057 if (chap_table->flags & BIT_7) /* local */
6060 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
6063 strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
6064 strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
6068 mutex_unlock(&ha->chap_sem);
6074 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
6075 struct ql4_boot_session_info *boot_sess,
6078 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
6079 struct dev_db_entry *fw_ddb_entry;
6080 dma_addr_t fw_ddb_entry_dma;
6083 int ret = QLA_SUCCESS;
6085 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6086 &fw_ddb_entry_dma, GFP_KERNEL);
6087 if (!fw_ddb_entry) {
6088 DEBUG2(ql4_printk(KERN_ERR, ha,
6089 "%s: Unable to allocate dma buffer.\n",
6095 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
6096 fw_ddb_entry_dma, ddb_index)) {
6097 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
6098 "index [%d]\n", __func__, ddb_index));
6100 goto exit_boot_target;
6103 /* Update target name and IP from DDB */
6104 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
6105 min(sizeof(boot_sess->target_name),
6106 sizeof(fw_ddb_entry->iscsi_name)));
6108 options = le16_to_cpu(fw_ddb_entry->options);
6109 if (options & DDB_OPT_IPV6_DEVICE) {
6110 memcpy(&boot_conn->dest_ipaddr.ip_address,
6111 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
6113 boot_conn->dest_ipaddr.ip_type = 0x1;
6114 memcpy(&boot_conn->dest_ipaddr.ip_address,
6115 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
6118 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
6120 /* update chap information */
6121 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
6123 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6125 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
6127 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
6129 (char *)&boot_conn->chap.target_secret,
6132 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
6134 goto exit_boot_target;
6137 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6138 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6141 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
6143 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
6145 ret = qla4xxx_get_bidi_chap(ha,
6146 (char *)&boot_conn->chap.intr_chap_name,
6147 (char *)&boot_conn->chap.intr_secret);
6150 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
6152 goto exit_boot_target;
6155 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
6156 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
6160 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6161 fw_ddb_entry, fw_ddb_entry_dma);
6165 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
6167 uint16_t ddb_index[2];
6168 int ret = QLA_ERROR;
6171 memset(ddb_index, 0, sizeof(ddb_index));
6172 ddb_index[0] = 0xffff;
6173 ddb_index[1] = 0xffff;
6174 ret = get_fw_boot_info(ha, ddb_index);
6175 if (ret != QLA_SUCCESS) {
6176 DEBUG2(ql4_printk(KERN_INFO, ha,
6177 "%s: No boot target configured.\n", __func__));
6181 if (ql4xdisablesysfsboot)
6184 if (ddb_index[0] == 0xffff)
6187 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
6189 if (rval != QLA_SUCCESS) {
6190 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
6191 "configured\n", __func__));
6196 if (ddb_index[1] == 0xffff)
6197 goto exit_get_boot_info;
6199 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
6201 if (rval != QLA_SUCCESS) {
6202 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
6203 " configured\n", __func__));
6211 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
6213 struct iscsi_boot_kobj *boot_kobj;
6215 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
6218 if (ql4xdisablesysfsboot) {
6219 ql4_printk(KERN_INFO, ha,
6220 "%s: syfsboot disabled - driver will trigger login "
6221 "and publish session for discovery .\n", __func__);
6226 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
6230 if (!scsi_host_get(ha->host))
6232 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
6233 qla4xxx_show_boot_tgt_pri_info,
6234 qla4xxx_tgt_get_attr_visibility,
6235 qla4xxx_boot_release);
6239 if (!scsi_host_get(ha->host))
6241 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
6242 qla4xxx_show_boot_tgt_sec_info,
6243 qla4xxx_tgt_get_attr_visibility,
6244 qla4xxx_boot_release);
6248 if (!scsi_host_get(ha->host))
6250 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
6251 qla4xxx_show_boot_ini_info,
6252 qla4xxx_ini_get_attr_visibility,
6253 qla4xxx_boot_release);
6257 if (!scsi_host_get(ha->host))
6259 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
6260 qla4xxx_show_boot_eth_info,
6261 qla4xxx_eth_get_attr_visibility,
6262 qla4xxx_boot_release);
6269 scsi_host_put(ha->host);
6271 iscsi_boot_destroy_kset(ha->boot_kset);
6276 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
6277 struct ql4_tuple_ddb *tddb)
6279 struct iscsi_cls_session *cls_sess;
6280 struct iscsi_cls_conn *cls_conn;
6281 struct iscsi_session *sess;
6282 struct iscsi_conn *conn;
6284 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6285 cls_sess = ddb_entry->sess;
6286 sess = cls_sess->dd_data;
6287 cls_conn = ddb_entry->conn;
6288 conn = cls_conn->dd_data;
6290 tddb->tpgt = sess->tpgt;
6291 tddb->port = conn->persistent_port;
6292 strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
6293 strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
6296 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
6297 struct ql4_tuple_ddb *tddb,
6298 uint8_t *flash_isid)
6300 uint16_t options = 0;
6302 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
6303 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
6304 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
6306 options = le16_to_cpu(fw_ddb_entry->options);
6307 if (options & DDB_OPT_IPV6_DEVICE)
6308 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
6310 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
6312 tddb->port = le16_to_cpu(fw_ddb_entry->port);
6314 if (flash_isid == NULL)
6315 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
6316 sizeof(tddb->isid));
6318 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
6321 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
6322 struct ql4_tuple_ddb *old_tddb,
6323 struct ql4_tuple_ddb *new_tddb,
6324 uint8_t is_isid_compare)
6326 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6329 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
6332 if (old_tddb->port != new_tddb->port)
6335 /* For multi sessions, driver generates the ISID, so do not compare
6336 * ISID in reset path since it would be a comparison between the
6337 * driver generated ISID and firmware generated ISID. This could
6338 * lead to adding duplicated DDBs in the list as driver generated
6339 * ISID would not match firmware generated ISID.
6341 if (is_isid_compare) {
6342 DEBUG2(ql4_printk(KERN_INFO, ha,
6343 "%s: old ISID [%pmR] New ISID [%pmR]\n",
6344 __func__, old_tddb->isid, new_tddb->isid));
6346 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6347 sizeof(old_tddb->isid)))
6351 DEBUG2(ql4_printk(KERN_INFO, ha,
6352 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
6353 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
6354 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
6355 new_tddb->ip_addr, new_tddb->iscsi_name));
6360 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
6361 struct dev_db_entry *fw_ddb_entry,
6364 struct ddb_entry *ddb_entry;
6365 struct ql4_tuple_ddb *fw_tddb = NULL;
6366 struct ql4_tuple_ddb *tmp_tddb = NULL;
6368 int ret = QLA_ERROR;
6370 fw_tddb = vzalloc(sizeof(*fw_tddb));
6372 DEBUG2(ql4_printk(KERN_WARNING, ha,
6373 "Memory Allocation failed.\n"));
6378 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6380 DEBUG2(ql4_printk(KERN_WARNING, ha,
6381 "Memory Allocation failed.\n"));
6386 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6388 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6389 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6390 if (ddb_entry == NULL)
6393 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
6394 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
6395 ret = QLA_SUCCESS; /* found */
6411 * qla4xxx_check_existing_isid - check if target with same isid exist
6413 * @list_nt: list of target
6414 * @isid: isid to check
6416 * This routine return QLA_SUCCESS if target with same isid exist
6418 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
6420 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6421 struct dev_db_entry *fw_ddb_entry;
6423 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6424 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
6426 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
6427 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
6435 * qla4xxx_update_isid - compare ddbs and updated isid
6436 * @ha: Pointer to host adapter structure.
6437 * @list_nt: list of nt target
6438 * @fw_ddb_entry: firmware ddb entry
6440 * This routine update isid if ddbs have same iqn, same isid and
6441 * different IP addr.
6442 * Return QLA_SUCCESS if isid is updated.
6444 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
6445 struct list_head *list_nt,
6446 struct dev_db_entry *fw_ddb_entry)
6448 uint8_t base_value, i;
6450 base_value = fw_ddb_entry->isid[1] & 0x1f;
6451 for (i = 0; i < 8; i++) {
6452 fw_ddb_entry->isid[1] = (base_value | (i << 5));
6453 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6457 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
6464 * qla4xxx_should_update_isid - check if isid need to update
6465 * @ha: Pointer to host adapter structure.
6466 * @old_tddb: ddb tuple
6467 * @new_tddb: ddb tuple
6469 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
6472 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
6473 struct ql4_tuple_ddb *old_tddb,
6474 struct ql4_tuple_ddb *new_tddb)
6476 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
6478 if (old_tddb->port == new_tddb->port)
6482 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
6486 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
6487 sizeof(old_tddb->isid)))
6488 /* different isid */
6495 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
6496 * @ha: Pointer to host adapter structure.
6497 * @list_nt: list of nt target.
6498 * @fw_ddb_entry: firmware ddb entry.
6500 * This routine check if fw_ddb_entry already exists in list_nt to avoid
6501 * duplicate ddb in list_nt.
6502 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
6503 * Note: This function also update isid of DDB if required.
6506 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
6507 struct list_head *list_nt,
6508 struct dev_db_entry *fw_ddb_entry)
6510 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
6511 struct ql4_tuple_ddb *fw_tddb = NULL;
6512 struct ql4_tuple_ddb *tmp_tddb = NULL;
6513 int rval, ret = QLA_ERROR;
6515 fw_tddb = vzalloc(sizeof(*fw_tddb));
6517 DEBUG2(ql4_printk(KERN_WARNING, ha,
6518 "Memory Allocation failed.\n"));
6523 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6525 DEBUG2(ql4_printk(KERN_WARNING, ha,
6526 "Memory Allocation failed.\n"));
6531 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
6533 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6534 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
6535 nt_ddb_idx->flash_isid);
6536 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
6537 /* found duplicate ddb */
6538 if (ret == QLA_SUCCESS)
6542 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
6543 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
6545 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
6546 if (ret == QLA_SUCCESS) {
6547 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
6548 if (rval == QLA_SUCCESS)
6565 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
6567 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6569 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6570 list_del_init(&ddb_idx->list);
6575 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
6576 struct dev_db_entry *fw_ddb_entry)
6578 struct iscsi_endpoint *ep;
6579 struct sockaddr_in *addr;
6580 struct sockaddr_in6 *addr6;
6581 struct sockaddr *t_addr;
6582 struct sockaddr_storage *dst_addr;
6585 /* TODO: need to destroy on unload iscsi_endpoint*/
6586 dst_addr = vmalloc(sizeof(*dst_addr));
6590 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
6591 t_addr = (struct sockaddr *)dst_addr;
6592 t_addr->sa_family = AF_INET6;
6593 addr6 = (struct sockaddr_in6 *)dst_addr;
6594 ip = (char *)&addr6->sin6_addr;
6595 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
6596 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
6599 t_addr = (struct sockaddr *)dst_addr;
6600 t_addr->sa_family = AF_INET;
6601 addr = (struct sockaddr_in *)dst_addr;
6602 ip = (char *)&addr->sin_addr;
6603 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
6604 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
6607 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
6612 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
6614 if (ql4xdisablesysfsboot)
6616 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
6621 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
6622 struct ddb_entry *ddb_entry,
6625 uint16_t def_timeout;
6627 ddb_entry->ddb_type = FLASH_DDB;
6628 ddb_entry->fw_ddb_index = INVALID_ENTRY;
6629 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
6631 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
6632 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
6633 ddb_entry->chap_tbl_idx = INVALID_ENTRY;
6635 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6636 atomic_set(&ddb_entry->relogin_timer, 0);
6637 atomic_set(&ddb_entry->relogin_retry_count, 0);
6638 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
6639 ddb_entry->default_relogin_timeout =
6640 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
6641 def_timeout : LOGIN_TOV;
6642 ddb_entry->default_time2wait =
6643 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
6645 if (ql4xdisablesysfsboot &&
6646 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
6647 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
6650 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
6653 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
6654 uint32_t sts[MBOX_REG_COUNT];
6656 unsigned long wtime;
6659 wtime = jiffies + (HZ * IP_CONFIG_TOV);
6661 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
6662 if (ip_idx[idx] == -1)
6665 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
6667 if (ret == QLA_ERROR) {
6672 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
6674 DEBUG2(ql4_printk(KERN_INFO, ha,
6675 "Waiting for IP state for idx = %d, state = 0x%x\n",
6676 ip_idx[idx], ip_state));
6677 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
6678 ip_state == IP_ADDRSTATE_INVALID ||
6679 ip_state == IP_ADDRSTATE_PREFERRED ||
6680 ip_state == IP_ADDRSTATE_DEPRICATED ||
6681 ip_state == IP_ADDRSTATE_DISABLING)
6685 /* Break if all IP states checked */
6686 if ((ip_idx[0] == -1) &&
6687 (ip_idx[1] == -1) &&
6688 (ip_idx[2] == -1) &&
6691 schedule_timeout_uninterruptible(HZ);
6692 } while (time_after(wtime, jiffies));
6695 static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
6696 struct dev_db_entry *flash_ddb_entry)
6698 uint16_t options = 0;
6699 size_t ip_len = IP_ADDR_LEN;
6701 options = le16_to_cpu(fw_ddb_entry->options);
6702 if (options & DDB_OPT_IPV6_DEVICE)
6703 ip_len = IPv6_ADDR_LEN;
6705 if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
6708 if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
6709 sizeof(fw_ddb_entry->isid)))
6712 if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
6713 sizeof(fw_ddb_entry->port)))
6719 static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
6720 struct dev_db_entry *fw_ddb_entry,
6721 uint32_t fw_idx, uint32_t *flash_index)
6723 struct dev_db_entry *flash_ddb_entry;
6724 dma_addr_t flash_ddb_entry_dma;
6727 int ret = QLA_ERROR, status;
6729 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6732 flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6733 &flash_ddb_entry_dma);
6734 if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
6735 ql4_printk(KERN_ERR, ha, "Out of memory\n");
6736 goto exit_find_st_idx;
6739 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6740 flash_ddb_entry_dma, fw_idx);
6741 if (status == QLA_SUCCESS) {
6742 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6743 if (status == QLA_SUCCESS) {
6744 *flash_index = fw_idx;
6746 goto exit_find_st_idx;
6750 for (idx = 0; idx < max_ddbs; idx++) {
6751 status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
6752 flash_ddb_entry_dma, idx);
6753 if (status == QLA_ERROR)
6756 status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
6757 if (status == QLA_SUCCESS) {
6760 goto exit_find_st_idx;
6764 if (idx == max_ddbs)
6765 ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
6769 if (flash_ddb_entry)
6770 dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
6771 flash_ddb_entry_dma);
6776 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
6777 struct list_head *list_st)
6779 struct qla_ddb_index *st_ddb_idx;
6782 struct dev_db_entry *fw_ddb_entry;
6783 dma_addr_t fw_ddb_dma;
6785 uint32_t idx = 0, next_idx = 0;
6786 uint32_t state = 0, conn_err = 0;
6787 uint32_t flash_index = -1;
6788 uint16_t conn_id = 0;
6790 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6792 if (fw_ddb_entry == NULL) {
6793 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
6797 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6799 fw_idx_size = sizeof(struct qla_ddb_index);
6801 for (idx = 0; idx < max_ddbs; idx = next_idx) {
6802 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
6803 NULL, &next_idx, &state,
6804 &conn_err, NULL, &conn_id);
6805 if (ret == QLA_ERROR)
6808 /* Ignore DDB if invalid state (unassigned) */
6809 if (state == DDB_DS_UNASSIGNED)
6810 goto continue_next_st;
6812 /* Check if ST, add to the list_st */
6813 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
6814 goto continue_next_st;
6816 st_ddb_idx = vzalloc(fw_idx_size);
6820 ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
6822 if (ret == QLA_ERROR) {
6823 ql4_printk(KERN_ERR, ha,
6824 "No flash entry for ST at idx [%d]\n", idx);
6825 st_ddb_idx->flash_ddb_idx = idx;
6827 ql4_printk(KERN_INFO, ha,
6828 "ST at idx [%d] is stored at flash [%d]\n",
6830 st_ddb_idx->flash_ddb_idx = flash_index;
6833 st_ddb_idx->fw_ddb_idx = idx;
6835 list_add_tail(&st_ddb_idx->list, list_st);
6843 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6847 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
6848 * @ha: pointer to adapter structure
6849 * @list_ddb: List from which failed ddb to be removed
6851 * Iterate over the list of DDBs and find and remove DDBs that are either in
6852 * no connection active state or failed state
6854 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
6855 struct list_head *list_ddb)
6857 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6858 uint32_t next_idx = 0;
6859 uint32_t state = 0, conn_err = 0;
6862 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6863 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
6864 NULL, 0, NULL, &next_idx, &state,
6865 &conn_err, NULL, NULL);
6866 if (ret == QLA_ERROR)
6869 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
6870 state == DDB_DS_SESSION_FAILED) {
6871 list_del_init(&ddb_idx->list);
6877 static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
6878 struct ddb_entry *ddb_entry,
6879 struct dev_db_entry *fw_ddb_entry)
6881 struct iscsi_cls_session *cls_sess;
6882 struct iscsi_session *sess;
6883 uint32_t max_ddbs = 0;
6884 uint16_t ddb_link = -1;
6886 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6889 cls_sess = ddb_entry->sess;
6890 sess = cls_sess->dd_data;
6892 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6893 if (ddb_link < max_ddbs)
6894 sess->discovery_parent_idx = ddb_link;
6896 sess->discovery_parent_idx = DDB_NO_LINK;
6899 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
6900 struct dev_db_entry *fw_ddb_entry,
6901 int is_reset, uint16_t idx)
6903 struct iscsi_cls_session *cls_sess;
6904 struct iscsi_session *sess;
6905 struct iscsi_cls_conn *cls_conn;
6906 struct iscsi_endpoint *ep;
6907 uint16_t cmds_max = 32;
6908 uint16_t conn_id = 0;
6909 uint32_t initial_cmdsn = 0;
6910 int ret = QLA_SUCCESS;
6912 struct ddb_entry *ddb_entry = NULL;
6914 /* Create session object, with INVALID_ENTRY,
6915 * the targer_id would get set when we issue the login
6917 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
6918 cmds_max, sizeof(struct ddb_entry),
6919 sizeof(struct ql4_task_data),
6920 initial_cmdsn, INVALID_ENTRY);
6927 * so calling module_put function to decrement the
6930 module_put(qla4xxx_iscsi_transport.owner);
6931 sess = cls_sess->dd_data;
6932 ddb_entry = sess->dd_data;
6933 ddb_entry->sess = cls_sess;
6935 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
6936 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
6937 sizeof(struct dev_db_entry));
6939 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
6941 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
6948 ddb_entry->conn = cls_conn;
6950 /* Setup ep, for displaying attributes in sysfs */
6951 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
6953 ep->conn = cls_conn;
6956 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
6961 /* Update sess/conn params */
6962 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
6963 qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
6965 if (is_reset == RESET_ADAPTER) {
6966 iscsi_block_session(cls_sess);
6967 /* Use the relogin path to discover new devices
6968 * by short-circuting the logic of setting
6969 * timer to relogin - instead set the flags
6970 * to initiate login right away.
6972 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
6973 set_bit(DF_RELOGIN, &ddb_entry->flags);
6980 static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
6981 struct list_head *list_ddb,
6982 struct dev_db_entry *fw_ddb_entry)
6984 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
6987 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
6989 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
6990 if (ddb_idx->fw_ddb_idx == ddb_link) {
6991 DEBUG2(ql4_printk(KERN_INFO, ha,
6992 "Updating NT parent idx from [%d] to [%d]\n",
6993 ddb_link, ddb_idx->flash_ddb_idx));
6994 fw_ddb_entry->ddb_link =
6995 cpu_to_le16(ddb_idx->flash_ddb_idx);
7001 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
7002 struct list_head *list_nt,
7003 struct list_head *list_st,
7006 struct dev_db_entry *fw_ddb_entry;
7007 struct ddb_entry *ddb_entry = NULL;
7008 dma_addr_t fw_ddb_dma;
7012 uint32_t idx = 0, next_idx = 0;
7013 uint32_t state = 0, conn_err = 0;
7014 uint32_t ddb_idx = -1;
7015 uint16_t conn_id = 0;
7016 uint16_t ddb_link = -1;
7017 struct qla_ddb_index *nt_ddb_idx;
7019 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7021 if (fw_ddb_entry == NULL) {
7022 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7025 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7027 fw_idx_size = sizeof(struct qla_ddb_index);
7029 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7030 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7031 NULL, &next_idx, &state,
7032 &conn_err, NULL, &conn_id);
7033 if (ret == QLA_ERROR)
7036 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
7037 goto continue_next_nt;
7039 /* Check if NT, then add to list it */
7040 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
7041 goto continue_next_nt;
7043 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
7044 if (ddb_link < max_ddbs)
7045 qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
7047 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
7048 state == DDB_DS_SESSION_FAILED) &&
7049 (is_reset == INIT_ADAPTER))
7050 goto continue_next_nt;
7052 DEBUG2(ql4_printk(KERN_INFO, ha,
7053 "Adding DDB to session = 0x%x\n", idx));
7055 if (is_reset == INIT_ADAPTER) {
7056 nt_ddb_idx = vmalloc(fw_idx_size);
7060 nt_ddb_idx->fw_ddb_idx = idx;
7062 /* Copy original isid as it may get updated in function
7063 * qla4xxx_update_isid(). We need original isid in
7064 * function qla4xxx_compare_tuple_ddb to find duplicate
7066 memcpy(&nt_ddb_idx->flash_isid[0],
7067 &fw_ddb_entry->isid[0],
7068 sizeof(nt_ddb_idx->flash_isid));
7070 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
7072 if (ret == QLA_SUCCESS) {
7073 /* free nt_ddb_idx and do not add to list_nt */
7075 goto continue_next_nt;
7078 /* Copy updated isid */
7079 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
7080 sizeof(struct dev_db_entry));
7082 list_add_tail(&nt_ddb_idx->list, list_nt);
7083 } else if (is_reset == RESET_ADAPTER) {
7084 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
7086 if (ret == QLA_SUCCESS) {
7087 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
7089 if (ddb_entry != NULL)
7090 qla4xxx_update_sess_disc_idx(ha,
7093 goto continue_next_nt;
7097 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
7098 if (ret == QLA_ERROR)
7108 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7111 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
7112 struct list_head *list_nt,
7115 struct dev_db_entry *fw_ddb_entry;
7116 dma_addr_t fw_ddb_dma;
7120 uint32_t idx = 0, next_idx = 0;
7121 uint32_t state = 0, conn_err = 0;
7122 uint16_t conn_id = 0;
7123 struct qla_ddb_index *nt_ddb_idx;
7125 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7127 if (fw_ddb_entry == NULL) {
7128 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
7129 goto exit_new_nt_list;
7131 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
7133 fw_idx_size = sizeof(struct qla_ddb_index);
7135 for (idx = 0; idx < max_ddbs; idx = next_idx) {
7136 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
7137 NULL, &next_idx, &state,
7138 &conn_err, NULL, &conn_id);
7139 if (ret == QLA_ERROR)
7142 /* Check if NT, then add it to list */
7143 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7144 goto continue_next_new_nt;
7146 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
7147 goto continue_next_new_nt;
7149 DEBUG2(ql4_printk(KERN_INFO, ha,
7150 "Adding DDB to session = 0x%x\n", idx));
7152 nt_ddb_idx = vmalloc(fw_idx_size);
7156 nt_ddb_idx->fw_ddb_idx = idx;
7158 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7159 if (ret == QLA_SUCCESS) {
7160 /* free nt_ddb_idx and do not add to list_nt */
7162 goto continue_next_new_nt;
7165 if (target_id < max_ddbs)
7166 fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
7168 list_add_tail(&nt_ddb_idx->list, list_nt);
7170 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7172 if (ret == QLA_ERROR)
7173 goto exit_new_nt_list;
7175 continue_next_new_nt:
7182 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7186 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
7187 * @dev: dev associated with the sysfs entry
7188 * @data: pointer to flashnode session object
7191 * 1: if flashnode entry is non-persistent
7192 * 0: if flashnode entry is persistent
7194 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
7196 struct iscsi_bus_flash_session *fnode_sess;
7198 if (!iscsi_flashnode_bus_match(dev, NULL))
7201 fnode_sess = iscsi_dev_to_flash_session(dev);
7203 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
7207 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
7208 * @ha: pointer to host
7209 * @fw_ddb_entry: flash ddb data
7210 * @idx: target index
7211 * @user: if set then this call is made from userland else from kernel
7214 * On sucess: QLA_SUCCESS
7215 * On failure: QLA_ERROR
7217 * This create separate sysfs entries for session and connection attributes of
7218 * the given fw ddb entry.
7219 * If this is invoked as a result of a userspace call then the entry is marked
7220 * as nonpersistent using flash_state field.
7222 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
7223 struct dev_db_entry *fw_ddb_entry,
7224 uint16_t *idx, int user)
7226 struct iscsi_bus_flash_session *fnode_sess = NULL;
7227 struct iscsi_bus_flash_conn *fnode_conn = NULL;
7230 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
7231 &qla4xxx_iscsi_transport, 0);
7233 ql4_printk(KERN_ERR, ha,
7234 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
7235 __func__, *idx, ha->host_no);
7236 goto exit_tgt_create;
7239 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
7240 &qla4xxx_iscsi_transport, 0);
7242 ql4_printk(KERN_ERR, ha,
7243 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
7244 __func__, *idx, ha->host_no);
7249 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
7251 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7253 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
7254 fnode_sess->is_boot_target = 1;
7256 fnode_sess->is_boot_target = 0;
7259 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
7264 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7265 __func__, fnode_sess->dev.kobj.name);
7267 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
7268 __func__, fnode_conn->dev.kobj.name);
7273 iscsi_destroy_flashnode_sess(fnode_sess);
7280 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
7281 * @shost: pointer to host
7282 * @buf: type of ddb entry (ipv4/ipv6)
7283 * @len: length of buf
7285 * This creates new ddb entry in the flash by finding first free index and
7286 * storing default ddb there. And then create sysfs entry for the new ddb entry.
7288 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
7291 struct scsi_qla_host *ha = to_qla_host(shost);
7292 struct dev_db_entry *fw_ddb_entry = NULL;
7293 dma_addr_t fw_ddb_entry_dma;
7296 uint16_t max_ddbs = 0;
7297 uint32_t options = 0;
7298 uint32_t rval = QLA_ERROR;
7300 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
7301 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
7302 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
7307 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
7310 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7311 &fw_ddb_entry_dma, GFP_KERNEL);
7312 if (!fw_ddb_entry) {
7313 DEBUG2(ql4_printk(KERN_ERR, ha,
7314 "%s: Unable to allocate dma buffer\n",
7319 dev = iscsi_find_flashnode_sess(ha->host, NULL,
7320 qla4xxx_sysfs_ddb_is_non_persistent);
7322 ql4_printk(KERN_ERR, ha,
7323 "%s: A non-persistent entry %s found\n",
7324 __func__, dev->kobj.name);
7329 /* Index 0 and 1 are reserved for boot target entries */
7330 for (idx = 2; idx < max_ddbs; idx++) {
7331 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
7332 fw_ddb_entry_dma, idx))
7336 if (idx == max_ddbs)
7339 if (!strncasecmp("ipv6", buf, 4))
7340 options |= IPV6_DEFAULT_DDB_ENTRY;
7342 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7343 if (rval == QLA_ERROR)
7346 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
7350 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7351 fw_ddb_entry, fw_ddb_entry_dma);
7352 if (rval == QLA_SUCCESS)
7359 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
7360 * @fnode_sess: pointer to session attrs of flash ddb entry
7361 * @fnode_conn: pointer to connection attrs of flash ddb entry
7363 * This writes the contents of target ddb buffer to Flash with a valid cookie
7364 * value in order to make the ddb entry persistent.
7366 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
7367 struct iscsi_bus_flash_conn *fnode_conn)
7369 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7370 struct scsi_qla_host *ha = to_qla_host(shost);
7371 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
7372 struct dev_db_entry *fw_ddb_entry = NULL;
7373 dma_addr_t fw_ddb_entry_dma;
7374 uint32_t options = 0;
7377 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7378 &fw_ddb_entry_dma, GFP_KERNEL);
7379 if (!fw_ddb_entry) {
7380 DEBUG2(ql4_printk(KERN_ERR, ha,
7381 "%s: Unable to allocate dma buffer\n",
7384 goto exit_ddb_apply;
7387 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7388 options |= IPV6_DEFAULT_DDB_ENTRY;
7390 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7391 if (rval == QLA_ERROR)
7392 goto exit_ddb_apply;
7394 dev_db_start_offset += (fnode_sess->target_id *
7395 sizeof(*fw_ddb_entry));
7397 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7398 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7400 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
7401 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
7403 if (rval == QLA_SUCCESS) {
7404 fnode_sess->flash_state = DEV_DB_PERSISTENT;
7405 ql4_printk(KERN_INFO, ha,
7406 "%s: flash node %u of host %lu written to flash\n",
7407 __func__, fnode_sess->target_id, ha->host_no);
7410 ql4_printk(KERN_ERR, ha,
7411 "%s: Error while writing flash node %u of host %lu to flash\n",
7412 __func__, fnode_sess->target_id, ha->host_no);
7417 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7418 fw_ddb_entry, fw_ddb_entry_dma);
7422 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
7423 struct dev_db_entry *fw_ddb_entry,
7426 struct dev_db_entry *ddb_entry = NULL;
7427 dma_addr_t ddb_entry_dma;
7428 unsigned long wtime;
7429 uint32_t mbx_sts = 0;
7430 uint32_t state = 0, conn_err = 0;
7434 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7435 &ddb_entry_dma, GFP_KERNEL);
7437 DEBUG2(ql4_printk(KERN_ERR, ha,
7438 "%s: Unable to allocate dma buffer\n",
7443 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
7445 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
7446 if (ret != QLA_SUCCESS) {
7447 DEBUG2(ql4_printk(KERN_ERR, ha,
7448 "%s: Unable to set ddb entry for index %d\n",
7450 goto exit_ddb_conn_open;
7453 qla4xxx_conn_open(ha, idx);
7455 /* To ensure that sendtargets is done, wait for at least 12 secs */
7456 tmo = ((ha->def_timeout > LOGIN_TOV) &&
7457 (ha->def_timeout < LOGIN_TOV * 10) ?
7458 ha->def_timeout : LOGIN_TOV);
7460 DEBUG2(ql4_printk(KERN_INFO, ha,
7461 "Default time to wait for login to ddb %d\n", tmo));
7463 wtime = jiffies + (HZ * tmo);
7465 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
7466 NULL, &state, &conn_err, NULL,
7468 if (ret == QLA_ERROR)
7471 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
7472 state == DDB_DS_SESSION_FAILED)
7475 schedule_timeout_uninterruptible(HZ / 10);
7476 } while (time_after(wtime, jiffies));
7480 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
7481 ddb_entry, ddb_entry_dma);
7485 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
7486 struct dev_db_entry *fw_ddb_entry,
7489 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
7490 struct list_head list_nt;
7494 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
7495 ql4_printk(KERN_WARNING, ha,
7496 "%s: A discovery already in progress!\n", __func__);
7500 INIT_LIST_HEAD(&list_nt);
7502 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7504 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
7505 if (ret == QLA_ERROR)
7506 goto exit_login_st_clr_bit;
7508 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
7509 if (ret == QLA_ERROR)
7512 qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
7514 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
7515 list_del_init(&ddb_idx->list);
7516 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
7521 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
7522 ql4_printk(KERN_ERR, ha,
7523 "Unable to clear DDB index = 0x%x\n", ddb_index);
7526 clear_bit(ddb_index, ha->ddb_idx_map);
7528 exit_login_st_clr_bit:
7529 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
7533 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
7534 struct dev_db_entry *fw_ddb_entry,
7537 int ret = QLA_ERROR;
7539 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
7540 if (ret != QLA_SUCCESS)
7541 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
7550 * qla4xxx_sysfs_ddb_login - Login to the specified target
7551 * @fnode_sess: pointer to session attrs of flash ddb entry
7552 * @fnode_conn: pointer to connection attrs of flash ddb entry
7554 * This logs in to the specified target
7556 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
7557 struct iscsi_bus_flash_conn *fnode_conn)
7559 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7560 struct scsi_qla_host *ha = to_qla_host(shost);
7561 struct dev_db_entry *fw_ddb_entry = NULL;
7562 dma_addr_t fw_ddb_entry_dma;
7563 uint32_t options = 0;
7566 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
7567 ql4_printk(KERN_ERR, ha,
7568 "%s: Target info is not persistent\n", __func__);
7570 goto exit_ddb_login;
7573 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7574 &fw_ddb_entry_dma, GFP_KERNEL);
7575 if (!fw_ddb_entry) {
7576 DEBUG2(ql4_printk(KERN_ERR, ha,
7577 "%s: Unable to allocate dma buffer\n",
7580 goto exit_ddb_login;
7583 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7584 options |= IPV6_DEFAULT_DDB_ENTRY;
7586 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
7587 if (ret == QLA_ERROR)
7588 goto exit_ddb_login;
7590 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
7591 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
7593 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
7594 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
7595 fnode_sess->target_id);
7597 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
7598 fnode_sess->target_id);
7605 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7606 fw_ddb_entry, fw_ddb_entry_dma);
7611 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
7612 * @cls_sess: pointer to session to be logged out
7614 * This performs session log out from the specified target
7616 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
7618 struct iscsi_session *sess;
7619 struct ddb_entry *ddb_entry = NULL;
7620 struct scsi_qla_host *ha;
7621 struct dev_db_entry *fw_ddb_entry = NULL;
7622 dma_addr_t fw_ddb_entry_dma;
7623 unsigned long flags;
7624 unsigned long wtime;
7629 sess = cls_sess->dd_data;
7630 ddb_entry = sess->dd_data;
7633 if (ddb_entry->ddb_type != FLASH_DDB) {
7634 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
7637 goto exit_ddb_logout;
7640 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
7641 ql4_printk(KERN_ERR, ha,
7642 "%s: Logout from boot target entry is not permitted.\n",
7645 goto exit_ddb_logout;
7648 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7649 &fw_ddb_entry_dma, GFP_KERNEL);
7650 if (!fw_ddb_entry) {
7651 ql4_printk(KERN_ERR, ha,
7652 "%s: Unable to allocate dma buffer\n", __func__);
7654 goto exit_ddb_logout;
7657 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
7658 goto ddb_logout_init;
7660 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7661 fw_ddb_entry, fw_ddb_entry_dma,
7662 NULL, NULL, &ddb_state, NULL,
7664 if (ret == QLA_ERROR)
7665 goto ddb_logout_init;
7667 if (ddb_state == DDB_DS_SESSION_ACTIVE)
7668 goto ddb_logout_init;
7670 /* wait until next relogin is triggered using DF_RELOGIN and
7671 * clear DF_RELOGIN to avoid invocation of further relogin
7673 wtime = jiffies + (HZ * RELOGIN_TOV);
7675 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
7676 goto ddb_logout_init;
7678 schedule_timeout_uninterruptible(HZ);
7679 } while ((time_after(wtime, jiffies)));
7682 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
7683 atomic_set(&ddb_entry->relogin_timer, 0);
7685 options = LOGOUT_OPTION_CLOSE_SESSION;
7686 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
7688 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
7689 wtime = jiffies + (HZ * LOGOUT_TOV);
7691 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
7692 fw_ddb_entry, fw_ddb_entry_dma,
7693 NULL, NULL, &ddb_state, NULL,
7695 if (ret == QLA_ERROR)
7696 goto ddb_logout_clr_sess;
7698 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
7699 (ddb_state == DDB_DS_SESSION_FAILED))
7700 goto ddb_logout_clr_sess;
7702 schedule_timeout_uninterruptible(HZ);
7703 } while ((time_after(wtime, jiffies)));
7705 ddb_logout_clr_sess:
7706 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7708 * we have decremented the reference count of the driver
7709 * when we setup the session to have the driver unload
7710 * to be seamless without actually destroying the
7713 try_module_get(qla4xxx_iscsi_transport.owner);
7714 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7716 spin_lock_irqsave(&ha->hardware_lock, flags);
7717 qla4xxx_free_ddb(ha, ddb_entry);
7718 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
7719 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7721 iscsi_session_teardown(ddb_entry->sess);
7723 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
7728 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
7729 fw_ddb_entry, fw_ddb_entry_dma);
7734 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
7735 * @fnode_sess: pointer to session attrs of flash ddb entry
7736 * @fnode_conn: pointer to connection attrs of flash ddb entry
7738 * This performs log out from the specified target
7740 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
7741 struct iscsi_bus_flash_conn *fnode_conn)
7743 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7744 struct scsi_qla_host *ha = to_qla_host(shost);
7745 struct ql4_tuple_ddb *flash_tddb = NULL;
7746 struct ql4_tuple_ddb *tmp_tddb = NULL;
7747 struct dev_db_entry *fw_ddb_entry = NULL;
7748 struct ddb_entry *ddb_entry = NULL;
7749 dma_addr_t fw_ddb_dma;
7750 uint32_t next_idx = 0;
7751 uint32_t state = 0, conn_err = 0;
7752 uint16_t conn_id = 0;
7754 int status, ret = 0;
7756 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
7758 if (fw_ddb_entry == NULL) {
7759 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
7761 goto exit_ddb_logout;
7764 flash_tddb = vzalloc(sizeof(*flash_tddb));
7766 ql4_printk(KERN_WARNING, ha,
7767 "%s:Memory Allocation failed.\n", __func__);
7769 goto exit_ddb_logout;
7772 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
7774 ql4_printk(KERN_WARNING, ha,
7775 "%s:Memory Allocation failed.\n", __func__);
7777 goto exit_ddb_logout;
7780 if (!fnode_sess->targetname) {
7781 ql4_printk(KERN_ERR, ha,
7782 "%s:Cannot logout from SendTarget entry\n",
7785 goto exit_ddb_logout;
7788 if (fnode_sess->is_boot_target) {
7789 ql4_printk(KERN_ERR, ha,
7790 "%s: Logout from boot target entry is not permitted.\n",
7793 goto exit_ddb_logout;
7796 strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
7799 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7800 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
7802 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
7804 flash_tddb->tpgt = fnode_sess->tpgt;
7805 flash_tddb->port = fnode_conn->port;
7807 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
7809 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7810 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7811 if (ddb_entry == NULL)
7814 if (ddb_entry->ddb_type != FLASH_DDB)
7817 index = ddb_entry->sess->target_id;
7818 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
7819 fw_ddb_dma, NULL, &next_idx,
7820 &state, &conn_err, NULL,
7822 if (status == QLA_ERROR) {
7827 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
7829 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
7831 if (status == QLA_SUCCESS) {
7832 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
7837 if (idx == MAX_DDB_ENTRIES)
7846 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
7852 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
7853 int param, char *buf)
7855 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
7856 struct scsi_qla_host *ha = to_qla_host(shost);
7857 struct iscsi_bus_flash_conn *fnode_conn;
7858 struct ql4_chap_table chap_tbl;
7863 dev = iscsi_find_flashnode_conn(fnode_sess);
7867 fnode_conn = iscsi_dev_to_flash_conn(dev);
7870 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
7871 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
7873 case ISCSI_FLASHNODE_PORTAL_TYPE:
7874 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
7876 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
7877 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
7879 case ISCSI_FLASHNODE_DISCOVERY_SESS:
7880 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
7882 case ISCSI_FLASHNODE_ENTRY_EN:
7883 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
7885 case ISCSI_FLASHNODE_HDR_DGST_EN:
7886 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
7888 case ISCSI_FLASHNODE_DATA_DGST_EN:
7889 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
7891 case ISCSI_FLASHNODE_IMM_DATA_EN:
7892 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
7894 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
7895 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
7897 case ISCSI_FLASHNODE_DATASEQ_INORDER:
7898 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
7900 case ISCSI_FLASHNODE_PDU_INORDER:
7901 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
7903 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
7904 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
7906 case ISCSI_FLASHNODE_SNACK_REQ_EN:
7907 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
7909 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
7910 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
7912 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
7913 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
7915 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
7916 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
7918 case ISCSI_FLASHNODE_ERL:
7919 rc = sprintf(buf, "%u\n", fnode_sess->erl);
7921 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
7922 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
7924 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
7925 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
7927 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
7928 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
7930 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
7931 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
7933 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
7934 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
7936 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
7937 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
7939 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
7940 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
7942 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
7943 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
7945 case ISCSI_FLASHNODE_FIRST_BURST:
7946 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
7948 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
7949 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
7951 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
7952 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
7954 case ISCSI_FLASHNODE_MAX_R2T:
7955 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
7957 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
7958 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
7960 case ISCSI_FLASHNODE_ISID:
7961 rc = sprintf(buf, "%pm\n", fnode_sess->isid);
7963 case ISCSI_FLASHNODE_TSID:
7964 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
7966 case ISCSI_FLASHNODE_PORT:
7967 rc = sprintf(buf, "%d\n", fnode_conn->port);
7969 case ISCSI_FLASHNODE_MAX_BURST:
7970 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
7972 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
7973 rc = sprintf(buf, "%u\n",
7974 fnode_sess->default_taskmgmt_timeout);
7976 case ISCSI_FLASHNODE_IPADDR:
7977 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7978 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
7980 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
7982 case ISCSI_FLASHNODE_ALIAS:
7983 if (fnode_sess->targetalias)
7984 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
7986 rc = sprintf(buf, "\n");
7988 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
7989 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
7990 rc = sprintf(buf, "%pI6\n",
7991 fnode_conn->redirect_ipaddr);
7993 rc = sprintf(buf, "%pI4\n",
7994 fnode_conn->redirect_ipaddr);
7996 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
7997 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
7999 case ISCSI_FLASHNODE_LOCAL_PORT:
8000 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
8002 case ISCSI_FLASHNODE_IPV4_TOS:
8003 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
8005 case ISCSI_FLASHNODE_IPV6_TC:
8006 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8007 rc = sprintf(buf, "%u\n",
8008 fnode_conn->ipv6_traffic_class);
8010 rc = sprintf(buf, "\n");
8012 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8013 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
8015 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8016 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
8017 rc = sprintf(buf, "%pI6\n",
8018 fnode_conn->link_local_ipv6_addr);
8020 rc = sprintf(buf, "\n");
8022 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8023 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
8025 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
8026 if (fnode_sess->discovery_parent_type == DDB_ISNS)
8027 parent_type = ISCSI_DISC_PARENT_ISNS;
8028 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
8029 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8030 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
8031 parent_type = ISCSI_DISC_PARENT_SENDTGT;
8033 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
8035 rc = sprintf(buf, "%s\n",
8036 iscsi_get_discovery_parent_name(parent_type));
8038 case ISCSI_FLASHNODE_NAME:
8039 if (fnode_sess->targetname)
8040 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
8042 rc = sprintf(buf, "\n");
8044 case ISCSI_FLASHNODE_TPGT:
8045 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
8047 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8048 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
8050 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8051 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
8053 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8054 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
8056 case ISCSI_FLASHNODE_USERNAME:
8057 if (fnode_sess->chap_auth_en) {
8058 qla4xxx_get_uni_chap_at_index(ha,
8061 fnode_sess->chap_out_idx);
8062 rc = sprintf(buf, "%s\n", chap_tbl.name);
8064 rc = sprintf(buf, "\n");
8067 case ISCSI_FLASHNODE_PASSWORD:
8068 if (fnode_sess->chap_auth_en) {
8069 qla4xxx_get_uni_chap_at_index(ha,
8072 fnode_sess->chap_out_idx);
8073 rc = sprintf(buf, "%s\n", chap_tbl.secret);
8075 rc = sprintf(buf, "\n");
8078 case ISCSI_FLASHNODE_STATSN:
8079 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
8081 case ISCSI_FLASHNODE_EXP_STATSN:
8082 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
8084 case ISCSI_FLASHNODE_IS_BOOT_TGT:
8085 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
8097 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
8098 * @fnode_sess: pointer to session attrs of flash ddb entry
8099 * @fnode_conn: pointer to connection attrs of flash ddb entry
8100 * @data: Parameters and their values to update
8103 * This sets the parameter of flash ddb entry and writes them to flash
8106 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
8107 struct iscsi_bus_flash_conn *fnode_conn,
8108 void *data, int len)
8110 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8111 struct scsi_qla_host *ha = to_qla_host(shost);
8112 struct iscsi_flashnode_param_info *fnode_param;
8113 struct ql4_chap_table chap_tbl;
8114 struct nlattr *attr;
8115 uint16_t chap_out_idx = INVALID_ENTRY;
8119 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
8120 nla_for_each_attr(attr, data, len, rem) {
8121 fnode_param = nla_data(attr);
8123 switch (fnode_param->param) {
8124 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
8125 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
8127 case ISCSI_FLASHNODE_PORTAL_TYPE:
8128 memcpy(fnode_sess->portal_type, fnode_param->value,
8129 strlen(fnode_sess->portal_type));
8131 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
8132 fnode_sess->auto_snd_tgt_disable =
8133 fnode_param->value[0];
8135 case ISCSI_FLASHNODE_DISCOVERY_SESS:
8136 fnode_sess->discovery_sess = fnode_param->value[0];
8138 case ISCSI_FLASHNODE_ENTRY_EN:
8139 fnode_sess->entry_state = fnode_param->value[0];
8141 case ISCSI_FLASHNODE_HDR_DGST_EN:
8142 fnode_conn->hdrdgst_en = fnode_param->value[0];
8144 case ISCSI_FLASHNODE_DATA_DGST_EN:
8145 fnode_conn->datadgst_en = fnode_param->value[0];
8147 case ISCSI_FLASHNODE_IMM_DATA_EN:
8148 fnode_sess->imm_data_en = fnode_param->value[0];
8150 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
8151 fnode_sess->initial_r2t_en = fnode_param->value[0];
8153 case ISCSI_FLASHNODE_DATASEQ_INORDER:
8154 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
8156 case ISCSI_FLASHNODE_PDU_INORDER:
8157 fnode_sess->pdu_inorder_en = fnode_param->value[0];
8159 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
8160 fnode_sess->chap_auth_en = fnode_param->value[0];
8161 /* Invalidate chap index if chap auth is disabled */
8162 if (!fnode_sess->chap_auth_en)
8163 fnode_sess->chap_out_idx = INVALID_ENTRY;
8166 case ISCSI_FLASHNODE_SNACK_REQ_EN:
8167 fnode_conn->snack_req_en = fnode_param->value[0];
8169 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
8170 fnode_sess->discovery_logout_en = fnode_param->value[0];
8172 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
8173 fnode_sess->bidi_chap_en = fnode_param->value[0];
8175 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
8176 fnode_sess->discovery_auth_optional =
8177 fnode_param->value[0];
8179 case ISCSI_FLASHNODE_ERL:
8180 fnode_sess->erl = fnode_param->value[0];
8182 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
8183 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
8185 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
8186 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
8188 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
8189 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
8191 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
8192 fnode_conn->tcp_timer_scale = fnode_param->value[0];
8194 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
8195 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
8197 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
8198 fnode_conn->fragment_disable = fnode_param->value[0];
8200 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
8201 fnode_conn->max_recv_dlength =
8202 *(unsigned *)fnode_param->value;
8204 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
8205 fnode_conn->max_xmit_dlength =
8206 *(unsigned *)fnode_param->value;
8208 case ISCSI_FLASHNODE_FIRST_BURST:
8209 fnode_sess->first_burst =
8210 *(unsigned *)fnode_param->value;
8212 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
8213 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
8215 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
8216 fnode_sess->time2retain =
8217 *(uint16_t *)fnode_param->value;
8219 case ISCSI_FLASHNODE_MAX_R2T:
8220 fnode_sess->max_r2t =
8221 *(uint16_t *)fnode_param->value;
8223 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
8224 fnode_conn->keepalive_timeout =
8225 *(uint16_t *)fnode_param->value;
8227 case ISCSI_FLASHNODE_ISID:
8228 memcpy(fnode_sess->isid, fnode_param->value,
8229 sizeof(fnode_sess->isid));
8231 case ISCSI_FLASHNODE_TSID:
8232 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
8234 case ISCSI_FLASHNODE_PORT:
8235 fnode_conn->port = *(uint16_t *)fnode_param->value;
8237 case ISCSI_FLASHNODE_MAX_BURST:
8238 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
8240 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
8241 fnode_sess->default_taskmgmt_timeout =
8242 *(uint16_t *)fnode_param->value;
8244 case ISCSI_FLASHNODE_IPADDR:
8245 memcpy(fnode_conn->ipaddress, fnode_param->value,
8248 case ISCSI_FLASHNODE_ALIAS:
8249 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
8250 (char *)fnode_param->value);
8252 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
8253 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
8256 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
8257 fnode_conn->max_segment_size =
8258 *(unsigned *)fnode_param->value;
8260 case ISCSI_FLASHNODE_LOCAL_PORT:
8261 fnode_conn->local_port =
8262 *(uint16_t *)fnode_param->value;
8264 case ISCSI_FLASHNODE_IPV4_TOS:
8265 fnode_conn->ipv4_tos = fnode_param->value[0];
8267 case ISCSI_FLASHNODE_IPV6_TC:
8268 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
8270 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
8271 fnode_conn->ipv6_flow_label = fnode_param->value[0];
8273 case ISCSI_FLASHNODE_NAME:
8274 rc = iscsi_switch_str_param(&fnode_sess->targetname,
8275 (char *)fnode_param->value);
8277 case ISCSI_FLASHNODE_TPGT:
8278 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
8280 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
8281 memcpy(fnode_conn->link_local_ipv6_addr,
8282 fnode_param->value, IPv6_ADDR_LEN);
8284 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
8285 fnode_sess->discovery_parent_idx =
8286 *(uint16_t *)fnode_param->value;
8288 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
8289 fnode_conn->tcp_xmit_wsf =
8290 *(uint8_t *)fnode_param->value;
8292 case ISCSI_FLASHNODE_TCP_RECV_WSF:
8293 fnode_conn->tcp_recv_wsf =
8294 *(uint8_t *)fnode_param->value;
8296 case ISCSI_FLASHNODE_STATSN:
8297 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
8299 case ISCSI_FLASHNODE_EXP_STATSN:
8300 fnode_conn->exp_statsn =
8301 *(uint32_t *)fnode_param->value;
8303 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
8304 chap_out_idx = *(uint16_t *)fnode_param->value;
8305 if (!qla4xxx_get_uni_chap_at_index(ha,
8309 fnode_sess->chap_out_idx = chap_out_idx;
8310 /* Enable chap auth if chap index is valid */
8311 fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
8315 ql4_printk(KERN_ERR, ha,
8316 "%s: No such sysfs attribute\n", __func__);
8318 goto exit_set_param;
8322 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
8329 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
8330 * @fnode_sess: pointer to session attrs of flash ddb entry
8332 * This invalidates the flash ddb entry at the given index
8334 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
8336 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
8337 struct scsi_qla_host *ha = to_qla_host(shost);
8338 uint32_t dev_db_start_offset;
8339 uint32_t dev_db_end_offset;
8340 struct dev_db_entry *fw_ddb_entry = NULL;
8341 dma_addr_t fw_ddb_entry_dma;
8342 uint16_t *ddb_cookie = NULL;
8343 size_t ddb_size = 0;
8348 if (fnode_sess->is_boot_target) {
8350 DEBUG2(ql4_printk(KERN_ERR, ha,
8351 "%s: Deletion of boot target entry is not permitted.\n",
8356 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
8359 if (is_qla40XX(ha)) {
8360 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
8361 dev_db_end_offset = FLASH_OFFSET_DB_END;
8362 dev_db_start_offset += (fnode_sess->target_id *
8363 sizeof(*fw_ddb_entry));
8364 ddb_size = sizeof(*fw_ddb_entry);
8366 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
8367 (ha->hw.flt_region_ddb << 2);
8368 /* flt_ddb_size is DDB table size for both ports
8369 * so divide it by 2 to calculate the offset for second port
8371 if (ha->port_num == 1)
8372 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
8374 dev_db_end_offset = dev_db_start_offset +
8375 (ha->hw.flt_ddb_size / 2);
8377 dev_db_start_offset += (fnode_sess->target_id *
8378 sizeof(*fw_ddb_entry));
8379 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
8381 ddb_size = sizeof(*ddb_cookie);
8384 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
8385 __func__, dev_db_start_offset, dev_db_end_offset));
8387 if (dev_db_start_offset > dev_db_end_offset) {
8389 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
8390 __func__, fnode_sess->target_id));
8394 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
8395 &fw_ddb_entry_dma, GFP_KERNEL);
8398 DEBUG2(ql4_printk(KERN_ERR, ha,
8399 "%s: Unable to allocate dma buffer\n",
8404 if (is_qla40XX(ha)) {
8405 fw_ddb_entry = pddb;
8406 memset(fw_ddb_entry, 0, ddb_size);
8407 ddb_cookie = &fw_ddb_entry->cookie;
8412 /* invalidate the cookie */
8413 *ddb_cookie = 0xFFEE;
8414 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
8415 ddb_size, FLASH_OPT_RMW_COMMIT);
8418 target_id = fnode_sess->target_id;
8419 iscsi_destroy_flashnode_sess(fnode_sess);
8420 ql4_printk(KERN_INFO, ha,
8421 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
8422 __func__, target_id, ha->host_no);
8425 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
8431 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
8432 * @ha: pointer to adapter structure
8434 * Export the firmware DDB for all send targets and normal targets to sysfs.
8436 int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
8438 struct dev_db_entry *fw_ddb_entry = NULL;
8439 dma_addr_t fw_ddb_entry_dma;
8442 int ret = QLA_SUCCESS;
8444 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
8445 sizeof(*fw_ddb_entry),
8446 &fw_ddb_entry_dma, GFP_KERNEL);
8447 if (!fw_ddb_entry) {
8448 DEBUG2(ql4_printk(KERN_ERR, ha,
8449 "%s: Unable to allocate dma buffer\n",
8454 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
8457 for (idx = 0; idx < max_ddbs; idx++) {
8458 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
8462 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
8469 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
8475 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
8477 iscsi_destroy_all_flashnode(ha->host);
8481 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
8482 * @ha: pointer to adapter structure
8483 * @is_reset: Is this init path or reset path
8485 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
8486 * using connection open, then create the list of normal targets (nt)
8487 * from firmware DDBs. Based on the list of nt setup session and connection
8490 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
8493 struct list_head list_st, list_nt;
8494 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
8495 unsigned long wtime;
8497 if (!test_bit(AF_LINK_UP, &ha->flags)) {
8498 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
8499 ha->is_reset = is_reset;
8503 INIT_LIST_HEAD(&list_st);
8504 INIT_LIST_HEAD(&list_nt);
8506 qla4xxx_build_st_list(ha, &list_st);
8508 /* Before issuing conn open mbox, ensure all IPs states are configured
8509 * Note, conn open fails if IPs are not configured
8511 qla4xxx_wait_for_ip_configuration(ha);
8513 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
8514 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
8515 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
8518 /* Wait to ensure all sendtargets are done for min 12 sec wait */
8519 tmo = ((ha->def_timeout > LOGIN_TOV) &&
8520 (ha->def_timeout < LOGIN_TOV * 10) ?
8521 ha->def_timeout : LOGIN_TOV);
8523 DEBUG2(ql4_printk(KERN_INFO, ha,
8524 "Default time to wait for build ddb %d\n", tmo));
8526 wtime = jiffies + (HZ * tmo);
8528 if (list_empty(&list_st))
8531 qla4xxx_remove_failed_ddb(ha, &list_st);
8532 schedule_timeout_uninterruptible(HZ / 10);
8533 } while (time_after(wtime, jiffies));
8536 qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
8538 qla4xxx_free_ddb_list(&list_st);
8539 qla4xxx_free_ddb_list(&list_nt);
8541 qla4xxx_free_ddb_index(ha);
8545 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
8547 * @ha: pointer to adapter structure
8549 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
8550 * set in DDB and we will wait for login response of boot targets during
8553 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
8555 struct ddb_entry *ddb_entry;
8556 struct dev_db_entry *fw_ddb_entry = NULL;
8557 dma_addr_t fw_ddb_entry_dma;
8558 unsigned long wtime;
8560 int max_ddbs, idx, ret;
8562 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
8565 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8566 &fw_ddb_entry_dma, GFP_KERNEL);
8567 if (!fw_ddb_entry) {
8568 ql4_printk(KERN_ERR, ha,
8569 "%s: Unable to allocate dma buffer\n", __func__);
8570 goto exit_login_resp;
8573 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
8575 for (idx = 0; idx < max_ddbs; idx++) {
8576 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8577 if (ddb_entry == NULL)
8580 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
8581 DEBUG2(ql4_printk(KERN_INFO, ha,
8582 "%s: DDB index [%d]\n", __func__,
8583 ddb_entry->fw_ddb_index));
8585 ret = qla4xxx_get_fwddb_entry(ha,
8586 ddb_entry->fw_ddb_index,
8587 fw_ddb_entry, fw_ddb_entry_dma,
8588 NULL, NULL, &ddb_state, NULL,
8590 if (ret == QLA_ERROR)
8591 goto exit_login_resp;
8593 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
8594 (ddb_state == DDB_DS_SESSION_FAILED))
8597 schedule_timeout_uninterruptible(HZ);
8599 } while ((time_after(wtime, jiffies)));
8601 if (!time_after(wtime, jiffies)) {
8602 DEBUG2(ql4_printk(KERN_INFO, ha,
8603 "%s: Login response wait timer expired\n",
8605 goto exit_login_resp;
8612 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8613 fw_ddb_entry, fw_ddb_entry_dma);
8617 * qla4xxx_probe_adapter - callback function to probe HBA
8618 * @pdev: pointer to pci_dev structure
8619 * @ent: pointer to pci_device entry
8621 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
8622 * It returns zero if successful. It also initializes all data necessary for
8625 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
8626 const struct pci_device_id *ent)
8628 int ret = -ENODEV, status;
8629 struct Scsi_Host *host;
8630 struct scsi_qla_host *ha;
8631 uint8_t init_retry_count = 0;
8633 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
8636 if (pci_enable_device(pdev))
8639 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
8642 "qla4xxx: Couldn't allocate host from scsi layer!\n");
8643 goto probe_disable_device;
8646 /* Clear our data area */
8647 ha = to_qla_host(host);
8648 memset(ha, 0, sizeof(*ha));
8650 /* Save the information from PCI BIOS. */
8653 ha->host_no = host->host_no;
8654 ha->func_num = PCI_FUNC(ha->pdev->devfn);
8656 pci_enable_pcie_error_reporting(pdev);
8658 /* Setup Runtime configurable options */
8659 if (is_qla8022(ha)) {
8660 ha->isp_ops = &qla4_82xx_isp_ops;
8661 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
8662 ha->qdr_sn_window = -1;
8663 ha->ddr_mn_window = -1;
8664 ha->curr_window = 255;
8665 nx_legacy_intr = &legacy_intr[ha->func_num];
8666 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
8667 ha->nx_legacy_intr.tgt_status_reg =
8668 nx_legacy_intr->tgt_status_reg;
8669 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
8670 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
8671 } else if (is_qla8032(ha) || is_qla8042(ha)) {
8672 ha->isp_ops = &qla4_83xx_isp_ops;
8673 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
8675 ha->isp_ops = &qla4xxx_isp_ops;
8678 if (is_qla80XX(ha)) {
8679 rwlock_init(&ha->hw_lock);
8680 ha->pf_bit = ha->func_num << 16;
8681 /* Set EEH reset type to fundamental if required by hba */
8682 pdev->needs_freset = 1;
8685 /* Configure PCI I/O space. */
8686 ret = ha->isp_ops->iospace_config(ha);
8688 goto probe_failed_ioconfig;
8690 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
8691 pdev->device, pdev->irq, ha->reg);
8693 qla4xxx_config_dma_addressing(ha);
8695 /* Initialize lists and spinlocks. */
8696 INIT_LIST_HEAD(&ha->free_srb_q);
8698 mutex_init(&ha->mbox_sem);
8699 mutex_init(&ha->chap_sem);
8700 init_completion(&ha->mbx_intr_comp);
8701 init_completion(&ha->disable_acb_comp);
8702 init_completion(&ha->idc_comp);
8703 init_completion(&ha->link_up_comp);
8705 spin_lock_init(&ha->hardware_lock);
8706 spin_lock_init(&ha->work_lock);
8708 /* Initialize work list */
8709 INIT_LIST_HEAD(&ha->work_list);
8711 /* Allocate dma buffers */
8712 if (qla4xxx_mem_alloc(ha)) {
8713 ql4_printk(KERN_WARNING, ha,
8714 "[ERROR] Failed to allocate memory for adapter\n");
8720 host->cmd_per_lun = 3;
8721 host->max_channel = 0;
8722 host->max_lun = MAX_LUNS - 1;
8723 host->max_id = MAX_TARGETS;
8724 host->max_cmd_len = IOCB_MAX_CDB_LEN;
8725 host->can_queue = MAX_SRBS ;
8726 host->transportt = qla4xxx_scsi_transport;
8728 pci_set_drvdata(pdev, ha);
8730 ret = scsi_add_host(host, &pdev->dev);
8735 qla4_8xxx_get_flash_info(ha);
8737 if (is_qla8032(ha) || is_qla8042(ha)) {
8738 qla4_83xx_read_reset_template(ha);
8740 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
8741 * If DONRESET_BIT0 is set, drivers should not set dev_state
8742 * to NEED_RESET. But if NEED_RESET is set, drivers should
8743 * should honor the reset.
8745 if (ql4xdontresethba == 1)
8746 qla4_83xx_set_idc_dontreset(ha);
8750 * Initialize the Host adapter request/response queues and
8752 * NOTE: interrupts enabled upon successful completion
8754 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8756 /* Dont retry adapter initialization if IRQ allocation failed */
8757 if (is_qla80XX(ha) && (status == QLA_ERROR))
8758 goto skip_retry_init;
8760 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
8761 init_retry_count++ < MAX_INIT_RETRIES) {
8763 if (is_qla80XX(ha)) {
8764 ha->isp_ops->idc_lock(ha);
8765 dev_state = qla4_8xxx_rd_direct(ha,
8766 QLA8XXX_CRB_DEV_STATE);
8767 ha->isp_ops->idc_unlock(ha);
8768 if (dev_state == QLA8XXX_DEV_FAILED) {
8769 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
8770 "initialize adapter. H/W is in failed state\n",
8775 DEBUG2(printk("scsi: %s: retrying adapter initialization "
8776 "(%d)\n", __func__, init_retry_count));
8778 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
8781 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
8782 if (is_qla80XX(ha) && (status == QLA_ERROR)) {
8783 if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
8784 goto skip_retry_init;
8789 if (!test_bit(AF_ONLINE, &ha->flags)) {
8790 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
8792 if ((is_qla8022(ha) && ql4xdontresethba) ||
8793 ((is_qla8032(ha) || is_qla8042(ha)) &&
8794 qla4_83xx_idc_dontreset(ha))) {
8795 /* Put the device in failed state. */
8796 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
8797 ha->isp_ops->idc_lock(ha);
8798 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8799 QLA8XXX_DEV_FAILED);
8800 ha->isp_ops->idc_unlock(ha);
8806 /* Startup the kernel thread for this host adapter. */
8807 DEBUG2(printk("scsi: %s: Starting kernel thread for "
8808 "qla4xxx_dpc\n", __func__));
8809 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
8810 ha->dpc_thread = create_singlethread_workqueue(buf);
8811 if (!ha->dpc_thread) {
8812 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
8816 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
8818 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
8821 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
8827 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
8828 * (which is called indirectly by qla4xxx_initialize_adapter),
8829 * so that irqs will be registered after crbinit but before
8832 if (is_qla40XX(ha)) {
8833 ret = qla4xxx_request_irqs(ha);
8835 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
8836 "interrupt %d already in use.\n", pdev->irq);
8841 pci_save_state(ha->pdev);
8842 ha->isp_ops->enable_intrs(ha);
8844 /* Start timer thread. */
8845 qla4xxx_start_timer(ha, 1);
8847 set_bit(AF_INIT_DONE, &ha->flags);
8849 qla4_8xxx_alloc_sysfs_attr(ha);
8852 " QLogic iSCSI HBA Driver version: %s\n"
8853 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
8854 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
8855 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
8856 ha->fw_info.fw_patch, ha->fw_info.fw_build);
8858 /* Set the driver version */
8860 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
8862 if (qla4xxx_setup_boot_info(ha))
8863 ql4_printk(KERN_ERR, ha,
8864 "%s: No iSCSI boot target configured\n", __func__);
8866 set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
8867 /* Perform the build ddb list and login to each */
8868 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
8869 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
8870 qla4xxx_wait_login_resp_boot_tgt(ha);
8872 qla4xxx_create_chap_list(ha);
8874 qla4xxx_create_ifaces(ha);
8878 scsi_remove_host(ha->host);
8881 qla4xxx_free_adapter(ha);
8883 probe_failed_ioconfig:
8884 pci_disable_pcie_error_reporting(pdev);
8885 scsi_host_put(ha->host);
8887 probe_disable_device:
8888 pci_disable_device(pdev);
8894 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
8895 * @ha: pointer to adapter structure
8897 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
8898 * so that the other port will not re-initialize while in the process of
8899 * removing the ha due to driver unload or hba hotplug.
8901 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
8903 struct scsi_qla_host *other_ha = NULL;
8904 struct pci_dev *other_pdev = NULL;
8905 int fn = ISP4XXX_PCI_FN_2;
8907 /*iscsi function numbers for ISP4xxx is 1 and 3*/
8908 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
8909 fn = ISP4XXX_PCI_FN_1;
8912 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8913 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8916 /* Get other_ha if other_pdev is valid and state is enable*/
8918 if (atomic_read(&other_pdev->enable_cnt)) {
8919 other_ha = pci_get_drvdata(other_pdev);
8921 set_bit(AF_HA_REMOVAL, &other_ha->flags);
8922 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
8923 "Prevent %s reinit\n", __func__,
8924 dev_name(&other_ha->pdev->dev)));
8927 pci_dev_put(other_pdev);
8931 static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
8932 struct ddb_entry *ddb_entry)
8934 struct dev_db_entry *fw_ddb_entry = NULL;
8935 dma_addr_t fw_ddb_entry_dma;
8936 unsigned long wtime;
8941 options = LOGOUT_OPTION_CLOSE_SESSION;
8942 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
8943 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
8947 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8948 &fw_ddb_entry_dma, GFP_KERNEL);
8949 if (!fw_ddb_entry) {
8950 ql4_printk(KERN_ERR, ha,
8951 "%s: Unable to allocate dma buffer\n", __func__);
8955 wtime = jiffies + (HZ * LOGOUT_TOV);
8957 status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
8958 fw_ddb_entry, fw_ddb_entry_dma,
8959 NULL, NULL, &ddb_state, NULL,
8961 if (status == QLA_ERROR)
8964 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
8965 (ddb_state == DDB_DS_SESSION_FAILED))
8968 schedule_timeout_uninterruptible(HZ);
8969 } while ((time_after(wtime, jiffies)));
8972 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
8973 fw_ddb_entry, fw_ddb_entry_dma);
8975 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
8978 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
8980 struct ddb_entry *ddb_entry;
8983 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
8985 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
8986 if ((ddb_entry != NULL) &&
8987 (ddb_entry->ddb_type == FLASH_DDB)) {
8989 qla4xxx_destroy_ddb(ha, ddb_entry);
8991 * we have decremented the reference count of the driver
8992 * when we setup the session to have the driver unload
8993 * to be seamless without actually destroying the
8996 try_module_get(qla4xxx_iscsi_transport.owner);
8997 iscsi_destroy_endpoint(ddb_entry->conn->ep);
8998 qla4xxx_free_ddb(ha, ddb_entry);
8999 iscsi_session_teardown(ddb_entry->sess);
9004 * qla4xxx_remove_adapter - callback function to remove adapter.
9005 * @pdev: PCI device pointer
9007 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
9009 struct scsi_qla_host *ha;
9012 * If the PCI device is disabled then it means probe_adapter had
9013 * failed and resources already cleaned up on probe_adapter exit.
9015 if (!pci_is_enabled(pdev))
9018 ha = pci_get_drvdata(pdev);
9021 qla4xxx_prevent_other_port_reinit(ha);
9023 /* destroy iface from sysfs */
9024 qla4xxx_destroy_ifaces(ha);
9026 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
9027 iscsi_boot_destroy_kset(ha->boot_kset);
9029 qla4xxx_destroy_fw_ddb_session(ha);
9030 qla4_8xxx_free_sysfs_attr(ha);
9032 qla4xxx_sysfs_ddb_remove(ha);
9033 scsi_remove_host(ha->host);
9035 qla4xxx_free_adapter(ha);
9037 scsi_host_put(ha->host);
9039 pci_disable_pcie_error_reporting(pdev);
9040 pci_disable_device(pdev);
9044 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
9047 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
9049 /* Update our PCI device dma_mask for full 64 bit mask */
9050 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9051 dev_dbg(&ha->pdev->dev,
9052 "Failed to set 64 bit PCI consistent mask; "
9054 dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9058 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9060 struct iscsi_cls_session *cls_sess;
9061 struct iscsi_session *sess;
9062 struct ddb_entry *ddb;
9063 int queue_depth = QL4_DEF_QDEPTH;
9065 cls_sess = starget_to_session(sdev->sdev_target);
9066 sess = cls_sess->dd_data;
9067 ddb = sess->dd_data;
9069 sdev->hostdata = ddb;
9071 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9072 queue_depth = ql4xmaxqdepth;
9074 scsi_change_queue_depth(sdev, queue_depth);
9079 * qla4xxx_del_from_active_array - returns an active srb
9080 * @ha: Pointer to host adapter structure.
9081 * @index: index into the active_array
9083 * This routine removes and returns the srb at the specified index
9085 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
9088 struct srb *srb = NULL;
9089 struct scsi_cmnd *cmd = NULL;
9091 cmd = scsi_host_find_tag(ha->host, index);
9095 srb = (struct srb *)CMD_SP(cmd);
9099 /* update counters */
9100 if (srb->flags & SRB_DMA_VALID) {
9101 ha->iocb_cnt -= srb->iocb_cnt;
9103 srb->cmd->host_scribble =
9104 (unsigned char *)(unsigned long) MAX_SRBS;
9110 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
9111 * @ha: Pointer to host adapter structure.
9112 * @cmd: Scsi Command to wait on.
9114 * This routine waits for the command to be returned by the Firmware
9115 * for some max time.
9117 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
9118 struct scsi_cmnd *cmd)
9122 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
9125 /* Dont wait on command if PCI error is being handled
9128 if (unlikely(pci_channel_offline(ha->pdev)) ||
9129 (test_bit(AF_EEH_BUSY, &ha->flags))) {
9130 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
9131 ha->host_no, __func__);
9136 /* Checking to see if its returned to OS */
9137 rp = (struct srb *) CMD_SP(cmd);
9144 } while (max_wait_time--);
9150 * qla4xxx_wait_for_hba_online - waits for HBA to come online
9151 * @ha: Pointer to host adapter structure
9153 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
9155 unsigned long wait_online;
9157 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
9158 while (time_before(jiffies, wait_online)) {
9170 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
9171 * @ha: pointer to HBA
9172 * @stgt: pointer to SCSI target
9173 * @sdev: pointer to SCSI device
9175 * This function waits for all outstanding commands to a lun to complete. It
9176 * returns 0 if all pending commands are returned and 1 otherwise.
9178 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
9179 struct scsi_target *stgt,
9180 struct scsi_device *sdev)
9184 struct scsi_cmnd *cmd;
9187 * Waiting for all commands for the designated target or dev
9188 * in the active array
9190 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
9191 cmd = scsi_host_find_tag(ha->host, cnt);
9192 if (cmd && stgt == scsi_target(cmd->device) &&
9193 (!sdev || sdev == cmd->device)) {
9194 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9204 * qla4xxx_eh_abort - callback for abort task.
9205 * @cmd: Pointer to Linux's SCSI command structure
9207 * This routine is called by the Linux OS to abort the specified
9210 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
9212 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9213 unsigned int id = cmd->device->id;
9214 uint64_t lun = cmd->device->lun;
9215 unsigned long flags;
9216 struct srb *srb = NULL;
9221 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
9222 ha->host_no, id, lun, cmd, cmd->cmnd[0]);
9224 rval = qla4xxx_isp_check_reg(ha);
9225 if (rval != QLA_SUCCESS) {
9226 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9230 spin_lock_irqsave(&ha->hardware_lock, flags);
9231 srb = (struct srb *) CMD_SP(cmd);
9233 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9234 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
9235 ha->host_no, id, lun);
9238 kref_get(&srb->srb_ref);
9239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
9241 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
9242 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
9243 ha->host_no, id, lun));
9246 DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
9247 ha->host_no, id, lun));
9251 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
9253 /* Wait for command to complete */
9255 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
9256 DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
9257 ha->host_no, id, lun));
9262 ql4_printk(KERN_INFO, ha,
9263 "scsi%ld:%d:%llu: Abort command - %s\n",
9264 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
9270 * qla4xxx_eh_device_reset - callback for target reset.
9271 * @cmd: Pointer to Linux's SCSI command structure
9273 * This routine is called by the Linux OS to reset all luns on the
9276 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
9278 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9279 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9280 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 rval = qla4xxx_isp_check_reg(ha);
9302 if (rval != QLA_SUCCESS) {
9303 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9307 /* FIXME: wait for hba to go online */
9308 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
9309 if (stat != QLA_SUCCESS) {
9310 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
9311 goto eh_dev_reset_done;
9314 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9316 ql4_printk(KERN_INFO, ha,
9317 "DEVICE RESET FAILED - waiting for "
9319 goto eh_dev_reset_done;
9323 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9324 MM_LUN_RESET) != QLA_SUCCESS)
9325 goto eh_dev_reset_done;
9327 ql4_printk(KERN_INFO, ha,
9328 "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
9329 ha->host_no, cmd->device->channel, cmd->device->id,
9340 * qla4xxx_eh_target_reset - callback for target reset.
9341 * @cmd: Pointer to Linux's SCSI command structure
9343 * This routine is called by the Linux OS to reset the target.
9345 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
9347 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
9348 struct ddb_entry *ddb_entry = cmd->device->hostdata;
9355 ret = iscsi_block_scsi_eh(cmd);
9359 starget_printk(KERN_INFO, scsi_target(cmd->device),
9360 "WARM TARGET RESET ISSUED.\n");
9362 DEBUG2(printk(KERN_INFO
9363 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
9364 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
9365 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
9366 ha->dpc_flags, cmd->result, cmd->allowed));
9368 rval = qla4xxx_isp_check_reg(ha);
9369 if (rval != QLA_SUCCESS) {
9370 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9374 stat = qla4xxx_reset_target(ha, ddb_entry);
9375 if (stat != QLA_SUCCESS) {
9376 starget_printk(KERN_INFO, scsi_target(cmd->device),
9377 "WARM TARGET RESET FAILED.\n");
9381 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
9383 starget_printk(KERN_INFO, scsi_target(cmd->device),
9384 "WARM TARGET DEVICE RESET FAILED - "
9385 "waiting for commands.\n");
9390 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
9391 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
9392 starget_printk(KERN_INFO, scsi_target(cmd->device),
9393 "WARM TARGET DEVICE RESET FAILED - "
9394 "marker iocb failed.\n");
9398 starget_printk(KERN_INFO, scsi_target(cmd->device),
9399 "WARM TARGET RESET SUCCEEDED.\n");
9404 * qla4xxx_is_eh_active - check if error handler is running
9405 * @shost: Pointer to SCSI Host struct
9407 * This routine finds that if reset host is called in EH
9408 * scenario or from some application like sg_reset
9410 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
9412 if (shost->shost_state == SHOST_RECOVERY)
9418 * qla4xxx_eh_host_reset - kernel callback
9419 * @cmd: Pointer to Linux's SCSI command structure
9421 * This routine is invoked by the Linux kernel to perform fatal error
9422 * recovery on the specified adapter.
9424 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
9426 int return_status = FAILED;
9427 struct scsi_qla_host *ha;
9430 ha = to_qla_host(cmd->device->host);
9432 rval = qla4xxx_isp_check_reg(ha);
9433 if (rval != QLA_SUCCESS) {
9434 ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
9438 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
9439 qla4_83xx_set_idc_dontreset(ha);
9442 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
9443 * protocol drivers, we should not set device_state to NEED_RESET
9445 if (ql4xdontresethba ||
9446 ((is_qla8032(ha) || is_qla8042(ha)) &&
9447 qla4_83xx_idc_dontreset(ha))) {
9448 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
9449 ha->host_no, __func__));
9451 /* Clear outstanding srb in queues */
9452 if (qla4xxx_is_eh_active(cmd->device->host))
9453 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
9458 ql4_printk(KERN_INFO, ha,
9459 "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
9460 cmd->device->channel, cmd->device->id, cmd->device->lun);
9462 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
9463 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
9464 "DEAD.\n", ha->host_no, cmd->device->channel,
9470 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9472 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
9474 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9477 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
9478 return_status = SUCCESS;
9480 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
9481 return_status == FAILED ? "FAILED" : "SUCCEEDED");
9483 return return_status;
9486 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
9488 uint32_t mbox_cmd[MBOX_REG_COUNT];
9489 uint32_t mbox_sts[MBOX_REG_COUNT];
9490 struct addr_ctrl_blk_def *acb = NULL;
9491 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
9492 int rval = QLA_SUCCESS;
9495 acb = dma_alloc_coherent(&ha->pdev->dev,
9496 sizeof(struct addr_ctrl_blk_def),
9497 &acb_dma, GFP_KERNEL);
9499 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
9502 goto exit_port_reset;
9505 memset(acb, 0, acb_len);
9507 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
9508 if (rval != QLA_SUCCESS) {
9513 rval = qla4xxx_disable_acb(ha);
9514 if (rval != QLA_SUCCESS) {
9519 wait_for_completion_timeout(&ha->disable_acb_comp,
9520 DISABLE_ACB_TOV * HZ);
9522 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
9523 if (rval != QLA_SUCCESS) {
9529 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
9532 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
9533 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
9537 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
9539 struct scsi_qla_host *ha = to_qla_host(shost);
9540 int rval = QLA_SUCCESS;
9543 if (ql4xdontresethba) {
9544 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
9547 goto exit_host_reset;
9550 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
9551 goto recover_adapter;
9553 switch (reset_type) {
9554 case SCSI_ADAPTER_RESET:
9555 set_bit(DPC_RESET_HA, &ha->dpc_flags);
9557 case SCSI_FIRMWARE_RESET:
9558 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9560 /* set firmware context reset */
9561 set_bit(DPC_RESET_HA_FW_CONTEXT,
9564 rval = qla4xxx_context_reset(ha);
9565 goto exit_host_reset;
9572 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
9573 * reset is issued by application */
9574 if ((is_qla8032(ha) || is_qla8042(ha)) &&
9575 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
9576 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
9577 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
9578 (idc_ctrl | GRACEFUL_RESET_BIT1));
9581 rval = qla4xxx_recover_adapter(ha);
9582 if (rval != QLA_SUCCESS) {
9583 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
9592 /* PCI AER driver recovers from all correctable errors w/o
9593 * driver intervention. For uncorrectable errors PCI AER
9594 * driver calls the following device driver's callbacks
9596 * - Fatal Errors - link_reset
9597 * - Non-Fatal Errors - driver's error_detected() which
9598 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
9600 * PCI AER driver calls
9601 * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled()
9602 * returns RECOVERED or NEED_RESET if fw_hung
9603 * NEED_RESET - driver's slot_reset()
9604 * DISCONNECT - device is dead & cannot recover
9605 * RECOVERED - driver's resume()
9607 static pci_ers_result_t
9608 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
9610 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9612 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
9613 ha->host_no, __func__, state);
9615 if (!is_aer_supported(ha))
9616 return PCI_ERS_RESULT_NONE;
9619 case pci_channel_io_normal:
9620 clear_bit(AF_EEH_BUSY, &ha->flags);
9621 return PCI_ERS_RESULT_CAN_RECOVER;
9622 case pci_channel_io_frozen:
9623 set_bit(AF_EEH_BUSY, &ha->flags);
9624 qla4xxx_mailbox_premature_completion(ha);
9625 qla4xxx_free_irqs(ha);
9626 pci_disable_device(pdev);
9627 /* Return back all IOs */
9628 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
9629 return PCI_ERS_RESULT_NEED_RESET;
9630 case pci_channel_io_perm_failure:
9631 set_bit(AF_EEH_BUSY, &ha->flags);
9632 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
9633 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
9634 return PCI_ERS_RESULT_DISCONNECT;
9636 return PCI_ERS_RESULT_NEED_RESET;
9640 * qla4xxx_pci_mmio_enabled() gets called if
9641 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
9642 * and read/write to the device still works.
9643 * @pdev: PCI device pointer
9645 static pci_ers_result_t
9646 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
9648 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9650 if (!is_aer_supported(ha))
9651 return PCI_ERS_RESULT_NONE;
9653 return PCI_ERS_RESULT_RECOVERED;
9656 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
9658 uint32_t rval = QLA_ERROR;
9660 struct pci_dev *other_pdev = NULL;
9662 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
9664 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9666 if (test_bit(AF_ONLINE, &ha->flags)) {
9667 clear_bit(AF_ONLINE, &ha->flags);
9668 clear_bit(AF_LINK_UP, &ha->flags);
9669 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
9670 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
9673 fn = PCI_FUNC(ha->pdev->devfn);
9674 if (is_qla8022(ha)) {
9677 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
9678 ha->host_no, __func__, fn);
9679 /* Get the pci device given the domain, bus,
9680 * slot/function number */
9681 other_pdev = pci_get_domain_bus_and_slot(
9682 pci_domain_nr(ha->pdev->bus),
9683 ha->pdev->bus->number,
9684 PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
9690 if (atomic_read(&other_pdev->enable_cnt)) {
9691 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
9692 ha->host_no, __func__, fn);
9693 pci_dev_put(other_pdev);
9696 pci_dev_put(other_pdev);
9699 /* this case is meant for ISP83xx/ISP84xx only */
9700 if (qla4_83xx_can_perform_reset(ha)) {
9701 /* reset fn as iSCSI is going to perform the reset */
9706 /* The first function on the card, the reset owner will
9707 * start & initialize the firmware. The other functions
9708 * on the card will reset the firmware context
9711 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
9712 "0x%x is the owner\n", ha->host_no, __func__,
9715 ha->isp_ops->idc_lock(ha);
9716 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9718 ha->isp_ops->idc_unlock(ha);
9720 rval = qla4_8xxx_update_idc_reg(ha);
9721 if (rval == QLA_ERROR) {
9722 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
9723 ha->host_no, __func__);
9724 ha->isp_ops->idc_lock(ha);
9725 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9726 QLA8XXX_DEV_FAILED);
9727 ha->isp_ops->idc_unlock(ha);
9728 goto exit_error_recovery;
9731 clear_bit(AF_FW_RECOVERY, &ha->flags);
9732 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9734 if (rval != QLA_SUCCESS) {
9735 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9736 "FAILED\n", ha->host_no, __func__);
9737 qla4xxx_free_irqs(ha);
9738 ha->isp_ops->idc_lock(ha);
9739 qla4_8xxx_clear_drv_active(ha);
9740 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9741 QLA8XXX_DEV_FAILED);
9742 ha->isp_ops->idc_unlock(ha);
9744 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
9745 "READY\n", ha->host_no, __func__);
9746 ha->isp_ops->idc_lock(ha);
9747 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
9749 /* Clear driver state register */
9750 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
9751 qla4_8xxx_set_drv_active(ha);
9752 ha->isp_ops->idc_unlock(ha);
9753 ha->isp_ops->enable_intrs(ha);
9756 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
9757 "the reset owner\n", ha->host_no, __func__,
9759 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
9760 QLA8XXX_DEV_READY)) {
9761 clear_bit(AF_FW_RECOVERY, &ha->flags);
9762 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
9763 if (rval == QLA_SUCCESS)
9764 ha->isp_ops->enable_intrs(ha);
9766 qla4xxx_free_irqs(ha);
9768 ha->isp_ops->idc_lock(ha);
9769 qla4_8xxx_set_drv_active(ha);
9770 ha->isp_ops->idc_unlock(ha);
9773 exit_error_recovery:
9774 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
9778 static pci_ers_result_t
9779 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
9781 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
9782 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9785 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
9786 ha->host_no, __func__);
9788 if (!is_aer_supported(ha))
9789 return PCI_ERS_RESULT_NONE;
9791 /* Restore the saved state of PCIe device -
9792 * BAR registers, PCI Config space, PCIX, MSI,
9795 pci_restore_state(pdev);
9797 /* pci_restore_state() clears the saved_state flag of the device
9798 * save restored state which resets saved_state flag
9800 pci_save_state(pdev);
9802 /* Initialize device or resume if in suspended state */
9803 rc = pci_enable_device(pdev);
9805 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
9806 "device after reset\n", ha->host_no, __func__);
9807 goto exit_slot_reset;
9810 ha->isp_ops->disable_intrs(ha);
9812 if (is_qla80XX(ha)) {
9813 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
9814 ret = PCI_ERS_RESULT_RECOVERED;
9815 goto exit_slot_reset;
9817 goto exit_slot_reset;
9821 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
9822 "device after reset\n", ha->host_no, __func__, ret);
9827 qla4xxx_pci_resume(struct pci_dev *pdev)
9829 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
9832 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
9833 ha->host_no, __func__);
9835 ret = qla4xxx_wait_for_hba_online(ha);
9836 if (ret != QLA_SUCCESS) {
9837 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
9838 "resume I/O from slot/link_reset\n", ha->host_no,
9842 clear_bit(AF_EEH_BUSY, &ha->flags);
9845 static const struct pci_error_handlers qla4xxx_err_handler = {
9846 .error_detected = qla4xxx_pci_error_detected,
9847 .mmio_enabled = qla4xxx_pci_mmio_enabled,
9848 .slot_reset = qla4xxx_pci_slot_reset,
9849 .resume = qla4xxx_pci_resume,
9852 static struct pci_device_id qla4xxx_pci_tbl[] = {
9854 .vendor = PCI_VENDOR_ID_QLOGIC,
9855 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
9856 .subvendor = PCI_ANY_ID,
9857 .subdevice = PCI_ANY_ID,
9860 .vendor = PCI_VENDOR_ID_QLOGIC,
9861 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
9862 .subvendor = PCI_ANY_ID,
9863 .subdevice = PCI_ANY_ID,
9866 .vendor = PCI_VENDOR_ID_QLOGIC,
9867 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
9868 .subvendor = PCI_ANY_ID,
9869 .subdevice = PCI_ANY_ID,
9872 .vendor = PCI_VENDOR_ID_QLOGIC,
9873 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
9874 .subvendor = PCI_ANY_ID,
9875 .subdevice = PCI_ANY_ID,
9878 .vendor = PCI_VENDOR_ID_QLOGIC,
9879 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
9880 .subvendor = PCI_ANY_ID,
9881 .subdevice = PCI_ANY_ID,
9884 .vendor = PCI_VENDOR_ID_QLOGIC,
9885 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
9886 .subvendor = PCI_ANY_ID,
9887 .subdevice = PCI_ANY_ID,
9891 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
9893 static struct pci_driver qla4xxx_pci_driver = {
9894 .name = DRIVER_NAME,
9895 .id_table = qla4xxx_pci_tbl,
9896 .probe = qla4xxx_probe_adapter,
9897 .remove = qla4xxx_remove_adapter,
9898 .err_handler = &qla4xxx_err_handler,
9901 static int __init qla4xxx_module_init(void)
9905 if (ql4xqfulltracking)
9906 qla4xxx_driver_template.track_queue_depth = 1;
9908 /* Allocate cache for SRBs. */
9909 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9910 SLAB_HWCACHE_ALIGN, NULL);
9911 if (srb_cachep == NULL) {
9913 "%s: Unable to allocate SRB cache..."
9914 "Failing load!\n", DRIVER_NAME);
9919 /* Derive version string. */
9920 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
9921 if (ql4xextended_error_logging)
9922 strcat(qla4xxx_version_str, "-debug");
9924 qla4xxx_scsi_transport =
9925 iscsi_register_transport(&qla4xxx_iscsi_transport);
9926 if (!qla4xxx_scsi_transport){
9928 goto release_srb_cache;
9931 ret = pci_register_driver(&qla4xxx_pci_driver);
9933 goto unregister_transport;
9935 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
9938 unregister_transport:
9939 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9941 kmem_cache_destroy(srb_cachep);
9946 static void __exit qla4xxx_module_exit(void)
9948 pci_unregister_driver(&qla4xxx_pci_driver);
9949 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
9950 kmem_cache_destroy(srb_cachep);
9953 module_init(qla4xxx_module_init);
9954 module_exit(qla4xxx_module_exit);
9956 MODULE_AUTHOR("QLogic Corporation");
9957 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
9958 MODULE_LICENSE("GPL");
9959 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);