PCI: endpoint: Add new pci_epc_ops to get EPC features
authorKishon Vijay Abraham I <kishon@ti.com>
Mon, 14 Jan 2019 11:14:59 +0000 (16:44 +0530)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Thu, 14 Feb 2019 16:08:10 +0000 (16:08 +0000)
Add a new pci_epc_ops ->get_features() to get the features
supported by the EPC. Since EPC can provide different features to
different functions, the ->get_features() ops takes _func_no_ as
an argument.

Tested-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
drivers/pci/endpoint/pci-epc-core.c
include/linux/pci-epc.h

index 094dcc3..5a09947 100644 (file)
@@ -84,6 +84,36 @@ err:
 EXPORT_SYMBOL_GPL(pci_epc_get);
 
 /**
+ * pci_epc_get_features() - get the features supported by EPC
+ * @epc: the features supported by *this* EPC device will be returned
+ * @func_no: the features supported by the EPC device specific to the
+ *          endpoint function with func_no will be returned
+ *
+ * Invoke to get the features provided by the EPC which may be
+ * specific to an endpoint function. Returns pci_epc_features on success
+ * and NULL for any failures.
+ */
+const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
+                                                   u8 func_no)
+{
+       const struct pci_epc_features *epc_features;
+       unsigned long flags;
+
+       if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
+               return NULL;
+
+       if (!epc->ops->get_features)
+               return NULL;
+
+       spin_lock_irqsave(&epc->lock, flags);
+       epc_features = epc->ops->get_features(epc, func_no);
+       spin_unlock_irqrestore(&epc->lock, flags);
+
+       return epc_features;
+}
+EXPORT_SYMBOL_GPL(pci_epc_get_features);
+
+/**
  * pci_epc_stop() - stop the PCI link
  * @epc: the link of the EPC device that has to be stopped
  *
index 37dab81..79fbcf9 100644 (file)
@@ -59,6 +59,8 @@ struct pci_epc_ops {
                             enum pci_epc_irq_type type, u16 interrupt_num);
        int     (*start)(struct pci_epc *epc);
        void    (*stop)(struct pci_epc *epc);
+       const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
+                                                      u8 func_no);
        struct module *owner;
 };
 
@@ -100,6 +102,24 @@ struct pci_epc {
        unsigned int                    features;
 };
 
+/**
+ * struct pci_epc_features - features supported by a EPC device per function
+ * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
+ * @msi_capable: indicate if the endpoint function has MSI capability
+ * @msix_capable: indicate if the endpoint function has MSI-X capability
+ * @reserved_bar: bitmap to indicate reserved BAR unavailable to function driver
+ * @bar_fixed_64bit: bitmap to indicate fixed 64bit BARs
+ * @bar_fixed_size: Array specifying the size supported by each BAR
+ */
+struct pci_epc_features {
+       unsigned int    linkup_notifier : 1;
+       unsigned int    msi_capable : 1;
+       unsigned int    msix_capable : 1;
+       u8      reserved_bar;
+       u8      bar_fixed_64bit;
+       u64     bar_fixed_size[BAR_5 + 1];
+};
+
 #define EPC_FEATURE_NO_LINKUP_NOTIFIER         BIT(0)
 #define EPC_FEATURE_BAR_MASK                   (BIT(1) | BIT(2) | BIT(3))
 #define EPC_FEATURE_MSIX_AVAILABLE             BIT(4)
@@ -158,6 +178,8 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no,
                      enum pci_epc_irq_type type, u16 interrupt_num);
 int pci_epc_start(struct pci_epc *epc);
 void pci_epc_stop(struct pci_epc *epc);
+const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
+                                                   u8 func_no);
 struct pci_epc *pci_epc_get(const char *epc_name);
 void pci_epc_put(struct pci_epc *epc);