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>
31 * arc_emac_adjust_link - Adjust the PHY link duplex.
32 * @ndev: Pointer to the net_device structure.
34 * This function is called to change the duplex setting after auto negotiation
37 static void arc_emac_adjust_link(struct net_device *ndev)
39 struct arc_emac_priv *priv = netdev_priv(ndev);
40 struct phy_device *phy_dev = priv->phy_dev;
41 unsigned int reg, state_changed = 0;
43 if (priv->link != phy_dev->link) {
44 priv->link = phy_dev->link;
48 if (priv->speed != phy_dev->speed) {
49 priv->speed = phy_dev->speed;
51 if (priv->set_mac_speed)
52 priv->set_mac_speed(priv, priv->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 struct arc_emac_priv *priv = netdev_priv(ndev);
125 strlcpy(info->driver, priv->drv_name, sizeof(info->driver));
126 strlcpy(info->version, priv->drv_version, sizeof(info->version));
129 static const struct ethtool_ops arc_emac_ethtool_ops = {
130 .get_settings = arc_emac_get_settings,
131 .set_settings = arc_emac_set_settings,
132 .get_drvinfo = arc_emac_get_drvinfo,
133 .get_link = ethtool_op_get_link,
136 #define FIRST_OR_LAST_MASK (FIRST_MASK | LAST_MASK)
139 * arc_emac_tx_clean - clears processed by EMAC Tx BDs.
140 * @ndev: Pointer to the network device.
142 static void arc_emac_tx_clean(struct net_device *ndev)
144 struct arc_emac_priv *priv = netdev_priv(ndev);
145 struct net_device_stats *stats = &ndev->stats;
148 for (i = 0; i < TX_BD_NUM; i++) {
149 unsigned int *txbd_dirty = &priv->txbd_dirty;
150 struct arc_emac_bd *txbd = &priv->txbd[*txbd_dirty];
151 struct buffer_state *tx_buff = &priv->tx_buff[*txbd_dirty];
152 struct sk_buff *skb = tx_buff->skb;
153 unsigned int info = le32_to_cpu(txbd->info);
155 if ((info & FOR_EMAC) || !txbd->data)
158 if (unlikely(info & (DROP | DEFR | LTCL | UFLO))) {
163 stats->tx_carrier_errors++;
169 stats->tx_fifo_errors++;
170 } else if (likely(info & FIRST_OR_LAST_MASK)) {
172 stats->tx_bytes += skb->len;
175 dma_unmap_single(&ndev->dev, dma_unmap_addr(tx_buff, addr),
176 dma_unmap_len(tx_buff, len), DMA_TO_DEVICE);
178 /* return the sk_buff to system */
179 dev_kfree_skb_irq(skb);
184 *txbd_dirty = (*txbd_dirty + 1) % TX_BD_NUM;
186 if (netif_queue_stopped(ndev))
187 netif_wake_queue(ndev);
192 * arc_emac_rx - processing of Rx packets.
193 * @ndev: Pointer to the network device.
194 * @budget: How many BDs to process on 1 call.
196 * returns: Number of processed BDs
198 * Iterate through Rx BDs and deliver received packages to upper layer.
200 static int arc_emac_rx(struct net_device *ndev, int budget)
202 struct arc_emac_priv *priv = netdev_priv(ndev);
203 unsigned int work_done;
205 for (work_done = 0; work_done < budget; work_done++) {
206 unsigned int *last_rx_bd = &priv->last_rx_bd;
207 struct net_device_stats *stats = &ndev->stats;
208 struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
209 struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd];
210 unsigned int pktlen, info = le32_to_cpu(rxbd->info);
214 if (unlikely((info & OWN_MASK) == FOR_EMAC))
217 /* Make a note that we saw a packet at this BD.
218 * So next time, driver starts from this + 1
220 *last_rx_bd = (*last_rx_bd + 1) % RX_BD_NUM;
222 if (unlikely((info & FIRST_OR_LAST_MASK) !=
223 FIRST_OR_LAST_MASK)) {
224 /* We pre-allocate buffers of MTU size so incoming
225 * packets won't be split/chained.
228 netdev_err(ndev, "incomplete packet received\n");
230 /* Return ownership to EMAC */
231 rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
233 stats->rx_length_errors++;
237 pktlen = info & LEN_MASK;
239 stats->rx_bytes += pktlen;
241 skb_put(skb, pktlen);
243 skb->protocol = eth_type_trans(skb, ndev);
245 dma_unmap_single(&ndev->dev, dma_unmap_addr(rx_buff, addr),
246 dma_unmap_len(rx_buff, len), DMA_FROM_DEVICE);
248 /* Prepare the BD for next cycle */
249 rx_buff->skb = netdev_alloc_skb_ip_align(ndev,
251 if (unlikely(!rx_buff->skb)) {
253 /* Because receive_skb is below, increment rx_dropped */
258 /* receive_skb only if new skb was allocated to avoid holes */
259 netif_receive_skb(skb);
261 addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
262 EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
263 if (dma_mapping_error(&ndev->dev, addr)) {
265 netdev_err(ndev, "cannot dma map\n");
266 dev_kfree_skb(rx_buff->skb);
270 dma_unmap_addr_set(rx_buff, addr, addr);
271 dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);
273 rxbd->data = cpu_to_le32(addr);
275 /* Make sure pointer to data buffer is set */
278 /* Return ownership to EMAC */
279 rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
286 * arc_emac_poll - NAPI poll handler.
287 * @napi: Pointer to napi_struct structure.
288 * @budget: How many BDs to process on 1 call.
290 * returns: Number of processed BDs
292 static int arc_emac_poll(struct napi_struct *napi, int budget)
294 struct net_device *ndev = napi->dev;
295 struct arc_emac_priv *priv = netdev_priv(ndev);
296 unsigned int work_done;
298 arc_emac_tx_clean(ndev);
300 work_done = arc_emac_rx(ndev, budget);
301 if (work_done < budget) {
303 arc_reg_or(priv, R_ENABLE, RXINT_MASK);
310 * arc_emac_intr - Global interrupt handler for EMAC.
312 * @dev_instance: device instance.
314 * returns: IRQ_HANDLED for all cases.
316 * ARC EMAC has only 1 interrupt line, and depending on bits raised in
317 * STATUS register we may tell what is a reason for interrupt to fire.
319 static irqreturn_t arc_emac_intr(int irq, void *dev_instance)
321 struct net_device *ndev = dev_instance;
322 struct arc_emac_priv *priv = netdev_priv(ndev);
323 struct net_device_stats *stats = &ndev->stats;
326 status = arc_reg_get(priv, R_STATUS);
327 status &= ~MDIO_MASK;
329 /* Reset all flags except "MDIO complete" */
330 arc_reg_set(priv, R_STATUS, status);
332 if (status & RXINT_MASK) {
333 if (likely(napi_schedule_prep(&priv->napi))) {
334 arc_reg_clr(priv, R_ENABLE, RXINT_MASK);
335 __napi_schedule(&priv->napi);
339 if (status & ERR_MASK) {
340 /* MSER/RXCR/RXFR/RXFL interrupt fires on corresponding
341 * 8-bit error counter overrun.
344 if (status & MSER_MASK) {
345 stats->rx_missed_errors += 0x100;
346 stats->rx_errors += 0x100;
349 if (status & RXCR_MASK) {
350 stats->rx_crc_errors += 0x100;
351 stats->rx_errors += 0x100;
354 if (status & RXFR_MASK) {
355 stats->rx_frame_errors += 0x100;
356 stats->rx_errors += 0x100;
359 if (status & RXFL_MASK) {
360 stats->rx_over_errors += 0x100;
361 stats->rx_errors += 0x100;
368 #ifdef CONFIG_NET_POLL_CONTROLLER
369 static void arc_emac_poll_controller(struct net_device *dev)
371 disable_irq(dev->irq);
372 arc_emac_intr(dev->irq, dev);
373 enable_irq(dev->irq);
378 * arc_emac_open - Open the network device.
379 * @ndev: Pointer to the network device.
381 * returns: 0, on success or non-zero error value on failure.
383 * This function sets the MAC address, requests and enables an IRQ
384 * for the EMAC device and starts the Tx queue.
385 * It also connects to the phy device.
387 static int arc_emac_open(struct net_device *ndev)
389 struct arc_emac_priv *priv = netdev_priv(ndev);
390 struct phy_device *phy_dev = priv->phy_dev;
393 phy_dev->autoneg = AUTONEG_ENABLE;
396 phy_dev->advertising &= phy_dev->supported;
398 priv->last_rx_bd = 0;
400 /* Allocate and set buffers for Rx BD's */
401 for (i = 0; i < RX_BD_NUM; i++) {
403 unsigned int *last_rx_bd = &priv->last_rx_bd;
404 struct arc_emac_bd *rxbd = &priv->rxbd[*last_rx_bd];
405 struct buffer_state *rx_buff = &priv->rx_buff[*last_rx_bd];
407 rx_buff->skb = netdev_alloc_skb_ip_align(ndev,
409 if (unlikely(!rx_buff->skb))
412 addr = dma_map_single(&ndev->dev, (void *)rx_buff->skb->data,
413 EMAC_BUFFER_SIZE, DMA_FROM_DEVICE);
414 if (dma_mapping_error(&ndev->dev, addr)) {
415 netdev_err(ndev, "cannot dma map\n");
416 dev_kfree_skb(rx_buff->skb);
419 dma_unmap_addr_set(rx_buff, addr, addr);
420 dma_unmap_len_set(rx_buff, len, EMAC_BUFFER_SIZE);
422 rxbd->data = cpu_to_le32(addr);
424 /* Make sure pointer to data buffer is set */
427 /* Return ownership to EMAC */
428 rxbd->info = cpu_to_le32(FOR_EMAC | EMAC_BUFFER_SIZE);
430 *last_rx_bd = (*last_rx_bd + 1) % RX_BD_NUM;
434 memset(priv->txbd, 0, TX_RING_SZ);
436 /* Initialize logical address filter */
437 arc_reg_set(priv, R_LAFL, 0);
438 arc_reg_set(priv, R_LAFH, 0);
440 /* Set BD ring pointers for device side */
441 arc_reg_set(priv, R_RX_RING, (unsigned int)priv->rxbd_dma);
442 arc_reg_set(priv, R_TX_RING, (unsigned int)priv->txbd_dma);
444 /* Enable interrupts */
445 arc_reg_set(priv, R_ENABLE, RXINT_MASK | ERR_MASK);
448 arc_reg_set(priv, R_CTRL,
449 (RX_BD_NUM << 24) | /* RX BD table length */
450 (TX_BD_NUM << 16) | /* TX BD table length */
451 TXRN_MASK | RXRN_MASK);
453 napi_enable(&priv->napi);
456 arc_reg_or(priv, R_CTRL, EN_MASK);
458 phy_start_aneg(priv->phy_dev);
460 netif_start_queue(ndev);
466 * arc_emac_set_rx_mode - Change the receive filtering mode.
467 * @ndev: Pointer to the network device.
469 * This function enables/disables promiscuous or all-multicast mode
470 * and updates the multicast filtering list of the network device.
472 static void arc_emac_set_rx_mode(struct net_device *ndev)
474 struct arc_emac_priv *priv = netdev_priv(ndev);
476 if (ndev->flags & IFF_PROMISC) {
477 arc_reg_or(priv, R_CTRL, PROM_MASK);
479 arc_reg_clr(priv, R_CTRL, PROM_MASK);
481 if (ndev->flags & IFF_ALLMULTI) {
482 arc_reg_set(priv, R_LAFL, ~0);
483 arc_reg_set(priv, R_LAFH, ~0);
485 struct netdev_hw_addr *ha;
486 unsigned int filter[2] = { 0, 0 };
489 netdev_for_each_mc_addr(ha, ndev) {
490 bit = ether_crc_le(ETH_ALEN, ha->addr) >> 26;
491 filter[bit >> 5] |= 1 << (bit & 31);
494 arc_reg_set(priv, R_LAFL, filter[0]);
495 arc_reg_set(priv, R_LAFH, filter[1]);
501 * arc_emac_stop - Close the network device.
502 * @ndev: Pointer to the network device.
504 * This function stops the Tx queue, disables interrupts and frees the IRQ for
506 * It also disconnects the PHY device associated with the EMAC device.
508 static int arc_emac_stop(struct net_device *ndev)
510 struct arc_emac_priv *priv = netdev_priv(ndev);
512 napi_disable(&priv->napi);
513 netif_stop_queue(ndev);
515 /* Disable interrupts */
516 arc_reg_clr(priv, R_ENABLE, RXINT_MASK | ERR_MASK);
519 arc_reg_clr(priv, R_CTRL, EN_MASK);
525 * arc_emac_stats - Get system network statistics.
526 * @ndev: Pointer to net_device structure.
528 * Returns the address of the device statistics structure.
529 * Statistics are updated in interrupt handler.
531 static struct net_device_stats *arc_emac_stats(struct net_device *ndev)
533 struct arc_emac_priv *priv = netdev_priv(ndev);
534 struct net_device_stats *stats = &ndev->stats;
535 unsigned long miss, rxerr;
536 u8 rxcrc, rxfram, rxoflow;
538 rxerr = arc_reg_get(priv, R_RXERR);
539 miss = arc_reg_get(priv, R_MISS);
543 rxoflow = rxerr >> 16;
545 stats->rx_errors += miss;
546 stats->rx_errors += rxcrc + rxfram + rxoflow;
548 stats->rx_over_errors += rxoflow;
549 stats->rx_frame_errors += rxfram;
550 stats->rx_crc_errors += rxcrc;
551 stats->rx_missed_errors += miss;
557 * arc_emac_tx - Starts the data transmission.
558 * @skb: sk_buff pointer that contains data to be Transmitted.
559 * @ndev: Pointer to net_device structure.
561 * returns: NETDEV_TX_OK, on success
562 * NETDEV_TX_BUSY, if any of the descriptors are not free.
564 * This function is invoked from upper layers to initiate transmission.
566 static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
568 struct arc_emac_priv *priv = netdev_priv(ndev);
569 unsigned int len, *txbd_curr = &priv->txbd_curr;
570 struct net_device_stats *stats = &ndev->stats;
571 __le32 *info = &priv->txbd[*txbd_curr].info;
574 if (skb_padto(skb, ETH_ZLEN))
577 len = max_t(unsigned int, ETH_ZLEN, skb->len);
579 /* EMAC still holds this buffer in its possession.
580 * CPU must not modify this buffer descriptor
582 if (unlikely((le32_to_cpu(*info) & OWN_MASK) == FOR_EMAC)) {
583 netif_stop_queue(ndev);
584 return NETDEV_TX_BUSY;
587 addr = dma_map_single(&ndev->dev, (void *)skb->data, len,
590 if (unlikely(dma_mapping_error(&ndev->dev, addr))) {
596 dma_unmap_addr_set(&priv->tx_buff[*txbd_curr], addr, addr);
597 dma_unmap_len_set(&priv->tx_buff[*txbd_curr], len, len);
599 priv->tx_buff[*txbd_curr].skb = skb;
600 priv->txbd[*txbd_curr].data = cpu_to_le32(addr);
602 /* Make sure pointer to data buffer is set */
605 skb_tx_timestamp(skb);
607 *info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len);
609 /* Increment index to point to the next BD */
610 *txbd_curr = (*txbd_curr + 1) % TX_BD_NUM;
612 /* Get "info" of the next BD */
613 info = &priv->txbd[*txbd_curr].info;
615 /* Check if if Tx BD ring is full - next BD is still owned by EMAC */
616 if (unlikely((le32_to_cpu(*info) & OWN_MASK) == FOR_EMAC))
617 netif_stop_queue(ndev);
619 arc_reg_set(priv, R_STATUS, TXPL_MASK);
624 static void arc_emac_set_address_internal(struct net_device *ndev)
626 struct arc_emac_priv *priv = netdev_priv(ndev);
627 unsigned int addr_low, addr_hi;
629 addr_low = le32_to_cpu(*(__le32 *) &ndev->dev_addr[0]);
630 addr_hi = le16_to_cpu(*(__le16 *) &ndev->dev_addr[4]);
632 arc_reg_set(priv, R_ADDRL, addr_low);
633 arc_reg_set(priv, R_ADDRH, addr_hi);
637 * arc_emac_set_address - Set the MAC address for this device.
638 * @ndev: Pointer to net_device structure.
639 * @p: 6 byte Address to be written as MAC address.
641 * This function copies the HW address from the sockaddr structure to the
642 * net_device structure and updates the address in HW.
644 * returns: -EBUSY if the net device is busy or 0 if the address is set
647 static int arc_emac_set_address(struct net_device *ndev, void *p)
649 struct sockaddr *addr = p;
651 if (netif_running(ndev))
654 if (!is_valid_ether_addr(addr->sa_data))
655 return -EADDRNOTAVAIL;
657 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
659 arc_emac_set_address_internal(ndev);
664 static const struct net_device_ops arc_emac_netdev_ops = {
665 .ndo_open = arc_emac_open,
666 .ndo_stop = arc_emac_stop,
667 .ndo_start_xmit = arc_emac_tx,
668 .ndo_set_mac_address = arc_emac_set_address,
669 .ndo_get_stats = arc_emac_stats,
670 .ndo_set_rx_mode = arc_emac_set_rx_mode,
671 #ifdef CONFIG_NET_POLL_CONTROLLER
672 .ndo_poll_controller = arc_emac_poll_controller,
676 int arc_emac_probe(struct net_device *ndev, int interface)
678 struct device *dev = ndev->dev.parent;
679 struct resource res_regs;
680 struct device_node *phy_node;
681 struct arc_emac_priv *priv;
682 const char *mac_addr;
683 unsigned int id, clock_frequency, irq;
687 /* Get PHY from device tree */
688 phy_node = of_parse_phandle(dev->of_node, "phy", 0);
690 dev_err(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(dev->of_node, 0, &res_regs);
697 dev_err(dev, "failed to retrieve registers base from device tree\n");
701 /* Get IRQ from device tree */
702 irq = irq_of_parse_and_map(dev->of_node, 0);
704 dev_err(dev, "failed to retrieve <irq> value from device tree\n");
709 ndev->netdev_ops = &arc_emac_netdev_ops;
710 ndev->ethtool_ops = &arc_emac_ethtool_ops;
711 ndev->watchdog_timeo = TX_TIMEOUT;
712 /* FIXME :: no multicast support yet */
713 ndev->flags &= ~IFF_MULTICAST;
715 priv = netdev_priv(ndev);
718 priv->regs = devm_ioremap_resource(dev, &res_regs);
719 if (IS_ERR(priv->regs)) {
720 return PTR_ERR(priv->regs);
722 dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs);
725 err = clk_prepare_enable(priv->clk);
727 dev_err(dev, "failed to enable clock\n");
731 clock_frequency = clk_get_rate(priv->clk);
733 /* Get CPU clock frequency from device tree */
734 if (of_property_read_u32(dev->of_node, "clock-frequency",
736 dev_err(dev, "failed to retrieve <clock-frequency> from device tree\n");
741 id = arc_reg_get(priv, R_ID);
743 /* Check for EMAC revision 5 or 7, magic number */
744 if (!(id == 0x0005fd02 || id == 0x0007fd02)) {
745 dev_err(dev, "ARC EMAC not detected, id=0x%x\n", id);
749 dev_info(dev, "ARC EMAC detected with id: 0x%x\n", id);
751 /* Set poll rate so that it polls every 1 ms */
752 arc_reg_set(priv, R_POLLRATE, clock_frequency / 1000000);
755 dev_info(dev, "IRQ is %d\n", ndev->irq);
757 /* Register interrupt handler for device */
758 err = devm_request_irq(dev, ndev->irq, arc_emac_intr, 0,
761 dev_err(dev, "could not allocate IRQ\n");
765 /* Get MAC address from device tree */
766 mac_addr = of_get_mac_address(dev->of_node);
769 memcpy(ndev->dev_addr, mac_addr, ETH_ALEN);
771 eth_hw_addr_random(ndev);
773 arc_emac_set_address_internal(ndev);
774 dev_info(dev, "MAC address is now %pM\n", ndev->dev_addr);
776 /* Do 1 allocation instead of 2 separate ones for Rx and Tx BD rings */
777 priv->rxbd = dmam_alloc_coherent(dev, RX_RING_SZ + TX_RING_SZ,
778 &priv->rxbd_dma, GFP_KERNEL);
781 dev_err(dev, "failed to allocate data buffers\n");
786 priv->txbd = priv->rxbd + RX_BD_NUM;
788 priv->txbd_dma = priv->rxbd_dma + RX_RING_SZ;
789 dev_dbg(dev, "EMAC Device addr: Rx Ring [0x%x], Tx Ring[%x]\n",
790 (unsigned int)priv->rxbd_dma, (unsigned int)priv->txbd_dma);
792 err = arc_mdio_probe(priv);
794 dev_err(dev, "failed to probe MII bus\n");
798 priv->phy_dev = of_phy_connect(ndev, phy_node, arc_emac_adjust_link, 0,
800 if (!priv->phy_dev) {
801 dev_err(dev, "of_phy_connect() failed\n");
806 dev_info(dev, "connected to %s phy with id 0x%x\n",
807 priv->phy_dev->drv->name, priv->phy_dev->phy_id);
809 netif_napi_add(ndev, &priv->napi, arc_emac_poll, ARC_EMAC_NAPI_WEIGHT);
811 err = register_netdev(ndev);
813 dev_err(dev, "failed to register network device\n");
820 netif_napi_del(&priv->napi);
821 phy_disconnect(priv->phy_dev);
822 priv->phy_dev = NULL;
824 arc_mdio_remove(priv);
827 clk_disable_unprepare(priv->clk);
830 EXPORT_SYMBOL_GPL(arc_emac_probe);
832 int arc_emac_remove(struct net_device *ndev)
834 struct arc_emac_priv *priv = netdev_priv(ndev);
836 phy_disconnect(priv->phy_dev);
837 priv->phy_dev = NULL;
838 arc_mdio_remove(priv);
839 unregister_netdev(ndev);
840 netif_napi_del(&priv->napi);
842 if (!IS_ERR(priv->clk)) {
843 clk_disable_unprepare(priv->clk);
849 EXPORT_SYMBOL_GPL(arc_emac_remove);
851 MODULE_AUTHOR("Alexey Brodkin <abrodkin@synopsys.com>");
852 MODULE_DESCRIPTION("ARC EMAC driver");
853 MODULE_LICENSE("GPL");