lib: stackdepot: add support to disable stack depot
[linux-2.6-microblaze.git] / include / linux / qed / qed_ll2_if.h
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_LL2_IF_H
8 #define _QED_LL2_IF_H
9
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/netdevice.h>
13 #include <linux/pci.h>
14 #include <linux/skbuff.h>
15 #include <linux/version.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/qed/qed_if.h>
19
20 enum qed_ll2_conn_type {
21         QED_LL2_TYPE_FCOE,
22         QED_LL2_TYPE_ISCSI,
23         QED_LL2_TYPE_TEST,
24         QED_LL2_TYPE_OOO,
25         QED_LL2_TYPE_RESERVED2,
26         QED_LL2_TYPE_ROCE,
27         QED_LL2_TYPE_IWARP,
28         QED_LL2_TYPE_RESERVED3,
29         MAX_QED_LL2_CONN_TYPE
30 };
31
32 enum qed_ll2_rx_conn_type {
33         QED_LL2_RX_TYPE_LEGACY,
34         QED_LL2_RX_TYPE_CTX,
35         MAX_QED_LL2_RX_CONN_TYPE
36 };
37
38 enum qed_ll2_roce_flavor_type {
39         QED_LL2_ROCE,
40         QED_LL2_RROCE,
41         MAX_QED_LL2_ROCE_FLAVOR_TYPE
42 };
43
44 enum qed_ll2_tx_dest {
45         QED_LL2_TX_DEST_NW, /* Light L2 TX Destination to the Network */
46         QED_LL2_TX_DEST_LB, /* Light L2 TX Destination to the Loopback */
47         QED_LL2_TX_DEST_DROP, /* Light L2 Drop the TX packet */
48         QED_LL2_TX_DEST_MAX
49 };
50
51 enum qed_ll2_error_handle {
52         QED_LL2_DROP_PACKET,
53         QED_LL2_DO_NOTHING,
54         QED_LL2_ASSERT,
55 };
56
57 struct qed_ll2_stats {
58         u64 gsi_invalid_hdr;
59         u64 gsi_invalid_pkt_length;
60         u64 gsi_unsupported_pkt_typ;
61         u64 gsi_crcchksm_error;
62
63         u64 packet_too_big_discard;
64         u64 no_buff_discard;
65
66         u64 rcv_ucast_bytes;
67         u64 rcv_mcast_bytes;
68         u64 rcv_bcast_bytes;
69         u64 rcv_ucast_pkts;
70         u64 rcv_mcast_pkts;
71         u64 rcv_bcast_pkts;
72
73         u64 sent_ucast_bytes;
74         u64 sent_mcast_bytes;
75         u64 sent_bcast_bytes;
76         u64 sent_ucast_pkts;
77         u64 sent_mcast_pkts;
78         u64 sent_bcast_pkts;
79 };
80
81 struct qed_ll2_comp_rx_data {
82         void *cookie;
83         dma_addr_t rx_buf_addr;
84         u16 parse_flags;
85         u16 err_flags;
86         u16 vlan;
87         bool b_last_packet;
88         u8 connection_handle;
89
90         union {
91                 u16 packet_length;
92                 u16 data_length;
93         } length;
94
95         u32 opaque_data_0;
96         u32 opaque_data_1;
97
98         /* GSI only */
99         u32 src_qp;
100         u16 qp_id;
101
102         union {
103                 u8 placement_offset;
104                 u8 data_length_error;
105         } u;
106 };
107
108 typedef
109 void (*qed_ll2_complete_rx_packet_cb)(void *cxt,
110                                       struct qed_ll2_comp_rx_data *data);
111
112 typedef
113 void (*qed_ll2_release_rx_packet_cb)(void *cxt,
114                                      u8 connection_handle,
115                                      void *cookie,
116                                      dma_addr_t rx_buf_addr,
117                                      bool b_last_packet);
118
119 typedef
120 void (*qed_ll2_complete_tx_packet_cb)(void *cxt,
121                                       u8 connection_handle,
122                                       void *cookie,
123                                       dma_addr_t first_frag_addr,
124                                       bool b_last_fragment,
125                                       bool b_last_packet);
126
127 typedef
128 void (*qed_ll2_release_tx_packet_cb)(void *cxt,
129                                      u8 connection_handle,
130                                      void *cookie,
131                                      dma_addr_t first_frag_addr,
132                                      bool b_last_fragment, bool b_last_packet);
133
134 typedef
135 void (*qed_ll2_slowpath_cb)(void *cxt, u8 connection_handle,
136                             u32 opaque_data_0, u32 opaque_data_1);
137
138 struct qed_ll2_cbs {
139         qed_ll2_complete_rx_packet_cb rx_comp_cb;
140         qed_ll2_release_rx_packet_cb rx_release_cb;
141         qed_ll2_complete_tx_packet_cb tx_comp_cb;
142         qed_ll2_release_tx_packet_cb tx_release_cb;
143         qed_ll2_slowpath_cb slowpath_cb;
144         void *cookie;
145 };
146
147 struct qed_ll2_acquire_data_inputs {
148         enum qed_ll2_rx_conn_type rx_conn_type;
149         enum qed_ll2_conn_type conn_type;
150         u16 mtu;
151         u16 rx_num_desc;
152         u16 rx_num_ooo_buffers;
153         u8 rx_drop_ttl0_flg;
154         u8 rx_vlan_removal_en;
155         u16 tx_num_desc;
156         u8 tx_max_bds_per_packet;
157         u8 tx_tc;
158         enum qed_ll2_tx_dest tx_dest;
159         enum qed_ll2_error_handle ai_err_packet_too_big;
160         enum qed_ll2_error_handle ai_err_no_buf;
161         bool secondary_queue;
162         u8 gsi_enable;
163 };
164
165 struct qed_ll2_acquire_data {
166         struct qed_ll2_acquire_data_inputs input;
167         const struct qed_ll2_cbs *cbs;
168
169         /* Output container for LL2 connection's handle */
170         u8 *p_connection_handle;
171 };
172
173 struct qed_ll2_tx_pkt_info {
174         void *cookie;
175         dma_addr_t first_frag;
176         enum qed_ll2_tx_dest tx_dest;
177         enum qed_ll2_roce_flavor_type qed_roce_flavor;
178         u16 vlan;
179         u16 l4_hdr_offset_w;    /* from start of packet */
180         u16 first_frag_len;
181         u8 num_of_bds;
182         u8 bd_flags;
183         bool enable_ip_cksum;
184         bool enable_l4_cksum;
185         bool calc_ip_len;
186         bool remove_stag;
187 };
188
189 #define QED_LL2_UNUSED_HANDLE   (0xff)
190
191 struct qed_ll2_cb_ops {
192         int (*rx_cb)(void *, struct sk_buff *, u32, u32);
193         int (*tx_cb)(void *, struct sk_buff *, bool);
194 };
195
196 struct qed_ll2_params {
197         u16 mtu;
198         bool drop_ttl0_packets;
199         bool rx_vlan_stripping;
200         u8 tx_tc;
201         bool frags_mapped;
202         u8 ll2_mac_address[ETH_ALEN];
203 };
204
205 enum qed_ll2_xmit_flags {
206         /* FIP discovery packet */
207         QED_LL2_XMIT_FLAGS_FIP_DISCOVERY
208 };
209
210 struct qed_ll2_ops {
211 /**
212  * @brief start - initializes ll2
213  *
214  * @param cdev
215  * @param params - protocol driver configuration for the ll2.
216  *
217  * @return 0 on success, otherwise error value.
218  */
219         int (*start)(struct qed_dev *cdev, struct qed_ll2_params *params);
220
221 /**
222  * @brief stop - stops the ll2
223  *
224  * @param cdev
225  *
226  * @return 0 on success, otherwise error value.
227  */
228         int (*stop)(struct qed_dev *cdev);
229
230 /**
231  * @brief start_xmit - transmits an skb over the ll2 interface
232  *
233  * @param cdev
234  * @param skb
235  * @param xmit_flags - Transmit options defined by the enum qed_ll2_xmit_flags.
236  *
237  * @return 0 on success, otherwise error value.
238  */
239         int (*start_xmit)(struct qed_dev *cdev, struct sk_buff *skb,
240                           unsigned long xmit_flags);
241
242 /**
243  * @brief register_cb_ops - protocol driver register the callback for Rx/Tx
244  * packets. Should be called before `start'.
245  *
246  * @param cdev
247  * @param cookie - to be passed to the callback functions.
248  * @param ops - the callback functions to register for Rx / Tx.
249  *
250  * @return 0 on success, otherwise error value.
251  */
252         void (*register_cb_ops)(struct qed_dev *cdev,
253                                 const struct qed_ll2_cb_ops *ops,
254                                 void *cookie);
255
256 /**
257  * @brief get LL2 related statistics
258  *
259  * @param cdev
260  * @param stats - pointer to struct that would be filled with stats
261  *
262  * @return 0 on success, error otherwise.
263  */
264         int (*get_stats)(struct qed_dev *cdev, struct qed_ll2_stats *stats);
265 };
266
267 #ifdef CONFIG_QED_LL2
268 int qed_ll2_alloc_if(struct qed_dev *);
269 void qed_ll2_dealloc_if(struct qed_dev *);
270 #else
271 static const struct qed_ll2_ops qed_ll2_ops_pass = {
272         .start = NULL,
273         .stop = NULL,
274         .start_xmit = NULL,
275         .register_cb_ops = NULL,
276         .get_stats = NULL,
277 };
278
279 static inline int qed_ll2_alloc_if(struct qed_dev *cdev)
280 {
281         return 0;
282 }
283
284 static inline void qed_ll2_dealloc_if(struct qed_dev *cdev)
285 {
286 }
287 #endif
288 #endif