xref: /freebsd/sys/arm/ti/cpsw/if_cpswvar.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org>
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 AUTHOR 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 AUTHOR 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	_IF_CPSWVAR_H
30 #define	_IF_CPSWVAR_H
31 
32 #define	CPSW_PORTS		2
33 #define	CPSW_INTR_COUNT		4
34 
35 /* MII BUS  */
36 #define	CPSW_MIIBUS_RETRIES	20
37 #define	CPSW_MIIBUS_DELAY	100
38 
39 #define	CPSW_MAX_ALE_ENTRIES	1024
40 
41 #define	CPSW_SYSCTL_COUNT	34
42 
43 #ifdef CPSW_ETHERSWITCH
44 #define	CPSW_CPU_PORT		0
45 #define	CPSW_PORTS_MASK		0x7
46 #define	CPSW_VLANS		128	/* Arbitrary number. */
47 
48 struct cpsw_vlangroups {
49 	int vid;
50 };
51 #endif
52 
53 struct cpsw_slot {
54 	uint32_t bd_offset;  /* Offset of corresponding BD within CPPI RAM. */
55 	bus_dmamap_t dmamap;
56 	if_t ifp;
57 	struct mbuf *mbuf;
58 	STAILQ_ENTRY(cpsw_slot) next;
59 };
60 STAILQ_HEAD(cpsw_slots, cpsw_slot);
61 
62 struct cpsw_queue {
63 	struct mtx	lock;
64 	int		running;
65 	int		teardown;
66 	struct cpsw_slots active;
67 	struct cpsw_slots avail;
68 	uint32_t	queue_adds; /* total bufs added */
69 	uint32_t	queue_removes; /* total bufs removed */
70 	uint32_t	queue_removes_at_last_tick; /* Used by watchdog */
71 	uint32_t	queue_restart;
72 	int		queue_slots;
73 	int		active_queue_len;
74 	int		max_active_queue_len;
75 	int		avail_queue_len;
76 	int		max_avail_queue_len;
77 	int		longest_chain; /* Largest # segments in a single packet. */
78 	int		hdp_offset;
79 };
80 
81 struct cpsw_port {
82 	device_t	dev;
83 	int		phy;
84 	int		vlan;
85 };
86 
87 struct cpsw_softc {
88 	device_t	dev;
89 	int		active_slave;
90 	int		debug;
91 	int		dualemac;
92 	phandle_t	node;
93 	struct bintime	attach_uptime; /* system uptime when attach happened. */
94 	struct cpsw_port port[2];
95 	unsigned	coal_us;
96 
97 	/* RX and TX buffer tracking */
98 	struct cpsw_queue rx, tx;
99 
100 	/* We expect 1 memory resource and 4 interrupts from the device tree. */
101 	int		mem_rid;
102 	struct resource	*mem_res;
103 	struct resource	*irq_res[CPSW_INTR_COUNT];
104 	void		*ih_cookie[CPSW_INTR_COUNT];
105 
106 	/* A buffer full of nulls for TX padding. */
107 	void		*nullpad;
108 
109 	bus_dma_tag_t	mbuf_dtag;
110 
111 	struct {
112 		int resets;
113 		int timer;
114 		struct callout  callout;
115 	} watchdog;
116 
117 	/* 64-bit versions of 32-bit hardware statistics counters */
118 	uint64_t shadow_stats[CPSW_SYSCTL_COUNT];
119 
120 	/* CPPI STATERAM has 512 slots for building TX/RX queues. */
121 	/* TODO: Size here supposedly varies with different versions
122 	   of the controller.  Check DaVinci specs and find a good
123 	   way to adjust this.  One option is to have a separate
124 	   Device Tree parameter for number slots; another option
125 	   is to calculate it from the memory size in the device tree. */
126 	struct cpsw_slot _slots[CPSW_CPPI_RAM_SIZE / sizeof(struct cpsw_cpdma_bd)];
127 	struct cpsw_slots avail;
128 };
129 
130 struct cpswp_softc {
131 	device_t	dev;
132 	device_t	miibus;
133 	device_t	pdev;
134 	int		media_status;
135 	int		unit;
136 	int		vlan;
137 	struct bintime	init_uptime; /* system uptime when init happened. */
138 	struct callout	mii_callout;
139 	struct cpsw_softc *swsc;
140 	if_t		ifp;
141 	struct mii_data	*mii;
142 	struct mtx	lock;
143 	uint32_t	if_flags;
144 	uint32_t	phy;
145 	uint32_t	phyaccess;
146 	uint32_t	physel;
147 };
148 
149 #endif /*_IF_CPSWVAR_H */
150