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/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>
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.
26 #define QED_MAX_NUM_OF_LL2_CONNS_PF (4)
27 #define QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF (3)
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)
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
35 struct 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
;
48 struct qed_ll2_tx_packet
{
49 struct list_head list_entry
;
53 /* Flexible Array of bds_set determined by max_bds_per_packet */
55 struct core_tx_bd
*txq_bd
;
61 struct qed_ll2_rx_queue
{
62 /* Lock protecting the Rx queue manipulation */
64 struct qed_chain rxq_chain
;
65 struct qed_chain rcq_chain
;
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
;
78 struct qed_ll2_tx_queue
{
79 /* Lock protecting the Tx queue manipulation */
81 struct qed_chain txq_chain
;
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
;
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
;
100 struct qed_ll2_info
{
101 /* Lock protecting the state of LL2 */
104 struct qed_ll2_acquire_data_inputs input
;
110 enum core_tx_dest tx_dest
;
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
;
118 extern const struct qed_ll2_ops qed_ll2_ops_pass
;
121 * qed_ll2_acquire_connection(): Allocate resources,
122 * starts rx & tx (if relevant) queues pair.
123 * Provides connecion handler as output
126 * @cxt: Pointer to the hw-function [opaque to some].
127 * @data: Describes connection parameters.
131 int qed_ll2_acquire_connection(void *cxt
, struct qed_ll2_acquire_data
*data
);
134 * qed_ll2_establish_connection(): start previously allocated LL2 queues pair
136 * @cxt: Pointer to the hw-function [opaque to some].
137 * @connection_handle: LL2 connection's handle obtained from
138 * qed_ll2_require_connection.
140 * Return: 0 on success, failure otherwise.
142 int qed_ll2_establish_connection(void *cxt
, u8 connection_handle
);
145 * qed_ll2_post_rx_buffer(): Submit buffers to LL2 Rx queue.
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.
153 * @notify_fw: Produce corresponding Rx BD immediately.
155 * Return: 0 on success, failure otherwise.
157 int qed_ll2_post_rx_buffer(void *cxt
,
158 u8 connection_handle
,
160 u16 buf_len
, void *cookie
, u8 notify_fw
);
163 * qed_ll2_prepare_tx_packet(): Request for start Tx BD
164 * to prepare Tx packet submission to FW.
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.
171 * Return: 0 on success, failure otherwise.
173 int qed_ll2_prepare_tx_packet(void *cxt
,
174 u8 connection_handle
,
175 struct qed_ll2_tx_pkt_info
*pkt
,
179 * qed_ll2_release_connection(): Releases resources allocated for LL2
182 * @cxt: Pointer to the hw-function [opaque to some].
183 * @connection_handle: LL2 connection's handle obtained from
184 * qed_ll2_require_connection.
188 void qed_ll2_release_connection(void *cxt
, u8 connection_handle
);
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
195 * @cxt: Pointer to the hw-function [opaque to some].
196 * @connection_handle: LL2 connection's handle obtained from
197 * qed_ll2_require_connection.
199 * @nbytes: Number of bytes.
201 * Return: 0 on success, failure otherwise.
203 int qed_ll2_set_fragment_of_tx_packet(void *cxt
,
204 u8 connection_handle
,
205 dma_addr_t addr
, u16 nbytes
);
208 * qed_ll2_terminate_connection(): Stops Tx/Rx queues
210 * @cxt: Pointer to the hw-function [opaque to some].
211 * @connection_handle: LL2 connection's handle obtained from
212 * qed_ll2_require_connection.
214 * Return: 0 on success, failure otherwise.
216 int qed_ll2_terminate_connection(void *cxt
, u8 connection_handle
);
219 * qed_ll2_get_stats(): Get LL2 queue's statistics
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.
226 * Return: 0 on success, failure otherwise.
228 int qed_ll2_get_stats(void *cxt
,
229 u8 connection_handle
, struct qed_ll2_stats
*p_stats
);
232 * qed_ll2_alloc(): Allocates LL2 connections set.
234 * @p_hwfn: HW device data.
238 int qed_ll2_alloc(struct qed_hwfn
*p_hwfn
);
241 * qed_ll2_setup(): Inits LL2 connections set.
243 * @p_hwfn: HW device data.
248 void qed_ll2_setup(struct qed_hwfn
*p_hwfn
);
251 * qed_ll2_free(): Releases LL2 connections set
253 * @p_hwfn: HW device data.
258 void qed_ll2_free(struct qed_hwfn
*p_hwfn
);