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. Signed-off-by: Catherine Sullivan <csully@google.com> Signed-off-by: Sagi Shahar <sagis@google.com> Signed-off-by: Jon Olson <jonolson@google.com> Acked-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Luigi Rizzo <lrizzo@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
2a8d8e0fec
commit
893ce44df5
135
drivers/net/ethernet/google/gve/gve.h
Normal file
135
drivers/net/ethernet/google/gve/gve.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* SPDX-License-Identifier: (GPL-2.0 OR MIT)
|
||||
* Google virtual Ethernet (gve) driver
|
||||
*
|
||||
* Copyright (C) 2015-2019 Google, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _GVE_H_
|
||||
#define _GVE_H_
|
||||
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
#ifndef PCI_VENDOR_ID_GOOGLE
|
||||
#define PCI_VENDOR_ID_GOOGLE 0x1ae0
|
||||
#endif
|
||||
|
||||
#define PCI_DEV_ID_GVNIC 0x0042
|
||||
|
||||
#define GVE_REGISTER_BAR 0
|
||||
#define GVE_DOORBELL_BAR 2
|
||||
|
||||
/* 1 for management */
|
||||
#define GVE_MIN_MSIX 3
|
||||
|
||||
struct gve_notify_block {
|
||||
__be32 irq_db_index; /* idx into Bar2 - set by device, must be 1st */
|
||||
char name[IFNAMSIZ + 16]; /* name registered with the kernel */
|
||||
struct napi_struct napi; /* kernel napi struct for this block */
|
||||
struct gve_priv *priv;
|
||||
} ____cacheline_aligned;
|
||||
|
||||
struct gve_priv {
|
||||
struct net_device *dev;
|
||||
struct gve_notify_block *ntfy_blocks; /* array of num_ntfy_blks */
|
||||
dma_addr_t ntfy_block_bus;
|
||||
struct msix_entry *msix_vectors; /* array of num_ntfy_blks + 1 */
|
||||
char mgmt_msix_name[IFNAMSIZ + 16];
|
||||
u32 mgmt_msix_idx;
|
||||
__be32 *counter_array; /* array of num_event_counters */
|
||||
dma_addr_t counter_array_bus;
|
||||
|
||||
u16 num_event_counters;
|
||||
|
||||
u32 num_ntfy_blks; /* spilt between TX and RX so must be even */
|
||||
|
||||
struct gve_registers __iomem *reg_bar0; /* see gve_register.h */
|
||||
__be32 __iomem *db_bar2; /* "array" of doorbells */
|
||||
u32 msg_enable; /* level for netif* netdev print macros */
|
||||
struct pci_dev *pdev;
|
||||
|
||||
/* Admin queue - see gve_adminq.h*/
|
||||
union gve_adminq_command *adminq;
|
||||
dma_addr_t adminq_bus_addr;
|
||||
u32 adminq_mask; /* masks prod_cnt to adminq size */
|
||||
u32 adminq_prod_cnt; /* free-running count of AQ cmds executed */
|
||||
|
||||
unsigned long state_flags;
|
||||
};
|
||||
|
||||
enum gve_state_flags {
|
||||
GVE_PRIV_FLAGS_ADMIN_QUEUE_OK = BIT(1),
|
||||
GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK = BIT(2),
|
||||
GVE_PRIV_FLAGS_DEVICE_RINGS_OK = BIT(3),
|
||||
GVE_PRIV_FLAGS_NAPI_ENABLED = BIT(4),
|
||||
};
|
||||
|
||||
static inline bool gve_get_admin_queue_ok(struct gve_priv *priv)
|
||||
{
|
||||
return test_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_set_admin_queue_ok(struct gve_priv *priv)
|
||||
{
|
||||
set_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_clear_admin_queue_ok(struct gve_priv *priv)
|
||||
{
|
||||
clear_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline bool gve_get_device_resources_ok(struct gve_priv *priv)
|
||||
{
|
||||
return test_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_set_device_resources_ok(struct gve_priv *priv)
|
||||
{
|
||||
set_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_clear_device_resources_ok(struct gve_priv *priv)
|
||||
{
|
||||
clear_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline bool gve_get_device_rings_ok(struct gve_priv *priv)
|
||||
{
|
||||
return test_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_set_device_rings_ok(struct gve_priv *priv)
|
||||
{
|
||||
set_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_clear_device_rings_ok(struct gve_priv *priv)
|
||||
{
|
||||
clear_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline bool gve_get_napi_enabled(struct gve_priv *priv)
|
||||
{
|
||||
return test_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_set_napi_enabled(struct gve_priv *priv)
|
||||
{
|
||||
set_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags);
|
||||
}
|
||||
|
||||
static inline void gve_clear_napi_enabled(struct gve_priv *priv)
|
||||
{
|
||||
clear_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags);
|
||||
}
|
||||
|
||||
/* Returns the address of the ntfy_blocks irq doorbell
|
||||
*/
|
||||
static inline __be32 __iomem *gve_irq_doorbell(struct gve_priv *priv,
|
||||
struct gve_notify_block *block)
|
||||
{
|
||||
return &priv->db_bar2[be32_to_cpu(block->irq_db_index)];
|
||||
}
|
||||
#endif /* _GVE_H_ */
|
Reference in New Issue
Block a user