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