Changeset 448


Ignore:
Timestamp:
Nov 11, 2014, 4:10:53 PM (10 years ago)
Author:
alain
Message:

Simplifying the NIC and CMA drivers.
Complex functionnalities have been moved to the sys_handler.c file.

Location:
soft/giet_vm/giet_drivers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_drivers/cma_driver.c

    r437 r448  
    3434
    3535////////////////////////////////////////////////////
    36 void _cma_start_channel( unsigned int       channel,
     36void _cma_channel_start( unsigned int       channel,
    3737                         unsigned long long src_paddr,
    3838                         unsigned int       src_nbufs,
     
    5353
    5454//////////////////////////////////////////////
    55 void _cma_stop_channel( unsigned int channel )
     55void _cma_channel_stop( unsigned int channel )
    5656{
    57     _cma_set_register( channel, CHBUF_RUN      , 0 );
     57    _cma_set_register( channel, CHBUF_RUN, 0 );
    5858}
    5959
     
    6363               unsigned int channel )
    6464{
    65     _puts("\n[GIET ERROR] _cma_isr() not implemented\n");
    66     _exit();
     65    // get CMA channel status
     66    unsigned int status = _cma_get_register( channel, CHBUF_STATUS );
     67
     68    if (status == CHANNEL_SRC_DESC_ERROR )
     69        _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : "
     70                "impossible access to source chbuf descriptor\n",
     71                channel, _get_proctime() );
     72
     73    else if (status == CHANNEL_SRC_DATA_ERROR )
     74        _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : "
     75                "impossible access to source data buffer\n",
     76                channel, _get_proctime() );
     77
     78    else if (status == CHANNEL_DST_DESC_ERROR )
     79        _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : "
     80                "impossible access to destination chbuf descriptor\n",
     81                channel, _get_proctime() );
     82
     83    else if (status == CHANNEL_DST_DATA_ERROR )
     84        _printf("\n[CMA WARNING] CMA channel %d blocked at cycle %d : "
     85                "impossible access to destination data buffer\n",
     86                channel, _get_proctime() );
     87
     88    else
     89        _printf("\n[CMA WARNING] CMA channel %d : "
     90                "... strange IRQ received, but channel not blocked...",
     91                channel, _get_proctime() );
     92   
     93    // acknowledge IRQ
     94    _cma_set_register( channel, CHBUF_RUN, 0 );
    6795}
    6896
  • soft/giet_vm/giet_drivers/cma_driver.h

    r437 r448  
    2727
    2828///////////////////////////////////////////////////////////////////////////////////
    29 //  registers offsets
     29//  CMA channel registers offsets
    3030///////////////////////////////////////////////////////////////////////////////////
    3131
    32 enum CMA_registers
     32enum CMA_registers_e
    3333{
    3434    CHBUF_RUN           = 0,    // write-only : channel activated
     
    4747
    4848///////////////////////////////////////////////////////////////////////////////////
     49//  CMA channel status values
     50///////////////////////////////////////////////////////////////////////////////////
     51
     52enum CMA_status_e
     53{
     54    CHANNEL_IDLE,
     55
     56    CHANNEL_SRC_DATA_ERROR,
     57    CHANNEL_DST_DATA_ERROR,
     58    CHANNEL_SRC_DESC_ERROR,
     59    CHANNEL_DST_DESC_ERROR,
     60
     61    CHANNEL_READ_SRC_STATUS,
     62    CHANNEL_READ_SRC_STATUS_WAIT,
     63    CHANNEL_READ_SRC_STATUS_DELAY,
     64    CHANNEL_READ_SRC_BUFADDR,
     65    CHANNEL_READ_SRC_BUFADDR_WAIT,
     66
     67    CHANNEL_READ_DST_STATUS,
     68    CHANNEL_READ_DST_STATUS_WAIT,
     69    CHANNEL_READ_DST_STATUS_DELAY,
     70    CHANNEL_READ_DST_BUFADDR,
     71    CHANNEL_READ_DST_BUFADDR_WAIT,
     72
     73    CHANNEL_READ_BURST,
     74    CHANNEL_READ_REQ_FIRST,
     75    CHANNEL_READ_WAIT_FIRST,
     76    CHANNEL_READ_REQ_SECOND,
     77    CHANNEL_READ_WAIT_SECOND,
     78
     79    CHANNEL_WRITE_BURST,
     80    CHANNEL_WRITE_REQ_FIRST,
     81    CHANNEL_WRITE_WAIT_FIRST,
     82    CHANNEL_WRITE_REQ_SECOND,
     83    CHANNEL_WRITE_WAIT_SECOND,
     84
     85    CHANNEL_SRC_STATUS_WRITE,
     86    CHANNEL_SRC_STATUS_WRITE_WAIT,
     87    CHANNEL_DST_STATUS_WRITE,
     88    CHANNEL_DST_STATUS_WRITE_WAIT,
     89    CHANNEL_SRC_NEXT_BUFFER,
     90    CHANNEL_DST_NEXT_BUFFER,
     91};
     92
     93///////////////////////////////////////////////////////////////////////////////////
    4994//    access functions
    5095///////////////////////////////////////////////////////////////////////////////////
    5196
    52 ////////////////////////////////////////////////////////////
    5397extern unsigned int _cma_get_register( unsigned int channel,
    5498                                       unsigned int index );
    5599
    56 ///////////////////////////////////////////////////
    57100extern void _cma_set_register( unsigned int channel,
    58101                               unsigned int index,
    59102                               unsigned int value );
    60103
    61 ///////////////////////////////////////////////////
    62 void _cma_start_channel( unsigned int       channel,
     104void _cma_channel_start( unsigned int       channel,
    63105                         unsigned long long src_paddr,
    64106                         unsigned int       src_nbufs,
     
    67109                         unsigned int       buf_length );
    68110
    69 //////////////////////////////////////////////
    70 void _cma_stop_channel( unsigned int channel );
     111void _cma_channel_stop( unsigned int channel );
    71112
    72 ////////////////////////////////////////////
    73113extern void _cma_isr( unsigned int irq_type,
    74114                      unsigned int irq_id,
  • soft/giet_vm/giet_drivers/nic_driver.c

    r437 r448  
    4949#endif
    5050
    51 #if !defined( GIET_CHBUF_NBUFS )
    52 # error: You must define GIET_CHBUF_NBUFS in the giet_config.h file
     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
    5361#endif
    5462
     
    115123
    116124////////////////////////////////////////////
    117 int _nic_channel_init( unsigned int index,
    118                        unsigned int mac4,
    119                        unsigned int mac2 )
     125int _nic_channel_start( unsigned int channel,
     126                        unsigned int is_rx,
     127                        unsigned int mac4,
     128                        unsigned int mac2 )
    120129{
    121130    unsigned int base     = SEG_NIC_BASE;
    122131    unsigned int extend   = (X_IO << Y_WIDTH) + Y_IO;
    123132
    124     _nic_set_channel_register( index, NIC_RX_DESC_LO_0 + 4096, base );
    125     _nic_set_channel_register( index, NIC_RX_DESC_LO_1 + 4096, base + 0x1000 );
    126     _nic_set_channel_register( index, NIC_TX_DESC_LO_0 + 4096, base + 0x2000 );
    127     _nic_set_channel_register( index, NIC_TX_DESC_LO_1 + 4096, base + 0x3000 );
     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    }
    128149
    129     _nic_set_channel_register( index, NIC_RX_DESC_HI_0       , extend );
    130     _nic_set_channel_register( index, NIC_RX_DESC_HI_1       , extend );
    131     _nic_set_channel_register( index, NIC_TX_DESC_HI_0       , extend );
    132     _nic_set_channel_register( index, NIC_TX_DESC_HI_1       , extend );
    133 
    134     _nic_set_channel_register( index, NIC_MAC_4              , mac4 );
    135     _nic_set_channel_register( index, NIC_MAC_2              , mac2 );
     150    _nic_set_channel_register( channel, NIC_MAC_4              , mac4 );
     151    _nic_set_channel_register( channel, NIC_MAC_2              , mac2 );
    136152   
    137     _nic_set_channel_register( index, NIC_RX_RUN             , 1 );
    138     _nic_set_channel_register( index, NIC_TX_RUN             , 1 );
    139 
    140153    return 0;
    141154}
    142155
    143 /////////////////////////////////////////////////////////////////////////////////////
    144 //             Synchronous access functions
    145 /////////////////////////////////////////////////////////////////////////////////////
     156////////////////////////////////////////////
     157int _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 );
    146162
    147 ///////////////////////////////////////////////
    148 int _nic_sync_send( unsigned int        channel,
    149                     unsigned long long  user_paddr )
    150 {
    151     unsigned long long nic_paddr;   // nic buffer physical address
    152     unsigned int       done = 0;
    153     unsigned int       lsb;
    154     unsigned int       msb;
    155 
    156     if ( channel >= NB_NIC_CHANNELS )
    157     {
    158         _puts("[GIET ERROR] in _timer_sync_send()\n");
    159         return -1;
    160     }
    161 
    162     // poll the NIC buffers
    163     while ( done == 0 )
    164     {
    165         // test availability of NIC TX buffer 0
    166         lsb  = _nic_get_channel_register( channel, NIC_TX_DESC_LO_0 );
    167         msb  = _nic_get_channel_register( channel, NIC_TX_DESC_HI_0 );
    168         if ( (msb & 0x80000000) == 0 )
    169         {
    170             msb  = msb & 0x0000FFFF;
    171             done = 1;
    172             continue;
    173         }
    174 
    175         // test availability of NIC TX buffer 1
    176         lsb  = _nic_get_channel_register( channel, NIC_TX_DESC_LO_1 );
    177         msb  = _nic_get_channel_register( channel, NIC_TX_DESC_HI_1 );
    178         if ( (msb & 0x80000000) == 0 )
    179         {
    180             msb  = msb & 0x0000FFFF;
    181             done = 1;
    182             continue;
    183         }
    184 
    185         // random delay (average value: 380 cycle)
    186         _random_wait( 8 );
    187     }
    188 
    189     // make the transfer
    190     nic_paddr = (unsigned long long)lsb + (((unsigned long long)msb) << 32);
    191 
    192     _physical_memcpy( nic_paddr , user_paddr, 4096 );
    193 
    194     return 0;
     163    return 0;   
    195164}
    196165
    197 ///////////////////////////////////////////////////
    198 int _nic_sync_receive( unsigned int        channel,
    199                        unsigned long long  user_paddr )
    200 {
    201     unsigned long long nic_paddr;   // nic  buffer physical address
    202     unsigned int       done = 0;
    203     unsigned int       lsb;
    204     unsigned int       msb;
    205166
    206     if ( channel >= NB_NIC_CHANNELS )
    207     {
    208         _puts("[GIET ERROR] in _timer_sync_receive()\n");
    209         return -1;
    210     }
    211 
    212     // polling the NIC buffers
    213     while ( done == 0 )
    214     {
    215         // test availability of NIC RX buffer 0
    216         lsb  = _nic_get_channel_register( channel, NIC_RX_DESC_LO_0 );
    217         msb  = _nic_get_channel_register( channel, NIC_RX_DESC_HI_0 );
    218         if ( (msb & 0x80000000) == 1 )
    219         {
    220             msb  = msb & 0x0000FFFF;
    221             done = 1;
    222             continue;
    223         }
    224 
    225         // test availability of NIC RX buffer 1
    226         lsb  = _nic_get_channel_register( channel, NIC_RX_DESC_LO_1 );
    227         msb  = _nic_get_channel_register( channel, NIC_RX_DESC_HI_1 );
    228         if ( (msb & 0x80000000) == 1 )
    229         {
    230             msb  = msb & 0x0000FFFF;
    231             done = 1;
    232             continue;
    233         }
    234 
    235         // random delay (average value: 380 cycle)
    236         _random_wait( 8 );
    237     }
    238 
    239     // make the transfer
    240     nic_paddr = (unsigned long long)lsb + (((unsigned long long)msb) << 32);
    241 
    242     _physical_memcpy( user_paddr, nic_paddr , 4096 );
    243 
    244     return 0;
    245 }
    246 
    247 /////////////////////////////////////////////////////////////////////////////////////
    248 //             CMA access functions
    249 /////////////////////////////////////////////////////////////////////////////////////
    250 
    251 //////////////////////////////////////////////////////////////
    252 int _nic_cma_receive( unsigned int  nic_channel,
    253                       unsigned int  cma_channel,
    254                       nic_chbuf_t*  kernel_chbuf )
    255                              
    256 {
    257     unsigned int nic_chbuf_lsb;     // 32 LSB bits of the NIC chbuf physical address
    258     unsigned int nic_chbuf_msb;     // 16 MSB bits of the NIC chbuf physical address
    259     unsigned int mem_chbuf_lsb;     // 32 LSB bits of the kernel chbuf physical address
    260     unsigned int mem_chbuf_msb;     // 16 MSB bits of the kernel chbuf physical address
    261 
    262     unsigned int ppn;
    263     unsigned int flags;
    264 
    265     // checking parameters
    266     if ( nic_channel >= NB_NIC_CHANNELS )
    267     {
    268         _puts("[GIET ERROR] in _nic_cma_start_receive() : nic_channel index too large\n");
    269         return -1;
    270     }
    271     if ( cma_channel >= NB_CMA_CHANNELS )
    272     {
    273         _puts("[GIET ERROR] in _nic_cma_start_receive() : cma_channel index too large\n");
    274         return -1;
    275     }
    276 
    277     // get the NIC_RX chbuf descriptor physical address
    278     nic_chbuf_lsb = SEG_NIC_BASE + (nic_channel * NIC_CHANNEL_SPAN) + 0x1000;
    279     nic_chbuf_msb = (X_IO << Y_WIDTH) + Y_IO;
    280 
    281     // compute the kernel chbuf physical address
    282     unsigned int ptab  = _get_context_slot(CTX_PTAB_ID);
    283     unsigned int vaddr = (unsigned int)kernel_chbuf;
    284     unsigned int ko    = _v2p_translate( (page_table_t*)ptab,
    285                                           vaddr,
    286                                           &ppn,
    287                                           &flags );
    288     if ( ko )
    289     {
    290         _puts("\n[GIET ERROR] in _nic_cma_start_receive() : kernel buffer unmapped\n");
    291         return -1;
    292     }
    293 
    294     mem_chbuf_lsb = (ppn << 12) | (vaddr & 0x00000FFF);
    295     mem_chbuf_msb = ppn >> 20;
    296 
    297     // initializes CMA registers defining the source chbuf (NIC_RX)
    298     _cma_set_register( cma_channel, CHBUF_SRC_DESC , nic_chbuf_lsb );
    299     _cma_set_register( cma_channel, CHBUF_DST_EXT  , nic_chbuf_msb );
    300     _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, 2 );
    301 
    302     // initializes CMA registers defining the destination chbuf (kernel memory)
    303     _cma_set_register( cma_channel, CHBUF_DST_DESC , mem_chbuf_lsb );
    304     _cma_set_register( cma_channel, CHBUF_DST_EXT  , mem_chbuf_msb );
    305     _cma_set_register( cma_channel, CHBUF_DST_NBUFS, GIET_CHBUF_NBUFS );
    306 
    307     // set buffer size, polling period, and start
    308     _cma_set_register( cma_channel, CHBUF_BUF_SIZE , 4096 );
    309     _cma_set_register( cma_channel, CHBUF_PERIOD   , 300 );
    310     _cma_set_register( cma_channel, CHBUF_RUN      , 1 );
    311 
    312     return 0;
    313 }
    314 
    315 //////////////////////////////////////////////////////////
    316 int _nic_cma_send( unsigned int  nic_channel,
    317                    unsigned int  cma_channel,
    318                    nic_chbuf_t*  kernel_chbuf )
    319 {
    320     unsigned int nic_chbuf_lsb;     // 32 LSB bits of the NIC chbuf physical address
    321     unsigned int nic_chbuf_msb;     // 16 MSB bits of the NIC chbuf physical address
    322     unsigned int mem_chbuf_lsb;     // 32 LSB bits of the kernel chbuf physical address
    323     unsigned int mem_chbuf_msb;     // 16 MSB bits of the kernel chbuf physical address
    324 
    325     unsigned int ppn;
    326     unsigned int flags;
    327 
    328     // checking parameters
    329     if ( nic_channel >= NB_NIC_CHANNELS )
    330     {
    331         _puts("[GIET ERROR] in _nic_cma_start_send() : nic_channel index too large\n");
    332         return -1;
    333     }
    334     if ( cma_channel >= NB_CMA_CHANNELS )
    335     {
    336         _puts("[GIET ERROR] in _nic_cma_start_send() : cma_channel index too large\n");
    337         return -1;
    338     }
    339 
    340     // get the NIC_TX chbuf descriptor physical address
    341     nic_chbuf_lsb = SEG_NIC_BASE + (nic_channel * NIC_CHANNEL_SPAN) + 0x1010;
    342     nic_chbuf_msb = (X_IO << Y_WIDTH) + Y_IO;
    343 
    344     // compute the kernel chbuf physical address
    345     unsigned int ptab  = _get_context_slot(CTX_PTAB_ID);
    346     unsigned int vaddr = (unsigned int)kernel_chbuf;
    347     unsigned int ko    = _v2p_translate( (page_table_t*)ptab,
    348                                           vaddr,
    349                                           &ppn,
    350                                           &flags );
    351     if ( ko )
    352     {
    353         _puts("\n[GIET ERROR] in _nic_cma_start_send() : kernel buffer unmapped\n");
    354         return -1;
    355     }
    356 
    357     mem_chbuf_lsb = (ppn << 12) | (vaddr & 0x00000FFF);
    358     mem_chbuf_msb = ppn >> 20;
    359 
    360     // initializes CMA registers defining the source chbuf (kernel memory)
    361     _cma_set_register( cma_channel, CHBUF_SRC_DESC , mem_chbuf_lsb );
    362     _cma_set_register( cma_channel, CHBUF_DST_EXT  , mem_chbuf_msb );
    363     _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, GIET_CHBUF_NBUFS );
    364 
    365     // initializes CMA registers defining the destination chbuf (NIC_TX)
    366     _cma_set_register( cma_channel, CHBUF_DST_DESC , nic_chbuf_lsb );
    367     _cma_set_register( cma_channel, CHBUF_DST_EXT  , nic_chbuf_msb );
    368     _cma_set_register( cma_channel, CHBUF_DST_NBUFS, 2 );
    369 
    370     // set buffer size, polling period, and start
    371     _cma_set_register( cma_channel, CHBUF_BUF_SIZE , 4096 );
    372     _cma_set_register( cma_channel, CHBUF_PERIOD   , 300 );
    373     _cma_set_register( cma_channel, CHBUF_RUN      , 1 );
    374 
    375     return 0;
    376 }
    377167
    378168////////////////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_drivers/nic_driver.h

    r437 r448  
    9999
    100100
    101 ////////////////////////////////////////////////////////////////////////////////////
    102 //              Chained Buffer Descriptor Structure
    103 ////////////////////////////////////////////////////////////////////////////////////
    104 typedef struct nic_chbuf_s
    105 {
    106     unsigned long long buf[GIET_CHBUF_NBUFS]; // array of buffer descriptors
    107     unsigned int       buf_length;            // buffer length (bytes)
    108     unsigned int       nb_buffers;            // actual number of buffers
    109 } nic_chbuf_t;
    110 
    111101///////////////////////////////////////////////////////////////////////////////////
    112102//              Initialization functions
     
    118108                             unsigned int bypass_enable );
    119109
    120 extern int _nic_channel_init( unsigned int index,
    121                               unsigned int mac4,
    122                               unsigned int mac2 );
     110extern int _nic_channel_start( unsigned int channel,
     111                               unsigned int is_rx,
     112                               unsigned int mac4,
     113                               unsigned int mac2 );
    123114
    124 ///////////////////////////////////////////////////////////////////////////////////
    125 //              Blocking functions using a physical_memcpy()
    126 ///////////////////////////////////////////////////////////////////////////////////
     115extern int _nic_channel_stop( unsigned int channel,
     116                              unsigned int is_rx );
    127117
    128 extern int _nic_sync_receive( unsigned int       channel,
    129                               unsigned long long user_paddr );
    130 
    131 extern int _nic_sync_send( unsigned int       channel,
    132                            unsigned long long user_paddr );
    133 
    134 ///////////////////////////////////////////////////////////////////////////////////
    135 //              Non blocking functions using the chained buffer DMA
    136 ///////////////////////////////////////////////////////////////////////////////////
    137 
    138 extern int _nic_cma_receive( unsigned int  nic_channel,
    139                              unsigned int  cma_channel,
    140                              nic_chbuf_t*  kernel_chbuf );
    141 
    142 extern int _nic_cma_send( unsigned int  nic_channel,
    143                           unsigned int  cma_channel,
    144                           nic_chbuf_t*  kernel_chbuf );
    145118
    146119///////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.