xref: /freebsd/sys/dev/dpaa/if_dtsec.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
10aeed3e9SJustin Hibbits /*-
20aeed3e9SJustin Hibbits  * Copyright (c) 2011-2012 Semihalf.
30aeed3e9SJustin Hibbits  * All rights reserved.
40aeed3e9SJustin Hibbits  *
50aeed3e9SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
60aeed3e9SJustin Hibbits  * modification, are permitted provided that the following conditions
70aeed3e9SJustin Hibbits  * are met:
80aeed3e9SJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
90aeed3e9SJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
100aeed3e9SJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
110aeed3e9SJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
120aeed3e9SJustin Hibbits  *    documentation and/or other materials provided with the distribution.
130aeed3e9SJustin Hibbits  *
140aeed3e9SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
150aeed3e9SJustin Hibbits  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
160aeed3e9SJustin Hibbits  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
170aeed3e9SJustin Hibbits  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
180aeed3e9SJustin Hibbits  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
190aeed3e9SJustin Hibbits  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
200aeed3e9SJustin Hibbits  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
210aeed3e9SJustin Hibbits  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
220aeed3e9SJustin Hibbits  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
230aeed3e9SJustin Hibbits  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
240aeed3e9SJustin Hibbits  * SUCH DAMAGE.
250aeed3e9SJustin Hibbits  */
260aeed3e9SJustin Hibbits 
270aeed3e9SJustin Hibbits #ifndef IF_DTSEC_H_
280aeed3e9SJustin Hibbits #define IF_DTSEC_H_
290aeed3e9SJustin Hibbits 
300aeed3e9SJustin Hibbits /**
310aeed3e9SJustin Hibbits  * @group dTSEC common API.
320aeed3e9SJustin Hibbits  * @{
330aeed3e9SJustin Hibbits  */
340aeed3e9SJustin Hibbits #define DTSEC_MODE_REGULAR		0
350aeed3e9SJustin Hibbits #define DTSEC_MODE_INDEPENDENT		1
360aeed3e9SJustin Hibbits 
370aeed3e9SJustin Hibbits #define DTSEC_LOCK(sc)			mtx_lock(&(sc)->sc_lock)
380aeed3e9SJustin Hibbits #define DTSEC_UNLOCK(sc)		mtx_unlock(&(sc)->sc_lock)
390aeed3e9SJustin Hibbits #define DTSEC_LOCK_ASSERT(sc)		mtx_assert(&(sc)->sc_lock, MA_OWNED)
400aeed3e9SJustin Hibbits #define DTSEC_MII_LOCK(sc)		mtx_lock(&(sc)->sc_mii_lock)
410aeed3e9SJustin Hibbits #define DTSEC_MII_UNLOCK(sc)		mtx_unlock(&(sc)->sc_mii_lock)
420aeed3e9SJustin Hibbits 
430aeed3e9SJustin Hibbits enum eth_dev_type {
440aeed3e9SJustin Hibbits 	ETH_DTSEC = 0x1,
450aeed3e9SJustin Hibbits 	ETH_10GSEC = 0x2
460aeed3e9SJustin Hibbits };
470aeed3e9SJustin Hibbits 
480aeed3e9SJustin Hibbits struct dtsec_softc {
490aeed3e9SJustin Hibbits 	/* XXX MII bus requires that struct ifnet is first!!! */
50*0083fc5cSJustin Hibbits 	if_t				sc_ifnet;
510aeed3e9SJustin Hibbits 
520aeed3e9SJustin Hibbits 	device_t			sc_dev;
53a32b5435SJustin Hibbits 	struct resource			*sc_mem;
540aeed3e9SJustin Hibbits 	struct mtx			sc_lock;
550aeed3e9SJustin Hibbits 	int				sc_mode;
560aeed3e9SJustin Hibbits 
570aeed3e9SJustin Hibbits 	/* Methods */
580aeed3e9SJustin Hibbits 	int				(*sc_port_rx_init)
590aeed3e9SJustin Hibbits 	    (struct dtsec_softc *sc, int unit);
600aeed3e9SJustin Hibbits 	int				(*sc_port_tx_init)
610aeed3e9SJustin Hibbits 	    (struct dtsec_softc *sc, int unit);
620aeed3e9SJustin Hibbits 	void				(*sc_start_locked)
630aeed3e9SJustin Hibbits 	    (struct dtsec_softc *sc);
640aeed3e9SJustin Hibbits 
650aeed3e9SJustin Hibbits 	/* dTSEC data */
660aeed3e9SJustin Hibbits 	enum eth_dev_type		sc_eth_dev_type;
671163f061SJustin Hibbits 	uint8_t				sc_eth_id; /* Ethernet ID within its frame manager */
680aeed3e9SJustin Hibbits 	uintptr_t			sc_mac_mem_offset;
690aeed3e9SJustin Hibbits 	e_EnetMode			sc_mac_enet_mode;
700aeed3e9SJustin Hibbits 	int				sc_mac_mdio_irq;
710aeed3e9SJustin Hibbits 	uint8_t				sc_mac_addr[6];
720aeed3e9SJustin Hibbits 	int				sc_port_rx_hw_id;
730aeed3e9SJustin Hibbits 	int				sc_port_tx_hw_id;
740aeed3e9SJustin Hibbits 	uint32_t			sc_port_tx_qman_chan;
750aeed3e9SJustin Hibbits 	int				sc_phy_addr;
760aeed3e9SJustin Hibbits 	bool				sc_hidden;
7747cabd04SJustin Hibbits 	device_t			sc_mdio;
780aeed3e9SJustin Hibbits 
790aeed3e9SJustin Hibbits 	/* Params from fman_bus driver */
800aeed3e9SJustin Hibbits 	vm_offset_t			sc_fm_base;
810aeed3e9SJustin Hibbits 	t_Handle			sc_fmh;
820aeed3e9SJustin Hibbits 	t_Handle			sc_muramh;
830aeed3e9SJustin Hibbits 
840aeed3e9SJustin Hibbits 	t_Handle			sc_mach;
850aeed3e9SJustin Hibbits 	t_Handle			sc_rxph;
860aeed3e9SJustin Hibbits 	t_Handle			sc_txph;
870aeed3e9SJustin Hibbits 
880aeed3e9SJustin Hibbits 	/* MII data */
890aeed3e9SJustin Hibbits 	struct mii_data			*sc_mii;
900aeed3e9SJustin Hibbits 	device_t			sc_mii_dev;
910aeed3e9SJustin Hibbits 	struct mtx			sc_mii_lock;
920aeed3e9SJustin Hibbits 
930aeed3e9SJustin Hibbits 	struct callout			sc_tick_callout;
940aeed3e9SJustin Hibbits 
950aeed3e9SJustin Hibbits 	/* RX Pool */
960aeed3e9SJustin Hibbits 	t_Handle			sc_rx_pool;
970aeed3e9SJustin Hibbits 	uint8_t				sc_rx_bpid;
980aeed3e9SJustin Hibbits 	uma_zone_t			sc_rx_zone;
990aeed3e9SJustin Hibbits 	char				sc_rx_zname[64];
1000aeed3e9SJustin Hibbits 
1010aeed3e9SJustin Hibbits 	/* RX Frame Queue */
1020aeed3e9SJustin Hibbits 	t_Handle			sc_rx_fqr;
1030aeed3e9SJustin Hibbits 	uint32_t			sc_rx_fqid;
1040aeed3e9SJustin Hibbits 
1050aeed3e9SJustin Hibbits 	/* TX Frame Queue */
1060aeed3e9SJustin Hibbits 	t_Handle			sc_tx_fqr;
1070aeed3e9SJustin Hibbits 	bool				sc_tx_fqr_full;
1080aeed3e9SJustin Hibbits 	t_Handle			sc_tx_conf_fqr;
1090aeed3e9SJustin Hibbits 	uint32_t			sc_tx_conf_fqid;
1100aeed3e9SJustin Hibbits 
1110aeed3e9SJustin Hibbits 	/* Frame Info Zone */
1120aeed3e9SJustin Hibbits 	uma_zone_t			sc_fi_zone;
1130aeed3e9SJustin Hibbits 	char				sc_fi_zname[64];
1140aeed3e9SJustin Hibbits };
1150aeed3e9SJustin Hibbits /** @} */
1160aeed3e9SJustin Hibbits 
1170aeed3e9SJustin Hibbits 
1180aeed3e9SJustin Hibbits /**
1190aeed3e9SJustin Hibbits  * @group dTSEC FMan PORT API.
1200aeed3e9SJustin Hibbits  * @{
1210aeed3e9SJustin Hibbits  */
1220aeed3e9SJustin Hibbits enum dtsec_fm_port_params {
1230aeed3e9SJustin Hibbits 	FM_PORT_LIODN_BASE	= 0,
1240aeed3e9SJustin Hibbits 	FM_PORT_LIODN_OFFSET 	= 0,
1250aeed3e9SJustin Hibbits 	FM_PORT_MEM_ID		= 0,
1260aeed3e9SJustin Hibbits 	FM_PORT_MEM_ATTR	= MEMORY_ATTR_CACHEABLE,
1270aeed3e9SJustin Hibbits 	FM_PORT_BUFFER_SIZE	= MCLBYTES,
1280aeed3e9SJustin Hibbits };
1290aeed3e9SJustin Hibbits 
1300aeed3e9SJustin Hibbits e_FmPortType	dtsec_fm_port_rx_type(enum eth_dev_type type);
1310aeed3e9SJustin Hibbits void		dtsec_fm_port_rx_exception_callback(t_Handle app,
1320aeed3e9SJustin Hibbits 		    e_FmPortExceptions exception);
1330aeed3e9SJustin Hibbits void		dtsec_fm_port_tx_exception_callback(t_Handle app,
1340aeed3e9SJustin Hibbits 		    e_FmPortExceptions exception);
1350aeed3e9SJustin Hibbits e_FmPortType	dtsec_fm_port_tx_type(enum eth_dev_type type);
1360aeed3e9SJustin Hibbits /** @} */
1370aeed3e9SJustin Hibbits 
1380aeed3e9SJustin Hibbits 
1390aeed3e9SJustin Hibbits /**
1400aeed3e9SJustin Hibbits  * @group dTSEC bus interface.
1410aeed3e9SJustin Hibbits  * @{
1420aeed3e9SJustin Hibbits  */
1430aeed3e9SJustin Hibbits int		dtsec_attach(device_t dev);
1440aeed3e9SJustin Hibbits int		dtsec_detach(device_t dev);
1450aeed3e9SJustin Hibbits int		dtsec_suspend(device_t dev);
1460aeed3e9SJustin Hibbits int		dtsec_resume(device_t dev);
1470aeed3e9SJustin Hibbits int		dtsec_shutdown(device_t dev);
1480aeed3e9SJustin Hibbits int		dtsec_miibus_readreg(device_t dev, int phy, int reg);
1490aeed3e9SJustin Hibbits int		dtsec_miibus_writereg(device_t dev, int phy, int reg,
1500aeed3e9SJustin Hibbits 		    int value);
1510aeed3e9SJustin Hibbits void		dtsec_miibus_statchg(device_t dev);
1520aeed3e9SJustin Hibbits /** @} */
1530aeed3e9SJustin Hibbits 
1540aeed3e9SJustin Hibbits #endif /* IF_DTSEC_H_ */
155