mirror of
https://github.com/fpganinja/taxi.git
synced 2026-01-18 01:30:36 -08:00
cndm: Assign instance ID
Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
@@ -25,6 +25,9 @@ struct cndm_dev {
|
||||
struct pci_dev *pdev;
|
||||
struct device *dev;
|
||||
|
||||
unsigned int id;
|
||||
char name[16];
|
||||
|
||||
struct net_device *ndev[32];
|
||||
|
||||
void __iomem *bar;
|
||||
|
||||
@@ -18,6 +18,25 @@ MODULE_AUTHOR("FPGA Ninja");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_VERSION(DRIVER_VERSION);
|
||||
|
||||
static DEFINE_IDA(cndm_instance_ida);
|
||||
|
||||
static int cndm_assign_id(struct cndm_dev *cdev)
|
||||
{
|
||||
int ret = ida_alloc(&cndm_instance_ida, GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
cdev->id = ret;
|
||||
snprintf(cdev->name, sizeof(cdev->name), DRIVER_NAME "%d", cdev->id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cndm_free_id(struct cndm_dev *cdev)
|
||||
{
|
||||
ida_free(&cndm_instance_ida, cdev->id);
|
||||
}
|
||||
|
||||
static int cndm_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
@@ -43,6 +62,10 @@ static int cndm_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
cdev->dev = dev;
|
||||
pci_set_drvdata(pdev, cdev);
|
||||
|
||||
ret = cndm_assign_id(cdev);
|
||||
if (ret)
|
||||
goto fail_assign_id;
|
||||
|
||||
ret = pci_enable_device_mem(pdev);
|
||||
if (ret) {
|
||||
dev_err(dev, "Failed to enable device");
|
||||
@@ -132,6 +155,8 @@ fail_regions:
|
||||
pci_clear_master(pdev);
|
||||
pci_disable_device(pdev);
|
||||
fail_enable_device:
|
||||
cndm_free_id(cdev);
|
||||
fail_assign_id:
|
||||
cndm_devlink_free(devlink);
|
||||
return ret;
|
||||
}
|
||||
@@ -159,6 +184,7 @@ static void cndm_pci_remove(struct pci_dev *pdev)
|
||||
pci_release_regions(pdev);
|
||||
pci_clear_master(pdev);
|
||||
pci_disable_device(pdev);
|
||||
cndm_free_id(cdev);
|
||||
cndm_devlink_free(devlink);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user