xref: /freebsd/sys/dev/liquidio/base/lio_config.h (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Cavium, Inc. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*  \file  lio_config.h
35  *  \brief Host Driver: Configuration data structures for the host driver.
36  */
37 
38 #ifndef __LIO_CONFIG_H__
39 #define __LIO_CONFIG_H__
40 
41 /*--------------------------CONFIG VALUES------------------------*/
42 
43 /*
44  * The following macros affect the way the driver data structures
45  * are generated for Octeon devices.
46  * They can be modified.
47  */
48 
49 /*
50  * Maximum octeon devices defined as LIO_MAX_IF to support
51  * multiple(<= LIO_MAX_IF) Miniports
52  */
53 #define LIO_MAX_IF			128
54 #define LIO_MAX_DEVICES			LIO_MAX_IF
55 #define LIO_MAX_MULTICAST_ADDR		32
56 
57 /* CN23xx IQ configuration macros */
58 #define LIO_CN23XX_PF_MAX_RINGS		64
59 
60 #define LIO_BR_SIZE			4096
61 
62 #define LIO_CN23XX_PF_MAX_INPUT_QUEUES		LIO_CN23XX_PF_MAX_RINGS
63 #define LIO_CN23XX_MAX_IQ_DESCRIPTORS		2048
64 #define LIO_CN23XX_DEFAULT_IQ_DESCRIPTORS	512
65 #define LIO_CN23XX_MIN_IQ_DESCRIPTORS		128
66 #define LIO_CN23XX_DB_MIN			1
67 #define LIO_CN23XX_DB_TIMEOUT			1
68 
69 #define LIO_CN23XX_PF_MAX_OUTPUT_QUEUES		LIO_CN23XX_PF_MAX_RINGS
70 #define LIO_CN23XX_MAX_OQ_DESCRIPTORS		2048
71 #define LIO_CN23XX_DEFAULT_OQ_DESCRIPTORS	512
72 #define LIO_CN23XX_MIN_OQ_DESCRIPTORS		128
73 #define LIO_CN23XX_OQ_BUF_SIZE			MCLBYTES
74 #define LIO_CN23XX_OQ_PKTS_PER_INTR		128
75 #define LIO_CN23XX_OQ_REFIL_THRESHOLD		16
76 
77 #define LIO_CN23XX_OQ_INTR_PKT			64
78 #define LIO_CN23XX_OQ_INTR_TIME			100
79 #define LIO_CN23XX_DEFAULT_NUM_PORTS		1
80 
81 #define LIO_CN23XX_CFG_IO_QUEUES		LIO_CN23XX_PF_MAX_RINGS
82 
83 #define LIO_CN23XX_DEF_IQ_INTR_THRESHOLD	32
84 #define LIO_CN23XX_PKI_MAX_FRAME_SIZE		65535
85 #define LIO_CN23XX_RAW_FRONT_SIZE		48
86 /*
87  * this is the max jabber value.Any packets greater than this size sent over
88  * DPI will be truncated.
89  */
90 #define LIO_CN23XX_MAX_INPUT_JABBER  (LIO_CN23XX_PKI_MAX_FRAME_SIZE - \
91 				      LIO_CN23XX_RAW_FRONT_SIZE)
92 
93 /* common OCTEON configuration macros */
94 #define LIO_64BYTE_INSTR		64
95 
96 #define LIO_MAX_TXQS_PER_INTF		8
97 #define LIO_MAX_RXQS_PER_INTF		8
98 #define LIO_DEF_TXQS_PER_INTF		4
99 #define LIO_DEF_RXQS_PER_INTF		4
100 
101 /* Macros to get octeon config params */
102 #define LIO_GET_IQ_CFG(cfg)			((cfg)->iq)
103 #define LIO_GET_IQ_MAX_Q_CFG(cfg)		((cfg)->iq.max_iqs)
104 #define LIO_GET_IQ_INSTR_TYPE_CFG(cfg)		((cfg)->iq.instr_type)
105 
106 #define LIO_GET_IQ_INTR_PKT_CFG(cfg)		((cfg)->iq.iq_intr_pkt)
107 
108 #define LIO_GET_OQ_MAX_Q_CFG(cfg)		((cfg)->oq.max_oqs)
109 #define LIO_GET_OQ_PKTS_PER_INTR_CFG(cfg)	((cfg)->oq.pkts_per_intr)
110 #define LIO_GET_OQ_REFILL_THRESHOLD_CFG(cfg)	((cfg)->oq.refill_threshold)
111 #define LIO_GET_OQ_INTR_PKT_CFG(cfg)		((cfg)->oq.oq_intr_pkt)
112 #define LIO_GET_OQ_INTR_TIME_CFG(cfg)		((cfg)->oq.oq_intr_time)
113 
114 #define LIO_GET_NUM_NIC_PORTS_CFG(cfg)		((cfg)->num_nic_ports)
115 #define LIO_GET_NUM_DEF_TX_DESCS_CFG(cfg)	((cfg)->num_def_tx_descs)
116 #define LIO_GET_NUM_DEF_RX_DESCS_CFG(cfg)	((cfg)->num_def_rx_descs)
117 #define LIO_GET_DEF_RX_BUF_SIZE_CFG(cfg)	((cfg)->def_rx_buf_size)
118 
119 #define LIO_GET_NUM_RX_DESCS_NIC_IF_CFG(cfg, idx)	\
120 		((cfg)->nic_if_cfg[idx].num_rx_descs)
121 #define LIO_GET_NUM_TX_DESCS_NIC_IF_CFG(cfg, idx)	\
122 		((cfg)->nic_if_cfg[idx].num_tx_descs)
123 #define LIO_GET_NUM_RX_BUF_SIZE_NIC_IF_CFG(cfg, idx)	\
124 		((cfg)->nic_if_cfg[idx].rx_buf_size)
125 
126 #define LIO_GET_IS_SLI_BP_ON_CFG(cfg)	((cfg)->misc.enable_sli_oq_bp)
127 
128 /* Max IOQs per OCTEON Link */
129 #define LIO_MAX_IOQS_PER_NICIF			64
130 
131 #define LIO_SET_NUM_RX_DESCS_NIC_IF(cfg, idx, value)		\
132 		((cfg)->nic_if_cfg[idx].num_rx_descs = value)
133 #define LIO_SET_NUM_TX_DESCS_NIC_IF(cfg, idx, value)		\
134 		((cfg)->nic_if_cfg[idx].num_tx_descs = value)
135 
136 /* TX/RX process pkt budget */
137 #define LIO_DEFAULT_TX_PKTS_PROCESS_BUDGET	64
138 #define LIO_DEFAULT_RX_PKTS_PROCESS_BUDGET	64
139 
140 enum lio_card_type {
141 	LIO_23XX	/* 23xx */
142 };
143 
144 #define LIO_23XX_NAME  "23xx"
145 
146 /*
147  *  Structure to define the configuration attributes for each Input queue.
148  *  Applicable to all Octeon processors
149  */
150 struct lio_iq_config {
151 #if BYTE_ORDER == BIG_ENDIAN
152 	uint64_t	reserved:16;
153 
154 	/* Tx interrupt packets. Applicable to 23xx only */
155 	uint64_t	iq_intr_pkt:16;
156 
157 	/* Minimum ticks to wait before checking for pending instructions. */
158 	uint64_t	db_timeout:16;
159 
160 	/*
161 	 *  Minimum number of commands pending to be posted to Octeon
162 	 *  before driver hits the Input queue doorbell.
163 	 */
164 	uint64_t	db_min:8;
165 
166 	/* Command size - 32 or 64 bytes */
167 	uint64_t	instr_type:32;
168 
169 	/*
170 	 *  Pending list size (usually set to the sum of the size of all Input
171 	 *  queues)
172 	 */
173 	uint64_t	pending_list_size:32;
174 
175 	/* Max number of IQs available */
176 	uint64_t	max_iqs:8;
177 
178 #else	/* BYTE_ORDER != BIG_ENDIAN */
179 
180 	/* Max number of IQs available */
181 	uint64_t	max_iqs:8;
182 
183 	/*
184 	 *  Pending list size (usually set to the sum of the size of all Input
185 	 *  queues)
186 	 */
187 	uint64_t	pending_list_size:32;
188 
189 	/* Command size - 32 or 64 bytes */
190 	uint64_t	instr_type:32;
191 
192 	/*
193 	 *  Minimum number of commands pending to be posted to Octeon
194 	 *  before driver hits the Input queue doorbell.
195 	 */
196 	uint64_t	db_min:8;
197 
198 	/* Minimum ticks to wait before checking for pending instructions. */
199 	uint64_t	db_timeout:16;
200 
201 	/* Tx interrupt packets. Applicable to 23xx only */
202 	uint64_t	iq_intr_pkt:16;
203 
204 	uint64_t	reserved:16;
205 
206 #endif	/* BYTE_ORDER == BIG_ENDIAN */
207 };
208 
209 /*
210  *  Structure to define the configuration attributes for each Output queue.
211  *  Applicable to all Octeon processors
212  */
213 struct lio_oq_config {
214 #if BYTE_ORDER == BIG_ENDIAN
215 	uint64_t	reserved:16;
216 
217 	uint64_t	pkts_per_intr:16;
218 
219 	/*
220 	 *  Interrupt Coalescing (Time Interval). Octeon will interrupt the
221 	 *  host if atleast one packet was sent in the time interval specified
222 	 *  by this field. The driver uses time interval interrupt coalescing
223 	 *  by default. The time is specified in microseconds.
224 	 */
225 	uint64_t	oq_intr_time:16;
226 
227 	/*
228 	 *  Interrupt Coalescing (Packet Count). Octeon will interrupt the host
229 	 *  only if it sent as many packets as specified by this field.
230 	 *  The driver
231 	 *  usually does not use packet count interrupt coalescing.
232 	 */
233 	uint64_t	oq_intr_pkt:16;
234 
235 	/*
236 	 *   The number of buffers that were consumed during packet processing by
237 	 *   the driver on this Output queue before the driver attempts to
238 	 *   replenish
239 	 *   the descriptor ring with new buffers.
240 	 */
241 	uint64_t	refill_threshold:16;
242 
243 	/* Max number of OQs available */
244 	uint64_t	max_oqs:8;
245 
246 #else	/* BYTE_ORDER != BIG_ENDIAN */
247 
248 	/* Max number of OQs available */
249 	uint64_t	max_oqs:8;
250 
251 	/*
252 	 *   The number of buffers that were consumed during packet processing by
253 	 *   the driver on this Output queue before the driver attempts to
254 	 *   replenish
255 	 *   the descriptor ring with new buffers.
256 	 */
257 	uint64_t	refill_threshold:16;
258 
259 	/*
260 	 *  Interrupt Coalescing (Packet Count). Octeon will interrupt the host
261 	 *  only if it sent as many packets as specified by this field.
262 	 *  The driver
263 	 *  usually does not use packet count interrupt coalescing.
264 	 */
265 	uint64_t	oq_intr_pkt:16;
266 
267 	/*
268 	 *  Interrupt Coalescing (Time Interval). Octeon will interrupt the
269 	 *  host if atleast one packet was sent in the time interval specified
270 	 *  by this field. The driver uses time interval interrupt coalescing
271 	 *  by default.  The time is specified in microseconds.
272 	 */
273 	uint64_t	oq_intr_time:16;
274 
275 	uint64_t	pkts_per_intr:16;
276 
277 	uint64_t	reserved:16;
278 #endif	/* BYTE_ORDER == BIG_ENDIAN */
279 
280 };
281 
282 /*
283  *  This structure conatins the NIC link configuration attributes,
284  *  common for all the OCTEON Modles.
285  */
286 struct lio_nic_if_config {
287 #if BYTE_ORDER == BIG_ENDIAN
288 	uint64_t	reserved:56;
289 
290 	uint64_t	base_queue:16;
291 
292 	uint64_t	gmx_port_id:8;
293 
294 	/*
295 	 * mbuf size, We need not change buf size even for Jumbo frames.
296 	 * Octeon can send jumbo frames in 4 consecutive descriptors,
297 	 */
298 	uint64_t	rx_buf_size:16;
299 
300 	/* Num of desc for tx rings */
301 	uint64_t	num_tx_descs:16;
302 
303 	/* Num of desc for rx rings */
304 	uint64_t	num_rx_descs:16;
305 
306 	/* Actual configured value. Range could be: 1...max_rxqs */
307 	uint64_t	num_rxqs:16;
308 
309 	/* Max Rxqs: Half for each of the two ports :max_oq/2  */
310 	uint64_t	max_rxqs:16;
311 
312 	/* Actual configured value. Range could be: 1...max_txqs */
313 	uint64_t	num_txqs:16;
314 
315 	/* Max Txqs: Half for each of the two ports :max_iq/2 */
316 	uint64_t	max_txqs:16;
317 
318 #else	/* BYTE_ORDER != BIG_ENDIAN */
319 
320 	/* Max Txqs: Half for each of the two ports :max_iq/2 */
321 	uint64_t	max_txqs:16;
322 
323 	/* Actual configured value. Range could be: 1...max_txqs */
324 	uint64_t	num_txqs:16;
325 
326 	/* Max Rxqs: Half for each of the two ports :max_oq/2  */
327 	uint64_t	max_rxqs:16;
328 
329 	/* Actual configured value. Range could be: 1...max_rxqs */
330 	uint64_t	num_rxqs:16;
331 
332 	/* Num of desc for rx rings */
333 	uint64_t	num_rx_descs:16;
334 
335 	/* Num of desc for tx rings */
336 	uint64_t	num_tx_descs:16;
337 
338 	/*
339 	 * mbuf size, We need not change buf size even for Jumbo frames.
340 	 * Octeon can send jumbo frames in 4 consecutive descriptors,
341 	 */
342 	uint64_t	rx_buf_size:16;
343 
344 	uint64_t	gmx_port_id:8;
345 
346 	uint64_t	base_queue:16;
347 
348 	uint64_t	reserved:56;
349 #endif	/* BYTE_ORDER == BIG_ENDIAN */
350 
351 };
352 
353 /*
354  *  Structure to define the configuration attributes for meta data.
355  *  Applicable to all Octeon processors.
356  */
357 
358 struct lio_misc_config {
359 #if BYTE_ORDER == BIG_ENDIAN
360 	/* Host link status polling period */
361 	uint64_t	host_link_query_interval:32;
362 	/* Oct link status polling period */
363 	uint64_t	oct_link_query_interval:32;
364 
365 	uint64_t	enable_sli_oq_bp:1;
366 	/* Control IQ Group */
367 	uint64_t	ctrlq_grp:4;
368 
369 #else	/* BYTE_ORDER != BIG_ENDIAN */
370 
371 	/* Control IQ Group */
372 	uint64_t	ctrlq_grp:4;
373 	/* BP for SLI OQ */
374 	uint64_t	enable_sli_oq_bp:1;
375 	/* Host link status polling period */
376 	uint64_t	oct_link_query_interval:32;
377 	/* Oct link status polling period */
378 	uint64_t	host_link_query_interval:32;
379 
380 #endif	/* BYTE_ORDER == BIG_ENDIAN */
381 };
382 
383 /* Structure to define the configuration for all OCTEON processors. */
384 struct lio_config {
385 	uint16_t	card_type;
386 	char		*card_name;
387 
388 	/* Input Queue attributes. */
389 	struct lio_iq_config iq;
390 
391 	/* Output Queue attributes. */
392 	struct lio_oq_config oq;
393 
394 	/* NIC Port Configuration */
395 	struct lio_nic_if_config nic_if_cfg[LIO_MAX_IF];
396 
397 	/* Miscellaneous attributes */
398 	struct lio_misc_config	misc;
399 
400 	int		num_nic_ports;
401 
402 	int		num_def_tx_descs;
403 
404 	/* Num of desc for rx rings */
405 	int		num_def_rx_descs;
406 
407 	int		def_rx_buf_size;
408 
409 };
410 
411 /* The following config values are fixed and should not be modified. */
412 /* Maximum address space to be mapped for Octeon's BAR1 index-based access. */
413 #define LIO_MAX_BAR1_MAP_INDEX		2
414 
415 /*
416  * Response lists - 1 ordered, 1 unordered-blocking, 1 unordered-nonblocking
417  * NoResponse Lists are now maintained with each IQ. (Dec' 2007).
418  */
419 #define LIO_MAX_RESPONSE_LISTS		4
420 
421 /*
422  * Opcode hash bits. The opcode is hashed on the lower 6-bits to lookup the
423  * dispatch table.
424  */
425 #define LIO_OPCODE_MASK_BITS		6
426 
427 /* Mask for the 6-bit lookup hash */
428 #define LIO_OPCODE_MASK			0x3f
429 
430 /* Size of the dispatch table. The 6-bit hash can index into 2^6 entries */
431 #define LIO_DISPATCH_LIST_SIZE		BIT(LIO_OPCODE_MASK_BITS)
432 
433 #define LIO_MAX_INSTR_QUEUES(oct)	LIO_CN23XX_PF_MAX_INPUT_QUEUES
434 #define LIO_MAX_OUTPUT_QUEUES(oct)	LIO_CN23XX_PF_MAX_OUTPUT_QUEUES
435 
436 #define LIO_MAX_POSSIBLE_INSTR_QUEUES	LIO_CN23XX_PF_MAX_INPUT_QUEUES
437 #define LIO_MAX_POSSIBLE_OUTPUT_QUEUES	LIO_CN23XX_PF_MAX_OUTPUT_QUEUES
438 #endif	/* __LIO_CONFIG_H__  */
439