12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2c3e79bafSAviad Krawczyk /* 3c3e79bafSAviad Krawczyk * Huawei HiNIC PCI Express Linux driver 4c3e79bafSAviad Krawczyk * Copyright(c) 2017 Huawei Technologies Co., Ltd 5c3e79bafSAviad Krawczyk */ 6c3e79bafSAviad Krawczyk 7c3e79bafSAviad Krawczyk #ifndef HINIC_HW_QP_H 8c3e79bafSAviad Krawczyk #define HINIC_HW_QP_H 9c3e79bafSAviad Krawczyk 1000e57a6dSAviad Krawczyk #include <linux/kernel.h> 11b15a9f37SAviad Krawczyk #include <linux/types.h> 12b15a9f37SAviad Krawczyk #include <linux/sizes.h> 13f91090f7SAviad Krawczyk #include <linux/pci.h> 14f91090f7SAviad Krawczyk #include <linux/skbuff.h> 15f91090f7SAviad Krawczyk 16e2585ea7SAviad Krawczyk #include "hinic_common.h" 17f91090f7SAviad Krawczyk #include "hinic_hw_if.h" 18f91090f7SAviad Krawczyk #include "hinic_hw_wqe.h" 19f91090f7SAviad Krawczyk #include "hinic_hw_wq.h" 2053e7d6feSAviad Krawczyk #include "hinic_hw_qp_ctxt.h" 21b15a9f37SAviad Krawczyk 2200e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_PI_HI_SHIFT 0 2300e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_QID_SHIFT 8 2400e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_PATH_SHIFT 23 2500e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_COS_SHIFT 24 2600e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_TYPE_SHIFT 27 2700e57a6dSAviad Krawczyk 2800e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_PI_HI_MASK 0xFF 2900e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_QID_MASK 0x3FF 3000e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_PATH_MASK 0x1 3100e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_COS_MASK 0x7 3200e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_TYPE_MASK 0x1F 3300e57a6dSAviad Krawczyk 3400e57a6dSAviad Krawczyk #define HINIC_SQ_DB_INFO_SET(val, member) \ 3500e57a6dSAviad Krawczyk (((u32)(val) & HINIC_SQ_DB_INFO_##member##_MASK) \ 3600e57a6dSAviad Krawczyk << HINIC_SQ_DB_INFO_##member##_SHIFT) 3700e57a6dSAviad Krawczyk 38b15a9f37SAviad Krawczyk #define HINIC_SQ_WQEBB_SIZE 64 39b15a9f37SAviad Krawczyk #define HINIC_RQ_WQEBB_SIZE 32 40b15a9f37SAviad Krawczyk 417dd29ee1SLuo bin #define HINIC_SQ_PAGE_SIZE SZ_256K 427dd29ee1SLuo bin #define HINIC_RQ_PAGE_SIZE SZ_256K 43b15a9f37SAviad Krawczyk 44b15a9f37SAviad Krawczyk #define HINIC_SQ_DEPTH SZ_4K 45b15a9f37SAviad Krawczyk #define HINIC_RQ_DEPTH SZ_4K 46b15a9f37SAviad Krawczyk 47bcab6782SLuo bin #define HINIC_MAX_QUEUE_DEPTH SZ_4K 48bcab6782SLuo bin #define HINIC_MIN_QUEUE_DEPTH 128 49bcab6782SLuo bin 50cde66f24SAviad Krawczyk /* In any change to HINIC_RX_BUF_SZ, HINIC_RX_BUF_SZ_IDX must be changed */ 51f91090f7SAviad Krawczyk #define HINIC_RX_BUF_SZ 2048 52cde66f24SAviad Krawczyk #define HINIC_RX_BUF_SZ_IDX HINIC_RX_BUF_SZ_2048_IDX 53f91090f7SAviad Krawczyk 5400e57a6dSAviad Krawczyk #define HINIC_MIN_TX_WQE_SIZE(wq) \ 5500e57a6dSAviad Krawczyk ALIGN(HINIC_SQ_WQE_SIZE(1), (wq)->wqebb_size) 5600e57a6dSAviad Krawczyk 5700e57a6dSAviad Krawczyk #define HINIC_MIN_TX_NUM_WQEBBS(sq) \ 5800e57a6dSAviad Krawczyk (HINIC_MIN_TX_WQE_SIZE((sq)->wq) / (sq)->wq->wqebb_size) 5900e57a6dSAviad Krawczyk 60cde66f24SAviad Krawczyk enum hinic_rx_buf_sz_idx { 61cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_32_IDX, 62cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_64_IDX, 63cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_96_IDX, 64cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_128_IDX, 65cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_192_IDX, 66cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_256_IDX, 67cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_384_IDX, 68cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_512_IDX, 69cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_768_IDX, 70cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_1024_IDX, 71cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_1536_IDX, 72cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_2048_IDX, 73cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_3072_IDX, 74cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_4096_IDX, 75cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_8192_IDX, 76cde66f24SAviad Krawczyk HINIC_RX_BUF_SZ_16384_IDX, 77cde66f24SAviad Krawczyk }; 78cde66f24SAviad Krawczyk 79c3e79bafSAviad Krawczyk struct hinic_sq { 80f91090f7SAviad Krawczyk struct hinic_hwif *hwif; 81f91090f7SAviad Krawczyk 82f91090f7SAviad Krawczyk struct hinic_wq *wq; 83f91090f7SAviad Krawczyk 84253ac3a9SLuo bin u16 qid; 85253ac3a9SLuo bin 86f91090f7SAviad Krawczyk u32 irq; 87f91090f7SAviad Krawczyk u16 msix_entry; 88f91090f7SAviad Krawczyk 89f91090f7SAviad Krawczyk void *hw_ci_addr; 90f91090f7SAviad Krawczyk dma_addr_t hw_ci_dma_addr; 91f91090f7SAviad Krawczyk 92f91090f7SAviad Krawczyk void __iomem *db_base; 93f91090f7SAviad Krawczyk 94f91090f7SAviad Krawczyk struct sk_buff **saved_skb; 95253ac3a9SLuo bin struct hinic_debug_priv *dbg; 96c3e79bafSAviad Krawczyk }; 97c3e79bafSAviad Krawczyk 98c3e79bafSAviad Krawczyk struct hinic_rq { 99f91090f7SAviad Krawczyk struct hinic_hwif *hwif; 100f91090f7SAviad Krawczyk 101f91090f7SAviad Krawczyk struct hinic_wq *wq; 102f91090f7SAviad Krawczyk 103626f0603SLuo bin u16 qid; 104626f0603SLuo bin 1050bff777bSLuo bin struct cpumask affinity_mask; 106f91090f7SAviad Krawczyk u32 irq; 107f91090f7SAviad Krawczyk u16 msix_entry; 108f91090f7SAviad Krawczyk 109f91090f7SAviad Krawczyk size_t buf_sz; 110f91090f7SAviad Krawczyk 111f91090f7SAviad Krawczyk struct sk_buff **saved_skb; 112f91090f7SAviad Krawczyk 113f91090f7SAviad Krawczyk struct hinic_rq_cqe **cqe; 114f91090f7SAviad Krawczyk dma_addr_t *cqe_dma; 115f91090f7SAviad Krawczyk 116f91090f7SAviad Krawczyk u16 *pi_virt_addr; 117f91090f7SAviad Krawczyk dma_addr_t pi_dma_addr; 118626f0603SLuo bin struct hinic_debug_priv *dbg; 119c3e79bafSAviad Krawczyk }; 120c3e79bafSAviad Krawczyk 121c3e79bafSAviad Krawczyk struct hinic_qp { 122c3e79bafSAviad Krawczyk struct hinic_sq sq; 123c3e79bafSAviad Krawczyk struct hinic_rq rq; 124b15a9f37SAviad Krawczyk 125b15a9f37SAviad Krawczyk u16 q_id; 126c3e79bafSAviad Krawczyk }; 127c3e79bafSAviad Krawczyk 12853e7d6feSAviad Krawczyk void hinic_qp_prepare_header(struct hinic_qp_ctxt_header *qp_ctxt_hdr, 12953e7d6feSAviad Krawczyk enum hinic_qp_ctxt_type ctxt_type, 13053e7d6feSAviad Krawczyk u16 num_queues, u16 max_queues); 13153e7d6feSAviad Krawczyk 13253e7d6feSAviad Krawczyk void hinic_sq_prepare_ctxt(struct hinic_sq_ctxt *sq_ctxt, 13353e7d6feSAviad Krawczyk struct hinic_sq *sq, u16 global_qid); 13453e7d6feSAviad Krawczyk 13553e7d6feSAviad Krawczyk void hinic_rq_prepare_ctxt(struct hinic_rq_ctxt *rq_ctxt, 13653e7d6feSAviad Krawczyk struct hinic_rq *rq, u16 global_qid); 13753e7d6feSAviad Krawczyk 138f91090f7SAviad Krawczyk int hinic_init_sq(struct hinic_sq *sq, struct hinic_hwif *hwif, 139f91090f7SAviad Krawczyk struct hinic_wq *wq, struct msix_entry *entry, void *ci_addr, 140f91090f7SAviad Krawczyk dma_addr_t ci_dma_addr, void __iomem *db_base); 141f91090f7SAviad Krawczyk 142f91090f7SAviad Krawczyk void hinic_clean_sq(struct hinic_sq *sq); 143f91090f7SAviad Krawczyk 144f91090f7SAviad Krawczyk int hinic_init_rq(struct hinic_rq *rq, struct hinic_hwif *hwif, 145f91090f7SAviad Krawczyk struct hinic_wq *wq, struct msix_entry *entry); 146f91090f7SAviad Krawczyk 147f91090f7SAviad Krawczyk void hinic_clean_rq(struct hinic_rq *rq); 148f91090f7SAviad Krawczyk 14900e57a6dSAviad Krawczyk int hinic_get_sq_free_wqebbs(struct hinic_sq *sq); 15000e57a6dSAviad Krawczyk 151e2585ea7SAviad Krawczyk int hinic_get_rq_free_wqebbs(struct hinic_rq *rq); 152e2585ea7SAviad Krawczyk 153cc18a754SZhao Chen void hinic_task_set_l2hdr(struct hinic_sq_task *task, u32 len); 154cc18a754SZhao Chen 155cc18a754SZhao Chen void hinic_task_set_outter_l3(struct hinic_sq_task *task, 156cc18a754SZhao Chen enum hinic_l3_offload_type l3_type, 157cc18a754SZhao Chen u32 network_len); 158cc18a754SZhao Chen 159cc18a754SZhao Chen void hinic_task_set_inner_l3(struct hinic_sq_task *task, 160cc18a754SZhao Chen enum hinic_l3_offload_type l3_type, 161cc18a754SZhao Chen u32 network_len); 162cc18a754SZhao Chen 163cc18a754SZhao Chen void hinic_task_set_tunnel_l4(struct hinic_sq_task *task, 1646e29464bSNathan Chancellor enum hinic_l4_tunnel_type l4_type, 165cc18a754SZhao Chen u32 tunnel_len); 166cc18a754SZhao Chen 167cc18a754SZhao Chen void hinic_set_cs_inner_l4(struct hinic_sq_task *task, 168cc18a754SZhao Chen u32 *queue_info, 169cc18a754SZhao Chen enum hinic_l4_offload_type l4_offload, 170cc18a754SZhao Chen u32 l4_len, u32 offset); 171cc18a754SZhao Chen 172cc18a754SZhao Chen void hinic_set_tso_inner_l4(struct hinic_sq_task *task, 173cc18a754SZhao Chen u32 *queue_info, 174cc18a754SZhao Chen enum hinic_l4_offload_type l4_offload, 175cc18a754SZhao Chen u32 l4_len, 176cc18a754SZhao Chen u32 offset, u32 ip_ident, u32 mss); 177cc18a754SZhao Chen 178*c706df6dSZhengchao Shao void hinic_sq_prepare_wqe(struct hinic_sq *sq, struct hinic_sq_wqe *wqe, 179*c706df6dSZhengchao Shao struct hinic_sge *sges, int nr_sges); 18000e57a6dSAviad Krawczyk 18100e57a6dSAviad Krawczyk void hinic_sq_write_db(struct hinic_sq *sq, u16 prod_idx, unsigned int wqe_size, 18200e57a6dSAviad Krawczyk unsigned int cos); 18300e57a6dSAviad Krawczyk 18400e57a6dSAviad Krawczyk struct hinic_sq_wqe *hinic_sq_get_wqe(struct hinic_sq *sq, 18500e57a6dSAviad Krawczyk unsigned int wqe_size, u16 *prod_idx); 18600e57a6dSAviad Krawczyk 187cc18a754SZhao Chen void hinic_sq_return_wqe(struct hinic_sq *sq, unsigned int wqe_size); 188cc18a754SZhao Chen 18900e57a6dSAviad Krawczyk void hinic_sq_write_wqe(struct hinic_sq *sq, u16 prod_idx, 19000e57a6dSAviad Krawczyk struct hinic_sq_wqe *wqe, struct sk_buff *skb, 19100e57a6dSAviad Krawczyk unsigned int wqe_size); 19200e57a6dSAviad Krawczyk 19300e57a6dSAviad Krawczyk struct hinic_sq_wqe *hinic_sq_read_wqe(struct hinic_sq *sq, 19400e57a6dSAviad Krawczyk struct sk_buff **skb, 1959c2956d2SZhao Chen unsigned int wqe_size, u16 *cons_idx); 1969c2956d2SZhao Chen 1979c2956d2SZhao Chen struct hinic_sq_wqe *hinic_sq_read_wqebb(struct hinic_sq *sq, 1989c2956d2SZhao Chen struct sk_buff **skb, 19900e57a6dSAviad Krawczyk unsigned int *wqe_size, u16 *cons_idx); 20000e57a6dSAviad Krawczyk 20100e57a6dSAviad Krawczyk void hinic_sq_put_wqe(struct hinic_sq *sq, unsigned int wqe_size); 20200e57a6dSAviad Krawczyk 20300e57a6dSAviad Krawczyk void hinic_sq_get_sges(struct hinic_sq_wqe *wqe, struct hinic_sge *sges, 20400e57a6dSAviad Krawczyk int nr_sges); 20500e57a6dSAviad Krawczyk 206e2585ea7SAviad Krawczyk struct hinic_rq_wqe *hinic_rq_get_wqe(struct hinic_rq *rq, 207e2585ea7SAviad Krawczyk unsigned int wqe_size, u16 *prod_idx); 208e2585ea7SAviad Krawczyk 209e2585ea7SAviad Krawczyk void hinic_rq_write_wqe(struct hinic_rq *rq, u16 prod_idx, 210e2585ea7SAviad Krawczyk struct hinic_rq_wqe *wqe, struct sk_buff *skb); 211e2585ea7SAviad Krawczyk 212e2585ea7SAviad Krawczyk struct hinic_rq_wqe *hinic_rq_read_wqe(struct hinic_rq *rq, 213e2585ea7SAviad Krawczyk unsigned int wqe_size, 214e2585ea7SAviad Krawczyk struct sk_buff **skb, u16 *cons_idx); 215e2585ea7SAviad Krawczyk 216e2585ea7SAviad Krawczyk struct hinic_rq_wqe *hinic_rq_read_next_wqe(struct hinic_rq *rq, 217e2585ea7SAviad Krawczyk unsigned int wqe_size, 218e2585ea7SAviad Krawczyk struct sk_buff **skb, 219e2585ea7SAviad Krawczyk u16 *cons_idx); 220e2585ea7SAviad Krawczyk 221e2585ea7SAviad Krawczyk void hinic_rq_put_wqe(struct hinic_rq *rq, u16 cons_idx, 222e2585ea7SAviad Krawczyk unsigned int wqe_size); 223e2585ea7SAviad Krawczyk 224e2585ea7SAviad Krawczyk void hinic_rq_get_sge(struct hinic_rq *rq, struct hinic_rq_wqe *wqe, 225e2585ea7SAviad Krawczyk u16 cons_idx, struct hinic_sge *sge); 226e2585ea7SAviad Krawczyk 227e2585ea7SAviad Krawczyk void hinic_rq_prepare_wqe(struct hinic_rq *rq, u16 prod_idx, 228e2585ea7SAviad Krawczyk struct hinic_rq_wqe *wqe, struct hinic_sge *sge); 229e2585ea7SAviad Krawczyk 230e2585ea7SAviad Krawczyk void hinic_rq_update(struct hinic_rq *rq, u16 prod_idx); 231e2585ea7SAviad Krawczyk 232c3e79bafSAviad Krawczyk #endif 233