Commit cdc74c9d authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'gve-queue-api'

Shailend Chand says:

====================
gve: Implement queue api

Following the discussion on
https://patchwork.kernel.org/project/linux-media/patch/20240305020153.2787423-2-almasrymina@google.com/

,
the queue api defined by Mina is implemented for gve.

The first patch is just Mina's introduction of the api. The rest of the
patches make surgical changes in gve to enable it to work correctly with
only a subset of queues present (thus far it had assumed that either all
queues are up or all are down). The final patch has the api
implementation.

Changes since v1: clang warning fixes, kdoc warning fix, and addressed
review comments.
====================

Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 173e7622 ee24284e
Loading
Loading
Loading
Loading
+7 −24
Original line number Diff line number Diff line
@@ -610,6 +610,7 @@ struct gve_notify_block {
	struct gve_priv *priv;
	struct gve_tx_ring *tx; /* tx rings on this block */
	struct gve_rx_ring *rx; /* rx rings on this block */
	u32 irq;
};

/* Tracks allowed and current queue settings */
@@ -637,26 +638,10 @@ struct gve_ptype_lut {
	struct gve_ptype ptypes[GVE_NUM_PTYPES];
};

/* Parameters for allocating queue page lists */
struct gve_qpls_alloc_cfg {
	struct gve_queue_config *tx_cfg;
	struct gve_queue_config *rx_cfg;

	u16 num_xdp_queues;
	bool raw_addressing;
	bool is_gqi;

	/* Allocated resources are returned here */
	struct gve_queue_page_list *qpls;
};

/* Parameters for allocating resources for tx queues */
struct gve_tx_alloc_rings_cfg {
	struct gve_queue_config *qcfg;

	/* qpls must already be allocated */
	struct gve_queue_page_list *qpls;

