Lines Matching +full:tx +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Xilinx EmacLite Linux driver for the Xilinx Ethernet MAC Lite device.
7 * Copyright (c) 2007 - 2013 Xilinx, Inc.
36 #define XEL_TSR_OFFSET 0x07FC /* Tx status */
37 #define XEL_TPLR_OFFSET 0x07F4 /* Tx packet length */
43 #define XEL_BUFFER_OFFSET 0x0800 /* Next Tx/Rx buffer's offset */
65 #define XEL_TSR_XMIT_BUSY_MASK 0x00000001 /* Tx complete */
67 #define XEL_TSR_XMIT_IE_MASK 0x00000008 /* Tx interrupt enable bit */
81 #define XEL_TPLR_LENGTH_MASK 0x0000FFFF /* Tx packet length */
93 #define TX_TIMEOUT (60 * HZ) /* Tx timeout is 60 seconds. */
104 * struct net_local - Our private per device data
105 * @ndev: instance of the network device
106 * @tx_ping_pong: indicates whether Tx Pong buffer is configured in HW
108 * @next_tx_buf_to_use: next Tx buffer to write to
110 * @base_addr: base address of the Emaclite device
113 * Tx buffer is not free
114 * @phy_dev: pointer to the PHY device
115 * @phy_node: pointer to the PHY device node
144 * xemaclite_enable_interrupts - Enable the interrupts for the EmacLite device
145 * @drvdata: Pointer to the Emaclite device private data
147 * This function enables the Tx and Rx interrupts for the Emaclite device along
154 /* Enable the Tx interrupts for the first Buffer */ in xemaclite_enable_interrupts()
155 reg_data = xemaclite_readl(drvdata->base_addr + XEL_TSR_OFFSET); in xemaclite_enable_interrupts()
157 drvdata->base_addr + XEL_TSR_OFFSET); in xemaclite_enable_interrupts()
160 xemaclite_writel(XEL_RSR_RECV_IE_MASK, drvdata->base_addr + XEL_RSR_OFFSET); in xemaclite_enable_interrupts()
163 xemaclite_writel(XEL_GIER_GIE_MASK, drvdata->base_addr + XEL_GIER_OFFSET); in xemaclite_enable_interrupts()
167 * xemaclite_disable_interrupts - Disable the interrupts for the EmacLite device
168 * @drvdata: Pointer to the Emaclite device private data
170 * This function disables the Tx and Rx interrupts for the Emaclite device,
178 xemaclite_writel(XEL_GIER_GIE_MASK, drvdata->base_addr + XEL_GIER_OFFSET); in xemaclite_disable_interrupts()
180 /* Disable the Tx interrupts for the first buffer */ in xemaclite_disable_interrupts()
181 reg_data = xemaclite_readl(drvdata->base_addr + XEL_TSR_OFFSET); in xemaclite_disable_interrupts()
183 drvdata->base_addr + XEL_TSR_OFFSET); in xemaclite_disable_interrupts()
186 reg_data = xemaclite_readl(drvdata->base_addr + XEL_RSR_OFFSET); in xemaclite_disable_interrupts()
188 drvdata->base_addr + XEL_RSR_OFFSET); in xemaclite_disable_interrupts()
192 * xemaclite_aligned_write - Write from 16-bit aligned to 32-bit aligned address
193 * @src_ptr: Void pointer to the 16-bit aligned source address
194 * @dest_ptr: Pointer to the 32-bit aligned destination address
197 * This function writes data from a 16-bit aligned buffer to a 32-bit aligned
198 * address in the EmacLite device.
212 for (; length > 3; length -= 4) { in xemaclite_aligned_write()
236 for (; length > 0; length--) in xemaclite_aligned_write()
250 * xemaclite_aligned_read - Read from 32-bit aligned to 16-bit aligned buffer
251 * @src_ptr: Pointer to the 32-bit aligned source address
252 * @dest_ptr: Pointer to the 16-bit aligned destination address
255 * This function reads data from a 32-bit aligned address in the EmacLite device
256 * to a 16-bit aligned buffer.
268 for (; length > 3; length -= 4) { in xemaclite_aligned_read()
287 for (; length > 0; length--) in xemaclite_aligned_read()
293 * xemaclite_send_data - Send an Ethernet frame
294 * @drvdata: Pointer to the Emaclite device private data
298 * This function checks if the Tx buffer of the Emaclite device is free to send
299 * data. If so, it fills the Tx buffer with data for transmission. Otherwise, it
302 * Return: 0 upon success or -1 if the buffer(s) are full.
304 * Note: The maximum Tx packet size can not be more than Ethernet header
313 /* Determine the expected Tx buffer address */ in xemaclite_send_data()
314 addr = drvdata->base_addr + drvdata->next_tx_buf_to_use; in xemaclite_send_data()
325 if (drvdata->tx_ping_pong != 0) in xemaclite_send_data()
326 drvdata->next_tx_buf_to_use ^= XEL_BUFFER_OFFSET; in xemaclite_send_data()
327 } else if (drvdata->tx_ping_pong != 0) { in xemaclite_send_data()
338 return -1; /* Buffers were full, return failure */ in xemaclite_send_data()
340 return -1; /* Buffer was full, return failure */ in xemaclite_send_data()
349 /* Update the Tx Status Register to indicate that there is a in xemaclite_send_data()
362 * xemaclite_recv_data - Receive a frame
363 * @drvdata: Pointer to the Emaclite device private data
379 addr = (drvdata->base_addr + drvdata->next_rx_buf_to_use); in xemaclite_recv_data()
385 if (drvdata->rx_ping_pong != 0) in xemaclite_recv_data()
386 drvdata->next_rx_buf_to_use ^= XEL_BUFFER_OFFSET; in xemaclite_recv_data()
393 if (drvdata->rx_ping_pong != 0) in xemaclite_recv_data()
442 /* Read from the EmacLite device */ in xemaclite_recv_data()
455 * xemaclite_update_address - Update the MAC address in the device
456 * @drvdata: Pointer to the Emaclite device private data
457 * @address_ptr:Pointer to the MAC address (MAC address is a 48-bit value)
459 * Tx must be idle and Rx should be idle for deterministic results.
461 * initialization and before transmission of any packets from the device.
471 /* Determine the expected Tx buffer address */ in xemaclite_update_address()
472 addr = drvdata->base_addr + drvdata->next_tx_buf_to_use; in xemaclite_update_address()
489 * xemaclite_set_mac_address - Set the MAC address for this device
490 * @dev: Pointer to the network device instance
496 * Return: Error if the net device is busy or 0 if the addr is set
505 return -EBUSY; in xemaclite_set_mac_address()
507 eth_hw_addr_set(dev, addr->sa_data); in xemaclite_set_mac_address()
508 xemaclite_update_address(lp, dev->dev_addr); in xemaclite_set_mac_address()
513 * xemaclite_tx_timeout - Callback for Tx Timeout
514 * @dev: Pointer to the network device
517 * This function is called when Tx time out occurs for Emaclite device.
524 dev_err(&lp->ndev->dev, "Exceeded transmit timeout of %lu ms\n", in xemaclite_tx_timeout()
527 dev->stats.tx_errors++; in xemaclite_tx_timeout()
529 /* Reset the device */ in xemaclite_tx_timeout()
530 spin_lock_irqsave(&lp->reset_lock, flags); in xemaclite_tx_timeout()
538 if (lp->deferred_skb) { in xemaclite_tx_timeout()
539 dev_kfree_skb_irq(lp->deferred_skb); in xemaclite_tx_timeout()
540 lp->deferred_skb = NULL; in xemaclite_tx_timeout()
541 dev->stats.tx_errors++; in xemaclite_tx_timeout()
544 /* To exclude tx timeout */ in xemaclite_tx_timeout()
545 netif_trans_update(dev); /* prevent tx timeout */ in xemaclite_tx_timeout()
549 spin_unlock_irqrestore(&lp->reset_lock, flags); in xemaclite_tx_timeout()
557 * xemaclite_tx_handler - Interrupt handler for frames sent
558 * @dev: Pointer to the network device
567 dev->stats.tx_packets++; in xemaclite_tx_handler()
569 if (!lp->deferred_skb) in xemaclite_tx_handler()
572 if (xemaclite_send_data(lp, (u8 *)lp->deferred_skb->data, in xemaclite_tx_handler()
573 lp->deferred_skb->len)) in xemaclite_tx_handler()
576 dev->stats.tx_bytes += lp->deferred_skb->len; in xemaclite_tx_handler()
577 dev_consume_skb_irq(lp->deferred_skb); in xemaclite_tx_handler()
578 lp->deferred_skb = NULL; in xemaclite_tx_handler()
579 netif_trans_update(dev); /* prevent tx timeout */ in xemaclite_tx_handler()
584 * xemaclite_rx_handler- Interrupt handler for frames received
585 * @dev: Pointer to the network device
600 dev->stats.rx_dropped++; in xemaclite_rx_handler()
601 dev_err(&lp->ndev->dev, "Could not allocate receive buffer\n"); in xemaclite_rx_handler()
607 len = xemaclite_recv_data(lp, (u8 *)skb->data, len); in xemaclite_rx_handler()
610 dev->stats.rx_errors++; in xemaclite_rx_handler()
617 skb->protocol = eth_type_trans(skb, dev); in xemaclite_rx_handler()
620 dev->stats.rx_packets++; in xemaclite_rx_handler()
621 dev->stats.rx_bytes += len; in xemaclite_rx_handler()
628 * xemaclite_interrupt - Interrupt handler for this driver
629 * @irq: Irq of the Emaclite device
630 * @dev_id: Void pointer to the network device instance used as callback
635 * This function handles the Tx and Rx interrupts of the EmacLite device.
642 void __iomem *base_addr = lp->base_addr; in xemaclite_interrupt()
674 /* If there was a Tx interrupt, call the Tx Handler */ in xemaclite_interrupt()
686 * xemaclite_mdio_wait - Wait for the MDIO to be ready to use
687 * @lp: Pointer to the Emaclite device private data
689 * This function waits till the device is ready to accept a new MDIO
703 lp->base_addr + XEL_MDIOCTRL_OFFSET, in xemaclite_mdio_wait()
709 * xemaclite_mdio_read - Read from a given MII management register
714 * This function waits till the device is ready to accept a new MDIO
722 struct net_local *lp = bus->priv; in xemaclite_mdio_read()
727 return -ETIMEDOUT; in xemaclite_mdio_read()
733 ctrl_reg = xemaclite_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET); in xemaclite_mdio_read()
736 lp->base_addr + XEL_MDIOADDR_OFFSET); in xemaclite_mdio_read()
738 lp->base_addr + XEL_MDIOCTRL_OFFSET); in xemaclite_mdio_read()
741 return -ETIMEDOUT; in xemaclite_mdio_read()
743 rc = xemaclite_readl(lp->base_addr + XEL_MDIORD_OFFSET); in xemaclite_mdio_read()
745 dev_dbg(&lp->ndev->dev, in xemaclite_mdio_read()
753 * xemaclite_mdio_write - Write to a given MII management register
759 * This function waits till the device is ready to accept a new MDIO
767 struct net_local *lp = bus->priv; in xemaclite_mdio_write()
770 dev_dbg(&lp->ndev->dev, in xemaclite_mdio_write()
775 return -ETIMEDOUT; in xemaclite_mdio_write()
782 ctrl_reg = xemaclite_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET); in xemaclite_mdio_write()
785 lp->base_addr + XEL_MDIOADDR_OFFSET); in xemaclite_mdio_write()
786 xemaclite_writel(val, lp->base_addr + XEL_MDIOWR_OFFSET); in xemaclite_mdio_write()
788 lp->base_addr + XEL_MDIOCTRL_OFFSET); in xemaclite_mdio_write()
794 * xemaclite_mdio_setup - Register mii_bus for the Emaclite device
795 * @lp: Pointer to the Emaclite device private data
796 * @dev: Pointer to OF device structure
798 * This function enables MDIO bus in the Emaclite device and registers a
803 static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev) in xemaclite_mdio_setup()
807 struct device_node *np = of_get_parent(lp->phy_node); in xemaclite_mdio_setup()
816 return -ENODEV; in xemaclite_mdio_setup()
823 dev->of_node->full_name); in xemaclite_mdio_setup()
827 if (lp->ndev->mem_start != res.start) { in xemaclite_mdio_setup()
830 phydev = of_phy_find_device(lp->phy_node); in xemaclite_mdio_setup()
835 put_device(&phydev->mdio.dev); in xemaclite_mdio_setup()
844 lp->base_addr + XEL_MDIOCTRL_OFFSET); in xemaclite_mdio_setup()
850 return -ENOMEM; in xemaclite_mdio_setup()
853 snprintf(bus->id, MII_BUS_ID_SIZE, "%.8llx", in xemaclite_mdio_setup()
855 bus->priv = lp; in xemaclite_mdio_setup()
856 bus->name = "Xilinx Emaclite MDIO"; in xemaclite_mdio_setup()
857 bus->read = xemaclite_mdio_read; in xemaclite_mdio_setup()
858 bus->write = xemaclite_mdio_write; in xemaclite_mdio_setup()
859 bus->parent = dev; in xemaclite_mdio_setup()
868 lp->mii_bus = bus; in xemaclite_mdio_setup()
878 * xemaclite_adjust_link - Link state callback for the Emaclite device
881 * There's nothing in the Emaclite device to be configured when the link
887 struct phy_device *phy = lp->phy_dev; in xemaclite_adjust_link()
891 link_state = phy->speed | (phy->duplex << 1) | phy->link; in xemaclite_adjust_link()
893 if (lp->last_link != link_state) { in xemaclite_adjust_link()
894 lp->last_link = link_state; in xemaclite_adjust_link()
900 * xemaclite_open - Open the network device
901 * @dev: Pointer to the network device
904 * for the Emaclite device and starts the Tx queue.
905 * It also connects to the phy device, if MDIO is included in Emaclite device.
907 * Return: 0 on success. -ENODEV, if PHY cannot be connected.
908 * Non-zero error value on failure.
915 /* Just to be safe, stop the device first */ in xemaclite_open()
918 if (lp->phy_node) { in xemaclite_open()
919 lp->phy_dev = of_phy_connect(lp->ndev, lp->phy_node, in xemaclite_open()
922 if (!lp->phy_dev) { in xemaclite_open()
923 dev_err(&lp->ndev->dev, "of_phy_connect() failed\n"); in xemaclite_open()
924 return -ENODEV; in xemaclite_open()
927 /* EmacLite doesn't support giga-bit speeds */ in xemaclite_open()
928 phy_set_max_speed(lp->phy_dev, SPEED_100); in xemaclite_open()
929 phy_start(lp->phy_dev); in xemaclite_open()
933 xemaclite_update_address(lp, dev->dev_addr); in xemaclite_open()
936 retval = request_irq(dev->irq, xemaclite_interrupt, 0, dev->name, dev); in xemaclite_open()
938 dev_err(&lp->ndev->dev, "Could not allocate interrupt %d\n", in xemaclite_open()
939 dev->irq); in xemaclite_open()
940 if (lp->phy_dev) in xemaclite_open()
941 phy_disconnect(lp->phy_dev); in xemaclite_open()
942 lp->phy_dev = NULL; in xemaclite_open()
957 * xemaclite_close - Close the network device
958 * @dev: Pointer to the network device
960 * This function stops the Tx queue, disables interrupts and frees the IRQ for
961 * the Emaclite device.
962 * It also disconnects the phy device associated with the Emaclite device.
972 free_irq(dev->irq, dev); in xemaclite_close()
974 if (lp->phy_dev) in xemaclite_close()
975 phy_disconnect(lp->phy_dev); in xemaclite_close()
976 lp->phy_dev = NULL; in xemaclite_close()
982 * xemaclite_send - Transmit a frame
984 * @dev: Pointer to the network device
986 * This function checks if the Tx buffer of the Emaclite device is free to send
987 * data. If so, it fills the Tx buffer with data from socket buffer data,
988 * updates the stats and frees the socket buffer. The Tx completion is signaled
989 * by an interrupt. If the Tx buffer isn't free, then the socket buffer is
990 * deferred and the Tx queue is stopped so that the deferred socket buffer can
991 * be transmitted when the Emaclite device is free to transmit data.
1003 len = orig_skb->len; in xemaclite_send()
1007 spin_lock_irqsave(&lp->reset_lock, flags); in xemaclite_send()
1008 if (xemaclite_send_data(lp, (u8 *)new_skb->data, len) != 0) { in xemaclite_send()
1009 /* If the Emaclite Tx buffer is busy, stop the Tx queue and in xemaclite_send()
1014 lp->deferred_skb = new_skb; in xemaclite_send()
1017 spin_unlock_irqrestore(&lp->reset_lock, flags); in xemaclite_send()
1020 spin_unlock_irqrestore(&lp->reset_lock, flags); in xemaclite_send()
1024 dev->stats.tx_bytes += len; in xemaclite_send()
1031 * get_bool - Get a parameter from the OF device
1032 * @ofdev: Pointer to OF device structure
1035 * This function looks for a property in the device node and returns the value
1042 u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL); in get_bool()
1045 dev_warn(&ofdev->dev, "Parameter %s not found, defaulting to false\n", s); in get_bool()
1053 * xemaclite_ethtools_get_drvinfo - Get various Axi Emac Lite driver info
1058 * Issue "ethtool -i ethX" under linux prompt to execute this function.
1063 strscpy(ed->driver, DRIVER_NAME, sizeof(ed->driver)); in xemaclite_ethtools_get_drvinfo()
1076 * xemaclite_of_probe - Probe method for the Emaclite device.
1077 * @ofdev: Pointer to OF device structure
1079 * This function probes for the Emaclite device in the device tree.
1081 * address and registers the network device.
1082 * It also registers a mii_bus for the Emaclite device, if MDIO is included
1083 * in the device.
1085 * Return: 0, if the driver is bound to the Emaclite device, or
1093 struct device *dev = &ofdev->dev; in xemaclite_of_probe()
1097 dev_info(dev, "Device Tree Probing\n"); in xemaclite_of_probe()
1099 /* Create an ethernet device instance */ in xemaclite_of_probe()
1102 return -ENOMEM; in xemaclite_of_probe()
1105 SET_NETDEV_DEV(ndev, &ofdev->dev); in xemaclite_of_probe()
1108 lp->ndev = ndev; in xemaclite_of_probe()
1110 /* Get IRQ for the device */ in xemaclite_of_probe()
1115 ndev->irq = rc; in xemaclite_of_probe()
1117 lp->base_addr = devm_platform_get_and_ioremap_resource(ofdev, 0, &res); in xemaclite_of_probe()
1118 if (IS_ERR(lp->base_addr)) { in xemaclite_of_probe()
1119 rc = PTR_ERR(lp->base_addr); in xemaclite_of_probe()
1123 ndev->mem_start = res->start; in xemaclite_of_probe()
1124 ndev->mem_end = res->end; in xemaclite_of_probe()
1126 spin_lock_init(&lp->reset_lock); in xemaclite_of_probe()
1127 lp->next_tx_buf_to_use = 0x0; in xemaclite_of_probe()
1128 lp->next_rx_buf_to_use = 0x0; in xemaclite_of_probe()
1129 lp->tx_ping_pong = get_bool(ofdev, "xlnx,tx-ping-pong"); in xemaclite_of_probe()
1130 lp->rx_ping_pong = get_bool(ofdev, "xlnx,rx-ping-pong"); in xemaclite_of_probe()
1132 rc = of_get_ethdev_address(ofdev->dev.of_node, ndev); in xemaclite_of_probe()
1138 /* Clear the Tx CSR's in case this is a restart */ in xemaclite_of_probe()
1139 xemaclite_writel(0, lp->base_addr + XEL_TSR_OFFSET); in xemaclite_of_probe()
1140 xemaclite_writel(0, lp->base_addr + XEL_BUFFER_OFFSET + XEL_TSR_OFFSET); in xemaclite_of_probe()
1142 /* Set the MAC address in the EmacLite device */ in xemaclite_of_probe()
1143 xemaclite_update_address(lp, ndev->dev_addr); in xemaclite_of_probe()
1145 lp->phy_node = of_parse_phandle(ofdev->dev.of_node, "phy-handle", 0); in xemaclite_of_probe()
1146 xemaclite_mdio_setup(lp, &ofdev->dev); in xemaclite_of_probe()
1148 dev_info(dev, "MAC address is now %pM\n", ndev->dev_addr); in xemaclite_of_probe()
1150 ndev->netdev_ops = &xemaclite_netdev_ops; in xemaclite_of_probe()
1151 ndev->ethtool_ops = &xemaclite_ethtool_ops; in xemaclite_of_probe()
1152 ndev->flags &= ~IFF_MULTICAST; in xemaclite_of_probe()
1153 ndev->watchdog_timeo = TX_TIMEOUT; in xemaclite_of_probe()
1155 /* Finally, register the device */ in xemaclite_of_probe()
1159 "Cannot register network device, aborting\n"); in xemaclite_of_probe()
1165 (unsigned long __force)ndev->mem_start, lp->base_addr, ndev->irq); in xemaclite_of_probe()
1169 of_node_put(lp->phy_node); in xemaclite_of_probe()
1176 * xemaclite_of_remove - Unbind the driver from the Emaclite device.
1177 * @of_dev: Pointer to OF device structure
1179 * This function is called if a device is physically removed from the system or
1181 * the device.
1189 /* Un-register the mii_bus, if configured */ in xemaclite_of_remove()
1190 if (lp->mii_bus) { in xemaclite_of_remove()
1191 mdiobus_unregister(lp->mii_bus); in xemaclite_of_remove()
1192 mdiobus_free(lp->mii_bus); in xemaclite_of_remove()
1193 lp->mii_bus = NULL; in xemaclite_of_remove()
1198 of_node_put(lp->phy_node); in xemaclite_of_remove()
1199 lp->phy_node = NULL; in xemaclite_of_remove()
1208 disable_irq(ndev->irq); in xemaclite_poll_controller()
1209 xemaclite_interrupt(ndev->irq, ndev); in xemaclite_poll_controller()
1210 enable_irq(ndev->irq); in xemaclite_poll_controller()
1217 if (!dev->phydev || !netif_running(dev)) in xemaclite_ioctl()
1218 return -EINVAL; in xemaclite_ioctl()
1224 return phy_mii_ioctl(dev->phydev, rq, cmd); in xemaclite_ioctl()
1226 return -EOPNOTSUPP; in xemaclite_ioctl()
1244 { .compatible = "xlnx,opb-ethernetlite-1.01.a", },
1245 { .compatible = "xlnx,opb-ethernetlite-1.01.b", },
1246 { .compatible = "xlnx,xps-ethernetlite-1.00.a", },
1247 { .compatible = "xlnx,xps-ethernetlite-2.00.a", },
1248 { .compatible = "xlnx,xps-ethernetlite-2.01.a", },
1249 { .compatible = "xlnx,xps-ethernetlite-3.00.a", },