Changeset 188 for trunk/kernel/devices/dev_nic.c
- Timestamp:
- Jul 12, 2017, 8:12:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/devices/dev_nic.c
r23 r188 2 2 * dev_nic.c - NIC (Network Controler) generic device API implementation. 3 3 * 4 * Author Alain Greiner (2016 )4 * Author Alain Greiner (2016,2017) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 36 36 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c 37 37 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 ////////////////////////////////// 39 void dev_nic_init( chdev_t * nic ) 42 40 { 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" ); 47 46 48 47 // 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; 52 51 53 52 // 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 ); 55 55 56 56 // set driver specific fields in chdev descriptor and call driver init function 57 57 if( impl == IMPL_NIC_SOC ) 58 58 { 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 ); 62 62 } 63 63 else … … 66 66 } 67 67 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 74 69 lid_t lid = cluster_select_local_core(); 75 70 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 ); 84 74 85 75 // create server thread … … 90 80 THREAD_DEV, 91 81 &chdev_sequencial_server, 92 chdev,82 nic, 93 83 lid ); 94 84 … … 96 86 97 87 // set "server" field in chdev descriptor 98 chdev->server = new_thread;88 nic->server = new_thread; 99 89 100 90 // start server thread … … 142 132 if( thread_ptr->command.nic.status == false ) 143 133 { 144 // get NIC-RX IRQ index and type145 uint32_t irq_type = dev_ptr->irq_type;146 uint32_t irq_id = dev_ptr->irq_id;147 148 134 // 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 deschedule135 dev_pic_enable_irq( core->lid , dev_ptr ); 136 137 // block on THREAD_BLOCKED_IO condition and deschedule 152 138 thread_block( thread_ptr , THREAD_BLOCKED_IO ); 153 139 sched_yield(); 154 140 155 // disable NIC-RX channelIRQ156 dev_ icu_disable_irq( core->lid , irq_type , irq_id);141 // disable NIC-RX IRQ 142 dev_pic_disable_irq( core->lid , dev_ptr ); 157 143 } 158 144 … … 206 192 207 193 // call driver to test writable 208 thread_ptr->command.nic.cmd 194 thread_ptr->command.nic.cmd = NIC_CMD_WRITABLE; 209 195 dev_ptr->cmd( thread_xp ); 210 196 … … 216 202 if( thread_ptr->command.nic.status == false ) 217 203 { 218 // get NIC-TX IRQ index and type219 uint32_t irq_type = dev_ptr->irq_type;220 uint32_t irq_id = dev_ptr->irq_id;221 222 204 // 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 ); 224 206 225 207 // block on THREAD_BLOCKED I/O condition and deschedule … … 228 210 229 211 // disable NIC-TX IRQ 230 dev_ icu_disable_irq( core->lid , irq_type , irq_id);212 dev_pic_disable_irq( core->lid , dev_ptr ); 231 213 } 232 214
Note: See TracChangeset
for help on using the changeset viewer.