Commit c4b87ac8 authored by Bailey Forrest's avatar Bailey Forrest Committed by David S. Miller

gve: Add support for DQO RX PTYPE map

Unlike GQI, DQO RX descriptors do not contain the L3 and L4 type of the
packet. L3 and L4 types are necessary in order to set the hash and csum
on RX SKBs correctly.

DQO RX descriptors instead contain a 10 bit PTYPE index. The PTYPE map
enables the device to tell the driver how to map from PTYPE index to
L3/L4 type.

The device doesn't provide any guarantees about the range of possible
PTYPEs, so we just use a 1024 entry array to implement a fast mapping
structure.
Signed-off-by: default avatarBailey Forrest <bcf@google.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Reviewed-by: default avatarCatherine Sullivan <csully@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5ca2265e
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/u64_stats_sync.h> #include <linux/u64_stats_sync.h>
#include "gve_desc.h" #include "gve_desc.h"
#ifndef PCI_VENDOR_ID_GOOGLE #ifndef PCI_VENDOR_ID_GOOGLE
...@@ -40,6 +41,9 @@ ...@@ -40,6 +41,9 @@
#define GVE_DATA_SLOT_ADDR_PAGE_MASK (~(PAGE_SIZE - 1)) #define GVE_DATA_SLOT_ADDR_PAGE_MASK (~(PAGE_SIZE - 1))
/* PTYPEs are always 10 bits. */
#define GVE_NUM_PTYPES 1024
/* Each slot in the desc ring has a 1:1 mapping to a slot in the data ring */ /* Each slot in the desc ring has a 1:1 mapping to a slot in the data ring */
struct gve_rx_desc_queue { struct gve_rx_desc_queue {
struct gve_rx_desc *desc_ring; /* the descriptor ring */ struct gve_rx_desc *desc_ring; /* the descriptor ring */
...@@ -199,6 +203,15 @@ struct gve_options_dqo_rda { ...@@ -199,6 +203,15 @@ struct gve_options_dqo_rda {
u16 rx_buff_ring_entries; /* number of rx_buff descriptors */ u16 rx_buff_ring_entries; /* number of rx_buff descriptors */
}; };
struct gve_ptype {
u8 l3_type; /* `gve_l3_type` in gve_adminq.h */
u8 l4_type; /* `gve_l4_type` in gve_adminq.h */
};
struct gve_ptype_lut {
struct gve_ptype ptypes[GVE_NUM_PTYPES];
};
/* GVE_QUEUE_FORMAT_UNSPECIFIED must be zero since 0 is the default value /* GVE_QUEUE_FORMAT_UNSPECIFIED must be zero since 0 is the default value
* when the entire configure_device_resources command is zeroed out and the * when the entire configure_device_resources command is zeroed out and the
* queue_format is not specified. * queue_format is not specified.
...@@ -266,6 +279,7 @@ struct gve_priv { ...@@ -266,6 +279,7 @@ struct gve_priv {
u32 adminq_set_driver_parameter_cnt; u32 adminq_set_driver_parameter_cnt;
u32 adminq_report_stats_cnt; u32 adminq_report_stats_cnt;
u32 adminq_report_link_speed_cnt; u32 adminq_report_link_speed_cnt;
u32 adminq_get_ptype_map_cnt;
/* Global stats */ /* Global stats */
u32 interface_up_cnt; /* count of times interface turned up since last reset */ u32 interface_up_cnt; /* count of times interface turned up since last reset */
...@@ -292,6 +306,7 @@ struct gve_priv { ...@@ -292,6 +306,7 @@ struct gve_priv {
u64 link_speed; u64 link_speed;
struct gve_options_dqo_rda options_dqo_rda; struct gve_options_dqo_rda options_dqo_rda;
struct gve_ptype_lut *ptype_lut_dqo;
enum gve_queue_format queue_format; enum gve_queue_format queue_format;
}; };
......
...@@ -176,6 +176,7 @@ int gve_adminq_alloc(struct device *dev, struct gve_priv *priv) ...@@ -176,6 +176,7 @@ int gve_adminq_alloc(struct device *dev, struct gve_priv *priv)
priv->adminq_set_driver_parameter_cnt = 0; priv->adminq_set_driver_parameter_cnt = 0;
priv->adminq_report_stats_cnt = 0; priv->adminq_report_stats_cnt = 0;
priv->adminq_report_link_speed_cnt = 0; priv->adminq_report_link_speed_cnt = 0;
priv->adminq_get_ptype_map_cnt = 0;
/* Setup Admin queue with the device */ /* Setup Admin queue with the device */
iowrite32be(priv->adminq_bus_addr / PAGE_SIZE, iowrite32be(priv->adminq_bus_addr / PAGE_SIZE,
...@@ -381,6 +382,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv, ...@@ -381,6 +382,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_REPORT_LINK_SPEED: case GVE_ADMINQ_REPORT_LINK_SPEED:
priv->adminq_report_link_speed_cnt++; priv->adminq_report_link_speed_cnt++;
break; break;
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
default: default:
dev_err(&priv->pdev->dev, "unknown AQ command opcode %d\n", opcode); dev_err(&priv->pdev->dev, "unknown AQ command opcode %d\n", opcode);
} }
...@@ -393,7 +397,8 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv, ...@@ -393,7 +397,8 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
* The caller is also responsible for making sure there are no commands * The caller is also responsible for making sure there are no commands
* waiting to be executed. * waiting to be executed.
*/ */
static int gve_adminq_execute_cmd(struct gve_priv *priv, union gve_adminq_command *cmd_orig) static int gve_adminq_execute_cmd(struct gve_priv *priv,
union gve_adminq_command *cmd_orig)
{ {
u32 tail, head; u32 tail, head;
int err; int err;
...@@ -827,3 +832,41 @@ int gve_adminq_report_link_speed(struct gve_priv *priv) ...@@ -827,3 +832,41 @@ int gve_adminq_report_link_speed(struct gve_priv *priv)
link_speed_region_bus); link_speed_region_bus);
return err; return err;
} }
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut)
{
struct gve_ptype_map *ptype_map;
union gve_adminq_command cmd;
dma_addr_t ptype_map_bus;
int err = 0;
int i;
memset(&cmd, 0, sizeof(cmd));
ptype_map = dma_alloc_coherent(&priv->pdev->dev, sizeof(*ptype_map),
&ptype_map_bus, GFP_KERNEL);
if (!ptype_map)
return -ENOMEM;
cmd.opcode = cpu_to_be32(GVE_ADMINQ_GET_PTYPE_MAP);
cmd.get_ptype_map = (struct gve_adminq_get_ptype_map) {
.ptype_map_len = cpu_to_be64(sizeof(*ptype_map)),
.ptype_map_addr = cpu_to_be64(ptype_map_bus),
};
err = gve_adminq_execute_cmd(priv, &cmd);
if (err)
goto err;
/* Populate ptype_lut. */
for (i = 0; i < GVE_NUM_PTYPES; i++) {
ptype_lut->ptypes[i].l3_type =
ptype_map->ptypes[i].l3_type;
ptype_lut->ptypes[i].l4_type =
ptype_map->ptypes[i].l4_type;
}
err:
dma_free_coherent(&priv->pdev->dev, sizeof(*ptype_map), ptype_map,
ptype_map_bus);
return err;
}
...@@ -22,7 +22,8 @@ enum gve_adminq_opcodes { ...@@ -22,7 +22,8 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES = 0x9, GVE_ADMINQ_DECONFIGURE_DEVICE_RESOURCES = 0x9,
GVE_ADMINQ_SET_DRIVER_PARAMETER = 0xB, GVE_ADMINQ_SET_DRIVER_PARAMETER = 0xB,
GVE_ADMINQ_REPORT_STATS = 0xC, GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
}; };
/* Admin queue status codes */ /* Admin queue status codes */
...@@ -266,6 +267,41 @@ enum gve_stat_names { ...@@ -266,6 +267,41 @@ enum gve_stat_names {
RX_DROPS_INVALID_CHECKSUM = 68, RX_DROPS_INVALID_CHECKSUM = 68,
}; };
enum gve_l3_type {
/* Must be zero so zero initialized LUT is unknown. */
GVE_L3_TYPE_UNKNOWN = 0,
GVE_L3_TYPE_OTHER,
GVE_L3_TYPE_IPV4,
GVE_L3_TYPE_IPV6,
};
enum gve_l4_type {
/* Must be zero so zero initialized LUT is unknown. */
GVE_L4_TYPE_UNKNOWN = 0,
GVE_L4_TYPE_OTHER,
GVE_L4_TYPE_TCP,
GVE_L4_TYPE_UDP,
GVE_L4_TYPE_ICMP,
GVE_L4_TYPE_SCTP,
};
/* These are control path types for PTYPE which are the same as the data path
* types.
*/
struct gve_ptype_entry {
u8 l3_type;
u8 l4_type;
};
struct gve_ptype_map {
struct gve_ptype_entry ptypes[1 << 10]; /* PTYPES are always 10 bits. */
};
struct gve_adminq_get_ptype_map {
__be64 ptype_map_len;
__be64 ptype_map_addr;
};
union gve_adminq_command { union gve_adminq_command {
struct { struct {
__be32 opcode; __be32 opcode;
...@@ -283,6 +319,7 @@ union gve_adminq_command { ...@@ -283,6 +319,7 @@ union gve_adminq_command {
struct gve_adminq_set_driver_parameter set_driver_param; struct gve_adminq_set_driver_parameter set_driver_param;
struct gve_adminq_report_stats report_stats; struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed; struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
}; };
}; };
u8 reserved[64]; u8 reserved[64];
...@@ -311,4 +348,9 @@ int gve_adminq_set_mtu(struct gve_priv *priv, u64 mtu); ...@@ -311,4 +348,9 @@ int gve_adminq_set_mtu(struct gve_priv *priv, u64 mtu);
int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len, int gve_adminq_report_stats(struct gve_priv *priv, u64 stats_report_len,
dma_addr_t stats_report_addr, u64 interval); dma_addr_t stats_report_addr, u64 interval);
int gve_adminq_report_link_speed(struct gve_priv *priv); int gve_adminq_report_link_speed(struct gve_priv *priv);
struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
#endif /* _GVE_ADMINQ_H */ #endif /* _GVE_ADMINQ_H */
...@@ -346,6 +346,22 @@ static int gve_setup_device_resources(struct gve_priv *priv) ...@@ -346,6 +346,22 @@ static int gve_setup_device_resources(struct gve_priv *priv)
err = -ENXIO; err = -ENXIO;
goto abort_with_stats_report; goto abort_with_stats_report;
} }
if (priv->queue_format == GVE_DQO_RDA_FORMAT) {
priv->ptype_lut_dqo = kvzalloc(sizeof(*priv->ptype_lut_dqo),
GFP_KERNEL);
if (!priv->ptype_lut_dqo) {
err = -ENOMEM;
goto abort_with_stats_report;
}
err = gve_adminq_get_ptype_map_dqo(priv, priv->ptype_lut_dqo);
if (err) {
dev_err(&priv->pdev->dev,
"Failed to get ptype map: err=%d\n", err);
goto abort_with_ptype_lut;
}
}
err = gve_adminq_report_stats(priv, priv->stats_report_len, err = gve_adminq_report_stats(priv, priv->stats_report_len,
priv->stats_report_bus, priv->stats_report_bus,
GVE_STATS_REPORT_TIMER_PERIOD); GVE_STATS_REPORT_TIMER_PERIOD);
...@@ -354,12 +370,17 @@ static int gve_setup_device_resources(struct gve_priv *priv) ...@@ -354,12 +370,17 @@ static int gve_setup_device_resources(struct gve_priv *priv)
"Failed to report stats: err=%d\n", err); "Failed to report stats: err=%d\n", err);
gve_set_device_resources_ok(priv); gve_set_device_resources_ok(priv);
return 0; return 0;
abort_with_ptype_lut:
kvfree(priv->ptype_lut_dqo);
priv->ptype_lut_dqo = NULL;
abort_with_stats_report: abort_with_stats_report:
gve_free_stats_report(priv); gve_free_stats_report(priv);
abort_with_ntfy_blocks: abort_with_ntfy_blocks:
gve_free_notify_blocks(priv); gve_free_notify_blocks(priv);
abort_with_counter: abort_with_counter:
gve_free_counter_array(priv); gve_free_counter_array(priv);
return err; return err;
} }
...@@ -386,6 +407,10 @@ static void gve_teardown_device_resources(struct gve_priv *priv) ...@@ -386,6 +407,10 @@ static void gve_teardown_device_resources(struct gve_priv *priv)
gve_trigger_reset(priv); gve_trigger_reset(priv);
} }
} }
kvfree(priv->ptype_lut_dqo);
priv->ptype_lut_dqo = NULL;
gve_free_counter_array(priv); gve_free_counter_array(priv);
gve_free_notify_blocks(priv); gve_free_notify_blocks(priv);
gve_free_stats_report(priv); gve_free_stats_report(priv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment