Add gve driver
Subsystems (4)
v4 cover Add gve driver
This patch series adds the gve driver which will support the Compute Engine Virtual NIC that will be available in the future.
v2:
- Patch 1:
- Remove gve_size_assert.h and use static_assert instead.
- Loop forever instead of bugging if the device won't reset
- Use module_pci_driver
- Patch 2:
- Use be16_to_cpu in the RX Seq No define
- Remove unneeded ndo_change_mtu
- Patch 3:
- No Changes
- Patch 4:
- Instead of checking netif_carrier_ok in ethtool stats, just make sure
v3:
- Patch 1:
- Remove X86 dep
- Patch 2:
- No changes
- Patch 3:
- No changes
- Patch 4:
- Remove unneeded memsets in ethtool stats
v4:
- Patch 1:
- Use io[read|write]32be instead of [read|write]l(cpu_to_be32())
- Explicitly add padding to gve_adminq_set_driver_parameter
- Use static where appropriate
- Patch 2:
- Use u64_stats_sync
- Explicity add padding to gve_adminq_create_rx_queue
- Fix some enianness typing issues found by kbuild
- Use static where appropriate
- Remove unused variables
- Patch 3:
- Use io[read|write]32be instead of [read|write]l(cpu_to_be32())
- Patch 4:
- Use u64_stats_sync
- Use static where appropriate
Warnings reported by:
Catherine Sullivan (4):
gve: Add basic driver framework for Compute Engine Virtual NIC
gve: Add transmit and receive support
gve: Add workqueue and reset support
gve: Add ethtool support
.../networking/device_drivers/google/gve.rst | 123 ++ .../networking/device_drivers/index.rst | 1 + MAINTAINERS | 9 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/google/Kconfig | 27 + drivers/net/ethernet/google/Makefile | 5 + drivers/net/ethernet/google/gve/Makefile | 4 + drivers/net/ethernet/google/gve/gve.h | 459 ++++++ drivers/net/ethernet/google/gve/gve_adminq.c | 387 ++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 217 +++ drivers/net/ethernet/google/gve/gve_desc.h | 113 ++ drivers/net/ethernet/google/gve/gve_ethtool.c | 243 ++++ drivers/net/ethernet/google/gve/gve_main.c | 1228 +++++++++++++++++ .../net/ethernet/google/gve/gve_register.h | 27 + drivers/net/ethernet/google/gve/gve_rx.c | 446 ++++++ drivers/net/ethernet/google/gve/gve_tx.c | 584 ++++++++ 17 files changed, 3875 insertions(+) create mode 100644 Documentation/networking/device_drivers/google/gve.rst create mode 100644 drivers/net/ethernet/google/Kconfig create mode 100644 drivers/net/ethernet/google/Makefile create mode 100644 drivers/net/ethernet/google/gve/Makefile create mode 100644 drivers/net/ethernet/google/gve/gve.h create mode 100644 drivers/net/ethernet/google/gve/gve_adminq.c create mode 100644 drivers/net/ethernet/google/gve/gve_adminq.h create mode 100644 drivers/net/ethernet/google/gve/gve_desc.h create mode 100644 drivers/net/ethernet/google/gve/gve_ethtool.c create mode 100644 drivers/net/ethernet/google/gve/gve_main.c create mode 100644 drivers/net/ethernet/google/gve/gve_register.h create mode 100644 drivers/net/ethernet/google/gve/gve_rx.c create mode 100644 drivers/net/ethernet/google/gve/gve_tx.c
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v4 1/4 gve: Add basic driver framework for Compute Engine Virtual NIC
Add a driver framework for the Compute Engine Virtual NIC that will be available in the future.
At this point the only functionality is loading the driver.
--- .../networking/device_drivers/google/gve.rst | 82 ++++ .../networking/device_drivers/index.rst | 1 + MAINTAINERS | 9 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/google/Kconfig | 27 ++ drivers/net/ethernet/google/Makefile | 5 + drivers/net/ethernet/google/gve/Makefile | 4 + drivers/net/ethernet/google/gve/gve.h | 135 ++++++ drivers/net/ethernet/google/gve/gve_adminq.c | 249 ++++++++++ drivers/net/ethernet/google/gve/gve_adminq.h | 134 ++++++ drivers/net/ethernet/google/gve/gve_main.c | 446 ++++++++++++++++++ .../net/ethernet/google/gve/gve_register.h | 27 ++ 13 files changed, 1121 insertions(+) create mode 100644 Documentation/networking/device_drivers/google/gve.rst create mode 100644 drivers/net/ethernet/google/Kconfig create mode 100644 drivers/net/ethernet/google/Makefile create mode 100644 drivers/net/ethernet/google/gve/Makefile create mode 100644 drivers/net/ethernet/google/gve/gve.h create mode 100644 drivers/net/ethernet/google/gve/gve_adminq.c create mode 100644 drivers/net/ethernet/google/gve/gve_adminq.h create mode 100644 drivers/net/ethernet/google/gve/gve_main.c create mode 100644 drivers/net/ethernet/google/gve/gve_register.h
Documentation/networking/device_drivers/google/gve.rst new file +82 -0
@@ -0,0 +1,82 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +============================================================== +Linux kernel driver for Compute Engine Virtual Ethernet (gve): +============================================================== + +Supported Hardware +=================== +The GVE driver binds to a single PCI device id used by the virtual +Ethernet device found in some Compute Engine VMs. + ++--------------+----------+---------+ +|Field | Value | Comments| ++==============+==========+=========+ +|Vendor ID | `0x1AE0` | Google | ++--------------+----------+---------+ +|Device ID | `0x0042` | | ++--------------+----------+---------+ +|Sub-vendor ID | `0x1AE0` | Google | ++--------------+----------+---------+ +|Sub-device ID | `0x0058` | | ++--------------+----------+---------+ +|Revision ID | `0x0` | | ++--------------+----------+---------+ +|Device Class | `0x200` | Ethernet| ++--------------+----------+---------+ + +PCI Bars +======== +The gVNIC PCI device exposes three 32-bit memory BARS: +- Bar0 - Device configuration and status registers. +- Bar1 - MSI-X vector table +- Bar2 - IRQ, RX and TX doorbells + +Device Interactions +=================== +The driver interacts with the device in the following ways: + - Registers + - A block of MMIO registers + - See gve_register.h for more detail + - Admin Queue + - See description below + - Interrupts + - See supported interrupts below + +Registers +--------- +All registers are MMIO and big endian. + +The registers are used for initializing and configuring the device as well as +querying device status in response to management interrupts. + +Admin Queue (AQ) +---------------- +The Admin Queue is a PAGE_SIZE memory block, treated as an array of AQ +commands, used by the driver to issue commands to the device and set up +resources.The driver and the device maintain a count of how many commands +have been submitted and executed. To issue AQ commands, the driver must do +the following (with proper locking): + +1) Copy new commands into next available slots in the AQ array +2) Increment its counter by he number of new commands +3) Write the counter into the GVE_ADMIN_QUEUE_DOORBELL register +4) Poll the ADMIN_QUEUE_EVENT_COUNTER register until it equals + the value written to the doorbell, or until a timeout. + +The device will update the status field in each AQ command reported as +executed through the ADMIN_QUEUE_EVENT_COUNTER register. + +Interrupts +---------- +The following interrupts are supported by the driver: + +Management Interrupt +~~~~~~~~~~~~~~~~~~~~ +The management interrupt is used by the device to tell the driver to +look at the GVE_DEVICE_STATUS register. + +Notification Block Interrupts +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The notification block interrupts are used to tell the driver to poll +the queues associated with that interrupt.
Documentation/networking/device_drivers/index.rst +1 -0
@@ -21,6 +21,7 @@ Contents: intel/i40e intel/iavf intel/ice + google/gve mellanox/mlx5 .. only:: subproject
MAINTAINERS +9 -0
@@ -6720,6 +6720,15 @@ L: [email protected] S: Maintained F: drivers/input/touchscreen/goodix.c +GOOGLE ETHERNET DRIVERS +M: Catherine Sullivan <[email protected]> +R: Sagi Shahar <[email protected]> +R: Jon Olson <[email protected]> +L: [email protected] +S: Supported +F: Documentation/networking/device_drivers/google/gve.txt +F: drivers/net/ethernet/google + GPD POCKET FAN DRIVER M: Hans de Goede <[email protected]> L: [email protected]
drivers/net/ethernet/Kconfig +1 -0
@@ -76,6 +76,7 @@ source "drivers/net/ethernet/ezchip/Kconfig" source "drivers/net/ethernet/faraday/Kconfig" source "drivers/net/ethernet/freescale/Kconfig" source "drivers/net/ethernet/fujitsu/Kconfig" +source "drivers/net/ethernet/google/Kconfig" source "drivers/net/ethernet/hisilicon/Kconfig" source "drivers/net/ethernet/hp/Kconfig" source "drivers/net/ethernet/huawei/Kconfig"
drivers/net/ethernet/Makefile +1 -0
@@ -39,6 +39,7 @@ obj-$(CONFIG_NET_VENDOR_EZCHIP) += ezchip/ obj-$(CONFIG_NET_VENDOR_FARADAY) += faraday/ obj-$(CONFIG_NET_VENDOR_FREESCALE) += freescale/ obj-$(CONFIG_NET_VENDOR_FUJITSU) += fujitsu/ +obj-$(CONFIG_NET_VENDOR_GOOGLE) += google/ obj-$(CONFIG_NET_VENDOR_HISILICON) += hisilicon/ obj-$(CONFIG_NET_VENDOR_HP) += hp/ obj-$(CONFIG_NET_VENDOR_HUAWEI) += huawei/
drivers/net/ethernet/google/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ +# +# Google network device configuration +# + +config NET_VENDOR_GOOGLE + bool "Google Devices" + default y + help + If you have a network (Ethernet) device belonging to this class, say Y. + + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Google devices. If you say Y, you will be asked + for your specific device in the following questions. + +if NET_VENDOR_GOOGLE + +config GVE + tristate "Google Virtual NIC (gVNIC) support" + depends on PCI_MSI + help + This driver supports Google Virtual NIC (gVNIC)" + + To compile this driver as a module, choose M here. + The module will be called gve. + +endif #NET_VENDOR_GOOGLE
drivers/net/ethernet/google/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the Google network device drivers. +# + +obj-$(CONFIG_GVE) += gve/
drivers/net/ethernet/google/gve/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# Makefile for the Google virtual Ethernet (gve) driver + +obj-$(CONFIG_GVE) += gve.o +gve-objs := gve_main.o gve_adminq.o
drivers/net/ethernet/google/gve/gve.h new file +135 -0
135 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_adminq.c new file +249 -0
249 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_adminq.h new file +134 -0
134 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_main.c new file +446 -0
446 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_register.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) +* Google virtual Ethernet (gve) driver +* +* Copyright (C) 2015-2019 Google, Inc. +*/ + +#ifndef _GVE_REGISTER_H_ +#define _GVE_REGISTER_H_ + +/* Fixed Configuration Registers */ +struct gve_registers { +__be32 device_status; +__be32 driver_status; +__be32 max_tx_queues; +__be32 max_rx_queues; +__be32 adminq_pfn; +__be32 adminq_doorbell; +__be32 adminq_event_counter; +u8 reserved[3 ]; +u8 driver_version; +}; + +enum gve_device_status_flags { +GVE_DEVICE_STATUS_RESET_MASK =BIT (1 ), +GVE_DEVICE_STATUS_LINK_STATUS_MASK =BIT (2 ), +}; +#endif /* _GVE_REGISTER_H_ */
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v4 2/4 gve: Add transmit and receive support
In reply to Catherine SullivanAdd support for passing traffic.
--- .../networking/device_drivers/google/gve.rst | 30 + drivers/net/ethernet/google/gve/Makefile | 2 +- drivers/net/ethernet/google/gve/gve.h | 260 +++++++- drivers/net/ethernet/google/gve/gve_adminq.c | 138 +++++ drivers/net/ethernet/google/gve/gve_adminq.h | 83 +++ drivers/net/ethernet/google/gve/gve_desc.h | 113 ++++ drivers/net/ethernet/google/gve/gve_main.c | 573 ++++++++++++++++- drivers/net/ethernet/google/gve/gve_rx.c | 443 +++++++++++++ drivers/net/ethernet/google/gve/gve_tx.c | 584 ++++++++++++++++++ 9 files changed, 2221 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/google/gve/gve_desc.h create mode 100644 drivers/net/ethernet/google/gve/gve_rx.c create mode 100644 drivers/net/ethernet/google/gve/gve_tx.c
Documentation/networking/device_drivers/google/gve.rst +30 -0
@@ -42,6 +42,8 @@ The driver interacts with the device in the following ways: - See description below - Interrupts - See supported interrupts below + - Transmit and Receive Queues + - See description below Registers ---------
@@ -80,3 +82,31 @@ Notification Block Interrupts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The notification block interrupts are used to tell the driver to poll the queues associated with that interrupt. + +The handler for these irqs schedule the napi for that block to run +and poll the queues. + +Traffic Queues +-------------- +gVNIC's queues are composed of a descriptor ring and a buffer and are +assigned to a notification block. + +The descriptor rings are power-of-two-sized ring buffers consisting of +fixed-size descriptors. They advance their head pointer using a __be32 +doorbell located in Bar2. The tail pointers are advanced by consuming +descriptors in-order and updating a __be32 counter. Both the doorbell +and the counter overflow to zero. + +Each queue's buffers must be registered in advance with the device as a +queue page list, and packet data can only be put in those pages. + +Transmit +~~~~~~~~ +gve maps the buffers for transmit rings into a FIFO and copies the packets +into the FIFO before sending them to the NIC. + +Receive +~~~~~~~ +The buffers for receive rings are put into a data ring that is the same +length as the descriptor ring and the head and tail pointers advance over +the rings together.
drivers/net/ethernet/google/gve/Makefile +1 -1
@@ -1,4 +1,4 @@ # Makefile for the Google virtual Ethernet (gve) driver obj-$(CONFIG_GVE) += gve.o -gve-objs := gve_main.o gve_adminq.o +gve-objs := gve_main.o gve_tx.o gve_rx.o gve_adminq.o
drivers/net/ethernet/google/gve/gve.h +259 -1
300 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_adminq.c +138 -0
162 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_adminq.h +83 -0
107 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_desc.h new file +113 -0
113 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_main.c +570 -3
643 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_rx.c new file +443 -0
443 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_tx.c new file +584 -0
584 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v4 3/4 gve: Add workqueue and reset support
In reply to Catherine SullivanAdd support for the workqueue to handle management interrupts and support for resets.
--- .../networking/device_drivers/google/gve.rst | 11 + drivers/net/ethernet/google/gve/gve.h | 62 ++++++ drivers/net/ethernet/google/gve/gve_main.c | 190 +++++++++++++++++- drivers/net/ethernet/google/gve/gve_rx.c | 5 +- 4 files changed, 260 insertions(+), 8 deletions(-)
Documentation/networking/device_drivers/google/gve.rst +11 -0
@@ -40,6 +40,8 @@ The driver interacts with the device in the following ways: - See gve_register.h for more detail - Admin Queue - See description below + - Reset + - At any time the device can be reset - Interrupts - See supported interrupts below - Transmit and Receive Queues
@@ -69,6 +71,12 @@ the following (with proper locking): The device will update the status field in each AQ command reported as executed through the ADMIN_QUEUE_EVENT_COUNTER register. +Device Resets +------------- +A device reset is triggered by writing 0x0 to the AQ PFN register. +This causes the device to release all resources allocated by the +driver, including the AQ itself. + Interrupts ---------- The following interrupts are supported by the driver:
@@ -78,6 +86,9 @@ Management Interrupt The management interrupt is used by the device to tell the driver to look at the GVE_DEVICE_STATUS register. +The handler for the management irq simply queues the service task in +the workqueue to check the register and acks the irq. + Notification Block Interrupts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The notification block interrupts are used to tell the driver to poll
drivers/net/ethernet/google/gve/gve.h +62 -0
81 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_main.c +183 -7
327 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_rx.c +4 -1
@@ -334,6 +334,9 @@ static bool gve_rx(struct gve_rx_ring *rx, struct gve_rx_desc *rx_desc,#endif have_skb: +/* We didn't manage to allocate an skb but we haven't had any +* reset worthy failures. +*/ if (!skb)return true;
@@ -399,7 +402,7 @@ bool gve_clean_rx_done(struct gve_rx_ring *rx, int budget, rx->desc.seqno); bytes +=be16_to_cpu (desc->len) -GVE_RX_PAD ;if (!gve_rx (rx, desc, feat)) -return false; +gve_schedule_reset (priv); cnt++; idx = cnt & rx->desc.mask; desc = rx->desc.desc_ring + idx;
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v4 4/4 gve: Add ethtool support
In reply to Catherine SullivanAdd support for the following ethtool commands:
ethtool -s|--change devname [msglvl N] [msglevel type on|off] ethtool -S|--statistics devname ethtool -i|--driver devname ethtool -l|--show-channels devname ethtool -L|--set-channels devname ethtool -g|--show-ring devname
ethtool --reset devname
--- drivers/net/ethernet/google/gve/Makefile | 2 +- drivers/net/ethernet/google/gve/gve.h | 4 + drivers/net/ethernet/google/gve/gve_ethtool.c | 243 ++++++++++++++++++ drivers/net/ethernet/google/gve/gve_main.c | 41 ++- 4 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/google/gve/gve_ethtool.c
drivers/net/ethernet/google/gve/Makefile +1 -1
@@ -1,4 +1,4 @@ # Makefile for the Google virtual Ethernet (gve) driver obj-$(CONFIG_GVE) += gve.o -gve-objs := gve_main.o gve_tx.o gve_rx.o gve_adminq.o +gve-objs := gve_main.o gve_tx.o gve_rx.o gve_ethtool.o gve_adminq.o
drivers/net/ethernet/google/gve/gve.h +4 -0
@@ -452,4 +452,8 @@ int gve_reset(struct gve_priv *priv, bool attempt_teardown);int gve_adjust_queues (struct gve_priv *priv,struct gve_queue_config new_rx_config,struct gve_queue_config new_tx_config); +/* exported by ethtool.c */ +extern const struct ethtool_ops gve_ethtool_ops; +/* needed by ethtool */ +extern const char gve_version_str[];#endif /* _GVE_H_ */
drivers/net/ethernet/google/gve/gve_ethtool.c new file +243 -0
243 lines not on this page · raw message
drivers/net/ethernet/google/gve/gve_main.c +40 -1
59 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
David Miller
maintainerFrom: Catherine Sullivan <[email protected]>
Date: Mon, 1 Jul 2019 15:57:51 -0700
Quoted 2 lines
This patch series adds the gve driver which will support the Compute Engine Virtual NIC that will be available in the future.
...
Series applied to net-next, thanks.
Re: [PATCH net-next v4 1/4] gve: Add basic driver framework for Compute Engine Virtual NIC
In reply to Catherine SullivanQuoted 11 lines · Catherine Sullivan
Add a driver framework for the Compute Engine Virtual NIC that will be available in the future.
At this point the only functionality is loading the driver.
Signed-off-by Catherine Sullivan <[email protected]>Signed-off-by Sagi Shahar <[email protected]>Signed-off-by Jon Olson <[email protected]>Acked-by Willem de Bruijn <[email protected]>Reviewed-by Luigi Rizzo <[email protected]>
Documentation/networking/device_drivers/google/gve.rst line 62
Quoted 10 lines
Documentation/networking/device_drivers/google/gve.rst new file +10
-0+Admin Queue (AQ) +---------------- +The Admin Queue is a PAGE_SIZE memory block, treated as an array of AQ +commands, used by the driver to issue commands to the device and set up +resources.The driver and the device maintain a count of how many commands +have been submitted and executed. To issue AQ commands, the driver must do +the following (with proper locking): + +1) Copy new commands into next available slots in the AQ array +2) Increment its counter by he number of new commands
s/he/the/
Quoted 13 lines
+3) Write the counter into the
GVE_ADMIN_QUEUE_DOORBELLregister +4) Poll theADMIN_QUEUE_EVENT_COUNTERregister until it equalsdrivers/net/ethernet/google/gve/gve_adminq.c new file +10
-0+ the value written to the doorbell, or until a timeout. + +The device will update the status field in each AQ command reported as +executed through the ADMIN_QUEUE_EVENT_COUNTER register. + +/* This function is not threadsafe - the caller is responsible for any + * necessary locks. + */ +int gve_adminq_execute_cmd(struct gve_priv *priv, +union gve_adminq_command *cmd_orig)
drivers/net/ethernet/google/gve/gve_adminq.c line 138
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_adminq.c new file +10
-0+{ +union gve_adminq_command *cmd; +u32 status =0 ; +u32 prod_cnt; + + cmd = &priv->adminq[priv->adminq_prod_cnt & priv->adminq_mask]; + priv->adminq_prod_cnt++; + prod_cnt = priv->adminq_prod_cnt; + +memcpy (cmd, cmd_orig,sizeof (*cmd_orig));
Eh, I guess you don't even need memory barriers around the data movement to the DMA buffer because of the restriction to x86? :)
Quoted 36 lines
drivers/net/ethernet/google/gve/gve_adminq.c new file +34
-0+gve_adminq_kick_cmd (priv, prod_cnt); +if (!gve_adminq_wait_for_cmd (priv, prod_cnt)) { +dev_err (&priv->pdev->dev,"AQ command timed out, need to reset AQ\n" ); +return -ENOTRECOVERABLE ; + } +memcpy (cmd_orig, cmd,sizeof (*cmd)); + status =be32_to_cpu (READ_ONCE (cmd->status)); +return gve_adminq_parse_err (&priv->pdev->dev, status); +} +int gve_adminq_describe_device (struct gve_priv *priv) +{ +struct gve_device_descriptor *descriptor; +union gve_adminq_command cmd; +dma_addr_t descriptor_bus; +int err =0 ; +u8 *mac; +u16 mtu; + +memset (&cmd,0 ,sizeof (cmd)); + descriptor =dma_alloc_coherent (&priv->pdev->dev,PAGE_SIZE , + &descriptor_bus,GFP_KERNEL ); +if (!descriptor) +return -ENOMEM ; + cmd.opcode =cpu_to_be32 (GVE_ADMINQ_DESCRIBE_DEVICE ); + cmd.describe_device.device_descriptor_addr = +cpu_to_be64 (descriptor_bus); + cmd.describe_device.device_descriptor_version = +cpu_to_be32 (GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION ); + cmd.describe_device.available_length =cpu_to_be32 (PAGE_SIZE ); + + err =gve_adminq_execute_cmd (priv, &cmd); +if (err) + goto free_device_descriptor; +
drivers/net/ethernet/google/gve/gve_adminq.c line 227
Quoted 10 lines
drivers/net/ethernet/google/gve/gve_adminq.c new file +10
-0+ mtu =be16_to_cpu (descriptor->mtu); +if (mtu <ETH_MIN_MTU ) { +netif_err (priv, drv, priv->dev,"MTU %d below minimum MTU\n" , + mtu); + err = -EINVAL ; + goto free_device_descriptor; + } + priv->dev->max_mtu = mtu; + priv->num_event_counters =be16_to_cpu (descriptor->counters); +ether_addr_copy (priv->dev->dev_addr, descriptor->mac);
Since you check MTU you can check the address with is_valid_ether_addr().
Also it's common practice to copy the provisioned MAC to netdev->perm_addr as well as dev_addr for VFs.
drivers/net/ethernet/google/gve/gve_adminq.c line 235
Quoted 8 lines
drivers/net/ethernet/google/gve/gve_adminq.c new file +8
-0+ mac = descriptor->mac; +netif_info (priv, drv, priv->dev,"MAC addr: %pM\n" , mac); + +free_device_descriptor: +dma_free_coherent (&priv->pdev->dev,sizeof (*descriptor), descriptor, + descriptor_bus); +return err; +}
Oh, okay, David already applied..