Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * QLogic iSCSI Offload Driver
0004  * Copyright (c) 2016 Cavium Inc.
0005  */
0006 
0007 #ifndef _QEDI_H_
0008 #define _QEDI_H_
0009 
0010 #define __PREVENT_QED_HSI__
0011 
0012 #include <scsi/scsi_transport_iscsi.h>
0013 #include <scsi/libiscsi.h>
0014 #include <scsi/scsi_host.h>
0015 #include <linux/uio_driver.h>
0016 
0017 #include "qedi_hsi.h"
0018 #include <linux/qed/qed_if.h>
0019 #include "qedi_dbg.h"
0020 #include <linux/qed/qed_iscsi_if.h>
0021 #include <linux/qed/qed_ll2_if.h>
0022 #include "qedi_version.h"
0023 #include "qedi_nvm_iscsi_cfg.h"
0024 
0025 #define QEDI_MODULE_NAME        "qedi"
0026 
0027 struct qedi_endpoint;
0028 
0029 #ifndef GET_FIELD2
0030 #define GET_FIELD2(value, name) \
0031     (((value) & (name ## _MASK)) >> (name ## _OFFSET))
0032 #endif
0033 
0034 /*
0035  * PCI function probe defines
0036  */
0037 #define QEDI_MODE_NORMAL    0
0038 #define QEDI_MODE_RECOVERY  1
0039 #define QEDI_MODE_SHUTDOWN  2
0040 
0041 #define ISCSI_WQE_SET_PTU_INVALIDATE    1
0042 #define QEDI_MAX_ISCSI_TASK     4096
0043 #define QEDI_MAX_TASK_NUM       0x0FFF
0044 #define QEDI_MAX_ISCSI_CONNS_PER_HBA    1024
0045 #define QEDI_ISCSI_MAX_BDS_PER_CMD  255 /* Firmware max BDs is 255 */
0046 #define MAX_OUTSTANDING_TASKS_PER_CON   1024
0047 
0048 #define QEDI_MAX_BD_LEN     0xffff
0049 #define QEDI_BD_SPLIT_SZ    0x1000
0050 #define QEDI_PAGE_SIZE      4096
0051 #define QEDI_FAST_SGE_COUNT 4
0052 /* MAX Length for cached SGL */
0053 #define MAX_SGLEN_FOR_CACHESGL  ((1U << 16) - 1)
0054 
0055 #define MIN_NUM_CPUS_MSIX(x)    min_t(u32, x->dev_info.num_cqs, \
0056                     num_online_cpus())
0057 
0058 #define QEDI_LOCAL_PORT_MIN     60000
0059 #define QEDI_LOCAL_PORT_MAX     61024
0060 #define QEDI_LOCAL_PORT_RANGE   (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN)
0061 #define QEDI_LOCAL_PORT_INVALID 0xffff
0062 #define TX_RX_RING      16
0063 #define RX_RING         (TX_RX_RING - 1)
0064 #define QEDI_PAGE_ALIGN(addr)   ALIGN(addr, QEDI_PAGE_SIZE)
0065 #define QEDI_PAGE_MASK      (~((QEDI_PAGE_SIZE) - 1))
0066 
0067 #define QEDI_HW_DMA_BOUNDARY    0xfff
0068 #define QEDI_PATH_HANDLE    0xFE0000000UL
0069 
0070 enum qedi_nvm_tgts {
0071     QEDI_NVM_TGT_PRI,
0072     QEDI_NVM_TGT_SEC,
0073 };
0074 
0075 struct qedi_nvm_iscsi_image {
0076     struct nvm_iscsi_cfg iscsi_cfg;
0077     u32 crc;
0078 };
0079 
0080 struct qedi_uio_ctrl {
0081     /* meta data */
0082     u32 uio_hsi_version;
0083 
0084     /* user writes */
0085     u32 host_tx_prod;
0086     u32 host_rx_cons;
0087     u32 host_rx_bd_cons;
0088     u32 host_tx_pkt_len;
0089     u32 host_rx_cons_cnt;
0090 
0091     /* driver writes */
0092     u32 hw_tx_cons;
0093     u32 hw_rx_prod;
0094     u32 hw_rx_bd_prod;
0095     u32 hw_rx_prod_cnt;
0096 
0097     /* other */
0098     u8 mac_addr[6];
0099     u8 reserve[2];
0100 };
0101 
0102 struct qedi_rx_bd {
0103     u32 rx_pkt_index;
0104     u32 rx_pkt_len;
0105     u16 vlan_id;
0106 };
0107 
0108 #define QEDI_RX_DESC_CNT    (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
0109 #define QEDI_MAX_RX_DESC_CNT    (QEDI_RX_DESC_CNT - 1)
0110 #define QEDI_NUM_RX_BD      (QEDI_RX_DESC_CNT * 1)
0111 #define QEDI_MAX_RX_BD      (QEDI_NUM_RX_BD - 1)
0112 
0113 #define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
0114                   (QEDI_MAX_RX_DESC_CNT - 1)) ?     \
0115                  (x) + 2 : (x) + 1)
0116 
0117 struct qedi_uio_dev {
0118     struct uio_info     qedi_uinfo;
0119     u32         uio_dev;
0120     struct list_head    list;
0121 
0122     u32         ll2_ring_size;
0123     void            *ll2_ring;
0124 
0125     u32         ll2_buf_size;
0126     void            *ll2_buf;
0127 
0128     void            *rx_pkt;
0129     void            *tx_pkt;
0130 
0131     struct qedi_ctx     *qedi;
0132     struct pci_dev      *pdev;
0133     void            *uctrl;
0134 };
0135 
0136 /* List to maintain the skb pointers */
0137 struct skb_work_list {
0138     struct list_head list;
0139     struct sk_buff *skb;
0140     u16 vlan_id;
0141 };
0142 
0143 /* Queue sizes in number of elements */
0144 #define QEDI_SQ_SIZE        MAX_OUTSTANDING_TASKS_PER_CON
0145 #define QEDI_CQ_SIZE        2048
0146 #define QEDI_CMDQ_SIZE      QEDI_MAX_ISCSI_TASK
0147 #define QEDI_PROTO_CQ_PROD_IDX  0
0148 
0149 struct qedi_glbl_q_params {
0150     u64 hw_p_cq;    /* Completion queue PBL */
0151     u64 hw_p_rq;    /* Request queue PBL */
0152     u64 hw_p_cmdq;  /* Command queue PBL */
0153 };
0154 
0155 struct global_queue {
0156     union iscsi_cqe *cq;
0157     dma_addr_t cq_dma;
0158     u32 cq_mem_size;
0159     u32 cq_cons_idx; /* Completion queue consumer index */
0160 
0161     void *cq_pbl;
0162     dma_addr_t cq_pbl_dma;
0163     u32 cq_pbl_size;
0164 
0165 };
0166 
0167 struct qedi_fastpath {
0168     struct qed_sb_info  *sb_info;
0169     u16         sb_id;
0170 #define QEDI_NAME_SIZE      16
0171     char            name[QEDI_NAME_SIZE];
0172     struct qedi_ctx         *qedi;
0173 };
0174 
0175 /* Used to pass fastpath information needed to process CQEs */
0176 struct qedi_io_work {
0177     struct list_head list;
0178     struct iscsi_cqe_solicited cqe;
0179     u16 que_idx;
0180 };
0181 
0182 /**
0183  * struct iscsi_cid_queue - Per adapter iscsi cid queue
0184  *
0185  * @cid_que_base:           queue base memory
0186  * @cid_que:                queue memory pointer
0187  * @cid_q_prod_idx:         produce index
0188  * @cid_q_cons_idx:         consumer index
0189  * @cid_q_max_idx:          max index. used to detect wrap around condition
0190  * @cid_free_cnt:           queue size
0191  * @conn_cid_tbl:           iscsi cid to conn structure mapping table
0192  *
0193  * Per adapter iSCSI CID Queue
0194  */
0195 struct iscsi_cid_queue {
0196     void *cid_que_base;
0197     u32 *cid_que;
0198     u32 cid_q_prod_idx;
0199     u32 cid_q_cons_idx;
0200     u32 cid_q_max_idx;
0201     u32 cid_free_cnt;
0202     struct qedi_conn **conn_cid_tbl;
0203 };
0204 
0205 struct qedi_portid_tbl {
0206     spinlock_t      lock;   /* Port id lock */
0207     u16             start;
0208     u16             max;
0209     u16             next;
0210     unsigned long   *table;
0211 };
0212 
0213 struct qedi_itt_map {
0214     __le32  itt;
0215     struct qedi_cmd *p_cmd;
0216 };
0217 
0218 /* I/O tracing entry */
0219 #define QEDI_IO_TRACE_SIZE             2048
0220 struct qedi_io_log {
0221 #define QEDI_IO_TRACE_REQ              0
0222 #define QEDI_IO_TRACE_RSP              1
0223     u8 direction;
0224     u16 task_id;
0225     u32 cid;
0226     u32 port_id;    /* Remote port fabric ID */
0227     int lun;
0228     u8 op;      /* SCSI CDB */
0229     u8 lba[4];
0230     unsigned int bufflen;   /* SCSI buffer length */
0231     unsigned int sg_count;  /* Number of SG elements */
0232     u8 fast_sgs;        /* number of fast sgls */
0233     u8 slow_sgs;        /* number of slow sgls */
0234     u8 cached_sgs;      /* number of cached sgls */
0235     int result;     /* Result passed back to mid-layer */
0236     unsigned long jiffies;  /* Time stamp when I/O logged */
0237     int refcount;       /* Reference count for task id */
0238     unsigned int blk_req_cpu; /* CPU that the task is queued on by
0239                    * blk layer
0240                    */
0241     unsigned int req_cpu;   /* CPU that the task is queued on */
0242     unsigned int intr_cpu;  /* Interrupt CPU that the task is received on */
0243     unsigned int blk_rsp_cpu;/* CPU that task is actually processed and
0244                   * returned to blk layer
0245                   */
0246     bool cached_sge;
0247     bool slow_sge;
0248     bool fast_sge;
0249 };
0250 
0251 /* Number of entries in BDQ */
0252 #define QEDI_BDQ_NUM        256
0253 #define QEDI_BDQ_BUF_SIZE   256
0254 
0255 /* DMA coherent buffers for BDQ */
0256 struct qedi_bdq_buf {
0257     void *buf_addr;
0258     dma_addr_t buf_dma;
0259 };
0260 
0261 /* Main port level struct */
0262 struct qedi_ctx {
0263     struct qedi_dbg_ctx dbg_ctx;
0264     struct Scsi_Host *shost;
0265     struct pci_dev *pdev;
0266     struct qed_dev *cdev;
0267     struct qed_dev_iscsi_info dev_info;
0268     struct qed_int_info int_info;
0269     struct qedi_glbl_q_params *p_cpuq;
0270     struct global_queue **global_queues;
0271     /* uio declaration */
0272     struct qedi_uio_dev *udev;
0273     struct list_head ll2_skb_list;
0274     spinlock_t ll2_lock;    /* Light L2 lock */
0275     spinlock_t hba_lock;    /* per port lock */
0276     struct task_struct *ll2_recv_thread;
0277     unsigned long qedi_err_flags;
0278 #define QEDI_ERR_ATTN_CLR_EN    0
0279 #define QEDI_ERR_IS_RECOVERABLE 2
0280 #define QEDI_ERR_OVERRIDE_EN    31
0281     unsigned long flags;
0282 #define UIO_DEV_OPENED      1
0283 #define QEDI_IOTHREAD_WAKE  2
0284 #define QEDI_IN_RECOVERY    5
0285 #define QEDI_IN_OFFLINE     6
0286 #define QEDI_IN_SHUTDOWN    7
0287 #define QEDI_BLOCK_IO       8
0288 
0289     u8 mac[ETH_ALEN];
0290     u32 src_ip[4];
0291     u8 ip_type;
0292 
0293     /* Physical address of above array */
0294     dma_addr_t hw_p_cpuq;
0295 
0296     struct qedi_bdq_buf bdq[QEDI_BDQ_NUM];
0297     void *bdq_pbl;
0298     dma_addr_t bdq_pbl_dma;
0299     size_t bdq_pbl_mem_size;
0300     void *bdq_pbl_list;
0301     dma_addr_t bdq_pbl_list_dma;
0302     u8 bdq_pbl_list_num_entries;
0303     struct qedi_nvm_iscsi_image *iscsi_image;
0304     dma_addr_t nvm_buf_dma;
0305     void __iomem *bdq_primary_prod;
0306     void __iomem *bdq_secondary_prod;
0307     u16 bdq_prod_idx;
0308     u16 rq_num_entries;
0309 
0310     u32 max_sqes;
0311     u8 num_queues;
0312     u32 max_active_conns;
0313     s32 msix_count;
0314 
0315     struct iscsi_cid_queue cid_que;
0316     struct qedi_endpoint **ep_tbl;
0317     struct qedi_portid_tbl lcl_port_tbl;
0318 
0319     /* Rx fast path intr context */
0320     struct qed_sb_info  *sb_array;
0321     struct qedi_fastpath    *fp_array;
0322     struct qed_iscsi_tid    tasks;
0323 
0324 #define QEDI_LINK_DOWN      0
0325 #define QEDI_LINK_UP        1
0326     atomic_t link_state;
0327 
0328 #define QEDI_RESERVE_TASK_ID    0
0329 #define MAX_ISCSI_TASK_ENTRIES  4096
0330 #define QEDI_INVALID_TASK_ID    (MAX_ISCSI_TASK_ENTRIES + 1)
0331     unsigned long task_idx_map[MAX_ISCSI_TASK_ENTRIES / BITS_PER_LONG];
0332     struct qedi_itt_map *itt_map;
0333     u16 tid_reuse_count[QEDI_MAX_ISCSI_TASK];
0334     struct qed_pf_params pf_params;
0335 
0336     struct workqueue_struct *tmf_thread;
0337     struct workqueue_struct *offload_thread;
0338 
0339     u16 ll2_mtu;
0340 
0341     struct workqueue_struct *dpc_wq;
0342     struct delayed_work recovery_work;
0343     struct delayed_work board_disable_work;
0344 
0345     spinlock_t task_idx_lock;   /* To protect gbl context */
0346     s32 last_tidx_alloc;
0347     s32 last_tidx_clear;
0348 
0349     struct qedi_io_log io_trace_buf[QEDI_IO_TRACE_SIZE];
0350     spinlock_t io_trace_lock;   /* prtect trace Log buf */
0351     u16 io_trace_idx;
0352     unsigned int intr_cpu;
0353     u32 cached_sgls;
0354     bool use_cached_sge;
0355     u32 slow_sgls;
0356     bool use_slow_sge;
0357     u32 fast_sgls;
0358     bool use_fast_sge;
0359 
0360     atomic_t num_offloads;
0361 #define SYSFS_FLAG_FW_SEL_BOOT 2
0362 #define IPV6_LEN    41
0363 #define IPV4_LEN    17
0364     struct iscsi_boot_kset *boot_kset;
0365 
0366     /* Used for iscsi statistics */
0367     struct mutex stats_lock;
0368 };
0369 
0370 struct qedi_work {
0371     struct list_head list;
0372     struct qedi_ctx *qedi;
0373     union iscsi_cqe cqe;
0374     u16     que_idx;
0375     bool is_solicited;
0376 };
0377 
0378 struct qedi_percpu_s {
0379     struct task_struct *iothread;
0380     struct list_head work_list;
0381     spinlock_t p_work_lock;     /* Per cpu worker lock */
0382 };
0383 
0384 static inline void *qedi_get_task_mem(struct qed_iscsi_tid *info, u32 tid)
0385 {
0386     return (info->blocks[tid / info->num_tids_per_block] +
0387         (tid % info->num_tids_per_block) * info->size);
0388 }
0389 
0390 #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32))
0391 #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
0392 
0393 #endif /* _QEDI_H_ */