1*dbc0da67Ssimonb /* $NetBSD: octeon_gmxvar.h,v 1.7 2020/06/23 05:17:13 simonb Exp $ */
2f693c922Shikaru
3f693c922Shikaru /*
4f693c922Shikaru * Copyright (c) 2007 Internet Initiative Japan, Inc.
5f693c922Shikaru * All rights reserved.
6f693c922Shikaru *
7f693c922Shikaru * Redistribution and use in source and binary forms, with or without
8f693c922Shikaru * modification, are permitted provided that the following conditions
9f693c922Shikaru * are met:
10f693c922Shikaru * 1. Redistributions of source code must retain the above copyright
11f693c922Shikaru * notice, this list of conditions and the following disclaimer.
12f693c922Shikaru * 2. Redistributions in binary form must reproduce the above copyright
13f693c922Shikaru * notice, this list of conditions and the following disclaimer in the
14f693c922Shikaru * documentation and/or other materials provided with the distribution.
15f693c922Shikaru *
16f693c922Shikaru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17f693c922Shikaru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f693c922Shikaru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f693c922Shikaru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20f693c922Shikaru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f693c922Shikaru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f693c922Shikaru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f693c922Shikaru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f693c922Shikaru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f693c922Shikaru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f693c922Shikaru * SUCH DAMAGE.
27f693c922Shikaru */
28f693c922Shikaru
29f693c922Shikaru #ifndef _OCTEON_GMXVAR_H_
30f693c922Shikaru #define _OCTEON_GMXVAR_H_
31f693c922Shikaru
32f693c922Shikaru #include <net/if.h>
33f693c922Shikaru #include <net/if_media.h>
34f693c922Shikaru #include <net/if_ether.h>
35f693c922Shikaru #include <dev/mii/mii.h>
36f693c922Shikaru #include <dev/mii/miivar.h>
37f693c922Shikaru
38f693c922Shikaru #define GMX_MII_PORT 1
39f693c922Shikaru #define GMX_GMII_PORT 2
40f693c922Shikaru #define GMX_RGMII_PORT 3
41*dbc0da67Ssimonb #define GMX_SGMII_PORT 4
42*dbc0da67Ssimonb #define GMX_SPI42_PORT 5
43f693c922Shikaru
44f693c922Shikaru #define GMX_FRM_MAX_SIZ 0x600
45f693c922Shikaru
463f508e4dSsimonb enum CNMAC_QUIRKS {
473f508e4dSsimonb CNMAC_QUIRKS_NO_RX_INBND = 1 << 0,
483f508e4dSsimonb CNMAC_QUIRKS_NO_PRE_ALIGN = 1 << 1,
49f693c922Shikaru };
50f693c922Shikaru
51f693c922Shikaru #if 1
523f508e4dSsimonb struct octgmx_softc;
533f508e4dSsimonb struct octgmx_port_softc;
54f693c922Shikaru
553f508e4dSsimonb struct octgmx_port_softc {
563f508e4dSsimonb struct octgmx_softc *sc_port_gmx;
57f693c922Shikaru bus_space_handle_t sc_port_regh;
58f693c922Shikaru int sc_port_no; /* GMX0:0, GMX0:1, ... */
59f693c922Shikaru int sc_port_type;
60f693c922Shikaru uint64_t sc_mac;
61f693c922Shikaru int sc_quirks;
62f693c922Shikaru uint64_t sc_link;
63f693c922Shikaru struct mii_data *sc_port_mii;
64f693c922Shikaru struct ethercom *sc_port_ec;
653f508e4dSsimonb struct octgmx_port_ops
66f693c922Shikaru *sc_port_ops;
673f508e4dSsimonb struct octasx_softc *sc_port_asx;
68*dbc0da67Ssimonb bus_space_handle_t sc_port_pcs_regh;
693f508e4dSsimonb struct octipd_softc *sc_ipd;
70f693c922Shikaru int sc_port_flowflags;
71f693c922Shikaru
72d37326b4Smrg int sc_clk_tx_setting;
73d37326b4Smrg int sc_clk_rx_setting;
74f693c922Shikaru };
75f693c922Shikaru
763f508e4dSsimonb struct octgmx_softc {
77f693c922Shikaru device_t sc_dev;
78f693c922Shikaru
79f693c922Shikaru bus_space_tag_t sc_regt;
80f693c922Shikaru bus_space_handle_t sc_regh;
81f693c922Shikaru int sc_unitno; /* GMX0, GMX1, ... */
82f693c922Shikaru int sc_nports;
83f693c922Shikaru int sc_port_types[4/* XXX */];
84f693c922Shikaru
853f508e4dSsimonb struct octgmx_port_softc
86f693c922Shikaru *sc_ports;
87f693c922Shikaru };
88f693c922Shikaru #endif
89f693c922Shikaru
903f508e4dSsimonb struct octgmx_attach_args {
91f693c922Shikaru bus_space_tag_t ga_regt;
92f693c922Shikaru bus_addr_t ga_addr;
93f693c922Shikaru const char *ga_name;
94f693c922Shikaru int ga_portno;
95f693c922Shikaru int ga_port_type;
96*dbc0da67Ssimonb struct octsmi_softc *ga_smi;
97f693c922Shikaru
983f508e4dSsimonb struct octgmx_softc *ga_gmx;
993f508e4dSsimonb struct octgmx_port_softc
100f693c922Shikaru *ga_gmx_port;
101f693c922Shikaru };
102f693c922Shikaru
103*dbc0da67Ssimonb int octgmx_port_enable(struct octgmx_port_softc *, int);
104*dbc0da67Ssimonb int octgmx_stats_init(struct octgmx_port_softc *);
105*dbc0da67Ssimonb void octgmx_stats(struct octgmx_port_softc *);
106*dbc0da67Ssimonb int octgmx_set_mac_addr(struct octgmx_port_softc *, const uint8_t *);
107*dbc0da67Ssimonb int octgmx_set_filter(struct octgmx_port_softc *);
1083f508e4dSsimonb int octgmx_tx_stats_rd_clr(struct octgmx_port_softc *, int);
1093f508e4dSsimonb int octgmx_rx_stats_rd_clr(struct octgmx_port_softc *, int);
1103f508e4dSsimonb int octgmx_reset_speed(struct octgmx_port_softc *);
1113f508e4dSsimonb int octgmx_reset_flowctl(struct octgmx_port_softc *);
1123f508e4dSsimonb int octgmx_reset_timing(struct octgmx_port_softc *);
1133f508e4dSsimonb static __inline int octgmx_link_status(struct octgmx_port_softc *);
114f693c922Shikaru
11587fd18f8Schristos static __inline int
octgmx_link_status(struct octgmx_port_softc * sc)1163f508e4dSsimonb octgmx_link_status(struct octgmx_port_softc *sc)
117f693c922Shikaru {
118*dbc0da67Ssimonb
119*dbc0da67Ssimonb return ((sc->sc_port_mii->mii_media_status & (IFM_AVALID | IFM_ACTIVE))
120*dbc0da67Ssimonb == (IFM_AVALID | IFM_ACTIVE));
121f693c922Shikaru }
122f693c922Shikaru
123b9fcd28bSsimonb #endif /* _OCTEON_GMXVAR_H_ */
124