Ignore:
Timestamp:
Jul 12, 2017, 8:12:41 PM (7 years ago)
Author:
alain
Message:

Redefine the PIC device API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_nic.c

    r23 r188  
    22 * dev_nic.c - NIC (Network Controler) generic device API implementation.
    33 *
    4  * Author  Alain Greiner    (2016)
     4 * Author  Alain Greiner    (2016,2017)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3636extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
    3737
    38 extern chdev_pic_input_t  chdev_pic_input;   // allocated in kernel_init.c
    39 
    40 ////////////////////////////////////
    41 void dev_nic_init( chdev_t * chdev )
     38//////////////////////////////////
     39void dev_nic_init( chdev_t * nic )
    4240{
    43     // the local ICU chdev must be initialized before the NIC chdev, because
    44     // the NIC chdevs initialisation requires allocation of a WTI from local ICU
    45     xptr_t  icu_xp  = chdev_dir.icu[local_cxy];
    46     assert( (icu_xp != XPTR_NULL) , __FUNCTION__ , "ICU not initialised before NIC" );
     41    // the PIC chdev must be initialized before the NIC chdev, because
     42    // the NIC chdev initialisation requires the routing of an external IRQ.
     43    xptr_t  pic_xp  = chdev_dir.pic;
     44
     45    assert( (pic_xp != XPTR_NULL) , __FUNCTION__ , "ICU not initialised before NIC" );
    4746
    4847    // get "impl" , "channel" , "is_rx" fields from chdev descriptor
    49     uint32_t  impl    = chdev->impl;
    50     uint32_t  is_rx   = chdev->is_rx;
    51     uint32_t  channel = chdev->channel;
     48    uint32_t  impl    = nic->impl;
     49    uint32_t  channel = nic->channel;
     50    bool_t    is_rx   = nic->is_rx;
    5251
    5352    // set chdev name
    54     snprintf( chdev->name , 16 , "nic_%d" , chdev->channel );
     53    if( is_rx ) snprintf( nic->name , 16 , "nic_rx_%d" , channel );
     54    else        snprintf( nic->name , 16 , "nic_tx_%d" , channel );
    5555
    5656    // set driver specific fields in chdev descriptor and call driver init function
    5757    if( impl == IMPL_NIC_SOC )
    5858    {
    59         chdev->cmd = &soclib_nic_cmd;
    60         chdev->isr = &soclib_nic_isr;
    61         soclib_nic_init( chdev );
     59        nic->cmd = &soclib_nic_cmd;
     60        nic->isr = &soclib_nic_isr;
     61        soclib_nic_init( nic );
    6262    }
    6363    else
     
    6666    }
    6767
    68     // get a WTI mailbox from local ICU
    69     uint32_t wti_id = dev_icu_wti_alloc();
    70 
    71     assert( (wti_id != -1) , __FUNCTION__ , "cannot allocate WTI mailbox" );
    72 
    73     // select a core
     68    // select a core to execute the NIC server thread
    7469    lid_t lid = cluster_select_local_core();
    7570
    76     // enable WTI IRQ and update WTI interrupt vector
    77     dev_icu_enable_irq( lid , WTI_TYPE , wti_id , chdev );
    78 
    79     // link NIC IRQ to WTI mailbox in PIC component
    80     uint32_t irq_id;
    81     if( is_rx ) irq_id = chdev_pic_input.nic_rx[channel];
    82     else        irq_id = chdev_pic_input.nic_tx[channel];
    83     dev_pic_bind_irq( irq_id , local_cxy , wti_id );
     71    // bind the NIC IRQ to the selected core
     72    // but does NOT enable it
     73    dev_pic_bind_irq( lid , nic );
    8474
    8575    // create server thread
     
    9080                                  THREAD_DEV,
    9181                                  &chdev_sequencial_server,
    92                                   chdev,
     82                                  nic,
    9383                                  lid );
    9484
     
    9686
    9787    // set "server" field in chdev descriptor
    98     chdev->server = new_thread;
     88    nic->server = new_thread;
    9989   
    10090    // start server thread
     
    142132    if( thread_ptr->command.nic.status == false ) 
    143133    {
    144         // get NIC-RX IRQ index and type
    145         uint32_t   irq_type = dev_ptr->irq_type;
    146         uint32_t   irq_id   = dev_ptr->irq_id;
    147 
    148134        // enable NIC-RX IRQ
    149         dev_icu_enable_irq( core->lid , irq_type , irq_id , dev_ptr );
    150 
    151         // block on THREAD_BLOCKED I/O condition and deschedule
     135        dev_pic_enable_irq( core->lid , dev_ptr );
     136
     137        // block on THREAD_BLOCKED_IO condition and deschedule
    152138        thread_block( thread_ptr , THREAD_BLOCKED_IO );
    153139        sched_yield();
    154140
    155         // disable NIC-RX channel IRQ
    156         dev_icu_disable_irq( core->lid , irq_type , irq_id );
     141        // disable NIC-RX IRQ
     142        dev_pic_disable_irq( core->lid , dev_ptr );
    157143    }
    158144
     
    206192
    207193    // call driver to test writable
    208     thread_ptr->command.nic.cmd    = NIC_CMD_WRITABLE;
     194    thread_ptr->command.nic.cmd = NIC_CMD_WRITABLE;
    209195    dev_ptr->cmd( thread_xp );
    210196
     
    216202    if( thread_ptr->command.nic.status == false ) 
    217203    {
    218         // get NIC-TX IRQ index and type
    219         uint32_t   irq_type = dev_ptr->irq_type;
    220         uint32_t   irq_id   = dev_ptr->irq_id;
    221 
    222204        // enable NIC-TX IRQ
    223         dev_icu_enable_irq( core->lid , irq_type , irq_id , dev_ptr );
     205        dev_pic_enable_irq( core->lid ,dev_ptr );
    224206
    225207        // block on THREAD_BLOCKED I/O condition and deschedule
     
    228210
    229211        // disable NIC-TX IRQ
    230         dev_icu_disable_irq( core->lid , irq_type , irq_id );
     212        dev_pic_disable_irq( core->lid , dev_ptr );
    231213    }
    232214
Note: See TracChangeset for help on using the changeset viewer.