- the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
- The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton. It functions against current hardware though.
-- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
- would be nice if the AIO fileops in kpc_dma could be made to work
- probably want to add a CONFIG_ option to control compilation of the AIO functions
- if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
// SPDX-License-Identifier: GPL-2.0+
#include <linux/kernel.h>
+#include <linux/idr.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/pci.h>
#include "pcie.h"
#include "uapi.h"
+static DEFINE_IDA(card_num_ida);
+
/*******************************************************
* SysFS Attributes
******************************************************/
{
int err = 0;
struct kp2000_device *pcard;
- static int card_count = 1;
int rv;
unsigned long reg_bar_phys_addr;
unsigned long reg_bar_phys_len;
/*
* Step 2: Initialize trivial pcard elements
*/
- pcard->card_num = card_count;
- card_count++;
- scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num);
+ err = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
+ if (err < 0) {
+ dev_err(&pdev->dev, "probe: failed to get card number (%d)\n",
+ err);
+ goto out2;
+ }
+ pcard->card_num = err;
+ scnprintf(pcard->name, 16, "kpcard%u", pcard->card_num);
mutex_init(&pcard->sem);
mutex_lock(&pcard->sem);
pci_disable_device(pcard->pdev);
out3:
mutex_unlock(&pcard->sem);
+ ida_simple_remove(&card_num_ida, pcard->card_num);
+out2:
kfree(pcard);
return err;
}
pci_disable_device(pcard->pdev);
pci_set_drvdata(pdev, NULL);
mutex_unlock(&pcard->sem);
+ ida_simple_remove(&card_num_ida, pcard->card_num);
kfree(pcard);
}
{
pci_unregister_driver(&kp2000_driver_inst);
class_destroy(kpc_uio_class);
+ ida_destroy(&card_num_ida);
}
module_exit(kp2000_pcie_exit);