Skip to contentSkip to conversation

GVE Raw Addressing

PATCH Superseded David Awogbemila 5 participants 11 messages Nov 18, 2020 – Nov 20, 2020

Subsystems (3)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover GVE Raw Addressing

Patch 1: Use u8 instead of bool for raw_addressing bit in gve_priv structure.
Simplify pointer arithmetic: use (option + 1) in gve_get_next_option. Separate option parsing switch statement into individual function.
Patch 2: Use u8 instead of bool for raw_addressing bit in gve_gve_rx_data_queue structure.
Correct typo in gve_desc.h comment (s/than/then/).
Change gve_rx_data_slot from struct to union.
Remove dma_mapping_error path change in gve_alloc_page - it should probably be a bug fix.
Use & to obtain page address from data_ring->addr.
Move declarations of local variables i and slots to if statement where they are used within gve_rx_unfill_pages.
Simplify alloc_err path by using "while(i--)", eliminating need for extra "int j" variable in gve_prefill_rx_pages.
Apply byteswap to constant in gve_rx_flip_buff.
Remove gve_rx_raw_addressing as it does not do much more than gve_rx_add_frags. Remove stats update from elseif block, no need to optimize for infrequent case of work_done = 0.
Patch 3: Use u8 instead of bool for can_flip in gve_rx_slot_page_info.
Move comment in gve_rx_flip_buff to earlier, more relevant patch. Fix comment wrap in gve_rx_can_flip_buffers.
Use ternary statement for gve_rx_can_flip_buffers.
Correct comment in gve_rx_qpl.
Patch 4: Use u8 instead of bool in gve_tx_ring structure.
Get rid of unnecessary local variable "dma" in gve_dma_sync_for_device.

Catherine Sullivan (3):
gve: Add support for raw addressing device option
gve: Add support for raw addressing to the rx path
gve: Add support for raw addressing in the tx path

David Awogbemila (1):
gve: Rx Buffer Recycling

 drivers/net/ethernet/google/gve/gve.h        |  38 +-
 drivers/net/ethernet/google/gve/gve_adminq.c |  90 ++++-
 drivers/net/ethernet/google/gve/gve_adminq.h |  15 +-
 drivers/net/ethernet/google/gve/gve_desc.h   |  19 +-
 drivers/net/ethernet/google/gve/gve_main.c   |  11 +-
 drivers/net/ethernet/google/gve/gve_rx.c     | 403 ++++++++++++++-----
 drivers/net/ethernet/google/gve/gve_tx.c     | 211 ++++++++--
 7 files changed, 620 insertions(+), 167 deletions(-)
Signature · 1 line
2.29.2.299.gdc1121823c-goog
#1 lore raw

PATCH v7 1/4 gve: Add support for raw addressing device option

From: Catherine Sullivan <[email protected]>

Add support to describe device for parsing device options. As the first device option, add raw addressing.

"Raw Addressing" mode (as opposed to the current "qpl" mode) is an operational mode which allows the driver avoid bounce buffer copies which it currently performs using pre-allocated qpls (queue_page_lists) when sending and receiving packets.
For egress packets, the provided skb data addresses will be dma_map'ed and passed to the device, allowing the NIC can perform DMA directly - the driver will not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
For ingress packets, copies are also eliminated as buffers are handed to the networking stack and then recycled or re-allocated as necessary, avoiding the use of skb_copy_to_linear_data().

This patch only introduces the option to the driver. Subsequent patches will add the ingress and egress functionality.

---
 drivers/net/ethernet/google/gve/gve.h        |  1 +
 drivers/net/ethernet/google/gve/gve_adminq.c | 71 ++++++++++++++++++++
 drivers/net/ethernet/google/gve/gve_adminq.h | 15 +++--
 drivers/net/ethernet/google/gve/gve_main.c   |  9 +++
 4 files changed, 92 insertions(+), 4 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -0
