xref: /linux/include/linux/qed/qed_ll2_if.h (revision 2da68a77)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2 /* QLogic qed NIC Driver
3  * Copyright (c) 2015-2017  QLogic Corporation
4  * Copyright (c) 2019-2020 Marvell International Ltd.
5  */
6 
7 #ifndef _QED_LL2_IF_H
8 #define _QED_LL2_IF_H
9 
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/netdevice.h>
13 #include <linux/pci.h>
14 #include <linux/skbuff.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/qed/qed_if.h>
18 
19 enum qed_ll2_conn_type {
20 	QED_LL2_TYPE_FCOE,
21 	QED_LL2_TYPE_TCP_ULP,
22 	QED_LL2_TYPE_TEST,
23 	QED_LL2_TYPE_OOO,
24 	QED_LL2_TYPE_RESERVED2,
25 	QED_LL2_TYPE_ROCE,
26 	QED_LL2_TYPE_IWARP,
27 	QED_LL2_TYPE_RESERVED3,
28 	MAX_QED_LL2_CONN_TYPE
29 };
30 
31 enum qed_ll2_rx_conn_type {
32 	QED_LL2_RX_TYPE_LEGACY,
33 	QED_LL2_RX_TYPE_CTX,
34 	MAX_QED_LL2_RX_CONN_TYPE
35 };
36 
37 enum qed_ll2_roce_flavor_type {
38 	QED_LL2_ROCE,
39 	QED_LL2_RROCE,
40 	MAX_QED_LL2_ROCE_FLAVOR_TYPE
41 };
42 
43 enum qed_ll2_tx_dest {
44 	QED_LL2_TX_DEST_NW, /* Light L2 TX Destination to the Network */
45 	QED_LL2_TX_DEST_LB, /* Light L2 TX Destination to the Loopback */
46 	QED_LL2_TX_DEST_DROP, /* Light L2 Drop the TX packet */
47 	QED_LL2_TX_DEST_MAX
48 };
49 
50 enum qed_ll2_error_handle {
51 	QED_LL2_DROP_PACKET,
52 	QED_LL2_DO_NOTHING,
53 	QED_LL2_ASSERT,
54 };
55 
56 struct qed_ll2_stats {
57 	u64 gsi_invalid_hdr;
58 	u64 gsi_invalid_pkt_length;
59 	u64 gsi_unsupported_pkt_typ;
60 	u64 gsi_crcchksm_error;
61 
62 	u64 packet_too_big_discard;
63 	u64 no_buff_discard;
64 
65 	u64 rcv_ucast_bytes;
66 	u64 rcv_mcast_bytes;
67 	u64 rcv_bcast_bytes;
68 	u64 rcv_ucast_pkts;
69 	u64 rcv_mcast_pkts;
70 	u64 rcv_bcast_pkts;
71 
72 	u64 sent_ucast_bytes;
73 	u64 sent_mcast_bytes;
74 	u64 sent_bcast_bytes;
75 	u64 sent_ucast_pkts;
76 	u64 sent_mcast_pkts;
77 	u64 sent_bcast_pkts;
78 };
79 
80 struct qed_ll2_comp_rx_data {
81 	void *cookie;
82 	dma_addr_t rx_buf_addr;
83 	u16 parse_flags;
84 	u16 err_flags;
85 	u16 vlan;
86 	bool b_last_packet;
87 	u8 connection_handle;
88 
89 	union {
90 		u16 packet_length;
91 		u16 data_length;
92 	} length;
93 
94 	u32 opaque_data_0;
95 	u32 opaque_data_1;
96 
97 	/* GSI only */
98 	u32 src_qp;
99 	u16 qp_id;
100 
101 	union {
102 		u8 placement_offset;
103 		u8 data_length_error;
104 	} u;
105 };
106 
107 typedef
108 void (*qed_ll2_complete_rx_packet_cb)(void *cxt,
109 				      struct qed_ll2_comp_rx_data *data);
110 
111 typedef
112 void (*qed_ll2_release_rx_packet_cb)(void *cxt,
113 				     u8 connection_handle,
114 				     void *cookie,
115 				     dma_addr_t rx_buf_addr,
116 				     bool b_last_packet);
117 
118 typedef
119 void (*qed_ll2_complete_tx_packet_cb)(void *cxt,
120 				      u8 connection_handle,
121 				      void *cookie,
122 				      dma_addr_t first_frag_addr,
123 				      bool b_last_fragment,
124 				      bool b_last_packet);
125 
126 typedef
127 void (*qed_ll2_release_tx_packet_cb)(void *cxt,
128 				     u8 connection_handle,
129 				     void *cookie,
130 				     dma_addr_t first_frag_addr,
131 				     bool b_last_fragment, bool b_last_packet);
132 
133 typedef
134 void (*qed_ll2_slowpath_cb)(void *cxt, u8 connection_handle,
135 			    u32 opaque_data_0, u32 opaque_data_1);
136 
137 struct qed_ll2_cbs {
138 	qed_ll2_complete_rx_packet_cb rx_comp_cb;
139 	qed_ll2_release_rx_packet_cb rx_release_cb;
140 	qed_ll2_complete_tx_packet_cb tx_comp_cb;
141 	qed_ll2_release_tx_packet_cb tx_release_cb;
142 	qed_ll2_slowpath_cb slowpath_cb;
143 	void *cookie;
144 };
145 
146 struct qed_ll2_acquire_data_inputs {
147 	enum qed_ll2_rx_conn_type rx_conn_type;
148 	enum qed_ll2_conn_type conn_type;
149 	u16 mtu;
150 	u16 rx_num_desc;
151 	u16 rx_num_ooo_buffers;
152 	u8 rx_drop_ttl0_flg;
153 	u8 rx_vlan_removal_en;
154 	u16 tx_num_desc;
155 	u8 tx_max_bds_per_packet;
156 	u8 tx_tc;
157 	enum qed_ll2_tx_dest tx_dest;
158 	enum qed_ll2_error_handle ai_err_packet_too_big;
159 	enum qed_ll2_error_handle ai_err_no_buf;
160 	bool secondary_queue;
161 	u8 gsi_enable;
162 };
163 
164 struct qed_ll2_acquire_data {
165 	struct qed_ll2_acquire_data_inputs input;
166 	const struct qed_ll2_cbs *cbs;
167 
168 	/* Output container for LL2 connection's handle */
169 	u8 *p_connection_handle;
170 };
171 
172 struct qed_ll2_tx_pkt_info {
173 	void *cookie;
174 	dma_addr_t first_frag;
175 	enum qed_ll2_tx_dest tx_dest;
176 	enum qed_ll2_roce_flavor_type qed_roce_flavor;
177 	u16 vlan;
178 	u16 l4_hdr_offset_w;	/* from start of packet */
179 	u16 first_frag_len;
180 	u8 num_of_bds;
181 	u8 bd_flags;
182 	bool enable_ip_cksum;
183 	bool enable_l4_cksum;
184 	bool calc_ip_len;
185 	bool remove_stag;
186 };
187 
188 #define QED_LL2_UNUSED_HANDLE   (0xff)
189 
190 struct qed_ll2_cb_ops {
191 	int (*rx_cb)(void *, struct sk_buff *, u32, u32);
192 	int (*tx_cb)(void *, struct sk_buff *, bool);
193 };
194 
195 struct qed_ll2_params {
196 	u16 mtu;
197 	bool drop_ttl0_packets;
198 	bool rx_vlan_stripping;
199 	u8 tx_tc;
200 	bool frags_mapped;
201 	u8 ll2_mac_address[ETH_ALEN];
202 };
203 
204 enum qed_ll2_xmit_flags {
205 	/* FIP discovery packet */
206 	QED_LL2_XMIT_FLAGS_FIP_DISCOVERY
207 };
208 
209 struct qed_ll2_ops {
210 /**
211  * start(): Initializes ll2.
212  *
213  * @cdev: Qed dev pointer.
214  * @params: Protocol driver configuration for the ll2.
215  *
216  * Return: 0 on success, otherwise error value.
217  */
218 	int (*start)(struct qed_dev *cdev, struct qed_ll2_params *params);
219 
220 /**
221  * stop(): Stops the ll2
222  *
223  * @cdev: Qed dev pointer.
224  *
225  * Return: 0 on success, otherwise error value.
226  */
227 	int (*stop)(struct qed_dev *cdev);
228 
229 /**
230  * start_xmit(): Transmits an skb over the ll2 interface
231  *
232  * @cdev: Qed dev pointer.
233  * @skb: SKB.
234  * @xmit_flags: Transmit options defined by the enum qed_ll2_xmit_flags.
235  *
236  * Return: 0 on success, otherwise error value.
237  */
238 	int (*start_xmit)(struct qed_dev *cdev, struct sk_buff *skb,
239 			  unsigned long xmit_flags);
240 
241 /**
242  * register_cb_ops(): Protocol driver register the callback for Rx/Tx
243  * packets. Should be called before `start'.
244  *
245  * @cdev: Qed dev pointer.
246  * @cookie: to be passed to the callback functions.
247  * @ops: the callback functions to register for Rx / Tx.
248  *
249  * Return: 0 on success, otherwise error value.
250  */
251 	void (*register_cb_ops)(struct qed_dev *cdev,
252 				const struct qed_ll2_cb_ops *ops,
253 				void *cookie);
254 
255 /**
256  * get_stats(): Get LL2 related statistics.
257  *
258  * @cdev: Qed dev pointer.
259  * @stats: Pointer to struct that would be filled with stats.
260  *
261  * Return: 0 on success, error otherwise.
262  */
263 	int (*get_stats)(struct qed_dev *cdev, struct qed_ll2_stats *stats);
264 };
265 
266 #ifdef CONFIG_QED_LL2
267 int qed_ll2_alloc_if(struct qed_dev *);
268 void qed_ll2_dealloc_if(struct qed_dev *);
269 #else
270 static const struct qed_ll2_ops qed_ll2_ops_pass = {
271 	.start = NULL,
272 	.stop = NULL,
273 	.start_xmit = NULL,
274 	.register_cb_ops = NULL,
275 	.get_stats = NULL,
276 };
277 
278 static inline int qed_ll2_alloc_if(struct qed_dev *cdev)
279 {
280 	return 0;
281 }
282 
283 static inline void qed_ll2_dealloc_if(struct qed_dev *cdev)
284 {
285 }
286 #endif
287 #endif
288