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