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