Add SR-IOV support in PCIe Endpoint Core
Subsystems (12)
v2 cover Add SR-IOV support in PCIe Endpoint Core
Patch series
*) Adds support to add virtual functions to enable endpoint controller
which supports SR-IOV capability
*) Add support in Cadence endpoint driver to configure virtual functions *) Enable pci_endpoint_test driver to create pci_device for virtual
functions
Here both physical functions and virtual functions use the same pci_endpoint_test driver and existing pcitest utility can be used to test virtual functions as well.
Changes from v1:
*) Re-based and Re-worked to latest kernel 5.10.0-rc2+ (now has generic
binding for EP)
Patch series is created on top of NTB series [2]
v1 of the patch series can be found @ [1]
[1] -> http://lore.kernel.org/r/[email protected]
[2] -> http://lore.kernel.org/r/[email protected]
Kishon Vijay Abraham I (6):
dt-bindings: PCI: pci-ep: Add binding to specify virtual function
PCI: endpoint: Add support to add virtual function in endpoint core
PCI: endpoint: Add support to link a physical function to a virtual
function
PCI: endpoint: Add virtual function number in pci_epc ops
PCI: cadence: Add support to configure virtual functions
misc: pci_endpoint_test: Populate sriov_configure ops to configure
SR-IOV device
.../devicetree/bindings/pci/pci-ep.yaml | 9 + drivers/misc/pci_endpoint_test.c | 1 + .../pci/controller/cadence/pcie-cadence-ep.c | 251 +++++++++++++++--- drivers/pci/controller/cadence/pcie-cadence.h | 7 + .../pci/controller/dwc/pcie-designware-ep.c | 36 +-- drivers/pci/controller/pcie-rcar-ep.c | 19 +- drivers/pci/controller/pcie-rockchip-ep.c | 18 +- drivers/pci/endpoint/functions/pci-epf-ntb.c | 83 +++--- drivers/pci/endpoint/functions/pci-epf-test.c | 66 +++-- drivers/pci/endpoint/pci-ep-cfs.c | 24 ++ drivers/pci/endpoint/pci-epc-core.c | 166 +++++++++--- drivers/pci/endpoint/pci-epf-core.c | 144 +++++++++- include/linux/pci-epc.h | 57 ++-- include/linux/pci-epf.h | 16 +- 14 files changed, 693 insertions(+), 204 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 1/6 dt-bindings: PCI: pci-ep: Add binding to specify virtual function
Add binding to specify virtual function (associated with each physical function) in endpoint mode.
--- Documentation/devicetree/bindings/pci/pci-ep.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/pci/pci-ep.yaml +9 -0
@@ -23,6 +23,15 @@ properties: default: 1 maximum: 255 + max-virtual-functions: + description: Maximum number of virtual functions that can be configured + allOf: + - $ref: /schemas/types.yaml#/definitions/uint8-array + minItems: 0 + maxItems: 255 + items: + maximum: 255 + max-link-speed: $ref: /schemas/types.yaml#/definitions/uint32 enum: [ 1, 2, 3, 4 ]
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH v2 1/6] dt-bindings: PCI: pci-ep: Add binding to specify virtual function
Quoted 13 lines · Kishon Vijay Abraham I
Add binding to specify virtual function (associated with each physical function) in endpoint mode.
Signed-off-by Kishon Vijay Abraham I <[email protected]>--- Documentation/devicetree/bindings/pci/pci-ep.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)Documentation/devicetree/bindings/pci/pci-ep.yaml +0
-0
Documentation/devicetree/bindings/pci/pci-ep.yaml properties: · line 27
Quoted 5 lines
Documentation/devicetree/bindings/pci/pci-ep.yaml +2
-0@@ -23,6 +23,15 @@ properties: default: 1 maximum: 255 + max-virtual-functions: + description: Maximum number of virtual functions that can be configured
Need to say what each element of the array corresponds to.
Documentation/devicetree/bindings/pci/pci-ep.yaml properties: · line 28
Quoted 1 line
Documentation/devicetree/bindings/pci/pci-ep.yaml +1
-0+ allOf:
Can drop 'allOf' here.
Documentation/devicetree/bindings/pci/pci-ep.yaml properties: · line 30
Quoted 2 lines
Documentation/devicetree/bindings/pci/pci-ep.yaml +2
-0+ - $ref: /schemas/types.yaml#/definitions/uint8-array + minItems: 0
minItems should never be 0. That's no property present.
Quoted 10 lines
Documentation/devicetree/bindings/pci/pci-ep.yaml +4
-0+ maxItems: 255 + items: + maximum: 255 + max-link-speed: $ref: /schemas/types.yaml#/definitions/uint32 enum: [ 1, 2, 3, 4 ]Signature · 1 line
2.17.1
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 2/6 PCI: endpoint: Add support to add virtual function in endpoint core
In reply to Kishon Vijay Abraham IAdd support to add virtual function in endpoint core. The virtual function can only be associated with a physical function instead of a endpoint controller. Provide APIs to associate a virtual function with a physical function here.
--- drivers/pci/endpoint/pci-epc-core.c | 2 +- drivers/pci/endpoint/pci-epf-core.c | 96 ++++++++++++++++++++++++++++- include/linux/pci-epf.h | 16 ++++- 3 files changed, 111 insertions(+), 3 deletions(-)
drivers/pci/endpoint/pci-epc-core.c +1 -1
@@ -548,7 +548,7 @@ int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf,u32 func_no;int ret =0 ; -if (IS_ERR_OR_NULL (epc)) +if (IS_ERR_OR_NULL (epc) || epf->is_vf)return -EINVAL ;if (type ==PRIMARY_INTERFACE && epf->epc)
drivers/pci/endpoint/pci-epf-core.c +95 -1
133 lines not on this page · raw message
include/linux/pci-epf.h +15 -1
@@ -118,8 +118,10 @@ struct pci_epf_bar {* @header: represents standard configuration header * @bar: represents the BAR of EPF device * @msi_interrupts: number of MSI interrupts required by this function -* @func_no: unique function number within this endpoint device +* @func_no: unique (physical) function number within this endpoint device +* @vfunc_no: unique virtual function number within a physical function * @epc: the EPC device to which this EPF device is bound +* @epf_pf: the physical EPF device to which this virtual EPF device is bound * @driver: the EPF driver to which this EPF device is bound * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc * @nb: notifier block to notify EPF of any EPC events (like linkup)
@@ -130,6 +132,10 @@ struct pci_epf_bar {* @sec_epc_bar: represents the BAR of EPF device associated with secondary EPC * @sec_epc_func_no: unique (physical) function number within the secondary EPC * @group: configfs group associated with the EPF device +* @is_bound: indicates if bind notification to function driver has been invoked +* @is_vf: true - virtual function, false - physical function +* @vfunction_num_map: bitmap to manage virtual function number +* @pci_vepf: list of virtual endpoint functions associated with this function */ struct pci_epf {struct device dev;
@@ -139,8 +145,10 @@ struct pci_epf {u8 msi_interrupts;u16 msix_interrupts;u8 func_no; +u8 vfunc_no;struct pci_epc *epc; +struct pci_epf *epf_pf;struct pci_epf_driver *driver;struct list_head list;struct notifier_block nb;
@@ -153,6 +161,10 @@ struct pci_epf {struct pci_epf_bar sec_epc_bar[6 ];u8 sec_epc_func_no;struct config_group *group; +unsigned int is_bound; +unsigned int is_vf; +unsigned long vfunction_num_map; +struct list_head pci_vepf; };/**
@@ -196,4 +208,6 @@ int pci_epf_bind(struct pci_epf *epf);void pci_epf_unbind (struct pci_epf *epf);struct config_group *pci_epf_type_add_cfs (struct pci_epf *epf,struct config_group *group); +int pci_epf_add_vepf (struct pci_epf *epf_pf,struct pci_epf *epf_vf); +void pci_epf_remove_vepf (struct pci_epf *epf_pf,struct pci_epf *epf_vf);#endif /* __LINUX_PCI_EPF_H */
Signature · 1 line
2.17.1
PATCH v2 3/6 PCI: endpoint: Add support to link a physical function to a virtual function
In reply to Kishon Vijay Abraham IWhile the physical function has to be linked to endpoint controller, the virtual function has to be linked to a physical function. Add support to link a physical function to a virtual function in pci-ep-cfs.
--- drivers/pci/endpoint/pci-ep-cfs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/pci/endpoint/pci-ep-cfs.c +24 -0
@@ -475,6 +475,28 @@ static struct configfs_attribute *pci_epf_attrs[] = { NULL, }; +static int pci_epf_vepf_link (struct config_item *epf_pf_item, +struct config_item *epf_vf_item) +{ +struct pci_epf_group *epf_vf_group =to_pci_epf_group (epf_vf_item); +struct pci_epf_group *epf_pf_group =to_pci_epf_group (epf_pf_item); +struct pci_epf *epf_pf = epf_pf_group->epf; +struct pci_epf *epf_vf = epf_vf_group->epf; + +return pci_epf_add_vepf (epf_pf, epf_vf); +} + +static void pci_epf_vepf_unlink (struct config_item *epf_pf_item, +struct config_item *epf_vf_item) +{ +struct pci_epf_group *epf_vf_group =to_pci_epf_group (epf_vf_item); +struct pci_epf_group *epf_pf_group =to_pci_epf_group (epf_pf_item); +struct pci_epf *epf_pf = epf_pf_group->epf; +struct pci_epf *epf_vf = epf_vf_group->epf; + +pci_epf_remove_vepf (epf_pf, epf_vf); +} +static void pci_epf_release (struct config_item *item) {struct pci_epf_group *epf_group =to_pci_epf_group (item);
@@ -487,6 +509,8 @@ static void pci_epf_release(struct config_item *item) }static struct configfs_item_operations pci_epf_ops = { + .allow_link = pci_epf_vepf_link, + .drop_link = pci_epf_vepf_unlink, .release = pci_epf_release, };
Signature · 1 line
2.17.1
PATCH v2 4/6 PCI: endpoint: Add virtual function number in pci_epc ops
In reply to Kishon Vijay Abraham IAdd virtual function number in pci_epc ops. EPC controller driver can perform virtual function specific initialization based on the virtual function number.
--- .../pci/controller/cadence/pcie-cadence-ep.c | 44 ++--- .../pci/controller/dwc/pcie-designware-ep.c | 36 ++-- drivers/pci/controller/pcie-rcar-ep.c | 19 +- drivers/pci/controller/pcie-rockchip-ep.c | 18 +- drivers/pci/endpoint/functions/pci-epf-ntb.c | 83 +++++---- drivers/pci/endpoint/functions/pci-epf-test.c | 66 +++---- drivers/pci/endpoint/pci-epc-core.c | 164 ++++++++++++++---- drivers/pci/endpoint/pci-epf-core.c | 48 ++++- include/linux/pci-epc.h | 57 +++--- 9 files changed, 351 insertions(+), 184 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-ep.c +23 -21
@@ -16,7 +16,7 @@#define CDNS_PCIE_EP_IRQ_PCI_ADDR_NONE 0x1#define CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY 0x3 -static int cdns_pcie_ep_write_header (struct pci_epc *epc,u8 fn, +static int cdns_pcie_ep_write_header (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_header *hdr) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);
@@ -47,7 +47,7 @@ static int cdns_pcie_ep_write_header(struct pci_epc *epc, u8 fn,return 0 ; } -static int cdns_pcie_ep_set_bar (struct pci_epc *epc,u8 fn, +static int cdns_pcie_ep_set_bar (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_bar *epf_bar) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);
@@ -117,7 +117,7 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn,return 0 ; } -static void cdns_pcie_ep_clear_bar (struct pci_epc *epc,u8 fn, +static void cdns_pcie_ep_clear_bar (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_bar *epf_bar) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);
@@ -147,8 +147,8 @@ static void cdns_pcie_ep_clear_bar(struct pci_epc *epc, u8 fn, epf->epf_bar[bar] =NULL ; } -static int cdns_pcie_ep_map_addr (struct pci_epc *epc,u8 fn,phys_addr_t addr, -u64 pci_addr,size_t size) +static int cdns_pcie_ep_map_addr (struct pci_epc *epc,u8 fn,u8 vfn, +phys_addr_t addr,u64 pci_addr,size_t size) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;
@@ -169,7 +169,7 @@ static int cdns_pcie_ep_map_addr(struct pci_epc *epc, u8 fn, phys_addr_t addr,return 0 ; } -static void cdns_pcie_ep_unmap_addr (struct pci_epc *epc,u8 fn, +static void cdns_pcie_ep_unmap_addr (struct pci_epc *epc,u8 fn,u8 vfn,phys_addr_t addr) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);
@@ -189,7 +189,7 @@ static void cdns_pcie_ep_unmap_addr(struct pci_epc *epc, u8 fn,clear_bit (r, &ep->ob_region_map); } -static int cdns_pcie_ep_set_msi (struct pci_epc *epc,u8 fn,u8 mmc) +static int cdns_pcie_ep_set_msi (struct pci_epc *epc,u8 fn,u8 vfn,u8 mmc) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;
@@ -209,7 +209,7 @@ static int cdns_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 mmc)return 0 ; } -static int cdns_pcie_ep_get_msi (struct pci_epc *epc,u8 fn) +static int cdns_pcie_ep_get_msi (struct pci_epc *epc,u8 fn,u8 vfn) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;
@@ -230,7 +230,7 @@ static int cdns_pcie_ep_get_msi(struct pci_epc *epc, u8 fn)return mme; } -static int cdns_pcie_ep_get_msix (struct pci_epc *epc,u8 func_no) +static int cdns_pcie_ep_get_msix (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;
@@ -247,8 +247,9 @@ static int cdns_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)return val; } -static int cdns_pcie_ep_set_msix (struct pci_epc *epc,u8 fn,u16 interrupts, -enum pci_barno bir,u32 offset) +static int cdns_pcie_ep_set_msix (struct pci_epc *epc,u8 fn,u8 vfn, +u16 interrupts,enum pci_barno bir, +u32 offset) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;
@@ -317,7 +318,8 @@ static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep *ep, u8 fn,writel (0 , ep->irq_cpu_addr + offset); } -static int cdns_pcie_ep_send_legacy_irq (struct cdns_pcie_ep *ep,u8 fn,u8 intx) +static int cdns_pcie_ep_send_legacy_irq (struct cdns_pcie_ep *ep,u8 fn,u8 vfn, +u8 intx) {u16 cmd;
@@ -334,7 +336,7 @@ static int cdns_pcie_ep_send_legacy_irq(struct cdns_pcie_ep *ep, u8 fn, u8 intx)return 0 ; } -static int cdns_pcie_ep_send_msi_irq (struct cdns_pcie_ep *ep,u8 fn, +static int cdns_pcie_ep_send_msi_irq (struct cdns_pcie_ep *ep,u8 fn,u8 vfn,u8 interrupt_num) {struct cdns_pcie *pcie = &ep->pcie;
@@ -382,7 +384,7 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep *ep, u8 fn,return 0 ; } -static int cdns_pcie_ep_map_msi_irq (struct pci_epc *epc,u8 fn, +static int cdns_pcie_ep_map_msi_irq (struct pci_epc *epc,u8 fn,u8 vfn,phys_addr_t addr,u8 interrupt_num,u32 entry_size,u32 *msi_data,u32 *msi_addr_offset)
@@ -419,7 +421,7 @@ static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn, pci_addr &=GENMASK_ULL (63 ,2 );for (i =0 ; i < interrupt_num; i++) { - ret =cdns_pcie_ep_map_addr (epc, fn, addr, + ret =cdns_pcie_ep_map_addr (epc, fn, vfn, addr, pci_addr & ~pci_addr_mask, entry_size);if (ret)
@@ -433,7 +435,7 @@ static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn,return 0 ; } -static int cdns_pcie_ep_send_msix_irq (struct cdns_pcie_ep *ep,u8 fn, +static int cdns_pcie_ep_send_msix_irq (struct cdns_pcie_ep *ep,u8 fn,u8 vfn,u16 interrupt_num) {u32 cap =CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET ;
@@ -478,7 +480,7 @@ static int cdns_pcie_ep_send_msix_irq(struct cdns_pcie_ep *ep, u8 fn,return 0 ; } -static int cdns_pcie_ep_raise_irq (struct pci_epc *epc,u8 fn, +static int cdns_pcie_ep_raise_irq (struct pci_epc *epc,u8 fn,u8 vfn,enum pci_epc_irq_type type,u16 interrupt_num) {
@@ -486,13 +488,13 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn,switch (type) {case PCI_EPC_IRQ_LEGACY : -return cdns_pcie_ep_send_legacy_irq (ep, fn,0 ); +return cdns_pcie_ep_send_legacy_irq (ep, fn, vfn,0 );case PCI_EPC_IRQ_MSI : -return cdns_pcie_ep_send_msi_irq (ep, fn, interrupt_num); +return cdns_pcie_ep_send_msi_irq (ep, fn, vfn, interrupt_num);case PCI_EPC_IRQ_MSIX : -return cdns_pcie_ep_send_msix_irq (ep, fn, interrupt_num); +return cdns_pcie_ep_send_msix_irq (ep, fn, vfn, interrupt_num);default :break ;
@@ -531,7 +533,7 @@ static const struct pci_epc_features cdns_pcie_epc_features = { };static const struct pci_epc_features * -cdns_pcie_ep_get_features (struct pci_epc *epc,u8 func_no) +cdns_pcie_ep_get_features (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {return &cdns_pcie_epc_features; }
drivers/pci/controller/dwc/pcie-designware-ep.c +18 -18
@@ -124,7 +124,7 @@ static u8 dw_pcie_ep_find_capability(struct dw_pcie_ep *ep, u8 func_no, u8 cap)return __dw_pcie_ep_find_next_cap (ep, func_no, next_cap_ptr, cap); } -static int dw_pcie_ep_write_header (struct pci_epc *epc,u8 func_no, +static int dw_pcie_ep_write_header (struct pci_epc *epc,u8 func_no,u8 vfunc_no,struct pci_epf_header *hdr) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);
@@ -201,7 +201,7 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, u8 func_no,return 0 ; } -static void dw_pcie_ep_clear_bar (struct pci_epc *epc,u8 func_no, +static void dw_pcie_ep_clear_bar (struct pci_epc *epc,u8 func_no,u8 vfunc_no,struct pci_epf_bar *epf_bar) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);
@@ -216,7 +216,7 @@ static void dw_pcie_ep_clear_bar(struct pci_epc *epc, u8 func_no, ep->epf_bar[bar] =NULL ; } -static int dw_pcie_ep_set_bar (struct pci_epc *epc,u8 func_no, +static int dw_pcie_ep_set_bar (struct pci_epc *epc,u8 func_no,u8 vfunc_no,struct pci_epf_bar *epf_bar) {int ret;
@@ -274,7 +274,7 @@ static int dw_pcie_find_index(struct dw_pcie_ep *ep, phys_addr_t addr,return -EINVAL ; } -static void dw_pcie_ep_unmap_addr (struct pci_epc *epc,u8 func_no, +static void dw_pcie_ep_unmap_addr (struct pci_epc *epc,u8 func_no,u8 vfunc_no,phys_addr_t addr) {int ret;
@@ -290,9 +290,8 @@ static void dw_pcie_ep_unmap_addr(struct pci_epc *epc, u8 func_no,clear_bit (atu_index, ep->ob_window_map); } -static int dw_pcie_ep_map_addr (struct pci_epc *epc,u8 func_no, -phys_addr_t addr, -u64 pci_addr,size_t size) +static int dw_pcie_ep_map_addr (struct pci_epc *epc,u8 func_no,u8 vfunc_no, +phys_addr_t addr,u64 pci_addr,size_t size) {int ret;struct dw_pcie_ep *ep =epc_get_drvdata (epc);
@@ -307,7 +306,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no,return 0 ; } -static int dw_pcie_ep_get_msi (struct pci_epc *epc,u8 func_no) +static int dw_pcie_ep_get_msi (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);struct dw_pcie *pci =to_dw_pcie_from_ep (ep);
@@ -331,7 +330,8 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no)return val; } -static int dw_pcie_ep_set_msi (struct pci_epc *epc,u8 func_no,u8 interrupts) +static int dw_pcie_ep_set_msi (struct pci_epc *epc,u8 func_no,u8 vfunc_no, +u8 interrupts) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);struct dw_pcie *pci =to_dw_pcie_from_ep (ep);
@@ -356,7 +356,7 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts)return 0 ; } -static int dw_pcie_ep_get_msix (struct pci_epc *epc,u8 func_no) +static int dw_pcie_ep_get_msix (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);struct dw_pcie *pci =to_dw_pcie_from_ep (ep);
@@ -380,8 +380,8 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)return val; } -static int dw_pcie_ep_set_msix (struct pci_epc *epc,u8 func_no,u16 interrupts, -enum pci_barno bir,u32 offset) +static int dw_pcie_ep_set_msix (struct pci_epc *epc,u8 func_no,u8 vfunc_no, +u16 interrupts,enum pci_barno bir,u32 offset) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);struct dw_pcie *pci =to_dw_pcie_from_ep (ep);
@@ -416,7 +416,7 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts,return 0 ; } -static int dw_pcie_ep_raise_irq (struct pci_epc *epc,u8 func_no, +static int dw_pcie_ep_raise_irq (struct pci_epc *epc,u8 func_no,u8 vfunc_no,enum pci_epc_irq_type type,u16 interrupt_num) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);
@@ -450,7 +450,7 @@ static int dw_pcie_ep_start(struct pci_epc *epc) }static const struct pci_epc_features * -dw_pcie_ep_get_features (struct pci_epc *epc,u8 func_no) +dw_pcie_ep_get_features (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {struct dw_pcie_ep *ep =epc_get_drvdata (epc);
@@ -525,14 +525,14 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no, aligned_offset = msg_addr_lower & (epc->mem->window.page_size -1 ); msg_addr = ((u64 )msg_addr_upper) <<32 | (msg_addr_lower & ~aligned_offset); - ret =dw_pcie_ep_map_addr (epc, func_no, ep->msi_mem_phys, msg_addr, + ret =dw_pcie_ep_map_addr (epc, func_no,0 , ep->msi_mem_phys, msg_addr, epc->mem->window.page_size);if (ret)return ret;writel (msg_data | (interrupt_num -1 ), ep->msi_mem + aligned_offset); -dw_pcie_ep_unmap_addr (epc, func_no, ep->msi_mem_phys); +dw_pcie_ep_unmap_addr (epc, func_no,0 , ep->msi_mem_phys);return 0 ; }
@@ -593,14 +593,14 @@ int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no, } aligned_offset = msg_addr & (epc->mem->window.page_size -1 ); - ret =dw_pcie_ep_map_addr (epc, func_no, ep->msi_mem_phys, msg_addr, + ret =dw_pcie_ep_map_addr (epc, func_no,0 , ep->msi_mem_phys, msg_addr, epc->mem->window.page_size);if (ret)return ret;writel (msg_data, ep->msi_mem + aligned_offset); -dw_pcie_ep_unmap_addr (epc, func_no, ep->msi_mem_phys); +dw_pcie_ep_unmap_addr (epc, func_no,0 , ep->msi_mem_phys);return 0 ; }
drivers/pci/controller/pcie-rcar-ep.c +10 -9
@@ -159,7 +159,7 @@ static int rcar_pcie_ep_get_pdata(struct rcar_pcie_endpoint *ep,return 0 ; } -static int rcar_pcie_ep_write_header (struct pci_epc *epc,u8 fn, +static int rcar_pcie_ep_write_header (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_header *hdr) {struct rcar_pcie_endpoint *ep =epc_get_drvdata (epc);
@@ -195,7 +195,7 @@ static int rcar_pcie_ep_write_header(struct pci_epc *epc, u8 fn,return 0 ; } -static int rcar_pcie_ep_set_bar (struct pci_epc *epc,u8 func_no, +static int rcar_pcie_ep_set_bar (struct pci_epc *epc,u8 func_no,u8 vfunc_no,struct pci_epf_bar *epf_bar) {int flags = epf_bar->flags |LAR_ENABLE |LAM_64BIT ;
@@ -246,7 +246,7 @@ static int rcar_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no,return 0 ; } -static void rcar_pcie_ep_clear_bar (struct pci_epc *epc,u8 fn, +static void rcar_pcie_ep_clear_bar (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_bar *epf_bar) {struct rcar_pcie_endpoint *ep =epc_get_drvdata (epc);
@@ -259,7 +259,8 @@ static void rcar_pcie_ep_clear_bar(struct pci_epc *epc, u8 fn,clear_bit (atu_index +1 , ep->ib_window_map); } -static int rcar_pcie_ep_set_msi (struct pci_epc *epc,u8 fn,u8 interrupts) +static int rcar_pcie_ep_set_msi (struct pci_epc *epc,u8 fn,u8 vfn, +u8 interrupts) {struct rcar_pcie_endpoint *ep =epc_get_drvdata (epc);struct rcar_pcie *pcie = &ep->pcie;
@@ -272,7 +273,7 @@ static int rcar_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 interrupts)return 0 ; } -static int rcar_pcie_ep_get_msi (struct pci_epc *epc,u8 fn) +static int rcar_pcie_ep_get_msi (struct pci_epc *epc,u8 fn,u8 vfn) {struct rcar_pcie_endpoint *ep =epc_get_drvdata (epc);struct rcar_pcie *pcie = &ep->pcie;
@@ -285,7 +286,7 @@ static int rcar_pcie_ep_get_msi(struct pci_epc *epc, u8 fn)return ((flags &MSICAP0_MMESE_MASK ) >>MSICAP0_MMESE_OFFSET ); } -static int rcar_pcie_ep_map_addr (struct pci_epc *epc,u8 fn, +static int rcar_pcie_ep_map_addr (struct pci_epc *epc,u8 fn,u8 vfn,phys_addr_t addr,u64 pci_addr,size_t size) {struct rcar_pcie_endpoint *ep =epc_get_drvdata (epc);
@@ -322,7 +323,7 @@ static int rcar_pcie_ep_map_addr(struct pci_epc *epc, u8 fn,return 0 ; } -static void rcar_pcie_ep_unmap_addr (struct pci_epc *epc,u8 fn, +static void rcar_pcie_ep_unmap_addr (struct pci_epc *epc,u8 fn,u8 vfn,phys_addr_t addr) {struct rcar_pcie_endpoint *ep =epc_get_drvdata (epc);
@@ -403,7 +404,7 @@ static int rcar_pcie_ep_assert_msi(struct rcar_pcie *pcie,return 0 ; } -static int rcar_pcie_ep_raise_irq (struct pci_epc *epc,u8 fn, +static int rcar_pcie_ep_raise_irq (struct pci_epc *epc,u8 fn,u8 vfn,enum pci_epc_irq_type type,u16 interrupt_num) {
@@ -451,7 +452,7 @@ static const struct pci_epc_features rcar_pcie_epc_features = { };static const struct pci_epc_features * -rcar_pcie_ep_get_features (struct pci_epc *epc,u8 func_no) +rcar_pcie_ep_get_features (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {return &rcar_pcie_epc_features; }
drivers/pci/controller/pcie-rockchip-ep.c +9 -9
@@ -122,7 +122,7 @@ static void rockchip_pcie_prog_ep_ob_atu(struct rockchip_pcie *rockchip, u8 fn, ROCKCHIP_PCIE_AT_OB_REGION_CPU_ADDR1(r)); } -static int rockchip_pcie_ep_write_header (struct pci_epc *epc,u8 fn, +static int rockchip_pcie_ep_write_header (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_header *hdr) {struct rockchip_pcie_ep *ep =epc_get_drvdata (epc);
@@ -159,7 +159,7 @@ static int rockchip_pcie_ep_write_header(struct pci_epc *epc, u8 fn,return 0 ; } -static int rockchip_pcie_ep_set_bar (struct pci_epc *epc,u8 fn, +static int rockchip_pcie_ep_set_bar (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_bar *epf_bar) {struct rockchip_pcie_ep *ep =epc_get_drvdata (epc);
@@ -227,7 +227,7 @@ static int rockchip_pcie_ep_set_bar(struct pci_epc *epc, u8 fn,return 0 ; } -static void rockchip_pcie_ep_clear_bar (struct pci_epc *epc,u8 fn, +static void rockchip_pcie_ep_clear_bar (struct pci_epc *epc,u8 fn,u8 vfn,struct pci_epf_bar *epf_bar) {struct rockchip_pcie_ep *ep =epc_get_drvdata (epc);
@@ -256,7 +256,7 @@ static void rockchip_pcie_ep_clear_bar(struct pci_epc *epc, u8 fn, ROCKCHIP_PCIE_AT_IB_EP_FUNC_BAR_ADDR1(fn, bar)); } -static int rockchip_pcie_ep_map_addr (struct pci_epc *epc,u8 fn, +static int rockchip_pcie_ep_map_addr (struct pci_epc *epc,u8 fn,u8 vfn,phys_addr_t addr,u64 pci_addr,size_t size) {
@@ -284,7 +284,7 @@ static int rockchip_pcie_ep_map_addr(struct pci_epc *epc, u8 fn,return 0 ; } -static void rockchip_pcie_ep_unmap_addr (struct pci_epc *epc,u8 fn, +static void rockchip_pcie_ep_unmap_addr (struct pci_epc *epc,u8 fn,u8 vfn,phys_addr_t addr) {struct rockchip_pcie_ep *ep =epc_get_drvdata (epc);
@@ -308,7 +308,7 @@ static void rockchip_pcie_ep_unmap_addr(struct pci_epc *epc, u8 fn,clear_bit (r, &ep->ob_region_map); } -static int rockchip_pcie_ep_set_msi (struct pci_epc *epc,u8 fn, +static int rockchip_pcie_ep_set_msi (struct pci_epc *epc,u8 fn,u8 vfn,u8 multi_msg_cap) {struct rockchip_pcie_ep *ep =epc_get_drvdata (epc);
@@ -329,7 +329,7 @@ static int rockchip_pcie_ep_set_msi(struct pci_epc *epc, u8 fn,return 0 ; } -static int rockchip_pcie_ep_get_msi (struct pci_epc *epc,u8 fn) +static int rockchip_pcie_ep_get_msi (struct pci_epc *epc,u8 fn,u8 vfn) {struct rockchip_pcie_ep *ep =epc_get_drvdata (epc);struct rockchip_pcie *rockchip = &ep->rockchip;
@@ -471,7 +471,7 @@ static int rockchip_pcie_ep_send_msi_irq(struct rockchip_pcie_ep *ep, u8 fn,return 0 ; } -static int rockchip_pcie_ep_raise_irq (struct pci_epc *epc,u8 fn, +static int rockchip_pcie_ep_raise_irq (struct pci_epc *epc,u8 fn,u8 vfn,enum pci_epc_irq_type type,u16 interrupt_num) {
@@ -510,7 +510,7 @@ static const struct pci_epc_features rockchip_pcie_epc_features = { };static const struct pci_epc_features * -rockchip_pcie_ep_get_features (struct pci_epc *epc,u8 func_no) +rockchip_pcie_ep_get_features (struct pci_epc *epc,u8 func_no,u8 vfunc_no) {return &rockchip_pcie_epc_features; }
drivers/pci/endpoint/functions/pci-epf-ntb.c +50 -33
356 lines not on this page · raw message
drivers/pci/endpoint/functions/pci-epf-test.c +37 -29
186 lines not on this page · raw message
drivers/pci/endpoint/pci-epc-core.c +126 -38
414 lines not on this page · raw message
drivers/pci/endpoint/pci-epf-core.c +47 -1
65 lines not on this page · raw message
include/linux/pci-epc.h +31 -26
105 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 5/6 PCI: cadence: Add support to configure virtual functions
In reply to Kishon Vijay Abraham INow that support for SR-IOV is added in PCIe endpoint core, add support to configure virtual functions in the Cadence PCIe EP driver.
--- .../pci/controller/cadence/pcie-cadence-ep.c | 207 ++++++++++++++++-- drivers/pci/controller/cadence/pcie-cadence.h | 7 + 2 files changed, 197 insertions(+), 17 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-ep.c +190 -17
@@ -20,7 +20,18 @@ static int cdns_pcie_ep_write_header(struct pci_epc *epc, u8 fn, u8 vfn, struct pci_epf_header *hdr) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc); +u32 cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;struct cdns_pcie *pcie = &ep->pcie; +u32 reg; + +if (vfn >1 ) { +dev_dbg (&epc->dev,"Only Virtual Function #1 has deviceID\n" ); +return 0 ; + }else if (vfn ==1 ) { + reg = cap +PCI_SRIOV_VF_DID ; +cdns_pcie_ep_fn_writew (pcie, fn, reg, hdr->deviceid); +return 0 ; + }cdns_pcie_ep_fn_writew (pcie, fn,PCI_DEVICE_ID , hdr->deviceid);cdns_pcie_ep_fn_writeb (pcie, fn,PCI_REVISION_ID , hdr->revid);
@@ -51,12 +62,14 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn, struct pci_epf_bar *epf_bar) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc); +u32 cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;struct cdns_pcie_epf *epf = &ep->epf[fn];struct cdns_pcie *pcie = &ep->pcie;dma_addr_t bar_phys = epf_bar->phys_addr;enum pci_barno bar = epf_bar->barno;int flags = epf_bar->flags;u32 addr0, addr1, reg, cfg, b, aperture, ctrl; +u32 first_vf_offset, stride;u64 sz;/* BAR size is 2^(aperture + 7) */
@@ -92,19 +105,39 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn, addr0 =lower_32_bits (bar_phys); addr1 =upper_32_bits (bar_phys); + +if (vfn ==1 ) { +if (bar <BAR_4 ) { + reg =CDNS_PCIE_LM_EP_VFUNC_BAR_CFG0 (fn); + b = bar; + }else { + reg =CDNS_PCIE_LM_EP_VFUNC_BAR_CFG1 (fn); + b = bar -BAR_4 ; + } + }else { +if (bar <BAR_4 ) { + reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG0 (fn); + b = bar; + }else { + reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG1 (fn); + b = bar -BAR_4 ; + } + } + +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + epf = &epf->epf[vfn -1 ]; + } +cdns_pcie_writel (pcie,CDNS_PCIE_AT_IB_EP_FUNC_BAR_ADDR0 (fn, bar), addr0);cdns_pcie_writel (pcie,CDNS_PCIE_AT_IB_EP_FUNC_BAR_ADDR1 (fn, bar), addr1); -if (bar <BAR_4 ) { - reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG0 (fn); - b = bar; - }else { - reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG1 (fn); - b = bar -BAR_4 ; - } - cfg =cdns_pcie_readl (pcie, reg); cfg &= ~(CDNS_PCIE_LM_EP_FUNC_BAR_CFG_BAR_APERTURE_MASK (b) |CDNS_PCIE_LM_EP_FUNC_BAR_CFG_BAR_CTRL_MASK (b));
@@ -121,17 +154,38 @@ static void cdns_pcie_ep_clear_bar(struct pci_epc *epc, u8 fn, u8 vfn, struct pci_epf_bar *epf_bar) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc); +u32 cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;struct cdns_pcie_epf *epf = &ep->epf[fn];struct cdns_pcie *pcie = &ep->pcie;enum pci_barno bar = epf_bar->barno; +u32 first_vf_offset, stride;u32 reg, cfg, b, ctrl; -if (bar <BAR_4 ) { - reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG0 (fn); - b = bar; +if (vfn ==1 ) { +if (bar <BAR_4 ) { + reg =CDNS_PCIE_LM_EP_VFUNC_BAR_CFG0 (fn); + b = bar; + }else { + reg =CDNS_PCIE_LM_EP_VFUNC_BAR_CFG1 (fn); + b = bar -BAR_4 ; + } }else { - reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG1 (fn); - b = bar -BAR_4 ; +if (bar <BAR_4 ) { + reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG0 (fn); + b = bar; + }else { + reg =CDNS_PCIE_LM_EP_FUNC_BAR_CFG1 (fn); + b = bar -BAR_4 ; + } + } + +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + epf = &epf->epf[vfn -1 ]; } ctrl =CDNS_PCIE_LM_BAR_CFG_CTRL_DISABLED ;
@@ -152,8 +206,18 @@ static int cdns_pcie_ep_map_addr(struct pci_epc *epc, u8 fn, u8 vfn, {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie; +u32 cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ; +u32 first_vf_offset, stride;u32 r; +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + } + r =find_first_zero_bit (&ep->ob_region_map,sizeof (ep->ob_region_map) *BITS_PER_LONG );if (r >= ep->max_regions -1 ) {
@@ -193,9 +257,19 @@ static int cdns_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn, u8 mmc) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie; +u32 sriov_cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;u32 cap =CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET ; +u32 first_vf_offset, stride;u16 flags; +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + } +/* * Set the Multiple Message Capable bitfield into the Message Control * register.
@@ -213,9 +287,19 @@ static int cdns_pcie_ep_get_msi(struct pci_epc *epc, u8 fn, u8 vfn) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie; +u32 sriov_cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;u32 cap =CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET ; +u32 first_vf_offset, stride;u16 flags, mme; +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + } +/* Validate that the MSI feature is actually enabled. */ flags =cdns_pcie_ep_fn_readw (pcie, fn, cap +PCI_MSI_FLAGS );if (!(flags &PCI_MSI_FLAGS_ENABLE ))
@@ -232,11 +316,21 @@ static int cdns_pcie_ep_get_msi(struct pci_epc *epc, u8 fn, u8 vfn)static int cdns_pcie_ep_get_msix (struct pci_epc *epc,u8 func_no,u8 vfunc_no) { +u32 sriov_cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;u32 cap =CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET ; +u32 first_vf_offset, stride;u32 val, reg; +if (vfunc_no >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, func_no, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, func_no, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + func_no = func_no + first_vf_offset + ((vfunc_no -1 ) * stride); + } + reg = cap +PCI_MSIX_FLAGS ; val =cdns_pcie_ep_fn_readw (pcie, func_no, reg);if (!(val &PCI_MSIX_FLAGS_ENABLE ))
@@ -251,11 +345,21 @@ static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn, u16 interrupts, enum pci_barno bir, u32 offset) { + u32 sriov_cap = CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET;struct cdns_pcie_ep *ep =epc_get_drvdata (epc);struct cdns_pcie *pcie = &ep->pcie;u32 cap =CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET ; +u32 first_vf_offset, stride;u32 val, reg; +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + } + reg = cap +PCI_MSIX_FLAGS ; val =cdns_pcie_ep_fn_readw (pcie, fn, reg); val &= ~PCI_MSIX_FLAGS_QSIZE ;
@@ -275,8 +379,8 @@ static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn,return 0 ; } -static void cdns_pcie_ep_assert_intx (struct cdns_pcie_ep *ep,u8 fn, -u8 intx,bool is_asserted) +static void cdns_pcie_ep_assert_intx (struct cdns_pcie_ep *ep,u8 fn,u8 intx, +bool is_asserted) {struct cdns_pcie *pcie = &ep->pcie;unsigned long flags;
@@ -339,11 +443,21 @@ static int cdns_pcie_ep_send_legacy_irq(struct cdns_pcie_ep *ep, u8 fn, u8 vfn,static int cdns_pcie_ep_send_msi_irq (struct cdns_pcie_ep *ep,u8 fn,u8 vfn,u8 interrupt_num) { +u32 sriov_cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;struct cdns_pcie *pcie = &ep->pcie;u32 cap =CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET ;u16 flags, mme, data, data_mask;u8 msi_count;u64 pci_addr, pci_addr_mask =0xff ; +u32 first_vf_offset, stride; + +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + }/* Check whether the MSI feature has been enabled by the PCI host. */ flags =cdns_pcie_ep_fn_readw (pcie, fn, cap +PCI_MSI_FLAGS );
@@ -389,15 +503,25 @@ static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn, u8 vfn, u32 entry_size, u32 *msi_data, u32 *msi_addr_offset) { + u32 sriov_cap = CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET;struct cdns_pcie_ep *ep =epc_get_drvdata (epc);u32 cap =CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET ;struct cdns_pcie *pcie = &ep->pcie;u64 pci_addr, pci_addr_mask =0xff ;u16 flags, mme, data, data_mask; +u32 first_vf_offset, stride;u8 msi_count;int ret;int i; +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + } +/* Check whether the MSI feature has been enabled by the PCI host. */ flags =cdns_pcie_ep_fn_readw (pcie, fn, cap +PCI_MSI_FLAGS );if (!(flags &PCI_MSI_FLAGS_ENABLE ))
@@ -438,16 +562,29 @@ static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn, u8 vfn,static int cdns_pcie_ep_send_msix_irq (struct cdns_pcie_ep *ep,u8 fn,u8 vfn,u16 interrupt_num) { +u32 sriov_cap =CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET ;u32 cap =CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET ;u32 tbl_offset, msg_data, reg;struct cdns_pcie *pcie = &ep->pcie;struct pci_epf_msix_tbl *msix_tbl; +u32 first_vf_offset, stride;struct cdns_pcie_epf *epf;u64 pci_addr_mask =0xff ;u64 msg_addr;u16 flags;u8 bir; + epf = &ep->epf[fn]; + +if (vfn >0 ) { + first_vf_offset =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_OFFSET ); + stride =cdns_pcie_ep_fn_readw (pcie, fn, sriov_cap + +PCI_SRIOV_VF_STRIDE ); + fn = fn + first_vf_offset + ((vfn -1 ) * stride); + epf = &epf->epf[vfn -1 ]; + } +/* Check whether the MSI-X feature has been enabled by the PCI host. */ flags =cdns_pcie_ep_fn_readw (pcie, fn, cap +PCI_MSIX_FLAGS );if (!(flags &PCI_MSIX_FLAGS_ENABLE ))
@@ -458,7 +595,6 @@ static int cdns_pcie_ep_send_msix_irq(struct cdns_pcie_ep *ep, u8 fn, u8 vfn, bir = tbl_offset &PCI_MSIX_TABLE_BIR ; tbl_offset &=PCI_MSIX_TABLE_OFFSET ; - epf = &ep->epf[fn]; msix_tbl = epf->epf_bar[bir]->addr + tbl_offset; msg_addr = msix_tbl[(interrupt_num -1 )].msg_addr; msg_data = msix_tbl[(interrupt_num -1 )].msg_data;
@@ -485,9 +621,15 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn, u8 vfn, u16 interrupt_num) {struct cdns_pcie_ep *ep =epc_get_drvdata (epc); +struct cdns_pcie *pcie = &ep->pcie; +struct device *dev = pcie->dev;switch (type) {case PCI_EPC_IRQ_LEGACY : +if (vfn >0 ) { +dev_err (dev,"Cannot raise legacy interrupts for VF\n" ); +return -EINVAL ; + }return cdns_pcie_ep_send_legacy_irq (ep, fn, vfn,0 );case PCI_EPC_IRQ_MSI :
@@ -525,6 +667,13 @@ static int cdns_pcie_ep_start(struct pci_epc *epc)return 0 ; } +static const struct pci_epc_features cdns_pcie_epc_vf_features = { + .linkup_notifier = false, + .msi_capable = true, + .msix_capable = true, + .align =65536 , +}; +static const struct pci_epc_features cdns_pcie_epc_features = { .linkup_notifier = false, .msi_capable = true,
@@ -535,7 +684,10 @@ static const struct pci_epc_features cdns_pcie_epc_features = {static const struct pci_epc_features *cdns_pcie_ep_get_features (struct pci_epc *epc,u8 func_no,u8 vfunc_no) { -return &cdns_pcie_epc_features; +if (!vfunc_no) +return &cdns_pcie_epc_features; + +return &cdns_pcie_epc_vf_features; }static const struct pci_epc_ops cdns_pcie_epc_ops = {
@@ -561,9 +713,11 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep)struct platform_device *pdev =to_platform_device (dev);struct device_node *np = dev->of_node;struct cdns_pcie *pcie = &ep->pcie; +struct cdns_pcie_epf *epf;struct resource *res;struct pci_epc *epc;int ret; +int i; pcie->is_rc = false;
@@ -611,6 +765,25 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep)if (!ep->epf)return -ENOMEM ; + epc->max_vfs =devm_kcalloc (dev, epc->max_functions, +sizeof (*epc->max_vfs),GFP_KERNEL ); +if (!epc->max_vfs) +return -ENOMEM ; + + ret =of_property_read_u16_array (np,"max-virtual-functions" , + epc->max_vfs, epc->max_functions); +if (ret ==0 ) { +for (i =0 ; i < epc->max_functions; i++) { + epf = &ep->epf[i]; +if (epc->max_vfs[i] ==0 ) +continue ; + epf->epf =devm_kcalloc (dev, epc->max_vfs[i], +sizeof (*ep->epf),GFP_KERNEL ); +if (!epf->epf) +return -ENOMEM ; + } + } + ret =pci_epc_mem_init (epc, pcie->mem_res->start,resource_size (pcie->mem_res),PAGE_SIZE );if (ret <0 ) {
drivers/pci/controller/cadence/pcie-cadence.h +7 -0
@@ -50,6 +50,10 @@ (CDNS_PCIE_LM_BASE + 0x0240 + (fn) * 0x0008)#define CDNS_PCIE_LM_EP_FUNC_BAR_CFG1 (fn) \ (CDNS_PCIE_LM_BASE + 0x0244 + (fn) * 0x0008) +#define CDNS_PCIE_LM_EP_VFUNC_BAR_CFG0 (fn) \ + (CDNS_PCIE_LM_BASE + 0x0280 + (fn) * 0x0008) +#define CDNS_PCIE_LM_EP_VFUNC_BAR_CFG1 (fn) \ + (CDNS_PCIE_LM_BASE + 0x0284 + (fn) * 0x0008)#define CDNS_PCIE_LM_EP_FUNC_BAR_CFG_BAR_APERTURE_MASK (b) \ (GENMASK(4, 0) << ((b) * 8))#define CDNS_PCIE_LM_EP_FUNC_BAR_CFG_BAR_APERTURE (b, a) \
@@ -114,6 +118,7 @@#define CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET 0x90#define CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET 0xb0 +#define CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET 0x200/* * Root Port Registers (PCI configuration space for the root port function)
@@ -302,9 +307,11 @@ struct cdns_pcie_rc {/** * struct cdns_pcie_epf - Structure to hold info about endpoint function +* @epf: Info about virtual functions attached to the physical function * @epf_bar: reference to the pci_epf_bar for the six Base Address Registers */ struct cdns_pcie_epf { +struct cdns_pcie_epf *epf;struct pci_epf_bar *epf_bar[PCI_STD_NUM_BARS ]; };
Signature · 1 line
2.17.1
PATCH v2 6/6 misc: pci_endpoint_test: Populate sriov_configure ops to configure SR-IOV device
In reply to Kishon Vijay Abraham IPopulate sriov_configure ops with pci_sriov_configure_simple to configure SR-IOV device.
--- drivers/misc/pci_endpoint_test.c | 1 + 1 file changed, 1 insertion(+)
drivers/misc/pci_endpoint_test.c +1 -0
@@ -974,6 +974,7 @@ static struct pci_driver pci_endpoint_test_driver = { .id_table = pci_endpoint_test_tbl, .probe = pci_endpoint_test_probe, .remove = pci_endpoint_test_remove, + .sriov_configure = pci_sriov_configure_simple, };module_pci_driver (pci_endpoint_test_driver);
Signature · 1 line
2.17.1