Loading...
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_H
8#define _QED_LL2_H
9
10#include <linux/types.h>
11#include <linux/kernel.h>
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/slab.h>
15#include <linux/spinlock.h>
16#include <linux/qed/qed_chain.h>
17#include <linux/qed/qed_ll2_if.h>
18#include "qed.h"
19#include "qed_hsi.h"
20#include "qed_sp.h"
21
22#define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
23/* LL2 queues handles will be split as follows:
24 * first will be legacy queues, and then the ctx based queues.
25 */
26#define QED_MAX_NUM_OF_LL2_CONNS_PF (4)
27#define QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF (3)
28
29#define QED_MAX_NUM_OF_CTX_LL2_CONNS_PF \
30 (QED_MAX_NUM_OF_LL2_CONNS_PF - QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF)
31
32#define QED_LL2_LEGACY_CONN_BASE_PF 0
33#define QED_LL2_CTX_CONN_BASE_PF QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF
34
35struct qed_ll2_rx_packet {
36 struct list_head list_entry;
37 struct core_rx_bd_with_buff_len *rxq_bd;
38 dma_addr_t rx_buf_addr;
39 u16 buf_length;
40 void *cookie;
41 u8 placement_offset;
42 u16 parse_flags;
43 u16 packet_length;
44 u16 vlan;
45 u32 opaque_data[2];
46};
47
48struct qed_ll2_tx_packet {
49 struct list_head list_entry;
50 u16 bd_used;
51 bool notify_fw;
52 void *cookie;
53 /* Flexible Array of bds_set determined by max_bds_per_packet */
54 struct {
55 struct core_tx_bd *txq_bd;
56 dma_addr_t tx_frag;
57 u16 frag_len;
58 } bds_set[];
59};
60
61struct qed_ll2_rx_queue {
62 /* Lock protecting the Rx queue manipulation */
63 spinlock_t lock;
64 struct qed_chain rxq_chain;
65 struct qed_chain rcq_chain;
66 u8 rx_sb_index;
67 u8 ctx_based;
68 bool b_cb_registered;
69 __le16 *p_fw_cons;
70 struct list_head active_descq;
71 struct list_head free_descq;
72 struct list_head posting_descq;
73 struct qed_ll2_rx_packet *descq_array;
74 void __iomem *set_prod_addr;
75 struct core_pwm_prod_update_data db_data;
76};
77
78struct qed_ll2_tx_queue {
79 /* Lock protecting the Tx queue manipulation */
80 spinlock_t lock;
81 struct qed_chain txq_chain;
82 u8 tx_sb_index;
83 bool b_cb_registered;
84 __le16 *p_fw_cons;
85 struct list_head active_descq;
86 struct list_head free_descq;
87 struct list_head sending_descq;
88 u16 cur_completing_bd_idx;
89 void __iomem *doorbell_addr;
90 struct core_db_data db_msg;
91 u16 bds_idx;
92 u16 cur_send_frag_num;
93 u16 cur_completing_frag_num;
94 bool b_completing_packet;
95 void *descq_mem; /* memory for variable sized qed_ll2_tx_packet*/
96 struct qed_ll2_tx_packet *cur_send_packet;
97 struct qed_ll2_tx_packet cur_completing_packet;
98};
99
100struct qed_ll2_info {
101 /* Lock protecting the state of LL2 */
102 struct mutex mutex;
103
104 struct qed_ll2_acquire_data_inputs input;
105 u32 cid;
106 u8 my_id;
107 u8 queue_id;
108 u8 tx_stats_id;
109 bool b_active;
110 enum core_tx_dest tx_dest;
111 u8 tx_stats_en;
112 bool main_func_queue;
113 struct qed_ll2_cbs cbs;
114 struct qed_ll2_rx_queue rx_queue;
115 struct qed_ll2_tx_queue tx_queue;
116};
117
118extern const struct qed_ll2_ops qed_ll2_ops_pass;
119
120/**
121 * qed_ll2_acquire_connection(): Allocate resources,
122 * starts rx & tx (if relevant) queues pair.
123 * Provides connecion handler as output
124 * parameter.
125 *
126 * @cxt: Pointer to the hw-function [opaque to some].
127 * @data: Describes connection parameters.
128 *
129 * Return: Int.
130 */
131int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data);
132
133/**
134 * qed_ll2_establish_connection(): start previously allocated LL2 queues pair
135 *
136 * @cxt: Pointer to the hw-function [opaque to some].
137 * @connection_handle: LL2 connection's handle obtained from
138 * qed_ll2_require_connection.
139 *
140 * Return: 0 on success, failure otherwise.
141 */
142int qed_ll2_establish_connection(void *cxt, u8 connection_handle);
143
144/**
145 * qed_ll2_post_rx_buffer(): Submit buffers to LL2 Rx queue.
146 *
147 * @cxt: Pointer to the hw-function [opaque to some].
148 * @connection_handle: LL2 connection's handle obtained from
149 * qed_ll2_require_connection.
150 * @addr: RX (physical address) buffers to submit.
151 * @buf_len: Buffer Len.
152 * @cookie: Cookie.
153 * @notify_fw: Produce corresponding Rx BD immediately.
154 *
155 * Return: 0 on success, failure otherwise.
156 */
157int qed_ll2_post_rx_buffer(void *cxt,
158 u8 connection_handle,
159 dma_addr_t addr,
160 u16 buf_len, void *cookie, u8 notify_fw);
161
162/**
163 * qed_ll2_prepare_tx_packet(): Request for start Tx BD
164 * to prepare Tx packet submission to FW.
165 *
166 * @cxt: Pointer to the hw-function [opaque to some].
167 * @connection_handle: Connection handle.
168 * @pkt: Info regarding the tx packet.
169 * @notify_fw: Issue doorbell to fw for this packet.
170 *
171 * Return: 0 on success, failure otherwise.
172 */
173int qed_ll2_prepare_tx_packet(void *cxt,
174 u8 connection_handle,
175 struct qed_ll2_tx_pkt_info *pkt,
176 bool notify_fw);
177
178/**
179 * qed_ll2_release_connection(): Releases resources allocated for LL2
180 * connection.
181 *
182 * @cxt: Pointer to the hw-function [opaque to some].
183 * @connection_handle: LL2 connection's handle obtained from
184 * qed_ll2_require_connection.
185 *
186 * Return: Void.
187 */
188void qed_ll2_release_connection(void *cxt, u8 connection_handle);
189
190/**
191 * qed_ll2_set_fragment_of_tx_packet(): Provides fragments to fill
192 * Tx BD of BDs requested by
193 * qed_ll2_prepare_tx_packet
194 *
195 * @cxt: Pointer to the hw-function [opaque to some].
196 * @connection_handle: LL2 connection's handle obtained from
197 * qed_ll2_require_connection.
198 * @addr: Address.
199 * @nbytes: Number of bytes.
200 *
201 * Return: 0 on success, failure otherwise.
202 */
203int qed_ll2_set_fragment_of_tx_packet(void *cxt,
204 u8 connection_handle,
205 dma_addr_t addr, u16 nbytes);
206
207/**
208 * qed_ll2_terminate_connection(): Stops Tx/Rx queues
209 *
210 * @cxt: Pointer to the hw-function [opaque to some].
211 * @connection_handle: LL2 connection's handle obtained from
212 * qed_ll2_require_connection.
213 *
214 * Return: 0 on success, failure otherwise.
215 */
216int qed_ll2_terminate_connection(void *cxt, u8 connection_handle);
217
218/**
219 * qed_ll2_get_stats(): Get LL2 queue's statistics
220 *
221 * @cxt: Pointer to the hw-function [opaque to some].
222 * @connection_handle: LL2 connection's handle obtained from
223 * qed_ll2_require_connection.
224 * @p_stats: Pointer Status.
225 *
226 * Return: 0 on success, failure otherwise.
227 */
228int qed_ll2_get_stats(void *cxt,
229 u8 connection_handle, struct qed_ll2_stats *p_stats);
230
231/**
232 * qed_ll2_alloc(): Allocates LL2 connections set.
233 *
234 * @p_hwfn: HW device data.
235 *
236 * Return: Int.
237 */
238int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
239
240/**
241 * qed_ll2_setup(): Inits LL2 connections set.
242 *
243 * @p_hwfn: HW device data.
244 *
245 * Return: Void.
246 *
247 */
248void qed_ll2_setup(struct qed_hwfn *p_hwfn);
249
250/**
251 * qed_ll2_free(): Releases LL2 connections set
252 *
253 * @p_hwfn: HW device data.
254 *
255 * Return: Void.
256 *
257 */
258void qed_ll2_free(struct qed_hwfn *p_hwfn);
259
260#endif
1/* QLogic qed NIC Driver
2 *
3 * Copyright (c) 2015 QLogic Corporation
4 *
5 * This software is available under the terms of the GNU General Public License
6 * (GPL) Version 2, available from the file COPYING in the main directory of
7 * this source tree.
8 */
9
10#ifndef _QED_LL2_H
11#define _QED_LL2_H
12
13#include <linux/types.h>
14#include <linux/kernel.h>
15#include <linux/list.h>
16#include <linux/mutex.h>
17#include <linux/slab.h>
18#include <linux/spinlock.h>
19#include <linux/qed/qed_chain.h>
20#include <linux/qed/qed_ll2_if.h>
21#include "qed.h"
22#include "qed_hsi.h"
23#include "qed_sp.h"
24
25#define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
26
27enum qed_ll2_roce_flavor_type {
28 QED_LL2_ROCE,
29 QED_LL2_RROCE,
30 MAX_QED_LL2_ROCE_FLAVOR_TYPE
31};
32
33enum qed_ll2_conn_type {
34 QED_LL2_TYPE_RESERVED,
35 QED_LL2_TYPE_ISCSI,
36 QED_LL2_TYPE_TEST,
37 QED_LL2_TYPE_ISCSI_OOO,
38 QED_LL2_TYPE_RESERVED2,
39 QED_LL2_TYPE_ROCE,
40 QED_LL2_TYPE_RESERVED3,
41 MAX_QED_LL2_RX_CONN_TYPE
42};
43
44enum 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_MAX
48};
49
50struct qed_ll2_rx_packet {
51 struct list_head list_entry;
52 struct core_rx_bd_with_buff_len *rxq_bd;
53 dma_addr_t rx_buf_addr;
54 u16 buf_length;
55 void *cookie;
56 u8 placement_offset;
57 u16 parse_flags;
58 u16 packet_length;
59 u16 vlan;
60 u32 opaque_data[2];
61};
62
63struct qed_ll2_tx_packet {
64 struct list_head list_entry;
65 u16 bd_used;
66 u16 vlan;
67 u16 l4_hdr_offset_w;
68 u8 bd_flags;
69 bool notify_fw;
70 void *cookie;
71
72 struct {
73 struct core_tx_bd *txq_bd;
74 dma_addr_t tx_frag;
75 u16 frag_len;
76 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
77};
78
79struct qed_ll2_rx_queue {
80 /* Lock protecting the Rx queue manipulation */
81 spinlock_t lock;
82 struct qed_chain rxq_chain;
83 struct qed_chain rcq_chain;
84 u8 rx_sb_index;
85 bool b_cb_registred;
86 __le16 *p_fw_cons;
87 struct list_head active_descq;
88 struct list_head free_descq;
89 struct list_head posting_descq;
90 struct qed_ll2_rx_packet *descq_array;
91 void __iomem *set_prod_addr;
92};
93
94struct qed_ll2_tx_queue {
95 /* Lock protecting the Tx queue manipulation */
96 spinlock_t lock;
97 struct qed_chain txq_chain;
98 u8 tx_sb_index;
99 bool b_cb_registred;
100 __le16 *p_fw_cons;
101 struct list_head active_descq;
102 struct list_head free_descq;
103 struct list_head sending_descq;
104 struct qed_ll2_tx_packet *descq_array;
105 struct qed_ll2_tx_packet *cur_send_packet;
106 struct qed_ll2_tx_packet cur_completing_packet;
107 u16 cur_completing_bd_idx;
108 void __iomem *doorbell_addr;
109 u16 bds_idx;
110 u16 cur_send_frag_num;
111 u16 cur_completing_frag_num;
112 bool b_completing_packet;
113};
114
115struct qed_ll2_conn {
116 enum qed_ll2_conn_type conn_type;
117 u16 mtu;
118 u8 rx_drop_ttl0_flg;
119 u8 rx_vlan_removal_en;
120 u8 tx_tc;
121 enum core_tx_dest tx_dest;
122 enum core_error_handle ai_err_packet_too_big;
123 enum core_error_handle ai_err_no_buf;
124 u8 gsi_enable;
125};
126
127struct qed_ll2_info {
128 /* Lock protecting the state of LL2 */
129 struct mutex mutex;
130 struct qed_ll2_conn conn;
131 u32 cid;
132 u8 my_id;
133 u8 queue_id;
134 u8 tx_stats_id;
135 bool b_active;
136 u8 tx_stats_en;
137 struct qed_ll2_rx_queue rx_queue;
138 struct qed_ll2_tx_queue tx_queue;
139};
140
141/**
142 * @brief qed_ll2_acquire_connection - allocate resources,
143 * starts rx & tx (if relevant) queues pair. Provides
144 * connecion handler as output parameter.
145 *
146 * @param p_hwfn
147 * @param p_params Contain various configuration properties
148 * @param rx_num_desc
149 * @param tx_num_desc
150 *
151 * @param p_connection_handle Output container for LL2 connection's handle
152 *
153 * @return 0 on success, failure otherwise
154 */
155int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
156 struct qed_ll2_conn *p_params,
157 u16 rx_num_desc,
158 u16 tx_num_desc,
159 u8 *p_connection_handle);
160
161/**
162 * @brief qed_ll2_establish_connection - start previously
163 * allocated LL2 queues pair
164 *
165 * @param p_hwfn
166 * @param p_ptt
167 * @param connection_handle LL2 connection's handle obtained from
168 * qed_ll2_require_connection
169 *
170 * @return 0 on success, failure otherwise
171 */
172int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
173
174/**
175 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
176 *
177 * @param p_hwfn
178 * @param connection_handle LL2 connection's handle obtained from
179 * qed_ll2_require_connection
180 * @param addr rx (physical address) buffers to submit
181 * @param cookie
182 * @param notify_fw produce corresponding Rx BD immediately
183 *
184 * @return 0 on success, failure otherwise
185 */
186int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
187 u8 connection_handle,
188 dma_addr_t addr,
189 u16 buf_len, void *cookie, u8 notify_fw);
190
191/**
192 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
193 * to prepare Tx packet submission to FW.
194 *
195 * @param p_hwfn
196 * @param connection_handle LL2 connection's handle obtained from
197 * qed_ll2_require_connection
198 * @param num_of_bds a number of requested BD equals a number of
199 * fragments in Tx packet
200 * @param vlan VLAN to insert to packet (if insertion set)
201 * @param bd_flags
202 * @param l4_hdr_offset_w L4 Header Offset from start of packet
203 * (in words). This is needed if both l4_csum
204 * and ipv6_ext are set
205 * @param e_tx_dest indicates if the packet is to be transmitted via
206 * loopback or to the network
207 * @param first_frag
208 * @param first_frag_len
209 * @param cookie
210 *
211 * @param notify_fw
212 *
213 * @return 0 on success, failure otherwise
214 */
215int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
216 u8 connection_handle,
217 u8 num_of_bds,
218 u16 vlan,
219 u8 bd_flags,
220 u16 l4_hdr_offset_w,
221 enum qed_ll2_tx_dest e_tx_dest,
222 enum qed_ll2_roce_flavor_type qed_roce_flavor,
223 dma_addr_t first_frag,
224 u16 first_frag_len, void *cookie, u8 notify_fw);
225
226/**
227 * @brief qed_ll2_release_connection - releases resources
228 * allocated for LL2 connection
229 *
230 * @param p_hwfn
231 * @param connection_handle LL2 connection's handle obtained from
232 * qed_ll2_require_connection
233 */
234void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
235
236/**
237 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
238 * Tx BD of BDs requested by
239 * qed_ll2_prepare_tx_packet
240 *
241 * @param p_hwfn
242 * @param connection_handle LL2 connection's handle
243 * obtained from
244 * qed_ll2_require_connection
245 * @param addr
246 * @param nbytes
247 *
248 * @return 0 on success, failure otherwise
249 */
250int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
251 u8 connection_handle,
252 dma_addr_t addr, u16 nbytes);
253
254/**
255 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
256 *
257 *
258 * @param p_hwfn
259 * @param connection_handle LL2 connection's handle
260 * obtained from
261 * qed_ll2_require_connection
262 *
263 * @return 0 on success, failure otherwise
264 */
265int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
266
267/**
268 * @brief qed_ll2_get_stats - get LL2 queue's statistics
269 *
270 *
271 * @param p_hwfn
272 * @param connection_handle LL2 connection's handle obtained from
273 * qed_ll2_require_connection
274 * @param p_stats
275 *
276 * @return 0 on success, failure otherwise
277 */
278int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
279 u8 connection_handle, struct qed_ll2_stats *p_stats);
280
281/**
282 * @brief qed_ll2_alloc - Allocates LL2 connections set
283 *
284 * @param p_hwfn
285 *
286 * @return pointer to alocated qed_ll2_info or NULL
287 */
288struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn);
289
290/**
291 * @brief qed_ll2_setup - Inits LL2 connections set
292 *
293 * @param p_hwfn
294 * @param p_ll2_connections
295 *
296 */
297void qed_ll2_setup(struct qed_hwfn *p_hwfn,
298 struct qed_ll2_info *p_ll2_connections);
299
300/**
301 * @brief qed_ll2_free - Releases LL2 connections set
302 *
303 * @param p_hwfn
304 * @param p_ll2_connections
305 *
306 */
307void qed_ll2_free(struct qed_hwfn *p_hwfn,
308 struct qed_ll2_info *p_ll2_connections);
309#endif