blob: 90912293424648470b74e5b269d2bf6527c38906 [file] [log] [blame]
Gary Leshnerd99dc602020-05-11 12:05:48 -04001/* 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"
Kaike Wan6991abc2020-05-11 12:06:31 -040025#include "netdev.h"
Gary Leshnerd99dc602020-05-11 12:05:48 -040026
27#include <rdma/ib_verbs.h>
28
29#define HFI1_IPOIB_ENTROPY_SHIFT 24
30
31#define HFI1_IPOIB_TXREQ_NAME_LEN 32
32
Kaike Wan6991abc2020-05-11 12:06:31 -040033#define HFI1_IPOIB_PSEUDO_LEN 20
Gary Leshnerd99dc602020-05-11 12:05:48 -040034#define HFI1_IPOIB_ENCAP_LEN 4
35
36struct hfi1_ipoib_dev_priv;
37
38union hfi1_ipoib_flow {
39 u16 as_int;
40 struct {
41 u8 tx_queue;
42 u8 sc5;
43 } __attribute__((__packed__));
44};
45
46/**
Mike Marciniszyn6d1ebcc2021-09-13 09:28:52 -040047 * struct ipoib_txreq - IPOIB transmit descriptor
48 * @txreq: sdma transmit request
49 * @sdma_hdr: 9b ib headers
50 * @sdma_status: status returned by sdma engine
51 * @complete: non-zero implies complete
52 * @priv: ipoib netdev private data
53 * @txq: txq on which skb was output
54 * @skb: skb to send
55 */
56struct ipoib_txreq {
57 struct sdma_txreq txreq;
58 struct hfi1_sdma_header sdma_hdr;
59 int sdma_status;
60 int complete;
61 struct hfi1_ipoib_dev_priv *priv;
62 struct hfi1_ipoib_txq *txq;
63 struct sk_buff *skb;
64};
65
66/**
Gary Leshnerd99dc602020-05-11 12:05:48 -040067 * struct hfi1_ipoib_circ_buf - List of items to be processed
Mike Marciniszynd47dfc22021-09-13 09:28:26 -040068 * @items: ring of items each a power of two size
Gary Leshnerd99dc602020-05-11 12:05:48 -040069 * @max_items: max items + 1 that the ring can contain
Mike Marciniszynd47dfc22021-09-13 09:28:26 -040070 * @shift: log2 of size for getting txreq
Mike Marciniszynf5dc70a2021-09-13 09:28:42 -040071 * @sent_txreqs: count of txreqs posted to sdma
72 * @tail: ring tail
73 * @stops: count of stops of queue
74 * @ring_full: ring has been filled
75 * @no_desc: descriptor shortage seen
76 * @complete_txreqs: count of txreqs completed by sdma
77 * @head: ring head
Gary Leshnerd99dc602020-05-11 12:05:48 -040078 */
79struct hfi1_ipoib_circ_buf {
Mike Marciniszynd47dfc22021-09-13 09:28:26 -040080 void *items;
Mike Marciniszynd47dfc22021-09-13 09:28:26 -040081 u32 max_items;
82 u32 shift;
Mike Marciniszynf5dc70a2021-09-13 09:28:42 -040083 /* consumer cache line */
84 u64 ____cacheline_aligned_in_smp sent_txreqs;
85 u32 avail;
86 u32 tail;
87 atomic_t stops;
88 atomic_t ring_full;
89 atomic_t no_desc;
90 /* producer cache line */
Mike Marciniszynb4b90a52021-09-13 09:28:47 -040091 u64 ____cacheline_aligned_in_smp complete_txreqs;
Mike Marciniszynf5dc70a2021-09-13 09:28:42 -040092 u32 head;
Gary Leshnerd99dc602020-05-11 12:05:48 -040093};
94
95/**
96 * struct hfi1_ipoib_txq - IPOIB per Tx queue information
97 * @priv: private pointer
98 * @sde: sdma engine
99 * @tx_list: tx request list
100 * @sent_txreqs: count of txreqs posted to sdma
101 * @flow: tracks when list needs to be flushed for a flow change
102 * @q_idx: ipoib Tx queue index
103 * @pkts_sent: indicator packets have been sent from this queue
104 * @wait: iowait structure
Gary Leshnerd99dc602020-05-11 12:05:48 -0400105 * @napi: pointer to tx napi interface
106 * @tx_ring: ring of ipoib txreqs to be reaped by napi callback
107 */
108struct hfi1_ipoib_txq {
Mike Marciniszyn4bf0ca02021-09-13 09:28:31 -0400109 struct napi_struct napi;
Gary Leshnerd99dc602020-05-11 12:05:48 -0400110 struct hfi1_ipoib_dev_priv *priv;
111 struct sdma_engine *sde;
112 struct list_head tx_list;
Gary Leshnerd99dc602020-05-11 12:05:48 -0400113 union hfi1_ipoib_flow flow;
114 u8 q_idx;
115 bool pkts_sent;
116 struct iowait wait;
117
Mike Marciniszynf5dc70a2021-09-13 09:28:42 -0400118 struct hfi1_ipoib_circ_buf ____cacheline_aligned_in_smp tx_ring;
Gary Leshnerd99dc602020-05-11 12:05:48 -0400119};
120
121struct hfi1_ipoib_dev_priv {
122 struct hfi1_devdata *dd;
123 struct net_device *netdev;
124 struct ib_device *device;
125 struct hfi1_ipoib_txq *txqs;
Gary Leshnerd99dc602020-05-11 12:05:48 -0400126 const struct net_device_ops *netdev_ops;
127 struct rvt_qp *qp;
Mike Marciniszynf5dc70a2021-09-13 09:28:42 -0400128 u32 qkey;
129 u16 pkey;
130 u16 pkey_index;
131 u8 port_num;
Gary Leshnerd99dc602020-05-11 12:05:48 -0400132};
133
134/* hfi1 ipoib rdma netdev's private data structure */
135struct hfi1_ipoib_rdma_netdev {
136 struct rdma_netdev rn; /* keep this first */
137 /* followed by device private data */
138 struct hfi1_ipoib_dev_priv dev_priv;
139};
140
141static inline struct hfi1_ipoib_dev_priv *
142hfi1_ipoib_priv(const struct net_device *dev)
143{
144 return &((struct hfi1_ipoib_rdma_netdev *)netdev_priv(dev))->dev_priv;
145}
146
Mike Marciniszyn326a2392021-03-29 09:54:11 -0400147int hfi1_ipoib_send(struct net_device *dev,
148 struct sk_buff *skb,
149 struct ib_ah *address,
150 u32 dqpn);
Gary Leshnerd99dc602020-05-11 12:05:48 -0400151
152int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv);
153void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv);
154
Grzegorz Andrejczuk370caa52020-05-11 12:06:43 -0400155int hfi1_ipoib_rxq_init(struct net_device *dev);
156void hfi1_ipoib_rxq_deinit(struct net_device *dev);
157
Gary Leshnerd99dc602020-05-11 12:05:48 -0400158void hfi1_ipoib_napi_tx_enable(struct net_device *dev);
159void hfi1_ipoib_napi_tx_disable(struct net_device *dev);
160
Kaike Wan6991abc2020-05-11 12:06:31 -0400161struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
162 int size, void *data);
163
Gary Leshner438d7dd2020-05-11 12:05:54 -0400164int hfi1_ipoib_rn_get_params(struct ib_device *device,
Mark Bloch1fb7f892021-03-01 09:04:20 +0200165 u32 port_num,
Gary Leshner438d7dd2020-05-11 12:05:54 -0400166 enum rdma_netdev_t type,
167 struct rdma_netdev_alloc_params *params);
168
Mike Marciniszyn042a00f2021-03-29 09:54:08 -0400169void hfi1_ipoib_tx_timeout(struct net_device *dev, unsigned int q);
170
Gary Leshnerd99dc602020-05-11 12:05:48 -0400171#endif /* _IPOIB_H */