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 | /////////////////////////////////////////////////////////////////////////////// |
---|
53 | // This low_level function returns the value contained in a channel register. |
---|
54 | /////////////////////////////////////////////////////////////////////////////// |
---|
55 | unsigned int _nic_get_channel_register( unsigned int channel, |
---|
56 | unsigned int index ) |
---|
57 | { |
---|
58 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
59 | NIC_CHANNEL_SPAN * channel + 0x1000 + index; |
---|
60 | return _io_extended_read( vaddr ); |
---|
61 | } |
---|
62 | |
---|
63 | /////////////////////////////////////////////////////////////////////////////// |
---|
64 | // This low-level function set a new value in a channel register. |
---|
65 | /////////////////////////////////////////////////////////////////////////////// |
---|
66 | void _nic_set_channel_register( unsigned int channel, |
---|
67 | unsigned int index, |
---|
68 | unsigned int value ) |
---|
69 | { |
---|
70 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
71 | NIC_CHANNEL_SPAN * channel + 0x1000 + index; |
---|
72 | _io_extended_write( vaddr, value ); |
---|
73 | } |
---|
74 | |
---|
75 | /////////////////////////////////////////////////////////////////////////////// |
---|
76 | // This low_level function returns the value contained in a global register. |
---|
77 | /////////////////////////////////////////////////////////////////////////////// |
---|
78 | unsigned int _nic_get_global_register( unsigned int index ) |
---|
79 | { |
---|
80 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
81 | NIC_CHANNEL_SPAN * 8 + index; |
---|
82 | return _io_extended_read( vaddr ); |
---|
83 | } |
---|
84 | |
---|
85 | /////////////////////////////////////////////////////////////////////////////// |
---|
86 | // This low-level function set a new value in a global register. |
---|
87 | /////////////////////////////////////////////////////////////////////////////// |
---|
88 | void _nic_set_global_register( unsigned int index, |
---|
89 | unsigned int value ) |
---|
90 | { |
---|
91 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
92 | NIC_CHANNEL_SPAN * 8 + index; |
---|
93 | _io_extended_write( vaddr, value ); |
---|
94 | } |
---|
95 | |
---|
96 | //////////////////////////////////////////// |
---|
97 | int _nic_global_init( unsigned int bc_enable, |
---|
98 | unsigned int bypass_enable, |
---|
99 | unsigned int tdm_enable, |
---|
100 | unsigned int tdm_period ) |
---|
101 | { |
---|
102 | _nic_set_global_register( NIC_G_BC_ENABLE , bc_enable ); |
---|
103 | _nic_set_global_register( NIC_G_BYPASS_ENABLE, bypass_enable ); |
---|
104 | _nic_set_global_register( NIC_G_TDM_ENABLE , tdm_enable ); |
---|
105 | _nic_set_global_register( NIC_G_TDM_PERIOD , tdm_period ); |
---|
106 | _nic_set_global_register( NIC_G_VIS , 0 ); // channels activated later |
---|
107 | _nic_set_global_register( NIC_G_ON , 1 ); |
---|
108 | |
---|
109 | return 0; |
---|
110 | } |
---|
111 | |
---|
112 | //////////////////////////////////////////// |
---|
113 | int _nic_channel_start( unsigned int channel, |
---|
114 | unsigned int is_rx, |
---|
115 | unsigned int mac4, |
---|
116 | unsigned int mac2 ) |
---|
117 | { |
---|
118 | unsigned int vis = _nic_get_global_register( NIC_G_VIS ); |
---|
119 | vis |= (0x1 << channel ); |
---|
120 | |
---|
121 | _nic_set_global_register( NIC_G_MAC_4 + channel, mac4 ); |
---|
122 | _nic_set_global_register( NIC_G_MAC_2 + channel, mac2 ); |
---|
123 | _nic_set_global_register( NIC_G_VIS , vis ); |
---|
124 | |
---|
125 | unsigned int base = SEG_NIC_BASE; |
---|
126 | unsigned int extend = (X_IO << Y_WIDTH) + Y_IO; |
---|
127 | |
---|
128 | if ( is_rx ) |
---|
129 | { |
---|
130 | _nic_set_channel_register( channel, NIC_RX_DESC_LO_0, base ); |
---|
131 | _nic_set_channel_register( channel, NIC_RX_DESC_LO_1, base + 0x1000 ); |
---|
132 | _nic_set_channel_register( channel, NIC_RX_DESC_HI_0, extend ); |
---|
133 | _nic_set_channel_register( channel, NIC_RX_DESC_HI_1, extend ); |
---|
134 | _nic_set_channel_register( channel, NIC_RX_RUN , 1 ); |
---|
135 | } |
---|
136 | else |
---|
137 | { |
---|
138 | _nic_set_channel_register( channel, NIC_TX_DESC_LO_0, base + 0x2000 ); |
---|
139 | _nic_set_channel_register( channel, NIC_TX_DESC_LO_1, base + 0x3000 ); |
---|
140 | _nic_set_channel_register( channel, NIC_TX_DESC_HI_0, extend ); |
---|
141 | _nic_set_channel_register( channel, NIC_TX_DESC_HI_1, extend ); |
---|
142 | _nic_set_channel_register( channel, NIC_TX_RUN , 1 ); |
---|
143 | } |
---|
144 | |
---|
145 | return 0; |
---|
146 | } |
---|
147 | |
---|
148 | //////////////////////////////////////////// |
---|
149 | int _nic_channel_stop( unsigned int channel, |
---|
150 | unsigned int is_rx ) |
---|
151 | { |
---|
152 | if ( is_rx ) _nic_set_channel_register( channel, NIC_RX_RUN, 0 ); |
---|
153 | else _nic_set_channel_register( channel, NIC_TX_RUN, 0 ); |
---|
154 | |
---|
155 | return 0; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
161 | // Interrupt Service Routines |
---|
162 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
163 | |
---|
164 | //////////////////////////////////////// |
---|
165 | void _nic_rx_isr( unsigned int irq_type, |
---|
166 | unsigned int irq_id, |
---|
167 | unsigned int channel ) |
---|
168 | { |
---|
169 | _puts("[NIC WARNING] RX buffers are full for NIC channel "); |
---|
170 | _putd( channel ); |
---|
171 | _puts("\n"); |
---|
172 | } |
---|
173 | |
---|
174 | //////////////////////////////////////// |
---|
175 | void _nic_tx_isr( unsigned int irq_type, |
---|
176 | unsigned int irq_id, |
---|
177 | unsigned int channel ) |
---|
178 | { |
---|
179 | _puts("[NIC WARNING] TX buffers are full for NIC channel "); |
---|
180 | _putd( channel ); |
---|
181 | _puts("\n"); |
---|
182 | } |
---|
183 | |
---|
184 | // Local Variables: |
---|
185 | // tab-width: 4 |
---|
186 | // c-basic-offset: 4 |
---|
187 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
188 | // indent-tabs-mode: nil |
---|
189 | // End: |
---|
190 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
191 | |
---|