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