Skip to content

Commit fb0a6a2

Browse files
elic307iSaeed Mahameed
authored andcommitted
net/mlx5: Provide external API for allocating vectors
Provide external API to be used by other drivers relying on mlx5_core, for allocating MSIX vectors. An example for such a driver would be mlx5_vdpa. Signed-off-by: Eli Cohen <[email protected]> Reviewed-by: Shay Drory <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Jacob Keller <[email protected]>
1 parent b637ac5 commit fb0a6a2

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,58 @@ struct mlx5_irq *mlx5_irq_request(struct mlx5_core_dev *dev, u16 vecidx,
483483
return irq;
484484
}
485485

486+
/**
487+
* mlx5_msix_alloc - allocate msix interrupt
488+
* @dev: mlx5 device from which to request
489+
* @handler: interrupt handler
490+
* @affdesc: affinity descriptor
491+
* @name: interrupt name
492+
*
493+
* Returns: struct msi_map with result encoded.
494+
* Note: the caller must make sure to release the irq by calling
495+
* mlx5_msix_free() if shutdown was initiated.
496+
*/
497+
struct msi_map mlx5_msix_alloc(struct mlx5_core_dev *dev,
498+
irqreturn_t (*handler)(int, void *),
499+
const struct irq_affinity_desc *affdesc,
500+
const char *name)
501+
{
502+
struct msi_map map;
503+
int err;
504+
505+
if (!dev->pdev) {
506+
map.virq = 0;
507+
map.index = -EINVAL;
508+
return map;
509+
}
510+
511+
map = pci_msix_alloc_irq_at(dev->pdev, MSI_ANY_INDEX, affdesc);
512+
if (!map.virq)
513+
return map;
514+
515+
err = request_irq(map.virq, handler, 0, name, NULL);
516+
if (err) {
517+
mlx5_core_warn(dev, "err %d\n", err);
518+
pci_msix_free_irq(dev->pdev, map);
519+
map.virq = 0;
520+
map.index = -ENOMEM;
521+
}
522+
return map;
523+
}
524+
EXPORT_SYMBOL(mlx5_msix_alloc);
525+
526+
/**
527+
* mlx5_msix_free - free a previously allocated msix interrupt
528+
* @dev: mlx5 device associated with interrupt
529+
* @map: map previously returned by mlx5_msix_alloc()
530+
*/
531+
void mlx5_msix_free(struct mlx5_core_dev *dev, struct msi_map map)
532+
{
533+
free_irq(map.virq, NULL);
534+
pci_msix_free_irq(dev->pdev, map);
535+
}
536+
EXPORT_SYMBOL(mlx5_msix_free);
537+
486538
/**
487539
* mlx5_irqs_release_vectors - release one or more IRQs back to the system.
488540
* @irqs: IRQs to be released.

include/linux/mlx5/driver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,4 +1308,10 @@ enum {
13081308
MLX5_OCTWORD = 16,
13091309
};
13101310

1311+
struct msi_map mlx5_msix_alloc(struct mlx5_core_dev *dev,
1312+
irqreturn_t (*handler)(int, void *),
1313+
const struct irq_affinity_desc *affdesc,
1314+
const char *name);
1315+
void mlx5_msix_free(struct mlx5_core_dev *dev, struct msi_map map);
1316+
13111317
#endif /* MLX5_DRIVER_H */

0 commit comments

Comments
 (0)