// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2004-2013 Synopsys, Inc. (www.synopsys.com) * * Driver for the ARC EMAC 10100 (hardware revision 5) * * Contributors: * Amit Bhor * Sameer Dhavale * Vineet Gupta */ #include <linux/crc32.h> #include <linux/etherdevice.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/of_mdio.h> #include <linux/of_net.h> #include "emac.h" static void arc_emac_restart(struct net_device *ndev); /** * arc_emac_tx_avail - Return the number of available slots in the tx ring. * @priv: Pointer to ARC EMAC private data structure. * * returns: the number of slots available for transmission in tx the ring. */ static inline int arc_emac_tx_avail(struct arc_emac_priv *priv) { … } /** * arc_emac_adjust_link - Adjust the PHY link duplex. * @ndev: Pointer to the net_device structure. * * This function is called to change the duplex setting after auto negotiation * is done by the PHY. */ static void arc_emac_adjust_link(struct net_device *ndev) { … } /** * arc_emac_get_drvinfo - Get EMAC driver information. * @ndev: Pointer to net_device structure. * @info: Pointer to ethtool_drvinfo structure. * * This implements ethtool command for getting the driver information. * Issue "ethtool -i ethX" under linux prompt to execute this function. */ static void arc_emac_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info) { … } static const struct ethtool_ops arc_emac_ethtool_ops = …; #define FIRST_OR_LAST_MASK … /** * arc_emac_tx_clean - clears processed by EMAC Tx BDs. * @ndev: Pointer to the network device. */ static void arc_emac_tx_clean(struct net_device *ndev) { … } /** * arc_emac_rx - processing of Rx packets. * @ndev: Pointer to the network device. * @budget: How many BDs to process on 1 call. * * returns: Number of processed BDs * * Iterate through Rx BDs and deliver received packages to upper layer. */ static int arc_emac_rx(struct net_device *ndev, int budget) { … } /** * arc_emac_rx_miss_handle - handle R_MISS register * @ndev: Pointer to the net_device structure. */ static void arc_emac_rx_miss_handle(struct net_device *ndev) { … } /** * arc_emac_rx_stall_check - check RX stall * @ndev: Pointer to the net_device structure. * @budget: How many BDs requested to process on 1 call. * @work_done: How many BDs processed * * Under certain conditions EMAC stop reception of incoming packets and * continuously increment R_MISS register instead of saving data into * provided buffer. This function detect that condition and restart * EMAC. */ static void arc_emac_rx_stall_check(struct net_device *ndev, int budget, unsigned int work_done) { … } /** * arc_emac_poll - NAPI poll handler. * @napi: Pointer to napi_struct structure. * @budget: How many BDs to process on 1 call. * * returns: Number of processed BDs */ static int arc_emac_poll(struct napi_struct *napi, int budget) { … } /** * arc_emac_intr - Global interrupt handler for EMAC. * @irq: irq number. * @dev_instance: device instance. * * returns: IRQ_HANDLED for all cases. * * ARC EMAC has only 1 interrupt line, and depending on bits raised in * STATUS register we may tell what is a reason for interrupt to fire. */ static irqreturn_t arc_emac_intr(int irq, void *dev_instance) { … } #ifdef CONFIG_NET_POLL_CONTROLLER static void arc_emac_poll_controller(struct net_device *dev) { … } #endif /** * arc_emac_open - Open the network device. * @ndev: Pointer to the network device. * * returns: 0, on success or non-zero error value on failure. * * This function sets the MAC address, requests and enables an IRQ * for the EMAC device and starts the Tx queue. * It also connects to the phy device. */ static int arc_emac_open(struct net_device *ndev) { … } /** * arc_emac_set_rx_mode - Change the receive filtering mode. * @ndev: Pointer to the network device. * * This function enables/disables promiscuous or all-multicast mode * and updates the multicast filtering list of the network device. */ static void arc_emac_set_rx_mode(struct net_device *ndev) { … } /** * arc_free_tx_queue - free skb from tx queue * @ndev: Pointer to the network device. * * This function must be called while EMAC disable */ static void arc_free_tx_queue(struct net_device *ndev) { … } /** * arc_free_rx_queue - free skb from rx queue * @ndev: Pointer to the network device. * * This function must be called while EMAC disable */ static void arc_free_rx_queue(struct net_device *ndev) { … } /** * arc_emac_stop - Close the network device. * @ndev: Pointer to the network device. * * This function stops the Tx queue, disables interrupts and frees the IRQ for * the EMAC device. * It also disconnects the PHY device associated with the EMAC device. */ static int arc_emac_stop(struct net_device *ndev) { … } /** * arc_emac_stats - Get system network statistics. * @ndev: Pointer to net_device structure. * * Returns the address of the device statistics structure. * Statistics are updated in interrupt handler. */ static struct net_device_stats *arc_emac_stats(struct net_device *ndev) { … } /** * arc_emac_tx - Starts the data transmission. * @skb: sk_buff pointer that contains data to be Transmitted. * @ndev: Pointer to net_device structure. * * returns: NETDEV_TX_OK, on success * NETDEV_TX_BUSY, if any of the descriptors are not free. * * This function is invoked from upper layers to initiate transmission. */ static netdev_tx_t arc_emac_tx(struct sk_buff *skb, struct net_device *ndev) { … } static void arc_emac_set_address_internal(struct net_device *ndev) { … } /** * arc_emac_set_address - Set the MAC address for this device. * @ndev: Pointer to net_device structure. * @p: 6 byte Address to be written as MAC address. * * This function copies the HW address from the sockaddr structure to the * net_device structure and updates the address in HW. * * returns: -EBUSY if the net device is busy or 0 if the address is set * successfully. */ static int arc_emac_set_address(struct net_device *ndev, void *p) { … } /** * arc_emac_restart - Restart EMAC * @ndev: Pointer to net_device structure. * * This function do hardware reset of EMAC in order to restore * network packets reception. */ static void arc_emac_restart(struct net_device *ndev) { … } static const struct net_device_ops arc_emac_netdev_ops = …; int arc_emac_probe(struct net_device *ndev, int interface) { … } EXPORT_SYMBOL_GPL(…); void arc_emac_remove(struct net_device *ndev) { … } EXPORT_SYMBOL_GPL(…); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;