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

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

All drivers have been modified to use only the information
contained in the hard_config.h file

File size: 6.4 KB
RevLine 
[258]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.
[320]26//
27// The SEG_NIC_BASE address must be defined in the hard_config.h file.
[258]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
[320]38#if !defined(SEG_NIC_BASE)
39# error: You must define SEG_NIC_BASE in the hard_config.h file
40#endif
41
[258]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
[295]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{
[320]70    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
71                           NIC_CHANNEL_SPAN * channel + index;
[295]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{
[320]82    unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + 
83                           NIC_CHANNEL_SPAN * channel + index;
[295]84    _io_extended_write( vaddr, value );
85}
86
[258]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{
[295]95    _printf("[GIET ERROR] _nic_sync_write function not implemented\n");
[258]96    _exit();
97
98    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
99    // memcpy((void *) nic_address, (void *) buffer, length);
100    return 0;
101}
102//////////////////////////////////////////////////////////////////////////////////
103// Transfer data from the NIC device to a memory buffer using a memcpy.
104// - buffer : base address of the memory buffer.
105// - length : number of bytes to be transfered.
106//////////////////////////////////////////////////////////////////////////////////
107unsigned int _nic_sync_read( const void*    buffer, 
108                             unsigned int   length ) 
109{
[295]110    _printf("[GIET ERROR] _nic_sync_read function not implemented\n");
[258]111    _exit();
112
113    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
114    // memcpy((void *) buffer, (void *) nic_address, length);
115    return 0;
116}
117//////////////////////////////////////////////////////////////////////////////////
118// Returns 0 if success, > 0 if error.
119//////////////////////////////////////////////////////////////////////////////////
120unsigned int _nic_cma_start( )
121{
[295]122    _printf("[GIET ERROR] _nic_cma_start() not implemented\n");
[258]123    _exit();
124
125    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
126    return 0;
127}
128//////////////////////////////////////////////////////////////////////////////////
129// Returns 0 if success, > 0 if error.
130//////////////////////////////////////////////////////////////////////////////////
131unsigned int _nic_cma_stop()
132{
[295]133    _printf("[GIET ERROR] _nic_cma_stop() not implemented\n");
[258]134    _exit();
135
136    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
137    return 0;
138}
139
[295]140//////////////////////////////////////////////////////////////////////////////////
141// This ISR handles IRQx from a NIC RX channeL
142//////////////////////////////////////////////////////////////////////////////////
143void _nic_rx_isr( unsigned int irq_type,
144                  unsigned int irq_id,
145                  unsigned int channel )
146{
147    _printf("[GIET ERROR] _nic_rx_isr() not implemented\n");
148    _exit();
149}
[258]150
[295]151//////////////////////////////////////////////////////////////////////////////////
152// This ISR handles IRQx from a NIC RX channeL
153//////////////////////////////////////////////////////////////////////////////////
154void _nic_tx_isr( unsigned int irq_type,
155                  unsigned int irq_id,
156                  unsigned int channel )
157{
158    _printf("[GIET ERROR] _nic_tx_isr() not implemented\n");
159    _exit();
160}
161
[258]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.