1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
36 #include <linux/types.h>
37 #include <linux/interrupt.h>
38 #include <linux/netdevice.h>
39 #include <linux/pci.h>
40 #include <linux/skbuff.h>
41 #include <linux/version.h>
42 #include <linux/kernel.h>
43 #include <linux/slab.h>
44 #include <linux/qed/qed_if.h>
46 enum qed_ll2_conn_type
{
51 QED_LL2_TYPE_RESERVED2
,
54 QED_LL2_TYPE_RESERVED3
,
55 MAX_QED_LL2_RX_CONN_TYPE
58 enum qed_ll2_roce_flavor_type
{
61 MAX_QED_LL2_ROCE_FLAVOR_TYPE
64 enum qed_ll2_tx_dest
{
65 QED_LL2_TX_DEST_NW
, /* Light L2 TX Destination to the Network */
66 QED_LL2_TX_DEST_LB
, /* Light L2 TX Destination to the Loopback */
67 QED_LL2_TX_DEST_DROP
, /* Light L2 Drop the TX packet */
71 enum qed_ll2_error_handle
{
77 struct qed_ll2_stats
{
79 u64 gsi_invalid_pkt_length
;
80 u64 gsi_unsupported_pkt_typ
;
81 u64 gsi_crcchksm_error
;
83 u64 packet_too_big_discard
;
101 struct qed_ll2_comp_rx_data
{
103 dma_addr_t rx_buf_addr
;
108 u8 connection_handle
;
124 u8 data_length_error
;
129 void (*qed_ll2_complete_rx_packet_cb
)(void *cxt
,
130 struct qed_ll2_comp_rx_data
*data
);
133 void (*qed_ll2_release_rx_packet_cb
)(void *cxt
,
134 u8 connection_handle
,
136 dma_addr_t rx_buf_addr
,
140 void (*qed_ll2_complete_tx_packet_cb
)(void *cxt
,
141 u8 connection_handle
,
143 dma_addr_t first_frag_addr
,
144 bool b_last_fragment
,
148 void (*qed_ll2_release_tx_packet_cb
)(void *cxt
,
149 u8 connection_handle
,
151 dma_addr_t first_frag_addr
,
152 bool b_last_fragment
, bool b_last_packet
);
155 void (*qed_ll2_slowpath_cb
)(void *cxt
, u8 connection_handle
,
156 u32 opaque_data_0
, u32 opaque_data_1
);
159 qed_ll2_complete_rx_packet_cb rx_comp_cb
;
160 qed_ll2_release_rx_packet_cb rx_release_cb
;
161 qed_ll2_complete_tx_packet_cb tx_comp_cb
;
162 qed_ll2_release_tx_packet_cb tx_release_cb
;
163 qed_ll2_slowpath_cb slowpath_cb
;
167 struct qed_ll2_acquire_data_inputs
{
168 enum qed_ll2_conn_type conn_type
;
171 u16 rx_num_ooo_buffers
;
173 u8 rx_vlan_removal_en
;
175 u8 tx_max_bds_per_packet
;
177 enum qed_ll2_tx_dest tx_dest
;
178 enum qed_ll2_error_handle ai_err_packet_too_big
;
179 enum qed_ll2_error_handle ai_err_no_buf
;
180 bool secondary_queue
;
184 struct qed_ll2_acquire_data
{
185 struct qed_ll2_acquire_data_inputs input
;
186 const struct qed_ll2_cbs
*cbs
;
188 /* Output container for LL2 connection's handle */
189 u8
*p_connection_handle
;
192 struct qed_ll2_tx_pkt_info
{
194 dma_addr_t first_frag
;
195 enum qed_ll2_tx_dest tx_dest
;
196 enum qed_ll2_roce_flavor_type qed_roce_flavor
;
198 u16 l4_hdr_offset_w
; /* from start of packet */
202 bool enable_ip_cksum
;
203 bool enable_l4_cksum
;
207 #define QED_LL2_UNUSED_HANDLE (0xff)
209 struct qed_ll2_cb_ops
{
210 int (*rx_cb
)(void *, struct sk_buff
*, u32
, u32
);
211 int (*tx_cb
)(void *, struct sk_buff
*, bool);
214 struct qed_ll2_params
{
216 bool drop_ttl0_packets
;
217 bool rx_vlan_stripping
;
220 u8 ll2_mac_address
[ETH_ALEN
];
225 * @brief start - initializes ll2
228 * @param params - protocol driver configuration for the ll2.
230 * @return 0 on success, otherwise error value.
232 int (*start
)(struct qed_dev
*cdev
, struct qed_ll2_params
*params
);
235 * @brief stop - stops the ll2
239 * @return 0 on success, otherwise error value.
241 int (*stop
)(struct qed_dev
*cdev
);
244 * @brief start_xmit - transmits an skb over the ll2 interface
249 * @return 0 on success, otherwise error value.
251 int (*start_xmit
)(struct qed_dev
*cdev
, struct sk_buff
*skb
);
254 * @brief register_cb_ops - protocol driver register the callback for Rx/Tx
255 * packets. Should be called before `start'.
258 * @param cookie - to be passed to the callback functions.
259 * @param ops - the callback functions to register for Rx / Tx.
261 * @return 0 on success, otherwise error value.
263 void (*register_cb_ops
)(struct qed_dev
*cdev
,
264 const struct qed_ll2_cb_ops
*ops
,
268 * @brief get LL2 related statistics
271 * @param stats - pointer to struct that would be filled with stats
273 * @return 0 on success, error otherwise.
275 int (*get_stats
)(struct qed_dev
*cdev
, struct qed_ll2_stats
*stats
);
278 #ifdef CONFIG_QED_LL2
279 int qed_ll2_alloc_if(struct qed_dev
*);
280 void qed_ll2_dealloc_if(struct qed_dev
*);
282 static const struct qed_ll2_ops qed_ll2_ops_pass
= {
286 .register_cb_ops
= NULL
,
290 static inline int qed_ll2_alloc_if(struct qed_dev
*cdev
)
295 static inline void qed_ll2_dealloc_if(struct qed_dev
*cdev
)