2 * Copyright (C) 2004-2013 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Driver for the ARC EMAC 10100 (hardware revision 5)
16 #include <linux/crc32.h>
17 #include <linux/etherdevice.h>
18 #include <linux/interrupt.h>
20 #include <linux/module.h>
21 #include <linux/of_address.h>
22 #include <linux/of_irq.h>
23 #include <linux/of_mdio.h>
24 #include <linux/of_net.h>
25 #include <linux/of_platform.h>
29 #define DRV_NAME "arc_emac"
30 #define DRV_VERSION "1.0"
33 * arc_emac_adjust_link - Adjust the PHY link duplex.
34 * @ndev: Pointer to the net_device structure.
36 * This function is called to change the duplex setting after auto negotiation
39 static void arc_emac_adjust_link(struct net_device *ndev)
41 struct arc_emac_priv *priv = netdev_priv(ndev);
42 struct phy_device *phy_dev = priv->phy_dev;
43 unsigned int reg, state_changed = 0;
45 if (priv->link != phy_dev->link) {
46 priv->link = phy_dev->link;
50 if (priv->speed != phy_dev->speed) {
51 priv->speed = phy_dev->speed;
55 if (priv->duplex != phy_dev->duplex) {
56 reg = arc_reg_get(priv, R_CTRL);
58 if (DUPLEX_FULL == phy_dev->duplex)
63 arc_reg_set(priv, R_CTRL, reg);
64 priv->duplex = phy_dev->duplex;
69 phy_print_status(phy_dev);
73 * arc_emac_get_settings - Get PHY settings.
74 * @ndev: Pointer to net_device structure.
75 * @cmd: Pointer to ethtool_cmd structure.
77 * This implements ethtool command for getting PHY settings. If PHY could
78 * not be found, the function returns -ENODEV. This function calls the
79 * relevant PHY ethtool API to get the PHY settings.
80 * Issue "ethtool ethX" under linux prompt to execute this function.
82 static int arc_emac_get_settings(struct net_device *ndev,
83 struct ethtool_cmd *cmd)
85 struct arc_emac_priv *priv = netdev_priv(ndev);
87 return phy_ethtool_gset(priv->phy_dev, cmd);
91 * arc_emac_set_settings - Set PHY settings as passed in the argument.
92 * @ndev: Pointer to net_device structure.
93 * @cmd: Pointer to ethtool_cmd structure.
95 * This implements ethtool command for setting various PHY settings. If PHY
96 * could not be found, the function returns -ENODEV. This function calls the
97 * relevant PHY ethtool API to set the PHY.
98 * Issue e.g. "ethtool -s ethX speed 1000" under linux prompt to execute this
101 static int arc_emac_set_settings(struct net_device *ndev,
102 struct ethtool_cmd *cmd)
104 struct arc_emac_priv *priv = netdev_priv(ndev);
106 if (!capable(CAP_NET_ADMIN))
109 return phy_ethtool_sset(priv->phy_dev, cmd);
113 * arc_emac_get_drvinfo - Get EMAC driver information.
114 * @ndev: Pointer to net_device structure.
115 * @info: Pointer to ethtool_drvinfo structure.
117 * This implements ethtool command for getting the driver information.
118 * Issue "ethtool -i ethX" under linux prompt to execute this function.
120 static void arc_emac_get_drvinfo(struct net_device *ndev,
121 struct ethtool_drvinfo *info)
123 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
124 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
127 static const struct ethtool_ops arc_emac_ethtool_ops = {
128 .get_settings = arc_emac_get_settings,
129 .set_settings = arc_emac_set_settings,
130 .get_drvinfo = arc_emac_get_drvinfo,
131 .get_link = ethtool_op_get_link,
134 #define FIRST_OR_LAST_MASK (FIRST_MASK | LAST_MASK)
137 * arc_emac_tx_clean - clears processed by EMAC Tx BDs.
138 * @ndev: Pointer to the network device.
140 static void arc_emac_tx_clean(struct net_device *ndev)
142 struct arc_emac_priv *priv = netdev_priv(ndev);
143 struct net_device_stats *stats = &ndev->stats;
146 for (i = 0; i < TX_BD_NUM; i++) {
147 unsigned int *txbd_dirty = &priv->txbd_dirty;
148 struct arc_emac_bd *txbd = &priv->txbd[*txbd_dirty];
149 struct buffer_state *tx_buff = &priv->tx_buff[*txbd_dirty];
150 struct sk_buff *skb = tx_buff->skb;
151 unsigned int info = le32_to_cpu(txbd->info);
153 if ((info & FOR_EMAC) || !txbd->data)
156 if (unlikely(info & (DROP | DEFR | LTCL | UFLO))) {
161 stats->tx_carrier_errors++;
167 stats->tx_fifo_errors++;
168 } else if (likely(info & FIRST_OR_LAST_MASK)) {
170 stats->tx_bytes += skb->len;
173 dma_unmap_single(&ndev->dev, dma_unmap_addr(tx_buff, addr),
174 dma_unmap_len(tx_buff, len), DMA_TO_DEVICE);
176 /* return the sk_buff to system */
177 dev_kfree_skb_irq(skb);
182 *txbd_dirty = (*txbd_dirty + 1) % TX_BD_NUM;
184 if (netif_queue_stopped(ndev))
185 netif_wake_queue(ndev);
190 * arc_emac_rx - processing of Rx packets.
191 * @ndev: Pointer to the network device.
192 * @budget: How many BDs to process on 1 call.
194 * returns: Number of processed BDs
196 * Iterate through Rx BDs and deliver received packages to upper layer.
198 static int arc_emac_rx(struct net_device *ndev, int budget)
200 struct arc_emac_priv *priv = netdev_priv(ndev);
201 unsigned int work_done;
203 for (work_done = 0; work_done < budget; work_done++) {
204 unsigned int *last_rx_bd = &priv->last_rx_bd;
205 struct net_device_stats *stats = &ndev->stats;
206 struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
207 struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd];
208 unsigned int pktlen, info = le32_to_cpu(rxbd->info);
212 if (unlikely((info & OWN_MASK) == FOR_EMAC))
215 /* Make a note that we saw a packet at this BD.
216 * So next time, driver starts from this + 1
218 *last_rx_bd = (*last_rx_bd + 1) % RX_BD_NUM;
220 if (unlikely((info & FIRST_OR_LAST_MASK) !=
221 FIRST_OR_LAST_MASK)) {
222 /* We pre-allocate buffers of MTU size so incoming
223 * packets won't be split/chained.
226 netdev_err(ndev, "incomplete packet received\n");
228 /* Return ownership to EMAC */
229 rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
231 stats->rx_length_errors++;
235 pktlen = info & LEN_MASK;
237 stats->rx_bytes += pktlen;
239 skb_put(skb, pktlen);
241 skb->protocol = eth_type_trans(skb, ndev);
243 dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr),
244 dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE);
246 /* Prepare the BD for next cycle */
247 rx_buff->skb = netdev_alloc_skb_ip_align(ndev,
249 if (unlikely(!rx_buff->skb)) {
251 /* Because receive_skb is below, increment rx_dropped */
256 /* receive_skb only if new skb was allocated to avoid holes */
257 netif_receive_skb(skb);
259 addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
260 EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
261 if (dma_mapping_error(&ndev->dev, addr)) {
263 netdev_err(ndev, "cannot dma map\n");
264 dev_kfree_skb(rx_buff->skb);
268 dma_unmap_addr_set(rx_buff, addr, addr);
269 dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);
271 rxbd->data = cpu_to_le32(addr);
273 /* Make sure pointer to data buffer is set */
276 /* Return ownership to EMAC */
277 rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
284 * arc_emac_poll - NAPI poll handler.
285 * @napi: Pointer to napi_struct structure.
286 * @budget: How many BDs to process on 1 call.
288 * returns: Number of processed BDs
290 static int arc_emac_poll(struct napi_struct *napi, int budget)
292 struct net_device *ndev = napi->dev;
293 struct arc_emac_priv *priv = netdev_priv(ndev);
294 unsigned int work_done;
296 arc_emac_tx_clean(ndev);
298 work_done = arc_emac_rx(ndev, budget);
299 if (work_done < budget) {
301 arc_reg_or(priv, R_ENABLE, RXINT_MASK);
308 * arc_emac_intr - Global interrupt handler for EMAC.
310 * @dev_instance: device instance.
312 * returns: IRQ_HANDLED for all cases.
314 * ARC EMAC has only 1 interrupt line, and depending on bits raised in
315 * STATUS register we may tell what is a reason for interrupt to fire.
317 static irqreturn_t arc_emac_intr(int irq, void *dev_instance)
319 struct net_device *ndev = dev_instance;
320 struct arc_emac_priv *priv = netdev_priv(ndev);
321 struct net_device_stats *stats = &ndev->stats;
324 status = arc_reg_get(priv, R_STATUS);
325 status &= ~MDIO_MASK;
327 /* Reset all flags except "MDIO complete" */
328 arc_reg_set(priv, R_STATUS, status);
330 if (status & RXINT_MASK) {
331 if (likely(napi_schedule_prep(&priv->napi))) {
332 arc_reg_clr(priv, R_ENABLE, RXINT_MASK);
333 __napi_schedule(&priv->napi);
337 if (status & ERR_MASK) {
338 /* MSER/RXCR/RXFR/RXFL interrupt fires on corresponding
339 * 8-bit error counter overrun.
342 if (status & MSER_MASK) {
343 stats->rx_missed_errors += 0x100;
344 stats->rx_errors += 0x100;
347 if (status & RXCR_MASK) {
348 stats->rx_crc_errors += 0x100;
349 stats->rx_errors += 0x100;
352 if (status & RXFR_MASK) {
353 stats->rx_frame_errors += 0x100;
354 stats->rx_errors += 0x100;
357 if (status & RXFL_MASK) {
358 stats->rx_over_errors += 0x100;
359 stats->rx_errors += 0x100;
366 #ifdef CONFIG_NET_POLL_CONTROLLER
367 static void arc_emac_poll_controller(struct net_device *dev)
369 disable_irq(dev->irq);
370 arc_emac_intr(dev->irq, dev);
371 enable_irq(dev->irq);
376 * arc_emac_open - Open the network device.
377 * @ndev: Pointer to the network device.
379 * returns: 0, on success or non-zero error value on failure.
381 * This function sets the MAC address, requests and enables an IRQ
382 * for the EMAC device and starts the Tx queue.
383 * It also connects to the phy device.
385 static int arc_emac_open(struct net_device *ndev)
387 struct arc_emac_priv *priv = netdev_priv(ndev);
388 struct phy_device *phy_dev = priv->phy_dev;
391 phy_dev->autoneg = AUTONEG_ENABLE;
394 phy_dev->advertising &= phy_dev->supported;
396 priv->last_rx_bd = 0;
398 /* Allocate and set buffers for Rx BD's */
399 for (i = 0; i < RX_BD_NUM; i++) {
401 unsigned int *last_rx_bd = &priv->last_rx_bd;
402 struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd];
403 struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
405 rx_buff->skb = netdev_alloc_skb_ip_align(ndev,
407 if (unlikely(!rx_buff->skb))
410 addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
411 EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
412 if (dma_mapping_error(&ndev->dev, addr)) {
413 netdev_err(ndev, "cannot dma map\n");
414 dev_kfree_skb(rx_buff->skb);
417 dma_unmap_addr_set(rx_buff, addr, addr);
418 dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);
420 rxbd->data = cpu_to_le32(addr);
422 /* Make sure pointer to data buffer is set */
425 /* Return ownership to EMAC */
426 rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
428 *last_rx_bd = (*last_rx_bd + 1) % RX_BD_NUM;
432 memset(priv->txbd, 0, TX_RING_SZ);
434 /* Initialize logical address filter */
435 arc_reg_set(priv, R_LAFL, 0);
436 arc_reg_set(priv, R_LAFH, 0);
438 /* Set BD ring pointers for device side */
439 arc_reg_set(priv, R_RX_RING, (unsigned int)priv->rxbd_dma);
440 arc_reg_set(priv, R_TX_RING, (unsigned int)priv->txbd_dma);
442 /* Enable interrupts */
443 arc_reg_set(priv, R_ENABLE, RXINT_MASK | ERR_MASK);
446 arc_reg_set(priv, R_CTRL,
447 (RX_BD_NUM << 24) | /* RX BD table length */
448 (TX_BD_NUM << 16) | /* TX BD table length */
449 TXRN_MASK | RXRN_MASK);
451 napi_enable(&priv->napi);
454 arc_reg_or(priv, R_CTRL, EN_MASK);
456 phy_start_aneg(priv->phy_dev);
458 netif_start_queue(ndev);
464 * arc_emac_set_rx_mode - Change the receive filtering mode.
465 * @ndev: Pointer to the network device.
467 * This function enables/disables promiscuous or all-multicast mode
468 * and updates the multicast filtering list of the network device.
470 static void arc_emac_set_rx_mode(struct net_device *ndev)
472 struct arc_emac_priv *priv = netdev_priv(ndev);
474 if (ndev->flags & IFF_PROMISC) {
475 arc_reg_or(priv, R_CTRL, PROM_MASK);
477 arc_reg_clr(priv, R_CTRL, PROM_MASK);
479 if (ndev->flags & IFF_ALLMULTI) {
480 arc_reg_set(priv, R_LAFL, ~0);
481 arc_reg_set(priv, R_LAFH, ~0);
483 struct netdev_hw_addr *ha;
484 unsigned int filter[2] = { 0, 0 };
487 netdev_for_each_mc_addr(ha, ndev) {
488 bit = ether_crc_le(ETH_ALEN, ha->addr) >> 26;
489 filter[bit >> 5] |= 1 << (bit & 31);
492 arc_reg_set(priv, R_LAFL, filter[0]);
493 arc_reg_set(priv, R_LAFH, filter[1]);
499 * arc_emac_stop - Close the network device.
500 * @ndev: Pointer to the network device.
502 * This function stops the Tx queue, disables interrupts and frees the IRQ for
504 * It also disconnects the PHY device associated with the EMAC device.
506 static int arc_emac_stop(struct net_device *ndev)
508 struct arc_emac_priv *priv = netdev_priv(ndev);
510 napi_disable(&priv->napi);
511 netif_stop_queue(ndev);
513 /* Disable interrupts */
514 arc_reg_clr(priv, R_ENABLE, RXINT_MASK | ERR_MASK);
517 arc_reg_clr(priv, R_CTRL, EN_MASK);
523 * arc_emac_stats - Get system network statistics.
524 * @ndev: Pointer to net_device structure.
526 * Returns the address of the device statistics structure.
527 * Statistics are updated in interrupt handler.
529 static struct net_device_stats *arc_emac_stats(struct net_device *ndev)
531 struct arc_emac_priv *priv = netdev_priv(ndev);
532 struct net_device_stats *stats = &ndev->stats;
533 unsigned long miss, rxerr;
534 u8 rxcrc, rxfram, rxoflow;
536 rxerr = arc_reg_get(priv, R_RXERR);
537 miss = arc_reg_get(priv, R_MISS);
541 rxoflow = rxerr >> 16;
543 stats->rx_errors += miss;
544 stats->rx_errors += rxcrc + rxfram + rxoflow;
546 stats->rx_over_errors += rxoflow;
547 stats->rx_frame_errors += rxfram;
548 stats->rx_crc_errors += rxcrc;
549 stats->rx_missed_errors += miss;
555 * arc_emac_tx - Starts the data transmission.
556 * @skb: sk_buff pointer that contains data to be Transmitted.
557 * @ndev: Pointer to net_device structure.
559 * returns: NETDEV_TX_OK, on success
560 * NETDEV_TX_BUSY, if any of the descriptors are not free.
562 * This function is invoked from upper layers to initiate transmission.
564 static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
566 struct arc_emac_priv *priv = netdev_priv(ndev);
567 unsigned int len, *txbd_curr = &priv->txbd_curr;
568 struct net_device_stats *stats = &ndev->stats;
569 __le32 *info = &priv->txbd[*txbd_curr].info;
572 if (skb_padto(skb, ETH_ZLEN))
575 len = max_t(unsigned int, ETH_ZLEN, skb->len);
577 /* EMAC still holds this buffer in its possession.
578 * CPU must not modify this buffer descriptor
580 if (unlikely((le32_to_cpu(*info) & OWN_MASK) == FOR_EMAC)) {
581 netif_stop_queue(ndev);
582 return NETDEV_TX_BUSY;
585 addr = dma_map_single(&ndev->dev, (void *)skb->data, len,
588 if (unlikely(dma_mapping_error(&ndev->dev, addr))) {
594 dma_unmap_addr_set(&priv->tx_buff[*txbd_curr], addr, addr);
595 dma_unmap_len_set(&priv->tx_buff[*txbd_curr], len, len);
597 priv->tx_buff[*txbd_curr].skb = skb;
598 priv->txbd[*txbd_curr].data = cpu_to_le32(addr);
600 /* Make sure pointer to data buffer is set */
603 skb_tx_timestamp(skb);
605 *info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len);
607 /* Increment index to point to the next BD */
608 *txbd_curr = (*txbd_curr + 1) % TX_BD_NUM;
610 /* Get "info" of the next BD */
611 info = &priv->txbd[*txbd_curr].info;
613 /* Check if if Tx BD ring is full - next BD is still owned by EMAC */
614 if (unlikely((le32_to_cpu(*info) & OWN_MASK) == FOR_EMAC))
615 netif_stop_queue(ndev);
617 arc_reg_set(priv, R_STATUS, TXPL_MASK);
622 static void arc_emac_set_address_internal(struct net_device *ndev)
624 struct arc_emac_priv *priv = netdev_priv(ndev);
625 unsigned int addr_low, addr_hi;
627 addr_low = le32_to_cpu(*(__le32 *) &ndev->dev_addr[0]);
628 addr_hi = le16_to_cpu(*(__le16 *) &ndev->dev_addr[4]);
630 arc_reg_set(priv, R_ADDRL, addr_low);
631 arc_reg_set(priv, R_ADDRH, addr_hi);
635 * arc_emac_set_address - Set the MAC address for this device.
636 * @ndev: Pointer to net_device structure.
637 * @p: 6 byte Address to be written as MAC address.
639 * This function copies the HW address from the sockaddr structure to the
640 * net_device structure and updates the address in HW.
642 * returns: -EBUSY if the net device is busy or 0 if the address is set
645 static int arc_emac_set_address(struct net_device *ndev, void *p)
647 struct sockaddr *addr = p;
649 if (netif_running(ndev))
652 if (!is_valid_ether_addr(addr->sa_data))
653 return -EADDRNOTAVAIL;
655 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
657 arc_emac_set_address_internal(ndev);
662 static const struct net_device_ops arc_emac_netdev_ops = {
663 .ndo_open = arc_emac_open,
664 .ndo_stop = arc_emac_stop,
665 .ndo_start_xmit = arc_emac_tx,
666 .ndo_set_mac_address = arc_emac_set_address,
667 .ndo_get_stats = arc_emac_stats,
668 .ndo_set_rx_mode = arc_emac_set_rx_mode,
669 #ifdef CONFIG_NET_POLL_CONTROLLER
670 .ndo_poll_controller = arc_emac_poll_controller,
674 static int arc_emac_probe(struct platform_device *pdev)
676 struct resource res_regs;
677 struct device_node *phy_node;
678 struct arc_emac_priv *priv;
679 struct net_device *ndev;
680 const char *mac_addr;
681 unsigned int id, clock_frequency, irq;
684 if (!pdev->dev.of_node)
687 /* Get PHY from device tree */
688 phy_node = of_parse_phandle(pdev->dev.of_node, "phy", 0);
690 dev_err(&pdev->dev, "failed to retrieve phy description from device tree\n");
694 /* Get EMAC registers base address from device tree */
695 err = of_address_to_resource(pdev->dev.of_node, 0, &res_regs);
697 dev_err(&pdev->dev, "failed to retrieve registers base from device tree\n");
701 /* Get IRQ from device tree */
702 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
704 dev_err(&pdev->dev, "failed to retrieve <irq> value from device tree\n");
708 ndev = alloc_etherdev(sizeof(struct arc_emac_priv));
712 platform_set_drvdata(pdev, ndev);
713 SET_NETDEV_DEV(ndev, &pdev->dev);
715 ndev->netdev_ops = &arc_emac_netdev_ops;
716 ndev->ethtool_ops = &arc_emac_ethtool_ops;
717 ndev->watchdog_timeo = TX_TIMEOUT;
718 /* FIXME :: no multicast support yet */
719 ndev->flags &= ~IFF_MULTICAST;
721 priv = netdev_priv(ndev);
722 priv->dev = &pdev->dev;
725 priv->regs = devm_ioremap_resource(&pdev->dev, &res_regs);
726 if (IS_ERR(priv->regs)) {
727 err = PTR_ERR(priv->regs);
730 dev_dbg(&pdev->dev, "Registers base address is 0x%p\n", priv->regs);
732 priv->clk = of_clk_get(pdev->dev.of_node, 0);
733 if (IS_ERR(priv->clk)) {
734 /* Get CPU clock frequency from device tree */
735 if (of_property_read_u32(pdev->dev.of_node, "clock-frequency",
737 dev_err(&pdev->dev, "failed to retrieve <clock-frequency> from device tree\n");
742 err = clk_prepare_enable(priv->clk);
744 dev_err(&pdev->dev, "failed to enable clock\n");
748 clock_frequency = clk_get_rate(priv->clk);
751 id = arc_reg_get(priv, R_ID);
753 /* Check for EMAC revision 5 or 7, magic number */
754 if (!(id == 0x0005fd02 || id == 0x0007fd02)) {
755 dev_err(&pdev->dev, "ARC EMAC not detected, id=0x%x\n", id);
759 dev_info(&pdev->dev, "ARC EMAC detected with id: 0x%x\n", id);
761 /* Set poll rate so that it polls every 1 ms */
762 arc_reg_set(priv, R_POLLRATE, clock_frequency / 1000000);
765 dev_info(&pdev->dev, "IRQ is %d\n", ndev->irq);
767 /* Register interrupt handler for device */
768 err = devm_request_irq(&pdev->dev, ndev->irq, arc_emac_intr, 0,
771 dev_err(&pdev->dev, "could not allocate IRQ\n");
775 /* Get MAC address from device tree */
776 mac_addr = of_get_mac_address(pdev->dev.of_node);
779 memcpy(ndev->dev_addr, mac_addr, ETH_ALEN);
781 eth_hw_addr_random(ndev);
783 arc_emac_set_address_internal(ndev);
784 dev_info(&pdev->dev, "MAC address is now %pM\n", ndev->dev_addr);
786 /* Do 1 allocation instead of 2 separate ones for Rx and Tx BD rings */
787 priv->rxbd = dmam_alloc_coherent(&pdev->dev, RX_RING_SZ + TX_RING_SZ,
788 &priv->rxbd_dma, GFP_KERNEL);
791 dev_err(&pdev->dev, "failed to allocate data buffers\n");
796 priv->txbd = priv->rxbd + RX_BD_NUM;
798 priv->txbd_dma = priv->rxbd_dma + RX_RING_SZ;
799 dev_dbg(&pdev->dev, "EMAC Device addr: Rx Ring [0x%x], Tx Ring[%x]\n",
800 (unsigned int)priv->rxbd_dma, (unsigned int)priv->txbd_dma);
802 err = arc_mdio_probe(pdev, priv);
804 dev_err(&pdev->dev, "failed to probe MII bus\n");
808 priv->phy_dev = of_phy_connect(ndev, phy_node, arc_emac_adjust_link, 0,
809 PHY_INTERFACE_MODE_MII);
810 if (!priv->phy_dev) {
811 dev_err(&pdev->dev, "of_phy_connect() failed\n");
816 dev_info(&pdev->dev, "connected to %s phy with id 0x%x\n",
817 priv->phy_dev->drv->name, priv->phy_dev->phy_id);
819 netif_napi_add(ndev, &priv->napi, arc_emac_poll, ARC_EMAC_NAPI_WEIGHT);
821 err = register_netdev(ndev);
823 dev_err(&pdev->dev, "failed to register network device\n");
830 netif_napi_del(&priv->napi);
831 phy_disconnect(priv->phy_dev);
832 priv->phy_dev = NULL;
834 arc_mdio_remove(priv);
836 if (!IS_ERR(priv->clk))
837 clk_disable_unprepare(priv->clk);
839 if (!IS_ERR(priv->clk))
846 static int arc_emac_remove(struct platform_device *pdev)
848 struct net_device *ndev = platform_get_drvdata(pdev);
849 struct arc_emac_priv *priv = netdev_priv(ndev);
851 phy_disconnect(priv->phy_dev);
852 priv->phy_dev = NULL;
853 arc_mdio_remove(priv);
854 unregister_netdev(ndev);
855 netif_napi_del(&priv->napi);
857 if (!IS_ERR(priv->clk)) {
858 clk_disable_unprepare(priv->clk);
867 static const struct of_device_id arc_emac_dt_ids[] = {
868 { .compatible = "snps,arc-emac" },
871 MODULE_DEVICE_TABLE(of, arc_emac_dt_ids);
873 static struct platform_driver arc_emac_driver = {
874 .probe = arc_emac_probe,
875 .remove = arc_emac_remove,
878 .owner = THIS_MODULE,
879 .of_match_table = arc_emac_dt_ids,
883 module_platform_driver(arc_emac_driver);
885 MODULE_AUTHOR("Alexey Brodkin <abrodkin@synopsys.com>");
886 MODULE_DESCRIPTION("ARC EMAC driver");
887 MODULE_LICENSE("GPL");