f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/*
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * sfe_util.h: header to support the gem layer used by Masa Murayama
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff *
23d366e350386ec109bfa9b2cf91225729a1a26bduboff * Copyright (c) 2002-2008 Masayuki Murayama. All rights reserved.
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff *
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * Redistribution and use in source and binary forms, with or without
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * modification, are permitted provided that the following conditions are met:
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff *
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * 1. Redistributions of source code must retain the above copyright notice,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * this list of conditions and the following disclaimer.
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff *
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * 2. Redistributions in binary form must reproduce the above copyright notice,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * this list of conditions and the following disclaimer in the documentation
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * and/or other materials provided with the distribution.
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff *
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * 3. Neither the name of the author nor the names of its contributors may be
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * used to endorse or promote products derived from this software without
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * specific prior written permission.
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff *
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * DAMAGE.
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff */
23d366e350386ec109bfa9b2cf91225729a1a26bduboff
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng/*
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Use is subject to license terms.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng */
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#ifndef _SFE_UTIL_H_
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define _SFE_UTIL_H_
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#include <sys/mac_provider.h>
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#include <sys/mac_ether.h>
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/*
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * Useful macros and typedefs
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_NAME_LEN 32
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TX_TIMEOUT (drv_usectohz(5*1000000))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TX_TIMEOUT_INTERVAL (drv_usectohz(1*1000000))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_LINK_WATCH_INTERVAL (drv_usectohz(1*1000000)) /* 1 sec */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/* general return code */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SUCCESS 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_FAILURE (-1)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/* return code of gem_tx_done */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define INTR_RESTART_TX 0x80000000
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
23d366e350386ec109bfa9b2cf91225729a1a26bdubofftypedef int32_t seqnum_t;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/*
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * I/O instructions
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define OUTB(dp, p, v) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_put8((dp)->regs_handle, \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (void *)((caddr_t)((dp)->base_addr) + (p)), v)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define OUTW(dp, p, v) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_put16((dp)->regs_handle, \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (void *)((caddr_t)((dp)->base_addr) + (p)), v)
915ebf8da9f4ef3e7b2e34dd367f64d358a628d9Alan Duboff#define OUTL(dp, p, v) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_put32((dp)->regs_handle, \
915ebf8da9f4ef3e7b2e34dd367f64d358a628d9Alan Duboff (void *)((caddr_t)((dp)->base_addr) + (p)), v)
915ebf8da9f4ef3e7b2e34dd367f64d358a628d9Alan Duboff#define OUTLINL(dp, p, v) \
915ebf8da9f4ef3e7b2e34dd367f64d358a628d9Alan Duboff ddi_put32((dp)->regs_handle, \
915ebf8da9f4ef3e7b2e34dd367f64d358a628d9Alan Duboff (void *)((caddr_t)((dp)->base_addr) + (p)), v); \
915ebf8da9f4ef3e7b2e34dd367f64d358a628d9Alan Duboff (void) INL((dp), (p))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define INB(dp, p) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_get8((dp)->regs_handle, \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (void *)(((caddr_t)(dp)->base_addr) + (p)))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define INW(dp, p) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_get16((dp)->regs_handle, \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (void *)(((caddr_t)(dp)->base_addr) + (p)))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define INL(dp, p) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_get32((dp)->regs_handle, \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (void *)(((caddr_t)(dp)->base_addr) + (p)))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct gem_stats {
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t intr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t crc;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t errrcv;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t overflow;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t frame;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t missed;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t runt;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t frame_too_long;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t norcvbuf;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t sqe;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t collisions;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t first_coll;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t multi_coll;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t excoll;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t xmit_internal_err;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t nocarrier;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t defer;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t errxmt;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t underflow;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t xmtlatecoll;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t noxmtbuf;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t jabber;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t rbytes;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t obytes;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t rpackets;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t opackets;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t rbcast;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t obcast;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t rmcast;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t omcast;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t rcv_internal_err;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff};
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MAXTXSEGS 4
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MAXRXSEGS 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MAXTXFRAGS 8
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MAXRXFRAGS 4
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/* TX buffer management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct txbuf {
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct txbuf *txb_next;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* pointer to original mblk */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff mblk_t *txb_mp;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* dma mapping for current packet */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_cookie_t txb_dmacookie[GEM_MAXTXFRAGS];
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t txb_nfrags;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* bounce buffer management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_handle_t txb_bdh;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_acc_handle_t txb_bah;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t txb_buf; /* vaddr of bounce buffer */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t txb_buf_dma; /* paddr of bounce buffer */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* timeout management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t txb_stime;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* Hardware descriptor info */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t txb_desc;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int txb_ndescs;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t txb_flag;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff};
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/* RX buffer management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct rxbuf {
23d366e350386ec109bfa9b2cf91225729a1a26bduboff /* Hardware independent section */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct rxbuf *rxb_next;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct gem_dev *rxb_devp;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* dma mapping management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_handle_t rxb_dh;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t rxb_buf;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff size_t rxb_buf_len;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_cookie_t rxb_dmacookie[GEM_MAXRXFRAGS];
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t rxb_nfrags;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* bounce buffer management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_acc_handle_t rxb_bah;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff};
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct mcast_addr {
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ether_addr addr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t hash;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff};
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MAXMC 64
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MCALLOC (sizeof (struct mcast_addr) * GEM_MAXMC)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define SUB(x, y) ((seqnum_t)((x) - (y)))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define SLOT(seqnum, size) (((unsigned int)(seqnum)) & ((size)-1))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/*
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * mac soft state
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct gem_dev {
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff dev_info_t *dip;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff mac_handle_t mh;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff char name[GEM_NAME_LEN];
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void *base_addr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_acc_handle_t regs_handle;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_iblock_cookie_t iblock_cookie;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* MAC address information */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ether_addr cur_addr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ether_addr dev_addr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* Descriptor rings, io area */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_handle_t desc_dma_handle;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_acc_handle_t desc_acc_handle;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t rx_ring;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t tx_ring;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t io_area;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* caddr_t rx_buf; */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t rx_ring_dma;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t tx_ring_dma;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t io_area_dma;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* RX slot ring management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff kmutex_t intrlock;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t intr_busy;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t rx_active_head;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t rx_active_tail;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff mac_resource_handle_t mac_rx_ring_ha;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* Rx buffer management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct rxbuf *rx_buf_head;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct rxbuf *rx_buf_tail;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct rxbuf *rx_buf_freelist;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int rx_buf_allocated;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int rx_buf_freecnt;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int rx_buf_len;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* TX descriptor ring management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_desc_head;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_desc_tail;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_desc_intr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* TX buffur ring management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff kmutex_t xmitlock;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff kcondvar_t tx_drain_cv;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_active_head;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_active_tail;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_softq_head;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_softq_tail;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_free_head;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_free_tail;
23d366e350386ec109bfa9b2cf91225729a1a26bduboff int tx_max_packets;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* TX buffer resource management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct txbuf *tx_buf;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff seqnum_t tx_slots_base;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* TX state management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int tx_busy;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int tx_reclaim_busy;
23d366e350386ec109bfa9b2cf91225729a1a26bduboff clock_t tx_blocked;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* NIC state */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff volatile boolean_t mac_active; /* tx and rx are running */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff volatile int nic_state; /* logical driver state */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define NIC_STATE_STOPPED 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define NIC_STATE_INITIALIZED 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define NIC_STATE_ONLINE 2
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff volatile boolean_t mac_suspended;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* robustness: timer and watchdog */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff volatile timeout_id_t timeout_id;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* MII management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_autoneg:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_1000fdx:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_1000hdx:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_100t4:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_100fdx:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_100hdx:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_10fdx:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_10hdx:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t anadv_flow_control:2;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t mii_advert_ro:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t full_duplex:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int speed:3;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SPD_10 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SPD_100 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SPD_1000 2
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_SPD_NUM 3
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff unsigned int flow_control:2;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define FLOW_CONTROL_NONE 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define FLOW_CONTROL_SYMMETRIC 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define FLOW_CONTROL_TX_PAUSE 2
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define FLOW_CONTROL_RX_PAUSE 3
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t mii_supress_msg:1;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t mii_phy_id;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_status;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_advert;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_lpable;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_exp;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_ctl1000;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_stat1000;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t mii_xstatus;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int8_t mii_phy_addr; /* must be signed */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint8_t mii_state;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_UNKNOWN 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_RESETTING 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_AUTONEGOTIATING 2
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_AN_DONE 3
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_MEDIA_SETUP 4
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_LINKUP 5
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_STATE_LINKDOWN 6
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t mii_last_check; /* in tick */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t mii_timer; /* in tick */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_RESET_TIMEOUT drv_usectohz(1000*1000)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_AN_TIMEOUT drv_usectohz(5000*1000)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_LINKDOWN_TIMEOUT drv_usectohz(10000*1000)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t mii_interval; /* in tick */
23d366e350386ec109bfa9b2cf91225729a1a26bduboff clock_t linkup_delay; /* in tick */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff volatile timeout_id_t link_watcher_id;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_softintr_t soft_id;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* multcast list management */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int16_t mc_count;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int16_t mc_count_req;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct mcast_addr *mc_list;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t rxmode;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define RXMODE_PROMISC 0x01
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define RXMODE_ALLMULTI_REQ 0x02
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define RXMODE_MULTI_OVF 0x04
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define RXMODE_ENABLE 0x08
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define RXMODE_ALLMULTI (RXMODE_ALLMULTI_REQ | RXMODE_MULTI_OVF)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define RXMODE_BITS \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff "\020" \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff "\004ENABLE" \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff "\003MULTI_OVF" \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff "\002ALLMULTI_REQ" \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff "\001PROMISC"
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* statistcs */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct gem_stats stats;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* pointer to local structure */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void *private;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int priv_size;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* polling mode */
23d366e350386ec109bfa9b2cf91225729a1a26bduboff int poll_pkt_delay; /* in number of packets */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* descriptor area */
23d366e350386ec109bfa9b2cf91225729a1a26bduboff int tx_desc_size;
23d366e350386ec109bfa9b2cf91225729a1a26bduboff int rx_desc_size;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* configuration */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct gem_conf {
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* name */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff char gc_name[GEM_NAME_LEN];
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* specification on tx and rx dma engine */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff long gc_tx_buf_align;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_max_frags;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_max_descs_per_pkt;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_buf_size;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_buf_limit;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_desc_unit_shift;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_ring_size;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_ring_limit;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_tx_copy_thresh;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t gc_tx_auto_pad;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t gc_tx_desc_write_oo;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff long gc_rx_buf_align;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_rx_max_frags;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_rx_desc_unit_shift;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_rx_ring_size;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_rx_copy_thresh;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_rx_buf_max;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_rx_header_len;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_io_area_size;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* memory mapping attributes */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ddi_device_acc_attr gc_dev_attr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ddi_device_acc_attr gc_buf_attr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ddi_device_acc_attr gc_desc_attr;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* dma attributes */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_attr_t gc_dma_attr_desc;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_attr_t gc_dma_attr_txbuf;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_attr_t gc_dma_attr_rxbuf;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* tx time out parameters */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_tx_timeout;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_tx_timeout_interval;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* auto negotiation capability */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_flow_control;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* MII mode */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_mii_mode;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MODE_100BASETX 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MODE_1000BASET 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_MODE_1000BASETX 2
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* MII link state watch parameters */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_linkdown_timeout;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_link_watch_interval;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_reset_timeout;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_an_watch_interval;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_an_timeout;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_an_wait;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff clock_t gc_mii_an_delay;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* MII configuration */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_mii_addr_min;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_mii_linkdown_action;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_mii_linkdown_timeout_action;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_ACTION_NONE 0
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_ACTION_RESET 1
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define MII_ACTION_RSA 2
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t gc_mii_dont_reset;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t gc_mii_an_oneshot;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t gc_mii_hw_link_detection;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff boolean_t gc_mii_stop_mac_on_linkdown;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* I/O methods */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* mac operation */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_attach_chip)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_reset_chip)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_init_chip)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_start_chip)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_stop_chip)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t (*gc_multicast_hash)(struct gem_dev *dp, uint8_t *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_set_rx_filter)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_set_media)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_get_stats)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t (*gc_interrupt)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* descriptor operation */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_tx_desc_write)(struct gem_dev *dp, int slot,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_cookie_t *dmacookie,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int frags, uint64_t flag);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_INTR 0x00000001ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_TCP 0x00000002ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_TCP_SHIFT 1ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_UDP 0x00000004ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_UDP_SHIFT 2ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_IPv4 0x00000008ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_IPv4_SHIFT 3ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_IPv6 0x00000010ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_IPv6_SHIFT 4ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_HEAD 0x00000020ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_TAIL 0x00000040ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_SWVTAG 0x00000080ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_PRIVATE 0x0000ff00ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_PRIVATE_SHIFT 8ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_PRIVATE_MASK 0xffull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_VID 0x0fff0000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_VID_SHIFT 16ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_VID_MASK 0xfffull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_CFI 0x10000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_PRI 0xe0000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_PRI_SHIFT 29ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_PRI_MASK 0x7ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_VTAG 0xffff0000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_VTAG_SHIFT 16ull
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_TXFLAG_HCKSTART 0x000000ff00000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_HCKSTART_SHIFT 32ull
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_TXFLAG_HCKSTUFF 0x0000ff0000000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TXFLAG_HCKSTUFF_SHIFT 40ull
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_TXFLAG_TCPHLEN 0x0000ff0000000000ull
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_TXFLAG_TCPHLEN_SHIFT 40ull
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_TXFLAG_MSS 0xffff000000000000ull
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_TXFLAG_MSS_SHIFT 48ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_tx_start) (struct gem_dev *dp, int slot, int frags);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_rx_desc_write)(struct gem_dev *dp, int slot,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ddi_dma_cookie_t *dmacookie, int frags);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_rx_start)(struct gem_dev *dp, int slot, int frags);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t (*gc_tx_desc_stat)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (struct gem_dev *dp, int slot, int descs);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TX_DONE 0x00010000
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_TX_ERR 0x00020000
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint64_t (*gc_rx_desc_stat)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff (struct gem_dev *dp, int slot, int frags);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM 0xffff000000000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_SHIFT 48
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_PRI 0x0000e00000000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_PRI_SHIFT 45
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CFI 0x0000100000000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_VID 0x00000fff00000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_VID_SHIFT 32
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_VTAG 0x0000ffff00000000ull
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_VTAG_SHIFT 32
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_IPv6 0x00080000ul
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_IPv6_SHIFT 19
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_IPv4 0x00040000ul
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_IPv4_SHIFT 18
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_UDP 0x00020000ul
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_UDP_SHIFT 17
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_TCP 0x00010000ul
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_CKSUM_TCP_SHIFT 16
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_ERR 0x00008000ul
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_DONE 0x00004000ul
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RX_LEN 0x00003ffful /* 16KB - 1 */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_tx_desc_init)(struct gem_dev *dp, int slot);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_rx_desc_init)(struct gem_dev *dp, int slot);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_tx_desc_clean)(struct gem_dev *dp, int slot);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_rx_desc_clean)(struct gem_dev *dp, int slot);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* mii operations */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_mii_probe)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_mii_init)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int (*gc_mii_config)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_mii_sync)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint16_t (*gc_mii_read)(struct gem_dev *dp, uint_t reg);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_mii_write)(struct gem_dev *dp,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t reg, uint16_t val);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_mii_tune_phy)(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* packet in/out operation for copy-style */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff void (*gc_put_packet)(struct gem_dev *dp,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff mblk_t *, void *, size_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff mblk_t *(*gc_get_packet)(struct gem_dev *dp,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct rxbuf *, size_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int gc_nports;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* hw checksum */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t gc_hck_rx_start;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff } gc;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint32_t misc_flag;
23d366e350386ec109bfa9b2cf91225729a1a26bduboff#define GEM_LSO 0x00000400
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_CTRL_PKT 0x00000200
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SOFTINTR 0x00000100
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_POLL_RXONLY 0x00000080
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_VLAN_HARD 0x00000040
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_VLAN_SOFT 0x00000020
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_VLAN (GEM_VLAN_HARD | GEM_VLAN_SOFT)
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_CKSUM_HEADER_IPv4 0x00000010
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_CKSUM_PARTIAL 0x00000008
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_CKSUM_FULL_IPv6 0x00000004
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_CKSUM_FULL_IPv4 0x00000002
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_NOINTR 0x00000001
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff volatile timeout_id_t intr_watcher_id;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t mtu;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* performance tuning parameters */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t txthr; /* tx fifo threshoold */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t txmaxdma; /* tx max dma burst size */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t rxthr; /* rx fifo threshoold */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff uint_t rxmaxdma; /* tx max dma burst size */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* kstat stuff */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff kstat_t *ksp;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
23d366e350386ec109bfa9b2cf91225729a1a26bduboff /* multiple port device support */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct gem_dev *next; /* pointer to next port on the same device */
23d366e350386ec109bfa9b2cf91225729a1a26bduboff int port;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff /* ndd stuff */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t nd_data_p;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff caddr_t nd_arg_p;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#ifdef GEM_DEBUG_LEVEL
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int tx_cnt;
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#endif
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff};
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff/*
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff * Exported functions
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffboolean_t gem_get_mac_addr_conf(struct gem_dev *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_mii_probe_default(struct gem_dev *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_mii_config_default(struct gem_dev *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffboolean_t gem_mii_link_check(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffuint16_t gem_mii_read(struct gem_dev *, uint_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffvoid gem_mii_write(struct gem_dev *, uint_t, uint16_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_reclaim_txbuf(struct gem_dev *dp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_restart_nic(struct gem_dev *dp, uint_t flags);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RESTART_NOWAIT 0x00000002
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_RESTART_KEEP_BUF 0x00000001
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffboolean_t gem_tx_done(struct gem_dev *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_receive(struct gem_dev *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_receive_copy(struct gem_dev *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct gem_dev *gem_do_attach(dev_info_t *, int,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct gem_conf *, void *, ddi_acc_handle_t *, void *, int);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffmblk_t *gem_send_common(struct gem_dev *, mblk_t *, uint32_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SEND_COPY 0x00008000
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SEND_CTRL 0x000000ff /* private flags for control packets */
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SEND_VTAG 0xffff0000
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_SEND_VTAG_SHIFT 16
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffmblk_t *gem_get_packet_default(struct gem_dev *, struct rxbuf *, size_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffuint32_t gem_ether_crc_le(const uint8_t *addr, int len);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffuint32_t gem_ether_crc_be(const uint8_t *addr, int len);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_do_detach(dev_info_t *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_getlongprop_buf(dev_t dev, dev_info_t *dip,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int flags, char *name, void *buf, int *lenp);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_getprop(dev_t dev, dev_info_t *dip,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff int flags, char *name, int defvalue);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffstruct rxbuf *gem_get_rxbuf(struct gem_dev *, int);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffvoid gem_rx_desc_dma_sync(struct gem_dev *, int, int, int);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffvoid gem_tx_desc_dma_sync(struct gem_dev *, int, int, int);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_resume(dev_info_t *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_suspend(dev_info_t *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffuint8_t gem_search_pci_cap(dev_info_t *dip, ddi_acc_handle_t, uint8_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_pci_set_power_state(dev_info_t *, ddi_acc_handle_t, uint_t);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffint gem_pci_regs_map_setup(dev_info_t *, uint32_t, uint32_t,
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff struct ddi_device_acc_attr *, caddr_t *, ddi_acc_handle_t *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffvoid gem_mod_init(struct dev_ops *, char *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboffvoid gem_mod_fini(struct dev_ops *);
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#define GEM_GET_DEV(dip) \
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff ((struct gem_dev *)(ddi_get_driver_private(dip)))
f8919bdadda3ebb97bd55cc14a16e0271ed57615duboff#endif /* _SFE_UTIL_H_ */