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