Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright(c) 2020 Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file contains HFI1 support for IPOIB functionality
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #ifndef HFI1_IPOIB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define HFI1_IPOIB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/if_infiniband.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "hfi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "iowait.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "netdev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <rdma/ib_verbs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define HFI1_IPOIB_ENTROPY_SHIFT   24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define HFI1_IPOIB_TXREQ_NAME_LEN   32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define HFI1_IPOIB_PSEUDO_LEN 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define HFI1_IPOIB_ENCAP_LEN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct hfi1_ipoib_dev_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) union hfi1_ipoib_flow {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u16 as_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		u8 tx_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		u8 sc5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	} __attribute__((__packed__));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * struct hfi1_ipoib_circ_buf - List of items to be processed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @items: ring of items
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @head: ring head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @tail: ring tail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @max_items: max items + 1 that the ring can contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * @producer_lock: producer sync lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * @consumer_lock: consumer sync lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct ipoib_txreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) struct hfi1_ipoib_circ_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct ipoib_txreq **items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned long head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned long tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned long max_items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	spinlock_t producer_lock; /* head sync lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	spinlock_t consumer_lock; /* tail sync lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * struct hfi1_ipoib_txq - IPOIB per Tx queue information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @priv: private pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * @sde: sdma engine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @tx_list: tx request list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * @sent_txreqs: count of txreqs posted to sdma
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * @stops: count of stops of queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * @ring_full: ring has been filled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * @no_desc: descriptor shortage seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * @flow: tracks when list needs to be flushed for a flow change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * @q_idx: ipoib Tx queue index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @pkts_sent: indicator packets have been sent from this queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @wait: iowait structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * @complete_txreqs: count of txreqs completed by sdma
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * @napi: pointer to tx napi interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * @tx_ring: ring of ipoib txreqs to be reaped by napi callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) struct hfi1_ipoib_txq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct hfi1_ipoib_dev_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct sdma_engine *sde;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct list_head tx_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	u64 sent_txreqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	atomic_t stops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	atomic_t ring_full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	atomic_t no_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	union hfi1_ipoib_flow flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u8 q_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	bool pkts_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct iowait wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	atomic64_t ____cacheline_aligned_in_smp complete_txreqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct napi_struct *napi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct hfi1_ipoib_circ_buf tx_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct hfi1_ipoib_dev_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct hfi1_devdata *dd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct net_device   *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct ib_device    *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct hfi1_ipoib_txq *txqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct kmem_cache *txreq_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct napi_struct *tx_napis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	u16 pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u16 pkey_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	u32 qkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	u8 port_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	const struct net_device_ops *netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct rvt_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct pcpu_sw_netstats __percpu *netstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* hfi1 ipoib rdma netdev's private data structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct hfi1_ipoib_rdma_netdev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct rdma_netdev rn;  /* keep this first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/* followed by device private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct hfi1_ipoib_dev_priv dev_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline struct hfi1_ipoib_dev_priv *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) hfi1_ipoib_priv(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return &((struct hfi1_ipoib_rdma_netdev *)netdev_priv(dev))->dev_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) hfi1_ipoib_update_rx_netstats(struct hfi1_ipoib_dev_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			      u64 packets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			      u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct pcpu_sw_netstats *netstats = this_cpu_ptr(priv->netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	u64_stats_update_begin(&netstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	netstats->rx_packets += packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	netstats->rx_bytes += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	u64_stats_update_end(&netstats->syncp);
^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) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) hfi1_ipoib_update_tx_netstats(struct hfi1_ipoib_dev_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			      u64 packets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			      u64 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct pcpu_sw_netstats *netstats = this_cpu_ptr(priv->netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	u64_stats_update_begin(&netstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	netstats->tx_packets += packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	netstats->tx_bytes += bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	u64_stats_update_end(&netstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int hfi1_ipoib_send_dma(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			struct ib_ah *address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			u32 dqpn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int hfi1_ipoib_rxq_init(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) void hfi1_ipoib_rxq_deinit(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) void hfi1_ipoib_napi_tx_enable(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void hfi1_ipoib_napi_tx_disable(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				       int size, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int hfi1_ipoib_rn_get_params(struct ib_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			     u8 port_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			     enum rdma_netdev_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			     struct rdma_netdev_alloc_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif /* _IPOIB_H */