blob: 9bdd08f15c793cd7bb70dbfdd6ea2895f74ddce5 [file] [log] [blame]
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintz0a7fb112016-10-01 21:59:55 +03003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * 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:
Yuval Mintz0a7fb112016-10-01 21:59:55 +03009 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +020010 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
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.
22 *
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
30 * SOFTWARE.
Yuval Mintz0a7fb112016-10-01 21:59:55 +030031 */
32
33#ifndef _QED_LL2_H
34#define _QED_LL2_H
35
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>
44#include "qed.h"
45#include "qed_hsi.h"
46#include "qed_sp.h"
47
48#define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
49
Yuval Mintz0a7fb112016-10-01 21:59:55 +030050struct 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;
54 u16 buf_length;
55 void *cookie;
56 u8 placement_offset;
57 u16 parse_flags;
58 u16 packet_length;
59 u16 vlan;
60 u32 opaque_data[2];
61};
62
63struct qed_ll2_tx_packet {
64 struct list_head list_entry;
65 u16 bd_used;
Yuval Mintz0a7fb112016-10-01 21:59:55 +030066 bool notify_fw;
67 void *cookie;
Michal Kalderonf5823fe2017-10-09 12:37:43 +030068 /* Flexible Array of bds_set determined by max_bds_per_packet */
Yuval Mintz0a7fb112016-10-01 21:59:55 +030069 struct {
70 struct core_tx_bd *txq_bd;
71 dma_addr_t tx_frag;
72 u16 frag_len;
Michal Kalderonf5823fe2017-10-09 12:37:43 +030073 } bds_set[1];
Yuval Mintz0a7fb112016-10-01 21:59:55 +030074};
75
76struct qed_ll2_rx_queue {
77 /* Lock protecting the Rx queue manipulation */
78 spinlock_t lock;
79 struct qed_chain rxq_chain;
80 struct qed_chain rcq_chain;
81 u8 rx_sb_index;
82 bool b_cb_registred;
83 __le16 *p_fw_cons;
84 struct list_head active_descq;
85 struct list_head free_descq;
86 struct list_head posting_descq;
87 struct qed_ll2_rx_packet *descq_array;
88 void __iomem *set_prod_addr;
89};
90
91struct qed_ll2_tx_queue {
92 /* Lock protecting the Tx queue manipulation */
93 spinlock_t lock;
94 struct qed_chain txq_chain;
95 u8 tx_sb_index;
96 bool b_cb_registred;
97 __le16 *p_fw_cons;
98 struct list_head active_descq;
99 struct list_head free_descq;
100 struct list_head sending_descq;
Michal Kalderonf5823fe2017-10-09 12:37:43 +0300101 void *descq_mem; /* memory for variable sized qed_ll2_tx_packet*/
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300102 struct qed_ll2_tx_packet *cur_send_packet;
103 struct qed_ll2_tx_packet cur_completing_packet;
104 u16 cur_completing_bd_idx;
105 void __iomem *doorbell_addr;
106 u16 bds_idx;
107 u16 cur_send_frag_num;
108 u16 cur_completing_frag_num;
109 bool b_completing_packet;
110};
111
Arnd Bergmann0629a332017-01-18 15:52:52 +0100112struct qed_ll2_info {
113 /* Lock protecting the state of LL2 */
114 struct mutex mutex;
Mintz, Yuval13c54772017-06-09 17:13:20 +0300115
116 struct qed_ll2_acquire_data_inputs input;
Arnd Bergmann0629a332017-01-18 15:52:52 +0100117 u32 cid;
118 u8 my_id;
119 u8 queue_id;
120 u8 tx_stats_id;
121 bool b_active;
Mintz, Yuval13c54772017-06-09 17:13:20 +0300122 enum core_tx_dest tx_dest;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300123 u8 tx_stats_en;
124 struct qed_ll2_rx_queue rx_queue;
125 struct qed_ll2_tx_queue tx_queue;
Michal Kalderon0518c122017-06-09 17:13:22 +0300126 struct qed_ll2_cbs cbs;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300127};
128
129/**
130 * @brief qed_ll2_acquire_connection - allocate resources,
131 * starts rx & tx (if relevant) queues pair. Provides
132 * connecion handler as output parameter.
133 *
Mintz, Yuval13c54772017-06-09 17:13:20 +0300134 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300135 * @param cxt - pointer to the hw-function [opaque to some]
Mintz, Yuval13c54772017-06-09 17:13:20 +0300136 * @param data - describes connection parameters
137 * @return int
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300138 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300139int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300140
141/**
142 * @brief qed_ll2_establish_connection - start previously
143 * allocated LL2 queues pair
144 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300145 * @param cxt - pointer to the hw-function [opaque to some]
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300146 * @param p_ptt
147 * @param connection_handle LL2 connection's handle obtained from
148 * qed_ll2_require_connection
149 *
150 * @return 0 on success, failure otherwise
151 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300152int qed_ll2_establish_connection(void *cxt, u8 connection_handle);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300153
154/**
155 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
156 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300157 * @param cxt - pointer to the hw-function [opaque to some]
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300158 * @param connection_handle LL2 connection's handle obtained from
159 * qed_ll2_require_connection
160 * @param addr rx (physical address) buffers to submit
161 * @param cookie
162 * @param notify_fw produce corresponding Rx BD immediately
163 *
164 * @return 0 on success, failure otherwise
165 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300166int qed_ll2_post_rx_buffer(void *cxt,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300167 u8 connection_handle,
168 dma_addr_t addr,
169 u16 buf_len, void *cookie, u8 notify_fw);
170
171/**
172 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
173 * to prepare Tx packet submission to FW.
174 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300175 * @param cxt - pointer to the hw-function [opaque to some]
Mintz, Yuval7c7973b2017-06-09 17:13:18 +0300176 * @param connection_handle
177 * @param pkt - info regarding the tx packet
178 * @param notify_fw - issue doorbell to fw for this packet
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300179 *
180 * @return 0 on success, failure otherwise
181 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300182int qed_ll2_prepare_tx_packet(void *cxt,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300183 u8 connection_handle,
Mintz, Yuval7c7973b2017-06-09 17:13:18 +0300184 struct qed_ll2_tx_pkt_info *pkt,
185 bool notify_fw);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300186
187/**
188 * @brief qed_ll2_release_connection - releases resources
189 * allocated for LL2 connection
190 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300191 * @param cxt - pointer to the hw-function [opaque to some]
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300192 * @param connection_handle LL2 connection's handle obtained from
193 * qed_ll2_require_connection
194 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300195void qed_ll2_release_connection(void *cxt, u8 connection_handle);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300196
197/**
198 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
199 * Tx BD of BDs requested by
200 * qed_ll2_prepare_tx_packet
201 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300202 * @param cxt - pointer to the hw-function [opaque to some]
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300203 * @param connection_handle LL2 connection's handle
204 * obtained from
205 * qed_ll2_require_connection
206 * @param addr
207 * @param nbytes
208 *
209 * @return 0 on success, failure otherwise
210 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300211int qed_ll2_set_fragment_of_tx_packet(void *cxt,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300212 u8 connection_handle,
213 dma_addr_t addr, u16 nbytes);
214
215/**
216 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
217 *
218 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300219 * @param cxt - pointer to the hw-function [opaque to some]
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300220 * @param connection_handle LL2 connection's handle
221 * obtained from
222 * qed_ll2_require_connection
223 *
224 * @return 0 on success, failure otherwise
225 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300226int qed_ll2_terminate_connection(void *cxt, u8 connection_handle);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300227
228/**
229 * @brief qed_ll2_get_stats - get LL2 queue's statistics
230 *
231 *
Michal Kalderon0518c122017-06-09 17:13:22 +0300232 * @param cxt - pointer to the hw-function [opaque to some]
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300233 * @param connection_handle LL2 connection's handle obtained from
234 * qed_ll2_require_connection
235 * @param p_stats
236 *
237 * @return 0 on success, failure otherwise
238 */
Michal Kalderon0518c122017-06-09 17:13:22 +0300239int qed_ll2_get_stats(void *cxt,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300240 u8 connection_handle, struct qed_ll2_stats *p_stats);
241
242/**
243 * @brief qed_ll2_alloc - Allocates LL2 connections set
244 *
245 * @param p_hwfn
246 *
Tomer Tayar3587cb82017-05-21 12:10:56 +0300247 * @return int
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300248 */
Tomer Tayar3587cb82017-05-21 12:10:56 +0300249int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300250
251/**
252 * @brief qed_ll2_setup - Inits LL2 connections set
253 *
254 * @param p_hwfn
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300255 *
256 */
Tomer Tayar3587cb82017-05-21 12:10:56 +0300257void qed_ll2_setup(struct qed_hwfn *p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300258
259/**
260 * @brief qed_ll2_free - Releases LL2 connections set
261 *
262 * @param p_hwfn
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300263 *
264 */
Tomer Tayar3587cb82017-05-21 12:10:56 +0300265void qed_ll2_free(struct qed_hwfn *p_hwfn);
266
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300267#endif