2 * Copyright 2000 MontaVista Software Inc.
3 * Author: MontaVista Software, Inc.
4 * stevel@mvista.com or source@mvista.com
6 * ########################################################################
8 * This program is free software; you can distribute it and/or modify it
9 * under the terms of the GNU General Public License (Version 2) as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
21 * ########################################################################
23 * Ethernet driver definitions for the MIPS GT96100 Advanced
24 * Communication Controller.
30 #include <asm/galileo-boards/gt96100.h>
32 #define dbg(lvl, format, arg...) \
33 if (lvl <= GT96100_DEBUG) \
34 printk(KERN_DEBUG "%s: " format, dev->name , ## arg)
35 #define err(format, arg...) \
36 printk(KERN_ERR "%s: " format, dev->name , ## arg)
37 #define info(format, arg...) \
38 printk(KERN_INFO "%s: " format, dev->name , ## arg)
39 #define warn(format, arg...) \
40 printk(KERN_WARNING "%s: " format, dev->name , ## arg)
42 /* Keep the ring sizes a power of two for efficiency. */
43 #define TX_RING_SIZE 16
44 #define RX_RING_SIZE 32
45 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
47 #define RX_HASH_TABLE_SIZE 16384
48 #define HASH_HOP_NUMBER 12
50 #define NUM_INTERFACES 2
52 #define GT96100ETH_TX_TIMEOUT HZ/4
54 #define GT96100_ETH0_BASE (MIPS_GT96100_BASE + GT96100_ETH_PORT_CONFIG)
55 #define GT96100_ETH1_BASE (GT96100_ETH0_BASE + GT96100_ETH_IO_SIZE)
57 #ifdef CONFIG_MIPS_EV96100
58 #define GT96100_ETHER0_IRQ 3
59 #define GT96100_ETHER1_IRQ 4
61 #define GT96100_ETHER0_IRQ -1
62 #define GT96100_ETHER1_IRQ -1
66 #define REV_GT96100A_1 2
67 #define REV_GT96100A 3
69 #define GT96100ETH_READ(gp, offset) \
70 GT96100_READ((gp->port_offset + offset))
72 #define GT96100ETH_WRITE(gp, offset, data) \
73 GT96100_WRITE((gp->port_offset + offset), data)
75 #define GT96100ETH_SETBIT(gp, offset, bits) {\
76 u32 val = GT96100ETH_READ(gp, offset); val |= (u32)(bits); \
77 GT96100ETH_WRITE(gp, offset, val); }
79 #define GT96100ETH_CLRBIT(gp, offset, bits) {\
80 u32 val = GT96100ETH_READ(gp, offset); val &= (u32)(~(bits)); \
81 GT96100ETH_WRITE(gp, offset, val); }
84 /* Bit definitions of the SMI Reg */
86 smirDataMask = 0xffff,
87 smirPhyAdMask = 0x1f<<16,
89 smirRegAdMask = 0x1f<<21,
92 smirReadValid = 1<<27,
96 /* Bit definitions of the Port Config Reg */
102 pcrLPBKMask = 0x3<<8,
109 pcrISLMask = 0x7<<28,
114 /* Bit definitions of the Port Config Extend Reg */
119 pcxrPRIOtxMask = 0x7<<3,
121 pcxrPRIOrxMask = 0x3<<6,
123 pcxrPRIOrxOverride = 1<<8,
128 pcxrMFLMask = 0x3<<14,
130 pcxrMIBclrMode = 1<<16,
137 /* Bit definitions of the Port Command Reg */
143 /* Bit definitions of the Port Status Reg */
155 /* Bit definitions of the SDMA Config Reg */
163 sdcrBSZMask = 0x3<<12,
167 /* Bit definitions of the SDMA Command Reg */
178 /* Bit definitions of the Interrupt Cause Reg */
181 icrTxBufferHigh = 1<<2,
182 icrTxBufferLow = 1<<3,
186 icrTxErrorHigh = 1<<10,
187 icrTxErrorLow = 1<<11,
190 icrRxBufferQ0 = 1<<16,
191 icrRxBufferQ1 = 1<<17,
192 icrRxBufferQ2 = 1<<18,
193 icrRxBufferQ3 = 1<<19,
194 icrRxErrorQ0 = 1<<20,
195 icrRxErrorQ1 = 1<<21,
196 icrRxErrorQ2 = 1<<22,
197 icrRxErrorQ3 = 1<<23,
198 icrMIIPhySTC = 1<<28,
200 icrEtherIntSum = 1<<31
204 /* The Rx and Tx descriptor lists. */
216 } __attribute__ ((packed)) gt96100_td_t;
229 } __attribute__ ((packed)) gt96100_rd_t;
232 /* Values for the Tx command-status descriptor entry. */
241 txErrorSummary = 1<<15,
242 txReTxCntMask = 0x0f<<10,
247 txLateCollision = 1<<5
251 /* Values for the Rx command-status descriptor entry. */
258 rxErrorSummary = 1<<15,
260 rxHashExpired = 1<<13,
261 rxMissedFrame = 1<<12,
264 rxMaxFrameLen = 1<<7,
270 /* Bit fields of a Hash Table Entry */
271 enum hash_table_entry {
283 u32 totalByteReceived;
284 u32 totalFramesReceived;
285 u32 broadcastFramesReceived;
286 u32 multicastFramesReceived;
298 u32 frames1024_MaxSize;
301 u32 outMulticastFrames;
302 u32 outBroadcastFrames;
307 struct gt96100_private {
308 gt96100_rd_t* rx_ring;
309 gt96100_td_t* tx_ring;
310 // The Rx and Tx rings must be 16-byte aligned
311 dma_addr_t rx_ring_dma;
312 dma_addr_t tx_ring_dma;
314 // The Hash Table must be 8-byte aligned
315 dma_addr_t hash_table_dma;
318 // The Rx buffers must be 8-byte aligned
320 dma_addr_t rx_buff_dma;
321 // Tx buffers (tx_skbuff[i]->data) with less than 8 bytes
322 // of payload must be 8-byte aligned
323 struct sk_buff* tx_skbuff[TX_RING_SIZE];
324 int rx_next_out; /* The next free ring entry to receive */
325 int tx_next_in; /* The next free ring entry to send */
326 int tx_next_out; /* The last ring entry the ISR processed */
327 int tx_count; /* current # of pkts waiting to be sent in Tx ring */
328 int intr_work_done; /* number of Rx and Tx pkts processed in the isr */
329 int tx_full; /* Tx ring is full */
332 struct net_device_stats stats;
334 int port_num; // 0 or 1
338 int phy_addr; // PHY address
339 u32 last_psr; // last value of the port status register
341 int options; /* User-settable misc. driver options. */
342 struct timer_list timer;
343 spinlock_t lock; /* Serialise access to device */