Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx. |
| 3 | * Copyright (c) 1997 Dan Malek (dmalek@jlc.net) |
| 4 | * |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 5 | * Right now, I am very wasteful with the buffers. I allocate memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * pages and then divide them into 2K frame buffers. This way I know I |
| 7 | * have buffers large enough to hold one frame within one buffer descriptor. |
| 8 | * Once I get this working, I will use 64 or 128 byte CPM buffers, which |
| 9 | * will be much more memory efficient and will easily handle lots of |
| 10 | * small packets. |
| 11 | * |
| 12 | * Much better multiple PHY support by Magnus Damm. |
| 13 | * Copyright (c) 2000 Ericsson Radio Systems AB. |
| 14 | * |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 15 | * Support for FEC controller of ColdFire processors. |
| 16 | * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 17 | * |
| 18 | * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be) |
Philippe De Muyter | 677177c | 2006-06-27 13:05:33 +1000 | [diff] [blame] | 19 | * Copyright (c) 2004-2006 Macq Electronique SA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/ptrace.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/ioport.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/netdevice.h> |
| 34 | #include <linux/etherdevice.h> |
| 35 | #include <linux/skbuff.h> |
| 36 | #include <linux/spinlock.h> |
| 37 | #include <linux/workqueue.h> |
| 38 | #include <linux/bitops.h> |
Sascha Hauer | 6f501b1 | 2009-01-28 23:03:05 +0000 | [diff] [blame] | 39 | #include <linux/io.h> |
| 40 | #include <linux/irq.h> |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 41 | #include <linux/clk.h> |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 42 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Greg Ungerer | 080853a | 2007-07-30 16:28:46 +1000 | [diff] [blame] | 44 | #include <asm/cacheflush.h> |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 45 | |
| 46 | #ifndef CONFIG_ARCH_MXC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/coldfire.h> |
| 48 | #include <asm/mcfsim.h> |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 49 | #endif |
Sascha Hauer | 6f501b1 | 2009-01-28 23:03:05 +0000 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "fec.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_ARCH_MXC |
| 54 | #include <mach/hardware.h> |
| 55 | #define FEC_ALIGNMENT 0xf |
| 56 | #else |
| 57 | #define FEC_ALIGNMENT 0x3 |
| 58 | #endif |
| 59 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 60 | /* |
| 61 | * Define the fixed address of the FEC hardware. |
| 62 | */ |
Greg Ungerer | 87f4abb | 2008-06-06 15:55:36 +1000 | [diff] [blame] | 63 | #if defined(CONFIG_M5272) |
Sebastian Siewior | c1d9615 | 2008-05-01 14:04:02 +1000 | [diff] [blame] | 64 | #define HAVE_mii_link_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | static unsigned char fec_mac_default[] = { |
| 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 68 | }; |
| 69 | |
| 70 | /* |
| 71 | * Some hardware gets it MAC address out of local flash memory. |
| 72 | * if this is non-zero then assume it is the address to get MAC from. |
| 73 | */ |
| 74 | #if defined(CONFIG_NETtel) |
| 75 | #define FEC_FLASHMAC 0xf0006006 |
| 76 | #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES) |
| 77 | #define FEC_FLASHMAC 0xf0006000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #elif defined(CONFIG_CANCam) |
| 79 | #define FEC_FLASHMAC 0xf0020000 |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 80 | #elif defined (CONFIG_M5272C3) |
| 81 | #define FEC_FLASHMAC (0xffe04000 + 4) |
| 82 | #elif defined(CONFIG_MOD5272) |
| 83 | #define FEC_FLASHMAC 0xffc0406b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #else |
| 85 | #define FEC_FLASHMAC 0 |
| 86 | #endif |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 87 | #endif /* CONFIG_M5272 */ |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 88 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 89 | /* Forward declarations of some structures to support different PHYs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | typedef struct { |
| 92 | uint mii_data; |
| 93 | void (*funct)(uint mii_reg, struct net_device *dev); |
| 94 | } phy_cmd_t; |
| 95 | |
| 96 | typedef struct { |
| 97 | uint id; |
| 98 | char *name; |
| 99 | |
| 100 | const phy_cmd_t *config; |
| 101 | const phy_cmd_t *startup; |
| 102 | const phy_cmd_t *ack_int; |
| 103 | const phy_cmd_t *shutdown; |
| 104 | } phy_info_t; |
| 105 | |
| 106 | /* The number of Tx and Rx buffers. These are allocated from the page |
| 107 | * pool. The code may assume these are power of two, so it it best |
| 108 | * to keep them that size. |
| 109 | * We don't need to allocate pages for the transmitter. We just use |
| 110 | * the skbuffer directly. |
| 111 | */ |
| 112 | #define FEC_ENET_RX_PAGES 8 |
| 113 | #define FEC_ENET_RX_FRSIZE 2048 |
| 114 | #define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE) |
| 115 | #define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES) |
| 116 | #define FEC_ENET_TX_FRSIZE 2048 |
| 117 | #define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE) |
| 118 | #define TX_RING_SIZE 16 /* Must be power of two */ |
| 119 | #define TX_RING_MOD_MASK 15 /* for this to work */ |
| 120 | |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 121 | #if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE) |
Matt Waddel | 6b26529 | 2006-06-27 13:10:56 +1000 | [diff] [blame] | 122 | #error "FEC: descriptor ring size constants too large" |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 123 | #endif |
| 124 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 125 | /* Interrupt events/masks. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */ |
| 127 | #define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */ |
| 128 | #define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */ |
| 129 | #define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */ |
| 130 | #define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */ |
| 131 | #define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */ |
| 132 | #define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */ |
| 133 | #define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */ |
| 134 | #define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */ |
| 135 | #define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */ |
| 136 | |
| 137 | /* The FEC stores dest/src/type, data, and checksum for receive packets. |
| 138 | */ |
| 139 | #define PKT_MAXBUF_SIZE 1518 |
| 140 | #define PKT_MINBUF_SIZE 64 |
| 141 | #define PKT_MAXBLR_SIZE 1520 |
| 142 | |
| 143 | |
| 144 | /* |
Matt Waddel | 6b26529 | 2006-06-27 13:10:56 +1000 | [diff] [blame] | 145 | * The 5270/5271/5280/5282/532x RX control register also contains maximum frame |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | * size bits. Other FEC hardware does not, so we need to take that into |
| 147 | * account when setting it. |
| 148 | */ |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 149 | #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \ |
Sascha Hauer | 196719e | 2009-01-28 23:03:10 +0000 | [diff] [blame] | 150 | defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARCH_MXC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | #define OPT_FRAME_SIZE (PKT_MAXBUF_SIZE << 16) |
| 152 | #else |
| 153 | #define OPT_FRAME_SIZE 0 |
| 154 | #endif |
| 155 | |
| 156 | /* The FEC buffer descriptors track the ring buffers. The rx_bd_base and |
| 157 | * tx_bd_base always point to the base of the buffer descriptors. The |
| 158 | * cur_rx and cur_tx point to the currently available buffer. |
| 159 | * The dirty_tx tracks the current buffer that is being sent by the |
| 160 | * controller. The cur_tx and dirty_tx are equal under both completely |
| 161 | * empty and completely full conditions. The empty/ready indicator in |
| 162 | * the buffer descriptor determines the actual condition. |
| 163 | */ |
| 164 | struct fec_enet_private { |
| 165 | /* Hardware registers of the FEC device */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 166 | void __iomem *hwp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 168 | struct net_device *netdev; |
| 169 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 170 | struct clk *clk; |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* The saved address of a sent-in-place packet/buffer, for skfree(). */ |
| 173 | unsigned char *tx_bounce[TX_RING_SIZE]; |
| 174 | struct sk_buff* tx_skbuff[TX_RING_SIZE]; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 175 | struct sk_buff* rx_skbuff[RX_RING_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | ushort skb_cur; |
| 177 | ushort skb_dirty; |
| 178 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 179 | /* CPM dual port RAM relative addresses */ |
Sascha Hauer | 4661e75 | 2009-01-28 23:03:07 +0000 | [diff] [blame] | 180 | dma_addr_t bd_dma; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 181 | /* Address of Rx and Tx buffers */ |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 182 | struct bufdesc *rx_bd_base; |
| 183 | struct bufdesc *tx_bd_base; |
| 184 | /* The next free ring entry */ |
| 185 | struct bufdesc *cur_rx, *cur_tx; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 186 | /* The ring entries to be free()ed */ |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 187 | struct bufdesc *dirty_tx; |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | uint tx_full; |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 190 | /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */ |
| 191 | spinlock_t hw_lock; |
| 192 | /* hold while accessing the mii_list_t() elements */ |
| 193 | spinlock_t mii_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | uint phy_id; |
| 196 | uint phy_id_done; |
| 197 | uint phy_status; |
| 198 | uint phy_speed; |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 199 | phy_info_t const *phy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | struct work_struct phy_task; |
| 201 | |
| 202 | uint sequence_done; |
| 203 | uint mii_phy_task_queued; |
| 204 | |
| 205 | uint phy_addr; |
| 206 | |
| 207 | int index; |
| 208 | int opened; |
| 209 | int link; |
| 210 | int old_link; |
| 211 | int full_duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static void fec_enet_mii(struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 215 | static irqreturn_t fec_enet_interrupt(int irq, void * dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | static void fec_enet_tx(struct net_device *dev); |
| 217 | static void fec_enet_rx(struct net_device *dev); |
| 218 | static int fec_enet_close(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | static void fec_restart(struct net_device *dev, int duplex); |
| 220 | static void fec_stop(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | |
| 223 | /* MII processing. We keep this as simple as possible. Requests are |
| 224 | * placed on the list (if there is room). When the request is finished |
| 225 | * by the MII, an optional function may be called. |
| 226 | */ |
| 227 | typedef struct mii_list { |
| 228 | uint mii_regval; |
| 229 | void (*mii_func)(uint val, struct net_device *dev); |
| 230 | struct mii_list *mii_next; |
| 231 | } mii_list_t; |
| 232 | |
| 233 | #define NMII 20 |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 234 | static mii_list_t mii_cmds[NMII]; |
| 235 | static mii_list_t *mii_free; |
| 236 | static mii_list_t *mii_head; |
| 237 | static mii_list_t *mii_tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 239 | static int mii_queue(struct net_device *dev, int request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | void (*func)(uint, struct net_device *)); |
| 241 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 242 | /* Make MII read/write commands for the FEC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18)) |
| 244 | #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | \ |
| 245 | (VAL & 0xffff)) |
| 246 | #define mk_mii_end 0 |
| 247 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 248 | /* Transmitter timeout */ |
| 249 | #define TX_TIMEOUT (2 * HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 251 | /* Register definitions for the PHY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | #define MII_REG_CR 0 /* Control Register */ |
| 254 | #define MII_REG_SR 1 /* Status Register */ |
| 255 | #define MII_REG_PHYIR1 2 /* PHY Identification Register 1 */ |
| 256 | #define MII_REG_PHYIR2 3 /* PHY Identification Register 2 */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 257 | #define MII_REG_ANAR 4 /* A-N Advertisement Register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | #define MII_REG_ANLPAR 5 /* A-N Link Partner Ability Register */ |
| 259 | #define MII_REG_ANER 6 /* A-N Expansion Register */ |
| 260 | #define MII_REG_ANNPTR 7 /* A-N Next Page Transmit Register */ |
| 261 | #define MII_REG_ANLPRNPR 8 /* A-N Link Partner Received Next Page Reg. */ |
| 262 | |
| 263 | /* values for phy_status */ |
| 264 | |
| 265 | #define PHY_CONF_ANE 0x0001 /* 1 auto-negotiation enabled */ |
| 266 | #define PHY_CONF_LOOP 0x0002 /* 1 loopback mode enabled */ |
| 267 | #define PHY_CONF_SPMASK 0x00f0 /* mask for speed */ |
| 268 | #define PHY_CONF_10HDX 0x0010 /* 10 Mbit half duplex supported */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 269 | #define PHY_CONF_10FDX 0x0020 /* 10 Mbit full duplex supported */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | #define PHY_CONF_100HDX 0x0040 /* 100 Mbit half duplex supported */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 271 | #define PHY_CONF_100FDX 0x0080 /* 100 Mbit full duplex supported */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | #define PHY_STAT_LINK 0x0100 /* 1 up - 0 down */ |
| 274 | #define PHY_STAT_FAULT 0x0200 /* 1 remote fault */ |
| 275 | #define PHY_STAT_ANC 0x0400 /* 1 auto-negotiation complete */ |
| 276 | #define PHY_STAT_SPMASK 0xf000 /* mask for speed */ |
| 277 | #define PHY_STAT_10HDX 0x1000 /* 10 Mbit half duplex selected */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 278 | #define PHY_STAT_10FDX 0x2000 /* 10 Mbit full duplex selected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | #define PHY_STAT_100HDX 0x4000 /* 100 Mbit half duplex selected */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 280 | #define PHY_STAT_100FDX 0x8000 /* 100 Mbit full duplex selected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | |
| 283 | static int |
| 284 | fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 285 | { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 286 | struct fec_enet_private *fep = netdev_priv(dev); |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 287 | struct bufdesc *bdp; |
Greg Ungerer | 9555b31 | 2009-08-06 17:58:18 +0000 | [diff] [blame] | 288 | void *bufaddr; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 289 | unsigned short status; |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 290 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (!fep->link) { |
| 293 | /* Link is down or autonegotiation is in progress. */ |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 294 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 297 | spin_lock_irqsave(&fep->hw_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* Fill in a Tx ring entry */ |
| 299 | bdp = fep->cur_tx; |
| 300 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 301 | status = bdp->cbd_sc; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 302 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 303 | if (status & BD_ENET_TX_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /* Ooops. All transmit buffers are full. Bail out. |
| 305 | * This should not happen, since dev->tbusy should be set. |
| 306 | */ |
| 307 | printk("%s: tx queue full!.\n", dev->name); |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 308 | spin_unlock_irqrestore(&fep->hw_lock, flags); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 309 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 312 | /* Clear all of the status flags */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 313 | status &= ~BD_ENET_TX_STATS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 315 | /* Set buffer length and buffer pointer */ |
Greg Ungerer | 9555b31 | 2009-08-06 17:58:18 +0000 | [diff] [blame] | 316 | bufaddr = skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | bdp->cbd_datlen = skb->len; |
| 318 | |
| 319 | /* |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 320 | * On some FEC implementations data must be aligned on |
| 321 | * 4-byte boundaries. Use bounce buffers to copy data |
| 322 | * and get it aligned. Ugh. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | */ |
Greg Ungerer | 9555b31 | 2009-08-06 17:58:18 +0000 | [diff] [blame] | 324 | if (((unsigned long) bufaddr) & FEC_ALIGNMENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | unsigned int index; |
| 326 | index = bdp - fep->tx_bd_base; |
Sascha Hauer | 6989f51 | 2009-01-28 23:03:06 +0000 | [diff] [blame] | 327 | memcpy(fep->tx_bounce[index], (void *)skb->data, skb->len); |
Greg Ungerer | 9555b31 | 2009-08-06 17:58:18 +0000 | [diff] [blame] | 328 | bufaddr = fep->tx_bounce[index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 331 | /* Save skb pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | fep->tx_skbuff[fep->skb_cur] = skb; |
| 333 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 334 | dev->stats.tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* Push the data cache so the CPM does not get stale memory |
| 338 | * data. |
| 339 | */ |
Greg Ungerer | 9555b31 | 2009-08-06 17:58:18 +0000 | [diff] [blame] | 340 | bdp->cbd_bufaddr = dma_map_single(&dev->dev, bufaddr, |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 341 | FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 343 | /* Send it on its way. Tell FEC it's ready, interrupt when done, |
| 344 | * it's the last BD of the frame, and to put the CRC on the end. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 346 | status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | | BD_ENET_TX_LAST | BD_ENET_TX_TC); |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 348 | bdp->cbd_sc = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | dev->trans_start = jiffies; |
| 351 | |
| 352 | /* Trigger transmission start */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 353 | writel(0, fep->hwp + FEC_X_DES_ACTIVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 355 | /* If this was the last BD in the ring, start at the beginning again. */ |
| 356 | if (status & BD_ENET_TX_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | bdp = fep->tx_bd_base; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 358 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | bdp++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | if (bdp == fep->dirty_tx) { |
| 362 | fep->tx_full = 1; |
| 363 | netif_stop_queue(dev); |
| 364 | } |
| 365 | |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 366 | fep->cur_tx = bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 368 | spin_unlock_irqrestore(&fep->hw_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 370 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void |
| 374 | fec_timeout(struct net_device *dev) |
| 375 | { |
| 376 | struct fec_enet_private *fep = netdev_priv(dev); |
| 377 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 378 | dev->stats.tx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 380 | fec_restart(dev, fep->full_duplex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | netif_wake_queue(dev); |
| 382 | } |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 385 | fec_enet_interrupt(int irq, void * dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
| 387 | struct net_device *dev = dev_id; |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 388 | struct fec_enet_private *fep = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | uint int_events; |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 390 | irqreturn_t ret = IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 392 | do { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 393 | int_events = readl(fep->hwp + FEC_IEVENT); |
| 394 | writel(int_events, fep->hwp + FEC_IEVENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (int_events & FEC_ENET_RXF) { |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 397 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | fec_enet_rx(dev); |
| 399 | } |
| 400 | |
| 401 | /* Transmit OK, or non-fatal error. Update the buffer |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 402 | * descriptors. FEC handles all errors, we just discover |
| 403 | * them as part of the transmit process. |
| 404 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (int_events & FEC_ENET_TXF) { |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 406 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | fec_enet_tx(dev); |
| 408 | } |
| 409 | |
| 410 | if (int_events & FEC_ENET_MII) { |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 411 | ret = IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | fec_enet_mii(dev); |
| 413 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 414 | |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 415 | } while (int_events); |
| 416 | |
| 417 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | |
| 421 | static void |
| 422 | fec_enet_tx(struct net_device *dev) |
| 423 | { |
| 424 | struct fec_enet_private *fep; |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 425 | struct bufdesc *bdp; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 426 | unsigned short status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | struct sk_buff *skb; |
| 428 | |
| 429 | fep = netdev_priv(dev); |
Uwe Kleine-König | 81538e7 | 2009-09-01 23:14:16 +0000 | [diff] [blame] | 430 | spin_lock(&fep->hw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | bdp = fep->dirty_tx; |
| 432 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 433 | while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) { |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 434 | if (bdp == fep->cur_tx && fep->tx_full == 0) |
| 435 | break; |
| 436 | |
| 437 | dma_unmap_single(&dev->dev, bdp->cbd_bufaddr, FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE); |
| 438 | bdp->cbd_bufaddr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | skb = fep->tx_skbuff[fep->skb_dirty]; |
| 441 | /* Check for errors. */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 442 | if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | BD_ENET_TX_RL | BD_ENET_TX_UN | |
| 444 | BD_ENET_TX_CSL)) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 445 | dev->stats.tx_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 446 | if (status & BD_ENET_TX_HB) /* No heartbeat */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 447 | dev->stats.tx_heartbeat_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 448 | if (status & BD_ENET_TX_LC) /* Late collision */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 449 | dev->stats.tx_window_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 450 | if (status & BD_ENET_TX_RL) /* Retrans limit */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 451 | dev->stats.tx_aborted_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 452 | if (status & BD_ENET_TX_UN) /* Underrun */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 453 | dev->stats.tx_fifo_errors++; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 454 | if (status & BD_ENET_TX_CSL) /* Carrier lost */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 455 | dev->stats.tx_carrier_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } else { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 457 | dev->stats.tx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 460 | if (status & BD_ENET_TX_READY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | printk("HEY! Enet xmit interrupt and TX_READY.\n"); |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* Deferred means some collisions occurred during transmit, |
| 464 | * but we eventually sent the packet OK. |
| 465 | */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 466 | if (status & BD_ENET_TX_DEF) |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 467 | dev->stats.collisions++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 468 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 469 | /* Free the sk buffer associated with this last transmit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | dev_kfree_skb_any(skb); |
| 471 | fep->tx_skbuff[fep->skb_dirty] = NULL; |
| 472 | fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 473 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 474 | /* Update pointer to next buffer descriptor to be transmitted */ |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 475 | if (status & BD_ENET_TX_WRAP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | bdp = fep->tx_bd_base; |
| 477 | else |
| 478 | bdp++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 479 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 480 | /* Since we have freed up a buffer, the ring is no longer full |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | */ |
| 482 | if (fep->tx_full) { |
| 483 | fep->tx_full = 0; |
| 484 | if (netif_queue_stopped(dev)) |
| 485 | netif_wake_queue(dev); |
| 486 | } |
| 487 | } |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 488 | fep->dirty_tx = bdp; |
Uwe Kleine-König | 81538e7 | 2009-09-01 23:14:16 +0000 | [diff] [blame] | 489 | spin_unlock(&fep->hw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
| 493 | /* During a receive, the cur_rx points to the current incoming buffer. |
| 494 | * When we update through the ring, if the next incoming buffer has |
| 495 | * not been given to the system, we just set the empty indicator, |
| 496 | * effectively tossing the packet. |
| 497 | */ |
| 498 | static void |
| 499 | fec_enet_rx(struct net_device *dev) |
| 500 | { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 501 | struct fec_enet_private *fep = netdev_priv(dev); |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 502 | struct bufdesc *bdp; |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 503 | unsigned short status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | struct sk_buff *skb; |
| 505 | ushort pkt_len; |
| 506 | __u8 *data; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 507 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 508 | #ifdef CONFIG_M532x |
| 509 | flush_cache_all(); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 510 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Uwe Kleine-König | 81538e7 | 2009-09-01 23:14:16 +0000 | [diff] [blame] | 512 | spin_lock(&fep->hw_lock); |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* First, grab all of the stats for the incoming packet. |
| 515 | * These get messed up if we get called due to a busy condition. |
| 516 | */ |
| 517 | bdp = fep->cur_rx; |
| 518 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 519 | while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 521 | /* Since we have allocated space to hold a complete frame, |
| 522 | * the last indicator should be set. |
| 523 | */ |
| 524 | if ((status & BD_ENET_RX_LAST) == 0) |
| 525 | printk("FEC ENET: rcv is not +last\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 527 | if (!fep->opened) |
| 528 | goto rx_processing_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 530 | /* Check for errors. */ |
| 531 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | BD_ENET_RX_CR | BD_ENET_RX_OV)) { |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 533 | dev->stats.rx_errors++; |
| 534 | if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) { |
| 535 | /* Frame too long or too short. */ |
| 536 | dev->stats.rx_length_errors++; |
| 537 | } |
| 538 | if (status & BD_ENET_RX_NO) /* Frame alignment */ |
| 539 | dev->stats.rx_frame_errors++; |
| 540 | if (status & BD_ENET_RX_CR) /* CRC Error */ |
| 541 | dev->stats.rx_crc_errors++; |
| 542 | if (status & BD_ENET_RX_OV) /* FIFO overrun */ |
| 543 | dev->stats.rx_fifo_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 545 | |
| 546 | /* Report late collisions as a frame error. |
| 547 | * On this error, the BD is closed, but we don't know what we |
| 548 | * have in the buffer. So, just drop this frame on the floor. |
| 549 | */ |
| 550 | if (status & BD_ENET_RX_CL) { |
| 551 | dev->stats.rx_errors++; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 552 | dev->stats.rx_frame_errors++; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 553 | goto rx_processing_done; |
| 554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 556 | /* Process the incoming frame. */ |
| 557 | dev->stats.rx_packets++; |
| 558 | pkt_len = bdp->cbd_datlen; |
| 559 | dev->stats.rx_bytes += pkt_len; |
| 560 | data = (__u8*)__va(bdp->cbd_bufaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 562 | dma_unmap_single(NULL, bdp->cbd_bufaddr, bdp->cbd_datlen, |
| 563 | DMA_FROM_DEVICE); |
Sascha Hauer | ccdc4f1 | 2009-01-28 23:03:09 +0000 | [diff] [blame] | 564 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 565 | /* This does 16 byte alignment, exactly what we need. |
| 566 | * The packet length includes FCS, but we don't want to |
| 567 | * include that when passing upstream as it messes up |
| 568 | * bridging applications. |
| 569 | */ |
Sascha Hauer | 8549889 | 2009-04-15 01:32:21 +0000 | [diff] [blame] | 570 | skb = dev_alloc_skb(pkt_len - 4 + NET_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Sascha Hauer | 8549889 | 2009-04-15 01:32:21 +0000 | [diff] [blame] | 572 | if (unlikely(!skb)) { |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 573 | printk("%s: Memory squeeze, dropping packet.\n", |
| 574 | dev->name); |
| 575 | dev->stats.rx_dropped++; |
| 576 | } else { |
Sascha Hauer | 8549889 | 2009-04-15 01:32:21 +0000 | [diff] [blame] | 577 | skb_reserve(skb, NET_IP_ALIGN); |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 578 | skb_put(skb, pkt_len - 4); /* Make room */ |
| 579 | skb_copy_to_linear_data(skb, data, pkt_len - 4); |
| 580 | skb->protocol = eth_type_trans(skb, dev); |
| 581 | netif_rx(skb); |
| 582 | } |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 583 | |
| 584 | bdp->cbd_bufaddr = dma_map_single(NULL, data, bdp->cbd_datlen, |
| 585 | DMA_FROM_DEVICE); |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 586 | rx_processing_done: |
| 587 | /* Clear the status flags for this buffer */ |
| 588 | status &= ~BD_ENET_RX_STATS; |
| 589 | |
| 590 | /* Mark the buffer empty */ |
| 591 | status |= BD_ENET_RX_EMPTY; |
| 592 | bdp->cbd_sc = status; |
| 593 | |
| 594 | /* Update BD pointer to next entry */ |
| 595 | if (status & BD_ENET_RX_WRAP) |
| 596 | bdp = fep->rx_bd_base; |
| 597 | else |
| 598 | bdp++; |
| 599 | /* Doing this here will keep the FEC running while we process |
| 600 | * incoming frames. On a heavily loaded network, we should be |
| 601 | * able to keep up at the expense of system resources. |
| 602 | */ |
| 603 | writel(0, fep->hwp + FEC_R_DES_ACTIVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 605 | fep->cur_rx = bdp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Uwe Kleine-König | 81538e7 | 2009-09-01 23:14:16 +0000 | [diff] [blame] | 607 | spin_unlock(&fep->hw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 610 | /* called from interrupt context */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | static void |
| 612 | fec_enet_mii(struct net_device *dev) |
| 613 | { |
| 614 | struct fec_enet_private *fep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | mii_list_t *mip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | fep = netdev_priv(dev); |
Uwe Kleine-König | 81538e7 | 2009-09-01 23:14:16 +0000 | [diff] [blame] | 618 | spin_lock(&fep->mii_lock); |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | if ((mip = mii_head) == NULL) { |
| 621 | printk("MII and no head!\n"); |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 622 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | if (mip->mii_func != NULL) |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 626 | (*(mip->mii_func))(readl(fep->hwp + FEC_MII_DATA), dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | mii_head = mip->mii_next; |
| 629 | mip->mii_next = mii_free; |
| 630 | mii_free = mip; |
| 631 | |
| 632 | if ((mip = mii_head) != NULL) |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 633 | writel(mip->mii_regval, fep->hwp + FEC_MII_DATA); |
Greg Ungerer | 0e702ab | 2006-06-27 13:19:33 +1000 | [diff] [blame] | 634 | |
| 635 | unlock: |
Uwe Kleine-König | 81538e7 | 2009-09-01 23:14:16 +0000 | [diff] [blame] | 636 | spin_unlock(&fep->mii_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | static int |
Uwe Kleine-König | 84177a20 | 2009-09-01 23:14:15 +0000 | [diff] [blame] | 640 | mii_queue_unlocked(struct net_device *dev, int regval, |
| 641 | void (*func)(uint, struct net_device *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
| 643 | struct fec_enet_private *fep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | mii_list_t *mip; |
| 645 | int retval; |
| 646 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 647 | /* Add PHY address to register command */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | fep = netdev_priv(dev); |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | regval |= fep->phy_addr << 23; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | retval = 0; |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | if ((mip = mii_free) != NULL) { |
| 654 | mii_free = mip->mii_next; |
| 655 | mip->mii_regval = regval; |
| 656 | mip->mii_func = func; |
| 657 | mip->mii_next = NULL; |
| 658 | if (mii_head) { |
| 659 | mii_tail->mii_next = mip; |
| 660 | mii_tail = mip; |
Philippe De Muyter | f909b1e | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 661 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | mii_head = mii_tail = mip; |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 663 | writel(regval, fep->hwp + FEC_MII_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
Philippe De Muyter | f909b1e | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 665 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | retval = 1; |
| 667 | } |
| 668 | |
Uwe Kleine-König | 84177a20 | 2009-09-01 23:14:15 +0000 | [diff] [blame] | 669 | return retval; |
| 670 | } |
| 671 | |
| 672 | static int |
| 673 | mii_queue(struct net_device *dev, int regval, |
| 674 | void (*func)(uint, struct net_device *)) |
| 675 | { |
| 676 | struct fec_enet_private *fep; |
| 677 | unsigned long flags; |
| 678 | int retval; |
| 679 | fep = netdev_priv(dev); |
| 680 | spin_lock_irqsave(&fep->mii_lock, flags); |
| 681 | retval = mii_queue_unlocked(dev, regval, func); |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 682 | spin_unlock_irqrestore(&fep->mii_lock, flags); |
| 683 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c) |
| 687 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | if(!c) |
| 689 | return; |
| 690 | |
Philippe De Muyter | be6cb66 | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 691 | for (; c->mii_data != mk_mii_end; c++) |
| 692 | mii_queue(dev, c->mii_data, c->funct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void mii_parse_sr(uint mii_reg, struct net_device *dev) |
| 696 | { |
| 697 | struct fec_enet_private *fep = netdev_priv(dev); |
| 698 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 699 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 701 | status = *s & ~(PHY_STAT_LINK | PHY_STAT_FAULT | PHY_STAT_ANC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
| 703 | if (mii_reg & 0x0004) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 704 | status |= PHY_STAT_LINK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | if (mii_reg & 0x0010) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 706 | status |= PHY_STAT_FAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if (mii_reg & 0x0020) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 708 | status |= PHY_STAT_ANC; |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 709 | *s = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static void mii_parse_cr(uint mii_reg, struct net_device *dev) |
| 713 | { |
| 714 | struct fec_enet_private *fep = netdev_priv(dev); |
| 715 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 716 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 718 | status = *s & ~(PHY_CONF_ANE | PHY_CONF_LOOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | if (mii_reg & 0x1000) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 721 | status |= PHY_CONF_ANE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | if (mii_reg & 0x4000) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 723 | status |= PHY_CONF_LOOP; |
| 724 | *s = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static void mii_parse_anar(uint mii_reg, struct net_device *dev) |
| 728 | { |
| 729 | struct fec_enet_private *fep = netdev_priv(dev); |
| 730 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 731 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 733 | status = *s & ~(PHY_CONF_SPMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | if (mii_reg & 0x0020) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 736 | status |= PHY_CONF_10HDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | if (mii_reg & 0x0040) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 738 | status |= PHY_CONF_10FDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | if (mii_reg & 0x0080) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 740 | status |= PHY_CONF_100HDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (mii_reg & 0x00100) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 742 | status |= PHY_CONF_100FDX; |
| 743 | *s = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* ------------------------------------------------------------------------- */ |
| 747 | /* The Level one LXT970 is used by many boards */ |
| 748 | |
| 749 | #define MII_LXT970_MIRROR 16 /* Mirror register */ |
| 750 | #define MII_LXT970_IER 17 /* Interrupt Enable Register */ |
| 751 | #define MII_LXT970_ISR 18 /* Interrupt Status Register */ |
| 752 | #define MII_LXT970_CONFIG 19 /* Configuration Register */ |
| 753 | #define MII_LXT970_CSR 20 /* Chip Status Register */ |
| 754 | |
| 755 | static void mii_parse_lxt970_csr(uint mii_reg, struct net_device *dev) |
| 756 | { |
| 757 | struct fec_enet_private *fep = netdev_priv(dev); |
| 758 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 759 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 761 | status = *s & ~(PHY_STAT_SPMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | if (mii_reg & 0x0800) { |
| 763 | if (mii_reg & 0x1000) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 764 | status |= PHY_STAT_100FDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | else |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 766 | status |= PHY_STAT_100HDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } else { |
| 768 | if (mii_reg & 0x1000) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 769 | status |= PHY_STAT_10FDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | else |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 771 | status |= PHY_STAT_10HDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 773 | *s = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 776 | static phy_cmd_t const phy_cmd_lxt970_config[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 778 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 779 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 780 | }; |
| 781 | static phy_cmd_t const phy_cmd_lxt970_startup[] = { /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { mk_mii_write(MII_LXT970_IER, 0x0002), NULL }, |
| 783 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
| 784 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 785 | }; |
| 786 | static phy_cmd_t const phy_cmd_lxt970_ack_int[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | /* read SR and ISR to acknowledge */ |
| 788 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 789 | { mk_mii_read(MII_LXT970_ISR), NULL }, |
| 790 | |
| 791 | /* find out the current status */ |
| 792 | { mk_mii_read(MII_LXT970_CSR), mii_parse_lxt970_csr }, |
| 793 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 794 | }; |
| 795 | static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { mk_mii_write(MII_LXT970_IER, 0x0000), NULL }, |
| 797 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 798 | }; |
| 799 | static phy_info_t const phy_info_lxt970 = { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 800 | .id = 0x07810000, |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 801 | .name = "LXT970", |
| 802 | .config = phy_cmd_lxt970_config, |
| 803 | .startup = phy_cmd_lxt970_startup, |
| 804 | .ack_int = phy_cmd_lxt970_ack_int, |
| 805 | .shutdown = phy_cmd_lxt970_shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | }; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | /* ------------------------------------------------------------------------- */ |
| 809 | /* The Level one LXT971 is used on some of my custom boards */ |
| 810 | |
| 811 | /* register definitions for the 971 */ |
| 812 | |
| 813 | #define MII_LXT971_PCR 16 /* Port Control Register */ |
| 814 | #define MII_LXT971_SR2 17 /* Status Register 2 */ |
| 815 | #define MII_LXT971_IER 18 /* Interrupt Enable Register */ |
| 816 | #define MII_LXT971_ISR 19 /* Interrupt Status Register */ |
| 817 | #define MII_LXT971_LCR 20 /* LED Control Register */ |
| 818 | #define MII_LXT971_TCR 30 /* Transmit Control Register */ |
| 819 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 820 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | * I had some nice ideas of running the MDIO faster... |
| 822 | * The 971 should support 8MHz and I tried it, but things acted really |
| 823 | * weird, so 2.5 MHz ought to be enough for anyone... |
| 824 | */ |
| 825 | |
| 826 | static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev) |
| 827 | { |
| 828 | struct fec_enet_private *fep = netdev_priv(dev); |
| 829 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 830 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 832 | status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | if (mii_reg & 0x0400) { |
| 835 | fep->link = 1; |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 836 | status |= PHY_STAT_LINK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } else { |
| 838 | fep->link = 0; |
| 839 | } |
| 840 | if (mii_reg & 0x0080) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 841 | status |= PHY_STAT_ANC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | if (mii_reg & 0x4000) { |
| 843 | if (mii_reg & 0x0200) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 844 | status |= PHY_STAT_100FDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | else |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 846 | status |= PHY_STAT_100HDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } else { |
| 848 | if (mii_reg & 0x0200) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 849 | status |= PHY_STAT_10FDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | else |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 851 | status |= PHY_STAT_10HDX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | if (mii_reg & 0x0008) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 854 | status |= PHY_STAT_FAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 856 | *s = status; |
| 857 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 858 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 859 | static phy_cmd_t const phy_cmd_lxt971_config[] = { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 860 | /* limit to 10MBit because my prototype board |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | * doesn't work with 100. */ |
| 862 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 863 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 864 | { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 }, |
| 865 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 866 | }; |
| 867 | static phy_cmd_t const phy_cmd_lxt971_startup[] = { /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | { mk_mii_write(MII_LXT971_IER, 0x00f2), NULL }, |
| 869 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
| 870 | { mk_mii_write(MII_LXT971_LCR, 0xd422), NULL }, /* LED config */ |
| 871 | /* Somehow does the 971 tell me that the link is down |
| 872 | * the first read after power-up. |
| 873 | * read here to get a valid value in ack_int */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 874 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 876 | }; |
| 877 | static phy_cmd_t const phy_cmd_lxt971_ack_int[] = { |
| 878 | /* acknowledge the int before reading status ! */ |
| 879 | { mk_mii_read(MII_LXT971_ISR), NULL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | /* find out the current status */ |
| 881 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 882 | { mk_mii_read(MII_LXT971_SR2), mii_parse_lxt971_sr2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 884 | }; |
| 885 | static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { mk_mii_write(MII_LXT971_IER, 0x0000), NULL }, |
| 887 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 888 | }; |
| 889 | static phy_info_t const phy_info_lxt971 = { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 890 | .id = 0x0001378e, |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 891 | .name = "LXT971", |
| 892 | .config = phy_cmd_lxt971_config, |
| 893 | .startup = phy_cmd_lxt971_startup, |
| 894 | .ack_int = phy_cmd_lxt971_ack_int, |
| 895 | .shutdown = phy_cmd_lxt971_shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | }; |
| 897 | |
| 898 | /* ------------------------------------------------------------------------- */ |
| 899 | /* The Quality Semiconductor QS6612 is used on the RPX CLLF */ |
| 900 | |
| 901 | /* register definitions */ |
| 902 | |
| 903 | #define MII_QS6612_MCR 17 /* Mode Control Register */ |
| 904 | #define MII_QS6612_FTR 27 /* Factory Test Register */ |
| 905 | #define MII_QS6612_MCO 28 /* Misc. Control Register */ |
| 906 | #define MII_QS6612_ISR 29 /* Interrupt Source Register */ |
| 907 | #define MII_QS6612_IMR 30 /* Interrupt Mask Register */ |
| 908 | #define MII_QS6612_PCR 31 /* 100BaseTx PHY Control Reg. */ |
| 909 | |
| 910 | static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev) |
| 911 | { |
| 912 | struct fec_enet_private *fep = netdev_priv(dev); |
| 913 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 914 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 916 | status = *s & ~(PHY_STAT_SPMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | switch((mii_reg >> 2) & 7) { |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 919 | case 1: status |= PHY_STAT_10HDX; break; |
| 920 | case 2: status |= PHY_STAT_100HDX; break; |
| 921 | case 5: status |= PHY_STAT_10FDX; break; |
| 922 | case 6: status |= PHY_STAT_100FDX; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 925 | *s = status; |
| 926 | } |
| 927 | |
| 928 | static phy_cmd_t const phy_cmd_qs6612_config[] = { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 929 | /* The PHY powers up isolated on the RPX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | * so send a command to allow operation. |
| 931 | */ |
| 932 | { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL }, |
| 933 | |
| 934 | /* parse cr and anar to get some info */ |
| 935 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 936 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 937 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 938 | }; |
| 939 | static phy_cmd_t const phy_cmd_qs6612_startup[] = { /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { mk_mii_write(MII_QS6612_IMR, 0x003a), NULL }, |
| 941 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
| 942 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 943 | }; |
| 944 | static phy_cmd_t const phy_cmd_qs6612_ack_int[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | /* we need to read ISR, SR and ANER to acknowledge */ |
| 946 | { mk_mii_read(MII_QS6612_ISR), NULL }, |
| 947 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 948 | { mk_mii_read(MII_REG_ANER), NULL }, |
| 949 | |
| 950 | /* read pcr to get info */ |
| 951 | { mk_mii_read(MII_QS6612_PCR), mii_parse_qs6612_pcr }, |
| 952 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 953 | }; |
| 954 | static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { mk_mii_write(MII_QS6612_IMR, 0x0000), NULL }, |
| 956 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 957 | }; |
| 958 | static phy_info_t const phy_info_qs6612 = { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 959 | .id = 0x00181440, |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 960 | .name = "QS6612", |
| 961 | .config = phy_cmd_qs6612_config, |
| 962 | .startup = phy_cmd_qs6612_startup, |
| 963 | .ack_int = phy_cmd_qs6612_ack_int, |
| 964 | .shutdown = phy_cmd_qs6612_shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | }; |
| 966 | |
| 967 | /* ------------------------------------------------------------------------- */ |
| 968 | /* AMD AM79C874 phy */ |
| 969 | |
| 970 | /* register definitions for the 874 */ |
| 971 | |
| 972 | #define MII_AM79C874_MFR 16 /* Miscellaneous Feature Register */ |
| 973 | #define MII_AM79C874_ICSR 17 /* Interrupt/Status Register */ |
| 974 | #define MII_AM79C874_DR 18 /* Diagnostic Register */ |
| 975 | #define MII_AM79C874_PMLR 19 /* Power and Loopback Register */ |
| 976 | #define MII_AM79C874_MCR 21 /* ModeControl Register */ |
| 977 | #define MII_AM79C874_DC 23 /* Disconnect Counter */ |
| 978 | #define MII_AM79C874_REC 24 /* Recieve Error Counter */ |
| 979 | |
| 980 | static void mii_parse_am79c874_dr(uint mii_reg, struct net_device *dev) |
| 981 | { |
| 982 | struct fec_enet_private *fep = netdev_priv(dev); |
| 983 | volatile uint *s = &(fep->phy_status); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 984 | uint status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 986 | status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
| 988 | if (mii_reg & 0x0080) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 989 | status |= PHY_STAT_ANC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | if (mii_reg & 0x0400) |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 991 | status |= ((mii_reg & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | else |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 993 | status |= ((mii_reg & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX); |
| 994 | |
| 995 | *s = status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 998 | static phy_cmd_t const phy_cmd_am79c874_config[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 1000 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 1001 | { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr }, |
| 1002 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1003 | }; |
| 1004 | static phy_cmd_t const phy_cmd_am79c874_startup[] = { /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL }, |
| 1006 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1007 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1009 | }; |
| 1010 | static phy_cmd_t const phy_cmd_am79c874_ack_int[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | /* find out the current status */ |
| 1012 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 1013 | { mk_mii_read(MII_AM79C874_DR), mii_parse_am79c874_dr }, |
| 1014 | /* we only need to read ISR to acknowledge */ |
| 1015 | { mk_mii_read(MII_AM79C874_ICSR), NULL }, |
| 1016 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1017 | }; |
| 1018 | static phy_cmd_t const phy_cmd_am79c874_shutdown[] = { /* disable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { mk_mii_write(MII_AM79C874_ICSR, 0x0000), NULL }, |
| 1020 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1021 | }; |
| 1022 | static phy_info_t const phy_info_am79c874 = { |
| 1023 | .id = 0x00022561, |
| 1024 | .name = "AM79C874", |
| 1025 | .config = phy_cmd_am79c874_config, |
| 1026 | .startup = phy_cmd_am79c874_startup, |
| 1027 | .ack_int = phy_cmd_am79c874_ack_int, |
| 1028 | .shutdown = phy_cmd_am79c874_shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | }; |
| 1030 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | /* ------------------------------------------------------------------------- */ |
| 1033 | /* Kendin KS8721BL phy */ |
| 1034 | |
| 1035 | /* register definitions for the 8721 */ |
| 1036 | |
| 1037 | #define MII_KS8721BL_RXERCR 21 |
Sascha Hauer | 43268dc | 2009-01-28 23:03:08 +0000 | [diff] [blame] | 1038 | #define MII_KS8721BL_ICSR 27 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | #define MII_KS8721BL_PHYCR 31 |
| 1040 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1041 | static phy_cmd_t const phy_cmd_ks8721bl_config[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 1043 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 1044 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1045 | }; |
| 1046 | static phy_cmd_t const phy_cmd_ks8721bl_startup[] = { /* enable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL }, |
| 1048 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1049 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1051 | }; |
| 1052 | static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | /* find out the current status */ |
| 1054 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 1055 | /* we only need to read ISR to acknowledge */ |
| 1056 | { mk_mii_read(MII_KS8721BL_ICSR), NULL }, |
| 1057 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1058 | }; |
| 1059 | static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | { mk_mii_write(MII_KS8721BL_ICSR, 0x0000), NULL }, |
| 1061 | { mk_mii_end, } |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1062 | }; |
| 1063 | static phy_info_t const phy_info_ks8721bl = { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1064 | .id = 0x00022161, |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1065 | .name = "KS8721BL", |
| 1066 | .config = phy_cmd_ks8721bl_config, |
| 1067 | .startup = phy_cmd_ks8721bl_startup, |
| 1068 | .ack_int = phy_cmd_ks8721bl_ack_int, |
| 1069 | .shutdown = phy_cmd_ks8721bl_shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | }; |
| 1071 | |
| 1072 | /* ------------------------------------------------------------------------- */ |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 1073 | /* register definitions for the DP83848 */ |
| 1074 | |
| 1075 | #define MII_DP8384X_PHYSTST 16 /* PHY Status Register */ |
| 1076 | |
| 1077 | static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev) |
| 1078 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1079 | struct fec_enet_private *fep = netdev_priv(dev); |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 1080 | volatile uint *s = &(fep->phy_status); |
| 1081 | |
| 1082 | *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC); |
| 1083 | |
| 1084 | /* Link up */ |
| 1085 | if (mii_reg & 0x0001) { |
| 1086 | fep->link = 1; |
| 1087 | *s |= PHY_STAT_LINK; |
| 1088 | } else |
| 1089 | fep->link = 0; |
| 1090 | /* Status of link */ |
| 1091 | if (mii_reg & 0x0010) /* Autonegotioation complete */ |
| 1092 | *s |= PHY_STAT_ANC; |
| 1093 | if (mii_reg & 0x0002) { /* 10MBps? */ |
| 1094 | if (mii_reg & 0x0004) /* Full Duplex? */ |
| 1095 | *s |= PHY_STAT_10FDX; |
| 1096 | else |
| 1097 | *s |= PHY_STAT_10HDX; |
| 1098 | } else { /* 100 Mbps? */ |
| 1099 | if (mii_reg & 0x0004) /* Full Duplex? */ |
| 1100 | *s |= PHY_STAT_100FDX; |
| 1101 | else |
| 1102 | *s |= PHY_STAT_100HDX; |
| 1103 | } |
| 1104 | if (mii_reg & 0x0008) |
| 1105 | *s |= PHY_STAT_FAULT; |
| 1106 | } |
| 1107 | |
| 1108 | static phy_info_t phy_info_dp83848= { |
| 1109 | 0x020005c9, |
| 1110 | "DP83848", |
| 1111 | |
| 1112 | (const phy_cmd_t []) { /* config */ |
| 1113 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 1114 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 1115 | { mk_mii_read(MII_DP8384X_PHYSTST), mii_parse_dp8384x_sr2 }, |
| 1116 | { mk_mii_end, } |
| 1117 | }, |
| 1118 | (const phy_cmd_t []) { /* startup - enable interrupts */ |
| 1119 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
| 1120 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 1121 | { mk_mii_end, } |
| 1122 | }, |
| 1123 | (const phy_cmd_t []) { /* ack_int - never happens, no interrupt */ |
| 1124 | { mk_mii_end, } |
| 1125 | }, |
| 1126 | (const phy_cmd_t []) { /* shutdown */ |
| 1127 | { mk_mii_end, } |
| 1128 | }, |
| 1129 | }; |
| 1130 | |
Amit Kucheria | fceb291 | 2010-02-05 08:56:21 +0000 | [diff] [blame] | 1131 | static phy_info_t phy_info_lan8700 = { |
| 1132 | 0x0007C0C, |
| 1133 | "LAN8700", |
| 1134 | (const phy_cmd_t []) { /* config */ |
| 1135 | { mk_mii_read(MII_REG_CR), mii_parse_cr }, |
| 1136 | { mk_mii_read(MII_REG_ANAR), mii_parse_anar }, |
| 1137 | { mk_mii_end, } |
| 1138 | }, |
| 1139 | (const phy_cmd_t []) { /* startup */ |
| 1140 | { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */ |
| 1141 | { mk_mii_read(MII_REG_SR), mii_parse_sr }, |
| 1142 | { mk_mii_end, } |
| 1143 | }, |
| 1144 | (const phy_cmd_t []) { /* act_int */ |
| 1145 | { mk_mii_end, } |
| 1146 | }, |
| 1147 | (const phy_cmd_t []) { /* shutdown */ |
| 1148 | { mk_mii_end, } |
| 1149 | }, |
| 1150 | }; |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 1151 | /* ------------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1153 | static phy_info_t const * const phy_info[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | &phy_info_lxt970, |
| 1155 | &phy_info_lxt971, |
| 1156 | &phy_info_qs6612, |
| 1157 | &phy_info_am79c874, |
| 1158 | &phy_info_ks8721bl, |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 1159 | &phy_info_dp83848, |
Amit Kucheria | fceb291 | 2010-02-05 08:56:21 +0000 | [diff] [blame] | 1160 | &phy_info_lan8700, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | NULL |
| 1162 | }; |
| 1163 | |
| 1164 | /* ------------------------------------------------------------------------- */ |
Sebastian Siewior | c1d9615 | 2008-05-01 14:04:02 +1000 | [diff] [blame] | 1165 | #ifdef HAVE_mii_link_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1167 | mii_link_interrupt(int irq, void * dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | /* |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 1170 | * This is specific to the MII interrupt setup of the M5272EVB. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | */ |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 1172 | static void __inline__ fec_request_mii_intr(struct net_device *dev) |
| 1173 | { |
| 1174 | if (request_irq(66, mii_link_interrupt, IRQF_DISABLED, "fec(MII)", dev) != 0) |
| 1175 | printk("FEC: Could not allocate fec(MII) IRQ(66)!\n"); |
| 1176 | } |
| 1177 | |
Greg Ungerer | 4980296 | 2009-07-07 12:13:23 +1000 | [diff] [blame] | 1178 | static void __inline__ fec_disable_phy_intr(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { |
Greg Ungerer | 4980296 | 2009-07-07 12:13:23 +1000 | [diff] [blame] | 1180 | free_irq(66, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | } |
Sascha Hauer | fb922b0 | 2009-04-08 15:44:45 -0700 | [diff] [blame] | 1182 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 1184 | #ifdef CONFIG_M5272 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | static void __inline__ fec_get_mac(struct net_device *dev) |
| 1186 | { |
| 1187 | struct fec_enet_private *fep = netdev_priv(dev); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1188 | unsigned char *iap, tmpaddr[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1190 | if (FEC_FLASHMAC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | /* |
| 1192 | * Get MAC address from FLASH. |
| 1193 | * If it is all 1's or 0's, use the default. |
| 1194 | */ |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1195 | iap = (unsigned char *)FEC_FLASHMAC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) && |
| 1197 | (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0)) |
| 1198 | iap = fec_mac_default; |
| 1199 | if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) && |
| 1200 | (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff)) |
| 1201 | iap = fec_mac_default; |
| 1202 | } else { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1203 | *((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW); |
| 1204 | *((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | iap = &tmpaddr[0]; |
| 1206 | } |
| 1207 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1208 | memcpy(dev->dev_addr, iap, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
| 1210 | /* Adjust MAC if using default MAC address */ |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1211 | if (iap == fec_mac_default) |
| 1212 | dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | #endif |
| 1215 | |
| 1216 | /* ------------------------------------------------------------------------- */ |
| 1217 | |
| 1218 | static void mii_display_status(struct net_device *dev) |
| 1219 | { |
| 1220 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1221 | volatile uint *s = &(fep->phy_status); |
| 1222 | |
| 1223 | if (!fep->link && !fep->old_link) { |
| 1224 | /* Link is still down - don't print anything */ |
| 1225 | return; |
| 1226 | } |
| 1227 | |
| 1228 | printk("%s: status: ", dev->name); |
| 1229 | |
| 1230 | if (!fep->link) { |
| 1231 | printk("link down"); |
| 1232 | } else { |
| 1233 | printk("link up"); |
| 1234 | |
| 1235 | switch(*s & PHY_STAT_SPMASK) { |
| 1236 | case PHY_STAT_100FDX: printk(", 100MBit Full Duplex"); break; |
| 1237 | case PHY_STAT_100HDX: printk(", 100MBit Half Duplex"); break; |
| 1238 | case PHY_STAT_10FDX: printk(", 10MBit Full Duplex"); break; |
| 1239 | case PHY_STAT_10HDX: printk(", 10MBit Half Duplex"); break; |
| 1240 | default: |
| 1241 | printk(", Unknown speed/duplex"); |
| 1242 | } |
| 1243 | |
| 1244 | if (*s & PHY_STAT_ANC) |
| 1245 | printk(", auto-negotiation complete"); |
| 1246 | } |
| 1247 | |
| 1248 | if (*s & PHY_STAT_FAULT) |
| 1249 | printk(", remote fault"); |
| 1250 | |
| 1251 | printk(".\n"); |
| 1252 | } |
| 1253 | |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1254 | static void mii_display_config(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | { |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1256 | struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task); |
| 1257 | struct net_device *dev = fep->netdev; |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1258 | uint status = fep->phy_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | /* |
| 1261 | ** When we get here, phy_task is already removed from |
| 1262 | ** the workqueue. It is thus safe to allow to reuse it. |
| 1263 | */ |
| 1264 | fep->mii_phy_task_queued = 0; |
| 1265 | printk("%s: config: auto-negotiation ", dev->name); |
| 1266 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1267 | if (status & PHY_CONF_ANE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | printk("on"); |
| 1269 | else |
| 1270 | printk("off"); |
| 1271 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1272 | if (status & PHY_CONF_100FDX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | printk(", 100FDX"); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1274 | if (status & PHY_CONF_100HDX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | printk(", 100HDX"); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1276 | if (status & PHY_CONF_10FDX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | printk(", 10FDX"); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1278 | if (status & PHY_CONF_10HDX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | printk(", 10HDX"); |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1280 | if (!(status & PHY_CONF_SPMASK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | printk(", No speed/duplex selected?"); |
| 1282 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1283 | if (status & PHY_CONF_LOOP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | printk(", loopback enabled"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | printk(".\n"); |
| 1287 | |
| 1288 | fep->sequence_done = 1; |
| 1289 | } |
| 1290 | |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1291 | static void mii_relink(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | { |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1293 | struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task); |
| 1294 | struct net_device *dev = fep->netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | int duplex; |
| 1296 | |
| 1297 | /* |
| 1298 | ** When we get here, phy_task is already removed from |
| 1299 | ** the workqueue. It is thus safe to allow to reuse it. |
| 1300 | */ |
| 1301 | fep->mii_phy_task_queued = 0; |
| 1302 | fep->link = (fep->phy_status & PHY_STAT_LINK) ? 1 : 0; |
| 1303 | mii_display_status(dev); |
| 1304 | fep->old_link = fep->link; |
| 1305 | |
| 1306 | if (fep->link) { |
| 1307 | duplex = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1308 | if (fep->phy_status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | & (PHY_STAT_100FDX | PHY_STAT_10FDX)) |
| 1310 | duplex = 1; |
| 1311 | fec_restart(dev, duplex); |
Philippe De Muyter | f909b1e | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 1312 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | fec_stop(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | /* mii_queue_relink is called in interrupt context from mii_link_interrupt */ |
| 1317 | static void mii_queue_relink(uint mii_reg, struct net_device *dev) |
| 1318 | { |
| 1319 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1320 | |
| 1321 | /* |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1322 | * We cannot queue phy_task twice in the workqueue. It |
| 1323 | * would cause an endless loop in the workqueue. |
| 1324 | * Fortunately, if the last mii_relink entry has not yet been |
| 1325 | * executed now, it will do the job for the current interrupt, |
| 1326 | * which is just what we want. |
| 1327 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | if (fep->mii_phy_task_queued) |
| 1329 | return; |
| 1330 | |
| 1331 | fep->mii_phy_task_queued = 1; |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1332 | INIT_WORK(&fep->phy_task, mii_relink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | schedule_work(&fep->phy_task); |
| 1334 | } |
| 1335 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1336 | /* mii_queue_config is called in interrupt context from fec_enet_mii */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | static void mii_queue_config(uint mii_reg, struct net_device *dev) |
| 1338 | { |
| 1339 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1340 | |
| 1341 | if (fep->mii_phy_task_queued) |
| 1342 | return; |
| 1343 | |
| 1344 | fep->mii_phy_task_queued = 1; |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1345 | INIT_WORK(&fep->phy_task, mii_display_config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | schedule_work(&fep->phy_task); |
| 1347 | } |
| 1348 | |
Greg Ungerer | 7dd6a2a | 2005-09-12 11:18:10 +1000 | [diff] [blame] | 1349 | phy_cmd_t const phy_cmd_relink[] = { |
| 1350 | { mk_mii_read(MII_REG_CR), mii_queue_relink }, |
| 1351 | { mk_mii_end, } |
| 1352 | }; |
| 1353 | phy_cmd_t const phy_cmd_config[] = { |
| 1354 | { mk_mii_read(MII_REG_CR), mii_queue_config }, |
| 1355 | { mk_mii_end, } |
| 1356 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1358 | /* Read remainder of PHY ID. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | static void |
| 1360 | mii_discover_phy3(uint mii_reg, struct net_device *dev) |
| 1361 | { |
| 1362 | struct fec_enet_private *fep; |
| 1363 | int i; |
| 1364 | |
| 1365 | fep = netdev_priv(dev); |
| 1366 | fep->phy_id |= (mii_reg & 0xffff); |
| 1367 | printk("fec: PHY @ 0x%x, ID 0x%08x", fep->phy_addr, fep->phy_id); |
| 1368 | |
| 1369 | for(i = 0; phy_info[i]; i++) { |
| 1370 | if(phy_info[i]->id == (fep->phy_id >> 4)) |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | if (phy_info[i]) |
| 1375 | printk(" -- %s\n", phy_info[i]->name); |
| 1376 | else |
| 1377 | printk(" -- unknown PHY!\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | fep->phy = phy_info[i]; |
| 1380 | fep->phy_id_done = 1; |
| 1381 | } |
| 1382 | |
| 1383 | /* Scan all of the MII PHY addresses looking for someone to respond |
| 1384 | * with a valid ID. This usually happens quickly. |
| 1385 | */ |
| 1386 | static void |
| 1387 | mii_discover_phy(uint mii_reg, struct net_device *dev) |
| 1388 | { |
| 1389 | struct fec_enet_private *fep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | uint phytype; |
| 1391 | |
| 1392 | fep = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
| 1394 | if (fep->phy_addr < 32) { |
| 1395 | if ((phytype = (mii_reg & 0xffff)) != 0xffff && phytype != 0) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1396 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1397 | /* Got first part of ID, now get remainder */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | fep->phy_id = phytype << 16; |
Uwe Kleine-König | 84177a20 | 2009-09-01 23:14:15 +0000 | [diff] [blame] | 1399 | mii_queue_unlocked(dev, mk_mii_read(MII_REG_PHYIR2), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | mii_discover_phy3); |
Philippe De Muyter | f909b1e | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 1401 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | fep->phy_addr++; |
Uwe Kleine-König | 84177a20 | 2009-09-01 23:14:15 +0000 | [diff] [blame] | 1403 | mii_queue_unlocked(dev, mk_mii_read(MII_REG_PHYIR1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | mii_discover_phy); |
| 1405 | } |
| 1406 | } else { |
| 1407 | printk("FEC: No PHY device found.\n"); |
| 1408 | /* Disable external MII interface */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1409 | writel(0, fep->hwp + FEC_MII_SPEED); |
| 1410 | fep->phy_speed = 0; |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 1411 | #ifdef HAVE_mii_link_interrupt |
Greg Ungerer | 4980296 | 2009-07-07 12:13:23 +1000 | [diff] [blame] | 1412 | fec_disable_phy_intr(dev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1413 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | } |
| 1416 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1417 | /* This interrupt occurs when the PHY detects a link change */ |
Sebastian Siewior | c1d9615 | 2008-05-01 14:04:02 +1000 | [diff] [blame] | 1418 | #ifdef HAVE_mii_link_interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1420 | mii_link_interrupt(int irq, void * dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | { |
| 1422 | struct net_device *dev = dev_id; |
| 1423 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | mii_do_cmd(dev, fep->phy->ack_int); |
| 1426 | mii_do_cmd(dev, phy_cmd_relink); /* restart and display status */ |
| 1427 | |
| 1428 | return IRQ_HANDLED; |
| 1429 | } |
Sebastian Siewior | c1d9615 | 2008-05-01 14:04:02 +1000 | [diff] [blame] | 1430 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1432 | static void fec_enet_free_buffers(struct net_device *dev) |
| 1433 | { |
| 1434 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1435 | int i; |
| 1436 | struct sk_buff *skb; |
| 1437 | struct bufdesc *bdp; |
| 1438 | |
| 1439 | bdp = fep->rx_bd_base; |
| 1440 | for (i = 0; i < RX_RING_SIZE; i++) { |
| 1441 | skb = fep->rx_skbuff[i]; |
| 1442 | |
| 1443 | if (bdp->cbd_bufaddr) |
| 1444 | dma_unmap_single(&dev->dev, bdp->cbd_bufaddr, |
| 1445 | FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); |
| 1446 | if (skb) |
| 1447 | dev_kfree_skb(skb); |
| 1448 | bdp++; |
| 1449 | } |
| 1450 | |
| 1451 | bdp = fep->tx_bd_base; |
| 1452 | for (i = 0; i < TX_RING_SIZE; i++) |
| 1453 | kfree(fep->tx_bounce[i]); |
| 1454 | } |
| 1455 | |
| 1456 | static int fec_enet_alloc_buffers(struct net_device *dev) |
| 1457 | { |
| 1458 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1459 | int i; |
| 1460 | struct sk_buff *skb; |
| 1461 | struct bufdesc *bdp; |
| 1462 | |
| 1463 | bdp = fep->rx_bd_base; |
| 1464 | for (i = 0; i < RX_RING_SIZE; i++) { |
| 1465 | skb = dev_alloc_skb(FEC_ENET_RX_FRSIZE); |
| 1466 | if (!skb) { |
| 1467 | fec_enet_free_buffers(dev); |
| 1468 | return -ENOMEM; |
| 1469 | } |
| 1470 | fep->rx_skbuff[i] = skb; |
| 1471 | |
| 1472 | bdp->cbd_bufaddr = dma_map_single(&dev->dev, skb->data, |
| 1473 | FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE); |
| 1474 | bdp->cbd_sc = BD_ENET_RX_EMPTY; |
| 1475 | bdp++; |
| 1476 | } |
| 1477 | |
| 1478 | /* Set the last buffer to wrap. */ |
| 1479 | bdp--; |
| 1480 | bdp->cbd_sc |= BD_SC_WRAP; |
| 1481 | |
| 1482 | bdp = fep->tx_bd_base; |
| 1483 | for (i = 0; i < TX_RING_SIZE; i++) { |
| 1484 | fep->tx_bounce[i] = kmalloc(FEC_ENET_TX_FRSIZE, GFP_KERNEL); |
| 1485 | |
| 1486 | bdp->cbd_sc = 0; |
| 1487 | bdp->cbd_bufaddr = 0; |
| 1488 | bdp++; |
| 1489 | } |
| 1490 | |
| 1491 | /* Set the last buffer to wrap. */ |
| 1492 | bdp--; |
| 1493 | bdp->cbd_sc |= BD_SC_WRAP; |
| 1494 | |
| 1495 | return 0; |
| 1496 | } |
| 1497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | static int |
| 1499 | fec_enet_open(struct net_device *dev) |
| 1500 | { |
| 1501 | struct fec_enet_private *fep = netdev_priv(dev); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1502 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
| 1504 | /* I should reset the ring buffers here, but I don't yet know |
| 1505 | * a simple way to do that. |
| 1506 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1508 | ret = fec_enet_alloc_buffers(dev); |
| 1509 | if (ret) |
| 1510 | return ret; |
| 1511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | fep->sequence_done = 0; |
| 1513 | fep->link = 0; |
| 1514 | |
Sascha Hauer | fe957c4 | 2009-04-15 01:32:25 +0000 | [diff] [blame] | 1515 | fec_restart(dev, 1); |
| 1516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | if (fep->phy) { |
| 1518 | mii_do_cmd(dev, fep->phy->ack_int); |
| 1519 | mii_do_cmd(dev, fep->phy->config); |
| 1520 | mii_do_cmd(dev, phy_cmd_config); /* display configuration */ |
| 1521 | |
Matt Waddel | 6b26529 | 2006-06-27 13:10:56 +1000 | [diff] [blame] | 1522 | /* Poll until the PHY tells us its configuration |
| 1523 | * (not link state). |
| 1524 | * Request is initiated by mii_do_cmd above, but answer |
| 1525 | * comes by interrupt. |
| 1526 | * This should take about 25 usec per register at 2.5 MHz, |
| 1527 | * and we read approximately 5 registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | */ |
| 1529 | while(!fep->sequence_done) |
| 1530 | schedule(); |
| 1531 | |
| 1532 | mii_do_cmd(dev, fep->phy->startup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Sascha Hauer | fe957c4 | 2009-04-15 01:32:25 +0000 | [diff] [blame] | 1535 | /* Set the initial link state to true. A lot of hardware |
| 1536 | * based on this device does not implement a PHY interrupt, |
| 1537 | * so we are never notified of link change. |
| 1538 | */ |
| 1539 | fep->link = 1; |
| 1540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | netif_start_queue(dev); |
| 1542 | fep->opened = 1; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1543 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | static int |
| 1547 | fec_enet_close(struct net_device *dev) |
| 1548 | { |
| 1549 | struct fec_enet_private *fep = netdev_priv(dev); |
| 1550 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1551 | /* Don't know what to do yet. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | fep->opened = 0; |
| 1553 | netif_stop_queue(dev); |
| 1554 | fec_stop(dev); |
| 1555 | |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1556 | fec_enet_free_buffers(dev); |
| 1557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | return 0; |
| 1559 | } |
| 1560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | /* Set or clear the multicast filter for this adaptor. |
| 1562 | * Skeleton taken from sunlance driver. |
| 1563 | * The CPM Ethernet implementation allows Multicast as well as individual |
| 1564 | * MAC address filtering. Some of the drivers check to make sure it is |
| 1565 | * a group multicast address, and discard those that are not. I guess I |
| 1566 | * will do the same for now, but just remove the test if you want |
| 1567 | * individual filtering as well (do the upper net layers want or support |
| 1568 | * this kind of feature?). |
| 1569 | */ |
| 1570 | |
| 1571 | #define HASH_BITS 6 /* #bits in hash */ |
| 1572 | #define CRC32_POLY 0xEDB88320 |
| 1573 | |
| 1574 | static void set_multicast_list(struct net_device *dev) |
| 1575 | { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1576 | struct fec_enet_private *fep = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | struct dev_mc_list *dmi; |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 1578 | unsigned int i, bit, data, crc, tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | unsigned char hash; |
| 1580 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1581 | if (dev->flags & IFF_PROMISC) { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1582 | tmp = readl(fep->hwp + FEC_R_CNTRL); |
| 1583 | tmp |= 0x8; |
| 1584 | writel(tmp, fep->hwp + FEC_R_CNTRL); |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1585 | return; |
| 1586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1588 | tmp = readl(fep->hwp + FEC_R_CNTRL); |
| 1589 | tmp &= ~0x8; |
| 1590 | writel(tmp, fep->hwp + FEC_R_CNTRL); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1591 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1592 | if (dev->flags & IFF_ALLMULTI) { |
| 1593 | /* Catch all multicast addresses, so set the |
| 1594 | * filter to all 1's |
| 1595 | */ |
| 1596 | writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 1597 | writel(0xffffffff, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1599 | return; |
| 1600 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1601 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1602 | /* Clear filter and add the addresses in hash register |
| 1603 | */ |
| 1604 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 1605 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 1607 | netdev_for_each_mc_addr(dmi, dev) { |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1608 | /* Only support group multicast for now */ |
| 1609 | if (!(dmi->dmi_addr[0] & 1)) |
| 1610 | continue; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1611 | |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1612 | /* calculate crc32 value of mac address */ |
| 1613 | crc = 0xffffffff; |
| 1614 | |
| 1615 | for (i = 0; i < dmi->dmi_addrlen; i++) { |
| 1616 | data = dmi->dmi_addr[i]; |
| 1617 | for (bit = 0; bit < 8; bit++, data >>= 1) { |
| 1618 | crc = (crc >> 1) ^ |
| 1619 | (((crc ^ data) & 1) ? CRC32_POLY : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | } |
| 1621 | } |
Sascha Hauer | 4e83183 | 2009-04-15 01:32:19 +0000 | [diff] [blame] | 1622 | |
| 1623 | /* only upper 6 bits (HASH_BITS) are used |
| 1624 | * which point to specific bit in he hash registers |
| 1625 | */ |
| 1626 | hash = (crc >> (32 - HASH_BITS)) & 0x3f; |
| 1627 | |
| 1628 | if (hash > 31) { |
| 1629 | tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 1630 | tmp |= 1 << (hash - 32); |
| 1631 | writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 1632 | } else { |
| 1633 | tmp = readl(fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
| 1634 | tmp |= 1 << hash; |
| 1635 | writel(tmp, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
| 1636 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1640 | /* Set a MAC change in hardware. */ |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1641 | static int |
| 1642 | fec_set_mac_address(struct net_device *dev, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1644 | struct fec_enet_private *fep = netdev_priv(dev); |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1645 | struct sockaddr *addr = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1647 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1648 | return -EADDRNOTAVAIL; |
| 1649 | |
| 1650 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 1651 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1652 | writel(dev->dev_addr[3] | (dev->dev_addr[2] << 8) | |
| 1653 | (dev->dev_addr[1] << 16) | (dev->dev_addr[0] << 24), |
| 1654 | fep->hwp + FEC_ADDR_LOW); |
| 1655 | writel((dev->dev_addr[5] << 16) | (dev->dev_addr[4] << 24), |
Mattias Walström | 7cff094 | 2010-05-05 00:55:48 -0700 | [diff] [blame] | 1656 | fep->hwp + FEC_ADDR_HIGH); |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1657 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1660 | static const struct net_device_ops fec_netdev_ops = { |
| 1661 | .ndo_open = fec_enet_open, |
| 1662 | .ndo_stop = fec_enet_close, |
| 1663 | .ndo_start_xmit = fec_enet_start_xmit, |
| 1664 | .ndo_set_multicast_list = set_multicast_list, |
Ben Hutchings | 635ecaa | 2009-07-09 17:59:01 +0000 | [diff] [blame] | 1665 | .ndo_change_mtu = eth_change_mtu, |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1666 | .ndo_validate_addr = eth_validate_addr, |
| 1667 | .ndo_tx_timeout = fec_timeout, |
| 1668 | .ndo_set_mac_address = fec_set_mac_address, |
| 1669 | }; |
| 1670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | /* |
| 1672 | * XXX: We need to clean up on failure exits here. |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1673 | * |
| 1674 | * index is only used in legacy code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | */ |
Steven King | 78abcb1 | 2009-10-20 18:51:37 -0700 | [diff] [blame] | 1676 | static int fec_enet_init(struct net_device *dev, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | { |
| 1678 | struct fec_enet_private *fep = netdev_priv(dev); |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1679 | struct bufdesc *cbd_base; |
Rob Herring | 633e753 | 2010-02-05 08:56:20 +0000 | [diff] [blame] | 1680 | struct bufdesc *bdp; |
Sascha Hauer | f0b3fbe | 2009-04-15 01:32:24 +0000 | [diff] [blame] | 1681 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Sascha Hauer | 8d4dd5c | 2009-04-15 01:32:17 +0000 | [diff] [blame] | 1683 | /* Allocate memory for buffer descriptors. */ |
| 1684 | cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma, |
| 1685 | GFP_KERNEL); |
| 1686 | if (!cbd_base) { |
Greg Ungerer | 562d2f8 | 2005-11-07 14:09:50 +1000 | [diff] [blame] | 1687 | printk("FEC: allocate descriptor memory failed?\n"); |
| 1688 | return -ENOMEM; |
| 1689 | } |
| 1690 | |
Sebastian Siewior | 3b2b74c | 2008-05-01 14:08:12 +1000 | [diff] [blame] | 1691 | spin_lock_init(&fep->hw_lock); |
| 1692 | spin_lock_init(&fep->mii_lock); |
| 1693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | fep->index = index; |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1695 | fep->hwp = (void __iomem *)dev->base_addr; |
Greg Ungerer | cb84d6e | 2007-07-30 16:29:09 +1000 | [diff] [blame] | 1696 | fep->netdev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1698 | /* Set the Ethernet address */ |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 1699 | #ifdef CONFIG_M5272 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | fec_get_mac(dev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1701 | #else |
| 1702 | { |
| 1703 | unsigned long l; |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1704 | l = readl(fep->hwp + FEC_ADDR_LOW); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1705 | dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24); |
| 1706 | dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16); |
| 1707 | dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8); |
| 1708 | dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0); |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1709 | l = readl(fep->hwp + FEC_ADDR_HIGH); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1710 | dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24); |
| 1711 | dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16); |
| 1712 | } |
| 1713 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
Sascha Hauer | 8d4dd5c | 2009-04-15 01:32:17 +0000 | [diff] [blame] | 1715 | /* Set receive and transmit descriptor base. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | fep->rx_bd_base = cbd_base; |
| 1717 | fep->tx_bd_base = cbd_base + RX_RING_SIZE; |
| 1718 | |
Greg Ungerer | 43be636 | 2009-02-26 22:42:51 -0800 | [diff] [blame] | 1719 | #ifdef HAVE_mii_link_interrupt |
| 1720 | fec_request_mii_intr(dev); |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1721 | #endif |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1722 | /* The FEC Ethernet specific entries in the device structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | dev->watchdog_timeo = TX_TIMEOUT; |
Sascha Hauer | 009fda8 | 2009-04-15 01:32:23 +0000 | [diff] [blame] | 1724 | dev->netdev_ops = &fec_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
| 1726 | for (i=0; i<NMII-1; i++) |
| 1727 | mii_cmds[i].mii_next = &mii_cmds[i+1]; |
| 1728 | mii_free = mii_cmds; |
| 1729 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1730 | /* Set MII speed to 2.5 MHz */ |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1731 | fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999) |
| 1732 | / 2500000) / 2) & 0x3F) << 1; |
Rob Herring | 633e753 | 2010-02-05 08:56:20 +0000 | [diff] [blame] | 1733 | |
| 1734 | /* Initialize the receive buffer descriptors. */ |
| 1735 | bdp = fep->rx_bd_base; |
| 1736 | for (i = 0; i < RX_RING_SIZE; i++) { |
| 1737 | |
| 1738 | /* Initialize the BD for every fragment in the page. */ |
| 1739 | bdp->cbd_sc = 0; |
| 1740 | bdp++; |
| 1741 | } |
| 1742 | |
| 1743 | /* Set the last buffer to wrap */ |
| 1744 | bdp--; |
| 1745 | bdp->cbd_sc |= BD_SC_WRAP; |
| 1746 | |
| 1747 | /* ...and the same for transmit */ |
| 1748 | bdp = fep->tx_bd_base; |
| 1749 | for (i = 0; i < TX_RING_SIZE; i++) { |
| 1750 | |
| 1751 | /* Initialize the BD for every fragment in the page. */ |
| 1752 | bdp->cbd_sc = 0; |
| 1753 | bdp->cbd_bufaddr = 0; |
| 1754 | bdp++; |
| 1755 | } |
| 1756 | |
| 1757 | /* Set the last buffer to wrap */ |
| 1758 | bdp--; |
| 1759 | bdp->cbd_sc |= BD_SC_WRAP; |
| 1760 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1761 | fec_restart(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | /* Queue up command to detect the PHY and initialize the |
| 1764 | * remainder of the interface. |
| 1765 | */ |
| 1766 | fep->phy_id_done = 0; |
| 1767 | fep->phy_addr = 0; |
| 1768 | mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy); |
| 1769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return 0; |
| 1771 | } |
| 1772 | |
| 1773 | /* This function is called to start or restart the FEC during a link |
| 1774 | * change. This only happens when switching between half and full |
| 1775 | * duplex. |
| 1776 | */ |
| 1777 | static void |
| 1778 | fec_restart(struct net_device *dev, int duplex) |
| 1779 | { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1780 | struct fec_enet_private *fep = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | int i; |
| 1782 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1783 | /* Whack a reset. We should wait for this. */ |
| 1784 | writel(1, fep->hwp + FEC_ECNTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | udelay(10); |
| 1786 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1787 | /* Clear any outstanding interrupt. */ |
| 1788 | writel(0xffc00000, fep->hwp + FEC_IEVENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1790 | /* Reset all multicast. */ |
| 1791 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_HIGH); |
| 1792 | writel(0, fep->hwp + FEC_GRP_HASH_TABLE_LOW); |
Sascha Hauer | 4f1ceb4 | 2009-04-15 01:32:20 +0000 | [diff] [blame] | 1793 | #ifndef CONFIG_M5272 |
| 1794 | writel(0, fep->hwp + FEC_HASH_TABLE_HIGH); |
| 1795 | writel(0, fep->hwp + FEC_HASH_TABLE_LOW); |
| 1796 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1798 | /* Set maximum receive buffer size. */ |
| 1799 | writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1801 | /* Set receive and transmit descriptor base. */ |
| 1802 | writel(fep->bd_dma, fep->hwp + FEC_R_DES_START); |
Sascha Hauer | 2e28532 | 2009-04-15 01:32:16 +0000 | [diff] [blame] | 1803 | writel((unsigned long)fep->bd_dma + sizeof(struct bufdesc) * RX_RING_SIZE, |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1804 | fep->hwp + FEC_X_DES_START); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
| 1806 | fep->dirty_tx = fep->cur_tx = fep->tx_bd_base; |
| 1807 | fep->cur_rx = fep->rx_bd_base; |
| 1808 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1809 | /* Reset SKB transmit buffers. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | fep->skb_cur = fep->skb_dirty = 0; |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1811 | for (i = 0; i <= TX_RING_MOD_MASK; i++) { |
| 1812 | if (fep->tx_skbuff[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | dev_kfree_skb_any(fep->tx_skbuff[i]); |
| 1814 | fep->tx_skbuff[i] = NULL; |
| 1815 | } |
| 1816 | } |
| 1817 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1818 | /* Enable MII mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | if (duplex) { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1820 | /* MII enable / FD enable */ |
| 1821 | writel(OPT_FRAME_SIZE | 0x04, fep->hwp + FEC_R_CNTRL); |
| 1822 | writel(0x04, fep->hwp + FEC_X_CNTRL); |
Philippe De Muyter | f909b1e | 2007-10-23 14:37:54 +1000 | [diff] [blame] | 1823 | } else { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1824 | /* MII enable / No Rcv on Xmit */ |
| 1825 | writel(OPT_FRAME_SIZE | 0x06, fep->hwp + FEC_R_CNTRL); |
| 1826 | writel(0x0, fep->hwp + FEC_X_CNTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | } |
| 1828 | fep->full_duplex = duplex; |
| 1829 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1830 | /* Set MII speed */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1831 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1833 | /* And last, enable the transmit and receive processing */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1834 | writel(2, fep->hwp + FEC_ECNTRL); |
| 1835 | writel(0, fep->hwp + FEC_R_DES_ACTIVE); |
Matt Waddel | 6b26529 | 2006-06-27 13:10:56 +1000 | [diff] [blame] | 1836 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1837 | /* Enable interrupts we wish to service */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1838 | writel(FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII, |
| 1839 | fep->hwp + FEC_IMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | static void |
| 1843 | fec_stop(struct net_device *dev) |
| 1844 | { |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1845 | struct fec_enet_private *fep = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
Sascha Hauer | 22f6b86 | 2009-04-15 01:32:18 +0000 | [diff] [blame] | 1847 | /* We cannot expect a graceful transmit stop without link !!! */ |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1848 | if (fep->link) { |
| 1849 | writel(1, fep->hwp + FEC_X_CNTRL); /* Graceful transmit stop */ |
Philippe De Muyter | 677177c | 2006-06-27 13:05:33 +1000 | [diff] [blame] | 1850 | udelay(10); |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1851 | if (!(readl(fep->hwp + FEC_IEVENT) & FEC_ENET_GRA)) |
Philippe De Muyter | 677177c | 2006-06-27 13:05:33 +1000 | [diff] [blame] | 1852 | printk("fec_stop : Graceful transmit stop did not complete !\n"); |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1855 | /* Whack a reset. We should wait for this. */ |
| 1856 | writel(1, fep->hwp + FEC_ECNTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | udelay(10); |
| 1858 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1859 | /* Clear outstanding MII command interrupts. */ |
| 1860 | writel(FEC_ENET_MII, fep->hwp + FEC_IEVENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
Sascha Hauer | f44d630 | 2009-04-15 03:11:30 +0000 | [diff] [blame] | 1862 | writel(FEC_ENET_MII, fep->hwp + FEC_IMASK); |
| 1863 | writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Sascha Hauer | ead7318 | 2009-01-28 23:03:11 +0000 | [diff] [blame] | 1866 | static int __devinit |
| 1867 | fec_probe(struct platform_device *pdev) |
| 1868 | { |
| 1869 | struct fec_enet_private *fep; |
| 1870 | struct net_device *ndev; |
| 1871 | int i, irq, ret = 0; |
| 1872 | struct resource *r; |
| 1873 | |
| 1874 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1875 | if (!r) |
| 1876 | return -ENXIO; |
| 1877 | |
| 1878 | r = request_mem_region(r->start, resource_size(r), pdev->name); |
| 1879 | if (!r) |
| 1880 | return -EBUSY; |
| 1881 | |
| 1882 | /* Init network device */ |
| 1883 | ndev = alloc_etherdev(sizeof(struct fec_enet_private)); |
| 1884 | if (!ndev) |
| 1885 | return -ENOMEM; |
| 1886 | |
| 1887 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 1888 | |
| 1889 | /* setup board info structure */ |
| 1890 | fep = netdev_priv(ndev); |
| 1891 | memset(fep, 0, sizeof(*fep)); |
| 1892 | |
| 1893 | ndev->base_addr = (unsigned long)ioremap(r->start, resource_size(r)); |
| 1894 | |
| 1895 | if (!ndev->base_addr) { |
| 1896 | ret = -ENOMEM; |
| 1897 | goto failed_ioremap; |
| 1898 | } |
| 1899 | |
| 1900 | platform_set_drvdata(pdev, ndev); |
| 1901 | |
| 1902 | /* This device has up to three irqs on some platforms */ |
| 1903 | for (i = 0; i < 3; i++) { |
| 1904 | irq = platform_get_irq(pdev, i); |
| 1905 | if (i && irq < 0) |
| 1906 | break; |
| 1907 | ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev); |
| 1908 | if (ret) { |
| 1909 | while (i >= 0) { |
| 1910 | irq = platform_get_irq(pdev, i); |
| 1911 | free_irq(irq, ndev); |
| 1912 | i--; |
| 1913 | } |
| 1914 | goto failed_irq; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | fep->clk = clk_get(&pdev->dev, "fec_clk"); |
| 1919 | if (IS_ERR(fep->clk)) { |
| 1920 | ret = PTR_ERR(fep->clk); |
| 1921 | goto failed_clk; |
| 1922 | } |
| 1923 | clk_enable(fep->clk); |
| 1924 | |
| 1925 | ret = fec_enet_init(ndev, 0); |
| 1926 | if (ret) |
| 1927 | goto failed_init; |
| 1928 | |
| 1929 | ret = register_netdev(ndev); |
| 1930 | if (ret) |
| 1931 | goto failed_register; |
| 1932 | |
| 1933 | return 0; |
| 1934 | |
| 1935 | failed_register: |
| 1936 | failed_init: |
| 1937 | clk_disable(fep->clk); |
| 1938 | clk_put(fep->clk); |
| 1939 | failed_clk: |
| 1940 | for (i = 0; i < 3; i++) { |
| 1941 | irq = platform_get_irq(pdev, i); |
| 1942 | if (irq > 0) |
| 1943 | free_irq(irq, ndev); |
| 1944 | } |
| 1945 | failed_irq: |
| 1946 | iounmap((void __iomem *)ndev->base_addr); |
| 1947 | failed_ioremap: |
| 1948 | free_netdev(ndev); |
| 1949 | |
| 1950 | return ret; |
| 1951 | } |
| 1952 | |
| 1953 | static int __devexit |
| 1954 | fec_drv_remove(struct platform_device *pdev) |
| 1955 | { |
| 1956 | struct net_device *ndev = platform_get_drvdata(pdev); |
| 1957 | struct fec_enet_private *fep = netdev_priv(ndev); |
| 1958 | |
| 1959 | platform_set_drvdata(pdev, NULL); |
| 1960 | |
| 1961 | fec_stop(ndev); |
| 1962 | clk_disable(fep->clk); |
| 1963 | clk_put(fep->clk); |
| 1964 | iounmap((void __iomem *)ndev->base_addr); |
| 1965 | unregister_netdev(ndev); |
| 1966 | free_netdev(ndev); |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | static int |
| 1971 | fec_suspend(struct platform_device *dev, pm_message_t state) |
| 1972 | { |
| 1973 | struct net_device *ndev = platform_get_drvdata(dev); |
| 1974 | struct fec_enet_private *fep; |
| 1975 | |
| 1976 | if (ndev) { |
| 1977 | fep = netdev_priv(ndev); |
| 1978 | if (netif_running(ndev)) { |
| 1979 | netif_device_detach(ndev); |
| 1980 | fec_stop(ndev); |
| 1981 | } |
| 1982 | } |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | static int |
| 1987 | fec_resume(struct platform_device *dev) |
| 1988 | { |
| 1989 | struct net_device *ndev = platform_get_drvdata(dev); |
| 1990 | |
| 1991 | if (ndev) { |
| 1992 | if (netif_running(ndev)) { |
| 1993 | fec_enet_init(ndev, 0); |
| 1994 | netif_device_attach(ndev); |
| 1995 | } |
| 1996 | } |
| 1997 | return 0; |
| 1998 | } |
| 1999 | |
| 2000 | static struct platform_driver fec_driver = { |
| 2001 | .driver = { |
| 2002 | .name = "fec", |
| 2003 | .owner = THIS_MODULE, |
| 2004 | }, |
| 2005 | .probe = fec_probe, |
| 2006 | .remove = __devexit_p(fec_drv_remove), |
| 2007 | .suspend = fec_suspend, |
| 2008 | .resume = fec_resume, |
| 2009 | }; |
| 2010 | |
| 2011 | static int __init |
| 2012 | fec_enet_module_init(void) |
| 2013 | { |
| 2014 | printk(KERN_INFO "FEC Ethernet Driver\n"); |
| 2015 | |
| 2016 | return platform_driver_register(&fec_driver); |
| 2017 | } |
| 2018 | |
| 2019 | static void __exit |
| 2020 | fec_enet_cleanup(void) |
| 2021 | { |
| 2022 | platform_driver_unregister(&fec_driver); |
| 2023 | } |
| 2024 | |
| 2025 | module_exit(fec_enet_cleanup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | module_init(fec_enet_module_init); |
| 2027 | |
| 2028 | MODULE_LICENSE("GPL"); |