1d99dc602SGary Leshner /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ 2d99dc602SGary Leshner /* 3d99dc602SGary Leshner * Copyright(c) 2020 Intel Corporation. 4d99dc602SGary Leshner * 5d99dc602SGary Leshner */ 6d99dc602SGary Leshner 7d99dc602SGary Leshner /* 8d99dc602SGary Leshner * This file contains HFI1 support for IPOIB functionality 9d99dc602SGary Leshner */ 10d99dc602SGary Leshner 11d99dc602SGary Leshner #ifndef HFI1_IPOIB_H 12d99dc602SGary Leshner #define HFI1_IPOIB_H 13d99dc602SGary Leshner 14d99dc602SGary Leshner #include <linux/types.h> 15d99dc602SGary Leshner #include <linux/stddef.h> 16d99dc602SGary Leshner #include <linux/atomic.h> 17d99dc602SGary Leshner #include <linux/netdevice.h> 18d99dc602SGary Leshner #include <linux/slab.h> 19d99dc602SGary Leshner #include <linux/skbuff.h> 20d99dc602SGary Leshner #include <linux/list.h> 21d99dc602SGary Leshner #include <linux/if_infiniband.h> 22d99dc602SGary Leshner 23d99dc602SGary Leshner #include "hfi.h" 24d99dc602SGary Leshner #include "iowait.h" 256991abcbSKaike Wan #include "netdev.h" 26d99dc602SGary Leshner 27d99dc602SGary Leshner #include <rdma/ib_verbs.h> 28d99dc602SGary Leshner 29d99dc602SGary Leshner #define HFI1_IPOIB_ENTROPY_SHIFT 24 30d99dc602SGary Leshner 31d99dc602SGary Leshner #define HFI1_IPOIB_TXREQ_NAME_LEN 32 32d99dc602SGary Leshner 336991abcbSKaike Wan #define HFI1_IPOIB_PSEUDO_LEN 20 34d99dc602SGary Leshner #define HFI1_IPOIB_ENCAP_LEN 4 35d99dc602SGary Leshner 36d99dc602SGary Leshner struct hfi1_ipoib_dev_priv; 37d99dc602SGary Leshner 38d99dc602SGary Leshner union hfi1_ipoib_flow { 39d99dc602SGary Leshner u16 as_int; 40d99dc602SGary Leshner struct { 41d99dc602SGary Leshner u8 tx_queue; 42d99dc602SGary Leshner u8 sc5; 43d99dc602SGary Leshner } __attribute__((__packed__)); 44d99dc602SGary Leshner }; 45d99dc602SGary Leshner 46d99dc602SGary Leshner /** 476d1ebccbSMike Marciniszyn * struct ipoib_txreq - IPOIB transmit descriptor 486d1ebccbSMike Marciniszyn * @txreq: sdma transmit request 496d1ebccbSMike Marciniszyn * @sdma_hdr: 9b ib headers 506d1ebccbSMike Marciniszyn * @sdma_status: status returned by sdma engine 516d1ebccbSMike Marciniszyn * @complete: non-zero implies complete 526d1ebccbSMike Marciniszyn * @priv: ipoib netdev private data 536d1ebccbSMike Marciniszyn * @txq: txq on which skb was output 546d1ebccbSMike Marciniszyn * @skb: skb to send 556d1ebccbSMike Marciniszyn */ 566d1ebccbSMike Marciniszyn struct ipoib_txreq { 576d1ebccbSMike Marciniszyn struct sdma_txreq txreq; 58*b1151b74SMike Marciniszyn struct hfi1_sdma_header *sdma_hdr; 596d1ebccbSMike Marciniszyn int sdma_status; 606d1ebccbSMike Marciniszyn int complete; 616d1ebccbSMike Marciniszyn struct hfi1_ipoib_dev_priv *priv; 626d1ebccbSMike Marciniszyn struct hfi1_ipoib_txq *txq; 636d1ebccbSMike Marciniszyn struct sk_buff *skb; 646d1ebccbSMike Marciniszyn }; 656d1ebccbSMike Marciniszyn 666d1ebccbSMike Marciniszyn /** 67d99dc602SGary Leshner * struct hfi1_ipoib_circ_buf - List of items to be processed 68d47dfc2bSMike Marciniszyn * @items: ring of items each a power of two size 69d99dc602SGary Leshner * @max_items: max items + 1 that the ring can contain 70d47dfc2bSMike Marciniszyn * @shift: log2 of size for getting txreq 71f5dc70a0SMike Marciniszyn * @sent_txreqs: count of txreqs posted to sdma 72f5dc70a0SMike Marciniszyn * @tail: ring tail 73f5dc70a0SMike Marciniszyn * @stops: count of stops of queue 74f5dc70a0SMike Marciniszyn * @ring_full: ring has been filled 75f5dc70a0SMike Marciniszyn * @no_desc: descriptor shortage seen 76f5dc70a0SMike Marciniszyn * @complete_txreqs: count of txreqs completed by sdma 77f5dc70a0SMike Marciniszyn * @head: ring head 78d99dc602SGary Leshner */ 79d99dc602SGary Leshner struct hfi1_ipoib_circ_buf { 80d47dfc2bSMike Marciniszyn void *items; 81d47dfc2bSMike Marciniszyn u32 max_items; 82d47dfc2bSMike Marciniszyn u32 shift; 83f5dc70a0SMike Marciniszyn /* consumer cache line */ 84f5dc70a0SMike Marciniszyn u64 ____cacheline_aligned_in_smp sent_txreqs; 85f5dc70a0SMike Marciniszyn u32 avail; 86f5dc70a0SMike Marciniszyn u32 tail; 87f5dc70a0SMike Marciniszyn atomic_t stops; 88f5dc70a0SMike Marciniszyn atomic_t ring_full; 89f5dc70a0SMike Marciniszyn atomic_t no_desc; 90f5dc70a0SMike Marciniszyn /* producer cache line */ 91b4b90a50SMike Marciniszyn u64 ____cacheline_aligned_in_smp complete_txreqs; 92f5dc70a0SMike Marciniszyn u32 head; 93d99dc602SGary Leshner }; 94d99dc602SGary Leshner 95d99dc602SGary Leshner /** 96d99dc602SGary Leshner * struct hfi1_ipoib_txq - IPOIB per Tx queue information 97d99dc602SGary Leshner * @priv: private pointer 98d99dc602SGary Leshner * @sde: sdma engine 99d99dc602SGary Leshner * @tx_list: tx request list 100d99dc602SGary Leshner * @sent_txreqs: count of txreqs posted to sdma 101d99dc602SGary Leshner * @flow: tracks when list needs to be flushed for a flow change 102d99dc602SGary Leshner * @q_idx: ipoib Tx queue index 103d99dc602SGary Leshner * @pkts_sent: indicator packets have been sent from this queue 104d99dc602SGary Leshner * @wait: iowait structure 105d99dc602SGary Leshner * @napi: pointer to tx napi interface 106d99dc602SGary Leshner * @tx_ring: ring of ipoib txreqs to be reaped by napi callback 107d99dc602SGary Leshner */ 108d99dc602SGary Leshner struct hfi1_ipoib_txq { 1094bf0ca0cSMike Marciniszyn struct napi_struct napi; 110d99dc602SGary Leshner struct hfi1_ipoib_dev_priv *priv; 111d99dc602SGary Leshner struct sdma_engine *sde; 112d99dc602SGary Leshner struct list_head tx_list; 113d99dc602SGary Leshner union hfi1_ipoib_flow flow; 114d99dc602SGary Leshner u8 q_idx; 115d99dc602SGary Leshner bool pkts_sent; 116d99dc602SGary Leshner struct iowait wait; 117d99dc602SGary Leshner 118f5dc70a0SMike Marciniszyn struct hfi1_ipoib_circ_buf ____cacheline_aligned_in_smp tx_ring; 119d99dc602SGary Leshner }; 120d99dc602SGary Leshner 121d99dc602SGary Leshner struct hfi1_ipoib_dev_priv { 122d99dc602SGary Leshner struct hfi1_devdata *dd; 123d99dc602SGary Leshner struct net_device *netdev; 124d99dc602SGary Leshner struct ib_device *device; 125d99dc602SGary Leshner struct hfi1_ipoib_txq *txqs; 126d99dc602SGary Leshner const struct net_device_ops *netdev_ops; 127d99dc602SGary Leshner struct rvt_qp *qp; 128f5dc70a0SMike Marciniszyn u32 qkey; 129f5dc70a0SMike Marciniszyn u16 pkey; 130f5dc70a0SMike Marciniszyn u16 pkey_index; 131f5dc70a0SMike Marciniszyn u8 port_num; 132d99dc602SGary Leshner }; 133d99dc602SGary Leshner 134d99dc602SGary Leshner /* hfi1 ipoib rdma netdev's private data structure */ 135d99dc602SGary Leshner struct hfi1_ipoib_rdma_netdev { 136d99dc602SGary Leshner struct rdma_netdev rn; /* keep this first */ 137d99dc602SGary Leshner /* followed by device private data */ 138d99dc602SGary Leshner struct hfi1_ipoib_dev_priv dev_priv; 139d99dc602SGary Leshner }; 140d99dc602SGary Leshner 141d99dc602SGary Leshner static inline struct hfi1_ipoib_dev_priv * hfi1_ipoib_priv(const struct net_device * dev)142d99dc602SGary Leshnerhfi1_ipoib_priv(const struct net_device *dev) 143d99dc602SGary Leshner { 144d99dc602SGary Leshner return &((struct hfi1_ipoib_rdma_netdev *)netdev_priv(dev))->dev_priv; 145d99dc602SGary Leshner } 146d99dc602SGary Leshner 147326a2393SMike Marciniszyn int hfi1_ipoib_send(struct net_device *dev, 148d99dc602SGary Leshner struct sk_buff *skb, 149d99dc602SGary Leshner struct ib_ah *address, 150d99dc602SGary Leshner u32 dqpn); 151d99dc602SGary Leshner 152d99dc602SGary Leshner int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv); 153d99dc602SGary Leshner void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv); 154d99dc602SGary Leshner 155370caa5bSGrzegorz Andrejczuk int hfi1_ipoib_rxq_init(struct net_device *dev); 156370caa5bSGrzegorz Andrejczuk void hfi1_ipoib_rxq_deinit(struct net_device *dev); 157370caa5bSGrzegorz Andrejczuk 158d99dc602SGary Leshner void hfi1_ipoib_napi_tx_enable(struct net_device *dev); 159d99dc602SGary Leshner void hfi1_ipoib_napi_tx_disable(struct net_device *dev); 160d99dc602SGary Leshner 1616991abcbSKaike Wan struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq, 1626991abcbSKaike Wan int size, void *data); 1636991abcbSKaike Wan 164438d7ddaSGary Leshner int hfi1_ipoib_rn_get_params(struct ib_device *device, 1651fb7f897SMark Bloch u32 port_num, 166438d7ddaSGary Leshner enum rdma_netdev_t type, 167438d7ddaSGary Leshner struct rdma_netdev_alloc_params *params); 168438d7ddaSGary Leshner 169042a00f9SMike Marciniszyn void hfi1_ipoib_tx_timeout(struct net_device *dev, unsigned int q); 170042a00f9SMike Marciniszyn 171d99dc602SGary Leshner #endif /* _IPOIB_H */ 172