1/*-
2 * Copyright (c) 2003-2012 Broadcom Corporation
3 * All Rights Reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in
13 *    the documentation and/or other materials provided with the
14 *    distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30
31#ifndef __XLPGE_H__
32#define __XLPGE_H__
33
34#define	NLM_XLPGE_TXQ_SIZE	1024
35#define	MAC_CRC_LEN		4
36
37enum xlpge_link_state {
38	NLM_LINK_DOWN,
39	NLM_LINK_UP
40};
41
42enum xlpge_floctrl_status {
43	NLM_FLOWCTRL_DISABLED,
44	NLM_FLOWCTRL_ENABLED
45};
46
47struct nlm_xlp_portdata {
48	struct ifnet *xlpge_if;
49	struct nlm_xlpge_softc *xlpge_sc;
50};
51
52struct nlm_xlpnae_softc {
53	device_t	xlpnae_dev;
54	int		node;		/* XLP Node id */
55	uint64_t	base;		/* NAE IO base */
56	uint64_t	poe_base;	/* POE IO base */
57	uint64_t	poedv_base;	/* POE distribution vec IO base */
58
59	int		freq;		/* frequency of nae block */
60	int		flow_crc_poly;	/* Flow CRC16 polynomial */
61	int		total_free_desc; /* total for node */
62	int		max_ports;
63	int		total_num_ports;
64	int		per_port_num_flows;
65
66	u_int		nucores;
67	u_int		nblocks;
68	u_int		num_complex;
69	u_int		ncontexts;
70
71	/*  Ingress side parameters */
72	u_int		num_desc;	/* no of descriptors in each packet */
73	u_int		parser_threshold;/* threshold of entries above which */
74					/* the parser sequencer is scheduled */
75	/* NetIOR configs */
76	u_int		cmplx_type[8];		/* XXXJC: redundant? */
77	struct nae_port_config *portcfg;
78	u_int		blockmask;
79	u_int		portmask[XLP_NAE_NBLOCKS];
80	u_int		ilmask;
81	u_int		xauimask;
82	u_int		sgmiimask;
83	u_int		hw_parser_en;
84	u_int		prepad_en;
85	u_int		prepad_size;
86	u_int		driver_mode;
87	u_int		ieee_1588_en;
88};
89
90struct nlm_xlpge_softc {
91	struct ifnet	*xlpge_if;	/* should be first member */
92					/* see - mii.c:miibus_attach() */
93	device_t	xlpge_dev;
94	device_t	mii_bus;
95	struct nlm_xlpnae_softc *network_sc;
96	uint64_t	base_addr;	/* NAE IO base */
97	int		node;		/* node id (quickread) */
98	int		block;		/* network block id (quickread) */
99	int		port;		/* port id - among the 18 in XLP */
100	int		type;		/* port type - see xlp_gmac_port_types */
101	int		valid;		/* boolean: valid port or not */
102	struct mii_data	xlpge_mii;
103	int		nfree_desc;	/* No of free descriptors sent to port */
104	int		phy_addr;	/* PHY id for the interface */
105
106	int		speed;		/* Port speed */
107	int		duplexity;	/* Port duplexity */
108	int		link;		/* Port link status */
109	int		 flowctrl;	/* Port flow control setting */
110
111	unsigned char	dev_addr[ETHER_ADDR_LEN];
112	struct mtx	sc_lock;
113	int		if_flags;
114	struct nae_port_config *portcfg;
115	struct callout  xlpge_callout;
116	int		mdio_bus;
117	int		txq;
118	int		rxfreeq;
119	int		hw_parser_en;
120	int		prepad_en;
121	int		prepad_size;
122};
123
124#define	XLP_NTXFRAGS		16
125#define	NULL_VFBID		127
126
127struct xlpge_tx_desc {
128        uint64_t        frag[XLP_NTXFRAGS];
129};
130
131#define	XLPGE_LOCK_INIT(_sc, _name)	\
132	mtx_init(&(_sc)->sc_lock, _name, MTX_NETWORK_LOCK, MTX_DEF)
133#define	XLPGE_LOCK_DESTROY(_sc)	mtx_destroy(&(_sc)->sc_lock)
134#define	XLPGE_LOCK(_sc)		mtx_lock(&(_sc)->sc_lock)
135#define	XLPGE_UNLOCK(_sc)	mtx_unlock(&(_sc)->sc_lock)
136#define	XLPGE_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->sc_lock, MA_OWNED)
137
138#endif
139