Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1 | /* |
Mike Frysinger | 2fb9d6f | 2008-01-30 16:52:24 +0800 | [diff] [blame] | 2 | * Blackfin On-Chip MAC Driver |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 3 | * |
Mike Frysinger | 2fb9d6f | 2008-01-30 16:52:24 +0800 | [diff] [blame] | 4 | * Copyright 2004-2007 Analog Devices Inc. |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 5 | * |
Mike Frysinger | 2fb9d6f | 2008-01-30 16:52:24 +0800 | [diff] [blame] | 6 | * Enter bugs at http://blackfin.uclinux.org/ |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 7 | * |
Mike Frysinger | 2fb9d6f | 2008-01-30 16:52:24 +0800 | [diff] [blame] | 8 | * Licensed under the GPL-2 or later. |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/timer.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/ioport.h> |
| 22 | #include <linux/crc32.h> |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/spinlock.h> |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 25 | #include <linux/mii.h> |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 26 | #include <linux/phy.h> |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 27 | #include <linux/netdevice.h> |
| 28 | #include <linux/etherdevice.h> |
Bryan Wu | 679dce3 | 2008-04-25 11:53:11 +0800 | [diff] [blame] | 29 | #include <linux/ethtool.h> |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 30 | #include <linux/skbuff.h> |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 32 | |
| 33 | #include <asm/dma.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | |
| 36 | #include <asm/blackfin.h> |
| 37 | #include <asm/cacheflush.h> |
| 38 | #include <asm/portmux.h> |
| 39 | |
| 40 | #include "bfin_mac.h" |
| 41 | |
| 42 | #define DRV_NAME "bfin_mac" |
| 43 | #define DRV_VERSION "1.1" |
| 44 | #define DRV_AUTHOR "Bryan Wu, Luke Yang" |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 45 | #define DRV_DESC "Blackfin on-chip Ethernet MAC driver" |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 46 | |
| 47 | MODULE_AUTHOR(DRV_AUTHOR); |
| 48 | MODULE_LICENSE("GPL"); |
| 49 | MODULE_DESCRIPTION(DRV_DESC); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 50 | MODULE_ALIAS("platform:bfin_mac"); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 51 | |
| 52 | #if defined(CONFIG_BFIN_MAC_USE_L1) |
| 53 | # define bfin_mac_alloc(dma_handle, size) l1_data_sram_zalloc(size) |
| 54 | # define bfin_mac_free(dma_handle, ptr) l1_data_sram_free(ptr) |
| 55 | #else |
| 56 | # define bfin_mac_alloc(dma_handle, size) \ |
| 57 | dma_alloc_coherent(NULL, size, dma_handle, GFP_KERNEL) |
| 58 | # define bfin_mac_free(dma_handle, ptr) \ |
| 59 | dma_free_coherent(NULL, sizeof(*ptr), ptr, dma_handle) |
| 60 | #endif |
| 61 | |
| 62 | #define PKT_BUF_SZ 1580 |
| 63 | |
| 64 | #define MAX_TIMEOUT_CNT 500 |
| 65 | |
| 66 | /* pointers to maintain transmit list */ |
| 67 | static struct net_dma_desc_tx *tx_list_head; |
| 68 | static struct net_dma_desc_tx *tx_list_tail; |
| 69 | static struct net_dma_desc_rx *rx_list_head; |
| 70 | static struct net_dma_desc_rx *rx_list_tail; |
| 71 | static struct net_dma_desc_rx *current_rx_ptr; |
| 72 | static struct net_dma_desc_tx *current_tx_ptr; |
| 73 | static struct net_dma_desc_tx *tx_desc; |
| 74 | static struct net_dma_desc_rx *rx_desc; |
| 75 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 76 | #if defined(CONFIG_BFIN_MAC_RMII) |
| 77 | static u16 pin_req[] = P_RMII0; |
| 78 | #else |
| 79 | static u16 pin_req[] = P_MII0; |
| 80 | #endif |
| 81 | |
| 82 | static void bfin_mac_disable(void); |
| 83 | static void bfin_mac_enable(void); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 84 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 85 | static void desc_list_free(void) |
| 86 | { |
| 87 | struct net_dma_desc_rx *r; |
| 88 | struct net_dma_desc_tx *t; |
| 89 | int i; |
| 90 | #if !defined(CONFIG_BFIN_MAC_USE_L1) |
| 91 | dma_addr_t dma_handle = 0; |
| 92 | #endif |
| 93 | |
| 94 | if (tx_desc) { |
| 95 | t = tx_list_head; |
| 96 | for (i = 0; i < CONFIG_BFIN_TX_DESC_NUM; i++) { |
| 97 | if (t) { |
| 98 | if (t->skb) { |
| 99 | dev_kfree_skb(t->skb); |
| 100 | t->skb = NULL; |
| 101 | } |
| 102 | t = t->next; |
| 103 | } |
| 104 | } |
| 105 | bfin_mac_free(dma_handle, tx_desc); |
| 106 | } |
| 107 | |
| 108 | if (rx_desc) { |
| 109 | r = rx_list_head; |
| 110 | for (i = 0; i < CONFIG_BFIN_RX_DESC_NUM; i++) { |
| 111 | if (r) { |
| 112 | if (r->skb) { |
| 113 | dev_kfree_skb(r->skb); |
| 114 | r->skb = NULL; |
| 115 | } |
| 116 | r = r->next; |
| 117 | } |
| 118 | } |
| 119 | bfin_mac_free(dma_handle, rx_desc); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | static int desc_list_init(void) |
| 124 | { |
| 125 | int i; |
| 126 | struct sk_buff *new_skb; |
| 127 | #if !defined(CONFIG_BFIN_MAC_USE_L1) |
| 128 | /* |
| 129 | * This dma_handle is useless in Blackfin dma_alloc_coherent(). |
| 130 | * The real dma handler is the return value of dma_alloc_coherent(). |
| 131 | */ |
| 132 | dma_addr_t dma_handle; |
| 133 | #endif |
| 134 | |
| 135 | tx_desc = bfin_mac_alloc(&dma_handle, |
| 136 | sizeof(struct net_dma_desc_tx) * |
| 137 | CONFIG_BFIN_TX_DESC_NUM); |
| 138 | if (tx_desc == NULL) |
| 139 | goto init_error; |
| 140 | |
| 141 | rx_desc = bfin_mac_alloc(&dma_handle, |
| 142 | sizeof(struct net_dma_desc_rx) * |
| 143 | CONFIG_BFIN_RX_DESC_NUM); |
| 144 | if (rx_desc == NULL) |
| 145 | goto init_error; |
| 146 | |
| 147 | /* init tx_list */ |
| 148 | tx_list_head = tx_list_tail = tx_desc; |
| 149 | |
| 150 | for (i = 0; i < CONFIG_BFIN_TX_DESC_NUM; i++) { |
| 151 | struct net_dma_desc_tx *t = tx_desc + i; |
| 152 | struct dma_descriptor *a = &(t->desc_a); |
| 153 | struct dma_descriptor *b = &(t->desc_b); |
| 154 | |
| 155 | /* |
| 156 | * disable DMA |
| 157 | * read from memory WNR = 0 |
| 158 | * wordsize is 32 bits |
| 159 | * 6 half words is desc size |
| 160 | * large desc flow |
| 161 | */ |
| 162 | a->config = WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE; |
| 163 | a->start_addr = (unsigned long)t->packet; |
| 164 | a->x_count = 0; |
| 165 | a->next_dma_desc = b; |
| 166 | |
| 167 | /* |
| 168 | * enabled DMA |
| 169 | * write to memory WNR = 1 |
| 170 | * wordsize is 32 bits |
| 171 | * disable interrupt |
| 172 | * 6 half words is desc size |
| 173 | * large desc flow |
| 174 | */ |
| 175 | b->config = DMAEN | WNR | WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE; |
| 176 | b->start_addr = (unsigned long)(&(t->status)); |
| 177 | b->x_count = 0; |
| 178 | |
| 179 | t->skb = NULL; |
| 180 | tx_list_tail->desc_b.next_dma_desc = a; |
| 181 | tx_list_tail->next = t; |
| 182 | tx_list_tail = t; |
| 183 | } |
| 184 | tx_list_tail->next = tx_list_head; /* tx_list is a circle */ |
| 185 | tx_list_tail->desc_b.next_dma_desc = &(tx_list_head->desc_a); |
| 186 | current_tx_ptr = tx_list_head; |
| 187 | |
| 188 | /* init rx_list */ |
| 189 | rx_list_head = rx_list_tail = rx_desc; |
| 190 | |
| 191 | for (i = 0; i < CONFIG_BFIN_RX_DESC_NUM; i++) { |
| 192 | struct net_dma_desc_rx *r = rx_desc + i; |
| 193 | struct dma_descriptor *a = &(r->desc_a); |
| 194 | struct dma_descriptor *b = &(r->desc_b); |
| 195 | |
| 196 | /* allocate a new skb for next time receive */ |
| 197 | new_skb = dev_alloc_skb(PKT_BUF_SZ + 2); |
| 198 | if (!new_skb) { |
| 199 | printk(KERN_NOTICE DRV_NAME |
| 200 | ": init: low on mem - packet dropped\n"); |
| 201 | goto init_error; |
| 202 | } |
| 203 | skb_reserve(new_skb, 2); |
| 204 | r->skb = new_skb; |
| 205 | |
| 206 | /* |
| 207 | * enabled DMA |
| 208 | * write to memory WNR = 1 |
| 209 | * wordsize is 32 bits |
| 210 | * disable interrupt |
| 211 | * 6 half words is desc size |
| 212 | * large desc flow |
| 213 | */ |
| 214 | a->config = DMAEN | WNR | WDSIZE_32 | NDSIZE_6 | DMAFLOW_LARGE; |
| 215 | /* since RXDWA is enabled */ |
| 216 | a->start_addr = (unsigned long)new_skb->data - 2; |
| 217 | a->x_count = 0; |
| 218 | a->next_dma_desc = b; |
| 219 | |
| 220 | /* |
| 221 | * enabled DMA |
| 222 | * write to memory WNR = 1 |
| 223 | * wordsize is 32 bits |
| 224 | * enable interrupt |
| 225 | * 6 half words is desc size |
| 226 | * large desc flow |
| 227 | */ |
| 228 | b->config = DMAEN | WNR | WDSIZE_32 | DI_EN | |
| 229 | NDSIZE_6 | DMAFLOW_LARGE; |
| 230 | b->start_addr = (unsigned long)(&(r->status)); |
| 231 | b->x_count = 0; |
| 232 | |
| 233 | rx_list_tail->desc_b.next_dma_desc = a; |
| 234 | rx_list_tail->next = r; |
| 235 | rx_list_tail = r; |
| 236 | } |
| 237 | rx_list_tail->next = rx_list_head; /* rx_list is a circle */ |
| 238 | rx_list_tail->desc_b.next_dma_desc = &(rx_list_head->desc_a); |
| 239 | current_rx_ptr = rx_list_head; |
| 240 | |
| 241 | return 0; |
| 242 | |
| 243 | init_error: |
| 244 | desc_list_free(); |
| 245 | printk(KERN_ERR DRV_NAME ": kmalloc failed\n"); |
| 246 | return -ENOMEM; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | /*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/ |
| 251 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 252 | /* |
| 253 | * MII operations |
| 254 | */ |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 255 | /* Wait until the previous MDC/MDIO transaction has completed */ |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 256 | static void mdio_poll(void) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 257 | { |
| 258 | int timeout_cnt = MAX_TIMEOUT_CNT; |
| 259 | |
| 260 | /* poll the STABUSY bit */ |
| 261 | while ((bfin_read_EMAC_STAADD()) & STABUSY) { |
Bryan Wu | 6db9e46 | 2008-01-30 16:52:21 +0800 | [diff] [blame] | 262 | udelay(1); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 263 | if (timeout_cnt-- < 0) { |
| 264 | printk(KERN_ERR DRV_NAME |
| 265 | ": wait MDC/MDIO transaction to complete timeout\n"); |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /* Read an off-chip register in a PHY through the MDC/MDIO port */ |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 272 | static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 273 | { |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 274 | mdio_poll(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 275 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 276 | /* read mode */ |
| 277 | bfin_write_EMAC_STAADD(SET_PHYAD((u16) phy_addr) | |
| 278 | SET_REGAD((u16) regnum) | |
| 279 | STABUSY); |
| 280 | |
| 281 | mdio_poll(); |
| 282 | |
| 283 | return (int) bfin_read_EMAC_STADAT(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* Write an off-chip register in a PHY through the MDC/MDIO port */ |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 287 | static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, |
| 288 | u16 value) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 289 | { |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 290 | mdio_poll(); |
| 291 | |
| 292 | bfin_write_EMAC_STADAT((u32) value); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 293 | |
| 294 | /* write mode */ |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 295 | bfin_write_EMAC_STAADD(SET_PHYAD((u16) phy_addr) | |
| 296 | SET_REGAD((u16) regnum) | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 297 | STAOP | |
| 298 | STABUSY); |
| 299 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 300 | mdio_poll(); |
| 301 | |
| 302 | return 0; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 303 | } |
| 304 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 305 | static int mdiobus_reset(struct mii_bus *bus) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 306 | { |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 307 | return 0; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 308 | } |
| 309 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 310 | static void bfin_mac_adjust_link(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 311 | { |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 312 | struct bfin_mac_local *lp = netdev_priv(dev); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 313 | struct phy_device *phydev = lp->phydev; |
| 314 | unsigned long flags; |
| 315 | int new_state = 0; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 316 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 317 | spin_lock_irqsave(&lp->lock, flags); |
| 318 | if (phydev->link) { |
| 319 | /* Now we make sure that we can be in full duplex mode. |
| 320 | * If not, we operate in half-duplex mode. */ |
| 321 | if (phydev->duplex != lp->old_duplex) { |
| 322 | u32 opmode = bfin_read_EMAC_OPMODE(); |
| 323 | new_state = 1; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 324 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 325 | if (phydev->duplex) |
| 326 | opmode |= FDMODE; |
| 327 | else |
| 328 | opmode &= ~(FDMODE); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 329 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 330 | bfin_write_EMAC_OPMODE(opmode); |
| 331 | lp->old_duplex = phydev->duplex; |
| 332 | } |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 333 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 334 | if (phydev->speed != lp->old_speed) { |
| 335 | #if defined(CONFIG_BFIN_MAC_RMII) |
| 336 | u32 opmode = bfin_read_EMAC_OPMODE(); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 337 | switch (phydev->speed) { |
| 338 | case 10: |
| 339 | opmode |= RMII_10; |
| 340 | break; |
| 341 | case 100: |
| 342 | opmode &= ~(RMII_10); |
| 343 | break; |
| 344 | default: |
| 345 | printk(KERN_WARNING |
| 346 | "%s: Ack! Speed (%d) is not 10/100!\n", |
| 347 | DRV_NAME, phydev->speed); |
| 348 | break; |
| 349 | } |
| 350 | bfin_write_EMAC_OPMODE(opmode); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 351 | #endif |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 352 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 353 | new_state = 1; |
| 354 | lp->old_speed = phydev->speed; |
| 355 | } |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 356 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 357 | if (!lp->old_link) { |
| 358 | new_state = 1; |
| 359 | lp->old_link = 1; |
| 360 | netif_schedule(dev); |
| 361 | } |
| 362 | } else if (lp->old_link) { |
| 363 | new_state = 1; |
| 364 | lp->old_link = 0; |
| 365 | lp->old_speed = 0; |
| 366 | lp->old_duplex = -1; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 367 | } |
| 368 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 369 | if (new_state) { |
| 370 | u32 opmode = bfin_read_EMAC_OPMODE(); |
| 371 | phy_print_status(phydev); |
| 372 | pr_debug("EMAC_OPMODE = 0x%08x\n", opmode); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 373 | } |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 374 | |
| 375 | spin_unlock_irqrestore(&lp->lock, flags); |
| 376 | } |
| 377 | |
Bryan Wu | 7cc8f38 | 2008-01-30 16:52:22 +0800 | [diff] [blame] | 378 | /* MDC = 2.5 MHz */ |
| 379 | #define MDC_CLK 2500000 |
| 380 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 381 | static int mii_probe(struct net_device *dev) |
| 382 | { |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 383 | struct bfin_mac_local *lp = netdev_priv(dev); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 384 | struct phy_device *phydev = NULL; |
| 385 | unsigned short sysctl; |
| 386 | int i; |
Bryan Wu | 7cc8f38 | 2008-01-30 16:52:22 +0800 | [diff] [blame] | 387 | u32 sclk, mdc_div; |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 388 | |
| 389 | /* Enable PHY output early */ |
| 390 | if (!(bfin_read_VR_CTL() & PHYCLKOE)) |
| 391 | bfin_write_VR_CTL(bfin_read_VR_CTL() | PHYCLKOE); |
| 392 | |
Bryan Wu | 7cc8f38 | 2008-01-30 16:52:22 +0800 | [diff] [blame] | 393 | sclk = get_sclk(); |
| 394 | mdc_div = ((sclk / MDC_CLK) / 2) - 1; |
| 395 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 396 | sysctl = bfin_read_EMAC_SYSCTL(); |
Bryan Wu | 9dc7f30 | 2008-01-30 16:52:28 +0800 | [diff] [blame] | 397 | sysctl = (sysctl & ~MDCDIV) | SET_MDCDIV(mdc_div); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 398 | bfin_write_EMAC_SYSCTL(sysctl); |
| 399 | |
| 400 | /* search for connect PHY device */ |
| 401 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
| 402 | struct phy_device *const tmp_phydev = lp->mii_bus.phy_map[i]; |
| 403 | |
| 404 | if (!tmp_phydev) |
| 405 | continue; /* no PHY here... */ |
| 406 | |
| 407 | phydev = tmp_phydev; |
| 408 | break; /* found it */ |
| 409 | } |
| 410 | |
| 411 | /* now we are supposed to have a proper phydev, to attach to... */ |
| 412 | if (!phydev) { |
| 413 | printk(KERN_INFO "%s: Don't found any phy device at all\n", |
| 414 | dev->name); |
| 415 | return -ENODEV; |
| 416 | } |
| 417 | |
| 418 | #if defined(CONFIG_BFIN_MAC_RMII) |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 419 | phydev = phy_connect(dev, phydev->dev.bus_id, &bfin_mac_adjust_link, 0, |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 420 | PHY_INTERFACE_MODE_RMII); |
| 421 | #else |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 422 | phydev = phy_connect(dev, phydev->dev.bus_id, &bfin_mac_adjust_link, 0, |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 423 | PHY_INTERFACE_MODE_MII); |
| 424 | #endif |
| 425 | |
| 426 | if (IS_ERR(phydev)) { |
| 427 | printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); |
| 428 | return PTR_ERR(phydev); |
| 429 | } |
| 430 | |
| 431 | /* mask with MAC supported features */ |
| 432 | phydev->supported &= (SUPPORTED_10baseT_Half |
| 433 | | SUPPORTED_10baseT_Full |
| 434 | | SUPPORTED_100baseT_Half |
| 435 | | SUPPORTED_100baseT_Full |
| 436 | | SUPPORTED_Autoneg |
| 437 | | SUPPORTED_Pause | SUPPORTED_Asym_Pause |
| 438 | | SUPPORTED_MII |
| 439 | | SUPPORTED_TP); |
| 440 | |
| 441 | phydev->advertising = phydev->supported; |
| 442 | |
| 443 | lp->old_link = 0; |
| 444 | lp->old_speed = 0; |
| 445 | lp->old_duplex = -1; |
| 446 | lp->phydev = phydev; |
| 447 | |
| 448 | printk(KERN_INFO "%s: attached PHY driver [%s] " |
Bryan Wu | 7cc8f38 | 2008-01-30 16:52:22 +0800 | [diff] [blame] | 449 | "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)" |
| 450 | "@sclk=%dMHz)\n", |
| 451 | DRV_NAME, phydev->drv->name, phydev->dev.bus_id, phydev->irq, |
| 452 | MDC_CLK, mdc_div, sclk/1000000); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 453 | |
| 454 | return 0; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 455 | } |
| 456 | |
Bryan Wu | 679dce3 | 2008-04-25 11:53:11 +0800 | [diff] [blame] | 457 | /* |
| 458 | * Ethtool support |
| 459 | */ |
| 460 | |
| 461 | static int |
| 462 | bfin_mac_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 463 | { |
| 464 | struct bfin_mac_local *lp = netdev_priv(dev); |
| 465 | |
| 466 | if (lp->phydev) |
| 467 | return phy_ethtool_gset(lp->phydev, cmd); |
| 468 | |
| 469 | return -EINVAL; |
| 470 | } |
| 471 | |
| 472 | static int |
| 473 | bfin_mac_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 474 | { |
| 475 | struct bfin_mac_local *lp = netdev_priv(dev); |
| 476 | |
| 477 | if (!capable(CAP_NET_ADMIN)) |
| 478 | return -EPERM; |
| 479 | |
| 480 | if (lp->phydev) |
| 481 | return phy_ethtool_sset(lp->phydev, cmd); |
| 482 | |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | |
| 486 | static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev, |
| 487 | struct ethtool_drvinfo *info) |
| 488 | { |
| 489 | strcpy(info->driver, DRV_NAME); |
| 490 | strcpy(info->version, DRV_VERSION); |
| 491 | strcpy(info->fw_version, "N/A"); |
| 492 | strcpy(info->bus_info, dev->dev.bus_id); |
| 493 | } |
| 494 | |
| 495 | static struct ethtool_ops bfin_mac_ethtool_ops = { |
| 496 | .get_settings = bfin_mac_ethtool_getsettings, |
| 497 | .set_settings = bfin_mac_ethtool_setsettings, |
| 498 | .get_link = ethtool_op_get_link, |
| 499 | .get_drvinfo = bfin_mac_ethtool_getdrvinfo, |
| 500 | }; |
| 501 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 502 | /**************************************************************************/ |
| 503 | void setup_system_regs(struct net_device *dev) |
| 504 | { |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 505 | unsigned short sysctl; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 506 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 507 | /* |
| 508 | * Odd word alignment for Receive Frame DMA word |
| 509 | * Configure checksum support and rcve frame word alignment |
| 510 | */ |
| 511 | sysctl = bfin_read_EMAC_SYSCTL(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 512 | #if defined(BFIN_MAC_CSUM_OFFLOAD) |
| 513 | sysctl |= RXDWA | RXCKS; |
| 514 | #else |
| 515 | sysctl |= RXDWA; |
| 516 | #endif |
| 517 | bfin_write_EMAC_SYSCTL(sysctl); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 518 | |
| 519 | bfin_write_EMAC_MMC_CTL(RSTC | CROLL); |
| 520 | |
| 521 | /* Initialize the TX DMA channel registers */ |
| 522 | bfin_write_DMA2_X_COUNT(0); |
| 523 | bfin_write_DMA2_X_MODIFY(4); |
| 524 | bfin_write_DMA2_Y_COUNT(0); |
| 525 | bfin_write_DMA2_Y_MODIFY(0); |
| 526 | |
| 527 | /* Initialize the RX DMA channel registers */ |
| 528 | bfin_write_DMA1_X_COUNT(0); |
| 529 | bfin_write_DMA1_X_MODIFY(4); |
| 530 | bfin_write_DMA1_Y_COUNT(0); |
| 531 | bfin_write_DMA1_Y_MODIFY(0); |
| 532 | } |
| 533 | |
Alex Landau | 73f8318 | 2007-09-19 23:14:18 +0800 | [diff] [blame] | 534 | static void setup_mac_addr(u8 *mac_addr) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 535 | { |
| 536 | u32 addr_low = le32_to_cpu(*(__le32 *) & mac_addr[0]); |
| 537 | u16 addr_hi = le16_to_cpu(*(__le16 *) & mac_addr[4]); |
| 538 | |
| 539 | /* this depends on a little-endian machine */ |
| 540 | bfin_write_EMAC_ADDRLO(addr_low); |
| 541 | bfin_write_EMAC_ADDRHI(addr_hi); |
| 542 | } |
| 543 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 544 | static int bfin_mac_set_mac_address(struct net_device *dev, void *p) |
Alex Landau | 73f8318 | 2007-09-19 23:14:18 +0800 | [diff] [blame] | 545 | { |
| 546 | struct sockaddr *addr = p; |
| 547 | if (netif_running(dev)) |
| 548 | return -EBUSY; |
| 549 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 550 | setup_mac_addr(dev->dev_addr); |
| 551 | return 0; |
| 552 | } |
| 553 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 554 | static void adjust_tx_list(void) |
| 555 | { |
| 556 | int timeout_cnt = MAX_TIMEOUT_CNT; |
| 557 | |
| 558 | if (tx_list_head->status.status_word != 0 |
| 559 | && current_tx_ptr != tx_list_head) { |
| 560 | goto adjust_head; /* released something, just return; */ |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * if nothing released, check wait condition |
| 565 | * current's next can not be the head, |
| 566 | * otherwise the dma will not stop as we want |
| 567 | */ |
| 568 | if (current_tx_ptr->next->next == tx_list_head) { |
| 569 | while (tx_list_head->status.status_word == 0) { |
Bryan Wu | 6db9e46 | 2008-01-30 16:52:21 +0800 | [diff] [blame] | 570 | mdelay(1); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 571 | if (tx_list_head->status.status_word != 0 |
| 572 | || !(bfin_read_DMA2_IRQ_STATUS() & 0x08)) { |
| 573 | goto adjust_head; |
| 574 | } |
| 575 | if (timeout_cnt-- < 0) { |
| 576 | printk(KERN_ERR DRV_NAME |
| 577 | ": wait for adjust tx list head timeout\n"); |
| 578 | break; |
| 579 | } |
| 580 | } |
| 581 | if (tx_list_head->status.status_word != 0) { |
| 582 | goto adjust_head; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | return; |
| 587 | |
| 588 | adjust_head: |
| 589 | do { |
| 590 | tx_list_head->desc_a.config &= ~DMAEN; |
| 591 | tx_list_head->status.status_word = 0; |
| 592 | if (tx_list_head->skb) { |
| 593 | dev_kfree_skb(tx_list_head->skb); |
| 594 | tx_list_head->skb = NULL; |
| 595 | } else { |
| 596 | printk(KERN_ERR DRV_NAME |
| 597 | ": no sk_buff in a transmitted frame!\n"); |
| 598 | } |
| 599 | tx_list_head = tx_list_head->next; |
| 600 | } while (tx_list_head->status.status_word != 0 |
| 601 | && current_tx_ptr != tx_list_head); |
| 602 | return; |
| 603 | |
| 604 | } |
| 605 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 606 | static int bfin_mac_hard_start_xmit(struct sk_buff *skb, |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 607 | struct net_device *dev) |
| 608 | { |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 609 | unsigned int data; |
| 610 | |
| 611 | current_tx_ptr->skb = skb; |
| 612 | |
| 613 | /* |
| 614 | * Is skb->data always 16-bit aligned? |
| 615 | * Do we need to memcpy((char *)(tail->packet + 2), skb->data, len)? |
| 616 | */ |
| 617 | if ((((unsigned int)(skb->data)) & 0x02) == 2) { |
| 618 | /* move skb->data to current_tx_ptr payload */ |
| 619 | data = (unsigned int)(skb->data) - 2; |
| 620 | *((unsigned short *)data) = (unsigned short)(skb->len); |
| 621 | current_tx_ptr->desc_a.start_addr = (unsigned long)data; |
| 622 | /* this is important! */ |
| 623 | blackfin_dcache_flush_range(data, (data + (skb->len)) + 2); |
| 624 | |
| 625 | } else { |
| 626 | *((unsigned short *)(current_tx_ptr->packet)) = |
| 627 | (unsigned short)(skb->len); |
| 628 | memcpy((char *)(current_tx_ptr->packet + 2), skb->data, |
| 629 | (skb->len)); |
| 630 | current_tx_ptr->desc_a.start_addr = |
| 631 | (unsigned long)current_tx_ptr->packet; |
| 632 | if (current_tx_ptr->status.status_word != 0) |
| 633 | current_tx_ptr->status.status_word = 0; |
| 634 | blackfin_dcache_flush_range((unsigned int)current_tx_ptr-> |
| 635 | packet, |
| 636 | (unsigned int)(current_tx_ptr-> |
| 637 | packet + skb->len) + |
| 638 | 2); |
| 639 | } |
| 640 | |
| 641 | /* enable this packet's dma */ |
| 642 | current_tx_ptr->desc_a.config |= DMAEN; |
| 643 | |
| 644 | /* tx dma is running, just return */ |
| 645 | if (bfin_read_DMA2_IRQ_STATUS() & 0x08) |
| 646 | goto out; |
| 647 | |
| 648 | /* tx dma is not running */ |
| 649 | bfin_write_DMA2_NEXT_DESC_PTR(&(current_tx_ptr->desc_a)); |
| 650 | /* dma enabled, read from memory, size is 6 */ |
| 651 | bfin_write_DMA2_CONFIG(current_tx_ptr->desc_a.config); |
| 652 | /* Turn on the EMAC tx */ |
| 653 | bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE); |
| 654 | |
| 655 | out: |
| 656 | adjust_tx_list(); |
| 657 | current_tx_ptr = current_tx_ptr->next; |
| 658 | dev->trans_start = jiffies; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 659 | dev->stats.tx_packets++; |
| 660 | dev->stats.tx_bytes += (skb->len); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 661 | return 0; |
| 662 | } |
| 663 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 664 | static void bfin_mac_rx(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 665 | { |
| 666 | struct sk_buff *skb, *new_skb; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 667 | unsigned short len; |
| 668 | |
| 669 | /* allocate a new skb for next time receive */ |
| 670 | skb = current_rx_ptr->skb; |
| 671 | new_skb = dev_alloc_skb(PKT_BUF_SZ + 2); |
| 672 | if (!new_skb) { |
| 673 | printk(KERN_NOTICE DRV_NAME |
| 674 | ": rx: low on mem - packet dropped\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 675 | dev->stats.rx_dropped++; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 676 | goto out; |
| 677 | } |
| 678 | /* reserve 2 bytes for RXDWA padding */ |
| 679 | skb_reserve(new_skb, 2); |
| 680 | current_rx_ptr->skb = new_skb; |
| 681 | current_rx_ptr->desc_a.start_addr = (unsigned long)new_skb->data - 2; |
| 682 | |
Alexey Demin | 6e01d1a | 2008-01-30 16:52:27 +0800 | [diff] [blame] | 683 | /* Invidate the data cache of skb->data range when it is write back |
| 684 | * cache. It will prevent overwritting the new data from DMA |
| 685 | */ |
| 686 | blackfin_dcache_invalidate_range((unsigned long)new_skb->head, |
| 687 | (unsigned long)new_skb->end); |
| 688 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 689 | len = (unsigned short)((current_rx_ptr->status.status_word) & RX_FRLEN); |
| 690 | skb_put(skb, len); |
| 691 | blackfin_dcache_invalidate_range((unsigned long)skb->head, |
| 692 | (unsigned long)skb->tail); |
| 693 | |
| 694 | dev->last_rx = jiffies; |
| 695 | skb->dev = dev; |
| 696 | skb->protocol = eth_type_trans(skb, dev); |
| 697 | #if defined(BFIN_MAC_CSUM_OFFLOAD) |
| 698 | skb->csum = current_rx_ptr->status.ip_payload_csum; |
Vitja Makarov | 00ff49a | 2007-11-23 17:55:51 +0800 | [diff] [blame] | 699 | skb->ip_summed = CHECKSUM_COMPLETE; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 700 | #endif |
| 701 | |
| 702 | netif_rx(skb); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 703 | dev->stats.rx_packets++; |
| 704 | dev->stats.rx_bytes += len; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 705 | current_rx_ptr->status.status_word = 0x00000000; |
| 706 | current_rx_ptr = current_rx_ptr->next; |
| 707 | |
| 708 | out: |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | /* interrupt routine to handle rx and error signal */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 713 | static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 714 | { |
| 715 | struct net_device *dev = dev_id; |
| 716 | int number = 0; |
| 717 | |
| 718 | get_one_packet: |
| 719 | if (current_rx_ptr->status.status_word == 0) { |
| 720 | /* no more new packet received */ |
| 721 | if (number == 0) { |
| 722 | if (current_rx_ptr->next->status.status_word != 0) { |
| 723 | current_rx_ptr = current_rx_ptr->next; |
| 724 | goto real_rx; |
| 725 | } |
| 726 | } |
| 727 | bfin_write_DMA1_IRQ_STATUS(bfin_read_DMA1_IRQ_STATUS() | |
| 728 | DMA_DONE | DMA_ERR); |
| 729 | return IRQ_HANDLED; |
| 730 | } |
| 731 | |
| 732 | real_rx: |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 733 | bfin_mac_rx(dev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 734 | number++; |
| 735 | goto get_one_packet; |
| 736 | } |
| 737 | |
| 738 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 739 | static void bfin_mac_poll(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 740 | { |
| 741 | disable_irq(IRQ_MAC_RX); |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 742 | bfin_mac_interrupt(IRQ_MAC_RX, dev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 743 | enable_irq(IRQ_MAC_RX); |
| 744 | } |
| 745 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 746 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 747 | static void bfin_mac_disable(void) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 748 | { |
| 749 | unsigned int opmode; |
| 750 | |
| 751 | opmode = bfin_read_EMAC_OPMODE(); |
| 752 | opmode &= (~RE); |
| 753 | opmode &= (~TE); |
| 754 | /* Turn off the EMAC */ |
| 755 | bfin_write_EMAC_OPMODE(opmode); |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | * Enable Interrupts, Receive, and Transmit |
| 760 | */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 761 | static void bfin_mac_enable(void) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 762 | { |
| 763 | u32 opmode; |
| 764 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 765 | pr_debug("%s: %s\n", DRV_NAME, __FUNCTION__); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 766 | |
| 767 | /* Set RX DMA */ |
| 768 | bfin_write_DMA1_NEXT_DESC_PTR(&(rx_list_head->desc_a)); |
| 769 | bfin_write_DMA1_CONFIG(rx_list_head->desc_a.config); |
| 770 | |
| 771 | /* Wait MII done */ |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 772 | mdio_poll(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 773 | |
| 774 | /* We enable only RX here */ |
| 775 | /* ASTP : Enable Automatic Pad Stripping |
| 776 | PR : Promiscuous Mode for test |
| 777 | PSF : Receive frames with total length less than 64 bytes. |
| 778 | FDMODE : Full Duplex Mode |
| 779 | LB : Internal Loopback for test |
| 780 | RE : Receiver Enable */ |
| 781 | opmode = bfin_read_EMAC_OPMODE(); |
| 782 | if (opmode & FDMODE) |
| 783 | opmode |= PSF; |
| 784 | else |
| 785 | opmode |= DRO | DC | PSF; |
| 786 | opmode |= RE; |
| 787 | |
| 788 | #if defined(CONFIG_BFIN_MAC_RMII) |
| 789 | opmode |= RMII; /* For Now only 100MBit are supported */ |
Michael Hennerich | 6893ff1 | 2008-01-30 16:52:25 +0800 | [diff] [blame] | 790 | #if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) && CONFIG_BF_REV_0_2 |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 791 | opmode |= TE; |
| 792 | #endif |
| 793 | #endif |
| 794 | /* Turn on the EMAC rx */ |
| 795 | bfin_write_EMAC_OPMODE(opmode); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* Our watchdog timed out. Called by the networking layer */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 799 | static void bfin_mac_timeout(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 800 | { |
| 801 | pr_debug("%s: %s\n", dev->name, __FUNCTION__); |
| 802 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 803 | bfin_mac_disable(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 804 | |
| 805 | /* reset tx queue */ |
| 806 | tx_list_tail = tx_list_head->next; |
| 807 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 808 | bfin_mac_enable(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 809 | |
| 810 | /* We can accept TX packets again */ |
| 811 | dev->trans_start = jiffies; |
| 812 | netif_wake_queue(dev); |
| 813 | } |
| 814 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 815 | static void bfin_mac_multicast_hash(struct net_device *dev) |
Aidan Williams | 775919b | 2008-01-30 16:52:23 +0800 | [diff] [blame] | 816 | { |
| 817 | u32 emac_hashhi, emac_hashlo; |
| 818 | struct dev_mc_list *dmi = dev->mc_list; |
| 819 | char *addrs; |
| 820 | int i; |
| 821 | u32 crc; |
| 822 | |
| 823 | emac_hashhi = emac_hashlo = 0; |
| 824 | |
| 825 | for (i = 0; i < dev->mc_count; i++) { |
| 826 | addrs = dmi->dmi_addr; |
| 827 | dmi = dmi->next; |
| 828 | |
| 829 | /* skip non-multicast addresses */ |
| 830 | if (!(*addrs & 1)) |
| 831 | continue; |
| 832 | |
| 833 | crc = ether_crc(ETH_ALEN, addrs); |
| 834 | crc >>= 26; |
| 835 | |
| 836 | if (crc & 0x20) |
| 837 | emac_hashhi |= 1 << (crc & 0x1f); |
| 838 | else |
| 839 | emac_hashlo |= 1 << (crc & 0x1f); |
| 840 | } |
| 841 | |
| 842 | bfin_write_EMAC_HASHHI(emac_hashhi); |
| 843 | bfin_write_EMAC_HASHLO(emac_hashlo); |
| 844 | |
| 845 | return; |
| 846 | } |
| 847 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 848 | /* |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 849 | * This routine will, depending on the values passed to it, |
| 850 | * either make it accept multicast packets, go into |
| 851 | * promiscuous mode (for TCPDUMP and cousins) or accept |
| 852 | * a select set of multicast packets |
| 853 | */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 854 | static void bfin_mac_set_multicast_list(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 855 | { |
| 856 | u32 sysctl; |
| 857 | |
| 858 | if (dev->flags & IFF_PROMISC) { |
| 859 | printk(KERN_INFO "%s: set to promisc mode\n", dev->name); |
| 860 | sysctl = bfin_read_EMAC_OPMODE(); |
| 861 | sysctl |= RAF; |
| 862 | bfin_write_EMAC_OPMODE(sysctl); |
Aidan Williams | 775919b | 2008-01-30 16:52:23 +0800 | [diff] [blame] | 863 | } else if (dev->flags & IFF_ALLMULTI) { |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 864 | /* accept all multicast */ |
| 865 | sysctl = bfin_read_EMAC_OPMODE(); |
| 866 | sysctl |= PAM; |
| 867 | bfin_write_EMAC_OPMODE(sysctl); |
Aidan Williams | 775919b | 2008-01-30 16:52:23 +0800 | [diff] [blame] | 868 | } else if (dev->mc_count) { |
| 869 | /* set up multicast hash table */ |
| 870 | sysctl = bfin_read_EMAC_OPMODE(); |
| 871 | sysctl |= HM; |
| 872 | bfin_write_EMAC_OPMODE(sysctl); |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 873 | bfin_mac_multicast_hash(dev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 874 | } else { |
| 875 | /* clear promisc or multicast mode */ |
| 876 | sysctl = bfin_read_EMAC_OPMODE(); |
| 877 | sysctl &= ~(RAF | PAM); |
| 878 | bfin_write_EMAC_OPMODE(sysctl); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | /* |
| 883 | * this puts the device in an inactive state |
| 884 | */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 885 | static void bfin_mac_shutdown(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 886 | { |
| 887 | /* Turn off the EMAC */ |
| 888 | bfin_write_EMAC_OPMODE(0x00000000); |
| 889 | /* Turn off the EMAC RX DMA */ |
| 890 | bfin_write_DMA1_CONFIG(0x0000); |
| 891 | bfin_write_DMA2_CONFIG(0x0000); |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * Open and Initialize the interface |
| 896 | * |
| 897 | * Set up everything, reset the card, etc.. |
| 898 | */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 899 | static int bfin_mac_open(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 900 | { |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 901 | struct bfin_mac_local *lp = netdev_priv(dev); |
Michael Hennerich | 4af4b84 | 2007-07-25 14:09:54 +0800 | [diff] [blame] | 902 | int retval; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 903 | pr_debug("%s: %s\n", dev->name, __FUNCTION__); |
| 904 | |
| 905 | /* |
| 906 | * Check that the address is valid. If its not, refuse |
| 907 | * to bring the device up. The user must specify an |
| 908 | * address using ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx |
| 909 | */ |
| 910 | if (!is_valid_ether_addr(dev->dev_addr)) { |
| 911 | printk(KERN_WARNING DRV_NAME ": no valid ethernet hw addr\n"); |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
| 915 | /* initial rx and tx list */ |
Michael Hennerich | 4af4b84 | 2007-07-25 14:09:54 +0800 | [diff] [blame] | 916 | retval = desc_list_init(); |
| 917 | |
| 918 | if (retval) |
| 919 | return retval; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 920 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 921 | phy_start(lp->phydev); |
Vitja Makarov | 136492b | 2008-01-30 16:52:26 +0800 | [diff] [blame] | 922 | phy_write(lp->phydev, MII_BMCR, BMCR_RESET); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 923 | setup_system_regs(dev); |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 924 | bfin_mac_disable(); |
| 925 | bfin_mac_enable(); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 926 | pr_debug("hardware init finished\n"); |
| 927 | netif_start_queue(dev); |
| 928 | netif_carrier_on(dev); |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | * |
| 935 | * this makes the board clean up everything that it can |
| 936 | * and not talk to the outside world. Caused by |
| 937 | * an 'ifconfig ethX down' |
| 938 | */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 939 | static int bfin_mac_close(struct net_device *dev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 940 | { |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 941 | struct bfin_mac_local *lp = netdev_priv(dev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 942 | pr_debug("%s: %s\n", dev->name, __FUNCTION__); |
| 943 | |
| 944 | netif_stop_queue(dev); |
| 945 | netif_carrier_off(dev); |
| 946 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 947 | phy_stop(lp->phydev); |
Vitja Makarov | 136492b | 2008-01-30 16:52:26 +0800 | [diff] [blame] | 948 | phy_write(lp->phydev, MII_BMCR, BMCR_PDOWN); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 949 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 950 | /* clear everything */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 951 | bfin_mac_shutdown(dev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 952 | |
| 953 | /* free the rx/tx buffers */ |
| 954 | desc_list_free(); |
| 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 959 | static int __init bfin_mac_probe(struct platform_device *pdev) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 960 | { |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 961 | struct net_device *ndev; |
| 962 | struct bfin_mac_local *lp; |
| 963 | int rc, i; |
| 964 | |
| 965 | ndev = alloc_etherdev(sizeof(struct bfin_mac_local)); |
| 966 | if (!ndev) { |
| 967 | dev_err(&pdev->dev, "Cannot allocate net device!\n"); |
| 968 | return -ENOMEM; |
| 969 | } |
| 970 | |
| 971 | SET_NETDEV_DEV(ndev, &pdev->dev); |
| 972 | platform_set_drvdata(pdev, ndev); |
| 973 | lp = netdev_priv(ndev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 974 | |
| 975 | /* Grab the MAC address in the MAC */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 976 | *(__le32 *) (&(ndev->dev_addr[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO()); |
| 977 | *(__le16 *) (&(ndev->dev_addr[4])) = cpu_to_le16((u16) bfin_read_EMAC_ADDRHI()); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 978 | |
| 979 | /* probe mac */ |
| 980 | /*todo: how to proble? which is revision_register */ |
| 981 | bfin_write_EMAC_ADDRLO(0x12345678); |
| 982 | if (bfin_read_EMAC_ADDRLO() != 0x12345678) { |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 983 | dev_err(&pdev->dev, "Cannot detect Blackfin on-chip ethernet MAC controller!\n"); |
| 984 | rc = -ENODEV; |
| 985 | goto out_err_probe_mac; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /* set the GPIO pins to Ethernet mode */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 989 | rc = peripheral_request_list(pin_req, DRV_NAME); |
| 990 | if (rc) { |
| 991 | dev_err(&pdev->dev, "Requesting peripherals failed!\n"); |
| 992 | rc = -EFAULT; |
| 993 | goto out_err_setup_pin_mux; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 994 | } |
| 995 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 996 | /* |
| 997 | * Is it valid? (Did bootloader initialize it?) |
| 998 | * Grab the MAC from the board somehow |
| 999 | * this is done in the arch/blackfin/mach-bfxxx/boards/eth_mac.c |
| 1000 | */ |
| 1001 | if (!is_valid_ether_addr(ndev->dev_addr)) |
| 1002 | bfin_get_ether_addr(ndev->dev_addr); |
| 1003 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1004 | /* If still not valid, get a random one */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1005 | if (!is_valid_ether_addr(ndev->dev_addr)) |
| 1006 | random_ether_addr(ndev->dev_addr); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1007 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1008 | setup_mac_addr(ndev->dev_addr); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1009 | |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 1010 | /* MDIO bus initial */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1011 | lp->mii_bus.priv = ndev; |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 1012 | lp->mii_bus.read = mdiobus_read; |
| 1013 | lp->mii_bus.write = mdiobus_write; |
| 1014 | lp->mii_bus.reset = mdiobus_reset; |
| 1015 | lp->mii_bus.name = "bfin_mac_mdio"; |
Andy Fleming | 9d9326d | 2008-04-09 19:38:13 -0500 | [diff] [blame] | 1016 | snprintf(lp->mii_bus.id, MII_BUS_ID_SIZE, "0"); |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 1017 | lp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); |
| 1018 | for (i = 0; i < PHY_MAX_ADDR; ++i) |
| 1019 | lp->mii_bus.irq[i] = PHY_POLL; |
| 1020 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1021 | rc = mdiobus_register(&lp->mii_bus); |
| 1022 | if (rc) { |
| 1023 | dev_err(&pdev->dev, "Cannot register MDIO bus!\n"); |
| 1024 | goto out_err_mdiobus_register; |
| 1025 | } |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 1026 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1027 | rc = mii_probe(ndev); |
| 1028 | if (rc) { |
| 1029 | dev_err(&pdev->dev, "MII Probe failed!\n"); |
| 1030 | goto out_err_mii_probe; |
| 1031 | } |
Bryan Wu | 4ae5a3a | 2007-09-19 23:37:36 +0800 | [diff] [blame] | 1032 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1033 | /* Fill in the fields of the device structure with ethernet values. */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1034 | ether_setup(ndev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1035 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1036 | ndev->open = bfin_mac_open; |
| 1037 | ndev->stop = bfin_mac_close; |
| 1038 | ndev->hard_start_xmit = bfin_mac_hard_start_xmit; |
| 1039 | ndev->set_mac_address = bfin_mac_set_mac_address; |
| 1040 | ndev->tx_timeout = bfin_mac_timeout; |
| 1041 | ndev->set_multicast_list = bfin_mac_set_multicast_list; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1042 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1043 | ndev->poll_controller = bfin_mac_poll; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1044 | #endif |
Bryan Wu | 679dce3 | 2008-04-25 11:53:11 +0800 | [diff] [blame] | 1045 | ndev->ethtool_ops = &bfin_mac_ethtool_ops; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1046 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1047 | spin_lock_init(&lp->lock); |
| 1048 | |
| 1049 | /* now, enable interrupts */ |
| 1050 | /* register irq handler */ |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1051 | rc = request_irq(IRQ_MAC_RX, bfin_mac_interrupt, |
| 1052 | IRQF_DISABLED | IRQF_SHARED, "EMAC_RX", ndev); |
| 1053 | if (rc) { |
| 1054 | dev_err(&pdev->dev, "Cannot request Blackfin MAC RX IRQ!\n"); |
| 1055 | rc = -EBUSY; |
| 1056 | goto out_err_request_irq; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1057 | } |
| 1058 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1059 | rc = register_netdev(ndev); |
| 1060 | if (rc) { |
| 1061 | dev_err(&pdev->dev, "Cannot register net device!\n"); |
| 1062 | goto out_err_reg_ndev; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1065 | /* now, print out the card info, in a short format.. */ |
| 1066 | dev_info(&pdev->dev, "%s, Version %s\n", DRV_DESC, DRV_VERSION); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1067 | |
| 1068 | return 0; |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1069 | |
| 1070 | out_err_reg_ndev: |
| 1071 | free_irq(IRQ_MAC_RX, ndev); |
| 1072 | out_err_request_irq: |
| 1073 | out_err_mii_probe: |
| 1074 | mdiobus_unregister(&lp->mii_bus); |
| 1075 | out_err_mdiobus_register: |
| 1076 | peripheral_free_list(pin_req); |
| 1077 | out_err_setup_pin_mux: |
| 1078 | out_err_probe_mac: |
| 1079 | platform_set_drvdata(pdev, NULL); |
| 1080 | free_netdev(ndev); |
| 1081 | |
| 1082 | return rc; |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | static int bfin_mac_remove(struct platform_device *pdev) |
| 1086 | { |
| 1087 | struct net_device *ndev = platform_get_drvdata(pdev); |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1088 | struct bfin_mac_local *lp = netdev_priv(ndev); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1089 | |
| 1090 | platform_set_drvdata(pdev, NULL); |
| 1091 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1092 | mdiobus_unregister(&lp->mii_bus); |
| 1093 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1094 | unregister_netdev(ndev); |
| 1095 | |
| 1096 | free_irq(IRQ_MAC_RX, ndev); |
| 1097 | |
| 1098 | free_netdev(ndev); |
| 1099 | |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1100 | peripheral_free_list(pin_req); |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
Bryan Wu | 496a34c | 2007-09-19 23:37:14 +0800 | [diff] [blame] | 1105 | #ifdef CONFIG_PM |
| 1106 | static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t mesg) |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1107 | { |
Bryan Wu | 496a34c | 2007-09-19 23:37:14 +0800 | [diff] [blame] | 1108 | struct net_device *net_dev = platform_get_drvdata(pdev); |
| 1109 | |
| 1110 | if (netif_running(net_dev)) |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1111 | bfin_mac_close(net_dev); |
Bryan Wu | 496a34c | 2007-09-19 23:37:14 +0800 | [diff] [blame] | 1112 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | static int bfin_mac_resume(struct platform_device *pdev) |
| 1117 | { |
Bryan Wu | 496a34c | 2007-09-19 23:37:14 +0800 | [diff] [blame] | 1118 | struct net_device *net_dev = platform_get_drvdata(pdev); |
| 1119 | |
| 1120 | if (netif_running(net_dev)) |
Bryan Wu | 7ef0a7e | 2008-04-25 11:53:10 +0800 | [diff] [blame] | 1121 | bfin_mac_open(net_dev); |
Bryan Wu | 496a34c | 2007-09-19 23:37:14 +0800 | [diff] [blame] | 1122 | |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1123 | return 0; |
| 1124 | } |
Bryan Wu | 496a34c | 2007-09-19 23:37:14 +0800 | [diff] [blame] | 1125 | #else |
| 1126 | #define bfin_mac_suspend NULL |
| 1127 | #define bfin_mac_resume NULL |
| 1128 | #endif /* CONFIG_PM */ |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1129 | |
| 1130 | static struct platform_driver bfin_mac_driver = { |
| 1131 | .probe = bfin_mac_probe, |
| 1132 | .remove = bfin_mac_remove, |
| 1133 | .resume = bfin_mac_resume, |
| 1134 | .suspend = bfin_mac_suspend, |
| 1135 | .driver = { |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 1136 | .name = DRV_NAME, |
| 1137 | .owner = THIS_MODULE, |
| 1138 | }, |
Bryan Wu | e190d6b | 2007-07-17 14:43:44 +0800 | [diff] [blame] | 1139 | }; |
| 1140 | |
| 1141 | static int __init bfin_mac_init(void) |
| 1142 | { |
| 1143 | return platform_driver_register(&bfin_mac_driver); |
| 1144 | } |
| 1145 | |
| 1146 | module_init(bfin_mac_init); |
| 1147 | |
| 1148 | static void __exit bfin_mac_cleanup(void) |
| 1149 | { |
| 1150 | platform_driver_unregister(&bfin_mac_driver); |
| 1151 | } |
| 1152 | |
| 1153 | module_exit(bfin_mac_cleanup); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 1154 | |