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.
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/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/qed/qed_if.h>
19 enum qed_ll2_conn_type {
24 QED_LL2_TYPE_RESERVED2,
27 QED_LL2_TYPE_RESERVED3,
31 enum qed_ll2_rx_conn_type {
32 QED_LL2_RX_TYPE_LEGACY,
34 MAX_QED_LL2_RX_CONN_TYPE
37 enum qed_ll2_roce_flavor_type {
40 MAX_QED_LL2_ROCE_FLAVOR_TYPE
43 enum qed_ll2_tx_dest {
44 QED_LL2_TX_DEST_NW, /* Light L2 TX Destination to the Network */
45 QED_LL2_TX_DEST_LB, /* Light L2 TX Destination to the Loopback */
46 QED_LL2_TX_DEST_DROP, /* Light L2 Drop the TX packet */
50 enum qed_ll2_error_handle {
56 struct qed_ll2_stats {
58 u64 gsi_invalid_pkt_length;
59 u64 gsi_unsupported_pkt_typ;
60 u64 gsi_crcchksm_error;
62 u64 packet_too_big_discard;
80 struct qed_ll2_comp_rx_data {
82 dma_addr_t rx_buf_addr;
103 u8 data_length_error;
108 void (*qed_ll2_complete_rx_packet_cb)(void *cxt,
109 struct qed_ll2_comp_rx_data *data);
112 void (*qed_ll2_release_rx_packet_cb)(void *cxt,
113 u8 connection_handle,
115 dma_addr_t rx_buf_addr,
119 void (*qed_ll2_complete_tx_packet_cb)(void *cxt,
120 u8 connection_handle,
122 dma_addr_t first_frag_addr,
123 bool b_last_fragment,
127 void (*qed_ll2_release_tx_packet_cb)(void *cxt,
128 u8 connection_handle,
130 dma_addr_t first_frag_addr,
131 bool b_last_fragment, bool b_last_packet);
134 void (*qed_ll2_slowpath_cb)(void *cxt, u8 connection_handle,
135 u32 opaque_data_0, u32 opaque_data_1);
138 qed_ll2_complete_rx_packet_cb rx_comp_cb;
139 qed_ll2_release_rx_packet_cb rx_release_cb;
140 qed_ll2_complete_tx_packet_cb tx_comp_cb;
141 qed_ll2_release_tx_packet_cb tx_release_cb;
142 qed_ll2_slowpath_cb slowpath_cb;
146 struct qed_ll2_acquire_data_inputs {
147 enum qed_ll2_rx_conn_type rx_conn_type;
148 enum qed_ll2_conn_type conn_type;
151 u16 rx_num_ooo_buffers;
153 u8 rx_vlan_removal_en;
155 u8 tx_max_bds_per_packet;
157 enum qed_ll2_tx_dest tx_dest;
158 enum qed_ll2_error_handle ai_err_packet_too_big;
159 enum qed_ll2_error_handle ai_err_no_buf;
160 bool secondary_queue;
164 struct qed_ll2_acquire_data {
165 struct qed_ll2_acquire_data_inputs input;
166 const struct qed_ll2_cbs *cbs;
168 /* Output container for LL2 connection's handle */
169 u8 *p_connection_handle;
172 struct qed_ll2_tx_pkt_info {
174 dma_addr_t first_frag;
175 enum qed_ll2_tx_dest tx_dest;
176 enum qed_ll2_roce_flavor_type qed_roce_flavor;
178 u16 l4_hdr_offset_w; /* from start of packet */
182 bool enable_ip_cksum;
183 bool enable_l4_cksum;
188 #define QED_LL2_UNUSED_HANDLE (0xff)
190 struct qed_ll2_cb_ops {
191 int (*rx_cb)(void *, struct sk_buff *, u32, u32);
192 int (*tx_cb)(void *, struct sk_buff *, bool);
195 struct qed_ll2_params {
197 bool drop_ttl0_packets;
198 bool rx_vlan_stripping;
201 u8 ll2_mac_address[ETH_ALEN];
204 enum qed_ll2_xmit_flags {
205 /* FIP discovery packet */
206 QED_LL2_XMIT_FLAGS_FIP_DISCOVERY
211 * @brief start - initializes ll2
214 * @param params - protocol driver configuration for the ll2.
216 * @return 0 on success, otherwise error value.
218 int (*start)(struct qed_dev *cdev, struct qed_ll2_params *params);
221 * @brief stop - stops the ll2
225 * @return 0 on success, otherwise error value.
227 int (*stop)(struct qed_dev *cdev);
230 * @brief start_xmit - transmits an skb over the ll2 interface
234 * @param xmit_flags - Transmit options defined by the enum qed_ll2_xmit_flags.
236 * @return 0 on success, otherwise error value.
238 int (*start_xmit)(struct qed_dev *cdev, struct sk_buff *skb,
239 unsigned long xmit_flags);
242 * @brief register_cb_ops - protocol driver register the callback for Rx/Tx
243 * packets. Should be called before `start'.
246 * @param cookie - to be passed to the callback functions.
247 * @param ops - the callback functions to register for Rx / Tx.
249 * @return 0 on success, otherwise error value.
251 void (*register_cb_ops)(struct qed_dev *cdev,
252 const struct qed_ll2_cb_ops *ops,
256 * @brief get LL2 related statistics
259 * @param stats - pointer to struct that would be filled with stats
261 * @return 0 on success, error otherwise.
263 int (*get_stats)(struct qed_dev *cdev, struct qed_ll2_stats *stats);
266 #ifdef CONFIG_QED_LL2
267 int qed_ll2_alloc_if(struct qed_dev *);
268 void qed_ll2_dealloc_if(struct qed_dev *);
270 static const struct qed_ll2_ops qed_ll2_ops_pass = {
274 .register_cb_ops = NULL,
278 static inline int qed_ll2_alloc_if(struct qed_dev *cdev)
283 static inline void qed_ll2_dealloc_if(struct qed_dev *cdev)