xref: /linux/drivers/infiniband/hw/hfi1/vnic.h (revision 4b660dbd9ee2059850fd30e0df420ca7a38a1856)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright(c) 2017 - 2020 Intel Corporation.
4  */
5 
6 #ifndef _HFI1_VNIC_H
7 #define _HFI1_VNIC_H
8 #include <rdma/opa_vnic.h>
9 #include "hfi.h"
10 #include "sdma.h"
11 
12 #define HFI1_VNIC_MAX_TXQ     16
13 #define HFI1_VNIC_MAX_PAD     12
14 
15 /* L4 header definitions */
16 #define HFI1_VNIC_L4_HDR_OFFSET  OPA_VNIC_L2_HDR_LEN
17 
18 #define HFI1_VNIC_GET_L4_HDR(data)   \
19 	(*((u16 *)((u8 *)(data) + HFI1_VNIC_L4_HDR_OFFSET)))
20 
21 #define HFI1_VNIC_GET_VESWID(data)   \
22 	(HFI1_VNIC_GET_L4_HDR(data) & 0xFFF)
23 
24 /* Service class */
25 #define HFI1_VNIC_SC_OFFSET_LOW 6
26 #define HFI1_VNIC_SC_OFFSET_HI  7
27 #define HFI1_VNIC_SC_SHIFT      4
28 
29 #define HFI1_VNIC_MAX_QUEUE 16
30 #define HFI1_NUM_VNIC_CTXT 8
31 
32 /**
33  * struct hfi1_vnic_sdma - VNIC per Tx ring SDMA information
34  * @dd - device data pointer
35  * @sde - sdma engine
36  * @vinfo - vnic info pointer
37  * @wait - iowait structure
38  * @stx - sdma tx request
39  * @state - vnic Tx ring SDMA state
40  * @q_idx - vnic Tx queue index
41  */
42 struct hfi1_vnic_sdma {
43 	struct hfi1_devdata *dd;
44 	struct sdma_engine  *sde;
45 	struct hfi1_vnic_vport_info *vinfo;
46 	struct iowait wait;
47 	struct sdma_txreq stx;
48 	unsigned int state;
49 	u8 q_idx;
50 	bool pkts_sent;
51 };
52 
53 /**
54  * struct hfi1_vnic_rx_queue - HFI1 VNIC receive queue
55  * @idx: queue index
56  * @vinfo: pointer to vport information
57  * @netdev: network device
58  * @napi: netdev napi structure
59  * @skbq: queue of received socket buffers
60  */
61 struct hfi1_vnic_rx_queue {
62 	u8                           idx;
63 	struct hfi1_vnic_vport_info *vinfo;
64 	struct net_device           *netdev;
65 	struct napi_struct           napi;
66 };
67 
68 /**
69  * struct hfi1_vnic_vport_info - HFI1 VNIC virtual port information
70  * @dd: device data pointer
71  * @netdev: net device pointer
72  * @flags: state flags
73  * @lock: vport lock
74  * @num_tx_q: number of transmit queues
75  * @num_rx_q: number of receive queues
76  * @vesw_id: virtual switch id
77  * @rxq: Array of receive queues
78  * @stats: per queue stats
79  * @sdma: VNIC SDMA structure per TXQ
80  */
81 struct hfi1_vnic_vport_info {
82 	struct hfi1_devdata *dd;
83 	struct net_device   *netdev;
84 	unsigned long        flags;
85 
86 	/* Lock used around state updates */
87 	struct mutex         lock;
88 
89 	u8  num_tx_q;
90 	u8  num_rx_q;
91 	u16 vesw_id;
92 	struct hfi1_vnic_rx_queue rxq[HFI1_NUM_VNIC_CTXT];
93 
94 	struct opa_vnic_stats  stats[HFI1_VNIC_MAX_QUEUE];
95 	struct hfi1_vnic_sdma  sdma[HFI1_VNIC_MAX_TXQ];
96 };
97 
98 #define v_dbg(format, arg...) \
99 	netdev_dbg(vinfo->netdev, format, ## arg)
100 #define v_err(format, arg...) \
101 	netdev_err(vinfo->netdev, format, ## arg)
102 #define v_info(format, arg...) \
103 	netdev_info(vinfo->netdev, format, ## arg)
104 
105 /* vnic hfi1 internal functions */
106 void hfi1_vnic_setup(struct hfi1_devdata *dd);
107 int hfi1_vnic_txreq_init(struct hfi1_devdata *dd);
108 void hfi1_vnic_txreq_deinit(struct hfi1_devdata *dd);
109 
110 void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet);
111 void hfi1_vnic_sdma_init(struct hfi1_vnic_vport_info *vinfo);
112 bool hfi1_vnic_sdma_write_avail(struct hfi1_vnic_vport_info *vinfo,
113 				u8 q_idx);
114 
115 /* vnic rdma netdev operations */
116 struct net_device *hfi1_vnic_alloc_rn(struct ib_device *device,
117 				      u32 port_num,
118 				      enum rdma_netdev_t type,
119 				      const char *name,
120 				      unsigned char name_assign_type,
121 				      void (*setup)(struct net_device *));
122 int hfi1_vnic_send_dma(struct hfi1_devdata *dd, u8 q_idx,
123 		       struct hfi1_vnic_vport_info *vinfo,
124 		       struct sk_buff *skb, u64 pbc, u8 plen);
125 
126 #endif /* _HFI1_VNIC_H */
127