/* * Module parameter information and variables
*/ staticint ql4xdisablesysfsboot = 1;
module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ql4xdisablesysfsboot, " Set to disable exporting boot targets to sysfs.\n" "\t\t 0 - Export boot targets\n" "\t\t 1 - Do not export boot targets (Default)");
int ql4xdontresethba;
module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ql4xdontresethba, " Don't reset the HBA for driver recovery.\n" "\t\t 0 - It will reset HBA (Default)\n" "\t\t 1 - It will NOT reset HBA");
int ql4xextended_error_logging;
module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ql4xextended_error_logging, " Option to enable extended error logging.\n" "\t\t 0 - no logging (Default)\n" "\t\t 2 - 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" "\t\t 0 = enable INTx interrupt mechanism.\n" "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n" "\t\t 2 = enable MSI interrupt mechanism.");
#define QL4_DEF_QDEPTH 32 staticint 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" "\t\t Default: 32.");
int ql4xmdcapmask = 0;
module_param(ql4xmdcapmask, int, S_IRUGO);
MODULE_PARM_DESC(ql4xmdcapmask, " Set the Minidump driver capture mask level.\n" "\t\t Default is 0 (firmware default capture mask)\n" "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
int ql4xenablemd = 1;
module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ql4xenablemd, " Set to enable minidump.\n" "\t\t 0 - disable minidump\n" "\t\t 1 - enable minidump (Default)");
static umode_t qla4_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: case ISCSI_HOST_PARAM_PORT_STATE: case ISCSI_HOST_PARAM_PORT_SPEED: 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: case ISCSI_PARAM_CHAP_OUT_IDX: case ISCSI_PARAM_CHAP_IN_IDX: case ISCSI_PARAM_USERNAME: case ISCSI_PARAM_PASSWORD: case ISCSI_PARAM_USERNAME_IN: case ISCSI_PARAM_PASSWORD_IN: case ISCSI_PARAM_AUTO_SND_TGT_DISABLE: case ISCSI_PARAM_DISCOVERY_SESS: case ISCSI_PARAM_PORTAL_TYPE: case ISCSI_PARAM_CHAP_AUTH_EN: case ISCSI_PARAM_DISCOVERY_LOGOUT_EN: case ISCSI_PARAM_BIDI_CHAP_EN: case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL: case ISCSI_PARAM_DEF_TIME2WAIT: case ISCSI_PARAM_DEF_TIME2RETAIN: case ISCSI_PARAM_HDRDGST_EN: case ISCSI_PARAM_DATADGST_EN: case ISCSI_PARAM_INITIAL_R2T_EN: case ISCSI_PARAM_IMM_DATA_EN: case ISCSI_PARAM_PDU_INORDER_EN: case ISCSI_PARAM_DATASEQ_INORDER_EN: case ISCSI_PARAM_MAX_SEGMENT_SIZE: case ISCSI_PARAM_TCP_TIMESTAMP_STAT: case ISCSI_PARAM_TCP_WSF_DISABLE: case ISCSI_PARAM_TCP_NAGLE_DISABLE: case ISCSI_PARAM_TCP_TIMER_SCALE: case ISCSI_PARAM_TCP_TIMESTAMP_EN: case ISCSI_PARAM_TCP_XMIT_WSF: case ISCSI_PARAM_TCP_RECV_WSF: case ISCSI_PARAM_IP_FRAGMENT_DISABLE: case ISCSI_PARAM_IPV4_TOS: case ISCSI_PARAM_IPV6_TC: case ISCSI_PARAM_IPV6_FLOW_LABEL: case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6: case ISCSI_PARAM_KEEPALIVE_TMO: case ISCSI_PARAM_LOCAL_PORT: case ISCSI_PARAM_ISID: case ISCSI_PARAM_TSID: case ISCSI_PARAM_DEF_TASKMGMT_TMO: case ISCSI_PARAM_ERL: case ISCSI_PARAM_STATSN: case ISCSI_PARAM_EXP_STATSN: case ISCSI_PARAM_DISCOVERY_PARENT_IDX: case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: case ISCSI_PARAM_LOCAL_IPADDR: 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: case ISCSI_NET_PARAM_IPADDR_STATE: case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE: case ISCSI_NET_PARAM_IPV6_ROUTER_STATE: case ISCSI_NET_PARAM_DELAYED_ACK_EN: case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: case ISCSI_NET_PARAM_TCP_WSF_DISABLE: case ISCSI_NET_PARAM_TCP_WSF: case ISCSI_NET_PARAM_TCP_TIMER_SCALE: case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: case ISCSI_NET_PARAM_CACHE_ID: case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN: case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN: case ISCSI_NET_PARAM_IPV4_TOS_EN: case ISCSI_NET_PARAM_IPV4_TOS: case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN: case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN: case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID: case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN: case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN: case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID: case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN: case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE: case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN: case ISCSI_NET_PARAM_REDIRECT_EN: case ISCSI_NET_PARAM_IPV4_TTL: case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN: case ISCSI_NET_PARAM_IPV6_MLD_EN: case ISCSI_NET_PARAM_IPV6_FLOW_LABEL: case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS: case ISCSI_NET_PARAM_IPV6_HOP_LIMIT: case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO: case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME: case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO: case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT: case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU: return S_IRUGO; default: return 0;
} case ISCSI_IFACE_PARAM: switch (param) { case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO: case ISCSI_IFACE_PARAM_HDRDGST_EN: case ISCSI_IFACE_PARAM_DATADGST_EN: case ISCSI_IFACE_PARAM_IMM_DATA_EN: case ISCSI_IFACE_PARAM_INITIAL_R2T_EN: case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN: case ISCSI_IFACE_PARAM_PDU_INORDER_EN: case ISCSI_IFACE_PARAM_ERL: case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH: case ISCSI_IFACE_PARAM_FIRST_BURST: case ISCSI_IFACE_PARAM_MAX_R2T: case ISCSI_IFACE_PARAM_MAX_BURST: case ISCSI_IFACE_PARAM_CHAP_AUTH_EN: case ISCSI_IFACE_PARAM_BIDI_CHAP_EN: case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL: case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN: case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN: case ISCSI_IFACE_PARAM_INITIATOR_NAME: return S_IRUGO; default: return 0;
} case ISCSI_FLASHNODE_PARAM: switch (param) { case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6: case ISCSI_FLASHNODE_PORTAL_TYPE: case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE: case ISCSI_FLASHNODE_DISCOVERY_SESS: case ISCSI_FLASHNODE_ENTRY_EN: case ISCSI_FLASHNODE_HDR_DGST_EN: case ISCSI_FLASHNODE_DATA_DGST_EN: case ISCSI_FLASHNODE_IMM_DATA_EN: case ISCSI_FLASHNODE_INITIAL_R2T_EN: case ISCSI_FLASHNODE_DATASEQ_INORDER: case ISCSI_FLASHNODE_PDU_INORDER: case ISCSI_FLASHNODE_CHAP_AUTH_EN: case ISCSI_FLASHNODE_SNACK_REQ_EN: case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN: case ISCSI_FLASHNODE_BIDI_CHAP_EN: case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL: case ISCSI_FLASHNODE_ERL: case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT: case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE: case ISCSI_FLASHNODE_TCP_WSF_DISABLE: case ISCSI_FLASHNODE_TCP_TIMER_SCALE: case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN: case ISCSI_FLASHNODE_IP_FRAG_DISABLE: case ISCSI_FLASHNODE_MAX_RECV_DLENGTH: case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH: case ISCSI_FLASHNODE_FIRST_BURST: case ISCSI_FLASHNODE_DEF_TIME2WAIT: case ISCSI_FLASHNODE_DEF_TIME2RETAIN: case ISCSI_FLASHNODE_MAX_R2T: case ISCSI_FLASHNODE_KEEPALIVE_TMO: case ISCSI_FLASHNODE_ISID: case ISCSI_FLASHNODE_TSID: case ISCSI_FLASHNODE_PORT: case ISCSI_FLASHNODE_MAX_BURST: case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO: case ISCSI_FLASHNODE_IPADDR: case ISCSI_FLASHNODE_ALIAS: case ISCSI_FLASHNODE_REDIRECT_IPADDR: case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE: case ISCSI_FLASHNODE_LOCAL_PORT: case ISCSI_FLASHNODE_IPV4_TOS: case ISCSI_FLASHNODE_IPV6_TC: case ISCSI_FLASHNODE_IPV6_FLOW_LABEL: case ISCSI_FLASHNODE_NAME: case ISCSI_FLASHNODE_TPGT: case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX: case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: case ISCSI_FLASHNODE_TCP_XMIT_WSF: case ISCSI_FLASHNODE_TCP_RECV_WSF: case ISCSI_FLASHNODE_CHAP_OUT_IDX: case ISCSI_FLASHNODE_USERNAME: case ISCSI_FLASHNODE_PASSWORD: case ISCSI_FLASHNODE_STATSN: case ISCSI_FLASHNODE_EXP_STATSN: case ISCSI_FLASHNODE_IS_BOOT_TGT: return S_IRUGO; default: return 0;
}
}
return 0;
}
/** * qla4xxx_create_chap_list - Create CHAP list from FLASH * @ha: pointer to adapter structure * * Read flash and make a list of CHAP entries, during login when a CHAP entry * is received, it will be checked in this list. If entry exist then the CHAP * entry index is set in the DDB. If CHAP entry does not exist in this list * then a new entry is added in FLASH in CHAP table and the index obtained is * used in the DDB.
**/ staticvoid qla4xxx_create_chap_list(struct scsi_qla_host *ha)
{ int rval = 0;
uint8_t *chap_flash_data = NULL;
uint32_t offset;
dma_addr_t chap_dma;
uint32_t chap_size = 0;
if (is_qla40XX(ha))
chap_size = MAX_CHAP_ENTRIES_40XX * sizeof(struct ql4_chap_table); else/* Single region contains CHAP info for both * ports which is divided into half for each port.
*/
chap_size = ha->hw.flt_chap_size / 2;
chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
&chap_dma, GFP_KERNEL); if (!chap_flash_data) {
ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n"); return;
}
if (ha->chap_list == NULL)
ha->chap_list = vmalloc(chap_size); if (ha->chap_list == NULL) {
ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n"); goto exit_chap_list;
}
/** * qla4xxx_find_free_chap_index - Find the first free chap index * @ha: pointer to adapter structure * @chap_index: CHAP index to be returned * * Find the first free chap index available in the chap table * * Note: Caller should acquire the chap lock before getting here.
**/ staticint qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
uint16_t *chap_index)
{ int i, rval; int free_index = -1; int max_chap_entries = 0; struct ql4_chap_table *chap_table;
if (chap_tbl_idx > max_chap_entries) {
ret = -EINVAL; goto exit_delete_chap;
}
/* Check if chap index is in use.
* If chap is in use don't delet chap entry */
ret = qla4xxx_is_chap_active(shost, chap_tbl_idx); if (ret) {
ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot " "delete from flash\n", chap_tbl_idx);
ret = -EBUSY; goto exit_delete_chap;
}
chap_size = sizeof(struct ql4_chap_table); if (is_qla40XX(ha))
offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size); else {
offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2); /* flt_chap_size is CHAP table size for both ports * so divide it by 2 to calculate the offset for second port
*/ if (ha->port_num == 1)
offset += (ha->hw.flt_chap_size / 2);
offset += (chap_tbl_idx * chap_size);
}
ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size); if (ret != QLA_SUCCESS) {
ret = -EINVAL; goto exit_delete_chap;
}
DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
__le16_to_cpu(chap_table->cookie)));
if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
ql4_printk(KERN_ERR, ha, "No valid chap entry found\n"); goto exit_delete_chap;
}
chap_table->cookie = cpu_to_le16(0xFFFF);
offset = FLASH_CHAP_OFFSET |
(chap_tbl_idx * sizeof(struct ql4_chap_table));
ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
FLASH_OPT_RMW_COMMIT); if (ret == QLA_SUCCESS && ha->chap_list) {
mutex_lock(&ha->chap_sem); /* Update ha chap_list cache */
memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
chap_table, sizeof(struct ql4_chap_table));
mutex_unlock(&ha->chap_sem);
} if (ret != QLA_SUCCESS)
ret = -EINVAL;
/** * qla4xxx_set_chap_entry - Make chap entry with given information * @shost: pointer to host * @data: chap info - credentials, index and type to make chap entry * @len: length of data * * Add or update chap entry with the given information
**/ staticint qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
{ struct scsi_qla_host *ha = to_qla_host(shost); struct iscsi_chap_rec chap_rec; struct ql4_chap_table *chap_entry = NULL; struct iscsi_param_info *param_info; struct nlattr *attr; int max_chap_entries = 0; int type; int rem = len; int rc = 0; int size;
mutex_lock(&ha->chap_sem); if (chap_rec.chap_tbl_idx < max_chap_entries) {
rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
&chap_entry); if (!rc) { if (!(type == qla4xxx_get_chap_type(chap_entry))) {
ql4_printk(KERN_INFO, ha, "Type mismatch for CHAP entry %d\n",
chap_rec.chap_tbl_idx);
rc = -EINVAL; goto exit_unlock_chap;
}
/* If chap index is in use then don't modify it */
rc = qla4xxx_is_chap_active(shost,
chap_rec.chap_tbl_idx); if (rc) {
ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use\n",
chap_rec.chap_tbl_idx);
rc = -EBUSY; goto exit_unlock_chap;
}
}
} else {
rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx); if (rc) {
ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
rc = -EBUSY; goto exit_unlock_chap;
}
}
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");
ret = -ENOMEM; goto exit_host_stats;
}
ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
__func__); return ret;
}
staticint 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 ival; char *pval = NULL; int len = -ENOSYS;
if (param_type == ISCSI_NET_PARAM) { 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) {
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_IPV4_PROTOCOL_ENABLE, pval);
} else {
OP_STATE(ha->ip_config.ipv6_options,
IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
}
len = sprintf(buf, "%s\n", pval); 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:
pval = (ha->ip_config.ipv6_addl_options &
IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? "nd" : "static";
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
pval = (ha->ip_config.ipv6_addl_options &
IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? "auto" : "static";
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_VLAN_ID: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
ival = ha->ip_config.ipv4_vlan_tag &
ISCSI_MAX_VLAN_ID; else
ival = ha->ip_config.ipv6_vlan_tag &
ISCSI_MAX_VLAN_ID;
len = sprintf(buf, "%d\n", ival); break; case ISCSI_NET_PARAM_VLAN_PRIORITY: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
ISCSI_MAX_VLAN_PRIORITY; else
ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
ISCSI_MAX_VLAN_PRIORITY;
len = sprintf(buf, "%d\n", ival); break; case ISCSI_NET_PARAM_VLAN_ENABLED: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_VLAN_TAGGING_ENABLE, pval);
} else {
OP_STATE(ha->ip_config.ipv6_options,
IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
}
len = sprintf(buf, "%s\n", pval); 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
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_port); break; case ISCSI_NET_PARAM_IPADDR_STATE: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
pval = iscsi_get_ipaddress_state_name(
ha->ip_config.ipv4_addr_state);
} else { if (iface->iface_num == 0)
pval = iscsi_get_ipaddress_state_name(
ha->ip_config.ipv6_addr0_state); elseif (iface->iface_num == 1)
pval = iscsi_get_ipaddress_state_name(
ha->ip_config.ipv6_addr1_state);
}
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
pval = iscsi_get_ipaddress_state_name(
ha->ip_config.ipv6_link_local_state);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
pval = iscsi_get_router_state_name(
ha->ip_config.ipv6_default_router_state);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_DELAYED_ACK_EN: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
OP_STATE(~ha->ip_config.tcp_options,
TCPOPT_DELAYED_ACK_DISABLE, pval);
} else {
OP_STATE(~ha->ip_config.ipv6_tcp_options,
IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
}
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
OP_STATE(~ha->ip_config.tcp_options,
TCPOPT_NAGLE_ALGO_DISABLE, pval);
} else {
OP_STATE(~ha->ip_config.ipv6_tcp_options,
IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
}
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_TCP_WSF_DISABLE: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
OP_STATE(~ha->ip_config.tcp_options,
TCPOPT_WINDOW_SCALE_DISABLE, pval);
} else {
OP_STATE(~ha->ip_config.ipv6_tcp_options,
IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
pval);
}
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_TCP_WSF: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
len = sprintf(buf, "%d\n",
ha->ip_config.tcp_wsf); else
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_tcp_wsf); break; case ISCSI_NET_PARAM_TCP_TIMER_SCALE: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
ival = (ha->ip_config.tcp_options &
TCPOPT_TIMER_SCALE) >> 1; else
ival = (ha->ip_config.ipv6_tcp_options &
IPV6_TCPOPT_TIMER_SCALE) >> 1;
len = sprintf(buf, "%d\n", ival); break; case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
OP_STATE(ha->ip_config.tcp_options,
TCPOPT_TIMESTAMP_ENABLE, pval);
} else {
OP_STATE(ha->ip_config.ipv6_tcp_options,
IPV6_TCPOPT_TIMESTAMP_EN, pval);
}
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_CACHE_ID: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
len = sprintf(buf, "%d\n",
ha->ip_config.ipv4_cache_id); else
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_cache_id); break; case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
OP_STATE(ha->ip_config.tcp_options,
TCPOPT_DNS_SERVER_IP_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
OP_STATE(ha->ip_config.tcp_options,
TCPOPT_SLP_DA_INFO_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_TOS_EN:
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_IPV4_TOS_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_TOS:
len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos); break; case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_GRAT_ARP_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
pval = (ha->ip_config.ipv4_alt_cid_len) ?
(char *)ha->ip_config.ipv4_alt_cid : "";
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_REQ_VID_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_USE_VID_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
pval = (ha->ip_config.ipv4_vid_len) ?
(char *)ha->ip_config.ipv4_vid : "";
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_LEARN_IQN_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
OP_STATE(~ha->ip_config.ipv4_options,
IPOPT_FRAGMENTATION_DISABLE, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_IN_FORWARD_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_REDIRECT_EN: if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
OP_STATE(ha->ip_config.ipv4_options,
IPOPT_ARP_REDIRECT_EN, pval);
} else {
OP_STATE(ha->ip_config.ipv6_options,
IPV6_OPT_REDIRECT_EN, pval);
}
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV4_TTL:
len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl); break; case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
OP_STATE(ha->ip_config.ipv6_options,
IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV6_MLD_EN:
OP_STATE(ha->ip_config.ipv6_addl_options,
IPV6_ADDOPT_MLD_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl); break; case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_traffic_class); break; case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_hop_limit); break; case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_nd_reach_time); break; case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_nd_rexmit_timer); break; case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_nd_stale_timeout); break; case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_dup_addr_detect_count); break; case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
len = sprintf(buf, "%d\n",
ha->ip_config.ipv6_gw_advrt_mtu); break; default:
len = -ENOSYS;
}
} elseif (param_type == ISCSI_IFACE_PARAM) { switch (param) { case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
len = sprintf(buf, "%d\n", ha->ip_config.def_timeout); break; case ISCSI_IFACE_PARAM_HDRDGST_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_HEADER_DIGEST_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_DATADGST_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_DATA_DIGEST_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_IMM_DATA_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_INITIAL_R2T_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_ERL:
len = sprintf(buf, "%d\n",
(ha->ip_config.iscsi_options &
ISCSIOPTS_ERL)); break; case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
len = sprintf(buf, "%u\n",
ha->ip_config.iscsi_max_pdu_size *
BYTE_UNITS); break; case ISCSI_IFACE_PARAM_FIRST_BURST:
len = sprintf(buf, "%u\n",
ha->ip_config.iscsi_first_burst_len *
BYTE_UNITS); break; case ISCSI_IFACE_PARAM_MAX_R2T:
len = sprintf(buf, "%d\n",
ha->ip_config.iscsi_max_outstnd_r2t); break; case ISCSI_IFACE_PARAM_MAX_BURST:
len = sprintf(buf, "%u\n",
ha->ip_config.iscsi_max_burst_len *
BYTE_UNITS); break; case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_CHAP_AUTH_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_BIDI_CHAP_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
OP_STATE(ha->ip_config.iscsi_options,
ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
len = sprintf(buf, "%s\n", pval); break; case ISCSI_IFACE_PARAM_INITIATOR_NAME:
len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name); break; default:
len = -ENOSYS;
}
}
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; case ISCSI_HOST_PARAM_PORT_STATE:
qla4xxx_set_port_state(shost);
len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost)); break; case ISCSI_HOST_PARAM_PORT_SPEED:
qla4xxx_set_port_speed(shost);
len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost)); break; default: return -ENOSYS;
}
return len;
}
staticvoid 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");
}
staticvoid 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");
}
staticvoid 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);
}
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;
}
staticint 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;
/* 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;
}
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;
}
/*** * 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);
}
/** * 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!.
**/ staticint 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;
/* * As per RISC alignment requirements -- the bus-address must be a * multiple of the request-ring size (in bytes).
*/
align = 0; if ((unsignedlong)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
align = MEM_ALIGN_VALUE - ((unsignedlong)ha->queues_dma &
(MEM_ALIGN_VALUE - 1));
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: return QLA_ERROR;
}
/** * qla4_8xxx_check_temp - Check the ISP82XX temperature. * @ha: adapter block pointer. * * Note: The caller should not hold the idc lock.
**/ staticint qla4_8xxx_check_temp(struct scsi_qla_host *ha)
{
uint32_t temp, temp_state, temp_val; int status = QLA_SUCCESS;
if (temp_state == QLA82XX_TEMP_PANIC) {
ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C" " exceeds maximum allowed. Hardware has been shut" " down.\n", temp_val);
status = QLA_ERROR;
} elseif (temp_state == QLA82XX_TEMP_WARN) { if (ha->temperature == QLA82XX_TEMP_NORMAL)
ql4_printk(KERN_WARNING, ha, "Device temperature %d" " degrees C exceeds operating range." " Immediate action needed.\n", temp_val);
} else { if (ha->temperature == QLA82XX_TEMP_WARN)
ql4_printk(KERN_INFO, ha, "Device temperature is" " now %d degrees C in normal range.\n",
temp_val);
}
ha->temperature = temp_state; return status;
}
/** * qla4_8xxx_check_fw_alive - Check firmware health * @ha: Pointer to host adapter structure. * * Context: Interrupt
**/ staticint qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
{
uint32_t fw_heartbeat_counter; int status = QLA_SUCCESS;
fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
QLA8XXX_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 status;
}
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;
qla4_8xxx_dump_peg_reg(ha);
status = QLA_ERROR;
}
} else
ha->seconds_since_last_heartbeat = 0;
if (is_qla8022(ha)) {
ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
__func__);
qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
CRB_NIU_XG_PAUSE_CTL_P0 |
CRB_NIU_XG_PAUSE_CTL_P1);
if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
__func__); if (halt_status & HALT_STATUS_UNRECOVERABLE)
halt_status_unrecoverable = 1;
} elseif (is_qla8032(ha) || is_qla8042(ha)) { if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
__func__); elseif (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
halt_status_unrecoverable = 1;
}
/* * Since we cannot change dev_state in interrupt context, * set appropriate DPC flag then wakeup DPC
*/ if (halt_status_unrecoverable) {
set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
} else {
ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
__func__);
set_bit(DPC_RESET_HA, &ha->dpc_flags);
}
qla4xxx_mailbox_premature_completion(ha);
qla4xxx_wake_dpc(ha);
}
/** * 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;
uint32_t idc_ctrl;
if (is_qla8032(ha) &&
(qla4_83xx_is_detached(ha) == QLA_SUCCESS))
WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
__func__, ha->func_num);
/* 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))) {
dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
if (qla4_8xxx_check_temp(ha)) { if (is_qla8022(ha)) {
ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
CRB_NIU_XG_PAUSE_CTL_P0 |
CRB_NIU_XG_PAUSE_CTL_P1);
}
set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
qla4xxx_wake_dpc(ha);
} elseif (dev_state == QLA8XXX_DEV_NEED_RESET &&
!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
__func__);
if (is_qla8032(ha) || is_qla8042(ha)) {
idc_ctrl = qla4_83xx_rd_reg(ha,
QLA83XX_IDC_DRV_CTRL); if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
__func__);
qla4xxx_mailbox_premature_completion(
ha);
}
}
if ((is_qla8032(ha) || is_qla8042(ha)) ||
(is_qla8022(ha) && !ql4xdontresethba)) {
set_bit(DPC_RESET_HA, &ha->dpc_flags);
qla4xxx_wake_dpc(ha);
}
} elseif (dev_state == QLA8XXX_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 */ if (qla4_8xxx_check_fw_alive(ha))
qla4_8xxx_process_fw_error(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. * @t: Context to obtain pointer to host adapter structure.
**/ staticvoid qla4xxx_timer(struct timer_list *t)
{ struct scsi_qla_host *ha = timer_container_of(ha, t, timer); int start_dpc = 0;
uint16_t w;
/* 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_qla80XX(ha))
qla4_8xxx_watchdog(ha);
if (is_qla40XX(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);
}
}
/* Process any deferred work. */ if (!list_empty(&ha->work_list))
start_dpc++;
/* 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.
**/ staticint qla4xxx_cmd_wait(struct scsi_qla_host *ha)
{
uint32_t index = 0; unsignedlong flags; struct scsi_cmnd *cmd; unsignedlong wtime;
uint32_t wtmo;
DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %u seconds for cmds to complete\n",
wtmo));
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 && qla4xxx_cmd_priv(cmd)->srb) 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;
}
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);
/** * 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; unsignedlong 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.
**/ staticvoid qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
{ struct srb *srb; int i; unsignedlong 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);
}
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-8xxx adapter, issue a stop_firmware if invoked
* from eh_host_reset or ioctl module */ if (is_qla80XX(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) {
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-8xxx.
* This is the default case for ISP-4xxx */ if (is_qla40XX(ha) || reset_chip) { if (is_qla40XX(ha)) goto chip_reset;
/* Check if 8XXX firmware is alive or not * We may have arrived here from NEED_RESET
* detection only */ if (test_bit(AF_FW_RECOVERY, &ha->flags)) goto chip_reset;
wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ); while (time_before(jiffies, wait)) { if (qla4_8xxx_check_fw_alive(ha)) {
qla4xxx_mailbox_premature_completion(ha); break;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(HZ);
}
chip_reset: if (!test_bit(AF_FW_RECOVERY, &ha->flags))
qla4xxx_cmd_wait(ha);
qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
DEBUG2(ql4_printk(KERN_INFO, ha, "scsi%ld: %s - Performing chip reset..\n",
ha->host_no, __func__));
status = ha->isp_ops->reset_chip(ha);
qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
}
/* 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_qla40XX(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); if (is_qla80XX(ha) && (status == QLA_ERROR)) {
status = qla4_8xxx_check_init_adapter_retry(ha); if (status == QLA_ERROR) {
ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
ha->host_no, __func__);
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); goto exit_recover;
}
}
}
/* 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 (is_qla80XX(ha)) {
ha->isp_ops->idc_lock(ha);
dev_state = qla4_8xxx_rd_direct(ha,
QLA8XXX_CRB_DEV_STATE);
ha->isp_ops->idc_unlock(ha); if (dev_state == QLA8XXX_DEV_FAILED) {
ql4_printk(KERN_INFO, ha, "%s: don't retry " "recover adapter. H/W is in Failed " "state\n", __func__);
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;
goto exit_recover;
}
}
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);
}
exit_recover:
ha->adapter_error_count++;
if (test_bit(AF_ONLINE, &ha->flags))
ha->isp_ops->enable_intrs(ha);
switch (e->type) { case QLA4_EVENT_AEN:
iscsi_post_host_event(ha->host_no,
&qla4xxx_iscsi_transport,
e->u.aen.code,
e->u.aen.data_size,
e->u.aen.data); break; case QLA4_EVENT_PING_STATUS:
iscsi_ping_comp_event(ha->host_no,
&qla4xxx_iscsi_transport,
e->u.ping.status,
e->u.ping.pid,
e->u.ping.data_size,
e->u.ping.data); break; default:
ql4_printk(KERN_WARNING, ha, "event type: 0x%x not " "supported", e->type);
}
kfree(e);
}
}
/** * qla4xxx_do_dpc - dpc routine * @work: Context to obtain pointer to host 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.
**/ staticvoid 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;
/* post events to application */
qla4xxx_do_work(ha);
if (is_qla80XX(ha)) { if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { if (is_qla8032(ha) || is_qla8042(ha)) {
ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
__func__); /* disable pause frame for ISP83xx */
qla4_83xx_disable_pause(ha);
}
/* ---- link change? --- */ if (!test_bit(AF_LOOPBACK, &ha->flags) &&
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);
}
} if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) { if (qla4xxx_sysfs_ddb_export(ha))
ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
__func__);
}
}
/* 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_qla80XX(ha)) {
ha->isp_ops->idc_lock(ha);
qla4_8xxx_clear_drv_active(ha);
ha->isp_ops->idc_unlock(ha);
}
/* Detach interrupts */
qla4xxx_free_irqs(ha);
/* free extra memory */
qla4xxx_mem_free(ha);
}
int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
{ int status = 0; unsignedlong mem_base, mem_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;
}
/*** * 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)
{ unsignedlong pio, pio_len, pio_flags; unsignedlong 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");
static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
{ int rc;
switch (type) { case ISCSI_BOOT_TGT_NAME: case ISCSI_BOOT_TGT_IP_ADDR: case ISCSI_BOOT_TGT_PORT: case ISCSI_BOOT_TGT_CHAP_NAME: case ISCSI_BOOT_TGT_CHAP_SECRET: case ISCSI_BOOT_TGT_REV_CHAP_NAME: case ISCSI_BOOT_TGT_REV_CHAP_SECRET: case ISCSI_BOOT_TGT_NIC_ASSOC: case ISCSI_BOOT_TGT_FLAGS:
rc = S_IRUGO; break; default:
rc = 0; break;
} return rc;
}
/** * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password * @ha: pointer to adapter structure * @username: CHAP username to be returned * @password: CHAP password to be returned * * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/. * So from the CHAP cache find the first BIDI CHAP entry and set it * to the boot record in sysfs.
**/ staticint qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username, char *password)
{ int i, ret = -EINVAL; int max_chap_entries = 0; struct ql4_chap_table *chap_table;
fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
&fw_ddb_entry_dma, GFP_KERNEL); if (!fw_ddb_entry) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to allocate dma buffer.\n",
__func__));
ret = QLA_ERROR; return ret;
}
if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
fw_ddb_entry_dma, ddb_index)) {
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at " "index [%d]\n", __func__, ddb_index));
ret = QLA_ERROR; goto exit_boot_target;
}
/* Update target name and IP from DDB */
memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
min(sizeof(boot_sess->target_name), sizeof(fw_ddb_entry->iscsi_name)));
/* update chap information */
idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
target_chap_name,
(char *)&boot_conn->chap.target_secret,
idx); if (ret) {
ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
ret = QLA_ERROR; goto exit_boot_target;
}
if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr)) return QLA_ERROR;
if (old_tddb->port != new_tddb->port) return QLA_ERROR;
/* For multi sessions, driver generates the ISID, so do not compare * ISID in reset path since it would be a comparison between the * driver generated ISID and firmware generated ISID. This could * lead to adding duplicated DDBs in the list as driver generated * ISID would not match firmware generated ISID.
*/ if (is_isid_compare) {
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%pmR] New ISID [%pmR]\n",
__func__, old_tddb->isid, new_tddb->isid));
if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], sizeof(old_tddb->isid))) return QLA_ERROR;
}
/** * qla4xxx_check_existing_isid - check if target with same isid exist * in target list * @list_nt: list of target * @isid: isid to check * * This routine return QLA_SUCCESS if target with same isid exist
**/ staticint qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
{ struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp; struct dev_db_entry *fw_ddb_entry;
/** * qla4xxx_update_isid - compare ddbs and updated isid * @ha: Pointer to host adapter structure. * @list_nt: list of nt target * @fw_ddb_entry: firmware ddb entry * * This routine update isid if ddbs have same iqn, same isid and * different IP addr. * Return QLA_SUCCESS if isid is updated.
**/ staticint qla4xxx_update_isid(struct scsi_qla_host *ha, struct list_head *list_nt, struct dev_db_entry *fw_ddb_entry)
{
uint8_t base_value, i;
base_value = fw_ddb_entry->isid[1] & 0x1f; for (i = 0; i < 8; i++) {
fw_ddb_entry->isid[1] = (base_value | (i << 5)); if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) break;
}
if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid)) return QLA_ERROR;
return QLA_SUCCESS;
}
/** * qla4xxx_should_update_isid - check if isid need to update * @ha: Pointer to host adapter structure. * @old_tddb: ddb tuple * @new_tddb: ddb tuple * * Return QLA_SUCCESS if different IP, different PORT, same iqn, * same isid
**/ staticint qla4xxx_should_update_isid(struct scsi_qla_host *ha, struct ql4_tuple_ddb *old_tddb, struct ql4_tuple_ddb *new_tddb)
{ if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) { /* Same ip */ if (old_tddb->port == new_tddb->port) return QLA_ERROR;
}
if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name)) /* different iqn */ return QLA_ERROR;
if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0], sizeof(old_tddb->isid))) /* different isid */ return QLA_ERROR;
return QLA_SUCCESS;
}
/** * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt * @ha: Pointer to host adapter structure. * @list_nt: list of nt target. * @fw_ddb_entry: firmware ddb entry. * * This routine check if fw_ddb_entry already exists in list_nt to avoid * duplicate ddb in list_nt. * Return QLA_SUCCESS if duplicate ddb exit in list_nl. * Note: This function also update isid of DDB if required.
**/
for (idx = 0; idx < max_ddbs; idx = next_idx) {
ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
NULL, &next_idx, &state,
&conn_err, NULL, &conn_id); if (ret == QLA_ERROR) break;
/* Ignore DDB if invalid state (unassigned) */ if (state == DDB_DS_UNASSIGNED) goto continue_next_st;
/* Check if ST, add to the list_st */ if (strlen((char *) fw_ddb_entry->iscsi_name) != 0) goto continue_next_st;
st_ddb_idx = vzalloc(fw_idx_size); if (!st_ddb_idx) break;
ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
&flash_index); if (ret == QLA_ERROR) {
ql4_printk(KERN_ERR, ha, "No flash entry for ST at idx [%d]\n", idx);
st_ddb_idx->flash_ddb_idx = idx;
} else {
ql4_printk(KERN_INFO, ha, "ST at idx [%d] is stored at flash [%d]\n",
idx, flash_index);
st_ddb_idx->flash_ddb_idx = flash_index;
}
st_ddb_idx->fw_ddb_idx = idx;
list_add_tail(&st_ddb_idx->list, list_st);
continue_next_st: if (next_idx == 0) break;
}
exit_st_list: if (fw_ddb_entry)
dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
}
/** * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list * @ha: pointer to adapter structure * @list_ddb: List from which failed ddb to be removed * * Iterate over the list of DDBs and find and remove DDBs that are either in * no connection active state or failed state
**/ staticvoid qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha, struct list_head *list_ddb)
{ struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
uint32_t next_idx = 0;
uint32_t state = 0, conn_err = 0; int ret;
/* Create session object, with INVALID_ENTRY, * the targer_id would get set when we issue the login
*/
cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
cmds_max, sizeof(struct ddb_entry), sizeof(struct ql4_task_data),
initial_cmdsn, INVALID_ENTRY); if (!cls_sess) {
ret = QLA_ERROR; goto exit_setup;
}
/* * so calling module_put function to decrement the * reference count.
**/
module_put(qla4xxx_iscsi_transport.owner);
sess = cls_sess->dd_data;
ddb_entry = sess->dd_data;
ddb_entry->sess = cls_sess;
if (!cls_conn) {
ret = QLA_ERROR; goto exit_setup;
}
ddb_entry->conn = cls_conn;
/* Setup ep, for displaying attributes in sysfs */
ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry); if (ep) {
ep->conn = cls_conn;
cls_conn->ep = ep;
} else {
DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
ret = QLA_ERROR; goto exit_setup;
}
if (is_reset == RESET_ADAPTER) {
iscsi_block_session(cls_sess); /* Use the relogin path to discover new devices * by short-circuiting the logic of setting * timer to relogin - instead set the flags * to initiate login right away.
*/
set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
set_bit(DF_RELOGIN, &ddb_entry->flags);
}
fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
&fw_ddb_dma); if (fw_ddb_entry == NULL) {
DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); goto exit_nt_list;
}
max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
MAX_DEV_DB_ENTRIES;
fw_idx_size = sizeof(struct qla_ddb_index);
for (idx = 0; idx < max_ddbs; idx = next_idx) {
ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
NULL, &next_idx, &state,
&conn_err, NULL, &conn_id); if (ret == QLA_ERROR) break;
if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS) goto continue_next_nt;
/* Check if NT, then add to list it */ if (strlen((char *) fw_ddb_entry->iscsi_name) == 0) goto continue_next_nt;
ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link); if (ddb_link < max_ddbs)
qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
state == DDB_DS_SESSION_FAILED) &&
(is_reset == INIT_ADAPTER)) goto continue_next_nt;
DEBUG2(ql4_printk(KERN_INFO, ha, "Adding DDB to session = 0x%x\n", idx));
if (is_reset == INIT_ADAPTER) {
nt_ddb_idx = vmalloc(fw_idx_size); if (!nt_ddb_idx) break;
nt_ddb_idx->fw_ddb_idx = idx;
/* Copy original isid as it may get updated in function * qla4xxx_update_isid(). We need original isid in * function qla4xxx_compare_tuple_ddb to find duplicate
* target */
memcpy(&nt_ddb_idx->flash_isid[0],
&fw_ddb_entry->isid[0], sizeof(nt_ddb_idx->flash_isid));
ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
fw_ddb_entry); if (ret == QLA_SUCCESS) { /* free nt_ddb_idx and do not add to list_nt */
vfree(nt_ddb_idx); goto continue_next_nt;
}
fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
&fw_ddb_dma); if (fw_ddb_entry == NULL) {
DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n")); goto exit_new_nt_list;
}
max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
MAX_DEV_DB_ENTRIES;
fw_idx_size = sizeof(struct qla_ddb_index);
for (idx = 0; idx < max_ddbs; idx = next_idx) {
ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
NULL, &next_idx, &state,
&conn_err, NULL, &conn_id); if (ret == QLA_ERROR) break;
/* Check if NT, then add it to list */ if (strlen((char *)fw_ddb_entry->iscsi_name) == 0) goto continue_next_new_nt;
if (!(state == DDB_DS_NO_CONNECTION_ACTIVE)) goto continue_next_new_nt;
DEBUG2(ql4_printk(KERN_INFO, ha, "Adding DDB to session = 0x%x\n", idx));
nt_ddb_idx = vmalloc(fw_idx_size); if (!nt_ddb_idx) break;
nt_ddb_idx->fw_ddb_idx = idx;
ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); if (ret == QLA_SUCCESS) { /* free nt_ddb_idx and do not add to list_nt */
vfree(nt_ddb_idx); goto continue_next_new_nt;
}
if (target_id < max_ddbs)
fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
list_add_tail(&nt_ddb_idx->list, list_nt);
ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
idx); if (ret == QLA_ERROR) goto exit_new_nt_list;
continue_next_new_nt: if (next_idx == 0) break;
}
exit_new_nt_list: if (fw_ddb_entry)
dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
}
/** * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry * @dev: dev associated with the sysfs entry * @data: pointer to flashnode session object * * Returns: * 1: if flashnode entry is non-persistent * 0: if flashnode entry is persistent
**/ staticint qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, constvoid *data)
{ struct iscsi_bus_flash_session *fnode_sess;
if (!iscsi_flashnode_bus_match(dev, NULL)) return 0;
/** * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target * @ha: pointer to host * @fw_ddb_entry: flash ddb data * @idx: target index * @user: if set then this call is made from userland else from kernel * * Returns: * On sucess: QLA_SUCCESS * On failure: QLA_ERROR * * This create separate sysfs entries for session and connection attributes of * the given fw ddb entry. * If this is invoked as a result of a userspace call then the entry is marked * as nonpersistent using flash_state field.
**/ staticint qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha, struct dev_db_entry *fw_ddb_entry,
uint16_t *idx, int user)
{ struct iscsi_bus_flash_session *fnode_sess = NULL; struct iscsi_bus_flash_conn *fnode_conn = NULL; int rc = QLA_ERROR;
fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
&qla4xxx_iscsi_transport, 0); if (!fnode_sess) {
ql4_printk(KERN_ERR, ha, "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
__func__, *idx, ha->host_no); goto exit_tgt_create;
}
fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
&qla4xxx_iscsi_transport, 0); if (!fnode_conn) {
ql4_printk(KERN_ERR, ha, "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
__func__, *idx, ha->host_no); goto free_sess;
}
/** * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash * @shost: pointer to host * @buf: type of ddb entry (ipv4/ipv6) * @len: length of buf * * This creates new ddb entry in the flash by finding first free index and * storing default ddb there. And then create sysfs entry for the new ddb entry.
**/ staticint qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, constchar *buf, int len)
{ struct scsi_qla_host *ha = to_qla_host(shost); struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma; struct device *dev;
uint16_t idx = 0;
uint16_t max_ddbs = 0;
uint32_t options = 0;
uint32_t rval = QLA_ERROR;
if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
__func__)); goto exit_ddb_add;
}
fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
&fw_ddb_entry_dma, GFP_KERNEL); if (!fw_ddb_entry) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to allocate dma buffer\n",
__func__)); goto exit_ddb_add;
}
dev = iscsi_find_flashnode_sess(ha->host, NULL,
qla4xxx_sysfs_ddb_is_non_persistent); if (dev) {
ql4_printk(KERN_ERR, ha, "%s: A non-persistent entry %s found\n",
__func__, dev->kobj.name);
put_device(dev); goto exit_ddb_add;
}
/* Index 0 and 1 are reserved for boot target entries */ for (idx = 2; idx < max_ddbs; idx++) { if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
fw_ddb_entry_dma, idx)) break;
}
if (idx == max_ddbs) goto exit_ddb_add;
if (!strncasecmp("ipv6", buf, 4))
options |= IPV6_DEFAULT_DDB_ENTRY;
exit_ddb_add: if (fw_ddb_entry)
dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
fw_ddb_entry, fw_ddb_entry_dma); if (rval == QLA_SUCCESS) return idx; else return -EIO;
}
/** * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash * @fnode_sess: pointer to session attrs of flash ddb entry * @fnode_conn: pointer to connection attrs of flash ddb entry * * This writes the contents of target ddb buffer to Flash with a valid cookie * value in order to make the ddb entry persistent.
**/ staticint qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess, struct iscsi_bus_flash_conn *fnode_conn)
{ struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); struct scsi_qla_host *ha = to_qla_host(shost);
uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO; struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma;
uint32_t options = 0; int rval = 0;
fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
&fw_ddb_entry_dma, GFP_KERNEL); if (!fw_ddb_entry) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to allocate dma buffer\n",
__func__));
rval = -ENOMEM; goto exit_ddb_apply;
}
if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
options |= IPV6_DEFAULT_DDB_ENTRY;
ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts); if (ret != QLA_SUCCESS) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to set ddb entry for index %d\n",
__func__, idx)); goto exit_ddb_conn_open;
}
qla4xxx_conn_open(ha, idx);
/* To ensure that sendtargets is done, wait for at least 12 secs */
tmo = ((ha->def_timeout > LOGIN_TOV) &&
(ha->def_timeout < LOGIN_TOV * 10) ?
ha->def_timeout : LOGIN_TOV);
DEBUG2(ql4_printk(KERN_INFO, ha, "Default time to wait for login to ddb %d\n", tmo));
wtime = jiffies + (HZ * tmo); do {
ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
NULL, &state, &conn_err, NULL,
NULL); if (ret == QLA_ERROR) continue;
if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
state == DDB_DS_SESSION_FAILED) break;
schedule_timeout_uninterruptible(HZ / 10);
} while (time_after(wtime, jiffies));
exit_ddb_conn_open: if (ddb_entry)
dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
ddb_entry, ddb_entry_dma); return ret;
}
if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
ql4_printk(KERN_WARNING, ha, "%s: A discovery already in progress!\n", __func__); return QLA_ERROR;
}
INIT_LIST_HEAD(&list_nt);
set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
ret = qla4xxx_get_ddb_index(ha, &ddb_index); if (ret == QLA_ERROR) goto exit_login_st_clr_bit;
ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index); if (ret == QLA_ERROR) goto exit_login_st;
staticint qla4xxx_ddb_login_nt(struct scsi_qla_host *ha, struct dev_db_entry *fw_ddb_entry,
uint16_t idx)
{ int ret = QLA_ERROR;
ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL); if (ret != QLA_SUCCESS)
ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
idx); else
ret = -EPERM;
return ret;
}
/** * qla4xxx_sysfs_ddb_login - Login to the specified target * @fnode_sess: pointer to session attrs of flash ddb entry * @fnode_conn: pointer to connection attrs of flash ddb entry * * This logs in to the specified target
**/ staticint qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess, struct iscsi_bus_flash_conn *fnode_conn)
{ struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); struct scsi_qla_host *ha = to_qla_host(shost); struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma;
uint32_t options = 0; int ret = 0;
if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
ql4_printk(KERN_ERR, ha, "%s: Target info is not persistent\n", __func__);
ret = -EIO; goto exit_ddb_login;
}
fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
&fw_ddb_entry_dma, GFP_KERNEL); if (!fw_ddb_entry) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to allocate dma buffer\n",
__func__));
ret = -ENOMEM; goto exit_ddb_login;
}
if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
options |= IPV6_DEFAULT_DDB_ENTRY;
ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma); if (ret == QLA_ERROR) goto exit_ddb_login;
if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
fnode_sess->target_id); else
ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
fnode_sess->target_id);
if (ret > 0)
ret = -EIO;
exit_ddb_login: if (fw_ddb_entry)
dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
fw_ddb_entry, fw_ddb_entry_dma); return ret;
}
/** * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target * @cls_sess: pointer to session to be logged out * * This performs session log out from the specified target
**/ staticint qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
{ struct iscsi_session *sess; struct ddb_entry *ddb_entry = NULL; struct scsi_qla_host *ha; struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma; unsignedlong flags; unsignedlong wtime;
uint32_t ddb_state; int options; int ret = 0;
sess = cls_sess->dd_data;
ddb_entry = sess->dd_data;
ha = ddb_entry->ha;
if (ddb_entry->ddb_type != FLASH_DDB) {
ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
__func__);
ret = -ENXIO; goto exit_ddb_logout;
}
if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
ql4_printk(KERN_ERR, ha, "%s: Logout from boot target entry is not permitted.\n",
__func__);
ret = -EPERM; goto exit_ddb_logout;
}
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_ddb_logout;
}
if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags)) goto ddb_logout_init;
ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
fw_ddb_entry, fw_ddb_entry_dma,
NULL, NULL, &ddb_state, NULL,
NULL, NULL); if (ret == QLA_ERROR) goto ddb_logout_init;
if (ddb_state == DDB_DS_SESSION_ACTIVE) goto ddb_logout_init;
/* wait until next relogin is triggered using DF_RELOGIN and * clear DF_RELOGIN to avoid invocation of further relogin
*/
wtime = jiffies + (HZ * RELOGIN_TOV); do { if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags)) goto ddb_logout_init;
schedule_timeout_uninterruptible(HZ);
} while ((time_after(wtime, jiffies)));
memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
wtime = jiffies + (HZ * LOGOUT_TOV); do {
ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
fw_ddb_entry, fw_ddb_entry_dma,
NULL, NULL, &ddb_state, NULL,
NULL, NULL); if (ret == QLA_ERROR) goto ddb_logout_clr_sess;
if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
(ddb_state == DDB_DS_SESSION_FAILED)) goto ddb_logout_clr_sess;
schedule_timeout_uninterruptible(HZ);
} while ((time_after(wtime, jiffies)));
ddb_logout_clr_sess:
qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index); /* * we have decremented the reference count of the driver * when we setup the session to have the driver unload * to be seamless without actually destroying the * session
**/
try_module_get(qla4xxx_iscsi_transport.owner);
iscsi_destroy_endpoint(ddb_entry->conn->ep);
clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
ret = QLA_SUCCESS;
exit_ddb_logout: if (fw_ddb_entry)
dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
fw_ddb_entry, fw_ddb_entry_dma); return ret;
}
/** * qla4xxx_sysfs_ddb_logout - Logout from the specified target * @fnode_sess: pointer to session attrs of flash ddb entry * @fnode_conn: pointer to connection attrs of flash ddb entry * * This performs log out from the specified target
**/ staticint qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, struct iscsi_bus_flash_conn *fnode_conn)
{ struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); struct scsi_qla_host *ha = to_qla_host(shost); struct ql4_tuple_ddb *flash_tddb = NULL; struct ql4_tuple_ddb *tmp_tddb = NULL; struct dev_db_entry *fw_ddb_entry = NULL; struct ddb_entry *ddb_entry = NULL;
dma_addr_t fw_ddb_dma;
uint32_t next_idx = 0;
uint32_t state = 0, conn_err = 0;
uint16_t conn_id = 0; int idx, index; int status, ret = 0;
fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
&fw_ddb_dma); if (fw_ddb_entry == NULL) {
ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
ret = -ENOMEM; goto exit_ddb_logout;
}
flash_tddb = vzalloc(sizeof(*flash_tddb)); if (!flash_tddb) {
ql4_printk(KERN_WARNING, ha, "%s:Memory Allocation failed.\n", __func__);
ret = -ENOMEM; goto exit_ddb_logout;
}
tmp_tddb = vzalloc(sizeof(*tmp_tddb)); if (!tmp_tddb) {
ql4_printk(KERN_WARNING, ha, "%s:Memory Allocation failed.\n", __func__);
ret = -ENOMEM; goto exit_ddb_logout;
}
if (!fnode_sess->targetname) {
ql4_printk(KERN_ERR, ha, "%s:Cannot logout from SendTarget entry\n",
__func__);
ret = -EPERM; goto exit_ddb_logout;
}
if (fnode_sess->is_boot_target) {
ql4_printk(KERN_ERR, ha, "%s: Logout from boot target entry is not permitted.\n",
__func__);
ret = -EPERM; goto exit_ddb_logout;
}
dev = iscsi_find_flashnode_conn(fnode_sess); if (!dev) return -EIO;
fnode_conn = iscsi_dev_to_flash_conn(dev);
switch (param) { case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6); break; case ISCSI_FLASHNODE_PORTAL_TYPE:
rc = sprintf(buf, "%s\n", fnode_sess->portal_type); break; case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable); break; case ISCSI_FLASHNODE_DISCOVERY_SESS:
rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess); break; case ISCSI_FLASHNODE_ENTRY_EN:
rc = sprintf(buf, "%u\n", fnode_sess->entry_state); break; case ISCSI_FLASHNODE_HDR_DGST_EN:
rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en); break; case ISCSI_FLASHNODE_DATA_DGST_EN:
rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en); break; case ISCSI_FLASHNODE_IMM_DATA_EN:
rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en); break; case ISCSI_FLASHNODE_INITIAL_R2T_EN:
rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en); break; case ISCSI_FLASHNODE_DATASEQ_INORDER:
rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en); break; case ISCSI_FLASHNODE_PDU_INORDER:
rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en); break; case ISCSI_FLASHNODE_CHAP_AUTH_EN:
rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en); break; case ISCSI_FLASHNODE_SNACK_REQ_EN:
rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en); break; case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en); break; case ISCSI_FLASHNODE_BIDI_CHAP_EN:
rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en); break; case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional); break; case ISCSI_FLASHNODE_ERL:
rc = sprintf(buf, "%u\n", fnode_sess->erl); break; case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat); break; case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable); break; case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable); break; case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale); break; case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en); break; case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable); break; case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength); break; case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength); break; case ISCSI_FLASHNODE_FIRST_BURST:
rc = sprintf(buf, "%u\n", fnode_sess->first_burst); break; case ISCSI_FLASHNODE_DEF_TIME2WAIT:
rc = sprintf(buf, "%u\n", fnode_sess->time2wait); break; case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
rc = sprintf(buf, "%u\n", fnode_sess->time2retain); break; case ISCSI_FLASHNODE_MAX_R2T:
rc = sprintf(buf, "%u\n", fnode_sess->max_r2t); break; case ISCSI_FLASHNODE_KEEPALIVE_TMO:
rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout); break; case ISCSI_FLASHNODE_ISID:
rc = sprintf(buf, "%pm\n", fnode_sess->isid); break; case ISCSI_FLASHNODE_TSID:
rc = sprintf(buf, "%u\n", fnode_sess->tsid); break; case ISCSI_FLASHNODE_PORT:
rc = sprintf(buf, "%d\n", fnode_conn->port); break; case ISCSI_FLASHNODE_MAX_BURST:
rc = sprintf(buf, "%u\n", fnode_sess->max_burst); break; case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
rc = sprintf(buf, "%u\n",
fnode_sess->default_taskmgmt_timeout); break; case ISCSI_FLASHNODE_IPADDR: if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress); else
rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress); break; case ISCSI_FLASHNODE_ALIAS: if (fnode_sess->targetalias)
rc = sprintf(buf, "%s\n", fnode_sess->targetalias); else
rc = sprintf(buf, "\n"); break; case ISCSI_FLASHNODE_REDIRECT_IPADDR: if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
rc = sprintf(buf, "%pI6\n",
fnode_conn->redirect_ipaddr); else
rc = sprintf(buf, "%pI4\n",
fnode_conn->redirect_ipaddr); break; case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size); break; case ISCSI_FLASHNODE_LOCAL_PORT:
rc = sprintf(buf, "%u\n", fnode_conn->local_port); break; case ISCSI_FLASHNODE_IPV4_TOS:
rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos); break; case ISCSI_FLASHNODE_IPV6_TC: if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
rc = sprintf(buf, "%u\n",
fnode_conn->ipv6_traffic_class); else
rc = sprintf(buf, "\n"); break; case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label); break; case ISCSI_FLASHNODE_LINK_LOCAL_IPV6: if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
rc = sprintf(buf, "%pI6\n",
fnode_conn->link_local_ipv6_addr); else
rc = sprintf(buf, "\n"); break; case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx); break; case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE: if (fnode_sess->discovery_parent_type == DDB_ISNS)
parent_type = ISCSI_DISC_PARENT_ISNS; elseif (fnode_sess->discovery_parent_type == DDB_NO_LINK)
parent_type = ISCSI_DISC_PARENT_UNKNOWN; elseif (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
parent_type = ISCSI_DISC_PARENT_SENDTGT; else
parent_type = ISCSI_DISC_PARENT_UNKNOWN;
rc = sprintf(buf, "%s\n",
iscsi_get_discovery_parent_name(parent_type)); break; case ISCSI_FLASHNODE_NAME: if (fnode_sess->targetname)
rc = sprintf(buf, "%s\n", fnode_sess->targetname); else
rc = sprintf(buf, "\n"); break; case ISCSI_FLASHNODE_TPGT:
rc = sprintf(buf, "%u\n", fnode_sess->tpgt); break; case ISCSI_FLASHNODE_TCP_XMIT_WSF:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf); break; case ISCSI_FLASHNODE_TCP_RECV_WSF:
rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf); break; case ISCSI_FLASHNODE_CHAP_OUT_IDX:
rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx); break; case ISCSI_FLASHNODE_USERNAME: if (fnode_sess->chap_auth_en) {
qla4xxx_get_uni_chap_at_index(ha,
chap_tbl.name,
chap_tbl.secret,
fnode_sess->chap_out_idx);
rc = sprintf(buf, "%s\n", chap_tbl.name);
} else {
rc = sprintf(buf, "\n");
} break; case ISCSI_FLASHNODE_PASSWORD: if (fnode_sess->chap_auth_en) {
qla4xxx_get_uni_chap_at_index(ha,
chap_tbl.name,
chap_tbl.secret,
fnode_sess->chap_out_idx);
rc = sprintf(buf, "%s\n", chap_tbl.secret);
} else {
rc = sprintf(buf, "\n");
} break; case ISCSI_FLASHNODE_STATSN:
rc = sprintf(buf, "%u\n", fnode_conn->statsn); break; case ISCSI_FLASHNODE_EXP_STATSN:
rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn); break; case ISCSI_FLASHNODE_IS_BOOT_TGT:
rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target); break; default:
rc = -ENOSYS; break;
}
put_device(dev); return rc;
}
/** * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry * @fnode_sess: pointer to session attrs of flash ddb entry * @fnode_conn: pointer to connection attrs of flash ddb entry * @data: Parameters and their values to update * @len: len of data * * This sets the parameter of flash ddb entry and writes them to flash
**/ staticint
qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess, struct iscsi_bus_flash_conn *fnode_conn, void *data, int len)
{ struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); struct scsi_qla_host *ha = to_qla_host(shost); struct iscsi_flashnode_param_info *fnode_param; struct ql4_chap_table chap_tbl; struct nlattr *attr;
uint16_t chap_out_idx = INVALID_ENTRY; int rc = QLA_ERROR;
uint32_t rem = len;
switch (fnode_param->param) { case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0]; break; case ISCSI_FLASHNODE_PORTAL_TYPE:
memcpy(fnode_sess->portal_type, fnode_param->value,
strlen(fnode_sess->portal_type)); break; case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
fnode_sess->auto_snd_tgt_disable =
fnode_param->value[0]; break; case ISCSI_FLASHNODE_DISCOVERY_SESS:
fnode_sess->discovery_sess = fnode_param->value[0]; break; case ISCSI_FLASHNODE_ENTRY_EN:
fnode_sess->entry_state = fnode_param->value[0]; break; case ISCSI_FLASHNODE_HDR_DGST_EN:
fnode_conn->hdrdgst_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_DATA_DGST_EN:
fnode_conn->datadgst_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_IMM_DATA_EN:
fnode_sess->imm_data_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_INITIAL_R2T_EN:
fnode_sess->initial_r2t_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_DATASEQ_INORDER:
fnode_sess->dataseq_inorder_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_PDU_INORDER:
fnode_sess->pdu_inorder_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_CHAP_AUTH_EN:
fnode_sess->chap_auth_en = fnode_param->value[0]; /* Invalidate chap index if chap auth is disabled */ if (!fnode_sess->chap_auth_en)
fnode_sess->chap_out_idx = INVALID_ENTRY;
break; case ISCSI_FLASHNODE_SNACK_REQ_EN:
fnode_conn->snack_req_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
fnode_sess->discovery_logout_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_BIDI_CHAP_EN:
fnode_sess->bidi_chap_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
fnode_sess->discovery_auth_optional =
fnode_param->value[0]; break; case ISCSI_FLASHNODE_ERL:
fnode_sess->erl = fnode_param->value[0]; break; case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
fnode_conn->tcp_timestamp_stat = fnode_param->value[0]; break; case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
fnode_conn->tcp_nagle_disable = fnode_param->value[0]; break; case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
fnode_conn->tcp_wsf_disable = fnode_param->value[0]; break; case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
fnode_conn->tcp_timer_scale = fnode_param->value[0]; break; case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
fnode_conn->tcp_timestamp_en = fnode_param->value[0]; break; case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
fnode_conn->fragment_disable = fnode_param->value[0]; break; case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
fnode_conn->max_recv_dlength =
*(unsigned *)fnode_param->value; break; case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
fnode_conn->max_xmit_dlength =
*(unsigned *)fnode_param->value; break; case ISCSI_FLASHNODE_FIRST_BURST:
fnode_sess->first_burst =
*(unsigned *)fnode_param->value; break; case ISCSI_FLASHNODE_DEF_TIME2WAIT:
fnode_sess->time2wait = *(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
fnode_sess->time2retain =
*(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_MAX_R2T:
fnode_sess->max_r2t =
*(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_KEEPALIVE_TMO:
fnode_conn->keepalive_timeout =
*(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_ISID:
memcpy(fnode_sess->isid, fnode_param->value, sizeof(fnode_sess->isid)); break; case ISCSI_FLASHNODE_TSID:
fnode_sess->tsid = *(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_PORT:
fnode_conn->port = *(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_MAX_BURST:
fnode_sess->max_burst = *(unsigned *)fnode_param->value; break; case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
fnode_sess->default_taskmgmt_timeout =
*(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_IPADDR:
memcpy(fnode_conn->ipaddress, fnode_param->value,
IPv6_ADDR_LEN); break; case ISCSI_FLASHNODE_ALIAS:
rc = iscsi_switch_str_param(&fnode_sess->targetalias,
(char *)fnode_param->value); break; case ISCSI_FLASHNODE_REDIRECT_IPADDR:
memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
IPv6_ADDR_LEN); break; case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
fnode_conn->max_segment_size =
*(unsigned *)fnode_param->value; break; case ISCSI_FLASHNODE_LOCAL_PORT:
fnode_conn->local_port =
*(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_IPV4_TOS:
fnode_conn->ipv4_tos = fnode_param->value[0]; break; case ISCSI_FLASHNODE_IPV6_TC:
fnode_conn->ipv6_traffic_class = fnode_param->value[0]; break; case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
fnode_conn->ipv6_flow_label = fnode_param->value[0]; break; case ISCSI_FLASHNODE_NAME:
rc = iscsi_switch_str_param(&fnode_sess->targetname,
(char *)fnode_param->value); break; case ISCSI_FLASHNODE_TPGT:
fnode_sess->tpgt = *(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
memcpy(fnode_conn->link_local_ipv6_addr,
fnode_param->value, IPv6_ADDR_LEN); break; case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
fnode_sess->discovery_parent_idx =
*(uint16_t *)fnode_param->value; break; case ISCSI_FLASHNODE_TCP_XMIT_WSF:
fnode_conn->tcp_xmit_wsf =
*(uint8_t *)fnode_param->value; break; case ISCSI_FLASHNODE_TCP_RECV_WSF:
fnode_conn->tcp_recv_wsf =
*(uint8_t *)fnode_param->value; break; case ISCSI_FLASHNODE_STATSN:
fnode_conn->statsn = *(uint32_t *)fnode_param->value; break; case ISCSI_FLASHNODE_EXP_STATSN:
fnode_conn->exp_statsn =
*(uint32_t *)fnode_param->value; break; case ISCSI_FLASHNODE_CHAP_OUT_IDX:
chap_out_idx = *(uint16_t *)fnode_param->value; if (!qla4xxx_get_uni_chap_at_index(ha,
chap_tbl.name,
chap_tbl.secret,
chap_out_idx)) {
fnode_sess->chap_out_idx = chap_out_idx; /* Enable chap auth if chap index is valid */
fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
} break; default:
ql4_printk(KERN_ERR, ha, "%s: No such sysfs attribute\n", __func__);
rc = -ENOSYS; goto exit_set_param;
}
}
/** * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry * @fnode_sess: pointer to session attrs of flash ddb entry * * This invalidates the flash ddb entry at the given index
**/ staticint qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
{ struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess); struct scsi_qla_host *ha = to_qla_host(shost);
uint32_t dev_db_start_offset;
uint32_t dev_db_end_offset; struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma;
uint16_t *ddb_cookie = NULL;
size_t ddb_size = 0; void *pddb = NULL; int target_id; int rc = 0;
if (fnode_sess->is_boot_target) {
rc = -EPERM;
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Deletion of boot target entry is not permitted.\n",
__func__)); goto exit_ddb_del;
}
if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) goto sysfs_ddb_del;
if (is_qla40XX(ha)) {
dev_db_start_offset = FLASH_OFFSET_DB_INFO;
dev_db_end_offset = FLASH_OFFSET_DB_END;
dev_db_start_offset += (fnode_sess->target_id * sizeof(*fw_ddb_entry));
ddb_size = sizeof(*fw_ddb_entry);
} else {
dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
(ha->hw.flt_region_ddb << 2); /* flt_ddb_size is DDB table size for both ports * so divide it by 2 to calculate the offset for second port
*/ if (ha->port_num == 1)
dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
sysfs_ddb_del:
target_id = fnode_sess->target_id;
iscsi_destroy_flashnode_sess(fnode_sess);
ql4_printk(KERN_INFO, ha, "%s: session and conn entries for flashnode %u of host %lu deleted\n",
__func__, target_id, ha->host_no);
exit_ddb_del: if (pddb)
dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
fw_ddb_entry_dma); return rc;
}
/** * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs * @ha: pointer to adapter structure * * Export the firmware DDB for all send targets and normal targets to sysfs.
**/ int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
{ struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma;
uint16_t max_ddbs;
uint16_t idx = 0; int ret = QLA_SUCCESS;
fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
&fw_ddb_entry_dma, GFP_KERNEL); if (!fw_ddb_entry) {
DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to allocate dma buffer\n",
__func__)); return -ENOMEM;
}
/** * qla4xxx_build_ddb_list - Build ddb list and setup sessions * @ha: pointer to adapter structure * @is_reset: Is this init path or reset path * * Create a list of sendtargets (st) from firmware DDBs, issue send targets * using connection open, then create the list of normal targets (nt) * from firmware DDBs. Based on the list of nt setup session and connection * objects.
**/ void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
{
uint16_t tmo = 0; struct list_head list_st, list_nt; struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp; unsignedlong wtime;
/* Before issuing conn open mbox, ensure all IPs states are configured * Note, conn open fails if IPs are not configured
*/
qla4xxx_wait_for_ip_configuration(ha);
/* Go thru the STs and fire the sendtargets by issuing conn open mbx */
list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
}
/* Wait to ensure all sendtargets are done for min 12 sec wait */
tmo = ((ha->def_timeout > LOGIN_TOV) &&
(ha->def_timeout < LOGIN_TOV * 10) ?
ha->def_timeout : LOGIN_TOV);
DEBUG2(ql4_printk(KERN_INFO, ha, "Default time to wait for build ddb %d\n", tmo));
wtime = jiffies + (HZ * tmo); do { if (list_empty(&list_st)) break;
qla4xxx_remove_failed_ddb(ha, &list_st);
schedule_timeout_uninterruptible(HZ / 10);
} while (time_after(wtime, jiffies));
/** * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login * response. * @ha: pointer to adapter structure * * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be * set in DDB and we will wait for login response of boot targets during * probe.
**/ staticvoid qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
{ struct ddb_entry *ddb_entry; struct dev_db_entry *fw_ddb_entry = NULL;
dma_addr_t fw_ddb_entry_dma; unsignedlong wtime;
uint32_t ddb_state; int max_ddbs, idx, ret;
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_login_resp;
}
wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
for (idx = 0; idx < max_ddbs; idx++) {
ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx); if (ddb_entry == NULL) continue;
if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: DDB index [%d]\n", __func__,
ddb_entry->fw_ddb_index)); do {
ret = qla4xxx_get_fwddb_entry(ha,
ddb_entry->fw_ddb_index,
fw_ddb_entry, fw_ddb_entry_dma,
NULL, NULL, &ddb_state, NULL,
NULL, NULL); if (ret == QLA_ERROR) goto exit_login_resp;
if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
(ddb_state == DDB_DS_SESSION_FAILED)) break;
schedule_timeout_uninterruptible(HZ);
} while ((time_after(wtime, jiffies)));
if (!time_after(wtime, jiffies)) {
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Login response wait timer expired\n",
__func__)); goto exit_login_resp;
}
}
}
exit_login_resp: if (fw_ddb_entry)
dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
fw_ddb_entry, fw_ddb_entry_dma);
}
/** * qla4xxx_probe_adapter - callback function to probe HBA * @pdev: pointer to pci_dev structure * @ent: pointer to pci_device entry * * This routine will probe for Qlogic 4xxx iSCSI host adapters. * It returns zero if successful. It also initializes all data necessary for * the driver.
**/ staticint qla4xxx_probe_adapter(struct pci_dev *pdev, conststruct pci_device_id *ent)
{ int ret = -ENODEV, status; struct Scsi_Host *host; struct scsi_qla_host *ha;
uint8_t init_retry_count = 0; char buf[34]; struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
uint32_t dev_state;
if (is_qla80XX(ha)) {
rwlock_init(&ha->hw_lock);
ha->pf_bit = ha->func_num << 16; /* Set EEH reset type to fundamental if required by hba */
pdev->needs_freset = 1;
}
/* Configure PCI I/O space. */
ret = ha->isp_ops->iospace_config(ha); if (ret) goto probe_failed_ioconfig;
ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
pdev->device, pdev->irq, ha->reg);
qla4xxx_config_dma_addressing(ha);
/* Initialize lists and spinlocks. */
INIT_LIST_HEAD(&ha->free_srb_q);
ret = scsi_add_host(host, &pdev->dev); if (ret) goto probe_failed;
if (is_qla80XX(ha))
qla4_8xxx_get_flash_info(ha);
if (is_qla8032(ha) || is_qla8042(ha)) {
qla4_83xx_read_reset_template(ha); /* * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0. * If DONRESET_BIT0 is set, drivers should not set dev_state * to NEED_RESET. But if NEED_RESET is set, drivers should * should honor the reset.
*/ if (ql4xdontresethba == 1)
qla4_83xx_set_idc_dontreset(ha);
}
/* * Initialize the Host adapter request/response queues and * firmware * NOTE: interrupts enabled upon successful completion
*/
status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
/* Dont retry adapter initialization if IRQ allocation failed */ if (is_qla80XX(ha) && (status == QLA_ERROR)) goto skip_retry_init;
while ((!test_bit(AF_ONLINE, &ha->flags)) &&
init_retry_count++ < MAX_INIT_RETRIES) {
if (is_qla80XX(ha)) {
ha->isp_ops->idc_lock(ha);
dev_state = qla4_8xxx_rd_direct(ha,
QLA8XXX_CRB_DEV_STATE);
ha->isp_ops->idc_unlock(ha); if (dev_state == QLA8XXX_DEV_FAILED) {
ql4_printk(KERN_WARNING, ha, "%s: don't retry " "initialize adapter. H/W is in failed state\n",
__func__); break;
}
}
DEBUG2(printk("scsi: %s: retrying adapter initialization " "(%d)\n", __func__, init_retry_count));
if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) continue;
status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER); if (is_qla80XX(ha) && (status == QLA_ERROR)) { if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR) goto skip_retry_init;
}
}
skip_retry_init: if (!test_bit(AF_ONLINE, &ha->flags)) {
ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
if ((is_qla8022(ha) && ql4xdontresethba) ||
((is_qla8032(ha) || is_qla8042(ha)) &&
qla4_83xx_idc_dontreset(ha))) { /* Put the device in failed state. */
DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
ha->isp_ops->idc_lock(ha);
qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
QLA8XXX_DEV_FAILED);
ha->isp_ops->idc_unlock(ha);
}
ret = -ENODEV; goto remove_host;
}
/* Startup the kernel thread for this host adapter. */
DEBUG2(printk("scsi: %s: Starting kernel thread for " "qla4xxx_dpc\n", __func__));
sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
ha->dpc_thread = alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, buf); if (!ha->dpc_thread) {
ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
ret = -ENODEV; goto remove_host;
}
INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
ha->host_no); if (!ha->task_wq) {
ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
ret = -ENODEV; goto remove_host;
}
/* * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc * (which is called indirectly by qla4xxx_initialize_adapter), * so that irqs will be registered after crbinit but before * mbx_intr_enable.
*/ if (is_qla40XX(ha)) {
ret = qla4xxx_request_irqs(ha); if (ret) {
ql4_printk(KERN_WARNING, ha, "Failed to reserve " "interrupt %d already in use.\n", pdev->irq); goto remove_host;
}
}
/* Set the driver version */ if (is_qla80XX(ha))
qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
if (qla4xxx_setup_boot_info(ha))
ql4_printk(KERN_ERR, ha, "%s: No iSCSI boot target configured\n", __func__);
set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags); /* Perform the build ddb list and login to each */
qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
qla4xxx_wait_login_resp_boot_tgt(ha);
qla4xxx_create_chap_list(ha);
qla4xxx_create_ifaces(ha); return 0;
remove_host:
scsi_remove_host(ha->host);
probe_failed:
qla4xxx_free_adapter(ha);
probe_failed_ioconfig:
scsi_host_put(ha->host);
probe_disable_device:
pci_disable_device(pdev);
return ret;
}
/** * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize * @ha: pointer to adapter structure * * Mark the other ISP-4xxx port to indicate that the driver is being removed, * so that the other port will not re-initialize while in the process of * removing the ha due to driver unload or hba hotplug.
**/ staticvoid qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
{ struct scsi_qla_host *other_ha = NULL; struct pci_dev *other_pdev = NULL; int fn = ISP4XXX_PCI_FN_2;
/*iscsi function numbers for ISP4xxx is 1 and 3*/ if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
fn = ISP4XXX_PCI_FN_1;
/* Get other_ha if other_pdev is valid and state is enable*/ if (other_pdev) { if (atomic_read(&other_pdev->enable_cnt)) {
other_ha = pci_get_drvdata(other_pdev); if (other_ha) {
set_bit(AF_HA_REMOVAL, &other_ha->flags);
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " "Prevent %s reinit\n", __func__,
dev_name(&other_ha->pdev->dev)));
}
}
pci_dev_put(other_pdev);
}
}
qla4xxx_destroy_ddb(ha, ddb_entry); /* * we have decremented the reference count of the driver * when we setup the session to have the driver unload * to be seamless without actually destroying the * session
**/
try_module_get(qla4xxx_iscsi_transport.owner);
iscsi_destroy_endpoint(ddb_entry->conn->ep);
qla4xxx_free_ddb(ha, ddb_entry);
iscsi_session_teardown(ddb_entry->sess);
}
}
} /** * qla4xxx_remove_adapter - callback function to remove adapter. * @pdev: PCI device pointer
**/ staticvoid qla4xxx_remove_adapter(struct pci_dev *pdev)
{ struct scsi_qla_host *ha;
/* * If the PCI device is disabled then it means probe_adapter had * failed and resources already cleaned up on probe_adapter exit.
*/ if (!pci_is_enabled(pdev)) return;
ha = pci_get_drvdata(pdev);
if (is_qla40XX(ha))
qla4xxx_prevent_other_port_reinit(ha);
/* destroy iface from sysfs */
qla4xxx_destroy_ifaces(ha);
if ((!ql4xdisablesysfsboot) && ha->boot_kset)
iscsi_boot_destroy_kset(ha->boot_kset);
/** * qla4xxx_del_from_active_array - returns an active srb * @ha: Pointer to host adapter structure. * @index: index into the active_array * * This routine removes and returns the srb at the specified index
**/ struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
uint32_t index)
{ struct srb *srb = NULL; struct scsi_cmnd *cmd = NULL;
cmd = scsi_host_find_tag(ha->host, index); if (!cmd) return srb;
srb = qla4xxx_cmd_priv(cmd)->srb; if (!srb) return srb;
/** * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware * @ha: Pointer to host adapter structure. * @cmd: Scsi Command to wait on. * * This routine waits for the command to be returned by the Firmware * for some max time.
**/ staticint qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, struct scsi_cmnd *cmd)
{ int done = 0; struct srb *rp;
uint32_t max_wait_time = EH_WAIT_CMD_TOV; int ret = SUCCESS;
/* Dont wait on command if PCI error is being handled * by PCI AER driver
*/ if (unlikely(pci_channel_offline(ha->pdev)) ||
(test_bit(AF_EEH_BUSY, &ha->flags))) {
ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
ha->host_no, __func__); return ret;
}
do { /* Checking to see if its returned to OS */
rp = qla4xxx_cmd_priv(cmd)->srb; if (rp == NULL) {
done++; break;
}
msleep(2000);
} while (max_wait_time--);
return done;
}
/** * qla4xxx_wait_for_hba_online - waits for HBA to come online * @ha: Pointer to host adapter structure
**/ staticint qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
{ unsignedlong wait_online;
/** * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. * @ha: pointer to HBA * @stgt: pointer to SCSI target * @sdev: pointer to SCSI device * * This function waits for all outstanding commands to a lun to complete. It * returns 0 if all pending commands are returned and 1 otherwise.
**/ staticint qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, struct scsi_target *stgt, struct scsi_device *sdev)
{ int cnt; int status = 0; struct scsi_cmnd *cmd;
/* * Waiting for all commands for the designated target or dev * in the active array
*/ for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
cmd = scsi_host_find_tag(ha->host, cnt); if (cmd && stgt == scsi_target(cmd->device) &&
(!sdev || sdev == cmd->device)) { if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
status++; break;
}
}
} return status;
}
/** * qla4xxx_eh_abort - callback for abort task. * @cmd: Pointer to Linux's SCSI command structure * * This routine is called by the Linux OS to abort the specified * command.
**/ staticint qla4xxx_eh_abort(struct scsi_cmnd *cmd)
{ struct scsi_qla_host *ha = to_qla_host(cmd->device->host); unsignedint id = cmd->device->id;
uint64_t lun = cmd->device->lun; unsignedlong flags; struct srb *srb = NULL; int ret = SUCCESS; int wait = 0; int rval;
/** * qla4xxx_eh_device_reset - callback for target reset. * @cmd: Pointer to Linux's SCSI command structure * * This routine is called by the Linux OS to reset all luns on the * specified target.
**/ staticint qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
{ struct scsi_qla_host *ha = to_qla_host(cmd->device->host); struct ddb_entry *ddb_entry = cmd->device->hostdata; int ret = FAILED, stat; int rval;
if (!ddb_entry) return ret;
ret = iscsi_block_scsi_eh(cmd); if (ret) return ret;
ret = FAILED;
ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
cmd->device->channel, cmd->device->id, cmd->device->lun);
rval = qla4xxx_isp_check_reg(ha); if (rval != QLA_SUCCESS) {
ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n"); return FAILED;
}
/* FIXME: wait for hba to go online */
stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); if (stat != QLA_SUCCESS) {
ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); goto eh_dev_reset_done;
}
if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
cmd->device)) {
ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED - waiting for " "commands.\n"); goto eh_dev_reset_done;
}
ql4_printk(KERN_INFO, ha, "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
ha->host_no, cmd->device->channel, cmd->device->id,
cmd->device->lun);
ret = SUCCESS;
eh_dev_reset_done:
return ret;
}
/** * qla4xxx_eh_target_reset - callback for target reset. * @cmd: Pointer to Linux's SCSI command structure * * This routine is called by the Linux OS to reset the target.
**/ staticint qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
{ struct scsi_qla_host *ha = to_qla_host(cmd->device->host); struct ddb_entry *ddb_entry = cmd->device->hostdata; int stat, ret; int rval;
if (!ddb_entry) return FAILED;
ret = iscsi_block_scsi_eh(cmd); if (ret) return ret;
/** * qla4xxx_is_eh_active - check if error handler is running * @shost: Pointer to SCSI Host struct * * This routine finds that if reset host is called in EH * scenario or from some application like sg_reset
**/ staticint qla4xxx_is_eh_active(struct Scsi_Host *shost)
{ if (shost->shost_state == SHOST_RECOVERY) return 1; return 0;
}
/** * qla4xxx_eh_host_reset - kernel callback * @cmd: Pointer to Linux's SCSI command structure * * This routine is invoked by the Linux kernel to perform fatal error * recovery on the specified adapter.
**/ staticint qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
{ int return_status = FAILED; struct scsi_qla_host *ha; int rval;
ha = to_qla_host(cmd->device->host);
rval = qla4xxx_isp_check_reg(ha); if (rval != QLA_SUCCESS) {
ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n"); return FAILED;
}
if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
qla4_83xx_set_idc_dontreset(ha);
/* * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other * protocol drivers, we should not set device_state to NEED_RESET
*/ if (ql4xdontresethba ||
((is_qla8032(ha) || is_qla8042(ha)) &&
qla4_83xx_idc_dontreset(ha))) {
DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
ha->host_no, __func__));
/* Clear outstanding srb in queues */ if (qla4xxx_is_eh_active(cmd->device->host))
qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
return FAILED;
}
ql4_printk(KERN_INFO, ha, "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
cmd->device->channel, cmd->device->id, cmd->device->lun);
if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " "DEAD.\n", ha->host_no, cmd->device->channel,
__func__));
return FAILED;
}
if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { if (is_qla80XX(ha))
set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); else
set_bit(DPC_RESET_HA, &ha->dpc_flags);
}
if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
return_status = SUCCESS;
staticint qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
{ struct scsi_qla_host *ha = to_qla_host(shost); int rval = QLA_SUCCESS;
uint32_t idc_ctrl;
if (ql4xdontresethba) {
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
__func__));
rval = -EPERM; goto exit_host_reset;
}
if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) goto recover_adapter;
switch (reset_type) { case SCSI_ADAPTER_RESET:
set_bit(DPC_RESET_HA, &ha->dpc_flags); break; case SCSI_FIRMWARE_RESET: if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { if (is_qla80XX(ha)) /* set firmware context reset */
set_bit(DPC_RESET_HA_FW_CONTEXT,
&ha->dpc_flags); else {
rval = qla4xxx_context_reset(ha); goto exit_host_reset;
}
} break;
}
recover_adapter: /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
* reset is issued by application */ if ((is_qla8032(ha) || is_qla8042(ha)) &&
test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
(idc_ctrl | GRACEFUL_RESET_BIT1));
}
rval = qla4xxx_recover_adapter(ha); if (rval != QLA_SUCCESS) {
DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
__func__));
rval = -EIO;
}
exit_host_reset: return rval;
}
/* PCI AER driver recovers from all correctable errors w/o * driver intervention. For uncorrectable errors PCI AER * driver calls the following device driver's callbacks * * - Fatal Errors - link_reset * - Non-Fatal Errors - driver's error_detected() which * returns CAN_RECOVER, NEED_RESET or DISCONNECT. * * PCI AER driver calls * CAN_RECOVER - driver's mmio_enabled(), mmio_enabled() * returns RECOVERED or NEED_RESET if fw_hung * NEED_RESET - driver's slot_reset() * DISCONNECT - device is dead & cannot recover * RECOVERED - driver's resume()
*/ static pci_ers_result_t
qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
{ struct scsi_qla_host *ha = pci_get_drvdata(pdev);
ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
ha->host_no, __func__, state);
if (!is_aer_supported(ha)) return PCI_ERS_RESULT_NONE;
switch (state) { case pci_channel_io_normal:
clear_bit(AF_EEH_BUSY, &ha->flags); return PCI_ERS_RESULT_CAN_RECOVER; case pci_channel_io_frozen:
set_bit(AF_EEH_BUSY, &ha->flags);
qla4xxx_mailbox_premature_completion(ha);
qla4xxx_free_irqs(ha);
pci_disable_device(pdev); /* Return back all IOs */
qla4xxx_abort_active_cmds(ha, DID_RESET << 16); return PCI_ERS_RESULT_NEED_RESET; case pci_channel_io_perm_failure:
set_bit(AF_EEH_BUSY, &ha->flags);
set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); return PCI_ERS_RESULT_DISCONNECT;
} return PCI_ERS_RESULT_NEED_RESET;
}
/** * qla4xxx_pci_mmio_enabled() - gets called if * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER * and read/write to the device still works. * @pdev: PCI device pointer
**/ static pci_ers_result_t
qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
{ struct scsi_qla_host *ha = pci_get_drvdata(pdev);
if (!is_aer_supported(ha)) return PCI_ERS_RESULT_NONE;
fn = PCI_FUNC(ha->pdev->devfn); if (is_qla8022(ha)) { while (fn > 0) {
fn--;
ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
ha->host_no, __func__, fn); /* Get the pci device given the domain, bus,
* slot/function number */
other_pdev = pci_get_domain_bus_and_slot(
pci_domain_nr(ha->pdev->bus),
ha->pdev->bus->number,
PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
fn));
if (!other_pdev) continue;
if (atomic_read(&other_pdev->enable_cnt)) {
ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
ha->host_no, __func__, fn);
pci_dev_put(other_pdev); break;
}
pci_dev_put(other_pdev);
}
} else { /* this case is meant for ISP83xx/ISP84xx only */ if (qla4_83xx_can_perform_reset(ha)) { /* reset fn as iSCSI is going to perform the reset */
fn = 0;
}
}
/* The first function on the card, the reset owner will * start & initialize the firmware. The other functions * on the card will reset the firmware context
*/ if (!fn) {
ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " "0x%x is the owner\n", ha->host_no, __func__,
ha->pdev->devfn);
static pci_ers_result_t
qla4xxx_pci_slot_reset(struct pci_dev *pdev)
{
pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; struct scsi_qla_host *ha = pci_get_drvdata(pdev); int rc;
ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
ha->host_no, __func__);
if (!is_aer_supported(ha)) return PCI_ERS_RESULT_NONE;
/* Restore the saved state of PCIe device - * BAR registers, PCI Config space, PCIX, MSI, * IOV states
*/
pci_restore_state(pdev);
/* pci_restore_state() clears the saved_state flag of the device * save restored state which resets saved_state flag
*/
pci_save_state(pdev);
/* Initialize device or resume if in suspended state */
rc = pci_enable_device(pdev); if (rc) {
ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " "device after reset\n", ha->host_no, __func__); goto exit_slot_reset;
}
ha->isp_ops->disable_intrs(ha);
if (is_qla80XX(ha)) { if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
ret = PCI_ERS_RESULT_RECOVERED; goto exit_slot_reset;
} else goto exit_slot_reset;
}
exit_slot_reset:
ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" "device after reset\n", ha->host_no, __func__, ret); return ret;
}
ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
ha->host_no, __func__);
ret = qla4xxx_wait_for_hba_online(ha); if (ret != QLA_SUCCESS) {
ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " "resume I/O from slot/link_reset\n", ha->host_no,
__func__);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.