Changeset 01b6ca9 in rtems
- Timestamp:
- Jun 13, 2003, 5:43:11 PM (18 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 7fa1f667
- Parents:
- 97a0f76a
- Location:
- c/src/libchip
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/libchip/ChangeLog
r97a0f76a r01b6ca9 1 2003-06-13 Greg Menke <gregory.menke@gsfc.nasa.gov> 2 3 PR 405/bsps 4 PR 393/networking 5 * network/dec21140.c: Fix leak also known as PR393. 6 * network/elnk.c, network/if_media.h, network/mii.h: New files. 7 * network/Makefile.am: Reflect new files. 8 1 9 2003-06-13 Greg Menke <gregory.menke@gsfc.nasa.gov> 2 10 -
c/src/libchip/network/Makefile.am
r97a0f76a r01b6ca9 9 9 LIB = $(ARCH)/$(LIBNAME).a 10 10 11 C_FILES = cs8900.c dec21140.c i82586.c sonic.c if_fxp.c 11 C_FILES = cs8900.c dec21140.c i82586.c sonic.c if_fxp.c elnk.c 12 12 OBJS = $(C_FILES:%.c=$(ARCH)/%.$(OBJEXT)) 13 13 14 include_libchip_HEADERS = cs8900.h i82586var.h if_fxpvar.h sonic.h 14 include_libchip_HEADERS = cs8900.h i82586var.h if_fxpvar.h sonic.h if_media.h mii.h 15 15 16 16 include $(top_srcdir)/../../../automake/compile.am -
c/src/libchip/network/dec21140.c
r97a0f76a r01b6ca9 26 26 * look for the 21143. 27 27 * ------------------------------------------------------------------------ 28 * 29 * 2003-03-13, Greg Menke, gregory.menke@gsfc.nasa.gov 30 * 31 * Added support for up to 8 units (which is an arbitrary limit now), 32 * consolidating their support into a single pair of rx/tx daemons and a 33 * single ISR for all vectors servicing the DEC units. The driver now 34 * simply uses whatever INTERRUPT_LINE the card supplies, requiring it 35 * be configured either by the boot monitor or bspstart() hackery. 36 * Tested on a MCP750 PPC based system with 2 DEC21140 boards. 37 * 38 * Also fixed a few bugs related to board configuration, start and stop. 39 * 28 40 */ 29 41 … … 40 52 #endif 41 53 42 #if defined(__PPC__) && (defined(mpc604) || defined(mpc750) )54 #if defined(__PPC__) && (defined(mpc604) || defined(mpc750) || defined(mpc603e)) 43 55 #define DEC21140_SUPPORTED 44 56 #endif … … 58 70 #include <stdio.h> 59 71 #include <stdarg.h> 72 #include <string.h> 60 73 #include <rtems/error.h> 61 74 #include <rtems/bspIo.h> … … 89 102 /* note: the 21143 isn't really a DEC, it's an Intel chip */ 90 103 #define PCI_INVALID_VENDORDEVICEID 0xffffffff 91 #define PCI_VENDOR_ID_DEC 0x1011 92 #define PCI_DEVICE_ID_DEC_21140 0x0009 93 #define PCI_DEVICE_ID_DEC_21143 0x0019 104 #define PCI_VENDOR_ID_DEC 0x1011 105 #define PCI_DEVICE_ID_DEC_21140 0x0009 106 #define PCI_DEVICE_ID_DEC_21143 0x0019 107 108 #define DRIVER_PREFIX "dc" 94 109 95 110 #define IO_MASK 0x3 … … 134 149 #define DEC_REGISTER_SIZE 0x100 /* to reserve virtual memory */ 135 150 151 152 153 136 154 #define RESET_CHIP 0x00000001 137 155 #if defined(__PPC) … … 148 166 #define NO_IT 0x00000000 149 167 150 #define NRXBUFS 32 /* number of receive buffers */ 151 #define NTXBUFS 16 /* number of transmit buffers */ 168 152 169 153 170 /* message descriptor entry */ … … 156 173 volatile unsigned32 status; 157 174 volatile unsigned32 counts; 158 unsigned32 buf1, buf2;175 volatile unsigned32 buf1, buf2; 159 176 /* used by software */ 160 177 volatile struct mbuf *m; 161 178 volatile struct MD *next; 162 }; 163 164 /* 165 * Number of DECs supported by this driver 166 */ 167 #define NDECDRIVER 1 179 } __attribute__ ((packed)); 180 181 182 183 184 /* 185 ** These buffers allocated for each unit, so ensure 186 ** 187 ** rtems_bsdnet_config.mbuf_bytecount 188 ** rtems_bsdnet_config.mbuf_cluster_bytecount 189 ** 190 ** are adequately sized to provide enough clusters and mbufs for all the 191 ** units. The default bsdnet configuration is sufficient for one dec 192 ** unit, but will be nearing exhaustion with 2 or more. Although a 193 ** little expensive in memory, the following configuration should 194 ** eliminate all mbuf/cluster issues; 195 ** 196 ** rtems_bsdnet_config.mbuf_bytecount = 128*1024; 197 ** rtems_bsdnet_config.mbuf_cluster_bytecount = 256*1024; 198 */ 199 200 #define NRXBUFS 16 /* number of receive buffers */ 201 #define NTXBUFS 16 /* number of transmit buffers */ 202 203 204 /* 205 * Number of DEC boards supported by this driver 206 */ 207 #define NDECDRIVER 8 208 168 209 169 210 /* … … 172 213 #define RBUF_SIZE 1536 173 214 174 #define ET_MINLEN 60 /* minimum message length */ 175 176 /* 177 * RTEMS event used by interrupt handler to signal driver tasks. 178 * This must not be any of the events used by the network task synchronization. 179 */ 180 #define INTERRUPT_EVENT RTEMS_EVENT_1 181 182 /* 183 * RTEMS event used to start transmit daemon. 184 * This must not be the same as INTERRUPT_EVENT. 185 */ 186 #define START_TRANSMIT_EVENT RTEMS_EVENT_2 215 #define ET_MINLEN 60 /* minimum message length */ 216 217 218 /* 219 ** Events, one per unit. The event is sent to the rx task from the isr 220 ** or from the stack to the tx task whenever a unit needs service. The 221 ** rx/tx tasks identify the requesting unit(s) by their particular 222 ** events so only requesting units are serviced. 223 */ 224 225 static rtems_event_set unit_signals[NDECDRIVER]= { RTEMS_EVENT_1, 226 RTEMS_EVENT_2, 227 RTEMS_EVENT_3, 228 RTEMS_EVENT_4, 229 RTEMS_EVENT_5, 230 RTEMS_EVENT_6, 231 RTEMS_EVENT_7, 232 RTEMS_EVENT_8 }; 233 187 234 188 235 #if defined(__PPC) … … 213 260 #endif 214 261 262 263 264 265 215 266 /* 216 267 * Per-device data 217 268 */ 218 struct dec21140_softc { 219 220 struct arpcom arpcom; 221 222 rtems_irq_connect_data irqInfo; 223 224 volatile struct MD *MDbase; 225 volatile unsigned char *bufferBase; 226 int acceptBroadcast; 227 rtems_id rxDaemonTid; 228 rtems_id txDaemonTid; 269 struct dec21140_softc { 270 271 struct arpcom arpcom; 272 273 rtems_irq_connect_data irqInfo; 274 275 rtems_event_set ioevent; 276 277 volatile struct MD *MDbase; 278 volatile struct MD *nextRxMD; 279 volatile unsigned char *bufferBase; 280 int acceptBroadcast; 229 281 230 volatile struct MD *TxMD;231 volatile struct MD *SentTxMD;232 int PendingTxCount;233 int TxSuspended;234 235 unsigned int port;236 volatile unsigned int *base;237 238 /*239 * Statistics240 */241 unsigned long rxInterrupts;242 unsigned long rxNotFirst;243 unsigned long rxNotLast;244 unsigned long rxGiant;245 unsigned long rxNonOctet;246 unsigned long rxRunt;247 unsigned long rxBadCRC;248 unsigned long rxOverrun;249 unsigned long rxCollision;282 volatile struct MD *TxMD; 283 volatile struct MD *SentTxMD; 284 int PendingTxCount; 285 int TxSuspended; 286 287 unsigned int port; 288 volatile unsigned int *base; 289 290 /* 291 * Statistics 292 */ 293 unsigned long rxInterrupts; 294 unsigned long rxNotFirst; 295 unsigned long rxNotLast; 296 unsigned long rxGiant; 297 unsigned long rxNonOctet; 298 unsigned long rxRunt; 299 unsigned long rxBadCRC; 300 unsigned long rxOverrun; 301 unsigned long rxCollision; 250 302 251 unsigned long txInterrupts;252 unsigned long txDeferred;253 unsigned long txHeartbeat;254 unsigned long txLateCollision;255 unsigned long txRetryLimit;256 unsigned long txUnderrun;257 unsigned long txLostCarrier;258 unsigned long txRawWait;303 unsigned long txInterrupts; 304 unsigned long txDeferred; 305 unsigned long txHeartbeat; 306 unsigned long txLateCollision; 307 unsigned long txRetryLimit; 308 unsigned long txUnderrun; 309 unsigned long txLostCarrier; 310 unsigned long txRawWait; 259 311 }; 260 312 261 313 static struct dec21140_softc dec21140_softc[NDECDRIVER]; 262 263 /* 264 * DEC21140 interrupt handler 265 */ 266 static rtems_isr 267 dec21140Enet_interrupt_handler (rtems_vector_number v) 268 { 269 volatile unsigned32 *tbase; 270 unsigned32 status; 271 struct dec21140_softc *sc; 272 273 sc = &dec21140_softc[0]; 274 tbase = (unsigned32 *)(sc->base) ; 275 276 /* 277 * Read status 278 */ 279 status = ld_le32(tbase+memCSR5); 280 st_le32((tbase+memCSR5), status); /* clear the bits we've read */ 281 282 /* 283 * Frame received? 284 */ 285 if (status & 0x000000c0){ 286 sc->rxInterrupts++; 287 rtems_event_send (sc->rxDaemonTid, INTERRUPT_EVENT); 288 } 289 } 290 291 static void nopOn(const rtems_irq_connect_data* notUsed) 292 { 293 /* 294 * code should be moved from dec21140Enet_initialize_hardware 295 * to this location 296 */ 297 } 298 299 static int dec21140IsOn(const rtems_irq_connect_data* irq) 300 { 301 return BSP_irq_enabled_at_i8259s (irq->name); 302 } 314 static rtems_id rxDaemonTid; 315 static rtems_id txDaemonTid; 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 303 331 304 332 … … 322 350 static int eeget16(volatile unsigned int *ioaddr, int location) 323 351 { 324 325 326 352 int i; 353 unsigned short retval = 0; 354 int read_cmd = location | EE_READ_CMD; 327 355 328 329 356 st_le32(ioaddr, EE_ENB & ~EE_CS); 357 st_le32(ioaddr, EE_ENB); 330 358 331 332 333 334 335 336 337 338 339 340 341 359 /* Shift the read command bits out. */ 360 for (i = 10; i >= 0; i--) { 361 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; 362 st_le32(ioaddr, EE_ENB | dataval); 363 rtems_bsp_delay_in_bus_cycles(200); 364 st_le32(ioaddr, EE_ENB | dataval | EE_SHIFT_CLK); 365 rtems_bsp_delay_in_bus_cycles(200); 366 st_le32(ioaddr, EE_ENB | dataval); /* Finish EEPROM a clock tick. */ 367 rtems_bsp_delay_in_bus_cycles(200); 368 } 369 st_le32(ioaddr, EE_ENB); 342 370 343 for (i = 16; i > 0; i--) { 344 st_le32(ioaddr, EE_ENB | EE_SHIFT_CLK); 345 rtems_bsp_delay_in_bus_cycles(200); 346 retval = (retval << 1) | ((ld_le32(ioaddr) & EE_DATA_READ) ? 1 : 0); 347 st_le32(ioaddr, EE_ENB); 348 rtems_bsp_delay_in_bus_cycles(200); 349 } 350 351 /* Terminate the EEPROM access. */ 352 st_le32(ioaddr, EE_ENB & ~EE_CS); 353 return ( ((retval<<8)&0xff00) | ((retval>>8)&0xff) ); 354 } 371 for (i = 16; i > 0; i--) { 372 st_le32(ioaddr, EE_ENB | EE_SHIFT_CLK); 373 rtems_bsp_delay_in_bus_cycles(200); 374 retval = (retval << 1) | ((ld_le32(ioaddr) & EE_DATA_READ) ? 1 : 0); 375 st_le32(ioaddr, EE_ENB); 376 rtems_bsp_delay_in_bus_cycles(200); 377 } 378 379 /* Terminate the EEPROM access. */ 380 st_le32(ioaddr, EE_ENB & ~EE_CS); 381 return ( ((retval<<8)&0xff00) | ((retval>>8)&0xff) ); 382 } 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 static void no_op(const rtems_irq_connect_data* irq) 406 { 407 return; 408 } 409 410 411 412 413 static int dec21140IsOn(const rtems_irq_connect_data* irq) 414 { 415 return BSP_irq_enabled_at_i8259s (irq->name); 416 } 417 418 419 420 421 /* 422 * DEC21140 interrupt handler 423 */ 424 static rtems_isr 425 dec21140Enet_interrupt_handler ( struct dec21140_softc *sc ) 426 { 427 volatile unsigned32 *tbase; 428 unsigned32 status; 429 430 tbase = (unsigned32 *)(sc->base); 431 432 /* 433 * Read status 434 */ 435 status = ld_le32(tbase+memCSR5); 436 st_le32((tbase+memCSR5), status); 437 438 /* 439 * Frame received? 440 */ 441 if( status & 0x000000c0 ) 442 { 443 sc->rxInterrupts++; 444 rtems_event_send(rxDaemonTid, sc->ioevent); 445 } 446 } 447 448 449 450 static rtems_isr 451 dec21140Enet_interrupt_handler_entry() 452 { 453 int i; 454 455 /* 456 ** Check all the initialized dec units for interrupt service 457 */ 458 459 for(i=0; i< NDECDRIVER; i++ ) 460 { 461 if( dec21140_softc[i].base ) 462 dec21140Enet_interrupt_handler( &dec21140_softc[i] ); 463 } 464 } 465 466 467 468 469 470 471 472 473 355 474 356 475 /* … … 360 479 dec21140Enet_initialize_hardware (struct dec21140_softc *sc) 361 480 { 362 rtems_status_code st; 363 volatile unsigned int *tbase; 364 int i; 365 volatile unsigned char *cp, *setup_frm, *eaddrs; 366 volatile unsigned char *buffer; 367 volatile struct MD *rmd; 368 369 tbase = sc->base; 370 371 /* 372 * WARNING : First write in CSR6 373 * Then Reset the chip ( 1 in CSR0) 374 */ 375 st_le32( (tbase+memCSR6), CSR6_INIT); 376 st_le32( (tbase+memCSR0), RESET_CHIP); 377 rtems_bsp_delay_in_bus_cycles(200); 378 379 /* 380 * Init CSR0 381 */ 382 st_le32( (tbase+memCSR0), CSR0_MODE); 481 int i,st; 482 volatile unsigned int *tbase; 483 volatile unsigned char *cp, *setup_frm, *eaddrs; 484 volatile unsigned char *buffer; 485 volatile struct MD *rmd; 486 383 487 384 488 #ifdef DEC_DEBUG 385 printk("DC2114x %x:%x:%x:%x:%x:%x IRQ %d IO %x M %x .........\n", 386 sc->arpcom.ac_enaddr[0], sc->arpcom.ac_enaddr[1], 387 sc->arpcom.ac_enaddr[2], sc->arpcom.ac_enaddr[3], 388 sc->arpcom.ac_enaddr[4], sc->arpcom.ac_enaddr[5], 389 sc->irqInfo.name, sc->port, (unsigned) sc->base); 390 #endif 391 392 /* 393 * Init RX ring 394 */ 395 cp = (volatile unsigned char *)malloc(((NRXBUFS+NTXBUFS)*sizeof(struct MD)) 396 + (NTXBUFS*RBUF_SIZE) 397 + CPU_CACHE_ALIGNMENT_FOR_BUFFER); 398 sc->bufferBase = cp; 399 cp += (CPU_CACHE_ALIGNMENT_FOR_BUFFER - (int)cp) 400 & (CPU_CACHE_ALIGNMENT_FOR_BUFFER - 1); 489 printk("dec2114x : %02x:%02x:%02x:%02x:%02x:%02x name '%s%d', io %x, mem %x, int %d\n", 490 sc->arpcom.ac_enaddr[0], sc->arpcom.ac_enaddr[1], 491 sc->arpcom.ac_enaddr[2], sc->arpcom.ac_enaddr[3], 492 sc->arpcom.ac_enaddr[4], sc->arpcom.ac_enaddr[5], 493 sc->arpcom.ac_if.if_name, sc->arpcom.ac_if.if_unit, 494 sc->port, (unsigned) sc->base, sc->irqInfo.name ); 495 #endif 496 497 498 499 tbase = sc->base; 500 501 /* 502 * WARNING : First write in CSR6 503 * Then Reset the chip ( 1 in CSR0) 504 */ 505 st_le32( (tbase+memCSR6), CSR6_INIT); 506 st_le32( (tbase+memCSR0), RESET_CHIP); 507 rtems_bsp_delay_in_bus_cycles(200); 508 509 st_le32( (tbase+memCSR7), NO_IT); 510 511 /* 512 * Init CSR0 513 */ 514 st_le32( (tbase+memCSR0), CSR0_MODE); 515 516 /* 517 * Init RX ring 518 */ 519 cp = (volatile unsigned char *)malloc(((NRXBUFS+NTXBUFS)*sizeof(struct MD)) 520 + (NTXBUFS*RBUF_SIZE) 521 + CPU_CACHE_ALIGNMENT_FOR_BUFFER); 522 sc->bufferBase = cp; 523 cp += (CPU_CACHE_ALIGNMENT_FOR_BUFFER - (int)cp) & (CPU_CACHE_ALIGNMENT_FOR_BUFFER - 1); 401 524 #if defined(__i386__) 402 525 #ifdef PCI_BRIDGE_DOES_NOT_ENSURE_CACHE_COHERENCY_FOR_DMA 403 if (_CPU_is_paging_enabled()) 404 _CPU_change_memory_mapping_attribute 405 (NULL, cp, 406 ((NRXBUFS+NTXBUFS)*sizeof(struct MD)) 407 + (NTXBUFS*RBUF_SIZE), 408 PTE_CACHE_DISABLE | PTE_WRITABLE); 409 #endif 410 #endif 411 rmd = (volatile struct MD*)cp; 412 sc->MDbase = rmd; 413 buffer = cp + ((NRXBUFS+NTXBUFS)*sizeof(struct MD)); 414 st_le32( (tbase+memCSR3), (long)(phys_to_bus((long)(sc->MDbase)))); 415 for (i=0 ; i<NRXBUFS; i++){ 416 struct mbuf *m; 526 if (_CPU_is_paging_enabled()) 527 _CPU_change_memory_mapping_attribute 528 (NULL, cp, 529 ((NRXBUFS+NTXBUFS)*sizeof(struct MD)) 530 + (NTXBUFS*RBUF_SIZE), 531 PTE_CACHE_DISABLE | PTE_WRITABLE); 532 #endif 533 #endif 534 rmd = (volatile struct MD*)cp; 535 sc->MDbase = rmd; 536 sc->nextRxMD = sc->MDbase; 537 538 buffer = cp + ((NRXBUFS+NTXBUFS)*sizeof(struct MD)); 539 st_le32( (tbase+memCSR3), (long)(phys_to_bus((long)(sc->MDbase)))); 540 541 for (i=0 ; i<NRXBUFS; i++) 542 { 543 struct mbuf *m; 417 544 418 /* allocate an mbuf for each receive descriptor */ 419 MGETHDR (m, M_WAIT, MT_DATA); 420 MCLGET (m, M_WAIT); 421 m->m_pkthdr.rcvif = &sc->arpcom.ac_if; 422 rmd->m = m; 423 424 rmd->buf2 = phys_to_bus(rmd+1); 425 rmd->buf1 = phys_to_bus(mtod(m, void *)); 426 rmd->counts = 0xfdc00000 | (RBUF_SIZE); 427 rmd->status = 0x80000000; 428 rmd->next = rmd + 1; 429 rmd++; 430 } 431 /* 432 * mark last RX buffer. 433 */ 434 sc->MDbase [NRXBUFS-1].counts = 0xfec00000 | (RBUF_SIZE); 435 sc->MDbase [NRXBUFS-1].next = sc->MDbase; 436 437 /* 438 * Init TX ring 439 */ 440 st_le32( (tbase+memCSR4), (long)(phys_to_bus((long)(rmd))) ); 441 for (i=0 ; i<NTXBUFS; i++){ 442 (rmd+i)->buf2 = phys_to_bus(rmd+i+1); 443 (rmd+i)->buf1 = phys_to_bus(buffer + (i*RBUF_SIZE)); 444 (rmd+i)->counts = 0x01000000; 445 (rmd+i)->status = 0x0; 446 (rmd+i)->next = rmd+i+1; 447 (rmd+i)->m = 0; 448 } 449 450 /* 451 * mark last TX buffer. 452 */ 453 (rmd+NTXBUFS-1)->buf2 = phys_to_bus(rmd); 454 (rmd+NTXBUFS-1)->next = rmd; 455 456 /* 457 * Set up interrupts 458 */ 459 sc->irqInfo.hdl = (rtems_irq_hdl)dec21140Enet_interrupt_handler; 460 sc->irqInfo.on = nopOn; 461 sc->irqInfo.off = nopOn; 462 sc->irqInfo.isOn = dec21140IsOn; 463 st = BSP_install_rtems_irq_handler (&sc->irqInfo); 464 if (!st) 465 rtems_panic ("Can't attach DEC21140 interrupt handler for irq %d\n", 466 sc->irqInfo.name); 467 468 st_le32( (tbase+memCSR7), NO_IT); 469 470 /* 471 * Build setup frame 472 */ 473 setup_frm = (volatile unsigned char *)(bus_to_phys(rmd->buf1)); 474 eaddrs = (char *)(sc->arpcom.ac_enaddr); 475 /* Fill the buffer with our physical address. */ 476 for (i = 1; i < 16; i++) { 477 *setup_frm++ = eaddrs[0]; 478 *setup_frm++ = eaddrs[1]; 479 *setup_frm++ = eaddrs[0]; 480 *setup_frm++ = eaddrs[1]; 481 *setup_frm++ = eaddrs[2]; 482 *setup_frm++ = eaddrs[3]; 483 *setup_frm++ = eaddrs[2]; 484 *setup_frm++ = eaddrs[3]; 485 *setup_frm++ = eaddrs[4]; 486 *setup_frm++ = eaddrs[5]; 487 *setup_frm++ = eaddrs[4]; 488 *setup_frm++ = eaddrs[5]; 489 } 490 /* Add the broadcast address when doing perfect filtering */ 491 memset((void*) setup_frm, 0xff, 12); 492 rmd->counts = 0x09000000 | 192 ; 493 rmd->status = 0x80000000; 494 st_le32( (tbase+memCSR6), CSR6_INIT | CSR6_TX); 495 st_le32( (tbase+memCSR1), 1); 496 while (rmd->status != 0x7fffffff); 497 rmd->counts = 0x01000000; 498 sc->TxMD = rmd+1; 499 500 /* 501 * Enable RX and TX 502 */ 503 st_le32( (tbase+memCSR5), IT_SETUP); 504 st_le32( (tbase+memCSR7), IT_SETUP); 505 st_le32( (unsigned int*)(tbase+memCSR6), CSR6_INIT | CSR6_TXRX); 506 } 545 /* allocate an mbuf for each receive descriptor */ 546 MGETHDR (m, M_WAIT, MT_DATA); 547 MCLGET (m, M_WAIT); 548 m->m_pkthdr.rcvif = &sc->arpcom.ac_if; 549 rmd->m = m; 550 551 rmd->buf2 = phys_to_bus(rmd+1); 552 rmd->buf1 = phys_to_bus(mtod(m, void *)); 553 rmd->status = 0x80000000; 554 rmd->counts = 0xfdc00000 | (RBUF_SIZE); 555 rmd->next = rmd+1; 556 rmd++; 557 } 558 /* 559 * mark last RX buffer. 560 */ 561 sc->MDbase [NRXBUFS-1].buf2 = 0; 562 sc->MDbase [NRXBUFS-1].counts = 0xfec00000 | (RBUF_SIZE); 563 sc->MDbase [NRXBUFS-1].next = sc->MDbase; 564 565 566 567 /* 568 * Init TX ring 569 */ 570 st_le32( (tbase+memCSR4), (long)(phys_to_bus((long)(rmd))) ); 571 for (i=0 ; i<NTXBUFS; i++){ 572 (rmd+i)->buf2 = phys_to_bus(rmd+i+1); 573 (rmd+i)->buf1 = phys_to_bus(buffer + (i*RBUF_SIZE)); 574 (rmd+i)->counts = 0x01000000; 575 (rmd+i)->status = 0x0; 576 (rmd+i)->next = rmd+i+1; 577 (rmd+i)->m = 0; 578 } 579 580 /* 581 * mark last TX buffer. 582 */ 583 (rmd+NTXBUFS-1)->buf2 = phys_to_bus(rmd); 584 (rmd+NTXBUFS-1)->next = rmd; 585 586 587 /* 588 * Build setup frame 589 */ 590 setup_frm = (volatile unsigned char *)(bus_to_phys(rmd->buf1)); 591 eaddrs = (char *)(sc->arpcom.ac_enaddr); 592 /* Fill the buffer with our physical address. */ 593 for (i = 1; i < 16; i++) { 594 *setup_frm++ = eaddrs[0]; 595 *setup_frm++ = eaddrs[1]; 596 *setup_frm++ = eaddrs[0]; 597 *setup_frm++ = eaddrs[1]; 598 *setup_frm++ = eaddrs[2]; 599 *setup_frm++ = eaddrs[3]; 600 *setup_frm++ = eaddrs[2]; 601 *setup_frm++ = eaddrs[3]; 602 *setup_frm++ = eaddrs[4]; 603 *setup_frm++ = eaddrs[5]; 604 *setup_frm++ = eaddrs[4]; 605 *setup_frm++ = eaddrs[5]; 606 } 607 608 /* Add the broadcast address when doing perfect filtering */ 609 memset((void*) setup_frm, 0xff, 12); 610 rmd->counts = 0x09000000 | 192 ; 611 rmd->status = 0x80000000; 612 st_le32( (tbase+memCSR6), CSR6_INIT | CSR6_TX); 613 st_le32( (tbase+memCSR1), 1); 614 615 while (rmd->status != 0x7fffffff); 616 rmd->counts = 0x01000000; 617 618 sc->TxMD = rmd+1; 619 620 621 622 623 624 sc->irqInfo.hdl = (rtems_irq_hdl)dec21140Enet_interrupt_handler_entry; 625 sc->irqInfo.on = no_op; 626 sc->irqInfo.off = no_op; 627 sc->irqInfo.isOn = dec21140IsOn; 628 629 #ifdef BSP_SHARED_HANDLER_SUPPORT 630 st = BSP_install_rtems_shared_irq_handler( &sc->irqInfo ); 631 #else 632 st = BSP_install_rtems_irq_handler( &sc->irqInfo ); 633 #endif 634 635 if (!st) 636 rtems_panic ("dec2114x : Interrupt name %d already in use\n", sc->irqInfo.name ); 637 } 638 639 640 641 642 643 507 644 508 645 static void 509 646 dec21140_rxDaemon (void *arg) 510 647 { 511 volatile unsigned int *tbase; 512 struct ether_header *eh; 513 struct dec21140_softc *dp = (struct dec21140_softc *)&dec21140_softc[0]; 514 struct ifnet *ifp = &dp->arpcom.ac_if; 515 struct mbuf *m; 516 volatile struct MD *rmd; 517 unsigned int len; 518 rtems_event_set events; 519 520 tbase = dec21140_softc[0].base ; 521 rmd = dec21140_softc[0].MDbase; 522 523 for (;;){ 524 525 rtems_bsdnet_event_receive (INTERRUPT_EVENT, 526 RTEMS_WAIT|RTEMS_EVENT_ANY, 527 RTEMS_NO_TIMEOUT, 528 &events); 529 530 while((rmd->status & 0x80000000) == 0){ 531 /* pass on the packet in the mbuf */ 532 len = (rmd->status >> 16) & 0x7ff; 533 m = (struct mbuf *)(rmd->m); 534 m->m_len = m->m_pkthdr.len = len - sizeof(struct ether_header); 535 eh = mtod (m, struct ether_header *); 536 m->m_data += sizeof(struct ether_header); 537 ether_input (ifp, eh, m); 538 539 /* get a new mbuf for the 21140 */ 540 MGETHDR (m, M_WAIT, MT_DATA); 541 MCLGET (m, M_WAIT); 542 m->m_pkthdr.rcvif = ifp; 543 rmd->m = m; 544 rmd->buf1 = phys_to_bus(mtod(m, void *)); 545 546 rmd->status = 0x80000000; 648 volatile unsigned int *tbase; 649 volatile struct MD *rmd; 650 struct dec21140_softc *sc; 651 volatile struct ifnet *ifp; 652 struct ether_header *eh; 653 struct mbuf *m; 654 unsigned int i,len; 655 rtems_event_set events; 656 657 for (;;) 658 { 659 660 rtems_bsdnet_event_receive( RTEMS_ALL_EVENTS, 661 RTEMS_WAIT|RTEMS_EVENT_ANY, 662 RTEMS_NO_TIMEOUT, 663 &events); 664 665 for(i=0; i< NDECDRIVER; i++ ) 666 { 667 sc = &dec21140_softc[i]; 668 if( sc->base ) 669 { 670 if( events & sc->ioevent ) 671 { 672 ifp = &sc->arpcom.ac_if; 673 tbase = sc->base; 674 rmd = sc->nextRxMD; 675 676 /* 677 ** Read off all the packets we've received on this unit 678 */ 679 while((rmd->status & 0x80000000) == 0) 680 { 681 /* printk("unit %i rx\n", ifp->if_unit ); */ 682 683 /* pass on the packet in the mbuf */ 684 len = (rmd->status >> 16) & 0x7ff; 685 m = (struct mbuf *)(rmd->m); 686 m->m_len = m->m_pkthdr.len = len - sizeof(struct ether_header); 687 eh = mtod (m, struct ether_header *); 688 m->m_data += sizeof(struct ether_header); 689 ether_input (ifp, eh, m); 690 691 /* get a new mbuf for the 21140 */ 692 MGETHDR (m, M_WAIT, MT_DATA); 693 MCLGET (m, M_WAIT); 694 m->m_pkthdr.rcvif = ifp; 695 rmd->m = m; 696 rmd->buf1 = phys_to_bus(mtod(m, void *)); 697 698 /* mark the descriptor as ready to receive */ 699 rmd->status = 0x80000000; 547 700 548 rmd=rmd->next; 549 } 550 } 551 } 701 rmd=rmd->next; 702 } 703 704 sc->nextRxMD = rmd; 705 } 706 } 707 } 708 709 } 710 } 711 712 713 714 715 716 552 717 553 718 static void 554 719 sendpacket (struct ifnet *ifp, struct mbuf *m) 555 720 { 556 struct dec21140_softc *dp = ifp->if_softc; 557 volatile struct MD *tmd; 558 volatile unsigned char *temp; 559 struct mbuf *n; 560 unsigned int len; 561 volatile unsigned int *tbase; 562 563 tbase = dp->base; 564 /* 565 * Waiting for Transmitter ready 566 */ 567 tmd = dec21140_softc[0].TxMD; 568 n = m; 569 570 while ((tmd->status & 0x80000000) != 0){ 571 tmd=tmd->next; 572 } 573 574 len = 0; 575 temp = (volatile unsigned char *)(bus_to_phys(tmd->buf1)); 721 struct dec21140_softc *dp = ifp->if_softc; 722 volatile struct MD *tmd; 723 volatile unsigned char *temp; 724 struct mbuf *n; 725 unsigned int len; 726 volatile unsigned int *tbase; 727 728 tbase = dp->base; 729 /* 730 * Waiting for Transmitter ready 731 */ 732 733 tmd = dp->TxMD; 734 n = m; 735 736 while ((tmd->status & 0x80000000) != 0) 737 { 738 tmd=tmd->next; 739 } 740 741 len = 0; 742 temp = (volatile unsigned char *)(bus_to_phys(tmd->buf1)); 576 743 577 for (;;){ 578 len += m->m_len; 579 memcpy((void*) temp, (char *)m->m_data, m->m_len); 580 temp += m->m_len ; 581 if ((m = m->m_next) == NULL) 582 break; 583 } 584 585 if (len < ET_MINLEN) len = ET_MINLEN; 586 tmd->counts = 0xe1000000 | (len & 0x7ff); 587 tmd->status = 0x80000000; 588 589 st_le32( (tbase+memCSR1), 0x1); 590 591 m_freem(n); 592 dec21140_softc[0].TxMD = tmd->next; 593 } 744 for (;;) 745 { 746 len += m->m_len; 747 memcpy((void*) temp, (char *)m->m_data, m->m_len); 748 temp += m->m_len ; 749 if ((m = m->m_next) == NULL) 750 break; 751 } 752 753 if (len < ET_MINLEN) len = ET_MINLEN; 754 tmd->counts = 0xe1000000 | (len & 0x7ff); 755 tmd->status = 0x80000000; 756 757 st_le32( (tbase+memCSR1), 0x1); 758 759 m_freem(n); 760 761 dp->TxMD = tmd->next; 762 } 763 764 765 766 594 767 595 768 /* … … 599 772 dec21140_txDaemon (void *arg) 600 773 { 601 struct dec21140_softc *sc = (struct dec21140_softc *)arg; 602 struct ifnet *ifp = &sc->arpcom.ac_if; 603 struct mbuf *m; 604 rtems_event_set events; 605 606 for (;;) { 607 /* 608 * Wait for packet 609 */ 610 611 rtems_bsdnet_event_receive (START_TRANSMIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &events); 612 613 /* 614 * Send packets till queue is empty 615 */ 616 for (;;) { 774 struct dec21140_softc *sc; 775 struct ifnet *ifp; 776 struct mbuf *m; 777 int i; 778 rtems_event_set events; 779 780 for (;;) 781 { 617 782 /* 618 * Get the next mbuf chain to transmit.783 * Wait for packets bound for any of the dec units 619 784 */ 620 IF_DEQUEUE(&ifp->if_snd, m); 621 if (!m) 622 break; 623 sendpacket (ifp, m); 624 } 625 ifp->if_flags &= ~IFF_OACTIVE; 626 } 627 } 785 rtems_bsdnet_event_receive( RTEMS_ALL_EVENTS, 786 RTEMS_EVENT_ANY | RTEMS_WAIT, 787 RTEMS_NO_TIMEOUT, &events); 788 789 for(i=0; i< NDECDRIVER; i++ ) 790 { 791 sc = &dec21140_softc[i]; 792 if( sc->base ) 793 { 794 if( events & sc->ioevent ) 795 { 796 ifp = &sc->arpcom.ac_if; 797 798 /* 799 * Send packets till queue is empty 800 */ 801 for(;;) 802 { 803 IF_DEQUEUE(&ifp->if_snd, m); 804 if( !m ) break; 805 /* printk("unit %i tx\n", ifp->if_unit ); */ 806 sendpacket (ifp, m); 807 } 808 809 ifp->if_flags &= ~IFF_OACTIVE; 810 } 811 } 812 } 813 814 } 815 } 816 817 628 818 629 819 … … 631 821 dec21140_start (struct ifnet *ifp) 632 822 { 633 struct dec21140_softc *sc = ifp->if_softc; 634 635 rtems_event_send (sc->txDaemonTid, START_TRANSMIT_EVENT); 636 ifp->if_flags |= IFF_OACTIVE; 637 } 823 struct dec21140_softc *sc = ifp->if_softc; 824 rtems_event_send( txDaemonTid, sc->ioevent ); 825 ifp->if_flags |= IFF_OACTIVE; 826 } 827 828 829 830 638 831 639 832 /* … … 643 836 dec21140_init (void *arg) 644 837 { 645 struct dec21140_softc *sc = arg; 646 struct ifnet *ifp = &sc->arpcom.ac_if; 647 648 if (sc->txDaemonTid == 0) { 649 650 /* 651 * Set up DEC21140 hardware 652 */ 653 dec21140Enet_initialize_hardware (sc); 654 655 /* 656 * Start driver tasks 657 */ 658 sc->rxDaemonTid = rtems_bsdnet_newproc ("DCrx", 4096, 659 dec21140_rxDaemon, sc); 660 sc->txDaemonTid = rtems_bsdnet_newproc ("DCtx", 4096, 661 dec21140_txDaemon, sc); 662 } 663 664 /* 665 * Tell the world that we're running. 666 */ 667 ifp->if_flags |= IFF_RUNNING; 668 669 } 838 struct dec21140_softc *sc = arg; 839 struct ifnet *ifp = &sc->arpcom.ac_if; 840 volatile unsigned int *tbase; 841 842 /* 843 * Set up DEC21140 hardware if its not already been done 844 */ 845 if( !sc->irqInfo.hdl ) 846 { 847 dec21140Enet_initialize_hardware (sc); 848 } 849 850 /* 851 * Enable RX and TX 852 */ 853 tbase = sc->base; 854 st_le32( (tbase+memCSR5), IT_SETUP); 855 st_le32( (tbase+memCSR7), IT_SETUP); 856 st_le32( (unsigned int*)(tbase+memCSR6), CSR6_INIT | CSR6_TXRX); 857 858 /* 859 * Tell the world that we're running. 860 */ 861 ifp->if_flags |= IFF_RUNNING; 862 } 863 864 865 866 867 868 670 869 671 870 /* … … 683 882 * Stop the transmitter 684 883 */ 685 tbase =dec21140_softc[0].base;884 tbase = sc->base; 686 885 st_le32( (tbase+memCSR7), NO_IT); 687 886 st_le32( (tbase+memCSR6), CSR6_INIT); 688 free((void*)sc->bufferBase); 887 888 /* free((void*)sc->bufferBase); */ 689 889 } 690 890 … … 716 916 } 717 917 918 919 920 718 921 /* 719 922 * Driver ioctl handler … … 722 925 dec21140_ioctl (struct ifnet *ifp, int command, caddr_t data) 723 926 { 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 927 struct dec21140_softc *sc = ifp->if_softc; 928 int error = 0; 929 930 switch (command) { 931 case SIOCGIFADDR: 932 case SIOCSIFADDR: 933 ether_ioctl (ifp, command, data); 934 break; 935 936 case SIOCSIFFLAGS: 937 switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) { 938 case IFF_RUNNING: 939 dec21140_stop (sc); 940 break; 941 942 case IFF_UP: 943 dec21140_init (sc); 944 break; 945 946 case IFF_UP | IFF_RUNNING: 947 dec21140_stop (sc); 948 dec21140_init (sc); 949 break; 950 951 default: 952 break; 953 } 954 break; 955 956 case SIO_RTEMS_SHOW_STATS: 957 dec21140_stats (sc); 958 break; 756 959 757 /* 758 * FIXME: All sorts of multicast commands need to be added here! 759 */ 760 default: 761 error = EINVAL; 762 break; 763 } 764 765 return error; 766 } 960 /* 961 * FIXME: All sorts of multicast commands need to be added here! 962 */ 963 default: 964 error = EINVAL; 965 break; 966 } 967 968 return error; 969 } 970 971 972 973 974 975 976 977 /* 978 int iftap(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m ) 979 { 980 int i; 981 982 if( ifp->if_unit == 1 ) return 0; 983 984 printf("unit %i, src ", ifp->if_unit ); 985 for(i=0; i< ETHER_ADDR_LEN; i++) printf("%02x", (char) eh->ether_shost[i] ); 986 printf(" dest "); 987 for(i=0; i< ETHER_ADDR_LEN; i++) printf("%02x", (char) eh->ether_dhost[i] ); 988 printf("\n"); 989 990 return -1; 991 } 992 */ 993 994 995 996 767 997 768 998 /* … … 772 1002 rtems_dec21140_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach) 773 1003 { 774 struct dec21140_softc *sc; 775 struct ifnet *ifp; 776 int mtu; 777 int i; 1004 struct dec21140_softc *sc; 1005 struct ifnet *ifp; 1006 char *unitName; 1007 int unitNumber; 1008 int mtu; 1009 unsigned char cvalue; 778 1010 #if defined(__i386__) 779 int deviceId = PCI_DEVICE_ID_DEC_21140; /* network card device ID */ 780 #endif 1011 int signature; 1012 int value; 1013 char interrupt; 1014 int diag; 1015 unsigned int deviceId; 1016 #endif 1017 #if defined(__PPC) 1018 int pbus, pdev, pfun; 1019 int tmp; 1020 unsigned int lvalue; 1021 #endif 1022 1023 1024 /* 1025 * Get the instance number for the board we're going to configure 1026 * from the user. 1027 */ 1028 if( (unitNumber = rtems_bsdnet_parse_driver_name( config, &unitName)) == -1 ) 1029 { 1030 return 0; 1031 } 1032 if( strcmp(unitName, DRIVER_PREFIX) ) 1033 { 1034 printk("dec2114x : unit name '%s' not %s\n", unitName, DRIVER_PREFIX ); 1035 return 0; 1036 } 1037 1038 1039 #if defined(__i386__) 1040 /* 1041 * First, find a DEC board 1042 */ 1043 1044 if (pcib_init() == PCIB_ERR_NOTPRESENT) 1045 rtems_panic("PCI BIOS not found !!"); 781 1046 782 /* 783 * First, find a DEC board 784 */ 785 #if defined(__i386__) 786 int signature; 787 int value; 788 char interrupt; 789 int diag; 790 791 if (pcib_init() == PCIB_ERR_NOTPRESENT) 792 rtems_panic("PCI BIOS not found !!"); 793 794 /* 795 * Try to find the network card on the PCI bus. Probe for a DEC 21140 796 * card first. If not found probe the bus for a DEC/Intel 21143 card. 797 */ 798 deviceId = PCI_DEVICE_ID_DEC_21140; 799 diag = pcib_find_by_devid( PCI_VENDOR_ID_DEC, deviceId, 800 0, &signature); 801 if ( diag == PCIB_ERR_SUCCESS) 1047 /* 1048 * Try to find the network card on the PCI bus. Probe for a DEC 21140 1049 * card first. If not found probe the bus for a DEC/Intel 21143 card. 1050 */ 1051 deviceId = PCI_DEVICE_ID_DEC_21140; 1052 diag = pcib_find_by_devid( PCI_VENDOR_ID_DEC, deviceId, unitNumber-1, &signature); 1053 1054 if ( diag == PCIB_ERR_SUCCESS) 802 1055 printk( "DEC 21140 PCI network card found\n" ); 803 804 1056 else 1057 { 805 1058 deviceId = PCI_DEVICE_ID_DEC_21143; 806 diag = pcib_find_by_devid( PCI_VENDOR_ID_DEC, deviceId, 807 0, &signature); 1059 diag = pcib_find_by_devid( PCI_VENDOR_ID_DEC, deviceId, unitNumber-1, &signature); 808 1060 if ( diag == PCIB_ERR_SUCCESS) 809 printk( "DEC/Intel 21143 PCI network card found\n" );1061 printk( "DEC/Intel 21143 PCI network card found\n" ); 810 1062 else 811 rtems_panic("DEC PCI network card not found !!\n");812 1063 rtems_panic("DEC PCI network card not found !!\n"); 1064 } 813 1065 #endif 814 1066 #if defined(__PPC) 815 unsigned char ucSlotNumber, ucFnNumber; 816 unsigned int ulDeviceID, lvalue, tmp; 817 unsigned char cvalue; 818 819 for(ucSlotNumber=0;ucSlotNumber<PCI_MAX_DEVICES;ucSlotNumber++) { 820 for(ucFnNumber=0;ucFnNumber<PCI_MAX_FUNCTIONS;ucFnNumber++) { 821 (void)pci_read_config_dword(0, 822 ucSlotNumber, 823 ucFnNumber, 824 PCI_VENDOR_ID, 825 &ulDeviceID); 826 if(ulDeviceID==PCI_INVALID_VENDORDEVICEID) { 827 /* 828 * This slot is empty 829 */ 830 continue; 831 } 832 if (ulDeviceID == ((PCI_DEVICE_ID_DEC_21140<<16) + PCI_VENDOR_ID_DEC)) 833 break; 834 } 835 if (ulDeviceID == ((PCI_DEVICE_ID_DEC_21140<<16) + PCI_VENDOR_ID_DEC)){ 836 printk("DEC Adapter found !!\n"); 837 break; 838 } 839 } 1067 /* 1068 * Find the board 1069 */ 1070 if( BSP_pciFindDevice( PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21140, 1071 unitNumber-1, &pbus, &pdev, &pfun) == -1 ) 1072 { 1073 if( BSP_pciFindDevice( PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21143, 1074 unitNumber-1, &pbus, &pdev, &pfun) != -1 ) 1075 { 1076 printk("dec21143 : found device '%s', PPC support has not been tested. Using it anyway.\n", 1077 config->name ); 1078 1079 pci_write_config_dword(pbus, 1080 pdev, 1081 pfun, 1082 0x40, 1083 PCI_DEVICE_ID_DEC_21143 ); 1084 1085 } 1086 else 1087 { 1088 printk("dec2114x : device '%s' not found on PCI bus\n", config->name ); 1089 return 0; 1090 } 1091 } 1092 1093 #ifdef DEC_DEBUG 1094 else 1095 { 1096 printk("dec21140 : found device '%s', bus 0x%02x, dev 0x%02x, func 0x%02x\n", 1097 config->name, pbus, pdev, pfun); 1098 } 1099 #endif 1100 1101 #endif 1102 1103 1104 1105 1106 if ((unitNumber < 1) || (unitNumber > NDECDRIVER)) 1107 { 1108 printk("dec2114x : unit %i is invalid, must be (1 <= n <= %d)\n", unitNumber); 1109 return 0; 1110 } 1111 1112 sc = &dec21140_softc[unitNumber - 1]; 1113 ifp = &sc->arpcom.ac_if; 1114 if (ifp->if_softc != NULL) 1115 { 1116 printk("dec2114x : unit %i already in use.\n", unitNumber ); 1117 return 0; 1118 } 1119 1120 1121 /* 1122 ** Get this unit's rx/tx event 1123 */ 1124 sc->ioevent = unit_signals[unitNumber-1]; 1125 1126 1127 /* 1128 * Get card address spaces & retrieve its isr vector 1129 */ 1130 #if defined(__i386__) 1131 1132 /* the 21143 chip must be enabled before it can be accessed */ 1133 if ( deviceId == PCI_DEVICE_ID_DEC_21143 ) 1134 pcib_conf_write32( signature, 0x40, 0 ); 1135 1136 pcib_conf_read32(signature, 16, &value); 1137 sc->port = value & ~IO_MASK; 1138 1139 pcib_conf_read32(signature, 20, &value); 1140 if (_CPU_is_paging_enabled()) 1141 _CPU_map_phys_address((void **) &(sc->base), 1142 (void *)(value & ~MEM_MASK), 1143 DEC_REGISTER_SIZE , 1144 PTE_CACHE_DISABLE | PTE_WRITABLE); 1145 else 1146 sc->base = (unsigned int *)(value & ~MEM_MASK); 840 1147 841 if(ulDeviceID==PCI_INVALID_VENDORDEVICEID) 842 rtems_panic("DEC PCI board not found !!\n"); 843 #endif 844 /* 845 * Find a free driver 846 */ 847 for (i = 0 ; i < NDECDRIVER ; i++) { 848 sc = &dec21140_softc[i]; 849 ifp = &sc->arpcom.ac_if; 850 if (ifp->if_softc == NULL) 851 break; 852 } 853 if (i >= NDECDRIVER) { 854 printk ("Too many DEC drivers.\n"); 855 return 0; 856 } 857 858 /* 859 * Process options 860 */ 1148 pcib_conf_read8(signature, 60, &interrupt); 1149 cvalue = interrupt; 1150 #endif 1151 #if defined(__PPC) 1152 (void)pci_read_config_dword(pbus, 1153 pdev, 1154 pfun, 1155 PCI_BASE_ADDRESS_0, 1156 &lvalue); 1157 1158 sc->port = lvalue & (unsigned int)(~IO_MASK); 1159 1160 (void)pci_read_config_dword(pbus, 1161 pdev, 1162 pfun, 1163 PCI_BASE_ADDRESS_1, 1164 &lvalue); 1165 1166 tmp = (unsigned int)(lvalue & (unsigned int)(~MEM_MASK)) 1167 + (unsigned int)PCI_MEM_BASE; 1168 1169 sc->base = (unsigned int *)(tmp); 1170 1171 pci_read_config_byte(pbus, 1172 pdev, 1173 pfun, 1174 PCI_INTERRUPT_LINE, 1175 &cvalue); 1176 1177 #endif 1178 1179 /* 1180 ** Prep the board 1181 */ 1182 pci_write_config_word(pbus, pdev, pfun, 1183 PCI_COMMAND, 1184 (unsigned16)( PCI_COMMAND_MEMORY | 1185 PCI_COMMAND_MASTER | 1186 PCI_COMMAND_INVALIDATE | 1187 PCI_COMMAND_WAIT | 1188 PCI_COMMAND_FAST_BACK ) ); 1189 1190 /* 1191 ** Store the interrupt name, we'll use it later when we initialize 1192 ** the board. 1193 */ 1194 memset(&sc->irqInfo,0,sizeof(rtems_irq_connect_data)); 1195 sc->irqInfo.name = cvalue; 1196 1197 1198 /* printk("dec2114x : unit %d base address %08x.\n", unitNumber, sc->base ); */ 1199 1200 1201 /* 1202 ** Setup ethernet address 1203 */ 1204 if (config->hardware_address) { 1205 memcpy (sc->arpcom.ac_enaddr, config->hardware_address, 1206 ETHER_ADDR_LEN); 1207 } 1208 else { 1209 union {char c[64]; unsigned short s[32];} rombuf; 1210 int i; 1211 1212 for (i=0; i<32; i++){ 1213 rombuf.s[i] = eeget16( sc->base + memCSR9, i); 1214 } 861 1215 #if defined(__i386__) 862 863 /* the 21143 chip must be enabled before it can be accessed */ 864 if ( deviceId == PCI_DEVICE_ID_DEC_21143 ) 865 pcib_conf_write32( signature, 0x40, 0 ); 866 867 pcib_conf_read32(signature, 16, &value); 868 sc->port = value & ~IO_MASK; 869 870 pcib_conf_read32(signature, 20, &value); 871 if (_CPU_is_paging_enabled()) 872 _CPU_map_phys_address((void **) &(sc->base), 873 (void *)(value & ~MEM_MASK), 874 DEC_REGISTER_SIZE , 875 PTE_CACHE_DISABLE | PTE_WRITABLE); 876 else 877 sc->base = (unsigned int *)(value & ~MEM_MASK); 878 879 pcib_conf_read8(signature, 60, &interrupt); 880 sc->irqInfo.name = (rtems_irq_symbolic_name)interrupt; 1216 for (i=0 ; i<(ETHER_ADDR_LEN/2); i++){ 1217 sc->arpcom.ac_enaddr[2*i] = rombuf.c[20+2*i+1]; 1218 sc->arpcom.ac_enaddr[2*i+1] = rombuf.c[20+2*i]; 1219 } 881 1220 #endif 882 1221 #if defined(__PPC) 883 (void)pci_read_config_dword(0, 884 ucSlotNumber, 885 ucFnNumber, 886 PCI_BASE_ADDRESS_0, 887 &lvalue); 888 889 sc->port = lvalue & (unsigned int)(~IO_MASK); 890 891 (void)pci_read_config_dword(0, 892 ucSlotNumber, 893 ucFnNumber, 894 PCI_BASE_ADDRESS_1 , 895 &lvalue); 896 897 898 tmp = (unsigned int)(lvalue & (unsigned int)(~MEM_MASK)) 899 + (unsigned int)PCI_MEM_BASE; 900 sc->base = (unsigned int *)(tmp); 901 902 (void)pci_read_config_byte(0, 903 ucSlotNumber, 904 ucFnNumber, 905 PCI_INTERRUPT_LINE, 906 &cvalue); 907 sc->irqInfo.name = (rtems_irq_symbolic_name)cvalue; 908 #endif 909 if (config->hardware_address) { 910 memcpy (sc->arpcom.ac_enaddr, config->hardware_address, 911 ETHER_ADDR_LEN); 912 } 913 else { 914 union {char c[64]; unsigned short s[32];} rombuf; 915 int i; 916 917 for (i=0; i<32; i++){ 918 rombuf.s[i] = eeget16(sc->base+memCSR9, i); 919 } 920 #if defined(__i386__) 921 for (i=0 ; i<(ETHER_ADDR_LEN/2); i++){ 922 sc->arpcom.ac_enaddr[2*i] = rombuf.c[20+2*i+1]; 923 sc->arpcom.ac_enaddr[2*i+1] = rombuf.c[20+2*i]; 924 } 925 #endif 926 #if defined(__PPC) 927 memcpy (sc->arpcom.ac_enaddr, rombuf.c+20, ETHER_ADDR_LEN); 928 #endif 929 } 930 931 if (config->mtu) 932 mtu = config->mtu; 933 else 934 mtu = ETHERMTU; 935 936 sc->acceptBroadcast = !config->ignore_broadcast; 937 938 /* 939 * Set up network interface values 940 */ 941 ifp->if_softc = sc; 942 ifp->if_unit = i + 1; 943 ifp->if_name = "dc"; 944 ifp->if_mtu = mtu; 945 ifp->if_init = dec21140_init; 946 ifp->if_ioctl = dec21140_ioctl; 947 ifp->if_start = dec21140_start; 948 ifp->if_output = ether_output; 949 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; 950 if (ifp->if_snd.ifq_maxlen == 0) 951 ifp->if_snd.ifq_maxlen = ifqmaxlen; 952 953 /* 954 * Attach the interface 955 */ 956 if_attach (ifp); 957 ether_ifattach (ifp); 958 959 printk( "DC2114x : driver has been attached\n" ); 960 return 1; 1222 memcpy (sc->arpcom.ac_enaddr, rombuf.c+20, ETHER_ADDR_LEN); 1223 #endif 1224 } 1225 1226 if (config->mtu) 1227 mtu = config->mtu; 1228 else 1229 mtu = ETHERMTU; 1230 1231 sc->acceptBroadcast = !config->ignore_broadcast; 1232 1233 /* 1234 * Set up network interface values 1235 */ 1236 1237 /* ifp->if_tap = iftap; */ 1238 1239 ifp->if_softc = sc; 1240 ifp->if_unit = unitNumber; 1241 ifp->if_name = unitName; 1242 ifp->if_mtu = mtu; 1243 ifp->if_init = dec21140_init; 1244 ifp->if_ioctl = dec21140_ioctl; 1245 ifp->if_start = dec21140_start; 1246 ifp->if_output = ether_output; 1247 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; 1248 if (ifp->if_snd.ifq_maxlen == 0) 1249 ifp->if_snd.ifq_maxlen = ifqmaxlen; 1250 1251 /* 1252 * Attach the interface 1253 */ 1254 if_attach (ifp); 1255 ether_ifattach (ifp); 1256 1257 #ifdef DEC_DEBUG 1258 printk( "dec2114x : driver attached\n" ); 1259 #endif 1260 1261 1262 /* 1263 * Start driver tasks if this is the first dec unit initialized 1264 */ 1265 if (txDaemonTid == 0) 1266 { 1267 rxDaemonTid = rtems_bsdnet_newproc( "DCrx", 4096, 1268 dec21140_rxDaemon, NULL); 1269 1270 txDaemonTid = rtems_bsdnet_newproc( "DCtx", 4096, 1271 dec21140_txDaemon, NULL); 1272 #ifdef DEC_DEBUG 1273 printk( "dec2114x : driver tasks created\n" ); 1274 #endif 1275 } 1276 1277 return 1; 961 1278 }; 1279 962 1280 #endif /* DEC21140_SUPPORTED */ 963 1281 1282 1283 /* eof */
Note: See TracChangeset
for help on using the changeset viewer.