• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_L2_H
8 #define _QED_L2_H
9 #include <linux/types.h>
10 #include <linux/io.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/qed/qed_eth_if.h>
14 #include "qed.h"
15 #include "qed_hw.h"
16 #include "qed_sp.h"
17 struct qed_rss_params {
18 	u8 update_rss_config;
19 	u8 rss_enable;
20 	u8 rss_eng_id;
21 	u8 update_rss_capabilities;
22 	u8 update_rss_ind_table;
23 	u8 update_rss_key;
24 	u8 rss_caps;
25 	u8 rss_table_size_log;
26 
27 	/* Indirection table consist of rx queue handles */
28 	void *rss_ind_table[QED_RSS_IND_TABLE_SIZE];
29 	u32 rss_key[QED_RSS_KEY_SIZE];
30 };
31 
32 struct qed_sge_tpa_params {
33 	u8 max_buffers_per_cqe;
34 
35 	u8 update_tpa_en_flg;
36 	u8 tpa_ipv4_en_flg;
37 	u8 tpa_ipv6_en_flg;
38 	u8 tpa_ipv4_tunn_en_flg;
39 	u8 tpa_ipv6_tunn_en_flg;
40 
41 	u8 update_tpa_param_flg;
42 	u8 tpa_pkt_split_flg;
43 	u8 tpa_hdr_data_split_flg;
44 	u8 tpa_gro_consistent_flg;
45 	u8 tpa_max_aggs_num;
46 	u16 tpa_max_size;
47 	u16 tpa_min_size_to_start;
48 	u16 tpa_min_size_to_cont;
49 };
50 
51 enum qed_filter_opcode {
52 	QED_FILTER_ADD,
53 	QED_FILTER_REMOVE,
54 	QED_FILTER_MOVE,
55 	QED_FILTER_REPLACE,	/* Delete all MACs and add new one instead */
56 	QED_FILTER_FLUSH,	/* Removes all filters */
57 };
58 
59 enum qed_filter_ucast_type {
60 	QED_FILTER_MAC,
61 	QED_FILTER_VLAN,
62 	QED_FILTER_MAC_VLAN,
63 	QED_FILTER_INNER_MAC,
64 	QED_FILTER_INNER_VLAN,
65 	QED_FILTER_INNER_PAIR,
66 	QED_FILTER_INNER_MAC_VNI_PAIR,
67 	QED_FILTER_MAC_VNI_PAIR,
68 	QED_FILTER_VNI,
69 };
70 
71 struct qed_filter_ucast {
72 	enum qed_filter_opcode opcode;
73 	enum qed_filter_ucast_type type;
74 	u8 is_rx_filter;
75 	u8 is_tx_filter;
76 	u8 vport_to_add_to;
77 	u8 vport_to_remove_from;
78 	unsigned char mac[ETH_ALEN];
79 	u8 assert_on_error;
80 	u16 vlan;
81 	u32 vni;
82 };
83 
84 struct qed_filter_mcast {
85 	/* MOVE is not supported for multicast */
86 	enum qed_filter_opcode opcode;
87 	u8 vport_to_add_to;
88 	u8 vport_to_remove_from;
89 	u8 num_mc_addrs;
90 #define QED_MAX_MC_ADDRS        64
91 	unsigned char mac[QED_MAX_MC_ADDRS][ETH_ALEN];
92 };
93 
94 /**
95  * qed_eth_rx_queue_stop(): This ramrod closes an Rx queue.
96  *
97  * @p_hwfn: HW device data.
98  * @p_rxq: Handler of queue to close
99  * @eq_completion_only: If True completion will be on
100  *                      EQe, if False completion will be
101  *                      on EQe if p_hwfn opaque
102  *                      different from the RXQ opaque
103  *                      otherwise on CQe.
104  * @cqe_completion: If True completion will be receive on CQe.
105  *
106  * Return: Int.
107  */
108 int
109 qed_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
110 		      void *p_rxq,
111 		      bool eq_completion_only, bool cqe_completion);
112 
113 /**
114  * qed_eth_tx_queue_stop(): Closes a Tx queue.
115  *
116  * @p_hwfn: HW device data.
117  * @p_txq: handle to Tx queue needed to be closed.
118  *
119  * Return: Int.
120  */
121 int qed_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, void *p_txq);
122 
123 enum qed_tpa_mode {
124 	QED_TPA_MODE_NONE,
125 	QED_TPA_MODE_UNUSED,
126 	QED_TPA_MODE_GRO,
127 	QED_TPA_MODE_MAX
128 };
129 
130 struct qed_sp_vport_start_params {
131 	enum qed_tpa_mode tpa_mode;
132 	bool remove_inner_vlan;
133 	bool tx_switching;
134 	bool handle_ptp_pkts;
135 	bool only_untagged;
136 	bool drop_ttl0;
137 	u8 max_buffers_per_cqe;
138 	u32 concrete_fid;
139 	u16 opaque_fid;
140 	u8 vport_id;
141 	u16 mtu;
142 	bool check_mac;
143 	bool check_ethtype;
144 };
145 
146 int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
147 			   struct qed_sp_vport_start_params *p_params);
148 
149 
150 struct qed_filter_accept_flags {
151 	u8	update_rx_mode_config;
152 	u8	update_tx_mode_config;
153 	u8	rx_accept_filter;
154 	u8	tx_accept_filter;
155 #define QED_ACCEPT_NONE         0x01
156 #define QED_ACCEPT_UCAST_MATCHED        0x02
157 #define QED_ACCEPT_UCAST_UNMATCHED      0x04
158 #define QED_ACCEPT_MCAST_MATCHED        0x08
159 #define QED_ACCEPT_MCAST_UNMATCHED      0x10
160 #define QED_ACCEPT_BCAST                0x20
161 #define QED_ACCEPT_ANY_VNI              0x40
162 };
163 
164 struct qed_arfs_config_params {
165 	bool tcp;
166 	bool udp;
167 	bool ipv4;
168 	bool ipv6;
169 	enum qed_filter_config_mode mode;
170 };
171 
172 struct qed_sp_vport_update_params {
173 	u16				opaque_fid;
174 	u8				vport_id;
175 	u8				update_vport_active_rx_flg;
176 	u8				vport_active_rx_flg;
177 	u8				update_vport_active_tx_flg;
178 	u8				vport_active_tx_flg;
179 	u8				update_inner_vlan_removal_flg;
180 	u8				inner_vlan_removal_flg;
181 	u8				silent_vlan_removal_flg;
182 	u8				update_default_vlan_enable_flg;
183 	u8				default_vlan_enable_flg;
184 	u8				update_default_vlan_flg;
185 	u16				default_vlan;
186 	u8				update_tx_switching_flg;
187 	u8				tx_switching_flg;
188 	u8				update_approx_mcast_flg;
189 	u8				update_anti_spoofing_en_flg;
190 	u8				anti_spoofing_en;
191 	u8				update_accept_any_vlan_flg;
192 	u8				accept_any_vlan;
193 	u32				bins[8];
194 	struct qed_rss_params		*rss_params;
195 	struct qed_filter_accept_flags	accept_flags;
196 	struct qed_sge_tpa_params	*sge_tpa_params;
197 	u8				update_ctl_frame_check;
198 	u8				mac_chk_en;
199 	u8				ethtype_chk_en;
200 };
201 
202 int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
203 			struct qed_sp_vport_update_params *p_params,
204 			enum spq_mode comp_mode,
205 			struct qed_spq_comp_cb *p_comp_data);
206 
207 /**
208  * qed_sp_vport_stop: This ramrod closes a VPort after all its
209  *                    RX and TX queues are terminated.
210  *                    An Assert is generated if any queues are left open.
211  *
212  * @p_hwfn: HW device data.
213  * @opaque_fid: Opaque FID
214  * @vport_id: VPort ID.
215  *
216  * Return: Int.
217  */
218 int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id);
219 
220 int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
221 			    u16 opaque_fid,
222 			    struct qed_filter_ucast *p_filter_cmd,
223 			    enum spq_mode comp_mode,
224 			    struct qed_spq_comp_cb *p_comp_data);
225 
226 /**
227  * qed_sp_eth_rx_queues_update(): This ramrod updates an RX queue.
228  *                                It is used for setting the active state
229  *                                of the queue and updating the TPA and
230  *                                SGE parameters.
231  * @p_hwfn: HW device data.
232  * @pp_rxq_handlers: An array of queue handlers to be updated.
233  * @num_rxqs: number of queues to update.
234  * @complete_cqe_flg: Post completion to the CQE Ring if set.
235  * @complete_event_flg: Post completion to the Event Ring if set.
236  * @comp_mode: Comp mode.
237  * @p_comp_data: Pointer Comp data.
238  *
239  * Return: Int.
240  *
241  * Note At the moment - only used by non-linux VFs.
242  */
243 
244 int
245 qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
246 			    void **pp_rxq_handlers,
247 			    u8 num_rxqs,
248 			    u8 complete_cqe_flg,
249 			    u8 complete_event_flg,
250 			    enum spq_mode comp_mode,
251 			    struct qed_spq_comp_cb *p_comp_data);
252 
253 /**
254  * qed_get_vport_stats(): Fills provided statistics
255  *			  struct with statistics.
256  *
257  * @cdev: Qed dev pointer.
258  * @stats: Points to struct that will be filled with statistics.
259  *
260  * Return: Void.
261  */
262 void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats);
263 
264 /**
265  * qed_get_vport_stats_context(): Fills provided statistics
266  *				  struct with statistics.
267  *
268  * @cdev: Qed dev pointer.
269  * @stats: Points to struct that will be filled with statistics.
270  * @is_atomic: Hint from the caller - if the func can sleep or not.
271  *
272  * Context: The function should not sleep in case is_atomic == true.
273  * Return: Void.
274  */
275 void qed_get_vport_stats_context(struct qed_dev *cdev,
276 				 struct qed_eth_stats *stats,
277 				 bool is_atomic);
278 
279 void qed_reset_vport_stats(struct qed_dev *cdev);
280 
281 /**
282  * qed_arfs_mode_configure(): Enable or disable rfs mode.
283  *                            It must accept at least one of tcp or udp true
284  *                            and at least one of ipv4 or ipv6 true to enable
285  *                            rfs mode.
286  *
287  * @p_hwfn: HW device data.
288  * @p_ptt: P_ptt.
289  * @p_cfg_params: arfs mode configuration parameters.
290  *
291  * Return. Void.
292  */
293 void qed_arfs_mode_configure(struct qed_hwfn *p_hwfn,
294 			     struct qed_ptt *p_ptt,
295 			     struct qed_arfs_config_params *p_cfg_params);
296 
297 /**
298  * qed_configure_rfs_ntuple_filter(): This ramrod should be used to add
299  *                                     or remove arfs hw filter
300  *
301  * @p_hwfn: HW device data.
302  * @p_cb: Used for QED_SPQ_MODE_CB,where client would initialize
303  *        it with cookie and callback function address, if not
304  *        using this mode then client must pass NULL.
305  * @p_params: Pointer to params.
306  *
307  * Return: Void.
308  */
309 int
310 qed_configure_rfs_ntuple_filter(struct qed_hwfn *p_hwfn,
311 				struct qed_spq_comp_cb *p_cb,
312 				struct qed_ntuple_filter_params *p_params);
313 
314 #define MAX_QUEUES_PER_QZONE    (sizeof(unsigned long) * 8)
315 #define QED_QUEUE_CID_SELF	(0xff)
316 
317 /* Almost identical to the qed_queue_start_common_params,
318  * but here we maintain the SB index in IGU CAM.
319  */
320 struct qed_queue_cid_params {
321 	u8 vport_id;
322 	u16 queue_id;
323 	u8 stats_id;
324 };
325 
326 /* Additional parameters required for initialization of the queue_cid
327  * and are relevant only for a PF initializing one for its VFs.
328  */
329 struct qed_queue_cid_vf_params {
330 	/* Should match the VF's relative index */
331 	u8 vfid;
332 
333 	/* 0-based queue index. Should reflect the relative qzone the
334 	 * VF thinks is associated with it [in its range].
335 	 */
336 	u8 vf_qid;
337 
338 	/* Indicates a VF is legacy, making it differ in several things:
339 	 *  - Producers would be placed in a different place.
340 	 *  - Makes assumptions regarding the CIDs.
341 	 */
342 	u8 vf_legacy;
343 
344 	u8 qid_usage_idx;
345 };
346 
347 struct qed_queue_cid {
348 	/* For stats-id, the `rel' is actually absolute as well */
349 	struct qed_queue_cid_params rel;
350 	struct qed_queue_cid_params abs;
351 
352 	/* These have no 'relative' meaning */
353 	u16 sb_igu_id;
354 	u8 sb_idx;
355 
356 	u32 cid;
357 	u16 opaque_fid;
358 
359 	bool b_is_rx;
360 
361 	/* VFs queues are mapped differently, so we need to know the
362 	 * relative queue associated with them [0-based].
363 	 * Notice this is relevant on the *PF* queue-cid of its VF's queues,
364 	 * and not on the VF itself.
365 	 */
366 	u8 vfid;
367 	u8 vf_qid;
368 
369 	/* We need an additional index to differentiate between queues opened
370 	 * for same queue-zone, as VFs would have to communicate the info
371 	 * to the PF [otherwise PF has no way to differentiate].
372 	 */
373 	u8 qid_usage_idx;
374 
375 	u8 vf_legacy;
376 #define QED_QCID_LEGACY_VF_RX_PROD	(BIT(0))
377 #define QED_QCID_LEGACY_VF_CID		(BIT(1))
378 
379 	struct qed_hwfn *p_owner;
380 };
381 
382 int qed_l2_alloc(struct qed_hwfn *p_hwfn);
383 void qed_l2_setup(struct qed_hwfn *p_hwfn);
384 void qed_l2_free(struct qed_hwfn *p_hwfn);
385 
386 void qed_eth_queue_cid_release(struct qed_hwfn *p_hwfn,
387 			       struct qed_queue_cid *p_cid);
388 
389 struct qed_queue_cid *
390 qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
391 		     u16 opaque_fid,
392 		     struct qed_queue_start_common_params *p_params,
393 		     bool b_is_rx,
394 		     struct qed_queue_cid_vf_params *p_vf_params);
395 
396 int
397 qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
398 		       struct qed_sp_vport_start_params *p_params);
399 
400 /**
401  * qed_eth_rxq_start_ramrod(): Starts an Rx queue, when queue_cid is
402  *                             already prepared
403  *
404  * @p_hwfn: HW device data.
405  * @p_cid: Pointer CID.
406  * @bd_max_bytes: Max bytes.
407  * @bd_chain_phys_addr: Chain physcial address.
408  * @cqe_pbl_addr: PBL address.
409  * @cqe_pbl_size: PBL size.
410  *
411  * Return: Int.
412  */
413 int
414 qed_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
415 			 struct qed_queue_cid *p_cid,
416 			 u16 bd_max_bytes,
417 			 dma_addr_t bd_chain_phys_addr,
418 			 dma_addr_t cqe_pbl_addr, u16 cqe_pbl_size);
419 
420 /**
421  * qed_eth_txq_start_ramrod(): Starts a Tx queue, where queue_cid is
422  *                             already prepared
423  *
424  * @p_hwfn: HW device data.
425  * @p_cid: Pointer CID.
426  * @pbl_addr: PBL address.
427  * @pbl_size: PBL size.
428  * @pq_id: Parameters for choosing the PQ for this Tx queue.
429  *
430  * Return: Int.
431  */
432 int
433 qed_eth_txq_start_ramrod(struct qed_hwfn *p_hwfn,
434 			 struct qed_queue_cid *p_cid,
435 			 dma_addr_t pbl_addr, u16 pbl_size, u16 pq_id);
436 
437 u8 qed_mcast_bin_from_mac(u8 *mac);
438 
439 int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn,
440 			 struct qed_ptt *p_ptt,
441 			 u16 coalesce, struct qed_queue_cid *p_cid);
442 
443 int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn,
444 			 struct qed_ptt *p_ptt,
445 			 u16 coalesce, struct qed_queue_cid *p_cid);
446 
447 int qed_get_rxq_coalesce(struct qed_hwfn *p_hwfn,
448 			 struct qed_ptt *p_ptt,
449 			 struct qed_queue_cid *p_cid, u16 *p_hw_coal);
450 
451 int qed_get_txq_coalesce(struct qed_hwfn *p_hwfn,
452 			 struct qed_ptt *p_ptt,
453 			 struct qed_queue_cid *p_cid, u16 *p_hw_coal);
454 
455 #endif
456