blob: a037c4845928acd5558130a161c0b77c8f773240 [file] [log] [blame]
Yuval Mintz0a7fb112016-10-01 21:59:55 +03001/* QLogic qed NIC Driver
2 *
3 * Copyright (c) 2015 QLogic Corporation
4 *
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
7 * this source tree.
8 */
9
10#ifndef _QED_LL2_H
11#define _QED_LL2_H
12
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>
21#include "qed.h"
22#include "qed_hsi.h"
23#include "qed_sp.h"
24
25#define QED_MAX_NUM_OF_LL2_CONNECTIONS (4)
26
27enum qed_ll2_conn_type {
28 QED_LL2_TYPE_RESERVED,
29 QED_LL2_TYPE_ISCSI,
30 QED_LL2_TYPE_TEST,
31 QED_LL2_TYPE_ISCSI_OOO,
32 QED_LL2_TYPE_RESERVED2,
33 QED_LL2_TYPE_ROCE,
34 QED_LL2_TYPE_RESERVED3,
35 MAX_QED_LL2_RX_CONN_TYPE
36};
37
38struct qed_ll2_rx_packet {
39 struct list_head list_entry;
40 struct core_rx_bd_with_buff_len *rxq_bd;
41 dma_addr_t rx_buf_addr;
42 u16 buf_length;
43 void *cookie;
44 u8 placement_offset;
45 u16 parse_flags;
46 u16 packet_length;
47 u16 vlan;
48 u32 opaque_data[2];
49};
50
51struct qed_ll2_tx_packet {
52 struct list_head list_entry;
53 u16 bd_used;
54 u16 vlan;
55 u16 l4_hdr_offset_w;
56 u8 bd_flags;
57 bool notify_fw;
58 void *cookie;
59
60 struct {
61 struct core_tx_bd *txq_bd;
62 dma_addr_t tx_frag;
63 u16 frag_len;
64 } bds_set[ETH_TX_MAX_BDS_PER_NON_LSO_PACKET];
65};
66
67struct qed_ll2_rx_queue {
68 /* Lock protecting the Rx queue manipulation */
69 spinlock_t lock;
70 struct qed_chain rxq_chain;
71 struct qed_chain rcq_chain;
72 u8 rx_sb_index;
73 bool b_cb_registred;
74 __le16 *p_fw_cons;
75 struct list_head active_descq;
76 struct list_head free_descq;
77 struct list_head posting_descq;
78 struct qed_ll2_rx_packet *descq_array;
79 void __iomem *set_prod_addr;
80};
81
82struct qed_ll2_tx_queue {
83 /* Lock protecting the Tx queue manipulation */
84 spinlock_t lock;
85 struct qed_chain txq_chain;
86 u8 tx_sb_index;
87 bool b_cb_registred;
88 __le16 *p_fw_cons;
89 struct list_head active_descq;
90 struct list_head free_descq;
91 struct list_head sending_descq;
92 struct qed_ll2_tx_packet *descq_array;
93 struct qed_ll2_tx_packet *cur_send_packet;
94 struct qed_ll2_tx_packet cur_completing_packet;
95 u16 cur_completing_bd_idx;
96 void __iomem *doorbell_addr;
97 u16 bds_idx;
98 u16 cur_send_frag_num;
99 u16 cur_completing_frag_num;
100 bool b_completing_packet;
101};
102
103struct qed_ll2_info {
104 /* Lock protecting the state of LL2 */
105 struct mutex mutex;
106 enum qed_ll2_conn_type conn_type;
107 u32 cid;
108 u8 my_id;
109 u8 queue_id;
110 u8 tx_stats_id;
111 bool b_active;
112 u16 mtu;
113 u8 rx_drop_ttl0_flg;
114 u8 rx_vlan_removal_en;
115 u8 tx_tc;
116 enum core_tx_dest tx_dest;
117 enum core_error_handle ai_err_packet_too_big;
118 enum core_error_handle ai_err_no_buf;
119 u8 tx_stats_en;
120 struct qed_ll2_rx_queue rx_queue;
121 struct qed_ll2_tx_queue tx_queue;
122};
123
124/**
125 * @brief qed_ll2_acquire_connection - allocate resources,
126 * starts rx & tx (if relevant) queues pair. Provides
127 * connecion handler as output parameter.
128 *
129 * @param p_hwfn
130 * @param p_params Contain various configuration properties
131 * @param rx_num_desc
132 * @param tx_num_desc
133 *
134 * @param p_connection_handle Output container for LL2 connection's handle
135 *
136 * @return 0 on success, failure otherwise
137 */
138int qed_ll2_acquire_connection(struct qed_hwfn *p_hwfn,
139 struct qed_ll2_info *p_params,
140 u16 rx_num_desc,
141 u16 tx_num_desc,
142 u8 *p_connection_handle);
143
144/**
145 * @brief qed_ll2_establish_connection - start previously
146 * allocated LL2 queues pair
147 *
148 * @param p_hwfn
149 * @param p_ptt
150 * @param connection_handle LL2 connection's handle obtained from
151 * qed_ll2_require_connection
152 *
153 * @return 0 on success, failure otherwise
154 */
155int qed_ll2_establish_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
156
157/**
158 * @brief qed_ll2_post_rx_buffers - submit buffers to LL2 Rx queue.
159 *
160 * @param p_hwfn
161 * @param connection_handle LL2 connection's handle obtained from
162 * qed_ll2_require_connection
163 * @param addr rx (physical address) buffers to submit
164 * @param cookie
165 * @param notify_fw produce corresponding Rx BD immediately
166 *
167 * @return 0 on success, failure otherwise
168 */
169int qed_ll2_post_rx_buffer(struct qed_hwfn *p_hwfn,
170 u8 connection_handle,
171 dma_addr_t addr,
172 u16 buf_len, void *cookie, u8 notify_fw);
173
174/**
175 * @brief qed_ll2_prepare_tx_packet - request for start Tx BD
176 * to prepare Tx packet submission to FW.
177 *
178 * @param p_hwfn
179 * @param connection_handle LL2 connection's handle obtained from
180 * qed_ll2_require_connection
181 * @param num_of_bds a number of requested BD equals a number of
182 * fragments in Tx packet
183 * @param vlan VLAN to insert to packet (if insertion set)
184 * @param bd_flags
185 * @param l4_hdr_offset_w L4 Header Offset from start of packet
186 * (in words). This is needed if both l4_csum
187 * and ipv6_ext are set
188 * @param first_frag
189 * @param first_frag_len
190 * @param cookie
191 *
192 * @param notify_fw
193 *
194 * @return 0 on success, failure otherwise
195 */
196int qed_ll2_prepare_tx_packet(struct qed_hwfn *p_hwfn,
197 u8 connection_handle,
198 u8 num_of_bds,
199 u16 vlan,
200 u8 bd_flags,
201 u16 l4_hdr_offset_w,
202 dma_addr_t first_frag,
203 u16 first_frag_len, void *cookie, u8 notify_fw);
204
205/**
206 * @brief qed_ll2_release_connection - releases resources
207 * allocated for LL2 connection
208 *
209 * @param p_hwfn
210 * @param connection_handle LL2 connection's handle obtained from
211 * qed_ll2_require_connection
212 */
213void qed_ll2_release_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
214
215/**
216 * @brief qed_ll2_set_fragment_of_tx_packet - provides fragments to fill
217 * Tx BD of BDs requested by
218 * qed_ll2_prepare_tx_packet
219 *
220 * @param p_hwfn
221 * @param connection_handle LL2 connection's handle
222 * obtained from
223 * qed_ll2_require_connection
224 * @param addr
225 * @param nbytes
226 *
227 * @return 0 on success, failure otherwise
228 */
229int qed_ll2_set_fragment_of_tx_packet(struct qed_hwfn *p_hwfn,
230 u8 connection_handle,
231 dma_addr_t addr, u16 nbytes);
232
233/**
234 * @brief qed_ll2_terminate_connection - stops Tx/Rx queues
235 *
236 *
237 * @param p_hwfn
238 * @param connection_handle LL2 connection's handle
239 * obtained from
240 * qed_ll2_require_connection
241 *
242 * @return 0 on success, failure otherwise
243 */
244int qed_ll2_terminate_connection(struct qed_hwfn *p_hwfn, u8 connection_handle);
245
246/**
247 * @brief qed_ll2_get_stats - get LL2 queue's statistics
248 *
249 *
250 * @param p_hwfn
251 * @param connection_handle LL2 connection's handle obtained from
252 * qed_ll2_require_connection
253 * @param p_stats
254 *
255 * @return 0 on success, failure otherwise
256 */
257int qed_ll2_get_stats(struct qed_hwfn *p_hwfn,
258 u8 connection_handle, struct qed_ll2_stats *p_stats);
259
260/**
261 * @brief qed_ll2_alloc - Allocates LL2 connections set
262 *
263 * @param p_hwfn
264 *
265 * @return pointer to alocated qed_ll2_info or NULL
266 */
267struct qed_ll2_info *qed_ll2_alloc(struct qed_hwfn *p_hwfn);
268
269/**
270 * @brief qed_ll2_setup - Inits LL2 connections set
271 *
272 * @param p_hwfn
273 * @param p_ll2_connections
274 *
275 */
276void qed_ll2_setup(struct qed_hwfn *p_hwfn,
277 struct qed_ll2_info *p_ll2_connections);
278
279/**
280 * @brief qed_ll2_free - Releases LL2 connections set
281 *
282 * @param p_hwfn
283 * @param p_ll2_connections
284 *
285 */
286void qed_ll2_free(struct qed_hwfn *p_hwfn,
287 struct qed_ll2_info *p_ll2_connections);
288
289#endif