xref: /openbsd/sys/arch/octeon/dev/cn30xxgmxvar.h (revision 274d7c50)
1 /*	$OpenBSD: cn30xxgmxvar.h,v 1.8 2017/11/03 16:46:17 visa Exp $	*/
2 
3 /*
4  * Copyright (c) 2007 Internet Initiative Japan, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _CN30XXGMXVAR_H_
30 #define _CN30XXGMXVAR_H_
31 
32 #include <sys/socket.h>
33 #include <net/if.h>
34 #include <net/if_media.h>
35 #include <netinet/in.h>
36 #include <netinet/if_ether.h>
37 #include <dev/mii/mii.h>
38 #include <dev/mii/miivar.h>
39 
40 #define GMX_MII_PORT	1
41 #define GMX_GMII_PORT	2
42 #define GMX_RGMII_PORT	3
43 #define GMX_SGMII_PORT	4
44 #define GMX_SPI42_PORT	5
45 
46 #define GMX_FRM_MAX_SIZ	0x600
47 
48 /* Disable 802.3x flow-control when AutoNego is enabled */
49 #define GMX_802_3X_DISABLE_AUTONEG
50 
51 
52 struct cn30xxgmx_softc;
53 struct cn30xxgmx_port_softc;
54 
55 struct cn30xxgmx_port_softc {
56 	struct cn30xxgmx_softc	*sc_port_gmx;
57 	bus_space_handle_t	sc_port_regh;
58 	int			sc_port_no;	/* GMX0:0, GMX0:1, ... */
59 	int			sc_port_type;
60 	uint64_t		sc_mac;
61 	uint64_t		sc_link;
62 	struct mii_data		*sc_port_mii;
63 	struct arpcom		*sc_port_ac;
64 	struct cn30xxgmx_port_ops
65 				*sc_port_ops;
66 	struct cn30xxasx_softc	*sc_port_asx;
67 	bus_space_handle_t	 sc_port_pcs_regh;
68 	struct cn30xxipd_softc	*sc_ipd;
69 	uint64_t		sc_port_flowflags;
70 };
71 
72 struct cn30xxgmx_softc {
73 	struct device		sc_dev;
74 
75 	bus_space_tag_t		sc_regt;
76 	bus_space_handle_t	sc_regh;
77 	int			sc_unitno;	/* GMX0, GMX1, ... */
78 	int			sc_nports;
79 	int			sc_port_types[4/* XXX */];
80 
81 	struct cn30xxgmx_port_softc
82 				*sc_ports;
83 };
84 
85 
86 struct cn30xxgmx_attach_args {
87         bus_space_tag_t         ga_regt;
88 	bus_addr_t		ga_addr;
89 	bus_dma_tag_t		ga_dmat;
90 	const char		*ga_name;
91 	int			ga_portno;
92 	int			ga_port_type;
93 	struct cn30xxsmi_softc	*ga_smi;
94 	int			ga_phy_addr;
95 
96 	struct cn30xxgmx_softc *ga_gmx;
97 	struct cn30xxgmx_port_softc
98 				*ga_gmx_port;
99 };
100 
101 int		cn30xxgmx_link_enable(struct cn30xxgmx_port_softc *, int);
102 int		cn30xxgmx_tx_stats_rd_clr(struct cn30xxgmx_port_softc *, int);
103 int		cn30xxgmx_rx_stats_rd_clr(struct cn30xxgmx_port_softc *, int);
104 void		cn30xxgmx_rx_stats_dec_bad(struct cn30xxgmx_port_softc *);
105 int		cn30xxgmx_stats_init(struct cn30xxgmx_port_softc *);
106 void		cn30xxgmx_tx_int_enable(struct cn30xxgmx_port_softc *, int);
107 void		cn30xxgmx_rx_int_enable(struct cn30xxgmx_port_softc *, int);
108 int		cn30xxgmx_rx_frm_ctl_enable(struct cn30xxgmx_port_softc *,
109 		    uint64_t rx_frm_ctl);
110 int		cn30xxgmx_rx_frm_ctl_disable(struct cn30xxgmx_port_softc *,
111 		    uint64_t rx_frm_ctl);
112 int		cn30xxgmx_tx_thresh(struct cn30xxgmx_port_softc *, int);
113 int		cn30xxgmx_set_mac_addr(struct cn30xxgmx_port_softc *, uint8_t *);
114 int		cn30xxgmx_set_filter(struct cn30xxgmx_port_softc *);
115 int		cn30xxgmx_port_enable(struct cn30xxgmx_port_softc *, int);
116 int		cn30xxgmx_reset_speed(struct cn30xxgmx_port_softc *);
117 int		cn30xxgmx_reset_flowctl(struct cn30xxgmx_port_softc *);
118 int		cn30xxgmx_reset_timing(struct cn30xxgmx_port_softc *);
119 int		cn30xxgmx_reset_board(struct cn30xxgmx_port_softc *);
120 void		cn30xxgmx_stats(struct cn30xxgmx_port_softc *);
121 uint64_t	cn30xxgmx_get_rx_int_reg(struct cn30xxgmx_port_softc *sc);
122 uint64_t	cn30xxgmx_get_tx_int_reg(struct cn30xxgmx_port_softc *sc);
123 static inline int	cn30xxgmx_link_status(struct cn30xxgmx_port_softc *);
124 
125 static inline int
126 cn30xxgmx_link_status(struct cn30xxgmx_port_softc *sc)
127 {
128 	return ((sc->sc_port_mii->mii_media_status & (IFM_AVALID | IFM_ACTIVE))
129 	    == (IFM_AVALID | IFM_ACTIVE));
130 }
131 
132 #endif
133