2 * Atheros AR71xx built-in ethernet mac driver
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * Based on Atheros' AG7100 driver
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
16 #define AG71XX_DEFAULT_MSG_ENABLE \
26 static int ag71xx_debug
= -1;
28 module_param(ag71xx_debug
, int, 0);
29 MODULE_PARM_DESC(ag71xx_debug
, "Debug level (-1=defaults,0=none,...,16=all)");
31 static void ag71xx_dump_dma_regs(struct ag71xx
*ag
)
33 DBG("%s: dma_tx_ctrl=%08x, dma_tx_desc=%08x, dma_tx_status=%08x\n",
35 ag71xx_rr(ag
, AG71XX_REG_TX_CTRL
),
36 ag71xx_rr(ag
, AG71XX_REG_TX_DESC
),
37 ag71xx_rr(ag
, AG71XX_REG_TX_STATUS
));
39 DBG("%s: dma_rx_ctrl=%08x, dma_rx_desc=%08x, dma_rx_status=%08x\n",
41 ag71xx_rr(ag
, AG71XX_REG_RX_CTRL
),
42 ag71xx_rr(ag
, AG71XX_REG_RX_DESC
),
43 ag71xx_rr(ag
, AG71XX_REG_RX_STATUS
));
46 static void ag71xx_dump_regs(struct ag71xx
*ag
)
48 DBG("%s: mac_cfg1=%08x, mac_cfg2=%08x, ipg=%08x, hdx=%08x, mfl=%08x\n",
50 ag71xx_rr(ag
, AG71XX_REG_MAC_CFG1
),
51 ag71xx_rr(ag
, AG71XX_REG_MAC_CFG2
),
52 ag71xx_rr(ag
, AG71XX_REG_MAC_IPG
),
53 ag71xx_rr(ag
, AG71XX_REG_MAC_HDX
),
54 ag71xx_rr(ag
, AG71XX_REG_MAC_MFL
));
55 DBG("%s: mac_ifctl=%08x, mac_addr1=%08x, mac_addr2=%08x\n",
57 ag71xx_rr(ag
, AG71XX_REG_MAC_IFCTL
),
58 ag71xx_rr(ag
, AG71XX_REG_MAC_ADDR1
),
59 ag71xx_rr(ag
, AG71XX_REG_MAC_ADDR2
));
60 DBG("%s: fifo_cfg0=%08x, fifo_cfg1=%08x, fifo_cfg2=%08x\n",
62 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG0
),
63 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG1
),
64 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG2
));
65 DBG("%s: fifo_cfg3=%08x, fifo_cfg4=%08x, fifo_cfg5=%08x\n",
67 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG3
),
68 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG4
),
69 ag71xx_rr(ag
, AG71XX_REG_FIFO_CFG5
));
72 static inline void ag71xx_dump_intr(struct ag71xx
*ag
, char *label
, u32 intr
)
74 DBG("%s: %s intr=%08x %s%s%s%s%s%s\n",
75 ag
->dev
->name
, label
, intr
,
76 (intr
& AG71XX_INT_TX_PS
) ? "TXPS " : "",
77 (intr
& AG71XX_INT_TX_UR
) ? "TXUR " : "",
78 (intr
& AG71XX_INT_TX_BE
) ? "TXBE " : "",
79 (intr
& AG71XX_INT_RX_PR
) ? "RXPR " : "",
80 (intr
& AG71XX_INT_RX_OF
) ? "RXOF " : "",
81 (intr
& AG71XX_INT_RX_BE
) ? "RXBE " : "");
84 static void ag71xx_ring_free(struct ag71xx_ring
*ring
)
89 dma_free_coherent(NULL
, ring
->size
* sizeof(*ring
->descs
),
90 ring
->descs
, ring
->descs_dma
);
93 static int ag71xx_ring_alloc(struct ag71xx_ring
*ring
, unsigned int size
)
97 ring
->descs
= dma_alloc_coherent(NULL
, size
* sizeof(*ring
->descs
),
107 ring
->buf
= kzalloc(size
* sizeof(*ring
->buf
), GFP_KERNEL
);
119 static void ag71xx_ring_tx_clean(struct ag71xx
*ag
)
121 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
122 struct net_device
*dev
= ag
->dev
;
124 while (ring
->curr
!= ring
->dirty
) {
125 u32 i
= ring
->dirty
% AG71XX_TX_RING_SIZE
;
127 if (!ag71xx_desc_empty(&ring
->descs
[i
])) {
128 ring
->descs
[i
].ctrl
= 0;
129 dev
->stats
.tx_errors
++;
132 if (ring
->buf
[i
].skb
)
133 dev_kfree_skb_any(ring
->buf
[i
].skb
);
135 ring
->buf
[i
].skb
= NULL
;
140 /* flush descriptors */
145 static void ag71xx_ring_tx_init(struct ag71xx
*ag
)
147 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
150 for (i
= 0; i
< AG71XX_TX_RING_SIZE
; i
++) {
151 ring
->descs
[i
].next
= (u32
) (ring
->descs_dma
+
152 sizeof(*ring
->descs
) * ((i
+ 1) % AG71XX_TX_RING_SIZE
));
154 ring
->descs
[i
].ctrl
= DESC_EMPTY
;
155 ring
->buf
[i
].skb
= NULL
;
158 /* flush descriptors */
165 static void ag71xx_ring_rx_clean(struct ag71xx
*ag
)
167 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
173 for (i
= 0; i
< AG71XX_RX_RING_SIZE
; i
++)
174 if (ring
->buf
[i
].skb
)
175 kfree_skb(ring
->buf
[i
].skb
);
179 static int ag71xx_ring_rx_init(struct ag71xx
*ag
)
181 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
186 for (i
= 0; i
< AG71XX_RX_RING_SIZE
; i
++)
187 ring
->descs
[i
].next
= (u32
) (ring
->descs_dma
+
188 sizeof(*ring
->descs
) * ((i
+ 1) % AG71XX_RX_RING_SIZE
));
190 for (i
= 0; i
< AG71XX_RX_RING_SIZE
; i
++) {
193 skb
= dev_alloc_skb(AG71XX_RX_PKT_SIZE
);
199 dma_map_single(NULL
, skb
->data
, AG71XX_RX_PKT_SIZE
,
203 skb_reserve(skb
, AG71XX_RX_PKT_RESERVE
);
205 ring
->buf
[i
].skb
= skb
;
206 ring
->descs
[i
].data
= virt_to_phys(skb
->data
);
207 ring
->descs
[i
].ctrl
= DESC_EMPTY
;
210 /* flush descriptors */
219 static int ag71xx_ring_rx_refill(struct ag71xx
*ag
)
221 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
225 for (; ring
->curr
- ring
->dirty
> 0; ring
->dirty
++) {
228 i
= ring
->dirty
% AG71XX_RX_RING_SIZE
;
230 if (ring
->buf
[i
].skb
== NULL
) {
233 skb
= dev_alloc_skb(AG71XX_RX_PKT_SIZE
);
237 dma_map_single(NULL
, skb
->data
, AG71XX_RX_PKT_SIZE
,
240 skb_reserve(skb
, AG71XX_RX_PKT_RESERVE
);
243 ring
->buf
[i
].skb
= skb
;
244 ring
->descs
[i
].data
= virt_to_phys(skb
->data
);
247 ring
->descs
[i
].ctrl
= DESC_EMPTY
;
251 /* flush descriptors */
254 DBG("%s: %u rx descriptors refilled\n", ag
->dev
->name
, count
);
259 static int ag71xx_rings_init(struct ag71xx
*ag
)
263 ret
= ag71xx_ring_alloc(&ag
->tx_ring
, AG71XX_TX_RING_SIZE
);
267 ag71xx_ring_tx_init(ag
);
269 ret
= ag71xx_ring_alloc(&ag
->rx_ring
, AG71XX_RX_RING_SIZE
);
273 ret
= ag71xx_ring_rx_init(ag
);
277 static void ag71xx_rings_cleanup(struct ag71xx
*ag
)
279 ag71xx_ring_rx_clean(ag
);
280 ag71xx_ring_free(&ag
->rx_ring
);
282 ag71xx_ring_tx_clean(ag
);
283 ag71xx_ring_free(&ag
->tx_ring
);
286 static void ag71xx_hw_set_macaddr(struct ag71xx
*ag
, unsigned char *mac
)
290 t
= (((u32
) mac
[0]) << 24) | (((u32
) mac
[1]) << 16)
291 | (((u32
) mac
[2]) << 8) | ((u32
) mac
[3]);
293 ag71xx_wr(ag
, AG71XX_REG_MAC_ADDR1
, t
);
295 t
= (((u32
) mac
[4]) << 24) | (((u32
) mac
[5]) << 16);
296 ag71xx_wr(ag
, AG71XX_REG_MAC_ADDR2
, t
);
299 static void ag71xx_dma_reset(struct ag71xx
*ag
)
303 ag71xx_dump_dma_regs(ag
);
306 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, 0);
307 ag71xx_wr(ag
, AG71XX_REG_TX_CTRL
, 0);
309 /* clear descriptor addresses */
310 ag71xx_wr(ag
, AG71XX_REG_TX_DESC
, 0);
311 ag71xx_wr(ag
, AG71XX_REG_RX_DESC
, 0);
313 /* clear pending RX/TX interrupts */
314 for (i
= 0; i
< 256; i
++) {
315 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_PR
);
316 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_PS
);
319 /* clear pending errors */
320 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_BE
| RX_STATUS_OF
);
321 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_BE
| TX_STATUS_UR
);
323 if (ag71xx_rr(ag
, AG71XX_REG_RX_STATUS
))
324 printk(KERN_ALERT
"%s: unable to clear DMA Rx status\n",
327 if (ag71xx_rr(ag
, AG71XX_REG_TX_STATUS
))
328 printk(KERN_ALERT
"%s: unable to clear DMA Tx status\n",
331 ag71xx_dump_dma_regs(ag
);
334 #define MAC_CFG1_INIT (MAC_CFG1_RXE | MAC_CFG1_TXE | \
335 MAC_CFG1_SRX | MAC_CFG1_STX)
337 #define FIFO_CFG0_INIT (FIFO_CFG0_ALL << FIFO_CFG0_ENABLE_SHIFT)
339 #define FIFO_CFG4_INIT (FIFO_CFG4_DE | FIFO_CFG4_DV | FIFO_CFG4_FC | \
340 FIFO_CFG4_CE | FIFO_CFG4_CR | FIFO_CFG4_LM | \
341 FIFO_CFG4_LO | FIFO_CFG4_OK | FIFO_CFG4_MC | \
342 FIFO_CFG4_BC | FIFO_CFG4_DR | FIFO_CFG4_LE | \
343 FIFO_CFG4_CF | FIFO_CFG4_PF | FIFO_CFG4_UO | \
346 #define FIFO_CFG5_INIT (FIFO_CFG5_DE | FIFO_CFG5_DV | FIFO_CFG5_FC | \
347 FIFO_CFG5_CE | FIFO_CFG5_LO | FIFO_CFG5_OK | \
348 FIFO_CFG5_MC | FIFO_CFG5_BC | FIFO_CFG5_DR | \
349 FIFO_CFG5_CF | FIFO_CFG5_PF | FIFO_CFG5_VT | \
350 FIFO_CFG5_LE | FIFO_CFG5_FT | FIFO_CFG5_16 | \
351 FIFO_CFG5_17 | FIFO_CFG5_SF)
353 static void ag71xx_hw_init(struct ag71xx
*ag
)
355 struct ag71xx_platform_data
*pdata
= ag71xx_get_pdata(ag
);
357 ag71xx_sb(ag
, AG71XX_REG_MAC_CFG1
, MAC_CFG1_SR
);
360 ar71xx_device_stop(pdata
->reset_bit
);
362 ar71xx_device_start(pdata
->reset_bit
);
365 /* setup MAC configuration registers */
366 ag71xx_wr(ag
, AG71XX_REG_MAC_CFG1
, MAC_CFG1_INIT
);
367 ag71xx_sb(ag
, AG71XX_REG_MAC_CFG2
,
368 MAC_CFG2_PAD_CRC_EN
| MAC_CFG2_LEN_CHECK
);
370 /* setup max frame length */
371 ag71xx_wr(ag
, AG71XX_REG_MAC_MFL
, AG71XX_TX_MTU_LEN
);
373 /* setup MII interface type */
374 ag71xx_mii_ctrl_set_if(ag
, pdata
->mii_if
);
376 /* setup FIFO configuration registers */
377 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG0
, FIFO_CFG0_INIT
);
378 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG1
, 0x0fff0000);
379 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG2
, 0x00001fff);
380 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG4
, FIFO_CFG4_INIT
);
381 ag71xx_wr(ag
, AG71XX_REG_FIFO_CFG5
, FIFO_CFG5_INIT
);
383 ag71xx_dma_reset(ag
);
386 static void ag71xx_hw_start(struct ag71xx
*ag
)
388 /* start RX engine */
389 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, RX_CTRL_RXE
);
391 /* enable interrupts */
392 ag71xx_wr(ag
, AG71XX_REG_INT_ENABLE
, AG71XX_INT_INIT
);
395 static void ag71xx_hw_stop(struct ag71xx
*ag
)
397 /* disable all interrupts */
398 ag71xx_wr(ag
, AG71XX_REG_INT_ENABLE
, 0);
400 ag71xx_dma_reset(ag
);
403 static int ag71xx_open(struct net_device
*dev
)
405 struct ag71xx
*ag
= netdev_priv(dev
);
408 ret
= ag71xx_rings_init(ag
);
412 napi_enable(&ag
->napi
);
414 netif_carrier_off(dev
);
415 ag71xx_phy_start(ag
);
417 ag71xx_wr(ag
, AG71XX_REG_TX_DESC
, ag
->tx_ring
.descs_dma
);
418 ag71xx_wr(ag
, AG71XX_REG_RX_DESC
, ag
->rx_ring
.descs_dma
);
420 ag71xx_hw_set_macaddr(ag
, dev
->dev_addr
);
424 netif_start_queue(dev
);
429 ag71xx_rings_cleanup(ag
);
433 static int ag71xx_stop(struct net_device
*dev
)
435 struct ag71xx
*ag
= netdev_priv(dev
);
438 spin_lock_irqsave(&ag
->lock
, flags
);
440 netif_stop_queue(dev
);
444 netif_carrier_off(dev
);
447 napi_disable(&ag
->napi
);
448 del_timer_sync(&ag
->oom_timer
);
450 spin_unlock_irqrestore(&ag
->lock
, flags
);
452 ag71xx_rings_cleanup(ag
);
457 static int ag71xx_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
459 struct ag71xx
*ag
= netdev_priv(dev
);
460 struct ag71xx_platform_data
*pdata
= ag71xx_get_pdata(ag
);
461 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
462 struct ag71xx_desc
*desc
;
466 i
= ring
->curr
% AG71XX_TX_RING_SIZE
;
467 desc
= &ring
->descs
[i
];
469 spin_lock_irqsave(&ag
->lock
, flags
);
471 spin_unlock_irqrestore(&ag
->lock
, flags
);
473 if (!ag71xx_desc_empty(desc
))
477 DBG("%s: packet len is too small\n", ag
->dev
->name
);
481 dma_map_single(NULL
, skb
->data
, skb
->len
, DMA_TO_DEVICE
);
483 ring
->buf
[i
].skb
= skb
;
485 /* setup descriptor fields */
486 desc
->data
= virt_to_phys(skb
->data
);
487 desc
->ctrl
= (skb
->len
& DESC_PKTLEN_M
);
489 /* flush descriptor */
493 if (ring
->curr
== (ring
->dirty
+ AG71XX_TX_THRES_STOP
)) {
494 DBG("%s: tx queue full\n", ag
->dev
->name
);
495 netif_stop_queue(dev
);
498 DBG("%s: packet injected into TX queue\n", ag
->dev
->name
);
500 /* enable TX engine */
501 ag71xx_wr(ag
, AG71XX_REG_TX_CTRL
, TX_CTRL_TXE
);
503 dev
->trans_start
= jiffies
;
508 dev
->stats
.tx_dropped
++;
514 static int ag71xx_do_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
516 struct mii_ioctl_data
*data
= (struct mii_ioctl_data
*) &ifr
->ifr_data
;
517 struct ag71xx
*ag
= netdev_priv(dev
);
522 if (ag
->phy_dev
== NULL
)
525 spin_lock_irq(&ag
->lock
);
526 ret
= phy_ethtool_ioctl(ag
->phy_dev
, (void *) ifr
->ifr_data
);
527 spin_unlock_irq(&ag
->lock
);
532 (dev
->dev_addr
, ifr
->ifr_data
, sizeof(dev
->dev_addr
)))
538 (ifr
->ifr_data
, dev
->dev_addr
, sizeof(dev
->dev_addr
)))
545 if (ag
->phy_dev
== NULL
)
548 return phy_mii_ioctl(ag
->phy_dev
, data
, cmd
);
557 static void ag71xx_oom_timer_handler(unsigned long data
)
559 struct net_device
*dev
= (struct net_device
*) data
;
560 struct ag71xx
*ag
= netdev_priv(dev
);
562 netif_rx_schedule(dev
, &ag
->napi
);
565 static void ag71xx_tx_timeout(struct net_device
*dev
)
567 struct ag71xx
*ag
= netdev_priv(dev
);
569 if (netif_msg_tx_err(ag
))
570 printk(KERN_DEBUG
"%s: tx timeout\n", ag
->dev
->name
);
572 schedule_work(&ag
->restart_work
);
575 static void ag71xx_restart_work_func(struct work_struct
*work
)
577 struct ag71xx
*ag
= container_of(work
, struct ag71xx
, restart_work
);
579 ag71xx_stop(ag
->dev
);
580 ag71xx_open(ag
->dev
);
583 static void ag71xx_tx_packets(struct ag71xx
*ag
)
585 struct ag71xx_ring
*ring
= &ag
->tx_ring
;
588 DBG("%s: processing TX ring\n", ag
->dev
->name
);
591 while (ring
->dirty
!= ring
->curr
) {
592 unsigned int i
= ring
->dirty
% AG71XX_TX_RING_SIZE
;
593 struct ag71xx_desc
*desc
= &ring
->descs
[i
];
594 struct sk_buff
*skb
= ring
->buf
[i
].skb
;
596 if (!ag71xx_desc_empty(desc
))
599 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_PS
);
601 ag
->dev
->stats
.tx_bytes
+= skb
->len
;
602 ag
->dev
->stats
.tx_packets
++;
604 dev_kfree_skb_any(skb
);
605 ring
->buf
[i
].skb
= NULL
;
611 DBG("%s: %d packets sent out\n", ag
->dev
->name
, sent
);
613 if ((ring
->curr
- ring
->dirty
) < AG71XX_TX_THRES_WAKEUP
)
614 netif_wake_queue(ag
->dev
);
618 static int ag71xx_rx_packets(struct ag71xx
*ag
, int limit
)
620 struct net_device
*dev
= ag
->dev
;
621 struct ag71xx_ring
*ring
= &ag
->rx_ring
;
624 DBG("%s: rx packets, limit=%d, curr=%u, dirty=%u\n",
625 dev
->name
, limit
, ring
->curr
, ring
->dirty
);
627 while (done
< limit
) {
628 unsigned int i
= ring
->curr
% AG71XX_RX_RING_SIZE
;
629 struct ag71xx_desc
*desc
= &ring
->descs
[i
];
633 if (ag71xx_desc_empty(desc
))
636 if ((ring
->dirty
+ AG71XX_RX_RING_SIZE
) == ring
->curr
) {
641 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_PR
);
643 skb
= ring
->buf
[i
].skb
;
644 pktlen
= ag71xx_desc_pktlen(desc
);
645 pktlen
-= ETH_FCS_LEN
;
647 skb_put(skb
, pktlen
);
650 skb
->protocol
= eth_type_trans(skb
, dev
);
651 skb
->ip_summed
= CHECKSUM_NONE
;
653 netif_receive_skb(skb
);
655 dev
->last_rx
= jiffies
;
656 dev
->stats
.rx_packets
++;
657 dev
->stats
.rx_bytes
+= pktlen
;
659 ring
->buf
[i
].skb
= NULL
;
665 ag71xx_ring_rx_refill(ag
);
667 DBG("%s: rx finish, curr=%u, dirty=%u, done=%d\n",
668 dev
->name
, ring
->curr
, ring
->dirty
, done
);
673 static int ag71xx_poll(struct napi_struct
*napi
, int limit
)
675 struct ag71xx
*ag
= container_of(napi
, struct ag71xx
, napi
);
676 struct ag71xx_platform_data
*pdata
= ag71xx_get_pdata(ag
);
677 struct net_device
*dev
= ag
->dev
;
678 struct ag71xx_ring
*rx_ring
;
684 ag71xx_tx_packets(ag
);
686 DBG("%s: processing RX ring\n", dev
->name
);
687 done
= ag71xx_rx_packets(ag
, limit
);
689 rx_ring
= &ag
->rx_ring
;
690 if (rx_ring
->buf
[rx_ring
->dirty
% AG71XX_RX_RING_SIZE
].skb
== NULL
)
693 status
= ag71xx_rr(ag
, AG71XX_REG_RX_STATUS
);
694 if (unlikely(status
& RX_STATUS_OF
)) {
695 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_OF
);
696 dev
->stats
.rx_fifo_errors
++;
699 ag71xx_wr(ag
, AG71XX_REG_RX_CTRL
, RX_CTRL_RXE
);
703 if (status
& RX_STATUS_PR
)
706 status
= ag71xx_rr(ag
, AG71XX_REG_TX_STATUS
);
707 if (status
& TX_STATUS_PS
)
710 DBG("%s: disable polling mode, done=%d, limit=%d\n",
711 dev
->name
, done
, limit
);
713 netif_rx_complete(dev
, napi
);
715 /* enable interrupts */
716 spin_lock_irqsave(&ag
->lock
, flags
);
717 ag71xx_int_enable(ag
, AG71XX_INT_POLL
);
718 spin_unlock_irqrestore(&ag
->lock
, flags
);
723 DBG("%s: stay in polling mode, done=%d, limit=%d\n",
724 dev
->name
, done
, limit
);
728 if (netif_msg_rx_err(ag
))
729 printk(KERN_DEBUG
"%s: out of memory\n", dev
->name
);
731 mod_timer(&ag
->oom_timer
, jiffies
+ AG71XX_OOM_REFILL
);
732 netif_rx_complete(dev
, napi
);
736 static irqreturn_t
ag71xx_interrupt(int irq
, void *dev_id
)
738 struct net_device
*dev
= dev_id
;
739 struct ag71xx
*ag
= netdev_priv(dev
);
742 status
= ag71xx_rr(ag
, AG71XX_REG_INT_STATUS
);
743 ag71xx_dump_intr(ag
, "raw", status
);
745 if (unlikely(!status
))
748 if (unlikely(status
& AG71XX_INT_ERR
)) {
749 if (status
& AG71XX_INT_TX_BE
) {
750 ag71xx_wr(ag
, AG71XX_REG_TX_STATUS
, TX_STATUS_BE
);
751 dev_err(&dev
->dev
, "TX BUS error\n");
753 if (status
& AG71XX_INT_RX_BE
) {
754 ag71xx_wr(ag
, AG71XX_REG_RX_STATUS
, RX_STATUS_BE
);
755 dev_err(&dev
->dev
, "RX BUS error\n");
759 if (likely(status
& AG71XX_INT_POLL
)) {
760 ag71xx_int_disable(ag
, AG71XX_INT_POLL
);
761 DBG("%s: enable polling mode\n", dev
->name
);
762 netif_rx_schedule(dev
, &ag
->napi
);
768 static void ag71xx_set_multicast_list(struct net_device
*dev
)
773 static int __init
ag71xx_probe(struct platform_device
*pdev
)
775 struct net_device
*dev
;
776 struct resource
*res
;
778 struct ag71xx_platform_data
*pdata
;
781 pdata
= pdev
->dev
.platform_data
;
783 dev_err(&pdev
->dev
, "no platform data specified\n");
788 dev
= alloc_etherdev(sizeof(*ag
));
790 dev_err(&pdev
->dev
, "alloc_etherdev failed\n");
795 SET_NETDEV_DEV(dev
, &pdev
->dev
);
797 ag
= netdev_priv(dev
);
800 ag
->mii_bus
= ag71xx_mdio_bus
->mii_bus
;
801 ag
->msg_enable
= netif_msg_init(ag71xx_debug
,
802 AG71XX_DEFAULT_MSG_ENABLE
);
803 spin_lock_init(&ag
->lock
);
805 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "mac_base");
807 dev_err(&pdev
->dev
, "no mac_base resource found\n");
812 ag
->mac_base
= ioremap_nocache(res
->start
, res
->end
- res
->start
+ 1);
814 dev_err(&pdev
->dev
, "unable to ioremap mac_base\n");
819 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "mac_base2");
821 dev_err(&pdev
->dev
, "no mac_base2 resource found\n");
823 goto err_unmap_base1
;
826 ag
->mac_base2
= ioremap_nocache(res
->start
, res
->end
- res
->start
+ 1);
828 dev_err(&pdev
->dev
, "unable to ioremap mac_base2\n");
830 goto err_unmap_base1
;
833 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "mii_ctrl");
835 dev_err(&pdev
->dev
, "no mii_ctrl resource found\n");
837 goto err_unmap_base2
;
840 ag
->mii_ctrl
= ioremap_nocache(res
->start
, res
->end
- res
->start
+ 1);
842 dev_err(&pdev
->dev
, "unable to ioremap mii_ctrl\n");
844 goto err_unmap_base2
;
847 dev
->irq
= platform_get_irq(pdev
, 0);
848 err
= request_irq(dev
->irq
, ag71xx_interrupt
,
849 IRQF_DISABLED
| IRQF_SAMPLE_RANDOM
,
852 dev_err(&pdev
->dev
, "unable to request IRQ %d\n", dev
->irq
);
853 goto err_unmap_mii_ctrl
;
856 dev
->base_addr
= (unsigned long)ag
->mac_base
;
857 dev
->open
= ag71xx_open
;
858 dev
->stop
= ag71xx_stop
;
859 dev
->hard_start_xmit
= ag71xx_hard_start_xmit
;
860 dev
->set_multicast_list
= ag71xx_set_multicast_list
;
861 dev
->do_ioctl
= ag71xx_do_ioctl
;
862 dev
->ethtool_ops
= &ag71xx_ethtool_ops
;
864 dev
->tx_timeout
= ag71xx_tx_timeout
;
865 INIT_WORK(&ag
->restart_work
, ag71xx_restart_work_func
);
867 init_timer(&ag
->oom_timer
);
868 ag
->oom_timer
.data
= (unsigned long) dev
;
869 ag
->oom_timer
.function
= ag71xx_oom_timer_handler
;
871 memcpy(dev
->dev_addr
, pdata
->mac_addr
, ETH_ALEN
);
873 netif_napi_add(dev
, &ag
->napi
, ag71xx_poll
, AG71XX_NAPI_WEIGHT
);
875 err
= register_netdev(dev
);
877 dev_err(&pdev
->dev
, "unable to register net device\n");
881 printk(KERN_INFO
"%s: Atheros AG71xx at 0x%08lx, irq %d\n",
882 dev
->name
, dev
->base_addr
, dev
->irq
);
884 ag71xx_dump_regs(ag
);
888 ag71xx_dump_regs(ag
);
890 /* Reset the mdio bus explicitly */
892 mutex_lock(&ag
->mii_bus
->mdio_lock
);
893 ag
->mii_bus
->reset(ag
->mii_bus
);
894 mutex_unlock(&ag
->mii_bus
->mdio_lock
);
897 err
= ag71xx_phy_connect(ag
);
899 goto err_unregister_netdev
;
901 platform_set_drvdata(pdev
, dev
);
905 err_unregister_netdev
:
906 unregister_netdev(dev
);
908 free_irq(dev
->irq
, dev
);
910 iounmap(ag
->mii_ctrl
);
912 iounmap(ag
->mac_base2
);
914 iounmap(ag
->mac_base
);
918 platform_set_drvdata(pdev
, NULL
);
922 static int __exit
ag71xx_remove(struct platform_device
*pdev
)
924 struct net_device
*dev
= platform_get_drvdata(pdev
);
927 struct ag71xx
*ag
= netdev_priv(dev
);
929 ag71xx_phy_disconnect(ag
);
930 unregister_netdev(dev
);
931 free_irq(dev
->irq
, dev
);
932 iounmap(ag
->mii_ctrl
);
933 iounmap(ag
->mac_base2
);
934 iounmap(ag
->mac_base
);
936 platform_set_drvdata(pdev
, NULL
);
942 static struct platform_driver ag71xx_driver
= {
943 .probe
= ag71xx_probe
,
944 .remove
= __exit_p(ag71xx_remove
),
946 .name
= AG71XX_DRV_NAME
,
950 static int __init
ag71xx_module_init(void)
954 ret
= ag71xx_mdio_driver_init();
958 ret
= platform_driver_register(&ag71xx_driver
);
965 ag71xx_mdio_driver_exit();
970 static void __exit
ag71xx_module_exit(void)
972 platform_driver_unregister(&ag71xx_driver
);
973 ag71xx_mdio_driver_exit();
976 module_init(ag71xx_module_init
);
977 module_exit(ag71xx_module_exit
);
979 MODULE_VERSION(AG71XX_DRV_VERSION
);
980 MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
981 MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org>");
982 MODULE_LICENSE("GPL v2");
983 MODULE_ALIAS("platform:" AG71XX_DRV_NAME
);