sfe_util.h revision da14cebe459d3275048785f25bd869cb09b5307f
/*
* sfe_util.h: header to support the gem layer used by Masa Murayama
*
* Copyright (c) 2002-2008 Masayuki Murayama. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
*
* 3. Neither the name of the author nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SFE_UTIL_H_
#define _SFE_UTIL_H_
#include <sys/mac_provider.h>
#include <sys/mac_ether.h>
/*
* Useful macros and typedefs
*/
#define GEM_NAME_LEN 32
/* general return code */
#define GEM_SUCCESS 0
#define GEM_FAILURE (-1)
/* return code of gem_tx_done */
#define INTR_RESTART_TX 0x80000000
/*
* I/O instructions
*/
struct gem_stats {
};
#define GEM_MAXTXSEGS 4
#define GEM_MAXRXSEGS 1
#define GEM_MAXTXFRAGS 8
#define GEM_MAXRXFRAGS 4
/* TX buffer management */
struct txbuf {
/* pointer to original mblk */
/* dma mapping for current packet */
/* bounce buffer management */
/* timeout management */
/* Hardware descriptor info */
int txb_ndescs;
};
/* RX buffer management */
struct rxbuf {
/* Hardware independent section */
/* dma mapping management */
/* bounce buffer management */
};
struct mcast_addr {
struct ether_addr addr;
};
#define GEM_MAXMC 64
/*
* mac soft state
*/
struct gem_dev {
char name[GEM_NAME_LEN];
void *base_addr;
/* MAC address information */
struct ether_addr cur_addr;
struct ether_addr dev_addr;
/* Descriptor rings, io area */
/* caddr_t rx_buf; */
/* RX slot ring management */
/* Rx buffer management */
struct rxbuf *rx_buf_head;
struct rxbuf *rx_buf_tail;
struct rxbuf *rx_buf_freelist;
int rx_buf_allocated;
int rx_buf_freecnt;
int rx_buf_len;
/* TX descriptor ring management */
/* TX buffur ring management */
int tx_max_packets;
/* TX buffer resource management */
/* TX state management */
int tx_busy;
int tx_reclaim_busy;
/* NIC state */
volatile int nic_state; /* logical driver state */
#define NIC_STATE_STOPPED 0
#define NIC_STATE_INITIALIZED 1
#define NIC_STATE_ONLINE 2
volatile boolean_t mac_suspended;
/* robustness: timer and watchdog */
volatile timeout_id_t timeout_id;
/* MII management */
int speed:3;
#define GEM_SPD_10 0
#define GEM_SPD_100 1
#define GEM_SPD_1000 2
#define GEM_SPD_NUM 3
unsigned int flow_control:2;
#define FLOW_CONTROL_NONE 0
#define FLOW_CONTROL_SYMMETRIC 1
#define FLOW_CONTROL_TX_PAUSE 2
#define FLOW_CONTROL_RX_PAUSE 3
#define MII_STATE_UNKNOWN 0
#define MII_STATE_RESETTING 1
#define MII_STATE_AUTONEGOTIATING 2
#define MII_STATE_AN_DONE 3
#define MII_STATE_MEDIA_SETUP 4
#define MII_STATE_LINKUP 5
#define MII_STATE_LINKDOWN 6
volatile timeout_id_t link_watcher_id;
/* multcast list management */
struct mcast_addr *mc_list;
#define RXMODE_PROMISC 0x01
#define RXMODE_ALLMULTI_REQ 0x02
#define RXMODE_MULTI_OVF 0x04
#define RXMODE_ENABLE 0x08
#define RXMODE_BITS \
"\020" \
"\004ENABLE" \
"\003MULTI_OVF" \
"\002ALLMULTI_REQ" \
"\001PROMISC"
/* statistcs */
/* pointer to local structure */
void *private;
int priv_size;
/* polling mode */
int poll_pkt_delay; /* in number of packets */
/* descriptor area */
int tx_desc_size;
int rx_desc_size;
/* configuration */
struct gem_conf {
/* name */
char gc_name[GEM_NAME_LEN];
/* specification on tx and rx dma engine */
long gc_tx_buf_align;
int gc_tx_max_frags;
int gc_tx_buf_size;
int gc_tx_buf_limit;
int gc_tx_ring_size;
int gc_tx_ring_limit;
int gc_tx_copy_thresh;
long gc_rx_buf_align;
int gc_rx_max_frags;
int gc_rx_ring_size;
int gc_rx_copy_thresh;
int gc_rx_buf_max;
int gc_rx_header_len;
int gc_io_area_size;
/* memory mapping attributes */
struct ddi_device_acc_attr gc_dev_attr;
struct ddi_device_acc_attr gc_buf_attr;
struct ddi_device_acc_attr gc_desc_attr;
/* dma attributes */
/* tx time out parameters */
/* auto negotiation capability */
int gc_flow_control;
/* MII mode */
int gc_mii_mode;
#define GEM_MODE_100BASETX 0
#define GEM_MODE_1000BASET 1
#define GEM_MODE_1000BASETX 2
/* MII link state watch parameters */
/* MII configuration */
int gc_mii_addr_min;
#define MII_ACTION_NONE 0
#define MII_ACTION_RESET 1
#define MII_ACTION_RSA 2
/* I/O methods */
/* mac operation */
/* descriptor operation */
#define GEM_TXFLAG_INTR 0x00000001ull
#define GEM_TXFLAG_TCP 0x00000002ull
#define GEM_TXFLAG_TCP_SHIFT 1ull
#define GEM_TXFLAG_UDP 0x00000004ull
#define GEM_TXFLAG_UDP_SHIFT 2ull
#define GEM_TXFLAG_IPv4 0x00000008ull
#define GEM_TXFLAG_IPv4_SHIFT 3ull
#define GEM_TXFLAG_IPv6 0x00000010ull
#define GEM_TXFLAG_IPv6_SHIFT 4ull
#define GEM_TXFLAG_HEAD 0x00000020ull
#define GEM_TXFLAG_TAIL 0x00000040ull
#define GEM_TXFLAG_SWVTAG 0x00000080ull
#define GEM_TXFLAG_PRIVATE 0x0000ff00ull
#define GEM_TXFLAG_PRIVATE_SHIFT 8ull
#define GEM_TXFLAG_PRIVATE_MASK 0xffull
#define GEM_TXFLAG_VID 0x0fff0000ull
#define GEM_TXFLAG_VID_SHIFT 16ull
#define GEM_TXFLAG_VID_MASK 0xfffull
#define GEM_TXFLAG_CFI 0x10000000ull
#define GEM_TXFLAG_PRI 0xe0000000ull
#define GEM_TXFLAG_PRI_SHIFT 29ull
#define GEM_TXFLAG_PRI_MASK 0x7ull
#define GEM_TXFLAG_VTAG 0xffff0000ull
#define GEM_TXFLAG_VTAG_SHIFT 16ull
#define GEM_TXFLAG_HCKSTART 0x000000ff00000000ull
#define GEM_TXFLAG_HCKSTART_SHIFT 32ull
#define GEM_TXFLAG_HCKSTUFF 0x0000ff0000000000ull
#define GEM_TXFLAG_HCKSTUFF_SHIFT 40ull
#define GEM_TXFLAG_TCPHLEN 0x0000ff0000000000ull
#define GEM_TXFLAG_TCPHLEN_SHIFT 40ull
#define GEM_TXFLAG_MSS 0xffff000000000000ull
#define GEM_TXFLAG_MSS_SHIFT 48ull
#define GEM_TX_DONE 0x00010000
#define GEM_TX_ERR 0x00020000
#define GEM_RX_CKSUM 0xffff000000000000ull
#define GEM_RX_CKSUM_SHIFT 48
#define GEM_RX_PRI 0x0000e00000000000ull
#define GEM_RX_PRI_SHIFT 45
#define GEM_RX_CFI 0x0000100000000000ull
#define GEM_RX_VID 0x00000fff00000000ull
#define GEM_RX_VID_SHIFT 32
#define GEM_RX_VTAG 0x0000ffff00000000ull
#define GEM_RX_VTAG_SHIFT 32
#define GEM_RX_CKSUM_IPv6 0x00080000ul
#define GEM_RX_CKSUM_IPv6_SHIFT 19
#define GEM_RX_CKSUM_IPv4 0x00040000ul
#define GEM_RX_CKSUM_IPv4_SHIFT 18
#define GEM_RX_CKSUM_UDP 0x00020000ul
#define GEM_RX_CKSUM_UDP_SHIFT 17
#define GEM_RX_CKSUM_TCP 0x00010000ul
#define GEM_RX_CKSUM_TCP_SHIFT 16
#define GEM_RX_ERR 0x00008000ul
#define GEM_RX_DONE 0x00004000ul
/* mii operations */
int gc_nports;
/* hw checksum */
} gc;
#define GEM_LSO 0x00000400
#define GEM_CTRL_PKT 0x00000200
#define GEM_SOFTINTR 0x00000100
#define GEM_POLL_RXONLY 0x00000080
#define GEM_VLAN_HARD 0x00000040
#define GEM_VLAN_SOFT 0x00000020
#define GEM_CKSUM_HEADER_IPv4 0x00000010
#define GEM_CKSUM_PARTIAL 0x00000008
#define GEM_CKSUM_FULL_IPv6 0x00000004
#define GEM_CKSUM_FULL_IPv4 0x00000002
#define GEM_NOINTR 0x00000001
volatile timeout_id_t intr_watcher_id;
/* performance tuning parameters */
/* kstat stuff */
/* multiple port device support */
int port;
/* ndd stuff */
#ifdef GEM_DEBUG_LEVEL
int tx_cnt;
#endif
};
/*
* Exported functions
*/
int gem_mii_probe_default(struct gem_dev *);
int gem_mii_config_default(struct gem_dev *);
#define GEM_RESTART_NOWAIT 0x00000002
#define GEM_RESTART_KEEP_BUF 0x00000001
int gem_receive(struct gem_dev *);
int gem_receive_copy(struct gem_dev *);
struct gem_conf *, void *, ddi_acc_handle_t *, void *, int);
#define GEM_SEND_COPY 0x00008000
#define GEM_SEND_VTAG 0xffff0000
#define GEM_SEND_VTAG_SHIFT 16
int gem_do_detach(dev_info_t *);
void gem_rx_desc_dma_sync(struct gem_dev *, int, int, int);
void gem_tx_desc_dma_sync(struct gem_dev *, int, int, int);
int gem_resume(dev_info_t *);
int gem_suspend(dev_info_t *);
void gem_mod_init(struct dev_ops *, char *);
void gem_mod_fini(struct dev_ops *);
#define GEM_GET_DEV(dip) \
#endif /* _SFE_UTIL_H_ */