// SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2009 - 2018 Intel Corporation. */ #define pr_fmt(fmt) … #include <linux/bitfield.h> #include <linux/delay.h> #include <linux/ethtool.h> #include <linux/if_vlan.h> #include <linux/init.h> #include <linux/ipv6.h> #include <linux/mii.h> #include <linux/module.h> #include <linux/netdevice.h> #include <linux/pagemap.h> #include <linux/pci.h> #include <linux/prefetch.h> #include <linux/sctp.h> #include <linux/slab.h> #include <linux/tcp.h> #include <linux/types.h> #include <linux/vmalloc.h> #include <net/checksum.h> #include <net/ip6_checksum.h> #include "igbvf.h" char igbvf_driver_name[] = …; static const char igbvf_driver_string[] = …; static const char igbvf_copyright[] = …; #define DEFAULT_MSG_ENABLE … static int debug = …; module_param(debug, int, 0); MODULE_PARM_DESC(…) …; static int igbvf_poll(struct napi_struct *napi, int budget); static void igbvf_reset(struct igbvf_adapter *); static void igbvf_set_interrupt_capability(struct igbvf_adapter *); static void igbvf_reset_interrupt_capability(struct igbvf_adapter *); static struct igbvf_info igbvf_vf_info = …; static struct igbvf_info igbvf_i350_vf_info = …; static const struct igbvf_info *igbvf_info_tbl[] = …; /** * igbvf_desc_unused - calculate if we have unused descriptors * @ring: address of receive ring structure **/ static int igbvf_desc_unused(struct igbvf_ring *ring) { … } /** * igbvf_receive_skb - helper function to handle Rx indications * @adapter: board private structure * @netdev: pointer to netdev struct * @skb: skb to indicate to stack * @status: descriptor status field as written by hardware * @vlan: descriptor vlan field as written by hardware (no le/be conversion) * @skb: pointer to sk_buff to be indicated to stack **/ static void igbvf_receive_skb(struct igbvf_adapter *adapter, struct net_device *netdev, struct sk_buff *skb, u32 status, __le16 vlan) { … } static inline void igbvf_rx_checksum_adv(struct igbvf_adapter *adapter, u32 status_err, struct sk_buff *skb) { … } /** * igbvf_alloc_rx_buffers - Replace used receive buffers; packet split * @rx_ring: address of ring structure to repopulate * @cleaned_count: number of buffers to repopulate **/ static void igbvf_alloc_rx_buffers(struct igbvf_ring *rx_ring, int cleaned_count) { … } /** * igbvf_clean_rx_irq - Send received data up the network stack; legacy * @adapter: board private structure * @work_done: output parameter used to indicate completed work * @work_to_do: input parameter setting limit of work * * the return value indicates whether actual cleaning was done, there * is no guarantee that everything was cleaned **/ static bool igbvf_clean_rx_irq(struct igbvf_adapter *adapter, int *work_done, int work_to_do) { … } static void igbvf_put_txbuf(struct igbvf_adapter *adapter, struct igbvf_buffer *buffer_info) { … } /** * igbvf_setup_tx_resources - allocate Tx resources (Descriptors) * @adapter: board private structure * @tx_ring: ring being initialized * * Return 0 on success, negative on failure **/ int igbvf_setup_tx_resources(struct igbvf_adapter *adapter, struct igbvf_ring *tx_ring) { … } /** * igbvf_setup_rx_resources - allocate Rx resources (Descriptors) * @adapter: board private structure * @rx_ring: ring being initialized * * Returns 0 on success, negative on failure **/ int igbvf_setup_rx_resources(struct igbvf_adapter *adapter, struct igbvf_ring *rx_ring) { … } /** * igbvf_clean_tx_ring - Free Tx Buffers * @tx_ring: ring to be cleaned **/ static void igbvf_clean_tx_ring(struct igbvf_ring *tx_ring) { … } /** * igbvf_free_tx_resources - Free Tx Resources per Queue * @tx_ring: ring to free resources from * * Free all transmit software resources **/ void igbvf_free_tx_resources(struct igbvf_ring *tx_ring) { … } /** * igbvf_clean_rx_ring - Free Rx Buffers per Queue * @rx_ring: ring structure pointer to free buffers from **/ static void igbvf_clean_rx_ring(struct igbvf_ring *rx_ring) { … } /** * igbvf_free_rx_resources - Free Rx Resources * @rx_ring: ring to clean the resources from * * Free all receive software resources **/ void igbvf_free_rx_resources(struct igbvf_ring *rx_ring) { … } /** * igbvf_update_itr - update the dynamic ITR value based on statistics * @adapter: pointer to adapter * @itr_setting: current adapter->itr * @packets: the number of packets during this measurement interval * @bytes: the number of bytes during this measurement interval * * Stores a new ITR value based on packets and byte counts during the last * interrupt. The advantage of per interrupt computation is faster updates * and more accurate ITR for the current traffic pattern. Constants in this * function were computed based on theoretical maximum wire speed and thresholds * were set based on testing data as well as attempting to minimize response * time while increasing bulk throughput. **/ static enum latency_range igbvf_update_itr(struct igbvf_adapter *adapter, enum latency_range itr_setting, int packets, int bytes) { … } static int igbvf_range_to_itr(enum latency_range current_range) { … } static void igbvf_set_itr(struct igbvf_adapter *adapter) { … } /** * igbvf_clean_tx_irq - Reclaim resources after transmit completes * @tx_ring: ring structure to clean descriptors from * * returns true if ring is completely cleaned **/ static bool igbvf_clean_tx_irq(struct igbvf_ring *tx_ring) { … } static irqreturn_t igbvf_msix_other(int irq, void *data) { … } static irqreturn_t igbvf_intr_msix_tx(int irq, void *data) { … } static irqreturn_t igbvf_intr_msix_rx(int irq, void *data) { … } #define IGBVF_NO_QUEUE … static void igbvf_assign_vector(struct igbvf_adapter *adapter, int rx_queue, int tx_queue, int msix_vector) { … } /** * igbvf_configure_msix - Configure MSI-X hardware * @adapter: board private structure * * igbvf_configure_msix sets up the hardware to properly * generate MSI-X interrupts. **/ static void igbvf_configure_msix(struct igbvf_adapter *adapter) { … } static void igbvf_reset_interrupt_capability(struct igbvf_adapter *adapter) { … } /** * igbvf_set_interrupt_capability - set MSI or MSI-X if supported * @adapter: board private structure * * Attempt to configure interrupts using the best available * capabilities of the hardware and kernel. **/ static void igbvf_set_interrupt_capability(struct igbvf_adapter *adapter) { … } /** * igbvf_request_msix - Initialize MSI-X interrupts * @adapter: board private structure * * igbvf_request_msix allocates MSI-X vectors and requests interrupts from the * kernel. **/ static int igbvf_request_msix(struct igbvf_adapter *adapter) { … } /** * igbvf_alloc_queues - Allocate memory for all rings * @adapter: board private structure to initialize **/ static int igbvf_alloc_queues(struct igbvf_adapter *adapter) { … } /** * igbvf_request_irq - initialize interrupts * @adapter: board private structure * * Attempts to configure interrupts using the best available * capabilities of the hardware and kernel. **/ static int igbvf_request_irq(struct igbvf_adapter *adapter) { … } static void igbvf_free_irq(struct igbvf_adapter *adapter) { … } /** * igbvf_irq_disable - Mask off interrupt generation on the NIC * @adapter: board private structure **/ static void igbvf_irq_disable(struct igbvf_adapter *adapter) { … } /** * igbvf_irq_enable - Enable default interrupt generation settings * @adapter: board private structure **/ static void igbvf_irq_enable(struct igbvf_adapter *adapter) { … } /** * igbvf_poll - NAPI Rx polling callback * @napi: struct associated with this polling callback * @budget: amount of packets driver is allowed to process this poll **/ static int igbvf_poll(struct napi_struct *napi, int budget) { … } /** * igbvf_set_rlpml - set receive large packet maximum length * @adapter: board private structure * * Configure the maximum size of packets that will be received */ static void igbvf_set_rlpml(struct igbvf_adapter *adapter) { … } static int igbvf_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid) { … } static int igbvf_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid) { … } static void igbvf_restore_vlan(struct igbvf_adapter *adapter) { … } /** * igbvf_configure_tx - Configure Transmit Unit after Reset * @adapter: board private structure * * Configure the Tx unit of the MAC after a reset. **/ static void igbvf_configure_tx(struct igbvf_adapter *adapter) { … } /** * igbvf_setup_srrctl - configure the receive control registers * @adapter: Board private structure **/ static void igbvf_setup_srrctl(struct igbvf_adapter *adapter) { … } /** * igbvf_configure_rx - Configure Receive Unit after Reset * @adapter: board private structure * * Configure the Rx unit of the MAC after a reset. **/ static void igbvf_configure_rx(struct igbvf_adapter *adapter) { … } /** * igbvf_set_multi - Multicast and Promiscuous mode set * @netdev: network interface device structure * * The set_multi entry point is called whenever the multicast address * list or the network interface flags are updated. This routine is * responsible for configuring the hardware for proper multicast, * promiscuous mode, and all-multi behavior. **/ static void igbvf_set_multi(struct net_device *netdev) { … } /** * igbvf_set_uni - Configure unicast MAC filters * @netdev: network interface device structure * * This routine is responsible for configuring the hardware for proper * unicast filters. **/ static int igbvf_set_uni(struct net_device *netdev) { … } static void igbvf_set_rx_mode(struct net_device *netdev) { … } /** * igbvf_configure - configure the hardware for Rx and Tx * @adapter: private board structure **/ static void igbvf_configure(struct igbvf_adapter *adapter) { … } /* igbvf_reset - bring the hardware into a known good state * @adapter: private board structure * * This function boots the hardware and enables some settings that * require a configuration cycle of the hardware - those cannot be * set/changed during runtime. After reset the device needs to be * properly configured for Rx, Tx etc. */ static void igbvf_reset(struct igbvf_adapter *adapter) { … } int igbvf_up(struct igbvf_adapter *adapter) { … } void igbvf_down(struct igbvf_adapter *adapter) { … } void igbvf_reinit_locked(struct igbvf_adapter *adapter) { … } /** * igbvf_sw_init - Initialize general software structures (struct igbvf_adapter) * @adapter: board private structure to initialize * * igbvf_sw_init initializes the Adapter private data structure. * Fields are initialized based on PCI device information and * OS network device settings (MTU size). **/ static int igbvf_sw_init(struct igbvf_adapter *adapter) { … } static void igbvf_initialize_last_counter_stats(struct igbvf_adapter *adapter) { … } /** * igbvf_open - Called when a network interface is made active * @netdev: network interface device structure * * Returns 0 on success, negative value on failure * * The open entry point is called when a network interface is made * active by the system (IFF_UP). At this point all resources needed * for transmit and receive operations are allocated, the interrupt * handler is registered with the OS, the watchdog timer is started, * and the stack is notified that the interface is ready. **/ static int igbvf_open(struct net_device *netdev) { … } /** * igbvf_close - Disables a network interface * @netdev: network interface device structure * * Returns 0, this is not allowed to fail * * The close entry point is called when an interface is de-activated * by the OS. The hardware is still under the drivers control, but * needs to be disabled. A global MAC reset is issued to stop the * hardware, and all transmit and receive resources are freed. **/ static int igbvf_close(struct net_device *netdev) { … } /** * igbvf_set_mac - Change the Ethernet Address of the NIC * @netdev: network interface device structure * @p: pointer to an address structure * * Returns 0 on success, negative on failure **/ static int igbvf_set_mac(struct net_device *netdev, void *p) { … } #define UPDATE_VF_COUNTER(reg, name) … /** * igbvf_update_stats - Update the board statistics counters * @adapter: board private structure **/ void igbvf_update_stats(struct igbvf_adapter *adapter) { … } static void igbvf_print_link_info(struct igbvf_adapter *adapter) { … } static bool igbvf_has_link(struct igbvf_adapter *adapter) { … } /** * igbvf_watchdog - Timer Call-back * @t: timer list pointer containing private struct **/ static void igbvf_watchdog(struct timer_list *t) { … } static void igbvf_watchdog_task(struct work_struct *work) { … } #define IGBVF_TX_FLAGS_CSUM … #define IGBVF_TX_FLAGS_VLAN … #define IGBVF_TX_FLAGS_TSO … #define IGBVF_TX_FLAGS_IPV4 … #define IGBVF_TX_FLAGS_VLAN_MASK … #define IGBVF_TX_FLAGS_VLAN_SHIFT … static void igbvf_tx_ctxtdesc(struct igbvf_ring *tx_ring, u32 vlan_macip_lens, u32 type_tucmd, u32 mss_l4len_idx) { … } static int igbvf_tso(struct igbvf_ring *tx_ring, struct sk_buff *skb, u32 tx_flags, u8 *hdr_len) { … } static bool igbvf_tx_csum(struct igbvf_ring *tx_ring, struct sk_buff *skb, u32 tx_flags, __be16 protocol) { … } static int igbvf_maybe_stop_tx(struct net_device *netdev, int size) { … } #define IGBVF_MAX_TXD_PWR … #define IGBVF_MAX_DATA_PER_TXD … static inline int igbvf_tx_map_adv(struct igbvf_adapter *adapter, struct igbvf_ring *tx_ring, struct sk_buff *skb) { … } static inline void igbvf_tx_queue_adv(struct igbvf_adapter *adapter, struct igbvf_ring *tx_ring, int tx_flags, int count, unsigned int first, u32 paylen, u8 hdr_len) { … } static netdev_tx_t igbvf_xmit_frame_ring_adv(struct sk_buff *skb, struct net_device *netdev, struct igbvf_ring *tx_ring) { … } static netdev_tx_t igbvf_xmit_frame(struct sk_buff *skb, struct net_device *netdev) { … } /** * igbvf_tx_timeout - Respond to a Tx Hang * @netdev: network interface device structure * @txqueue: queue timing out (unused) **/ static void igbvf_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue) { … } static void igbvf_reset_task(struct work_struct *work) { … } /** * igbvf_change_mtu - Change the Maximum Transfer Unit * @netdev: network interface device structure * @new_mtu: new value for maximum frame size * * Returns 0 on success, negative on failure **/ static int igbvf_change_mtu(struct net_device *netdev, int new_mtu) { … } static int igbvf_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) { … } static int igbvf_suspend(struct device *dev_d) { … } static int igbvf_resume(struct device *dev_d) { … } static void igbvf_shutdown(struct pci_dev *pdev) { … } #ifdef CONFIG_NET_POLL_CONTROLLER /* Polling 'interrupt' - used by things like netconsole to send skbs * without having to re-enable interrupts. It's not called while * the interrupt routine is executing. */ static void igbvf_netpoll(struct net_device *netdev) { … } #endif /** * igbvf_io_error_detected - called when PCI error is detected * @pdev: Pointer to PCI device * @state: The current pci connection state * * This function is called after a PCI bus error affecting * this device has been detected. */ static pci_ers_result_t igbvf_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) { … } /** * igbvf_io_slot_reset - called after the pci bus has been reset. * @pdev: Pointer to PCI device * * Restart the card from scratch, as if from a cold-boot. Implementation * resembles the first-half of the igbvf_resume routine. */ static pci_ers_result_t igbvf_io_slot_reset(struct pci_dev *pdev) { … } /** * igbvf_io_resume - called when traffic can start flowing again. * @pdev: Pointer to PCI device * * This callback is called when the error recovery driver tells us that * its OK to resume normal operation. Implementation resembles the * second-half of the igbvf_resume routine. */ static void igbvf_io_resume(struct pci_dev *pdev) { … } /** * igbvf_io_prepare - prepare device driver for PCI reset * @pdev: PCI device information struct */ static void igbvf_io_prepare(struct pci_dev *pdev) { … } /** * igbvf_io_reset_done - PCI reset done, device driver reset can begin * @pdev: PCI device information struct */ static void igbvf_io_reset_done(struct pci_dev *pdev) { … } static void igbvf_print_device_info(struct igbvf_adapter *adapter) { … } static int igbvf_set_features(struct net_device *netdev, netdev_features_t features) { … } #define IGBVF_MAX_MAC_HDR_LEN … #define IGBVF_MAX_NETWORK_HDR_LEN … static netdev_features_t igbvf_features_check(struct sk_buff *skb, struct net_device *dev, netdev_features_t features) { … } static const struct net_device_ops igbvf_netdev_ops = …; /** * igbvf_probe - Device Initialization Routine * @pdev: PCI device information struct * @ent: entry in igbvf_pci_tbl * * Returns 0 on success, negative on failure * * igbvf_probe initializes an adapter identified by a pci_dev structure. * The OS initialization, configuring of the adapter private structure, * and a hardware reset occur. **/ static int igbvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { … } /** * igbvf_remove - Device Removal Routine * @pdev: PCI device information struct * * igbvf_remove is called by the PCI subsystem to alert the driver * that it should release a PCI device. The could be caused by a * Hot-Plug event, or because the driver is going to be removed from * memory. **/ static void igbvf_remove(struct pci_dev *pdev) { … } /* PCI Error Recovery (ERS) */ static const struct pci_error_handlers igbvf_err_handler = …; static const struct pci_device_id igbvf_pci_tbl[] = …; MODULE_DEVICE_TABLE(pci, igbvf_pci_tbl); static DEFINE_SIMPLE_DEV_PM_OPS(igbvf_pm_ops, igbvf_suspend, igbvf_resume); /* PCI Device API Driver */ static struct pci_driver igbvf_driver = …; /** * igbvf_init_module - Driver Registration Routine * * igbvf_init_module is the first routine called when the driver is * loaded. All it does is register with the PCI subsystem. **/ static int __init igbvf_init_module(void) { … } module_init(…) …; /** * igbvf_exit_module - Driver Exit Cleanup Routine * * igbvf_exit_module is called just before the driver is removed * from memory. **/ static void __exit igbvf_exit_module(void) { … } module_exit(igbvf_exit_module); MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; /* netdev.c */