Ignore:
Timestamp:
Apr 26, 2017, 2:10:21 PM (7 years ago)
Author:
alain
Message:

Introduce the chdev_t structure in place of device_t.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/drivers/soclib/soclib_nic.c

    r1 r4  
    2525#include <hal_remote.h>
    2626#include <hal_special.h>
    27 #include <device.h>
     27#include <chdev.h>
    2828#include <dev_nic.h>
    2929#include <spinlock.h>
     
    3434#include <soclib_nic.h>
    3535
    36 
    37 /////////////////////////////////////
    38 void soclib_nic_init( xptr_t dev_xp )
     36///////////////////////////////////////
     37void soclib_nic_init( chdev_t * chdev )
    3938{
    4039    uint32_t    i;
    4140    kmem_req_t  req;
    4241   
    43     // get NIC device descriptor cluster and local pointer
    44     cxy_t      dev_cxy  = GET_CXY( dev_xp );
    45     device_t * dev_ptr  = (device_t *)GET_PTR( dev_xp );
    46  
    47     // get hardware device base address
    48         xptr_t     base = hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
    49 
    5042    // get hardware device cluster and local pointer
    51     cxy_t      nic_cxy  = GET_CXY( base );
    52     uint32_t * nic_ptr  = (uint32_t *)GET_PTR( base );
     43    cxy_t      nic_cxy  = GET_CXY( chdev->base );
     44    uint32_t * nic_ptr  = (uint32_t *)GET_PTR( chdev->base );
    5345
    5446    // initialize Soclib NIC global registers
     
    5749
    5850    // allocate memory for chbuf descriptor (one page)
    59     if( sizeof(nic_chbuf_t) > CONFIG_PPM_PAGE_SIZE )
    60     {
    61         printk("\n[PANIC] in %s : chbuf descriptor exceeds one page\n", __FUNCTION__ );
    62         hal_core_sleep();
    63     }
     51    assert( (sizeof(nic_chbuf_t) <= CONFIG_PPM_PAGE_SIZE ) , __FUNCTION__ ,
     52            "chbuf descriptor exceeds one page" );
    6453
    6554    req.type   = KMEM_PAGE;
     
    6958    nic_chbuf_t * chbuf = (nic_chbuf_t *)kmem_alloc( &req );
    7059
    71     if( chbuf == NULL )
    72     {
    73         hal_core_sleep("%s : no more memory for chbuf desccriptor\n", __FUNCTION__ );
    74     }
     60    assert( (chbuf != NULL) , __FUNCTION__ ,
     61             "cannot allocate chbuf descriptor" );
    7562
    7663    // initialise chbuf state
     
    8168    // allocate containers (one page per container)
    8269    // and complete chbuf descriptor initialization
    83     if( CONFIG_PPM_PAGE_SIZE != 4096 )
    84     {
    85         hal_core_sleep("%s : chbuf container must be 4 Kbytes\n", __FUNCTION__ );
    86     }
     70    assert( (CONFIG_PPM_PAGE_SIZE == 4096) , __FUNCTION__ ,
     71            "chbuf container must be 4 Kbytes" );
    8772
    8873    for( i = 0 ; i < CONFIG_NIC_CHBUF_DEPTH ; i++ )
     
    9075        uint32_t * container = (uint32_t *)kmem_alloc( &req );   
    9176
    92         if( container == NULL )
    93         {
    94             hal_core_sleep("%s : no more memory for container\n", __FUNCTION__ );
    95         }
     77        assert( (container != NULL) , __FUNCTION__ ,
     78                "cannot allocate container" );
    9679       
    9780        chbuf->cont[i] = container;
    9881        chbuf->full[i] = (paddr_t)XPTR( local_cxy , container );
    9982    }
    100 
    10183} // end soclib_nic_init()
    10284
     
    121103
    122104    // get command arguments
    123     cmd    = thread_ptr->dev.nic.cmd;
    124     buffer = thread_ptr->dev.nic.buffer;
    125     length = thread_ptr->dev.nic.length;
    126     dev_xp = thread_ptr->dev.nic.dev_xp;
     105    cmd    = thread_ptr->command.nic.cmd;
     106    buffer = thread_ptr->command.nic.buffer;
     107    length = thread_ptr->command.nic.length;
     108    dev_xp = thread_ptr->command.nic.dev_xp;
    127109
    128110    // get local pointer for device
    129     device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
     111    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
    130112
    131113    // get chbuf descriptor pointer
     
    226208            {
    227209                // return chbuf writable
    228                 thread_ptr->dev.nic.status = true;
     210                thread_ptr->command.nic.status = true;
    229211            }
    230212            else                    // current container not writable
     
    244226                     
    245227                    // return chbuf writable
    246                     thread_ptr->dev.nic.status = true;
     228                    thread_ptr->command.nic.status = true;
    247229                }
    248230                else                            // next container full     
    249231                {
    250232                    // return chbuf non writable
    251                     thread_ptr->dev.nic.status = false;
     233                    thread_ptr->command.nic.status = false;
    252234                }
    253235            }
     
    270252            {
    271253                // return chbuf readable     
    272                 thread_ptr->dev.nic.status = true;
     254                thread_ptr->command.nic.status = true;
    273255            }
    274256            else                        // current container non readable
     
    288270                     
    289271                    // return chbuf readable
    290                     thread_ptr->dev.nic.status = true;
     272                    thread_ptr->command.nic.status = true;
    291273                }
    292274                else                            // next container empty   
    293275                {
    294276                    // return chbuf non readable
    295                     thread_ptr->dev.nic.status = false;
     277                    thread_ptr->command.nic.status = false;
    296278                }
    297279            }
     
    303285
    304286
    305 ////////////////////////////////////////////////////////////////
    306 void __attribute__ ((noinline)) soclib_nic_isr( device_t * dev )
     287/////////////////////////////////////////////////////////////////
     288void __attribute__ ((noinline)) soclib_nic_isr( chdev_t * chdev )
    307289{
    308290    // get base, size, channel, is_rx from NIC channel device NIC
    309     xptr_t     base    = dev->base;
    310     uint32_t   channel = dev->channel;
    311     bool_t     is_rx   = dev->is_rx;
     291    xptr_t     base    = chdev->base;
     292    uint32_t   channel = chdev->channel;
     293    bool_t     is_rx   = chdev->is_rx;
    312294
    313295    // get NIC peripheral cluster and local pointer
     
    326308   
    327309    // unblock server thread
    328     thread_t * server = dev->server;
     310    thread_t * server = chdev->server;
    329311    thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_IO );
    330312
Note: See TracChangeset for help on using the changeset viewer.