| 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 <ctx_handler.h> |
|---|
| 13 | #include <vmem.h> |
|---|
| 14 | |
|---|
| 15 | #if !defined(GIET_USE_IOMMU) |
|---|
| 16 | # error: You must define GIET_USE_IOMMU in the giet_config.h file |
|---|
| 17 | #endif |
|---|
| 18 | |
|---|
| 19 | #if !defined(SEG_NIC_BASE) |
|---|
| 20 | # error: You must define SEG_NIC_BASE in the hard_config.h file |
|---|
| 21 | #endif |
|---|
| 22 | |
|---|
| 23 | #if !defined(NB_NIC_CHANNELS) |
|---|
| 24 | # error: You must define NB_NIC_CHANNELS in the hard_config.h file |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 51 | #if !defined( GIET_NIC_CHBUF_NBUFS ) |
|---|
| 52 | # error: You must define GIET_NIC_CHBUF_NBUFS in the giet_config.h file |
|---|
| 53 | #endif |
|---|
| 54 | |
|---|
| 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 | |
|---|
| 63 | #define in_unckdata __attribute__((section (".unckdata"))) |
|---|
| 64 | |
|---|
| 65 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 66 | // This low_level function returns the value contained in a channel register. |
|---|
| 67 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 68 | unsigned int _nic_get_channel_register( unsigned int channel, |
|---|
| 69 | unsigned int index ) |
|---|
| 70 | { |
|---|
| 71 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
|---|
| 72 | NIC_CHANNEL_SPAN * channel + index; |
|---|
| 73 | return _io_extended_read( vaddr ); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 77 | // This low-level function set a new value in a channel register. |
|---|
| 78 | /////////////////////////////////////////////////////////////////////////////// |
|---|
| 79 | void _nic_set_channel_register( unsigned int channel, |
|---|
| 80 | unsigned int index, |
|---|
| 81 | unsigned int value ) |
|---|
| 82 | { |
|---|
| 83 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
|---|
| 84 | NIC_CHANNEL_SPAN * channel + index; |
|---|
| 85 | _io_extended_write( vaddr, value ); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 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 ) |
|---|
| 92 | { |
|---|
| 93 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
|---|
| 94 | NIC_CHANNEL_SPAN * NB_NIC_CHANNELS + index; |
|---|
| 95 | return _io_extended_read( vaddr ); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 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 | |
|---|
| 121 | return 0; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | //////////////////////////////////////////// |
|---|
| 125 | int _nic_channel_start( unsigned int channel, |
|---|
| 126 | unsigned int is_rx, |
|---|
| 127 | unsigned int mac4, |
|---|
| 128 | unsigned int mac2 ) |
|---|
| 129 | { |
|---|
| 130 | unsigned int base = SEG_NIC_BASE; |
|---|
| 131 | unsigned int extend = (X_IO << Y_WIDTH) + Y_IO; |
|---|
| 132 | |
|---|
| 133 | if ( is_rx ) |
|---|
| 134 | { |
|---|
| 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 ); |
|---|
| 140 | } |
|---|
| 141 | else |
|---|
| 142 | { |
|---|
| 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 ); |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | _nic_set_channel_register( channel, NIC_MAC_4 , mac4 ); |
|---|
| 151 | _nic_set_channel_register( channel, NIC_MAC_2 , mac2 ); |
|---|
| 152 | |
|---|
| 153 | return 0; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | //////////////////////////////////////////// |
|---|
| 157 | int _nic_channel_stop( unsigned int channel, |
|---|
| 158 | unsigned int is_rx ) |
|---|
| 159 | { |
|---|
| 160 | if ( is_rx ) _nic_set_channel_register( channel, NIC_RX_RUN, 0 ); |
|---|
| 161 | else _nic_set_channel_register( channel, NIC_TX_RUN, 0 ); |
|---|
| 162 | |
|---|
| 163 | return 0; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | //////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 169 | // Interrupt Service Routines |
|---|
| 170 | //////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 171 | |
|---|
| 172 | //////////////////////////////////////// |
|---|
| 173 | void _nic_rx_isr( unsigned int irq_type, |
|---|
| 174 | unsigned int irq_id, |
|---|
| 175 | unsigned int channel ) |
|---|
| 176 | { |
|---|
| 177 | _puts("[NIC WARNING] RX buffers are full for NIC channel "); |
|---|
| 178 | _putd( channel ); |
|---|
| 179 | _puts("\n"); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | //////////////////////////////////////// |
|---|
| 183 | void _nic_tx_isr( unsigned int irq_type, |
|---|
| 184 | unsigned int irq_id, |
|---|
| 185 | unsigned int channel ) |
|---|
| 186 | { |
|---|
| 187 | _puts("[NIC WARNING] TX buffers are full for NIC channel "); |
|---|
| 188 | _putd( channel ); |
|---|
| 189 | _puts("\n"); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 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 | |
|---|