xref: /freebsd/sys/arm/ti/cpsw/if_cpswvar.h (revision ba14258f328d4c9083657df9c24326c9448fc795)
1e53470feSOleksandr Tymoshenko /*-
2e53470feSOleksandr Tymoshenko  * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org>
3e53470feSOleksandr Tymoshenko  * All rights reserved.
4e53470feSOleksandr Tymoshenko  *
5e53470feSOleksandr Tymoshenko  * Redistribution and use in source and binary forms, with or without
6e53470feSOleksandr Tymoshenko  * modification, are permitted provided that the following conditions
7e53470feSOleksandr Tymoshenko  * are met:
8e53470feSOleksandr Tymoshenko  * 1. Redistributions of source code must retain the above copyright
9e53470feSOleksandr Tymoshenko  *    notice, this list of conditions and the following disclaimer.
10e53470feSOleksandr Tymoshenko  * 2. Redistributions in binary form must reproduce the above copyright
11e53470feSOleksandr Tymoshenko  *    notice, this list of conditions and the following disclaimer in the
12e53470feSOleksandr Tymoshenko  *    documentation and/or other materials provided with the distribution.
13e53470feSOleksandr Tymoshenko  *
14e53470feSOleksandr Tymoshenko  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15e53470feSOleksandr Tymoshenko  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16e53470feSOleksandr Tymoshenko  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17e53470feSOleksandr Tymoshenko  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18e53470feSOleksandr Tymoshenko  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19e53470feSOleksandr Tymoshenko  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20e53470feSOleksandr Tymoshenko  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21e53470feSOleksandr Tymoshenko  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22e53470feSOleksandr Tymoshenko  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23e53470feSOleksandr Tymoshenko  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24e53470feSOleksandr Tymoshenko  * SUCH DAMAGE.
25e53470feSOleksandr Tymoshenko  *
26e53470feSOleksandr Tymoshenko  * $FreeBSD$
27e53470feSOleksandr Tymoshenko  */
28e53470feSOleksandr Tymoshenko 
29e53470feSOleksandr Tymoshenko #ifndef	_IF_CPSWVAR_H
30e53470feSOleksandr Tymoshenko #define	_IF_CPSWVAR_H
31e53470feSOleksandr Tymoshenko 
3223cd11b6SLuiz Otavio O Souza #define	CPSW_PORTS		2
33e53470feSOleksandr Tymoshenko #define	CPSW_INTR_COUNT		4
34e53470feSOleksandr Tymoshenko 
35e53470feSOleksandr Tymoshenko /* MII BUS  */
36e53470feSOleksandr Tymoshenko #define	CPSW_MIIBUS_RETRIES	5
37e53470feSOleksandr Tymoshenko #define	CPSW_MIIBUS_DELAY	1000
38e53470feSOleksandr Tymoshenko 
39e53470feSOleksandr Tymoshenko #define	CPSW_MAX_ALE_ENTRIES	1024
40e53470feSOleksandr Tymoshenko 
41ae6aefafSTim Kientzle #define	CPSW_SYSCTL_COUNT	34
42ae6aefafSTim Kientzle 
435bf32555STim Kientzle struct cpsw_slot {
44ae6aefafSTim Kientzle 	uint32_t bd_offset;  /* Offset of corresponding BD within CPPI RAM. */
455bf32555STim Kientzle 	bus_dmamap_t dmamap;
469c2deddeSLuiz Otavio O Souza 	struct ifnet *ifp;
475bf32555STim Kientzle 	struct mbuf *mbuf;
485bf32555STim Kientzle 	STAILQ_ENTRY(cpsw_slot) next;
495bf32555STim Kientzle };
50ae6aefafSTim Kientzle STAILQ_HEAD(cpsw_slots, cpsw_slot);
51ae6aefafSTim Kientzle 
52ae6aefafSTim Kientzle struct cpsw_queue {
53ae6aefafSTim Kientzle 	struct mtx	lock;
54ae6aefafSTim Kientzle 	int		running;
55*ba14258fSLuiz Otavio O Souza 	int		teardown;
56ae6aefafSTim Kientzle 	struct cpsw_slots active;
57ae6aefafSTim Kientzle 	struct cpsw_slots avail;
58ae6aefafSTim Kientzle 	uint32_t	queue_adds; /* total bufs added */
59ae6aefafSTim Kientzle 	uint32_t	queue_removes; /* total bufs removed */
60ae6aefafSTim Kientzle 	uint32_t	queue_removes_at_last_tick; /* Used by watchdog */
61*ba14258fSLuiz Otavio O Souza 	uint32_t	queue_restart;
62ae6aefafSTim Kientzle 	int		queue_slots;
63ae6aefafSTim Kientzle 	int		active_queue_len;
64ae6aefafSTim Kientzle 	int		max_active_queue_len;
65ae6aefafSTim Kientzle 	int		avail_queue_len;
66ae6aefafSTim Kientzle 	int		max_avail_queue_len;
67ae6aefafSTim Kientzle 	int		longest_chain; /* Largest # segments in a single packet. */
68ae6aefafSTim Kientzle 	int		hdp_offset;
69ae6aefafSTim Kientzle };
705bf32555STim Kientzle 
7123cd11b6SLuiz Otavio O Souza struct cpsw_port {
72e53470feSOleksandr Tymoshenko 	device_t	dev;
7323cd11b6SLuiz Otavio O Souza 	int		phy;
7423cd11b6SLuiz Otavio O Souza 	int		vlan;
7523cd11b6SLuiz Otavio O Souza };
7623cd11b6SLuiz Otavio O Souza 
7723cd11b6SLuiz Otavio O Souza struct cpsw_softc {
7823cd11b6SLuiz Otavio O Souza 	device_t	dev;
7923cd11b6SLuiz Otavio O Souza 	int		active_slave;
8023cd11b6SLuiz Otavio O Souza 	int		debug;
8123cd11b6SLuiz Otavio O Souza 	int		dualemac;
82*ba14258fSLuiz Otavio O Souza 	int		rx_batch;
8323cd11b6SLuiz Otavio O Souza 	phandle_t	node;
84ae6aefafSTim Kientzle 	struct bintime	attach_uptime; /* system uptime when attach happened. */
8523cd11b6SLuiz Otavio O Souza 	struct cpsw_port port[2];
86feeb22f3SLuiz Otavio O Souza 	unsigned	coal_us;
87ae6aefafSTim Kientzle 
8823cd11b6SLuiz Otavio O Souza 	/* RX and TX buffer tracking */
8923cd11b6SLuiz Otavio O Souza 	struct cpsw_queue rx, tx;
90ae6aefafSTim Kientzle 
91ae6aefafSTim Kientzle 	/* We expect 1 memory resource and 4 interrupts from the device tree. */
925b03aba6SOleksandr Tymoshenko 	int		mem_rid;
9323cd11b6SLuiz Otavio O Souza 	struct resource	*mem_res;
945b03aba6SOleksandr Tymoshenko 	struct resource	*irq_res[CPSW_INTR_COUNT];
9523cd11b6SLuiz Otavio O Souza 	void		*ih_cookie[CPSW_INTR_COUNT];
96e53470feSOleksandr Tymoshenko 
97ae6aefafSTim Kientzle 	/* An mbuf full of nulls for TX padding. */
98ae6aefafSTim Kientzle 	bus_dmamap_t null_mbuf_dmamap;
99ae6aefafSTim Kientzle 	struct mbuf *null_mbuf;
100ae6aefafSTim Kientzle 	bus_addr_t null_mbuf_paddr;
101e53470feSOleksandr Tymoshenko 
10223cd11b6SLuiz Otavio O Souza 	bus_dma_tag_t	mbuf_dtag;
10323cd11b6SLuiz Otavio O Souza 
10423cd11b6SLuiz Otavio O Souza 	struct {
10523cd11b6SLuiz Otavio O Souza 		int resets;
10623cd11b6SLuiz Otavio O Souza 		int timer;
10723cd11b6SLuiz Otavio O Souza 		struct callout  callout;
10823cd11b6SLuiz Otavio O Souza 	} watchdog;
1095bf32555STim Kientzle 
110ae6aefafSTim Kientzle 	/* 64-bit versions of 32-bit hardware statistics counters */
111ae6aefafSTim Kientzle 	uint64_t shadow_stats[CPSW_SYSCTL_COUNT];
112ae6aefafSTim Kientzle 
113ae6aefafSTim Kientzle 	/* CPPI STATERAM has 512 slots for building TX/RX queues. */
114ae6aefafSTim Kientzle 	/* TODO: Size here supposedly varies with different versions
115ae6aefafSTim Kientzle 	   of the controller.  Check DaVinci specs and find a good
116ae6aefafSTim Kientzle 	   way to adjust this.  One option is to have a separate
117ae6aefafSTim Kientzle 	   Device Tree parameter for number slots; another option
118ae6aefafSTim Kientzle 	   is to calculate it from the memory size in the device tree. */
119ae6aefafSTim Kientzle 	struct cpsw_slot _slots[CPSW_CPPI_RAM_SIZE / sizeof(struct cpsw_cpdma_bd)];
120ae6aefafSTim Kientzle 	struct cpsw_slots avail;
121e53470feSOleksandr Tymoshenko };
122e53470feSOleksandr Tymoshenko 
12323cd11b6SLuiz Otavio O Souza struct cpswp_softc {
12423cd11b6SLuiz Otavio O Souza 	device_t	dev;
12523cd11b6SLuiz Otavio O Souza 	device_t	miibus;
12623cd11b6SLuiz Otavio O Souza 	device_t	pdev;
12723cd11b6SLuiz Otavio O Souza 	int		media_status;
12823cd11b6SLuiz Otavio O Souza 	int		unit;
12923cd11b6SLuiz Otavio O Souza 	int		vlan;
13023cd11b6SLuiz Otavio O Souza 	struct bintime	init_uptime; /* system uptime when init happened. */
13123cd11b6SLuiz Otavio O Souza 	struct callout	mii_callout;
13223cd11b6SLuiz Otavio O Souza 	struct cpsw_softc *swsc;
13323cd11b6SLuiz Otavio O Souza 	struct ifnet	*ifp;
13423cd11b6SLuiz Otavio O Souza 	struct mii_data	*mii;
13523cd11b6SLuiz Otavio O Souza 	struct mtx	lock;
13623cd11b6SLuiz Otavio O Souza 	uint32_t	if_flags;
13723cd11b6SLuiz Otavio O Souza 	uint32_t	phy;
13823cd11b6SLuiz Otavio O Souza 	uint32_t	phyaccess;
13923cd11b6SLuiz Otavio O Souza 	uint32_t	physel;
14023cd11b6SLuiz Otavio O Souza };
14123cd11b6SLuiz Otavio O Souza 
142e53470feSOleksandr Tymoshenko #endif /*_IF_CPSWVAR_H */
143