index f5c80229ea96..782e2791ee11 100644
@@ -199,6 +199,7 @@ struct gve_priv {
 	u64 num_registered_pages; /* num pages registered with NIC */
 	u32 rx_copybreak; /* copy packets smaller than this */
 	u16 default_num_queues; /* default num queues to set up */
+	u8 raw_addressing; /* 1 if this dev supports raw addressing, 0 otherwise */
 
 	struct gve_queue_config tx_cfg;
 	struct gve_queue_config rx_cfg;
drivers/net/ethernet/google/gve/gve_adminq.c +71 -0

94 lines not on this page · raw message

drivers/net/ethernet/google/gve/gve_adminq.h +11 -4
index 281de8326bc5..af5f586167bd 100644
@@ -79,12 +79,17 @@ struct gve_device_descriptor {
 
 static_assert(sizeof(struct gve_device_descriptor) == 40);
 
-struct device_option {
-	__be32 option_id;
-	__be32 option_length;
+struct gve_device_option {
+	__be16 option_id;
+	__be16 option_length;
+	__be32 feat_mask;
 };
 
-static_assert(sizeof(struct device_option) == 8);
+static_assert(sizeof(struct gve_device_option) == 8);
+
+#define GVE_DEV_OPT_ID_RAW_ADDRESSING 0x1
+#define GVE_DEV_OPT_LEN_RAW_ADDRESSING 0x0
+#define GVE_DEV_OPT_FEAT_MASK_RAW_ADDRESSING 0x0
 
 struct gve_adminq_configure_device_resources {
 	__be64 counter_array;
@@ -111,6 +116,8 @@ struct gve_adminq_unregister_page_list {
 
 static_assert(sizeof(struct gve_adminq_unregister_page_list) == 4);
 
+#define GVE_RAW_ADDRESSING_QPL_ID 0xFFFFFFFF
+
 struct gve_adminq_create_tx_queue {
 	__be32 queue_id;
 	__be32 reserved;
drivers/net/ethernet/google/gve/gve_main.c +9 -0
index 48a433154ce0..70685c10db0e 100644
@@ -678,6 +678,10 @@ static int gve_alloc_qpls(struct gve_priv *priv)
 	int i, j;
 	int err;
 
+	/* Raw addressing means no QPLs */
+	if (priv->raw_addressing)
+		return 0;
+
 	priv->qpls = kvzalloc(num_qpls * sizeof(*priv->qpls), GFP_KERNEL);
 	if (!priv->qpls)
 		return -ENOMEM;
@@ -718,6 +722,10 @@ static void gve_free_qpls(struct gve_priv *priv)
 	int num_qpls = gve_num_tx_qpls(priv) + gve_num_rx_qpls(priv);
 	int i;
 
+	/* Raw addressing means no QPLs */
+	if (priv->raw_addressing)
+		return;
+
 	kvfree(priv->qpl_cfg.qpl_id_map);
 
 	for (i = 0; i < num_qpls; i++)
@@ -1078,6 +1086,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
 	if (skip_describe_device)
 		goto setup_device;
 
+	priv->raw_addressing = false;
 	/* Get the initial information we need from the device */
 	err = gve_adminq_describe_device(priv);
 	if (err) {
Signature · 1 line
2.29.2.299.gdc1121823c-goog
#2 lore raw

Re: [PATCH net-next v7 1/4] gve: Add support for raw addressing device option

Quoted 28 lines · David Awogbemila

From: Catherine Sullivan <[email protected]>

Add support to describe device for parsing device options. As the first device option, add raw addressing.

"Raw Addressing" mode (as opposed to the current "qpl" mode) is an operational mode which allows the driver avoid bounce buffer copies which it currently performs using pre-allocated qpls (queue_page_lists)
when sending and receiving packets.
For egress packets, the provided skb data addresses will be dma_map'ed and
passed to the device, allowing the NIC can perform DMA directly - the driver will not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
For ingress packets, copies are also eliminated as buffers are handed to
the networking stack and then recycled or re-allocated as necessary, avoiding the use of skb_copy_to_linear_data().

This patch only introduces the option to the driver. Subsequent patches will add the ingress and egress functionality.

---

...

Quoted 6 lines
drivers/net/ethernet/google/gve/gve_adminq.c +0 -0
index 24ae6a28a806..1e2d407cb9d2 100644

drivers/net/ethernet/google/gve/gve_adminq.c line 23

Quoted 10 lines
drivers/net/ethernet/google/gve/gve_adminq.c +6 -0
@@ -14,6 +14,57 @@
 #define GVE_ADMINQ_SLEEP_LEN		20
 #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK	100
 
+#define GVE_DEVICE_OPTION_ERROR_FMT "%s option error:\n" \
+"Expected: length=%d, feature_mask=%x.\n" \
+"Actual: length=%d, feature_mask=%x.\n"
+
+static inline
+struct gve_device_option *gve_get_next_option(struct
 

Following Dave's policy, no static inline functions in C files. This is control path so you don't really need the inline here.

#3 lore raw

Re: [PATCH net-next v7 1/4] gve: Add support for raw addressing device option

Quoted 40 lines · Saeed Mahameed
Quoted 28 lines · David Awogbemila

From: Catherine Sullivan <[email protected]>

Add support to describe device for parsing device options. As the first device option, add raw addressing.

"Raw Addressing" mode (as opposed to the current "qpl" mode) is an operational mode which allows the driver avoid bounce buffer copies which it currently performs using pre-allocated qpls (queue_page_lists)
when sending and receiving packets.
For egress packets, the provided skb data addresses will be dma_map'ed and
passed to the device, allowing the NIC can perform DMA directly - the driver will not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
For ingress packets, copies are also eliminated as buffers are handed to
the networking stack and then recycled or re-allocated as necessary, avoiding the use of skb_copy_to_linear_data().

This patch only introduces the option to the driver. Subsequent patches will add the ingress and egress functionality.

---

...

Quoted 9 lines
drivers/net/ethernet/google/gve/gve_adminq.c +0 -0
index 24ae6a28a806..1e2d407cb9d2 100644
@@ -14,6 +14,57 @@
 #define GVE_ADMINQ_SLEEP_LEN         20
 #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK   100
 
Quoted 10 lines

drivers/net/ethernet/google/gve/gve_adminq.c

Quoted 7 lines
drivers/net/ethernet/google/gve/gve_adminq.c +6 -0
+#define GVE_DEVICE_OPTION_ERROR_FMT "%s option error:\n" \
+"Expected: length=%d, feature_mask=%x.\n" \
+"Actual: length=%d, feature_mask=%x.\n"
+
+static inline
+struct gve_device_option *gve_get_next_option(struct
 

Following Dave's policy, no static inline functions in C files. This is control path so you don't really need the inline here.

Okay, I'll move it to a header file.

Quoted 3 lines
#4 lore raw

Re: [PATCH net-next v7 1/4] gve: Add support for raw addressing device option

Quoted 52 lines · David Awogbemila
Quoted 40 lines · Saeed Mahameed
Quoted 28 lines · David Awogbemila

From: Catherine Sullivan <[email protected]>

Add support to describe device for parsing device options. As the first device option, add raw addressing.

"Raw Addressing" mode (as opposed to the current "qpl" mode) is an operational mode which allows the driver avoid bounce buffer copies which it currently performs using pre-allocated qpls (queue_page_lists)
when sending and receiving packets.
For egress packets, the provided skb data addresses will be dma_map'ed and
passed to the device, allowing the NIC can perform DMA directly - the driver will not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
For ingress packets, copies are also eliminated as buffers are handed to
the networking stack and then recycled or re-allocated as necessary, avoiding the use of skb_copy_to_linear_data().

This patch only introduces the option to the driver. Subsequent patches will add the ingress and egress functionality.

---

...

Quoted 9 lines
drivers/net/ethernet/google/gve/gve_adminq.c +0 -0
index 24ae6a28a806..1e2d407cb9d2 100644
@@ -14,6 +14,57 @@
 #define GVE_ADMINQ_SLEEP_LEN         20
 #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK   100
 
Quoted 10 lines

drivers/net/ethernet/google/gve/gve_adminq.c

Quoted 7 lines
drivers/net/ethernet/google/gve/gve_adminq.c +6 -0
+#define GVE_DEVICE_OPTION_ERROR_FMT "%s option error:\n" \
+"Expected: length=%d, feature_mask=%x.\n" \
+"Actual: length=%d, feature_mask=%x.\n"
+
+static inline
+struct gve_device_option *gve_get_next_option(struct
 

Following Dave's policy, no static inline functions in C files. This is control path so you don't really need the inline here.

Quoted 1 line

Okay, I'll move it to a header file.

That's not what Saeed meant I suppose. Policy says that we let the compiler to make the decision whether or not such static function should be inlined. And since it's not a performance critical path as Saeed says then drop the inline and keep the rest as-is.

Quoted 4 lines
Quoted 4 lines
#5 lore raw

Re: [PATCH net-next v7 1/4] gve: Add support for raw addressing device option

Quoted 54 lines · Maciej Fijalkowski
Quoted 52 lines · David Awogbemila
Quoted 50 lines · Saeed Mahameed
Quoted 28 lines · David Awogbemila

From: Catherine Sullivan <[email protected]>

Add support to describe device for parsing device options. As the first device option, add raw addressing.

"Raw Addressing" mode (as opposed to the current "qpl" mode) is an operational mode which allows the driver avoid bounce buffer copies which it currently performs using pre-allocated qpls (queue_page_lists)
when sending and receiving packets.
For egress packets, the provided skb data addresses will be dma_map'ed and
passed to the device, allowing the NIC can perform DMA directly - the driver will not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).
For ingress packets, copies are also eliminated as buffers are handed to
the networking stack and then recycled or re-allocated as necessary, avoiding the use of skb_copy_to_linear_data().

This patch only introduces the option to the driver. Subsequent patches will add the ingress and egress functionality.

---

...

Quoted 6 lines
drivers/net/ethernet/google/gve/gve_adminq.c +0 -0
index 24ae6a28a806..1e2d407cb9d2 100644

drivers/net/ethernet/google/gve/gve_adminq.c line 23

Quoted 10 lines
drivers/net/ethernet/google/gve/gve_adminq.c +6 -0
@@ -14,6 +14,57 @@
 #define GVE_ADMINQ_SLEEP_LEN         20
 #define GVE_MAX_ADMINQ_EVENT_COUNTER_CHECK   100
 
+#define GVE_DEVICE_OPTION_ERROR_FMT "%s option error:\n" \
+"Expected: length=%d, feature_mask=%x.\n" \
+"Actual: length=%d, feature_mask=%x.\n"
+
+static inline
+struct gve_device_option *gve_get_next_option(struct
 

Following Dave's policy, no static inline functions in C files. This is control path so you don't really need the inline here.

Quoted 6 lines
Quoted 1 line

Okay, I'll move it to a header file.

That's not what Saeed meant I suppose. Policy says that we let the compiler to make the decision whether or not such static function should be inlined. And since it's not a performance critical path as Saeed says then drop the inline and keep the rest as-is.

Oh I see, thanks for the clarification, I was going to remove the inline keyword and move it to a header file but I see now that I can just remove the inline keyword. thanks.

#6 lore raw

PATCH v7 2/4 gve: Add support for raw addressing to the rx path

In reply to David Awogbemila

From: Catherine Sullivan <[email protected]>

Add support to use raw dma addresses in the rx path. Due to this new support we can alloc a new buffer instead of making a copy.

RX buffers are handed to the networking stack and are re-allocated as needed, avoiding the need to use skb_copy_to_linear_data() as in "qpl" mode.

---
 drivers/net/ethernet/google/gve/gve.h        |  12 +-
 drivers/net/ethernet/google/gve/gve_adminq.c |  14 +-
 drivers/net/ethernet/google/gve/gve_desc.h   |  11 +-
 drivers/net/ethernet/google/gve/gve_main.c   |   2 +-
 drivers/net/ethernet/google/gve/gve_rx.c     | 206 ++++++++++++++-----
 5 files changed, 183 insertions(+), 62 deletions(-)
drivers/net/ethernet/google/gve/gve.h +8 -4
index 782e2791ee11..d8bba0ba34e3 100644
@@ -38,6 +38,8 @@
 #define NIC_TX_STATS_REPORT_NUM	0
 #define NIC_RX_STATS_REPORT_NUM	4
 
+#define GVE_DATA_SLOT_ADDR_PAGE_MASK (~(PAGE_SIZE - 1))
+
 /* 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 *desc_ring; /* the descriptor ring */
@@ -49,7 +51,7 @@ struct gve_rx_desc_queue {
 struct gve_rx_slot_page_info {
 	struct page *page;
 	void *page_address;
-	u32 page_offset; /* offset to write to in page */
+	u8 page_offset; /* flipped to second half? */
 };
 
 /* A list of pages registered with the device during setup and used by a queue
@@ -64,10 +66,11 @@ struct gve_queue_page_list {
 
 /* Each slot in the data ring has a 1:1 mapping to a slot in the desc ring */
 struct gve_rx_data_queue {
-	struct gve_rx_data_slot *data_ring; /* read by NIC */
+	union gve_rx_data_slot *data_ring; /* read by NIC */
 	dma_addr_t data_bus; /* dma mapping of the slots */
 	struct gve_rx_slot_page_info *page_info; /* page info of the buffers */
 	struct gve_queue_page_list *qpl; /* qpl assigned to this queue */
+	u8 raw_addressing; /* use raw_addressing? */
 };
 
 struct gve_priv;
@@ -82,6 +85,7 @@ struct gve_rx_ring {
 	u32 cnt; /* free-running total number of completed packets */
 	u32 fill_cnt; /* free-running total number of descs and buffs posted */
 	u32 mask; /* masks the cnt and fill_cnt to the size of the ring */
+	u32 db_threshold; /* threshold for posting new buffs and descs */
 	u64 rx_copybreak_pkt; /* free-running count of copybreak packets */
 	u64 rx_copied_pkt; /* free-running total number of copied packets */
 	u64 rx_skb_alloc_fail; /* free-running count of skb alloc fails */
@@ -194,7 +198,7 @@ struct gve_priv {
 	u16 tx_desc_cnt; /* num desc per ring */
 	u16 rx_desc_cnt; /* num desc per ring */
 	u16 tx_pages_per_qpl; /* tx buffer length */
-	u16 rx_pages_per_qpl; /* rx buffer length */
+	u16 rx_data_slot_cnt; /* rx buffer length */
 	u64 max_registered_pages;
 	u64 num_registered_pages; /* num pages registered with NIC */
 	u32 rx_copybreak; /* copy packets smaller than this */
@@ -444,7 +448,7 @@ static inline u32 gve_num_tx_qpls(struct gve_priv *priv)
  */
 static inline u32 gve_num_rx_qpls(struct gve_priv *priv)
 {
-	return priv->rx_cfg.num_queues;
+	return priv->raw_addressing ? 0 : priv->rx_cfg.num_queues;
 }
 
 /* Returns a pointer to the next available tx qpl in the list of qpls
drivers/net/ethernet/google/gve/gve_adminq.c +8 -6
index 1e2d407cb9d2..738dc7f9dd9c 100644
@@ -408,8 +408,10 @@ static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
 {
 	struct gve_rx_ring *rx = &priv->rx[queue_index];
 	union gve_adminq_command cmd;
+	u32 qpl_id;
 	int err;
 
+	qpl_id = priv->raw_addressing ? GVE_RAW_ADDRESSING_QPL_ID : rx->data.qpl->id;
 	memset(&cmd, 0, sizeof(cmd));
 	cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_RX_QUEUE);
 	cmd.create_rx_queue = (struct gve_adminq_create_rx_queue) {
@@ -420,7 +422,7 @@ static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
 		.queue_resources_addr = cpu_to_be64(rx->q_resources_bus),
 		.rx_desc_ring_addr = cpu_to_be64(rx->desc.bus),
 		.rx_data_ring_addr = cpu_to_be64(rx->data.data_bus),
-		.queue_page_list_id = cpu_to_be32(rx->data.qpl->id),
+		.queue_page_list_id = cpu_to_be32(qpl_id),
 	};
 
 	err = gve_adminq_issue_cmd(priv, &cmd);
@@ -565,11 +567,11 @@ int gve_adminq_describe_device(struct gve_priv *priv)
 	mac = descriptor->mac;
 	dev_info(&priv->pdev->dev, "MAC addr: %pM\n", mac);
 	priv->tx_pages_per_qpl = be16_to_cpu(descriptor->tx_pages_per_qpl);
-	priv->rx_pages_per_qpl = be16_to_cpu(descriptor->rx_pages_per_qpl);
-	if (priv->rx_pages_per_qpl < priv->rx_desc_cnt) {
-		dev_err(&priv->pdev->dev, "rx_pages_per_qpl cannot be smaller than rx_desc_cnt, setting rx_desc_cnt down to %d.\n",
-			priv->rx_pages_per_qpl);
-		priv->rx_desc_cnt = priv->rx_pages_per_qpl;
+	priv->rx_data_slot_cnt = be16_to_cpu(descriptor->rx_pages_per_qpl);
+	if (priv->rx_data_slot_cnt < priv->rx_desc_cnt) {
+		dev_err(&priv->pdev->dev, "rx_data_slot_cnt cannot be smaller than rx_desc_cnt, setting rx_desc_cnt down to %d.\n",
+			priv->rx_data_slot_cnt);
+		priv->rx_desc_cnt = priv->rx_data_slot_cnt;
 	}
 	priv->default_num_queues = be16_to_cpu(descriptor->default_num_queues);
 	dev_opt = (void *)(descriptor + 1);
drivers/net/ethernet/google/gve/gve_desc.h +7 -4
index 54779871d52e..a1c0aaa60139 100644
@@ -72,12 +72,15 @@ struct gve_rx_desc {
 } __packed;
 static_assert(sizeof(struct gve_rx_desc) == 64);
 
-/* As with the Tx ring format, the qpl_offset entries below are offsets into an
- * ordered list of registered pages.
+/* If the device supports raw dma addressing then the addr in data slot is
+ * the dma address of the buffer.
+ * If the device only supports registered segments then the addr is a byte
+ * offset into the registered segment (an ordered list of pages) where the
+ * buffer is.
  */
-struct gve_rx_data_slot {
-	/* byte offset into the rx registered segment of this slot */
+union gve_rx_data_slot {
 	__be64 qpl_offset;
+	__be64 addr;
 };
 
 /* GVE Recive Packet Descriptor Seq No */
drivers/net/ethernet/google/gve/gve_main.c +1 -1
index 70685c10db0e..b7dae4f7b2fd 100644
@@ -694,7 +694,7 @@ static int gve_alloc_qpls(struct gve_priv *priv)
 	}
 	for (; i < num_qpls; i++) {
 		err = gve_alloc_queue_page_list(priv, i,
-						priv->rx_pages_per_qpl);
+						priv->rx_data_slot_cnt);
 		if (err)
 			goto free_qpls;
 	}
drivers/net/ethernet/google/gve/gve_rx.c +159 -47

381 lines not on this page · raw message

Signature · 1 line
2.29.2.299.gdc1121823c-goog
#7 lore raw

PATCH v7 3/4 gve: Rx Buffer Recycling

In reply to David Awogbemila

This patch lets the driver reuse buffers that have been freed by the networking stack.

In the raw addressing case, this allows the driver avoid allocating new buffers.
In the qpl case, the driver can avoid copies.

---
 drivers/net/ethernet/google/gve/gve.h    |  10 +-
 drivers/net/ethernet/google/gve/gve_rx.c | 198 +++++++++++++++--------
 2 files changed, 134 insertions(+), 74 deletions(-)
drivers/net/ethernet/google/gve/gve.h +1 -9
index d8bba0ba34e3..8aad4af2aa2b 100644
@@ -52,6 +52,7 @@ struct gve_rx_slot_page_info {
 	struct page *page;
 	void *page_address;
 	u8 page_offset; /* flipped to second half? */
+	u8 can_flip;
 };
 
 /* A list of pages registered with the device during setup and used by a queue
@@ -502,15 +503,6 @@ static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,
 		return DMA_FROM_DEVICE;
 }
 
-/* Returns true if the max mtu allows page recycling */
-static inline bool gve_can_recycle_pages(struct net_device *dev)
-{
-	/* We can't recycle the pages if we can't fit a packet into half a
-	 * page.
-	 */
-	return dev->max_mtu <= PAGE_SIZE / 2;
-}
-
 /* buffers */
 int gve_alloc_page(struct gve_priv *priv, struct device *dev,
 		   struct page **page, dma_addr_t *dma,
drivers/net/ethernet/google/gve/gve_rx.c +133 -65

243 lines not on this page · raw message

Signature · 1 line
2.29.2.299.gdc1121823c-goog
#8 lore raw

PATCH v7 4/4 gve: Add support for raw addressing in the tx path

In reply to David Awogbemila

From: Catherine Sullivan <[email protected]>

During TX, skbs' data addresses are dma_map'ed and passed to the NIC. This means that the device can perform DMA directly from these addresses and the driver does not have to copy the buffer content into pre-allocated buffers/qpls (as in qpl mode).

---
 drivers/net/ethernet/google/gve/gve.h        |  15 +-
 drivers/net/ethernet/google/gve/gve_adminq.c |   4 +-
 drivers/net/ethernet/google/gve/gve_desc.h   |   8 +-
 drivers/net/ethernet/google/gve/gve_tx.c     | 209 +++++++++++++++----
 4 files changed, 189 insertions(+), 47 deletions(-)
drivers/net/ethernet/google/gve/gve.h +13 -2
index 8aad4af2aa2b..8768f486b942 100644
@@ -112,12 +112,20 @@ struct gve_tx_iovec {
 	u32 iov_padding; /* padding associated with this segment */
 };
 
+struct gve_tx_dma_buf {
+	DEFINE_DMA_UNMAP_ADDR(dma);
+	DEFINE_DMA_UNMAP_LEN(len);
+};
+
 /* Tracks the memory in the fifo occupied by the skb. Mapped 1:1 to a desc
  * ring entry but only used for a pkt_desc not a seg_desc
  */
 struct gve_tx_buffer_state {
 	struct sk_buff *skb; /* skb for this pkt */
-	struct gve_tx_iovec iov[GVE_TX_MAX_IOVEC]; /* segments of this pkt */
+	union {
+		struct gve_tx_iovec iov[GVE_TX_MAX_IOVEC]; /* segments of this pkt */
+		struct gve_tx_dma_buf buf;
+	};
 };
 
 /* A TX buffer - each queue has one */
@@ -140,13 +148,16 @@ struct gve_tx_ring {
 	__be32 last_nic_done ____cacheline_aligned; /* NIC tail pointer */
 	u64 pkt_done; /* free-running - total packets completed */
 	u64 bytes_done; /* free-running - total bytes completed */
+	u32 dropped_pkt; /* free-running - total packets dropped */
 
 	/* Cacheline 2 -- Read-mostly fields */
 	union gve_tx_desc *desc ____cacheline_aligned;
 	struct gve_tx_buffer_state *info; /* Maps 1:1 to a desc */
 	struct netdev_queue *netdev_txq;
 	struct gve_queue_resources *q_resources; /* head and tail pointer idx */
+	struct device *dev;
 	u32 mask; /* masks req and done down to queue size */
+	u8 raw_addressing; /* use raw_addressing? */
 
 	/* Slow-path fields */
 	u32 q_num ____cacheline_aligned; /* queue idx */
@@ -442,7 +453,7 @@ static inline u32 gve_rx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx)
  */
 static inline u32 gve_num_tx_qpls(struct gve_priv *priv)
 {
-	return priv->tx_cfg.num_queues;
+	return priv->raw_addressing ? 0 : priv->tx_cfg.num_queues;
 }
 
 /* Returns the number of rx queue page lists
drivers/net/ethernet/google/gve/gve_adminq.c +3 -1
index 738dc7f9dd9c..66c90eac3ecd 100644
@@ -369,8 +369,10 @@ static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index)
 {
 	struct gve_tx_ring *tx = &priv->tx[queue_index];
 	union gve_adminq_command cmd;
+	u32 qpl_id;
 	int err;
 
+	qpl_id = priv->raw_addressing ? GVE_RAW_ADDRESSING_QPL_ID : tx->tx_fifo.qpl->id;
 	memset(&cmd, 0, sizeof(cmd));
 	cmd.opcode = cpu_to_be32(GVE_ADMINQ_CREATE_TX_QUEUE);
 	cmd.create_tx_queue = (struct gve_adminq_create_tx_queue) {
@@ -379,7 +381,7 @@ static int gve_adminq_create_tx_queue(struct gve_priv *priv, u32 queue_index)
 		.queue_resources_addr =
 			cpu_to_be64(tx->q_resources_bus),
 		.tx_ring_addr = cpu_to_be64(tx->bus),
-		.queue_page_list_id = cpu_to_be32(tx->tx_fifo.qpl->id),
+		.queue_page_list_id = cpu_to_be32(qpl_id),
 		.ntfy_id = cpu_to_be32(tx->ntfy_id),
 	};
 
drivers/net/ethernet/google/gve/gve_desc.h +5 -3
index a1c0aaa60139..05ae6300e984 100644
@@ -16,9 +16,11 @@
  * Base addresses encoded in seg_addr are not assumed to be physical
  * addresses. The ring format assumes these come from some linear address
  * space. This could be physical memory, kernel virtual memory, user virtual
- * memory. gVNIC uses lists of registered pages. Each queue is assumed
- * to be associated with a single such linear address space to ensure a
- * consistent meaning for seg_addrs posted to its rings.
+ * memory.
+ * If raw dma addressing is not supported then gVNIC uses lists of registered
+ * pages. Each queue is assumed to be associated with a single such linear
+ * address space to ensure a consistent meaning for seg_addrs posted to its
+ * rings.
  */
 
 struct gve_tx_pkt_desc {
drivers/net/ethernet/google/gve/gve_tx.c +168 -41

313 lines not on this page · raw message

Signature · 1 line
2.29.2.299.gdc1121823c-goog
maintainer
#9 lore raw
In reply to David Awogbemila
Quoted 16 lines · On Wed, 18 Nov 2020 15:20:10 -0800 David Awogbemila wrote:

Patch 1: Use u8 instead of bool for raw_addressing bit in gve_priv structure.
Simplify pointer arithmetic: use (option + 1) in gve_get_next_option. Separate option parsing switch statement into individual function.
Patch 2: Use u8 instead of bool for raw_addressing bit in gve_gve_rx_data_queue structure.
Correct typo in gve_desc.h comment (s/than/then/).
Change gve_rx_data_slot from struct to union.
Remove dma_mapping_error path change in gve_alloc_page - it should probably be a bug fix.
Use & to obtain page address from data_ring->addr.
Move declarations of local variables i and slots to if statement where they are used within gve_rx_unfill_pages.
Simplify alloc_err path by using "while(i--)", eliminating need for extra "int j" variable in gve_prefill_rx_pages.
Apply byteswap to constant in gve_rx_flip_buff.
Remove gve_rx_raw_addressing as it does not do much more than gve_rx_add_frags. Remove stats update from elseif block, no need to optimize for infrequent case of

Quoted 8 lines

work_done = 0.
Patch 3: Use u8 instead of bool for can_flip in gve_rx_slot_page_info.
Move comment in gve_rx_flip_buff to earlier, more relevant patch. Fix comment wrap in gve_rx_can_flip_buffers.
Use ternary statement for gve_rx_can_flip_buffers.
Correct comment in gve_rx_qpl.
Patch 4: Use u8 instead of bool in gve_tx_ring structure.
Get rid of unnecessary local variable "dma" in gve_dma_sync_for_device.

You need to start CCing people who gave you feedback, and discuss the feedback _before_ you send another version of the patchset.

CCing Alex and Saeed

#10 lore raw
In reply to David Awogbemila

Where is the description of what this patch set is meant to do? I don't recall if I reviewed that in the last patch set but usually the cover page should tell us something about the patch set and not just be a list of changes which I assume are diffs from v3?

Quoted 46 lines · David Awogbemila

Patch 1: Use u8 instead of bool for raw_addressing bit in gve_priv structure.
Simplify pointer arithmetic: use (option + 1) in gve_get_next_option. Separate option parsing switch statement into individual function.
Patch 2: Use u8 instead of bool for raw_addressing bit in gve_gve_rx_data_queue structure.
Correct typo in gve_desc.h comment (s/than/then/).
Change gve_rx_data_slot from struct to union.
Remove dma_mapping_error path change in gve_alloc_page - it should probably be a bug fix.
Use & to obtain page address from data_ring->addr.
Move declarations of local variables i and slots to if statement where they are used within gve_rx_unfill_pages.
Simplify alloc_err path by using "while(i--)", eliminating need for extra "int j" variable in gve_prefill_rx_pages.
Apply byteswap to constant in gve_rx_flip_buff.
Remove gve_rx_raw_addressing as it does not do much more than gve_rx_add_frags. Remove stats update from elseif block, no need to optimize for infrequent case of work_done = 0.
Patch 3: Use u8 instead of bool for can_flip in gve_rx_slot_page_info.
Move comment in gve_rx_flip_buff to earlier, more relevant patch. Fix comment wrap in gve_rx_can_flip_buffers.
Use ternary statement for gve_rx_can_flip_buffers.
Correct comment in gve_rx_qpl.
Patch 4: Use u8 instead of bool in gve_tx_ring structure.
Get rid of unnecessary local variable "dma" in gve_dma_sync_for_device.

Catherine Sullivan (3):
gve: Add support for raw addressing device option
gve: Add support for raw addressing to the rx path
gve: Add support for raw addressing in the tx path

David Awogbemila (1):
gve: Rx Buffer Recycling

 drivers/net/ethernet/google/gve/gve.h        |  38 +-
 drivers/net/ethernet/google/gve/gve_adminq.c |  90 ++++-
 drivers/net/ethernet/google/gve/gve_adminq.h |  15 +-
 drivers/net/ethernet/google/gve/gve_desc.h   |  19 +-
 drivers/net/ethernet/google/gve/gve_main.c   |  11 +-
 drivers/net/ethernet/google/gve/gve_rx.c     | 403 ++++++++++++++-----
 drivers/net/ethernet/google/gve/gve_tx.c     | 211 ++++++++--
 7 files changed, 620 insertions(+), 167 deletions(-)

--
2.29.2.299.gdc1121823c-goog