source: trunk/hal/tsar_mips32/drivers/soclib_nic.h @ 336

Last change on this file since 336 was 75, checked in by max@…, 7 years ago

Create the drivers/ sub-directory in each hal, and move soclib
into it. Note that soclib is not valid for x86_64, but more
changes will come.

File size: 11.4 KB
RevLine 
[75]1/*
2 * soclib_nic.h - SOCLIB_NIC (Network Interface Controler) driver definition.
3 *
4 * Author    Alain Greiner (2016)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _SOCLIB_NIC_H_
25#define _SOCLIB_NIC_H_
26
27#include <chdev.h>
28#include <hal_types.h>
29
30/********************************************************************************************
31 * This driver supports the Soclib VciMasterNic component, that is a GMII compliant
32 * multi-channels Gigabit Ethernet controler.
33 *
34 * The VciMasterNic component supports up to 4 channels, indexed by the source IP address
35 * for the RX packets, and by the destination IP address for the TX packets.
36 *
37 * The Ethernet packet length can have any value, between 64 to 1538 bytes.
38 * The data transfer unit between software and the NIC is a 4 Kbytes "container",
39 * containing an integer number of variable size packets.
40 *
41 * The max number of packets in a container is 66 packets.
42 * The first 34 words of a container are the container header :
43 *
44 *     word0    |       NB_WORDS        |       NB_PACKETS      |
45 *     word1    |       PLEN[0]         |       PLEN[1]         |
46 *      ...         |   .......         |       ........        |
47 *     word33   |       PLEN[64]        |       PLEN[65]        |
48 *
49 *  - NB_PACKETS is the actual number of packets in the container.
50 *      - NB_WORDS   is the number of useful words in the container.
51 *      - PLEN[i]    is the number of bytes for the packet[i].
52 *
53 * Packets are stored in the (1024 - 34) following words, and the packets are word-aligned.
54 *
55 * The TX and RX queues are implemented as chained buffers, where each buffer is a 4 Kbytes
56 * container. Each container is protected by a SET/RESET synchronisation variable.
57 * The structure implementing the chbuf descriptor is described below.
58 *
59 * To access both the container status, and the data contained in the container, the NIC
60 * uses two physical addresses, that are packed in a 64 bits "container descriptor".
61 * - desc[25:0]  contain bits[31:6] of the status physical address.
62 * - desc[51:26] contain bits[31:6] of the buffer physical address.
63 * - desc[63:52] contain the common 12 physical address extension bits.
64 *******************************************************************************************/
65
66/********************************************************************************************
67 *       Addressable registers offsets
68 *******************************************************************************************/
69
70enum SoclibMasterNicGlobalRegisters
71{
72    NIC_G_RUN                        = 0,   /*! read_write : NIC component activated       */
73    NIC_G_NB_CHANNELS                = 1,   /*! read_only  : number of channels            */
74    NIC_G_BC_ENABLE                  = 2,   /*! read_write : broadcast enabled if non zero */ 
75    NIC_G_PERIOD                     = 3,   /*! read-write : container status poll period  */
76    NIC_G_MAC_4                      = 4,   /*! read-write : mac address 32 LSB bits       */
77    NIC_G_MAC_2                      = 5,   /*! read-write : mac address 16 MSB bits       */
78
79    NIC_G_NPKT_RX_G2S_RECEIVED       = 10,  /*! number of packets received                 */
80    NIC_G_NPKT_RX_G2S_DISCARDED      = 11,  /*! number of RX packets discarded by RX_G2S   */
81    NIC_G_NPKT_RX_DES_SUCCESS        = 12,  /*! number of RX packets transmited by RX_DES  */
82    NIC_G_NPKT_RX_DES_TOO_SMALL      = 13,  /*! number of discarded too small RX packets   */
83    NIC_G_NPKT_RX_DES_TOO_BIG        = 14,  /*! number of discarded too big RX packets     */
84    NIC_G_NPKT_RX_DES_MFIFO_FULL     = 15,  /*! number of discarded RX packets fifo full   */
85    NIC_G_NPKT_RX_DES_CRC_FAIL       = 16,  /*! number of discarded RX packets CRC32       */
86    NIC_G_NPKT_RX_DISPATCH_RECEIVED  = 17,  /*! number of packets received by RX_DISPATCH  */
87    NIC_G_NPKT_RX_DISPATCH_BROADCAST = 18,  /*! number of broadcast RX packets received    */
88    NIC_G_NPKT_RX_DISPATCH_DST_FAIL  = 19,  /*! number of discarded RX packets for DST MAC */
89    NIC_G_NPKT_RX_DISPATCH_CH_FULL   = 20,  /*! number of discarded RX packets cont full   */
90
91    NIC_G_NPKT_TX_DISPATCH_RECEIVED  = 41,  /*! number of packets received by TX_DISPATCH  */
92    NIC_G_NPKT_TX_DISPATCH_TOO_SMALL = 42,  /*! number of discarded too small TX packets   */
93    NIC_G_NPKT_TX_DISPATCH_TOO_BIG   = 43,  /*! number of discarded too big TX packets     */
94    NIC_G_NPKT_TX_DISPATCH_SRC_FAIL  = 44,  /*! number of discarded TX packets for SRC MAC */
95    NIC_G_NPKT_TX_DISPATCH_BROADCAST = 45,  /*! number of broadcast TX packets received    */
96    NIC_G_NPKT_TX_DISPATCH_TRANSMIT  = 46,  /*! number of transmit TX packets              */
97
98    NIC_GLOBAL_SPAN                  = 64   /*! 256 bytes for global registers             */
99};
100
101enum SoclibMasterNicChannelRegisters
102{
103    NIC_RX_STATUS             = 0,    /*! read-only  : RX channel status                   */
104    NIC_RX_CHBUF_DESC_L0      = 1,    /*! read-write : RX chbuf descriptor 32 LSB bits     */ 
105    NIC_RX_CHBUF_DESC_HI      = 2,    /*! read-write : RX chbuf descriptor 32 MSB bits     */ 
106    NIC_RX_CHBUF_NBUFS        = 3,    /*! read-write : RX chbuf depth (number of buffers)  */
107   
108    NIC_TX_STATUS             = 8,    /*! read-only  : TX channel status                   */
109    NIC_TX_CHBUF_DESC_L0      = 9,    /*! read-write : TX chbuf descriptor 32 LSB bits     */ 
110    NIC_TX_CHBUF_DESC_HI      = 10,   /*! read-write : TX chbuf descriptor 32 MSB bits     */ 
111    NIC_TX_CHBUF_NBUFS        = 11,   /*! read-write : TX chbuf depth (number of buffers)  */
112
113    NIC_CHANNEL_SPAN          = 16    /*! 64 bytes per channel                             */
114};
115   
116
117
118/********************************************************************************************
119 * This structure defines the chained buffer descriptor, used to implement both
120 * the RX and TX packets queues. Each buffer in a chbuf is a 4 Kbytes container
121 * containing a variable number of packets. All containers are allocated in
122 * the same cluster as the associated NIC device descriptor. The chbuf descriptor contains:
123 * - an array of container pointers cont[], used by the kernet threads to access the
124 *   packets contained in the containers.
125 * - an array of set/reset Boolean full[] used by both the software threads and
126 *   by the hardware FSMs for lock-less synchronisation.
127 * - an array of containers descriptors containing the physical addresses of the
128 *   "full[i]" and "cont[i]" variables, used by the DMA FSMs.
129 * Moreover, It contains three pointers (cont_id, pkt_id, and word_id) that are private
130 * variables used by the software thread to scan the chbuf.
131 *******************************************************************************************/
132
133typedef struct nic_chbuf_s
134{
135    uint32_t * cont[CONFIG_NIC_CHBUF_DEPTH]; /*! container virtual base address            */
136    uint32_t   full[CONFIG_NIC_CHBUF_DEPTH]; /*! Boolean : container full if non zero      */
137    uint64_t   desc[CONFIG_NIC_CHBUF_DEPTH]; /*! container & status physical addresses     */
138    uint32_t   cont_id;                      /*! current container index                   */
139    uint32_t   pkt_id;                       /*! current packet index in container         */
140    uint32_t   word_id;                      /*! first word of current packet              */
141}
142nic_chbuf_t;
143
144/********************************************************************************************
145 *        SOCLIB_NIC driver access functions
146 *******************************************************************************************/
147
148/********************************************************************************************
149 * This function initializes the SOCLIB_NIC hardware registers, allocates memory for
150 * the RX and TX containers, allocates and initializes the RX and TX chbuf descriptors.
151 * It allocates one WTI mailbox for the IRQ signaling availability of an RX full container,
152 * or a TX empty container, and route the WTI IRQ to the core running the server thread.
153 ********************************************************************************************
154 * @ chdev  :  pointer on NIC chdev descriptor.
155 *******************************************************************************************/
156extern void soclib_nic_init( chdev_t * chdev );
157
158/********************************************************************************************
159 * This function implement the READ / WRITE / READABLE / WRITABLE commands for TX/RX queues.
160 * These command don't access the NIC peripheral but only the TX and TX chbufs.
161 * It must be executed by a dedicated kernel thread running in the cluster containing
162 * the CHBUF implementing the TX/RX queues.
163 * It implements also the SET_MAC, SET_BC, SET_RUN configuration commands, that directly
164 * access the NIC peripheral registers.
165 * - READABLE
166 *   Returns in the command "status" a non zero value if a packet is available in RX queue.
167 *   Update the RX queue read pointer if required.
168 * - READ
169 *   Move a packet from the RX queue to the command "buffer", and returns the packet
170 *   "length" in the command. The READABLE command must be called before the READ command.
171 * - WRITABLE
172 *   Returns in the command "status" a non zero value if a packet with a given "length"
173 *   can be written in the TX queue. Update the RX queue read pointer if required.
174 * - WRITE
175 *   Move a packet of a given "length" from the command "buffer" to the TX queue.
176 *   The WRITABLE command must be called before the WRITE command.
177 * - SET_MAC
178 *   Set the values defined in the "length" and "status" command arguments,
179 *   into the NIC_C_MAC4 and NIG_G_MAC2  registers.
180 * - SET_BC
181 *   Enable/disable broadcast packets, as defined in the "status" command argument,
182 *   into the NIC_G_BC_ENABLE register.
183 * - SET_RUN
184 *   Enable/disable NIC, as defined in the "status" command argument,
185 *   into the NIC_G_RUN register.
186 * @ dev_xp  : extended pointer on the generic NIC device descriptor.
187 ********************************************************************************************
188 $ @ thread_xp : extended pointer on client thread (containing the command arguments).
189 *******************************************************************************************/
190extern void soclib_nic_cmd( xptr_t thread_xp );
191
192/********************************************************************************************
193 * This ISR acknowledge the NIC_RX or NIC_TX channel ISR signaling that a new container
194 * has beeen moved, and reactivate the corresponding server thread.
195 * In case of address error reported by the NIC controler in accessing the kernel chbuf,
196 * it goes to kernel panic.
197 ********************************************************************************************
198 * @ chdev     : local pointer on NIC chdev descriptor.
199 *******************************************************************************************/
200extern void soclib_nic_isr( chdev_t * chdev );
201
202
203#endif /* _BLOCK_H_ */
Note: See TracBrowser for help on using the repository browser.