15748Sduboff /* 25748Sduboff * sfe_util.h: header to support the gem layer used by Masa Murayama 35748Sduboff * 47116Sduboff * Copyright (c) 2002-2008 Masayuki Murayama. All rights reserved. 55748Sduboff * 65748Sduboff * Redistribution and use in source and binary forms, with or without 75748Sduboff * modification, are permitted provided that the following conditions are met: 85748Sduboff * 95748Sduboff * 1. Redistributions of source code must retain the above copyright notice, 105748Sduboff * this list of conditions and the following disclaimer. 115748Sduboff * 125748Sduboff * 2. Redistributions in binary form must reproduce the above copyright notice, 135748Sduboff * this list of conditions and the following disclaimer in the documentation 145748Sduboff * and/or other materials provided with the distribution. 155748Sduboff * 165748Sduboff * 3. Neither the name of the author nor the names of its contributors may be 175748Sduboff * used to endorse or promote products derived from this software without 185748Sduboff * specific prior written permission. 195748Sduboff * 205748Sduboff * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 215748Sduboff * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 225748Sduboff * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 235748Sduboff * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 245748Sduboff * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 255748Sduboff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 265748Sduboff * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 275748Sduboff * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 285748Sduboff * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 295748Sduboff * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 305748Sduboff * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 315748Sduboff * DAMAGE. 325748Sduboff */ 337116Sduboff 34*8275SEric Cheng /* 35*8275SEric Cheng * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 36*8275SEric Cheng * Use is subject to license terms. 37*8275SEric Cheng */ 38*8275SEric Cheng 395748Sduboff #ifndef _SFE_UTIL_H_ 405748Sduboff #define _SFE_UTIL_H_ 41*8275SEric Cheng #include <sys/mac_provider.h> 425748Sduboff #include <sys/mac_ether.h> 435748Sduboff 445748Sduboff /* 455748Sduboff * Useful macros and typedefs 465748Sduboff */ 475748Sduboff 485748Sduboff #define GEM_NAME_LEN 32 495748Sduboff 505748Sduboff #define GEM_TX_TIMEOUT (drv_usectohz(5*1000000)) 515748Sduboff #define GEM_TX_TIMEOUT_INTERVAL (drv_usectohz(1*1000000)) 525748Sduboff #define GEM_LINK_WATCH_INTERVAL (drv_usectohz(1*1000000)) /* 1 sec */ 535748Sduboff 545748Sduboff /* general return code */ 555748Sduboff #define GEM_SUCCESS 0 565748Sduboff #define GEM_FAILURE (-1) 575748Sduboff 585748Sduboff /* return code of gem_tx_done */ 595748Sduboff #define INTR_RESTART_TX 0x80000000 605748Sduboff 617116Sduboff typedef int32_t seqnum_t; 625748Sduboff 635748Sduboff /* 645748Sduboff * I/O instructions 655748Sduboff */ 665748Sduboff #define OUTB(dp, p, v) \ 675748Sduboff ddi_put8((dp)->regs_handle, \ 685748Sduboff (void *)((caddr_t)((dp)->base_addr) + (p)), v) 695748Sduboff #define OUTW(dp, p, v) \ 705748Sduboff ddi_put16((dp)->regs_handle, \ 715748Sduboff (void *)((caddr_t)((dp)->base_addr) + (p)), v) 727893SAlan.Duboff@Sun.COM #define OUTL(dp, p, v) \ 735748Sduboff ddi_put32((dp)->regs_handle, \ 747893SAlan.Duboff@Sun.COM (void *)((caddr_t)((dp)->base_addr) + (p)), v) 757893SAlan.Duboff@Sun.COM #define OUTLINL(dp, p, v) \ 767893SAlan.Duboff@Sun.COM ddi_put32((dp)->regs_handle, \ 777893SAlan.Duboff@Sun.COM (void *)((caddr_t)((dp)->base_addr) + (p)), v); \ 787893SAlan.Duboff@Sun.COM (void) INL((dp), (p)) 795748Sduboff #define INB(dp, p) \ 805748Sduboff ddi_get8((dp)->regs_handle, \ 815748Sduboff (void *)(((caddr_t)(dp)->base_addr) + (p))) 825748Sduboff #define INW(dp, p) \ 835748Sduboff ddi_get16((dp)->regs_handle, \ 845748Sduboff (void *)(((caddr_t)(dp)->base_addr) + (p))) 855748Sduboff #define INL(dp, p) \ 865748Sduboff ddi_get32((dp)->regs_handle, \ 875748Sduboff (void *)(((caddr_t)(dp)->base_addr) + (p))) 885748Sduboff 895748Sduboff struct gem_stats { 905748Sduboff uint32_t intr; 915748Sduboff 925748Sduboff uint32_t crc; 935748Sduboff uint32_t errrcv; 945748Sduboff uint32_t overflow; 955748Sduboff uint32_t frame; 965748Sduboff uint32_t missed; 975748Sduboff uint32_t runt; 985748Sduboff uint32_t frame_too_long; 995748Sduboff uint32_t norcvbuf; 1005748Sduboff uint32_t sqe; 1015748Sduboff 1025748Sduboff uint32_t collisions; 1035748Sduboff uint32_t first_coll; 1045748Sduboff uint32_t multi_coll; 1055748Sduboff uint32_t excoll; 1065748Sduboff uint32_t xmit_internal_err; 1075748Sduboff uint32_t nocarrier; 1085748Sduboff uint32_t defer; 1095748Sduboff uint32_t errxmt; 1105748Sduboff uint32_t underflow; 1115748Sduboff uint32_t xmtlatecoll; 1125748Sduboff uint32_t noxmtbuf; 1135748Sduboff uint32_t jabber; 1145748Sduboff 1155748Sduboff uint64_t rbytes; 1165748Sduboff uint64_t obytes; 1175748Sduboff uint64_t rpackets; 1185748Sduboff uint64_t opackets; 1195748Sduboff uint32_t rbcast; 1205748Sduboff uint32_t obcast; 1215748Sduboff uint32_t rmcast; 1225748Sduboff uint32_t omcast; 1235748Sduboff uint32_t rcv_internal_err; 1245748Sduboff }; 1255748Sduboff #define GEM_MAXTXSEGS 4 1265748Sduboff #define GEM_MAXRXSEGS 1 1275748Sduboff 1285748Sduboff #define GEM_MAXTXFRAGS 8 1295748Sduboff #define GEM_MAXRXFRAGS 4 1305748Sduboff /* TX buffer management */ 1315748Sduboff struct txbuf { 1325748Sduboff struct txbuf *txb_next; 1335748Sduboff 1345748Sduboff /* pointer to original mblk */ 1355748Sduboff mblk_t *txb_mp; 1365748Sduboff 1375748Sduboff /* dma mapping for current packet */ 1385748Sduboff ddi_dma_cookie_t txb_dmacookie[GEM_MAXTXFRAGS]; 1395748Sduboff uint_t txb_nfrags; 1405748Sduboff 1415748Sduboff /* bounce buffer management */ 1425748Sduboff ddi_dma_handle_t txb_bdh; 1435748Sduboff ddi_acc_handle_t txb_bah; 1445748Sduboff caddr_t txb_buf; /* vaddr of bounce buffer */ 1455748Sduboff uint64_t txb_buf_dma; /* paddr of bounce buffer */ 1465748Sduboff 1475748Sduboff /* timeout management */ 1485748Sduboff clock_t txb_stime; 1495748Sduboff 1505748Sduboff /* Hardware descriptor info */ 1515748Sduboff seqnum_t txb_desc; 1525748Sduboff int txb_ndescs; 1535748Sduboff uint64_t txb_flag; 1545748Sduboff }; 1555748Sduboff 1565748Sduboff 1575748Sduboff /* RX buffer management */ 1585748Sduboff struct rxbuf { 1597116Sduboff /* Hardware independent section */ 1605748Sduboff struct rxbuf *rxb_next; 1615748Sduboff struct gem_dev *rxb_devp; 1625748Sduboff 1635748Sduboff /* dma mapping management */ 1645748Sduboff ddi_dma_handle_t rxb_dh; 1655748Sduboff caddr_t rxb_buf; 1665748Sduboff size_t rxb_buf_len; 1675748Sduboff ddi_dma_cookie_t rxb_dmacookie[GEM_MAXRXFRAGS]; 1685748Sduboff uint_t rxb_nfrags; 1695748Sduboff 1705748Sduboff /* bounce buffer management */ 1715748Sduboff ddi_acc_handle_t rxb_bah; 1725748Sduboff }; 1735748Sduboff 1745748Sduboff struct mcast_addr { 1755748Sduboff struct ether_addr addr; 1765748Sduboff uint32_t hash; 1775748Sduboff }; 1785748Sduboff 1795748Sduboff #define GEM_MAXMC 64 1805748Sduboff #define GEM_MCALLOC (sizeof (struct mcast_addr) * GEM_MAXMC) 1815748Sduboff 1825748Sduboff #define SUB(x, y) ((seqnum_t)((x) - (y))) 1835748Sduboff #define SLOT(seqnum, size) (((unsigned int)(seqnum)) & ((size)-1)) 1845748Sduboff 1855748Sduboff /* 1865748Sduboff * mac soft state 1875748Sduboff */ 1885748Sduboff struct gem_dev { 1895748Sduboff dev_info_t *dip; 1905748Sduboff mac_handle_t mh; 1915748Sduboff char name[GEM_NAME_LEN]; 1925748Sduboff void *base_addr; 1935748Sduboff ddi_acc_handle_t regs_handle; 1945748Sduboff ddi_iblock_cookie_t iblock_cookie; 1955748Sduboff 1965748Sduboff /* MAC address information */ 1975748Sduboff struct ether_addr cur_addr; 1985748Sduboff struct ether_addr dev_addr; 1995748Sduboff 2005748Sduboff /* Descriptor rings, io area */ 2015748Sduboff ddi_dma_handle_t desc_dma_handle; 2025748Sduboff ddi_acc_handle_t desc_acc_handle; 2035748Sduboff caddr_t rx_ring; 2045748Sduboff caddr_t tx_ring; 2055748Sduboff caddr_t io_area; 2065748Sduboff /* caddr_t rx_buf; */ 2075748Sduboff 2085748Sduboff uint64_t rx_ring_dma; 2095748Sduboff uint64_t tx_ring_dma; 2105748Sduboff uint64_t io_area_dma; 2115748Sduboff 2125748Sduboff /* RX slot ring management */ 2135748Sduboff kmutex_t intrlock; 2145748Sduboff boolean_t intr_busy; 2155748Sduboff seqnum_t rx_active_head; 2165748Sduboff seqnum_t rx_active_tail; 2175748Sduboff mac_resource_handle_t mac_rx_ring_ha; 2185748Sduboff /* Rx buffer management */ 2195748Sduboff struct rxbuf *rx_buf_head; 2205748Sduboff struct rxbuf *rx_buf_tail; 2215748Sduboff struct rxbuf *rx_buf_freelist; 2225748Sduboff int rx_buf_allocated; 2235748Sduboff int rx_buf_freecnt; 2245748Sduboff int rx_buf_len; 2255748Sduboff 2265748Sduboff /* TX descriptor ring management */ 2275748Sduboff seqnum_t tx_desc_head; 2285748Sduboff seqnum_t tx_desc_tail; 2295748Sduboff seqnum_t tx_desc_intr; 2305748Sduboff 2315748Sduboff /* TX buffur ring management */ 2325748Sduboff kmutex_t xmitlock; 2335748Sduboff kcondvar_t tx_drain_cv; 2345748Sduboff seqnum_t tx_active_head; 2355748Sduboff seqnum_t tx_active_tail; 2365748Sduboff seqnum_t tx_softq_head; 2375748Sduboff seqnum_t tx_softq_tail; 2385748Sduboff seqnum_t tx_free_head; 2395748Sduboff seqnum_t tx_free_tail; 2407116Sduboff int tx_max_packets; 2415748Sduboff 2425748Sduboff /* TX buffer resource management */ 2435748Sduboff struct txbuf *tx_buf; 2445748Sduboff seqnum_t tx_slots_base; 2455748Sduboff 2465748Sduboff /* TX state management */ 2475748Sduboff int tx_busy; 2485748Sduboff int tx_reclaim_busy; 2497116Sduboff clock_t tx_blocked; 2505748Sduboff 2515748Sduboff /* NIC state */ 2525748Sduboff volatile boolean_t mac_active; /* tx and rx are running */ 2535748Sduboff volatile int nic_state; /* logical driver state */ 2545748Sduboff #define NIC_STATE_STOPPED 0 2555748Sduboff #define NIC_STATE_INITIALIZED 1 2565748Sduboff #define NIC_STATE_ONLINE 2 2575748Sduboff volatile boolean_t mac_suspended; 2585748Sduboff 2595748Sduboff /* robustness: timer and watchdog */ 2605748Sduboff volatile timeout_id_t timeout_id; 2615748Sduboff 2625748Sduboff 2635748Sduboff /* MII management */ 2645748Sduboff boolean_t anadv_autoneg:1; 2655748Sduboff boolean_t anadv_1000fdx:1; 2665748Sduboff boolean_t anadv_1000hdx:1; 2675748Sduboff boolean_t anadv_100t4:1; 2685748Sduboff boolean_t anadv_100fdx:1; 2695748Sduboff boolean_t anadv_100hdx:1; 2705748Sduboff boolean_t anadv_10fdx:1; 2715748Sduboff boolean_t anadv_10hdx:1; 2725748Sduboff boolean_t anadv_flow_control:2; 2735748Sduboff boolean_t mii_advert_ro:1; 2745748Sduboff 2755748Sduboff boolean_t full_duplex:1; 2765748Sduboff int speed:3; 2775748Sduboff #define GEM_SPD_10 0 2785748Sduboff #define GEM_SPD_100 1 2795748Sduboff #define GEM_SPD_1000 2 2807116Sduboff #define GEM_SPD_NUM 3 2815748Sduboff unsigned int flow_control:2; 2825748Sduboff #define FLOW_CONTROL_NONE 0 2835748Sduboff #define FLOW_CONTROL_SYMMETRIC 1 2845748Sduboff #define FLOW_CONTROL_TX_PAUSE 2 2855748Sduboff #define FLOW_CONTROL_RX_PAUSE 3 2865748Sduboff 2875748Sduboff boolean_t mii_supress_msg:1; 2885748Sduboff 2895748Sduboff uint32_t mii_phy_id; 2905748Sduboff uint16_t mii_status; 2915748Sduboff uint16_t mii_advert; 2925748Sduboff uint16_t mii_lpable; 2935748Sduboff uint16_t mii_exp; 2945748Sduboff uint16_t mii_ctl1000; 2955748Sduboff uint16_t mii_stat1000; 2965748Sduboff uint16_t mii_xstatus; 2975748Sduboff int8_t mii_phy_addr; /* must be signed */ 2985748Sduboff 2995748Sduboff uint8_t mii_state; 3005748Sduboff #define MII_STATE_UNKNOWN 0 3015748Sduboff #define MII_STATE_RESETTING 1 3025748Sduboff #define MII_STATE_AUTONEGOTIATING 2 3035748Sduboff #define MII_STATE_AN_DONE 3 3045748Sduboff #define MII_STATE_MEDIA_SETUP 4 3055748Sduboff #define MII_STATE_LINKUP 5 3065748Sduboff #define MII_STATE_LINKDOWN 6 3075748Sduboff 3085748Sduboff clock_t mii_last_check; /* in tick */ 3095748Sduboff clock_t mii_timer; /* in tick */ 3105748Sduboff #define MII_RESET_TIMEOUT drv_usectohz(1000*1000) 3115748Sduboff #define MII_AN_TIMEOUT drv_usectohz(5000*1000) 3125748Sduboff #define MII_LINKDOWN_TIMEOUT drv_usectohz(10000*1000) 3135748Sduboff clock_t mii_interval; /* in tick */ 3147116Sduboff clock_t linkup_delay; /* in tick */ 3155748Sduboff 3165748Sduboff volatile timeout_id_t link_watcher_id; 3175748Sduboff 3185748Sduboff ddi_softintr_t soft_id; 3195748Sduboff 3205748Sduboff /* multcast list management */ 3215748Sduboff int16_t mc_count; 3225748Sduboff int16_t mc_count_req; 3235748Sduboff struct mcast_addr *mc_list; 3245748Sduboff uint32_t rxmode; 3255748Sduboff #define RXMODE_PROMISC 0x01 3265748Sduboff #define RXMODE_ALLMULTI_REQ 0x02 3275748Sduboff #define RXMODE_MULTI_OVF 0x04 3285748Sduboff #define RXMODE_ENABLE 0x08 3295748Sduboff #define RXMODE_ALLMULTI (RXMODE_ALLMULTI_REQ | RXMODE_MULTI_OVF) 3305748Sduboff #define RXMODE_BITS \ 3315748Sduboff "\020" \ 3325748Sduboff "\004ENABLE" \ 3335748Sduboff "\003MULTI_OVF" \ 3345748Sduboff "\002ALLMULTI_REQ" \ 3355748Sduboff "\001PROMISC" 3365748Sduboff 3375748Sduboff /* statistcs */ 3385748Sduboff struct gem_stats stats; 3395748Sduboff 3405748Sduboff /* pointer to local structure */ 3415748Sduboff void *private; 3425748Sduboff int priv_size; 3435748Sduboff 3445748Sduboff /* polling mode */ 3457116Sduboff int poll_pkt_delay; /* in number of packets */ 3465748Sduboff 3475748Sduboff /* descriptor area */ 3487116Sduboff int tx_desc_size; 3497116Sduboff int rx_desc_size; 3505748Sduboff 3515748Sduboff /* configuration */ 3525748Sduboff struct gem_conf { 3535748Sduboff /* name */ 3545748Sduboff char gc_name[GEM_NAME_LEN]; 3555748Sduboff 3565748Sduboff /* specification on tx and rx dma engine */ 3575748Sduboff long gc_tx_buf_align; 3585748Sduboff int gc_tx_max_frags; 3595748Sduboff int gc_tx_max_descs_per_pkt; 3605748Sduboff int gc_tx_buf_size; 3615748Sduboff int gc_tx_buf_limit; 3625748Sduboff int gc_tx_desc_unit_shift; 3635748Sduboff int gc_tx_ring_size; 3645748Sduboff int gc_tx_ring_limit; 3655748Sduboff int gc_tx_copy_thresh; 3665748Sduboff boolean_t gc_tx_auto_pad; 3675748Sduboff boolean_t gc_tx_desc_write_oo; 3685748Sduboff 3695748Sduboff long gc_rx_buf_align; 3705748Sduboff int gc_rx_max_frags; 3715748Sduboff int gc_rx_desc_unit_shift; 3725748Sduboff int gc_rx_ring_size; 3735748Sduboff int gc_rx_copy_thresh; 3745748Sduboff int gc_rx_buf_max; 3755748Sduboff int gc_rx_header_len; 3765748Sduboff 3775748Sduboff int gc_io_area_size; 3785748Sduboff 3795748Sduboff /* memory mapping attributes */ 3805748Sduboff struct ddi_device_acc_attr gc_dev_attr; 3815748Sduboff struct ddi_device_acc_attr gc_buf_attr; 3825748Sduboff struct ddi_device_acc_attr gc_desc_attr; 3835748Sduboff 3845748Sduboff /* dma attributes */ 3855748Sduboff ddi_dma_attr_t gc_dma_attr_desc; 3865748Sduboff ddi_dma_attr_t gc_dma_attr_txbuf; 3875748Sduboff ddi_dma_attr_t gc_dma_attr_rxbuf; 3885748Sduboff 3895748Sduboff /* tx time out parameters */ 3905748Sduboff clock_t gc_tx_timeout; 3915748Sduboff clock_t gc_tx_timeout_interval; 3925748Sduboff 3935748Sduboff /* auto negotiation capability */ 3945748Sduboff int gc_flow_control; 3955748Sduboff 3965748Sduboff /* MII mode */ 3975748Sduboff int gc_mii_mode; 3985748Sduboff #define GEM_MODE_100BASETX 0 3995748Sduboff #define GEM_MODE_1000BASET 1 4005748Sduboff #define GEM_MODE_1000BASETX 2 4015748Sduboff 4025748Sduboff /* MII link state watch parameters */ 4035748Sduboff clock_t gc_mii_linkdown_timeout; 4045748Sduboff clock_t gc_mii_link_watch_interval; 4055748Sduboff clock_t gc_mii_reset_timeout; 4065748Sduboff 4075748Sduboff clock_t gc_mii_an_watch_interval; 4085748Sduboff clock_t gc_mii_an_timeout; 4095748Sduboff clock_t gc_mii_an_wait; 4105748Sduboff clock_t gc_mii_an_delay; 4115748Sduboff 4125748Sduboff /* MII configuration */ 4135748Sduboff int gc_mii_addr_min; 4145748Sduboff int gc_mii_linkdown_action; 4155748Sduboff int gc_mii_linkdown_timeout_action; 4165748Sduboff #define MII_ACTION_NONE 0 4175748Sduboff #define MII_ACTION_RESET 1 4185748Sduboff #define MII_ACTION_RSA 2 4195748Sduboff boolean_t gc_mii_dont_reset; 4205748Sduboff boolean_t gc_mii_an_oneshot; 4215748Sduboff boolean_t gc_mii_hw_link_detection; 4225748Sduboff boolean_t gc_mii_stop_mac_on_linkdown; 4235748Sduboff 4245748Sduboff /* I/O methods */ 4255748Sduboff 4265748Sduboff /* mac operation */ 4275748Sduboff int (*gc_attach_chip)(struct gem_dev *dp); 4285748Sduboff int (*gc_reset_chip)(struct gem_dev *dp); 4295748Sduboff int (*gc_init_chip)(struct gem_dev *dp); 4305748Sduboff int (*gc_start_chip)(struct gem_dev *dp); 4315748Sduboff int (*gc_stop_chip)(struct gem_dev *dp); 4325748Sduboff uint32_t (*gc_multicast_hash)(struct gem_dev *dp, uint8_t *); 4335748Sduboff int (*gc_set_rx_filter)(struct gem_dev *dp); 4345748Sduboff int (*gc_set_media)(struct gem_dev *dp); 4355748Sduboff int (*gc_get_stats)(struct gem_dev *dp); 4365748Sduboff uint_t (*gc_interrupt)(struct gem_dev *dp); 4375748Sduboff 4385748Sduboff /* descriptor operation */ 4395748Sduboff int (*gc_tx_desc_write)(struct gem_dev *dp, int slot, 4405748Sduboff ddi_dma_cookie_t *dmacookie, 4415748Sduboff int frags, uint64_t flag); 4425748Sduboff #define GEM_TXFLAG_INTR 0x00000001ull 4435748Sduboff #define GEM_TXFLAG_TCP 0x00000002ull 4445748Sduboff #define GEM_TXFLAG_TCP_SHIFT 1ull 4455748Sduboff #define GEM_TXFLAG_UDP 0x00000004ull 4465748Sduboff #define GEM_TXFLAG_UDP_SHIFT 2ull 4475748Sduboff #define GEM_TXFLAG_IPv4 0x00000008ull 4485748Sduboff #define GEM_TXFLAG_IPv4_SHIFT 3ull 4495748Sduboff #define GEM_TXFLAG_IPv6 0x00000010ull 4505748Sduboff #define GEM_TXFLAG_IPv6_SHIFT 4ull 4515748Sduboff #define GEM_TXFLAG_HEAD 0x00000020ull 4525748Sduboff #define GEM_TXFLAG_TAIL 0x00000040ull 4535748Sduboff #define GEM_TXFLAG_SWVTAG 0x00000080ull 4545748Sduboff #define GEM_TXFLAG_PRIVATE 0x0000ff00ull 4555748Sduboff #define GEM_TXFLAG_PRIVATE_SHIFT 8ull 4565748Sduboff #define GEM_TXFLAG_PRIVATE_MASK 0xffull 4575748Sduboff #define GEM_TXFLAG_VID 0x0fff0000ull 4585748Sduboff #define GEM_TXFLAG_VID_SHIFT 16ull 4595748Sduboff #define GEM_TXFLAG_VID_MASK 0xfffull 4605748Sduboff #define GEM_TXFLAG_CFI 0x10000000ull 4615748Sduboff #define GEM_TXFLAG_PRI 0xe0000000ull 4625748Sduboff #define GEM_TXFLAG_PRI_SHIFT 29ull 4635748Sduboff #define GEM_TXFLAG_PRI_MASK 0x7ull 4645748Sduboff #define GEM_TXFLAG_VTAG 0xffff0000ull 4655748Sduboff #define GEM_TXFLAG_VTAG_SHIFT 16ull 4667116Sduboff #define GEM_TXFLAG_HCKSTART 0x000000ff00000000ull 4675748Sduboff #define GEM_TXFLAG_HCKSTART_SHIFT 32ull 4687116Sduboff #define GEM_TXFLAG_HCKSTUFF 0x0000ff0000000000ull 4695748Sduboff #define GEM_TXFLAG_HCKSTUFF_SHIFT 40ull 4707116Sduboff #define GEM_TXFLAG_TCPHLEN 0x0000ff0000000000ull 4717116Sduboff #define GEM_TXFLAG_TCPHLEN_SHIFT 40ull 4727116Sduboff #define GEM_TXFLAG_MSS 0xffff000000000000ull 4737116Sduboff #define GEM_TXFLAG_MSS_SHIFT 48ull 4745748Sduboff 4755748Sduboff void (*gc_tx_start) (struct gem_dev *dp, int slot, int frags); 4765748Sduboff void (*gc_rx_desc_write)(struct gem_dev *dp, int slot, 4775748Sduboff ddi_dma_cookie_t *dmacookie, int frags); 4785748Sduboff void (*gc_rx_start)(struct gem_dev *dp, int slot, int frags); 4795748Sduboff 4805748Sduboff uint_t (*gc_tx_desc_stat) 4815748Sduboff (struct gem_dev *dp, int slot, int descs); 4825748Sduboff #define GEM_TX_DONE 0x00010000 4835748Sduboff #define GEM_TX_ERR 0x00020000 4845748Sduboff 4855748Sduboff 4865748Sduboff uint64_t (*gc_rx_desc_stat) 4875748Sduboff (struct gem_dev *dp, int slot, int frags); 4885748Sduboff 4895748Sduboff #define GEM_RX_CKSUM 0xffff000000000000ull 4905748Sduboff #define GEM_RX_CKSUM_SHIFT 48 4915748Sduboff #define GEM_RX_PRI 0x0000e00000000000ull 4925748Sduboff #define GEM_RX_PRI_SHIFT 45 4935748Sduboff #define GEM_RX_CFI 0x0000100000000000ull 4945748Sduboff #define GEM_RX_VID 0x00000fff00000000ull 4955748Sduboff #define GEM_RX_VID_SHIFT 32 4965748Sduboff #define GEM_RX_VTAG 0x0000ffff00000000ull 4975748Sduboff #define GEM_RX_VTAG_SHIFT 32 4985748Sduboff 4995748Sduboff #define GEM_RX_CKSUM_IPv6 0x00080000ul 5005748Sduboff #define GEM_RX_CKSUM_IPv6_SHIFT 19 5015748Sduboff #define GEM_RX_CKSUM_IPv4 0x00040000ul 5025748Sduboff #define GEM_RX_CKSUM_IPv4_SHIFT 18 5035748Sduboff #define GEM_RX_CKSUM_UDP 0x00020000ul 5045748Sduboff #define GEM_RX_CKSUM_UDP_SHIFT 17 5055748Sduboff #define GEM_RX_CKSUM_TCP 0x00010000ul 5065748Sduboff #define GEM_RX_CKSUM_TCP_SHIFT 16 5075748Sduboff #define GEM_RX_ERR 0x00008000ul 5085748Sduboff #define GEM_RX_DONE 0x00004000ul 5095748Sduboff #define GEM_RX_LEN 0x00003ffful /* 16KB - 1 */ 5105748Sduboff 5115748Sduboff void (*gc_tx_desc_init)(struct gem_dev *dp, int slot); 5125748Sduboff void (*gc_rx_desc_init)(struct gem_dev *dp, int slot); 5135748Sduboff void (*gc_tx_desc_clean)(struct gem_dev *dp, int slot); 5145748Sduboff void (*gc_rx_desc_clean)(struct gem_dev *dp, int slot); 5155748Sduboff 5165748Sduboff /* mii operations */ 5175748Sduboff int (*gc_mii_probe)(struct gem_dev *dp); 5185748Sduboff int (*gc_mii_init)(struct gem_dev *dp); 5195748Sduboff int (*gc_mii_config)(struct gem_dev *dp); 5205748Sduboff void (*gc_mii_sync)(struct gem_dev *dp); 5215748Sduboff uint16_t (*gc_mii_read)(struct gem_dev *dp, uint_t reg); 5225748Sduboff void (*gc_mii_write)(struct gem_dev *dp, 5235748Sduboff uint_t reg, uint16_t val); 5245748Sduboff void (*gc_mii_tune_phy)(struct gem_dev *dp); 5255748Sduboff 5265748Sduboff /* packet in/out operation for copy-style */ 5275748Sduboff void (*gc_put_packet)(struct gem_dev *dp, 5285748Sduboff mblk_t *, void *, size_t); 5295748Sduboff mblk_t *(*gc_get_packet)(struct gem_dev *dp, 5305748Sduboff struct rxbuf *, size_t); 5315748Sduboff int gc_nports; 5325748Sduboff 5335748Sduboff /* hw checksum */ 5345748Sduboff uint32_t gc_hck_rx_start; 5355748Sduboff } gc; 5365748Sduboff 5375748Sduboff uint32_t misc_flag; 5387116Sduboff #define GEM_LSO 0x00000400 5395748Sduboff #define GEM_CTRL_PKT 0x00000200 5405748Sduboff #define GEM_SOFTINTR 0x00000100 5415748Sduboff #define GEM_POLL_RXONLY 0x00000080 5425748Sduboff #define GEM_VLAN_HARD 0x00000040 5435748Sduboff #define GEM_VLAN_SOFT 0x00000020 5445748Sduboff #define GEM_VLAN (GEM_VLAN_HARD | GEM_VLAN_SOFT) 5455748Sduboff #define GEM_CKSUM_HEADER_IPv4 0x00000010 5465748Sduboff #define GEM_CKSUM_PARTIAL 0x00000008 5475748Sduboff #define GEM_CKSUM_FULL_IPv6 0x00000004 5485748Sduboff #define GEM_CKSUM_FULL_IPv4 0x00000002 5495748Sduboff #define GEM_NOINTR 0x00000001 5505748Sduboff 5515748Sduboff volatile timeout_id_t intr_watcher_id; 5525748Sduboff 5535748Sduboff uint_t mtu; 5545748Sduboff 5555748Sduboff /* performance tuning parameters */ 5565748Sduboff uint_t txthr; /* tx fifo threshoold */ 5575748Sduboff uint_t txmaxdma; /* tx max dma burst size */ 5585748Sduboff uint_t rxthr; /* rx fifo threshoold */ 5595748Sduboff uint_t rxmaxdma; /* tx max dma burst size */ 5605748Sduboff 5615748Sduboff /* kstat stuff */ 5625748Sduboff kstat_t *ksp; 5635748Sduboff 5647116Sduboff /* multiple port device support */ 5655748Sduboff struct gem_dev *next; /* pointer to next port on the same device */ 5667116Sduboff int port; 5675748Sduboff 5685748Sduboff /* ndd stuff */ 5695748Sduboff caddr_t nd_data_p; 5705748Sduboff caddr_t nd_arg_p; 5715748Sduboff 5725748Sduboff #ifdef GEM_DEBUG_LEVEL 5735748Sduboff int tx_cnt; 5745748Sduboff #endif 5755748Sduboff }; 5765748Sduboff 5775748Sduboff /* 5785748Sduboff * Exported functions 5795748Sduboff */ 5805748Sduboff boolean_t gem_get_mac_addr_conf(struct gem_dev *); 5815748Sduboff int gem_mii_probe_default(struct gem_dev *); 5825748Sduboff int gem_mii_config_default(struct gem_dev *); 5835748Sduboff boolean_t gem_mii_link_check(struct gem_dev *dp); 5845748Sduboff uint16_t gem_mii_read(struct gem_dev *, uint_t); 5855748Sduboff void gem_mii_write(struct gem_dev *, uint_t, uint16_t); 5865748Sduboff int gem_reclaim_txbuf(struct gem_dev *dp); 5875748Sduboff int gem_restart_nic(struct gem_dev *dp, uint_t flags); 5885748Sduboff #define GEM_RESTART_NOWAIT 0x00000002 5895748Sduboff #define GEM_RESTART_KEEP_BUF 0x00000001 5905748Sduboff boolean_t gem_tx_done(struct gem_dev *); 5915748Sduboff int gem_receive(struct gem_dev *); 5925748Sduboff int gem_receive_copy(struct gem_dev *); 5935748Sduboff struct gem_dev *gem_do_attach(dev_info_t *, int, 5945748Sduboff struct gem_conf *, void *, ddi_acc_handle_t *, void *, int); 5955748Sduboff 5965748Sduboff mblk_t *gem_send_common(struct gem_dev *, mblk_t *, uint32_t); 5975748Sduboff #define GEM_SEND_COPY 0x00008000 5985748Sduboff #define GEM_SEND_CTRL 0x000000ff /* private flags for control packets */ 5995748Sduboff #define GEM_SEND_VTAG 0xffff0000 6005748Sduboff #define GEM_SEND_VTAG_SHIFT 16 6015748Sduboff 6025748Sduboff mblk_t *gem_get_packet_default(struct gem_dev *, struct rxbuf *, size_t); 6035748Sduboff 6045748Sduboff uint32_t gem_ether_crc_le(const uint8_t *addr, int len); 6055748Sduboff uint32_t gem_ether_crc_be(const uint8_t *addr, int len); 6065748Sduboff int gem_do_detach(dev_info_t *); 6075748Sduboff 6085748Sduboff int gem_getlongprop_buf(dev_t dev, dev_info_t *dip, 6095748Sduboff int flags, char *name, void *buf, int *lenp); 6105748Sduboff int gem_getprop(dev_t dev, dev_info_t *dip, 6115748Sduboff int flags, char *name, int defvalue); 6125748Sduboff 6135748Sduboff struct rxbuf *gem_get_rxbuf(struct gem_dev *, int); 6145748Sduboff 6155748Sduboff void gem_rx_desc_dma_sync(struct gem_dev *, int, int, int); 6165748Sduboff void gem_tx_desc_dma_sync(struct gem_dev *, int, int, int); 6175748Sduboff 6185748Sduboff int gem_resume(dev_info_t *); 6195748Sduboff int gem_suspend(dev_info_t *); 6205748Sduboff uint8_t gem_search_pci_cap(dev_info_t *dip, ddi_acc_handle_t, uint8_t); 6215748Sduboff int gem_pci_set_power_state(dev_info_t *, ddi_acc_handle_t, uint_t); 6225748Sduboff int gem_pci_regs_map_setup(dev_info_t *, uint32_t, uint32_t, 6235748Sduboff struct ddi_device_acc_attr *, caddr_t *, ddi_acc_handle_t *); 6245748Sduboff void gem_mod_init(struct dev_ops *, char *); 6255748Sduboff void gem_mod_fini(struct dev_ops *); 6265748Sduboff 6275748Sduboff #define GEM_GET_DEV(dip) \ 6285748Sduboff ((struct gem_dev *)(ddi_get_driver_private(dip))) 6295748Sduboff #endif /* _SFE_UTIL_H_ */ 630