2 * drivers/net/ibm_emac/ibm_emac_mal.h
4 * Memory Access Layer (MAL) support
6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
9 * Based on original work by
10 * Armin Kuster <akuster@mvista.com>
11 * Copyright 2002 MontaVista Softare Inc.
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 #ifndef __IBM_EMAC_MAL_H_
20 #define __IBM_EMAC_MAL_H_
22 #include <linux/init.h>
23 #include <linux/list.h>
24 #include <linux/netdevice.h>
29 * These MAL "versions" probably aren't the real versions IBM uses for these
30 * MAL cores, I assigned them just to make #ifdefs in this file nicer and
31 * reflect the fact that 40x and 44x have slightly different MALs. --ebs
33 #if defined(CONFIG_405GP) || defined(CONFIG_405GPR) || defined(CONFIG_405EP) || \
34 defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_NP405H)
36 #elif defined(CONFIG_440GP) || defined(CONFIG_440GX) || defined(CONFIG_440SP) || \
37 defined(CONFIG_440SPE)
40 #error "Unknown SoC, please check chip manual and choose MAL 'version'"
43 /* MALx DCR registers */
45 #define MAL_CFG_SR 0x80000000
46 #define MAL_CFG_PLBB 0x00004000
47 #define MAL_CFG_OPBBL 0x00000080
48 #define MAL_CFG_EOPIE 0x00000004
49 #define MAL_CFG_LEA 0x00000002
50 #define MAL_CFG_SD 0x00000001
52 #define MAL_CFG_PLBP_MASK 0x00c00000
53 #define MAL_CFG_PLBP_10 0x00800000
54 #define MAL_CFG_GA 0x00200000
55 #define MAL_CFG_OA 0x00100000
56 #define MAL_CFG_PLBLE 0x00080000
57 #define MAL_CFG_PLBT_MASK 0x00078000
58 #define MAL_CFG_DEFAULT (MAL_CFG_PLBP_10 | MAL_CFG_PLBT_MASK)
59 #elif MAL_VERSION == 2
60 #define MAL_CFG_RPP_MASK 0x00c00000
61 #define MAL_CFG_RPP_10 0x00800000
62 #define MAL_CFG_RMBS_MASK 0x00300000
63 #define MAL_CFG_WPP_MASK 0x000c0000
64 #define MAL_CFG_WPP_10 0x00080000
65 #define MAL_CFG_WMBS_MASK 0x00030000
66 #define MAL_CFG_PLBLE 0x00008000
67 #define MAL_CFG_DEFAULT (MAL_CFG_RMBS_MASK | MAL_CFG_WMBS_MASK | \
68 MAL_CFG_RPP_10 | MAL_CFG_WPP_10)
70 #error "Unknown MAL version"
74 #define MAL_ESR_EVB 0x80000000
75 #define MAL_ESR_CIDT 0x40000000
76 #define MAL_ESR_CID_MASK 0x3e000000
77 #define MAL_ESR_CID_SHIFT 25
78 #define MAL_ESR_DE 0x00100000
79 #define MAL_ESR_OTE 0x00040000
80 #define MAL_ESR_OSE 0x00020000
81 #define MAL_ESR_PEIN 0x00010000
82 #define MAL_ESR_DEI 0x00000010
83 #define MAL_ESR_OTEI 0x00000004
84 #define MAL_ESR_OSEI 0x00000002
85 #define MAL_ESR_PBEI 0x00000001
87 #define MAL_ESR_ONE 0x00080000
88 #define MAL_ESR_ONEI 0x00000008
89 #elif MAL_VERSION == 2
90 #define MAL_ESR_PTE 0x00800000
91 #define MAL_ESR_PRE 0x00400000
92 #define MAL_ESR_PWE 0x00200000
93 #define MAL_ESR_PTEI 0x00000080
94 #define MAL_ESR_PREI 0x00000040
95 #define MAL_ESR_PWEI 0x00000020
97 #error "Unknown MAL version"
101 #define MAL_IER_DE 0x00000010
102 #define MAL_IER_OTE 0x00000004
103 #define MAL_IER_OE 0x00000002
104 #define MAL_IER_PE 0x00000001
106 #define MAL_IER_NWE 0x00000008
107 #define MAL_IER_SOC_EVENTS MAL_IER_NWE
108 #elif MAL_VERSION == 2
109 #define MAL_IER_PT 0x00000080
110 #define MAL_IER_PRE 0x00000040
111 #define MAL_IER_PWE 0x00000020
112 #define MAL_IER_SOC_EVENTS (MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE)
114 #error "Unknown MAL version"
116 #define MAL_IER_EVENTS (MAL_IER_SOC_EVENTS | MAL_IER_OTE | \
117 MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
119 #define MAL_TXCASR 0x04
120 #define MAL_TXCARR 0x05
121 #define MAL_TXEOBISR 0x06
122 #define MAL_TXDEIR 0x07
123 #define MAL_RXCASR 0x10
124 #define MAL_RXCARR 0x11
125 #define MAL_RXEOBISR 0x12
126 #define MAL_RXDEIR 0x13
127 #define MAL_TXCTPR(n) ((n) + 0x20)
128 #define MAL_RXCTPR(n) ((n) + 0x40)
129 #define MAL_RCBS(n) ((n) + 0x60)
131 /* In reality MAL can handle TX buffers up to 4095 bytes long,
132 * but this isn't a good round number :) --ebs
134 #define MAL_MAX_TX_SIZE 4080
135 #define MAL_MAX_RX_SIZE 4080
137 static inline int mal_rx_size(int len)
139 len = (len + 0xf) & ~0xf;
140 return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len;
143 static inline int mal_tx_chunks(int len)
145 return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE;
148 #define MAL_CHAN_MASK(n) (0x80000000 >> (n))
150 /* MAL Buffer Descriptor structure */
151 struct mal_descriptor {
152 u16 ctrl; /* MAL / Commac status control bits */
153 u16 data_len; /* Max length is 4K-1 (12 bits) */
154 u32 data_ptr; /* pointer to actual data buffer */
157 /* the following defines are for the MadMAL status and control registers. */
158 /* MADMAL transmit and receive status/control bits */
159 #define MAL_RX_CTRL_EMPTY 0x8000
160 #define MAL_RX_CTRL_WRAP 0x4000
161 #define MAL_RX_CTRL_CM 0x2000
162 #define MAL_RX_CTRL_LAST 0x1000
163 #define MAL_RX_CTRL_FIRST 0x0800
164 #define MAL_RX_CTRL_INTR 0x0400
165 #define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST)
166 #define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE)
168 #define MAL_TX_CTRL_READY 0x8000
169 #define MAL_TX_CTRL_WRAP 0x4000
170 #define MAL_TX_CTRL_CM 0x2000
171 #define MAL_TX_CTRL_LAST 0x1000
172 #define MAL_TX_CTRL_INTR 0x0400
174 struct mal_commac_ops {
175 void (*poll_tx) (void *dev);
176 int (*poll_rx) (void *dev, int budget);
177 int (*peek_rx) (void *dev);
178 void (*rxde) (void *dev);
182 struct mal_commac_ops *ops;
184 struct list_head poll_list;
189 struct list_head list;
195 struct list_head poll_list;
196 struct net_device poll_dev;
198 struct list_head list;
203 struct mal_descriptor *bd_virt;
208 static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
210 return mfdcr(mal->dcrbase + reg);
213 static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
215 mtdcr(mal->dcrbase + reg, val);
218 /* Register MAL devices */
219 int mal_init(void) __init;
220 void mal_exit(void) __exit;
222 int mal_register_commac(struct ibm_ocp_mal *mal,
223 struct mal_commac *commac) __init;
224 void mal_unregister_commac(struct ibm_ocp_mal *mal,
225 struct mal_commac *commac) __exit;
226 int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size);
228 /* Returns BD ring offset for a particular channel
229 (in 'struct mal_descriptor' elements)
231 int mal_tx_bd_offset(struct ibm_ocp_mal *mal, int channel);
232 int mal_rx_bd_offset(struct ibm_ocp_mal *mal, int channel);
234 void mal_enable_tx_channel(struct ibm_ocp_mal *mal, int channel);
235 void mal_disable_tx_channel(struct ibm_ocp_mal *mal, int channel);
236 void mal_enable_rx_channel(struct ibm_ocp_mal *mal, int channel);
237 void mal_disable_rx_channel(struct ibm_ocp_mal *mal, int channel);
239 /* Add/remove EMAC to/from MAL polling list */
240 void mal_poll_add(struct ibm_ocp_mal *mal, struct mal_commac *commac);
241 void mal_poll_del(struct ibm_ocp_mal *mal, struct mal_commac *commac);
243 /* Ethtool MAL registers */
244 struct ibm_mal_regs {
264 int mal_get_regs_len(struct ibm_ocp_mal *mal);
265 void *mal_dump_regs(struct ibm_ocp_mal *mal, void *buf);
267 #endif /* __IBM_EMAC_MAL_H_ */