blob: 96af50b733e8f62bc7fc6dfcfe0371a0c4ce4022 [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
50enum qed_ll2_conn_type {
Arun Easi1e128c82017-02-15 06:28:22 -080051 QED_LL2_TYPE_FCOE,
Yuval Mintz0a7fb112016-10-01 21:59:55 +030052 QED_LL2_TYPE_ISCSI,
53 QED_LL2_TYPE_TEST,
54 QED_LL2_TYPE_ISCSI_OOO,
55 QED_LL2_TYPE_RESERVED2,
56 QED_LL2_TYPE_ROCE,
57 QED_LL2_TYPE_RESERVED3,
58 MAX_QED_LL2_RX_CONN_TYPE
59};
60
61struct qed_ll2_rx_packet {
62 struct list_head list_entry;
63 struct core_rx_bd_with_buff_len *rxq_bd;
64 dma_addr_t rx_buf_addr;
65 u16 buf_length;
66 void *cookie;
67 u8 placement_offset;
68 u16 parse_flags;
69 u16 packet_length;
70 u16 vlan;
71 u32 opaque_data[2];
72};
73
74struct qed_ll2_tx_packet {
75 struct list_head list_entry;
76 u16 bd_used;
77 u16 vlan;
78 u16 l4_hdr_offset_w;
79 u8 bd_flags;
80 bool notify_fw;
81 void *cookie;
82
83 struct {
84 struct core_tx_bd *txq_bd;
85 dma_addr_t tx_frag;
86 u16 frag_len;
87 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
88};
89
90struct qed_ll2_rx_queue {
91 /* Lock protecting the Rx queue manipulation */
92 spinlock_t lock;
93 struct qed_chain rxq_chain;
94 struct qed_chain rcq_chain;
95 u8 rx_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 posting_descq;
101 struct qed_ll2_rx_packet *descq_array;
102 void __iomem *set_prod_addr;
103};
104
105struct qed_ll2_tx_queue {
106 /* Lock protecting the Tx queue manipulation */
107 spinlock_t lock;
108 struct qed_chain txq_chain;
109 u8 tx_sb_index;
110 bool b_cb_registred;
111 __le16 *p_fw_cons;
112 struct list_head active_descq;
113 struct list_head free_descq;
114 struct list_head sending_descq;
115 struct qed_ll2_tx_packet *descq_array;
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 u16 bds_idx;
121 u16 cur_send_frag_num;
122 u16 cur_completing_frag_num;
123 bool b_completing_packet;
124};
125
Arnd Bergmann0629a332017-01-18 15:52:52 +0100126struct qed_ll2_conn {
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300127 enum qed_ll2_conn_type conn_type;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300128 u16 mtu;
129 u8 rx_drop_ttl0_flg;
130 u8 rx_vlan_removal_en;
131 u8 tx_tc;
132 enum core_tx_dest tx_dest;
133 enum core_error_handle ai_err_packet_too_big;
134 enum core_error_handle ai_err_no_buf;
Arnd Bergmann0629a332017-01-18 15:52:52 +0100135 u8 gsi_enable;
136};
137
138struct qed_ll2_info {
139 /* Lock protecting the state of LL2 */
140 struct mutex mutex;
141 struct qed_ll2_conn conn;
142 u32 cid;
143 u8 my_id;
144 u8 queue_id;
145 u8 tx_stats_id;
146 bool b_active;
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300147 u8 tx_stats_en;
148 struct qed_ll2_rx_queue rx_queue;
149 struct qed_ll2_tx_queue tx_queue;
150};
151
152/**
153 * @brief qed_ll2_acquire_connection - allocate resources,
154 * starts rx & tx (if relevant) queues pair. Provides
155 * connecion handler as output parameter.
156 *
157 * @param p_hwfn
158 * @param p_params Contain various configuration properties
159 * @param rx_num_desc
160 * @param tx_num_desc
161 *
162 * @param p_connection_handle Output container for LL2 connection's handle
163 *
164 * @return 0 on success, failure otherwise
165 */
166int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
Arnd Bergmann0629a332017-01-18 15:52:52 +0100167 struct qed_ll2_conn *p_params,
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300168 u16 rx_num_desc,
169 u16 tx_num_desc,
170 u8 *p_connection_handle);
171
172/**
173 * @brief qed_ll2_establish_connection - start previously
174 * allocated LL2 queues pair
175 *
176 * @param p_hwfn
177 * @param p_ptt
178 * @param connection_handle LL2 connection's handle obtained from
179 * qed_ll2_require_connection
180 *
181 * @return 0 on success, failure otherwise
182 */
183int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
184
185/**
186 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
187 *
188 * @param p_hwfn
189 * @param connection_handle LL2 connection's handle obtained from
190 * qed_ll2_require_connection
191 * @param addr rx (physical address) buffers to submit
192 * @param cookie
193 * @param notify_fw produce corresponding Rx BD immediately
194 *
195 * @return 0 on success, failure otherwise
196 */
197int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
198 u8 connection_handle,
199 dma_addr_t addr,
200 u16 buf_len, void *cookie, u8 notify_fw);
201
202/**
203 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
204 * to prepare Tx packet submission to FW.
205 *
206 * @param p_hwfn
Mintz, Yuval7c7973b2017-06-09 17:13:18 +0300207 * @param connection_handle
208 * @param pkt - info regarding the tx packet
209 * @param notify_fw - issue doorbell to fw for this packet
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300210 *
211 * @return 0 on success, failure otherwise
212 */
213int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
214 u8 connection_handle,
Mintz, Yuval7c7973b2017-06-09 17:13:18 +0300215 struct qed_ll2_tx_pkt_info *pkt,
216 bool notify_fw);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300217
218/**
219 * @brief qed_ll2_release_connection - releases resources
220 * allocated for LL2 connection
221 *
222 * @param p_hwfn
223 * @param connection_handle LL2 connection's handle obtained from
224 * qed_ll2_require_connection
225 */
226void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
227
228/**
229 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
230 * Tx BD of BDs requested by
231 * qed_ll2_prepare_tx_packet
232 *
233 * @param p_hwfn
234 * @param connection_handle LL2 connection's handle
235 * obtained from
236 * qed_ll2_require_connection
237 * @param addr
238 * @param nbytes
239 *
240 * @return 0 on success, failure otherwise
241 */
242int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
243 u8 connection_handle,
244 dma_addr_t addr, u16 nbytes);
245
246/**
247 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
248 *
249 *
250 * @param p_hwfn
251 * @param connection_handle LL2 connection's handle
252 * obtained from
253 * qed_ll2_require_connection
254 *
255 * @return 0 on success, failure otherwise
256 */
257int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
258
259/**
260 * @brief qed_ll2_get_stats - get LL2 queue's statistics
261 *
262 *
263 * @param p_hwfn
264 * @param connection_handle LL2 connection's handle obtained from
265 * qed_ll2_require_connection
266 * @param p_stats
267 *
268 * @return 0 on success, failure otherwise
269 */
270int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
271 u8 connection_handle, struct qed_ll2_stats *p_stats);
272
273/**
274 * @brief qed_ll2_alloc - Allocates LL2 connections set
275 *
276 * @param p_hwfn
277 *
Tomer Tayar3587cb82017-05-21 12:10:56 +0300278 * @return int
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300279 */
Tomer Tayar3587cb82017-05-21 12:10:56 +0300280int qed_ll2_alloc(struct qed_hwfn *p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300281
282/**
283 * @brief qed_ll2_setup - Inits LL2 connections set
284 *
285 * @param p_hwfn
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300286 *
287 */
Tomer Tayar3587cb82017-05-21 12:10:56 +0300288void qed_ll2_setup(struct qed_hwfn *p_hwfn);
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300289
290/**
291 * @brief qed_ll2_free - Releases LL2 connections set
292 *
293 * @param p_hwfn
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300294 *
295 */
Tomer Tayar3587cb82017-05-21 12:10:56 +0300296void qed_ll2_free(struct qed_hwfn *p_hwfn);
297
Yuval Mintz0a7fb112016-10-01 21:59:55 +0300298#endif