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