Linux Audio

Check our new training course

Real-Time Linux with PREEMPT_RT training

Feb 18-20, 2025
Register
Loading...
v6.13.7
  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
v4.17
 
  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_H
 34#define _QED_LL2_H
 35
 36#include <linux/types.h>
 37#include <linux/kernel.h>
 38#include <linux/list.h>
 39#include <linux/mutex.h>
 40#include <linux/slab.h>
 41#include <linux/spinlock.h>
 42#include <linux/qed/qed_chain.h>
 43#include <linux/qed/qed_ll2_if.h>
 44#include "qed.h"
 45#include "qed_hsi.h"
 46#include "qed_sp.h"
 47
 48#define QED_MAX_NUM_OF_LL2_CONNECTIONS                    (4)
 
 
 
 
 
 
 
 
 
 
 
 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	bool notify_fw;
 67	void *cookie;
 68	/* Flexible Array of bds_set determined by max_bds_per_packet */
 69	struct {
 70		struct core_tx_bd *txq_bd;
 71		dma_addr_t tx_frag;
 72		u16 frag_len;
 73	} bds_set[1];
 74};
 75
 76struct qed_ll2_rx_queue {
 77	/* Lock protecting the Rx queue manipulation */
 78	spinlock_t lock;
 79	struct qed_chain rxq_chain;
 80	struct qed_chain rcq_chain;
 81	u8 rx_sb_index;
 82	bool b_cb_registred;
 
 83	__le16 *p_fw_cons;
 84	struct list_head active_descq;
 85	struct list_head free_descq;
 86	struct list_head posting_descq;
 87	struct qed_ll2_rx_packet *descq_array;
 88	void __iomem *set_prod_addr;
 
 89};
 90
 91struct qed_ll2_tx_queue {
 92	/* Lock protecting the Tx queue manipulation */
 93	spinlock_t lock;
 94	struct qed_chain txq_chain;
 95	u8 tx_sb_index;
 96	bool b_cb_registred;
 97	__le16 *p_fw_cons;
 98	struct list_head active_descq;
 99	struct list_head free_descq;
100	struct list_head sending_descq;
101	void *descq_mem; /* memory for variable sized qed_ll2_tx_packet*/
102	struct qed_ll2_tx_packet *cur_send_packet;
103	struct qed_ll2_tx_packet cur_completing_packet;
104	u16 cur_completing_bd_idx;
105	void __iomem *doorbell_addr;
 
106	u16 bds_idx;
107	u16 cur_send_frag_num;
108	u16 cur_completing_frag_num;
109	bool b_completing_packet;
 
 
 
110};
111
112struct qed_ll2_info {
113	/* Lock protecting the state of LL2 */
114	struct mutex mutex;
115
116	struct qed_ll2_acquire_data_inputs input;
117	u32 cid;
118	u8 my_id;
119	u8 queue_id;
120	u8 tx_stats_id;
121	bool b_active;
122	enum core_tx_dest tx_dest;
123	u8 tx_stats_en;
124	bool main_func_queue;
 
125	struct qed_ll2_rx_queue rx_queue;
126	struct qed_ll2_tx_queue tx_queue;
127	struct qed_ll2_cbs cbs;
128};
129
 
 
130/**
131 * @brief qed_ll2_acquire_connection - allocate resources,
132 *        starts rx & tx (if relevant) queues pair. Provides
133 *        connecion handler as output parameter.
 
134 *
 
 
135 *
136 * @param cxt - pointer to the hw-function [opaque to some]
137 * @param data - describes connection parameters
138 * @return int
139 */
140int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data);
141
142/**
143 * @brief qed_ll2_establish_connection - start previously
144 *        allocated LL2 queues pair
145 *
146 * @param cxt - pointer to the hw-function [opaque to some]
147 * @param p_ptt
148 * @param connection_handle	LL2 connection's handle obtained from
149 *                              qed_ll2_require_connection
150 *
151 * @return 0 on success, failure otherwise
152 */
153int qed_ll2_establish_connection(void *cxt, u8 connection_handle);
154
155/**
156 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
157 *
158 * @param cxt - pointer to the hw-function [opaque to some]
159 * @param connection_handle	LL2 connection's handle obtained from
160 *				qed_ll2_require_connection
161 * @param addr			rx (physical address) buffers to submit
162 * @param cookie
163 * @param notify_fw		produce corresponding Rx BD immediately
 
164 *
165 * @return 0 on success, failure otherwise
166 */
167int qed_ll2_post_rx_buffer(void *cxt,
168			   u8 connection_handle,
169			   dma_addr_t addr,
170			   u16 buf_len, void *cookie, u8 notify_fw);
171
172/**
173 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
174 *				      to prepare Tx packet submission to FW.
175 *
176 * @param cxt - pointer to the hw-function [opaque to some]
177 * @param connection_handle
178 * @param pkt - info regarding the tx packet
179 * @param notify_fw - issue doorbell to fw for this packet
180 *
181 * @return 0 on success, failure otherwise
182 */
183int qed_ll2_prepare_tx_packet(void *cxt,
184			      u8 connection_handle,
185			      struct qed_ll2_tx_pkt_info *pkt,
186			      bool notify_fw);
187
188/**
189 * @brief qed_ll2_release_connection -	releases resources
190 *					allocated for LL2 connection
 
 
 
 
191 *
192 * @param cxt - pointer to the hw-function [opaque to some]
193 * @param connection_handle		LL2 connection's handle obtained from
194 *					qed_ll2_require_connection
195 */
196void qed_ll2_release_connection(void *cxt, u8 connection_handle);
197
198/**
199 * @brief qed_ll2_set_fragment_of_tx_packet -	provides fragments to fill
200 *						Tx BD of BDs requested by
201 *						qed_ll2_prepare_tx_packet
202 *
203 * @param cxt - pointer to the hw-function [opaque to some]
204 * @param connection_handle			LL2 connection's handle
205 *						obtained from
206 *						qed_ll2_require_connection
207 * @param addr
208 * @param nbytes
209 *
210 * @return 0 on success, failure otherwise
211 */
212int qed_ll2_set_fragment_of_tx_packet(void *cxt,
213				      u8 connection_handle,
214				      dma_addr_t addr, u16 nbytes);
215
216/**
217 * @brief qed_ll2_terminate_connection -	stops Tx/Rx queues
218 *
 
 
 
219 *
220 * @param cxt - pointer to the hw-function [opaque to some]
221 * @param connection_handle			LL2 connection's handle
222 *						obtained from
223 *						qed_ll2_require_connection
224 *
225 * @return 0 on success, failure otherwise
226 */
227int qed_ll2_terminate_connection(void *cxt, u8 connection_handle);
228
229/**
230 * @brief qed_ll2_get_stats -	get LL2 queue's statistics
231 *
232 *
233 * @param cxt - pointer to the hw-function [opaque to some]
234 * @param connection_handle	LL2 connection's handle obtained from
235 *				qed_ll2_require_connection
236 * @param p_stats
237 *
238 * @return 0 on success, failure otherwise
239 */
240int qed_ll2_get_stats(void *cxt,
241		      u8 connection_handle, struct qed_ll2_stats *p_stats);
242
243/**
244 * @brief qed_ll2_alloc - Allocates LL2 connections set
245 *
246 * @param p_hwfn
247 *
248 * @return int
249 */
250int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
251
252/**
253 * @brief qed_ll2_setup - Inits LL2 connections set
254 *
255 * @param p_hwfn
 
 
256 *
257 */
258void qed_ll2_setup(struct qed_hwfn *p_hwfn);
259
260/**
261 * @brief qed_ll2_free - Releases LL2 connections set
 
 
262 *
263 * @param p_hwfn
264 *
265 */
266void qed_ll2_free(struct qed_hwfn *p_hwfn);
267
268#endif