	u16 ring_size;
	u16 start_idx;
	u16 num_rings;
@@ -672,9 +657,6 @@ struct gve_rx_alloc_rings_cfg {
	struct gve_queue_config *qcfg;
	struct gve_queue_config *qcfg_tx;

	/* qpls must already be allocated */
	struct gve_queue_page_list *qpls;

	u16 ring_size;
	u16 packet_buffer_size;
	bool raw_addressing;
@@ -700,7 +682,6 @@ struct gve_priv {
	struct net_device *dev;
	struct gve_tx_ring *tx; /* array of tx_cfg.num_queues */
	struct gve_rx_ring *rx; /* array of rx_cfg.num_queues */
	struct gve_queue_page_list *qpls; /* array of num qpls */
	struct gve_notify_block *ntfy_blocks; /* array of num_ntfy_blks */
	struct gve_irq_db *irq_db_indices; /* array of num_ntfy_blks */
	dma_addr_t irq_db_indices_bus;
@@ -1024,7 +1005,6 @@ static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid)
	return priv->tx_cfg.max_queues + rx_qid;
}

/* Returns the index into priv->qpls where a certain rx queue's QPL resides */
static inline u32 gve_get_rx_qpl_id(const struct gve_queue_config *tx_cfg, int rx_qid)
{
	return tx_cfg->max_queues + rx_qid;
@@ -1035,7 +1015,6 @@ static inline u32 gve_tx_start_qpl_id(struct gve_priv *priv)
	return gve_tx_qpl_id(priv, 0);
}

/* Returns the index into priv->qpls where the first rx queue's QPL resides */
static inline u32 gve_rx_start_qpl_id(const struct gve_queue_config *tx_cfg)
{
	return gve_get_rx_qpl_id(tx_cfg, 0);
@@ -1089,6 +1068,12 @@ int gve_alloc_page(struct gve_priv *priv, struct device *dev,
		   enum dma_data_direction, gfp_t gfp_flags);
void gve_free_page(struct device *dev, struct page *page, dma_addr_t dma,
		   enum dma_data_direction);
/* qpls */
struct gve_queue_page_list *gve_alloc_queue_page_list(struct gve_priv *priv,
						      u32 id, int pages);
void gve_free_queue_page_list(struct gve_priv *priv,
			      struct gve_queue_page_list *qpl,
			      u32 id);
/* tx handling */
netdev_tx_t gve_tx(struct sk_buff *skb, struct net_device *dev);
int gve_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
@@ -1125,11 +1110,9 @@ int gve_set_hsplit_config(struct gve_priv *priv, u8 tcp_data_split);
void gve_schedule_reset(struct gve_priv *priv);
int gve_reset(struct gve_priv *priv, bool attempt_teardown);
void gve_get_curr_alloc_cfgs(struct gve_priv *priv,
			     struct gve_qpls_alloc_cfg *qpls_alloc_cfg,
			     struct gve_tx_alloc_rings_cfg *tx_alloc_cfg,
			     struct gve_rx_alloc_rings_cfg *rx_alloc_cfg);
int gve_adjust_config(struct gve_priv *priv,
		      struct gve_qpls_alloc_cfg *qpls_alloc_cfg,
		      struct gve_tx_alloc_rings_cfg *tx_alloc_cfg,
		      struct gve_rx_alloc_rings_cfg *rx_alloc_cfg);
int gve_adjust_queues(struct gve_priv *priv,
+52 −27
Original line number Diff line number Diff line
@@ -630,14 +630,15 @@ int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_que
	return gve_adminq_kick_and_wait(priv);
}

static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
static void gve_adminq_get_create_rx_queue_cmd(struct gve_priv *priv,
					       union gve_adminq_command *cmd,
					       u32 queue_index)
{
	struct gve_rx_ring *rx = &priv->rx[queue_index];
	union gve_adminq_command cmd;

	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) {
	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) {
		.queue_id = cpu_to_be32(queue_index),
		.ntfy_id = cpu_to_be32(rx->ntfy_id),
		.queue_resources_addr = cpu_to_be64(rx->q_resources_bus),
@@ -648,13 +649,13 @@ static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
		u32 qpl_id = priv->queue_format == GVE_GQI_RDA_FORMAT ?
			GVE_RAW_ADDRESSING_QPL_ID : rx->data.qpl->id;

		cmd.create_rx_queue.rx_desc_ring_addr =
		cmd->create_rx_queue.rx_desc_ring_addr =
			cpu_to_be64(rx->desc.bus),
		cmd.create_rx_queue.rx_data_ring_addr =
		cmd->create_rx_queue.rx_data_ring_addr =
			cpu_to_be64(rx->data.data_bus),
		cmd.create_rx_queue.index = cpu_to_be32(queue_index);
		cmd.create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
		cmd.create_rx_queue.packet_buffer_size = cpu_to_be16(rx->packet_buffer_size);
		cmd->create_rx_queue.index = cpu_to_be32(queue_index);
		cmd->create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
		cmd->create_rx_queue.packet_buffer_size = cpu_to_be16(rx->packet_buffer_size);
	} else {
		u32 qpl_id = 0;

@@ -662,25 +663,40 @@ static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
			qpl_id = GVE_RAW_ADDRESSING_QPL_ID;
		else
			qpl_id = rx->dqo.qpl->id;
		cmd.create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
		cmd.create_rx_queue.rx_desc_ring_addr =
		cmd->create_rx_queue.queue_page_list_id = cpu_to_be32(qpl_id);
		cmd->create_rx_queue.rx_desc_ring_addr =
			cpu_to_be64(rx->dqo.complq.bus);
		cmd.create_rx_queue.rx_data_ring_addr =
		cmd->create_rx_queue.rx_data_ring_addr =
			cpu_to_be64(rx->dqo.bufq.bus);
		cmd.create_rx_queue.packet_buffer_size =
		cmd->create_rx_queue.packet_buffer_size =
			cpu_to_be16(priv->data_buffer_size_dqo);
		cmd.create_rx_queue.rx_buff_ring_size =
		cmd->create_rx_queue.rx_buff_ring_size =
			cpu_to_be16(priv->rx_desc_cnt);
		cmd.create_rx_queue.enable_rsc =
		cmd->create_rx_queue.enable_rsc =
			!!(priv->dev->features & NETIF_F_LRO);
		if (priv->header_split_enabled)
			cmd.create_rx_queue.header_buffer_size =
			cmd->create_rx_queue.header_buffer_size =
				cpu_to_be16(priv->header_buf_size);
	}
}

static int gve_adminq_create_rx_queue(struct gve_priv *priv, u32 queue_index)
{
	union gve_adminq_command cmd;

	gve_adminq_get_create_rx_queue_cmd(priv, &cmd, queue_index);
	return gve_adminq_issue_cmd(priv, &cmd);
}

/* Unlike gve_adminq_create_rx_queue, this actually rings the doorbell */
int gve_adminq_create_single_rx_queue(struct gve_priv *priv, u32 queue_index)
{
	union gve_adminq_command cmd;

	gve_adminq_get_create_rx_queue_cmd(priv, &cmd, queue_index);
	return gve_adminq_execute_cmd(priv, &cmd);
}

int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues)
{
	int err;
@@ -727,22 +743,31 @@ int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_qu
	return gve_adminq_kick_and_wait(priv);
}

