From: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
To: bhelgaas@google.com, kishon@ti.com, lorenzo.pieralisi@arm.com,
linux-pci@vger.kernel.org
Cc: adouglas@cadence.com, stelford@cadence.com, dgary@cadence.com,
kgopi@cadence.com, eandrews@cadence.com,
thomas.petazzoni@free-electrons.com, sureshp@cadence.com,
nsekhar@ti.com, linux-kernel@vger.kernel.org, robh@kernel.org,
devicetree@vger.kernel.org,
Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
Subject: [PATCH v5 09/11] PCI: endpoint: Fix EPF device name to support multi-function devices
Date: Sun, 28 Jan 2018 21:40:23 +0100 [thread overview]
Message-ID: <0c9ae7445f9900f96c62f78e91810dd906bab14f.1517170521.git.cyrille.pitchen@free-electrons.com> (raw)
In-Reply-To: <cover.1517170521.git.cyrille.pitchen@free-electrons.com>
In-Reply-To: <cover.1517170521.git.cyrille.pitchen@free-electrons.com>
Fix the pci_epf_make() function so it can now bind many EPF devices to the
same EPF driver.
Signed-off-by: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
---
drivers/pci/endpoint/pci-ep-cfs.c | 46 +++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c
index c9a2fb9dd49d..9ec28be1e378 100644
--- a/drivers/pci/endpoint/pci-ep-cfs.c
+++ b/drivers/pci/endpoint/pci-ep-cfs.c
@@ -18,18 +18,22 @@
*/
#include <linux/module.h>
+#include <linux/idr.h>
#include <linux/slab.h>
#include <linux/pci-epc.h>
#include <linux/pci-epf.h>
#include <linux/pci-ep-cfs.h>
+static DEFINE_IDR(functions_idr);
+static DEFINE_MUTEX(functions_mutex);
static struct config_group *functions_group;
static struct config_group *controllers_group;
struct pci_epf_group {
struct config_group group;
struct pci_epf *epf;
+ int index;
};
struct pci_epc_group {
@@ -354,6 +358,9 @@ static void pci_epf_release(struct config_item *item)
{
struct pci_epf_group *epf_group = to_pci_epf_group(item);
+ mutex_lock(&functions_mutex);
+ idr_remove(&functions_idr, epf_group->index);
+ mutex_unlock(&functions_mutex);
pci_epf_destroy(epf_group->epf);
kfree(epf_group);
}
@@ -373,22 +380,57 @@ static struct config_group *pci_epf_make(struct config_group *group,
{
struct pci_epf_group *epf_group;
struct pci_epf *epf;
+ char *epf_name;
+ int index, err;
epf_group = kzalloc(sizeof(*epf_group), GFP_KERNEL);
if (!epf_group)
return ERR_PTR(-ENOMEM);
+ mutex_lock(&functions_mutex);
+ index = idr_alloc(&functions_idr, epf_group, 0, 0, GFP_KERNEL);
+ mutex_unlock(&functions_mutex);
+ if (index < 0) {
+ err = index;
+ goto free_group;
+ }
+
+ epf_group->index = index;
+
config_group_init_type_name(&epf_group->group, name, &pci_epf_type);
- epf = pci_epf_create(group->cg_item.ci_name);
+ epf_name = kasprintf(GFP_KERNEL, "%s.%d",
+ group->cg_item.ci_name, epf_group->index);
+ if (!epf_name) {
+ err = -ENOMEM;
+ goto remove_idr;
+ }
+
+ epf = pci_epf_create(epf_name);
if (IS_ERR(epf)) {
pr_err("failed to create endpoint function device\n");
- return ERR_PTR(-EINVAL);
+ err = -EINVAL;
+ goto free_name;
}
epf_group->epf = epf;
+ kfree(epf_name);
+
return &epf_group->group;
+
+free_name:
+ kfree(epf_name);
+
+remove_idr:
+ mutex_lock(&functions_mutex);
+ idr_remove(&functions_idr, epf_group->index);
+ mutex_unlock(&functions_mutex);
+
+free_group:
+ kfree(epf_group);
+
+ return ERR_PTR(err);
}
static void pci_epf_drop(struct config_group *group, struct config_item *item)
--
2.11.0
next prev parent reply other threads:[~2018-01-28 20:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-28 20:40 [PATCH v5 00/11] PCI: Add support to the Cadence PCIe controller Cyrille Pitchen
[not found] ` <cover.1517170521.git.cyrille.pitchen-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2018-01-28 20:40 ` [PATCH v5 01/11] PCI: Regroup all PCI related entries into drivers/pci/Makefile Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 02/11] PCI: OF: Add generic function to parse and allocate PCI resources Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 03/11] PCI: generic: fix missing call of pci_free_resource_list() Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 04/11] PCI: Add generic function to probe PCI host controllers Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 05/11] PCI: Add vendor ID for Cadence Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 06/11] dt-bindings: PCI: cadence: Add DT bindings for Cadence PCIe host controller Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 07/11] PCI: cadence: Add host driver for Cadence PCIe controller Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 08/11] PCI: endpoint: Add the function number as argument to EPC ops Cyrille Pitchen
2018-01-28 20:40 ` Cyrille Pitchen [this message]
2018-01-28 20:40 ` [PATCH v5 10/11] dt-bindings: PCI: cadence: Add DT bindings for Cadence PCIe endpoint controller Cyrille Pitchen
2018-01-28 20:40 ` [PATCH v5 11/11] PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller Cyrille Pitchen
2018-01-28 21:47 ` [PATCH v5 00/11] PCI: Add support to the " Bjorn Helgaas
[not found] ` <20180128214741.GA232763-1RhO1Y9PlrlHTL0Zs8A6p5iNqAH0jzoTYJqu5kTmcBRl57MIdRCFDg@public.gmane.org>
2018-01-30 11:41 ` Lorenzo Pieralisi
[not found] ` <20180130114155.GA12009-4tUPXFaYRHv6sAKXYmQ0tx/iLCjYCKR+VpNB7YpNyf8@public.gmane.org>
2018-01-30 21:12 ` Cyrille Pitchen
[not found] ` <8cec81b2-85c4-d7bf-4171-9e94a745eab0-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2018-02-06 9:39 ` Lorenzo Pieralisi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0c9ae7445f9900f96c62f78e91810dd906bab14f.1517170521.git.cyrille.pitchen@free-electrons.com \
--to=cyrille.pitchen@free-electrons.com \
--cc=adouglas@cadence.com \
--cc=bhelgaas@google.com \
--cc=devicetree@vger.kernel.org \
--cc=dgary@cadence.com \
--cc=eandrews@cadence.com \
--cc=kgopi@cadence.com \
--cc=kishon@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=nsekhar@ti.com \
--cc=robh@kernel.org \
--cc=stelford@cadence.com \
--cc=sureshp@cadence.com \
--cc=thomas.petazzoni@free-electrons.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).