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 enum 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 */
50 struct 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;
63 struct qed_ll2_tx_packet {
64 struct list_head list_entry;
73 struct core_tx_bd *txq_bd;
76 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
79 struct qed_ll2_rx_queue {
80 /* Lock protecting the Rx queue manipulation */
82 struct qed_chain rxq_chain;
83 struct qed_chain rcq_chain;
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;
94 struct qed_ll2_tx_queue {
95 /* Lock protecting the Tx queue manipulation */
97 struct qed_chain txq_chain;
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;
110 u16 cur_send_frag_num;
111 u16 cur_completing_frag_num;
112 bool b_completing_packet;
115 struct qed_ll2_conn {
116 enum qed_ll2_conn_type conn_type;
119 u8 rx_vlan_removal_en;
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;
127 struct qed_ll2_info {
128 /* Lock protecting the state of LL2 */
130 struct qed_ll2_conn conn;
137 struct qed_ll2_rx_queue rx_queue;
138 struct qed_ll2_tx_queue tx_queue;
142 * @brief qed_ll2_acquire_connection - allocate resources,
143 * starts rx & tx (if relevant) queues pair. Provides
144 * connecion handler as output parameter.
147 * @param p_params Contain various configuration properties
151 * @param p_connection_handle Output container for LL2 connection's handle
153 * @return 0 on success, failure otherwise
155 int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
156 struct qed_ll2_conn *p_params,
159 u8 *p_connection_handle);
162 * @brief qed_ll2_establish_connection - start previously
163 * allocated LL2 queues pair
167 * @param connection_handle LL2 connection's handle obtained from
168 * qed_ll2_require_connection
170 * @return 0 on success, failure otherwise
172 int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
175 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
178 * @param connection_handle LL2 connection's handle obtained from
179 * qed_ll2_require_connection
180 * @param addr rx (physical address) buffers to submit
182 * @param notify_fw produce corresponding Rx BD immediately
184 * @return 0 on success, failure otherwise
186 int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
187 u8 connection_handle,
189 u16 buf_len, void *cookie, u8 notify_fw);
192 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
193 * to prepare Tx packet submission to FW.
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)
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
208 * @param first_frag_len
213 * @return 0 on success, failure otherwise
215 int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
216 u8 connection_handle,
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);
227 * @brief qed_ll2_release_connection - releases resources
228 * allocated for LL2 connection
231 * @param connection_handle LL2 connection's handle obtained from
232 * qed_ll2_require_connection
234 void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
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
242 * @param connection_handle LL2 connection's handle
244 * qed_ll2_require_connection
248 * @return 0 on success, failure otherwise
250 int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
251 u8 connection_handle,
252 dma_addr_t addr, u16 nbytes);
255 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
259 * @param connection_handle LL2 connection's handle
261 * qed_ll2_require_connection
263 * @return 0 on success, failure otherwise
265 int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
268 * @brief qed_ll2_get_stats - get LL2 queue's statistics
272 * @param connection_handle LL2 connection's handle obtained from
273 * qed_ll2_require_connection
276 * @return 0 on success, failure otherwise
278 int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
279 u8 connection_handle, struct qed_ll2_stats *p_stats);
282 * @brief qed_ll2_alloc - Allocates LL2 connections set
286 * @return pointer to alocated qed_ll2_info or NULL
288 struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn);
291 * @brief qed_ll2_setup - Inits LL2 connections set
294 * @param p_ll2_connections
297 void qed_ll2_setup(struct qed_hwfn *p_hwfn,
298 struct qed_ll2_info *p_ll2_connections);
301 * @brief qed_ll2_free - Releases LL2 connections set
304 * @param p_ll2_connections
307 void qed_ll2_free(struct qed_hwfn *p_hwfn,
308 struct qed_ll2_info *p_ll2_connections);