1 /*
2  * ibm_ocp_enet.h
3  *
4  * Ethernet driver for the built in ethernet on the IBM 405 PowerPC
5  * processor.
6  *
7  *      Armin Kuster akuster@mvista.com
8  *      Sept, 2001
9  *
10  *      Orignial driver
11  *         Johnnie Peters
12  *         jpeters@mvista.com
13  *
14  * Copyright 2000 MontaVista Softare Inc.
15  *
16  * This program is free software; you can redistribute  it and/or modify it
17  *  under  the terms of  the GNU General  Public License as published by the
18  *  Free Software Foundation;  either version 2 of the  License, or (at your
19  *  option) any later version.
20  *
21  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR   IMPLIED
22  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
23  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
24  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT,  INDIRECT,
25  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
27  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  *  You should have received a copy of the  GNU General Public License along
33  *  with this program; if not, write  to the Free Software Foundation, Inc.,
34  *  675 Mass Ave, Cambridge, MA 02139, USA.
35  *
36  *  Version: 1.0: Name change - armin
37  *  Version: 1.0: Added extern prototypes for new mal func. - David M.
38  *  		: removed #ifdef for irqs.i - Armin
39  *  		: added irq_resourse to private data struct.
40  *
41  *  Version: 1.1: Added new min/max value for phy & removed unused phy_id_done - *			- andrew May
42  *  Version: 1.2: added all emac extern protos here - Armin
43  *
44  *  Version: 1.3: Using CONFIG_IBM_OCP_ZMII instead of ZMII_NUMS > 0
45  *
46  *  Version: 1.3: Name change *_driver to *_dev
47  *  Version: 1.4: removed irq_resource & BL_* defines
48  *
49  */
50 
51 #ifndef _IBM_OCP_ENET_H_
52 #define _IBM_OCP_ENET_H_
53 
54 #include <linux/netdevice.h>
55 #include <asm/ocp.h>
56 #include <asm/mmu.h>		/* For phys_addr_t */
57 
58 #include "ibm_emac.h"
59 #include "ibm_ocp_phy.h"
60 #include "ibm_ocp_zmii.h"
61 #include "ibm_ocp_mal.h"
62 
63 #ifndef CONFIG_IBM_OCP_ENET_TX_BUFF
64 #define NUM_TX_BUFF		64
65 #define NUM_RX_BUFF		64
66 #else
67 #define NUM_TX_BUFF		CONFIG_IBM_OCP_ENET_TX_BUFF
68 #define NUM_RX_BUFF		CONFIG_IBM_OCP_ENET_RX_BUFF
69 #endif
70 
71 /* This does 16 byte alignment, exactly what we need.
72  * The packet length includes FCS, but we don't want to
73  * include that when passing upstream as it messes up
74  * bridging applications.
75  */
76 #ifndef CONFIG_IBM_OCP_ENET_SKB_RES
77 #define SKB_RES 2
78 #else
79 #define SKB_RES CONFIG_IBM_OCP_ENET_SKB_RES
80 #endif
81 
82 /* Note about alignement. alloc_skb() returns a cache line
83  * aligned buffer. However, dev_alloc_skb() will add 16 more
84  * bytes and "reserve" them, so our buffer will actually end
85  * on a half cache line. What we do is to use directly
86  * alloc_skb, allocate 16 more bytes to match the total amount
87  * allocated by dev_alloc_skb(), but we don't reserve.
88  */
89 #define MAX_NUM_BUF_DESC	255
90 #define DESC_RX_BUF_SIZE	1536
91 #define DESC_BUF_SIZE_REG	(DESC_RX_BUF_SIZE / 16)
92 
93 /* Transmitter timeout. */
94 #define TX_TIMEOUT		(2*HZ)
95 #define OCP_RESET_DELAY		50
96 #define MDIO_DELAY		2
97 
98 /* Power managment shift registers */
99 #define IBM_CPM_EMMII	0	/* Shift value for MII */
100 #define IBM_CPM_EMRX	1	/* Shift value for recv */
101 #define IBM_CPM_EMTX	2	/* Shift value for MAC */
102 #define IBM_CPM_EMAC(x)	(((x)>>IBM_CPM_EMMII) | ((x)>>IBM_CPM_EMRX) | ((x)>>IBM_CPM_EMTX))
103 
104 #ifdef CONFIG_IBM_OCP_ENET_ERROR_MSG
105 void emac_serr_dump_0(struct net_device *dev);
106 void emac_serr_dump_1(struct net_device *dev);
107 void emac_err_dump(struct net_device *dev, int em0isr);
108 void emac_phy_dump(struct net_device *);
109 void emac_desc_dump(struct net_device *);
110 void emac_mac_dump(struct net_device *);
111 void emac_mal_dump(struct net_device *);
112 #else
113 #define emac_serr_dump_0(dev) do { } while (0)
114 #define emac_serr_dump_1(dev) do { } while (0)
115 #define emac_err_dump(dev,x) do { } while (0)
116 #define emac_phy_dump(dev) do { } while (0)
117 #define emac_desc_dump(dev) do { } while (0)
118 #define emac_mac_dump(dev) do { } while (0)
119 #define emac_mal_dump(dev) do { } while (0)
120 #endif
121 
122 
123 struct ocp_enet_private {
124 	struct sk_buff *tx_skb[NUM_TX_BUFF];
125 	struct sk_buff *rx_skb[NUM_RX_BUFF];
126 	struct mal_descriptor *tx_desc;
127 	struct mal_descriptor *rx_desc;
128 	struct mal_descriptor *rx_dirty;
129 	struct net_device_stats stats;
130 	int tx_cnt;
131 	int rx_slot;
132 	int dirty_rx;
133 	int tx_slot;
134 	int ack_slot;
135 
136 	struct mii_phy phy_mii;
137         int mii_phy_addr;
138         int want_autoneg;
139         int timer_ticks;
140 	struct timer_list link_timer;
141 	struct net_device *mdio_dev;
142 
143 	struct ocp_device *zmii_dev;
144 	int zmii_input;
145 
146 	struct ibm_ocp_mal *mal;
147 	int mal_tx_chan, mal_rx_chan;
148 	struct mal_commac commac;
149 
150         int opened;
151         int going_away;
152         int wol_irq;
153 	volatile emac_t *emacp;
154 	struct ocp_device *ocpdev;
155         struct net_device *ndev;
156         spinlock_t lock;
157 };
158 
159 
160 #endif				/* _IBM_OCP_ENET_H_ */
161