Add a module parameter that allows specification of one or more CCPs
based on PCI bus identifiers. The value of the parameter is a comma-
separated list of bus numbers, in no particular order.
Signed-off-by: Gary R Hook <[email protected]>
---
drivers/crypto/ccp/sp-pci.c | 58 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
index bcd1e233dce7..a563d85b242e 100644
--- a/drivers/crypto/ccp/sp-pci.c
+++ b/drivers/crypto/ccp/sp-pci.c
@@ -40,6 +40,13 @@ static unsigned int pcidev;
module_param(pcidev, uint, 0444);
MODULE_PARM_DESC(pcidev, "Device number for a specific CCP");
+#define MAXCCPS 32
+static char *buses;
+static unsigned int n_pcibus = 0;
+static unsigned int pcibus[MAXCCPS];
+module_param(buses, charp, 0444);
+MODULE_PARM_DESC(buses, "PCI Bus number(s), comma-separated. List CCPs with 'lspci |grep Enc'");
+
static struct mutex devcount_mutex ____cacheline_aligned;
static unsigned int devcount = 0;
static unsigned int maxdev = 0;
@@ -50,6 +57,37 @@ static unsigned int nqueues = MAX_HW_QUEUES;
module_param(nqueues, uint, 0444);
MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
+#define COMMA ','
+static void ccp_parse_pci_buses(void)
+{
+ unsigned int busno;
+ unsigned int eos = 0;
+ int ret;
+ char *comma;
+ char *tok;
+
+ /* Nothing on the command line? */
+ if (!buses)
+ return;
+
+ comma = tok = buses;
+ while (!eos && *tok && (n_pcibus < MAXCCPS)) {
+ while (*comma && *comma != COMMA)
+ comma++;
+ if (*comma == COMMA)
+ *comma = '\0';
+ else
+ eos = 1;
+ ret = kstrtouint(tok, 0, &busno);
+ if (ret) {
+ pr_info("%s: Parsing error (%d) '%s'\n", __func__, ret, buses);
+ return;
+ }
+ pcibus[n_pcibus++] = busno;
+ tok = ++comma;
+ }
+}
+
#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
modparam_t moduleparameters[] = {
{"maxdev", &maxdev, S_IRUSR},
@@ -204,6 +242,7 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
void __iomem * const *iomap_table;
int bar_mask;
int ret;
+ int j;
if (maxdev && (devcount >= maxdev)) /* Too many devices? */
return 0;
@@ -212,6 +251,25 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (pcidev && (pdev->device != pcidev))
return 0;
+ /*
+ * Look for (1) a specific device, (2) devices on a certain
+ * bus, or (3) a specific device number. If both parameters
+ * are zero accept any device.
+ */
+ ccp_parse_pci_buses();
+ if (n_pcibus) {
+ int match = 0;
+
+ /* Scan the list of buses for a match */
+ for (j = 0 ; j < n_pcibus ; j++)
+ if (pcibus[j] == pdev->bus->number) {
+ match = 1;
+ break;
+ }
+ if (!match)
+ return 0;
+ }
+
ret = -ENOMEM;
sp = sp_alloc_struct(dev);
if (!sp)
On 6/24/19 2:29 PM, Hook, Gary wrote:
> Add a module parameter that allows specification of one or more CCPs
> based on PCI bus identifiers. The value of the parameter is a comma-
> separated list of bus numbers, in no particular order.
>
> Signed-off-by: Gary R Hook <[email protected]>
> ---
> drivers/crypto/ccp/sp-pci.c | 58 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 58 insertions(+)
>
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index bcd1e233dce7..a563d85b242e 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -40,6 +40,13 @@ static unsigned int pcidev;
> module_param(pcidev, uint, 0444);
> MODULE_PARM_DESC(pcidev, "Device number for a specific CCP");
>
> +#define MAXCCPS 32
> +static char *buses;
> +static unsigned int n_pcibus = 0;
> +static unsigned int pcibus[MAXCCPS];
> +module_param(buses, charp, 0444);
> +MODULE_PARM_DESC(buses, "PCI Bus number(s), comma-separated. List CCPs with 'lspci |grep Enc'");
> +
> static struct mutex devcount_mutex ____cacheline_aligned;
> static unsigned int devcount = 0;
> static unsigned int maxdev = 0;
> @@ -50,6 +57,37 @@ static unsigned int nqueues = MAX_HW_QUEUES;
> module_param(nqueues, uint, 0444);
> MODULE_PARM_DESC(nqueues, "Number of queues per CCP (default: 5)");
>
> +#define COMMA ','
> +static void ccp_parse_pci_buses(void)
> +{
> + unsigned int busno;
> + unsigned int eos = 0;
> + int ret;
> + char *comma;
> + char *tok;
> +
> + /* Nothing on the command line? */
> + if (!buses)
> + return;
> +
> + comma = tok = buses;
> + while (!eos && *tok && (n_pcibus < MAXCCPS)) {
> + while (*comma && *comma != COMMA)
> + comma++;
> + if (*comma == COMMA)
> + *comma = '\0';
> + else
> + eos = 1;
> + ret = kstrtouint(tok, 0, &busno);
> + if (ret) {
> + pr_info("%s: Parsing error (%d) '%s'\n", __func__, ret, buses);
> + return;
> + }
> + pcibus[n_pcibus++] = busno;
> + tok = ++comma;
> + }
> +}
> +
> #ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
> modparam_t moduleparameters[] = {
> {"maxdev", &maxdev, S_IRUSR},
> @@ -204,6 +242,7 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> void __iomem * const *iomap_table;
> int bar_mask;
> int ret;
> + int j;
>
> if (maxdev && (devcount >= maxdev)) /* Too many devices? */
> return 0;
> @@ -212,6 +251,25 @@ static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> if (pcidev && (pdev->device != pcidev))
> return 0;
>
> + /*
> + * Look for (1) a specific device, (2) devices on a certain
> + * bus, or (3) a specific device number. If both parameters
> + * are zero accept any device.
> + */
> + ccp_parse_pci_buses();
> + if (n_pcibus) {
> + int match = 0;
> +
> + /* Scan the list of buses for a match */
> + for (j = 0 ; j < n_pcibus ; j++)
> + if (pcibus[j] == pdev->bus->number) {
> + match = 1;
> + break;
> + }
> + if (!match)
> + return 0;
> + }
Same comment as before in regards to CCP and PSP interaction.
Thanks,
Tom
> +
> ret = -ENOMEM;
> sp = sp_alloc_struct(dev);
> if (!sp)
>