1/*	$OpenBSD: cn30xxgmxvar.h,v 1.14 2024/05/20 23:13:33 jsg 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 AUTHORS 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 AUTHORS 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/kstat.h>
33#include <sys/socket.h>
34#include <net/if.h>
35#include <net/if_media.h>
36#include <netinet/in.h>
37#include <netinet/if_ether.h>
38#include <dev/mii/mii.h>
39#include <dev/mii/miivar.h>
40
41#include "kstat.h"
42
43#define GMX_MII_PORT	1
44#define GMX_GMII_PORT	2
45#define GMX_RGMII_PORT	3
46#define GMX_SGMII_PORT	4
47#define GMX_SPI42_PORT	5
48#define GMX_AGL_PORT	6
49
50#define GMX_FRM_MAX_SIZ	0x600
51
52/* Disable 802.3x flow-control when AutoNego is enabled */
53#define GMX_802_3X_DISABLE_AUTONEG
54
55
56struct cn30xxgmx_softc;
57struct cn30xxgmx_port_softc;
58
59struct cn30xxgmx_port_softc {
60	struct cn30xxgmx_softc	*sc_port_gmx;
61	bus_space_handle_t	sc_port_regh;
62	int			sc_port_no;	/* GMX0:0, GMX0:1, ... */
63	int			sc_port_type;
64	uint64_t		sc_link;
65	struct mii_data		*sc_port_mii;
66	struct arpcom		*sc_port_ac;
67	struct cn30xxgmx_port_ops
68				*sc_port_ops;
69	struct cn30xxasx_softc	*sc_port_asx;
70	bus_space_handle_t	 sc_port_pcs_regh;
71	struct cn30xxipd_softc	*sc_ipd;
72	uint64_t		sc_port_flowflags;
73};
74
75struct cn30xxgmx_softc {
76	struct device		sc_dev;
77
78	bus_space_tag_t		sc_regt;
79	bus_space_handle_t	sc_regh;
80	int			sc_unitno;	/* GMX0, GMX1, ... */
81	int			sc_nports;
82	int			sc_port_types[4/* XXX */];
83
84	struct cn30xxgmx_port_softc
85				*sc_ports;
86};
87
88
89struct cn30xxgmx_attach_args {
90        bus_space_tag_t         ga_regt;
91	bus_addr_t		ga_addr;
92	bus_dma_tag_t		ga_dmat;
93	const char		*ga_name;
94	int			ga_portno;
95	int			ga_port_type;
96	struct cn30xxsmi_softc	*ga_smi;
97	int			ga_phy_addr;
98
99	struct cn30xxgmx_softc *ga_gmx;
100	struct cn30xxgmx_port_softc
101				*ga_gmx_port;
102};
103
104int		cn30xxgmx_link_enable(struct cn30xxgmx_port_softc *, int);
105void		cn30xxgmx_stats_init(struct cn30xxgmx_port_softc *);
106void		cn30xxgmx_tx_int_enable(struct cn30xxgmx_port_softc *, int);
107void		cn30xxgmx_rx_int_enable(struct cn30xxgmx_port_softc *, int);
108int		cn30xxgmx_rx_frm_ctl_enable(struct cn30xxgmx_port_softc *,
109		    uint64_t rx_frm_ctl);
110int		cn30xxgmx_rx_frm_ctl_disable(struct cn30xxgmx_port_softc *,
111		    uint64_t rx_frm_ctl);
112int		cn30xxgmx_tx_thresh(struct cn30xxgmx_port_softc *, int);
113int		cn30xxgmx_set_filter(struct cn30xxgmx_port_softc *);
114int		cn30xxgmx_port_enable(struct cn30xxgmx_port_softc *, int);
115int		cn30xxgmx_reset_speed(struct cn30xxgmx_port_softc *);
116int		cn30xxgmx_reset_flowctl(struct cn30xxgmx_port_softc *);
117int		cn30xxgmx_reset_timing(struct cn30xxgmx_port_softc *);
118#if NKSTAT > 0
119void		cn30xxgmx_kstat_read(struct cn30xxgmx_port_softc *,
120		    struct kstat_kv *);
121#endif
122
123static inline int
124cn30xxgmx_link_status(struct cn30xxgmx_port_softc *sc)
125{
126	return ((sc->sc_port_mii->mii_media_status & (IFM_AVALID | IFM_ACTIVE))
127	    == (IFM_AVALID | IFM_ACTIVE));
128}
129
130#endif
131