1caa2da34SSunil Goutham /* SPDX-License-Identifier: GPL-2.0 */ 2caa2da34SSunil Goutham /* Marvell OcteonTx2 RVU Ethernet driver 3caa2da34SSunil Goutham * 4caa2da34SSunil Goutham * Copyright (C) 2020 Marvell International Ltd. 5caa2da34SSunil Goutham * 6caa2da34SSunil Goutham * This program is free software; you can redistribute it and/or modify 7caa2da34SSunil Goutham * it under the terms of the GNU General Public License version 2 as 8caa2da34SSunil Goutham * published by the Free Software Foundation. 9caa2da34SSunil Goutham */ 10caa2da34SSunil Goutham 11caa2da34SSunil Goutham #ifndef OTX2_TXRX_H 12caa2da34SSunil Goutham #define OTX2_TXRX_H 13caa2da34SSunil Goutham 14caa2da34SSunil Goutham #include <linux/etherdevice.h> 15caa2da34SSunil Goutham #include <linux/iommu.h> 16caa2da34SSunil Goutham #include <linux/if_vlan.h> 17caa2da34SSunil Goutham 18caa2da34SSunil Goutham #define LBK_CHAN_BASE 0x000 19caa2da34SSunil Goutham #define SDP_CHAN_BASE 0x700 20caa2da34SSunil Goutham #define CGX_CHAN_BASE 0x800 21caa2da34SSunil Goutham 22caa2da34SSunil Goutham #define OTX2_DATA_ALIGN(X) ALIGN(X, OTX2_ALIGN) 23caa2da34SSunil Goutham #define OTX2_HEAD_ROOM OTX2_ALIGN 24caa2da34SSunil Goutham 2534bfe0ebSSunil Goutham #define OTX2_ETH_HLEN (VLAN_ETH_HLEN + VLAN_HLEN) 2634bfe0ebSSunil Goutham #define OTX2_MIN_MTU 64 2734bfe0ebSSunil Goutham #define OTX2_MAX_MTU (9212 - OTX2_ETH_HLEN) 2834bfe0ebSSunil Goutham 293ca6c4c8SSunil Goutham #define OTX2_MAX_FRAGS_IN_SQE 9 303ca6c4c8SSunil Goutham 31caa2da34SSunil Goutham /* Rx buffer size should be in multiples of 128bytes */ 32caa2da34SSunil Goutham #define RCV_FRAG_LEN1(x) \ 33caa2da34SSunil Goutham ((OTX2_HEAD_ROOM + OTX2_DATA_ALIGN(x)) + \ 34caa2da34SSunil Goutham OTX2_DATA_ALIGN(sizeof(struct skb_shared_info))) 35caa2da34SSunil Goutham 36caa2da34SSunil Goutham /* Prefer 2048 byte buffers for better last level cache 37caa2da34SSunil Goutham * utilization or data distribution across regions. 38caa2da34SSunil Goutham */ 39caa2da34SSunil Goutham #define RCV_FRAG_LEN(x) \ 40caa2da34SSunil Goutham ((RCV_FRAG_LEN1(x) < 2048) ? 2048 : RCV_FRAG_LEN1(x)) 41caa2da34SSunil Goutham 42caa2da34SSunil Goutham #define DMA_BUFFER_LEN(x) \ 43caa2da34SSunil Goutham ((x) - OTX2_HEAD_ROOM - \ 44caa2da34SSunil Goutham OTX2_DATA_ALIGN(sizeof(struct skb_shared_info))) 45caa2da34SSunil Goutham 4604a21ef3SSunil Goutham /* IRQ triggered when NIX_LF_CINTX_CNT[ECOUNT] 4704a21ef3SSunil Goutham * is equal to this value. 4804a21ef3SSunil Goutham */ 4904a21ef3SSunil Goutham #define CQ_CQE_THRESH_DEFAULT 10 5004a21ef3SSunil Goutham 5104a21ef3SSunil Goutham /* IRQ triggered when NIX_LF_CINTX_CNT[ECOUNT] 5204a21ef3SSunil Goutham * is nonzero and this much time elapses after that. 5304a21ef3SSunil Goutham */ 5404a21ef3SSunil Goutham #define CQ_TIMER_THRESH_DEFAULT 1 /* 1 usec */ 5504a21ef3SSunil Goutham #define CQ_TIMER_THRESH_MAX 25 /* 25 usec */ 5604a21ef3SSunil Goutham 5704a21ef3SSunil Goutham /* Min number of CQs (of the ones mapped to this CINT) 5804a21ef3SSunil Goutham * with valid CQEs. 5904a21ef3SSunil Goutham */ 6004a21ef3SSunil Goutham #define CQ_QCOUNT_DEFAULT 1 6104a21ef3SSunil Goutham 623ca6c4c8SSunil Goutham struct sg_list { 633ca6c4c8SSunil Goutham u16 num_segs; 643ca6c4c8SSunil Goutham u64 skb; 653ca6c4c8SSunil Goutham u64 size[OTX2_MAX_FRAGS_IN_SQE]; 663ca6c4c8SSunil Goutham u64 dma_addr[OTX2_MAX_FRAGS_IN_SQE]; 673ca6c4c8SSunil Goutham }; 683ca6c4c8SSunil Goutham 69caa2da34SSunil Goutham struct otx2_snd_queue { 70caa2da34SSunil Goutham u8 aura_id; 713ca6c4c8SSunil Goutham u16 head; 72caa2da34SSunil Goutham u16 sqe_size; 73caa2da34SSunil Goutham u32 sqe_cnt; 74caa2da34SSunil Goutham u16 num_sqbs; 753ca6c4c8SSunil Goutham u16 sqe_thresh; 76caa2da34SSunil Goutham u8 sqe_per_sqb; 77caa2da34SSunil Goutham u64 io_addr; 78caa2da34SSunil Goutham u64 *aura_fc_addr; 79caa2da34SSunil Goutham u64 *lmt_addr; 80caa2da34SSunil Goutham void *sqe_base; 81caa2da34SSunil Goutham struct qmem *sqe; 823ca6c4c8SSunil Goutham struct sg_list *sg; 83caa2da34SSunil Goutham u16 sqb_count; 84caa2da34SSunil Goutham u64 *sqb_ptrs; 85caa2da34SSunil Goutham } ____cacheline_aligned_in_smp; 86caa2da34SSunil Goutham 8704a21ef3SSunil Goutham enum cq_type { 8804a21ef3SSunil Goutham CQ_RX, 8904a21ef3SSunil Goutham CQ_TX, 9004a21ef3SSunil Goutham CQS_PER_CINT = 2, /* RQ + SQ */ 9104a21ef3SSunil Goutham }; 9204a21ef3SSunil Goutham 9304a21ef3SSunil Goutham struct otx2_cq_poll { 9404a21ef3SSunil Goutham void *dev; 9504a21ef3SSunil Goutham #define CINT_INVALID_CQ 255 9604a21ef3SSunil Goutham u8 cint_idx; 9704a21ef3SSunil Goutham u8 cq_ids[CQS_PER_CINT]; 9804a21ef3SSunil Goutham struct napi_struct napi; 9904a21ef3SSunil Goutham }; 10004a21ef3SSunil Goutham 101caa2da34SSunil Goutham struct otx2_pool { 102caa2da34SSunil Goutham struct qmem *stack; 103caa2da34SSunil Goutham struct qmem *fc_addr; 104caa2da34SSunil Goutham u8 rbpage_order; 105caa2da34SSunil Goutham u16 rbsize; 106caa2da34SSunil Goutham u32 page_offset; 107caa2da34SSunil Goutham u16 pageref; 108caa2da34SSunil Goutham struct page *page; 109caa2da34SSunil Goutham }; 110caa2da34SSunil Goutham 111caa2da34SSunil Goutham struct otx2_cq_queue { 112caa2da34SSunil Goutham u8 cq_idx; 113caa2da34SSunil Goutham u8 cq_type; 114abe02543SSunil Goutham u8 cint_idx; /* CQ interrupt id */ 1154ff7d148SGeetha sowjanya u8 refill_task_sched; 116caa2da34SSunil Goutham u16 cqe_size; 117caa2da34SSunil Goutham u16 pool_ptrs; 118caa2da34SSunil Goutham u32 cqe_cnt; 119abe02543SSunil Goutham u32 cq_head; 120caa2da34SSunil Goutham void *cqe_base; 121caa2da34SSunil Goutham struct qmem *cqe; 122caa2da34SSunil Goutham struct otx2_pool *rbpool; 123caa2da34SSunil Goutham } ____cacheline_aligned_in_smp; 124caa2da34SSunil Goutham 125caa2da34SSunil Goutham struct otx2_qset { 126caa2da34SSunil Goutham u32 rqe_cnt; 127caa2da34SSunil Goutham u32 sqe_cnt; /* Keep these two at top */ 128caa2da34SSunil Goutham #define OTX2_MAX_CQ_CNT 64 129caa2da34SSunil Goutham u16 cq_cnt; 130caa2da34SSunil Goutham u16 xqe_size; 131caa2da34SSunil Goutham struct otx2_pool *pool; 13204a21ef3SSunil Goutham struct otx2_cq_poll *napi; 133caa2da34SSunil Goutham struct otx2_cq_queue *cq; 134caa2da34SSunil Goutham struct otx2_snd_queue *sq; 135caa2da34SSunil Goutham }; 136caa2da34SSunil Goutham 137caa2da34SSunil Goutham /* Translate IOVA to physical address */ 138caa2da34SSunil Goutham static inline u64 otx2_iova_to_phys(void *iommu_domain, dma_addr_t dma_addr) 139caa2da34SSunil Goutham { 140caa2da34SSunil Goutham /* Translation is installed only when IOMMU is present */ 141caa2da34SSunil Goutham if (likely(iommu_domain)) 142caa2da34SSunil Goutham return iommu_iova_to_phys(iommu_domain, dma_addr); 143caa2da34SSunil Goutham return dma_addr; 144caa2da34SSunil Goutham } 145caa2da34SSunil Goutham 14604a21ef3SSunil Goutham int otx2_napi_handler(struct napi_struct *napi, int budget); 1473ca6c4c8SSunil Goutham bool otx2_sq_append_skb(struct net_device *netdev, struct otx2_snd_queue *sq, 1483ca6c4c8SSunil Goutham struct sk_buff *skb, u16 qidx); 149caa2da34SSunil Goutham #endif /* OTX2_TXRX_H */ 150