// SPDX-License-Identifier: GPL-2.0 /* Marvell Octeon EP (EndPoint) Ethernet Driver * * Copyright (C) 2020 Marvell. * */ #include <linux/types.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> #include <linux/rtnetlink.h> #include <linux/vmalloc.h> #include "octep_config.h" #include "octep_main.h" #include "octep_ctrl_net.h" #include "octep_pfvf_mbox.h" #define OCTEP_INTR_POLL_TIME_MSECS … struct workqueue_struct *octep_wq; /* Supported Devices */ static const struct pci_device_id octep_pci_id_tbl[] = …; MODULE_DEVICE_TABLE(pci, octep_pci_id_tbl); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…); MODULE_LICENSE(…) …; /** * octep_alloc_ioq_vectors() - Allocate Tx/Rx Queue interrupt info. * * @oct: Octeon device private data structure. * * Allocate resources to hold per Tx/Rx queue interrupt info. * This is the information passed to interrupt handler, from which napi poll * is scheduled and includes quick access to private data of Tx/Rx queue * corresponding to the interrupt being handled. * * Return: 0, on successful allocation of resources for all queue interrupts. * -1, if failed to allocate any resource. */ static int octep_alloc_ioq_vectors(struct octep_device *oct) { … } /** * octep_free_ioq_vectors() - Free Tx/Rx Queue interrupt vector info. * * @oct: Octeon device private data structure. */ static void octep_free_ioq_vectors(struct octep_device *oct) { … } /** * octep_enable_msix_range() - enable MSI-x interrupts. * * @oct: Octeon device private data structure. * * Allocate and enable all MSI-x interrupts (queue and non-queue interrupts) * for the Octeon device. * * Return: 0, on successfully enabling all MSI-x interrupts. * -1, if failed to enable any MSI-x interrupt. */ static int octep_enable_msix_range(struct octep_device *oct) { … } /** * octep_disable_msix() - disable MSI-x interrupts. * * @oct: Octeon device private data structure. * * Disable MSI-x on the Octeon device. */ static void octep_disable_msix(struct octep_device *oct) { … } /** * octep_mbox_intr_handler() - common handler for pfvf mbox interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for pfvf mbox interrupts. */ static irqreturn_t octep_mbox_intr_handler(int irq, void *data) { … } /** * octep_oei_intr_handler() - common handler for output endpoint interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for all output endpoint interrupts. */ static irqreturn_t octep_oei_intr_handler(int irq, void *data) { … } /** * octep_ire_intr_handler() - common handler for input ring error interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for input ring error interrupts. */ static irqreturn_t octep_ire_intr_handler(int irq, void *data) { … } /** * octep_ore_intr_handler() - common handler for output ring error interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for output ring error interrupts. */ static irqreturn_t octep_ore_intr_handler(int irq, void *data) { … } /** * octep_vfire_intr_handler() - common handler for vf input ring error interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for vf input ring error interrupts. */ static irqreturn_t octep_vfire_intr_handler(int irq, void *data) { … } /** * octep_vfore_intr_handler() - common handler for vf output ring error interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for vf output ring error interrupts. */ static irqreturn_t octep_vfore_intr_handler(int irq, void *data) { … } /** * octep_dma_intr_handler() - common handler for dpi dma related interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for dpi dma related interrupts. */ static irqreturn_t octep_dma_intr_handler(int irq, void *data) { … } /** * octep_dma_vf_intr_handler() - common handler for dpi dma transaction error interrupts for VFs. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for dpi dma transaction error interrupts for VFs. */ static irqreturn_t octep_dma_vf_intr_handler(int irq, void *data) { … } /** * octep_pp_vf_intr_handler() - common handler for pp transaction error interrupts for VFs. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for pp transaction error interrupts for VFs. */ static irqreturn_t octep_pp_vf_intr_handler(int irq, void *data) { … } /** * octep_misc_intr_handler() - common handler for mac related interrupts. * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for mac related interrupts. */ static irqreturn_t octep_misc_intr_handler(int irq, void *data) { … } /** * octep_rsvd_intr_handler() - common handler for reserved interrupts (future use). * * @irq: Interrupt number. * @data: interrupt data. * * this is common handler for all reserved interrupts. */ static irqreturn_t octep_rsvd_intr_handler(int irq, void *data) { … } /** * octep_ioq_intr_handler() - handler for all Tx/Rx queue interrupts. * * @irq: Interrupt number. * @data: interrupt data contains pointers to Tx/Rx queue private data * and correspong NAPI context. * * this is common handler for all non-queue (generic) interrupts. */ static irqreturn_t octep_ioq_intr_handler(int irq, void *data) { … } /** * octep_request_irqs() - Register interrupt handlers. * * @oct: Octeon device private data structure. * * Register handlers for all queue and non-queue interrupts. * * Return: 0, on successful registration of all interrupt handlers. * -1, on any error. */ static int octep_request_irqs(struct octep_device *oct) { … } /** * octep_free_irqs() - free all registered interrupts. * * @oct: Octeon device private data structure. * * Free all queue and non-queue interrupts of the Octeon device. */ static void octep_free_irqs(struct octep_device *oct) { … } /** * octep_setup_irqs() - setup interrupts for the Octeon device. * * @oct: Octeon device private data structure. * * Allocate data structures to hold per interrupt information, allocate/enable * MSI-x interrupt and register interrupt handlers. * * Return: 0, on successful allocation and registration of all interrupts. * -1, on any error. */ static int octep_setup_irqs(struct octep_device *oct) { … } /** * octep_clean_irqs() - free all interrupts and its resources. * * @oct: Octeon device private data structure. */ static void octep_clean_irqs(struct octep_device *oct) { … } /** * octep_enable_ioq_irq() - Enable MSI-x interrupt of a Tx/Rx queue. * * @iq: Octeon Tx queue data structure. * @oq: Octeon Rx queue data structure. */ static void octep_enable_ioq_irq(struct octep_iq *iq, struct octep_oq *oq) { … } /** * octep_napi_poll() - NAPI poll function for Tx/Rx. * * @napi: pointer to napi context. * @budget: max number of packets to be processed in single invocation. */ static int octep_napi_poll(struct napi_struct *napi, int budget) { … } /** * octep_napi_add() - Add NAPI poll for all Tx/Rx queues. * * @oct: Octeon device private data structure. */ static void octep_napi_add(struct octep_device *oct) { … } /** * octep_napi_delete() - delete NAPI poll callback for all Tx/Rx queues. * * @oct: Octeon device private data structure. */ static void octep_napi_delete(struct octep_device *oct) { … } /** * octep_napi_enable() - enable NAPI for all Tx/Rx queues. * * @oct: Octeon device private data structure. */ static void octep_napi_enable(struct octep_device *oct) { … } /** * octep_napi_disable() - disable NAPI for all Tx/Rx queues. * * @oct: Octeon device private data structure. */ static void octep_napi_disable(struct octep_device *oct) { … } static void octep_link_up(struct net_device *netdev) { … } /** * octep_open() - start the octeon network device. * * @netdev: pointer to kernel network device. * * setup Tx/Rx queues, interrupts and enable hardware operation of Tx/Rx queues * and interrupts.. * * Return: 0, on successfully setting up device and bring it up. * -1, on any error. */ static int octep_open(struct net_device *netdev) { … } /** * octep_stop() - stop the octeon network device. * * @netdev: pointer to kernel network device. * * stop the device Tx/Rx operations, bring down the link and * free up all resources allocated for Tx/Rx queues and interrupts. */ static int octep_stop(struct net_device *netdev) { … } /** * octep_iq_full_check() - check if a Tx queue is full. * * @iq: Octeon Tx queue data structure. * * Return: 0, if the Tx queue is not full. * 1, if the Tx queue is full. */ static inline int octep_iq_full_check(struct octep_iq *iq) { … } /** * octep_start_xmit() - Enqueue packet to Octoen hardware Tx Queue. * * @skb: packet skbuff pointer. * @netdev: kernel network device. * * Return: NETDEV_TX_BUSY, if Tx Queue is full. * NETDEV_TX_OK, if successfully enqueued to hardware Tx queue. */ static netdev_tx_t octep_start_xmit(struct sk_buff *skb, struct net_device *netdev) { … } /** * octep_get_stats64() - Get Octeon network device statistics. * * @netdev: kernel network device. * @stats: pointer to stats structure to be filled in. */ static void octep_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) { … } /** * octep_tx_timeout_task - work queue task to Handle Tx queue timeout. * * @work: pointer to Tx queue timeout work_struct * * Stop and start the device so that it frees up all queue resources * and restarts the queues, that potentially clears a Tx queue timeout * condition. **/ static void octep_tx_timeout_task(struct work_struct *work) { … } /** * octep_tx_timeout() - Handle Tx Queue timeout. * * @netdev: pointer to kernel network device. * @txqueue: Timed out Tx queue number. * * Schedule a work to handle Tx queue timeout. */ static void octep_tx_timeout(struct net_device *netdev, unsigned int txqueue) { … } static int octep_set_mac(struct net_device *netdev, void *p) { … } static int octep_change_mtu(struct net_device *netdev, int new_mtu) { … } static int octep_set_features(struct net_device *dev, netdev_features_t features) { … } static const struct net_device_ops octep_netdev_ops = …; /** * octep_intr_poll_task - work queue task to process non-ioq interrupts. * * @work: pointer to mbox work_struct * * Process non-ioq interrupts to handle control mailbox, pfvf mailbox. **/ static void octep_intr_poll_task(struct work_struct *work) { … } /** * octep_hb_timeout_task - work queue task to check firmware heartbeat. * * @work: pointer to hb work_struct * * Check for heartbeat miss count. Uninitialize oct device if miss count * exceeds configured max heartbeat miss count. * **/ static void octep_hb_timeout_task(struct work_struct *work) { … } /** * octep_ctrl_mbox_task - work queue task to handle ctrl mbox messages. * * @work: pointer to ctrl mbox work_struct * * Poll ctrl mbox message queue and handle control messages from firmware. **/ static void octep_ctrl_mbox_task(struct work_struct *work) { … } static const char *octep_devid_to_str(struct octep_device *oct) { … } /** * octep_device_setup() - Setup Octeon Device. * * @oct: Octeon device private data structure. * * Setup Octeon device hardware operations, configuration, etc ... */ int octep_device_setup(struct octep_device *oct) { … } /** * octep_device_cleanup() - Cleanup Octeon Device. * * @oct: Octeon device private data structure. * * Cleanup Octeon device allocated resources. */ static void octep_device_cleanup(struct octep_device *oct) { … } static bool get_fw_ready_status(struct pci_dev *pdev) { … } /** * octep_probe() - Octeon PCI device probe handler. * * @pdev: PCI device structure. * @ent: entry in Octeon PCI device ID table. * * Initializes and enables the Octeon PCI device for network operations. * Initializes Octeon private data structure and registers a network device. */ static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { … } static int octep_sriov_disable(struct octep_device *oct) { … } /** * octep_remove() - Remove Octeon PCI device from driver control. * * @pdev: PCI device structure of the Octeon device. * * Cleanup all resources allocated for the Octeon device. * Unregister from network device and disable the PCI device. */ static void octep_remove(struct pci_dev *pdev) { … } static int octep_sriov_enable(struct octep_device *oct, int num_vfs) { … } static int octep_sriov_configure(struct pci_dev *pdev, int num_vfs) { … } static struct pci_driver octep_driver = …; /** * octep_init_module() - Module initialiation. * * create common resource for the driver and register PCI driver. */ static int __init octep_init_module(void) { … } /** * octep_exit_module() - Module exit routine. * * unregister the driver with PCI subsystem and cleanup common resources. */ static void __exit octep_exit_module(void) { … } module_init(…) …; module_exit(octep_exit_module);