1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
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>
48 #define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
50 enum qed_ll2_roce_flavor_type
{
53 MAX_QED_LL2_ROCE_FLAVOR_TYPE
56 enum qed_ll2_conn_type
{
60 QED_LL2_TYPE_ISCSI_OOO
,
61 QED_LL2_TYPE_RESERVED2
,
63 QED_LL2_TYPE_RESERVED3
,
64 MAX_QED_LL2_RX_CONN_TYPE
67 enum qed_ll2_tx_dest
{
68 QED_LL2_TX_DEST_NW
, /* Light L2 TX Destination to the Network */
69 QED_LL2_TX_DEST_LB
, /* Light L2 TX Destination to the Loopback */
73 struct qed_ll2_rx_packet
{
74 struct list_head list_entry
;
75 struct core_rx_bd_with_buff_len
*rxq_bd
;
76 dma_addr_t rx_buf_addr
;
86 struct qed_ll2_tx_packet
{
87 struct list_head list_entry
;
96 struct core_tx_bd
*txq_bd
;
99 } bds_set
[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET
];
102 struct qed_ll2_rx_queue
{
103 /* Lock protecting the Rx queue manipulation */
105 struct qed_chain rxq_chain
;
106 struct qed_chain rcq_chain
;
110 struct list_head active_descq
;
111 struct list_head free_descq
;
112 struct list_head posting_descq
;
113 struct qed_ll2_rx_packet
*descq_array
;
114 void __iomem
*set_prod_addr
;
117 struct qed_ll2_tx_queue
{
118 /* Lock protecting the Tx queue manipulation */
120 struct qed_chain txq_chain
;
124 struct list_head active_descq
;
125 struct list_head free_descq
;
126 struct list_head sending_descq
;
127 struct qed_ll2_tx_packet
*descq_array
;
128 struct qed_ll2_tx_packet
*cur_send_packet
;
129 struct qed_ll2_tx_packet cur_completing_packet
;
130 u16 cur_completing_bd_idx
;
131 void __iomem
*doorbell_addr
;
133 u16 cur_send_frag_num
;
134 u16 cur_completing_frag_num
;
135 bool b_completing_packet
;
138 struct qed_ll2_conn
{
139 enum qed_ll2_conn_type conn_type
;
142 u8 rx_vlan_removal_en
;
144 enum core_tx_dest tx_dest
;
145 enum core_error_handle ai_err_packet_too_big
;
146 enum core_error_handle ai_err_no_buf
;
150 struct qed_ll2_info
{
151 /* Lock protecting the state of LL2 */
153 struct qed_ll2_conn conn
;
160 struct qed_ll2_rx_queue rx_queue
;
161 struct qed_ll2_tx_queue tx_queue
;
165 * @brief qed_ll2_acquire_connection - allocate resources,
166 * starts rx & tx (if relevant) queues pair. Provides
167 * connecion handler as output parameter.
170 * @param p_params Contain various configuration properties
174 * @param p_connection_handle Output container for LL2 connection's handle
176 * @return 0 on success, failure otherwise
178 int qed_ll2_acquire_connection(struct qed_hwfn
*p_hwfn
,
179 struct qed_ll2_conn
*p_params
,
182 u8
*p_connection_handle
);
185 * @brief qed_ll2_establish_connection - start previously
186 * allocated LL2 queues pair
190 * @param connection_handle LL2 connection's handle obtained from
191 * qed_ll2_require_connection
193 * @return 0 on success, failure otherwise
195 int qed_ll2_establish_connection(struct qed_hwfn
*p_hwfn
, u8 connection_handle
);
198 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
201 * @param connection_handle LL2 connection's handle obtained from
202 * qed_ll2_require_connection
203 * @param addr rx (physical address) buffers to submit
205 * @param notify_fw produce corresponding Rx BD immediately
207 * @return 0 on success, failure otherwise
209 int qed_ll2_post_rx_buffer(struct qed_hwfn
*p_hwfn
,
210 u8 connection_handle
,
212 u16 buf_len
, void *cookie
, u8 notify_fw
);
215 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
216 * to prepare Tx packet submission to FW.
219 * @param connection_handle LL2 connection's handle obtained from
220 * qed_ll2_require_connection
221 * @param num_of_bds a number of requested BD equals a number of
222 * fragments in Tx packet
223 * @param vlan VLAN to insert to packet (if insertion set)
225 * @param l4_hdr_offset_w L4 Header Offset from start of packet
226 * (in words). This is needed if both l4_csum
227 * and ipv6_ext are set
228 * @param e_tx_dest indicates if the packet is to be transmitted via
229 * loopback or to the network
231 * @param first_frag_len
236 * @return 0 on success, failure otherwise
238 int qed_ll2_prepare_tx_packet(struct qed_hwfn
*p_hwfn
,
239 u8 connection_handle
,
244 enum qed_ll2_tx_dest e_tx_dest
,
245 enum qed_ll2_roce_flavor_type qed_roce_flavor
,
246 dma_addr_t first_frag
,
247 u16 first_frag_len
, void *cookie
, u8 notify_fw
);
250 * @brief qed_ll2_release_connection - releases resources
251 * allocated for LL2 connection
254 * @param connection_handle LL2 connection's handle obtained from
255 * qed_ll2_require_connection
257 void qed_ll2_release_connection(struct qed_hwfn
*p_hwfn
, u8 connection_handle
);
260 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
261 * Tx BD of BDs requested by
262 * qed_ll2_prepare_tx_packet
265 * @param connection_handle LL2 connection's handle
267 * qed_ll2_require_connection
271 * @return 0 on success, failure otherwise
273 int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn
*p_hwfn
,
274 u8 connection_handle
,
275 dma_addr_t addr
, u16 nbytes
);
278 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
282 * @param connection_handle LL2 connection's handle
284 * qed_ll2_require_connection
286 * @return 0 on success, failure otherwise
288 int qed_ll2_terminate_connection(struct qed_hwfn
*p_hwfn
, u8 connection_handle
);
291 * @brief qed_ll2_get_stats - get LL2 queue's statistics
295 * @param connection_handle LL2 connection's handle obtained from
296 * qed_ll2_require_connection
299 * @return 0 on success, failure otherwise
301 int qed_ll2_get_stats(struct qed_hwfn
*p_hwfn
,
302 u8 connection_handle
, struct qed_ll2_stats
*p_stats
);
305 * @brief qed_ll2_alloc - Allocates LL2 connections set
309 * @return pointer to alocated qed_ll2_info or NULL
311 struct qed_ll2_info
*qed_ll2_alloc(struct qed_hwfn
*p_hwfn
);
314 * @brief qed_ll2_setup - Inits LL2 connections set
317 * @param p_ll2_connections
320 void qed_ll2_setup(struct qed_hwfn
*p_hwfn
,
321 struct qed_ll2_info
*p_ll2_connections
);
324 * @brief qed_ll2_free - Releases LL2 connections set
327 * @param p_ll2_connections
330 void qed_ll2_free(struct qed_hwfn
*p_hwfn
,
331 struct qed_ll2_info
*p_ll2_connections
);