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

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

Cosmetic

File size: 6.2 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : nic_driver.c
3// Date     : 23/05/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The nic_driver.c and nic_driver.h files are part ot the GIET-VM nano-kernel.
8// This driver supports the vci_multi_nic component.
9//
10// It can exist only one network controller in the architecture, but this
11// component supports several channels.
12//
13// It can be accessed directly by software with memcpy(),
14// or it can be accessed through the vci_chbuf_dma component:
15// 
16// The '_nic_sync_write' and '_nic_sync_read' functions use a memcpy strategy to
17// implement the transfer between a data buffer (user space) and the NIC
18// buffer (kernel space). They are blocking until completion of the transfer.
19//
20// The _nic_cma_*_init() and _nic_cma_stop() functions use the VciChbufDma component
21// to transfer a flow of packets from the NIC RX hard chbuf (two containers)
22// to an user RX chbuf (two containers), and to transfer another flow of packets
23// from an user TX chbuf (two containers) to the NIC TX chbuf (two containers).
24// One NIC channel and two CMA channels must be allocated to the task
25// in the mapping_info data structure.
26//
27// The SEG_NIC_BASE address must be defined in the hard_config.h file.
28//////////////////////////////////////////////////////////////////////////////////
29
30#include <giet_config.h>
31#include <nic_driver.h>
32#include <utils.h>
33
34#if !defined(GIET_USE_IOMMU)
35# error: You must define GIET_USE_IOMMU in the giet_config.h file
36#endif
37
38#if !defined(SEG_NIC_BASE)
39# error: You must define SEG_NIC_BASE in the hard_config.h file
40#endif
41
42#if !defined(NB_NIC_CHANNELS)
43# error: You must define NB_NIC_CHANNELS in the hard_config.h file
44#endif
45
46#if ( NB_NIC_CHANNELS > 8 )
47# error: NB_NIC_CHANNELS cannot be larger than 8
48#endif
49
50#if !defined(NB_CMA_CHANNELS)
51# error: You must define NB_CMA_CHANNELS in the hard_config.h file
52#endif
53
54#if ( NB_CMA_CHANNELS > 8 )
55# error: NB_CMA_CHANNELS cannot be larger than 8
56#endif
57
58#if !defined( USE_IOB )
59# error: You must define USE_IOB in the hard_config.h file
60#endif
61
62#define in_unckdata __attribute__((section (".unckdata")))
63
64///////////////////////////////////////////////////////////////////////////////
65// This low_level function returns the value contained in register (index).
66///////////////////////////////////////////////////////////////////////////////
67unsigned int _nic_get_register( unsigned int channel,
68                                unsigned int index )
69{
70    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
71                           NIC_CHANNEL_SPAN * channel + index;
72    return _io_extended_read( vaddr );
73}
74
75///////////////////////////////////////////////////////////////////////////////
76// This low-level function set a new value in register (index).
77///////////////////////////////////////////////////////////////////////////////
78void _nic_set_register( unsigned int channel,
79                        unsigned int index,
80                        unsigned int value ) 
81{
82    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
83                           NIC_CHANNEL_SPAN * channel + index;
84    _io_extended_write( vaddr, value );
85}
86
87//////////////////////////////////////////////////////////////////////////////////
88// Transfer data from an memory buffer to the NIC device using a memcpy.
89// - buffer : base address of the memory buffer.
90// - length : number of bytes to be transfered.
91//////////////////////////////////////////////////////////////////////////////////
92unsigned int _nic_sync_write( const void*    buffer,
93                              unsigned int   length ) 
94{
95    _printf("[GIET ERROR] _nic_sync_write function not implemented / cycle %d\n",
96            _get_proctime() );
97    _exit();
98
99    return 0;
100}
101//////////////////////////////////////////////////////////////////////////////////
102// Transfer data from the NIC device to a memory buffer using a memcpy.
103// - buffer : base address of the memory buffer.
104// - length : number of bytes to be transfered.
105//////////////////////////////////////////////////////////////////////////////////
106unsigned int _nic_sync_read( const void*    buffer, 
107                             unsigned int   length ) 
108{
109    _printf("[GIET ERROR] _nic_sync_read function not implemented / cycle %d\n",
110            _get_proctime() );
111    _exit();
112
113    return 0;
114}
115//////////////////////////////////////////////////////////////////////////////////
116// Returns 0 if success, > 0 if error.
117//////////////////////////////////////////////////////////////////////////////////
118unsigned int _nic_cma_start( )
119{
120    _printf("[GIET ERROR] _nic_cma_start() not implemented / cycle %d\n",
121            _get_proctime() );
122    _exit();
123
124    return 0;
125}
126//////////////////////////////////////////////////////////////////////////////////
127// Returns 0 if success, > 0 if error.
128//////////////////////////////////////////////////////////////////////////////////
129unsigned int _nic_cma_stop()
130{
131    _printf("[GIET ERROR] _nic_cma_stop() not implemented / cycle %d\n",
132            _get_proctime() );
133    _exit();
134
135    return 0;
136}
137
138//////////////////////////////////////////////////////////////////////////////////
139// This ISR handles IRQx from a NIC RX channeL
140//////////////////////////////////////////////////////////////////////////////////
141void _nic_rx_isr( unsigned int irq_type,
142                  unsigned int irq_id,
143                  unsigned int channel )
144{
145    _printf("[GIET ERROR] _nic_rx_isr() not implemented / cycle %d\n",
146            _get_proctime() );
147    _exit();
148}
149
150//////////////////////////////////////////////////////////////////////////////////
151// This ISR handles IRQx from a NIC RX channeL
152//////////////////////////////////////////////////////////////////////////////////
153void _nic_tx_isr( unsigned int irq_type,
154                  unsigned int irq_id,
155                  unsigned int channel )
156{
157    _printf("[GIET ERROR] _nic_tx_isr() not implemented / cycle %d\n",
158            _get_proctime() );
159    _exit();
160}
161
162// Local Variables:
163// tab-width: 4
164// c-basic-offset: 4
165// c-file-offsets:((innamespace . 0)(inline-open . 0))
166// indent-tabs-mode: nil
167// End:
168// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
169
Note: See TracBrowser for help on using the repository browser.