GNU Linux-libre 4.19.245-gnu1
[releases.git] / include / linux / qed / qed_eth_if.h
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
33 #ifndef _QED_ETH_IF_H
34 #define _QED_ETH_IF_H
35
36 #include <linux/list.h>
37 #include <linux/if_link.h>
38 #include <linux/qed/eth_common.h>
39 #include <linux/qed/qed_if.h>
40 #include <linux/qed/qed_iov_if.h>
41
42 /* 64 max queues * (1 rx + 4 tx-cos + 1 xdp) */
43 #define QED_MIN_L2_CONS (2 + NUM_PHYS_TCS_4PORT_K2)
44 #define QED_MAX_L2_CONS (64 * (QED_MIN_L2_CONS))
45
46 struct qed_queue_start_common_params {
47         /* Should always be relative to entity sending this. */
48         u8 vport_id;
49         u16 queue_id;
50
51         /* Relative, but relevant only for PFs */
52         u8 stats_id;
53
54         struct qed_sb_info *p_sb;
55         u8 sb_idx;
56
57         u8 tc;
58 };
59
60 struct qed_rxq_start_ret_params {
61         void __iomem *p_prod;
62         void *p_handle;
63 };
64
65 struct qed_txq_start_ret_params {
66         void __iomem *p_doorbell;
67         void *p_handle;
68 };
69
70 enum qed_filter_config_mode {
71         QED_FILTER_CONFIG_MODE_DISABLE,
72         QED_FILTER_CONFIG_MODE_5_TUPLE,
73         QED_FILTER_CONFIG_MODE_L4_PORT,
74         QED_FILTER_CONFIG_MODE_IP_DEST,
75         QED_FILTER_CONFIG_MODE_IP_SRC,
76 };
77
78 struct qed_ntuple_filter_params {
79         /* Physically mapped address containing header of buffer to be used
80          * as filter.
81          */
82         dma_addr_t addr;
83
84         /* Length of header in bytes */
85         u16 length;
86
87         /* Relative queue-id to receive classified packet */
88 #define QED_RFS_NTUPLE_QID_RSS ((u16)-1)
89         u16 qid;
90
91         /* Identifier can either be according to vport-id or vfid */
92         bool b_is_vf;
93         u8 vport_id;
94         u8 vf_id;
95
96         /* true iff this filter is to be added. Else to be removed */
97         bool b_is_add;
98
99         /* If flow needs to be dropped */
100         bool b_is_drop;
101 };
102
103 struct qed_dev_eth_info {
104         struct qed_dev_info common;
105
106         u8      num_queues;
107         u8      num_tc;
108
109         u8      port_mac[ETH_ALEN];
110         u16     num_vlan_filters;
111         u16     num_mac_filters;
112
113         /* Legacy VF - this affects the datapath, so qede has to know */
114         bool is_legacy;
115
116         /* Might depend on available resources [in case of VF] */
117         bool xdp_supported;
118 };
119
120 struct qed_update_vport_rss_params {
121         void    *rss_ind_table[128];
122         u32     rss_key[10];
123         u8      rss_caps;
124 };
125
126 struct qed_update_vport_params {
127         u8 vport_id;
128         u8 update_vport_active_flg;
129         u8 vport_active_flg;
130         u8 update_tx_switching_flg;
131         u8 tx_switching_flg;
132         u8 update_accept_any_vlan_flg;
133         u8 accept_any_vlan;
134         u8 update_rss_flg;
135         struct qed_update_vport_rss_params rss_params;
136 };
137
138 struct qed_start_vport_params {
139         bool remove_inner_vlan;
140         bool handle_ptp_pkts;
141         bool gro_enable;
142         bool drop_ttl0;
143         u8 vport_id;
144         u16 mtu;
145         bool clear_stats;
146 };
147
148 enum qed_filter_rx_mode_type {
149         QED_FILTER_RX_MODE_TYPE_REGULAR,
150         QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC,
151         QED_FILTER_RX_MODE_TYPE_PROMISC,
152 };
153
154 enum qed_filter_xcast_params_type {
155         QED_FILTER_XCAST_TYPE_ADD,
156         QED_FILTER_XCAST_TYPE_DEL,
157         QED_FILTER_XCAST_TYPE_REPLACE,
158 };
159
160 struct qed_filter_ucast_params {
161         enum qed_filter_xcast_params_type type;
162         u8 vlan_valid;
163         u16 vlan;
164         u8 mac_valid;
165         unsigned char mac[ETH_ALEN];
166 };
167
168 struct qed_filter_mcast_params {
169         enum qed_filter_xcast_params_type type;
170         u8 num;
171         unsigned char mac[64][ETH_ALEN];
172 };
173
174 union qed_filter_type_params {
175         enum qed_filter_rx_mode_type accept_flags;
176         struct qed_filter_ucast_params ucast;
177         struct qed_filter_mcast_params mcast;
178 };
179
180 enum qed_filter_type {
181         QED_FILTER_TYPE_UCAST,
182         QED_FILTER_TYPE_MCAST,
183         QED_FILTER_TYPE_RX_MODE,
184         QED_MAX_FILTER_TYPES,
185 };
186
187 struct qed_filter_params {
188         enum qed_filter_type type;
189         union qed_filter_type_params filter;
190 };
191
192 struct qed_tunn_params {
193         u16 vxlan_port;
194         u8 update_vxlan_port;
195         u16 geneve_port;
196         u8 update_geneve_port;
197 };
198
199 struct qed_eth_cb_ops {
200         struct qed_common_cb_ops common;
201         void (*force_mac) (void *dev, u8 *mac, bool forced);
202         void (*ports_update)(void *dev, u16 vxlan_port, u16 geneve_port);
203 };
204
205 #define QED_MAX_PHC_DRIFT_PPB   291666666
206
207 enum qed_ptp_filter_type {
208         QED_PTP_FILTER_NONE,
209         QED_PTP_FILTER_ALL,
210         QED_PTP_FILTER_V1_L4_EVENT,
211         QED_PTP_FILTER_V1_L4_GEN,
212         QED_PTP_FILTER_V2_L4_EVENT,
213         QED_PTP_FILTER_V2_L4_GEN,
214         QED_PTP_FILTER_V2_L2_EVENT,
215         QED_PTP_FILTER_V2_L2_GEN,
216         QED_PTP_FILTER_V2_EVENT,
217         QED_PTP_FILTER_V2_GEN
218 };
219
220 enum qed_ptp_hwtstamp_tx_type {
221         QED_PTP_HWTSTAMP_TX_OFF,
222         QED_PTP_HWTSTAMP_TX_ON,
223 };
224
225 #ifdef CONFIG_DCB
226 /* Prototype declaration of qed_eth_dcbnl_ops should match with the declaration
227  * of dcbnl_rtnl_ops structure.
228  */
229 struct qed_eth_dcbnl_ops {
230         /* IEEE 802.1Qaz std */
231         int (*ieee_getpfc)(struct qed_dev *cdev, struct ieee_pfc *pfc);
232         int (*ieee_setpfc)(struct qed_dev *cdev, struct ieee_pfc *pfc);
233         int (*ieee_getets)(struct qed_dev *cdev, struct ieee_ets *ets);
234         int (*ieee_setets)(struct qed_dev *cdev, struct ieee_ets *ets);
235         int (*ieee_peer_getets)(struct qed_dev *cdev, struct ieee_ets *ets);
236         int (*ieee_peer_getpfc)(struct qed_dev *cdev, struct ieee_pfc *pfc);
237         int (*ieee_getapp)(struct qed_dev *cdev, struct dcb_app *app);
238         int (*ieee_setapp)(struct qed_dev *cdev, struct dcb_app *app);
239
240         /* CEE std */
241         u8 (*getstate)(struct qed_dev *cdev);
242         u8 (*setstate)(struct qed_dev *cdev, u8 state);
243         void (*getpgtccfgtx)(struct qed_dev *cdev, int prio, u8 *prio_type,
244                              u8 *pgid, u8 *bw_pct, u8 *up_map);
245         void (*getpgbwgcfgtx)(struct qed_dev *cdev, int pgid, u8 *bw_pct);
246         void (*getpgtccfgrx)(struct qed_dev *cdev, int prio, u8 *prio_type,
247                              u8 *pgid, u8 *bw_pct, u8 *up_map);
248         void (*getpgbwgcfgrx)(struct qed_dev *cdev, int pgid, u8 *bw_pct);
249         void (*getpfccfg)(struct qed_dev *cdev, int prio, u8 *setting);
250         void (*setpfccfg)(struct qed_dev *cdev, int prio, u8 setting);
251         u8 (*getcap)(struct qed_dev *cdev, int capid, u8 *cap);
252         int (*getnumtcs)(struct qed_dev *cdev, int tcid, u8 *num);
253         u8 (*getpfcstate)(struct qed_dev *cdev);
254         int (*getapp)(struct qed_dev *cdev, u8 idtype, u16 id);
255         u8 (*getfeatcfg)(struct qed_dev *cdev, int featid, u8 *flags);
256
257         /* DCBX configuration */
258         u8 (*getdcbx)(struct qed_dev *cdev);
259         void (*setpgtccfgtx)(struct qed_dev *cdev, int prio,
260                              u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map);
261         void (*setpgtccfgrx)(struct qed_dev *cdev, int prio,
262                              u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map);
263         void (*setpgbwgcfgtx)(struct qed_dev *cdev, int pgid, u8 bw_pct);
264         void (*setpgbwgcfgrx)(struct qed_dev *cdev, int pgid, u8 bw_pct);
265         u8 (*setall)(struct qed_dev *cdev);
266         int (*setnumtcs)(struct qed_dev *cdev, int tcid, u8 num);
267         void (*setpfcstate)(struct qed_dev *cdev, u8 state);
268         int (*setapp)(struct qed_dev *cdev, u8 idtype, u16 idval, u8 up);
269         u8 (*setdcbx)(struct qed_dev *cdev, u8 state);
270         u8 (*setfeatcfg)(struct qed_dev *cdev, int featid, u8 flags);
271
272         /* Peer apps */
273         int (*peer_getappinfo)(struct qed_dev *cdev,
274                                struct dcb_peer_app_info *info,
275                                u16 *app_count);
276         int (*peer_getapptable)(struct qed_dev *cdev, struct dcb_app *table);
277
278         /* CEE peer */
279         int (*cee_peer_getpfc)(struct qed_dev *cdev, struct cee_pfc *pfc);
280         int (*cee_peer_getpg)(struct qed_dev *cdev, struct cee_pg *pg);
281 };
282 #endif
283
284 struct qed_eth_ptp_ops {
285         int (*cfg_filters)(struct qed_dev *, enum qed_ptp_filter_type,
286                            enum qed_ptp_hwtstamp_tx_type);
287         int (*read_rx_ts)(struct qed_dev *, u64 *);
288         int (*read_tx_ts)(struct qed_dev *, u64 *);
289         int (*read_cc)(struct qed_dev *, u64 *);
290         int (*disable)(struct qed_dev *);
291         int (*adjfreq)(struct qed_dev *, s32);
292         int (*enable)(struct qed_dev *);
293 };
294
295 struct qed_eth_ops {
296         const struct qed_common_ops *common;
297 #ifdef CONFIG_QED_SRIOV
298         const struct qed_iov_hv_ops *iov;
299 #endif
300 #ifdef CONFIG_DCB
301         const struct qed_eth_dcbnl_ops *dcb;
302 #endif
303         const struct qed_eth_ptp_ops *ptp;
304
305         int (*fill_dev_info)(struct qed_dev *cdev,
306                              struct qed_dev_eth_info *info);
307
308         void (*register_ops)(struct qed_dev *cdev,
309                              struct qed_eth_cb_ops *ops,
310                              void *cookie);
311
312          bool(*check_mac) (struct qed_dev *cdev, u8 *mac);
313
314         int (*vport_start)(struct qed_dev *cdev,
315                            struct qed_start_vport_params *params);
316
317         int (*vport_stop)(struct qed_dev *cdev,
318                           u8 vport_id);
319
320         int (*vport_update)(struct qed_dev *cdev,
321                             struct qed_update_vport_params *params);
322
323         int (*q_rx_start)(struct qed_dev *cdev,
324                           u8 rss_num,
325                           struct qed_queue_start_common_params *params,
326                           u16 bd_max_bytes,
327                           dma_addr_t bd_chain_phys_addr,
328                           dma_addr_t cqe_pbl_addr,
329                           u16 cqe_pbl_size,
330                           struct qed_rxq_start_ret_params *ret_params);
331
332         int (*q_rx_stop)(struct qed_dev *cdev, u8 rss_id, void *handle);
333
334         int (*q_tx_start)(struct qed_dev *cdev,
335                           u8 rss_num,
336                           struct qed_queue_start_common_params *params,
337                           dma_addr_t pbl_addr,
338                           u16 pbl_size,
339                           struct qed_txq_start_ret_params *ret_params);
340
341         int (*q_tx_stop)(struct qed_dev *cdev, u8 rss_id, void *handle);
342
343         int (*filter_config)(struct qed_dev *cdev,
344                              struct qed_filter_params *params);
345
346         int (*fastpath_stop)(struct qed_dev *cdev);
347
348         int (*eth_cqe_completion)(struct qed_dev *cdev,
349                                   u8 rss_id,
350                                   struct eth_slow_path_rx_cqe *cqe);
351
352         void (*get_vport_stats)(struct qed_dev *cdev,
353                                 struct qed_eth_stats *stats);
354
355         int (*tunn_config)(struct qed_dev *cdev,
356                            struct qed_tunn_params *params);
357
358         int (*ntuple_filter_config)(struct qed_dev *cdev,
359                                     void *cookie,
360                                     struct qed_ntuple_filter_params *params);
361
362         int (*configure_arfs_searcher)(struct qed_dev *cdev,
363                                        enum qed_filter_config_mode mode);
364         int (*get_coalesce)(struct qed_dev *cdev, u16 *coal, void *handle);
365         int (*req_bulletin_update_mac)(struct qed_dev *cdev, u8 *mac);
366 };
367
368 const struct qed_eth_ops *qed_get_eth_ops(void);
369 void qed_put_eth_ops(void);
370
371 #endif