1*438b5f69SJason King /* 2*438b5f69SJason King * Copyright (c) 2011 Jason King. 3*438b5f69SJason King * Copyright (c) 2000 Berkeley Software Design, Inc. 4*438b5f69SJason King * Copyright (c) 1997, 1998, 1999, 2000 5*438b5f69SJason King * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 6*438b5f69SJason King * 7*438b5f69SJason King * Redistribution and use in source and binary forms, with or without 8*438b5f69SJason King * modification, are permitted provided that the following conditions 9*438b5f69SJason King * are met: 10*438b5f69SJason King * 1. Redistributions of source code must retain the above copyright 11*438b5f69SJason King * notice, this list of conditions and the following disclaimer. 12*438b5f69SJason King * 2. Redistributions in binary form must reproduce the above copyright 13*438b5f69SJason King * notice, this list of conditions and the following disclaimer in the 14*438b5f69SJason King * documentation and/or other materials provided with the distribution. 15*438b5f69SJason King * 3. All advertising materials mentioning features or use of this software 16*438b5f69SJason King * must display the following acknowledgement: 17*438b5f69SJason King * This product includes software developed by Bill Paul. 18*438b5f69SJason King * 4. Neither the name of the author nor the names of any co-contributors 19*438b5f69SJason King * may be used to endorse or promote products derived from this software 20*438b5f69SJason King * without specific prior written permission. 21*438b5f69SJason King * 22*438b5f69SJason King * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 23*438b5f69SJason King * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*438b5f69SJason King * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*438b5f69SJason King * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 26*438b5f69SJason King * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27*438b5f69SJason King * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28*438b5f69SJason King * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29*438b5f69SJason King * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30*438b5f69SJason King * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31*438b5f69SJason King * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32*438b5f69SJason King * THE POSSIBILITY OF SUCH DAMAGE. 33*438b5f69SJason King * 34*438b5f69SJason King */ 35*438b5f69SJason King #ifndef _PCNIMPL_H 36*438b5f69SJason King #define _PCNIMPL_H 37*438b5f69SJason King 38*438b5f69SJason King #ifdef __cplusplus 39*438b5f69SJason King extern "C" { 40*438b5f69SJason King #endif 41*438b5f69SJason King 42*438b5f69SJason King #ifdef _KERNEL 43*438b5f69SJason King 44*438b5f69SJason King #define PCN_VENDORID 0x1022 45*438b5f69SJason King #define PCN_DEVICEID_PCNET 0x2000 46*438b5f69SJason King #define PCN_DEVICEID_HOME 0x2001 47*438b5f69SJason King 48*438b5f69SJason King typedef struct pcn_type { 49*438b5f69SJason King uint16_t pcn_vid; 50*438b5f69SJason King uint16_t pcn_did; 51*438b5f69SJason King char *pcn_name; /* ddi_set_prop takes char * */ 52*438b5f69SJason King } pcn_type_t; 53*438b5f69SJason King 54*438b5f69SJason King #define PCN_TXRECLAIM 8 55*438b5f69SJason King #define PCN_HEADROOM 34 56*438b5f69SJason King #define PCN_TXRESCHED 120 57*438b5f69SJason King 58*438b5f69SJason King #define PCN_RXSTAT_BAM 0x0008 /* broadcast address match */ 59*438b5f69SJason King #define PCN_RXSTAT_LAFM 0x0010 /* logical address filter match */ 60*438b5f69SJason King #define PCN_RXSTAT_PAM 0x0020 /* physical address match */ 61*438b5f69SJason King #define PCN_RXSTAT_BPE 0x0080 /* bus parity error */ 62*438b5f69SJason King #define PCN_RXSTAT_ENP 0x0100 /* end of packet */ 63*438b5f69SJason King #define PCN_RXSTAT_STP 0x0200 /* start of packet */ 64*438b5f69SJason King #define PCN_RXSTAT_BUFF 0x0400 /* buffer error */ 65*438b5f69SJason King #define PCN_RXSTAT_CRC 0x0800 /* CRC error */ 66*438b5f69SJason King #define PCN_RXSTAT_OFLOW 0x1000 /* rx overrun */ 67*438b5f69SJason King #define PCN_RXSTAT_FRAM 0x2000 /* framing error */ 68*438b5f69SJason King #define PCN_RXSTAT_ERR 0x4000 /* error summary */ 69*438b5f69SJason King #define PCN_RXSTAT_OWN 0x8000 70*438b5f69SJason King #define PCN_RXSTAT_STR \ 71*438b5f69SJason King "\020" \ 72*438b5f69SJason King "\004BAM" \ 73*438b5f69SJason King "\005LAFM" \ 74*438b5f69SJason King "\006PAM" \ 75*438b5f69SJason King "\010BPE" \ 76*438b5f69SJason King "\011ENP" \ 77*438b5f69SJason King "\012STP" \ 78*438b5f69SJason King "\013BUFF" \ 79*438b5f69SJason King "\014CRC" \ 80*438b5f69SJason King "\015OFLOW" \ 81*438b5f69SJason King "\016FRAM" \ 82*438b5f69SJason King "\017ERR" \ 83*438b5f69SJason King "\020OWN" 84*438b5f69SJason King 85*438b5f69SJason King #define PCN_RXLEN_MBO 0xF000 86*438b5f69SJason King #define PCN_RXLEN_BUFSZ 0x0FFF 87*438b5f69SJason King 88*438b5f69SJason King typedef struct pcn_rx_desc { 89*438b5f69SJason King uint16_t pcn_rxlen; 90*438b5f69SJason King uint16_t pcn_rsvd0; 91*438b5f69SJason King uint16_t pcn_bufsz; 92*438b5f69SJason King uint16_t pcn_rxstat; 93*438b5f69SJason King uint32_t pcn_rbaddr; 94*438b5f69SJason King uint32_t pcn_uspace; 95*438b5f69SJason King } pcn_rx_desc_t; 96*438b5f69SJason King 97*438b5f69SJason King typedef struct pcn_tx_desc { 98*438b5f69SJason King uint32_t pcn_txstat; 99*438b5f69SJason King uint32_t pcn_txctl; 100*438b5f69SJason King uint32_t pcn_tbaddr; 101*438b5f69SJason King uint32_t pcn_uspace; 102*438b5f69SJason King } pcn_tx_desc_t; 103*438b5f69SJason King 104*438b5f69SJason King #define PCN_TXCTL_OWN 0x80000000 105*438b5f69SJason King #define PCN_TXCTL_ERR 0x40000000 /* error summary */ 106*438b5f69SJason King #define PCN_TXCTL_ADD_FCS 0x20000000 /* add FCS to pkt */ 107*438b5f69SJason King #define PCN_TXCTL_MORE_LTINT 0x10000000 108*438b5f69SJason King #define PCN_TXCTL_ONE 0x08000000 109*438b5f69SJason King #define PCN_TXCTL_DEF 0x04000000 110*438b5f69SJason King #define PCN_TXCTL_STP 0x02000000 111*438b5f69SJason King #define PCN_TXCTL_ENP 0x01000000 112*438b5f69SJason King #define PCN_TXCTL_BPE 0x00800000 113*438b5f69SJason King #define PCN_TXCTL_MBO 0x0000F000 114*438b5f69SJason King #define PCN_TXCTL_BUFSZ 0x00000FFF 115*438b5f69SJason King #define PCN_TXCTL_STR \ 116*438b5f69SJason King "\020" \ 117*438b5f69SJason King "\040OWN" \ 118*438b5f69SJason King "\037ERR" \ 119*438b5f69SJason King "\036ADD_FCS" \ 120*438b5f69SJason King "\035MORE_LTINT" \ 121*438b5f69SJason King "\034ONE" \ 122*438b5f69SJason King "\033DEF" \ 123*438b5f69SJason King "\032STP" \ 124*438b5f69SJason King "\031ENP" \ 125*438b5f69SJason King "\030BPE" 126*438b5f69SJason King 127*438b5f69SJason King typedef struct pcn_buf { 128*438b5f69SJason King caddr_t pb_buf; 129*438b5f69SJason King ddi_dma_handle_t pb_dmah; 130*438b5f69SJason King ddi_acc_handle_t pb_acch; 131*438b5f69SJason King uint32_t pb_paddr; 132*438b5f69SJason King } pcn_buf_t; 133*438b5f69SJason King 134*438b5f69SJason King /* Constants, do not change */ 135*438b5f69SJason King #define PCN_BUFSZ (1664) 136*438b5f69SJason King #define PCN_MCHASH (64) 137*438b5f69SJason King 138*438b5f69SJason King /* Number of descriptor entries */ 139*438b5f69SJason King #define PCN_RXRING 64 140*438b5f69SJason King #define PCN_TXRING 256 141*438b5f69SJason King 142*438b5f69SJason King typedef struct pcn { 143*438b5f69SJason King dev_info_t *pcn_dip; 144*438b5f69SJason King mac_handle_t pcn_mh; 145*438b5f69SJason King mii_handle_t pcn_mii; 146*438b5f69SJason King uint16_t pcn_cachesize; 147*438b5f69SJason King int pcn_flags; 148*438b5f69SJason King int pcn_instance; 149*438b5f69SJason King kmutex_t pcn_xmtlock; 150*438b5f69SJason King kmutex_t pcn_intrlock; 151*438b5f69SJason King kmutex_t pcn_reglock; 152*438b5f69SJason King ddi_iblock_cookie_t pcn_icookie; 153*438b5f69SJason King uint_t pcn_int_pri; 154*438b5f69SJason King int pcn_type; 155*438b5f69SJason King int8_t pcn_extphyaddr; 156*438b5f69SJason King 157*438b5f69SJason King /* 158*438b5f69SJason King * Register and DMA access 159*438b5f69SJason King */ 160*438b5f69SJason King uintptr_t pcn_regs; 161*438b5f69SJason King ddi_acc_handle_t pcn_regshandle; 162*438b5f69SJason King 163*438b5f69SJason King /* 164*438b5f69SJason King * Receive descriptors. 165*438b5f69SJason King */ 166*438b5f69SJason King int pcn_rxhead; 167*438b5f69SJason King pcn_rx_desc_t *pcn_rxdescp; 168*438b5f69SJason King ddi_dma_handle_t pcn_rxdesc_dmah; 169*438b5f69SJason King ddi_acc_handle_t pcn_rxdesc_acch; 170*438b5f69SJason King uint32_t pcn_rxdesc_paddr; 171*438b5f69SJason King pcn_buf_t **pcn_rxbufs; 172*438b5f69SJason King 173*438b5f69SJason King /* 174*438b5f69SJason King * Transmit descriptors. 175*438b5f69SJason King */ 176*438b5f69SJason King int pcn_txreclaim; 177*438b5f69SJason King int pcn_txsend; 178*438b5f69SJason King int pcn_txavail; 179*438b5f69SJason King pcn_tx_desc_t *pcn_txdescp; 180*438b5f69SJason King ddi_dma_handle_t pcn_txdesc_dmah; 181*438b5f69SJason King ddi_acc_handle_t pcn_txdesc_acch; 182*438b5f69SJason King uint32_t pcn_txdesc_paddr; 183*438b5f69SJason King pcn_buf_t **pcn_txbufs; 184*438b5f69SJason King hrtime_t pcn_txstall_time; 185*438b5f69SJason King boolean_t pcn_wantw; 186*438b5f69SJason King 187*438b5f69SJason King /* 188*438b5f69SJason King * Address management. 189*438b5f69SJason King */ 190*438b5f69SJason King uchar_t pcn_addr[ETHERADDRL]; 191*438b5f69SJason King boolean_t pcn_promisc; 192*438b5f69SJason King uint16_t pcn_mccount[PCN_MCHASH]; 193*438b5f69SJason King uint16_t pcn_mctab[PCN_MCHASH / 16]; 194*438b5f69SJason King 195*438b5f69SJason King /* 196*438b5f69SJason King * stats 197*438b5f69SJason King */ 198*438b5f69SJason King uint64_t pcn_ipackets; 199*438b5f69SJason King uint64_t pcn_opackets; 200*438b5f69SJason King uint64_t pcn_rbytes; 201*438b5f69SJason King uint64_t pcn_obytes; 202*438b5f69SJason King uint64_t pcn_brdcstxmt; 203*438b5f69SJason King uint64_t pcn_multixmt; 204*438b5f69SJason King uint64_t pcn_brdcstrcv; 205*438b5f69SJason King uint64_t pcn_multircv; 206*438b5f69SJason King uint64_t pcn_norcvbuf; 207*438b5f69SJason King uint64_t pcn_errrcv; 208*438b5f69SJason King uint64_t pcn_errxmt; 209*438b5f69SJason King uint64_t pcn_missed; 210*438b5f69SJason King uint64_t pcn_underflow; 211*438b5f69SJason King uint64_t pcn_overflow; 212*438b5f69SJason King uint64_t pcn_align_errors; 213*438b5f69SJason King uint64_t pcn_fcs_errors; 214*438b5f69SJason King uint64_t pcn_carrier_errors; 215*438b5f69SJason King uint64_t pcn_collisions; 216*438b5f69SJason King uint64_t pcn_ex_collisions; 217*438b5f69SJason King uint64_t pcn_tx_late_collisions; 218*438b5f69SJason King uint64_t pcn_defer_xmts; 219*438b5f69SJason King uint64_t pcn_first_collisions; 220*438b5f69SJason King uint64_t pcn_multi_collisions; 221*438b5f69SJason King uint64_t pcn_sqe_errors; 222*438b5f69SJason King uint64_t pcn_macxmt_errors; 223*438b5f69SJason King uint64_t pcn_macrcv_errors; 224*438b5f69SJason King uint64_t pcn_toolong_errors; 225*438b5f69SJason King uint64_t pcn_runt; 226*438b5f69SJason King uint64_t pcn_jabber; 227*438b5f69SJason King } pcn_t; 228*438b5f69SJason King 229*438b5f69SJason King /* Flags */ 230*438b5f69SJason King #define PCN_RUNNING (1L << 0) 231*438b5f69SJason King #define PCN_SUSPENDED (1L << 1) 232*438b5f69SJason King #define PCN_INTR_ENABLED (1L << 2) 233*438b5f69SJason King #define PCN_FLAGSTR \ 234*438b5f69SJason King "\020" \ 235*438b5f69SJason King "\001RUNNING" \ 236*438b5f69SJason King "\002SUSPENDED" \ 237*438b5f69SJason King "\003INTR_ENABLED" 238*438b5f69SJason King #define IS_RUNNING(p) ((p)->pcn_flags & PCN_RUNNING) 239*438b5f69SJason King #define IS_SUSPENDED(p) ((p)->pcn_flags & PCN_SUSPENDED) 240*438b5f69SJason King 241*438b5f69SJason King #define SYNCTXDESC(pcnp, index, who) \ 242*438b5f69SJason King (void) ddi_dma_sync(pcnp->pcn_txdesc_dmah, \ 243*438b5f69SJason King (index * sizeof (pcn_tx_desc_t)), sizeof (pcn_tx_desc_t), who) 244*438b5f69SJason King 245*438b5f69SJason King #define SYNCRXDESC(pcnp, index, who) \ 246*438b5f69SJason King (void) ddi_dma_sync(pcnp->pcn_rxdesc_dmah, \ 247*438b5f69SJason King (index * sizeof (pcn_rx_desc_t)), sizeof (pcn_rx_desc_t), who) 248*438b5f69SJason King 249*438b5f69SJason King #define SYNCBUF(pb, len, who) \ 250*438b5f69SJason King (void) ddi_dma_sync(pb->pb_dmah, 0, len, who) 251*438b5f69SJason King 252*438b5f69SJason King #endif /* _KERNEL */ 253*438b5f69SJason King 254*438b5f69SJason King #ifdef __cplusplus 255*438b5f69SJason King } 256*438b5f69SJason King #endif 257*438b5f69SJason King 258*438b5f69SJason King #endif /* _PCNIMPL_H */ 259