static void gve_adminq_make_destroy_rx_queue_cmd(union gve_adminq_command *cmd,
						 u32 queue_index)
{
	memset(cmd, 0, sizeof(*cmd));
	cmd->opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_RX_QUEUE);
	cmd->destroy_rx_queue = (struct gve_adminq_destroy_rx_queue) {
		.queue_id = cpu_to_be32(queue_index),
	};
}

static int gve_adminq_destroy_rx_queue(struct gve_priv *priv, u32 queue_index)
{
	union gve_adminq_command cmd;
	int err;

	memset(&cmd, 0, sizeof(cmd));
	cmd.opcode = cpu_to_be32(GVE_ADMINQ_DESTROY_RX_QUEUE);
	cmd.destroy_rx_queue = (struct gve_adminq_destroy_rx_queue) {
		.queue_id = cpu_to_be32(queue_index),
	};
	gve_adminq_make_destroy_rx_queue_cmd(&cmd, queue_index);
	return gve_adminq_issue_cmd(priv, &cmd);
}

	err = gve_adminq_issue_cmd(priv, &cmd);
	if (err)
		return err;
/* Unlike gve_adminq_destroy_rx_queue, this actually rings the doorbell */
int gve_adminq_destroy_single_rx_queue(struct gve_priv *priv, u32 queue_index)
{
	union gve_adminq_command cmd;

	return 0;
	gve_adminq_make_destroy_rx_queue_cmd(&cmd, queue_index);
	return gve_adminq_execute_cmd(priv, &cmd);
}

int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 num_queues)
+2 −0
Original line number Diff line number Diff line
@@ -451,7 +451,9 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv);
int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_queues);
int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_queues);
int gve_adminq_create_single_rx_queue(struct gve_priv *priv, u32 queue_index);
int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues);
int gve_adminq_destroy_single_rx_queue(struct gve_priv *priv, u32 queue_index);
int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 queue_id);
int gve_adminq_register_page_list(struct gve_priv *priv,
				  struct gve_queue_page_list *qpl);
+37 −11
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#include "gve.h"
#include "gve_adminq.h"
#include "gve_dqo.h"
#include "gve_utils.h"

static void gve_get_drvinfo(struct net_device *netdev,
			    struct ethtool_drvinfo *info)
