2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2012 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 = 0x1F;
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 0x1F.\n"
91 "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F");
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);
154 * SCSI host template entry points
156 static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
157 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
158 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
159 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
160 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
161 static int qla4xxx_slave_alloc(struct scsi_device *device);
162 static int qla4xxx_slave_configure(struct scsi_device *device);
163 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
164 static umode_t qla4_attr_is_visible(int param_type, int param);
165 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
166 static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
170 * iSCSI Flash DDB sysfs entry points
173 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
174 struct iscsi_bus_flash_conn *fnode_conn,
175 void *data, int len);
177 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
178 int param, char *buf);
179 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
182 qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
183 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
184 struct iscsi_bus_flash_conn *fnode_conn);
185 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
186 struct iscsi_bus_flash_conn *fnode_conn);
187 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
189 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
190 QLA82XX_LEGACY_INTR_CONFIG;
192 static struct scsi_host_template qla4xxx_driver_template = {
193 .module = THIS_MODULE,
195 .proc_name = DRIVER_NAME,
196 .queuecommand = qla4xxx_queuecommand,
198 .eh_abort_handler = qla4xxx_eh_abort,
199 .eh_device_reset_handler = qla4xxx_eh_device_reset,
200 .eh_target_reset_handler = qla4xxx_eh_target_reset,
201 .eh_host_reset_handler = qla4xxx_eh_host_reset,
202 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
204 .slave_configure = qla4xxx_slave_configure,
205 .slave_alloc = qla4xxx_slave_alloc,
206 .slave_destroy = qla4xxx_slave_destroy,
207 .change_queue_depth = qla4xxx_change_queue_depth,
211 .use_clustering = ENABLE_CLUSTERING,
212 .sg_tablesize = SG_ALL,
214 .max_sectors = 0xFFFF,
215 .shost_attrs = qla4xxx_host_attrs,
216 .host_reset = qla4xxx_host_reset,
217 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
220 static struct iscsi_transport qla4xxx_iscsi_transport = {
221 .owner = THIS_MODULE,
223 .caps = CAP_TEXT_NEGO |
224 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
225 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
227 .attr_is_visible = qla4_attr_is_visible,
228 .create_session = qla4xxx_session_create,
229 .destroy_session = qla4xxx_session_destroy,
230 .start_conn = qla4xxx_conn_start,
231 .create_conn = qla4xxx_conn_create,
232 .bind_conn = qla4xxx_conn_bind,
233 .stop_conn = iscsi_conn_stop,
234 .destroy_conn = qla4xxx_conn_destroy,
235 .set_param = iscsi_set_param,
236 .get_conn_param = qla4xxx_conn_get_param,
237 .get_session_param = qla4xxx_session_get_param,
238 .get_ep_param = qla4xxx_get_ep_param,
239 .ep_connect = qla4xxx_ep_connect,
240 .ep_poll = qla4xxx_ep_poll,
241 .ep_disconnect = qla4xxx_ep_disconnect,
242 .get_stats = qla4xxx_conn_get_stats,
243 .send_pdu = iscsi_conn_send_pdu,
244 .xmit_task = qla4xxx_task_xmit,
245 .cleanup_task = qla4xxx_task_cleanup,
246 .alloc_pdu = qla4xxx_alloc_pdu,
248 .get_host_param = qla4xxx_host_get_param,
249 .set_iface_param = qla4xxx_iface_set_param,
250 .get_iface_param = qla4xxx_get_iface_param,
251 .bsg_request = qla4xxx_bsg_request,
252 .send_ping = qla4xxx_send_ping,
253 .get_chap = qla4xxx_get_chap_list,
254 .delete_chap = qla4xxx_delete_chap,
255 .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
256 .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
257 .new_flashnode = qla4xxx_sysfs_ddb_add,
258 .del_flashnode = qla4xxx_sysfs_ddb_delete,
259 .login_flashnode = qla4xxx_sysfs_ddb_login,
260 .logout_flashnode = qla4xxx_sysfs_ddb_logout,
261 .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
264 static struct scsi_transport_template *qla4xxx_scsi_transport;
266 static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
267 uint32_t iface_type, uint32_t payload_size,
268 uint32_t pid, struct sockaddr *dst_addr)
270 struct scsi_qla_host *ha = to_qla_host(shost);
271 struct sockaddr_in *addr;
272 struct sockaddr_in6 *addr6;
273 uint32_t options = 0;
274 uint8_t ipaddr[IPv6_ADDR_LEN];
277 memset(ipaddr, 0, IPv6_ADDR_LEN);
279 if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
280 (dst_addr->sa_family == AF_INET)) {
281 addr = (struct sockaddr_in *)dst_addr;
282 memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
283 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
284 "dest: %pI4\n", __func__,
285 &ha->ip_config.ip_address, ipaddr));
286 rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
290 } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
291 (dst_addr->sa_family == AF_INET6)) {
293 addr6 = (struct sockaddr_in6 *)dst_addr;
294 memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
296 options |= PING_IPV6_PROTOCOL_ENABLE;
298 /* Ping using LinkLocal address */
299 if ((iface_num == 0) || (iface_num == 1)) {
300 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
301 "src: %pI6 dest: %pI6\n", __func__,
302 &ha->ip_config.ipv6_link_local_addr,
304 options |= PING_IPV6_LINKLOCAL_ADDR;
305 rval = qla4xxx_ping_iocb(ha, options, payload_size,
308 ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
309 "not supported\n", __func__, iface_num);
315 * If ping using LinkLocal address fails, try ping using
318 if (rval != QLA_SUCCESS) {
319 options &= ~PING_IPV6_LINKLOCAL_ADDR;
320 if (iface_num == 0) {
321 options |= PING_IPV6_ADDR0;
322 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
324 "dest: %pI6\n", __func__,
325 &ha->ip_config.ipv6_addr0,
327 } else if (iface_num == 1) {
328 options |= PING_IPV6_ADDR1;
329 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
331 "dest: %pI6\n", __func__,
332 &ha->ip_config.ipv6_addr1,
335 rval = qla4xxx_ping_iocb(ha, options, payload_size,
346 static umode_t qla4_attr_is_visible(int param_type, int param)
348 switch (param_type) {
349 case ISCSI_HOST_PARAM:
351 case ISCSI_HOST_PARAM_HWADDRESS:
352 case ISCSI_HOST_PARAM_IPADDRESS:
353 case ISCSI_HOST_PARAM_INITIATOR_NAME:
354 case ISCSI_HOST_PARAM_PORT_STATE:
355 case ISCSI_HOST_PARAM_PORT_SPEED:
362 case ISCSI_PARAM_PERSISTENT_ADDRESS:
363 case ISCSI_PARAM_PERSISTENT_PORT:
364 case ISCSI_PARAM_CONN_ADDRESS:
365 case ISCSI_PARAM_CONN_PORT:
366 case ISCSI_PARAM_TARGET_NAME:
367 case ISCSI_PARAM_TPGT:
368 case ISCSI_PARAM_TARGET_ALIAS:
369 case ISCSI_PARAM_MAX_BURST:
370 case ISCSI_PARAM_MAX_R2T:
371 case ISCSI_PARAM_FIRST_BURST:
372 case ISCSI_PARAM_MAX_RECV_DLENGTH:
373 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
374 case ISCSI_PARAM_IFACE_NAME:
375 case ISCSI_PARAM_CHAP_OUT_IDX:
376 case ISCSI_PARAM_CHAP_IN_IDX:
377 case ISCSI_PARAM_USERNAME:
378 case ISCSI_PARAM_PASSWORD:
379 case ISCSI_PARAM_USERNAME_IN:
380 case ISCSI_PARAM_PASSWORD_IN:
381 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
382 case ISCSI_PARAM_DISCOVERY_SESS:
383 case ISCSI_PARAM_PORTAL_TYPE:
384 case ISCSI_PARAM_CHAP_AUTH_EN:
385 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
386 case ISCSI_PARAM_BIDI_CHAP_EN:
387 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
388 case ISCSI_PARAM_DEF_TIME2WAIT:
389 case ISCSI_PARAM_DEF_TIME2RETAIN:
390 case ISCSI_PARAM_HDRDGST_EN:
391 case ISCSI_PARAM_DATADGST_EN:
392 case ISCSI_PARAM_INITIAL_R2T_EN:
393 case ISCSI_PARAM_IMM_DATA_EN:
394 case ISCSI_PARAM_PDU_INORDER_EN:
395 case ISCSI_PARAM_DATASEQ_INORDER_EN:
396 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
397 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
398 case ISCSI_PARAM_TCP_WSF_DISABLE:
399 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
400 case ISCSI_PARAM_TCP_TIMER_SCALE:
401 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
402 case ISCSI_PARAM_TCP_XMIT_WSF:
403 case ISCSI_PARAM_TCP_RECV_WSF:
404 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
405 case ISCSI_PARAM_IPV4_TOS:
406 case ISCSI_PARAM_IPV6_TC:
407 case ISCSI_PARAM_IPV6_FLOW_LABEL:
408 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
409 case ISCSI_PARAM_KEEPALIVE_TMO:
410 case ISCSI_PARAM_LOCAL_PORT:
411 case ISCSI_PARAM_ISID:
412 case ISCSI_PARAM_TSID:
413 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
414 case ISCSI_PARAM_ERL:
415 case ISCSI_PARAM_STATSN:
416 case ISCSI_PARAM_EXP_STATSN:
417 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
418 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
423 case ISCSI_NET_PARAM:
425 case ISCSI_NET_PARAM_IPV4_ADDR:
426 case ISCSI_NET_PARAM_IPV4_SUBNET:
427 case ISCSI_NET_PARAM_IPV4_GW:
428 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
429 case ISCSI_NET_PARAM_IFACE_ENABLE:
430 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
431 case ISCSI_NET_PARAM_IPV6_ADDR:
432 case ISCSI_NET_PARAM_IPV6_ROUTER:
433 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
434 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
435 case ISCSI_NET_PARAM_VLAN_ID:
436 case ISCSI_NET_PARAM_VLAN_PRIORITY:
437 case ISCSI_NET_PARAM_VLAN_ENABLED:
438 case ISCSI_NET_PARAM_MTU:
439 case ISCSI_NET_PARAM_PORT:
444 case ISCSI_FLASHNODE_PARAM:
446 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
447 case ISCSI_FLASHNODE_PORTAL_TYPE:
448 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
449 case ISCSI_FLASHNODE_DISCOVERY_SESS:
450 case ISCSI_FLASHNODE_ENTRY_EN:
451 case ISCSI_FLASHNODE_HDR_DGST_EN:
452 case ISCSI_FLASHNODE_DATA_DGST_EN:
453 case ISCSI_FLASHNODE_IMM_DATA_EN:
454 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
455 case ISCSI_FLASHNODE_DATASEQ_INORDER:
456 case ISCSI_FLASHNODE_PDU_INORDER:
457 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
458 case ISCSI_FLASHNODE_SNACK_REQ_EN:
459 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
460 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
461 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
462 case ISCSI_FLASHNODE_ERL:
463 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
464 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
465 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
466 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
467 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
468 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
469 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
470 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
471 case ISCSI_FLASHNODE_FIRST_BURST:
472 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
473 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
474 case ISCSI_FLASHNODE_MAX_R2T:
475 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
476 case ISCSI_FLASHNODE_ISID:
477 case ISCSI_FLASHNODE_TSID:
478 case ISCSI_FLASHNODE_PORT:
479 case ISCSI_FLASHNODE_MAX_BURST:
480 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
481 case ISCSI_FLASHNODE_IPADDR:
482 case ISCSI_FLASHNODE_ALIAS:
483 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
484 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
485 case ISCSI_FLASHNODE_LOCAL_PORT:
486 case ISCSI_FLASHNODE_IPV4_TOS:
487 case ISCSI_FLASHNODE_IPV6_TC:
488 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
489 case ISCSI_FLASHNODE_NAME:
490 case ISCSI_FLASHNODE_TPGT:
491 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
492 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
493 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
494 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
495 case ISCSI_FLASHNODE_TCP_RECV_WSF:
496 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
497 case ISCSI_FLASHNODE_USERNAME:
498 case ISCSI_FLASHNODE_PASSWORD:
499 case ISCSI_FLASHNODE_STATSN:
500 case ISCSI_FLASHNODE_EXP_STATSN:
501 case ISCSI_FLASHNODE_IS_BOOT_TGT:
511 static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
512 uint32_t *num_entries, char *buf)
514 struct scsi_qla_host *ha = to_qla_host(shost);
515 struct ql4_chap_table *chap_table;
516 struct iscsi_chap_rec *chap_rec;
517 int max_chap_entries = 0;
518 int valid_chap_entries = 0;
522 max_chap_entries = (ha->hw.flt_chap_size / 2) /
523 sizeof(struct ql4_chap_table);
525 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
527 ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
528 __func__, *num_entries, chap_tbl_idx);
532 goto exit_get_chap_list;
535 chap_rec = (struct iscsi_chap_rec *) buf;
536 mutex_lock(&ha->chap_sem);
537 for (i = chap_tbl_idx; i < max_chap_entries; i++) {
538 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
539 if (chap_table->cookie !=
540 __constant_cpu_to_le16(CHAP_VALID_COOKIE))
543 chap_rec->chap_tbl_idx = i;
544 strncpy(chap_rec->username, chap_table->name,
545 ISCSI_CHAP_AUTH_NAME_MAX_LEN);
546 strncpy(chap_rec->password, chap_table->secret,
547 QL4_CHAP_MAX_SECRET_LEN);
548 chap_rec->password_length = chap_table->secret_len;
550 if (chap_table->flags & BIT_7) /* local */
551 chap_rec->chap_type = CHAP_TYPE_OUT;
553 if (chap_table->flags & BIT_6) /* peer */
554 chap_rec->chap_type = CHAP_TYPE_IN;
558 valid_chap_entries++;
559 if (valid_chap_entries == *num_entries)
564 mutex_unlock(&ha->chap_sem);
567 ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
568 __func__, valid_chap_entries);
569 *num_entries = valid_chap_entries;
573 static int __qla4xxx_is_chap_active(struct device *dev, void *data)
576 uint16_t *chap_tbl_idx = (uint16_t *) data;
577 struct iscsi_cls_session *cls_session;
578 struct iscsi_session *sess;
579 struct ddb_entry *ddb_entry;
581 if (!iscsi_is_session_dev(dev))
582 goto exit_is_chap_active;
584 cls_session = iscsi_dev_to_session(dev);
585 sess = cls_session->dd_data;
586 ddb_entry = sess->dd_data;
588 if (iscsi_session_chkready(cls_session))
589 goto exit_is_chap_active;
591 if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
598 static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
599 uint16_t chap_tbl_idx)
603 ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
604 __qla4xxx_is_chap_active);
609 static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
611 struct scsi_qla_host *ha = to_qla_host(shost);
612 struct ql4_chap_table *chap_table;
614 int max_chap_entries = 0;
619 chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
620 if (chap_table == NULL)
623 memset(chap_table, 0, sizeof(struct ql4_chap_table));
626 max_chap_entries = (ha->hw.flt_chap_size / 2) /
627 sizeof(struct ql4_chap_table);
629 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
631 if (chap_tbl_idx > max_chap_entries) {
633 goto exit_delete_chap;
636 /* Check if chap index is in use.
637 * If chap is in use don't delet chap entry */
638 ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
640 ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
641 "delete from flash\n", chap_tbl_idx);
643 goto exit_delete_chap;
646 chap_size = sizeof(struct ql4_chap_table);
648 offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
650 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
651 /* flt_chap_size is CHAP table size for both ports
652 * so divide it by 2 to calculate the offset for second port
654 if (ha->port_num == 1)
655 offset += (ha->hw.flt_chap_size / 2);
656 offset += (chap_tbl_idx * chap_size);
659 ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
660 if (ret != QLA_SUCCESS) {
662 goto exit_delete_chap;
665 DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
666 __le16_to_cpu(chap_table->cookie)));
668 if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
669 ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
670 goto exit_delete_chap;
673 chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
675 offset = FLASH_CHAP_OFFSET |
676 (chap_tbl_idx * sizeof(struct ql4_chap_table));
677 ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
678 FLASH_OPT_RMW_COMMIT);
679 if (ret == QLA_SUCCESS && ha->chap_list) {
680 mutex_lock(&ha->chap_sem);
681 /* Update ha chap_list cache */
682 memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
683 chap_table, sizeof(struct ql4_chap_table));
684 mutex_unlock(&ha->chap_sem);
686 if (ret != QLA_SUCCESS)
690 dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
694 static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
695 enum iscsi_param_type param_type,
696 int param, char *buf)
698 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
699 struct scsi_qla_host *ha = to_qla_host(shost);
702 if (param_type != ISCSI_NET_PARAM)
706 case ISCSI_NET_PARAM_IPV4_ADDR:
707 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
709 case ISCSI_NET_PARAM_IPV4_SUBNET:
710 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
712 case ISCSI_NET_PARAM_IPV4_GW:
713 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
715 case ISCSI_NET_PARAM_IFACE_ENABLE:
716 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
717 len = sprintf(buf, "%s\n",
718 (ha->ip_config.ipv4_options &
719 IPOPT_IPV4_PROTOCOL_ENABLE) ?
720 "enabled" : "disabled");
721 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
722 len = sprintf(buf, "%s\n",
723 (ha->ip_config.ipv6_options &
724 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
725 "enabled" : "disabled");
727 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
728 len = sprintf(buf, "%s\n",
729 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
732 case ISCSI_NET_PARAM_IPV6_ADDR:
733 if (iface->iface_num == 0)
734 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
735 if (iface->iface_num == 1)
736 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
738 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
739 len = sprintf(buf, "%pI6\n",
740 &ha->ip_config.ipv6_link_local_addr);
742 case ISCSI_NET_PARAM_IPV6_ROUTER:
743 len = sprintf(buf, "%pI6\n",
744 &ha->ip_config.ipv6_default_router_addr);
746 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
747 len = sprintf(buf, "%s\n",
748 (ha->ip_config.ipv6_addl_options &
749 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
752 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
753 len = sprintf(buf, "%s\n",
754 (ha->ip_config.ipv6_addl_options &
755 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
758 case ISCSI_NET_PARAM_VLAN_ID:
759 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
760 len = sprintf(buf, "%d\n",
761 (ha->ip_config.ipv4_vlan_tag &
763 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
764 len = sprintf(buf, "%d\n",
765 (ha->ip_config.ipv6_vlan_tag &
768 case ISCSI_NET_PARAM_VLAN_PRIORITY:
769 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
770 len = sprintf(buf, "%d\n",
771 ((ha->ip_config.ipv4_vlan_tag >> 13) &
772 ISCSI_MAX_VLAN_PRIORITY));
773 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
774 len = sprintf(buf, "%d\n",
775 ((ha->ip_config.ipv6_vlan_tag >> 13) &
776 ISCSI_MAX_VLAN_PRIORITY));
778 case ISCSI_NET_PARAM_VLAN_ENABLED:
779 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
780 len = sprintf(buf, "%s\n",
781 (ha->ip_config.ipv4_options &
782 IPOPT_VLAN_TAGGING_ENABLE) ?
783 "enabled" : "disabled");
784 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
785 len = sprintf(buf, "%s\n",
786 (ha->ip_config.ipv6_options &
787 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
788 "enabled" : "disabled");
790 case ISCSI_NET_PARAM_MTU:
791 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
793 case ISCSI_NET_PARAM_PORT:
794 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
795 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
796 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
797 len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
806 static struct iscsi_endpoint *
807 qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
811 struct iscsi_endpoint *ep;
812 struct qla_endpoint *qla_ep;
813 struct scsi_qla_host *ha;
814 struct sockaddr_in *addr;
815 struct sockaddr_in6 *addr6;
817 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
820 printk(KERN_ERR "%s: shost is NULL\n",
825 ha = iscsi_host_priv(shost);
827 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
833 qla_ep = ep->dd_data;
834 memset(qla_ep, 0, sizeof(struct qla_endpoint));
835 if (dst_addr->sa_family == AF_INET) {
836 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
837 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
838 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
839 (char *)&addr->sin_addr));
840 } else if (dst_addr->sa_family == AF_INET6) {
841 memcpy(&qla_ep->dst_addr, dst_addr,
842 sizeof(struct sockaddr_in6));
843 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
844 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
845 (char *)&addr6->sin6_addr));
848 qla_ep->host = shost;
853 static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
855 struct qla_endpoint *qla_ep;
856 struct scsi_qla_host *ha;
859 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
860 qla_ep = ep->dd_data;
861 ha = to_qla_host(qla_ep->host);
863 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
869 static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
871 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
872 iscsi_destroy_endpoint(ep);
875 static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
876 enum iscsi_param param,
879 struct qla_endpoint *qla_ep = ep->dd_data;
880 struct sockaddr *dst_addr;
882 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
885 case ISCSI_PARAM_CONN_PORT:
886 case ISCSI_PARAM_CONN_ADDRESS:
890 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
894 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
895 &qla_ep->dst_addr, param, buf);
901 static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
902 struct iscsi_stats *stats)
904 struct iscsi_session *sess;
905 struct iscsi_cls_session *cls_sess;
906 struct ddb_entry *ddb_entry;
907 struct scsi_qla_host *ha;
908 struct ql_iscsi_stats *ql_iscsi_stats;
911 dma_addr_t iscsi_stats_dma;
913 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
915 cls_sess = iscsi_conn_to_session(cls_conn);
916 sess = cls_sess->dd_data;
917 ddb_entry = sess->dd_data;
920 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
921 /* Allocate memory */
922 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
923 &iscsi_stats_dma, GFP_KERNEL);
924 if (!ql_iscsi_stats) {
925 ql4_printk(KERN_ERR, ha,
926 "Unable to allocate memory for iscsi stats\n");
930 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
932 if (ret != QLA_SUCCESS) {
933 ql4_printk(KERN_ERR, ha,
934 "Unable to retrieve iscsi stats\n");
939 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
940 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
942 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
943 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
944 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
945 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
946 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
947 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
948 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
949 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
951 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
952 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
953 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
954 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
955 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
956 stats->logoutrsp_pdus =
957 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
958 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
959 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
960 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
963 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
969 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
971 struct iscsi_cls_session *session;
972 struct iscsi_session *sess;
974 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
976 session = starget_to_session(scsi_target(sc->device));
977 sess = session->dd_data;
979 spin_lock_irqsave(&session->lock, flags);
980 if (session->state == ISCSI_SESSION_FAILED)
981 ret = BLK_EH_RESET_TIMER;
982 spin_unlock_irqrestore(&session->lock, flags);
987 static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
989 struct scsi_qla_host *ha = to_qla_host(shost);
990 struct iscsi_cls_host *ihost = shost->shost_data;
991 uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
993 qla4xxx_get_firmware_state(ha);
995 switch (ha->addl_fw_state & 0x0F00) {
996 case FW_ADDSTATE_LINK_SPEED_10MBPS:
997 speed = ISCSI_PORT_SPEED_10MBPS;
999 case FW_ADDSTATE_LINK_SPEED_100MBPS:
1000 speed = ISCSI_PORT_SPEED_100MBPS;
1002 case FW_ADDSTATE_LINK_SPEED_1GBPS:
1003 speed = ISCSI_PORT_SPEED_1GBPS;
1005 case FW_ADDSTATE_LINK_SPEED_10GBPS:
1006 speed = ISCSI_PORT_SPEED_10GBPS;
1009 ihost->port_speed = speed;
1012 static void qla4xxx_set_port_state(struct Scsi_Host *shost)
1014 struct scsi_qla_host *ha = to_qla_host(shost);
1015 struct iscsi_cls_host *ihost = shost->shost_data;
1016 uint32_t state = ISCSI_PORT_STATE_DOWN;
1018 if (test_bit(AF_LINK_UP, &ha->flags))
1019 state = ISCSI_PORT_STATE_UP;
1021 ihost->port_state = state;
1024 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
1025 enum iscsi_host_param param, char *buf)
1027 struct scsi_qla_host *ha = to_qla_host(shost);
1031 case ISCSI_HOST_PARAM_HWADDRESS:
1032 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
1034 case ISCSI_HOST_PARAM_IPADDRESS:
1035 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
1037 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1038 len = sprintf(buf, "%s\n", ha->name_string);
1040 case ISCSI_HOST_PARAM_PORT_STATE:
1041 qla4xxx_set_port_state(shost);
1042 len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
1044 case ISCSI_HOST_PARAM_PORT_SPEED:
1045 qla4xxx_set_port_speed(shost);
1046 len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
1055 static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
1061 ha->iface_ipv4 = iscsi_create_iface(ha->host,
1062 &qla4xxx_iscsi_transport,
1063 ISCSI_IFACE_TYPE_IPV4, 0, 0);
1064 if (!ha->iface_ipv4)
1065 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
1069 static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
1071 if (!ha->iface_ipv6_0)
1073 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
1074 &qla4xxx_iscsi_transport,
1075 ISCSI_IFACE_TYPE_IPV6, 0,
1077 if (!ha->iface_ipv6_0)
1078 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1081 if (!ha->iface_ipv6_1)
1083 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
1084 &qla4xxx_iscsi_transport,
1085 ISCSI_IFACE_TYPE_IPV6, 1,
1087 if (!ha->iface_ipv6_1)
1088 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
1092 static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
1094 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
1095 qla4xxx_create_ipv4_iface(ha);
1097 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
1098 qla4xxx_create_ipv6_iface(ha);
1101 static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
1103 if (ha->iface_ipv4) {
1104 iscsi_destroy_iface(ha->iface_ipv4);
1105 ha->iface_ipv4 = NULL;
1109 static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
1111 if (ha->iface_ipv6_0) {
1112 iscsi_destroy_iface(ha->iface_ipv6_0);
1113 ha->iface_ipv6_0 = NULL;
1115 if (ha->iface_ipv6_1) {
1116 iscsi_destroy_iface(ha->iface_ipv6_1);
1117 ha->iface_ipv6_1 = NULL;
1121 static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
1123 qla4xxx_destroy_ipv4_iface(ha);
1124 qla4xxx_destroy_ipv6_iface(ha);
1127 static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
1128 struct iscsi_iface_param_info *iface_param,
1129 struct addr_ctrl_blk *init_fw_cb)
1132 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
1133 * iface_num 1 is valid only for IPv6 Addr.
1135 switch (iface_param->param) {
1136 case ISCSI_NET_PARAM_IPV6_ADDR:
1137 if (iface_param->iface_num & 0x1)
1139 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
1140 sizeof(init_fw_cb->ipv6_addr1));
1143 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
1144 sizeof(init_fw_cb->ipv6_addr0));
1146 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
1147 if (iface_param->iface_num & 0x1)
1149 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
1150 sizeof(init_fw_cb->ipv6_if_id));
1152 case ISCSI_NET_PARAM_IPV6_ROUTER:
1153 if (iface_param->iface_num & 0x1)
1155 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
1156 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1158 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
1159 /* Autocfg applies to even interface */
1160 if (iface_param->iface_num & 0x1)
1163 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
1164 init_fw_cb->ipv6_addtl_opts &=
1166 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1167 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
1168 init_fw_cb->ipv6_addtl_opts |=
1170 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
1172 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
1175 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
1176 /* Autocfg applies to even interface */
1177 if (iface_param->iface_num & 0x1)
1180 if (iface_param->value[0] ==
1181 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
1182 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
1183 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1184 else if (iface_param->value[0] ==
1185 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
1186 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
1187 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
1189 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
1190 "IPv6 linklocal addr\n");
1192 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
1193 /* Autocfg applies to even interface */
1194 if (iface_param->iface_num & 0x1)
1197 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
1198 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
1199 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
1201 case ISCSI_NET_PARAM_IFACE_ENABLE:
1202 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
1203 init_fw_cb->ipv6_opts |=
1204 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
1205 qla4xxx_create_ipv6_iface(ha);
1207 init_fw_cb->ipv6_opts &=
1208 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
1210 qla4xxx_destroy_ipv6_iface(ha);
1213 case ISCSI_NET_PARAM_VLAN_TAG:
1214 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
1216 init_fw_cb->ipv6_vlan_tag =
1217 cpu_to_be16(*(uint16_t *)iface_param->value);
1219 case ISCSI_NET_PARAM_VLAN_ENABLED:
1220 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1221 init_fw_cb->ipv6_opts |=
1222 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
1224 init_fw_cb->ipv6_opts &=
1225 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
1227 case ISCSI_NET_PARAM_MTU:
1228 init_fw_cb->eth_mtu_size =
1229 cpu_to_le16(*(uint16_t *)iface_param->value);
1231 case ISCSI_NET_PARAM_PORT:
1232 /* Autocfg applies to even interface */
1233 if (iface_param->iface_num & 0x1)
1236 init_fw_cb->ipv6_port =
1237 cpu_to_le16(*(uint16_t *)iface_param->value);
1240 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
1241 iface_param->param);
1246 static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
1247 struct iscsi_iface_param_info *iface_param,
1248 struct addr_ctrl_blk *init_fw_cb)
1250 switch (iface_param->param) {
1251 case ISCSI_NET_PARAM_IPV4_ADDR:
1252 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
1253 sizeof(init_fw_cb->ipv4_addr));
1255 case ISCSI_NET_PARAM_IPV4_SUBNET:
1256 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
1257 sizeof(init_fw_cb->ipv4_subnet));
1259 case ISCSI_NET_PARAM_IPV4_GW:
1260 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
1261 sizeof(init_fw_cb->ipv4_gw_addr));
1263 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1264 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
1265 init_fw_cb->ipv4_tcp_opts |=
1266 cpu_to_le16(TCPOPT_DHCP_ENABLE);
1267 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
1268 init_fw_cb->ipv4_tcp_opts &=
1269 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
1271 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
1273 case ISCSI_NET_PARAM_IFACE_ENABLE:
1274 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
1275 init_fw_cb->ipv4_ip_opts |=
1276 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
1277 qla4xxx_create_ipv4_iface(ha);
1279 init_fw_cb->ipv4_ip_opts &=
1280 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
1282 qla4xxx_destroy_ipv4_iface(ha);
1285 case ISCSI_NET_PARAM_VLAN_TAG:
1286 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
1288 init_fw_cb->ipv4_vlan_tag =
1289 cpu_to_be16(*(uint16_t *)iface_param->value);
1291 case ISCSI_NET_PARAM_VLAN_ENABLED:
1292 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
1293 init_fw_cb->ipv4_ip_opts |=
1294 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
1296 init_fw_cb->ipv4_ip_opts &=
1297 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
1299 case ISCSI_NET_PARAM_MTU:
1300 init_fw_cb->eth_mtu_size =
1301 cpu_to_le16(*(uint16_t *)iface_param->value);
1303 case ISCSI_NET_PARAM_PORT:
1304 init_fw_cb->ipv4_port =
1305 cpu_to_le16(*(uint16_t *)iface_param->value);
1308 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
1309 iface_param->param);
1315 qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
1317 struct addr_ctrl_blk_def *acb;
1318 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
1319 memset(acb->reserved1, 0, sizeof(acb->reserved1));
1320 memset(acb->reserved2, 0, sizeof(acb->reserved2));
1321 memset(acb->reserved3, 0, sizeof(acb->reserved3));
1322 memset(acb->reserved4, 0, sizeof(acb->reserved4));
1323 memset(acb->reserved5, 0, sizeof(acb->reserved5));
1324 memset(acb->reserved6, 0, sizeof(acb->reserved6));
1325 memset(acb->reserved7, 0, sizeof(acb->reserved7));
1326 memset(acb->reserved8, 0, sizeof(acb->reserved8));
1327 memset(acb->reserved9, 0, sizeof(acb->reserved9));
1328 memset(acb->reserved10, 0, sizeof(acb->reserved10));
1329 memset(acb->reserved11, 0, sizeof(acb->reserved11));
1330 memset(acb->reserved12, 0, sizeof(acb->reserved12));
1331 memset(acb->reserved13, 0, sizeof(acb->reserved13));
1332 memset(acb->reserved14, 0, sizeof(acb->reserved14));
1333 memset(acb->reserved15, 0, sizeof(acb->reserved15));
1337 qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
1339 struct scsi_qla_host *ha = to_qla_host(shost);
1341 struct iscsi_iface_param_info *iface_param = NULL;
1342 struct addr_ctrl_blk *init_fw_cb = NULL;
1343 dma_addr_t init_fw_cb_dma;
1344 uint32_t mbox_cmd[MBOX_REG_COUNT];
1345 uint32_t mbox_sts[MBOX_REG_COUNT];
1347 struct nlattr *attr;
1349 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
1350 sizeof(struct addr_ctrl_blk),
1351 &init_fw_cb_dma, GFP_KERNEL);
1353 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
1358 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
1359 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
1360 memset(&mbox_sts, 0, sizeof(mbox_sts));
1362 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
1363 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
1365 goto exit_init_fw_cb;
1368 nla_for_each_attr(attr, data, len, rem) {
1369 iface_param = nla_data(attr);
1371 if (iface_param->param_type != ISCSI_NET_PARAM)
1374 switch (iface_param->iface_type) {
1375 case ISCSI_IFACE_TYPE_IPV4:
1376 switch (iface_param->iface_num) {
1378 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
1381 /* Cannot have more than one IPv4 interface */
1382 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
1384 iface_param->iface_num);
1388 case ISCSI_IFACE_TYPE_IPV6:
1389 switch (iface_param->iface_num) {
1392 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
1395 /* Cannot have more than two IPv6 interface */
1396 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
1398 iface_param->iface_num);
1403 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
1408 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
1410 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
1411 sizeof(struct addr_ctrl_blk),
1412 FLASH_OPT_RMW_COMMIT);
1413 if (rval != QLA_SUCCESS) {
1414 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
1417 goto exit_init_fw_cb;
1420 rval = qla4xxx_disable_acb(ha);
1421 if (rval != QLA_SUCCESS) {
1422 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
1425 goto exit_init_fw_cb;
1428 wait_for_completion_timeout(&ha->disable_acb_comp,
1429 DISABLE_ACB_TOV * HZ);
1431 qla4xxx_initcb_to_acb(init_fw_cb);
1433 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
1434 if (rval != QLA_SUCCESS) {
1435 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
1438 goto exit_init_fw_cb;
1441 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
1442 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
1446 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
1447 init_fw_cb, init_fw_cb_dma);
1452 static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
1453 enum iscsi_param param, char *buf)
1455 struct iscsi_session *sess = cls_sess->dd_data;
1456 struct ddb_entry *ddb_entry = sess->dd_data;
1457 struct scsi_qla_host *ha = ddb_entry->ha;
1462 case ISCSI_PARAM_CHAP_IN_IDX:
1463 rval = qla4xxx_get_chap_index(ha, sess->username_in,
1464 sess->password_in, BIDI_CHAP,
1467 len = sprintf(buf, "\n");
1469 len = sprintf(buf, "%hu\n", idx);
1471 case ISCSI_PARAM_CHAP_OUT_IDX:
1472 rval = qla4xxx_get_chap_index(ha, sess->username,
1473 sess->password, LOCAL_CHAP,
1476 len = sprintf(buf, "\n");
1478 len = sprintf(buf, "%hu\n", idx);
1481 return iscsi_session_get_param(cls_sess, param, buf);
1487 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
1488 enum iscsi_param param, char *buf)
1490 struct iscsi_conn *conn;
1491 struct qla_conn *qla_conn;
1492 struct sockaddr *dst_addr;
1495 conn = cls_conn->dd_data;
1496 qla_conn = conn->dd_data;
1497 dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
1500 case ISCSI_PARAM_CONN_PORT:
1501 case ISCSI_PARAM_CONN_ADDRESS:
1502 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
1503 dst_addr, param, buf);
1505 return iscsi_conn_get_param(cls_conn, param, buf);
1512 int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
1514 uint32_t mbx_sts = 0;
1515 uint16_t tmp_ddb_index;
1519 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
1521 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
1522 DEBUG2(ql4_printk(KERN_INFO, ha,
1523 "Free DDB index not available\n"));
1525 goto exit_get_ddb_index;
1528 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
1531 DEBUG2(ql4_printk(KERN_INFO, ha,
1532 "Found a free DDB index at %d\n", tmp_ddb_index));
1533 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
1534 if (ret == QLA_ERROR) {
1535 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1536 ql4_printk(KERN_INFO, ha,
1537 "DDB index = %d not available trying next\n",
1541 DEBUG2(ql4_printk(KERN_INFO, ha,
1542 "Free FW DDB not available\n"));
1545 *ddb_index = tmp_ddb_index;
1551 static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
1552 struct ddb_entry *ddb_entry,
1553 char *existing_ipaddr,
1556 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
1557 char formatted_ipaddr[DDB_IPADDR_LEN];
1558 int status = QLA_SUCCESS, ret = 0;
1560 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
1561 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1567 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
1569 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1575 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
1578 if (strcmp(existing_ipaddr, formatted_ipaddr))
1585 static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
1586 struct iscsi_cls_conn *cls_conn)
1588 int idx = 0, max_ddbs, rval;
1589 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1590 struct iscsi_session *sess, *existing_sess;
1591 struct iscsi_conn *conn, *existing_conn;
1592 struct ddb_entry *ddb_entry;
1594 sess = cls_sess->dd_data;
1595 conn = cls_conn->dd_data;
1597 if (sess->targetname == NULL ||
1598 conn->persistent_address == NULL ||
1599 conn->persistent_port == 0)
1602 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
1605 for (idx = 0; idx < max_ddbs; idx++) {
1606 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
1607 if (ddb_entry == NULL)
1610 if (ddb_entry->ddb_type != FLASH_DDB)
1613 existing_sess = ddb_entry->sess->dd_data;
1614 existing_conn = ddb_entry->conn->dd_data;
1616 if (existing_sess->targetname == NULL ||
1617 existing_conn->persistent_address == NULL ||
1618 existing_conn->persistent_port == 0)
1621 DEBUG2(ql4_printk(KERN_INFO, ha,
1622 "IQN = %s User IQN = %s\n",
1623 existing_sess->targetname,
1626 DEBUG2(ql4_printk(KERN_INFO, ha,
1627 "IP = %s User IP = %s\n",
1628 existing_conn->persistent_address,
1629 conn->persistent_address));
1631 DEBUG2(ql4_printk(KERN_INFO, ha,
1632 "Port = %d User Port = %d\n",
1633 existing_conn->persistent_port,
1634 conn->persistent_port));
1636 if (strcmp(existing_sess->targetname, sess->targetname))
1638 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
1639 existing_conn->persistent_address,
1640 conn->persistent_address);
1641 if (rval == QLA_ERROR)
1643 if (existing_conn->persistent_port != conn->persistent_port)
1648 if (idx == max_ddbs)
1651 DEBUG2(ql4_printk(KERN_INFO, ha,
1652 "Match found in fwdb sessions\n"));
1656 static struct iscsi_cls_session *
1657 qla4xxx_session_create(struct iscsi_endpoint *ep,
1658 uint16_t cmds_max, uint16_t qdepth,
1659 uint32_t initial_cmdsn)
1661 struct iscsi_cls_session *cls_sess;
1662 struct scsi_qla_host *ha;
1663 struct qla_endpoint *qla_ep;
1664 struct ddb_entry *ddb_entry;
1666 struct iscsi_session *sess;
1667 struct sockaddr *dst_addr;
1670 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1672 printk(KERN_ERR "qla4xxx: missing ep.\n");
1676 qla_ep = ep->dd_data;
1677 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1678 ha = to_qla_host(qla_ep->host);
1680 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
1681 if (ret == QLA_ERROR)
1684 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1685 cmds_max, sizeof(struct ddb_entry),
1686 sizeof(struct ql4_task_data),
1687 initial_cmdsn, ddb_index);
1691 sess = cls_sess->dd_data;
1692 ddb_entry = sess->dd_data;
1693 ddb_entry->fw_ddb_index = ddb_index;
1694 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1696 ddb_entry->sess = cls_sess;
1697 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
1698 ddb_entry->ddb_change = qla4xxx_ddb_change;
1699 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1700 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1706 static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1708 struct iscsi_session *sess;
1709 struct ddb_entry *ddb_entry;
1710 struct scsi_qla_host *ha;
1711 unsigned long flags, wtime;
1712 struct dev_db_entry *fw_ddb_entry = NULL;
1713 dma_addr_t fw_ddb_entry_dma;
1717 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1718 sess = cls_sess->dd_data;
1719 ddb_entry = sess->dd_data;
1722 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1723 &fw_ddb_entry_dma, GFP_KERNEL);
1724 if (!fw_ddb_entry) {
1725 ql4_printk(KERN_ERR, ha,
1726 "%s: Unable to allocate dma buffer\n", __func__);
1727 goto destroy_session;
1730 wtime = jiffies + (HZ * LOGOUT_TOV);
1732 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
1733 fw_ddb_entry, fw_ddb_entry_dma,
1734 NULL, NULL, &ddb_state, NULL,
1736 if (ret == QLA_ERROR)
1737 goto destroy_session;
1739 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
1740 (ddb_state == DDB_DS_SESSION_FAILED))
1741 goto destroy_session;
1743 schedule_timeout_uninterruptible(HZ);
1744 } while ((time_after(wtime, jiffies)));
1747 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1749 spin_lock_irqsave(&ha->hardware_lock, flags);
1750 qla4xxx_free_ddb(ha, ddb_entry);
1751 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1753 iscsi_session_teardown(cls_sess);
1756 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1757 fw_ddb_entry, fw_ddb_entry_dma);
1760 static struct iscsi_cls_conn *
1761 qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1763 struct iscsi_cls_conn *cls_conn;
1764 struct iscsi_session *sess;
1765 struct ddb_entry *ddb_entry;
1767 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1768 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1773 sess = cls_sess->dd_data;
1774 ddb_entry = sess->dd_data;
1775 ddb_entry->conn = cls_conn;
1780 static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1781 struct iscsi_cls_conn *cls_conn,
1782 uint64_t transport_fd, int is_leading)
1784 struct iscsi_conn *conn;
1785 struct qla_conn *qla_conn;
1786 struct iscsi_endpoint *ep;
1788 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1790 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1792 ep = iscsi_lookup_endpoint(transport_fd);
1793 conn = cls_conn->dd_data;
1794 qla_conn = conn->dd_data;
1795 qla_conn->qla_ep = ep->dd_data;
1799 static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1801 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1802 struct iscsi_session *sess;
1803 struct ddb_entry *ddb_entry;
1804 struct scsi_qla_host *ha;
1805 struct dev_db_entry *fw_ddb_entry = NULL;
1806 dma_addr_t fw_ddb_entry_dma;
1807 uint32_t mbx_sts = 0;
1809 int status = QLA_SUCCESS;
1811 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1812 sess = cls_sess->dd_data;
1813 ddb_entry = sess->dd_data;
1816 /* Check if we have matching FW DDB, if yes then do not
1817 * login to this target. This could cause target to logout previous
1820 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
1821 if (ret == QLA_SUCCESS) {
1822 ql4_printk(KERN_INFO, ha,
1823 "Session already exist in FW.\n");
1825 goto exit_conn_start;
1828 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1829 &fw_ddb_entry_dma, GFP_KERNEL);
1830 if (!fw_ddb_entry) {
1831 ql4_printk(KERN_ERR, ha,
1832 "%s: Unable to allocate dma buffer\n", __func__);
1834 goto exit_conn_start;
1837 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1839 /* If iscsid is stopped and started then no need to do
1840 * set param again since ddb state will be already
1841 * active and FW does not allow set ddb to an
1845 if (ddb_entry->fw_ddb_device_state ==
1846 DDB_DS_SESSION_ACTIVE) {
1847 ddb_entry->unblock_sess(ddb_entry->sess);
1848 goto exit_set_param;
1851 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1852 __func__, ddb_entry->fw_ddb_index);
1853 goto exit_conn_start;
1856 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1857 if (status == QLA_ERROR) {
1858 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1861 goto exit_conn_start;
1864 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
1865 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1867 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
1868 ddb_entry->fw_ddb_device_state));
1875 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1876 fw_ddb_entry, fw_ddb_entry_dma);
1880 static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1882 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1883 struct iscsi_session *sess;
1884 struct scsi_qla_host *ha;
1885 struct ddb_entry *ddb_entry;
1888 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1889 sess = cls_sess->dd_data;
1890 ddb_entry = sess->dd_data;
1893 options = LOGOUT_OPTION_CLOSE_SESSION;
1894 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1895 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1898 static void qla4xxx_task_work(struct work_struct *wdata)
1900 struct ql4_task_data *task_data;
1901 struct scsi_qla_host *ha;
1902 struct passthru_status *sts;
1903 struct iscsi_task *task;
1904 struct iscsi_hdr *hdr;
1907 struct iscsi_conn *conn;
1911 task_data = container_of(wdata, struct ql4_task_data, task_work);
1913 task = task_data->task;
1914 sts = &task_data->sts;
1915 hdr_len = sizeof(struct iscsi_hdr);
1917 DEBUG3(printk(KERN_INFO "Status returned\n"));
1918 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1919 DEBUG3(printk(KERN_INFO "Response buffer"));
1920 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1924 switch (sts->completionStatus) {
1925 case PASSTHRU_STATUS_COMPLETE:
1926 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1927 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1930 data = task_data->resp_buffer + hdr_len;
1931 data_len = task_data->resp_len - hdr_len;
1932 iscsi_complete_pdu(conn, hdr, data, data_len);
1935 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1936 sts->completionStatus);
1942 static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1944 struct ql4_task_data *task_data;
1945 struct iscsi_session *sess;
1946 struct ddb_entry *ddb_entry;
1947 struct scsi_qla_host *ha;
1950 sess = task->conn->session;
1951 ddb_entry = sess->dd_data;
1953 task_data = task->dd_data;
1954 memset(task_data, 0, sizeof(struct ql4_task_data));
1957 ql4_printk(KERN_INFO, ha,
1958 "%s: SCSI Commands not implemented\n", __func__);
1962 hdr_len = sizeof(struct iscsi_hdr);
1964 task_data->task = task;
1966 if (task->data_count) {
1967 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1972 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1973 __func__, task->conn->max_recv_dlength, hdr_len));
1975 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
1976 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1977 task_data->resp_len,
1978 &task_data->resp_dma,
1980 if (!task_data->resp_buffer)
1981 goto exit_alloc_pdu;
1983 task_data->req_len = task->data_count + hdr_len;
1984 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1986 &task_data->req_dma,
1988 if (!task_data->req_buffer)
1989 goto exit_alloc_pdu;
1991 task->hdr = task_data->req_buffer;
1993 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1998 if (task_data->resp_buffer)
1999 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
2000 task_data->resp_buffer, task_data->resp_dma);
2002 if (task_data->req_buffer)
2003 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
2004 task_data->req_buffer, task_data->req_dma);
2008 static void qla4xxx_task_cleanup(struct iscsi_task *task)
2010 struct ql4_task_data *task_data;
2011 struct iscsi_session *sess;
2012 struct ddb_entry *ddb_entry;
2013 struct scsi_qla_host *ha;
2016 hdr_len = sizeof(struct iscsi_hdr);
2017 sess = task->conn->session;
2018 ddb_entry = sess->dd_data;
2020 task_data = task->dd_data;
2022 if (task->data_count) {
2023 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
2024 task->data_count, PCI_DMA_TODEVICE);
2027 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
2028 __func__, task->conn->max_recv_dlength, hdr_len));
2030 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
2031 task_data->resp_buffer, task_data->resp_dma);
2032 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
2033 task_data->req_buffer, task_data->req_dma);
2037 static int qla4xxx_task_xmit(struct iscsi_task *task)
2039 struct scsi_cmnd *sc = task->sc;
2040 struct iscsi_session *sess = task->conn->session;
2041 struct ddb_entry *ddb_entry = sess->dd_data;
2042 struct scsi_qla_host *ha = ddb_entry->ha;
2045 return qla4xxx_send_passthru0(task);
2047 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
2052 static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
2053 struct iscsi_bus_flash_conn *conn,
2054 struct dev_db_entry *fw_ddb_entry)
2056 unsigned long options = 0;
2059 options = le16_to_cpu(fw_ddb_entry->options);
2060 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
2061 if (test_bit(OPT_IPV6_DEVICE, &options)) {
2062 rc = iscsi_switch_str_param(&sess->portal_type,
2067 rc = iscsi_switch_str_param(&sess->portal_type,
2073 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
2075 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
2076 sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
2078 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
2079 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
2080 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
2081 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
2082 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
2083 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
2085 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
2086 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
2087 conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
2088 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
2090 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
2091 sess->discovery_auth_optional =
2092 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
2093 if (test_bit(ISCSIOPT_ERL1, &options))
2095 if (test_bit(ISCSIOPT_ERL0, &options))
2098 options = le16_to_cpu(fw_ddb_entry->tcp_options);
2099 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
2100 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
2101 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
2102 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
2103 conn->tcp_timer_scale |= BIT_3;
2104 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
2105 conn->tcp_timer_scale |= BIT_2;
2106 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
2107 conn->tcp_timer_scale |= BIT_1;
2109 conn->tcp_timer_scale >>= 1;
2110 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
2112 options = le16_to_cpu(fw_ddb_entry->ip_options);
2113 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
2115 conn->max_recv_dlength = BYTE_UNITS *
2116 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
2117 conn->max_xmit_dlength = BYTE_UNITS *
2118 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
2119 sess->first_burst = BYTE_UNITS *
2120 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
2121 sess->max_burst = BYTE_UNITS *
2122 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
2123 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
2124 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2125 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
2126 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
2127 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
2128 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
2129 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
2130 conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
2131 conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
2132 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
2133 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
2134 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
2135 sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
2136 sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
2137 sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
2138 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
2140 sess->default_taskmgmt_timeout =
2141 le16_to_cpu(fw_ddb_entry->def_timeout);
2142 conn->port = le16_to_cpu(fw_ddb_entry->port);
2144 options = le16_to_cpu(fw_ddb_entry->options);
2145 conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
2146 if (!conn->ipaddress) {
2151 conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
2152 if (!conn->redirect_ipaddr) {
2157 memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
2158 memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
2160 if (test_bit(OPT_IPV6_DEVICE, &options)) {
2161 conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
2163 conn->link_local_ipv6_addr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
2164 if (!conn->link_local_ipv6_addr) {
2169 memcpy(conn->link_local_ipv6_addr,
2170 fw_ddb_entry->link_local_ipv6_addr, IPv6_ADDR_LEN);
2172 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
2175 if (fw_ddb_entry->iscsi_name[0]) {
2176 rc = iscsi_switch_str_param(&sess->targetname,
2177 (char *)fw_ddb_entry->iscsi_name);
2182 if (fw_ddb_entry->iscsi_alias[0]) {
2183 rc = iscsi_switch_str_param(&sess->targetalias,
2184 (char *)fw_ddb_entry->iscsi_alias);
2189 COPY_ISID(sess->isid, fw_ddb_entry->isid);
2195 static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
2196 struct iscsi_bus_flash_conn *conn,
2197 struct dev_db_entry *fw_ddb_entry)
2202 options = le16_to_cpu(fw_ddb_entry->options);
2203 SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
2204 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
2209 SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
2210 SET_BITVAL(sess->discovery_sess, options, BIT_4);
2211 SET_BITVAL(sess->entry_state, options, BIT_3);
2212 fw_ddb_entry->options = cpu_to_le16(options);
2214 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
2215 SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
2216 SET_BITVAL(conn->datadgst_en, options, BIT_12);
2217 SET_BITVAL(sess->imm_data_en, options, BIT_11);
2218 SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
2219 SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
2220 SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
2221 SET_BITVAL(sess->chap_auth_en, options, BIT_7);
2222 SET_BITVAL(conn->snack_req_en, options, BIT_6);
2223 SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
2224 SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
2225 SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
2226 SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
2227 SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
2228 fw_ddb_entry->iscsi_options = cpu_to_le16(options);
2230 options = le16_to_cpu(fw_ddb_entry->tcp_options);
2231 SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
2232 SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
2233 SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
2234 SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
2235 SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
2236 SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
2237 SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
2238 fw_ddb_entry->tcp_options = cpu_to_le16(options);
2240 options = le16_to_cpu(fw_ddb_entry->ip_options);
2241 SET_BITVAL(conn->fragment_disable, options, BIT_4);
2242 fw_ddb_entry->ip_options = cpu_to_le16(options);
2244 fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
2245 fw_ddb_entry->iscsi_max_rcv_data_seg_len =
2246 cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
2247 fw_ddb_entry->iscsi_max_snd_data_seg_len =
2248 cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
2249 fw_ddb_entry->iscsi_first_burst_len =
2250 cpu_to_le16(sess->first_burst / BYTE_UNITS);
2251 fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
2253 fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
2254 fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
2255 fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
2256 fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
2257 fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
2258 fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
2259 fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
2260 fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
2261 fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
2262 fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
2263 fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
2264 fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
2265 fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
2266 fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
2267 fw_ddb_entry->port = cpu_to_le16(conn->port);
2268 fw_ddb_entry->def_timeout =
2269 cpu_to_le16(sess->default_taskmgmt_timeout);
2271 if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
2272 fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
2274 fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
2276 if (conn->ipaddress)
2277 memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
2278 sizeof(fw_ddb_entry->ip_addr));
2280 if (conn->redirect_ipaddr)
2281 memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
2282 sizeof(fw_ddb_entry->tgt_addr));
2284 if (conn->link_local_ipv6_addr)
2285 memcpy(fw_ddb_entry->link_local_ipv6_addr,
2286 conn->link_local_ipv6_addr,
2287 sizeof(fw_ddb_entry->link_local_ipv6_addr));
2289 if (sess->targetname)
2290 memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
2291 sizeof(fw_ddb_entry->iscsi_name));
2293 if (sess->targetalias)
2294 memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
2295 sizeof(fw_ddb_entry->iscsi_alias));
2297 COPY_ISID(fw_ddb_entry->isid, sess->isid);
2302 static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
2303 struct iscsi_session *sess,
2304 struct dev_db_entry *fw_ddb_entry)
2306 unsigned long options = 0;
2308 uint16_t disc_parent;
2310 options = le16_to_cpu(fw_ddb_entry->options);
2311 conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
2312 sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
2314 sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
2316 options = le16_to_cpu(fw_ddb_entry->iscsi_options);
2317 conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
2318 conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
2319 sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
2320 sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
2321 sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
2323 sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
2324 sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
2325 sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
2327 sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
2328 sess->discovery_auth_optional =
2329 test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
2330 if (test_bit(ISCSIOPT_ERL1, &options))
2332 if (test_bit(ISCSIOPT_ERL0, &options))
2335 options = le16_to_cpu(fw_ddb_entry->tcp_options);
2336 conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
2337 conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
2338 conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
2339 if (test_bit(TCPOPT_TIMER_SCALE3, &options))
2340 conn->tcp_timer_scale |= BIT_3;
2341 if (test_bit(TCPOPT_TIMER_SCALE2, &options))
2342 conn->tcp_timer_scale |= BIT_2;
2343 if (test_bit(TCPOPT_TIMER_SCALE1, &options))
2344 conn->tcp_timer_scale |= BIT_1;
2346 conn->tcp_timer_scale >>= 1;
2347 conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
2349 options = le16_to_cpu(fw_ddb_entry->ip_options);
2350 conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
2352 conn->max_recv_dlength = BYTE_UNITS *
2353 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
2354 conn->max_xmit_dlength = BYTE_UNITS *
2355 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
2356 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
2357 sess->first_burst = BYTE_UNITS *
2358 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
2359 sess->max_burst = BYTE_UNITS *
2360 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
2361 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2362 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
2363 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
2364 conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
2365 conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
2366 conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
2367 conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
2368 conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
2369 conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
2370 conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
2371 conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
2372 sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
2373 COPY_ISID(sess->isid, fw_ddb_entry->isid);
2375 ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
2376 if (ddb_link < MAX_DDB_ENTRIES)
2377 sess->discovery_parent_idx = ddb_link;
2379 sess->discovery_parent_idx = DDB_NO_LINK;
2381 if (ddb_link == DDB_ISNS)
2382 disc_parent = ISCSI_DISC_PARENT_ISNS;
2383 else if (ddb_link == DDB_NO_LINK)
2384 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
2385 else if (ddb_link < MAX_DDB_ENTRIES)
2386 disc_parent = ISCSI_DISC_PARENT_SENDTGT;
2388 disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
2390 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
2391 iscsi_get_discovery_parent_name(disc_parent), 0);
2393 iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
2394 (char *)fw_ddb_entry->iscsi_alias, 0);
2397 static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
2398 struct dev_db_entry *fw_ddb_entry,
2399 struct iscsi_cls_session *cls_sess,
2400 struct iscsi_cls_conn *cls_conn)
2403 struct iscsi_session *sess;
2404 struct ddb_entry *ddb_entry;
2405 struct iscsi_conn *conn;
2406 char ip_addr[DDB_IPADDR_LEN];
2407 uint16_t options = 0;
2409 sess = cls_sess->dd_data;
2410 ddb_entry = sess->dd_data;
2411 conn = cls_conn->dd_data;
2413 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
2415 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
2417 sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
2418 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
2420 memset(ip_addr, 0, sizeof(ip_addr));
2421 options = le16_to_cpu(fw_ddb_entry->options);
2422 if (options & DDB_OPT_IPV6_DEVICE) {
2423 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
2425 memset(ip_addr, 0, sizeof(ip_addr));
2426 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
2428 iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
2429 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
2432 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
2433 (char *)ip_addr, buflen);
2434 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
2435 (char *)fw_ddb_entry->iscsi_name, buflen);
2436 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
2437 (char *)ha->name_string, buflen);
2440 void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
2441 struct ddb_entry *ddb_entry)
2443 struct iscsi_cls_session *cls_sess;
2444 struct iscsi_cls_conn *cls_conn;
2446 dma_addr_t fw_ddb_entry_dma;
2447 struct dev_db_entry *fw_ddb_entry;
2449 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2450 &fw_ddb_entry_dma, GFP_KERNEL);
2451 if (!fw_ddb_entry) {
2452 ql4_printk(KERN_ERR, ha,
2453 "%s: Unable to allocate dma buffer\n", __func__);
2454 goto exit_session_conn_fwddb_param;
2457 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
2458 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
2459 NULL, NULL, NULL) == QLA_ERROR) {
2460 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2461 "get_ddb_entry for fw_ddb_index %d\n",
2462 ha->host_no, __func__,
2463 ddb_entry->fw_ddb_index));
2464 goto exit_session_conn_fwddb_param;
2467 cls_sess = ddb_entry->sess;
2469 cls_conn = ddb_entry->conn;
2472 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
2474 exit_session_conn_fwddb_param:
2476 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2477 fw_ddb_entry, fw_ddb_entry_dma);
2480 void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
2481 struct ddb_entry *ddb_entry)
2483 struct iscsi_cls_session *cls_sess;
2484 struct iscsi_cls_conn *cls_conn;
2485 struct iscsi_session *sess;
2486 struct iscsi_conn *conn;
2488 dma_addr_t fw_ddb_entry_dma;
2489 struct dev_db_entry *fw_ddb_entry;
2491 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2492 &fw_ddb_entry_dma, GFP_KERNEL);
2493 if (!fw_ddb_entry) {
2494 ql4_printk(KERN_ERR, ha,
2495 "%s: Unable to allocate dma buffer\n", __func__);
2496 goto exit_session_conn_param;
2499 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
2500 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
2501 NULL, NULL, NULL) == QLA_ERROR) {
2502 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
2503 "get_ddb_entry for fw_ddb_index %d\n",
2504 ha->host_no, __func__,
2505 ddb_entry->fw_ddb_index));
2506 goto exit_session_conn_param;
2509 cls_sess = ddb_entry->sess;
2510 sess = cls_sess->dd_data;
2512 cls_conn = ddb_entry->conn;
2513 conn = cls_conn->dd_data;
2515 /* Update timers after login */
2516 ddb_entry->default_relogin_timeout =
2517 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
2518 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
2519 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
2520 ddb_entry->default_time2wait =
2521 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
2524 ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
2525 qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
2527 memcpy(sess->initiatorname, ha->name_string,
2528 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
2530 exit_session_conn_param:
2532 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
2533 fw_ddb_entry, fw_ddb_entry_dma);
2540 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
2541 unsigned long interval)
2543 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
2544 __func__, ha->host->host_no));
2545 init_timer(&ha->timer);
2546 ha->timer.expires = jiffies + interval * HZ;
2547 ha->timer.data = (unsigned long)ha;
2548 ha->timer.function = (void (*)(unsigned long))func;
2549 add_timer(&ha->timer);
2550 ha->timer_active = 1;
2553 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
2555 del_timer_sync(&ha->timer);
2556 ha->timer_active = 0;
2560 * qla4xxx_mark_device_missing - blocks the session
2561 * @cls_session: Pointer to the session to be blocked
2562 * @ddb_entry: Pointer to device database entry
2564 * This routine marks a device missing and close connection.
2566 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
2568 iscsi_block_session(cls_session);
2572 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
2573 * @ha: Pointer to host adapter structure.
2575 * This routine marks a device missing and resets the relogin retry count.
2577 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
2579 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
2582 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
2583 struct ddb_entry *ddb_entry,
2584 struct scsi_cmnd *cmd)
2588 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2592 kref_init(&srb->srb_ref);
2594 srb->ddb = ddb_entry;
2597 CMD_SP(cmd) = (void *)srb;
2602 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
2604 struct scsi_cmnd *cmd = srb->cmd;
2606 if (srb->flags & SRB_DMA_VALID) {
2607 scsi_dma_unmap(cmd);
2608 srb->flags &= ~SRB_DMA_VALID;
2613 void qla4xxx_srb_compl(struct kref *ref)
2615 struct srb *srb = container_of(ref, struct srb, srb_ref);
2616 struct scsi_cmnd *cmd = srb->cmd;
2617 struct scsi_qla_host *ha = srb->ha;
2619 qla4xxx_srb_free_dma(ha, srb);
2621 mempool_free(srb, ha->srb_mempool);
2623 cmd->scsi_done(cmd);
2627 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
2629 * @cmd: Pointer to Linux's SCSI command structure
2632 * This routine is invoked by Linux to send a SCSI command to the driver.
2633 * The mid-level driver tries to ensure that queuecommand never gets
2634 * invoked concurrently with itself or the interrupt handler (although
2635 * the interrupt handler may call this routine as part of request-
2636 * completion handling). Unfortunely, it sometimes calls the scheduler
2637 * in interrupt context which is a big NO! NO!.
2639 static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
2641 struct scsi_qla_host *ha = to_qla_host(host);
2642 struct ddb_entry *ddb_entry = cmd->device->hostdata;
2643 struct iscsi_cls_session *sess = ddb_entry->sess;
2647 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2648 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
2649 cmd->result = DID_NO_CONNECT << 16;
2651 cmd->result = DID_REQUEUE << 16;
2652 goto qc_fail_command;
2656 cmd->result = DID_IMM_RETRY << 16;
2657 goto qc_fail_command;
2660 rval = iscsi_session_chkready(sess);
2663 goto qc_fail_command;
2666 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2667 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2668 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2669 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2670 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
2671 !test_bit(AF_ONLINE, &ha->flags) ||
2672 !test_bit(AF_LINK_UP, &ha->flags) ||
2673 test_bit(AF_LOOPBACK, &ha->flags) ||
2674 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
2677 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
2681 rval = qla4xxx_send_command_to_isp(ha, srb);
2682 if (rval != QLA_SUCCESS)
2683 goto qc_host_busy_free_sp;
2687 qc_host_busy_free_sp:
2688 qla4xxx_srb_free_dma(ha, srb);
2689 mempool_free(srb, ha->srb_mempool);
2692 return SCSI_MLQUEUE_HOST_BUSY;
2695 cmd->scsi_done(cmd);
2701 * qla4xxx_mem_free - frees memory allocated to adapter
2702 * @ha: Pointer to host adapter structure.
2704 * Frees memory previously allocated by qla4xxx_mem_alloc
2706 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
2709 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
2718 ha->request_ring = NULL;
2719 ha->request_dma = 0;
2720 ha->response_ring = NULL;
2721 ha->response_dma = 0;
2722 ha->shadow_regs = NULL;
2723 ha->shadow_regs_dma = 0;
2725 ha->fw_dump_size = 0;
2727 /* Free srb pool. */
2728 if (ha->srb_mempool)
2729 mempool_destroy(ha->srb_mempool);
2731 ha->srb_mempool = NULL;
2733 if (ha->chap_dma_pool)
2734 dma_pool_destroy(ha->chap_dma_pool);
2737 vfree(ha->chap_list);
2738 ha->chap_list = NULL;
2740 if (ha->fw_ddb_dma_pool)
2741 dma_pool_destroy(ha->fw_ddb_dma_pool);
2743 /* release io space registers */
2744 if (is_qla8022(ha)) {
2747 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
2748 } else if (is_qla8032(ha) || is_qla8042(ha)) {
2751 (struct device_reg_83xx __iomem *)ha->nx_pcibase);
2752 } else if (ha->reg) {
2756 if (ha->reset_tmplt.buff)
2757 vfree(ha->reset_tmplt.buff);
2759 pci_release_regions(ha->pdev);
2763 * qla4xxx_mem_alloc - allocates memory for use by adapter.
2764 * @ha: Pointer to host adapter structure
2766 * Allocates DMA memory for request and response queues. Also allocates memory
2769 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
2771 unsigned long align;
2773 /* Allocate contiguous block of DMA memory for queues. */
2774 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
2775 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
2776 sizeof(struct shadow_regs) +
2778 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
2779 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
2780 &ha->queues_dma, GFP_KERNEL);
2781 if (ha->queues == NULL) {
2782 ql4_printk(KERN_WARNING, ha,
2783 "Memory Allocation failed - queues.\n");
2785 goto mem_alloc_error_exit;
2787 memset(ha->queues, 0, ha->queues_len);
2790 * As per RISC alignment requirements -- the bus-address must be a
2791 * multiple of the request-ring size (in bytes).
2794 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
2795 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
2796 (MEM_ALIGN_VALUE - 1));
2798 /* Update request and response queue pointers. */
2799 ha->request_dma = ha->queues_dma + align;
2800 ha->request_ring = (struct queue_entry *) (ha->queues + align);
2801 ha->response_dma = ha->queues_dma + align +
2802 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
2803 ha->response_ring = (struct queue_entry *) (ha->queues + align +
2804 (REQUEST_QUEUE_DEPTH *
2806 ha->shadow_regs_dma = ha->queues_dma + align +
2807 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
2808 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
2809 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
2810 (REQUEST_QUEUE_DEPTH *
2812 (RESPONSE_QUEUE_DEPTH *
2815 /* Allocate memory for srb pool. */
2816 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2817 mempool_free_slab, srb_cachep);
2818 if (ha->srb_mempool == NULL) {
2819 ql4_printk(KERN_WARNING, ha,
2820 "Memory Allocation failed - SRB Pool.\n");
2822 goto mem_alloc_error_exit;
2825 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
2826 CHAP_DMA_BLOCK_SIZE, 8, 0);
2828 if (ha->chap_dma_pool == NULL) {
2829 ql4_printk(KERN_WARNING, ha,
2830 "%s: chap_dma_pool allocation failed..\n", __func__);
2831 goto mem_alloc_error_exit;
2834 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
2835 DDB_DMA_BLOCK_SIZE, 8, 0);
2837 if (ha->fw_ddb_dma_pool == NULL) {
2838 ql4_printk(KERN_WARNING, ha,
2839 "%s: fw_ddb_dma_pool allocation failed..\n",
2841 goto mem_alloc_error_exit;
2846 mem_alloc_error_exit:
2847 qla4xxx_mem_free(ha);
2852 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
2853 * @ha: adapter block pointer.
2855 * Note: The caller should not hold the idc lock.
2857 static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
2859 uint32_t temp, temp_state, temp_val;
2860 int status = QLA_SUCCESS;
2862 temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
2864 temp_state = qla82xx_get_temp_state(temp);
2865 temp_val = qla82xx_get_temp_val(temp);
2867 if (temp_state == QLA82XX_TEMP_PANIC) {
2868 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
2869 " exceeds maximum allowed. Hardware has been shut"
2870 " down.\n", temp_val);
2872 } else if (temp_state == QLA82XX_TEMP_WARN) {
2873 if (ha->temperature == QLA82XX_TEMP_NORMAL)
2874 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
2875 " degrees C exceeds operating range."
2876 " Immediate action needed.\n", temp_val);
2878 if (ha->temperature == QLA82XX_TEMP_WARN)
2879 ql4_printk(KERN_INFO, ha, "Device temperature is"
2880 " now %d degrees C in normal range.\n",
2883 ha->temperature = temp_state;
2888 * qla4_8xxx_check_fw_alive - Check firmware health
2889 * @ha: Pointer to host adapter structure.
2891 * Context: Interrupt
2893 static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
2895 uint32_t fw_heartbeat_counter;
2896 int status = QLA_SUCCESS;
2898 fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
2899 QLA8XXX_PEG_ALIVE_COUNTER);
2900 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2901 if (fw_heartbeat_counter == 0xffffffff) {
2902 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
2903 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2904 ha->host_no, __func__));
2908 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
2909 ha->seconds_since_last_heartbeat++;
2910 /* FW not alive after 2 seconds */
2911 if (ha->seconds_since_last_heartbeat == 2) {
2912 ha->seconds_since_last_heartbeat = 0;
2913 qla4_8xxx_dump_peg_reg(ha);
2917 ha->seconds_since_last_heartbeat = 0;
2919 ha->fw_heartbeat_counter = fw_heartbeat_counter;
2923 static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
2925 uint32_t halt_status;
2926 int halt_status_unrecoverable = 0;
2928 halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
2930 if (is_qla8022(ha)) {
2931 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
2933 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2934 CRB_NIU_XG_PAUSE_CTL_P0 |
2935 CRB_NIU_XG_PAUSE_CTL_P1);
2937 if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
2938 ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
2940 if (halt_status & HALT_STATUS_UNRECOVERABLE)
2941 halt_status_unrecoverable = 1;
2942 } else if (is_qla8032(ha) || is_qla8042(ha)) {
2943 if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
2944 ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
2946 else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
2947 halt_status_unrecoverable = 1;
2951 * Since we cannot change dev_state in interrupt context,
2952 * set appropriate DPC flag then wakeup DPC
2954 if (halt_status_unrecoverable) {
2955 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2957 ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
2959 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2961 qla4xxx_mailbox_premature_completion(ha);
2962 qla4xxx_wake_dpc(ha);
2966 * qla4_8xxx_watchdog - Poll dev state
2967 * @ha: Pointer to host adapter structure.
2969 * Context: Interrupt
2971 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
2976 /* don't poll if reset is going on */
2977 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2978 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2979 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
2980 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
2982 if (qla4_8xxx_check_temp(ha)) {
2983 if (is_qla8022(ha)) {
2984 ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
2985 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2986 CRB_NIU_XG_PAUSE_CTL_P0 |
2987 CRB_NIU_XG_PAUSE_CTL_P1);
2989 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2990 qla4xxx_wake_dpc(ha);
2991 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
2992 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2994 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
2997 if (is_qla8032(ha) || is_qla8042(ha)) {
2998 idc_ctrl = qla4_83xx_rd_reg(ha,
2999 QLA83XX_IDC_DRV_CTRL);
3000 if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
3001 ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
3003 qla4xxx_mailbox_premature_completion(
3008 if ((is_qla8032(ha) || is_qla8042(ha)) ||
3009 (is_qla8022(ha) && !ql4xdontresethba)) {
3010 set_bit(DPC_RESET_HA, &ha->dpc_flags);
3011 qla4xxx_wake_dpc(ha);
3013 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
3014 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
3015 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
3017 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
3018 qla4xxx_wake_dpc(ha);
3020 /* Check firmware health */
3021 if (qla4_8xxx_check_fw_alive(ha))
3022 qla4_8xxx_process_fw_error(ha);
3027 static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
3029 struct iscsi_session *sess;
3030 struct ddb_entry *ddb_entry;
3031 struct scsi_qla_host *ha;
3033 sess = cls_sess->dd_data;
3034 ddb_entry = sess->dd_data;
3037 if (!(ddb_entry->ddb_type == FLASH_DDB))
3040 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
3041 !iscsi_is_session_online(cls_sess)) {
3042 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
3044 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
3046 atomic_set(&ddb_entry->retry_relogin_timer,
3048 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
3049 set_bit(DF_RELOGIN, &ddb_entry->flags);
3050 DEBUG2(ql4_printk(KERN_INFO, ha,
3051 "%s: index [%d] login device\n",
3052 __func__, ddb_entry->fw_ddb_index));
3054 atomic_dec(&ddb_entry->retry_relogin_timer);
3058 /* Wait for relogin to timeout */
3059 if (atomic_read(&ddb_entry->relogin_timer) &&
3060 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
3062 * If the relogin times out and the device is
3063 * still NOT ONLINE then try and relogin again.
3065 if (!iscsi_is_session_online(cls_sess)) {
3066 /* Reset retry relogin timer */
3067 atomic_inc(&ddb_entry->relogin_retry_count);
3068 DEBUG2(ql4_printk(KERN_INFO, ha,
3069 "%s: index[%d] relogin timed out-retrying"
3070 " relogin (%d), retry (%d)\n", __func__,
3071 ddb_entry->fw_ddb_index,
3072 atomic_read(&ddb_entry->relogin_retry_count),
3073 ddb_entry->default_time2wait + 4));
3074 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
3075 atomic_set(&ddb_entry->retry_relogin_timer,
3076 ddb_entry->default_time2wait + 4);
3082 * qla4xxx_timer - checks every second for work to do.
3083 * @ha: Pointer to host adapter structure.
3085 static void qla4xxx_timer(struct scsi_qla_host *ha)
3090 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
3092 /* If we are in the middle of AER/EEH processing
3093 * skip any processing and reschedule the timer
3095 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
3096 mod_timer(&ha->timer, jiffies + HZ);
3100 /* Hardware read to trigger an EEH error during mailbox waits. */
3101 if (!pci_channel_offline(ha->pdev))
3102 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
3105 qla4_8xxx_watchdog(ha);
3107 if (is_qla40XX(ha)) {
3108 /* Check for heartbeat interval. */
3109 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
3110 ha->heartbeat_interval != 0) {
3111 ha->seconds_since_last_heartbeat++;
3112 if (ha->seconds_since_last_heartbeat >
3113 ha->heartbeat_interval + 2)
3114 set_bit(DPC_RESET_HA, &ha->dpc_flags);
3118 /* Process any deferred work. */
3119 if (!list_empty(&ha->work_list))
3122 /* Wakeup the dpc routine for this adapter, if needed. */
3124 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
3125 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
3126 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
3127 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
3128 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
3129 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
3130 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
3131 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
3132 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
3133 test_bit(DPC_AEN, &ha->dpc_flags)) {
3134 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
3135 " - dpc flags = 0x%lx\n",
3136 ha->host_no, __func__, ha->dpc_flags));
3137 qla4xxx_wake_dpc(ha);
3140 /* Reschedule timer thread to call us back in one second */
3141 mod_timer(&ha->timer, jiffies + HZ);
3143 DEBUG2(ha->seconds_since_last_intr++);
3147 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
3148 * @ha: Pointer to host adapter structure.
3150 * This routine stalls the driver until all outstanding commands are returned.
3151 * Caller must release the Hardware Lock prior to calling this routine.
3153 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
3156 unsigned long flags;
3157 struct scsi_cmnd *cmd;
3159 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
3161 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
3162 "complete\n", WAIT_CMD_TOV));
3164 while (!time_after_eq(jiffies, wtime)) {
3165 spin_lock_irqsave(&ha->hardware_lock, flags);
3166 /* Find a command that hasn't completed. */
3167 for (index = 0; index < ha->host->can_queue; index++) {
3168 cmd = scsi_host_find_tag(ha->host, index);
3170 * We cannot just check if the index is valid,
3171 * becase if we are run from the scsi eh, then
3172 * the scsi/block layer is going to prevent
3173 * the tag from being released.
3175 if (cmd != NULL && CMD_SP(cmd))
3178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3180 /* If No Commands are pending, wait is complete */
3181 if (index == ha->host->can_queue)
3186 /* If we timed out on waiting for commands to come back
3191 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
3193 uint32_t ctrl_status;
3194 unsigned long flags = 0;
3196 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
3198 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
3201 spin_lock_irqsave(&ha->hardware_lock, flags);
3204 * If the SCSI Reset Interrupt bit is set, clear it.
3205 * Otherwise, the Soft Reset won't work.
3207 ctrl_status = readw(&ha->reg->ctrl_status);
3208 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
3209 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
3211 /* Issue Soft Reset */
3212 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
3213 readl(&ha->reg->ctrl_status);
3215 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3220 * qla4xxx_soft_reset - performs soft reset.
3221 * @ha: Pointer to host adapter structure.
3223 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
3225 uint32_t max_wait_time;
3226 unsigned long flags = 0;
3228 uint32_t ctrl_status;
3230 status = qla4xxx_hw_reset(ha);
3231 if (status != QLA_SUCCESS)
3235 /* Wait until the Network Reset Intr bit is cleared */
3236 max_wait_time = RESET_INTR_TOV;
3238 spin_lock_irqsave(&ha->hardware_lock, flags);
3239 ctrl_status = readw(&ha->reg->ctrl_status);
3240 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3242 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
3246 } while ((--max_wait_time));
3248 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
3249 DEBUG2(printk(KERN_WARNING
3250 "scsi%ld: Network Reset Intr not cleared by "
3251 "Network function, clearing it now!\n",
3253 spin_lock_irqsave(&ha->hardware_lock, flags);
3254 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
3255 readl(&ha->reg->ctrl_status);
3256 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3259 /* Wait until the firmware tells us the Soft Reset is done */
3260 max_wait_time = SOFT_RESET_TOV;
3262 spin_lock_irqsave(&ha->hardware_lock, flags);
3263 ctrl_status = readw(&ha->reg->ctrl_status);
3264 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3266 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
3267 status = QLA_SUCCESS;
3272 } while ((--max_wait_time));
3275 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
3276 * after the soft reset has taken place.
3278 spin_lock_irqsave(&ha->hardware_lock, flags);
3279 ctrl_status = readw(&ha->reg->ctrl_status);
3280 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
3281 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
3282 readl(&ha->reg->ctrl_status);
3284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3286 /* If soft reset fails then most probably the bios on other
3287 * function is also enabled.
3288 * Since the initialization is sequential the other fn
3289 * wont be able to acknowledge the soft reset.
3290 * Issue a force soft reset to workaround this scenario.
3292 if (max_wait_time == 0) {
3293 /* Issue Force Soft Reset */
3294 spin_lock_irqsave(&ha->hardware_lock, flags);
3295 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
3296 readl(&ha->reg->ctrl_status);
3297 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3298 /* Wait until the firmware tells us the Soft Reset is done */
3299 max_wait_time = SOFT_RESET_TOV;
3301 spin_lock_irqsave(&ha->hardware_lock, flags);
3302 ctrl_status = readw(&ha->reg->ctrl_status);
3303 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3305 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
3306 status = QLA_SUCCESS;
3311 } while ((--max_wait_time));
3318 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
3319 * @ha: Pointer to host adapter structure.
3320 * @res: returned scsi status
3322 * This routine is called just prior to a HARD RESET to return all
3323 * outstanding commands back to the Operating System.
3324 * Caller should make sure that the following locks are released
3325 * before this calling routine: Hardware lock, and io_request_lock.
3327 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
3331 unsigned long flags;
3333 spin_lock_irqsave(&ha->hardware_lock, flags);
3334 for (i = 0; i < ha->host->can_queue; i++) {
3335 srb = qla4xxx_del_from_active_array(ha, i);
3337 srb->cmd->result = res;
3338 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
3341 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3344 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
3346 clear_bit(AF_ONLINE, &ha->flags);
3348 /* Disable the board */
3349 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
3351 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3352 qla4xxx_mark_all_devices_missing(ha);
3353 clear_bit(AF_INIT_DONE, &ha->flags);
3356 static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
3358 struct iscsi_session *sess;
3359 struct ddb_entry *ddb_entry;
3361 sess = cls_session->dd_data;
3362 ddb_entry = sess->dd_data;
3363 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
3365 if (ddb_entry->ddb_type == FLASH_DDB)
3366 iscsi_block_session(ddb_entry->sess);
3368 iscsi_session_failure(cls_session->dd_data,
3369 ISCSI_ERR_CONN_FAILED);
3373 * qla4xxx_recover_adapter - recovers adapter after a fatal error
3374 * @ha: Pointer to host adapter structure.
3376 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
3378 int status = QLA_ERROR;
3379 uint8_t reset_chip = 0;
3383 /* Stall incoming I/O until we are done */
3384 scsi_block_requests(ha->host);
3385 clear_bit(AF_ONLINE, &ha->flags);
3386 clear_bit(AF_LINK_UP, &ha->flags);
3388 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
3390 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3392 if ((is_qla8032(ha) || is_qla8042(ha)) &&
3393 !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
3394 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
3396 /* disable pause frame for ISP83xx */
3397 qla4_83xx_disable_pause(ha);
3400 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
3402 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
3405 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
3406 * do not reset adapter, jump to initialize_adapter */
3407 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
3408 status = QLA_SUCCESS;
3409 goto recover_ha_init_adapter;
3412 /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
3413 * from eh_host_reset or ioctl module */
3414 if (is_qla80XX(ha) && !reset_chip &&
3415 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
3417 DEBUG2(ql4_printk(KERN_INFO, ha,
3418 "scsi%ld: %s - Performing stop_firmware...\n",
3419 ha->host_no, __func__));
3420 status = ha->isp_ops->reset_firmware(ha);
3421 if (status == QLA_SUCCESS) {
3422 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
3423 qla4xxx_cmd_wait(ha);
3425 ha->isp_ops->disable_intrs(ha);
3426 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3427 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3429 /* If the stop_firmware fails then
3430 * reset the entire chip */
3432 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3433 set_bit(DPC_RESET_HA, &ha->dpc_flags);
3437 /* Issue full chip reset if recovering from a catastrophic error,
3438 * or if stop_firmware fails for ISP-8xxx.
3439 * This is the default case for ISP-4xxx */
3440 if (is_qla40XX(ha) || reset_chip) {
3444 /* Check if 8XXX firmware is alive or not
3445 * We may have arrived here from NEED_RESET
3447 if (test_bit(AF_FW_RECOVERY, &ha->flags))
3450 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
3451 while (time_before(jiffies, wait)) {
3452 if (qla4_8xxx_check_fw_alive(ha)) {
3453 qla4xxx_mailbox_premature_completion(ha);
3457 set_current_state(TASK_UNINTERRUPTIBLE);
3458 schedule_timeout(HZ);
3461 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
3462 qla4xxx_cmd_wait(ha);
3464 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3465 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3466 DEBUG2(ql4_printk(KERN_INFO, ha,
3467 "scsi%ld: %s - Performing chip reset..\n",
3468 ha->host_no, __func__));
3469 status = ha->isp_ops->reset_chip(ha);
3472 /* Flush any pending ddb changed AENs */
3473 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3475 recover_ha_init_adapter:
3476 /* Upon successful firmware/chip reset, re-initialize the adapter */
3477 if (status == QLA_SUCCESS) {
3478 /* For ISP-4xxx, force function 1 to always initialize
3479 * before function 3 to prevent both funcions from
3480 * stepping on top of the other */
3481 if (is_qla40XX(ha) && (ha->mac_index == 3))
3484 /* NOTE: AF_ONLINE flag set upon successful completion of
3485 * qla4xxx_initialize_adapter */
3486 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
3489 /* Retry failed adapter initialization, if necessary
3490 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
3491 * case to prevent ping-pong resets between functions */
3492 if (!test_bit(AF_ONLINE, &ha->flags) &&
3493 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
3494 /* Adapter initialization failed, see if we can retry
3496 * Since we don't want to block the DPC for too long
3497 * with multiple resets in the same thread,
3498 * utilize DPC to retry */
3499 if (is_qla80XX(ha)) {
3500 ha->isp_ops->idc_lock(ha);
3501 dev_state = qla4_8xxx_rd_direct(ha,
3502 QLA8XXX_CRB_DEV_STATE);
3503 ha->isp_ops->idc_unlock(ha);
3504 if (dev_state == QLA8XXX_DEV_FAILED) {
3505 ql4_printk(KERN_INFO, ha, "%s: don't retry "
3506 "recover adapter. H/W is in Failed "
3507 "state\n", __func__);
3508 qla4xxx_dead_adapter_cleanup(ha);
3509 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3510 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3511 clear_bit(DPC_RESET_HA_FW_CONTEXT,
3519 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
3520 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
3521 DEBUG2(printk("scsi%ld: recover adapter - retrying "
3522 "(%d) more times\n", ha->host_no,
3523 ha->retry_reset_ha_cnt));
3524 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3527 if (ha->retry_reset_ha_cnt > 0) {
3528 /* Schedule another Reset HA--DPC will retry */
3529 ha->retry_reset_ha_cnt--;
3530 DEBUG2(printk("scsi%ld: recover adapter - "
3531 "retry remaining %d\n",
3533 ha->retry_reset_ha_cnt));
3537 if (ha->retry_reset_ha_cnt == 0) {
3538 /* Recover adapter retries have been exhausted.
3540 DEBUG2(printk("scsi%ld: recover adapter "
3541 "failed - board disabled\n",
3543 qla4xxx_dead_adapter_cleanup(ha);
3544 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3545 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3546 clear_bit(DPC_RESET_HA_FW_CONTEXT,
3552 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3553 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3554 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
3558 ha->adapter_error_count++;
3560 if (test_bit(AF_ONLINE, &ha->flags))
3561 ha->isp_ops->enable_intrs(ha);
3563 scsi_unblock_requests(ha->host);
3565 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3566 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
3567 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
3572 static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
3574 struct iscsi_session *sess;
3575 struct ddb_entry *ddb_entry;
3576 struct scsi_qla_host *ha;
3578 sess = cls_session->dd_data;
3579 ddb_entry = sess->dd_data;
3581 if (!iscsi_is_session_online(cls_session)) {
3582 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
3583 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3584 " unblock session\n", ha->host_no, __func__,
3585 ddb_entry->fw_ddb_index);
3586 iscsi_unblock_session(ddb_entry->sess);
3588 /* Trigger relogin */
3589 if (ddb_entry->ddb_type == FLASH_DDB) {
3590 if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
3591 test_bit(DF_DISABLE_RELOGIN,
3592 &ddb_entry->flags)))
3593 qla4xxx_arm_relogin_timer(ddb_entry);
3595 iscsi_session_failure(cls_session->dd_data,
3596 ISCSI_ERR_CONN_FAILED);
3601 int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
3603 struct iscsi_session *sess;
3604 struct ddb_entry *ddb_entry;
3605 struct scsi_qla_host *ha;
3607 sess = cls_session->dd_data;
3608 ddb_entry = sess->dd_data;
3610 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3611 " unblock session\n", ha->host_no, __func__,
3612 ddb_entry->fw_ddb_index);
3614 iscsi_unblock_session(ddb_entry->sess);
3616 /* Start scan target */
3617 if (test_bit(AF_ONLINE, &ha->flags)) {
3618 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3619 " start scan\n", ha->host_no, __func__,
3620 ddb_entry->fw_ddb_index);
3621 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
3626 int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
3628 struct iscsi_session *sess;
3629 struct ddb_entry *ddb_entry;
3630 struct scsi_qla_host *ha;
3631 int status = QLA_SUCCESS;
3633 sess = cls_session->dd_data;
3634 ddb_entry = sess->dd_data;
3636 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
3637 " unblock user space session\n", ha->host_no, __func__,
3638 ddb_entry->fw_ddb_index);
3640 if (!iscsi_is_session_online(cls_session)) {
3641 iscsi_conn_start(ddb_entry->conn);
3642 iscsi_conn_login_event(ddb_entry->conn,
3643 ISCSI_CONN_STATE_LOGGED_IN);
3645 ql4_printk(KERN_INFO, ha,
3646 "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
3647 ha->host_no, __func__, ddb_entry->fw_ddb_index,
3655 static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
3657 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
3660 static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
3662 uint16_t relogin_timer;
3663 struct iscsi_session *sess;
3664 struct ddb_entry *ddb_entry;
3665 struct scsi_qla_host *ha;
3667 sess = cls_sess->dd_data;
3668 ddb_entry = sess->dd_data;
3671 relogin_timer = max(ddb_entry->default_relogin_timeout,
3672 (uint16_t)RELOGIN_TOV);
3673 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
3675 DEBUG2(ql4_printk(KERN_INFO, ha,
3676 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
3677 ddb_entry->fw_ddb_index, relogin_timer));
3679 qla4xxx_login_flash_ddb(cls_sess);
3682 static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
3684 struct iscsi_session *sess;
3685 struct ddb_entry *ddb_entry;
3686 struct scsi_qla_host *ha;
3688 sess = cls_sess->dd_data;
3689 ddb_entry = sess->dd_data;
3692 if (!(ddb_entry->ddb_type == FLASH_DDB))
3695 if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
3698 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
3699 !iscsi_is_session_online(cls_sess)) {
3700 DEBUG2(ql4_printk(KERN_INFO, ha,
3701 "relogin issued\n"));
3702 qla4xxx_relogin_flash_ddb(cls_sess);
3706 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
3709 queue_work(ha->dpc_thread, &ha->dpc_work);
3712 static struct qla4_work_evt *
3713 qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
3714 enum qla4_work_type type)
3716 struct qla4_work_evt *e;
3717 uint32_t size = sizeof(struct qla4_work_evt) + data_size;
3719 e = kzalloc(size, GFP_ATOMIC);
3723 INIT_LIST_HEAD(&e->list);
3728 static void qla4xxx_post_work(struct scsi_qla_host *ha,
3729 struct qla4_work_evt *e)
3731 unsigned long flags;
3733 spin_lock_irqsave(&ha->work_lock, flags);
3734 list_add_tail(&e->list, &ha->work_list);
3735 spin_unlock_irqrestore(&ha->work_lock, flags);
3736 qla4xxx_wake_dpc(ha);
3739 int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
3740 enum iscsi_host_event_code aen_code,
3741 uint32_t data_size, uint8_t *data)
3743 struct qla4_work_evt *e;
3745 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
3749 e->u.aen.code = aen_code;
3750 e->u.aen.data_size = data_size;
3751 memcpy(e->u.aen.data, data, data_size);
3753 qla4xxx_post_work(ha, e);
3758 int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
3759 uint32_t status, uint32_t pid,
3760 uint32_t data_size, uint8_t *data)
3762 struct qla4_work_evt *e;
3764 e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
3768 e->u.ping.status = status;
3769 e->u.ping.pid = pid;
3770 e->u.ping.data_size = data_size;
3771 memcpy(e->u.ping.data, data, data_size);
3773 qla4xxx_post_work(ha, e);
3778 static void qla4xxx_do_work(struct scsi_qla_host *ha)
3780 struct qla4_work_evt *e, *tmp;
3781 unsigned long flags;
3784 spin_lock_irqsave(&ha->work_lock, flags);
3785 list_splice_init(&ha->work_list, &work);
3786 spin_unlock_irqrestore(&ha->work_lock, flags);
3788 list_for_each_entry_safe(e, tmp, &work, list) {
3789 list_del_init(&e->list);
3792 case QLA4_EVENT_AEN:
3793 iscsi_post_host_event(ha->host_no,
3794 &qla4xxx_iscsi_transport,
3799 case QLA4_EVENT_PING_STATUS:
3800 iscsi_ping_comp_event(ha->host_no,
3801 &qla4xxx_iscsi_transport,
3804 e->u.ping.data_size,
3808 ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
3809 "supported", e->type);
3816 * qla4xxx_do_dpc - dpc routine
3817 * @data: in our case pointer to adapter structure
3819 * This routine is a task that is schedule by the interrupt handler
3820 * to perform the background processing for interrupts. We put it
3821 * on a task queue that is consumed whenever the scheduler runs; that's
3822 * so you can do anything (i.e. put the process to sleep etc). In fact,
3823 * the mid-level tries to sleep when it reaches the driver threshold
3824 * "host->can_queue". This can cause a panic if we were in our interrupt code.
3826 static void qla4xxx_do_dpc(struct work_struct *work)
3828 struct scsi_qla_host *ha =
3829 container_of(work, struct scsi_qla_host, dpc_work);
3830 int status = QLA_ERROR;
3832 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
3833 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
3834 ha->host_no, __func__, ha->flags, ha->dpc_flags))
3836 /* Initialization not yet finished. Don't do anything yet. */
3837 if (!test_bit(AF_INIT_DONE, &ha->flags))
3840 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
3841 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
3842 ha->host_no, __func__, ha->flags));
3846 /* post events to application */
3847 qla4xxx_do_work(ha);
3849 if (is_qla80XX(ha)) {
3850 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
3851 if (is_qla8032(ha) || is_qla8042(ha)) {
3852 ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
3854 /* disable pause frame for ISP83xx */
3855 qla4_83xx_disable_pause(ha);
3858 ha->isp_ops->idc_lock(ha);
3859 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
3860 QLA8XXX_DEV_FAILED);
3861 ha->isp_ops->idc_unlock(ha);
3862 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
3863 qla4_8xxx_device_state_handler(ha);
3866 if (test_and_clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags))
3867 qla4_83xx_post_idc_ack(ha);
3869 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
3870 qla4_8xxx_need_qsnt_handler(ha);
3874 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
3875 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
3876 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
3877 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
3878 if ((is_qla8022(ha) && ql4xdontresethba) ||
3879 ((is_qla8032(ha) || is_qla8042(ha)) &&
3880 qla4_83xx_idc_dontreset(ha))) {
3881 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3882 ha->host_no, __func__));
3883 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
3884 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
3885 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3886 goto dpc_post_reset_ha;
3888 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
3889 test_bit(DPC_RESET_HA, &ha->dpc_flags))
3890 qla4xxx_recover_adapter(ha);
3892 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
3893 uint8_t wait_time = RESET_INTR_TOV;
3895 while ((readw(&ha->reg->ctrl_status) &
3896 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
3897 if (--wait_time == 0)
3902 DEBUG2(printk("scsi%ld: %s: SR|FSR "
3903 "bit not cleared-- resetting\n",
3904 ha->host_no, __func__));
3905 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
3906 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
3907 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
3908 status = qla4xxx_recover_adapter(ha);
3910 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
3911 if (status == QLA_SUCCESS)
3912 ha->isp_ops->enable_intrs(ha);
3917 /* ---- process AEN? --- */
3918 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
3919 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
3921 /* ---- Get DHCP IP Address? --- */
3922 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
3923 qla4xxx_get_dhcp_ip_address(ha);
3925 /* ---- relogin device? --- */
3926 if (adapter_up(ha) &&
3927 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
3928 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
3931 /* ---- link change? --- */
3932 if (!test_bit(AF_LOOPBACK, &ha->flags) &&
3933 test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
3934 if (!test_bit(AF_LINK_UP, &ha->flags)) {
3935 /* ---- link down? --- */
3936 qla4xxx_mark_all_devices_missing(ha);
3938 /* ---- link up? --- *
3939 * F/W will auto login to all devices ONLY ONCE after
3940 * link up during driver initialization and runtime
3941 * fatal error recovery. Therefore, the driver must
3942 * manually relogin to devices when recovering from
3943 * connection failures, logouts, expired KATO, etc. */
3944 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
3945 qla4xxx_build_ddb_list(ha, ha->is_reset);
3946 iscsi_host_for_each_session(ha->host,
3947 qla4xxx_login_flash_ddb);
3949 qla4xxx_relogin_all_devices(ha);
3955 * qla4xxx_free_adapter - release the adapter
3956 * @ha: pointer to adapter structure
3958 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
3960 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3962 /* Turn-off interrupts on the card. */
3963 ha->isp_ops->disable_intrs(ha);
3965 if (is_qla40XX(ha)) {
3966 writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
3967 &ha->reg->ctrl_status);
3968 readl(&ha->reg->ctrl_status);
3969 } else if (is_qla8022(ha)) {
3970 writel(0, &ha->qla4_82xx_reg->host_int);
3971 readl(&ha->qla4_82xx_reg->host_int);
3972 } else if (is_qla8032(ha) || is_qla8042(ha)) {
3973 writel(0, &ha->qla4_83xx_reg->risc_intr);
3974 readl(&ha->qla4_83xx_reg->risc_intr);
3977 /* Remove timer thread, if present */
3978 if (ha->timer_active)
3979 qla4xxx_stop_timer(ha);
3981 /* Kill the kernel thread for this host */
3983 destroy_workqueue(ha->dpc_thread);
3985 /* Kill the kernel thread for this host */
3987 destroy_workqueue(ha->task_wq);
3989 /* Put firmware in known state */
3990 ha->isp_ops->reset_firmware(ha);
3992 if (is_qla80XX(ha)) {
3993 ha->isp_ops->idc_lock(ha);
3994 qla4_8xxx_clear_drv_active(ha);
3995 ha->isp_ops->idc_unlock(ha);
3998 /* Detach interrupts */
3999 qla4xxx_free_irqs(ha);
4001 /* free extra memory */
4002 qla4xxx_mem_free(ha);
4005 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
4008 unsigned long mem_base, mem_len, db_base, db_len;
4009 struct pci_dev *pdev = ha->pdev;
4011 status = pci_request_regions(pdev, DRIVER_NAME);
4014 "scsi(%ld) Failed to reserve PIO regions (%s) "
4015 "status=%d\n", ha->host_no, pci_name(pdev), status);
4016 goto iospace_error_exit;
4019 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
4020 __func__, pdev->revision));
4021 ha->revision_id = pdev->revision;
4023 /* remap phys address */
4024 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
4025 mem_len = pci_resource_len(pdev, 0);
4026 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
4027 __func__, mem_base, mem_len));
4029 /* mapping of pcibase pointer */
4030 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
4031 if (!ha->nx_pcibase) {
4033 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
4034 pci_release_regions(ha->pdev);
4035 goto iospace_error_exit;
4038 /* Mapping of IO base pointer, door bell read and write pointer */
4040 /* mapping of IO base pointer */
4041 if (is_qla8022(ha)) {
4042 ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
4043 ((uint8_t *)ha->nx_pcibase + 0xbc000 +
4044 (ha->pdev->devfn << 11));
4045 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
4046 QLA82XX_CAM_RAM_DB2);
4047 } else if (is_qla8032(ha) || is_qla8042(ha)) {
4048 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
4049 ((uint8_t *)ha->nx_pcibase);
4052 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
4053 db_len = pci_resource_len(pdev, 4);
4061 * qla4xxx_iospace_config - maps registers
4062 * @ha: pointer to adapter structure
4064 * This routines maps HBA's registers from the pci address space
4065 * into the kernel virtual address space for memory mapped i/o.
4067 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
4069 unsigned long pio, pio_len, pio_flags;
4070 unsigned long mmio, mmio_len, mmio_flags;
4072 pio = pci_resource_start(ha->pdev, 0);
4073 pio_len = pci_resource_len(ha->pdev, 0);
4074 pio_flags = pci_resource_flags(ha->pdev, 0);
4075 if (pio_flags & IORESOURCE_IO) {
4076 if (pio_len < MIN_IOBASE_LEN) {
4077 ql4_printk(KERN_WARNING, ha,
4078 "Invalid PCI I/O region size\n");
4082 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
4086 /* Use MMIO operations for all accesses. */
4087 mmio = pci_resource_start(ha->pdev, 1);
4088 mmio_len = pci_resource_len(ha->pdev, 1);
4089 mmio_flags = pci_resource_flags(ha->pdev, 1);
4091 if (!(mmio_flags & IORESOURCE_MEM)) {
4092 ql4_printk(KERN_ERR, ha,
4093 "region #0 not an MMIO resource, aborting\n");
4095 goto iospace_error_exit;
4098 if (mmio_len < MIN_IOBASE_LEN) {
4099 ql4_printk(KERN_ERR, ha,
4100 "Invalid PCI mem region size, aborting\n");
4101 goto iospace_error_exit;
4104 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
4105 ql4_printk(KERN_WARNING, ha,
4106 "Failed to reserve PIO/MMIO regions\n");
4108 goto iospace_error_exit;
4111 ha->pio_address = pio;
4112 ha->pio_length = pio_len;
4113 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
4115 ql4_printk(KERN_ERR, ha,
4116 "cannot remap MMIO, aborting\n");
4118 goto iospace_error_exit;
4127 static struct isp_operations qla4xxx_isp_ops = {
4128 .iospace_config = qla4xxx_iospace_config,
4129 .pci_config = qla4xxx_pci_config,
4130 .disable_intrs = qla4xxx_disable_intrs,
4131 .enable_intrs = qla4xxx_enable_intrs,
4132 .start_firmware = qla4xxx_start_firmware,
4133 .intr_handler = qla4xxx_intr_handler,
4134 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
4135 .reset_chip = qla4xxx_soft_reset,
4136 .reset_firmware = qla4xxx_hw_reset,
4137 .queue_iocb = qla4xxx_queue_iocb,
4138 .complete_iocb = qla4xxx_complete_iocb,
4139 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
4140 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
4141 .get_sys_info = qla4xxx_get_sys_info,
4142 .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
4143 .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
4146 static struct isp_operations qla4_82xx_isp_ops = {
4147 .iospace_config = qla4_8xxx_iospace_config,
4148 .pci_config = qla4_8xxx_pci_config,
4149 .disable_intrs = qla4_82xx_disable_intrs,
4150 .enable_intrs = qla4_82xx_enable_intrs,
4151 .start_firmware = qla4_8xxx_load_risc,
4152 .restart_firmware = qla4_82xx_try_start_fw,
4153 .intr_handler = qla4_82xx_intr_handler,
4154 .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
4155 .need_reset = qla4_8xxx_need_reset,
4156 .reset_chip = qla4_82xx_isp_reset,
4157 .reset_firmware = qla4_8xxx_stop_firmware,
4158 .queue_iocb = qla4_82xx_queue_iocb,
4159 .complete_iocb = qla4_82xx_complete_iocb,
4160 .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
4161 .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
4162 .get_sys_info = qla4_8xxx_get_sys_info,
4163 .rd_reg_direct = qla4_82xx_rd_32,
4164 .wr_reg_direct = qla4_82xx_wr_32,
4165 .rd_reg_indirect = qla4_82xx_md_rd_32,
4166 .wr_reg_indirect = qla4_82xx_md_wr_32,
4167 .idc_lock = qla4_82xx_idc_lock,
4168 .idc_unlock = qla4_82xx_idc_unlock,
4169 .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
4170 .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
4171 .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
4174 static struct isp_operations qla4_83xx_isp_ops = {
4175 .iospace_config = qla4_8xxx_iospace_config,
4176 .pci_config = qla4_8xxx_pci_config,
4177 .disable_intrs = qla4_83xx_disable_intrs,
4178 .enable_intrs = qla4_83xx_enable_intrs,
4179 .start_firmware = qla4_8xxx_load_risc,
4180 .restart_firmware = qla4_83xx_start_firmware,
4181 .intr_handler = qla4_83xx_intr_handler,
4182 .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
4183 .need_reset = qla4_8xxx_need_reset,
4184 .reset_chip = qla4_83xx_isp_reset,
4185 .reset_firmware = qla4_8xxx_stop_firmware,
4186 .queue_iocb = qla4_83xx_queue_iocb,
4187 .complete_iocb = qla4_83xx_complete_iocb,
4188 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
4189 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
4190 .get_sys_info = qla4_8xxx_get_sys_info,
4191 .rd_reg_direct = qla4_83xx_rd_reg,
4192 .wr_reg_direct = qla4_83xx_wr_reg,
4193 .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
4194 .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
4195 .idc_lock = qla4_83xx_drv_lock,
4196 .idc_unlock = qla4_83xx_drv_unlock,
4197 .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
4198 .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
4199 .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
4202 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
4204 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
4207 uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
4209 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
4212 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
4214 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
4217 uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
4219 return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
4222 static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
4224 struct scsi_qla_host *ha = data;
4229 case ISCSI_BOOT_ETH_FLAGS:
4230 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
4232 case ISCSI_BOOT_ETH_INDEX:
4233 rc = sprintf(str, "0\n");
4235 case ISCSI_BOOT_ETH_MAC:
4236 rc = sysfs_format_mac(str, ha->my_mac,
4246 static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
4251 case ISCSI_BOOT_ETH_FLAGS:
4252 case ISCSI_BOOT_ETH_MAC:
4253 case ISCSI_BOOT_ETH_INDEX:
4263 static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
4265 struct scsi_qla_host *ha = data;
4270 case ISCSI_BOOT_INI_INITIATOR_NAME:
4271 rc = sprintf(str, "%s\n", ha->name_string);
4280 static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
4285 case ISCSI_BOOT_INI_INITIATOR_NAME:
4296 qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
4299 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
4304 case ISCSI_BOOT_TGT_NAME:
4305 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
4307 case ISCSI_BOOT_TGT_IP_ADDR:
4308 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
4309 rc = sprintf(buf, "%pI4\n",
4310 &boot_conn->dest_ipaddr.ip_address);
4312 rc = sprintf(str, "%pI6\n",
4313 &boot_conn->dest_ipaddr.ip_address);
4315 case ISCSI_BOOT_TGT_PORT:
4316 rc = sprintf(str, "%d\n", boot_conn->dest_port);
4318 case ISCSI_BOOT_TGT_CHAP_NAME:
4319 rc = sprintf(str, "%.*s\n",
4320 boot_conn->chap.target_chap_name_length,
4321 (char *)&boot_conn->chap.target_chap_name);
4323 case ISCSI_BOOT_TGT_CHAP_SECRET:
4324 rc = sprintf(str, "%.*s\n",
4325 boot_conn->chap.target_secret_length,
4326 (char *)&boot_conn->chap.target_secret);
4328 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
4329 rc = sprintf(str, "%.*s\n",
4330 boot_conn->chap.intr_chap_name_length,
4331 (char *)&boot_conn->chap.intr_chap_name);
4333 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
4334 rc = sprintf(str, "%.*s\n",
4335 boot_conn->chap.intr_secret_length,
4336 (char *)&boot_conn->chap.intr_secret);
4338 case ISCSI_BOOT_TGT_FLAGS:
4339 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
4341 case ISCSI_BOOT_TGT_NIC_ASSOC:
4342 rc = sprintf(str, "0\n");
4351 static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
4353 struct scsi_qla_host *ha = data;
4354 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
4356 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
4359 static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
4361 struct scsi_qla_host *ha = data;
4362 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
4364 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
4367 static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
4372 case ISCSI_BOOT_TGT_NAME:
4373 case ISCSI_BOOT_TGT_IP_ADDR:
4374 case ISCSI_BOOT_TGT_PORT:
4375 case ISCSI_BOOT_TGT_CHAP_NAME:
4376 case ISCSI_BOOT_TGT_CHAP_SECRET:
4377 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
4378 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
4379 case ISCSI_BOOT_TGT_NIC_ASSOC:
4380 case ISCSI_BOOT_TGT_FLAGS:
4390 static void qla4xxx_boot_release(void *data)
4392 struct scsi_qla_host *ha = data;
4394 scsi_host_put(ha->host);
4397 static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
4400 uint32_t addr, pri_addr, sec_addr;
4404 uint8_t *buf = NULL;
4405 size_t size = 13 * sizeof(uint8_t);
4406 int ret = QLA_SUCCESS;
4408 func_num = PCI_FUNC(ha->pdev->devfn);
4410 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
4411 __func__, ha->pdev->device, func_num);
4413 if (is_qla40XX(ha)) {
4414 if (func_num == 1) {
4415 addr = NVRAM_PORT0_BOOT_MODE;
4416 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
4417 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
4418 } else if (func_num == 3) {
4419 addr = NVRAM_PORT1_BOOT_MODE;
4420 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
4421 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
4424 goto exit_boot_info;
4427 /* Check Boot Mode */
4428 val = rd_nvram_byte(ha, addr);
4429 if (!(val & 0x07)) {
4430 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
4431 "options : 0x%x\n", __func__, val));
4433 goto exit_boot_info;
4436 /* get primary valid target index */
4437 val = rd_nvram_byte(ha, pri_addr);
4439 ddb_index[0] = (val & 0x7f);
4441 /* get secondary valid target index */
4442 val = rd_nvram_byte(ha, sec_addr);
4444 ddb_index[1] = (val & 0x7f);
4446 } else if (is_qla80XX(ha)) {
4447 buf = dma_alloc_coherent(&ha->pdev->dev, size,
4448 &buf_dma, GFP_KERNEL);
4450 DEBUG2(ql4_printk(KERN_ERR, ha,
4451 "%s: Unable to allocate dma buffer\n",
4454 goto exit_boot_info;
4457 if (ha->port_num == 0)
4458 offset = BOOT_PARAM_OFFSET_PORT0;
4459 else if (ha->port_num == 1)
4460 offset = BOOT_PARAM_OFFSET_PORT1;
4463 goto exit_boot_info_free;
4465 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
4467 if (qla4xxx_get_flash(ha, buf_dma, addr,
4468 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
4469 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
4470 " failed\n", ha->host_no, __func__));
4472 goto exit_boot_info_free;
4474 /* Check Boot Mode */
4475 if (!(buf[1] & 0x07)) {
4476 DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
4477 " : 0x%x\n", buf[1]));
4479 goto exit_boot_info_free;
4482 /* get primary valid target index */
4484 ddb_index[0] = buf[2] & 0x7f;
4486 /* get secondary valid target index */
4487 if (buf[11] & BIT_7)
4488 ddb_index[1] = buf[11] & 0x7f;
4491 goto exit_boot_info;
4494 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
4495 " target ID %d\n", __func__, ddb_index[0],
4498 exit_boot_info_free:
4499 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
4501 ha->pri_ddb_idx = ddb_index[0];
4502 ha->sec_ddb_idx = ddb_index[1];
4507 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
4508 * @ha: pointer to adapter structure
4509 * @username: CHAP username to be returned
4510 * @password: CHAP password to be returned
4512 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
4513 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
4514 * So from the CHAP cache find the first BIDI CHAP entry and set it
4515 * to the boot record in sysfs.
4517 static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
4520 int i, ret = -EINVAL;
4521 int max_chap_entries = 0;
4522 struct ql4_chap_table *chap_table;
4525 max_chap_entries = (ha->hw.flt_chap_size / 2) /
4526 sizeof(struct ql4_chap_table);
4528 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
4530 if (!ha->chap_list) {
4531 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
4535 mutex_lock(&ha->chap_sem);
4536 for (i = 0; i < max_chap_entries; i++) {
4537 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
4538 if (chap_table->cookie !=
4539 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
4543 if (chap_table->flags & BIT_7) /* local */
4546 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
4549 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
4550 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
4554 mutex_unlock(&ha->chap_sem);
4560 static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
4561 struct ql4_boot_session_info *boot_sess,
4564 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
4565 struct dev_db_entry *fw_ddb_entry;
4566 dma_addr_t fw_ddb_entry_dma;
4569 int ret = QLA_SUCCESS;
4571 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
4572 &fw_ddb_entry_dma, GFP_KERNEL);
4573 if (!fw_ddb_entry) {
4574 DEBUG2(ql4_printk(KERN_ERR, ha,
4575 "%s: Unable to allocate dma buffer.\n",
4581 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
4582 fw_ddb_entry_dma, ddb_index)) {
4583 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
4584 "index [%d]\n", __func__, ddb_index));
4586 goto exit_boot_target;
4589 /* Update target name and IP from DDB */
4590 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
4591 min(sizeof(boot_sess->target_name),
4592 sizeof(fw_ddb_entry->iscsi_name)));
4594 options = le16_to_cpu(fw_ddb_entry->options);
4595 if (options & DDB_OPT_IPV6_DEVICE) {
4596 memcpy(&boot_conn->dest_ipaddr.ip_address,
4597 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
4599 boot_conn->dest_ipaddr.ip_type = 0x1;
4600 memcpy(&boot_conn->dest_ipaddr.ip_address,
4601 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
4604 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
4606 /* update chap information */
4607 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
4609 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
4611 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
4613 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
4615 (char *)&boot_conn->chap.target_secret,
4618 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
4620 goto exit_boot_target;
4623 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
4624 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
4627 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
4629 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
4631 ret = qla4xxx_get_bidi_chap(ha,
4632 (char *)&boot_conn->chap.intr_chap_name,
4633 (char *)&boot_conn->chap.intr_secret);
4636 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
4638 goto exit_boot_target;
4641 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
4642 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
4646 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
4647 fw_ddb_entry, fw_ddb_entry_dma);
4651 static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
4653 uint16_t ddb_index[2];
4654 int ret = QLA_ERROR;
4657 memset(ddb_index, 0, sizeof(ddb_index));
4658 ddb_index[0] = 0xffff;
4659 ddb_index[1] = 0xffff;
4660 ret = get_fw_boot_info(ha, ddb_index);
4661 if (ret != QLA_SUCCESS) {
4662 DEBUG2(ql4_printk(KERN_INFO, ha,
4663 "%s: No boot target configured.\n", __func__));
4667 if (ql4xdisablesysfsboot)
4670 if (ddb_index[0] == 0xffff)
4673 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
4675 if (rval != QLA_SUCCESS) {
4676 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
4677 "configured\n", __func__));
4682 if (ddb_index[1] == 0xffff)
4683 goto exit_get_boot_info;
4685 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
4687 if (rval != QLA_SUCCESS) {
4688 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
4689 " configured\n", __func__));
4697 static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
4699 struct iscsi_boot_kobj *boot_kobj;
4701 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
4704 if (ql4xdisablesysfsboot) {
4705 ql4_printk(KERN_INFO, ha,
4706 "%s: syfsboot disabled - driver will trigger login "
4707 "and publish session for discovery .\n", __func__);
4712 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
4716 if (!scsi_host_get(ha->host))
4718 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
4719 qla4xxx_show_boot_tgt_pri_info,
4720 qla4xxx_tgt_get_attr_visibility,
4721 qla4xxx_boot_release);
4725 if (!scsi_host_get(ha->host))
4727 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
4728 qla4xxx_show_boot_tgt_sec_info,
4729 qla4xxx_tgt_get_attr_visibility,
4730 qla4xxx_boot_release);
4734 if (!scsi_host_get(ha->host))
4736 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
4737 qla4xxx_show_boot_ini_info,
4738 qla4xxx_ini_get_attr_visibility,
4739 qla4xxx_boot_release);
4743 if (!scsi_host_get(ha->host))
4745 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
4746 qla4xxx_show_boot_eth_info,
4747 qla4xxx_eth_get_attr_visibility,
4748 qla4xxx_boot_release);
4755 scsi_host_put(ha->host);
4757 iscsi_boot_destroy_kset(ha->boot_kset);
4763 * qla4xxx_create chap_list - Create CHAP list from FLASH
4764 * @ha: pointer to adapter structure
4766 * Read flash and make a list of CHAP entries, during login when a CHAP entry
4767 * is received, it will be checked in this list. If entry exist then the CHAP
4768 * entry index is set in the DDB. If CHAP entry does not exist in this list
4769 * then a new entry is added in FLASH in CHAP table and the index obtained is
4772 static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
4775 uint8_t *chap_flash_data = NULL;
4777 dma_addr_t chap_dma;
4778 uint32_t chap_size = 0;
4781 chap_size = MAX_CHAP_ENTRIES_40XX *
4782 sizeof(struct ql4_chap_table);
4783 else /* Single region contains CHAP info for both
4784 * ports which is divided into half for each port.
4786 chap_size = ha->hw.flt_chap_size / 2;
4788 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
4789 &chap_dma, GFP_KERNEL);
4790 if (!chap_flash_data) {
4791 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
4795 offset = FLASH_CHAP_OFFSET;
4797 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
4798 if (ha->port_num == 1)
4799 offset += chap_size;
4802 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
4803 if (rval != QLA_SUCCESS)
4804 goto exit_chap_list;
4806 if (ha->chap_list == NULL)
4807 ha->chap_list = vmalloc(chap_size);
4808 if (ha->chap_list == NULL) {
4809 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
4810 goto exit_chap_list;
4813 memcpy(ha->chap_list, chap_flash_data, chap_size);
4816 dma_free_coherent(&ha->pdev->dev, chap_size,
4817 chap_flash_data, chap_dma);
4820 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
4821 struct ql4_tuple_ddb *tddb)
4823 struct scsi_qla_host *ha;
4824 struct iscsi_cls_session *cls_sess;
4825 struct iscsi_cls_conn *cls_conn;
4826 struct iscsi_session *sess;
4827 struct iscsi_conn *conn;
4829 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
4831 cls_sess = ddb_entry->sess;
4832 sess = cls_sess->dd_data;
4833 cls_conn = ddb_entry->conn;
4834 conn = cls_conn->dd_data;
4836 tddb->tpgt = sess->tpgt;
4837 tddb->port = conn->persistent_port;
4838 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
4839 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
4842 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
4843 struct ql4_tuple_ddb *tddb,
4844 uint8_t *flash_isid)
4846 uint16_t options = 0;
4848 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
4849 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
4850 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
4852 options = le16_to_cpu(fw_ddb_entry->options);
4853 if (options & DDB_OPT_IPV6_DEVICE)
4854 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
4856 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
4858 tddb->port = le16_to_cpu(fw_ddb_entry->port);
4860 if (flash_isid == NULL)
4861 memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
4862 sizeof(tddb->isid));
4864 memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
4867 static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
4868 struct ql4_tuple_ddb *old_tddb,
4869 struct ql4_tuple_ddb *new_tddb,
4870 uint8_t is_isid_compare)
4872 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
4875 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
4878 if (old_tddb->port != new_tddb->port)
4881 /* For multi sessions, driver generates the ISID, so do not compare
4882 * ISID in reset path since it would be a comparison between the
4883 * driver generated ISID and firmware generated ISID. This could
4884 * lead to adding duplicated DDBs in the list as driver generated
4885 * ISID would not match firmware generated ISID.
4887 if (is_isid_compare) {
4888 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
4889 "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
4890 __func__, old_tddb->isid[5], old_tddb->isid[4],
4891 old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
4892 old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
4893 new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
4894 new_tddb->isid[0]));
4896 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
4897 sizeof(old_tddb->isid)))
4901 DEBUG2(ql4_printk(KERN_INFO, ha,
4902 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
4903 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
4904 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
4905 new_tddb->ip_addr, new_tddb->iscsi_name));
4910 static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
4911 struct dev_db_entry *fw_ddb_entry)
4913 struct ddb_entry *ddb_entry;
4914 struct ql4_tuple_ddb *fw_tddb = NULL;
4915 struct ql4_tuple_ddb *tmp_tddb = NULL;
4917 int ret = QLA_ERROR;
4919 fw_tddb = vzalloc(sizeof(*fw_tddb));
4921 DEBUG2(ql4_printk(KERN_WARNING, ha,
4922 "Memory Allocation failed.\n"));
4927 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
4929 DEBUG2(ql4_printk(KERN_WARNING, ha,
4930 "Memory Allocation failed.\n"));
4935 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
4937 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
4938 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
4939 if (ddb_entry == NULL)
4942 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
4943 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
4944 ret = QLA_SUCCESS; /* found */
4958 * qla4xxx_check_existing_isid - check if target with same isid exist
4960 * @list_nt: list of target
4961 * @isid: isid to check
4963 * This routine return QLA_SUCCESS if target with same isid exist
4965 static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
4967 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
4968 struct dev_db_entry *fw_ddb_entry;
4970 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
4971 fw_ddb_entry = &nt_ddb_idx->fw_ddb;
4973 if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
4974 sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
4982 * qla4xxx_update_isid - compare ddbs and updated isid
4983 * @ha: Pointer to host adapter structure.
4984 * @list_nt: list of nt target
4985 * @fw_ddb_entry: firmware ddb entry
4987 * This routine update isid if ddbs have same iqn, same isid and
4988 * different IP addr.
4989 * Return QLA_SUCCESS if isid is updated.
4991 static int qla4xxx_update_isid(struct scsi_qla_host *ha,
4992 struct list_head *list_nt,
4993 struct dev_db_entry *fw_ddb_entry)
4995 uint8_t base_value, i;
4997 base_value = fw_ddb_entry->isid[1] & 0x1f;
4998 for (i = 0; i < 8; i++) {
4999 fw_ddb_entry->isid[1] = (base_value | (i << 5));
5000 if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
5004 if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
5011 * qla4xxx_should_update_isid - check if isid need to update
5012 * @ha: Pointer to host adapter structure.
5013 * @old_tddb: ddb tuple
5014 * @new_tddb: ddb tuple
5016 * Return QLA_SUCCESS if different IP, different PORT, same iqn,
5019 static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
5020 struct ql4_tuple_ddb *old_tddb,
5021 struct ql4_tuple_ddb *new_tddb)
5023 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
5025 if (old_tddb->port == new_tddb->port)
5029 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
5033 if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
5034 sizeof(old_tddb->isid)))
5035 /* different isid */
5042 * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
5043 * @ha: Pointer to host adapter structure.
5044 * @list_nt: list of nt target.
5045 * @fw_ddb_entry: firmware ddb entry.
5047 * This routine check if fw_ddb_entry already exists in list_nt to avoid
5048 * duplicate ddb in list_nt.
5049 * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
5050 * Note: This function also update isid of DDB if required.
5053 static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
5054 struct list_head *list_nt,
5055 struct dev_db_entry *fw_ddb_entry)
5057 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
5058 struct ql4_tuple_ddb *fw_tddb = NULL;
5059 struct ql4_tuple_ddb *tmp_tddb = NULL;
5060 int rval, ret = QLA_ERROR;
5062 fw_tddb = vzalloc(sizeof(*fw_tddb));
5064 DEBUG2(ql4_printk(KERN_WARNING, ha,
5065 "Memory Allocation failed.\n"));
5070 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
5072 DEBUG2(ql4_printk(KERN_WARNING, ha,
5073 "Memory Allocation failed.\n"));
5078 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
5080 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
5081 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
5082 nt_ddb_idx->flash_isid);
5083 ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
5084 /* found duplicate ddb */
5085 if (ret == QLA_SUCCESS)
5089 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
5090 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
5092 ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
5093 if (ret == QLA_SUCCESS) {
5094 rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
5095 if (rval == QLA_SUCCESS)
5112 static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
5114 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
5116 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
5117 list_del_init(&ddb_idx->list);
5122 static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
5123 struct dev_db_entry *fw_ddb_entry)
5125 struct iscsi_endpoint *ep;
5126 struct sockaddr_in *addr;
5127 struct sockaddr_in6 *addr6;
5128 struct sockaddr *t_addr;
5129 struct sockaddr_storage *dst_addr;
5132 /* TODO: need to destroy on unload iscsi_endpoint*/
5133 dst_addr = vmalloc(sizeof(*dst_addr));
5137 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
5138 t_addr = (struct sockaddr *)dst_addr;
5139 t_addr->sa_family = AF_INET6;
5140 addr6 = (struct sockaddr_in6 *)dst_addr;
5141 ip = (char *)&addr6->sin6_addr;
5142 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
5143 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
5146 t_addr = (struct sockaddr *)dst_addr;
5147 t_addr->sa_family = AF_INET;
5148 addr = (struct sockaddr_in *)dst_addr;
5149 ip = (char *)&addr->sin_addr;
5150 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
5151 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
5154 ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
5159 static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
5161 if (ql4xdisablesysfsboot)
5163 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
5168 static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
5169 struct ddb_entry *ddb_entry,
5172 uint16_t def_timeout;
5174 ddb_entry->ddb_type = FLASH_DDB;
5175 ddb_entry->fw_ddb_index = INVALID_ENTRY;
5176 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
5178 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
5179 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
5181 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
5182 atomic_set(&ddb_entry->relogin_timer, 0);
5183 atomic_set(&ddb_entry->relogin_retry_count, 0);
5184 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
5185 ddb_entry->default_relogin_timeout =
5186 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
5187 def_timeout : LOGIN_TOV;
5188 ddb_entry->default_time2wait =
5189 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
5191 if (ql4xdisablesysfsboot &&
5192 (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
5193 set_bit(DF_BOOT_TGT, &ddb_entry->flags);
5196 static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
5199 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
5200 uint32_t sts[MBOX_REG_COUNT];
5202 unsigned long wtime;
5205 wtime = jiffies + (HZ * IP_CONFIG_TOV);
5207 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
5208 if (ip_idx[idx] == -1)
5211 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
5213 if (ret == QLA_ERROR) {
5218 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
5220 DEBUG2(ql4_printk(KERN_INFO, ha,
5221 "Waiting for IP state for idx = %d, state = 0x%x\n",
5222 ip_idx[idx], ip_state));
5223 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
5224 ip_state == IP_ADDRSTATE_INVALID ||
5225 ip_state == IP_ADDRSTATE_PREFERRED ||
5226 ip_state == IP_ADDRSTATE_DEPRICATED ||
5227 ip_state == IP_ADDRSTATE_DISABLING)
5231 /* Break if all IP states checked */
5232 if ((ip_idx[0] == -1) &&
5233 (ip_idx[1] == -1) &&
5234 (ip_idx[2] == -1) &&
5237 schedule_timeout_uninterruptible(HZ);
5238 } while (time_after(wtime, jiffies));
5241 static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
5242 struct list_head *list_st)
5244 struct qla_ddb_index *st_ddb_idx;
5247 struct dev_db_entry *fw_ddb_entry;
5248 dma_addr_t fw_ddb_dma;
5250 uint32_t idx = 0, next_idx = 0;
5251 uint32_t state = 0, conn_err = 0;
5252 uint16_t conn_id = 0;
5254 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
5256 if (fw_ddb_entry == NULL) {
5257 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
5261 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
5263 fw_idx_size = sizeof(struct qla_ddb_index);
5265 for (idx = 0; idx < max_ddbs; idx = next_idx) {
5266 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
5267 NULL, &next_idx, &state,
5268 &conn_err, NULL, &conn_id);
5269 if (ret == QLA_ERROR)
5272 /* Ignore DDB if invalid state (unassigned) */
5273 if (state == DDB_DS_UNASSIGNED)
5274 goto continue_next_st;
5276 /* Check if ST, add to the list_st */
5277 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
5278 goto continue_next_st;
5280 st_ddb_idx = vzalloc(fw_idx_size);
5284 st_ddb_idx->fw_ddb_idx = idx;
5286 list_add_tail(&st_ddb_idx->list, list_st);
5294 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
5298 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
5299 * @ha: pointer to adapter structure
5300 * @list_ddb: List from which failed ddb to be removed
5302 * Iterate over the list of DDBs and find and remove DDBs that are either in
5303 * no connection active state or failed state
5305 static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
5306 struct list_head *list_ddb)
5308 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
5309 uint32_t next_idx = 0;
5310 uint32_t state = 0, conn_err = 0;
5313 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
5314 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
5315 NULL, 0, NULL, &next_idx, &state,
5316 &conn_err, NULL, NULL);
5317 if (ret == QLA_ERROR)
5320 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
5321 state == DDB_DS_SESSION_FAILED) {
5322 list_del_init(&ddb_idx->list);
5328 static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
5329 struct dev_db_entry *fw_ddb_entry,
5330 int is_reset, uint16_t idx)
5332 struct iscsi_cls_session *cls_sess;
5333 struct iscsi_session *sess;
5334 struct iscsi_cls_conn *cls_conn;
5335 struct iscsi_endpoint *ep;
5336 uint16_t cmds_max = 32;
5337 uint16_t conn_id = 0;
5338 uint32_t initial_cmdsn = 0;
5339 int ret = QLA_SUCCESS;
5341 struct ddb_entry *ddb_entry = NULL;
5343 /* Create session object, with INVALID_ENTRY,
5344 * the targer_id would get set when we issue the login
5346 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
5347 cmds_max, sizeof(struct ddb_entry),
5348 sizeof(struct ql4_task_data),
5349 initial_cmdsn, INVALID_ENTRY);
5356 * so calling module_put function to decrement the
5359 module_put(qla4xxx_iscsi_transport.owner);
5360 sess = cls_sess->dd_data;
5361 ddb_entry = sess->dd_data;
5362 ddb_entry->sess = cls_sess;
5364 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
5365 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
5366 sizeof(struct dev_db_entry));
5368 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
5370 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
5377 ddb_entry->conn = cls_conn;
5379 /* Setup ep, for displaying attributes in sysfs */
5380 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
5382 ep->conn = cls_conn;
5385 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
5390 /* Update sess/conn params */
5391 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
5393 if (is_reset == RESET_ADAPTER) {
5394 iscsi_block_session(cls_sess);
5395 /* Use the relogin path to discover new devices
5396 * by short-circuting the logic of setting
5397 * timer to relogin - instead set the flags
5398 * to initiate login right away.
5400 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
5401 set_bit(DF_RELOGIN, &ddb_entry->flags);
5408 static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
5409 struct list_head *list_nt, int is_reset)
5411 struct dev_db_entry *fw_ddb_entry;
5412 dma_addr_t fw_ddb_dma;
5416 uint32_t idx = 0, next_idx = 0;
5417 uint32_t state = 0, conn_err = 0;
5418 uint16_t conn_id = 0;
5419 struct qla_ddb_index *nt_ddb_idx;
5421 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
5423 if (fw_ddb_entry == NULL) {
5424 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
5427 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
5429 fw_idx_size = sizeof(struct qla_ddb_index);
5431 for (idx = 0; idx < max_ddbs; idx = next_idx) {
5432 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
5433 NULL, &next_idx, &state,
5434 &conn_err, NULL, &conn_id);
5435 if (ret == QLA_ERROR)
5438 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
5439 goto continue_next_nt;
5441 /* Check if NT, then add to list it */
5442 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
5443 goto continue_next_nt;
5445 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
5446 state == DDB_DS_SESSION_FAILED))
5447 goto continue_next_nt;
5449 DEBUG2(ql4_printk(KERN_INFO, ha,
5450 "Adding DDB to session = 0x%x\n", idx));
5451 if (is_reset == INIT_ADAPTER) {
5452 nt_ddb_idx = vmalloc(fw_idx_size);
5456 nt_ddb_idx->fw_ddb_idx = idx;
5458 /* Copy original isid as it may get updated in function
5459 * qla4xxx_update_isid(). We need original isid in
5460 * function qla4xxx_compare_tuple_ddb to find duplicate
5462 memcpy(&nt_ddb_idx->flash_isid[0],
5463 &fw_ddb_entry->isid[0],
5464 sizeof(nt_ddb_idx->flash_isid));
5466 ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
5468 if (ret == QLA_SUCCESS) {
5469 /* free nt_ddb_idx and do not add to list_nt */
5471 goto continue_next_nt;
5474 /* Copy updated isid */
5475 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
5476 sizeof(struct dev_db_entry));
5478 list_add_tail(&nt_ddb_idx->list, list_nt);
5479 } else if (is_reset == RESET_ADAPTER) {
5480 if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
5482 goto continue_next_nt;
5485 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
5486 if (ret == QLA_ERROR)
5496 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
5499 static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
5500 struct list_head *list_nt)
5502 struct dev_db_entry *fw_ddb_entry;
5503 dma_addr_t fw_ddb_dma;
5507 uint32_t idx = 0, next_idx = 0;
5508 uint32_t state = 0, conn_err = 0;
5509 uint16_t conn_id = 0;
5510 struct qla_ddb_index *nt_ddb_idx;
5512 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
5514 if (fw_ddb_entry == NULL) {
5515 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
5516 goto exit_new_nt_list;
5518 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
5520 fw_idx_size = sizeof(struct qla_ddb_index);
5522 for (idx = 0; idx < max_ddbs; idx = next_idx) {
5523 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
5524 NULL, &next_idx, &state,
5525 &conn_err, NULL, &conn_id);
5526 if (ret == QLA_ERROR)
5529 /* Check if NT, then add it to list */
5530 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
5531 goto continue_next_new_nt;
5533 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
5534 goto continue_next_new_nt;
5536 DEBUG2(ql4_printk(KERN_INFO, ha,
5537 "Adding DDB to session = 0x%x\n", idx));
5539 nt_ddb_idx = vmalloc(fw_idx_size);
5543 nt_ddb_idx->fw_ddb_idx = idx;
5545 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
5546 if (ret == QLA_SUCCESS) {
5547 /* free nt_ddb_idx and do not add to list_nt */
5549 goto continue_next_new_nt;
5552 list_add_tail(&nt_ddb_idx->list, list_nt);
5554 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
5556 if (ret == QLA_ERROR)
5557 goto exit_new_nt_list;
5559 continue_next_new_nt:
5566 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
5570 * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
5571 * @dev: dev associated with the sysfs entry
5572 * @data: pointer to flashnode session object
5575 * 1: if flashnode entry is non-persistent
5576 * 0: if flashnode entry is persistent
5578 static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
5580 struct iscsi_bus_flash_session *fnode_sess;
5582 if (!iscsi_flashnode_bus_match(dev, NULL))
5585 fnode_sess = iscsi_dev_to_flash_session(dev);
5587 return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
5591 * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
5592 * @ha: pointer to host
5593 * @fw_ddb_entry: flash ddb data
5594 * @idx: target index
5595 * @user: if set then this call is made from userland else from kernel
5598 * On sucess: QLA_SUCCESS
5599 * On failure: QLA_ERROR
5601 * This create separate sysfs entries for session and connection attributes of
5602 * the given fw ddb entry.
5603 * If this is invoked as a result of a userspace call then the entry is marked
5604 * as nonpersistent using flash_state field.
5606 static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
5607 struct dev_db_entry *fw_ddb_entry,
5608 uint16_t *idx, int user)
5610 struct iscsi_bus_flash_session *fnode_sess = NULL;
5611 struct iscsi_bus_flash_conn *fnode_conn = NULL;
5614 fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
5615 &qla4xxx_iscsi_transport, 0);
5617 ql4_printk(KERN_ERR, ha,
5618 "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
5619 __func__, *idx, ha->host_no);
5620 goto exit_tgt_create;
5623 fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
5624 &qla4xxx_iscsi_transport, 0);
5626 ql4_printk(KERN_ERR, ha,
5627 "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
5628 __func__, *idx, ha->host_no);
5633 fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
5635 fnode_sess->flash_state = DEV_DB_PERSISTENT;
5637 if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
5638 fnode_sess->is_boot_target = 1;
5640 fnode_sess->is_boot_target = 0;
5643 rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
5646 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
5647 __func__, fnode_sess->dev.kobj.name);
5649 ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
5650 __func__, fnode_conn->dev.kobj.name);
5655 iscsi_destroy_flashnode_sess(fnode_sess);
5662 * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
5663 * @shost: pointer to host
5664 * @buf: type of ddb entry (ipv4/ipv6)
5665 * @len: length of buf
5667 * This creates new ddb entry in the flash by finding first free index and
5668 * storing default ddb there. And then create sysfs entry for the new ddb entry.
5670 static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
5673 struct scsi_qla_host *ha = to_qla_host(shost);
5674 struct dev_db_entry *fw_ddb_entry = NULL;
5675 dma_addr_t fw_ddb_entry_dma;
5678 uint16_t max_ddbs = 0;
5679 uint32_t options = 0;
5680 uint32_t rval = QLA_ERROR;
5682 if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
5683 strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
5684 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
5689 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
5692 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5693 &fw_ddb_entry_dma, GFP_KERNEL);
5694 if (!fw_ddb_entry) {
5695 DEBUG2(ql4_printk(KERN_ERR, ha,
5696 "%s: Unable to allocate dma buffer\n",
5701 dev = iscsi_find_flashnode_sess(ha->host, NULL,
5702 qla4xxx_sysfs_ddb_is_non_persistent);
5704 ql4_printk(KERN_ERR, ha,
5705 "%s: A non-persistent entry %s found\n",
5706 __func__, dev->kobj.name);
5711 /* Index 0 and 1 are reserved for boot target entries */
5712 for (idx = 2; idx < max_ddbs; idx++) {
5713 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
5714 fw_ddb_entry_dma, idx))
5718 if (idx == max_ddbs)
5721 if (!strncasecmp("ipv6", buf, 4))
5722 options |= IPV6_DEFAULT_DDB_ENTRY;
5724 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
5725 if (rval == QLA_ERROR)
5728 rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
5732 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5733 fw_ddb_entry, fw_ddb_entry_dma);
5734 if (rval == QLA_SUCCESS)
5741 * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
5742 * @fnode_sess: pointer to session attrs of flash ddb entry
5743 * @fnode_conn: pointer to connection attrs of flash ddb entry
5745 * This writes the contents of target ddb buffer to Flash with a valid cookie
5746 * value in order to make the ddb entry persistent.
5748 static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
5749 struct iscsi_bus_flash_conn *fnode_conn)
5751 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
5752 struct scsi_qla_host *ha = to_qla_host(shost);
5753 uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
5754 struct dev_db_entry *fw_ddb_entry = NULL;
5755 dma_addr_t fw_ddb_entry_dma;
5756 uint32_t options = 0;
5759 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5760 &fw_ddb_entry_dma, GFP_KERNEL);
5761 if (!fw_ddb_entry) {
5762 DEBUG2(ql4_printk(KERN_ERR, ha,
5763 "%s: Unable to allocate dma buffer\n",
5766 goto exit_ddb_apply;
5769 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
5770 options |= IPV6_DEFAULT_DDB_ENTRY;
5772 rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
5773 if (rval == QLA_ERROR)
5774 goto exit_ddb_apply;
5776 dev_db_start_offset += (fnode_sess->target_id *
5777 sizeof(*fw_ddb_entry));
5779 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
5780 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
5782 rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
5783 sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
5785 if (rval == QLA_SUCCESS) {
5786 fnode_sess->flash_state = DEV_DB_PERSISTENT;
5787 ql4_printk(KERN_INFO, ha,
5788 "%s: flash node %u of host %lu written to flash\n",
5789 __func__, fnode_sess->target_id, ha->host_no);
5792 ql4_printk(KERN_ERR, ha,
5793 "%s: Error while writing flash node %u of host %lu to flash\n",
5794 __func__, fnode_sess->target_id, ha->host_no);
5799 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5800 fw_ddb_entry, fw_ddb_entry_dma);
5804 static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
5805 struct dev_db_entry *fw_ddb_entry,
5808 struct dev_db_entry *ddb_entry = NULL;
5809 dma_addr_t ddb_entry_dma;
5810 unsigned long wtime;
5811 uint32_t mbx_sts = 0;
5812 uint32_t state = 0, conn_err = 0;
5816 ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
5817 &ddb_entry_dma, GFP_KERNEL);
5819 DEBUG2(ql4_printk(KERN_ERR, ha,
5820 "%s: Unable to allocate dma buffer\n",
5825 memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
5827 ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
5828 if (ret != QLA_SUCCESS) {
5829 DEBUG2(ql4_printk(KERN_ERR, ha,
5830 "%s: Unable to set ddb entry for index %d\n",
5832 goto exit_ddb_conn_open;
5835 qla4xxx_conn_open(ha, idx);
5837 /* To ensure that sendtargets is done, wait for at least 12 secs */
5838 tmo = ((ha->def_timeout > LOGIN_TOV) &&
5839 (ha->def_timeout < LOGIN_TOV * 10) ?
5840 ha->def_timeout : LOGIN_TOV);
5842 DEBUG2(ql4_printk(KERN_INFO, ha,
5843 "Default time to wait for login to ddb %d\n", tmo));
5845 wtime = jiffies + (HZ * tmo);
5847 ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
5848 NULL, &state, &conn_err, NULL,
5850 if (ret == QLA_ERROR)
5853 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
5854 state == DDB_DS_SESSION_FAILED)
5857 schedule_timeout_uninterruptible(HZ / 10);
5858 } while (time_after(wtime, jiffies));
5862 dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
5863 ddb_entry, ddb_entry_dma);
5867 static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
5868 struct dev_db_entry *fw_ddb_entry)
5870 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
5871 struct list_head list_nt;
5875 if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
5876 ql4_printk(KERN_WARNING, ha,
5877 "%s: A discovery already in progress!\n", __func__);
5881 INIT_LIST_HEAD(&list_nt);
5883 set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
5885 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
5886 if (ret == QLA_ERROR)
5887 goto exit_login_st_clr_bit;
5889 ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
5890 if (ret == QLA_ERROR)
5893 qla4xxx_build_new_nt_list(ha, &list_nt);
5895 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
5896 list_del_init(&ddb_idx->list);
5897 qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
5902 if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
5903 ql4_printk(KERN_ERR, ha,
5904 "Unable to clear DDB index = 0x%x\n", ddb_index);
5907 clear_bit(ddb_index, ha->ddb_idx_map);
5909 exit_login_st_clr_bit:
5910 clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
5914 static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
5915 struct dev_db_entry *fw_ddb_entry,
5918 int ret = QLA_ERROR;
5920 ret = qla4xxx_is_session_exists(ha, fw_ddb_entry);
5921 if (ret != QLA_SUCCESS)
5922 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
5931 * qla4xxx_sysfs_ddb_login - Login to the specified target
5932 * @fnode_sess: pointer to session attrs of flash ddb entry
5933 * @fnode_conn: pointer to connection attrs of flash ddb entry
5935 * This logs in to the specified target
5937 static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
5938 struct iscsi_bus_flash_conn *fnode_conn)
5940 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
5941 struct scsi_qla_host *ha = to_qla_host(shost);
5942 struct dev_db_entry *fw_ddb_entry = NULL;
5943 dma_addr_t fw_ddb_entry_dma;
5944 uint32_t options = 0;
5947 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
5948 ql4_printk(KERN_ERR, ha,
5949 "%s: Target info is not persistent\n", __func__);
5951 goto exit_ddb_login;
5954 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5955 &fw_ddb_entry_dma, GFP_KERNEL);
5956 if (!fw_ddb_entry) {
5957 DEBUG2(ql4_printk(KERN_ERR, ha,
5958 "%s: Unable to allocate dma buffer\n",
5961 goto exit_ddb_login;
5964 if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
5965 options |= IPV6_DEFAULT_DDB_ENTRY;
5967 ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
5968 if (ret == QLA_ERROR)
5969 goto exit_ddb_login;
5971 qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
5972 fw_ddb_entry->cookie = DDB_VALID_COOKIE;
5974 if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
5975 ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry);
5977 ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
5978 fnode_sess->target_id);
5985 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
5986 fw_ddb_entry, fw_ddb_entry_dma);
5991 * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
5992 * @cls_sess: pointer to session to be logged out
5994 * This performs session log out from the specified target
5996 static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
5998 struct iscsi_session *sess;
5999 struct ddb_entry *ddb_entry = NULL;
6000 struct scsi_qla_host *ha;
6001 struct dev_db_entry *fw_ddb_entry = NULL;
6002 dma_addr_t fw_ddb_entry_dma;
6003 unsigned long flags;
6004 unsigned long wtime;
6009 sess = cls_sess->dd_data;
6010 ddb_entry = sess->dd_data;
6013 if (ddb_entry->ddb_type != FLASH_DDB) {
6014 ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
6017 goto exit_ddb_logout;
6020 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
6021 ql4_printk(KERN_ERR, ha,
6022 "%s: Logout from boot target entry is not permitted.\n",
6025 goto exit_ddb_logout;
6028 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6029 &fw_ddb_entry_dma, GFP_KERNEL);
6030 if (!fw_ddb_entry) {
6031 ql4_printk(KERN_ERR, ha,
6032 "%s: Unable to allocate dma buffer\n", __func__);
6034 goto exit_ddb_logout;
6037 if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
6038 goto ddb_logout_init;
6040 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
6041 fw_ddb_entry, fw_ddb_entry_dma,
6042 NULL, NULL, &ddb_state, NULL,
6044 if (ret == QLA_ERROR)
6045 goto ddb_logout_init;
6047 if (ddb_state == DDB_DS_SESSION_ACTIVE)
6048 goto ddb_logout_init;
6050 /* wait until next relogin is triggered using DF_RELOGIN and
6051 * clear DF_RELOGIN to avoid invocation of further relogin
6053 wtime = jiffies + (HZ * RELOGIN_TOV);
6055 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
6056 goto ddb_logout_init;
6058 schedule_timeout_uninterruptible(HZ);
6059 } while ((time_after(wtime, jiffies)));
6062 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
6063 atomic_set(&ddb_entry->relogin_timer, 0);
6065 options = LOGOUT_OPTION_CLOSE_SESSION;
6066 qla4xxx_session_logout_ddb(ha, ddb_entry, options);
6068 memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
6069 wtime = jiffies + (HZ * LOGOUT_TOV);
6071 ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
6072 fw_ddb_entry, fw_ddb_entry_dma,
6073 NULL, NULL, &ddb_state, NULL,
6075 if (ret == QLA_ERROR)
6076 goto ddb_logout_clr_sess;
6078 if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
6079 (ddb_state == DDB_DS_SESSION_FAILED))
6080 goto ddb_logout_clr_sess;
6082 schedule_timeout_uninterruptible(HZ);
6083 } while ((time_after(wtime, jiffies)));
6085 ddb_logout_clr_sess:
6086 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
6088 * we have decremented the reference count of the driver
6089 * when we setup the session to have the driver unload
6090 * to be seamless without actually destroying the
6093 try_module_get(qla4xxx_iscsi_transport.owner);
6094 iscsi_destroy_endpoint(ddb_entry->conn->ep);
6096 spin_lock_irqsave(&ha->hardware_lock, flags);
6097 qla4xxx_free_ddb(ha, ddb_entry);
6098 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
6099 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6101 iscsi_session_teardown(ddb_entry->sess);
6103 clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
6108 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6109 fw_ddb_entry, fw_ddb_entry_dma);
6114 * qla4xxx_sysfs_ddb_logout - Logout from the specified target
6115 * @fnode_sess: pointer to session attrs of flash ddb entry
6116 * @fnode_conn: pointer to connection attrs of flash ddb entry
6118 * This performs log out from the specified target
6120 static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
6121 struct iscsi_bus_flash_conn *fnode_conn)
6123 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
6124 struct scsi_qla_host *ha = to_qla_host(shost);
6125 struct ql4_tuple_ddb *flash_tddb = NULL;
6126 struct ql4_tuple_ddb *tmp_tddb = NULL;
6127 struct dev_db_entry *fw_ddb_entry = NULL;
6128 struct ddb_entry *ddb_entry = NULL;
6129 dma_addr_t fw_ddb_dma;
6130 uint32_t next_idx = 0;
6131 uint32_t state = 0, conn_err = 0;
6132 uint16_t conn_id = 0;
6134 int status, ret = 0;
6136 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
6138 if (fw_ddb_entry == NULL) {
6139 ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
6141 goto exit_ddb_logout;
6144 flash_tddb = vzalloc(sizeof(*flash_tddb));
6146 ql4_printk(KERN_WARNING, ha,
6147 "%s:Memory Allocation failed.\n", __func__);
6149 goto exit_ddb_logout;
6152 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
6154 ql4_printk(KERN_WARNING, ha,
6155 "%s:Memory Allocation failed.\n", __func__);
6157 goto exit_ddb_logout;
6160 if (!fnode_sess->targetname) {
6161 ql4_printk(KERN_ERR, ha,
6162 "%s:Cannot logout from SendTarget entry\n",
6165 goto exit_ddb_logout;
6168 if (fnode_sess->is_boot_target) {
6169 ql4_printk(KERN_ERR, ha,
6170 "%s: Logout from boot target entry is not permitted.\n",
6173 goto exit_ddb_logout;
6176 strncpy(flash_tddb->iscsi_name, fnode_sess->targetname,
6179 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
6180 sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
6182 sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
6184 flash_tddb->tpgt = fnode_sess->tpgt;
6185 flash_tddb->port = fnode_conn->port;
6187 COPY_ISID(flash_tddb->isid, fnode_sess->isid);
6189 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
6190 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6191 if (ddb_entry == NULL)
6194 if (ddb_entry->ddb_type != FLASH_DDB)
6197 index = ddb_entry->sess->target_id;
6198 status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
6199 fw_ddb_dma, NULL, &next_idx,
6200 &state, &conn_err, NULL,
6202 if (status == QLA_ERROR) {
6207 qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
6209 status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
6211 if (status == QLA_SUCCESS) {
6212 ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
6217 if (idx == MAX_DDB_ENTRIES)
6226 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
6232 qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
6233 int param, char *buf)
6235 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
6236 struct scsi_qla_host *ha = to_qla_host(shost);
6237 struct iscsi_bus_flash_conn *fnode_conn;
6238 struct ql4_chap_table chap_tbl;
6243 dev = iscsi_find_flashnode_conn(fnode_sess);
6247 fnode_conn = iscsi_dev_to_flash_conn(dev);
6250 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
6251 rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
6253 case ISCSI_FLASHNODE_PORTAL_TYPE:
6254 rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
6256 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
6257 rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
6259 case ISCSI_FLASHNODE_DISCOVERY_SESS:
6260 rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
6262 case ISCSI_FLASHNODE_ENTRY_EN:
6263 rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
6265 case ISCSI_FLASHNODE_HDR_DGST_EN:
6266 rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
6268 case ISCSI_FLASHNODE_DATA_DGST_EN:
6269 rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
6271 case ISCSI_FLASHNODE_IMM_DATA_EN:
6272 rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
6274 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
6275 rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
6277 case ISCSI_FLASHNODE_DATASEQ_INORDER:
6278 rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
6280 case ISCSI_FLASHNODE_PDU_INORDER:
6281 rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
6283 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
6284 rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
6286 case ISCSI_FLASHNODE_SNACK_REQ_EN:
6287 rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
6289 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
6290 rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
6292 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
6293 rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
6295 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
6296 rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
6298 case ISCSI_FLASHNODE_ERL:
6299 rc = sprintf(buf, "%u\n", fnode_sess->erl);
6301 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
6302 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
6304 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
6305 rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
6307 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
6308 rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
6310 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
6311 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
6313 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
6314 rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
6316 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
6317 rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
6319 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
6320 rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
6322 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
6323 rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
6325 case ISCSI_FLASHNODE_FIRST_BURST:
6326 rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
6328 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
6329 rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
6331 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
6332 rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
6334 case ISCSI_FLASHNODE_MAX_R2T:
6335 rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
6337 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
6338 rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
6340 case ISCSI_FLASHNODE_ISID:
6341 rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
6342 fnode_sess->isid[0], fnode_sess->isid[1],
6343 fnode_sess->isid[2], fnode_sess->isid[3],
6344 fnode_sess->isid[4], fnode_sess->isid[5]);
6346 case ISCSI_FLASHNODE_TSID:
6347 rc = sprintf(buf, "%u\n", fnode_sess->tsid);
6349 case ISCSI_FLASHNODE_PORT:
6350 rc = sprintf(buf, "%d\n", fnode_conn->port);
6352 case ISCSI_FLASHNODE_MAX_BURST:
6353 rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
6355 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
6356 rc = sprintf(buf, "%u\n",
6357 fnode_sess->default_taskmgmt_timeout);
6359 case ISCSI_FLASHNODE_IPADDR:
6360 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
6361 rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
6363 rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
6365 case ISCSI_FLASHNODE_ALIAS:
6366 if (fnode_sess->targetalias)
6367 rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
6369 rc = sprintf(buf, "\n");
6371 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
6372 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
6373 rc = sprintf(buf, "%pI6\n",
6374 fnode_conn->redirect_ipaddr);
6376 rc = sprintf(buf, "%pI4\n",
6377 fnode_conn->redirect_ipaddr);
6379 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
6380 rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
6382 case ISCSI_FLASHNODE_LOCAL_PORT:
6383 rc = sprintf(buf, "%u\n", fnode_conn->local_port);
6385 case ISCSI_FLASHNODE_IPV4_TOS:
6386 rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
6388 case ISCSI_FLASHNODE_IPV6_TC:
6389 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
6390 rc = sprintf(buf, "%u\n",
6391 fnode_conn->ipv6_traffic_class);
6393 rc = sprintf(buf, "\n");
6395 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
6396 rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
6398 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
6399 if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
6400 rc = sprintf(buf, "%pI6\n",
6401 fnode_conn->link_local_ipv6_addr);
6403 rc = sprintf(buf, "\n");
6405 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
6406 rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
6408 case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
6409 if (fnode_sess->discovery_parent_type == DDB_ISNS)
6410 parent_type = ISCSI_DISC_PARENT_ISNS;
6411 else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
6412 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
6413 else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
6414 parent_type = ISCSI_DISC_PARENT_SENDTGT;
6416 parent_type = ISCSI_DISC_PARENT_UNKNOWN;
6418 rc = sprintf(buf, "%s\n",
6419 iscsi_get_discovery_parent_name(parent_type));
6421 case ISCSI_FLASHNODE_NAME:
6422 if (fnode_sess->targetname)
6423 rc = sprintf(buf, "%s\n", fnode_sess->targetname);
6425 rc = sprintf(buf, "\n");
6427 case ISCSI_FLASHNODE_TPGT:
6428 rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
6430 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
6431 rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
6433 case ISCSI_FLASHNODE_TCP_RECV_WSF:
6434 rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
6436 case ISCSI_FLASHNODE_CHAP_OUT_IDX:
6437 rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
6439 case ISCSI_FLASHNODE_USERNAME:
6440 if (fnode_sess->chap_auth_en) {
6441 qla4xxx_get_uni_chap_at_index(ha,
6444 fnode_sess->chap_out_idx);
6445 rc = sprintf(buf, "%s\n", chap_tbl.name);
6447 rc = sprintf(buf, "\n");
6450 case ISCSI_FLASHNODE_PASSWORD:
6451 if (fnode_sess->chap_auth_en) {
6452 qla4xxx_get_uni_chap_at_index(ha,
6455 fnode_sess->chap_out_idx);
6456 rc = sprintf(buf, "%s\n", chap_tbl.secret);
6458 rc = sprintf(buf, "\n");
6461 case ISCSI_FLASHNODE_STATSN:
6462 rc = sprintf(buf, "%u\n", fnode_conn->statsn);
6464 case ISCSI_FLASHNODE_EXP_STATSN:
6465 rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
6467 case ISCSI_FLASHNODE_IS_BOOT_TGT:
6468 rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
6480 * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
6481 * @fnode_sess: pointer to session attrs of flash ddb entry
6482 * @fnode_conn: pointer to connection attrs of flash ddb entry
6483 * @data: Parameters and their values to update
6486 * This sets the parameter of flash ddb entry and writes them to flash
6489 qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
6490 struct iscsi_bus_flash_conn *fnode_conn,
6491 void *data, int len)
6493 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
6494 struct scsi_qla_host *ha = to_qla_host(shost);
6495 struct iscsi_flashnode_param_info *fnode_param;
6496 struct nlattr *attr;
6500 nla_for_each_attr(attr, data, len, rem) {
6501 fnode_param = nla_data(attr);
6503 switch (fnode_param->param) {
6504 case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
6505 fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
6507 case ISCSI_FLASHNODE_PORTAL_TYPE:
6508 memcpy(fnode_sess->portal_type, fnode_param->value,
6509 strlen(fnode_sess->portal_type));
6511 case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
6512 fnode_sess->auto_snd_tgt_disable =
6513 fnode_param->value[0];
6515 case ISCSI_FLASHNODE_DISCOVERY_SESS:
6516 fnode_sess->discovery_sess = fnode_param->value[0];
6518 case ISCSI_FLASHNODE_ENTRY_EN:
6519 fnode_sess->entry_state = fnode_param->value[0];
6521 case ISCSI_FLASHNODE_HDR_DGST_EN:
6522 fnode_conn->hdrdgst_en = fnode_param->value[0];
6524 case ISCSI_FLASHNODE_DATA_DGST_EN:
6525 fnode_conn->datadgst_en = fnode_param->value[0];
6527 case ISCSI_FLASHNODE_IMM_DATA_EN:
6528 fnode_sess->imm_data_en = fnode_param->value[0];
6530 case ISCSI_FLASHNODE_INITIAL_R2T_EN:
6531 fnode_sess->initial_r2t_en = fnode_param->value[0];
6533 case ISCSI_FLASHNODE_DATASEQ_INORDER:
6534 fnode_sess->dataseq_inorder_en = fnode_param->value[0];
6536 case ISCSI_FLASHNODE_PDU_INORDER:
6537 fnode_sess->pdu_inorder_en = fnode_param->value[0];
6539 case ISCSI_FLASHNODE_CHAP_AUTH_EN:
6540 fnode_sess->chap_auth_en = fnode_param->value[0];
6542 case ISCSI_FLASHNODE_SNACK_REQ_EN:
6543 fnode_conn->snack_req_en = fnode_param->value[0];
6545 case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
6546 fnode_sess->discovery_logout_en = fnode_param->value[0];
6548 case ISCSI_FLASHNODE_BIDI_CHAP_EN:
6549 fnode_sess->bidi_chap_en = fnode_param->value[0];
6551 case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
6552 fnode_sess->discovery_auth_optional =
6553 fnode_param->value[0];
6555 case ISCSI_FLASHNODE_ERL:
6556 fnode_sess->erl = fnode_param->value[0];
6558 case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
6559 fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
6561 case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
6562 fnode_conn->tcp_nagle_disable = fnode_param->value[0];
6564 case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
6565 fnode_conn->tcp_wsf_disable = fnode_param->value[0];
6567 case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
6568 fnode_conn->tcp_timer_scale = fnode_param->value[0];
6570 case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
6571 fnode_conn->tcp_timestamp_en = fnode_param->value[0];
6573 case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
6574 fnode_conn->fragment_disable = fnode_param->value[0];
6576 case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
6577 fnode_conn->max_recv_dlength =
6578 *(unsigned *)fnode_param->value;
6580 case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
6581 fnode_conn->max_xmit_dlength =
6582 *(unsigned *)fnode_param->value;
6584 case ISCSI_FLASHNODE_FIRST_BURST:
6585 fnode_sess->first_burst =
6586 *(unsigned *)fnode_param->value;
6588 case ISCSI_FLASHNODE_DEF_TIME2WAIT:
6589 fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
6591 case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
6592 fnode_sess->time2retain =
6593 *(uint16_t *)fnode_param->value;
6595 case ISCSI_FLASHNODE_MAX_R2T:
6596 fnode_sess->max_r2t =
6597 *(uint16_t *)fnode_param->value;
6599 case ISCSI_FLASHNODE_KEEPALIVE_TMO:
6600 fnode_conn->keepalive_timeout =
6601 *(uint16_t *)fnode_param->value;
6603 case ISCSI_FLASHNODE_ISID:
6604 memcpy(fnode_sess->isid, fnode_param->value,
6605 sizeof(fnode_sess->isid));
6607 case ISCSI_FLASHNODE_TSID:
6608 fnode_sess->tsid = *(uint16_t *)fnode_param->value;
6610 case ISCSI_FLASHNODE_PORT:
6611 fnode_conn->port = *(uint16_t *)fnode_param->value;
6613 case ISCSI_FLASHNODE_MAX_BURST:
6614 fnode_sess->max_burst = *(unsigned *)fnode_param->value;
6616 case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
6617 fnode_sess->default_taskmgmt_timeout =
6618 *(uint16_t *)fnode_param->value;
6620 case ISCSI_FLASHNODE_IPADDR:
6621 memcpy(fnode_conn->ipaddress, fnode_param->value,
6624 case ISCSI_FLASHNODE_ALIAS:
6625 rc = iscsi_switch_str_param(&fnode_sess->targetalias,
6626 (char *)fnode_param->value);
6628 case ISCSI_FLASHNODE_REDIRECT_IPADDR:
6629 memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
6632 case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
6633 fnode_conn->max_segment_size =
6634 *(unsigned *)fnode_param->value;
6636 case ISCSI_FLASHNODE_LOCAL_PORT:
6637 fnode_conn->local_port =
6638 *(uint16_t *)fnode_param->value;
6640 case ISCSI_FLASHNODE_IPV4_TOS:
6641 fnode_conn->ipv4_tos = fnode_param->value[0];
6643 case ISCSI_FLASHNODE_IPV6_TC:
6644 fnode_conn->ipv6_traffic_class = fnode_param->value[0];
6646 case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
6647 fnode_conn->ipv6_flow_label = fnode_param->value[0];
6649 case ISCSI_FLASHNODE_NAME:
6650 rc = iscsi_switch_str_param(&fnode_sess->targetname,
6651 (char *)fnode_param->value);
6653 case ISCSI_FLASHNODE_TPGT:
6654 fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
6656 case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
6657 memcpy(fnode_conn->link_local_ipv6_addr,
6658 fnode_param->value, IPv6_ADDR_LEN);
6660 case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
6661 fnode_sess->discovery_parent_idx =
6662 *(uint16_t *)fnode_param->value;
6664 case ISCSI_FLASHNODE_TCP_XMIT_WSF:
6665 fnode_conn->tcp_xmit_wsf =
6666 *(uint8_t *)fnode_param->value;
6668 case ISCSI_FLASHNODE_TCP_RECV_WSF:
6669 fnode_conn->tcp_recv_wsf =
6670 *(uint8_t *)fnode_param->value;
6672 case ISCSI_FLASHNODE_STATSN:
6673 fnode_conn->statsn = *(uint32_t *)fnode_param->value;
6675 case ISCSI_FLASHNODE_EXP_STATSN:
6676 fnode_conn->exp_statsn =
6677 *(uint32_t *)fnode_param->value;
6680 ql4_printk(KERN_ERR, ha,
6681 "%s: No such sysfs attribute\n", __func__);
6683 goto exit_set_param;
6687 rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
6694 * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
6695 * @fnode_sess: pointer to session attrs of flash ddb entry
6697 * This invalidates the flash ddb entry at the given index
6699 static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
6701 struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
6702 struct scsi_qla_host *ha = to_qla_host(shost);
6703 uint32_t dev_db_start_offset;
6704 uint32_t dev_db_end_offset;
6705 struct dev_db_entry *fw_ddb_entry = NULL;
6706 dma_addr_t fw_ddb_entry_dma;
6707 uint16_t *ddb_cookie = NULL;
6708 size_t ddb_size = 0;
6713 if (fnode_sess->is_boot_target) {
6715 DEBUG2(ql4_printk(KERN_ERR, ha,
6716 "%s: Deletion of boot target entry is not permitted.\n",
6721 if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
6724 if (is_qla40XX(ha)) {
6725 dev_db_start_offset = FLASH_OFFSET_DB_INFO;
6726 dev_db_end_offset = FLASH_OFFSET_DB_END;
6727 dev_db_start_offset += (fnode_sess->target_id *
6728 sizeof(*fw_ddb_entry));
6729 ddb_size = sizeof(*fw_ddb_entry);
6731 dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
6732 (ha->hw.flt_region_ddb << 2);
6733 /* flt_ddb_size is DDB table size for both ports
6734 * so divide it by 2 to calculate the offset for second port
6736 if (ha->port_num == 1)
6737 dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
6739 dev_db_end_offset = dev_db_start_offset +
6740 (ha->hw.flt_ddb_size / 2);
6742 dev_db_start_offset += (fnode_sess->target_id *
6743 sizeof(*fw_ddb_entry));
6744 dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
6746 ddb_size = sizeof(*ddb_cookie);
6749 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
6750 __func__, dev_db_start_offset, dev_db_end_offset));
6752 if (dev_db_start_offset > dev_db_end_offset) {
6754 DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
6755 __func__, fnode_sess->target_id));
6759 pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
6760 &fw_ddb_entry_dma, GFP_KERNEL);
6763 DEBUG2(ql4_printk(KERN_ERR, ha,
6764 "%s: Unable to allocate dma buffer\n",
6769 if (is_qla40XX(ha)) {
6770 fw_ddb_entry = pddb;
6771 memset(fw_ddb_entry, 0, ddb_size);
6772 ddb_cookie = &fw_ddb_entry->cookie;
6777 /* invalidate the cookie */
6778 *ddb_cookie = 0xFFEE;
6779 qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
6780 ddb_size, FLASH_OPT_RMW_COMMIT);
6783 target_id = fnode_sess->target_id;
6784 iscsi_destroy_flashnode_sess(fnode_sess);
6785 ql4_printk(KERN_INFO, ha,
6786 "%s: session and conn entries for flashnode %u of host %lu deleted\n",
6787 __func__, target_id, ha->host_no);
6790 dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
6796 * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
6797 * @ha: pointer to adapter structure
6799 * Export the firmware DDB for all send targets and normal targets to sysfs.
6801 static int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
6803 struct dev_db_entry *fw_ddb_entry = NULL;
6804 dma_addr_t fw_ddb_entry_dma;
6807 int ret = QLA_SUCCESS;
6809 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
6810 sizeof(*fw_ddb_entry),
6811 &fw_ddb_entry_dma, GFP_KERNEL);
6812 if (!fw_ddb_entry) {
6813 DEBUG2(ql4_printk(KERN_ERR, ha,
6814 "%s: Unable to allocate dma buffer\n",
6819 max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
6822 for (idx = 0; idx < max_ddbs; idx++) {
6823 if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
6827 ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
6834 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
6840 static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
6842 iscsi_destroy_all_flashnode(ha->host);
6846 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
6847 * @ha: pointer to adapter structure
6848 * @is_reset: Is this init path or reset path
6850 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
6851 * using connection open, then create the list of normal targets (nt)
6852 * from firmware DDBs. Based on the list of nt setup session and connection
6855 void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
6858 struct list_head list_st, list_nt;
6859 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
6860 unsigned long wtime;
6862 if (!test_bit(AF_LINK_UP, &ha->flags)) {
6863 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
6864 ha->is_reset = is_reset;
6868 INIT_LIST_HEAD(&list_st);
6869 INIT_LIST_HEAD(&list_nt);
6871 qla4xxx_build_st_list(ha, &list_st);
6873 /* Before issuing conn open mbox, ensure all IPs states are configured
6874 * Note, conn open fails if IPs are not configured
6876 qla4xxx_wait_for_ip_configuration(ha);
6878 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
6879 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
6880 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
6883 /* Wait to ensure all sendtargets are done for min 12 sec wait */
6884 tmo = ((ha->def_timeout > LOGIN_TOV) &&
6885 (ha->def_timeout < LOGIN_TOV * 10) ?
6886 ha->def_timeout : LOGIN_TOV);
6888 DEBUG2(ql4_printk(KERN_INFO, ha,
6889 "Default time to wait for build ddb %d\n", tmo));
6891 wtime = jiffies + (HZ * tmo);
6893 if (list_empty(&list_st))
6896 qla4xxx_remove_failed_ddb(ha, &list_st);
6897 schedule_timeout_uninterruptible(HZ / 10);
6898 } while (time_after(wtime, jiffies));
6900 /* Free up the sendtargets list */
6901 qla4xxx_free_ddb_list(&list_st);
6903 qla4xxx_build_nt_list(ha, &list_nt, is_reset);
6905 qla4xxx_free_ddb_list(&list_nt);
6907 qla4xxx_free_ddb_index(ha);
6911 * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
6913 * @ha: pointer to adapter structure
6915 * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
6916 * set in DDB and we will wait for login response of boot targets during
6919 static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
6921 struct ddb_entry *ddb_entry;
6922 struct dev_db_entry *fw_ddb_entry = NULL;
6923 dma_addr_t fw_ddb_entry_dma;
6924 unsigned long wtime;
6926 int max_ddbs, idx, ret;
6928 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
6931 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6932 &fw_ddb_entry_dma, GFP_KERNEL);
6933 if (!fw_ddb_entry) {
6934 ql4_printk(KERN_ERR, ha,
6935 "%s: Unable to allocate dma buffer\n", __func__);
6936 goto exit_login_resp;
6939 wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
6941 for (idx = 0; idx < max_ddbs; idx++) {
6942 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
6943 if (ddb_entry == NULL)
6946 if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
6947 DEBUG2(ql4_printk(KERN_INFO, ha,
6948 "%s: DDB index [%d]\n", __func__,
6949 ddb_entry->fw_ddb_index));
6951 ret = qla4xxx_get_fwddb_entry(ha,
6952 ddb_entry->fw_ddb_index,
6953 fw_ddb_entry, fw_ddb_entry_dma,
6954 NULL, NULL, &ddb_state, NULL,
6956 if (ret == QLA_ERROR)
6957 goto exit_login_resp;
6959 if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
6960 (ddb_state == DDB_DS_SESSION_FAILED))
6963 schedule_timeout_uninterruptible(HZ);
6965 } while ((time_after(wtime, jiffies)));
6967 if (!time_after(wtime, jiffies)) {
6968 DEBUG2(ql4_printk(KERN_INFO, ha,
6969 "%s: Login response wait timer expired\n",
6971 goto exit_login_resp;
6978 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
6979 fw_ddb_entry, fw_ddb_entry_dma);
6983 * qla4xxx_probe_adapter - callback function to probe HBA
6984 * @pdev: pointer to pci_dev structure
6985 * @pci_device_id: pointer to pci_device entry
6987 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
6988 * It returns zero if successful. It also initializes all data necessary for
6991 static int qla4xxx_probe_adapter(struct pci_dev *pdev,
6992 const struct pci_device_id *ent)
6994 int ret = -ENODEV, status;
6995 struct Scsi_Host *host;
6996 struct scsi_qla_host *ha;
6997 uint8_t init_retry_count = 0;
6999 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
7002 if (pci_enable_device(pdev))
7005 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
7008 "qla4xxx: Couldn't allocate host from scsi layer!\n");
7009 goto probe_disable_device;
7012 /* Clear our data area */
7013 ha = to_qla_host(host);
7014 memset(ha, 0, sizeof(*ha));
7016 /* Save the information from PCI BIOS. */
7019 ha->host_no = host->host_no;
7020 ha->func_num = PCI_FUNC(ha->pdev->devfn);
7022 pci_enable_pcie_error_reporting(pdev);
7024 /* Setup Runtime configurable options */
7025 if (is_qla8022(ha)) {
7026 ha->isp_ops = &qla4_82xx_isp_ops;
7027 ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
7028 ha->qdr_sn_window = -1;
7029 ha->ddr_mn_window = -1;
7030 ha->curr_window = 255;
7031 nx_legacy_intr = &legacy_intr[ha->func_num];
7032 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
7033 ha->nx_legacy_intr.tgt_status_reg =
7034 nx_legacy_intr->tgt_status_reg;
7035 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
7036 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
7037 } else if (is_qla8032(ha) || is_qla8042(ha)) {
7038 ha->isp_ops = &qla4_83xx_isp_ops;
7039 ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
7041 ha->isp_ops = &qla4xxx_isp_ops;
7044 if (is_qla80XX(ha)) {
7045 rwlock_init(&ha->hw_lock);
7046 ha->pf_bit = ha->func_num << 16;
7047 /* Set EEH reset type to fundamental if required by hba */
7048 pdev->needs_freset = 1;
7051 /* Configure PCI I/O space. */
7052 ret = ha->isp_ops->iospace_config(ha);
7054 goto probe_failed_ioconfig;
7056 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
7057 pdev->device, pdev->irq, ha->reg);
7059 qla4xxx_config_dma_addressing(ha);
7061 /* Initialize lists and spinlocks. */
7062 INIT_LIST_HEAD(&ha->free_srb_q);
7064 mutex_init(&ha->mbox_sem);
7065 mutex_init(&ha->chap_sem);
7066 init_completion(&ha->mbx_intr_comp);
7067 init_completion(&ha->disable_acb_comp);
7069 spin_lock_init(&ha->hardware_lock);
7070 spin_lock_init(&ha->work_lock);
7072 /* Initialize work list */
7073 INIT_LIST_HEAD(&ha->work_list);
7075 /* Allocate dma buffers */
7076 if (qla4xxx_mem_alloc(ha)) {
7077 ql4_printk(KERN_WARNING, ha,
7078 "[ERROR] Failed to allocate memory for adapter\n");
7084 host->cmd_per_lun = 3;
7085 host->max_channel = 0;
7086 host->max_lun = MAX_LUNS - 1;
7087 host->max_id = MAX_TARGETS;
7088 host->max_cmd_len = IOCB_MAX_CDB_LEN;
7089 host->can_queue = MAX_SRBS ;
7090 host->transportt = qla4xxx_scsi_transport;
7092 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
7094 ql4_printk(KERN_WARNING, ha,
7095 "%s: scsi_init_shared_tag_map failed\n", __func__);
7099 pci_set_drvdata(pdev, ha);
7101 ret = scsi_add_host(host, &pdev->dev);
7106 qla4_8xxx_get_flash_info(ha);
7108 if (is_qla8032(ha) || is_qla8042(ha)) {
7109 qla4_83xx_read_reset_template(ha);
7111 * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
7112 * If DONRESET_BIT0 is set, drivers should not set dev_state
7113 * to NEED_RESET. But if NEED_RESET is set, drivers should
7114 * should honor the reset.
7116 if (ql4xdontresethba == 1)
7117 qla4_83xx_set_idc_dontreset(ha);
7121 * Initialize the Host adapter request/response queues and
7123 * NOTE: interrupts enabled upon successful completion
7125 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
7127 /* Dont retry adapter initialization if IRQ allocation failed */
7128 if (is_qla80XX(ha) && !test_bit(AF_IRQ_ATTACHED, &ha->flags)) {
7129 ql4_printk(KERN_WARNING, ha, "%s: Skipping retry of adapter initialization\n",
7131 goto skip_retry_init;
7134 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
7135 init_retry_count++ < MAX_INIT_RETRIES) {
7137 if (is_qla80XX(ha)) {
7138 ha->isp_ops->idc_lock(ha);
7139 dev_state = qla4_8xxx_rd_direct(ha,
7140 QLA8XXX_CRB_DEV_STATE);
7141 ha->isp_ops->idc_unlock(ha);
7142 if (dev_state == QLA8XXX_DEV_FAILED) {
7143 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
7144 "initialize adapter. H/W is in failed state\n",
7149 DEBUG2(printk("scsi: %s: retrying adapter initialization "
7150 "(%d)\n", __func__, init_retry_count));
7152 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
7155 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
7159 if (!test_bit(AF_ONLINE, &ha->flags)) {
7160 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
7162 if ((is_qla8022(ha) && ql4xdontresethba) ||
7163 ((is_qla8032(ha) || is_qla8042(ha)) &&
7164 qla4_83xx_idc_dontreset(ha))) {
7165 /* Put the device in failed state. */
7166 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
7167 ha->isp_ops->idc_lock(ha);
7168 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
7169 QLA8XXX_DEV_FAILED);
7170 ha->isp_ops->idc_unlock(ha);
7176 /* Startup the kernel thread for this host adapter. */
7177 DEBUG2(printk("scsi: %s: Starting kernel thread for "
7178 "qla4xxx_dpc\n", __func__));
7179 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
7180 ha->dpc_thread = create_singlethread_workqueue(buf);
7181 if (!ha->dpc_thread) {
7182 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
7186 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
7188 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
7191 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
7197 * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
7198 * (which is called indirectly by qla4xxx_initialize_adapter),
7199 * so that irqs will be registered after crbinit but before
7202 if (is_qla40XX(ha)) {
7203 ret = qla4xxx_request_irqs(ha);
7205 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
7206 "interrupt %d already in use.\n", pdev->irq);
7211 pci_save_state(ha->pdev);
7212 ha->isp_ops->enable_intrs(ha);
7214 /* Start timer thread. */
7215 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
7217 set_bit(AF_INIT_DONE, &ha->flags);
7219 qla4_8xxx_alloc_sysfs_attr(ha);
7222 " QLogic iSCSI HBA Driver version: %s\n"
7223 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
7224 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
7225 ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
7226 ha->fw_info.fw_patch, ha->fw_info.fw_build);
7228 /* Set the driver version */
7230 qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
7232 if (qla4xxx_setup_boot_info(ha))
7233 ql4_printk(KERN_ERR, ha,
7234 "%s: No iSCSI boot target configured\n", __func__);
7236 if (qla4xxx_sysfs_ddb_export(ha))
7237 ql4_printk(KERN_ERR, ha,
7238 "%s: Error exporting ddb to sysfs\n", __func__);
7240 /* Perform the build ddb list and login to each */
7241 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
7242 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
7243 qla4xxx_wait_login_resp_boot_tgt(ha);
7245 qla4xxx_create_chap_list(ha);
7247 qla4xxx_create_ifaces(ha);
7251 scsi_remove_host(ha->host);
7254 qla4xxx_free_adapter(ha);
7256 probe_failed_ioconfig:
7257 pci_disable_pcie_error_reporting(pdev);
7258 scsi_host_put(ha->host);
7260 probe_disable_device:
7261 pci_disable_device(pdev);
7267 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
7268 * @ha: pointer to adapter structure
7270 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
7271 * so that the other port will not re-initialize while in the process of
7272 * removing the ha due to driver unload or hba hotplug.
7274 static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
7276 struct scsi_qla_host *other_ha = NULL;
7277 struct pci_dev *other_pdev = NULL;
7278 int fn = ISP4XXX_PCI_FN_2;
7280 /*iscsi function numbers for ISP4xxx is 1 and 3*/
7281 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
7282 fn = ISP4XXX_PCI_FN_1;
7285 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
7286 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
7289 /* Get other_ha if other_pdev is valid and state is enable*/
7291 if (atomic_read(&other_pdev->enable_cnt)) {
7292 other_ha = pci_get_drvdata(other_pdev);
7294 set_bit(AF_HA_REMOVAL, &other_ha->flags);
7295 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
7296 "Prevent %s reinit\n", __func__,
7297 dev_name(&other_ha->pdev->dev)));
7300 pci_dev_put(other_pdev);
7304 static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
7306 struct ddb_entry *ddb_entry;
7310 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
7312 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
7313 if ((ddb_entry != NULL) &&
7314 (ddb_entry->ddb_type == FLASH_DDB)) {
7316 options = LOGOUT_OPTION_CLOSE_SESSION;
7317 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
7319 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
7322 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
7324 * we have decremented the reference count of the driver
7325 * when we setup the session to have the driver unload
7326 * to be seamless without actually destroying the
7329 try_module_get(qla4xxx_iscsi_transport.owner);
7330 iscsi_destroy_endpoint(ddb_entry->conn->ep);
7331 qla4xxx_free_ddb(ha, ddb_entry);
7332 iscsi_session_teardown(ddb_entry->sess);
7337 * qla4xxx_remove_adapter - callback function to remove adapter.
7338 * @pci_dev: PCI device pointer
7340 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
7342 struct scsi_qla_host *ha;
7345 * If the PCI device is disabled then it means probe_adapter had
7346 * failed and resources already cleaned up on probe_adapter exit.
7348 if (!pci_is_enabled(pdev))
7351 ha = pci_get_drvdata(pdev);
7354 qla4xxx_prevent_other_port_reinit(ha);
7356 /* destroy iface from sysfs */
7357 qla4xxx_destroy_ifaces(ha);
7359 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
7360 iscsi_boot_destroy_kset(ha->boot_kset);
7362 qla4xxx_destroy_fw_ddb_session(ha);
7363 qla4_8xxx_free_sysfs_attr(ha);
7365 qla4xxx_sysfs_ddb_remove(ha);
7366 scsi_remove_host(ha->host);
7368 qla4xxx_free_adapter(ha);
7370 scsi_host_put(ha->host);
7372 pci_disable_pcie_error_reporting(pdev);
7373 pci_disable_device(pdev);
7374 pci_set_drvdata(pdev, NULL);
7378 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
7381 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
7382 * supported addressing method.
7384 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
7388 /* Update our PCI device dma_mask for full 64 bit mask */
7389 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
7390 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
7391 dev_dbg(&ha->pdev->dev,
7392 "Failed to set 64 bit PCI consistent mask; "
7394 retval = pci_set_consistent_dma_mask(ha->pdev,
7398 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
7401 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
7403 struct iscsi_cls_session *cls_sess;
7404 struct iscsi_session *sess;
7405 struct ddb_entry *ddb;
7406 int queue_depth = QL4_DEF_QDEPTH;
7408 cls_sess = starget_to_session(sdev->sdev_target);
7409 sess = cls_sess->dd_data;
7410 ddb = sess->dd_data;
7412 sdev->hostdata = ddb;
7413 sdev->tagged_supported = 1;
7415 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
7416 queue_depth = ql4xmaxqdepth;
7418 scsi_activate_tcq(sdev, queue_depth);
7422 static int qla4xxx_slave_configure(struct scsi_device *sdev)
7424 sdev->tagged_supported = 1;
7428 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
7430 scsi_deactivate_tcq(sdev, 1);
7433 static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
7436 if (!ql4xqfulltracking)
7439 return iscsi_change_queue_depth(sdev, qdepth, reason);
7443 * qla4xxx_del_from_active_array - returns an active srb
7444 * @ha: Pointer to host adapter structure.
7445 * @index: index into the active_array
7447 * This routine removes and returns the srb at the specified index
7449 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
7452 struct srb *srb = NULL;
7453 struct scsi_cmnd *cmd = NULL;
7455 cmd = scsi_host_find_tag(ha->host, index);
7459 srb = (struct srb *)CMD_SP(cmd);
7463 /* update counters */
7464 if (srb->flags & SRB_DMA_VALID) {
7465 ha->iocb_cnt -= srb->iocb_cnt;
7467 srb->cmd->host_scribble =
7468 (unsigned char *)(unsigned long) MAX_SRBS;
7474 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
7475 * @ha: Pointer to host adapter structure.
7476 * @cmd: Scsi Command to wait on.
7478 * This routine waits for the command to be returned by the Firmware
7479 * for some max time.
7481 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
7482 struct scsi_cmnd *cmd)
7486 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
7489 /* Dont wait on command if PCI error is being handled
7492 if (unlikely(pci_channel_offline(ha->pdev)) ||
7493 (test_bit(AF_EEH_BUSY, &ha->flags))) {
7494 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
7495 ha->host_no, __func__);
7500 /* Checking to see if its returned to OS */
7501 rp = (struct srb *) CMD_SP(cmd);
7508 } while (max_wait_time--);
7514 * qla4xxx_wait_for_hba_online - waits for HBA to come online
7515 * @ha: Pointer to host adapter structure
7517 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
7519 unsigned long wait_online;
7521 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
7522 while (time_before(jiffies, wait_online)) {
7534 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
7535 * @ha: pointer to HBA
7539 * This function waits for all outstanding commands to a lun to complete. It
7540 * returns 0 if all pending commands are returned and 1 otherwise.
7542 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
7543 struct scsi_target *stgt,
7544 struct scsi_device *sdev)
7548 struct scsi_cmnd *cmd;
7551 * Waiting for all commands for the designated target or dev
7552 * in the active array
7554 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
7555 cmd = scsi_host_find_tag(ha->host, cnt);
7556 if (cmd && stgt == scsi_target(cmd->device) &&
7557 (!sdev || sdev == cmd->device)) {
7558 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
7568 * qla4xxx_eh_abort - callback for abort task.
7569 * @cmd: Pointer to Linux's SCSI command structure
7571 * This routine is called by the Linux OS to abort the specified
7574 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
7576 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
7577 unsigned int id = cmd->device->id;
7578 unsigned int lun = cmd->device->lun;
7579 unsigned long flags;
7580 struct srb *srb = NULL;
7584 ql4_printk(KERN_INFO, ha,
7585 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
7586 ha->host_no, id, lun, cmd);
7588 spin_lock_irqsave(&ha->hardware_lock, flags);
7589 srb = (struct srb *) CMD_SP(cmd);
7591 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7594 kref_get(&srb->srb_ref);
7595 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7597 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
7598 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
7599 ha->host_no, id, lun));
7602 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
7603 ha->host_no, id, lun));
7607 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
7609 /* Wait for command to complete */
7611 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
7612 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
7613 ha->host_no, id, lun));
7618 ql4_printk(KERN_INFO, ha,
7619 "scsi%ld:%d:%d: Abort command - %s\n",
7620 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
7626 * qla4xxx_eh_device_reset - callback for target reset.
7627 * @cmd: Pointer to Linux's SCSI command structure
7629 * This routine is called by the Linux OS to reset all luns on the
7632 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
7634 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
7635 struct ddb_entry *ddb_entry = cmd->device->hostdata;
7636 int ret = FAILED, stat;
7641 ret = iscsi_block_scsi_eh(cmd);
7646 ql4_printk(KERN_INFO, ha,
7647 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
7648 cmd->device->channel, cmd->device->id, cmd->device->lun);
7650 DEBUG2(printk(KERN_INFO
7651 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
7652 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
7653 cmd, jiffies, cmd->request->timeout / HZ,
7654 ha->dpc_flags, cmd->result, cmd->allowed));
7656 /* FIXME: wait for hba to go online */
7657 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
7658 if (stat != QLA_SUCCESS) {
7659 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
7660 goto eh_dev_reset_done;
7663 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
7665 ql4_printk(KERN_INFO, ha,
7666 "DEVICE RESET FAILED - waiting for "
7668 goto eh_dev_reset_done;
7672 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
7673 MM_LUN_RESET) != QLA_SUCCESS)
7674 goto eh_dev_reset_done;
7676 ql4_printk(KERN_INFO, ha,
7677 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
7678 ha->host_no, cmd->device->channel, cmd->device->id,
7689 * qla4xxx_eh_target_reset - callback for target reset.
7690 * @cmd: Pointer to Linux's SCSI command structure
7692 * This routine is called by the Linux OS to reset the target.
7694 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
7696 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
7697 struct ddb_entry *ddb_entry = cmd->device->hostdata;
7703 ret = iscsi_block_scsi_eh(cmd);
7707 starget_printk(KERN_INFO, scsi_target(cmd->device),
7708 "WARM TARGET RESET ISSUED.\n");
7710 DEBUG2(printk(KERN_INFO
7711 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
7712 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
7713 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
7714 ha->dpc_flags, cmd->result, cmd->allowed));
7716 stat = qla4xxx_reset_target(ha, ddb_entry);
7717 if (stat != QLA_SUCCESS) {
7718 starget_printk(KERN_INFO, scsi_target(cmd->device),
7719 "WARM TARGET RESET FAILED.\n");
7723 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
7725 starget_printk(KERN_INFO, scsi_target(cmd->device),
7726 "WARM TARGET DEVICE RESET FAILED - "
7727 "waiting for commands.\n");
7732 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
7733 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
7734 starget_printk(KERN_INFO, scsi_target(cmd->device),
7735 "WARM TARGET DEVICE RESET FAILED - "
7736 "marker iocb failed.\n");
7740 starget_printk(KERN_INFO, scsi_target(cmd->device),
7741 "WARM TARGET RESET SUCCEEDED.\n");
7746 * qla4xxx_is_eh_active - check if error handler is running
7747 * @shost: Pointer to SCSI Host struct
7749 * This routine finds that if reset host is called in EH
7750 * scenario or from some application like sg_reset
7752 static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
7754 if (shost->shost_state == SHOST_RECOVERY)
7760 * qla4xxx_eh_host_reset - kernel callback
7761 * @cmd: Pointer to Linux's SCSI command structure
7763 * This routine is invoked by the Linux kernel to perform fatal error
7764 * recovery on the specified adapter.
7766 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
7768 int return_status = FAILED;
7769 struct scsi_qla_host *ha;
7771 ha = to_qla_host(cmd->device->host);
7773 if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
7774 qla4_83xx_set_idc_dontreset(ha);
7777 * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
7778 * protocol drivers, we should not set device_state to NEED_RESET
7780 if (ql4xdontresethba ||
7781 ((is_qla8032(ha) || is_qla8042(ha)) &&
7782 qla4_83xx_idc_dontreset(ha))) {
7783 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
7784 ha->host_no, __func__));
7786 /* Clear outstanding srb in queues */
7787 if (qla4xxx_is_eh_active(cmd->device->host))
7788 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
7793 ql4_printk(KERN_INFO, ha,
7794 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
7795 cmd->device->channel, cmd->device->id, cmd->device->lun);
7797 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
7798 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
7799 "DEAD.\n", ha->host_no, cmd->device->channel,
7805 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
7807 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
7809 set_bit(DPC_RESET_HA, &ha->dpc_flags);
7812 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
7813 return_status = SUCCESS;
7815 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
7816 return_status == FAILED ? "FAILED" : "SUCCEEDED");
7818 return return_status;
7821 static int qla4xxx_context_reset(struct scsi_qla_host *ha)
7823 uint32_t mbox_cmd[MBOX_REG_COUNT];
7824 uint32_t mbox_sts[MBOX_REG_COUNT];
7825 struct addr_ctrl_blk_def *acb = NULL;
7826 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
7827 int rval = QLA_SUCCESS;
7830 acb = dma_alloc_coherent(&ha->pdev->dev,
7831 sizeof(struct addr_ctrl_blk_def),
7832 &acb_dma, GFP_KERNEL);
7834 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
7837 goto exit_port_reset;
7840 memset(acb, 0, acb_len);
7842 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
7843 if (rval != QLA_SUCCESS) {
7848 rval = qla4xxx_disable_acb(ha);
7849 if (rval != QLA_SUCCESS) {
7854 wait_for_completion_timeout(&ha->disable_acb_comp,
7855 DISABLE_ACB_TOV * HZ);
7857 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
7858 if (rval != QLA_SUCCESS) {
7864 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
7867 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
7868 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
7872 static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
7874 struct scsi_qla_host *ha = to_qla_host(shost);
7875 int rval = QLA_SUCCESS;
7878 if (ql4xdontresethba) {
7879 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
7882 goto exit_host_reset;
7885 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
7886 goto recover_adapter;
7888 switch (reset_type) {
7889 case SCSI_ADAPTER_RESET:
7890 set_bit(DPC_RESET_HA, &ha->dpc_flags);
7892 case SCSI_FIRMWARE_RESET:
7893 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
7895 /* set firmware context reset */
7896 set_bit(DPC_RESET_HA_FW_CONTEXT,
7899 rval = qla4xxx_context_reset(ha);
7900 goto exit_host_reset;
7907 /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
7908 * reset is issued by application */
7909 if ((is_qla8032(ha) || is_qla8042(ha)) &&
7910 test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
7911 idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
7912 qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
7913 (idc_ctrl | GRACEFUL_RESET_BIT1));
7916 rval = qla4xxx_recover_adapter(ha);
7917 if (rval != QLA_SUCCESS) {
7918 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
7927 /* PCI AER driver recovers from all correctable errors w/o
7928 * driver intervention. For uncorrectable errors PCI AER
7929 * driver calls the following device driver's callbacks
7931 * - Fatal Errors - link_reset
7932 * - Non-Fatal Errors - driver's pci_error_detected() which
7933 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
7935 * PCI AER driver calls
7936 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
7937 * returns RECOVERED or NEED_RESET if fw_hung
7938 * NEED_RESET - driver's slot_reset()
7939 * DISCONNECT - device is dead & cannot recover
7940 * RECOVERED - driver's pci_resume()
7942 static pci_ers_result_t
7943 qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
7945 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
7947 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
7948 ha->host_no, __func__, state);
7950 if (!is_aer_supported(ha))
7951 return PCI_ERS_RESULT_NONE;
7954 case pci_channel_io_normal:
7955 clear_bit(AF_EEH_BUSY, &ha->flags);
7956 return PCI_ERS_RESULT_CAN_RECOVER;
7957 case pci_channel_io_frozen:
7958 set_bit(AF_EEH_BUSY, &ha->flags);
7959 qla4xxx_mailbox_premature_completion(ha);
7960 qla4xxx_free_irqs(ha);
7961 pci_disable_device(pdev);
7962 /* Return back all IOs */
7963 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
7964 return PCI_ERS_RESULT_NEED_RESET;
7965 case pci_channel_io_perm_failure:
7966 set_bit(AF_EEH_BUSY, &ha->flags);
7967 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
7968 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
7969 return PCI_ERS_RESULT_DISCONNECT;
7971 return PCI_ERS_RESULT_NEED_RESET;
7975 * qla4xxx_pci_mmio_enabled() gets called if
7976 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
7977 * and read/write to the device still works.
7979 static pci_ers_result_t
7980 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
7982 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
7984 if (!is_aer_supported(ha))
7985 return PCI_ERS_RESULT_NONE;
7987 return PCI_ERS_RESULT_RECOVERED;
7990 static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
7992 uint32_t rval = QLA_ERROR;
7994 struct pci_dev *other_pdev = NULL;
7996 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
7998 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
8000 if (test_bit(AF_ONLINE, &ha->flags)) {
8001 clear_bit(AF_ONLINE, &ha->flags);
8002 clear_bit(AF_LINK_UP, &ha->flags);
8003 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
8004 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
8007 fn = PCI_FUNC(ha->pdev->devfn);
8010 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
8011 "func %x\n", ha->host_no, __func__, fn);
8012 /* Get the pci device given the domain, bus,
8013 * slot/function number */
8015 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
8016 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
8022 if (atomic_read(&other_pdev->enable_cnt)) {
8023 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
8024 "func in enabled state%x\n", ha->host_no,
8026 pci_dev_put(other_pdev);
8029 pci_dev_put(other_pdev);
8032 /* The first function on the card, the reset owner will
8033 * start & initialize the firmware. The other functions
8034 * on the card will reset the firmware context
8037 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
8038 "0x%x is the owner\n", ha->host_no, __func__,
8041 ha->isp_ops->idc_lock(ha);
8042 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8044 ha->isp_ops->idc_unlock(ha);
8046 rval = qla4_8xxx_update_idc_reg(ha);
8047 if (rval == QLA_ERROR) {
8048 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
8049 ha->host_no, __func__);
8050 ha->isp_ops->idc_lock(ha);
8051 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8052 QLA8XXX_DEV_FAILED);
8053 ha->isp_ops->idc_unlock(ha);
8054 goto exit_error_recovery;
8057 clear_bit(AF_FW_RECOVERY, &ha->flags);
8058 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
8060 if (rval != QLA_SUCCESS) {
8061 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
8062 "FAILED\n", ha->host_no, __func__);
8063 ha->isp_ops->idc_lock(ha);
8064 qla4_8xxx_clear_drv_active(ha);
8065 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8066 QLA8XXX_DEV_FAILED);
8067 ha->isp_ops->idc_unlock(ha);
8069 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
8070 "READY\n", ha->host_no, __func__);
8071 ha->isp_ops->idc_lock(ha);
8072 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
8074 /* Clear driver state register */
8075 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
8076 qla4_8xxx_set_drv_active(ha);
8077 ha->isp_ops->idc_unlock(ha);
8078 ha->isp_ops->enable_intrs(ha);
8081 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
8082 "the reset owner\n", ha->host_no, __func__,
8084 if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
8085 QLA8XXX_DEV_READY)) {
8086 clear_bit(AF_FW_RECOVERY, &ha->flags);
8087 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
8088 if (rval == QLA_SUCCESS)
8089 ha->isp_ops->enable_intrs(ha);
8091 ha->isp_ops->idc_lock(ha);
8092 qla4_8xxx_set_drv_active(ha);
8093 ha->isp_ops->idc_unlock(ha);
8096 exit_error_recovery:
8097 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
8101 static pci_ers_result_t
8102 qla4xxx_pci_slot_reset(struct pci_dev *pdev)
8104 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
8105 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
8108 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
8109 ha->host_no, __func__);
8111 if (!is_aer_supported(ha))
8112 return PCI_ERS_RESULT_NONE;
8114 /* Restore the saved state of PCIe device -
8115 * BAR registers, PCI Config space, PCIX, MSI,
8118 pci_restore_state(pdev);
8120 /* pci_restore_state() clears the saved_state flag of the device
8121 * save restored state which resets saved_state flag
8123 pci_save_state(pdev);
8125 /* Initialize device or resume if in suspended state */
8126 rc = pci_enable_device(pdev);
8128 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
8129 "device after reset\n", ha->host_no, __func__);
8130 goto exit_slot_reset;
8133 ha->isp_ops->disable_intrs(ha);
8135 if (is_qla80XX(ha)) {
8136 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
8137 ret = PCI_ERS_RESULT_RECOVERED;
8138 goto exit_slot_reset;
8140 goto exit_slot_reset;
8144 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
8145 "device after reset\n", ha->host_no, __func__, ret);
8150 qla4xxx_pci_resume(struct pci_dev *pdev)
8152 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
8155 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
8156 ha->host_no, __func__);
8158 ret = qla4xxx_wait_for_hba_online(ha);
8159 if (ret != QLA_SUCCESS) {
8160 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
8161 "resume I/O from slot/link_reset\n", ha->host_no,
8165 pci_cleanup_aer_uncorrect_error_status(pdev);
8166 clear_bit(AF_EEH_BUSY, &ha->flags);
8169 static const struct pci_error_handlers qla4xxx_err_handler = {
8170 .error_detected = qla4xxx_pci_error_detected,
8171 .mmio_enabled = qla4xxx_pci_mmio_enabled,
8172 .slot_reset = qla4xxx_pci_slot_reset,
8173 .resume = qla4xxx_pci_resume,
8176 static struct pci_device_id qla4xxx_pci_tbl[] = {
8178 .vendor = PCI_VENDOR_ID_QLOGIC,
8179 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
8180 .subvendor = PCI_ANY_ID,
8181 .subdevice = PCI_ANY_ID,
8184 .vendor = PCI_VENDOR_ID_QLOGIC,
8185 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
8186 .subvendor = PCI_ANY_ID,
8187 .subdevice = PCI_ANY_ID,
8190 .vendor = PCI_VENDOR_ID_QLOGIC,
8191 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
8192 .subvendor = PCI_ANY_ID,
8193 .subdevice = PCI_ANY_ID,
8196 .vendor = PCI_VENDOR_ID_QLOGIC,
8197 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
8198 .subvendor = PCI_ANY_ID,
8199 .subdevice = PCI_ANY_ID,
8202 .vendor = PCI_VENDOR_ID_QLOGIC,
8203 .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
8204 .subvendor = PCI_ANY_ID,
8205 .subdevice = PCI_ANY_ID,
8208 .vendor = PCI_VENDOR_ID_QLOGIC,
8209 .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
8210 .subvendor = PCI_ANY_ID,
8211 .subdevice = PCI_ANY_ID,
8215 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
8217 static struct pci_driver qla4xxx_pci_driver = {
8218 .name = DRIVER_NAME,
8219 .id_table = qla4xxx_pci_tbl,
8220 .probe = qla4xxx_probe_adapter,
8221 .remove = qla4xxx_remove_adapter,
8222 .err_handler = &qla4xxx_err_handler,
8225 static int __init qla4xxx_module_init(void)
8229 /* Allocate cache for SRBs. */
8230 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
8231 SLAB_HWCACHE_ALIGN, NULL);
8232 if (srb_cachep == NULL) {
8234 "%s: Unable to allocate SRB cache..."
8235 "Failing load!\n", DRIVER_NAME);
8240 /* Derive version string. */
8241 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
8242 if (ql4xextended_error_logging)
8243 strcat(qla4xxx_version_str, "-debug");
8245 qla4xxx_scsi_transport =
8246 iscsi_register_transport(&qla4xxx_iscsi_transport);
8247 if (!qla4xxx_scsi_transport){
8249 goto release_srb_cache;
8252 ret = pci_register_driver(&qla4xxx_pci_driver);
8254 goto unregister_transport;
8256 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
8259 unregister_transport:
8260 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
8262 kmem_cache_destroy(srb_cachep);
8267 static void __exit qla4xxx_module_exit(void)
8269 pci_unregister_driver(&qla4xxx_pci_driver);
8270 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
8271 kmem_cache_destroy(srb_cachep);
8274 module_init(qla4xxx_module_init);
8275 module_exit(qla4xxx_module_exit);
8277 MODULE_AUTHOR("QLogic Corporation");
8278 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
8279 MODULE_LICENSE("GPL");
8280 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);