^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * QLogic iSCSI Offload Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2016 Cavium Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _QEDI_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _QEDI_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define __PREVENT_QED_HSI__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <scsi/scsi_transport_iscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <scsi/libiscsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/uio_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "qedi_hsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/qed/qed_if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "qedi_dbg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/qed/qed_iscsi_if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/qed/qed_ll2_if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "qedi_version.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "qedi_nvm_iscsi_cfg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define QEDI_MODULE_NAME "qedi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct qedi_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifndef GET_FIELD2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define GET_FIELD2(value, name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) (((value) & (name ## _MASK)) >> (name ## _OFFSET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * PCI function probe defines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define QEDI_MODE_NORMAL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define QEDI_MODE_RECOVERY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define QEDI_MODE_SHUTDOWN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define ISCSI_WQE_SET_PTU_INVALIDATE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define QEDI_MAX_ISCSI_TASK 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define QEDI_MAX_TASK_NUM 0x0FFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define QEDI_MAX_ISCSI_CONNS_PER_HBA 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define QEDI_ISCSI_MAX_BDS_PER_CMD 255 /* Firmware max BDs is 255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define MAX_OUTSTANDING_TASKS_PER_CON 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define QEDI_MAX_BD_LEN 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define QEDI_BD_SPLIT_SZ 0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define QEDI_PAGE_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define QEDI_FAST_SGE_COUNT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* MAX Length for cached SGL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) num_online_cpus())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define QEDI_LOCAL_PORT_MIN 60000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define QEDI_LOCAL_PORT_MAX 61024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define QEDI_LOCAL_PORT_RANGE (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define QEDI_LOCAL_PORT_INVALID 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define TX_RX_RING 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define RX_RING (TX_RX_RING - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define QEDI_PAGE_ALIGN(addr) ALIGN(addr, QEDI_PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define QEDI_PAGE_MASK (~((QEDI_PAGE_SIZE) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define QEDI_HW_DMA_BOUNDARY 0xfff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define QEDI_PATH_HANDLE 0xFE0000000UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) enum qedi_nvm_tgts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) QEDI_NVM_TGT_PRI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) QEDI_NVM_TGT_SEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct qedi_nvm_iscsi_image {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct nvm_iscsi_cfg iscsi_cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u32 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct qedi_uio_ctrl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* meta data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u32 uio_hsi_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* user writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u32 host_tx_prod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u32 host_rx_cons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 host_rx_bd_cons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 host_tx_pkt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 host_rx_cons_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* driver writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) u32 hw_tx_cons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) u32 hw_rx_prod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u32 hw_rx_bd_prod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u32 hw_rx_prod_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* other */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u8 mac_addr[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u8 reserve[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct qedi_rx_bd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u32 rx_pkt_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u32 rx_pkt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) u16 vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define QEDI_RX_DESC_CNT (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define QEDI_MAX_RX_DESC_CNT (QEDI_RX_DESC_CNT - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define QEDI_NUM_RX_BD (QEDI_RX_DESC_CNT * 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define QEDI_MAX_RX_BD (QEDI_NUM_RX_BD - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) (QEDI_MAX_RX_DESC_CNT - 1)) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) (x) + 2 : (x) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct qedi_uio_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct uio_info qedi_uinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) u32 uio_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u32 ll2_ring_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) void *ll2_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u32 ll2_buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void *ll2_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) void *rx_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void *tx_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct qedi_ctx *qedi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) void *uctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* List to maintain the skb pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct skb_work_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u16 vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* Queue sizes in number of elements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define QEDI_SQ_SIZE MAX_OUTSTANDING_TASKS_PER_CON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define QEDI_CQ_SIZE 2048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define QEDI_CMDQ_SIZE QEDI_MAX_ISCSI_TASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define QEDI_PROTO_CQ_PROD_IDX 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct qedi_glbl_q_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) u64 hw_p_cq; /* Completion queue PBL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u64 hw_p_rq; /* Request queue PBL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u64 hw_p_cmdq; /* Command queue PBL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct global_queue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) union iscsi_cqe *cq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) dma_addr_t cq_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) u32 cq_mem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u32 cq_cons_idx; /* Completion queue consumer index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void *cq_pbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) dma_addr_t cq_pbl_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u32 cq_pbl_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct qedi_fastpath {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct qed_sb_info *sb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u16 sb_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define QEDI_NAME_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) char name[QEDI_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct qedi_ctx *qedi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Used to pass fastpath information needed to process CQEs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct qedi_io_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct iscsi_cqe_solicited cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u16 que_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * struct iscsi_cid_queue - Per adapter iscsi cid queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @cid_que_base: queue base memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * @cid_que: queue memory pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * @cid_q_prod_idx: produce index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * @cid_q_cons_idx: consumer index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * @cid_q_max_idx: max index. used to detect wrap around condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @cid_free_cnt: queue size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @conn_cid_tbl: iscsi cid to conn structure mapping table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Per adapter iSCSI CID Queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct iscsi_cid_queue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) void *cid_que_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) u32 *cid_que;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u32 cid_q_prod_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u32 cid_q_cons_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) u32 cid_q_max_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) u32 cid_free_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct qedi_conn **conn_cid_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct qedi_portid_tbl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) spinlock_t lock; /* Port id lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) u16 start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) u16 max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u16 next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unsigned long *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct qedi_itt_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) __le32 itt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct qedi_cmd *p_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* I/O tracing entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define QEDI_IO_TRACE_SIZE 2048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct qedi_io_log {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define QEDI_IO_TRACE_REQ 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define QEDI_IO_TRACE_RSP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u8 direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) u16 task_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) u32 cid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) u32 port_id; /* Remote port fabric ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) u8 op; /* SCSI CDB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) u8 lba[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) unsigned int bufflen; /* SCSI buffer length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) unsigned int sg_count; /* Number of SG elements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) u8 fast_sgs; /* number of fast sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) u8 slow_sgs; /* number of slow sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) u8 cached_sgs; /* number of cached sgls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int result; /* Result passed back to mid-layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned long jiffies; /* Time stamp when I/O logged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int refcount; /* Reference count for task id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) unsigned int blk_req_cpu; /* CPU that the task is queued on by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * blk layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned int req_cpu; /* CPU that the task is queued on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned int intr_cpu; /* Interrupt CPU that the task is received on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned int blk_rsp_cpu;/* CPU that task is actually processed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * returned to blk layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) bool cached_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) bool slow_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) bool fast_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Number of entries in BDQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define QEDI_BDQ_NUM 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define QEDI_BDQ_BUF_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* DMA coherent buffers for BDQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct qedi_bdq_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) void *buf_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dma_addr_t buf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Main port level struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct qedi_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct qedi_dbg_ctx dbg_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct Scsi_Host *shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct qed_dev *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct qed_dev_iscsi_info dev_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct qed_int_info int_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct qedi_glbl_q_params *p_cpuq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct global_queue **global_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* uio declaration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct qedi_uio_dev *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct list_head ll2_skb_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) spinlock_t ll2_lock; /* Light L2 lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) spinlock_t hba_lock; /* per port lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct task_struct *ll2_recv_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) unsigned long qedi_err_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #define QEDI_ERR_ATTN_CLR_EN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define QEDI_ERR_IS_RECOVERABLE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define QEDI_ERR_OVERRIDE_EN 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define UIO_DEV_OPENED 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define QEDI_IOTHREAD_WAKE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #define QEDI_IN_RECOVERY 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #define QEDI_IN_OFFLINE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define QEDI_IN_SHUTDOWN 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define QEDI_BLOCK_IO 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) u8 mac[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) u32 src_ip[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u8 ip_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* Physical address of above array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) dma_addr_t hw_p_cpuq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct qedi_bdq_buf bdq[QEDI_BDQ_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) void *bdq_pbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) dma_addr_t bdq_pbl_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) size_t bdq_pbl_mem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void *bdq_pbl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dma_addr_t bdq_pbl_list_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) u8 bdq_pbl_list_num_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct qedi_nvm_iscsi_image *iscsi_image;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dma_addr_t nvm_buf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) void __iomem *bdq_primary_prod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) void __iomem *bdq_secondary_prod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) u16 bdq_prod_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) u16 rq_num_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) u32 max_sqes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) u8 num_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) u32 max_active_conns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) s32 msix_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct iscsi_cid_queue cid_que;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct qedi_endpoint **ep_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct qedi_portid_tbl lcl_port_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* Rx fast path intr context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct qed_sb_info *sb_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct qedi_fastpath *fp_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct qed_iscsi_tid tasks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #define QEDI_LINK_DOWN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define QEDI_LINK_UP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) atomic_t link_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define QEDI_RESERVE_TASK_ID 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #define MAX_ISCSI_TASK_ENTRIES 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) #define QEDI_INVALID_TASK_ID (MAX_ISCSI_TASK_ENTRIES + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) unsigned long task_idx_map[MAX_ISCSI_TASK_ENTRIES / BITS_PER_LONG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct qedi_itt_map *itt_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) u16 tid_reuse_count[QEDI_MAX_ISCSI_TASK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct qed_pf_params pf_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct workqueue_struct *tmf_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct workqueue_struct *offload_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) u16 ll2_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct workqueue_struct *dpc_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct delayed_work recovery_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct delayed_work board_disable_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) spinlock_t task_idx_lock; /* To protect gbl context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) s32 last_tidx_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) s32 last_tidx_clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct qedi_io_log io_trace_buf[QEDI_IO_TRACE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) spinlock_t io_trace_lock; /* prtect trace Log buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) u16 io_trace_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) unsigned int intr_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u32 cached_sgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) bool use_cached_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) u32 slow_sgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) bool use_slow_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) u32 fast_sgls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) bool use_fast_sge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) atomic_t num_offloads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) #define SYSFS_FLAG_FW_SEL_BOOT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #define IPV6_LEN 41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) #define IPV4_LEN 17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct iscsi_boot_kset *boot_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* Used for iscsi statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct mutex stats_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct qedi_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct qedi_ctx *qedi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) union iscsi_cqe cqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) u16 que_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) bool is_solicited;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct qedi_percpu_s {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct task_struct *iothread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) struct list_head work_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) spinlock_t p_work_lock; /* Per cpu worker lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static inline void *qedi_get_task_mem(struct qed_iscsi_tid *info, u32 tid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return (info->blocks[tid / info->num_tids_per_block] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) (tid % info->num_tids_per_block) * info->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) #endif /* _QEDI_H_ */