[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 | |
---|
[295] | 52 | /////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 53 | // This low_level function returns the value contained in a channel register. |
---|
[295] | 54 | /////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 55 | unsigned int _nic_get_channel_register( unsigned int channel, |
---|
| 56 | unsigned int index ) |
---|
[295] | 57 | { |
---|
[320] | 58 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
[456] | 59 | NIC_CHANNEL_SPAN * channel + 0x1000 + index; |
---|
[295] | 60 | return _io_extended_read( vaddr ); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 64 | // This low-level function set a new value in a channel register. |
---|
[295] | 65 | /////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 66 | void _nic_set_channel_register( unsigned int channel, |
---|
| 67 | unsigned int index, |
---|
| 68 | unsigned int value ) |
---|
[295] | 69 | { |
---|
[320] | 70 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
[456] | 71 | NIC_CHANNEL_SPAN * channel + 0x1000 + index; |
---|
[295] | 72 | _io_extended_write( vaddr, value ); |
---|
| 73 | } |
---|
| 74 | |
---|
[437] | 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 ) |
---|
[258] | 79 | { |
---|
[437] | 80 | unsigned int* vaddr = (unsigned int*)SEG_NIC_BASE + |
---|
[456] | 81 | NIC_CHANNEL_SPAN * 8 + index; |
---|
[437] | 82 | return _io_extended_read( vaddr ); |
---|
| 83 | } |
---|
[258] | 84 | |
---|
[437] | 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 + |
---|
[456] | 92 | NIC_CHANNEL_SPAN * 8 + index; |
---|
[437] | 93 | _io_extended_write( vaddr, value ); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | //////////////////////////////////////////// |
---|
[456] | 97 | int _nic_global_init( unsigned int bc_enable, |
---|
| 98 | unsigned int bypass_enable, |
---|
| 99 | unsigned int tdm_enable, |
---|
| 100 | unsigned int tdm_period ) |
---|
[437] | 101 | { |
---|
| 102 | _nic_set_global_register( NIC_G_BC_ENABLE , bc_enable ); |
---|
| 103 | _nic_set_global_register( NIC_G_BYPASS_ENABLE, bypass_enable ); |
---|
[456] | 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 ); |
---|
[437] | 108 | |
---|
[258] | 109 | return 0; |
---|
| 110 | } |
---|
[437] | 111 | |
---|
| 112 | //////////////////////////////////////////// |
---|
[448] | 113 | int _nic_channel_start( unsigned int channel, |
---|
| 114 | unsigned int is_rx, |
---|
| 115 | unsigned int mac4, |
---|
| 116 | unsigned int mac2 ) |
---|
[258] | 117 | { |
---|
[456] | 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 | |
---|
[437] | 125 | unsigned int base = SEG_NIC_BASE; |
---|
| 126 | unsigned int extend = (X_IO << Y_WIDTH) + Y_IO; |
---|
[258] | 127 | |
---|
[448] | 128 | if ( is_rx ) |
---|
[437] | 129 | { |
---|
[456] | 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 ); |
---|
[437] | 135 | } |
---|
[448] | 136 | else |
---|
[437] | 137 | { |
---|
[456] | 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 ); |
---|
[437] | 143 | } |
---|
| 144 | |
---|
[258] | 145 | return 0; |
---|
| 146 | } |
---|
[437] | 147 | |
---|
[448] | 148 | //////////////////////////////////////////// |
---|
| 149 | int _nic_channel_stop( unsigned int channel, |
---|
| 150 | unsigned int is_rx ) |
---|
[258] | 151 | { |
---|
[448] | 152 | if ( is_rx ) _nic_set_channel_register( channel, NIC_RX_RUN, 0 ); |
---|
| 153 | else _nic_set_channel_register( channel, NIC_TX_RUN, 0 ); |
---|
[258] | 154 | |
---|
[448] | 155 | return 0; |
---|
[258] | 156 | } |
---|
| 157 | |
---|
[437] | 158 | |
---|
| 159 | |
---|
| 160 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 161 | // Interrupt Service Routines |
---|
| 162 | //////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 163 | |
---|
| 164 | //////////////////////////////////////// |
---|
[295] | 165 | void _nic_rx_isr( unsigned int irq_type, |
---|
| 166 | unsigned int irq_id, |
---|
| 167 | unsigned int channel ) |
---|
| 168 | { |
---|
[437] | 169 | _puts("[NIC WARNING] RX buffers are full for NIC channel "); |
---|
| 170 | _putd( channel ); |
---|
| 171 | _puts("\n"); |
---|
[295] | 172 | } |
---|
[258] | 173 | |
---|
[437] | 174 | //////////////////////////////////////// |
---|
[295] | 175 | void _nic_tx_isr( unsigned int irq_type, |
---|
| 176 | unsigned int irq_id, |
---|
| 177 | unsigned int channel ) |
---|
| 178 | { |
---|
[437] | 179 | _puts("[NIC WARNING] TX buffers are full for NIC channel "); |
---|
| 180 | _putd( channel ); |
---|
| 181 | _puts("\n"); |
---|
[295] | 182 | } |
---|
| 183 | |
---|
[258] | 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 | |
---|