1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Bill Paul. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 *
| 1/* 2 * Copyright (c) 1997, 1998, 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Bill Paul. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 *
|
353 354/* TX descriptor queue control registers */ 355#define SF_TXDQCTL_DESCTYPE 0x00000007 356#define SF_TXDQCTL_NODMACMP 0x00000008 357#define SF_TXDQCTL_MINSPACE 0x00000070 358#define SF_TXDQCTL_64BITADDR 0x00000080 359#define SF_TXDQCTL_BURSTLEN 0x00003F00 360#define SF_TXDQCTL_SKIPLEN 0x001F0000 361#define SF_TXDQCTL_HIPRIOTHRESH 0xFF000000 362 363#define SF_TXBUFDESC_TYPE0 0x00000000 364#define SF_TXBUFDESC_TYPE1 0x00000001 365#define SF_TXBUFDESC_TYPE2 0x00000002 366#define SF_TXBUFDESC_TYPE3 0x00000003 367#define SF_TXBUFDESC_TYPE4 0x00000004 368 369#define SF_TXMINSPACE_UNLIMIT 0x00000000 370#define SF_TXMINSPACE_32BYTES 0x00000010 371#define SF_TXMINSPACE_64BYTES 0x00000020 372#define SF_TXMINSPACE_128BYTES 0x00000030 373#define SF_TXMINSPACE_256BYTES 0x00000040 374 375#define SF_TXSKIPLEN_0BYTES 0x00000000 376#define SF_TXSKIPLEN_8BYTES 0x00010000 377#define SF_TXSKIPLEN_16BYTES 0x00020000 378#define SF_TXSKIPLEN_24BYTES 0x00030000 379#define SF_TXSKIPLEN_32BYTES 0x00040000 380 381/* TX frame control register */ 382#define SF_TXFRMCTL_TXTHRESH 0x000000FF 383#define SF_TXFRMCTL_CPLAFTERTX 0x00000100 384#define SF_TXFRMCRL_DEBUG 0x0000FE00 385#define SF_TXFRMCTL_STATUS 0x01FF0000 386#define SF_TXFRMCTL_MAC_TXIF 0xFE000000 387 388/* TX completion queue control register */ 389#define SF_TXCQ_THRESH 0x0000000F 390#define SF_TXCQ_COMMON 0x00000010 391#define SF_TXCQ_SIZE 0x00000020 392#define SF_TXCQ_WRITEENB 0x00000040 393#define SF_TXCQ_USE_64BIT 0x00000080 394#define SF_TXCQ_ADDR 0xFFFFFF00 395 396/* RX completion queue control register */ 397#define SF_RXCQ_THRESH 0x0000000F 398#define SF_RXCQ_TYPE 0x00000030 399#define SF_RXCQ_WRITEENB 0x00000040 400#define SF_RXCQ_USE_64BIT 0x00000080 401#define SF_RXCQ_ADDR 0xFFFFFF00 402 403#define SF_RXCQTYPE_0 0x00000000 404#define SF_RXCQTYPE_1 0x00000010 405#define SF_RXCQTYPE_2 0x00000020 406#define SF_RXCQTYPE_3 0x00000030 407 408/* TX descriptor queue producer index register */ 409#define SF_TXDQ_PRODIDX_LOPRIO 0x000007FF 410#define SF_TXDQ_PRODIDX_HIPRIO 0x07FF0000 411 412/* TX descriptor queue consumer index register */ 413#define SF_TXDQ_CONSIDX_LOPRIO 0x000007FF 414#define SF_TXDQ_CONSIDX_HIPRIO 0x07FF0000 415 416/* Completion queue consumer index register */ 417#define SF_CQ_CONSIDX_RXQ1 0x000003FF 418#define SF_CQ_CONSIDX_RXTHRMODE 0x00008000 419#define SF_CQ_CONSIDX_TXQ 0x03FF0000 420#define SF_CQ_CONSIDX_TXTHRMODE 0x80000000 421 422/* Completion queue producer index register */ 423#define SF_CQ_PRODIDX_RXQ1 0x000003FF 424#define SF_CQ_PRODIDX_TXQ 0x03FF0000 425 426/* RX completion queue 2 consumer/producer index register */ 427#define SF_CQ_RXQ2_CONSIDX 0x000003FF 428#define SF_CQ_RXQ2_RXTHRMODE 0x00008000 429#define SF_CQ_RXQ2_PRODIDX 0x03FF0000 430 431#define SF_CQ_RXTHRMODE_INT_ON 0x00008000 432#define SF_CQ_RXTHRMODE_INT_OFF 0x00000000 433#define SF_CQ_TXTHRMODE_INT_ON 0x80000000 434#define SF_CQ_TXTHRMODE_INT_OFF 0x00000000 435 436#define SF_IDX_LO(x) ((x) & 0x000007FF) 437#define SF_IDX_HI(x) (((x) >> 16) & 0x000007FF) 438 439/* RX DMA control register */ 440#define SF_RXDMA_BURSTSIZE 0x0000007F 441#define SF_RXDMA_FPTESTMODE 0x00000080 442#define SF_RXDMA_HIPRIOTHRESH 0x00000F00 443#define SF_RXDMA_RXEARLYTHRESH 0x0001F000 444#define SF_RXDMA_DMACRC 0x00040000 445#define SF_RXDMA_USEBKUPQUEUE 0x00080000 446#define SF_RXDMA_QUEUEMODE 0x00700000 447#define SF_RXDMA_RXCQ2_ON 0x00800000 448#define SF_RXDMA_CSUMMODE 0x03000000 449#define SF_RXDMA_DMAPAUSEPKTS 0x04000000 450#define SF_RXDMA_DMACTLPKTS 0x08000000 451#define SF_RXDMA_DMACRXERRPKTS 0x10000000 452#define SF_RXDMA_DMABADPKTS 0x20000000 453#define SF_RXDMA_DMARUNTS 0x40000000 454#define SF_RXDMA_REPORTBADPKTS 0x80000000 455 456#define SF_RXDQMODE_Q1ONLY 0x00100000 457#define SF_RXDQMODE_Q2_ON_FP 0x00200000 458#define SF_RXDQMODE_Q2_ON_SHORT 0x00300000 459#define SF_RXDQMODE_Q2_ON_PRIO 0x00400000 460#define SF_RXDQMODE_SPLITHDR 0x00500000 461 462#define SF_RXCSUMMODE_IGNORE 0x00000000 463#define SF_RXCSUMMODE_REJECT_BAD_TCP 0x01000000 464#define SF_RXCSUMMODE_REJECT_BAD_TCPUDP 0x02000000 465#define SF_RXCSUMMODE_RSVD 0x03000000 466 467/* RX descriptor queue control registers */ 468#define SF_RXDQCTL_MINDESCTHR 0x0000007F 469#define SF_RXDQCTL_Q1_WE 0x00000080 470#define SF_RXDQCTL_DESCSPACE 0x00000700 471#define SF_RXDQCTL_64BITDADDR 0x00000800 472#define SF_RXDQCTL_64BITBADDR 0x00001000 473#define SF_RXDQCTL_VARIABLE 0x00002000 474#define SF_RXDQCTL_ENTRIES 0x00004000 475#define SF_RXDQCTL_PREFETCH 0x00008000 476#define SF_RXDQCTL_BUFLEN 0xFFFF0000 477 478#define SF_DESCSPACE_4BYTES 0x00000000 479#define SF_DESCSPACE_8BYTES 0x00000100 480#define SF_DESCSPACE_16BYTES 0x00000200 481#define SF_DESCSPACE_32BYTES 0x00000300 482#define SF_DESCSPACE_64BYTES 0x00000400 483#define SF_DESCSPACE_128_BYTES 0x00000500 484 485/* RX buffer consumer/producer index registers */ 486#define SF_RXDQ_PRODIDX 0x000007FF 487#define SF_RXDQ_CONSIDX 0x07FF0000 488 489/* RX filter control register */ 490#define SF_RXFILT_PROMISC 0x00000001 491#define SF_RXFILT_ALLMULTI 0x00000002 492#define SF_RXFILT_BROAD 0x00000004 493#define SF_RXFILT_HASHPRIO 0x00000008 494#define SF_RXFILT_HASHMODE 0x00000030 495#define SF_RXFILT_PERFMODE 0x000000C0 496#define SF_RXFILT_VLANMODE 0x00000300 497#define SF_RXFILT_WAKEMODE 0x00000C00 498#define SF_RXFILT_MULTI_NOBROAD 0x00001000 499#define SF_RXFILT_MIN_VLANPRIO 0x0000E000 500#define SF_RXFILT_PEFECTPRIO 0xFFFF0000 501 502/* Hash filtering mode */ 503#define SF_HASHMODE_OFF 0x00000000 504#define SF_HASHMODE_WITHVLAN 0x00000010 505#define SF_HASHMODE_ANYVLAN 0x00000020 506#define SF_HASHMODE_ANY 0x00000030 507 508/* Perfect filtering mode */ 509#define SF_PERFMODE_OFF 0x00000000 510#define SF_PERFMODE_NORMAL 0x00000040 511#define SF_PERFMODE_INVERSE 0x00000080 512#define SF_PERFMODE_VLAN 0x000000C0 513 514/* VLAN mode */ 515#define SF_VLANMODE_OFF 0x00000000 516#define SF_VLANMODE_NOSTRIP 0x00000100 517#define SF_VLANMODE_STRIP 0x00000200 518#define SF_VLANMODE_RSVD 0x00000300 519 520/* Wakeup mode */ 521#define SF_WAKEMODE_OFF 0x00000000 522#define SF_WAKEMODE_FILTER 0x00000400 523#define SF_WAKEMODE_FP 0x00000800 524#define SF_WAKEMODE_HIPRIO 0x00000C00 525 526/* 527 * Extra PCI registers 0x0100 to 0x0FFF 528 */ 529#define SF_PCI_TARGSTAT 0x0100 530#define SF_PCI_MASTSTAT1 0x0104 531#define SF_PCI_MASTSTAT2 0x0108 532#define SF_PCI_DMAHOSTADDR_LO 0x010C 533#define SF_BAC_DMADIAG0 0x0110 534#define SF_BAC_DMADIAG1 0x0114 535#define SF_BAC_DMADIAG2 0x0118 536#define SF_BAC_DMADIAG3 0x011C 537#define SF_PAR0 0x0120 538#define SF_PAR1 0x0124 539#define SF_PCICB_FUNCEVENT 0x0130 540#define SF_PCICB_FUNCEVENT_MASK 0x0134 541#define SF_PCICB_FUNCSTATE 0x0138 542#define SF_PCICB_FUNCFORCE 0x013C 543 544/* 545 * Serial EEPROM registers 0x1000 to 0x1FFF 546 * Presumeably the EEPROM is mapped into this 8K window. 547 */ 548#define SF_EEADDR_BASE 0x1000 549#define SF_EEADDR_MAX 0x1FFF 550 551#define SF_EE_NODEADDR 14 552 553/* 554 * MII registers registers 0x2000 to 0x3FFF 555 * There are 32 sets of 32 registers, one set for each possible 556 * PHY address. Each 32 bit register is split into a 16-bit data 557 * port and a couple of status bits. 558 */ 559 560#define SF_MIIADDR_BASE 0x2000 561#define SF_MIIADDR_MAX 0x3FFF 562#define SF_MII_BLOCKS 32 563 564#define SF_MII_DATAVALID 0x80000000 565#define SF_MII_BUSY 0x40000000 566#define SF_MII_DATAPORT 0x0000FFFF 567 568#define SF_PHY_REG(phy, reg) \ 569 (SF_MIIADDR_BASE + (phy * SF_MII_BLOCKS * sizeof(u_int32_t)) + \ 570 (reg * sizeof(u_int32_t))) 571 572/* 573 * Ethernet extra registers 0x4000 to 0x4FFF 574 */ 575#define SF_TESTMODE 0x4000 576#define SF_RX_FRAMEPROC_CTL 0x4004 577#define SF_TX_FRAMEPROC_CTL 0x4008 578 579/* 580 * MAC registers 0x5000 to 0x5FFF 581 */ 582#define SF_MACCFG_1 0x5000 583#define SF_MACCFG_2 0x5004 584#define SF_BKTOBKIPG 0x5008 585#define SF_NONBKTOBKIPG 0x500C 586#define SF_COLRETRY 0x5010 587#define SF_MAXLEN 0x5014 588#define SF_TXNIBBLECNT 0x5018 589#define SF_TXBYTECNT 0x501C 590#define SF_RETXCNT 0x5020 591#define SF_RANDNUM 0x5024 592#define SF_RANDNUM_MASK 0x5028 593#define SF_TOTALTXCNT 0x5034 594#define SF_RXBYTECNT 0x5040 595#define SF_TXPAUSETIMER 0x5060 596#define SF_VLANTYPE 0x5064 597#define SF_MIISTATUS 0x5070 598 599#define SF_MACCFG1_HUGEFRAMES 0x00000001 600#define SF_MACCFG1_FULLDUPLEX 0x00000002 601#define SF_MACCFG1_AUTOPAD 0x00000004 602#define SF_MACCFG1_HDJAM 0x00000008 603#define SF_MACCFG1_DELAYCRC 0x00000010 604#define SF_MACCFG1_NOBACKOFF 0x00000020 605#define SF_MACCFG1_LENGTHCHECK 0x00000040 606#define SF_MACCFG1_PUREPREAMBLE 0x00000080 607#define SF_MACCFG1_PASSALLRX 0x00000100 608#define SF_MACCFG1_PREAM_DETCNT 0x00000200 609#define SF_MACCFG1_RX_FLOWENB 0x00000400 610#define SF_MACCFG1_TX_FLOWENB 0x00000800 611#define SF_MACCFG1_TESTMODE 0x00003000 612#define SF_MACCFG1_MIILOOPBK 0x00004000 613#define SF_MACCFG1_SOFTRESET 0x00008000 614 615/* 616 * There are the recommended IPG nibble counter settings 617 * specified in the Adaptec manual for full duplex and 618 * half duplex operation. 619 */ 620#define SF_IPGT_FDX 0x15 621#define SF_IPGT_HDX 0x11 622 623/* 624 * RX filter registers 0x6000 to 0x6FFF 625 */ 626#define SF_RXFILT_PERFECT_BASE 0x6000 627#define SF_RXFILT_PERFECT_MAX 0x60FF 628#define SF_RXFILT_PERFECT_SKIP 0x0010 629#define SF_RXFILT_PERFECT_CNT 0x0010 630 631#define SF_RXFILT_HASH_BASE 0x6100 632#define SF_RXFILT_HASH_MAX 0x62FF 633#define SF_RXFILT_HASH_SKIP 0x0010 634#define SF_RXFILT_HASH_CNT 0x001F 635#define SF_RXFILT_HASH_ADDROFF 0x0000 636#define SF_RXFILT_HASH_PRIOOFF 0x0004 637#define SF_RXFILT_HASH_VLANOFF 0x0008 638 639/* 640 * Statistics registers 0x7000 to 0x7FFF 641 */ 642#define SF_STATS_BASE 0x7000 643#define SF_STATS_END 0x7FFF 644 645/* 646 * TX frame processor instruction space 0x8000 to 0x9FFF 647 */ 648 649/* 650 * RX frame processor instruction space 0xA000 to 0xBFFF 651 */ 652 653/* 654 * Ethernet FIFO access space 0xC000 to 0xDFFF 655 */ 656 657/* 658 * Reserved 0xE000 to 0xFFFF 659 */ 660 661/* 662 * Descriptor data structures. 663 */ 664 665 666/* Receive descriptor formats. */ 667#define SF_RX_MINSPACING 8 668#define SF_RX_DLIST_CNT 256 669#define SF_RX_CLIST_CNT 1024 670#define SF_RX_HOSTADDR(x) (((x) >> 2) & 0x3FFFFFFF) 671 672/* 673 * RX buffer descriptor type 0, 32-bit addressing. Note that we 674 * program the RX buffer queue control register(s) to allow a 675 * descriptor spacing of 16 bytes, which leaves room after each 676 * descriptor to store a pointer to the mbuf for each buffer. 677 */ 678struct sf_rx_bufdesc_type0 { 679 u_int32_t sf_valid:1, 680 sf_end:1, 681 sf_addrlo:30; 682 u_int32_t sf_pad0; 683#ifdef __i386__ 684 u_int32_t sf_pad1; 685#endif 686 struct mbuf *sf_mbuf; 687}; 688 689/* 690 * RX buffer descriptor type 0, 64-bit addressing. 691 */ 692struct sf_rx_bufdesc_type1 { 693 u_int32_t sf_valid:1, 694 sf_end:1, 695 sf_addrlo:30; 696 u_int32_t sf_addrhi; 697#ifdef __i386__ 698 u_int32_t sf_pad; 699#endif 700 struct mbuf *sf_mbuf; 701}; 702 703/* 704 * RX completion descriptor, type 0 (short). 705 */ 706struct sf_rx_cmpdesc_type0 { 707 u_int32_t sf_len:16, 708 sf_endidx:11, 709 sf_status1:3, 710 sf_id:2; 711}; 712 713/* 714 * RX completion descriptor, type 1 (basic). Includes vlan ID 715 * if this is a vlan-addressed packet, plus extended status. 716 */ 717struct sf_rx_cmpdesc_type1 { 718 u_int32_t sf_len:16, 719 sf_endidx:11, 720 sf_status1:3, 721 sf_id:2; 722 u_int16_t sf_status2; 723 u_int16_t sf_vlanid; 724}; 725 726/* 727 * RX completion descriptor, type 2 (checksum). Includes partial TCP/IP 728 * checksum instead of vlan tag, plus extended status. 729 */ 730struct sf_rx_cmpdesc_type2 { 731 u_int32_t sf_len:16, 732 sf_endidx:11, 733 sf_status1:3, 734 sf_id:2; 735 u_int16_t sf_status2; 736 u_int16_t sf_cksum; 737}; 738 739/* 740 * RX completion descriptor type 3 (full). Includes timestamp, partial 741 * TCP/IP checksum, vlan tag plus priority, two extended status fields. 742 */ 743struct sf_rx_cmpdesc_type3 { 744 u_int32_t sf_len:16, 745 sf_endidx:11, 746 sf_status1:3, 747 sf_id:2; 748 u_int32_t sf_startidx:10, 749 sf_status3:6, 750 sf_status2:16; 751 u_int16_t sf_cksum; 752 u_int16_t sf_vlanid_prio; 753 u_int32_t sf_timestamp; 754}; 755 756#define SF_RXSTAT1_QUEUE 0x1 757#define SF_RXSTAT1_FIFOFULL 0x2 758#define SF_RXSTAT1_OK 0x4 759 760 /* 0=unknown,5=unsupported */ 761#define SF_RXSTAT2_FRAMETYPE 0x0007 /* 1=IPv4,2=IPv2,3=IPX,4=ICMP */ 762#define SF_RXSTAT2_UDP 0x0008 763#define SF_RXSTAT2_TCP 0x0010 764#define SF_RXSTAT2_FRAG 0x0020 765#define SF_RXSTAT2_PCSUM_OK 0x0040 /* partial checksum ok */ 766#define SF_RXSTAT2_CSUM_BAD 0x0080 /* TCP/IP checksum bad */ 767#define SF_RXSTAT2_CSUM_OK 0x0100 /* TCP/IP checksum ok */ 768#define SF_RXSTAT2_VLAN 0x0200 769#define SF_RXSTAT2_BADRXCODE 0x0400 770#define SF_RXSTAT2_DRIBBLE 0x0800 771#define SF_RXSTAT2_ISL_CRCERR 0x1000 772#define SF_RXSTAT2_CRCERR 0x2000 773#define SF_RXSTAT2_HASH 0x4000 774#define SF_RXSTAT2_PERFECT 0x8000 775 776#define SF_RXSTAT3_TRAILER 0x01 777#define SF_RXSTAT3_HEADER 0x02 778#define SF_RXSTAT3_CONTROL 0x04 779#define SF_RXSTAT3_PAUSE 0x08 780#define SF_RXSTAT3_ISL 0x10 781 782/* 783 * Transmit descriptor formats. 784 * Each transmit descriptor type allows for a skip field at the 785 * start of each structure. The size of the skip field can vary, 786 * however we always set it for 8 bytes, which is enough to hold 787 * a pointer (32 bits on x86, 64-bits on alpha) that we can use 788 * to hold the address of the head of the mbuf chain for the 789 * frame or fragment associated with the descriptor. This saves 790 * us from having to create a separate pointer array to hold 791 * the mbuf addresses. 792 */ 793#define SF_TX_BUFDESC_ID 0xB 794#define SF_MAXFRAGS 14 795#define SF_TX_MINSPACING 128 796#define SF_TX_DLIST_CNT 128 797#define SF_TX_DLIST_SIZE 16384 798#define SF_TX_SKIPLEN 1 799#define SF_TX_CLIST_CNT 1024 800 801struct sf_frag { 802 u_int32_t sf_addr; 803 u_int16_t sf_fraglen; 804 u_int16_t sf_pktlen; 805}; 806 807struct sf_frag_msdos { 808 u_int16_t sf_pktlen; 809 u_int16_t sf_fraglen; 810 u_int32_t sf_addr; 811}; 812 813/* 814 * TX frame descriptor type 0, 32-bit addressing. One descriptor can 815 * be used to map multiple packet fragments. We use this format since 816 * BSD networking fragments packet data across mbuf chains. Note that 817 * the number of fragments can be variable depending on how the descriptor 818 * spacing is specified in the TX descriptor queue control register. 819 * We always use a spacing of 128 bytes, and a skipfield length of 8 820 * bytes: this means 16 bytes for the descriptor, including the skipfield, 821 * with 121 bytes left for fragment maps. Each fragment requires 8 bytes, 822 * which allows for 14 fragments per descriptor. The total size of the 823 * transmit buffer queue is limited to 16384 bytes, so with a spacing of 824 * 128 bytes per descriptor, we have room for 128 descriptors in the queue. 825 */ 826struct sf_tx_bufdesc_type0 { 827#ifdef __i386__ 828 u_int32_t sf_pad; 829#endif 830 struct mbuf *sf_mbuf; 831 u_int32_t sf_rsvd0:24, 832 sf_crcen:1, 833 sf_caltcp:1, 834 sf_end:1, 835 sf_intr:1, 836 sf_id:4; 837 u_int8_t sf_fragcnt; 838 u_int8_t sf_rsvd2; 839 u_int16_t sf_rsvd1; 840 struct sf_frag sf_frags[14]; 841}; 842 843/* 844 * TX buffer descriptor type 1, 32-bit addressing. Each descriptor 845 * maps a single fragment. 846 */ 847struct sf_tx_bufdesc_type1 { 848#ifdef __i386__ 849 u_int32_t sf_pad; 850#endif 851 struct mbuf *sf_mbuf; 852 u_int32_t sf_fraglen:16, 853 sf_fragcnt:8, 854 sf_crcen:1, 855 sf_caltcp:1, 856 sf_end:1, 857 sf_intr:1, 858 sf_id:4; 859 u_int32_t sf_addr; 860}; 861 862/* 863 * TX buffer descriptor type 2, 64-bit addressing. Each descriptor 864 * maps a single fragment. 865 */ 866struct sf_tx_bufdesc_type2 { 867#ifdef __i386__ 868 u_int32_t sf_pad; 869#endif 870 struct mbuf *sf_mbuf; 871 u_int32_t sf_fraglen:16, 872 sf_fragcnt:8, 873 sf_crcen:1, 874 sf_caltcp:1, 875 sf_end:1, 876 sf_intr:1, 877 sf_id:4; 878 u_int32_t sf_addrlo; 879 u_int32_t sf_addrhi; 880}; 881 882/* TX buffer descriptor type 3 is not defined. */ 883 884/* 885 * TX frame descriptor type 4, 32-bit addressing. This is a special 886 * case of the type 0 descriptor, identical except that the fragment 887 * address and length fields are ordered differently. This is done 888 * to optimize copies in MS-DOS and OS/2 drivers. 889 */ 890struct sf_tx_bufdesc_type4 { 891#ifdef __i386__ 892 u_int32_t sf_pad; 893#endif 894 struct mbuf *sf_mbuf; 895 u_int32_t sf_rsvd0:24, 896 sf_crcen:1, 897 sf_caltcp:1, 898 sf_end:1, 899 sf_intr:1, 900 sf_id:4; 901 u_int8_t sf_fragcnt; 902 u_int8_t sf_rsvd2; 903 u_int16_t sf_rsvd1; 904 struct sf_frag_msdos sf_frags[14]; 905}; 906 907/* 908 * Transmit completion queue descriptor formats. 909 */ 910 911/* 912 * Transmit DMA completion descriptor, type 0. 913 */ 914#define SF_TXCMPTYPE_DMA 0x4 915struct sf_tx_cmpdesc_type0 { 916 u_int32_t sf_index:15, 917 sf_priority:1, 918 sf_timestamp:13, 919 sf_type:3; 920}; 921 922/* 923 * Transmit completion descriptor, type 1. 924 */ 925#define SF_TXCMPTYPE_TX 0x5 926struct sf_tx_cmpdesc_type1 { 927 u_int32_t sf_index:15, 928 sf_priority:1, 929 sf_txstat:13, 930 sf_type:3; 931}; 932 933#define SF_TXSTAT_CRCERR 0x0001 934#define SF_TXSTAT_LENCHECKERR 0x0002 935#define SF_TXSTAT_LENRANGEERR 0x0004 936#define SF_TXSTAT_TX_OK 0x0008 937#define SF_TXSTAT_TX_DEFERED 0x0010 938#define SF_TXSTAT_EXCESS_DEFER 0x0020 939#define SF_TXSTAT_EXCESS_COLL 0x0040 940#define SF_TXSTAT_LATE_COLL 0x0080 941#define SF_TXSTAT_TOOBIG 0x0100 942#define SF_TXSTAT_TX_UNDERRUN 0x0200 943#define SF_TXSTAT_CTLFRAME_OK 0x0400 944#define SF_TXSTAT_PAUSEFRAME_OK 0x0800 945#define SF_TXSTAT_PAUSED 0x1000 946 947/* Statistics counters. */ 948struct sf_stats { 949 u_int32_t sf_tx_frames; 950 u_int32_t sf_tx_single_colls; 951 u_int32_t sf_tx_multi_colls; 952 u_int32_t sf_tx_crcerrs; 953 u_int32_t sf_tx_bytes; 954 u_int32_t sf_tx_defered; 955 u_int32_t sf_tx_late_colls; 956 u_int32_t sf_tx_pause_frames; 957 u_int32_t sf_tx_control_frames; 958 u_int32_t sf_tx_excess_colls; 959 u_int32_t sf_tx_excess_defer; 960 u_int32_t sf_tx_mcast_frames; 961 u_int32_t sf_tx_bcast_frames; 962 u_int32_t sf_tx_frames_lost; 963 u_int32_t sf_rx_rx_frames; 964 u_int32_t sf_rx_crcerrs; 965 u_int32_t sf_rx_alignerrs; 966 u_int32_t sf_rx_bytes; 967 u_int32_t sf_rx_control_frames; 968 u_int32_t sf_rx_unsup_control_frames; 969 u_int32_t sf_rx_giants; 970 u_int32_t sf_rx_runts; 971 u_int32_t sf_rx_jabbererrs; 972 u_int32_t sf_rx_pkts_64; 973 u_int32_t sf_rx_pkts_65_127; 974 u_int32_t sf_rx_pkts_128_255; 975 u_int32_t sf_rx_pkts_256_511; 976 u_int32_t sf_rx_pkts_512_1023; 977 u_int32_t sf_rx_pkts_1024_1518; 978 u_int32_t sf_rx_frames_lost; 979 u_int16_t sf_tx_underruns; 980 u_int16_t sf_pad; 981}; 982 983/* 984 * register space access macros 985 */ 986#define CSR_WRITE_4(sc, reg, val) \ 987 bus_space_write_4(sc->sf_btag, sc->sf_bhandle, reg, val) 988 989#define CSR_READ_4(sc, reg) \ 990 bus_space_read_4(sc->sf_btag, sc->sf_bhandle, reg) 991 992#define CSR_READ_1(sc, reg) \ 993 bus_space_read_1(sc->sf_btag, sc->sf_bhandle, reg) 994 995 996struct sf_type { 997 u_int16_t sf_vid; 998 u_int16_t sf_did; 999 char *sf_name; 1000}; 1001 1002#define SF_INC(x, y) (x) = (x + 1) % y 1003 1004#define ETHER_ALIGN 2 1005 1006/* 1007 * Note: alignment is important here: each list must be aligned to 1008 * a 256-byte boundary. It turns out that each ring is some multiple 1009 * of 4K in length, so we can stack them all on top of each other 1010 * and just worry about aligning the whole mess. There's one transmit 1011 * buffer ring and two receive buffer rings: one RX ring is for small 1012 * packets and the other is for large packets. Each buffer ring also 1013 * has a companion completion queue. 1014 */ 1015struct sf_list_data { 1016 struct sf_tx_bufdesc_type0 sf_tx_dlist[SF_TX_DLIST_CNT]; 1017 struct sf_tx_cmpdesc_type1 sf_tx_clist[SF_TX_CLIST_CNT]; 1018 struct sf_rx_bufdesc_type0 sf_rx_dlist_big[SF_RX_DLIST_CNT]; 1019#ifdef notdef 1020 /* 1021 * Unfortunately, because the Starfire doesn't allow arbitrary 1022 * byte alignment, we have to copy packets in the RX handler in 1023 * order to align the payload correctly. This means that we 1024 * don't gain anything by having separate large and small descriptor 1025 * lists, so for now we don't bother with the small one. 1026 */ 1027 struct sf_rx_bufdesc_type0 sf_rx_dlist_small[SF_RX_DLIST_CNT]; 1028#endif 1029 struct sf_rx_cmpdesc_type3 sf_rx_clist[SF_RX_CLIST_CNT]; 1030}; 1031 1032struct sf_softc { 1033 struct arpcom arpcom; /* interface info */ 1034 bus_space_handle_t sf_bhandle; /* bus space handle */ 1035 bus_space_tag_t sf_btag; /* bus space tag */ 1036 void *sf_intrhand; /* interrupt handler cookie */ 1037 struct resource *sf_irq; /* irq resource descriptor */ 1038 struct resource *sf_res; /* mem/ioport resource */ 1039 struct sf_type *sf_info; /* Starfire adapter info */ 1040 device_t sf_miibus; 1041 u_int8_t sf_unit; /* interface number */ 1042 struct sf_list_data *sf_ldata; 1043 int sf_tx_cnt; 1044 u_int8_t sf_link; 1045 int sf_if_flags; 1046 struct callout_handle sf_stat_ch; 1047 struct mtx sf_mtx; 1048}; 1049 1050 1051#define SF_LOCK(_sc) mtx_lock(&(_sc)->sf_mtx) 1052#define SF_UNLOCK(_sc) mtx_unlock(&(_sc)->sf_mtx) 1053 1054#define SF_TIMEOUT 1000 1055 1056#ifdef __alpha__ 1057#undef vtophys 1058#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va) 1059#endif
| 354 355/* TX descriptor queue control registers */ 356#define SF_TXDQCTL_DESCTYPE 0x00000007 357#define SF_TXDQCTL_NODMACMP 0x00000008 358#define SF_TXDQCTL_MINSPACE 0x00000070 359#define SF_TXDQCTL_64BITADDR 0x00000080 360#define SF_TXDQCTL_BURSTLEN 0x00003F00 361#define SF_TXDQCTL_SKIPLEN 0x001F0000 362#define SF_TXDQCTL_HIPRIOTHRESH 0xFF000000 363 364#define SF_TXBUFDESC_TYPE0 0x00000000 365#define SF_TXBUFDESC_TYPE1 0x00000001 366#define SF_TXBUFDESC_TYPE2 0x00000002 367#define SF_TXBUFDESC_TYPE3 0x00000003 368#define SF_TXBUFDESC_TYPE4 0x00000004 369 370#define SF_TXMINSPACE_UNLIMIT 0x00000000 371#define SF_TXMINSPACE_32BYTES 0x00000010 372#define SF_TXMINSPACE_64BYTES 0x00000020 373#define SF_TXMINSPACE_128BYTES 0x00000030 374#define SF_TXMINSPACE_256BYTES 0x00000040 375 376#define SF_TXSKIPLEN_0BYTES 0x00000000 377#define SF_TXSKIPLEN_8BYTES 0x00010000 378#define SF_TXSKIPLEN_16BYTES 0x00020000 379#define SF_TXSKIPLEN_24BYTES 0x00030000 380#define SF_TXSKIPLEN_32BYTES 0x00040000 381 382/* TX frame control register */ 383#define SF_TXFRMCTL_TXTHRESH 0x000000FF 384#define SF_TXFRMCTL_CPLAFTERTX 0x00000100 385#define SF_TXFRMCRL_DEBUG 0x0000FE00 386#define SF_TXFRMCTL_STATUS 0x01FF0000 387#define SF_TXFRMCTL_MAC_TXIF 0xFE000000 388 389/* TX completion queue control register */ 390#define SF_TXCQ_THRESH 0x0000000F 391#define SF_TXCQ_COMMON 0x00000010 392#define SF_TXCQ_SIZE 0x00000020 393#define SF_TXCQ_WRITEENB 0x00000040 394#define SF_TXCQ_USE_64BIT 0x00000080 395#define SF_TXCQ_ADDR 0xFFFFFF00 396 397/* RX completion queue control register */ 398#define SF_RXCQ_THRESH 0x0000000F 399#define SF_RXCQ_TYPE 0x00000030 400#define SF_RXCQ_WRITEENB 0x00000040 401#define SF_RXCQ_USE_64BIT 0x00000080 402#define SF_RXCQ_ADDR 0xFFFFFF00 403 404#define SF_RXCQTYPE_0 0x00000000 405#define SF_RXCQTYPE_1 0x00000010 406#define SF_RXCQTYPE_2 0x00000020 407#define SF_RXCQTYPE_3 0x00000030 408 409/* TX descriptor queue producer index register */ 410#define SF_TXDQ_PRODIDX_LOPRIO 0x000007FF 411#define SF_TXDQ_PRODIDX_HIPRIO 0x07FF0000 412 413/* TX descriptor queue consumer index register */ 414#define SF_TXDQ_CONSIDX_LOPRIO 0x000007FF 415#define SF_TXDQ_CONSIDX_HIPRIO 0x07FF0000 416 417/* Completion queue consumer index register */ 418#define SF_CQ_CONSIDX_RXQ1 0x000003FF 419#define SF_CQ_CONSIDX_RXTHRMODE 0x00008000 420#define SF_CQ_CONSIDX_TXQ 0x03FF0000 421#define SF_CQ_CONSIDX_TXTHRMODE 0x80000000 422 423/* Completion queue producer index register */ 424#define SF_CQ_PRODIDX_RXQ1 0x000003FF 425#define SF_CQ_PRODIDX_TXQ 0x03FF0000 426 427/* RX completion queue 2 consumer/producer index register */ 428#define SF_CQ_RXQ2_CONSIDX 0x000003FF 429#define SF_CQ_RXQ2_RXTHRMODE 0x00008000 430#define SF_CQ_RXQ2_PRODIDX 0x03FF0000 431 432#define SF_CQ_RXTHRMODE_INT_ON 0x00008000 433#define SF_CQ_RXTHRMODE_INT_OFF 0x00000000 434#define SF_CQ_TXTHRMODE_INT_ON 0x80000000 435#define SF_CQ_TXTHRMODE_INT_OFF 0x00000000 436 437#define SF_IDX_LO(x) ((x) & 0x000007FF) 438#define SF_IDX_HI(x) (((x) >> 16) & 0x000007FF) 439 440/* RX DMA control register */ 441#define SF_RXDMA_BURSTSIZE 0x0000007F 442#define SF_RXDMA_FPTESTMODE 0x00000080 443#define SF_RXDMA_HIPRIOTHRESH 0x00000F00 444#define SF_RXDMA_RXEARLYTHRESH 0x0001F000 445#define SF_RXDMA_DMACRC 0x00040000 446#define SF_RXDMA_USEBKUPQUEUE 0x00080000 447#define SF_RXDMA_QUEUEMODE 0x00700000 448#define SF_RXDMA_RXCQ2_ON 0x00800000 449#define SF_RXDMA_CSUMMODE 0x03000000 450#define SF_RXDMA_DMAPAUSEPKTS 0x04000000 451#define SF_RXDMA_DMACTLPKTS 0x08000000 452#define SF_RXDMA_DMACRXERRPKTS 0x10000000 453#define SF_RXDMA_DMABADPKTS 0x20000000 454#define SF_RXDMA_DMARUNTS 0x40000000 455#define SF_RXDMA_REPORTBADPKTS 0x80000000 456 457#define SF_RXDQMODE_Q1ONLY 0x00100000 458#define SF_RXDQMODE_Q2_ON_FP 0x00200000 459#define SF_RXDQMODE_Q2_ON_SHORT 0x00300000 460#define SF_RXDQMODE_Q2_ON_PRIO 0x00400000 461#define SF_RXDQMODE_SPLITHDR 0x00500000 462 463#define SF_RXCSUMMODE_IGNORE 0x00000000 464#define SF_RXCSUMMODE_REJECT_BAD_TCP 0x01000000 465#define SF_RXCSUMMODE_REJECT_BAD_TCPUDP 0x02000000 466#define SF_RXCSUMMODE_RSVD 0x03000000 467 468/* RX descriptor queue control registers */ 469#define SF_RXDQCTL_MINDESCTHR 0x0000007F 470#define SF_RXDQCTL_Q1_WE 0x00000080 471#define SF_RXDQCTL_DESCSPACE 0x00000700 472#define SF_RXDQCTL_64BITDADDR 0x00000800 473#define SF_RXDQCTL_64BITBADDR 0x00001000 474#define SF_RXDQCTL_VARIABLE 0x00002000 475#define SF_RXDQCTL_ENTRIES 0x00004000 476#define SF_RXDQCTL_PREFETCH 0x00008000 477#define SF_RXDQCTL_BUFLEN 0xFFFF0000 478 479#define SF_DESCSPACE_4BYTES 0x00000000 480#define SF_DESCSPACE_8BYTES 0x00000100 481#define SF_DESCSPACE_16BYTES 0x00000200 482#define SF_DESCSPACE_32BYTES 0x00000300 483#define SF_DESCSPACE_64BYTES 0x00000400 484#define SF_DESCSPACE_128_BYTES 0x00000500 485 486/* RX buffer consumer/producer index registers */ 487#define SF_RXDQ_PRODIDX 0x000007FF 488#define SF_RXDQ_CONSIDX 0x07FF0000 489 490/* RX filter control register */ 491#define SF_RXFILT_PROMISC 0x00000001 492#define SF_RXFILT_ALLMULTI 0x00000002 493#define SF_RXFILT_BROAD 0x00000004 494#define SF_RXFILT_HASHPRIO 0x00000008 495#define SF_RXFILT_HASHMODE 0x00000030 496#define SF_RXFILT_PERFMODE 0x000000C0 497#define SF_RXFILT_VLANMODE 0x00000300 498#define SF_RXFILT_WAKEMODE 0x00000C00 499#define SF_RXFILT_MULTI_NOBROAD 0x00001000 500#define SF_RXFILT_MIN_VLANPRIO 0x0000E000 501#define SF_RXFILT_PEFECTPRIO 0xFFFF0000 502 503/* Hash filtering mode */ 504#define SF_HASHMODE_OFF 0x00000000 505#define SF_HASHMODE_WITHVLAN 0x00000010 506#define SF_HASHMODE_ANYVLAN 0x00000020 507#define SF_HASHMODE_ANY 0x00000030 508 509/* Perfect filtering mode */ 510#define SF_PERFMODE_OFF 0x00000000 511#define SF_PERFMODE_NORMAL 0x00000040 512#define SF_PERFMODE_INVERSE 0x00000080 513#define SF_PERFMODE_VLAN 0x000000C0 514 515/* VLAN mode */ 516#define SF_VLANMODE_OFF 0x00000000 517#define SF_VLANMODE_NOSTRIP 0x00000100 518#define SF_VLANMODE_STRIP 0x00000200 519#define SF_VLANMODE_RSVD 0x00000300 520 521/* Wakeup mode */ 522#define SF_WAKEMODE_OFF 0x00000000 523#define SF_WAKEMODE_FILTER 0x00000400 524#define SF_WAKEMODE_FP 0x00000800 525#define SF_WAKEMODE_HIPRIO 0x00000C00 526 527/* 528 * Extra PCI registers 0x0100 to 0x0FFF 529 */ 530#define SF_PCI_TARGSTAT 0x0100 531#define SF_PCI_MASTSTAT1 0x0104 532#define SF_PCI_MASTSTAT2 0x0108 533#define SF_PCI_DMAHOSTADDR_LO 0x010C 534#define SF_BAC_DMADIAG0 0x0110 535#define SF_BAC_DMADIAG1 0x0114 536#define SF_BAC_DMADIAG2 0x0118 537#define SF_BAC_DMADIAG3 0x011C 538#define SF_PAR0 0x0120 539#define SF_PAR1 0x0124 540#define SF_PCICB_FUNCEVENT 0x0130 541#define SF_PCICB_FUNCEVENT_MASK 0x0134 542#define SF_PCICB_FUNCSTATE 0x0138 543#define SF_PCICB_FUNCFORCE 0x013C 544 545/* 546 * Serial EEPROM registers 0x1000 to 0x1FFF 547 * Presumeably the EEPROM is mapped into this 8K window. 548 */ 549#define SF_EEADDR_BASE 0x1000 550#define SF_EEADDR_MAX 0x1FFF 551 552#define SF_EE_NODEADDR 14 553 554/* 555 * MII registers registers 0x2000 to 0x3FFF 556 * There are 32 sets of 32 registers, one set for each possible 557 * PHY address. Each 32 bit register is split into a 16-bit data 558 * port and a couple of status bits. 559 */ 560 561#define SF_MIIADDR_BASE 0x2000 562#define SF_MIIADDR_MAX 0x3FFF 563#define SF_MII_BLOCKS 32 564 565#define SF_MII_DATAVALID 0x80000000 566#define SF_MII_BUSY 0x40000000 567#define SF_MII_DATAPORT 0x0000FFFF 568 569#define SF_PHY_REG(phy, reg) \ 570 (SF_MIIADDR_BASE + (phy * SF_MII_BLOCKS * sizeof(u_int32_t)) + \ 571 (reg * sizeof(u_int32_t))) 572 573/* 574 * Ethernet extra registers 0x4000 to 0x4FFF 575 */ 576#define SF_TESTMODE 0x4000 577#define SF_RX_FRAMEPROC_CTL 0x4004 578#define SF_TX_FRAMEPROC_CTL 0x4008 579 580/* 581 * MAC registers 0x5000 to 0x5FFF 582 */ 583#define SF_MACCFG_1 0x5000 584#define SF_MACCFG_2 0x5004 585#define SF_BKTOBKIPG 0x5008 586#define SF_NONBKTOBKIPG 0x500C 587#define SF_COLRETRY 0x5010 588#define SF_MAXLEN 0x5014 589#define SF_TXNIBBLECNT 0x5018 590#define SF_TXBYTECNT 0x501C 591#define SF_RETXCNT 0x5020 592#define SF_RANDNUM 0x5024 593#define SF_RANDNUM_MASK 0x5028 594#define SF_TOTALTXCNT 0x5034 595#define SF_RXBYTECNT 0x5040 596#define SF_TXPAUSETIMER 0x5060 597#define SF_VLANTYPE 0x5064 598#define SF_MIISTATUS 0x5070 599 600#define SF_MACCFG1_HUGEFRAMES 0x00000001 601#define SF_MACCFG1_FULLDUPLEX 0x00000002 602#define SF_MACCFG1_AUTOPAD 0x00000004 603#define SF_MACCFG1_HDJAM 0x00000008 604#define SF_MACCFG1_DELAYCRC 0x00000010 605#define SF_MACCFG1_NOBACKOFF 0x00000020 606#define SF_MACCFG1_LENGTHCHECK 0x00000040 607#define SF_MACCFG1_PUREPREAMBLE 0x00000080 608#define SF_MACCFG1_PASSALLRX 0x00000100 609#define SF_MACCFG1_PREAM_DETCNT 0x00000200 610#define SF_MACCFG1_RX_FLOWENB 0x00000400 611#define SF_MACCFG1_TX_FLOWENB 0x00000800 612#define SF_MACCFG1_TESTMODE 0x00003000 613#define SF_MACCFG1_MIILOOPBK 0x00004000 614#define SF_MACCFG1_SOFTRESET 0x00008000 615 616/* 617 * There are the recommended IPG nibble counter settings 618 * specified in the Adaptec manual for full duplex and 619 * half duplex operation. 620 */ 621#define SF_IPGT_FDX 0x15 622#define SF_IPGT_HDX 0x11 623 624/* 625 * RX filter registers 0x6000 to 0x6FFF 626 */ 627#define SF_RXFILT_PERFECT_BASE 0x6000 628#define SF_RXFILT_PERFECT_MAX 0x60FF 629#define SF_RXFILT_PERFECT_SKIP 0x0010 630#define SF_RXFILT_PERFECT_CNT 0x0010 631 632#define SF_RXFILT_HASH_BASE 0x6100 633#define SF_RXFILT_HASH_MAX 0x62FF 634#define SF_RXFILT_HASH_SKIP 0x0010 635#define SF_RXFILT_HASH_CNT 0x001F 636#define SF_RXFILT_HASH_ADDROFF 0x0000 637#define SF_RXFILT_HASH_PRIOOFF 0x0004 638#define SF_RXFILT_HASH_VLANOFF 0x0008 639 640/* 641 * Statistics registers 0x7000 to 0x7FFF 642 */ 643#define SF_STATS_BASE 0x7000 644#define SF_STATS_END 0x7FFF 645 646/* 647 * TX frame processor instruction space 0x8000 to 0x9FFF 648 */ 649 650/* 651 * RX frame processor instruction space 0xA000 to 0xBFFF 652 */ 653 654/* 655 * Ethernet FIFO access space 0xC000 to 0xDFFF 656 */ 657 658/* 659 * Reserved 0xE000 to 0xFFFF 660 */ 661 662/* 663 * Descriptor data structures. 664 */ 665 666 667/* Receive descriptor formats. */ 668#define SF_RX_MINSPACING 8 669#define SF_RX_DLIST_CNT 256 670#define SF_RX_CLIST_CNT 1024 671#define SF_RX_HOSTADDR(x) (((x) >> 2) & 0x3FFFFFFF) 672 673/* 674 * RX buffer descriptor type 0, 32-bit addressing. Note that we 675 * program the RX buffer queue control register(s) to allow a 676 * descriptor spacing of 16 bytes, which leaves room after each 677 * descriptor to store a pointer to the mbuf for each buffer. 678 */ 679struct sf_rx_bufdesc_type0 { 680 u_int32_t sf_valid:1, 681 sf_end:1, 682 sf_addrlo:30; 683 u_int32_t sf_pad0; 684#ifdef __i386__ 685 u_int32_t sf_pad1; 686#endif 687 struct mbuf *sf_mbuf; 688}; 689 690/* 691 * RX buffer descriptor type 0, 64-bit addressing. 692 */ 693struct sf_rx_bufdesc_type1 { 694 u_int32_t sf_valid:1, 695 sf_end:1, 696 sf_addrlo:30; 697 u_int32_t sf_addrhi; 698#ifdef __i386__ 699 u_int32_t sf_pad; 700#endif 701 struct mbuf *sf_mbuf; 702}; 703 704/* 705 * RX completion descriptor, type 0 (short). 706 */ 707struct sf_rx_cmpdesc_type0 { 708 u_int32_t sf_len:16, 709 sf_endidx:11, 710 sf_status1:3, 711 sf_id:2; 712}; 713 714/* 715 * RX completion descriptor, type 1 (basic). Includes vlan ID 716 * if this is a vlan-addressed packet, plus extended status. 717 */ 718struct sf_rx_cmpdesc_type1 { 719 u_int32_t sf_len:16, 720 sf_endidx:11, 721 sf_status1:3, 722 sf_id:2; 723 u_int16_t sf_status2; 724 u_int16_t sf_vlanid; 725}; 726 727/* 728 * RX completion descriptor, type 2 (checksum). Includes partial TCP/IP 729 * checksum instead of vlan tag, plus extended status. 730 */ 731struct sf_rx_cmpdesc_type2 { 732 u_int32_t sf_len:16, 733 sf_endidx:11, 734 sf_status1:3, 735 sf_id:2; 736 u_int16_t sf_status2; 737 u_int16_t sf_cksum; 738}; 739 740/* 741 * RX completion descriptor type 3 (full). Includes timestamp, partial 742 * TCP/IP checksum, vlan tag plus priority, two extended status fields. 743 */ 744struct sf_rx_cmpdesc_type3 { 745 u_int32_t sf_len:16, 746 sf_endidx:11, 747 sf_status1:3, 748 sf_id:2; 749 u_int32_t sf_startidx:10, 750 sf_status3:6, 751 sf_status2:16; 752 u_int16_t sf_cksum; 753 u_int16_t sf_vlanid_prio; 754 u_int32_t sf_timestamp; 755}; 756 757#define SF_RXSTAT1_QUEUE 0x1 758#define SF_RXSTAT1_FIFOFULL 0x2 759#define SF_RXSTAT1_OK 0x4 760 761 /* 0=unknown,5=unsupported */ 762#define SF_RXSTAT2_FRAMETYPE 0x0007 /* 1=IPv4,2=IPv2,3=IPX,4=ICMP */ 763#define SF_RXSTAT2_UDP 0x0008 764#define SF_RXSTAT2_TCP 0x0010 765#define SF_RXSTAT2_FRAG 0x0020 766#define SF_RXSTAT2_PCSUM_OK 0x0040 /* partial checksum ok */ 767#define SF_RXSTAT2_CSUM_BAD 0x0080 /* TCP/IP checksum bad */ 768#define SF_RXSTAT2_CSUM_OK 0x0100 /* TCP/IP checksum ok */ 769#define SF_RXSTAT2_VLAN 0x0200 770#define SF_RXSTAT2_BADRXCODE 0x0400 771#define SF_RXSTAT2_DRIBBLE 0x0800 772#define SF_RXSTAT2_ISL_CRCERR 0x1000 773#define SF_RXSTAT2_CRCERR 0x2000 774#define SF_RXSTAT2_HASH 0x4000 775#define SF_RXSTAT2_PERFECT 0x8000 776 777#define SF_RXSTAT3_TRAILER 0x01 778#define SF_RXSTAT3_HEADER 0x02 779#define SF_RXSTAT3_CONTROL 0x04 780#define SF_RXSTAT3_PAUSE 0x08 781#define SF_RXSTAT3_ISL 0x10 782 783/* 784 * Transmit descriptor formats. 785 * Each transmit descriptor type allows for a skip field at the 786 * start of each structure. The size of the skip field can vary, 787 * however we always set it for 8 bytes, which is enough to hold 788 * a pointer (32 bits on x86, 64-bits on alpha) that we can use 789 * to hold the address of the head of the mbuf chain for the 790 * frame or fragment associated with the descriptor. This saves 791 * us from having to create a separate pointer array to hold 792 * the mbuf addresses. 793 */ 794#define SF_TX_BUFDESC_ID 0xB 795#define SF_MAXFRAGS 14 796#define SF_TX_MINSPACING 128 797#define SF_TX_DLIST_CNT 128 798#define SF_TX_DLIST_SIZE 16384 799#define SF_TX_SKIPLEN 1 800#define SF_TX_CLIST_CNT 1024 801 802struct sf_frag { 803 u_int32_t sf_addr; 804 u_int16_t sf_fraglen; 805 u_int16_t sf_pktlen; 806}; 807 808struct sf_frag_msdos { 809 u_int16_t sf_pktlen; 810 u_int16_t sf_fraglen; 811 u_int32_t sf_addr; 812}; 813 814/* 815 * TX frame descriptor type 0, 32-bit addressing. One descriptor can 816 * be used to map multiple packet fragments. We use this format since 817 * BSD networking fragments packet data across mbuf chains. Note that 818 * the number of fragments can be variable depending on how the descriptor 819 * spacing is specified in the TX descriptor queue control register. 820 * We always use a spacing of 128 bytes, and a skipfield length of 8 821 * bytes: this means 16 bytes for the descriptor, including the skipfield, 822 * with 121 bytes left for fragment maps. Each fragment requires 8 bytes, 823 * which allows for 14 fragments per descriptor. The total size of the 824 * transmit buffer queue is limited to 16384 bytes, so with a spacing of 825 * 128 bytes per descriptor, we have room for 128 descriptors in the queue. 826 */ 827struct sf_tx_bufdesc_type0 { 828#ifdef __i386__ 829 u_int32_t sf_pad; 830#endif 831 struct mbuf *sf_mbuf; 832 u_int32_t sf_rsvd0:24, 833 sf_crcen:1, 834 sf_caltcp:1, 835 sf_end:1, 836 sf_intr:1, 837 sf_id:4; 838 u_int8_t sf_fragcnt; 839 u_int8_t sf_rsvd2; 840 u_int16_t sf_rsvd1; 841 struct sf_frag sf_frags[14]; 842}; 843 844/* 845 * TX buffer descriptor type 1, 32-bit addressing. Each descriptor 846 * maps a single fragment. 847 */ 848struct sf_tx_bufdesc_type1 { 849#ifdef __i386__ 850 u_int32_t sf_pad; 851#endif 852 struct mbuf *sf_mbuf; 853 u_int32_t sf_fraglen:16, 854 sf_fragcnt:8, 855 sf_crcen:1, 856 sf_caltcp:1, 857 sf_end:1, 858 sf_intr:1, 859 sf_id:4; 860 u_int32_t sf_addr; 861}; 862 863/* 864 * TX buffer descriptor type 2, 64-bit addressing. Each descriptor 865 * maps a single fragment. 866 */ 867struct sf_tx_bufdesc_type2 { 868#ifdef __i386__ 869 u_int32_t sf_pad; 870#endif 871 struct mbuf *sf_mbuf; 872 u_int32_t sf_fraglen:16, 873 sf_fragcnt:8, 874 sf_crcen:1, 875 sf_caltcp:1, 876 sf_end:1, 877 sf_intr:1, 878 sf_id:4; 879 u_int32_t sf_addrlo; 880 u_int32_t sf_addrhi; 881}; 882 883/* TX buffer descriptor type 3 is not defined. */ 884 885/* 886 * TX frame descriptor type 4, 32-bit addressing. This is a special 887 * case of the type 0 descriptor, identical except that the fragment 888 * address and length fields are ordered differently. This is done 889 * to optimize copies in MS-DOS and OS/2 drivers. 890 */ 891struct sf_tx_bufdesc_type4 { 892#ifdef __i386__ 893 u_int32_t sf_pad; 894#endif 895 struct mbuf *sf_mbuf; 896 u_int32_t sf_rsvd0:24, 897 sf_crcen:1, 898 sf_caltcp:1, 899 sf_end:1, 900 sf_intr:1, 901 sf_id:4; 902 u_int8_t sf_fragcnt; 903 u_int8_t sf_rsvd2; 904 u_int16_t sf_rsvd1; 905 struct sf_frag_msdos sf_frags[14]; 906}; 907 908/* 909 * Transmit completion queue descriptor formats. 910 */ 911 912/* 913 * Transmit DMA completion descriptor, type 0. 914 */ 915#define SF_TXCMPTYPE_DMA 0x4 916struct sf_tx_cmpdesc_type0 { 917 u_int32_t sf_index:15, 918 sf_priority:1, 919 sf_timestamp:13, 920 sf_type:3; 921}; 922 923/* 924 * Transmit completion descriptor, type 1. 925 */ 926#define SF_TXCMPTYPE_TX 0x5 927struct sf_tx_cmpdesc_type1 { 928 u_int32_t sf_index:15, 929 sf_priority:1, 930 sf_txstat:13, 931 sf_type:3; 932}; 933 934#define SF_TXSTAT_CRCERR 0x0001 935#define SF_TXSTAT_LENCHECKERR 0x0002 936#define SF_TXSTAT_LENRANGEERR 0x0004 937#define SF_TXSTAT_TX_OK 0x0008 938#define SF_TXSTAT_TX_DEFERED 0x0010 939#define SF_TXSTAT_EXCESS_DEFER 0x0020 940#define SF_TXSTAT_EXCESS_COLL 0x0040 941#define SF_TXSTAT_LATE_COLL 0x0080 942#define SF_TXSTAT_TOOBIG 0x0100 943#define SF_TXSTAT_TX_UNDERRUN 0x0200 944#define SF_TXSTAT_CTLFRAME_OK 0x0400 945#define SF_TXSTAT_PAUSEFRAME_OK 0x0800 946#define SF_TXSTAT_PAUSED 0x1000 947 948/* Statistics counters. */ 949struct sf_stats { 950 u_int32_t sf_tx_frames; 951 u_int32_t sf_tx_single_colls; 952 u_int32_t sf_tx_multi_colls; 953 u_int32_t sf_tx_crcerrs; 954 u_int32_t sf_tx_bytes; 955 u_int32_t sf_tx_defered; 956 u_int32_t sf_tx_late_colls; 957 u_int32_t sf_tx_pause_frames; 958 u_int32_t sf_tx_control_frames; 959 u_int32_t sf_tx_excess_colls; 960 u_int32_t sf_tx_excess_defer; 961 u_int32_t sf_tx_mcast_frames; 962 u_int32_t sf_tx_bcast_frames; 963 u_int32_t sf_tx_frames_lost; 964 u_int32_t sf_rx_rx_frames; 965 u_int32_t sf_rx_crcerrs; 966 u_int32_t sf_rx_alignerrs; 967 u_int32_t sf_rx_bytes; 968 u_int32_t sf_rx_control_frames; 969 u_int32_t sf_rx_unsup_control_frames; 970 u_int32_t sf_rx_giants; 971 u_int32_t sf_rx_runts; 972 u_int32_t sf_rx_jabbererrs; 973 u_int32_t sf_rx_pkts_64; 974 u_int32_t sf_rx_pkts_65_127; 975 u_int32_t sf_rx_pkts_128_255; 976 u_int32_t sf_rx_pkts_256_511; 977 u_int32_t sf_rx_pkts_512_1023; 978 u_int32_t sf_rx_pkts_1024_1518; 979 u_int32_t sf_rx_frames_lost; 980 u_int16_t sf_tx_underruns; 981 u_int16_t sf_pad; 982}; 983 984/* 985 * register space access macros 986 */ 987#define CSR_WRITE_4(sc, reg, val) \ 988 bus_space_write_4(sc->sf_btag, sc->sf_bhandle, reg, val) 989 990#define CSR_READ_4(sc, reg) \ 991 bus_space_read_4(sc->sf_btag, sc->sf_bhandle, reg) 992 993#define CSR_READ_1(sc, reg) \ 994 bus_space_read_1(sc->sf_btag, sc->sf_bhandle, reg) 995 996 997struct sf_type { 998 u_int16_t sf_vid; 999 u_int16_t sf_did; 1000 char *sf_name; 1001}; 1002 1003#define SF_INC(x, y) (x) = (x + 1) % y 1004 1005#define ETHER_ALIGN 2 1006 1007/* 1008 * Note: alignment is important here: each list must be aligned to 1009 * a 256-byte boundary. It turns out that each ring is some multiple 1010 * of 4K in length, so we can stack them all on top of each other 1011 * and just worry about aligning the whole mess. There's one transmit 1012 * buffer ring and two receive buffer rings: one RX ring is for small 1013 * packets and the other is for large packets. Each buffer ring also 1014 * has a companion completion queue. 1015 */ 1016struct sf_list_data { 1017 struct sf_tx_bufdesc_type0 sf_tx_dlist[SF_TX_DLIST_CNT]; 1018 struct sf_tx_cmpdesc_type1 sf_tx_clist[SF_TX_CLIST_CNT]; 1019 struct sf_rx_bufdesc_type0 sf_rx_dlist_big[SF_RX_DLIST_CNT]; 1020#ifdef notdef 1021 /* 1022 * Unfortunately, because the Starfire doesn't allow arbitrary 1023 * byte alignment, we have to copy packets in the RX handler in 1024 * order to align the payload correctly. This means that we 1025 * don't gain anything by having separate large and small descriptor 1026 * lists, so for now we don't bother with the small one. 1027 */ 1028 struct sf_rx_bufdesc_type0 sf_rx_dlist_small[SF_RX_DLIST_CNT]; 1029#endif 1030 struct sf_rx_cmpdesc_type3 sf_rx_clist[SF_RX_CLIST_CNT]; 1031}; 1032 1033struct sf_softc { 1034 struct arpcom arpcom; /* interface info */ 1035 bus_space_handle_t sf_bhandle; /* bus space handle */ 1036 bus_space_tag_t sf_btag; /* bus space tag */ 1037 void *sf_intrhand; /* interrupt handler cookie */ 1038 struct resource *sf_irq; /* irq resource descriptor */ 1039 struct resource *sf_res; /* mem/ioport resource */ 1040 struct sf_type *sf_info; /* Starfire adapter info */ 1041 device_t sf_miibus; 1042 u_int8_t sf_unit; /* interface number */ 1043 struct sf_list_data *sf_ldata; 1044 int sf_tx_cnt; 1045 u_int8_t sf_link; 1046 int sf_if_flags; 1047 struct callout_handle sf_stat_ch; 1048 struct mtx sf_mtx; 1049}; 1050 1051 1052#define SF_LOCK(_sc) mtx_lock(&(_sc)->sf_mtx) 1053#define SF_UNLOCK(_sc) mtx_unlock(&(_sc)->sf_mtx) 1054 1055#define SF_TIMEOUT 1000 1056 1057#ifdef __alpha__ 1058#undef vtophys 1059#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va) 1060#endif
|