Changeset 448 for soft/giet_vm/giet_drivers/nic_driver.c
- Timestamp:
- Nov 11, 2014, 4:10:53 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_drivers/nic_driver.c
r437 r448 49 49 #endif 50 50 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 53 61 #endif 54 62 … … 115 123 116 124 //////////////////////////////////////////// 117 int _nic_channel_init( unsigned int index, 118 unsigned int mac4, 119 unsigned int mac2 ) 125 int _nic_channel_start( unsigned int channel, 126 unsigned int is_rx, 127 unsigned int mac4, 128 unsigned int mac2 ) 120 129 { 121 130 unsigned int base = SEG_NIC_BASE; 122 131 unsigned int extend = (X_IO << Y_WIDTH) + Y_IO; 123 132 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 } 128 149 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 ); 136 152 137 _nic_set_channel_register( index, NIC_RX_RUN , 1 );138 _nic_set_channel_register( index, NIC_TX_RUN , 1 );139 140 153 return 0; 141 154 } 142 155 143 ///////////////////////////////////////////////////////////////////////////////////// 144 // Synchronous access functions 145 ///////////////////////////////////////////////////////////////////////////////////// 156 //////////////////////////////////////////// 157 int _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 ); 146 162 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; 195 164 } 196 165 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 address202 unsigned int done = 0;203 unsigned int lsb;204 unsigned int msb;205 166 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 buffers213 while ( done == 0 )214 {215 // test availability of NIC RX buffer 0216 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 1226 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 transfer240 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 functions249 /////////////////////////////////////////////////////////////////////////////////////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 address258 unsigned int nic_chbuf_msb; // 16 MSB bits of the NIC chbuf physical address259 unsigned int mem_chbuf_lsb; // 32 LSB bits of the kernel chbuf physical address260 unsigned int mem_chbuf_msb; // 16 MSB bits of the kernel chbuf physical address261 262 unsigned int ppn;263 unsigned int flags;264 265 // checking parameters266 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 address278 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 address282 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 start308 _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 address321 unsigned int nic_chbuf_msb; // 16 MSB bits of the NIC chbuf physical address322 unsigned int mem_chbuf_lsb; // 32 LSB bits of the kernel chbuf physical address323 unsigned int mem_chbuf_msb; // 16 MSB bits of the kernel chbuf physical address324 325 unsigned int ppn;326 unsigned int flags;327 328 // checking parameters329 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 address341 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 address345 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 start371 _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 }377 167 378 168 ////////////////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.