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