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)
49 /* LL2 queues handles will be split as follows:
50 * first will be legacy queues, and then the ctx based queues.
52 #define QED_MAX_NUM_OF_LL2_CONNS_PF (4)
53 #define QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF (3)
55 #define QED_MAX_NUM_OF_CTX_LL2_CONNS_PF \
56 (QED_MAX_NUM_OF_LL2_CONNS_PF - QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF)
58 #define QED_LL2_LEGACY_CONN_BASE_PF 0
59 #define QED_LL2_CTX_CONN_BASE_PF QED_MAX_NUM_OF_LEGACY_LL2_CONNS_PF
62 struct qed_ll2_rx_packet {
63 struct list_head list_entry;
64 struct core_rx_bd_with_buff_len *rxq_bd;
65 dma_addr_t rx_buf_addr;
75 struct qed_ll2_tx_packet {
76 struct list_head list_entry;
80 /* Flexible Array of bds_set determined by max_bds_per_packet */
82 struct core_tx_bd *txq_bd;
88 struct qed_ll2_rx_queue {
89 /* Lock protecting the Rx queue manipulation */
91 struct qed_chain rxq_chain;
92 struct qed_chain rcq_chain;
97 struct list_head active_descq;
98 struct list_head free_descq;
99 struct list_head posting_descq;
100 struct qed_ll2_rx_packet *descq_array;
101 void __iomem *set_prod_addr;
102 struct core_pwm_prod_update_data db_data;
105 struct qed_ll2_tx_queue {
106 /* Lock protecting the Tx queue manipulation */
108 struct qed_chain txq_chain;
110 bool b_cb_registered;
112 struct list_head active_descq;
113 struct list_head free_descq;
114 struct list_head sending_descq;
115 void *descq_mem; /* memory for variable sized qed_ll2_tx_packet*/
116 struct qed_ll2_tx_packet *cur_send_packet;
117 struct qed_ll2_tx_packet cur_completing_packet;
118 u16 cur_completing_bd_idx;
119 void __iomem *doorbell_addr;
120 struct core_db_data db_msg;
122 u16 cur_send_frag_num;
123 u16 cur_completing_frag_num;
124 bool b_completing_packet;
127 struct qed_ll2_info {
128 /* Lock protecting the state of LL2 */
131 struct qed_ll2_acquire_data_inputs input;
137 enum core_tx_dest tx_dest;
139 bool main_func_queue;
140 struct qed_ll2_rx_queue rx_queue;
141 struct qed_ll2_tx_queue tx_queue;
142 struct qed_ll2_cbs cbs;
146 * @brief qed_ll2_acquire_connection - allocate resources,
147 * starts rx & tx (if relevant) queues pair. Provides
148 * connecion handler as output parameter.
151 * @param cxt - pointer to the hw-function [opaque to some]
152 * @param data - describes connection parameters
155 int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data);
158 * @brief qed_ll2_establish_connection - start previously
159 * allocated LL2 queues pair
161 * @param cxt - pointer to the hw-function [opaque to some]
163 * @param connection_handle LL2 connection's handle obtained from
164 * qed_ll2_require_connection
166 * @return 0 on success, failure otherwise
168 int qed_ll2_establish_connection(void *cxt, u8 connection_handle);
171 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
173 * @param cxt - pointer to the hw-function [opaque to some]
174 * @param connection_handle LL2 connection's handle obtained from
175 * qed_ll2_require_connection
176 * @param addr rx (physical address) buffers to submit
178 * @param notify_fw produce corresponding Rx BD immediately
180 * @return 0 on success, failure otherwise
182 int qed_ll2_post_rx_buffer(void *cxt,
183 u8 connection_handle,
185 u16 buf_len, void *cookie, u8 notify_fw);
188 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
189 * to prepare Tx packet submission to FW.
191 * @param cxt - pointer to the hw-function [opaque to some]
192 * @param connection_handle
193 * @param pkt - info regarding the tx packet
194 * @param notify_fw - issue doorbell to fw for this packet
196 * @return 0 on success, failure otherwise
198 int qed_ll2_prepare_tx_packet(void *cxt,
199 u8 connection_handle,
200 struct qed_ll2_tx_pkt_info *pkt,
204 * @brief qed_ll2_release_connection - releases resources
205 * allocated for LL2 connection
207 * @param cxt - pointer to the hw-function [opaque to some]
208 * @param connection_handle LL2 connection's handle obtained from
209 * qed_ll2_require_connection
211 void qed_ll2_release_connection(void *cxt, u8 connection_handle);
214 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
215 * Tx BD of BDs requested by
216 * qed_ll2_prepare_tx_packet
218 * @param cxt - pointer to the hw-function [opaque to some]
219 * @param connection_handle LL2 connection's handle
221 * qed_ll2_require_connection
225 * @return 0 on success, failure otherwise
227 int qed_ll2_set_fragment_of_tx_packet(void *cxt,
228 u8 connection_handle,
229 dma_addr_t addr, u16 nbytes);
232 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
235 * @param cxt - pointer to the hw-function [opaque to some]
236 * @param connection_handle LL2 connection's handle
238 * qed_ll2_require_connection
240 * @return 0 on success, failure otherwise
242 int qed_ll2_terminate_connection(void *cxt, u8 connection_handle);
245 * @brief qed_ll2_get_stats - get LL2 queue's statistics
248 * @param cxt - pointer to the hw-function [opaque to some]
249 * @param connection_handle LL2 connection's handle obtained from
250 * qed_ll2_require_connection
253 * @return 0 on success, failure otherwise
255 int qed_ll2_get_stats(void *cxt,
256 u8 connection_handle, struct qed_ll2_stats *p_stats);
259 * @brief qed_ll2_alloc - Allocates LL2 connections set
265 int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
268 * @brief qed_ll2_setup - Inits LL2 connections set
273 void qed_ll2_setup(struct qed_hwfn *p_hwfn);
276 * @brief qed_ll2_free - Releases LL2 connections set
281 void qed_ll2_free(struct qed_hwfn *p_hwfn);