Skip to content

Commit d30baac

Browse files
catSully012davem330
authored andcommitted
gve: Move the irq db indexes out of the ntfy block struct
Giving the device access to other kernel structs is not ideal. Move the indexes into their own array and just keep pointers to them in the ntfy block struct. Signed-off-by: Catherine Sullivan <[email protected]> Signed-off-by: David Awogbemila <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a10834a commit d30baac

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,13 @@ struct gve_tx_ring {
441441
* associated with that irq.
442442
*/
443443
struct gve_notify_block {
444-
__be32 irq_db_index; /* idx into Bar2 - set by device, must be 1st */
444+
__be32 *irq_db_index; /* pointer to idx into Bar2 */
445445
char name[IFNAMSIZ + 16]; /* name registered with the kernel */
446446
struct napi_struct napi; /* kernel napi struct for this block */
447447
struct gve_priv *priv;
448448
struct gve_tx_ring *tx; /* tx rings on this block */
449449
struct gve_rx_ring *rx; /* rx rings on this block */
450-
} ____cacheline_aligned;
450+
};
451451

452452
/* Tracks allowed and current queue settings */
453453
struct gve_queue_config {
@@ -466,6 +466,10 @@ struct gve_options_dqo_rda {
466466
u16 rx_buff_ring_entries; /* number of rx_buff descriptors */
467467
};
468468

469+
struct gve_irq_db {
470+
__be32 index;
471+
} ____cacheline_aligned;
472+
469473
struct gve_ptype {
470474
u8 l3_type; /* `gve_l3_type` in gve_adminq.h */
471475
u8 l4_type; /* `gve_l4_type` in gve_adminq.h */
@@ -492,7 +496,8 @@ struct gve_priv {
492496
struct gve_rx_ring *rx; /* array of rx_cfg.num_queues */
493497
struct gve_queue_page_list *qpls; /* array of num qpls */
494498
struct gve_notify_block *ntfy_blocks; /* array of num_ntfy_blks */
495-
dma_addr_t ntfy_block_bus;
499+
struct gve_irq_db *irq_db_indices; /* array of num_ntfy_blks */
500+
dma_addr_t irq_db_indices_bus;
496501
struct msix_entry *msix_vectors; /* array of num_ntfy_blks + 1 */
497502
char mgmt_msix_name[IFNAMSIZ + 16];
498503
u32 mgmt_msix_idx;
@@ -733,7 +738,7 @@ static inline void gve_clear_report_stats(struct gve_priv *priv)
733738
static inline __be32 __iomem *gve_irq_doorbell(struct gve_priv *priv,
734739
struct gve_notify_block *block)
735740
{
736-
return &priv->db_bar2[be32_to_cpu(block->irq_db_index)];
741+
return &priv->db_bar2[be32_to_cpu(*block->irq_db_index)];
737742
}
738743

739744
/* Returns the index into ntfy_blocks of the given tx ring's block

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
462462
.num_counters = cpu_to_be32(num_counters),
463463
.irq_db_addr = cpu_to_be64(db_array_bus_addr),
464464
.num_irq_dbs = cpu_to_be32(num_ntfy_blks),
465-
.irq_db_stride = cpu_to_be32(sizeof(priv->ntfy_blocks[0])),
465+
.irq_db_stride = cpu_to_be32(sizeof(*priv->irq_db_indices)),
466466
.ntfy_blk_msix_base_idx =
467467
cpu_to_be32(GVE_NTFY_BLK_BASE_MSIX_IDX),
468468
.queue_format = priv->queue_format,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static inline void
7373
gve_write_irq_doorbell_dqo(const struct gve_priv *priv,
7474
const struct gve_notify_block *block, u32 val)
7575
{
76-
u32 index = be32_to_cpu(block->irq_db_index);
76+
u32 index = be32_to_cpu(*block->irq_db_index);
7777

7878
iowrite32(val, &priv->db_bar2[index]);
7979
}

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,23 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv)
334334
dev_err(&priv->pdev->dev, "Did not receive management vector.\n");
335335
goto abort_with_msix_enabled;
336336
}
337-
priv->ntfy_blocks =
337+
priv->irq_db_indices =
338338
dma_alloc_coherent(&priv->pdev->dev,
339339
priv->num_ntfy_blks *
340-
sizeof(*priv->ntfy_blocks),
341-
&priv->ntfy_block_bus, GFP_KERNEL);
342-
if (!priv->ntfy_blocks) {
340+
sizeof(*priv->irq_db_indices),
341+
&priv->irq_db_indices_bus, GFP_KERNEL);
342+
if (!priv->irq_db_indices) {
343343
err = -ENOMEM;
344344
goto abort_with_mgmt_vector;
345345
}
346+
347+
priv->ntfy_blocks = kvzalloc(priv->num_ntfy_blks *
348+
sizeof(*priv->ntfy_blocks), GFP_KERNEL);
349+
if (!priv->ntfy_blocks) {
350+
err = -ENOMEM;
351+
goto abort_with_irq_db_indices;
352+
}
353+
346354
/* Setup the other blocks - the first n-1 vectors */
347355
for (i = 0; i < priv->num_ntfy_blks; i++) {
348356
struct gve_notify_block *block = &priv->ntfy_blocks[i];
@@ -361,6 +369,7 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv)
361369
}
362370
irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector,
363371
get_cpu_mask(i % active_cpus));
372+
block->irq_db_index = &priv->irq_db_indices[i].index;
364373
}
365374
return 0;
366375
abort_with_some_ntfy_blocks:
@@ -372,10 +381,13 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv)
372381
NULL);
373382
free_irq(priv->msix_vectors[msix_idx].vector, block);
374383
}
375-
dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks *
376-
sizeof(*priv->ntfy_blocks),
377-
priv->ntfy_blocks, priv->ntfy_block_bus);
384+
kvfree(priv->ntfy_blocks);
378385
priv->ntfy_blocks = NULL;
386+
abort_with_irq_db_indices:
387+
dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks *
388+
sizeof(*priv->irq_db_indices),
389+
priv->irq_db_indices, priv->irq_db_indices_bus);
390+
priv->irq_db_indices = NULL;
379391
abort_with_mgmt_vector:
380392
free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv);
381393
abort_with_msix_enabled:
@@ -403,10 +415,12 @@ static void gve_free_notify_blocks(struct gve_priv *priv)
403415
free_irq(priv->msix_vectors[msix_idx].vector, block);
404416
}
405417
free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv);
406-
dma_free_coherent(&priv->pdev->dev,
407-
priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks),
408-
priv->ntfy_blocks, priv->ntfy_block_bus);
418+
kvfree(priv->ntfy_blocks);
409419
priv->ntfy_blocks = NULL;
420+
dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks *
421+
sizeof(*priv->irq_db_indices),
422+
priv->irq_db_indices, priv->irq_db_indices_bus);
423+
priv->irq_db_indices = NULL;
410424
pci_disable_msix(priv->pdev);
411425
kvfree(priv->msix_vectors);
412426
priv->msix_vectors = NULL;
@@ -428,7 +442,7 @@ static int gve_setup_device_resources(struct gve_priv *priv)
428442
err = gve_adminq_configure_device_resources(priv,
429443
priv->counter_array_bus,
430444
priv->num_event_counters,
431-
priv->ntfy_block_bus,
445+
priv->irq_db_indices_bus,
432446
priv->num_ntfy_blks);
433447
if (unlikely(err)) {
434448
dev_err(&priv->pdev->dev,

0 commit comments

Comments
 (0)