if_nge.c (99004) | if_nge.c (99497) |
---|---|
1/* 2 * Copyright (c) 2001 Wind River Systems 3 * Copyright (c) 1997, 1998, 1999, 2000, 2001 4 * Bill Paul <wpaul@bsdi.com>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 16 unchanged lines hidden (view full) --- 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 * | 1/* 2 * Copyright (c) 2001 Wind River Systems 3 * Copyright (c) 1997, 1998, 1999, 2000, 2001 4 * Bill Paul <wpaul@bsdi.com>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 16 unchanged lines hidden (view full) --- 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/sys/dev/nge/if_nge.c 99004 2002-06-29 01:36:59Z alfred $ | 33 * $FreeBSD: head/sys/dev/nge/if_nge.c 99497 2002-07-06 15:59:57Z alfred $ |
34 */ 35 36/* 37 * National Semiconductor DP83820/DP83821 gigabit ethernet driver 38 * for FreeBSD. Datasheets are available from: 39 * 40 * http://www.national.com/ds/DP/DP83820.pdf 41 * http://www.national.com/ds/DP/DP83821.pdf --- 85 unchanged lines hidden (view full) --- 127 128MODULE_DEPEND(nge, miibus, 1, 1, 1); 129 130/* "controller miibus0" required. See GENERIC if you get errors here. */ 131#include "miibus_if.h" 132 133#ifndef lint 134static const char rcsid[] = | 34 */ 35 36/* 37 * National Semiconductor DP83820/DP83821 gigabit ethernet driver 38 * for FreeBSD. Datasheets are available from: 39 * 40 * http://www.national.com/ds/DP/DP83820.pdf 41 * http://www.national.com/ds/DP/DP83821.pdf --- 85 unchanged lines hidden (view full) --- 127 128MODULE_DEPEND(nge, miibus, 1, 1, 1); 129 130/* "controller miibus0" required. See GENERIC if you get errors here. */ 131#include "miibus_if.h" 132 133#ifndef lint 134static const char rcsid[] = |
135 "$FreeBSD: head/sys/dev/nge/if_nge.c 99004 2002-06-29 01:36:59Z alfred $"; | 135 "$FreeBSD: head/sys/dev/nge/if_nge.c 99497 2002-07-06 15:59:57Z alfred $"; |
136#endif 137 138#define NGE_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) 139 140/* 141 * Various supported device vendors/types and their names. 142 */ 143static struct nge_type nge_devs[] = { 144 { NGE_VENDORID, NGE_DEVICEID, 145 "National Semiconductor Gigabit Ethernet" }, 146 { 0, 0, NULL } 147}; 148 | 136#endif 137 138#define NGE_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP) 139 140/* 141 * Various supported device vendors/types and their names. 142 */ 143static struct nge_type nge_devs[] = { 144 { NGE_VENDORID, NGE_DEVICEID, 145 "National Semiconductor Gigabit Ethernet" }, 146 { 0, 0, NULL } 147}; 148 |
149static int nge_probe (device_t); 150static int nge_attach (device_t); 151static int nge_detach (device_t); | 149static int nge_probe(device_t); 150static int nge_attach(device_t); 151static int nge_detach(device_t); |
152 | 152 |
153static int nge_alloc_jumbo_mem (struct nge_softc *); 154static void nge_free_jumbo_mem (struct nge_softc *); 155static void *nge_jalloc (struct nge_softc *); 156static void nge_jfree (void *, void *); | 153static int nge_alloc_jumbo_mem(struct nge_softc *); 154static void nge_free_jumbo_mem(struct nge_softc *); 155static void *nge_jalloc(struct nge_softc *); 156static void nge_jfree(void *, void *); |
157 | 157 |
158static int nge_newbuf (struct nge_softc *, 159 struct nge_desc *, struct mbuf *); 160static int nge_encap (struct nge_softc *, 161 struct mbuf *, u_int32_t *); 162static void nge_rxeof (struct nge_softc *); 163static void nge_txeof (struct nge_softc *); 164static void nge_intr (void *); 165static void nge_tick (void *); 166static void nge_start (struct ifnet *); 167static int nge_ioctl (struct ifnet *, u_long, caddr_t); 168static void nge_init (void *); 169static void nge_stop (struct nge_softc *); 170static void nge_watchdog (struct ifnet *); 171static void nge_shutdown (device_t); 172static int nge_ifmedia_upd (struct ifnet *); 173static void nge_ifmedia_sts (struct ifnet *, struct ifmediareq *); | 158static int nge_newbuf(struct nge_softc *, struct nge_desc *, struct mbuf *); 159static int nge_encap(struct nge_softc *, struct mbuf *, u_int32_t *); 160static void nge_rxeof(struct nge_softc *); 161static void nge_txeof(struct nge_softc *); 162static void nge_intr(void *); 163static void nge_tick(void *); 164static void nge_start(struct ifnet *); 165static int nge_ioctl(struct ifnet *, u_long, caddr_t); 166static void nge_init(void *); 167static void nge_stop(struct nge_softc *); 168static void nge_watchdog(struct ifnet *); 169static void nge_shutdown(device_t); 170static int nge_ifmedia_upd(struct ifnet *); 171static void nge_ifmedia_sts(struct ifnet *, struct ifmediareq *); |
174 | 172 |
175static void nge_delay (struct nge_softc *); 176static void nge_eeprom_idle (struct nge_softc *); 177static void nge_eeprom_putbyte (struct nge_softc *, int); 178static void nge_eeprom_getword (struct nge_softc *, int, u_int16_t *); 179static void nge_read_eeprom (struct nge_softc *, caddr_t, int, int, int); | 173static void nge_delay(struct nge_softc *); 174static void nge_eeprom_idle(struct nge_softc *); 175static void nge_eeprom_putbyte(struct nge_softc *, int); 176static void nge_eeprom_getword(struct nge_softc *, int, u_int16_t *); 177static void nge_read_eeprom(struct nge_softc *, caddr_t, int, int, int); |
180 | 178 |
181static void nge_mii_sync (struct nge_softc *); 182static void nge_mii_send (struct nge_softc *, u_int32_t, int); 183static int nge_mii_readreg (struct nge_softc *, struct nge_mii_frame *); 184static int nge_mii_writereg (struct nge_softc *, struct nge_mii_frame *); | 179static void nge_mii_sync(struct nge_softc *); 180static void nge_mii_send(struct nge_softc *, u_int32_t, int); 181static int nge_mii_readreg(struct nge_softc *, struct nge_mii_frame *); 182static int nge_mii_writereg(struct nge_softc *, struct nge_mii_frame *); |
185 | 183 |
186static int nge_miibus_readreg (device_t, int, int); 187static int nge_miibus_writereg (device_t, int, int, int); 188static void nge_miibus_statchg (device_t); | 184static int nge_miibus_readreg(device_t, int, int); 185static int nge_miibus_writereg(device_t, int, int, int); 186static void nge_miibus_statchg(device_t); |
189 | 187 |
190static void nge_setmulti (struct nge_softc *); 191static u_int32_t nge_crc (struct nge_softc *, caddr_t); 192static void nge_reset (struct nge_softc *); 193static int nge_list_rx_init (struct nge_softc *); 194static int nge_list_tx_init (struct nge_softc *); | 188static void nge_setmulti(struct nge_softc *); 189static u_int32_t nge_crc(struct nge_softc *, caddr_t); 190static void nge_reset(struct nge_softc *); 191static int nge_list_rx_init(struct nge_softc *); 192static int nge_list_tx_init(struct nge_softc *); |
195 196#ifdef NGE_USEIOSPACE 197#define NGE_RES SYS_RES_IOPORT 198#define NGE_RID NGE_PCI_LOIO 199#else 200#define NGE_RES SYS_RES_MEMORY 201#define NGE_RID NGE_PCI_LOMEM 202#endif --- 37 unchanged lines hidden (view full) --- 240 CSR_READ_4(sc, reg) & ~(x)) 241 242#define SIO_SET(x) \ 243 CSR_WRITE_4(sc, NGE_MEAR, CSR_READ_4(sc, NGE_MEAR) | x) 244 245#define SIO_CLR(x) \ 246 CSR_WRITE_4(sc, NGE_MEAR, CSR_READ_4(sc, NGE_MEAR) & ~x) 247 | 193 194#ifdef NGE_USEIOSPACE 195#define NGE_RES SYS_RES_IOPORT 196#define NGE_RID NGE_PCI_LOIO 197#else 198#define NGE_RES SYS_RES_MEMORY 199#define NGE_RID NGE_PCI_LOMEM 200#endif --- 37 unchanged lines hidden (view full) --- 238 CSR_READ_4(sc, reg) & ~(x)) 239 240#define SIO_SET(x) \ 241 CSR_WRITE_4(sc, NGE_MEAR, CSR_READ_4(sc, NGE_MEAR) | x) 242 243#define SIO_CLR(x) \ 244 CSR_WRITE_4(sc, NGE_MEAR, CSR_READ_4(sc, NGE_MEAR) & ~x) 245 |
248static void nge_delay(sc) | 246static void 247nge_delay(sc) |
249 struct nge_softc *sc; 250{ 251 int idx; 252 253 for (idx = (300 / 33) + 1; idx > 0; idx--) 254 CSR_READ_4(sc, NGE_CSR); 255 256 return; 257} 258 | 248 struct nge_softc *sc; 249{ 250 int idx; 251 252 for (idx = (300 / 33) + 1; idx > 0; idx--) 253 CSR_READ_4(sc, NGE_CSR); 254 255 return; 256} 257 |
259static void nge_eeprom_idle(sc) | 258static void 259nge_eeprom_idle(sc) |
260 struct nge_softc *sc; 261{ 262 register int i; 263 264 SIO_SET(NGE_MEAR_EE_CSEL); 265 nge_delay(sc); 266 SIO_SET(NGE_MEAR_EE_CLK); 267 nge_delay(sc); --- 12 unchanged lines hidden (view full) --- 280 CSR_WRITE_4(sc, NGE_MEAR, 0x00000000); 281 282 return; 283} 284 285/* 286 * Send a read command and address to the EEPROM, check for ACK. 287 */ | 260 struct nge_softc *sc; 261{ 262 register int i; 263 264 SIO_SET(NGE_MEAR_EE_CSEL); 265 nge_delay(sc); 266 SIO_SET(NGE_MEAR_EE_CLK); 267 nge_delay(sc); --- 12 unchanged lines hidden (view full) --- 280 CSR_WRITE_4(sc, NGE_MEAR, 0x00000000); 281 282 return; 283} 284 285/* 286 * Send a read command and address to the EEPROM, check for ACK. 287 */ |
288static void nge_eeprom_putbyte(sc, addr) | 288static void 289nge_eeprom_putbyte(sc, addr) |
289 struct nge_softc *sc; 290 int addr; 291{ 292 register int d, i; 293 294 d = addr | NGE_EECMD_READ; 295 296 /* --- 13 unchanged lines hidden (view full) --- 310 } 311 312 return; 313} 314 315/* 316 * Read a word of data stored in the EEPROM at address 'addr.' 317 */ | 290 struct nge_softc *sc; 291 int addr; 292{ 293 register int d, i; 294 295 d = addr | NGE_EECMD_READ; 296 297 /* --- 13 unchanged lines hidden (view full) --- 311 } 312 313 return; 314} 315 316/* 317 * Read a word of data stored in the EEPROM at address 'addr.' 318 */ |
318static void nge_eeprom_getword(sc, addr, dest) | 319static void 320nge_eeprom_getword(sc, addr, dest) |
319 struct nge_softc *sc; 320 int addr; 321 u_int16_t *dest; 322{ 323 register int i; 324 u_int16_t word = 0; 325 326 /* Force EEPROM to idle state. */ --- 30 unchanged lines hidden (view full) --- 357 *dest = word; 358 359 return; 360} 361 362/* 363 * Read a sequence of words from the EEPROM. 364 */ | 321 struct nge_softc *sc; 322 int addr; 323 u_int16_t *dest; 324{ 325 register int i; 326 u_int16_t word = 0; 327 328 /* Force EEPROM to idle state. */ --- 30 unchanged lines hidden (view full) --- 359 *dest = word; 360 361 return; 362} 363 364/* 365 * Read a sequence of words from the EEPROM. 366 */ |
365static void nge_read_eeprom(sc, dest, off, cnt, swap) | 367static void 368nge_read_eeprom(sc, dest, off, cnt, swap) |
366 struct nge_softc *sc; 367 caddr_t dest; 368 int off; 369 int cnt; 370 int swap; 371{ 372 int i; 373 u_int16_t word = 0, *ptr; --- 8 unchanged lines hidden (view full) --- 382 } 383 384 return; 385} 386 387/* 388 * Sync the PHYs by setting data bit and strobing the clock 32 times. 389 */ | 369 struct nge_softc *sc; 370 caddr_t dest; 371 int off; 372 int cnt; 373 int swap; 374{ 375 int i; 376 u_int16_t word = 0, *ptr; --- 8 unchanged lines hidden (view full) --- 385 } 386 387 return; 388} 389 390/* 391 * Sync the PHYs by setting data bit and strobing the clock 32 times. 392 */ |
390static void nge_mii_sync(sc) | 393static void 394nge_mii_sync(sc) |
391 struct nge_softc *sc; 392{ 393 register int i; 394 395 SIO_SET(NGE_MEAR_MII_DIR|NGE_MEAR_MII_DATA); 396 397 for (i = 0; i < 32; i++) { 398 SIO_SET(NGE_MEAR_MII_CLK); 399 DELAY(1); 400 SIO_CLR(NGE_MEAR_MII_CLK); 401 DELAY(1); 402 } 403 404 return; 405} 406 407/* 408 * Clock a series of bits through the MII. 409 */ | 395 struct nge_softc *sc; 396{ 397 register int i; 398 399 SIO_SET(NGE_MEAR_MII_DIR|NGE_MEAR_MII_DATA); 400 401 for (i = 0; i < 32; i++) { 402 SIO_SET(NGE_MEAR_MII_CLK); 403 DELAY(1); 404 SIO_CLR(NGE_MEAR_MII_CLK); 405 DELAY(1); 406 } 407 408 return; 409} 410 411/* 412 * Clock a series of bits through the MII. 413 */ |
410static void nge_mii_send(sc, bits, cnt) | 414static void 415nge_mii_send(sc, bits, cnt) |
411 struct nge_softc *sc; 412 u_int32_t bits; 413 int cnt; 414{ 415 int i; 416 417 SIO_CLR(NGE_MEAR_MII_CLK); 418 --- 8 unchanged lines hidden (view full) --- 427 DELAY(1); 428 SIO_SET(NGE_MEAR_MII_CLK); 429 } 430} 431 432/* 433 * Read an PHY register through the MII. 434 */ | 416 struct nge_softc *sc; 417 u_int32_t bits; 418 int cnt; 419{ 420 int i; 421 422 SIO_CLR(NGE_MEAR_MII_CLK); 423 --- 8 unchanged lines hidden (view full) --- 432 DELAY(1); 433 SIO_SET(NGE_MEAR_MII_CLK); 434 } 435} 436 437/* 438 * Read an PHY register through the MII. 439 */ |
435static int nge_mii_readreg(sc, frame) | 440static int 441nge_mii_readreg(sc, frame) |
436 struct nge_softc *sc; 437 struct nge_mii_frame *frame; 438 439{ 440 int i, ack, s; 441 442 s = splimp(); 443 --- 75 unchanged lines hidden (view full) --- 519 if (ack) 520 return(1); 521 return(0); 522} 523 524/* 525 * Write to a PHY register through the MII. 526 */ | 442 struct nge_softc *sc; 443 struct nge_mii_frame *frame; 444 445{ 446 int i, ack, s; 447 448 s = splimp(); 449 --- 75 unchanged lines hidden (view full) --- 525 if (ack) 526 return(1); 527 return(0); 528} 529 530/* 531 * Write to a PHY register through the MII. 532 */ |
527static int nge_mii_writereg(sc, frame) | 533static int 534nge_mii_writereg(sc, frame) |
528 struct nge_softc *sc; 529 struct nge_mii_frame *frame; 530 531{ 532 int s; 533 534 s = splimp(); 535 /* --- 29 unchanged lines hidden (view full) --- 565 */ 566 SIO_CLR(NGE_MEAR_MII_DIR); 567 568 splx(s); 569 570 return(0); 571} 572 | 535 struct nge_softc *sc; 536 struct nge_mii_frame *frame; 537 538{ 539 int s; 540 541 s = splimp(); 542 /* --- 29 unchanged lines hidden (view full) --- 572 */ 573 SIO_CLR(NGE_MEAR_MII_DIR); 574 575 splx(s); 576 577 return(0); 578} 579 |
573static int nge_miibus_readreg(dev, phy, reg) | 580static int 581nge_miibus_readreg(dev, phy, reg) |
574 device_t dev; 575 int phy, reg; 576{ 577 struct nge_softc *sc; 578 struct nge_mii_frame frame; 579 580 sc = device_get_softc(dev); 581 582 bzero((char *)&frame, sizeof(frame)); 583 584 frame.mii_phyaddr = phy; 585 frame.mii_regaddr = reg; 586 nge_mii_readreg(sc, &frame); 587 588 return(frame.mii_data); 589} 590 | 582 device_t dev; 583 int phy, reg; 584{ 585 struct nge_softc *sc; 586 struct nge_mii_frame frame; 587 588 sc = device_get_softc(dev); 589 590 bzero((char *)&frame, sizeof(frame)); 591 592 frame.mii_phyaddr = phy; 593 frame.mii_regaddr = reg; 594 nge_mii_readreg(sc, &frame); 595 596 return(frame.mii_data); 597} 598 |
591static int nge_miibus_writereg(dev, phy, reg, data) | 599static int 600nge_miibus_writereg(dev, phy, reg, data) |
592 device_t dev; 593 int phy, reg, data; 594{ 595 struct nge_softc *sc; 596 struct nge_mii_frame frame; 597 598 sc = device_get_softc(dev); 599 600 bzero((char *)&frame, sizeof(frame)); 601 602 frame.mii_phyaddr = phy; 603 frame.mii_regaddr = reg; 604 frame.mii_data = data; 605 nge_mii_writereg(sc, &frame); 606 607 return(0); 608} 609 | 601 device_t dev; 602 int phy, reg, data; 603{ 604 struct nge_softc *sc; 605 struct nge_mii_frame frame; 606 607 sc = device_get_softc(dev); 608 609 bzero((char *)&frame, sizeof(frame)); 610 611 frame.mii_phyaddr = phy; 612 frame.mii_regaddr = reg; 613 frame.mii_data = data; 614 nge_mii_writereg(sc, &frame); 615 616 return(0); 617} 618 |
610static void nge_miibus_statchg(dev) | 619static void 620nge_miibus_statchg(dev) |
611 device_t dev; 612{ 613 struct nge_softc *sc; 614 struct mii_data *mii; 615 616 sc = device_get_softc(dev); 617 mii = device_get_softc(sc->nge_miibus); 618 --- 13 unchanged lines hidden (view full) --- 632 NGE_SETBIT(sc, NGE_CFG, NGE_CFG_MODE_1000); 633 } else { 634 NGE_CLRBIT(sc, NGE_CFG, NGE_CFG_MODE_1000); 635 } 636 637 return; 638} 639 | 621 device_t dev; 622{ 623 struct nge_softc *sc; 624 struct mii_data *mii; 625 626 sc = device_get_softc(dev); 627 mii = device_get_softc(sc->nge_miibus); 628 --- 13 unchanged lines hidden (view full) --- 642 NGE_SETBIT(sc, NGE_CFG, NGE_CFG_MODE_1000); 643 } else { 644 NGE_CLRBIT(sc, NGE_CFG, NGE_CFG_MODE_1000); 645 } 646 647 return; 648} 649 |
640static u_int32_t nge_crc(sc, addr) | 650static u_int32_t 651nge_crc(sc, addr) |
641 struct nge_softc *sc; 642 caddr_t addr; 643{ 644 u_int32_t crc, carry; 645 int i, j; 646 u_int8_t c; 647 648 /* Compute CRC for the address value. */ --- 12 unchanged lines hidden (view full) --- 661 662 /* 663 * return the filter bit position 664 */ 665 666 return((crc >> 21) & 0x00000FFF); 667} 668 | 652 struct nge_softc *sc; 653 caddr_t addr; 654{ 655 u_int32_t crc, carry; 656 int i, j; 657 u_int8_t c; 658 659 /* Compute CRC for the address value. */ --- 12 unchanged lines hidden (view full) --- 672 673 /* 674 * return the filter bit position 675 */ 676 677 return((crc >> 21) & 0x00000FFF); 678} 679 |
669static void nge_setmulti(sc) | 680static void 681nge_setmulti(sc) |
670 struct nge_softc *sc; 671{ 672 struct ifnet *ifp; 673 struct ifmultiaddr *ifma; 674 u_int32_t h = 0, i, filtsave; 675 int bit, index; 676 677 ifp = &sc->arpcom.ac_if; --- 40 unchanged lines hidden (view full) --- 718 NGE_SETBIT(sc, NGE_RXFILT_DATA, (1 << bit)); 719 } 720 721 CSR_WRITE_4(sc, NGE_RXFILT_CTL, filtsave); 722 723 return; 724} 725 | 682 struct nge_softc *sc; 683{ 684 struct ifnet *ifp; 685 struct ifmultiaddr *ifma; 686 u_int32_t h = 0, i, filtsave; 687 int bit, index; 688 689 ifp = &sc->arpcom.ac_if; --- 40 unchanged lines hidden (view full) --- 730 NGE_SETBIT(sc, NGE_RXFILT_DATA, (1 << bit)); 731 } 732 733 CSR_WRITE_4(sc, NGE_RXFILT_CTL, filtsave); 734 735 return; 736} 737 |
726static void nge_reset(sc) | 738static void 739nge_reset(sc) |
727 struct nge_softc *sc; 728{ 729 register int i; 730 731 NGE_SETBIT(sc, NGE_CSR, NGE_CSR_RESET); 732 733 for (i = 0; i < NGE_TIMEOUT; i++) { 734 if (!(CSR_READ_4(sc, NGE_CSR) & NGE_CSR_RESET)) --- 15 unchanged lines hidden (view full) --- 750 751 return; 752} 753 754/* 755 * Probe for an NatSemi chip. Check the PCI vendor and device 756 * IDs against our list and return a device name if we find a match. 757 */ | 740 struct nge_softc *sc; 741{ 742 register int i; 743 744 NGE_SETBIT(sc, NGE_CSR, NGE_CSR_RESET); 745 746 for (i = 0; i < NGE_TIMEOUT; i++) { 747 if (!(CSR_READ_4(sc, NGE_CSR) & NGE_CSR_RESET)) --- 15 unchanged lines hidden (view full) --- 763 764 return; 765} 766 767/* 768 * Probe for an NatSemi chip. Check the PCI vendor and device 769 * IDs against our list and return a device name if we find a match. 770 */ |
758static int nge_probe(dev) | 771static int 772nge_probe(dev) |
759 device_t dev; 760{ 761 struct nge_type *t; 762 763 t = nge_devs; 764 765 while(t->nge_name != NULL) { 766 if ((pci_get_vendor(dev) == t->nge_vid) && --- 6 unchanged lines hidden (view full) --- 773 774 return(ENXIO); 775} 776 777/* 778 * Attach the interface. Allocate softc structures, do ifmedia 779 * setup and ethernet/BPF attach. 780 */ | 773 device_t dev; 774{ 775 struct nge_type *t; 776 777 t = nge_devs; 778 779 while(t->nge_name != NULL) { 780 if ((pci_get_vendor(dev) == t->nge_vid) && --- 6 unchanged lines hidden (view full) --- 787 788 return(ENXIO); 789} 790 791/* 792 * Attach the interface. Allocate softc structures, do ifmedia 793 * setup and ethernet/BPF attach. 794 */ |
781static int nge_attach(dev) | 795static int 796nge_attach(dev) |
782 device_t dev; 783{ 784 int s; 785 u_char eaddr[ETHER_ADDR_LEN]; 786 u_int32_t command; 787 struct nge_softc *sc; 788 struct ifnet *ifp; 789 int unit, error = 0, rid; --- 169 unchanged lines hidden (view full) --- 959 callout_handle_init(&sc->nge_stat_ch); 960 961fail: 962 splx(s); 963 mtx_destroy(&sc->nge_mtx); 964 return(error); 965} 966 | 797 device_t dev; 798{ 799 int s; 800 u_char eaddr[ETHER_ADDR_LEN]; 801 u_int32_t command; 802 struct nge_softc *sc; 803 struct ifnet *ifp; 804 int unit, error = 0, rid; --- 169 unchanged lines hidden (view full) --- 974 callout_handle_init(&sc->nge_stat_ch); 975 976fail: 977 splx(s); 978 mtx_destroy(&sc->nge_mtx); 979 return(error); 980} 981 |
967static int nge_detach(dev) | 982static int 983nge_detach(dev) |
968 device_t dev; 969{ 970 struct nge_softc *sc; 971 struct ifnet *ifp; 972 int s; 973 974 s = splimp(); 975 --- 18 unchanged lines hidden (view full) --- 994 mtx_destroy(&sc->nge_mtx); 995 996 return(0); 997} 998 999/* 1000 * Initialize the transmit descriptors. 1001 */ | 984 device_t dev; 985{ 986 struct nge_softc *sc; 987 struct ifnet *ifp; 988 int s; 989 990 s = splimp(); 991 --- 18 unchanged lines hidden (view full) --- 1010 mtx_destroy(&sc->nge_mtx); 1011 1012 return(0); 1013} 1014 1015/* 1016 * Initialize the transmit descriptors. 1017 */ |
1002static int nge_list_tx_init(sc) | 1018static int 1019nge_list_tx_init(sc) |
1003 struct nge_softc *sc; 1004{ 1005 struct nge_list_data *ld; 1006 struct nge_ring_data *cd; 1007 int i; 1008 1009 cd = &sc->nge_cdata; 1010 ld = sc->nge_ldata; --- 21 unchanged lines hidden (view full) --- 1032} 1033 1034 1035/* 1036 * Initialize the RX descriptors and allocate mbufs for them. Note that 1037 * we arrange the descriptors in a closed ring, so that the last descriptor 1038 * points back to the first. 1039 */ | 1020 struct nge_softc *sc; 1021{ 1022 struct nge_list_data *ld; 1023 struct nge_ring_data *cd; 1024 int i; 1025 1026 cd = &sc->nge_cdata; 1027 ld = sc->nge_ldata; --- 21 unchanged lines hidden (view full) --- 1049} 1050 1051 1052/* 1053 * Initialize the RX descriptors and allocate mbufs for them. Note that 1054 * we arrange the descriptors in a closed ring, so that the last descriptor 1055 * points back to the first. 1056 */ |
1040static int nge_list_rx_init(sc) | 1057static int 1058nge_list_rx_init(sc) |
1041 struct nge_softc *sc; 1042{ 1043 struct nge_list_data *ld; 1044 struct nge_ring_data *cd; 1045 int i; 1046 1047 ld = sc->nge_ldata; 1048 cd = &sc->nge_cdata; --- 17 unchanged lines hidden (view full) --- 1066 cd->nge_rx_prod = 0; 1067 1068 return(0); 1069} 1070 1071/* 1072 * Initialize an RX descriptor and attach an MBUF cluster. 1073 */ | 1059 struct nge_softc *sc; 1060{ 1061 struct nge_list_data *ld; 1062 struct nge_ring_data *cd; 1063 int i; 1064 1065 ld = sc->nge_ldata; 1066 cd = &sc->nge_cdata; --- 17 unchanged lines hidden (view full) --- 1084 cd->nge_rx_prod = 0; 1085 1086 return(0); 1087} 1088 1089/* 1090 * Initialize an RX descriptor and attach an MBUF cluster. 1091 */ |
1074static int nge_newbuf(sc, c, m) | 1092static int 1093nge_newbuf(sc, c, m) |
1075 struct nge_softc *sc; 1076 struct nge_desc *c; 1077 struct mbuf *m; 1078{ 1079 struct mbuf *m_new = NULL; 1080 caddr_t *buf = NULL; 1081 1082 if (m == NULL) { --- 30 unchanged lines hidden (view full) --- 1113 c->nge_mbuf = m_new; 1114 c->nge_ptr = vtophys(mtod(m_new, caddr_t)); 1115 c->nge_ctl = m_new->m_len; 1116 c->nge_extsts = 0; 1117 1118 return(0); 1119} 1120 | 1094 struct nge_softc *sc; 1095 struct nge_desc *c; 1096 struct mbuf *m; 1097{ 1098 struct mbuf *m_new = NULL; 1099 caddr_t *buf = NULL; 1100 1101 if (m == NULL) { --- 30 unchanged lines hidden (view full) --- 1132 c->nge_mbuf = m_new; 1133 c->nge_ptr = vtophys(mtod(m_new, caddr_t)); 1134 c->nge_ctl = m_new->m_len; 1135 c->nge_extsts = 0; 1136 1137 return(0); 1138} 1139 |
1121static int nge_alloc_jumbo_mem(sc) | 1140static int 1141nge_alloc_jumbo_mem(sc) |
1122 struct nge_softc *sc; 1123{ 1124 caddr_t ptr; 1125 register int i; 1126 struct nge_jpool_entry *entry; 1127 1128 /* Grab a big chunk o' storage. */ 1129 sc->nge_cdata.nge_jumbo_buf = contigmalloc(NGE_JMEM, M_DEVBUF, --- 25 unchanged lines hidden (view full) --- 1155 entry->slot = i; 1156 SLIST_INSERT_HEAD(&sc->nge_jfree_listhead, 1157 entry, jpool_entries); 1158 } 1159 1160 return(0); 1161} 1162 | 1142 struct nge_softc *sc; 1143{ 1144 caddr_t ptr; 1145 register int i; 1146 struct nge_jpool_entry *entry; 1147 1148 /* Grab a big chunk o' storage. */ 1149 sc->nge_cdata.nge_jumbo_buf = contigmalloc(NGE_JMEM, M_DEVBUF, --- 25 unchanged lines hidden (view full) --- 1175 entry->slot = i; 1176 SLIST_INSERT_HEAD(&sc->nge_jfree_listhead, 1177 entry, jpool_entries); 1178 } 1179 1180 return(0); 1181} 1182 |
1163static void nge_free_jumbo_mem(sc) | 1183static void 1184nge_free_jumbo_mem(sc) |
1164 struct nge_softc *sc; 1165{ 1166 register int i; 1167 struct nge_jpool_entry *entry; 1168 1169 for (i = 0; i < NGE_JSLOTS; i++) { 1170 entry = SLIST_FIRST(&sc->nge_jfree_listhead); 1171 SLIST_REMOVE_HEAD(&sc->nge_jfree_listhead, jpool_entries); 1172 free(entry, M_DEVBUF); 1173 } 1174 1175 contigfree(sc->nge_cdata.nge_jumbo_buf, NGE_JMEM, M_DEVBUF); 1176 1177 return; 1178} 1179 1180/* 1181 * Allocate a jumbo buffer. 1182 */ | 1185 struct nge_softc *sc; 1186{ 1187 register int i; 1188 struct nge_jpool_entry *entry; 1189 1190 for (i = 0; i < NGE_JSLOTS; i++) { 1191 entry = SLIST_FIRST(&sc->nge_jfree_listhead); 1192 SLIST_REMOVE_HEAD(&sc->nge_jfree_listhead, jpool_entries); 1193 free(entry, M_DEVBUF); 1194 } 1195 1196 contigfree(sc->nge_cdata.nge_jumbo_buf, NGE_JMEM, M_DEVBUF); 1197 1198 return; 1199} 1200 1201/* 1202 * Allocate a jumbo buffer. 1203 */ |
1183static void *nge_jalloc(sc) | 1204static void * 1205nge_jalloc(sc) |
1184 struct nge_softc *sc; 1185{ 1186 struct nge_jpool_entry *entry; 1187 1188 entry = SLIST_FIRST(&sc->nge_jfree_listhead); 1189 1190 if (entry == NULL) { 1191#ifdef NGE_VERBOSE --- 5 unchanged lines hidden (view full) --- 1197 SLIST_REMOVE_HEAD(&sc->nge_jfree_listhead, jpool_entries); 1198 SLIST_INSERT_HEAD(&sc->nge_jinuse_listhead, entry, jpool_entries); 1199 return(sc->nge_cdata.nge_jslots[entry->slot]); 1200} 1201 1202/* 1203 * Release a jumbo buffer. 1204 */ | 1206 struct nge_softc *sc; 1207{ 1208 struct nge_jpool_entry *entry; 1209 1210 entry = SLIST_FIRST(&sc->nge_jfree_listhead); 1211 1212 if (entry == NULL) { 1213#ifdef NGE_VERBOSE --- 5 unchanged lines hidden (view full) --- 1219 SLIST_REMOVE_HEAD(&sc->nge_jfree_listhead, jpool_entries); 1220 SLIST_INSERT_HEAD(&sc->nge_jinuse_listhead, entry, jpool_entries); 1221 return(sc->nge_cdata.nge_jslots[entry->slot]); 1222} 1223 1224/* 1225 * Release a jumbo buffer. 1226 */ |
1205static void nge_jfree(buf, args) | 1227static void 1228nge_jfree(buf, args) |
1206 void *buf; 1207 void *args; 1208{ 1209 struct nge_softc *sc; 1210 int i; 1211 struct nge_jpool_entry *entry; 1212 1213 /* Extract the softc struct pointer. */ --- 17 unchanged lines hidden (view full) --- 1231 SLIST_INSERT_HEAD(&sc->nge_jfree_listhead, entry, jpool_entries); 1232 1233 return; 1234} 1235/* 1236 * A frame has been uploaded: pass the resulting mbuf chain up to 1237 * the higher level protocols. 1238 */ | 1229 void *buf; 1230 void *args; 1231{ 1232 struct nge_softc *sc; 1233 int i; 1234 struct nge_jpool_entry *entry; 1235 1236 /* Extract the softc struct pointer. */ --- 17 unchanged lines hidden (view full) --- 1254 SLIST_INSERT_HEAD(&sc->nge_jfree_listhead, entry, jpool_entries); 1255 1256 return; 1257} 1258/* 1259 * A frame has been uploaded: pass the resulting mbuf chain up to 1260 * the higher level protocols. 1261 */ |
1239static void nge_rxeof(sc) | 1262static void 1263nge_rxeof(sc) |
1240 struct nge_softc *sc; 1241{ 1242 struct ether_header *eh; 1243 struct mbuf *m; 1244 struct ifnet *ifp; 1245 struct nge_desc *cur_rx; 1246 int i, total_len = 0; 1247 u_int32_t rxstat; --- 97 unchanged lines hidden (view full) --- 1345 return; 1346} 1347 1348/* 1349 * A frame was downloaded to the chip. It's safe for us to clean up 1350 * the list buffers. 1351 */ 1352 | 1264 struct nge_softc *sc; 1265{ 1266 struct ether_header *eh; 1267 struct mbuf *m; 1268 struct ifnet *ifp; 1269 struct nge_desc *cur_rx; 1270 int i, total_len = 0; 1271 u_int32_t rxstat; --- 97 unchanged lines hidden (view full) --- 1369 return; 1370} 1371 1372/* 1373 * A frame was downloaded to the chip. It's safe for us to clean up 1374 * the list buffers. 1375 */ 1376 |
1353static void nge_txeof(sc) | 1377static void 1378nge_txeof(sc) |
1354 struct nge_softc *sc; 1355{ 1356 struct nge_desc *cur_tx = NULL; 1357 struct ifnet *ifp; 1358 u_int32_t idx; 1359 1360 ifp = &sc->arpcom.ac_if; 1361 --- 42 unchanged lines hidden (view full) --- 1404 sc->nge_cdata.nge_tx_cons = idx; 1405 1406 if (cur_tx != NULL) 1407 ifp->if_flags &= ~IFF_OACTIVE; 1408 1409 return; 1410} 1411 | 1379 struct nge_softc *sc; 1380{ 1381 struct nge_desc *cur_tx = NULL; 1382 struct ifnet *ifp; 1383 u_int32_t idx; 1384 1385 ifp = &sc->arpcom.ac_if; 1386 --- 42 unchanged lines hidden (view full) --- 1429 sc->nge_cdata.nge_tx_cons = idx; 1430 1431 if (cur_tx != NULL) 1432 ifp->if_flags &= ~IFF_OACTIVE; 1433 1434 return; 1435} 1436 |
1412static void nge_tick(xsc) | 1437static void 1438nge_tick(xsc) |
1413 void *xsc; 1414{ 1415 struct nge_softc *sc; 1416 struct mii_data *mii; 1417 struct ifnet *ifp; 1418 int s; 1419 1420 s = splimp(); --- 17 unchanged lines hidden (view full) --- 1438 } 1439 sc->nge_stat_ch = timeout(nge_tick, sc, hz); 1440 1441 splx(s); 1442 1443 return; 1444} 1445 | 1439 void *xsc; 1440{ 1441 struct nge_softc *sc; 1442 struct mii_data *mii; 1443 struct ifnet *ifp; 1444 int s; 1445 1446 s = splimp(); --- 17 unchanged lines hidden (view full) --- 1464 } 1465 sc->nge_stat_ch = timeout(nge_tick, sc, hz); 1466 1467 splx(s); 1468 1469 return; 1470} 1471 |
1446static void nge_intr(arg) | 1472static void 1473nge_intr(arg) |
1447 void *arg; 1448{ 1449 struct nge_softc *sc; 1450 struct ifnet *ifp; 1451 u_int32_t status; 1452 1453 sc = arg; 1454 ifp = &sc->arpcom.ac_if; --- 58 unchanged lines hidden (view full) --- 1513 1514 return; 1515} 1516 1517/* 1518 * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data 1519 * pointers to the fragment pointers. 1520 */ | 1474 void *arg; 1475{ 1476 struct nge_softc *sc; 1477 struct ifnet *ifp; 1478 u_int32_t status; 1479 1480 sc = arg; 1481 ifp = &sc->arpcom.ac_if; --- 58 unchanged lines hidden (view full) --- 1540 1541 return; 1542} 1543 1544/* 1545 * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data 1546 * pointers to the fragment pointers. 1547 */ |
1521static int nge_encap(sc, m_head, txidx) | 1548static int 1549nge_encap(sc, m_head, txidx) |
1522 struct nge_softc *sc; 1523 struct mbuf *m_head; 1524 u_int32_t *txidx; 1525{ 1526 struct nge_desc *f = NULL; 1527 struct mbuf *m; 1528 int frag, cur, cnt = 0; 1529 struct ifvlan *ifv = NULL; --- 59 unchanged lines hidden (view full) --- 1589 1590/* 1591 * Main transmit routine. To avoid having to do mbuf copies, we put pointers 1592 * to the mbuf data regions directly in the transmit lists. We also save a 1593 * copy of the pointers since the transmit list fragment pointers are 1594 * physical addresses. 1595 */ 1596 | 1550 struct nge_softc *sc; 1551 struct mbuf *m_head; 1552 u_int32_t *txidx; 1553{ 1554 struct nge_desc *f = NULL; 1555 struct mbuf *m; 1556 int frag, cur, cnt = 0; 1557 struct ifvlan *ifv = NULL; --- 59 unchanged lines hidden (view full) --- 1617 1618/* 1619 * Main transmit routine. To avoid having to do mbuf copies, we put pointers 1620 * to the mbuf data regions directly in the transmit lists. We also save a 1621 * copy of the pointers since the transmit list fragment pointers are 1622 * physical addresses. 1623 */ 1624 |
1597static void nge_start(ifp) | 1625static void 1626nge_start(ifp) |
1598 struct ifnet *ifp; 1599{ 1600 struct nge_softc *sc; 1601 struct mbuf *m_head = NULL; 1602 u_int32_t idx; 1603 1604 sc = ifp->if_softc; 1605 --- 32 unchanged lines hidden (view full) --- 1638 /* 1639 * Set a timeout in case the chip goes out to lunch. 1640 */ 1641 ifp->if_timer = 5; 1642 1643 return; 1644} 1645 | 1627 struct ifnet *ifp; 1628{ 1629 struct nge_softc *sc; 1630 struct mbuf *m_head = NULL; 1631 u_int32_t idx; 1632 1633 sc = ifp->if_softc; 1634 --- 32 unchanged lines hidden (view full) --- 1667 /* 1668 * Set a timeout in case the chip goes out to lunch. 1669 */ 1670 ifp->if_timer = 5; 1671 1672 return; 1673} 1674 |
1646static void nge_init(xsc) | 1675static void 1676nge_init(xsc) |
1647 void *xsc; 1648{ 1649 struct nge_softc *sc = xsc; 1650 struct ifnet *ifp = &sc->arpcom.ac_if; 1651 struct mii_data *mii; 1652 int s; 1653 1654 if (ifp->if_flags & IFF_RUNNING) --- 152 unchanged lines hidden (view full) --- 1807 (void)splx(s); 1808 1809 return; 1810} 1811 1812/* 1813 * Set media options. 1814 */ | 1677 void *xsc; 1678{ 1679 struct nge_softc *sc = xsc; 1680 struct ifnet *ifp = &sc->arpcom.ac_if; 1681 struct mii_data *mii; 1682 int s; 1683 1684 if (ifp->if_flags & IFF_RUNNING) --- 152 unchanged lines hidden (view full) --- 1837 (void)splx(s); 1838 1839 return; 1840} 1841 1842/* 1843 * Set media options. 1844 */ |
1815static int nge_ifmedia_upd(ifp) | 1845static int 1846nge_ifmedia_upd(ifp) |
1816 struct ifnet *ifp; 1817{ 1818 struct nge_softc *sc; 1819 struct mii_data *mii; 1820 1821 sc = ifp->if_softc; 1822 1823 mii = device_get_softc(sc->nge_miibus); --- 7 unchanged lines hidden (view full) --- 1831 mii_mediachg(mii); 1832 1833 return(0); 1834} 1835 1836/* 1837 * Report current media status. 1838 */ | 1847 struct ifnet *ifp; 1848{ 1849 struct nge_softc *sc; 1850 struct mii_data *mii; 1851 1852 sc = ifp->if_softc; 1853 1854 mii = device_get_softc(sc->nge_miibus); --- 7 unchanged lines hidden (view full) --- 1862 mii_mediachg(mii); 1863 1864 return(0); 1865} 1866 1867/* 1868 * Report current media status. 1869 */ |
1839static void nge_ifmedia_sts(ifp, ifmr) | 1870static void 1871nge_ifmedia_sts(ifp, ifmr) |
1840 struct ifnet *ifp; 1841 struct ifmediareq *ifmr; 1842{ 1843 struct nge_softc *sc; 1844 struct mii_data *mii; 1845 1846 sc = ifp->if_softc; 1847 1848 mii = device_get_softc(sc->nge_miibus); 1849 mii_pollstat(mii); 1850 ifmr->ifm_active = mii->mii_media_active; 1851 ifmr->ifm_status = mii->mii_media_status; 1852 1853 return; 1854} 1855 | 1872 struct ifnet *ifp; 1873 struct ifmediareq *ifmr; 1874{ 1875 struct nge_softc *sc; 1876 struct mii_data *mii; 1877 1878 sc = ifp->if_softc; 1879 1880 mii = device_get_softc(sc->nge_miibus); 1881 mii_pollstat(mii); 1882 ifmr->ifm_active = mii->mii_media_active; 1883 ifmr->ifm_status = mii->mii_media_status; 1884 1885 return; 1886} 1887 |
1856static int nge_ioctl(ifp, command, data) | 1888static int 1889nge_ioctl(ifp, command, data) |
1857 struct ifnet *ifp; 1858 u_long command; 1859 caddr_t data; 1860{ 1861 struct nge_softc *sc = ifp->if_softc; 1862 struct ifreq *ifr = (struct ifreq *) data; 1863 struct mii_data *mii; 1864 int s, error = 0; --- 63 unchanged lines hidden (view full) --- 1928 break; 1929 } 1930 1931 (void)splx(s); 1932 1933 return(error); 1934} 1935 | 1890 struct ifnet *ifp; 1891 u_long command; 1892 caddr_t data; 1893{ 1894 struct nge_softc *sc = ifp->if_softc; 1895 struct ifreq *ifr = (struct ifreq *) data; 1896 struct mii_data *mii; 1897 int s, error = 0; --- 63 unchanged lines hidden (view full) --- 1961 break; 1962 } 1963 1964 (void)splx(s); 1965 1966 return(error); 1967} 1968 |
1936static void nge_watchdog(ifp) | 1969static void 1970nge_watchdog(ifp) |
1937 struct ifnet *ifp; 1938{ 1939 struct nge_softc *sc; 1940 1941 sc = ifp->if_softc; 1942 1943 ifp->if_oerrors++; 1944 printf("nge%d: watchdog timeout\n", sc->nge_unit); --- 8 unchanged lines hidden (view full) --- 1953 1954 return; 1955} 1956 1957/* 1958 * Stop the adapter and free any mbufs allocated to the 1959 * RX and TX lists. 1960 */ | 1971 struct ifnet *ifp; 1972{ 1973 struct nge_softc *sc; 1974 1975 sc = ifp->if_softc; 1976 1977 ifp->if_oerrors++; 1978 printf("nge%d: watchdog timeout\n", sc->nge_unit); --- 8 unchanged lines hidden (view full) --- 1987 1988 return; 1989} 1990 1991/* 1992 * Stop the adapter and free any mbufs allocated to the 1993 * RX and TX lists. 1994 */ |
1961static void nge_stop(sc) | 1995static void 1996nge_stop(sc) |
1962 struct nge_softc *sc; 1963{ 1964 register int i; 1965 struct ifnet *ifp; 1966 struct mii_data *mii; 1967 1968 ifp = &sc->arpcom.ac_if; 1969 ifp->if_timer = 0; --- 40 unchanged lines hidden (view full) --- 2010 2011 return; 2012} 2013 2014/* 2015 * Stop all chip I/O so that the kernel's probe routines don't 2016 * get confused by errant DMAs when rebooting. 2017 */ | 1997 struct nge_softc *sc; 1998{ 1999 register int i; 2000 struct ifnet *ifp; 2001 struct mii_data *mii; 2002 2003 ifp = &sc->arpcom.ac_if; 2004 ifp->if_timer = 0; --- 40 unchanged lines hidden (view full) --- 2045 2046 return; 2047} 2048 2049/* 2050 * Stop all chip I/O so that the kernel's probe routines don't 2051 * get confused by errant DMAs when rebooting. 2052 */ |
2018static void nge_shutdown(dev) | 2053static void 2054nge_shutdown(dev) |
2019 device_t dev; 2020{ 2021 struct nge_softc *sc; 2022 2023 sc = device_get_softc(dev); 2024 2025 nge_reset(sc); 2026 nge_stop(sc); 2027 2028 return; 2029} | 2055 device_t dev; 2056{ 2057 struct nge_softc *sc; 2058 2059 sc = device_get_softc(dev); 2060 2061 nge_reset(sc); 2062 nge_stop(sc); 2063 2064 return; 2065} |