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