1 /* QLogic qed NIC Driver
2  * Copyright (c) 2015 QLogic Corporation
3  *
4  * This software is available under the terms of the GNU General Public License
5  * (GPL) Version 2, available from the file COPYING in the main directory of
6  * this source tree.
7  */
8 #ifndef _QED_L2_H
9 #define _QED_L2_H
10 #include <linux/types.h>
11 #include <linux/io.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/qed/qed_eth_if.h>
15 #include "qed.h"
16 #include "qed_hw.h"
17 #include "qed_sp.h"
18 
19 struct qed_sge_tpa_params {
20 	u8 max_buffers_per_cqe;
21 
22 	u8 update_tpa_en_flg;
23 	u8 tpa_ipv4_en_flg;
24 	u8 tpa_ipv6_en_flg;
25 	u8 tpa_ipv4_tunn_en_flg;
26 	u8 tpa_ipv6_tunn_en_flg;
27 
28 	u8 update_tpa_param_flg;
29 	u8 tpa_pkt_split_flg;
30 	u8 tpa_hdr_data_split_flg;
31 	u8 tpa_gro_consistent_flg;
32 	u8 tpa_max_aggs_num;
33 	u16 tpa_max_size;
34 	u16 tpa_min_size_to_start;
35 	u16 tpa_min_size_to_cont;
36 };
37 
38 enum qed_filter_opcode {
39 	QED_FILTER_ADD,
40 	QED_FILTER_REMOVE,
41 	QED_FILTER_MOVE,
42 	QED_FILTER_REPLACE,	/* Delete all MACs and add new one instead */
43 	QED_FILTER_FLUSH,	/* Removes all filters */
44 };
45 
46 enum qed_filter_ucast_type {
47 	QED_FILTER_MAC,
48 	QED_FILTER_VLAN,
49 	QED_FILTER_MAC_VLAN,
50 	QED_FILTER_INNER_MAC,
51 	QED_FILTER_INNER_VLAN,
52 	QED_FILTER_INNER_PAIR,
53 	QED_FILTER_INNER_MAC_VNI_PAIR,
54 	QED_FILTER_MAC_VNI_PAIR,
55 	QED_FILTER_VNI,
56 };
57 
58 struct qed_filter_ucast {
59 	enum qed_filter_opcode opcode;
60 	enum qed_filter_ucast_type type;
61 	u8 is_rx_filter;
62 	u8 is_tx_filter;
63 	u8 vport_to_add_to;
64 	u8 vport_to_remove_from;
65 	unsigned char mac[ETH_ALEN];
66 	u8 assert_on_error;
67 	u16 vlan;
68 	u32 vni;
69 };
70 
71 struct qed_filter_mcast {
72 	/* MOVE is not supported for multicast */
73 	enum qed_filter_opcode opcode;
74 	u8 vport_to_add_to;
75 	u8 vport_to_remove_from;
76 	u8 num_mc_addrs;
77 #define QED_MAX_MC_ADDRS        64
78 	unsigned char mac[QED_MAX_MC_ADDRS][ETH_ALEN];
79 };
80 
81 /**
82  * @brief qed_eth_rx_queue_stop - This ramrod closes an Rx queue
83  *
84  * @param p_hwfn
85  * @param p_rxq			Handler of queue to close
86  * @param eq_completion_only	If True completion will be on
87  *				EQe, if False completion will be
88  *				on EQe if p_hwfn opaque
89  *				different from the RXQ opaque
90  *				otherwise on CQe.
91  * @param cqe_completion	If True completion will be
92  *				receive on CQe.
93  * @return int
94  */
95 int
96 qed_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
97 		      void *p_rxq,
98 		      bool eq_completion_only, bool cqe_completion);
99 
100 /**
101  * @brief qed_eth_tx_queue_stop - closes a Tx queue
102  *
103  * @param p_hwfn
104  * @param p_txq - handle to Tx queue needed to be closed
105  *
106  * @return int
107  */
108 int qed_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, void *p_txq);
109 
110 enum qed_tpa_mode {
111 	QED_TPA_MODE_NONE,
112 	QED_TPA_MODE_UNUSED,
113 	QED_TPA_MODE_GRO,
114 	QED_TPA_MODE_MAX
115 };
116 
117 struct qed_sp_vport_start_params {
118 	enum qed_tpa_mode tpa_mode;
119 	bool remove_inner_vlan;
120 	bool tx_switching;
121 	bool only_untagged;
122 	bool drop_ttl0;
123 	u8 max_buffers_per_cqe;
124 	u32 concrete_fid;
125 	u16 opaque_fid;
126 	u8 vport_id;
127 	u16 mtu;
128 	bool check_mac;
129 	bool check_ethtype;
130 };
131 
132 int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
133 			   struct qed_sp_vport_start_params *p_params);
134 
135 struct qed_rss_params {
136 	u8	update_rss_config;
137 	u8	rss_enable;
138 	u8	rss_eng_id;
139 	u8	update_rss_capabilities;
140 	u8	update_rss_ind_table;
141 	u8	update_rss_key;
142 	u8	rss_caps;
143 	u8	rss_table_size_log;
144 	u16	rss_ind_table[QED_RSS_IND_TABLE_SIZE];
145 	u32	rss_key[QED_RSS_KEY_SIZE];
146 };
147 
148 struct qed_filter_accept_flags {
149 	u8	update_rx_mode_config;
150 	u8	update_tx_mode_config;
151 	u8	rx_accept_filter;
152 	u8	tx_accept_filter;
153 #define QED_ACCEPT_NONE         0x01
154 #define QED_ACCEPT_UCAST_MATCHED        0x02
155 #define QED_ACCEPT_UCAST_UNMATCHED      0x04
156 #define QED_ACCEPT_MCAST_MATCHED        0x08
157 #define QED_ACCEPT_MCAST_UNMATCHED      0x10
158 #define QED_ACCEPT_BCAST                0x20
159 };
160 
161 struct qed_sp_vport_update_params {
162 	u16				opaque_fid;
163 	u8				vport_id;
164 	u8				update_vport_active_rx_flg;
165 	u8				vport_active_rx_flg;
166 	u8				update_vport_active_tx_flg;
167 	u8				vport_active_tx_flg;
168 	u8				update_inner_vlan_removal_flg;
169 	u8				inner_vlan_removal_flg;
170 	u8				silent_vlan_removal_flg;
171 	u8				update_default_vlan_enable_flg;
172 	u8				default_vlan_enable_flg;
173 	u8				update_default_vlan_flg;
174 	u16				default_vlan;
175 	u8				update_tx_switching_flg;
176 	u8				tx_switching_flg;
177 	u8				update_approx_mcast_flg;
178 	u8				update_anti_spoofing_en_flg;
179 	u8				anti_spoofing_en;
180 	u8				update_accept_any_vlan_flg;
181 	u8				accept_any_vlan;
182 	unsigned long			bins[8];
183 	struct qed_rss_params		*rss_params;
184 	struct qed_filter_accept_flags	accept_flags;
185 	struct qed_sge_tpa_params	*sge_tpa_params;
186 };
187 
188 int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
189 			struct qed_sp_vport_update_params *p_params,
190 			enum spq_mode comp_mode,
191 			struct qed_spq_comp_cb *p_comp_data);
192 
193 /**
194  * @brief qed_sp_vport_stop -
195  *
196  * This ramrod closes a VPort after all its RX and TX queues are terminated.
197  * An Assert is generated if any queues are left open.
198  *
199  * @param p_hwfn
200  * @param opaque_fid
201  * @param vport_id VPort ID
202  *
203  * @return int
204  */
205 int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id);
206 
207 int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
208 			    u16 opaque_fid,
209 			    struct qed_filter_ucast *p_filter_cmd,
210 			    enum spq_mode comp_mode,
211 			    struct qed_spq_comp_cb *p_comp_data);
212 
213 /**
214  * @brief qed_sp_rx_eth_queues_update -
215  *
216  * This ramrod updates an RX queue. It is used for setting the active state
217  * of the queue and updating the TPA and SGE parameters.
218  *
219  * @note At the moment - only used by non-linux VFs.
220  *
221  * @param p_hwfn
222  * @param pp_rxq_handlers	An array of queue handlers to be updated.
223  * @param num_rxqs              number of queues to update.
224  * @param complete_cqe_flg	Post completion to the CQE Ring if set
225  * @param complete_event_flg	Post completion to the Event Ring if set
226  * @param comp_mode
227  * @param p_comp_data
228  *
229  * @return int
230  */
231 
232 int
233 qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
234 			    void **pp_rxq_handlers,
235 			    u8 num_rxqs,
236 			    u8 complete_cqe_flg,
237 			    u8 complete_event_flg,
238 			    enum spq_mode comp_mode,
239 			    struct qed_spq_comp_cb *p_comp_data);
240 
241 void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats);
242 
243 void qed_reset_vport_stats(struct qed_dev *cdev);
244 
245 struct qed_queue_cid {
246 	/* 'Relative' is a relative term ;-). Usually the indices [not counting
247 	 * SBs] would be PF-relative, but there are some cases where that isn't
248 	 * the case - specifically for a PF configuring its VF indices it's
249 	 * possible some fields [E.g., stats-id] in 'rel' would already be abs.
250 	 */
251 	struct qed_queue_start_common_params rel;
252 	struct qed_queue_start_common_params abs;
253 	u32 cid;
254 	u16 opaque_fid;
255 
256 	/* VFs queues are mapped differently, so we need to know the
257 	 * relative queue associated with them [0-based].
258 	 * Notice this is relevant on the *PF* queue-cid of its VF's queues,
259 	 * and not on the VF itself.
260 	 */
261 	bool is_vf;
262 	u8 vf_qid;
263 
264 	/* Legacy VFs might have Rx producer located elsewhere */
265 	bool b_legacy_vf;
266 };
267 
268 void qed_eth_queue_cid_release(struct qed_hwfn *p_hwfn,
269 			       struct qed_queue_cid *p_cid);
270 
271 struct qed_queue_cid *_qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
272 					    u16 opaque_fid,
273 					    u32 cid,
274 					    u8 vf_qid,
275 					    struct qed_queue_start_common_params
276 					    *p_params);
277 
278 int
279 qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
280 		       struct qed_sp_vport_start_params *p_params);
281 
282 /**
283  * @brief - Starts an Rx queue, when queue_cid is already prepared
284  *
285  * @param p_hwfn
286  * @param p_cid
287  * @param bd_max_bytes
288  * @param bd_chain_phys_addr
289  * @param cqe_pbl_addr
290  * @param cqe_pbl_size
291  *
292  * @return int
293  */
294 int
295 qed_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
296 			 struct qed_queue_cid *p_cid,
297 			 u16 bd_max_bytes,
298 			 dma_addr_t bd_chain_phys_addr,
299 			 dma_addr_t cqe_pbl_addr, u16 cqe_pbl_size);
300 
301 /**
302  * @brief - Starts a Tx queue, where queue_cid is already prepared
303  *
304  * @param p_hwfn
305  * @param p_cid
306  * @param pbl_addr
307  * @param pbl_size
308  * @param p_pq_params - parameters for choosing the PQ for this Tx queue
309  *
310  * @return int
311  */
312 int
313 qed_eth_txq_start_ramrod(struct qed_hwfn *p_hwfn,
314 			 struct qed_queue_cid *p_cid,
315 			 dma_addr_t pbl_addr, u16 pbl_size, u16 pq_id);
316 
317 u8 qed_mcast_bin_from_mac(u8 *mac);
318 
319 #endif /* _QED_L2_H */
320