@@ -165,6 +166,8 @@ gve_get_ethtool_stats(struct net_device *netdev,
	struct stats *report_stats;
	int *rx_qid_to_stats_idx;
	int *tx_qid_to_stats_idx;
	int num_stopped_rxqs = 0;
	int num_stopped_txqs = 0;
	struct gve_priv *priv;
	bool skip_nic_stats;
	unsigned int start;
@@ -181,12 +184,23 @@ gve_get_ethtool_stats(struct net_device *netdev,
					    sizeof(int), GFP_KERNEL);
	if (!rx_qid_to_stats_idx)
		return;
	for (ring = 0; ring < priv->rx_cfg.num_queues; ring++) {
		rx_qid_to_stats_idx[ring] = -1;
		if (!gve_rx_was_added_to_block(priv, ring))
			num_stopped_rxqs++;
	}
	tx_qid_to_stats_idx = kmalloc_array(num_tx_queues,
					    sizeof(int), GFP_KERNEL);
	if (!tx_qid_to_stats_idx) {
		kfree(rx_qid_to_stats_idx);
		return;
	}
	for (ring = 0; ring < num_tx_queues; ring++) {
		tx_qid_to_stats_idx[ring] = -1;
		if (!gve_tx_was_added_to_block(priv, ring))
			num_stopped_txqs++;
	}

	for (rx_pkts = 0, rx_bytes = 0, rx_hsplit_pkt = 0,
	     rx_skb_alloc_fail = 0, rx_buf_alloc_fail = 0,
	     rx_desc_err_dropped_pkt = 0, rx_hsplit_unsplit_pkt = 0,
@@ -260,7 +274,13 @@ gve_get_ethtool_stats(struct net_device *netdev,
	/* For rx cross-reporting stats, start from nic rx stats in report */
	base_stats_idx = GVE_TX_STATS_REPORT_NUM * num_tx_queues +
		GVE_RX_STATS_REPORT_NUM * priv->rx_cfg.num_queues;
	max_stats_idx = NIC_RX_STATS_REPORT_NUM * priv->rx_cfg.num_queues +
	/* The boundary between driver stats and NIC stats shifts if there are
	 * stopped queues.
	 */
	base_stats_idx += NIC_RX_STATS_REPORT_NUM * num_stopped_rxqs +
		NIC_TX_STATS_REPORT_NUM * num_stopped_txqs;
	max_stats_idx = NIC_RX_STATS_REPORT_NUM *
		(priv->rx_cfg.num_queues - num_stopped_rxqs) +
		base_stats_idx;
	/* Preprocess the stats report for rx, map queue id to start index */
	skip_nic_stats = false;
@@ -274,6 +294,10 @@ gve_get_ethtool_stats(struct net_device *netdev,
			skip_nic_stats = true;
			break;
		}
		if (queue_id < 0 || queue_id >= priv->rx_cfg.num_queues) {
			net_err_ratelimited("Invalid rxq id in NIC stats\n");
			continue;
		}
		rx_qid_to_stats_idx[queue_id] = stats_idx;
	}
	/* walk RX rings */
@@ -308,11 +332,11 @@ gve_get_ethtool_stats(struct net_device *netdev,
			data[i++] = rx->rx_copybreak_pkt;
			data[i++] = rx->rx_copied_pkt;
			/* stats from NIC */
			if (skip_nic_stats) {
			stats_idx = rx_qid_to_stats_idx[ring];
			if (skip_nic_stats || stats_idx < 0) {
				/* skip NIC rx stats */
				i += NIC_RX_STATS_REPORT_NUM;
			} else {
				stats_idx = rx_qid_to_stats_idx[ring];
				for (j = 0; j < NIC_RX_STATS_REPORT_NUM; j++) {
					u64 value =
						be64_to_cpu(report_stats[stats_idx + j].value);
@@ -338,7 +362,8 @@ gve_get_ethtool_stats(struct net_device *netdev,

	/* For tx cross-reporting stats, start from nic tx stats in report */
	base_stats_idx = max_stats_idx;
	max_stats_idx = NIC_TX_STATS_REPORT_NUM * num_tx_queues +
	max_stats_idx = NIC_TX_STATS_REPORT_NUM *
		(num_tx_queues - num_stopped_txqs) +
		max_stats_idx;
	/* Preprocess the stats report for tx, map queue id to start index */
	skip_nic_stats = false;
@@ -352,6 +377,10 @@ gve_get_ethtool_stats(struct net_device *netdev,
			skip_nic_stats = true;
			break;
		}
		if (queue_id < 0 || queue_id >= num_tx_queues) {
			net_err_ratelimited("Invalid txq id in NIC stats\n");
			continue;
		}
		tx_qid_to_stats_idx[queue_id] = stats_idx;
	}
	/* walk TX rings */
@@ -383,11 +412,11 @@ gve_get_ethtool_stats(struct net_device *netdev,
			data[i++] = gve_tx_load_event_counter(priv, tx);
			data[i++] = tx->dma_mapping_error;
			/* stats from NIC */
			if (skip_nic_stats) {
			stats_idx = tx_qid_to_stats_idx[ring];
			if (skip_nic_stats || stats_idx < 0) {
				/* skip NIC tx stats */
				i += NIC_TX_STATS_REPORT_NUM;
			} else {
				stats_idx = tx_qid_to_stats_idx[ring];
				for (j = 0; j < NIC_TX_STATS_REPORT_NUM; j++) {
					u64 value =
						be64_to_cpu(report_stats[stats_idx + j].value);
@@ -509,20 +538,17 @@ static int gve_adjust_ring_sizes(struct gve_priv *priv,
{
	struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0};
	struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0};
	struct gve_qpls_alloc_cfg qpls_alloc_cfg = {0};
	int err;

	/* get current queue configuration */
	gve_get_curr_alloc_cfgs(priv, &qpls_alloc_cfg,
				&tx_alloc_cfg, &rx_alloc_cfg);
	gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg);

	/* copy over the new ring_size from ethtool */
	tx_alloc_cfg.ring_size = new_tx_desc_cnt;
	rx_alloc_cfg.ring_size = new_rx_desc_cnt;

	if (netif_running(priv->dev)) {
		err = gve_adjust_config(priv, &qpls_alloc_cfg,
					&tx_alloc_cfg, &rx_alloc_cfg);
		err = gve_adjust_config(priv, &tx_alloc_cfg, &rx_alloc_cfg);
		if (err)
			return err;
	}
+141 −259

File changed.

Preview size limit exceeded, changes collapsed.

Loading