Commit fa47527c authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'gve-alloc-before-freeing-when-changing-config'

Shailend Chand says:

====================
gve: Alloc before freeing when changing config

Functions allocating resources did so directly into priv thus far. The
assumption doing that was that priv was not already holding references
to live resources.

When ring configuration is changed in any way from userspace, thus far
we relied on calling the ndo_stop and ndo_open callbacks in succession.
This meant that we teardown existing resources and rob the OS of
networking before we have successfully allocated resources for the new
config.

Correcting this requires us to perform allocations without editing priv.
That is what the "gve: Switch to config-aware..." patch does: it modifies
all the allocation paths so that they take a new configuration as input
and return references to newly allocated resources without modifying
priv or interfering with live resources in any way.

Having corrected the allocation paths so, the ndo open and close
callbacks are refactored to make available distinct functions for
allocating queue resources and starting or stopping them. This is then
put to use in the set_channels and set_features hooks in the last two
patches.

These changes have been tested by verifying the integrity of a stream of
integers while the driver is continuously reconfigured with ethtool.
====================

Link: https://lore.kernel.org/r/20240122182632.1102721-1-shailend@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 20df28fb f3753771
...@@ -622,6 +622,55 @@ struct gve_ptype_lut { ...@@ -622,6 +622,55 @@ struct gve_ptype_lut {
struct gve_ptype ptypes[GVE_NUM_PTYPES]; struct gve_ptype ptypes[GVE_NUM_PTYPES];
}; };
/* Parameters for allocating queue page lists */
struct gve_qpls_alloc_cfg {
struct gve_qpl_config *qpl_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 and qpl_cfg must already be allocated */
struct gve_queue_page_list *qpls;
struct gve_qpl_config *qpl_cfg;
u16 ring_size;
u16 start_idx;
u16 num_rings;
bool raw_addressing;
/* Allocated resources are returned here */
struct gve_tx_ring *tx;
};
/* Parameters for allocating resources for rx queues */
struct gve_rx_alloc_rings_cfg {
/* tx config is also needed to determine QPL ids */
struct gve_queue_config *qcfg;
struct gve_queue_config *qcfg_tx;
/* qpls and qpl_cfg must already be allocated */
struct gve_queue_page_list *qpls;
struct gve_qpl_config *qpl_cfg;
u16 ring_size;
bool raw_addressing;
bool enable_header_split;
/* Allocated resources are returned here */
struct gve_rx_ring *rx;
};
/* 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.
...@@ -917,14 +966,14 @@ static inline bool gve_is_qpl(struct gve_priv *priv) ...@@ -917,14 +966,14 @@ static inline bool gve_is_qpl(struct gve_priv *priv)
priv->queue_format == GVE_DQO_QPL_FORMAT; priv->queue_format == GVE_DQO_QPL_FORMAT;
} }
/* Returns the number of tx queue page lists /* Returns the number of tx queue page lists */
*/ static inline u32 gve_num_tx_qpls(const struct gve_queue_config *tx_cfg,
static inline u32 gve_num_tx_qpls(struct gve_priv *priv) int num_xdp_queues,
bool is_qpl)
{ {
if (!gve_is_qpl(priv)) if (!is_qpl)
return 0; return 0;
return tx_cfg->num_queues + num_xdp_queues;
return priv->tx_cfg.num_queues + priv->num_xdp_queues;
} }
/* Returns the number of XDP tx queue page lists /* Returns the number of XDP tx queue page lists
...@@ -937,14 +986,13 @@ static inline u32 gve_num_xdp_qpls(struct gve_priv *priv) ...@@ -937,14 +986,13 @@ static inline u32 gve_num_xdp_qpls(struct gve_priv *priv)
return priv->num_xdp_queues; return priv->num_xdp_queues;
} }
/* Returns the number of rx queue page lists /* Returns the number of rx queue page lists */
*/ static inline u32 gve_num_rx_qpls(const struct gve_queue_config *rx_cfg,
static inline u32 gve_num_rx_qpls(struct gve_priv *priv) bool is_qpl)
{ {
if (!gve_is_qpl(priv)) if (!is_qpl)
return 0; return 0;
return rx_cfg->num_queues;
return priv->rx_cfg.num_queues;
} }
static inline u32 gve_tx_qpl_id(struct gve_priv *priv, int tx_qid) static inline u32 gve_tx_qpl_id(struct gve_priv *priv, int tx_qid)
...@@ -957,59 +1005,59 @@ static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid) ...@@ -957,59 +1005,59 @@ static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid)
return priv->tx_cfg.max_queues + 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;
}
static inline u32 gve_tx_start_qpl_id(struct gve_priv *priv) static inline u32 gve_tx_start_qpl_id(struct gve_priv *priv)
{ {
return gve_tx_qpl_id(priv, 0); return gve_tx_qpl_id(priv, 0);
} }
static inline u32 gve_rx_start_qpl_id(struct gve_priv *priv) /* 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_rx_qpl_id(priv, 0); return gve_get_rx_qpl_id(tx_cfg, 0);
} }
/* Returns a pointer to the next available tx qpl in the list of qpls /* Returns a pointer to the next available tx qpl in the list of qpls */
*/
static inline static inline
struct gve_queue_page_list *gve_assign_tx_qpl(struct gve_priv *priv, int tx_qid) struct gve_queue_page_list *gve_assign_tx_qpl(struct gve_tx_alloc_rings_cfg *cfg,
int tx_qid)
{ {
int id = gve_tx_qpl_id(priv, tx_qid);
/* QPL already in use */ /* QPL already in use */
if (test_bit(id, priv->qpl_cfg.qpl_id_map)) if (test_bit(tx_qid, cfg->qpl_cfg->qpl_id_map))
return NULL; return NULL;
set_bit(tx_qid, cfg->qpl_cfg->qpl_id_map);
set_bit(id, priv->qpl_cfg.qpl_id_map); return &cfg->qpls[tx_qid];
return &priv->qpls[id];
} }
/* Returns a pointer to the next available rx qpl in the list of qpls /* Returns a pointer to the next available rx qpl in the list of qpls */
*/
static inline static inline
struct gve_queue_page_list *gve_assign_rx_qpl(struct gve_priv *priv, int rx_qid) struct gve_queue_page_list *gve_assign_rx_qpl(struct gve_rx_alloc_rings_cfg *cfg,
int rx_qid)
{ {
int id = gve_rx_qpl_id(priv, rx_qid); int id = gve_get_rx_qpl_id(cfg->qcfg_tx, rx_qid);
/* QPL already in use */ /* QPL already in use */
if (test_bit(id, priv->qpl_cfg.qpl_id_map)) if (test_bit(id, cfg->qpl_cfg->qpl_id_map))
return NULL; return NULL;
set_bit(id, cfg->qpl_cfg->qpl_id_map);
set_bit(id, priv->qpl_cfg.qpl_id_map); return &cfg->qpls[id];
return &priv->qpls[id];
} }
/* Unassigns the qpl with the given id /* Unassigns the qpl with the given id */
*/ static inline void gve_unassign_qpl(struct gve_qpl_config *qpl_cfg, int id)
static inline void gve_unassign_qpl(struct gve_priv *priv, int id)
{ {
clear_bit(id, priv->qpl_cfg.qpl_id_map); clear_bit(id, qpl_cfg->qpl_id_map);
} }
/* Returns the correct dma direction for tx and rx qpls /* Returns the correct dma direction for tx and rx qpls */
*/
static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv, static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,
int id) int id)
{ {
if (id < gve_rx_start_qpl_id(priv)) if (id < gve_rx_start_qpl_id(&priv->tx_cfg))
return DMA_TO_DEVICE; return DMA_TO_DEVICE;
else else
return DMA_FROM_DEVICE; return DMA_FROM_DEVICE;
...@@ -1036,6 +1084,9 @@ static inline u32 gve_xdp_tx_start_queue_id(struct gve_priv *priv) ...@@ -1036,6 +1084,9 @@ static inline u32 gve_xdp_tx_start_queue_id(struct gve_priv *priv)
return gve_xdp_tx_queue_id(priv, 0); return gve_xdp_tx_queue_id(priv, 0);
} }
/* gqi napi handler defined in gve_main.c */
int gve_napi_poll(struct napi_struct *napi, int budget);
/* buffers */ /* buffers */
int gve_alloc_page(struct gve_priv *priv, struct device *dev, int gve_alloc_page(struct gve_priv *priv, struct device *dev,
struct page **page, dma_addr_t *dma, struct page **page, dma_addr_t *dma,
...@@ -1051,8 +1102,12 @@ int gve_xdp_xmit_one(struct gve_priv *priv, struct gve_tx_ring *tx, ...@@ -1051,8 +1102,12 @@ int gve_xdp_xmit_one(struct gve_priv *priv, struct gve_tx_ring *tx,
void gve_xdp_tx_flush(struct gve_priv *priv, u32 xdp_qid); void gve_xdp_tx_flush(struct gve_priv *priv, u32 xdp_qid);
bool gve_tx_poll(struct gve_notify_block *block, int budget); bool gve_tx_poll(struct gve_notify_block *block, int budget);
bool gve_xdp_poll(struct gve_notify_block *block, int budget); bool gve_xdp_poll(struct gve_notify_block *block, int budget);
int gve_tx_alloc_rings(struct gve_priv *priv, int start_id, int num_rings); int gve_tx_alloc_rings_gqi(struct gve_priv *priv,
void gve_tx_free_rings_gqi(struct gve_priv *priv, int start_id, int num_rings); struct gve_tx_alloc_rings_cfg *cfg);
void gve_tx_free_rings_gqi(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg);
void gve_tx_start_ring_gqi(struct gve_priv *priv, int idx);
void gve_tx_stop_ring_gqi(struct gve_priv *priv, int idx);
u32 gve_tx_load_event_counter(struct gve_priv *priv, u32 gve_tx_load_event_counter(struct gve_priv *priv,
struct gve_tx_ring *tx); struct gve_tx_ring *tx);
bool gve_tx_clean_pending(struct gve_priv *priv, struct gve_tx_ring *tx); bool gve_tx_clean_pending(struct gve_priv *priv, struct gve_tx_ring *tx);
...@@ -1061,7 +1116,12 @@ void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx); ...@@ -1061,7 +1116,12 @@ void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx);
int gve_rx_poll(struct gve_notify_block *block, int budget); int gve_rx_poll(struct gve_notify_block *block, int budget);
bool gve_rx_work_pending(struct gve_rx_ring *rx); bool gve_rx_work_pending(struct gve_rx_ring *rx);
int gve_rx_alloc_rings(struct gve_priv *priv); int gve_rx_alloc_rings(struct gve_priv *priv);
void gve_rx_free_rings_gqi(struct gve_priv *priv); int gve_rx_alloc_rings_gqi(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg);
void gve_rx_free_rings_gqi(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg);
void gve_rx_start_ring_gqi(struct gve_priv *priv, int idx);
void gve_rx_stop_ring_gqi(struct gve_priv *priv, int idx);
/* Reset */ /* Reset */
void gve_schedule_reset(struct gve_priv *priv); void gve_schedule_reset(struct gve_priv *priv);
int gve_reset(struct gve_priv *priv, bool attempt_teardown); int gve_reset(struct gve_priv *priv, bool attempt_teardown);
......
...@@ -38,10 +38,18 @@ netdev_features_t gve_features_check_dqo(struct sk_buff *skb, ...@@ -38,10 +38,18 @@ netdev_features_t gve_features_check_dqo(struct sk_buff *skb,
netdev_features_t features); netdev_features_t features);
bool gve_tx_poll_dqo(struct gve_notify_block *block, bool do_clean); bool gve_tx_poll_dqo(struct gve_notify_block *block, bool do_clean);
int gve_rx_poll_dqo(struct gve_notify_block *block, int budget); int gve_rx_poll_dqo(struct gve_notify_block *block, int budget);
int gve_tx_alloc_rings_dqo(struct gve_priv *priv); int gve_tx_alloc_rings_dqo(struct gve_priv *priv,
void gve_tx_free_rings_dqo(struct gve_priv *priv); struct gve_tx_alloc_rings_cfg *cfg);
int gve_rx_alloc_rings_dqo(struct gve_priv *priv); void gve_tx_free_rings_dqo(struct gve_priv *priv,
void gve_rx_free_rings_dqo(struct gve_priv *priv); struct gve_tx_alloc_rings_cfg *cfg);
void gve_tx_start_ring_dqo(struct gve_priv *priv, int idx);
void gve_tx_stop_ring_dqo(struct gve_priv *priv, int idx);
int gve_rx_alloc_rings_dqo(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg);
void gve_rx_free_rings_dqo(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg);
void gve_rx_start_ring_dqo(struct gve_priv *priv, int idx);
void gve_rx_stop_ring_dqo(struct gve_priv *priv, int idx);
int gve_clean_tx_done_dqo(struct gve_priv *priv, struct gve_tx_ring *tx, int gve_clean_tx_done_dqo(struct gve_priv *priv, struct gve_tx_ring *tx,
struct napi_struct *napi); struct napi_struct *napi);
void gve_rx_post_buffers_dqo(struct gve_rx_ring *rx); void gve_rx_post_buffers_dqo(struct gve_rx_ring *rx);
...@@ -93,4 +101,6 @@ gve_set_itr_coalesce_usecs_dqo(struct gve_priv *priv, ...@@ -93,4 +101,6 @@ gve_set_itr_coalesce_usecs_dqo(struct gve_priv *priv,
gve_write_irq_doorbell_dqo(priv, block, gve_write_irq_doorbell_dqo(priv, block,
gve_setup_itr_interval_dqo(usecs)); gve_setup_itr_interval_dqo(usecs));
} }
int gve_napi_poll_dqo(struct napi_struct *napi, int budget);
#endif /* _GVE_DQO_H_ */ #endif /* _GVE_DQO_H_ */
This diff is collapsed.
...@@ -23,7 +23,9 @@ static void gve_rx_free_buffer(struct device *dev, ...@@ -23,7 +23,9 @@ static void gve_rx_free_buffer(struct device *dev,
gve_free_page(dev, page_info->page, dma, DMA_FROM_DEVICE); gve_free_page(dev, page_info->page, dma, DMA_FROM_DEVICE);
} }
static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx) static void gve_rx_unfill_pages(struct gve_priv *priv,
struct gve_rx_ring *rx,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
u32 slots = rx->mask + 1; u32 slots = rx->mask + 1;
int i; int i;
...@@ -36,7 +38,7 @@ static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx) ...@@ -36,7 +38,7 @@ static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx)
for (i = 0; i < slots; i++) for (i = 0; i < slots; i++)
page_ref_sub(rx->data.page_info[i].page, page_ref_sub(rx->data.page_info[i].page,
rx->data.page_info[i].pagecnt_bias - 1); rx->data.page_info[i].pagecnt_bias - 1);
gve_unassign_qpl(priv, rx->data.qpl->id); gve_unassign_qpl(cfg->qpl_cfg, rx->data.qpl->id);
rx->data.qpl = NULL; rx->data.qpl = NULL;
for (i = 0; i < rx->qpl_copy_pool_mask + 1; i++) { for (i = 0; i < rx->qpl_copy_pool_mask + 1; i++) {
...@@ -49,16 +51,26 @@ static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx) ...@@ -49,16 +51,26 @@ static void gve_rx_unfill_pages(struct gve_priv *priv, struct gve_rx_ring *rx)
rx->data.page_info = NULL; rx->data.page_info = NULL;
} }
static void gve_rx_free_ring(struct gve_priv *priv, int idx) void gve_rx_stop_ring_gqi(struct gve_priv *priv, int idx)
{
int ntfy_idx = gve_rx_idx_to_ntfy(priv, idx);
if (!gve_rx_was_added_to_block(priv, idx))
return;
gve_remove_napi(priv, ntfy_idx);
gve_rx_remove_from_block(priv, idx);
}
static void gve_rx_free_ring_gqi(struct gve_priv *priv, struct gve_rx_ring *rx,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
struct gve_rx_ring *rx = &priv->rx[idx];
struct device *dev = &priv->pdev->dev; struct device *dev = &priv->pdev->dev;
u32 slots = rx->mask + 1; u32 slots = rx->mask + 1;
int idx = rx->q_num;
size_t bytes; size_t bytes;
gve_rx_remove_from_block(priv, idx); bytes = sizeof(struct gve_rx_desc) * cfg->ring_size;
bytes = sizeof(struct gve_rx_desc) * priv->rx_desc_cnt;
dma_free_coherent(dev, bytes, rx->desc.desc_ring, rx->desc.bus); dma_free_coherent(dev, bytes, rx->desc.desc_ring, rx->desc.bus);
rx->desc.desc_ring = NULL; rx->desc.desc_ring = NULL;
...@@ -66,7 +78,7 @@ static void gve_rx_free_ring(struct gve_priv *priv, int idx) ...@@ -66,7 +78,7 @@ static void gve_rx_free_ring(struct gve_priv *priv, int idx)
rx->q_resources, rx->q_resources_bus); rx->q_resources, rx->q_resources_bus);
rx->q_resources = NULL; rx->q_resources = NULL;
gve_rx_unfill_pages(priv, rx); gve_rx_unfill_pages(priv, rx, cfg);
bytes = sizeof(*rx->data.data_ring) * slots; bytes = sizeof(*rx->data.data_ring) * slots;
dma_free_coherent(dev, bytes, rx->data.data_ring, dma_free_coherent(dev, bytes, rx->data.data_ring,
...@@ -108,7 +120,8 @@ static int gve_rx_alloc_buffer(struct gve_priv *priv, struct device *dev, ...@@ -108,7 +120,8 @@ static int gve_rx_alloc_buffer(struct gve_priv *priv, struct device *dev,
return 0; return 0;
} }
static int gve_prefill_rx_pages(struct gve_rx_ring *rx) static int gve_rx_prefill_pages(struct gve_rx_ring *rx,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
struct gve_priv *priv = rx->gve; struct gve_priv *priv = rx->gve;
u32 slots; u32 slots;
...@@ -127,7 +140,7 @@ static int gve_prefill_rx_pages(struct gve_rx_ring *rx) ...@@ -127,7 +140,7 @@ static int gve_prefill_rx_pages(struct gve_rx_ring *rx)
return -ENOMEM; return -ENOMEM;
if (!rx->data.raw_addressing) { if (!rx->data.raw_addressing) {
rx->data.qpl = gve_assign_rx_qpl(priv, rx->q_num); rx->data.qpl = gve_assign_rx_qpl(cfg, rx->q_num);
if (!rx->data.qpl) { if (!rx->data.qpl) {
kvfree(rx->data.page_info); kvfree(rx->data.page_info);
rx->data.page_info = NULL; rx->data.page_info = NULL;
...@@ -185,7 +198,7 @@ static int gve_prefill_rx_pages(struct gve_rx_ring *rx) ...@@ -185,7 +198,7 @@ static int gve_prefill_rx_pages(struct gve_rx_ring *rx)
page_ref_sub(rx->data.page_info[i].page, page_ref_sub(rx->data.page_info[i].page,
rx->data.page_info[i].pagecnt_bias - 1); rx->data.page_info[i].pagecnt_bias - 1);
gve_unassign_qpl(priv, rx->data.qpl->id); gve_unassign_qpl(cfg->qpl_cfg, rx->data.qpl->id);
rx->data.qpl = NULL; rx->data.qpl = NULL;
return err; return err;
...@@ -207,13 +220,23 @@ static void gve_rx_ctx_clear(struct gve_rx_ctx *ctx) ...@@ -207,13 +220,23 @@ static void gve_rx_ctx_clear(struct gve_rx_ctx *ctx)
ctx->drop_pkt = false; ctx->drop_pkt = false;
} }
static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) void gve_rx_start_ring_gqi(struct gve_priv *priv, int idx)
{
int ntfy_idx = gve_rx_idx_to_ntfy(priv, idx);
gve_rx_add_to_block(priv, idx);
gve_add_napi(priv, ntfy_idx, gve_napi_poll);
}
static int gve_rx_alloc_ring_gqi(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg,
struct gve_rx_ring *rx,
int idx)
{ {
struct gve_rx_ring *rx = &priv->rx[idx];
struct device *hdev = &priv->pdev->dev; struct device *hdev = &priv->pdev->dev;
u32 slots = priv->rx_data_slot_cnt;
int filled_pages; int filled_pages;
size_t bytes; size_t bytes;
u32 slots;
int err; int err;
netif_dbg(priv, drv, priv->dev, "allocating rx ring\n"); netif_dbg(priv, drv, priv->dev, "allocating rx ring\n");
...@@ -223,9 +246,8 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -223,9 +246,8 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx)
rx->gve = priv; rx->gve = priv;
rx->q_num = idx; rx->q_num = idx;
slots = priv->rx_data_slot_cnt;
rx->mask = slots - 1; rx->mask = slots - 1;
rx->data.raw_addressing = priv->queue_format == GVE_GQI_RDA_FORMAT; rx->data.raw_addressing = cfg->raw_addressing;
/* alloc rx data ring */ /* alloc rx data ring */
bytes = sizeof(*rx->data.data_ring) * slots; bytes = sizeof(*rx->data.data_ring) * slots;
...@@ -246,7 +268,7 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -246,7 +268,7 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx)
goto abort_with_slots; goto abort_with_slots;
} }
filled_pages = gve_prefill_rx_pages(rx); filled_pages = gve_rx_prefill_pages(rx, cfg);
if (filled_pages < 0) { if (filled_pages < 0) {
err = -ENOMEM; err = -ENOMEM;
goto abort_with_copy_pool; goto abort_with_copy_pool;
...@@ -269,7 +291,7 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -269,7 +291,7 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx)
(unsigned long)rx->data.data_bus); (unsigned long)rx->data.data_bus);
/* alloc rx desc ring */ /* alloc rx desc ring */
bytes = sizeof(struct gve_rx_desc) * priv->rx_desc_cnt; bytes = sizeof(struct gve_rx_desc) * cfg->ring_size;
rx->desc.desc_ring = dma_alloc_coherent(hdev, bytes, &rx->desc.bus, rx->desc.desc_ring = dma_alloc_coherent(hdev, bytes, &rx->desc.bus,
GFP_KERNEL); GFP_KERNEL);
if (!rx->desc.desc_ring) { if (!rx->desc.desc_ring) {
...@@ -277,15 +299,11 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -277,15 +299,11 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx)
goto abort_with_q_resources; goto abort_with_q_resources;
} }
rx->cnt = 0; rx->cnt = 0;
rx->db_threshold = priv->rx_desc_cnt / 2; rx->db_threshold = slots / 2;
rx->desc.seqno = 1; rx->desc.seqno = 1;
/* Allocating half-page buffers allows page-flipping which is faster
* than copying or allocating new pages.
*/
rx->packet_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE; rx->packet_buffer_size = GVE_DEFAULT_RX_BUFFER_SIZE;
gve_rx_ctx_clear(&rx->ctx); gve_rx_ctx_clear(&rx->ctx);
gve_rx_add_to_block(priv, idx);
return 0; return 0;
...@@ -294,7 +312,7 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -294,7 +312,7 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx)
rx->q_resources, rx->q_resources_bus); rx->q_resources, rx->q_resources_bus);
rx->q_resources = NULL; rx->q_resources = NULL;
abort_filled: abort_filled:
gve_rx_unfill_pages(priv, rx); gve_rx_unfill_pages(priv, rx, cfg);
abort_with_copy_pool: abort_with_copy_pool:
kvfree(rx->qpl_copy_pool); kvfree(rx->qpl_copy_pool);
rx->qpl_copy_pool = NULL; rx->qpl_copy_pool = NULL;
...@@ -306,36 +324,58 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -306,36 +324,58 @@ static int gve_rx_alloc_ring(struct gve_priv *priv, int idx)
return err; return err;
} }
int gve_rx_alloc_rings(struct gve_priv *priv) int gve_rx_alloc_rings_gqi(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
struct gve_rx_ring *rx;
int err = 0; int err = 0;
int i; int i, j;
for (i = 0; i < priv->rx_cfg.num_queues; i++) { if (!cfg->raw_addressing && !cfg->qpls) {
err = gve_rx_alloc_ring(priv, i); netif_err(priv, drv, priv->dev,
"Cannot alloc QPL ring before allocing QPLs\n");
return -EINVAL;
}
rx = kvcalloc(cfg->qcfg->max_queues, sizeof(struct gve_rx_ring),
GFP_KERNEL);
if (!rx)
return -ENOMEM;
for (i = 0; i < cfg->qcfg->num_queues; i++) {
err = gve_rx_alloc_ring_gqi(priv, cfg, &rx[i], i);
if (err) { if (err) {
netif_err(priv, drv, priv->dev, netif_err(priv, drv, priv->dev,
"Failed to alloc rx ring=%d: err=%d\n", "Failed to alloc rx ring=%d: err=%d\n",
i, err); i, err);
break; goto cleanup;
} }
} }
/* Unallocate if there was an error */
if (err) {
int j;
for (j = 0; j < i; j++) cfg->rx = rx;
gve_rx_free_ring(priv, j); return 0;
}
cleanup:
for (j = 0; j < i; j++)
gve_rx_free_ring_gqi(priv, &rx[j], cfg);
kvfree(rx);
return err; return err;
} }
void gve_rx_free_rings_gqi(struct gve_priv *priv) void gve_rx_free_rings_gqi(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
struct gve_rx_ring *rx = cfg->rx;
int i; int i;
for (i = 0; i < priv->rx_cfg.num_queues; i++) if (!rx)
gve_rx_free_ring(priv, i); return;
for (i = 0; i < cfg->qcfg->num_queues; i++)
gve_rx_free_ring_gqi(priv, &rx[i], cfg);
kvfree(rx);
cfg->rx = NULL;
} }
void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx) void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx)
......
...@@ -199,20 +199,30 @@ static int gve_alloc_page_dqo(struct gve_rx_ring *rx, ...@@ -199,20 +199,30 @@ static int gve_alloc_page_dqo(struct gve_rx_ring *rx,
return 0; return 0;
} }
static void gve_rx_free_ring_dqo(struct gve_priv *priv, int idx) void gve_rx_stop_ring_dqo(struct gve_priv *priv, int idx)
{
int ntfy_idx = gve_rx_idx_to_ntfy(priv, idx);
if (!gve_rx_was_added_to_block(priv, idx))
return;
gve_remove_napi(priv, ntfy_idx);
gve_rx_remove_from_block(priv, idx);
}
static void gve_rx_free_ring_dqo(struct gve_priv *priv, struct gve_rx_ring *rx,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
struct gve_rx_ring *rx = &priv->rx[idx];
struct device *hdev = &priv->pdev->dev; struct device *hdev = &priv->pdev->dev;
size_t completion_queue_slots; size_t completion_queue_slots;
size_t buffer_queue_slots; size_t buffer_queue_slots;
int idx = rx->q_num;
size_t size; size_t size;
int i; int i;
completion_queue_slots = rx->dqo.complq.mask + 1; completion_queue_slots = rx->dqo.complq.mask + 1;
buffer_queue_slots = rx->dqo.bufq.mask + 1; buffer_queue_slots = rx->dqo.bufq.mask + 1;
gve_rx_remove_from_block(priv, idx);
if (rx->q_resources) { if (rx->q_resources) {
dma_free_coherent(hdev, sizeof(*rx->q_resources), dma_free_coherent(hdev, sizeof(*rx->q_resources),
rx->q_resources, rx->q_resources_bus); rx->q_resources, rx->q_resources_bus);
...@@ -226,7 +236,7 @@ static void gve_rx_free_ring_dqo(struct gve_priv *priv, int idx) ...@@ -226,7 +236,7 @@ static void gve_rx_free_ring_dqo(struct gve_priv *priv, int idx)
gve_free_page_dqo(priv, bs, !rx->dqo.qpl); gve_free_page_dqo(priv, bs, !rx->dqo.qpl);
} }
if (rx->dqo.qpl) { if (rx->dqo.qpl) {
gve_unassign_qpl(priv, rx->dqo.qpl->id); gve_unassign_qpl(cfg->qpl_cfg, rx->dqo.qpl->id);
rx->dqo.qpl = NULL; rx->dqo.qpl = NULL;
} }
...@@ -251,17 +261,26 @@ static void gve_rx_free_ring_dqo(struct gve_priv *priv, int idx) ...@@ -251,17 +261,26 @@ static void gve_rx_free_ring_dqo(struct gve_priv *priv, int idx)
netif_dbg(priv, drv, priv->dev, "freed rx ring %d\n", idx); netif_dbg(priv, drv, priv->dev, "freed rx ring %d\n", idx);
} }
static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx) void gve_rx_start_ring_dqo(struct gve_priv *priv, int idx)
{
int ntfy_idx = gve_rx_idx_to_ntfy(priv, idx);
gve_rx_add_to_block(priv, idx);
gve_add_napi(priv, ntfy_idx, gve_napi_poll_dqo);
}
static int gve_rx_alloc_ring_dqo(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg,
struct gve_rx_ring *rx,
int idx)
{ {
struct gve_rx_ring *rx = &priv->rx[idx];
struct device *hdev = &priv->pdev->dev; struct device *hdev = &priv->pdev->dev;
size_t size; size_t size;
int i; int i;
const u32 buffer_queue_slots = const u32 buffer_queue_slots = cfg->raw_addressing ?
priv->queue_format == GVE_DQO_RDA_FORMAT ? priv->options_dqo_rda.rx_buff_ring_entries : cfg->ring_size;
priv->options_dqo_rda.rx_buff_ring_entries : priv->rx_desc_cnt; const u32 completion_queue_slots = cfg->ring_size;
const u32 completion_queue_slots = priv->rx_desc_cnt;
netif_dbg(priv, drv, priv->dev, "allocating rx ring DQO\n"); netif_dbg(priv, drv, priv->dev, "allocating rx ring DQO\n");
...@@ -274,7 +293,7 @@ static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx) ...@@ -274,7 +293,7 @@ static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx)
rx->ctx.skb_head = NULL; rx->ctx.skb_head = NULL;
rx->ctx.skb_tail = NULL; rx->ctx.skb_tail = NULL;
rx->dqo.num_buf_states = priv->queue_format == GVE_DQO_RDA_FORMAT ? rx->dqo.num_buf_states = cfg->raw_addressing ?
min_t(s16, S16_MAX, buffer_queue_slots * 4) : min_t(s16, S16_MAX, buffer_queue_slots * 4) :
priv->rx_pages_per_qpl; priv->rx_pages_per_qpl;
rx->dqo.buf_states = kvcalloc(rx->dqo.num_buf_states, rx->dqo.buf_states = kvcalloc(rx->dqo.num_buf_states,
...@@ -308,8 +327,8 @@ static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx) ...@@ -308,8 +327,8 @@ static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx)
if (!rx->dqo.bufq.desc_ring) if (!rx->dqo.bufq.desc_ring)
goto err; goto err;
if (priv->queue_format != GVE_DQO_RDA_FORMAT) { if (!cfg->raw_addressing) {
rx->dqo.qpl = gve_assign_rx_qpl(priv, rx->q_num); rx->dqo.qpl = gve_assign_rx_qpl(cfg, rx->q_num);
if (!rx->dqo.qpl) if (!rx->dqo.qpl)
goto err; goto err;
rx->dqo.next_qpl_page_idx = 0; rx->dqo.next_qpl_page_idx = 0;
...@@ -320,12 +339,10 @@ static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx) ...@@ -320,12 +339,10 @@ static int gve_rx_alloc_ring_dqo(struct gve_priv *priv, int idx)
if (!rx->q_resources) if (!rx->q_resources)
goto err; goto err;
gve_rx_add_to_block(priv, idx);
return 0; return 0;
err: err:
gve_rx_free_ring_dqo(priv, idx); gve_rx_free_ring_dqo(priv, rx, cfg);
return -ENOMEM; return -ENOMEM;
} }
...@@ -337,13 +354,26 @@ void gve_rx_write_doorbell_dqo(const struct gve_priv *priv, int queue_idx) ...@@ -337,13 +354,26 @@ void gve_rx_write_doorbell_dqo(const struct gve_priv *priv, int queue_idx)
iowrite32(rx->dqo.bufq.tail, &priv->db_bar2[index]); iowrite32(rx->dqo.bufq.tail, &priv->db_bar2[index]);
} }
int gve_rx_alloc_rings_dqo(struct gve_priv *priv) int gve_rx_alloc_rings_dqo(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
int err = 0; struct gve_rx_ring *rx;
int err;
int i; int i;
for (i = 0; i < priv->rx_cfg.num_queues; i++) { if (!cfg->raw_addressing && !cfg->qpls) {
err = gve_rx_alloc_ring_dqo(priv, i); netif_err(priv, drv, priv->dev,
"Cannot alloc QPL ring before allocing QPLs\n");
return -EINVAL;
}
rx = kvcalloc(cfg->qcfg->max_queues, sizeof(struct gve_rx_ring),
GFP_KERNEL);
if (!rx)
return -ENOMEM;
for (i = 0; i < cfg->qcfg->num_queues; i++) {
err = gve_rx_alloc_ring_dqo(priv, cfg, &rx[i], i);
if (err) { if (err) {
netif_err(priv, drv, priv->dev, netif_err(priv, drv, priv->dev,
"Failed to alloc rx ring=%d: err=%d\n", "Failed to alloc rx ring=%d: err=%d\n",
...@@ -352,21 +382,30 @@ int gve_rx_alloc_rings_dqo(struct gve_priv *priv) ...@@ -352,21 +382,30 @@ int gve_rx_alloc_rings_dqo(struct gve_priv *priv)
} }
} }
cfg->rx = rx;
return 0; return 0;
err: err:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
gve_rx_free_ring_dqo(priv, i); gve_rx_free_ring_dqo(priv, &rx[i], cfg);
kvfree(rx);
return err; return err;
} }
void gve_rx_free_rings_dqo(struct gve_priv *priv) void gve_rx_free_rings_dqo(struct gve_priv *priv,
struct gve_rx_alloc_rings_cfg *cfg)
{ {
struct gve_rx_ring *rx = cfg->rx;
int i; int i;
for (i = 0; i < priv->rx_cfg.num_queues; i++) if (!rx)
gve_rx_free_ring_dqo(priv, i); return;
for (i = 0; i < cfg->qcfg->num_queues; i++)
gve_rx_free_ring_dqo(priv, &rx[i], cfg);
kvfree(rx);
cfg->rx = NULL;
} }
void gve_rx_post_buffers_dqo(struct gve_rx_ring *rx) void gve_rx_post_buffers_dqo(struct gve_rx_ring *rx)
......
...@@ -196,29 +196,36 @@ static int gve_clean_xdp_done(struct gve_priv *priv, struct gve_tx_ring *tx, ...@@ -196,29 +196,36 @@ static int gve_clean_xdp_done(struct gve_priv *priv, struct gve_tx_ring *tx,
static int gve_clean_tx_done(struct gve_priv *priv, struct gve_tx_ring *tx, static int gve_clean_tx_done(struct gve_priv *priv, struct gve_tx_ring *tx,
u32 to_do, bool try_to_wake); u32 to_do, bool try_to_wake);
static void gve_tx_free_ring(struct gve_priv *priv, int idx) void gve_tx_stop_ring_gqi(struct gve_priv *priv, int idx)
{ {
int ntfy_idx = gve_tx_idx_to_ntfy(priv, idx);
struct gve_tx_ring *tx = &priv->tx[idx]; struct gve_tx_ring *tx = &priv->tx[idx];
if (!gve_tx_was_added_to_block(priv, idx))
return;
gve_remove_napi(priv, ntfy_idx);
gve_clean_tx_done(priv, tx, priv->tx_desc_cnt, false);
netdev_tx_reset_queue(tx->netdev_txq);
gve_tx_remove_from_block(priv, idx);
}
static void gve_tx_free_ring_gqi(struct gve_priv *priv, struct gve_tx_ring *tx,
struct gve_tx_alloc_rings_cfg *cfg)
{
struct device *hdev = &priv->pdev->dev; struct device *hdev = &priv->pdev->dev;
int idx = tx->q_num;
size_t bytes; size_t bytes;
u32 slots; u32 slots;
gve_tx_remove_from_block(priv, idx);
slots = tx->mask + 1; slots = tx->mask + 1;
if (tx->q_num < priv->tx_cfg.num_queues) {
gve_clean_tx_done(priv, tx, priv->tx_desc_cnt, false);
netdev_tx_reset_queue(tx->netdev_txq);
} else {
gve_clean_xdp_done(priv, tx, priv->tx_desc_cnt);
}
dma_free_coherent(hdev, sizeof(*tx->q_resources), dma_free_coherent(hdev, sizeof(*tx->q_resources),
tx->q_resources, tx->q_resources_bus); tx->q_resources, tx->q_resources_bus);
tx->q_resources = NULL; tx->q_resources = NULL;
if (!tx->raw_addressing) { if (!tx->raw_addressing) {
gve_tx_fifo_release(priv, &tx->tx_fifo); gve_tx_fifo_release(priv, &tx->tx_fifo);
gve_unassign_qpl(priv, tx->tx_fifo.qpl->id); gve_unassign_qpl(cfg->qpl_cfg, tx->tx_fifo.qpl->id);
tx->tx_fifo.qpl = NULL; tx->tx_fifo.qpl = NULL;
} }
...@@ -232,11 +239,23 @@ static void gve_tx_free_ring(struct gve_priv *priv, int idx) ...@@ -232,11 +239,23 @@ static void gve_tx_free_ring(struct gve_priv *priv, int idx)
netif_dbg(priv, drv, priv->dev, "freed tx queue %d\n", idx); netif_dbg(priv, drv, priv->dev, "freed tx queue %d\n", idx);
} }
static int gve_tx_alloc_ring(struct gve_priv *priv, int idx) void gve_tx_start_ring_gqi(struct gve_priv *priv, int idx)
{ {
int ntfy_idx = gve_tx_idx_to_ntfy(priv, idx);
struct gve_tx_ring *tx = &priv->tx[idx]; struct gve_tx_ring *tx = &priv->tx[idx];
gve_tx_add_to_block(priv, idx);
tx->netdev_txq = netdev_get_tx_queue(priv->dev, idx);
gve_add_napi(priv, ntfy_idx, gve_napi_poll);
}
static int gve_tx_alloc_ring_gqi(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg,
struct gve_tx_ring *tx,
int idx)
{
struct device *hdev = &priv->pdev->dev; struct device *hdev = &priv->pdev->dev;
u32 slots = priv->tx_desc_cnt;
size_t bytes; size_t bytes;
/* Make sure everything is zeroed to start */ /* Make sure everything is zeroed to start */
...@@ -245,23 +264,23 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -245,23 +264,23 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
spin_lock_init(&tx->xdp_lock); spin_lock_init(&tx->xdp_lock);
tx->q_num = idx; tx->q_num = idx;
tx->mask = slots - 1; tx->mask = cfg->ring_size - 1;
/* alloc metadata */ /* alloc metadata */
tx->info = vcalloc(slots, sizeof(*tx->info)); tx->info = vcalloc(cfg->ring_size, sizeof(*tx->info));
if (!tx->info) if (!tx->info)
return -ENOMEM; return -ENOMEM;
/* alloc tx queue */ /* alloc tx queue */
bytes = sizeof(*tx->desc) * slots; bytes = sizeof(*tx->desc) * cfg->ring_size;
tx->desc = dma_alloc_coherent(hdev, bytes, &tx->bus, GFP_KERNEL); tx->desc = dma_alloc_coherent(hdev, bytes, &tx->bus, GFP_KERNEL);
if (!tx->desc) if (!tx->desc)
goto abort_with_info; goto abort_with_info;
tx->raw_addressing = priv->queue_format == GVE_GQI_RDA_FORMAT; tx->raw_addressing = cfg->raw_addressing;
tx->dev = &priv->pdev->dev; tx->dev = hdev;
if (!tx->raw_addressing) { if (!tx->raw_addressing) {
tx->tx_fifo.qpl = gve_assign_tx_qpl(priv, idx); tx->tx_fifo.qpl = gve_assign_tx_qpl(cfg, idx);
if (!tx->tx_fifo.qpl) if (!tx->tx_fifo.qpl)
goto abort_with_desc; goto abort_with_desc;
/* map Tx FIFO */ /* map Tx FIFO */
...@@ -277,12 +296,6 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -277,12 +296,6 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
if (!tx->q_resources) if (!tx->q_resources)
goto abort_with_fifo; goto abort_with_fifo;
netif_dbg(priv, drv, priv->dev, "tx[%d]->bus=%lx\n", idx,
(unsigned long)tx->bus);
if (idx < priv->tx_cfg.num_queues)
tx->netdev_txq = netdev_get_tx_queue(priv->dev, idx);
gve_tx_add_to_block(priv, idx);
return 0; return 0;
abort_with_fifo: abort_with_fifo:
...@@ -290,7 +303,7 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -290,7 +303,7 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
gve_tx_fifo_release(priv, &tx->tx_fifo); gve_tx_fifo_release(priv, &tx->tx_fifo);
abort_with_qpl: abort_with_qpl:
if (!tx->raw_addressing) if (!tx->raw_addressing)
gve_unassign_qpl(priv, tx->tx_fifo.qpl->id); gve_unassign_qpl(cfg->qpl_cfg, tx->tx_fifo.qpl->id);
abort_with_desc: abort_with_desc:
dma_free_coherent(hdev, bytes, tx->desc, tx->bus); dma_free_coherent(hdev, bytes, tx->desc, tx->bus);
tx->desc = NULL; tx->desc = NULL;
...@@ -300,36 +313,73 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx) ...@@ -300,36 +313,73 @@ static int gve_tx_alloc_ring(struct gve_priv *priv, int idx)
return -ENOMEM; return -ENOMEM;
} }
int gve_tx_alloc_rings(struct gve_priv *priv, int start_id, int num_rings) int gve_tx_alloc_rings_gqi(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg)
{ {
struct gve_tx_ring *tx = cfg->tx;
int err = 0; int err = 0;
int i; int i, j;
if (!cfg->raw_addressing && !cfg->qpls) {
netif_err(priv, drv, priv->dev,
"Cannot alloc QPL ring before allocing QPLs\n");
return -EINVAL;
}
if (cfg->start_idx + cfg->num_rings > cfg->qcfg->max_queues) {
netif_err(priv, drv, priv->dev,
"Cannot alloc more than the max num of Tx rings\n");
return -EINVAL;
}
if (cfg->start_idx == 0) {
tx = kvcalloc(cfg->qcfg->max_queues, sizeof(struct gve_tx_ring),
GFP_KERNEL);
if (!tx)
return -ENOMEM;
} else if (!tx) {
netif_err(priv, drv, priv->dev,
"Cannot alloc tx rings from a nonzero start idx without tx array\n");
return -EINVAL;
}
for (i = start_id; i < start_id + num_rings; i++) { for (i = cfg->start_idx; i < cfg->start_idx + cfg->num_rings; i++) {
err = gve_tx_alloc_ring(priv, i); err = gve_tx_alloc_ring_gqi(priv, cfg, &tx[i], i);
if (err) { if (err) {
netif_err(priv, drv, priv->dev, netif_err(priv, drv, priv->dev,
"Failed to alloc tx ring=%d: err=%d\n", "Failed to alloc tx ring=%d: err=%d\n",
i, err); i, err);
break; goto cleanup;
} }
} }
/* Unallocate if there was an error */
if (err) {
int j;
for (j = start_id; j < i; j++) cfg->tx = tx;
gve_tx_free_ring(priv, j); return 0;
}
cleanup:
for (j = 0; j < i; j++)
gve_tx_free_ring_gqi(priv, &tx[j], cfg);
if (cfg->start_idx == 0)
kvfree(tx);
return err; return err;
} }
void gve_tx_free_rings_gqi(struct gve_priv *priv, int start_id, int num_rings) void gve_tx_free_rings_gqi(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg)
{ {
struct gve_tx_ring *tx = cfg->tx;
int i; int i;
for (i = start_id; i < start_id + num_rings; i++) if (!tx)
gve_tx_free_ring(priv, i); return;
for (i = cfg->start_idx; i < cfg->start_idx + cfg->num_rings; i++)
gve_tx_free_ring_gqi(priv, &tx[i], cfg);
if (cfg->start_idx == 0) {
kvfree(tx);
cfg->tx = NULL;
}
} }
/* gve_tx_avail - Calculates the number of slots available in the ring /* gve_tx_avail - Calculates the number of slots available in the ring
......
...@@ -188,13 +188,27 @@ static void gve_tx_clean_pending_packets(struct gve_tx_ring *tx) ...@@ -188,13 +188,27 @@ static void gve_tx_clean_pending_packets(struct gve_tx_ring *tx)
} }
} }
static void gve_tx_free_ring_dqo(struct gve_priv *priv, int idx) void gve_tx_stop_ring_dqo(struct gve_priv *priv, int idx)
{ {
int ntfy_idx = gve_tx_idx_to_ntfy(priv, idx);
struct gve_tx_ring *tx = &priv->tx[idx]; struct gve_tx_ring *tx = &priv->tx[idx];
struct device *hdev = &priv->pdev->dev;
size_t bytes;
if (!gve_tx_was_added_to_block(priv, idx))
return;
gve_remove_napi(priv, ntfy_idx);
gve_clean_tx_done_dqo(priv, tx, /*napi=*/NULL);
netdev_tx_reset_queue(tx->netdev_txq);
gve_tx_clean_pending_packets(tx);
gve_tx_remove_from_block(priv, idx); gve_tx_remove_from_block(priv, idx);
}
static void gve_tx_free_ring_dqo(struct gve_priv *priv, struct gve_tx_ring *tx,
struct gve_tx_alloc_rings_cfg *cfg)
{
struct device *hdev = &priv->pdev->dev;
int idx = tx->q_num;
size_t bytes;
if (tx->q_resources) { if (tx->q_resources) {
dma_free_coherent(hdev, sizeof(*tx->q_resources), dma_free_coherent(hdev, sizeof(*tx->q_resources),
...@@ -223,7 +237,7 @@ static void gve_tx_free_ring_dqo(struct gve_priv *priv, int idx) ...@@ -223,7 +237,7 @@ static void gve_tx_free_ring_dqo(struct gve_priv *priv, int idx)
tx->dqo.tx_qpl_buf_next = NULL; tx->dqo.tx_qpl_buf_next = NULL;
if (tx->dqo.qpl) { if (tx->dqo.qpl) {
gve_unassign_qpl(priv, tx->dqo.qpl->id); gve_unassign_qpl(cfg->qpl_cfg, tx->dqo.qpl->id);
tx->dqo.qpl = NULL; tx->dqo.qpl = NULL;
} }
...@@ -253,9 +267,22 @@ static int gve_tx_qpl_buf_init(struct gve_tx_ring *tx) ...@@ -253,9 +267,22 @@ static int gve_tx_qpl_buf_init(struct gve_tx_ring *tx)
return 0; return 0;
} }
static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx) void gve_tx_start_ring_dqo(struct gve_priv *priv, int idx)
{ {
int ntfy_idx = gve_tx_idx_to_ntfy(priv, idx);
struct gve_tx_ring *tx = &priv->tx[idx]; struct gve_tx_ring *tx = &priv->tx[idx];
gve_tx_add_to_block(priv, idx);
tx->netdev_txq = netdev_get_tx_queue(priv->dev, idx);
gve_add_napi(priv, ntfy_idx, gve_napi_poll_dqo);
}
static int gve_tx_alloc_ring_dqo(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg,
struct gve_tx_ring *tx,
int idx)
{
struct device *hdev = &priv->pdev->dev; struct device *hdev = &priv->pdev->dev;
int num_pending_packets; int num_pending_packets;
size_t bytes; size_t bytes;
...@@ -263,12 +290,11 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx) ...@@ -263,12 +290,11 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx)
memset(tx, 0, sizeof(*tx)); memset(tx, 0, sizeof(*tx));
tx->q_num = idx; tx->q_num = idx;
tx->dev = &priv->pdev->dev; tx->dev = hdev;
tx->netdev_txq = netdev_get_tx_queue(priv->dev, idx);
atomic_set_release(&tx->dqo_compl.hw_tx_head, 0); atomic_set_release(&tx->dqo_compl.hw_tx_head, 0);
/* Queue sizes must be a power of 2 */ /* Queue sizes must be a power of 2 */
tx->mask = priv->tx_desc_cnt - 1; tx->mask = cfg->ring_size - 1;
tx->dqo.complq_mask = priv->queue_format == GVE_DQO_RDA_FORMAT ? tx->dqo.complq_mask = priv->queue_format == GVE_DQO_RDA_FORMAT ?
priv->options_dqo_rda.tx_comp_ring_entries - 1 : priv->options_dqo_rda.tx_comp_ring_entries - 1 :
tx->mask; tx->mask;
...@@ -327,8 +353,8 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx) ...@@ -327,8 +353,8 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx)
if (!tx->q_resources) if (!tx->q_resources)
goto err; goto err;
if (gve_is_qpl(priv)) { if (!cfg->raw_addressing) {
tx->dqo.qpl = gve_assign_tx_qpl(priv, idx); tx->dqo.qpl = gve_assign_tx_qpl(cfg, idx);
if (!tx->dqo.qpl) if (!tx->dqo.qpl)
goto err; goto err;
...@@ -336,22 +362,45 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx) ...@@ -336,22 +362,45 @@ static int gve_tx_alloc_ring_dqo(struct gve_priv *priv, int idx)
goto err; goto err;
} }
gve_tx_add_to_block(priv, idx);
return 0; return 0;
err: err:
gve_tx_free_ring_dqo(priv, idx); gve_tx_free_ring_dqo(priv, tx, cfg);
return -ENOMEM; return -ENOMEM;
} }
int gve_tx_alloc_rings_dqo(struct gve_priv *priv) int gve_tx_alloc_rings_dqo(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg)
{ {
struct gve_tx_ring *tx = cfg->tx;
int err = 0; int err = 0;
int i; int i, j;
for (i = 0; i < priv->tx_cfg.num_queues; i++) { if (!cfg->raw_addressing && !cfg->qpls) {
err = gve_tx_alloc_ring_dqo(priv, i); netif_err(priv, drv, priv->dev,
"Cannot alloc QPL ring before allocing QPLs\n");
return -EINVAL;
}
if (cfg->start_idx + cfg->num_rings > cfg->qcfg->max_queues) {
netif_err(priv, drv, priv->dev,
"Cannot alloc more than the max num of Tx rings\n");
return -EINVAL;
}
if (cfg->start_idx == 0) {
tx = kvcalloc(cfg->qcfg->max_queues, sizeof(struct gve_tx_ring),
GFP_KERNEL);
if (!tx)
return -ENOMEM;
} else if (!tx) {
netif_err(priv, drv, priv->dev,
"Cannot alloc tx rings from a nonzero start idx without tx array\n");
return -EINVAL;
}
for (i = cfg->start_idx; i < cfg->start_idx + cfg->num_rings; i++) {
err = gve_tx_alloc_ring_dqo(priv, cfg, &tx[i], i);
if (err) { if (err) {
netif_err(priv, drv, priv->dev, netif_err(priv, drv, priv->dev,
"Failed to alloc tx ring=%d: err=%d\n", "Failed to alloc tx ring=%d: err=%d\n",
...@@ -360,27 +409,32 @@ int gve_tx_alloc_rings_dqo(struct gve_priv *priv) ...@@ -360,27 +409,32 @@ int gve_tx_alloc_rings_dqo(struct gve_priv *priv)
} }
} }
cfg->tx = tx;
return 0; return 0;
err: err:
for (i--; i >= 0; i--) for (j = 0; j < i; j++)
gve_tx_free_ring_dqo(priv, i); gve_tx_free_ring_dqo(priv, &tx[j], cfg);
if (cfg->start_idx == 0)
kvfree(tx);
return err; return err;
} }
void gve_tx_free_rings_dqo(struct gve_priv *priv) void gve_tx_free_rings_dqo(struct gve_priv *priv,
struct gve_tx_alloc_rings_cfg *cfg)
{ {
struct gve_tx_ring *tx = cfg->tx;
int i; int i;
for (i = 0; i < priv->tx_cfg.num_queues; i++) { if (!tx)
struct gve_tx_ring *tx = &priv->tx[i]; return;
gve_clean_tx_done_dqo(priv, tx, /*napi=*/NULL); for (i = cfg->start_idx; i < cfg->start_idx + cfg->num_rings; i++)
netdev_tx_reset_queue(tx->netdev_txq); gve_tx_free_ring_dqo(priv, &tx[i], cfg);
gve_tx_clean_pending_packets(tx);
gve_tx_free_ring_dqo(priv, i); if (cfg->start_idx == 0) {
kvfree(tx);
cfg->tx = NULL;
} }
} }
......
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
#include "gve_adminq.h" #include "gve_adminq.h"
#include "gve_utils.h" #include "gve_utils.h"
bool gve_tx_was_added_to_block(struct gve_priv *priv, int queue_idx)
{
struct gve_notify_block *block =
&priv->ntfy_blocks[gve_tx_idx_to_ntfy(priv, queue_idx)];
return block->tx != NULL;
}
void gve_tx_remove_from_block(struct gve_priv *priv, int queue_idx) void gve_tx_remove_from_block(struct gve_priv *priv, int queue_idx)
{ {
struct gve_notify_block *block = struct gve_notify_block *block =
...@@ -30,6 +38,14 @@ void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx) ...@@ -30,6 +38,14 @@ void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx)
queue_idx); queue_idx);
} }
bool gve_rx_was_added_to_block(struct gve_priv *priv, int queue_idx)
{
struct gve_notify_block *block =
&priv->ntfy_blocks[gve_rx_idx_to_ntfy(priv, queue_idx)];
return block->rx != NULL;
}
void gve_rx_remove_from_block(struct gve_priv *priv, int queue_idx) void gve_rx_remove_from_block(struct gve_priv *priv, int queue_idx)
{ {
struct gve_notify_block *block = struct gve_notify_block *block =
...@@ -81,3 +97,18 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info) ...@@ -81,3 +97,18 @@ void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info)
page_ref_add(page_info->page, INT_MAX - pagecount); page_ref_add(page_info->page, INT_MAX - pagecount);
} }
} }
void gve_add_napi(struct gve_priv *priv, int ntfy_idx,
int (*gve_poll)(struct napi_struct *, int))
{
struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];
netif_napi_add(priv->dev, &block->napi, gve_poll);
}
void gve_remove_napi(struct gve_priv *priv, int ntfy_idx)
{
struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];
netif_napi_del(&block->napi);
}
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
#include "gve.h" #include "gve.h"
bool gve_tx_was_added_to_block(struct gve_priv *priv, int queue_idx);
void gve_tx_remove_from_block(struct gve_priv *priv, int queue_idx); void gve_tx_remove_from_block(struct gve_priv *priv, int queue_idx);
void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx); void gve_tx_add_to_block(struct gve_priv *priv, int queue_idx);
bool gve_rx_was_added_to_block(struct gve_priv *priv, int queue_idx);
void gve_rx_remove_from_block(struct gve_priv *priv, int queue_idx); void gve_rx_remove_from_block(struct gve_priv *priv, int queue_idx);
void gve_rx_add_to_block(struct gve_priv *priv, int queue_idx); void gve_rx_add_to_block(struct gve_priv *priv, int queue_idx);
...@@ -23,5 +25,8 @@ struct sk_buff *gve_rx_copy(struct net_device *dev, struct napi_struct *napi, ...@@ -23,5 +25,8 @@ struct sk_buff *gve_rx_copy(struct net_device *dev, struct napi_struct *napi,
/* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */ /* Decrement pagecnt_bias. Set it back to INT_MAX if it reached zero. */
void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info); void gve_dec_pagecnt_bias(struct gve_rx_slot_page_info *page_info);
void gve_add_napi(struct gve_priv *priv, int ntfy_idx,
int (*gve_poll)(struct napi_struct *, int));
void gve_remove_napi(struct gve_priv *priv, int ntfy_idx);
#endif /* _GVE_UTILS_H */ #endif /* _GVE_UTILS_H */
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