source: soft/giet_vm/giet_drivers/nic_driver.c @ 463

Last change on this file since 463 was 456, checked in by alain, 10 years ago

Defining the NIC and CMA drivers (validated by the classif application).
Updating other drivers to comply with the new tty0 common file.

File size: 6.9 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : nic_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <giet_config.h>
9#include <nic_driver.h>
10#include <cma_driver.h>
11#include <utils.h>
12#include <tty0.h>
13#include <ctx_handler.h>
14#include <vmem.h>
15
16#if !defined(GIET_USE_IOMMU)
17# error: You must define GIET_USE_IOMMU in the giet_config.h file
18#endif
19
20#if !defined(SEG_NIC_BASE)
21# error: You must define SEG_NIC_BASE in the hard_config.h file
22#endif
23
24#if !defined(NB_NIC_CHANNELS)
25# error: You must define NB_NIC_CHANNELS in the hard_config.h file
26#endif
27
28#if !defined(X_IO)
29# error: You must define X_IO in the hard_config.h file
30#endif
31
32#if !defined(Y_IO)
33# error: You must define Y_IO in the hard_config.h file
34#endif
35
36#if ( NB_NIC_CHANNELS > 8 )
37# error: NB_NIC_CHANNELS cannot be larger than 8
38#endif
39
40#if !defined(NB_CMA_CHANNELS)
41# error: You must define NB_CMA_CHANNELS in the hard_config.h file
42#endif
43
44#if ( NB_CMA_CHANNELS > 8 )
45# error: NB_CMA_CHANNELS cannot be larger than 8
46#endif
47
48#if !defined( USE_IOB )
49# error: You must define USE_IOB in the hard_config.h file
50#endif
51
52#if !defined( GIET_NIC_NBUFS )
53# error: You must define GIET_NIC_NBUFS in the giet_config.h file
54#endif
55
56#if !defined( GIET_NIC_BUFSIZE )
57# error: You must define GIET_NIC_BUFSIZE in the giet_config.h file
58#endif
59
60#if !defined( GIET_NIC_TIMEOUT )
61# error: You must define GIET_NIC_TIMEOUT in the giet_config.h file
62#endif
63
64#define in_unckdata __attribute__((section (".unckdata")))
65
66///////////////////////////////////////////////////////////////////////////////
67// This low_level function returns the value contained in a channel register.
68///////////////////////////////////////////////////////////////////////////////
69unsigned int _nic_get_channel_register( unsigned int channel,
70                                        unsigned int index )
71{
72    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
73                           NIC_CHANNEL_SPAN * channel + 0x1000 + index;
74    return _io_extended_read( vaddr );
75}
76
77///////////////////////////////////////////////////////////////////////////////
78// This low-level function set a new value in a channel register.
79///////////////////////////////////////////////////////////////////////////////
80void _nic_set_channel_register( unsigned int channel,
81                                unsigned int index,
82                                unsigned int value ) 
83{
84    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
85                           NIC_CHANNEL_SPAN * channel + 0x1000 + index;
86    _io_extended_write( vaddr, value );
87}
88
89///////////////////////////////////////////////////////////////////////////////
90// This low_level function returns the value contained in a global register.
91///////////////////////////////////////////////////////////////////////////////
92unsigned int _nic_get_global_register( unsigned int index )
93{
94    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
95                           NIC_CHANNEL_SPAN * 8 + index;
96    return _io_extended_read( vaddr );
97}
98
99///////////////////////////////////////////////////////////////////////////////
100// This low-level function set a new value in a global register.
101///////////////////////////////////////////////////////////////////////////////
102void _nic_set_global_register( unsigned int index,
103                               unsigned int value ) 
104{
105    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
106                           NIC_CHANNEL_SPAN * 8 + index;
107    _io_extended_write( vaddr, value );
108}
109
110////////////////////////////////////////////
111int _nic_global_init( unsigned int bc_enable,
112                      unsigned int bypass_enable,
113                      unsigned int tdm_enable,
114                      unsigned int tdm_period )
115{
116    _nic_set_global_register( NIC_G_BC_ENABLE    , bc_enable );
117    _nic_set_global_register( NIC_G_BYPASS_ENABLE, bypass_enable );
118    _nic_set_global_register( NIC_G_TDM_ENABLE   , tdm_enable );
119    _nic_set_global_register( NIC_G_TDM_PERIOD   , tdm_period );
120    _nic_set_global_register( NIC_G_VIS          , 0 );     // channels activated later
121    _nic_set_global_register( NIC_G_ON           , 1 );   
122
123    return 0;
124}
125
126////////////////////////////////////////////
127int _nic_channel_start( unsigned int channel,
128                        unsigned int is_rx,
129                        unsigned int mac4,
130                        unsigned int mac2 )
131{
132    unsigned int vis = _nic_get_global_register( NIC_G_VIS );
133    vis |= (0x1 << channel );
134
135    _nic_set_global_register( NIC_G_MAC_4 + channel, mac4 );
136    _nic_set_global_register( NIC_G_MAC_2 + channel, mac2 );
137    _nic_set_global_register( NIC_G_VIS            , vis );
138   
139    unsigned int base     = SEG_NIC_BASE;
140    unsigned int extend   = (X_IO << Y_WIDTH) + Y_IO;
141
142    if ( is_rx )
143    {
144        _nic_set_channel_register( channel, NIC_RX_DESC_LO_0, base          );
145        _nic_set_channel_register( channel, NIC_RX_DESC_LO_1, base + 0x1000 );
146        _nic_set_channel_register( channel, NIC_RX_DESC_HI_0, extend        );
147        _nic_set_channel_register( channel, NIC_RX_DESC_HI_1, extend        );
148        _nic_set_channel_register( channel, NIC_RX_RUN      , 1             );
149    }
150    else
151    {
152        _nic_set_channel_register( channel, NIC_TX_DESC_LO_0, base + 0x2000 );
153        _nic_set_channel_register( channel, NIC_TX_DESC_LO_1, base + 0x3000 );
154        _nic_set_channel_register( channel, NIC_TX_DESC_HI_0, extend        );
155        _nic_set_channel_register( channel, NIC_TX_DESC_HI_1, extend        );
156        _nic_set_channel_register( channel, NIC_TX_RUN      , 1             );
157    }
158
159    return 0;
160}
161
162////////////////////////////////////////////
163int _nic_channel_stop( unsigned int channel,
164                       unsigned int is_rx )
165{
166    if ( is_rx )  _nic_set_channel_register( channel, NIC_RX_RUN, 0 );
167    else          _nic_set_channel_register( channel, NIC_TX_RUN, 0 );
168
169    return 0;   
170}
171
172
173
174////////////////////////////////////////////////////////////////////////////////////////////
175//            Interrupt Service Routines
176////////////////////////////////////////////////////////////////////////////////////////////
177
178////////////////////////////////////////
179void _nic_rx_isr( unsigned int irq_type,
180                  unsigned int irq_id,
181                  unsigned int channel )
182{
183    _puts("[NIC WARNING] RX buffers are full for NIC channel ");
184    _putd( channel );
185    _puts("\n");
186}
187
188////////////////////////////////////////
189void _nic_tx_isr( unsigned int irq_type,
190                  unsigned int irq_id,
191                  unsigned int channel )
192{
193    _puts("[NIC WARNING] TX buffers are full for NIC channel ");
194    _putd( channel );
195    _puts("\n");
196}
197
198// Local Variables:
199// tab-width: 4
200// c-basic-offset: 4
201// c-file-offsets:((innamespace . 0)(inline-open . 0))
202// indent-tabs-mode: nil
203// End:
204// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
205
Note: See TracBrowser for help on using the repository browser.