Skip to content

Commit 955f4d3

Browse files
jfrakerkuba-moo
authored andcommitted
gve: Perform adminq allocations through a dma_pool.
This allows the adminq to be smaller than a page, paving the way for non 4k page support. This is to support platforms where PAGE_SIZE is not 4k, such as some ARM platforms. Signed-off-by: Jordan Kimbrough <jrkim@google.com> Signed-off-by: John Fraker <jfraker@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://lore.kernel.org/r/20231128002648.320892-2-jfraker@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f1be1e0 commit 955f4d3

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

drivers/net/ethernet/google/gve/gve.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define _GVE_H_
99

1010
#include <linux/dma-mapping.h>
11+
#include <linux/dmapool.h>
1112
#include <linux/netdevice.h>
1213
#include <linux/pci.h>
1314
#include <linux/u64_stats_sync.h>
@@ -41,6 +42,8 @@
4142
#define NIC_TX_STATS_REPORT_NUM 0
4243
#define NIC_RX_STATS_REPORT_NUM 4
4344

45+
#define GVE_ADMINQ_BUFFER_SIZE 4096
46+
4447
#define GVE_DATA_SLOT_ADDR_PAGE_MASK (~(PAGE_SIZE - 1))
4548

4649
/* PTYPEs are always 10 bits. */
@@ -672,6 +675,7 @@ struct gve_priv {
672675
/* Admin queue - see gve_adminq.h*/
673676
union gve_adminq_command *adminq;
674677
dma_addr_t adminq_bus_addr;
678+
struct dma_pool *adminq_pool;
675679
u32 adminq_mask; /* masks prod_cnt to adminq size */
676680
u32 adminq_prod_cnt; /* free-running count of AQ cmds executed */
677681
u32 adminq_cmd_fail; /* free-running count of AQ cmds failed */

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,19 @@ gve_process_device_options(struct gve_priv *priv,
194194

195195
int gve_adminq_alloc(struct device *dev, struct gve_priv *priv)
196196
{
197-
priv->adminq = dma_alloc_coherent(dev, PAGE_SIZE,
198-
&priv->adminq_bus_addr, GFP_KERNEL);
199-
if (unlikely(!priv->adminq))
197+
priv->adminq_pool = dma_pool_create("adminq_pool", dev,
198+
GVE_ADMINQ_BUFFER_SIZE, 0, 0);
199+
if (unlikely(!priv->adminq_pool))
200200
return -ENOMEM;
201+
priv->adminq = dma_pool_alloc(priv->adminq_pool, GFP_KERNEL,
202+
&priv->adminq_bus_addr);
203+
if (unlikely(!priv->adminq)) {
204+
dma_pool_destroy(priv->adminq_pool);
205+
return -ENOMEM;
206+
}
201207

202-
priv->adminq_mask = (PAGE_SIZE / sizeof(union gve_adminq_command)) - 1;
208+
priv->adminq_mask =
209+
(GVE_ADMINQ_BUFFER_SIZE / sizeof(union gve_adminq_command)) - 1;
203210
priv->adminq_prod_cnt = 0;
204211
priv->adminq_cmd_fail = 0;
205212
priv->adminq_timeouts = 0;
@@ -251,7 +258,8 @@ void gve_adminq_free(struct device *dev, struct gve_priv *priv)
251258
if (!gve_get_admin_queue_ok(priv))
252259
return;
253260
gve_adminq_release(priv);
254-
dma_free_coherent(dev, PAGE_SIZE, priv->adminq, priv->adminq_bus_addr);
261+
dma_pool_free(priv->adminq_pool, priv->adminq, priv->adminq_bus_addr);
262+
dma_pool_destroy(priv->adminq_pool);
255263
gve_clear_admin_queue_ok(priv);
256264
}
257265

@@ -778,16 +786,17 @@ int gve_adminq_describe_device(struct gve_priv *priv)
778786
u16 mtu;
779787

780788
memset(&cmd, 0, sizeof(cmd));
781-
descriptor = dma_alloc_coherent(&priv->pdev->dev, PAGE_SIZE,
782-
&descriptor_bus, GFP_KERNEL);
789+
descriptor = dma_pool_alloc(priv->adminq_pool, GFP_KERNEL,
790+
&descriptor_bus);
783791
if (!descriptor)
784792
return -ENOMEM;
785793
cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESCRIBE_DEVICE);
786794
cmd.describe_device.device_descriptor_addr =
787795
cpu_to_be64(descriptor_bus);
788796
cmd.describe_device.device_descriptor_version =
789797
cpu_to_be32(GVE_ADMINQ_DEVICE_DESCRIPTOR_VERSION);
790-
cmd.describe_device.available_length = cpu_to_be32(PAGE_SIZE);
798+
cmd.describe_device.available_length =
799+
cpu_to_be32(GVE_ADMINQ_BUFFER_SIZE);
791800

792801
err = gve_adminq_execute_cmd(priv, &cmd);
793802
if (err)
@@ -868,8 +877,7 @@ int gve_adminq_describe_device(struct gve_priv *priv)
868877
dev_op_jumbo_frames, dev_op_dqo_qpl);
869878

870879
free_device_descriptor:
871-
dma_free_coherent(&priv->pdev->dev, PAGE_SIZE, descriptor,
872-
descriptor_bus);
880+
dma_pool_free(priv->adminq_pool, descriptor, descriptor_bus);
873881
return err;
874882
}
875883

0 commit comments

Comments
 (0)