]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/nxge/include/xgehal-fifo.h
This commit was generated by cvs2svn to compensate for changes in r172771,
[FreeBSD/FreeBSD.git] / sys / dev / nxge / include / xgehal-fifo.h
1 /*-
2  * Copyright (c) 2002-2007 Neterion, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 /*
30  *  FileName :    xgehal-fifo.h
31  *
32  *  Description:  Tx fifo object functionality
33  *
34  *  Created:      19 May 2004
35  */
36
37 #ifndef XGE_HAL_FIFO_H
38 #define XGE_HAL_FIFO_H
39
40 #include <dev/nxge/include/xgehal-channel.h>
41 #include <dev/nxge/include/xgehal-config.h>
42 #include <dev/nxge/include/xgehal-mm.h>
43
44 __EXTERN_BEGIN_DECLS
45
46 /* HW fifo configuration */
47 #define XGE_HAL_FIFO_INT_PER_LIST_THRESHOLD     65
48 #define XGE_HAL_FIFO_MAX_WRR                    5
49 #define XGE_HAL_FIFO_MAX_PARTITION              4
50 #define XGE_HAL_FIFO_MAX_WRR_STATE              36
51 #define XGE_HAL_FIFO_HW_PAIR_OFFSET             0x20000
52
53 /* HW FIFO Weight Calender */
54 #define XGE_HAL_FIFO_WRR_0      0x0706050407030602ULL
55 #define XGE_HAL_FIFO_WRR_1      0x0507040601070503ULL
56 #define XGE_HAL_FIFO_WRR_2      0x0604070205060700ULL
57 #define XGE_HAL_FIFO_WRR_3      0x0403060705010207ULL
58 #define XGE_HAL_FIFO_WRR_4      0x0604050300000000ULL
59 /*
60  * xge_hal_fifo_hw_pair_t
61  *
62  * Represent a single fifo in the BAR1 memory space.
63  */
64 typedef struct {
65         u64 txdl_pointer; /* offset 0x0 */
66
67         u64 reserved[2];
68
69         u64 list_control; /* offset 0x18 */
70 #define XGE_HAL_TX_FIFO_LAST_TXD_NUM( val)     vBIT(val,0,8)
71 #define XGE_HAL_TX_FIFO_FIRST_LIST             BIT(14)
72 #define XGE_HAL_TX_FIFO_LAST_LIST              BIT(15)
73 #define XGE_HAL_TX_FIFO_FIRSTNLAST_LIST        vBIT(3,14,2)
74 #define XGE_HAL_TX_FIFO_SPECIAL_FUNC           BIT(23)
75 #define XGE_HAL_TX_FIFO_NO_SNOOP(n)            vBIT(n,30,2)
76 } xge_hal_fifo_hw_pair_t;
77
78
79 /* Bad TxDL transfer codes */
80 #define XGE_HAL_TXD_T_CODE_OK                   0x0
81 #define XGE_HAL_TXD_T_CODE_UNUSED_1             0x1
82 #define XGE_HAL_TXD_T_CODE_ABORT_BUFFER         0x2
83 #define XGE_HAL_TXD_T_CODE_ABORT_DTOR           0x3
84 #define XGE_HAL_TXD_T_CODE_UNUSED_5             0x5
85 #define XGE_HAL_TXD_T_CODE_PARITY               0x7
86 #define XGE_HAL_TXD_T_CODE_LOSS_OF_LINK         0xA
87 #define XGE_HAL_TXD_T_CODE_GENERAL_ERR          0xF
88
89
90 /**
91  * struct xge_hal_fifo_txd_t - TxD.
92  * @control_1: Control_1.
93  * @control_2: Control_2.
94  * @buffer_pointer: Buffer_Address.
95  * @host_control: Host_Control.Opaque 64bit data stored by ULD inside the Xframe
96  *            descriptor prior to posting the latter on the channel
97  *            via xge_hal_fifo_dtr_post() or xge_hal_ring_dtr_post().
98  *            The %host_control is returned as is to the ULD with each
99  *            completed descriptor.
100  *
101  * Transmit descriptor (TxD).Fifo descriptor contains configured number
102  * (list) of TxDs. * For more details please refer to Xframe User Guide,
103  * Section 5.4.2 "Transmit Descriptor (TxD) Format".
104  */
105 typedef struct xge_hal_fifo_txd_t {
106         u64 control_1;
107 #define XGE_HAL_TXD_LIST_OWN_XENA       BIT(7)
108 #define XGE_HAL_TXD_T_CODE              (BIT(12)|BIT(13)|BIT(14)|BIT(15))
109 #define XGE_HAL_GET_TXD_T_CODE(val)     ((val & XGE_HAL_TXD_T_CODE)>>48)
110 #define XGE_HAL_SET_TXD_T_CODE(x, val)  (x |= (((u64)val & 0xF) << 48))
111 #define XGE_HAL_TXD_GATHER_CODE         (BIT(22) | BIT(23))
112 #define XGE_HAL_TXD_GATHER_CODE_FIRST   BIT(22)
113 #define XGE_HAL_TXD_GATHER_CODE_LAST    BIT(23)
114 #define XGE_HAL_TXD_NO_LSO                              0
115 #define XGE_HAL_TXD_UDF_COF                             1
116 #define XGE_HAL_TXD_TCP_LSO                             2
117 #define XGE_HAL_TXD_UDP_LSO                             3
118 #define XGE_HAL_TXD_LSO_COF_CTRL(val)   vBIT(val,30,2)
119 #define XGE_HAL_TXD_TCP_LSO_MSS(val)    vBIT(val,34,14)
120 #define XGE_HAL_TXD_BUFFER0_SIZE(val)   vBIT(val,48,16)
121 #define XGE_HAL_TXD_GET_LSO_BYTES_SENT(val) ((val & vBIT(0xFFFF,16,16))>>32)
122         u64 control_2;
123 #define XGE_HAL_TXD_TX_CKO_CONTROL      (BIT(5)|BIT(6)|BIT(7))
124 #define XGE_HAL_TXD_TX_CKO_IPV4_EN      BIT(5)
125 #define XGE_HAL_TXD_TX_CKO_TCP_EN       BIT(6)
126 #define XGE_HAL_TXD_TX_CKO_UDP_EN       BIT(7)
127 #define XGE_HAL_TXD_VLAN_ENABLE         BIT(15)
128 #define XGE_HAL_TXD_VLAN_TAG(val)       vBIT(val,16,16)
129 #define XGE_HAL_TXD_INT_NUMBER(val)     vBIT(val,34,6)
130 #define XGE_HAL_TXD_INT_TYPE_PER_LIST   BIT(47)
131 #define XGE_HAL_TXD_INT_TYPE_UTILZ      BIT(46)
132 #define XGE_HAL_TXD_SET_MARKER          vBIT(0x6,0,4)
133
134         u64 buffer_pointer;
135
136         u64 host_control;
137
138 } xge_hal_fifo_txd_t;
139
140 typedef xge_hal_fifo_txd_t* xge_hal_fifo_txdl_t;
141
142 /**
143  * struct xge_hal_fifo_t - Fifo channel.
144  * @channel: Channel "base" of this fifo, the common part of all HAL
145  *           channels.
146  * @post_lock_ptr: Points to a lock that serializes (pointer, control) PIOs.
147  *           Note that for Xena the serialization is done across all device
148  *           fifos.
149  * @hw_pair: Per-fifo (Pointer, Control) pair used to send descriptors to the
150  *           Xframe hardware (for details see Xframe user guide).
151  * @config: Fifo configuration, part of device configuration
152  *          (see xge_hal_device_config_t{}).
153  * @no_snoop_bits: See xge_hal_fifo_config_t{}.
154  * @txdl_per_memblock: Number of TxDLs (TxD lists) per memblock.
155  * on TxDL please refer to Xframe UG.
156  * @interrupt_type: FIXME: to-be-defined.
157  * @txdl_size: Configured TxDL size (i.e., number of TxDs in a list), plus
158  *             per-TxDL HAL private space (xge_hal_fifo_txdl_priv_t).
159  * @priv_size: Per-Tx descriptor space reserved for upper-layer driver
160  *             usage.
161  * @mempool: Memory pool, from which descriptors get allocated.
162  * @align_size: TBD
163  *
164  * Fifo channel.
165  * Note: The structure is cache line aligned.
166  */
167 typedef struct xge_hal_fifo_t {
168         xge_hal_channel_t       channel;
169         spinlock_t              *post_lock_ptr;
170         xge_hal_fifo_hw_pair_t  *hw_pair;
171         xge_hal_fifo_config_t   *config;
172         int                     no_snoop_bits;
173         int                     txdl_per_memblock;
174         u64                     interrupt_type;
175         int                     txdl_size;
176         int                     priv_size;
177         xge_hal_mempool_t       *mempool;
178         int                     align_size;
179 } __xge_os_attr_cacheline_aligned xge_hal_fifo_t;
180
181 /**
182  * struct xge_hal_fifo_txdl_priv_t - Transmit descriptor HAL-private
183  * data.
184  * @dma_addr: DMA (mapped) address of _this_ descriptor.
185  * @dma_handle: DMA handle used to map the descriptor onto device.
186  * @dma_offset: Descriptor's offset in the memory block. HAL allocates
187  * descriptors in memory blocks (see
188  * xge_hal_fifo_config_t{})
189  * Each memblock is a contiguous block of DMA-able memory.
190  * @frags: Total number of fragments (that is, contiguous data buffers)
191  * carried by this TxDL.
192  * @align_vaddr_start: (TODO).
193  * @align_vaddr: Virtual address of the per-TxDL area in memory used for
194  * alignement. Used to place one or more mis-aligned fragments
195  * (the maximum defined by configration variable
196  * @max_aligned_frags).
197  * @align_dma_addr: DMA address translated from the @align_vaddr.
198  * @align_dma_handle: DMA handle that corresponds to @align_dma_addr.
199  * @align_dma_acch: DMA access handle corresponds to @align_dma_addr.
200  * @align_dma_offset: The current offset into the @align_vaddr area.
201  * Grows while filling the descriptor, gets reset.
202  * @align_used_frags: (TODO).
203  * @alloc_frags: Total number of fragments allocated.
204  * @dang_frags: Number of fragments kept from release until this TxDL is freed.
205  * @bytes_sent: TODO
206  * @unused: TODO
207  * @dang_txdl: (TODO).
208  * @next_txdl_priv: (TODO).
209  * @first_txdp: (TODO).
210  * @dang_dtrh: Pointer to TxDL (list) kept from release until this TxDL
211  * is freed.
212  * @linked_txdl_priv: Pointer to any linked TxDL for creating contiguous
213  * TxDL list.
214  * @dtrh: Corresponding dtrh to this TxDL.
215  * @memblock: Pointer to the TxDL memory block or memory page.
216  * on the next send operation.
217  * @dma_object: DMA address and handle of the memory block that contains
218  * the descriptor. This member is used only in the "checked"
219  * version of the HAL (to enforce certain assertions);
220  * otherwise it gets compiled out.
221  * @allocated: True if the descriptor is reserved, 0 otherwise. Internal usage.
222  *
223  * Per-transmit decsriptor HAL-private data. HAL uses the space to keep DMA
224  * information associated with the descriptor. Note that ULD can ask HAL
225  * to allocate additional per-descriptor space for its own (ULD-specific)
226  * purposes.
227  *
228  * See also: xge_hal_ring_rxd_priv_t{}.
229  */
230 typedef struct xge_hal_fifo_txdl_priv_t {
231         dma_addr_t                              dma_addr;
232         pci_dma_h                               dma_handle;
233         ptrdiff_t                               dma_offset;
234         int                                     frags;
235         char                                    *align_vaddr_start;
236         char                                    *align_vaddr;
237         dma_addr_t                              align_dma_addr;
238         pci_dma_h                               align_dma_handle;
239         pci_dma_acc_h                           align_dma_acch;
240         ptrdiff_t                               align_dma_offset;
241         int                                     align_used_frags;
242         int                                     alloc_frags;
243         int                                     dang_frags;
244         unsigned int                            bytes_sent;
245         int                                     unused;
246         xge_hal_fifo_txd_t                      *dang_txdl;
247         struct xge_hal_fifo_txdl_priv_t         *next_txdl_priv;
248         xge_hal_fifo_txd_t                      *first_txdp;
249         void                                    *memblock;
250 #ifdef XGE_DEBUG_ASSERT
251         xge_hal_mempool_dma_t                   *dma_object;
252 #endif
253 #ifdef XGE_OS_MEMORY_CHECK
254         int                                     allocated;
255 #endif
256 } xge_hal_fifo_txdl_priv_t;
257
258 /**
259  * xge_hal_fifo_get_max_frags_cnt - Return the max fragments allocated
260  * for the fifo.
261  * @channelh: Channel handle.
262  */
263 static inline int
264 xge_hal_fifo_get_max_frags_cnt(xge_hal_channel_h channelh)
265 {
266         return ((xge_hal_fifo_t *)channelh)->config->max_frags;
267 }
268 /* ========================= FIFO PRIVATE API ============================= */
269
270 xge_hal_status_e __hal_fifo_open(xge_hal_channel_h channelh,
271                         xge_hal_channel_attr_t *attr);
272
273 void __hal_fifo_close(xge_hal_channel_h channelh);
274
275 void __hal_fifo_hw_initialize(xge_hal_device_h hldev);
276
277 xge_hal_status_e
278 __hal_fifo_dtr_align_alloc_map(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh);
279
280 void
281 __hal_fifo_dtr_align_free_unmap(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh);
282
283 #if defined(XGE_DEBUG_FP) && (XGE_DEBUG_FP & XGE_DEBUG_FP_FIFO)
284 #define __HAL_STATIC_FIFO
285 #define __HAL_INLINE_FIFO
286
287 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_fifo_txdl_priv_t*
288 __hal_fifo_txdl_priv(xge_hal_dtr_h dtrh);
289
290 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
291 __hal_fifo_dtr_post_single(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh,
292                         u64 ctrl_1);
293 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
294 __hal_fifo_txdl_restore_many(xge_hal_channel_h channelh,
295                           xge_hal_fifo_txd_t *txdp, int txdl_count);
296
297 /* ========================= FIFO PUBLIC API ============================== */
298
299 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_status_e
300 xge_hal_fifo_dtr_reserve(xge_hal_channel_h channelh, xge_hal_dtr_h *dtrh);
301
302 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void*
303 xge_hal_fifo_dtr_private(xge_hal_dtr_h dtrh);
304
305 __HAL_STATIC_FIFO __HAL_INLINE_FIFO int
306 xge_hal_fifo_dtr_buffer_cnt(xge_hal_dtr_h dtrh);
307
308 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_status_e
309 xge_hal_fifo_dtr_reserve_sp(xge_hal_channel_h channel, int dtr_sp_size,
310                         xge_hal_dtr_h dtr_sp);
311
312 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
313 xge_hal_fifo_dtr_post(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh);
314
315 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
316 xge_hal_fifo_dtr_post_many(xge_hal_channel_h channelh, int num,
317                         xge_hal_dtr_h dtrs[]);
318
319 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_status_e
320 xge_hal_fifo_dtr_next_completed(xge_hal_channel_h channelh, xge_hal_dtr_h *dtrh,
321                         u8 *t_code);
322
323 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
324 xge_hal_fifo_dtr_free(xge_hal_channel_h channelh, xge_hal_dtr_h dtr);
325
326 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
327 xge_hal_fifo_dtr_buffer_set(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh,
328                         int frag_idx, dma_addr_t dma_pointer, int size);
329
330 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_status_e
331 xge_hal_fifo_dtr_buffer_set_aligned(xge_hal_channel_h channelh,
332                         xge_hal_dtr_h dtrh, int frag_idx, void *vaddr,
333                         dma_addr_t dma_pointer, int size, int misaligned_size);
334
335 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_status_e
336 xge_hal_fifo_dtr_buffer_append(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh,
337                 void *vaddr, int size);
338
339 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
340 xge_hal_fifo_dtr_buffer_finalize(xge_hal_channel_h channelh, xge_hal_dtr_h dtrh,
341                 int frag_idx);
342
343 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
344 xge_hal_fifo_dtr_mss_set(xge_hal_dtr_h dtrh, int mss);
345
346 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
347 xge_hal_fifo_dtr_cksum_set_bits(xge_hal_dtr_h dtrh, u64 cksum_bits);
348
349 __HAL_STATIC_FIFO __HAL_INLINE_FIFO void
350 xge_hal_fifo_dtr_vlan_set(xge_hal_dtr_h dtrh, u16 vlan_tag);
351
352 __HAL_STATIC_FIFO __HAL_INLINE_FIFO xge_hal_status_e
353 xge_hal_fifo_is_next_dtr_completed(xge_hal_channel_h channelh);
354
355 #else /* XGE_FASTPATH_EXTERN */
356 #define __HAL_STATIC_FIFO static
357 #define __HAL_INLINE_FIFO inline
358 #include <dev/nxge/xgehal/xgehal-fifo-fp.c>
359 #endif /* XGE_FASTPATH_INLINE */
360
361 __EXTERN_END_DECLS
362
363 #endif /* XGE_HAL_FIFO_H */