28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/string.h>
32 #include <linux/errno.h>
34 #include <linux/slab.h>
36 #include <linux/netdevice.h>
40 #include <linux/bitops.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
46 #include <linux/prefetch.h>
48 #include <asm/cache.h>
50 #include <asm/processor.h>
54 #define CONFIG_SBMAC_COALESCE
57 #define TX_TIMEOUT (2*HZ)
71 #ifdef CONFIG_SBMAC_COALESCE
72 static int int_pktcnt_tx = 255;
76 static int int_timeout_tx = 255;
80 static int int_pktcnt_rx = 64;
84 static int int_timeout_rx = 64;
91 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
94 #define R_MAC_DMA_OODPKTLOST_RX R_MAC_DMA_OODPKTLOST
95 #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
99 #error invalid SiByte MAC configuration
105 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
106 #define UNIT_INT(n) (K_BCM1480_INT_MAC_0 + ((n) * 2))
107 #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
108 #define UNIT_INT(n) (K_INT_MAC_0 + (n))
110 #error invalid SiByte MAC configuration
114 #define SBMAC_PHY_INT K_INT_PHY
116 #define SBMAC_PHY_INT PHY_POLL
157 #define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \
158 (d)->sbdma_dscrtable : (d)->f+1)
161 #define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES)
163 #define SBMAC_MAX_TXDESCR 256
164 #define SBMAC_MAX_RXDESCR 256
166 #define ENET_PACKET_SIZE 1518
194 #ifdef CONFIG_SBMAC_COALESCE
286 int txrx,
int maxdescr);
287 static void sbdma_channel_start(
struct sbmacdma *
d,
int rxtx);
291 static void sbdma_emptyring(
struct sbmacdma *
d);
294 int work_to_do,
int poll);
303 static uint64_t sbmac_addr2reg(
unsigned char *
ptr);
304 static irqreturn_t sbmac_intr(
int irq,
void *dev_instance);
322 static void sbmac_mii_sync(
void __iomem *sbm_mdio);
323 static void sbmac_mii_senddata(
void __iomem *sbm_mdio,
unsigned int data,
334 static char sbmac_string[] =
"sb1250-mac";
336 static char sbmac_mdio_string[] =
"sb1250-mac-mdio";
343 #define MII_COMMAND_START 0x01
344 #define MII_COMMAND_READ 0x02
345 #define MII_COMMAND_WRITE 0x01
346 #define MII_COMMAND_ACK 0x02
348 #define M_MAC_MDIO_DIR_OUTPUT 0
366 static void sbmac_mii_sync(
void __iomem *sbm_mdio)
378 for (cnt = 0; cnt < 32; cnt++) {
396 static void sbmac_mii_senddata(
void __iomem *sbm_mdio,
unsigned int data,
401 unsigned int curmask;
409 curmask = 1 << (bitcnt - 1);
411 for (i = 0; i < bitcnt; i++) {
450 sbmac_mii_sync(sbm_mdio);
461 sbmac_mii_senddata(sbm_mdio, phyaddr, 5);
462 sbmac_mii_senddata(sbm_mdio, regidx, 5);
530 static int sbmac_mii_write(
struct mii_bus *bus,
int phyaddr,
int regidx,
537 sbmac_mii_sync(sbm_mdio);
541 sbmac_mii_senddata(sbm_mdio, phyaddr, 5);
542 sbmac_mii_senddata(sbm_mdio, regidx, 5);
544 sbmac_mii_senddata(sbm_mdio, regval, 16);
574 int txrx,
int maxdescr)
576 #ifdef CONFIG_SBMAC_COALESCE
577 int int_pktcnt, int_timeout;
664 #ifdef CONFIG_SBMAC_COALESCE
669 int_pktcnt = (txrx ==
DMA_TX) ? int_pktcnt_tx : int_pktcnt_rx;
676 int_timeout = (txrx ==
DMA_TX) ? int_timeout_tx : int_timeout_rx;
699 static void sbdma_channel_start(
struct sbmacdma *d,
int rxtx)
705 #ifdef CONFIG_SBMAC_COALESCE
740 static void sbdma_channel_stop(
struct sbmacdma *d)
760 static inline void sbdma_align_skb(
struct sk_buff *
skb,
761 unsigned int power2,
unsigned int offset)
764 unsigned char *newaddr =
PTR_ALIGN(addr, power2);
766 skb_reserve(skb, newaddr - addr + offset);
834 if (sb_new ==
NULL) {
835 pr_info(
"%s: sk_buff allocation failed\n",
854 #ifdef CONFIG_SBMAC_COALESCE
949 #ifndef CONFIG_SBMAC_COALESCE
995 static void sbdma_emptyring(
struct sbmacdma *d)
1029 if (sbdma_add_rcvbuffer(sc, d,
NULL) != 0)
1034 #ifdef CONFIG_NET_POLL_CONTROLLER
1035 static void sbmac_netpoll(
struct net_device *netdev)
1042 sbmac_intr(irq, netdev);
1044 #ifdef CONFIG_SBMAC_COALESCE
1072 int work_to_do,
int poll)
1087 dev->
stats.rx_fifo_errors
1091 while (work_to_do-- > 0) {
1119 if (curidx == hwidx)
1147 dev->
stats.rx_dropped++;
1149 sbdma_add_rcvbuffer(sc, d, sb);
1169 !((dsc->
dscr_a) & M_DMA_ETHRX_BADTCPCS)) {
1173 skb_checksum_none_assert(sb);
1184 dev->
stats.rx_dropped++;
1190 dev->
stats.rx_packets++;
1198 dev->
stats.rx_errors++;
1199 sbdma_add_rcvbuffer(sc, d, sb);
1244 unsigned long flags;
1245 int packets_handled = 0;
1275 if (curidx == hwidx)
1291 dev->
stats.tx_packets++;
1315 if (packets_handled)
1316 netif_wake_queue(d->
sbdma_eth->sbm_dev);
1319 spin_unlock_irqrestore(&(sc->
sbm_lock), flags);
1374 static void sbdma_uninitctx(
struct sbmacdma *d)
1388 static void sbmac_uninitctx(
struct sbmac_softc *sc)
1407 static void sbmac_channel_start(
struct sbmac_softc *s)
1516 #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
1562 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
1565 #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
1571 #error invalid SiByte MAC configuration
1574 #ifdef CONFIG_SBMAC_COALESCE
1605 sbmac_promiscuous_mode(s,1);
1623 static void sbmac_channel_stop(
struct sbmac_softc *s)
1681 if (state == oldstate) {
1690 sbmac_channel_start(sc);
1693 sbmac_channel_stop(sc);
1748 static void sbmac_set_iphdr_offset(
struct sbmac_softc *sc)
1780 static uint64_t sbmac_addr2reg(
unsigned char *
ptr)
1997 static irqreturn_t sbmac_intr(
int irq,
void *dev_instance)
2020 sbdma_tx_process(sc,&(sc->
sbm_txdma), 0);
2023 if (napi_schedule_prep(&sc->
napi)) {
2031 SBMAC_MAX_RXDESCR * 2, 0);
2053 unsigned long flags;
2063 if (sbdma_add_txbuffer(&(sc->
sbm_txdma),skb)) {
2065 netif_stop_queue(dev);
2066 spin_unlock_irqrestore(&sc->
sbm_lock, flags);
2071 spin_unlock_irqrestore(&sc->
sbm_lock, flags);
2090 static void sbmac_setmulti(
struct sbmac_softc *sc)
2145 if (idx == MAC_ADDR_COUNT)
2147 reg = sbmac_addr2reg(ha->
addr);
2165 static int sb1250_change_mtu(
struct net_device *_dev,
int new_mtu)
2169 _dev->
mtu = new_mtu;
2170 pr_info(
"changing the mtu to %d\n", new_mtu);
2175 .ndo_open = sbmac_open,
2176 .ndo_stop = sbmac_close,
2177 .ndo_start_xmit = sbmac_start_tx,
2178 .ndo_set_rx_mode = sbmac_set_rx_mode,
2179 .ndo_tx_timeout = sbmac_tx_timeout,
2180 .ndo_do_ioctl = sbmac_mii_ioctl,
2181 .ndo_change_mtu = sb1250_change_mtu,
2184 #ifdef CONFIG_NET_POLL_CONTROLLER
2185 .ndo_poll_controller = sbmac_netpoll,
2204 int idx = pldev->
id;
2206 unsigned char *eaddr;
2223 for (i = 0; i < 6; i++) {
2224 eaddr[
i] = (
uint8_t) (ea_reg & 0xFF);
2228 for (i = 0; i < 6; i++) {
2250 dev->
irq = UNIT_INT(idx);
2253 sbmac_set_iphdr_offset(sc);
2255 sc->
mii_bus = mdiobus_alloc();
2261 sc->
mii_bus->name = sbmac_mdio_string;
2265 sc->
mii_bus->read = sbmac_mii_read;
2266 sc->
mii_bus->write = sbmac_mii_write;
2290 pr_info(
"%s.%d: registered as %s\n", sbmac_string, idx, dev->
name);
2293 pr_info(
"%s: enabling TCP rcv checksum\n", dev->
name);
2300 pr_info(
"%s: SiByte Ethernet at 0x%08Lx, address: %pM\n",
2301 dev->
name, base, eaddr);
2310 sbmac_uninitctx(sc);
2315 static int sbmac_open(
struct net_device *dev)
2346 err = sbmac_mii_probe(dev);
2348 goto out_unregister;
2356 netif_start_queue(dev);
2358 sbmac_set_rx_mode(dev);
2362 napi_enable(&sc->
napi);
2372 static int sbmac_mii_probe(
struct net_device *dev)
2388 phy_dev =
phy_connect(dev, dev_name(&phy_dev->
dev), &sbmac_mii_poll, 0,
2390 if (IS_ERR(phy_dev)) {
2392 return PTR_ERR(phy_dev);
2408 pr_info(
"%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
2409 dev->
name, phy_dev->
drv->name,
2410 dev_name(&phy_dev->
dev), phy_dev->
irq);
2418 static void sbmac_mii_poll(
struct net_device *dev)
2422 unsigned long flags;
2424 int link_chg, speed_chg, duplex_chg, pause_chg, fc_chg;
2431 if (!link_chg && !speed_chg && !duplex_chg && !pause_chg)
2434 if (!phy_dev->
link) {
2466 if ((speed_chg || duplex_chg || fc_chg) &&
2473 "because PHY state changed\n", dev->
name);
2474 sbmac_channel_stop(sc);
2475 sbmac_channel_start(sc);
2478 spin_unlock_irqrestore(&sc->
sbm_lock, flags);
2482 static void sbmac_tx_timeout (
struct net_device *dev)
2485 unsigned long flags;
2491 dev->
stats.tx_errors++;
2493 spin_unlock_irqrestore(&sc->
sbm_lock, flags);
2501 static void sbmac_set_rx_mode(
struct net_device *dev)
2503 unsigned long flags;
2513 sbmac_promiscuous_mode(sc,1);
2516 sbmac_promiscuous_mode(sc,0);
2519 spin_unlock_irqrestore(&sc->
sbm_lock, flags);
2533 if (!netif_running(dev) || !sc->
phy_dev)
2539 static int sbmac_close(
struct net_device *dev)
2543 napi_disable(&sc->
napi);
2549 netif_stop_queue(dev);
2569 work_done = sbdma_rx_process(sc, &(sc->
sbm_rxdma), budget, 1);
2570 sbdma_tx_process(sc, &(sc->
sbm_txdma), 1);
2572 if (work_done < budget) {
2575 #ifdef CONFIG_SBMAC_COALESCE
2595 u64 sbmac_orig_hwaddr;
2603 dev_name(&pldev->
dev));
2614 pr_debug(
"%s: %sconfiguring MAC at 0x%08Lx\n", dev_name(&pldev->
dev),
2615 sbmac_orig_hwaddr ?
"" :
"not ", (
long long)res->
start);
2616 if (sbmac_orig_hwaddr == 0) {
2633 sc = netdev_priv(dev);
2636 err = sbmac_init(pldev, res->
start);
2659 sbmac_uninitctx(sc);
2669 .probe = sbmac_probe,
2672 .name = sbmac_string,