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 <linux/config.h>
31 #include <asm/galileo-boards/gt96100.h>
33 #define dbg(lvl, format, arg...) \
34 if (lvl <= GT96100_DEBUG) \
35 printk(KERN_DEBUG "%s: " format, dev->name , ## arg)
36 #define err(format, arg...) \
37 printk(KERN_ERR "%s: " format, dev->name , ## arg)
38 #define info(format, arg...) \
39 printk(KERN_INFO "%s: " format, dev->name , ## arg)
40 #define warn(format, arg...) \
41 printk(KERN_WARNING "%s: " format, dev->name , ## arg)
43 /* Keep the ring sizes a power of two for efficiency. */
44 #define TX_RING_SIZE 16
45 #define RX_RING_SIZE 32
46 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
48 #define RX_HASH_TABLE_SIZE 16384
49 #define HASH_HOP_NUMBER 12
51 #define NUM_INTERFACES 2
53 #define GT96100ETH_TX_TIMEOUT HZ/4
55 #define GT96100_ETH0_BASE (MIPS_GT96100_BASE + GT96100_ETH_PORT_CONFIG)
56 #define GT96100_ETH1_BASE (GT96100_ETH0_BASE + GT96100_ETH_IO_SIZE)
58 #ifdef CONFIG_MIPS_EV96100
59 #define GT96100_ETHER0_IRQ 3
60 #define GT96100_ETHER1_IRQ 4
62 #define GT96100_ETHER0_IRQ -1
63 #define GT96100_ETHER1_IRQ -1
67 #define REV_GT96100A_1 2
68 #define REV_GT96100A 3
70 #define GT96100ETH_READ(gp, offset) \
71 GT96100_READ((gp->port_offset + offset))
73 #define GT96100ETH_WRITE(gp, offset, data) \
74 GT96100_WRITE((gp->port_offset + offset), data)
76 #define GT96100ETH_SETBIT(gp, offset, bits) {\
77 u32 val = GT96100ETH_READ(gp, offset); val |= (u32)(bits); \
78 GT96100ETH_WRITE(gp, offset, val); }
80 #define GT96100ETH_CLRBIT(gp, offset, bits) {\
81 u32 val = GT96100ETH_READ(gp, offset); val &= (u32)(~(bits)); \
82 GT96100ETH_WRITE(gp, offset, val); }
85 /* Bit definitions of the SMI Reg */
87 smirDataMask
= 0xffff,
88 smirPhyAdMask
= 0x1f<<16,
90 smirRegAdMask
= 0x1f<<21,
93 smirReadValid
= 1<<27,
97 /* Bit definitions of the Port Config Reg */
103 pcrLPBKMask
= 0x3<<8,
110 pcrISLMask
= 0x7<<28,
115 /* Bit definitions of the Port Config Extend Reg */
120 pcxrPRIOtxMask
= 0x7<<3,
122 pcxrPRIOrxMask
= 0x3<<6,
124 pcxrPRIOrxOverride
= 1<<8,
129 pcxrMFLMask
= 0x3<<14,
131 pcxrMIBclrMode
= 1<<16,
138 /* Bit definitions of the Port Command Reg */
144 /* Bit definitions of the Port Status Reg */
156 /* Bit definitions of the SDMA Config Reg */
164 sdcrBSZMask
= 0x3<<12,
168 /* Bit definitions of the SDMA Command Reg */
179 /* Bit definitions of the Interrupt Cause Reg */
182 icrTxBufferHigh
= 1<<2,
183 icrTxBufferLow
= 1<<3,
187 icrTxErrorHigh
= 1<<10,
188 icrTxErrorLow
= 1<<11,
191 icrRxBufferQ0
= 1<<16,
192 icrRxBufferQ1
= 1<<17,
193 icrRxBufferQ2
= 1<<18,
194 icrRxBufferQ3
= 1<<19,
195 icrRxErrorQ0
= 1<<20,
196 icrRxErrorQ1
= 1<<21,
197 icrRxErrorQ2
= 1<<22,
198 icrRxErrorQ3
= 1<<23,
199 icrMIIPhySTC
= 1<<28,
201 icrEtherIntSum
= 1<<31
205 /* The Rx and Tx descriptor lists. */
217 } __attribute__ ((packed
)) gt96100_td_t
;
230 } __attribute__ ((packed
)) gt96100_rd_t
;
233 /* Values for the Tx command-status descriptor entry. */
242 txErrorSummary
= 1<<15,
243 txReTxCntMask
= 0x0f<<10,
248 txLateCollision
= 1<<5
252 /* Values for the Rx command-status descriptor entry. */
259 rxErrorSummary
= 1<<15,
261 rxHashExpired
= 1<<13,
262 rxMissedFrame
= 1<<12,
265 rxMaxFrameLen
= 1<<7,
271 /* Bit fields of a Hash Table Entry */
272 enum hash_table_entry
{
284 u32 totalByteReceived
;
285 u32 totalFramesReceived
;
286 u32 broadcastFramesReceived
;
287 u32 multicastFramesReceived
;
299 u32 frames1024_MaxSize
;
302 u32 outMulticastFrames
;
303 u32 outBroadcastFrames
;
308 struct gt96100_private
{
309 gt96100_rd_t
* rx_ring
;
310 gt96100_td_t
* tx_ring
;
311 // The Rx and Tx rings must be 16-byte aligned
312 dma_addr_t rx_ring_dma
;
313 dma_addr_t tx_ring_dma
;
315 // The Hash Table must be 8-byte aligned
316 dma_addr_t hash_table_dma
;
319 // The Rx buffers must be 8-byte aligned
321 dma_addr_t rx_buff_dma
;
322 // Tx buffers (tx_skbuff[i]->data) with less than 8 bytes
323 // of payload must be 8-byte aligned
324 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
325 int rx_next_out
; /* The next free ring entry to receive */
326 int tx_next_in
; /* The next free ring entry to send */
327 int tx_next_out
; /* The last ring entry the ISR processed */
328 int tx_count
; /* current # of pkts waiting to be sent in Tx ring */
329 int intr_work_done
; /* number of Rx and Tx pkts processed in the isr */
330 int tx_full
; /* Tx ring is full */
333 struct net_device_stats stats
;
336 int port_num
; // 0 or 1
340 int phy_addr
; // PHY address
341 u32 last_psr
; // last value of the port status register
343 int options
; /* User-settable misc. driver options. */
345 struct timer_list timer
;
346 spinlock_t lock
; /* Serialise access to device */