| /* |
| * QLogic iSCSI HBA Driver |
| * Copyright (c) 2003-2010 QLogic Corporation |
| * |
| * See LICENSE.qla4xxx for copyright and licensing details. |
| */ |
| #include <linux/moduleparam.h> |
| #include <linux/slab.h> |
| #include <linux/blkdev.h> |
| #include <linux/iscsi_boot_sysfs.h> |
| #include <linux/inet.h> |
| |
| #include <scsi/scsi_tcq.h> |
| #include <scsi/scsicam.h> |
| |
| #include "ql4_def.h" |
| #include "ql4_version.h" |
| #include "ql4_glbl.h" |
| #include "ql4_dbg.h" |
| #include "ql4_inline.h" |
| |
| /* |
| * Driver version |
| */ |
| static char qla4xxx_version_str[40]; |
| |
| /* |
| * SRB allocation cache |
| */ |
| static struct kmem_cache *srb_cachep; |
| |
| /* |
| * Module parameter information and variables |
| */ |
| int ql4xdisablesysfsboot = 1; |
| module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR); |
| MODULE_PARM_DESC(ql4xdisablesysfsboot, |
| "Set to disable exporting boot targets to sysfs\n" |
| " 0 - Export boot targets\n" |
| " 1 - Do not export boot targets (Default)"); |
| |
| int ql4xdontresethba = 0; |
| module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR); |
| MODULE_PARM_DESC(ql4xdontresethba, |
| "Don't reset the HBA for driver recovery \n" |
| " 0 - It will reset HBA (Default)\n" |
| " 1 - It will NOT reset HBA"); |
| |
| int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */ |
| module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR); |
| MODULE_PARM_DESC(ql4xextended_error_logging, |
| "Option to enable extended error logging, " |
| "Default is 0 - no logging, 1 - debug logging"); |
| |
| int ql4xenablemsix = 1; |
| module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR); |
| MODULE_PARM_DESC(ql4xenablemsix, |
| "Set to enable MSI or MSI-X interrupt mechanism.\n" |
| " 0 = enable INTx interrupt mechanism.\n" |
| " 1 = enable MSI-X interrupt mechanism (Default).\n" |
| " 2 = enable MSI interrupt mechanism."); |
| |
| #define QL4_DEF_QDEPTH 32 |
| static int ql4xmaxqdepth = QL4_DEF_QDEPTH; |
| module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR); |
| MODULE_PARM_DESC(ql4xmaxqdepth, |
| "Maximum queue depth to report for target devices.\n" |
| " Default: 32."); |
| |
| static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO; |
| module_param(ql4xsess_recovery_tmo, int, S_IRUGO); |
| MODULE_PARM_DESC(ql4xsess_recovery_tmo, |
| "Target Session Recovery Timeout.\n" |
| " Default: 120 sec."); |
| |
| static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha); |
| /* |
| * SCSI host template entry points |
| */ |
| static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha); |
| |
| /* |
| * iSCSI template entry points |
| */ |
| static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
| enum iscsi_param param, char *buf); |
| static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| enum iscsi_host_param param, char *buf); |
| static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, |
| uint32_t len); |
| static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| enum iscsi_param_type param_type, |
| int param, char *buf); |
| static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc); |
| static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost, |
| struct sockaddr *dst_addr, |
| int non_blocking); |
| static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms); |
| static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep); |
| static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| enum iscsi_param param, char *buf); |
| static int qla4xxx_conn_start(struct iscsi_cls_conn *conn); |
| static struct iscsi_cls_conn * |
| qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx); |
| static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| struct iscsi_cls_conn *cls_conn, |
| uint64_t transport_fd, int is_leading); |
| static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn); |
| static struct iscsi_cls_session * |
| qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, |
| uint16_t qdepth, uint32_t initial_cmdsn); |
| static void qla4xxx_session_destroy(struct iscsi_cls_session *sess); |
| static void qla4xxx_task_work(struct work_struct *wdata); |
| static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t); |
| static int qla4xxx_task_xmit(struct iscsi_task *); |
| static void qla4xxx_task_cleanup(struct iscsi_task *); |
| static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session); |
| static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| struct iscsi_stats *stats); |
| /* |
| * SCSI host template entry points |
| */ |
| static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
| static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); |
| static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); |
| static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); |
| static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); |
| static int qla4xxx_slave_alloc(struct scsi_device *device); |
| static int qla4xxx_slave_configure(struct scsi_device *device); |
| static void qla4xxx_slave_destroy(struct scsi_device *sdev); |
| static mode_t ql4_attr_is_visible(int param_type, int param); |
| static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); |
| |
| static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
| QLA82XX_LEGACY_INTR_CONFIG; |
| |
| static struct scsi_host_template qla4xxx_driver_template = { |
| .module = THIS_MODULE, |
| .name = DRIVER_NAME, |
| .proc_name = DRIVER_NAME, |
| .queuecommand = qla4xxx_queuecommand, |
| |
| .eh_abort_handler = qla4xxx_eh_abort, |
| .eh_device_reset_handler = qla4xxx_eh_device_reset, |
| .eh_target_reset_handler = qla4xxx_eh_target_reset, |
| .eh_host_reset_handler = qla4xxx_eh_host_reset, |
| .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
| |
| .slave_configure = qla4xxx_slave_configure, |
| .slave_alloc = qla4xxx_slave_alloc, |
| .slave_destroy = qla4xxx_slave_destroy, |
| |
| .this_id = -1, |
| .cmd_per_lun = 3, |
| .use_clustering = ENABLE_CLUSTERING, |
| .sg_tablesize = SG_ALL, |
| |
| .max_sectors = 0xFFFF, |
| .shost_attrs = qla4xxx_host_attrs, |
| .host_reset = qla4xxx_host_reset, |
| .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, |
| }; |
| |
| static struct iscsi_transport qla4xxx_iscsi_transport = { |
| .owner = THIS_MODULE, |
| .name = DRIVER_NAME, |
| .caps = CAP_TEXT_NEGO | |
| CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST | |
| CAP_DATADGST | CAP_LOGIN_OFFLOAD | |
| CAP_MULTI_R2T, |
| .attr_is_visible = ql4_attr_is_visible, |
| .create_session = qla4xxx_session_create, |
| .destroy_session = qla4xxx_session_destroy, |
| .start_conn = qla4xxx_conn_start, |
| .create_conn = qla4xxx_conn_create, |
| .bind_conn = qla4xxx_conn_bind, |
| .stop_conn = iscsi_conn_stop, |
| .destroy_conn = qla4xxx_conn_destroy, |
| .set_param = iscsi_set_param, |
| .get_conn_param = qla4xxx_conn_get_param, |
| .get_session_param = iscsi_session_get_param, |
| .get_ep_param = qla4xxx_get_ep_param, |
| .ep_connect = qla4xxx_ep_connect, |
| .ep_poll = qla4xxx_ep_poll, |
| .ep_disconnect = qla4xxx_ep_disconnect, |
| .get_stats = qla4xxx_conn_get_stats, |
| .send_pdu = iscsi_conn_send_pdu, |
| .xmit_task = qla4xxx_task_xmit, |
| .cleanup_task = qla4xxx_task_cleanup, |
| .alloc_pdu = qla4xxx_alloc_pdu, |
| |
| .get_host_param = qla4xxx_host_get_param, |
| .set_iface_param = qla4xxx_iface_set_param, |
| .get_iface_param = qla4xxx_get_iface_param, |
| .bsg_request = qla4xxx_bsg_request, |
| }; |
| |
| static struct scsi_transport_template *qla4xxx_scsi_transport; |
| |
| static mode_t ql4_attr_is_visible(int param_type, int param) |
| { |
| switch (param_type) { |
| case ISCSI_HOST_PARAM: |
| switch (param) { |
| case ISCSI_HOST_PARAM_HWADDRESS: |
| case ISCSI_HOST_PARAM_IPADDRESS: |
| case ISCSI_HOST_PARAM_INITIATOR_NAME: |
| return S_IRUGO; |
| default: |
| return 0; |
| } |
| case ISCSI_PARAM: |
| switch (param) { |
| case ISCSI_PARAM_PERSISTENT_ADDRESS: |
| case ISCSI_PARAM_PERSISTENT_PORT: |
| case ISCSI_PARAM_CONN_ADDRESS: |
| case ISCSI_PARAM_CONN_PORT: |
| case ISCSI_PARAM_TARGET_NAME: |
| case ISCSI_PARAM_TPGT: |
| case ISCSI_PARAM_TARGET_ALIAS: |
| case ISCSI_PARAM_MAX_BURST: |
| case ISCSI_PARAM_MAX_R2T: |
| case ISCSI_PARAM_FIRST_BURST: |
| case ISCSI_PARAM_MAX_RECV_DLENGTH: |
| case ISCSI_PARAM_MAX_XMIT_DLENGTH: |
| case ISCSI_PARAM_IFACE_NAME: |
| return S_IRUGO; |
| default: |
| return 0; |
| } |
| case ISCSI_NET_PARAM: |
| switch (param) { |
| case ISCSI_NET_PARAM_IPV4_ADDR: |
| case ISCSI_NET_PARAM_IPV4_SUBNET: |
| case ISCSI_NET_PARAM_IPV4_GW: |
| case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| case ISCSI_NET_PARAM_IFACE_ENABLE: |
| case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| case ISCSI_NET_PARAM_IPV6_ADDR: |
| case ISCSI_NET_PARAM_IPV6_ROUTER: |
| case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| case ISCSI_NET_PARAM_VLAN_ID: |
| case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| case ISCSI_NET_PARAM_VLAN_ENABLED: |
| case ISCSI_NET_PARAM_MTU: |
| case ISCSI_NET_PARAM_PORT: |
| return S_IRUGO; |
| default: |
| return 0; |
| } |
| } |
| |
| return 0; |
| } |
| |
| static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
| enum iscsi_param_type param_type, |
| int param, char *buf) |
| { |
| struct Scsi_Host *shost = iscsi_iface_to_shost(iface); |
| struct scsi_qla_host *ha = to_qla_host(shost); |
| int len = -ENOSYS; |
| |
| if (param_type != ISCSI_NET_PARAM) |
| return -ENOSYS; |
| |
| switch (param) { |
| case ISCSI_NET_PARAM_IPV4_ADDR: |
| len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| break; |
| case ISCSI_NET_PARAM_IPV4_SUBNET: |
| len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask); |
| break; |
| case ISCSI_NET_PARAM_IPV4_GW: |
| len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); |
| break; |
| case ISCSI_NET_PARAM_IFACE_ENABLE: |
| if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.ipv4_options & |
| IPOPT_IPV4_PROTOCOL_ENABLE) ? |
| "enabled" : "disabled"); |
| else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.ipv6_options & |
| IPV6_OPT_IPV6_PROTOCOL_ENABLE) ? |
| "enabled" : "disabled"); |
| break; |
| case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ? |
| "dhcp" : "static"); |
| break; |
| case ISCSI_NET_PARAM_IPV6_ADDR: |
| if (iface->iface_num == 0) |
| len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0); |
| if (iface->iface_num == 1) |
| len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1); |
| break; |
| case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| len = sprintf(buf, "%pI6\n", |
| &ha->ip_config.ipv6_link_local_addr); |
| break; |
| case ISCSI_NET_PARAM_IPV6_ROUTER: |
| len = sprintf(buf, "%pI6\n", |
| &ha->ip_config.ipv6_default_router_addr); |
| break; |
| case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.ipv6_addl_options & |
| IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? |
| "nd" : "static"); |
| break; |
| case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.ipv6_addl_options & |
| IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? |
| "auto" : "static"); |
| break; |
| case ISCSI_NET_PARAM_VLAN_ID: |
| if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| len = sprintf(buf, "%d\n", |
| (ha->ip_config.ipv4_vlan_tag & |
| ISCSI_MAX_VLAN_ID)); |
| else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| len = sprintf(buf, "%d\n", |
| (ha->ip_config.ipv6_vlan_tag & |
| ISCSI_MAX_VLAN_ID)); |
| break; |
| case ISCSI_NET_PARAM_VLAN_PRIORITY: |
| if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| len = sprintf(buf, "%d\n", |
| ((ha->ip_config.ipv4_vlan_tag >> 13) & |
| ISCSI_MAX_VLAN_PRIORITY)); |
| else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| len = sprintf(buf, "%d\n", |
| ((ha->ip_config.ipv6_vlan_tag >> 13) & |
| ISCSI_MAX_VLAN_PRIORITY)); |
| break; |
| case ISCSI_NET_PARAM_VLAN_ENABLED: |
| if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.ipv4_options & |
| IPOPT_VLAN_TAGGING_ENABLE) ? |
| "enabled" : "disabled"); |
| else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| len = sprintf(buf, "%s\n", |
| (ha->ip_config.ipv6_options & |
| IPV6_OPT_VLAN_TAGGING_ENABLE) ? |
| "enabled" : "disabled"); |
| break; |
| case ISCSI_NET_PARAM_MTU: |
| len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size); |
| break; |
| case ISCSI_NET_PARAM_PORT: |
| if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) |
| len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port); |
| else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) |
| len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port); |
| break; |
| default: |
| len = -ENOSYS; |
| } |
| |
| return len; |
| } |
| |
| static struct iscsi_endpoint * |
| qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, |
| int non_blocking) |
| { |
| int ret; |
| struct iscsi_endpoint *ep; |
| struct qla_endpoint *qla_ep; |
| struct scsi_qla_host *ha; |
| struct sockaddr_in *addr; |
| struct sockaddr_in6 *addr6; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| if (!shost) { |
| ret = -ENXIO; |
| printk(KERN_ERR "%s: shost is NULL\n", |
| __func__); |
| return ERR_PTR(ret); |
| } |
| |
| ha = iscsi_host_priv(shost); |
| |
| ep = iscsi_create_endpoint(sizeof(struct qla_endpoint)); |
| if (!ep) { |
| ret = -ENOMEM; |
| return ERR_PTR(ret); |
| } |
| |
| qla_ep = ep->dd_data; |
| memset(qla_ep, 0, sizeof(struct qla_endpoint)); |
| if (dst_addr->sa_family == AF_INET) { |
| memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in)); |
| addr = (struct sockaddr_in *)&qla_ep->dst_addr; |
| DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__, |
| (char *)&addr->sin_addr)); |
| } else if (dst_addr->sa_family == AF_INET6) { |
| memcpy(&qla_ep->dst_addr, dst_addr, |
| sizeof(struct sockaddr_in6)); |
| addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr; |
| DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__, |
| (char *)&addr6->sin6_addr)); |
| } |
| |
| qla_ep->host = shost; |
| |
| return ep; |
| } |
| |
| static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) |
| { |
| struct qla_endpoint *qla_ep; |
| struct scsi_qla_host *ha; |
| int ret = 0; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| qla_ep = ep->dd_data; |
| ha = to_qla_host(qla_ep->host); |
| |
| if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags)) |
| ret = 1; |
| |
| return ret; |
| } |
| |
| static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep) |
| { |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| iscsi_destroy_endpoint(ep); |
| } |
| |
| static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep, |
| enum iscsi_param param, |
| char *buf) |
| { |
| struct qla_endpoint *qla_ep = ep->dd_data; |
| struct sockaddr *dst_addr; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| |
| switch (param) { |
| case ISCSI_PARAM_CONN_PORT: |
| case ISCSI_PARAM_CONN_ADDRESS: |
| if (!qla_ep) |
| return -ENOTCONN; |
| |
| dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| if (!dst_addr) |
| return -ENOTCONN; |
| |
| return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| &qla_ep->dst_addr, param, buf); |
| default: |
| return -ENOSYS; |
| } |
| } |
| |
| static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn, |
| struct iscsi_stats *stats) |
| { |
| struct iscsi_session *sess; |
| struct iscsi_cls_session *cls_sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| struct ql_iscsi_stats *ql_iscsi_stats; |
| int stats_size; |
| int ret; |
| dma_addr_t iscsi_stats_dma; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| |
| cls_sess = iscsi_conn_to_session(cls_conn); |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats)); |
| /* Allocate memory */ |
| ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size, |
| &iscsi_stats_dma, GFP_KERNEL); |
| if (!ql_iscsi_stats) { |
| ql4_printk(KERN_ERR, ha, |
| "Unable to allocate memory for iscsi stats\n"); |
| goto exit_get_stats; |
| } |
| |
| ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size, |
| iscsi_stats_dma); |
| if (ret != QLA_SUCCESS) { |
| ql4_printk(KERN_ERR, ha, |
| "Unable to retreive iscsi stats\n"); |
| goto free_stats; |
| } |
| |
| /* octets */ |
| stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets); |
| stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets); |
| /* xmit pdus */ |
| stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus); |
| stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus); |
| stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus); |
| stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus); |
| stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus); |
| stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus); |
| stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus); |
| stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus); |
| /* recv pdus */ |
| stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus); |
| stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus); |
| stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus); |
| stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus); |
| stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus); |
| stats->logoutrsp_pdus = |
| le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus); |
| stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus); |
| stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus); |
| stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus); |
| |
| free_stats: |
| dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats, |
| iscsi_stats_dma); |
| exit_get_stats: |
| return; |
| } |
| |
| static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
| { |
| struct iscsi_cls_session *session; |
| struct iscsi_session *sess; |
| unsigned long flags; |
| enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED; |
| |
| session = starget_to_session(scsi_target(sc->device)); |
| sess = session->dd_data; |
| |
| spin_lock_irqsave(&session->lock, flags); |
| if (session->state == ISCSI_SESSION_FAILED) |
| ret = BLK_EH_RESET_TIMER; |
| spin_unlock_irqrestore(&session->lock, flags); |
| |
| return ret; |
| } |
| |
| static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
| enum iscsi_host_param param, char *buf) |
| { |
| struct scsi_qla_host *ha = to_qla_host(shost); |
| int len; |
| |
| switch (param) { |
| case ISCSI_HOST_PARAM_HWADDRESS: |
| len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
| break; |
| case ISCSI_HOST_PARAM_IPADDRESS: |
| len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
| break; |
| case ISCSI_HOST_PARAM_INITIATOR_NAME: |
| len = sprintf(buf, "%s\n", ha->name_string); |
| break; |
| default: |
| return -ENOSYS; |
| } |
| |
| return len; |
| } |
| |
| static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
| { |
| if (ha->iface_ipv4) |
| return; |
| |
| /* IPv4 */ |
| ha->iface_ipv4 = iscsi_create_iface(ha->host, |
| &qla4xxx_iscsi_transport, |
| ISCSI_IFACE_TYPE_IPV4, 0, 0); |
| if (!ha->iface_ipv4) |
| ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " |
| "iface0.\n"); |
| } |
| |
| static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) |
| { |
| if (!ha->iface_ipv6_0) |
| /* IPv6 iface-0 */ |
| ha->iface_ipv6_0 = iscsi_create_iface(ha->host, |
| &qla4xxx_iscsi_transport, |
| ISCSI_IFACE_TYPE_IPV6, 0, |
| 0); |
| if (!ha->iface_ipv6_0) |
| ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| "iface0.\n"); |
| |
| if (!ha->iface_ipv6_1) |
| /* IPv6 iface-1 */ |
| ha->iface_ipv6_1 = iscsi_create_iface(ha->host, |
| &qla4xxx_iscsi_transport, |
| ISCSI_IFACE_TYPE_IPV6, 1, |
| 0); |
| if (!ha->iface_ipv6_1) |
| ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " |
| "iface1.\n"); |
| } |
| |
| static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) |
| { |
| if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) |
| qla4xxx_create_ipv4_iface(ha); |
| |
| if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) |
| qla4xxx_create_ipv6_iface(ha); |
| } |
| |
| static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) |
| { |
| if (ha->iface_ipv4) { |
| iscsi_destroy_iface(ha->iface_ipv4); |
| ha->iface_ipv4 = NULL; |
| } |
| } |
| |
| static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) |
| { |
| if (ha->iface_ipv6_0) { |
| iscsi_destroy_iface(ha->iface_ipv6_0); |
| ha->iface_ipv6_0 = NULL; |
| } |
| if (ha->iface_ipv6_1) { |
| iscsi_destroy_iface(ha->iface_ipv6_1); |
| ha->iface_ipv6_1 = NULL; |
| } |
| } |
| |
| static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) |
| { |
| qla4xxx_destroy_ipv4_iface(ha); |
| qla4xxx_destroy_ipv6_iface(ha); |
| } |
| |
| static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
| struct iscsi_iface_param_info *iface_param, |
| struct addr_ctrl_blk *init_fw_cb) |
| { |
| /* |
| * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. |
| * iface_num 1 is valid only for IPv6 Addr. |
| */ |
| switch (iface_param->param) { |
| case ISCSI_NET_PARAM_IPV6_ADDR: |
| if (iface_param->iface_num & 0x1) |
| /* IPv6 Addr 1 */ |
| memcpy(init_fw_cb->ipv6_addr1, iface_param->value, |
| sizeof(init_fw_cb->ipv6_addr1)); |
| else |
| /* IPv6 Addr 0 */ |
| memcpy(init_fw_cb->ipv6_addr0, iface_param->value, |
| sizeof(init_fw_cb->ipv6_addr0)); |
| break; |
| case ISCSI_NET_PARAM_IPV6_LINKLOCAL: |
| if (iface_param->iface_num & 0x1) |
| break; |
| memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], |
| sizeof(init_fw_cb->ipv6_if_id)); |
| break; |
| case ISCSI_NET_PARAM_IPV6_ROUTER: |
| if (iface_param->iface_num & 0x1) |
| break; |
| memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, |
| sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| break; |
| case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: |
| /* Autocfg applies to even interface */ |
| if (iface_param->iface_num & 0x1) |
| break; |
| |
| if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) |
| init_fw_cb->ipv6_addtl_opts &= |
| cpu_to_le16( |
| ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) |
| init_fw_cb->ipv6_addtl_opts |= |
| cpu_to_le16( |
| IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); |
| else |
| ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " |
| "IPv6 addr\n"); |
| break; |
| case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: |
| /* Autocfg applies to even interface */ |
| if (iface_param->iface_num & 0x1) |
| break; |
| |
| if (iface_param->value[0] == |
| ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) |
| init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( |
| IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| else if (iface_param->value[0] == |
| ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) |
| init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( |
| ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); |
| else |
| ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " |
| "IPv6 linklocal addr\n"); |
| break; |
| case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: |
| /* Autocfg applies to even interface */ |
| if (iface_param->iface_num & 0x1) |
| break; |
| |
| if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) |
| memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, |
| sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); |
| break; |
| case ISCSI_NET_PARAM_IFACE_ENABLE: |
| if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
| init_fw_cb->ipv6_opts |= |
| cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); |
| qla4xxx_create_ipv6_iface(ha); |
| } else { |
| init_fw_cb->ipv6_opts &= |
| cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & |
| 0xFFFF); |
| qla4xxx_destroy_ipv6_iface(ha); |
| } |
| break; |
| case ISCSI_NET_PARAM_VLAN_TAG: |
| if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) |
| break; |
| init_fw_cb->ipv6_vlan_tag = |
| cpu_to_be16(*(uint16_t *)iface_param->value); |
| break; |
| case ISCSI_NET_PARAM_VLAN_ENABLED: |
| if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| init_fw_cb->ipv6_opts |= |
| cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE); |
| else |
| init_fw_cb->ipv6_opts &= |
| cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE); |
| break; |
| case ISCSI_NET_PARAM_MTU: |
| init_fw_cb->eth_mtu_size = |
| cpu_to_le16(*(uint16_t *)iface_param->value); |
| break; |
| case ISCSI_NET_PARAM_PORT: |
| /* Autocfg applies to even interface */ |
| if (iface_param->iface_num & 0x1) |
| break; |
| |
| init_fw_cb->ipv6_port = |
| cpu_to_le16(*(uint16_t *)iface_param->value); |
| break; |
| default: |
| ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", |
| iface_param->param); |
| break; |
| } |
| } |
| |
| static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, |
| struct iscsi_iface_param_info *iface_param, |
| struct addr_ctrl_blk *init_fw_cb) |
| { |
| switch (iface_param->param) { |
| case ISCSI_NET_PARAM_IPV4_ADDR: |
| memcpy(init_fw_cb->ipv4_addr, iface_param->value, |
| sizeof(init_fw_cb->ipv4_addr)); |
| break; |
| case ISCSI_NET_PARAM_IPV4_SUBNET: |
| memcpy(init_fw_cb->ipv4_subnet, iface_param->value, |
| sizeof(init_fw_cb->ipv4_subnet)); |
| break; |
| case ISCSI_NET_PARAM_IPV4_GW: |
| memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, |
| sizeof(init_fw_cb->ipv4_gw_addr)); |
| break; |
| case ISCSI_NET_PARAM_IPV4_BOOTPROTO: |
| if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) |
| init_fw_cb->ipv4_tcp_opts |= |
| cpu_to_le16(TCPOPT_DHCP_ENABLE); |
| else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) |
| init_fw_cb->ipv4_tcp_opts &= |
| cpu_to_le16(~TCPOPT_DHCP_ENABLE); |
| else |
| ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); |
| break; |
| case ISCSI_NET_PARAM_IFACE_ENABLE: |
| if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
| init_fw_cb->ipv4_ip_opts |= |
| cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
| qla4xxx_create_ipv4_iface(ha); |
| } else { |
| init_fw_cb->ipv4_ip_opts &= |
| cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
| 0xFFFF); |
| qla4xxx_destroy_ipv4_iface(ha); |
| } |
| break; |
| case ISCSI_NET_PARAM_VLAN_TAG: |
| if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) |
| break; |
| init_fw_cb->ipv4_vlan_tag = |
| cpu_to_be16(*(uint16_t *)iface_param->value); |
| break; |
| case ISCSI_NET_PARAM_VLAN_ENABLED: |
| if (iface_param->value[0] == ISCSI_VLAN_ENABLE) |
| init_fw_cb->ipv4_ip_opts |= |
| cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE); |
| else |
| init_fw_cb->ipv4_ip_opts &= |
| cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE); |
| break; |
| case ISCSI_NET_PARAM_MTU: |
| init_fw_cb->eth_mtu_size = |
| cpu_to_le16(*(uint16_t *)iface_param->value); |
| break; |
| case ISCSI_NET_PARAM_PORT: |
| init_fw_cb->ipv4_port = |
| cpu_to_le16(*(uint16_t *)iface_param->value); |
| break; |
| default: |
| ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", |
| iface_param->param); |
| break; |
| } |
| } |
| |
| static void |
| qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) |
| { |
| struct addr_ctrl_blk_def *acb; |
| acb = (struct addr_ctrl_blk_def *)init_fw_cb; |
| memset(acb->reserved1, 0, sizeof(acb->reserved1)); |
| memset(acb->reserved2, 0, sizeof(acb->reserved2)); |
| memset(acb->reserved3, 0, sizeof(acb->reserved3)); |
| memset(acb->reserved4, 0, sizeof(acb->reserved4)); |
| memset(acb->reserved5, 0, sizeof(acb->reserved5)); |
| memset(acb->reserved6, 0, sizeof(acb->reserved6)); |
| memset(acb->reserved7, 0, sizeof(acb->reserved7)); |
| memset(acb->reserved8, 0, sizeof(acb->reserved8)); |
| memset(acb->reserved9, 0, sizeof(acb->reserved9)); |
| memset(acb->reserved10, 0, sizeof(acb->reserved10)); |
| memset(acb->reserved11, 0, sizeof(acb->reserved11)); |
| memset(acb->reserved12, 0, sizeof(acb->reserved12)); |
| memset(acb->reserved13, 0, sizeof(acb->reserved13)); |
| memset(acb->reserved14, 0, sizeof(acb->reserved14)); |
| memset(acb->reserved15, 0, sizeof(acb->reserved15)); |
| } |
| |
| static int |
| qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len) |
| { |
| struct scsi_qla_host *ha = to_qla_host(shost); |
| int rval = 0; |
| struct iscsi_iface_param_info *iface_param = NULL; |
| struct addr_ctrl_blk *init_fw_cb = NULL; |
| dma_addr_t init_fw_cb_dma; |
| uint32_t mbox_cmd[MBOX_REG_COUNT]; |
| uint32_t mbox_sts[MBOX_REG_COUNT]; |
| uint32_t rem = len; |
| struct nlattr *attr; |
| |
| init_fw_cb = dma_alloc_coherent(&ha->pdev->dev, |
| sizeof(struct addr_ctrl_blk), |
| &init_fw_cb_dma, GFP_KERNEL); |
| if (!init_fw_cb) { |
| ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", |
| __func__); |
| return -ENOMEM; |
| } |
| |
| memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| memset(&mbox_cmd, 0, sizeof(mbox_cmd)); |
| memset(&mbox_sts, 0, sizeof(mbox_sts)); |
| |
| if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { |
| ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); |
| rval = -EIO; |
| goto exit_init_fw_cb; |
| } |
| |
| nla_for_each_attr(attr, data, len, rem) { |
| iface_param = nla_data(attr); |
| |
| if (iface_param->param_type != ISCSI_NET_PARAM) |
| continue; |
| |
| switch (iface_param->iface_type) { |
| case ISCSI_IFACE_TYPE_IPV4: |
| switch (iface_param->iface_num) { |
| case 0: |
| qla4xxx_set_ipv4(ha, iface_param, init_fw_cb); |
| break; |
| default: |
| /* Cannot have more than one IPv4 interface */ |
| ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface " |
| "number = %d\n", |
| iface_param->iface_num); |
| break; |
| } |
| break; |
| case ISCSI_IFACE_TYPE_IPV6: |
| switch (iface_param->iface_num) { |
| case 0: |
| case 1: |
| qla4xxx_set_ipv6(ha, iface_param, init_fw_cb); |
| break; |
| default: |
| /* Cannot have more than two IPv6 interface */ |
| ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface " |
| "number = %d\n", |
| iface_param->iface_num); |
| break; |
| } |
| break; |
| default: |
| ql4_printk(KERN_ERR, ha, "Invalid iface type\n"); |
| break; |
| } |
| } |
| |
| init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); |
| |
| rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, |
| sizeof(struct addr_ctrl_blk), |
| FLASH_OPT_RMW_COMMIT); |
| if (rval != QLA_SUCCESS) { |
| ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", |
| __func__); |
| rval = -EIO; |
| goto exit_init_fw_cb; |
| } |
| |
| qla4xxx_disable_acb(ha); |
| |
| qla4xxx_initcb_to_acb(init_fw_cb); |
| |
| rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); |
| if (rval != QLA_SUCCESS) { |
| ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", |
| __func__); |
| rval = -EIO; |
| goto exit_init_fw_cb; |
| } |
| |
| memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); |
| qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, |
| init_fw_cb_dma); |
| |
| exit_init_fw_cb: |
| dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), |
| init_fw_cb, init_fw_cb_dma); |
| |
| return rval; |
| } |
| |
| static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn, |
| enum iscsi_param param, char *buf) |
| { |
| struct iscsi_conn *conn; |
| struct qla_conn *qla_conn; |
| struct sockaddr *dst_addr; |
| int len = 0; |
| |
| conn = cls_conn->dd_data; |
| qla_conn = conn->dd_data; |
| dst_addr = &qla_conn->qla_ep->dst_addr; |
| |
| switch (param) { |
| case ISCSI_PARAM_CONN_PORT: |
| case ISCSI_PARAM_CONN_ADDRESS: |
| return iscsi_conn_get_addr_param((struct sockaddr_storage *) |
| dst_addr, param, buf); |
| default: |
| return iscsi_conn_get_param(cls_conn, param, buf); |
| } |
| |
| return len; |
| |
| } |
| |
| int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index) |
| { |
| uint32_t mbx_sts = 0; |
| uint16_t tmp_ddb_index; |
| int ret; |
| |
| get_ddb_index: |
| tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES); |
| |
| if (tmp_ddb_index >= MAX_DDB_ENTRIES) { |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "Free DDB index not available\n")); |
| ret = QLA_ERROR; |
| goto exit_get_ddb_index; |
| } |
| |
| if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map)) |
| goto get_ddb_index; |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "Found a free DDB index at %d\n", tmp_ddb_index)); |
| ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts); |
| if (ret == QLA_ERROR) { |
| if (mbx_sts == MBOX_STS_COMMAND_ERROR) { |
| ql4_printk(KERN_INFO, ha, |
| "DDB index = %d not available trying next\n", |
| tmp_ddb_index); |
| goto get_ddb_index; |
| } |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "Free FW DDB not available\n")); |
| } |
| |
| *ddb_index = tmp_ddb_index; |
| |
| exit_get_ddb_index: |
| return ret; |
| } |
| |
| static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha, |
| struct ddb_entry *ddb_entry, |
| char *existing_ipaddr, |
| char *user_ipaddr) |
| { |
| uint8_t dst_ipaddr[IPv6_ADDR_LEN]; |
| char formatted_ipaddr[DDB_IPADDR_LEN]; |
| int status = QLA_SUCCESS, ret = 0; |
| |
| if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) { |
| ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| '\0', NULL); |
| if (ret == 0) { |
| status = QLA_ERROR; |
| goto out_match; |
| } |
| ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr); |
| } else { |
| ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr, |
| '\0', NULL); |
| if (ret == 0) { |
| status = QLA_ERROR; |
| goto out_match; |
| } |
| ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr); |
| } |
| |
| if (strcmp(existing_ipaddr, formatted_ipaddr)) |
| status = QLA_ERROR; |
| |
| out_match: |
| return status; |
| } |
| |
| static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha, |
| struct iscsi_cls_conn *cls_conn) |
| { |
| int idx = 0, max_ddbs, rval; |
| struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| struct iscsi_session *sess, *existing_sess; |
| struct iscsi_conn *conn, *existing_conn; |
| struct ddb_entry *ddb_entry; |
| |
| sess = cls_sess->dd_data; |
| conn = cls_conn->dd_data; |
| |
| if (sess->targetname == NULL || |
| conn->persistent_address == NULL || |
| conn->persistent_port == 0) |
| return QLA_ERROR; |
| |
| max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX : |
| MAX_DEV_DB_ENTRIES; |
| |
| for (idx = 0; idx < max_ddbs; idx++) { |
| ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); |
| if (ddb_entry == NULL) |
| continue; |
| |
| if (ddb_entry->ddb_type != FLASH_DDB) |
| continue; |
| |
| existing_sess = ddb_entry->sess->dd_data; |
| existing_conn = ddb_entry->conn->dd_data; |
| |
| if (existing_sess->targetname == NULL || |
| existing_conn->persistent_address == NULL || |
| existing_conn->persistent_port == 0) |
| continue; |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "IQN = %s User IQN = %s\n", |
| existing_sess->targetname, |
| sess->targetname)); |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "IP = %s User IP = %s\n", |
| existing_conn->persistent_address, |
| conn->persistent_address)); |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "Port = %d User Port = %d\n", |
| existing_conn->persistent_port, |
| conn->persistent_port)); |
| |
| if (strcmp(existing_sess->targetname, sess->targetname)) |
| continue; |
| rval = qla4xxx_match_ipaddress(ha, ddb_entry, |
| existing_conn->persistent_address, |
| conn->persistent_address); |
| if (rval == QLA_ERROR) |
| continue; |
| if (existing_conn->persistent_port != conn->persistent_port) |
| continue; |
| break; |
| } |
| |
| if (idx == max_ddbs) |
| return QLA_ERROR; |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "Match found in fwdb sessions\n")); |
| return QLA_SUCCESS; |
| } |
| |
| static struct iscsi_cls_session * |
| qla4xxx_session_create(struct iscsi_endpoint *ep, |
| uint16_t cmds_max, uint16_t qdepth, |
| uint32_t initial_cmdsn) |
| { |
| struct iscsi_cls_session *cls_sess; |
| struct scsi_qla_host *ha; |
| struct qla_endpoint *qla_ep; |
| struct ddb_entry *ddb_entry; |
| uint16_t ddb_index; |
| struct iscsi_session *sess; |
| struct sockaddr *dst_addr; |
| int ret; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| if (!ep) { |
| printk(KERN_ERR "qla4xxx: missing ep.\n"); |
| return NULL; |
| } |
| |
| qla_ep = ep->dd_data; |
| dst_addr = (struct sockaddr *)&qla_ep->dst_addr; |
| ha = to_qla_host(qla_ep->host); |
| |
| ret = qla4xxx_get_ddb_index(ha, &ddb_index); |
| if (ret == QLA_ERROR) |
| return NULL; |
| |
| cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host, |
| cmds_max, sizeof(struct ddb_entry), |
| sizeof(struct ql4_task_data), |
| initial_cmdsn, ddb_index); |
| if (!cls_sess) |
| return NULL; |
| |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ddb_entry->fw_ddb_index = ddb_index; |
| ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE; |
| ddb_entry->ha = ha; |
| ddb_entry->sess = cls_sess; |
| ddb_entry->unblock_sess = qla4xxx_unblock_ddb; |
| ddb_entry->ddb_change = qla4xxx_ddb_change; |
| cls_sess->recovery_tmo = ql4xsess_recovery_tmo; |
| ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry; |
| ha->tot_ddbs++; |
| |
| return cls_sess; |
| } |
| |
| static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| unsigned long flags; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); |
| |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| qla4xxx_free_ddb(ha, ddb_entry); |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| iscsi_session_teardown(cls_sess); |
| } |
| |
| static struct iscsi_cls_conn * |
| qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx) |
| { |
| struct iscsi_cls_conn *cls_conn; |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), |
| conn_idx); |
| if (!cls_conn) |
| return NULL; |
| |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ddb_entry->conn = cls_conn; |
| |
| return cls_conn; |
| } |
| |
| static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, |
| struct iscsi_cls_conn *cls_conn, |
| uint64_t transport_fd, int is_leading) |
| { |
| struct iscsi_conn *conn; |
| struct qla_conn *qla_conn; |
| struct iscsi_endpoint *ep; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| |
| if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
| return -EINVAL; |
| ep = iscsi_lookup_endpoint(transport_fd); |
| conn = cls_conn->dd_data; |
| qla_conn = conn->dd_data; |
| qla_conn->qla_ep = ep->dd_data; |
| return 0; |
| } |
| |
| static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn) |
| { |
| struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| struct dev_db_entry *fw_ddb_entry = NULL; |
| dma_addr_t fw_ddb_entry_dma; |
| uint32_t mbx_sts = 0; |
| int ret = 0; |
| int status = QLA_SUCCESS; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| /* Check if we have matching FW DDB, if yes then do not |
| * login to this target. This could cause target to logout previous |
| * connection |
| */ |
| ret = qla4xxx_match_fwdb_session(ha, cls_conn); |
| if (ret == QLA_SUCCESS) { |
| ql4_printk(KERN_INFO, ha, |
| "Session already exist in FW.\n"); |
| ret = -EEXIST; |
| goto exit_conn_start; |
| } |
| |
| fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| &fw_ddb_entry_dma, GFP_KERNEL); |
| if (!fw_ddb_entry) { |
| ql4_printk(KERN_ERR, ha, |
| "%s: Unable to allocate dma buffer\n", __func__); |
| ret = -ENOMEM; |
| goto exit_conn_start; |
| } |
| |
| ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts); |
| if (ret) { |
| /* If iscsid is stopped and started then no need to do |
| * set param again since ddb state will be already |
| * active and FW does not allow set ddb to an |
| * active session. |
| */ |
| if (mbx_sts) |
| if (ddb_entry->fw_ddb_device_state == |
| DDB_DS_SESSION_ACTIVE) { |
| ddb_entry->unblock_sess(ddb_entry->sess); |
| goto exit_set_param; |
| } |
| |
| ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n", |
| __func__, ddb_entry->fw_ddb_index); |
| goto exit_conn_start; |
| } |
| |
| status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index); |
| if (status == QLA_ERROR) { |
| ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__, |
| sess->targetname); |
| ret = -EINVAL; |
| goto exit_conn_start; |
| } |
| |
| if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE) |
| ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS; |
| |
| DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__, |
| ddb_entry->fw_ddb_device_state)); |
| |
| exit_set_param: |
| ret = 0; |
| |
| exit_conn_start: |
| if (fw_ddb_entry) |
| dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| fw_ddb_entry, fw_ddb_entry_dma); |
| return ret; |
| } |
| |
| static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn) |
| { |
| struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn); |
| struct iscsi_session *sess; |
| struct scsi_qla_host *ha; |
| struct ddb_entry *ddb_entry; |
| int options; |
| |
| DEBUG2(printk(KERN_INFO "Func: %s\n", __func__)); |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| options = LOGOUT_OPTION_CLOSE_SESSION; |
| if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) |
| ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__); |
| } |
| |
| static void qla4xxx_task_work(struct work_struct *wdata) |
| { |
| struct ql4_task_data *task_data; |
| struct scsi_qla_host *ha; |
| struct passthru_status *sts; |
| struct iscsi_task *task; |
| struct iscsi_hdr *hdr; |
| uint8_t *data; |
| uint32_t data_len; |
| struct iscsi_conn *conn; |
| int hdr_len; |
| itt_t itt; |
| |
| task_data = container_of(wdata, struct ql4_task_data, task_work); |
| ha = task_data->ha; |
| task = task_data->task; |
| sts = &task_data->sts; |
| hdr_len = sizeof(struct iscsi_hdr); |
| |
| DEBUG3(printk(KERN_INFO "Status returned\n")); |
| DEBUG3(qla4xxx_dump_buffer(sts, 64)); |
| DEBUG3(printk(KERN_INFO "Response buffer")); |
| DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64)); |
| |
| conn = task->conn; |
| |
| switch (sts->completionStatus) { |
| case PASSTHRU_STATUS_COMPLETE: |
| hdr = (struct iscsi_hdr *)task_data->resp_buffer; |
| /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */ |
| itt = sts->handle; |
| hdr->itt = itt; |
| data = task_data->resp_buffer + hdr_len; |
| data_len = task_data->resp_len - hdr_len; |
| iscsi_complete_pdu(conn, hdr, data, data_len); |
| break; |
| default: |
| ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n", |
| sts->completionStatus); |
| break; |
| } |
| return; |
| } |
| |
| static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| { |
| struct ql4_task_data *task_data; |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| int hdr_len; |
| |
| sess = task->conn->session; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| task_data = task->dd_data; |
| memset(task_data, 0, sizeof(struct ql4_task_data)); |
| |
| if (task->sc) { |
| ql4_printk(KERN_INFO, ha, |
| "%s: SCSI Commands not implemented\n", __func__); |
| return -EINVAL; |
| } |
| |
| hdr_len = sizeof(struct iscsi_hdr); |
| task_data->ha = ha; |
| task_data->task = task; |
| |
| if (task->data_count) { |
| task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data, |
| task->data_count, |
| PCI_DMA_TODEVICE); |
| } |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| __func__, task->conn->max_recv_dlength, hdr_len)); |
| |
| task_data->resp_len = task->conn->max_recv_dlength + hdr_len; |
| task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| task_data->resp_len, |
| &task_data->resp_dma, |
| GFP_ATOMIC); |
| if (!task_data->resp_buffer) |
| goto exit_alloc_pdu; |
| |
| task_data->req_len = task->data_count + hdr_len; |
| task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev, |
| task_data->req_len, |
| &task_data->req_dma, |
| GFP_ATOMIC); |
| if (!task_data->req_buffer) |
| goto exit_alloc_pdu; |
| |
| task->hdr = task_data->req_buffer; |
| |
| INIT_WORK(&task_data->task_work, qla4xxx_task_work); |
| |
| return 0; |
| |
| exit_alloc_pdu: |
| if (task_data->resp_buffer) |
| dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| task_data->resp_buffer, task_data->resp_dma); |
| |
| if (task_data->req_buffer) |
| dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
| task_data->req_buffer, task_data->req_dma); |
| return -ENOMEM; |
| } |
| |
| static void qla4xxx_task_cleanup(struct iscsi_task *task) |
| { |
| struct ql4_task_data *task_data; |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| int hdr_len; |
| |
| hdr_len = sizeof(struct iscsi_hdr); |
| sess = task->conn->session; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| task_data = task->dd_data; |
| |
| if (task->data_count) { |
| dma_unmap_single(&ha->pdev->dev, task_data->data_dma, |
| task->data_count, PCI_DMA_TODEVICE); |
| } |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n", |
| __func__, task->conn->max_recv_dlength, hdr_len)); |
| |
| dma_free_coherent(&ha->pdev->dev, task_data->resp_len, |
| task_data->resp_buffer, task_data->resp_dma); |
| dma_free_coherent(&ha->pdev->dev, task_data->req_len, |
| task_data->req_buffer, task_data->req_dma); |
| return; |
| } |
| |
| static int qla4xxx_task_xmit(struct iscsi_task *task) |
| { |
| struct scsi_cmnd *sc = task->sc; |
| struct iscsi_session *sess = task->conn->session; |
| struct ddb_entry *ddb_entry = sess->dd_data; |
| struct scsi_qla_host *ha = ddb_entry->ha; |
| |
| if (!sc) |
| return qla4xxx_send_passthru0(task); |
| |
| ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n", |
| __func__); |
| return -ENOSYS; |
| } |
| |
| static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha, |
| struct dev_db_entry *fw_ddb_entry, |
| struct iscsi_cls_session *cls_sess, |
| struct iscsi_cls_conn *cls_conn) |
| { |
| int buflen = 0; |
| struct iscsi_session *sess; |
| struct iscsi_conn *conn; |
| char ip_addr[DDB_IPADDR_LEN]; |
| uint16_t options = 0; |
| |
| sess = cls_sess->dd_data; |
| conn = cls_conn->dd_data; |
| |
| conn->max_recv_dlength = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| |
| conn->max_xmit_dlength = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| |
| sess->initial_r2t_en = |
| (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| |
| sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| |
| sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| |
| sess->first_burst = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| |
| sess->max_burst = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| |
| sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| |
| sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| |
| conn->persistent_port = le16_to_cpu(fw_ddb_entry->port); |
| |
| sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| |
| options = le16_to_cpu(fw_ddb_entry->options); |
| if (options & DDB_OPT_IPV6_DEVICE) |
| sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr); |
| else |
| sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr); |
| |
| iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME, |
| (char *)fw_ddb_entry->iscsi_name, buflen); |
| iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME, |
| (char *)ha->name_string, buflen); |
| iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS, |
| (char *)ip_addr, buflen); |
| } |
| |
| void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha, |
| struct ddb_entry *ddb_entry) |
| { |
| struct iscsi_cls_session *cls_sess; |
| struct iscsi_cls_conn *cls_conn; |
| uint32_t ddb_state; |
| dma_addr_t fw_ddb_entry_dma; |
| struct dev_db_entry *fw_ddb_entry; |
| |
| fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| &fw_ddb_entry_dma, GFP_KERNEL); |
| if (!fw_ddb_entry) { |
| ql4_printk(KERN_ERR, ha, |
| "%s: Unable to allocate dma buffer\n", __func__); |
| goto exit_session_conn_fwddb_param; |
| } |
| |
| if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| NULL, NULL, NULL) == QLA_ERROR) { |
| DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| "get_ddb_entry for fw_ddb_index %d\n", |
| ha->host_no, __func__, |
| ddb_entry->fw_ddb_index)); |
| goto exit_session_conn_fwddb_param; |
| } |
| |
| cls_sess = ddb_entry->sess; |
| |
| cls_conn = ddb_entry->conn; |
| |
| /* Update params */ |
| qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn); |
| |
| exit_session_conn_fwddb_param: |
| if (fw_ddb_entry) |
| dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| fw_ddb_entry, fw_ddb_entry_dma); |
| } |
| |
| void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha, |
| struct ddb_entry *ddb_entry) |
| { |
| struct iscsi_cls_session *cls_sess; |
| struct iscsi_cls_conn *cls_conn; |
| struct iscsi_session *sess; |
| struct iscsi_conn *conn; |
| uint32_t ddb_state; |
| dma_addr_t fw_ddb_entry_dma; |
| struct dev_db_entry *fw_ddb_entry; |
| |
| fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| &fw_ddb_entry_dma, GFP_KERNEL); |
| if (!fw_ddb_entry) { |
| ql4_printk(KERN_ERR, ha, |
| "%s: Unable to allocate dma buffer\n", __func__); |
| goto exit_session_conn_param; |
| } |
| |
| if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry, |
| fw_ddb_entry_dma, NULL, NULL, &ddb_state, |
| NULL, NULL, NULL) == QLA_ERROR) { |
| DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed " |
| "get_ddb_entry for fw_ddb_index %d\n", |
| ha->host_no, __func__, |
| ddb_entry->fw_ddb_index)); |
| goto exit_session_conn_param; |
| } |
| |
| cls_sess = ddb_entry->sess; |
| sess = cls_sess->dd_data; |
| |
| cls_conn = ddb_entry->conn; |
| conn = cls_conn->dd_data; |
| |
| /* Update timers after login */ |
| ddb_entry->default_relogin_timeout = |
| le16_to_cpu(fw_ddb_entry->def_timeout); |
| ddb_entry->default_time2wait = |
| le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| |
| /* Update params */ |
| conn->max_recv_dlength = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len); |
| |
| conn->max_xmit_dlength = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len); |
| |
| sess->initial_r2t_en = |
| (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| |
| sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t); |
| |
| sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options)); |
| |
| sess->first_burst = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len); |
| |
| sess->max_burst = BYTE_UNITS * |
| le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len); |
| |
| sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait); |
| |
| sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain); |
| |
| sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp); |
| |
| memcpy(sess->initiatorname, ha->name_string, |
| min(sizeof(ha->name_string), sizeof(sess->initiatorname))); |
| |
| exit_session_conn_param: |
| if (fw_ddb_entry) |
| dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), |
| fw_ddb_entry, fw_ddb_entry_dma); |
| } |
| |
| /* |
| * Timer routines |
| */ |
| |
| static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, |
| unsigned long interval) |
| { |
| DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", |
| __func__, ha->host->host_no)); |
| init_timer(&ha->timer); |
| ha->timer.expires = jiffies + interval * HZ; |
| ha->timer.data = (unsigned long)ha; |
| ha->timer.function = (void (*)(unsigned long))func; |
| add_timer(&ha->timer); |
| ha->timer_active = 1; |
| } |
| |
| static void qla4xxx_stop_timer(struct scsi_qla_host *ha) |
| { |
| del_timer_sync(&ha->timer); |
| ha->timer_active = 0; |
| } |
| |
| /*** |
| * qla4xxx_mark_device_missing - blocks the session |
| * @cls_session: Pointer to the session to be blocked |
| * @ddb_entry: Pointer to device database entry |
| * |
| * This routine marks a device missing and close connection. |
| **/ |
| void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session) |
| { |
| iscsi_block_session(cls_session); |
| } |
| |
| /** |
| * qla4xxx_mark_all_devices_missing - mark all devices as missing. |
| * @ha: Pointer to host adapter structure. |
| * |
| * This routine marks a device missing and resets the relogin retry count. |
| **/ |
| void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) |
| { |
| iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing); |
| } |
| |
| static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
| struct ddb_entry *ddb_entry, |
| struct scsi_cmnd *cmd) |
| { |
| struct srb *srb; |
| |
| srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); |
| if (!srb) |
| return srb; |
| |
| kref_init(&srb->srb_ref); |
| srb->ha = ha; |
| srb->ddb = ddb_entry; |
| srb->cmd = cmd; |
| srb->flags = 0; |
| CMD_SP(cmd) = (void *)srb; |
| |
| return srb; |
| } |
| |
| static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) |
| { |
| struct scsi_cmnd *cmd = srb->cmd; |
| |
| if (srb->flags & SRB_DMA_VALID) { |
| scsi_dma_unmap(cmd); |
| srb->flags &= ~SRB_DMA_VALID; |
| } |
| CMD_SP(cmd) = NULL; |
| } |
| |
| void qla4xxx_srb_compl(struct kref *ref) |
| { |
| struct srb *srb = container_of(ref, struct srb, srb_ref); |
| struct scsi_cmnd *cmd = srb->cmd; |
| struct scsi_qla_host *ha = srb->ha; |
| |
| qla4xxx_srb_free_dma(ha, srb); |
| |
| mempool_free(srb, ha->srb_mempool); |
| |
| cmd->scsi_done(cmd); |
| } |
| |
| /** |
| * qla4xxx_queuecommand - scsi layer issues scsi command to driver. |
| * @host: scsi host |
| * @cmd: Pointer to Linux's SCSI command structure |
| * |
| * Remarks: |
| * This routine is invoked by Linux to send a SCSI command to the driver. |
| * The mid-level driver tries to ensure that queuecommand never gets |
| * invoked concurrently with itself or the interrupt handler (although |
| * the interrupt handler may call this routine as part of request- |
| * completion handling). Unfortunely, it sometimes calls the scheduler |
| * in interrupt context which is a big NO! NO!. |
| **/ |
| static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
| { |
| struct scsi_qla_host *ha = to_qla_host(host); |
| struct ddb_entry *ddb_entry = cmd->device->hostdata; |
| struct iscsi_cls_session *sess = ddb_entry->sess; |
| struct srb *srb; |
| int rval; |
| |
| if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) |
| cmd->result = DID_NO_CONNECT << 16; |
| else |
| cmd->result = DID_REQUEUE << 16; |
| goto qc_fail_command; |
| } |
| |
| if (!sess) { |
| cmd->result = DID_IMM_RETRY << 16; |
| goto qc_fail_command; |
| } |
| |
| rval = iscsi_session_chkready(sess); |
| if (rval) { |
| cmd->result = rval; |
| goto qc_fail_command; |
| } |
| |
| if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| !test_bit(AF_ONLINE, &ha->flags) || |
| !test_bit(AF_LINK_UP, &ha->flags) || |
| test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) |
| goto qc_host_busy; |
| |
| srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
| if (!srb) |
| goto qc_host_busy; |
| |
| rval = qla4xxx_send_command_to_isp(ha, srb); |
| if (rval != QLA_SUCCESS) |
| goto qc_host_busy_free_sp; |
| |
| return 0; |
| |
| qc_host_busy_free_sp: |
| qla4xxx_srb_free_dma(ha, srb); |
| mempool_free(srb, ha->srb_mempool); |
| |
| qc_host_busy: |
| return SCSI_MLQUEUE_HOST_BUSY; |
| |
| qc_fail_command: |
| cmd->scsi_done(cmd); |
| |
| return 0; |
| } |
| |
| /** |
| * qla4xxx_mem_free - frees memory allocated to adapter |
| * @ha: Pointer to host adapter structure. |
| * |
| * Frees memory previously allocated by qla4xxx_mem_alloc |
| **/ |
| static void qla4xxx_mem_free(struct scsi_qla_host *ha) |
| { |
| if (ha->queues) |
| dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, |
| ha->queues_dma); |
| |
| ha->queues_len = 0; |
| ha->queues = NULL; |
| ha->queues_dma = 0; |
| ha->request_ring = NULL; |
| ha->request_dma = 0; |
| ha->response_ring = NULL; |
| ha->response_dma = 0; |
| ha->shadow_regs = NULL; |
| ha->shadow_regs_dma = 0; |
| |
| /* Free srb pool. */ |
| if (ha->srb_mempool) |
| mempool_destroy(ha->srb_mempool); |
| |
| ha->srb_mempool = NULL; |
| |
| if (ha->chap_dma_pool) |
| dma_pool_destroy(ha->chap_dma_pool); |
| |
| if (ha->chap_list) |
| vfree(ha->chap_list); |
| ha->chap_list = NULL; |
| |
| if (ha->fw_ddb_dma_pool) |
| dma_pool_destroy(ha->fw_ddb_dma_pool); |
| |
| /* release io space registers */ |
| if (is_qla8022(ha)) { |
| if (ha->nx_pcibase) |
| iounmap( |
| (struct device_reg_82xx __iomem *)ha->nx_pcibase); |
| } else if (ha->reg) |
| iounmap(ha->reg); |
| pci_release_regions(ha->pdev); |
| } |
| |
| /** |
| * qla4xxx_mem_alloc - allocates memory for use by adapter. |
| * @ha: Pointer to host adapter structure |
| * |
| * Allocates DMA memory for request and response queues. Also allocates memory |
| * for srbs. |
| **/ |
| static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) |
| { |
| unsigned long align; |
| |
| /* Allocate contiguous block of DMA memory for queues. */ |
| ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + |
| sizeof(struct shadow_regs) + |
| MEM_ALIGN_VALUE + |
| (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); |
| ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, |
| &ha->queues_dma, GFP_KERNEL); |
| if (ha->queues == NULL) { |
| ql4_printk(KERN_WARNING, ha, |
| "Memory Allocation failed - queues.\n"); |
| |
| goto mem_alloc_error_exit; |
| } |
| memset(ha->queues, 0, ha->queues_len); |
| |
| /* |
| * As per RISC alignment requirements -- the bus-address must be a |
| * multiple of the request-ring size (in bytes). |
| */ |
| align = 0; |
| if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) |
| align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & |
| (MEM_ALIGN_VALUE - 1)); |
| |
| /* Update request and response queue pointers. */ |
| ha->request_dma = ha->queues_dma + align; |
| ha->request_ring = (struct queue_entry *) (ha->queues + align); |
| ha->response_dma = ha->queues_dma + align + |
| (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); |
| ha->response_ring = (struct queue_entry *) (ha->queues + align + |
| (REQUEST_QUEUE_DEPTH * |
| QUEUE_SIZE)); |
| ha->shadow_regs_dma = ha->queues_dma + align + |
| (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + |
| (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); |
| ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + |
| (REQUEST_QUEUE_DEPTH * |
| QUEUE_SIZE) + |
| (RESPONSE_QUEUE_DEPTH * |
| QUEUE_SIZE)); |
| |
| /* Allocate memory for srb pool. */ |
| ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, |
| mempool_free_slab, srb_cachep); |
| if (ha->srb_mempool == NULL) { |
| ql4_printk(KERN_WARNING, ha, |
| "Memory Allocation failed - SRB Pool.\n"); |
| |
| goto mem_alloc_error_exit; |
| } |
| |
| ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev, |
| CHAP_DMA_BLOCK_SIZE, 8, 0); |
| |
| if (ha->chap_dma_pool == NULL) { |
| ql4_printk(KERN_WARNING, ha, |
| "%s: chap_dma_pool allocation failed..\n", __func__); |
| goto mem_alloc_error_exit; |
| } |
| |
| ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev, |
| DDB_DMA_BLOCK_SIZE, 8, 0); |
| |
| if (ha->fw_ddb_dma_pool == NULL) { |
| ql4_printk(KERN_WARNING, ha, |
| "%s: fw_ddb_dma_pool allocation failed..\n", |
| __func__); |
| goto mem_alloc_error_exit; |
| } |
| |
| return QLA_SUCCESS; |
| |
| mem_alloc_error_exit: |
| qla4xxx_mem_free(ha); |
| return QLA_ERROR; |
| } |
| |
| /** |
| * qla4_8xxx_check_fw_alive - Check firmware health |
| * @ha: Pointer to host adapter structure. |
| * |
| * Context: Interrupt |
| **/ |
| static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) |
| { |
| uint32_t fw_heartbeat_counter, halt_status; |
| |
| fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); |
| /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
| if (fw_heartbeat_counter == 0xffffffff) { |
| DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " |
| "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", |
| ha->host_no, __func__)); |
| return; |
| } |
| |
| if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { |
| ha->seconds_since_last_heartbeat++; |
| /* FW not alive after 2 seconds */ |
| if (ha->seconds_since_last_heartbeat == 2) { |
| ha->seconds_since_last_heartbeat = 0; |
| halt_status = qla4_8xxx_rd_32(ha, |
| QLA82XX_PEG_HALT_STATUS1); |
| |
| ql4_printk(KERN_INFO, ha, |
| "scsi(%ld): %s, Dumping hw/fw registers:\n " |
| " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:" |
| " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:" |
| " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:" |
| " 0x%x,\n PEG_NET_4_PC: 0x%x\n", |
| ha->host_no, __func__, halt_status, |
| qla4_8xxx_rd_32(ha, |
| QLA82XX_PEG_HALT_STATUS2), |
| qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 + |
| 0x3c), |
| qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 + |
| 0x3c), |
| qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 + |
| 0x3c), |
| qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 + |
| 0x3c), |
| qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 + |
| 0x3c)); |
| |
| /* Since we cannot change dev_state in interrupt |
| * context, set appropriate DPC flag then wakeup |
| * DPC */ |
| if (halt_status & HALT_STATUS_UNRECOVERABLE) |
| set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); |
| else { |
| printk("scsi%ld: %s: detect abort needed!\n", |
| ha->host_no, __func__); |
| set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| } |
| qla4xxx_wake_dpc(ha); |
| qla4xxx_mailbox_premature_completion(ha); |
| } |
| } else |
| ha->seconds_since_last_heartbeat = 0; |
| |
| ha->fw_heartbeat_counter = fw_heartbeat_counter; |
| } |
| |
| /** |
| * qla4_8xxx_watchdog - Poll dev state |
| * @ha: Pointer to host adapter structure. |
| * |
| * Context: Interrupt |
| **/ |
| void qla4_8xxx_watchdog(struct scsi_qla_host *ha) |
| { |
| uint32_t dev_state; |
| |
| dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); |
| |
| /* don't poll if reset is going on */ |
| if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
| if (dev_state == QLA82XX_DEV_NEED_RESET && |
| !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
| if (!ql4xdontresethba) { |
| ql4_printk(KERN_INFO, ha, "%s: HW State: " |
| "NEED RESET!\n", __func__); |
| set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| qla4xxx_wake_dpc(ha); |
| qla4xxx_mailbox_premature_completion(ha); |
| } |
| } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT && |
| !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
| __func__); |
| set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
| qla4xxx_wake_dpc(ha); |
| } else { |
| /* Check firmware health */ |
| qla4_8xxx_check_fw_alive(ha); |
| } |
| } |
| } |
| |
| void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| return; |
| |
| if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) && |
| !iscsi_is_session_online(cls_sess)) { |
| if (atomic_read(&ddb_entry->retry_relogin_timer) != |
| INVALID_ENTRY) { |
| if (atomic_read(&ddb_entry->retry_relogin_timer) == |
| 0) { |
| atomic_set(&ddb_entry->retry_relogin_timer, |
| INVALID_ENTRY); |
| set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| set_bit(DF_RELOGIN, &ddb_entry->flags); |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "%s: index [%d] login device\n", |
| __func__, ddb_entry->fw_ddb_index)); |
| } else |
| atomic_dec(&ddb_entry->retry_relogin_timer); |
| } |
| } |
| |
| /* Wait for relogin to timeout */ |
| if (atomic_read(&ddb_entry->relogin_timer) && |
| (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { |
| /* |
| * If the relogin times out and the device is |
| * still NOT ONLINE then try and relogin again. |
| */ |
| if (!iscsi_is_session_online(cls_sess)) { |
| /* Reset retry relogin timer */ |
| atomic_inc(&ddb_entry->relogin_retry_count); |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "%s: index[%d] relogin timed out-retrying" |
| " relogin (%d), retry (%d)\n", __func__, |
| ddb_entry->fw_ddb_index, |
| atomic_read(&ddb_entry->relogin_retry_count), |
| ddb_entry->default_time2wait + 4)); |
| set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags); |
| atomic_set(&ddb_entry->retry_relogin_timer, |
| ddb_entry->default_time2wait + 4); |
| } |
| } |
| } |
| |
| /** |
| * qla4xxx_timer - checks every second for work to do. |
| * @ha: Pointer to host adapter structure. |
| **/ |
| static void qla4xxx_timer(struct scsi_qla_host *ha) |
| { |
| int start_dpc = 0; |
| uint16_t w; |
| |
| iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb); |
| |
| /* If we are in the middle of AER/EEH processing |
| * skip any processing and reschedule the timer |
| */ |
| if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| mod_timer(&ha->timer, jiffies + HZ); |
| return; |
| } |
| |
| /* Hardware read to trigger an EEH error during mailbox waits. */ |
| if (!pci_channel_offline(ha->pdev)) |
| pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
| |
| if (is_qla8022(ha)) { |
| qla4_8xxx_watchdog(ha); |
| } |
| |
| if (!is_qla8022(ha)) { |
| /* Check for heartbeat interval. */ |
| if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && |
| ha->heartbeat_interval != 0) { |
| ha->seconds_since_last_heartbeat++; |
| if (ha->seconds_since_last_heartbeat > |
| ha->heartbeat_interval + 2) |
| set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| } |
| } |
| |
| /* Wakeup the dpc routine for this adapter, if needed. */ |
| if (start_dpc || |
| test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || |
| test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || |
| test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
| test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
| test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || |
| test_bit(DPC_AEN, &ha->dpc_flags)) { |
| DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
| " - dpc flags = 0x%lx\n", |
| ha->host_no, __func__, ha->dpc_flags)); |
| qla4xxx_wake_dpc(ha); |
| } |
| |
| /* Reschedule timer thread to call us back in one second */ |
| mod_timer(&ha->timer, jiffies + HZ); |
| |
| DEBUG2(ha->seconds_since_last_intr++); |
| } |
| |
| /** |
| * qla4xxx_cmd_wait - waits for all outstanding commands to complete |
| * @ha: Pointer to host adapter structure. |
| * |
| * This routine stalls the driver until all outstanding commands are returned. |
| * Caller must release the Hardware Lock prior to calling this routine. |
| **/ |
| static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) |
| { |
| uint32_t index = 0; |
| unsigned long flags; |
| struct scsi_cmnd *cmd; |
| |
| unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " |
| "complete\n", WAIT_CMD_TOV)); |
| |
| while (!time_after_eq(jiffies, wtime)) { |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| /* Find a command that hasn't completed. */ |
| for (index = 0; index < ha->host->can_queue; index++) { |
| cmd = scsi_host_find_tag(ha->host, index); |
| /* |
| * We cannot just check if the index is valid, |
| * becase if we are run from the scsi eh, then |
| * the scsi/block layer is going to prevent |
| * the tag from being released. |
| */ |
| if (cmd != NULL && CMD_SP(cmd)) |
| break; |
| } |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| |
| /* If No Commands are pending, wait is complete */ |
| if (index == ha->host->can_queue) |
| return QLA_SUCCESS; |
| |
| msleep(1000); |
| } |
| /* If we timed out on waiting for commands to come back |
| * return ERROR. */ |
| return QLA_ERROR; |
| } |
| |
| int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
| { |
| uint32_t ctrl_status; |
| unsigned long flags = 0; |
| |
| DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); |
| |
| if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
| return QLA_ERROR; |
| |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| |
| /* |
| * If the SCSI Reset Interrupt bit is set, clear it. |
| * Otherwise, the Soft Reset won't work. |
| */ |
| ctrl_status = readw(&ha->reg->ctrl_status); |
| if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) |
| writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| |
| /* Issue Soft Reset */ |
| writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); |
| readl(&ha->reg->ctrl_status); |
| |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| return QLA_SUCCESS; |
| } |
| |
| /** |
| * qla4xxx_soft_reset - performs soft reset. |
| * @ha: Pointer to host adapter structure. |
| **/ |
| int qla4xxx_soft_reset(struct scsi_qla_host *ha) |
| { |
| uint32_t max_wait_time; |
| unsigned long flags = 0; |
| int status; |
| uint32_t ctrl_status; |
| |
| status = qla4xxx_hw_reset(ha); |
| if (status != QLA_SUCCESS) |
| return status; |
| |
| status = QLA_ERROR; |
| /* Wait until the Network Reset Intr bit is cleared */ |
| max_wait_time = RESET_INTR_TOV; |
| do { |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| ctrl_status = readw(&ha->reg->ctrl_status); |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| |
| if ((ctrl_status & CSR_NET_RESET_INTR) == 0) |
| break; |
| |
| msleep(1000); |
| } while ((--max_wait_time)); |
| |
| if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { |
| DEBUG2(printk(KERN_WARNING |
| "scsi%ld: Network Reset Intr not cleared by " |
| "Network function, clearing it now!\n", |
| ha->host_no)); |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); |
| readl(&ha->reg->ctrl_status); |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| } |
| |
| /* Wait until the firmware tells us the Soft Reset is done */ |
| max_wait_time = SOFT_RESET_TOV; |
| do { |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| ctrl_status = readw(&ha->reg->ctrl_status); |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| |
| if ((ctrl_status & CSR_SOFT_RESET) == 0) { |
| status = QLA_SUCCESS; |
| break; |
| } |
| |
| msleep(1000); |
| } while ((--max_wait_time)); |
| |
| /* |
| * Also, make sure that the SCSI Reset Interrupt bit has been cleared |
| * after the soft reset has taken place. |
| */ |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| ctrl_status = readw(&ha->reg->ctrl_status); |
| if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { |
| writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); |
| readl(&ha->reg->ctrl_status); |
| } |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| |
| /* If soft reset fails then most probably the bios on other |
| * function is also enabled. |
| * Since the initialization is sequential the other fn |
| * wont be able to acknowledge the soft reset. |
| * Issue a force soft reset to workaround this scenario. |
| */ |
| if (max_wait_time == 0) { |
| /* Issue Force Soft Reset */ |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); |
| readl(&ha->reg->ctrl_status); |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| /* Wait until the firmware tells us the Soft Reset is done */ |
| max_wait_time = SOFT_RESET_TOV; |
| do { |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| ctrl_status = readw(&ha->reg->ctrl_status); |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| |
| if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { |
| status = QLA_SUCCESS; |
| break; |
| } |
| |
| msleep(1000); |
| } while ((--max_wait_time)); |
| } |
| |
| return status; |
| } |
| |
| /** |
| * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S. |
| * @ha: Pointer to host adapter structure. |
| * @res: returned scsi status |
| * |
| * This routine is called just prior to a HARD RESET to return all |
| * outstanding commands back to the Operating System. |
| * Caller should make sure that the following locks are released |
| * before this calling routine: Hardware lock, and io_request_lock. |
| **/ |
| static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res) |
| { |
| struct srb *srb; |
| int i; |
| unsigned long flags; |
| |
| spin_lock_irqsave(&ha->hardware_lock, flags); |
| for (i = 0; i < ha->host->can_queue; i++) { |
| srb = qla4xxx_del_from_active_array(ha, i); |
| if (srb != NULL) { |
| srb->cmd->result = res; |
| kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
| } |
| } |
| spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| } |
| |
| void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
| { |
| clear_bit(AF_ONLINE, &ha->flags); |
| |
| /* Disable the board */ |
| ql4_printk(KERN_INFO, ha, "Disabling the board\n"); |
| |
| qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); |
| qla4xxx_mark_all_devices_missing(ha); |
| clear_bit(AF_INIT_DONE, &ha->flags); |
| } |
| |
| static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| |
| sess = cls_session->dd_data; |
| ddb_entry = sess->dd_data; |
| ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED; |
| |
| if (ddb_entry->ddb_type == FLASH_DDB) |
| iscsi_block_session(ddb_entry->sess); |
| else |
| iscsi_session_failure(cls_session->dd_data, |
| ISCSI_ERR_CONN_FAILED); |
| } |
| |
| /** |
| * qla4xxx_recover_adapter - recovers adapter after a fatal error |
| * @ha: Pointer to host adapter structure. |
| **/ |
| static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
| { |
| int status = QLA_ERROR; |
| uint8_t reset_chip = 0; |
| |
| /* Stall incoming I/O until we are done */ |
| scsi_block_requests(ha->host); |
| clear_bit(AF_ONLINE, &ha->flags); |
| clear_bit(AF_LINK_UP, &ha->flags); |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
| |
| set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| |
| iscsi_host_for_each_session(ha->host, qla4xxx_fail_session); |
| |
| if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| reset_chip = 1; |
| |
| /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
| * do not reset adapter, jump to initialize_adapter */ |
| if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| status = QLA_SUCCESS; |
| goto recover_ha_init_adapter; |
| } |
| |
| /* For the ISP-82xx adapter, issue a stop_firmware if invoked |
| * from eh_host_reset or ioctl module */ |
| if (is_qla8022(ha) && !reset_chip && |
| test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "scsi%ld: %s - Performing stop_firmware...\n", |
| ha->host_no, __func__)); |
| status = ha->isp_ops->reset_firmware(ha); |
| if (status == QLA_SUCCESS) { |
| if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| qla4xxx_cmd_wait(ha); |
| ha->isp_ops->disable_intrs(ha); |
| qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| } else { |
| /* If the stop_firmware fails then |
| * reset the entire chip */ |
| reset_chip = 1; |
| clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| set_bit(DPC_RESET_HA, &ha->dpc_flags); |
| } |
| } |
| |
| /* Issue full chip reset if recovering from a catastrophic error, |
| * or if stop_firmware fails for ISP-82xx. |
| * This is the default case for ISP-4xxx */ |
| if (!is_qla8022(ha) || reset_chip) { |
| if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
| qla4xxx_cmd_wait(ha); |
| qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "scsi%ld: %s - Performing chip reset..\n", |
| ha->host_no, __func__)); |
| status = ha->isp_ops->reset_chip(ha); |
| } |
| |
| /* Flush any pending ddb changed AENs */ |
| qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| |
| recover_ha_init_adapter: |
| /* Upon successful firmware/chip reset, re-initialize the adapter */ |
| if (status == QLA_SUCCESS) { |
| /* For ISP-4xxx, force function 1 to always initialize |
| * before function 3 to prevent both funcions from |
| * stepping on top of the other */ |
| if (!is_qla8022(ha) && (ha->mac_index == 3)) |
| ssleep(6); |
| |
| /* NOTE: AF_ONLINE flag set upon successful completion of |
| * qla4xxx_initialize_adapter */ |
| status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER); |
| } |
| |
| /* Retry failed adapter initialization, if necessary |
| * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) |
| * case to prevent ping-pong resets between functions */ |
| if (!test_bit(AF_ONLINE, &ha->flags) && |
| !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| /* Adapter initialization failed, see if we can retry |
| * resetting the ha. |
| * Since we don't want to block the DPC for too long |
| * with multiple resets in the same thread, |
| * utilize DPC to retry */ |
| if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
| ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; |
| DEBUG2(printk("scsi%ld: recover adapter - retrying " |
| "(%d) more times\n", ha->host_no, |
| ha->retry_reset_ha_cnt)); |
| set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| status = QLA_ERROR; |
| } else { |
| if (ha->retry_reset_ha_cnt > 0) { |
| /* Schedule another Reset HA--DPC will retry */ |
| ha->retry_reset_ha_cnt--; |
| DEBUG2(printk("scsi%ld: recover adapter - " |
| "retry remaining %d\n", |
| ha->host_no, |
| ha->retry_reset_ha_cnt)); |
| status = QLA_ERROR; |
| } |
| |
| if (ha->retry_reset_ha_cnt == 0) { |
| /* Recover adapter retries have been exhausted. |
| * Adapter DEAD */ |
| DEBUG2(printk("scsi%ld: recover adapter " |
| "failed - board disabled\n", |
| ha->host_no)); |
| qla4xxx_dead_adapter_cleanup(ha); |
| clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| clear_bit(DPC_RESET_HA_FW_CONTEXT, |
| &ha->dpc_flags); |
| status = QLA_ERROR; |
| } |
| } |
| } else { |
| clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
| } |
| |
| ha->adapter_error_count++; |
| |
| if (test_bit(AF_ONLINE, &ha->flags)) |
| ha->isp_ops->enable_intrs(ha); |
| |
| scsi_unblock_requests(ha->host); |
| |
| clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
| DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, |
| status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
| |
| return status; |
| } |
| |
| static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| |
| sess = cls_session->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| if (!iscsi_is_session_online(cls_session)) { |
| if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { |
| ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| " unblock session\n", ha->host_no, __func__, |
| ddb_entry->fw_ddb_index); |
| iscsi_unblock_session(ddb_entry->sess); |
| } else { |
| /* Trigger relogin */ |
| if (ddb_entry->ddb_type == FLASH_DDB) { |
| if (!test_bit(DF_RELOGIN, &ddb_entry->flags)) |
| qla4xxx_arm_relogin_timer(ddb_entry); |
| } else |
| iscsi_session_failure(cls_session->dd_data, |
| ISCSI_ERR_CONN_FAILED); |
| } |
| } |
| } |
| |
| int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| |
| sess = cls_session->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| " unblock session\n", ha->host_no, __func__, |
| ddb_entry->fw_ddb_index); |
| |
| iscsi_unblock_session(ddb_entry->sess); |
| |
| /* Start scan target */ |
| if (test_bit(AF_ONLINE, &ha->flags)) { |
| ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| " start scan\n", ha->host_no, __func__, |
| ddb_entry->fw_ddb_index); |
| scsi_queue_work(ha->host, &ddb_entry->sess->scan_work); |
| } |
| return QLA_SUCCESS; |
| } |
| |
| int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| |
| sess = cls_session->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" |
| " unblock user space session\n", ha->host_no, __func__, |
| ddb_entry->fw_ddb_index); |
| iscsi_conn_start(ddb_entry->conn); |
| iscsi_conn_login_event(ddb_entry->conn, |
| ISCSI_CONN_STATE_LOGGED_IN); |
| |
| return QLA_SUCCESS; |
| } |
| |
| static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
| { |
| iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices); |
| } |
| |
| static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess) |
| { |
| uint16_t relogin_timer; |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| relogin_timer = max(ddb_entry->default_relogin_timeout, |
| (uint16_t)RELOGIN_TOV); |
| atomic_set(&ddb_entry->relogin_timer, relogin_timer); |
| |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no, |
| ddb_entry->fw_ddb_index, relogin_timer)); |
| |
| qla4xxx_login_flash_ddb(cls_sess); |
| } |
| |
| static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess) |
| { |
| struct iscsi_session *sess; |
| struct ddb_entry *ddb_entry; |
| struct scsi_qla_host *ha; |
| |
| sess = cls_sess->dd_data; |
| ddb_entry = sess->dd_data; |
| ha = ddb_entry->ha; |
| |
| if (!(ddb_entry->ddb_type == FLASH_DDB)) |
| return; |
| |
| if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && |
| !iscsi_is_session_online(cls_sess)) { |
| DEBUG2(ql4_printk(KERN_INFO, ha, |
| "relogin issued\n")); |
| qla4xxx_relogin_flash_ddb(cls_sess); |
| } |
| } |
| |
| void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
| { |
| if (ha->dpc_thread) |
| queue_work(ha->dpc_thread, &ha->dpc_work); |
| } |
| |
| /** |
| * qla4xxx_do_dpc - dpc routine |
| * @data: in our case pointer to adapter structure |
| * |
| * This routine is a task that is schedule by the interrupt handler |
| * to perform the background processing for interrupts. We put it |
| * on a task queue that is consumed whenever the scheduler runs; that's |
| * so you can do anything (i.e. put the process to sleep etc). In fact, |
| * the mid-level tries to sleep when it reaches the driver threshold |
| * "host->can_queue". This can cause a panic if we were in our interrupt code. |
| **/ |
| static void qla4xxx_do_dpc(struct work_struct *work) |
| { |
| struct scsi_qla_host *ha = |
| container_of(work, struct scsi_qla_host, dpc_work); |
| int status = QLA_ERROR; |
| |
| DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
| "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
| ha->host_no, __func__, ha->flags, ha->dpc_flags)) |
| |
| /* Initialization not yet finished. Don't do anything yet. */ |
| if (!test_bit(AF_INIT_DONE, &ha->flags)) |
| return; |
| |
| if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
| DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", |
| ha->host_no, __func__, ha->flags)); |
| return; |
| } |
| |
| if (is_qla8022(ha)) { |
| if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { |
| qla4_8xxx_idc_lock(ha); |
| qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, |
| QLA82XX_DEV_FAILED); |
| qla4_8xxx_idc_unlock(ha); |
| ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); |
| qla4_8xxx_device_state_handler(ha); |
| } |
| if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { |
| qla4_8xxx_need_qsnt_handler(ha); |
| } |
| } |
| |
| if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && |
| (test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
| if (ql4xdontresethba) { |
| DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", |
| ha->host_no, __func__)); |
| clear_bit(DPC_RESET_HA, &ha->dpc_flags); |
| clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
| goto dpc_post_reset_ha; |
| } |
| if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
| test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
| qla4xxx_recover_adapter(ha); |
| |
| if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
| uint8_t wait_time = RESET_INTR_TOV; |
| |
| while ((readw(&ha->reg->ctrl_status) & |
| (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { |
| if (--wait_time == 0) |
| break; |
| msleep(1000); |
| } |
| if (wait_time == 0) |
| DEBUG2(printk("scsi%ld: %s: SR|FSR " |
| "bit not cleared-- resetting\n", |
| ha->host_no, __func__)); |
| qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
| if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
| qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
| status = qla4xxx_recover_adapter(ha); |
| } |
| clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); |
| if (status == QLA_SUCCESS) |
| ha->isp_ops->enable_intrs(ha); |
| } |
| } |
| |
| dpc_post_reset_ha: |
| /* ---- process AEN? --- */ |
| if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) |
| qla4xxx_process_aen(ha, PROCESS_ALL_AENS); |
| |
| /* ---- Get DHCP IP Address? --- */ |
| if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) |
| qla4xxx_get_dhcp_ip_address(ha); |
| |
| /* ---- relogin device? --- */ |
| if (adapter_up(ha) && |
| test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { |
| iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin); |
| } |
| |
| /* ---- link change? --- */ |
| if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { |
| if (!test_bit(AF_LINK_UP, &ha->flags)) { |
| /* ---- link down? --- */ |
| qla4xxx_mark_all_devices_missing(ha); |
| } else { |
| /* ---- link up? --- * |
| * F/W will auto login to all devices ONLY ONCE after |
| * link up during driver initialization and runtime |
| * fatal error recovery. Therefore, the driver must |
| * manually relogin to devices when recovering from |
| * connection failures, logouts, expired KATO, etc. */ |
| if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) { |
| qla4xxx_build_ddb_list(ha, ha->is_reset); |
| iscsi_host_for_each_session(ha->host, |
| qla4xxx_login_flash_ddb); |
| } else |
| qla4xxx_relogin_all_devices(ha); |
| } |
| } |
| } |
| |
| /** |
| * qla4xxx_free_adapter - release the adapter |
| * @ha: pointer to adapter structure |
| **/ |
| static void qla4xxx_free_adapter(struct scsi_qla_host *ha) |
| { |
| |
| if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) { |
| /* Turn-off interrupts on the card. */ |
| ha->isp_ops->disable_intrs(ha); |
| } |
| |
| /* Remove timer thread, if present */ |
| if (ha->timer_active) |
| qla4xxx_stop_timer(ha); |
| |
| /* Kill the kernel thread for this host */ |
| if (ha->dpc_thread) |
| destroy_workqueue(ha->dpc_thread); |
| |
| /* Kill the kernel thread for this host */ |
| if (ha->task_wq) |
| destroy_workqueue(ha->task_wq); |
| |
| /* Put firmware in known state */ |
| ha->isp_ops->reset_firmware(ha); |
| |
| if (is_qla8022(ha)) { |
| qla4_8xxx_idc_lock(ha); |
| qla4_8xxx_clear_drv_active(ha); |
| qla4_8xxx_idc_unlock(ha); |
| } |
| |
| /* Detach interrupts */ |
| if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags)) |
| qla4xxx_free_irqs(ha); |
| |
| /* free extra memory */ |
| qla4xxx_mem_free(ha); |
| } |
| |
| int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) |
| { |
| int status = 0; |
| uint8_t revision_id; |
| unsigned long mem_base, mem_len, db_base, db_len; |
| struct pci_dev *pdev = ha->pdev; |
| |
| status = pci_request_regions(pdev, DRIVER_NAME); |
| if (status) { |
| printk(KERN_WARNING |
| "scsi(%ld) Failed to reserve PIO regions (%s) " |
| "status=%d\n", ha->host_no, pci_name(pdev), status); |
| goto iospace_error_exit; |
| } |
| |
| pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id); |
| DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", |
| __func__, revision_id)); |
| ha->revision_id = revision_id; |
| |
| /* remap phys address */ |
| mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ |
| mem_len = pci_resource_len(pdev, 0); |
| DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", |
| __func__, mem_base, mem_len)); |
| |
| /* mapping of pcibase pointer */ |
| ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); |
| if (!ha->nx_pcibase) { |
| printk(KERN_ERR |
| "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); |
| pci_release_regions(ha->pdev); |
| goto iospace_error_exit; |
| } |
| |
| /* Mapping of IO base pointer, door bell read and write pointer */ |
| |
| /* mapping of IO base pointer */ |
| ha->qla4_8xxx_reg = |
| (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase + |
| 0xbc000 + (ha->pdev->devfn << 11)); |
| |
| db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ |
| db_len = pci_resource_len(pdev, 4); |
| |
| ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
| QLA82XX_CAM_RAM_DB2); |
| |
| return 0; |
| iospace_error_exit: |
| return -ENOMEM; |
| } |
| |
| /*** |
| * qla4xxx_iospace_config - maps registers |
| * @ha: pointer to adapter structure |
| * |
| * This routines maps HBA's registers from the pci address space |
| * into the kernel virtual address space for memory mapped i/o. |
| **/ |
| int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
| { |
| unsigned long pio, pio_len, pio_flags; |
| unsigned long mmio, mmio_len, mmio_flags; |
| |
| pio = pci_resource_start(ha->pdev, 0); |
| pio_len = pci_resource_len(ha->pdev, 0); |
| pio_flags = pci_resource_flags(ha->pdev, 0); |
| if (pio_flags & IORESOURCE_IO) { |
| if (pio_len < MIN_IOBASE_LEN) { |
| ql4_printk(KERN_WARNING, ha, |
| "Invalid PCI I/O region size\n"); |
| pio = 0; |
| } |
| } else { |
| ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
| pio = 0; |
| } |
| |
| /* Use MMIO operations for all accesses. */ |
| mmio = pci_resource_start(ha->pdev, 1); |
| mmio_len = pci_resource_len(ha->pdev, 1); |
| mmio_flags = pci_resource_flags(ha->pdev, 1); |
| |
| if (!(mmio_flags & IORESOURCE_MEM)) { |
| ql4_printk(KERN_ERR, ha, |
| "region #0 not an MMIO resource, aborting\n"); |
| |
| goto iospace_error_exit; |
| } |
| |
| if (mmio_len < MIN_IOBASE_LEN) { |
| ql4_printk(KERN_ERR, ha, |
| "Invalid PCI mem region size, aborting\n"); |
| goto iospace_error_exit; |
| } |
| |
| if (pci_request_regions(ha->pdev, DRIVER_NAME)) { |
| ql4_printk(KERN_WARNING, ha, |
| "Failed to reserve PIO/MMIO regions\n"); |
| |
| goto iospace_error_exit; |
| } |
| |
| ha->pio_address = pio; |
| ha->pio_length = pio_len; |
| ha->reg = ioremap(mmio, MIN_IOBASE_LEN); |
| if (!ha->reg) { |
| ql4_printk(KERN_ERR, ha, |
| "cannot remap MMIO, aborting\n"); |
| |
| goto iospace_error_exit; |
| } |
| |
| return 0; |
| |
| iospace_error_exit: |
| return -ENOMEM; |
| } |
| |
| static struct isp_operations qla4xxx_isp_ops = { |
| .iospace_config = qla4xxx_iospace_config, |
| .pci_config = qla4xxx_pci_config, |
| .disable_intrs = qla4xxx_disable_intrs, |
| .enable_intrs = qla4xxx_enable_intrs, |
| .start_firmware = qla4xxx_start_firmware, |
| .intr_handler = qla4xxx_intr_handler, |
| .interrupt_service_routine = qla4xxx_interrupt_service_routine, |
| .reset_chip = qla4xxx_soft_reset, |
| .reset_firmware = qla4xxx_hw_reset, |
| .queue_iocb = qla4xxx_queue_iocb, |
| .complete_iocb = qla4xxx_complete_iocb, |
| .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, |
| .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, |
| .get_sys_info = qla4xxx_get_sys_info, |
| }; |
| |
| static struct isp_operations qla4_8xxx_isp_ops = { |
| .iospace_config = qla4_8xxx_iospace_config, |
| .pci_config = qla4_8xxx_pci_config, |
| .disable_intrs = qla4_8xxx_disable_intrs, |
| .enable_intrs = qla4_8xxx_enable_intrs, |
| .start_firmware = qla4_8xxx_load_risc, |
| .intr_handler = qla4_8xxx_intr_handler, |
| .interrupt_service_routine = qla4_8xxx_interrupt_service_routine, |
| .reset_chip = qla4_8xxx_isp_reset, |
| .reset_firmware = qla4_8xxx_stop_firmware, |
| .queue_iocb = qla4_8xxx_queue_iocb, |
| .complete_iocb = qla4_8xxx_complete_iocb, |
| .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out, |
| .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in, |
| .get_sys_info = qla4_8xxx_get_sys_info, |
| }; |
| |
| uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| { |
| return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); |
| } |
| |
| uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) |
| { |
| return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out)); |
| } |
| |
| uint16_t
|