|
| 1 | +/* SPDX-License-Identifier: (GPL-2.0 OR MIT) |
| 2 | + * Google virtual Ethernet (gve) driver |
| 3 | + * |
| 4 | + * Copyright (C) 2015-2019 Google, Inc. |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef _GVE_H_ |
| 8 | +#define _GVE_H_ |
| 9 | + |
| 10 | +#include <linux/dma-mapping.h> |
| 11 | +#include <linux/netdevice.h> |
| 12 | +#include <linux/pci.h> |
| 13 | + |
| 14 | +#ifndef PCI_VENDOR_ID_GOOGLE |
| 15 | +#define PCI_VENDOR_ID_GOOGLE 0x1ae0 |
| 16 | +#endif |
| 17 | + |
| 18 | +#define PCI_DEV_ID_GVNIC 0x0042 |
| 19 | + |
| 20 | +#define GVE_REGISTER_BAR 0 |
| 21 | +#define GVE_DOORBELL_BAR 2 |
| 22 | + |
| 23 | +/* 1 for management */ |
| 24 | +#define GVE_MIN_MSIX 3 |
| 25 | + |
| 26 | +struct gve_notify_block { |
| 27 | + __be32 irq_db_index; /* idx into Bar2 - set by device, must be 1st */ |
| 28 | + char name[IFNAMSIZ + 16]; /* name registered with the kernel */ |
| 29 | + struct napi_struct napi; /* kernel napi struct for this block */ |
| 30 | + struct gve_priv *priv; |
| 31 | +} ____cacheline_aligned; |
| 32 | + |
| 33 | +struct gve_priv { |
| 34 | + struct net_device *dev; |
| 35 | + struct gve_notify_block *ntfy_blocks; /* array of num_ntfy_blks */ |
| 36 | + dma_addr_t ntfy_block_bus; |
| 37 | + struct msix_entry *msix_vectors; /* array of num_ntfy_blks + 1 */ |
| 38 | + char mgmt_msix_name[IFNAMSIZ + 16]; |
| 39 | + u32 mgmt_msix_idx; |
| 40 | + __be32 *counter_array; /* array of num_event_counters */ |
| 41 | + dma_addr_t counter_array_bus; |
| 42 | + |
| 43 | + u16 num_event_counters; |
| 44 | + |
| 45 | + u32 num_ntfy_blks; /* spilt between TX and RX so must be even */ |
| 46 | + |
| 47 | + struct gve_registers __iomem *reg_bar0; /* see gve_register.h */ |
| 48 | + __be32 __iomem *db_bar2; /* "array" of doorbells */ |
| 49 | + u32 msg_enable; /* level for netif* netdev print macros */ |
| 50 | + struct pci_dev *pdev; |
| 51 | + |
| 52 | + /* Admin queue - see gve_adminq.h*/ |
| 53 | + union gve_adminq_command *adminq; |
| 54 | + dma_addr_t adminq_bus_addr; |
| 55 | + u32 adminq_mask; /* masks prod_cnt to adminq size */ |
| 56 | + u32 adminq_prod_cnt; /* free-running count of AQ cmds executed */ |
| 57 | + |
| 58 | + unsigned long state_flags; |
| 59 | +}; |
| 60 | + |
| 61 | +enum gve_state_flags { |
| 62 | + GVE_PRIV_FLAGS_ADMIN_QUEUE_OK = BIT(1), |
| 63 | + GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK = BIT(2), |
| 64 | + GVE_PRIV_FLAGS_DEVICE_RINGS_OK = BIT(3), |
| 65 | + GVE_PRIV_FLAGS_NAPI_ENABLED = BIT(4), |
| 66 | +}; |
| 67 | + |
| 68 | +static inline bool gve_get_admin_queue_ok(struct gve_priv *priv) |
| 69 | +{ |
| 70 | + return test_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags); |
| 71 | +} |
| 72 | + |
| 73 | +static inline void gve_set_admin_queue_ok(struct gve_priv *priv) |
| 74 | +{ |
| 75 | + set_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags); |
| 76 | +} |
| 77 | + |
| 78 | +static inline void gve_clear_admin_queue_ok(struct gve_priv *priv) |
| 79 | +{ |
| 80 | + clear_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags); |
| 81 | +} |
| 82 | + |
| 83 | +static inline bool gve_get_device_resources_ok(struct gve_priv *priv) |
| 84 | +{ |
| 85 | + return test_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags); |
| 86 | +} |
| 87 | + |
| 88 | +static inline void gve_set_device_resources_ok(struct gve_priv *priv) |
| 89 | +{ |
| 90 | + set_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags); |
| 91 | +} |
| 92 | + |
| 93 | +static inline void gve_clear_device_resources_ok(struct gve_priv *priv) |
| 94 | +{ |
| 95 | + clear_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags); |
| 96 | +} |
| 97 | + |
| 98 | +static inline bool gve_get_device_rings_ok(struct gve_priv *priv) |
| 99 | +{ |
| 100 | + return test_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags); |
| 101 | +} |
| 102 | + |
| 103 | +static inline void gve_set_device_rings_ok(struct gve_priv *priv) |
| 104 | +{ |
| 105 | + set_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags); |
| 106 | +} |
| 107 | + |
| 108 | +static inline void gve_clear_device_rings_ok(struct gve_priv *priv) |
| 109 | +{ |
| 110 | + clear_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags); |
| 111 | +} |
| 112 | + |
| 113 | +static inline bool gve_get_napi_enabled(struct gve_priv *priv) |
| 114 | +{ |
| 115 | + return test_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags); |
| 116 | +} |
| 117 | + |
| 118 | +static inline void gve_set_napi_enabled(struct gve_priv *priv) |
| 119 | +{ |
| 120 | + set_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags); |
| 121 | +} |
| 122 | + |
| 123 | +static inline void gve_clear_napi_enabled(struct gve_priv *priv) |
| 124 | +{ |
| 125 | + clear_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags); |
| 126 | +} |
| 127 | + |
| 128 | +/* Returns the address of the ntfy_blocks irq doorbell |
| 129 | + */ |
| 130 | +static inline __be32 __iomem *gve_irq_doorbell(struct gve_priv *priv, |
| 131 | + struct gve_notify_block *block) |
| 132 | +{ |
| 133 | + return &priv->db_bar2[be32_to_cpu(block->irq_db_index)]; |
| 134 | +} |
| 135 | +#endif /* _GVE_H_ */ |
0 commit comments