X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/48f3d520ecaf73ee883ce339e756195562b9043f..93f85923e9ebb41b33223df0f07adc8afbdaa34a:/target/linux/ramips/files/drivers/net/ramips.c diff --git a/target/linux/ramips/files/drivers/net/ramips.c b/target/linux/ramips/files/drivers/net/ramips.c index 34d5b3e69..5a728be02 100644 --- a/target/linux/ramips/files/drivers/net/ramips.c +++ b/target/linux/ramips/files/drivers/net/ramips.c @@ -51,6 +51,32 @@ ramips_fe_rr(unsigned reg) return __raw_readl(ramips_fe_base + reg); } +static inline void +ramips_fe_int_disable(u32 mask) +{ + ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE) & ~mask, + RAMIPS_FE_INT_ENABLE); + /* flush write */ + ramips_fe_rr(RAMIPS_FE_INT_ENABLE); +} + +static inline void +ramips_fe_int_enable(u32 mask) +{ + ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE) | mask, + RAMIPS_FE_INT_ENABLE); + /* flush write */ + ramips_fe_rr(RAMIPS_FE_INT_ENABLE); +} + +static inline void +ramips_hw_set_macaddr(unsigned char *mac) +{ + ramips_fe_wr((mac[0] << 8) | mac[1], RAMIPS_GDMA1_MAC_ADRH); + ramips_fe_wr((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5], + RAMIPS_GDMA1_MAC_ADRL); +} + static void ramips_cleanup_dma(struct raeth_priv *re) { @@ -229,8 +255,7 @@ ramips_eth_rx_hw(unsigned long ptr) if (max_rx == 0) tasklet_schedule(&priv->rx_tasklet); else - ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE) | RAMIPS_RX_DLY_INT, - RAMIPS_FE_INT_ENABLE); + ramips_fe_int_enable(RAMIPS_RX_DLY_INT); } static void @@ -248,23 +273,7 @@ ramips_eth_tx_housekeeping(unsigned long ptr) priv->skb_free_idx = 0; } - ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE) | RAMIPS_TX_DLY_INT, - RAMIPS_FE_INT_ENABLE); -} - -static int -ramips_eth_set_mac_addr(struct net_device *dev, void *priv) -{ - unsigned char *mac = priv; - - if (netif_running(dev)) - return -EBUSY; - - memcpy(dev->dev_addr, ((struct sockaddr*)priv)->sa_data, dev->addr_len); - ramips_fe_wr((mac[0] << 8) | mac[1], RAMIPS_GDMA1_MAC_ADRH); - ramips_fe_wr((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5], - RAMIPS_GDMA1_MAC_ADRL); - return 0; + ramips_fe_int_enable(RAMIPS_TX_DLY_INT); } static void @@ -284,8 +293,7 @@ ramips_eth_irq(int irq, void *dev) ramips_fe_wr(0xFFFFFFFF, RAMIPS_FE_INT_STATUS); if (fe_int & RAMIPS_RX_DLY_INT) { - ramips_fe_wr(ramips_fe_rr(RAMIPS_FE_INT_ENABLE) & ~(RAMIPS_RX_DLY_INT), - RAMIPS_FE_INT_ENABLE); + ramips_fe_int_disable(RAMIPS_RX_DLY_INT); tasklet_schedule(&priv->rx_tasklet); } @@ -310,6 +318,8 @@ ramips_eth_open(struct net_device *dev) if (err) goto err_free_irq; + ramips_hw_set_macaddr(dev->dev_addr); + ramips_setup_dma(priv); ramips_fe_wr((ramips_fe_rr(RAMIPS_PDMA_GLO_CFG) & 0xff) | (RAMIPS_TX_WB_DDONE | RAMIPS_RX_DMA_EN | @@ -317,7 +327,7 @@ ramips_eth_open(struct net_device *dev) RAMIPS_PDMA_GLO_CFG); ramips_fe_wr((ramips_fe_rr(RAMIPS_FE_GLO_CFG) & ~(RAMIPS_US_CYC_CNT_MASK << RAMIPS_US_CYC_CNT_SHIFT)) | - ((rt305x_sys_freq / RAMIPS_US_CYC_CNT_DIVISOR) << RAMIPS_US_CYC_CNT_SHIFT), + ((priv->plat->sys_freq / RAMIPS_US_CYC_CNT_DIVISOR) << RAMIPS_US_CYC_CNT_SHIFT), RAMIPS_FE_GLO_CFG); tasklet_init(&priv->tx_housekeeping_tasklet, ramips_eth_tx_housekeeping, @@ -365,13 +375,11 @@ static int __init ramips_eth_probe(struct net_device *dev) { struct raeth_priv *priv = netdev_priv(dev); - struct sockaddr addr; BUG_ON(!priv->plat->reset_fe); priv->plat->reset_fe(); net_srandom(jiffies); - memcpy(addr.sa_data, priv->plat->mac, 6); - ramips_eth_set_mac_addr(dev, &addr); + memcpy(dev->dev_addr, priv->plat->mac, ETH_ALEN); ether_setup(dev); dev->mtu = 1500; @@ -388,7 +396,7 @@ static const struct net_device_ops ramips_eth_netdev_ops = { .ndo_start_xmit = ramips_eth_hard_start_xmit, .ndo_tx_timeout = ramips_eth_timeout, .ndo_change_mtu = eth_change_mtu, - .ndo_set_mac_address = ramips_eth_set_mac_addr, + .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, };