Changeset d3c9b60 in mainline
- Timestamp:
- 2011-01-06T14:42:39Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 506a805
- Parents:
- 95ff5c4
- Location:
- uspace/srv/hw/netif/dp8390
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390.c
r95ff5c4 rd3c9b60 332 332 { 333 333 int dp_rcr_reg; 334 int i; //, r;334 int i; 335 335 336 336 /* General initialization */ … … 343 343 printf("%x%c", dep->de_address.ea_addr[i], i < 5 ? ':' : '\n'); 344 344 } 345 346 /* Initialization of the dp8390 following the mandatory procedure 345 346 /* 347 * Initialization of the dp8390 following the mandatory procedure 347 348 * in reference manual ("DP8390D/NS32490D NIC Network Interface 348 349 * Controller", National Semiconductor, July 1995, Page 29). 349 350 */ 351 350 352 /* Step 1: */ 351 353 outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT); 354 352 355 /* Step 2: */ 353 356 if (dep->de_16bit) … … 355 358 else 356 359 outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS); 360 357 361 /* Step 3: */ 358 362 outb_reg0(dep, DP_RBCR0, 0); 359 363 outb_reg0(dep, DP_RBCR1, 0); 364 360 365 /* Step 4: */ 361 366 dp_rcr_reg = 0; 362 if (dep->de_flags &DEF_PROMISC) 367 368 if (dep->de_flags & DEF_PROMISC) 363 369 dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; 364 if (dep->de_flags &DEF_BROAD) 370 371 if (dep->de_flags & DEF_BROAD) 365 372 dp_rcr_reg |= RCR_AB; 366 if (dep->de_flags &DEF_MULTI) 373 374 if (dep->de_flags & DEF_MULTI) 367 375 dp_rcr_reg |= RCR_AM; 376 368 377 outb_reg0(dep, DP_RCR, dp_rcr_reg); 378 369 379 /* Step 5: */ 370 380 outb_reg0(dep, DP_TCR, TCR_INTERNAL); 381 371 382 /* Step 6: */ 372 383 outb_reg0(dep, DP_BNRY, dep->de_startpage); 373 384 outb_reg0(dep, DP_PSTART, dep->de_startpage); 374 385 outb_reg0(dep, DP_PSTOP, dep->de_stoppage); 386 375 387 /* Step 7: */ 376 388 outb_reg0(dep, DP_ISR, 0xFF); 389 377 390 /* Step 8: */ 378 391 outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | 379 IMR_OVWE | IMR_CNTE); 392 IMR_OVWE | IMR_CNTE); 393 380 394 /* Step 9: */ 381 395 outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP); 382 396 383 397 outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]); 384 398 outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]); … … 387 401 outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]); 388 402 outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]); 389 403 390 404 outb_reg1(dep, DP_MAR0, 0xff); 391 405 outb_reg1(dep, DP_MAR1, 0xff); … … 396 410 outb_reg1(dep, DP_MAR6, 0xff); 397 411 outb_reg1(dep, DP_MAR7, 0xff); 398 412 399 413 outb_reg1(dep, DP_CURR, dep->de_startpage + 1); 414 400 415 /* Step 10: */ 401 416 outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA); 417 402 418 /* Step 11: */ 403 419 outb_reg0(dep, DP_TCR, TCR_NORMAL); 404 405 inb_reg0(dep, DP_CNTR0); /* reset counters by reading */420 421 inb_reg0(dep, DP_CNTR0); /* Reset counters by reading */ 406 422 inb_reg0(dep, DP_CNTR1); 407 423 inb_reg0(dep, DP_CNTR2); 408 424 409 425 /* Finish the initialization. */ 410 426 dep->de_flags |= DEF_ENABLED; 411 for (i = 0; i<dep->de_sendq_nr; i++)427 for (i = 0; i < dep->de_sendq_nr; i++) 412 428 dep->de_sendq[i].sq_filled= 0; 413 dep->de_sendq_head= 0; 414 dep->de_sendq_tail= 0; 415 if (dep->de_16bit) 416 { 429 430 dep->de_sendq_head = 0; 431 dep->de_sendq_tail = 0; 432 433 if (dep->de_16bit) { 417 434 dep->de_user2nicf= dp_pio16_user2nic; 418 // dep->de_user2nicf_s= dp_pio16_user2nic_s;419 435 dep->de_nic2userf= dp_pio16_nic2user; 420 // dep->de_nic2userf_s= dp_pio16_nic2user_s;421 436 dep->de_getblockf= dp_pio16_getblock; 422 } 423 else 424 { 437 } else { 425 438 dep->de_user2nicf= dp_pio8_user2nic; 426 // dep->de_user2nicf_s= dp_pio8_user2nic_s;427 439 dep->de_nic2userf= dp_pio8_nic2user; 428 // dep->de_nic2userf_s= dp_pio8_nic2user_s;429 440 dep->de_getblockf= dp_pio8_getblock; 430 441 } 431 432 /* Set the interrupt handler and policy. Do not automatically 433 * reenable interrupts. Return the IRQ line number on interrupts. 434 */ 435 /* dep->de_hook = dep->de_irq; 436 r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook); 437 if (r != OK) 438 panic("DP8390", "sys_irqsetpolicy failed", r); 439 440 r= sys_irqenable(&dep->de_hook); 441 if (r != OK) 442 { 443 panic("DP8390", "unable enable interrupts", r); 444 } 445 */ 446 } 447 448 /*===========================================================================* 449 * dp_reinit * 450 *===========================================================================*/ 442 } 443 451 444 static void dp_reinit(dep) 452 445 dpeth_t *dep; -
uspace/srv/hw/netif/dp8390/dp8390.h
r95ff5c4 rd3c9b60 222 222 struct dpeth; 223 223 struct iovec_dat; 224 //struct iovec_dat_s; 224 225 225 _PROTOTYPE(typedef void (*dp_initf_t), (struct dpeth *dep) ); 226 226 _PROTOTYPE(typedef void (*dp_stopf_t), (struct dpeth *dep) ); … … 228 228 struct iovec_dat *iovp, vir_bytes offset, 229 229 int nic_addr, vir_bytes count) ); 230 //_PROTOTYPE(typedef void (*dp_user2nicf_s_t), (struct dpeth *dep,231 // struct iovec_dat_s *iovp, vir_bytes offset,232 // int nic_addr, vir_bytes count) );233 230 _PROTOTYPE(typedef void (*dp_nic2userf_t), (struct dpeth *dep, 234 231 int nic_addr, struct iovec_dat *iovp, 235 232 vir_bytes offset, vir_bytes count) ); 236 //_PROTOTYPE(typedef void (*dp_nic2userf_s_t), (struct dpeth *dep,237 // int nic_addr, struct iovec_dat_s *iovp,238 // vir_bytes offset, vir_bytes count) );239 //#if 0240 //_PROTOTYPE(typedef void (*dp_getheaderf_t), (struct dpeth *dep,241 // int page, struct dp_rcvhdr *h, u16_t *eth_type) );242 //#endif243 233 _PROTOTYPE(typedef void (*dp_getblock_t), (struct dpeth *dep, 244 234 int page, size_t offset, size_t size, void *dst) ); 245 235 246 /* iovectors are handled IOVEC_NR entries at a time. */ 247 //#define IOVEC_NR 16 248 // no vectors allowed 249 #define IOVEC_NR 1 250 251 /* 252 typedef int irq_hook_t; 253 */ 236 #define IOVEC_NR 1 237 254 238 typedef struct iovec_dat 255 239 { … … 275 259 /** Maximum number of waiting packets to be sent or received. 276 260 */ 277 #define MAX_PACKETS 261 #define MAX_PACKETS 4 278 262 279 263 typedef struct dpeth … … 282 266 */ 283 267 packet_t *packet_queue; 268 284 269 /** Outgoing packets count. 285 270 */ 286 271 int packet_count; 287 272 288 273 /** Received packets queue. 289 274 */ 290 275 packet_t *received_queue; 276 291 277 /** Received packets count. 292 278 */ … … 304 290 int de_irq; 305 291 int de_int_pending; 306 // irq_hook_t de_hook;307 292 dp_initf_t de_initf; 308 293 dp_stopf_t de_stopf; 309 294 char de_name[sizeof("dp8390#n")]; 310 295 311 296 /* The initf function fills the following fields. Only cards that do 312 297 * programmed I/O fill in the de_pata_port field. … … 322 307 int de_startpage; 323 308 int de_stoppage; 324 325 /* should be here - read even for ne2k isa init... */ 326 char de_pci; /* TRUE iff PCI device */ 327 309 328 310 /* Do it yourself send queue */ 329 struct sendq 330 { 311 struct sendq { 331 312 int sq_filled; /* this buffer contains a packet */ 332 313 int sq_size; /* with this size */ 333 314 int sq_sendpage; /* starting page of the buffer */ 334 315 } de_sendq[SENDQ_NR]; 316 335 317 int de_sendq_nr; 336 318 int de_sendq_head; /* Enqueue at the head */ 337 319 int de_sendq_tail; /* Dequeue at the tail */ 338 320 339 321 /* Fields for internal use by the dp8390 driver. */ 340 322 int de_flags; … … 342 324 eth_stat_t de_stat; 343 325 iovec_dat_t de_read_iovec; 344 // iovec_dat_s_t de_read_iovec_s;345 // int de_safecopy_read;346 326 iovec_dat_t de_write_iovec; 347 // iovec_dat_s_t de_write_iovec_s;348 327 iovec_dat_t de_tmp_iovec; 349 // iovec_dat_s_t de_tmp_iovec_s;350 328 vir_bytes de_read_s; 351 329 // int de_client; 352 330 // message de_sendmsg; 353 331 dp_user2nicf_t de_user2nicf; 354 // dp_user2nicf_s_t de_user2nicf_s;355 332 dp_nic2userf_t de_nic2userf; 356 // dp_nic2userf_s_t de_nic2userf_s;357 333 dp_getblock_t de_getblockf; 358 334 } dpeth_t; -
uspace/srv/hw/netif/dp8390/ne2000.c
r95ff5c4 rd3c9b60 73 73 void ne_init(struct dpeth *dep); 74 74 75 /*===========================================================================* 76 * ne_probe * 77 *===========================================================================*/ 78 int ne_probe(dep) 79 dpeth_t *dep; 75 int ne_probe(dpeth_t *dep) 80 76 { 81 77 int byte; … … 83 79 int loc1, loc2; 84 80 testf_t f; 85 86 dep->de_dp8390_port= dep->de_base_port + NE_DP8390; 87 88 /* We probe for an ne1000 or an ne2000 by testing whether the 81 82 dep->de_dp8390_port = dep->de_base_port + NE_DP8390; 83 84 /* 85 * We probe for an ne1000 or an ne2000 by testing whether the 89 86 * on board is reachable through the dp8390. Note that the 90 87 * ne1000 is an 8bit card and has a memory region distict from 91 88 * the 16bit ne2000 92 89 */ 93 94 for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++) 95 { 90 91 for (dep->de_16bit = 0; dep->de_16bit < 2; dep->de_16bit++) { 96 92 /* Reset the ethernet card */ 97 93 byte= inb_ne(dep, NE_RESET); … … 99 95 outb_ne(dep, NE_RESET, byte); 100 96 milli_delay(2); 101 97 102 98 /* Reset the dp8390 */ 103 99 outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT); 104 for (i = 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++)100 for (i = 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++) 105 101 ; /* Do nothing */ 106 102 107 103 /* Check if the dp8390 is really there */ 108 if ((inb_reg0(dep, DP_CR) &(CR_STP|CR_DM_ABORT)) != 109 (CR_STP|CR_DM_ABORT)) 110 { 104 if ((inb_reg0(dep, DP_CR) & (CR_STP | CR_DM_ABORT)) != 105 (CR_STP | CR_DM_ABORT)) 111 106 return 0; 112 } 113 107 114 108 /* Disable the receiver and init TCR and DCR. */ 115 109 outb_reg0(dep, DP_RCR, RCR_MON); 116 110 outb_reg0(dep, DP_TCR, TCR_NORMAL); 117 if (dep->de_16bit) 118 { 111 if (dep->de_16bit) { 119 112 outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | 120 DCR_BMS); 121 } 122 else 123 { 113 DCR_BMS); 114 } else { 124 115 outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | 125 DCR_BMS); 126 } 127 128 if (dep->de_16bit) 129 { 116 DCR_BMS); 117 } 118 119 if (dep->de_16bit) { 130 120 loc1= NE2000_START; 131 121 loc2= NE2000_START + NE2000_SIZE - 4; 132 122 f= test_16; 133 } 134 else 135 { 123 } else { 136 124 loc1= NE1000_START; 137 125 loc2= NE1000_START + NE1000_SIZE - 4; 138 126 f= test_8; 139 127 } 140 if (f(dep, loc1, pat0) && f(dep, loc1, pat1) &&141 f(dep, loc1, pat2) && f(dep, loc1, pat3) &&142 f(dep, loc2, pat0) && f(dep, loc2, pat1) &&143 f(dep, loc2, pat2) && f(dep, loc2, pat3))144 {128 129 if (f(dep, loc1, pat0) && f(dep, loc1, pat1) && 130 f(dep, loc1, pat2) && f(dep, loc1, pat3) && 131 f(dep, loc2, pat0) && f(dep, loc2, pat1) && 132 f(dep, loc2, pat2) && f(dep, loc2, pat3)) { 145 133 /* We don't need a memory segment */ 146 dep->de_linmem= 0; 147 if (!dep->de_pci) 148 dep->de_initf= ne_init; 149 dep->de_stopf= ne_stop; 134 dep->de_linmem = 0; 135 dep->de_initf = ne_init; 136 dep->de_stopf = ne_stop; 150 137 return 1; 151 138 } 152 139 } 140 153 141 return 0; 154 142 } 155 143 156 /*===========================================================================* 157 * ne_init * 158 *===========================================================================*/ 159 void ne_init(dep) 160 dpeth_t *dep; 144 void ne_init(dpeth_t *dep) 161 145 { 162 146 int i; 163 147 int word, sendq_nr; 164 148 165 149 /* Setup a transfer to get the ethernet address. */ 166 150 if (dep->de_16bit) … … 168 152 else 169 153 outb_reg0(dep, DP_RBCR0, 6); 154 170 155 outb_reg0(dep, DP_RBCR1, 0); 171 156 outb_reg0(dep, DP_RSAR0, 0); 172 157 outb_reg0(dep, DP_RSAR1, 0); 173 158 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 174 175 for (i= 0; i<6; i++) 176 { 177 if (dep->de_16bit) 178 { 179 word= inw_ne(dep, NE_DATA); 180 dep->de_address.ea_addr[i]= word; 181 } 182 else 183 { 159 160 for (i = 0; i < 6; i++) { 161 if (dep->de_16bit) { 162 word = inw_ne(dep, NE_DATA); 163 dep->de_address.ea_addr[i] = word; 164 } else 184 165 dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA); 185 186 }166 } 167 187 168 dep->de_data_port= dep->de_base_port + NE_DATA; 188 if (dep->de_16bit) 189 { 169 if (dep->de_16bit) { 190 170 dep->de_ramsize= NE2000_SIZE; 191 171 dep->de_offset_page= NE2000_START / DP_PAGESIZE; 192 } 193 else 194 { 172 } else { 195 173 dep->de_ramsize= NE1000_SIZE; 196 174 dep->de_offset_page= NE1000_START / DP_PAGESIZE; 197 175 } 198 176 199 177 /* Allocate one send buffer (1.5KB) per 8KB of on board memory. */ 200 178 sendq_nr= dep->de_ramsize / 0x2000; 179 201 180 if (sendq_nr < 1) 202 sendq_nr = 1;181 sendq_nr = 1; 203 182 else if (sendq_nr > SENDQ_NR) 204 sendq_nr= SENDQ_NR; 205 dep->de_sendq_nr= sendq_nr; 206 for (i= 0; i<sendq_nr; i++) 207 { 208 dep->de_sendq[i].sq_sendpage= dep->de_offset_page + 209 i*SENDQ_PAGES; 210 } 211 212 dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES; 213 dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE; 214 183 sendq_nr = SENDQ_NR; 184 185 dep->de_sendq_nr = sendq_nr; 186 for (i = 0; i < sendq_nr; i++) 187 dep->de_sendq[i].sq_sendpage= dep->de_offset_page + i * SENDQ_PAGES; 188 189 dep->de_startpage = dep->de_offset_page + i * SENDQ_PAGES; 190 dep->de_stoppage = dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE; 191 215 192 /* Can't override the default IRQ. */ 216 193 dep->de_irq &= ~DEI_DEFAULT; 217 194 218 195 if (!debug) 219 196 {
Note:
See TracChangeset
for help on using the changeset viewer.