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

Last change on this file since 318 was 295, checked in by alain, 11 years ago

Introducing a major release, to suppoort the tsar_generic_leti platform
and the various (external or internal) peripherals configurations.
The map.xml format has been modified, in order to support the new
vci_iopic componentand a new policy for peripherals initialisation.
The IRQs are nom described in the XICU and IOPIC components
(and not anymore in the processors).
To enforce this major change, the map.xml file signature changed:
The signature value must be: 0xDACE2014

This new release has been tested on the tsar_generic_leti platform
for the following mappings:

  • 4c_4p_sort_leti
  • 4c_4p_sort_leti_ext
  • 4c_4p_transpose_leti
  • 4c_4p_transpose_leti_ext
  • 4c_1p_four_leti_ext
File size: 6.2 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.
26//////////////////////////////////////////////////////////////////////////////////
27
28#include <giet_config.h>
29#include <nic_driver.h>
30#include <utils.h>
31
32#if !defined(GIET_USE_IOMMU)
33# error: You must define GIET_USE_IOMMU in the giet_config.h file
34#endif
35
36#if !defined(NB_NIC_CHANNELS)
37# error: You must define NB_NIC_CHANNELS in the hard_config.h file
38#endif
39
40#if ( NB_NIC_CHANNELS > 8 )
41# error: NB_NIC_CHANNELS cannot be larger than 8
42#endif
43
44#if !defined(NB_CMA_CHANNELS)
45# error: You must define NB_CMA_CHANNELS in the hard_config.h file
46#endif
47
48#if ( NB_CMA_CHANNELS > 8 )
49# error: NB_CMA_CHANNELS cannot be larger than 8
50#endif
51
52#if !defined( USE_IOB )
53# error: You must define USE_IOB in the hard_config.h file
54#endif
55
56#define in_unckdata __attribute__((section (".unckdata")))
57
[295]58///////////////////////////////////////////////////////////////////////////////
59// This low_level function returns the value contained in register (index).
60///////////////////////////////////////////////////////////////////////////////
61unsigned int _nic_get_register( unsigned int channel,
62                                unsigned int index )
63{
64    unsigned int* vaddr = (unsigned int*)&seg_nic_base + 
65                           NIC_CHANNEL_SPAN*channel + index;
66    return _io_extended_read( vaddr );
67}
68
69///////////////////////////////////////////////////////////////////////////////
70// This low-level function set a new value in register (index).
71///////////////////////////////////////////////////////////////////////////////
72void _nic_set_register( unsigned int channel,
73                        unsigned int index,
74                        unsigned int value ) 
75{
76    unsigned int* vaddr = (unsigned int*)&seg_nic_base + 
77                           NIC_CHANNEL_SPAN*channel + index;
78    _io_extended_write( vaddr, value );
79}
80
[258]81//////////////////////////////////////////////////////////////////////////////////
82// Transfer data from an memory buffer to the NIC device using a memcpy.
83// - buffer : base address of the memory buffer.
84// - length : number of bytes to be transfered.
85//////////////////////////////////////////////////////////////////////////////////
86unsigned int _nic_sync_write( const void*    buffer,
87                              unsigned int   length ) 
88{
[295]89    _printf("[GIET ERROR] _nic_sync_write function not implemented\n");
[258]90    _exit();
91
92    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
93    // memcpy((void *) nic_address, (void *) buffer, length);
94    return 0;
95}
96//////////////////////////////////////////////////////////////////////////////////
97// Transfer data from the NIC device to a memory buffer using a memcpy.
98// - buffer : base address of the memory buffer.
99// - length : number of bytes to be transfered.
100//////////////////////////////////////////////////////////////////////////////////
101unsigned int _nic_sync_read( const void*    buffer, 
102                             unsigned int   length ) 
103{
[295]104    _printf("[GIET ERROR] _nic_sync_read function not implemented\n");
[258]105    _exit();
106
107    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
108    // memcpy((void *) buffer, (void *) nic_address, length);
109    return 0;
110}
111//////////////////////////////////////////////////////////////////////////////////
112// Returns 0 if success, > 0 if error.
113//////////////////////////////////////////////////////////////////////////////////
114unsigned int _nic_cma_start( )
115{
[295]116    _printf("[GIET ERROR] _nic_cma_start() not implemented\n");
[258]117    _exit();
118
119    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
120    return 0;
121}
122//////////////////////////////////////////////////////////////////////////////////
123// Returns 0 if success, > 0 if error.
124//////////////////////////////////////////////////////////////////////////////////
125unsigned int _nic_cma_stop()
126{
[295]127    _printf("[GIET ERROR] _nic_cma_stop() not implemented\n");
[258]128    _exit();
129
130    // unsigned char* nic_address = (unsigned char *) &seg_nic_base;
131    return 0;
132}
133
[295]134//////////////////////////////////////////////////////////////////////////////////
135// This ISR handles IRQx from a NIC RX channeL
136//////////////////////////////////////////////////////////////////////////////////
137void _nic_rx_isr( unsigned int irq_type,
138                  unsigned int irq_id,
139                  unsigned int channel )
140{
141    _printf("[GIET ERROR] _nic_rx_isr() not implemented\n");
142    _exit();
143}
[258]144
[295]145//////////////////////////////////////////////////////////////////////////////////
146// This ISR handles IRQx from a NIC RX channeL
147//////////////////////////////////////////////////////////////////////////////////
148void _nic_tx_isr( unsigned int irq_type,
149                  unsigned int irq_id,
150                  unsigned int channel )
151{
152    _printf("[GIET ERROR] _nic_tx_isr() not implemented\n");
153    _exit();
154}
155
[258]156// Local Variables:
157// tab-width: 4
158// c-basic-offset: 4
159// c-file-offsets:((innamespace . 0)(inline-open . 0))
160// indent-tabs-mode: nil
161// End:
162// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
163
Note: See TracBrowser for help on using the repository browser.