octeon_gmxvar.h revision 1.2 1 /* $NetBSD: octeon_gmxvar.h,v 1.2 2018/04/19 21:50:06 christos 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 _OCTEON_GMXVAR_H_
30 #define _OCTEON_GMXVAR_H_
31
32 #include "opt_octeon.h"
33
34 #include <net/if.h>
35 #include <net/if_media.h>
36 #include <net/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_SPI42_PORT 4
44
45 #define GMX_FRM_MAX_SIZ 0x600
46
47 enum OCTEON_ETH_QUIRKS {
48 OCTEON_ETH_QUIRKS_NO_RX_INBND = 1 << 0,
49 OCTEON_ETH_QUIRKS_NO_PRE_ALIGN = 1 << 1,
50 };
51
52 #if 1
53 struct octeon_gmx_softc;
54 struct octeon_gmx_port_softc;
55
56 struct octeon_gmx_port_softc {
57 struct octeon_gmx_softc *sc_port_gmx;
58 bus_space_handle_t sc_port_regh;
59 int sc_port_no; /* GMX0:0, GMX0:1, ... */
60 int sc_port_type;
61 uint64_t sc_mac;
62 int sc_quirks;
63 uint64_t sc_link;
64 struct mii_data *sc_port_mii;
65 struct ethercom *sc_port_ec;
66 struct octeon_gmx_port_ops
67 *sc_port_ops;
68 struct octeon_asx_softc *sc_port_asx;
69 struct octeon_ipd_softc *sc_ipd;
70 int sc_port_flowflags;
71
72 #if defined(OCTEON_DEBUG) || defined(OCTEON_ETH_DEBUG)
73 #if 0
74 /* XXX */
75 struct evcnt sc_ev_pausedrp;
76 struct evcnt sc_ev_phydupx;
77 struct evcnt sc_ev_physpd;
78 struct evcnt sc_ev_phylink;
79 #endif
80 struct evcnt sc_ev_ifgerr;
81 struct evcnt sc_ev_coldet;
82 struct evcnt sc_ev_falerr;
83 struct evcnt sc_ev_rcverr;
84 struct evcnt sc_ev_rsverr;
85 struct evcnt sc_ev_pckterr;
86 struct evcnt sc_ev_ovrerr;
87 struct evcnt sc_ev_niberr;
88 struct evcnt sc_ev_skperr;
89 struct evcnt sc_ev_lenerr;
90 struct evcnt sc_ev_alnerr;
91 struct evcnt sc_ev_fcserr;
92 struct evcnt sc_ev_jabber;
93 struct evcnt sc_ev_maxerr;
94 struct evcnt sc_ev_carext;
95 struct evcnt sc_ev_minerr;
96 #endif
97 };
98
99 struct octeon_gmx_softc {
100 device_t sc_dev;
101
102 bus_space_tag_t sc_regt;
103 bus_space_handle_t sc_regh;
104 int sc_unitno; /* GMX0, GMX1, ... */
105 int sc_nports;
106 int sc_port_types[4/* XXX */];
107
108 struct octeon_gmx_port_softc
109 *sc_ports;
110
111 #if defined(OCTEON_DEBUG) || defined(OCTEON_ETH_DEBUG)
112 struct evcnt sc_ev_latecol;
113 struct evcnt sc_ev_xsdef;
114 struct evcnt sc_ev_xscol;
115 struct evcnt sc_ev_undflw;
116 struct evcnt sc_ev_pkonxa;
117 #endif
118 };
119 #endif
120
121 struct octeon_gmx_attach_args {
122 bus_space_tag_t ga_regt;
123 bus_addr_t ga_addr;
124 const char *ga_name;
125 int ga_portno;
126 int ga_port_type;
127
128 struct octeon_gmx_softc *ga_gmx;
129 struct octeon_gmx_port_softc
130 *ga_gmx_port;
131 };
132
133 #define CN30XXGMX_FILTER_NADDRS_MAX 8 /* XXX elsewhere */
134
135 enum CN30XXGMX_FILTER_POLICY {
136 CN30XXGMX_FILTER_POLICY_ACCEPT_ALL,
137 CN30XXGMX_FILTER_POLICY_ACCEPT,
138 CN30XXGMX_FILTER_POLICY_REJECT,
139 CN30XXGMX_FILTER_POLICY_REJECT_ALL
140 };
141
142 int octeon_gmx_link_enable(struct octeon_gmx_port_softc *, int);
143 int octeon_gmx_tx_stats_rd_clr(struct octeon_gmx_port_softc *, int);
144 int octeon_gmx_rx_stats_rd_clr(struct octeon_gmx_port_softc *, int);
145 void octeon_gmx_rx_stats_dec_bad(struct octeon_gmx_port_softc *);
146 int octeon_gmx_stats_init(struct octeon_gmx_port_softc *);
147 void octeon_gmx_tx_int_enable(struct octeon_gmx_port_softc *, int);
148 void octeon_gmx_rx_int_enable(struct octeon_gmx_port_softc *, int);
149 int octeon_gmx_setfilt(struct octeon_gmx_port_softc *,
150 enum CN30XXGMX_FILTER_POLICY, size_t, uint8_t **);
151 int octeon_gmx_rx_frm_ctl_enable(struct octeon_gmx_port_softc *,
152 uint64_t rx_frm_ctl);
153 int octeon_gmx_rx_frm_ctl_disable(struct octeon_gmx_port_softc *,
154 uint64_t rx_frm_ctl);
155 int octeon_gmx_tx_thresh(struct octeon_gmx_port_softc *, int);
156 int octeon_gmx_set_mac_addr(struct octeon_gmx_port_softc *, uint8_t *);
157 int octeon_gmx_set_filter(struct octeon_gmx_port_softc *);
158 int octeon_gmx_port_enable(struct octeon_gmx_port_softc *, int);
159 int octeon_gmx_reset_speed(struct octeon_gmx_port_softc *);
160 int octeon_gmx_reset_flowctl(struct octeon_gmx_port_softc *);
161 int octeon_gmx_reset_timing(struct octeon_gmx_port_softc *);
162 int octeon_gmx_reset_board(struct octeon_gmx_port_softc *);
163 void octeon_gmx_stats(struct octeon_gmx_port_softc *);
164 uint64_t octeon_gmx_get_rx_int_reg(struct octeon_gmx_port_softc *sc);
165 uint64_t octeon_gmx_get_tx_int_reg(struct octeon_gmx_port_softc *sc);
166 static __inline int octeon_gmx_link_status(struct octeon_gmx_port_softc *);
167
168 /* XXX RGMII specific */
169 static __inline int
170 octeon_gmx_link_status(struct octeon_gmx_port_softc *sc)
171 {
172 return (sc->sc_link & RXN_RX_INBND_STATUS) ? 1 : 0;
173 }
174
175 #endif
176