1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
3 * Copyright(c) 2017 - 2020 Intel Corporation.
8 #include <rdma/opa_vnic.h>
12 #define HFI1_VNIC_MAX_TXQ 16
13 #define HFI1_VNIC_MAX_PAD 12
15 /* L4 header definitions */
16 #define HFI1_VNIC_L4_HDR_OFFSET OPA_VNIC_L2_HDR_LEN
18 #define HFI1_VNIC_GET_L4_HDR(data) \
19 (*((u16 *)((u8 *)(data) + HFI1_VNIC_L4_HDR_OFFSET)))
21 #define HFI1_VNIC_GET_VESWID(data) \
22 (HFI1_VNIC_GET_L4_HDR(data) & 0xFFF)
25 #define HFI1_VNIC_SC_OFFSET_LOW 6
26 #define HFI1_VNIC_SC_OFFSET_HI 7
27 #define HFI1_VNIC_SC_SHIFT 4
29 #define HFI1_VNIC_MAX_QUEUE 16
30 #define HFI1_NUM_VNIC_CTXT 8
33 * struct hfi1_vnic_sdma - VNIC per Tx ring SDMA information
34 * @dd - device data pointer
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
42 struct hfi1_vnic_sdma
{
43 struct hfi1_devdata
*dd
;
44 struct sdma_engine
*sde
;
45 struct hfi1_vnic_vport_info
*vinfo
;
47 struct sdma_txreq stx
;
54 * struct hfi1_vnic_rx_queue - HFI1 VNIC receive queue
56 * @vinfo: pointer to vport information
57 * @netdev: network device
58 * @napi: netdev napi structure
59 * @skbq: queue of received socket buffers
61 struct hfi1_vnic_rx_queue
{
63 struct hfi1_vnic_vport_info
*vinfo
;
64 struct net_device
*netdev
;
65 struct napi_struct napi
;
69 * struct hfi1_vnic_vport_info - HFI1 VNIC virtual port information
70 * @dd: device data pointer
71 * @netdev: net device pointer
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
81 struct hfi1_vnic_vport_info
{
82 struct hfi1_devdata
*dd
;
83 struct net_device
*netdev
;
86 /* Lock used around state updates */
92 struct hfi1_vnic_rx_queue rxq
[HFI1_NUM_VNIC_CTXT
];
94 struct opa_vnic_stats stats
[HFI1_VNIC_MAX_QUEUE
];
95 struct hfi1_vnic_sdma sdma
[HFI1_VNIC_MAX_TXQ
];
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)
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
);
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
,
115 /* vnic rdma netdev operations */
116 struct net_device
*hfi1_vnic_alloc_rn(struct ib_device
*device
,
118 enum rdma_netdev_t type
,
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
);
126 #endif /* _HFI1_VNIC_H */