Changeset 4 for trunk/kernel/drivers/soclib/soclib_nic.c
- Timestamp:
- Apr 26, 2017, 2:10:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/drivers/soclib/soclib_nic.c
r1 r4 25 25 #include <hal_remote.h> 26 26 #include <hal_special.h> 27 #include < device.h>27 #include <chdev.h> 28 28 #include <dev_nic.h> 29 29 #include <spinlock.h> … … 34 34 #include <soclib_nic.h> 35 35 36 37 ///////////////////////////////////// 38 void soclib_nic_init( xptr_t dev_xp ) 36 /////////////////////////////////////// 37 void soclib_nic_init( chdev_t * chdev ) 39 38 { 40 39 uint32_t i; 41 40 kmem_req_t req; 42 41 43 // get NIC device descriptor cluster and local pointer44 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 address48 xptr_t base = hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );49 50 42 // 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 ); 53 45 54 46 // initialize Soclib NIC global registers … … 57 49 58 50 // 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" ); 64 53 65 54 req.type = KMEM_PAGE; … … 69 58 nic_chbuf_t * chbuf = (nic_chbuf_t *)kmem_alloc( &req ); 70 59 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" ); 75 62 76 63 // initialise chbuf state … … 81 68 // allocate containers (one page per container) 82 69 // 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" ); 87 72 88 73 for( i = 0 ; i < CONFIG_NIC_CHBUF_DEPTH ; i++ ) … … 90 75 uint32_t * container = (uint32_t *)kmem_alloc( &req ); 91 76 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" ); 96 79 97 80 chbuf->cont[i] = container; 98 81 chbuf->full[i] = (paddr_t)XPTR( local_cxy , container ); 99 82 } 100 101 83 } // end soclib_nic_init() 102 84 … … 121 103 122 104 // 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; 127 109 128 110 // 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 ); 130 112 131 113 // get chbuf descriptor pointer … … 226 208 { 227 209 // return chbuf writable 228 thread_ptr-> dev.nic.status = true;210 thread_ptr->command.nic.status = true; 229 211 } 230 212 else // current container not writable … … 244 226 245 227 // return chbuf writable 246 thread_ptr-> dev.nic.status = true;228 thread_ptr->command.nic.status = true; 247 229 } 248 230 else // next container full 249 231 { 250 232 // return chbuf non writable 251 thread_ptr-> dev.nic.status = false;233 thread_ptr->command.nic.status = false; 252 234 } 253 235 } … … 270 252 { 271 253 // return chbuf readable 272 thread_ptr-> dev.nic.status = true;254 thread_ptr->command.nic.status = true; 273 255 } 274 256 else // current container non readable … … 288 270 289 271 // return chbuf readable 290 thread_ptr-> dev.nic.status = true;272 thread_ptr->command.nic.status = true; 291 273 } 292 274 else // next container empty 293 275 { 294 276 // return chbuf non readable 295 thread_ptr-> dev.nic.status = false;277 thread_ptr->command.nic.status = false; 296 278 } 297 279 } … … 303 285 304 286 305 //////////////////////////////////////////////////////////////// 306 void __attribute__ ((noinline)) soclib_nic_isr( device_t *dev )287 ///////////////////////////////////////////////////////////////// 288 void __attribute__ ((noinline)) soclib_nic_isr( chdev_t * chdev ) 307 289 { 308 290 // 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; 312 294 313 295 // get NIC peripheral cluster and local pointer … … 326 308 327 309 // unblock server thread 328 thread_t * server = dev->server;310 thread_t * server = chdev->server; 329 311 thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_IO ); 330 312
Note: See TracChangeset
for help on using the changeset viewer.