1 /* QLogic qed NIC Driver
3 * Copyright (c) 2015 QLogic Corporation
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
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>
25 #define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
27 enum qed_ll2_roce_flavor_type {
30 MAX_QED_LL2_ROCE_FLAVOR_TYPE
33 enum qed_ll2_conn_type {
34 QED_LL2_TYPE_RESERVED,
37 QED_LL2_TYPE_ISCSI_OOO,
38 QED_LL2_TYPE_RESERVED2,
40 QED_LL2_TYPE_RESERVED3,
41 MAX_QED_LL2_RX_CONN_TYPE
44 struct qed_ll2_rx_packet {
45 struct list_head list_entry;
46 struct core_rx_bd_with_buff_len *rxq_bd;
47 dma_addr_t rx_buf_addr;
57 struct qed_ll2_tx_packet {
58 struct list_head list_entry;
67 struct core_tx_bd *txq_bd;
70 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
73 struct qed_ll2_rx_queue {
74 /* Lock protecting the Rx queue manipulation */
76 struct qed_chain rxq_chain;
77 struct qed_chain rcq_chain;
81 struct list_head active_descq;
82 struct list_head free_descq;
83 struct list_head posting_descq;
84 struct qed_ll2_rx_packet *descq_array;
85 void __iomem *set_prod_addr;
88 struct qed_ll2_tx_queue {
89 /* Lock protecting the Tx queue manipulation */
91 struct qed_chain txq_chain;
95 struct list_head active_descq;
96 struct list_head free_descq;
97 struct list_head sending_descq;
98 struct qed_ll2_tx_packet *descq_array;
99 struct qed_ll2_tx_packet *cur_send_packet;
100 struct qed_ll2_tx_packet cur_completing_packet;
101 u16 cur_completing_bd_idx;
102 void __iomem *doorbell_addr;
104 u16 cur_send_frag_num;
105 u16 cur_completing_frag_num;
106 bool b_completing_packet;
109 struct qed_ll2_info {
110 /* Lock protecting the state of LL2 */
112 enum qed_ll2_conn_type conn_type;
120 u8 rx_vlan_removal_en;
122 enum core_tx_dest tx_dest;
123 enum core_error_handle ai_err_packet_too_big;
124 enum core_error_handle ai_err_no_buf;
126 struct qed_ll2_rx_queue rx_queue;
127 struct qed_ll2_tx_queue tx_queue;
132 * @brief qed_ll2_acquire_connection - allocate resources,
133 * starts rx & tx (if relevant) queues pair. Provides
134 * connecion handler as output parameter.
137 * @param p_params Contain various configuration properties
141 * @param p_connection_handle Output container for LL2 connection's handle
143 * @return 0 on success, failure otherwise
145 int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
146 struct qed_ll2_info *p_params,
149 u8 *p_connection_handle);
152 * @brief qed_ll2_establish_connection - start previously
153 * allocated LL2 queues pair
157 * @param connection_handle LL2 connection's handle obtained from
158 * qed_ll2_require_connection
160 * @return 0 on success, failure otherwise
162 int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
165 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
168 * @param connection_handle LL2 connection's handle obtained from
169 * qed_ll2_require_connection
170 * @param addr rx (physical address) buffers to submit
172 * @param notify_fw produce corresponding Rx BD immediately
174 * @return 0 on success, failure otherwise
176 int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
177 u8 connection_handle,
179 u16 buf_len, void *cookie, u8 notify_fw);
182 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
183 * to prepare Tx packet submission to FW.
186 * @param connection_handle LL2 connection's handle obtained from
187 * qed_ll2_require_connection
188 * @param num_of_bds a number of requested BD equals a number of
189 * fragments in Tx packet
190 * @param vlan VLAN to insert to packet (if insertion set)
192 * @param l4_hdr_offset_w L4 Header Offset from start of packet
193 * (in words). This is needed if both l4_csum
194 * and ipv6_ext are set
196 * @param first_frag_len
201 * @return 0 on success, failure otherwise
203 int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
204 u8 connection_handle,
209 enum qed_ll2_roce_flavor_type qed_roce_flavor,
210 dma_addr_t first_frag,
211 u16 first_frag_len, void *cookie, u8 notify_fw);
214 * @brief qed_ll2_release_connection - releases resources
215 * allocated for LL2 connection
218 * @param connection_handle LL2 connection's handle obtained from
219 * qed_ll2_require_connection
221 void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
224 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
225 * Tx BD of BDs requested by
226 * qed_ll2_prepare_tx_packet
229 * @param connection_handle LL2 connection's handle
231 * qed_ll2_require_connection
235 * @return 0 on success, failure otherwise
237 int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
238 u8 connection_handle,
239 dma_addr_t addr, u16 nbytes);
242 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
246 * @param connection_handle LL2 connection's handle
248 * qed_ll2_require_connection
250 * @return 0 on success, failure otherwise
252 int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
255 * @brief qed_ll2_get_stats - get LL2 queue's statistics
259 * @param connection_handle LL2 connection's handle obtained from
260 * qed_ll2_require_connection
263 * @return 0 on success, failure otherwise
265 int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
266 u8 connection_handle, struct qed_ll2_stats *p_stats);
269 * @brief qed_ll2_alloc - Allocates LL2 connections set
273 * @return pointer to alocated qed_ll2_info or NULL
275 struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn);
278 * @brief qed_ll2_setup - Inits LL2 connections set
281 * @param p_ll2_connections
284 void qed_ll2_setup(struct qed_hwfn *p_hwfn,
285 struct qed_ll2_info *p_ll2_connections);
288 * @brief qed_ll2_free - Releases LL2 connections set
291 * @param p_ll2_connections
294 void qed_ll2_free(struct qed_hwfn *p_hwfn,
295 struct qed_ll2_info *p_ll2_connections);