PCIe: Endpoint: Redesign MSI-X support
Subsystems (4)
PATCH v2 1/3 PCI: endpoint: Fix ->set_msix() to take BIR and offset as arguments
In reply to Kishon Vijay Abraham Icommit 8963106eabdc ("PCI: endpoint: Add MSI-X interfaces") while adding support to raise MSI-X interrupts from endpoint didn't include BAR Indicator register (BIR) configuration and MSI-X table offset as arguments in pci_epc_set_msix(). This would result in endpoint controller register using random BAR indicator register, the memory for which might not be allocated by the endpoint function driver. Add BAR indicator register and MSI-X table offset as arguments in pci_epc_set_msix() and allocate space for MSI-X table and pending bit array (PBA) in pci-epf-test endpoint function driver.
--- .../pci/controller/dwc/pcie-designware-ep.c | 15 +++++++-- drivers/pci/endpoint/functions/pci-epf-test.c | 31 +++++++++++++++---- drivers/pci/endpoint/pci-epc-core.c | 7 +++-- include/linux/pci-epc.h | 6 ++-- 4 files changed, 47 insertions(+), 12 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +13 -2
@@ -269,7 +269,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) +static int dw_pcie_ep_set_msix (struct pci_epc *epc,u8 func_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);
@@ -278,12 +279,22 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)if (!ep->msix_cap)return -EINVAL ; +dw_pcie_dbi_ro_wr_en (pci); + reg = ep->msix_cap +PCI_MSIX_FLAGS ; val =dw_pcie_readw_dbi (pci, reg); val &= ~PCI_MSIX_FLAGS_QSIZE ; val |= interrupts; -dw_pcie_dbi_ro_wr_en (pci);dw_pcie_writew_dbi (pci, reg, val); + + reg = ep->msix_cap +PCI_MSIX_TABLE ; + val = offset | bir; +dw_pcie_writel_dbi (pci, reg, val); + + reg = ep->msix_cap +PCI_MSIX_PBA ; + val = (offset + (interrupts *PCI_MSIX_ENTRY_SIZE )) | bir; +dw_pcie_writel_dbi (pci, reg, val); +dw_pcie_dbi_ro_wr_dis (pci);return 0 ;
drivers/pci/endpoint/functions/pci-epf-test.c +25 -6
@@ -50,6 +50,7 @@ struct pci_epf_test {void *reg[PCI_STD_NUM_BARS ];struct pci_epf *epf;enum pci_barno test_reg_bar; +size_t msix_table_offset;struct delayed_work cmd_handler;struct dma_chan *dma_chan;struct completion transfer_complete;
@@ -674,6 +675,10 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)struct pci_epf_test *epf_test =epf_get_drvdata (epf);struct device *dev = &epf->dev;struct pci_epf_bar *epf_bar; +size_t msix_table_size =0 ; +size_t test_reg_bar_size; +size_t pba_size =0 ; +bool msix_capable;void *base;int bar, add;enum pci_barno test_reg_bar = epf_test->test_reg_bar;
@@ -682,13 +687,25 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) epc_features = epf_test->epc_features; -if (epc_features->bar_fixed_size[test_reg_bar]) + test_reg_bar_size =ALIGN (sizeof (struct pci_epf_test_reg ),128 ); + + msix_capable = epc_features->msix_capable; +if (msix_capable) { + msix_table_size =PCI_MSIX_ENTRY_SIZE * epf->msix_interrupts; + epf_test->msix_table_offset = test_reg_bar_size; +/* Align to QWORD or 8 Bytes */ + pba_size =ALIGN (DIV_ROUND_UP (epf->msix_interrupts,8 ),8 ); + } + test_reg_size = test_reg_bar_size + msix_table_size + pba_size; + +if (epc_features->bar_fixed_size[test_reg_bar]) { +if (test_reg_size > bar_size[test_reg_bar]) +return -ENOMEM ; test_reg_size = bar_size[test_reg_bar]; -else - test_reg_size =sizeof (struct pci_epf_test_reg ); + } - base =pci_epf_alloc_space (epf, test_reg_size, - test_reg_bar, epc_features->align); + base =pci_epf_alloc_space (epf, test_reg_size, test_reg_bar, + epc_features->align);if (!base) {dev_err (dev,"Failed to allocated register space\n" );return -ENOMEM ;
@@ -784,7 +801,9 @@ static int pci_epf_test_bind(struct pci_epf *epf) }if (msix_capable) { - ret =pci_epc_set_msix (epc, epf->func_no, epf->msix_interrupts); + ret =pci_epc_set_msix (epc, epf->func_no, epf->msix_interrupts, + epf_test->test_reg_bar, + epf_test->msix_table_offset);if (ret) {dev_err (dev,"MSI-X configuration failed\n" );return ret;
drivers/pci/endpoint/pci-epc-core.c +5 -2
@@ -297,10 +297,13 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msix);* @epc: the EPC device on which MSI-X has to be configured * @func_no: the endpoint function number in the EPC device * @interrupts: number of MSI-X interrupts required by the EPF +* @bir: BAR where the MSI-X table resides +* @offset: Offset pointing to the start of MSI-X table * * Invoke to set the required number of MSI-X interrupts. */ -int pci_epc_set_msix (struct pci_epc *epc,u8 func_no,u16 interrupts) +int pci_epc_set_msix (struct pci_epc *epc,u8 func_no,u16 interrupts, +enum pci_barno bir,u32 offset) {int ret;
@@ -312,7 +315,7 @@ int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)return 0 ;mutex_lock (&epc->lock); - ret = epc->ops->set_msix (epc, func_no, interrupts -1 ); + ret = epc->ops->set_msix (epc, func_no, interrupts -1 , bir, offset);mutex_unlock (&epc->lock);return ret;
include/linux/pci-epc.h +4 -2
@@ -53,7 +53,8 @@ struct pci_epc_ops { phys_addr_t addr);int (*set_msi)(struct pci_epc *epc,u8 func_no,u8 interrupts);int (*get_msi)(struct pci_epc *epc,u8 func_no); -int (*set_msix)(struct pci_epc *epc,u8 func_no,u16 interrupts); +int (*set_msix)(struct pci_epc *epc,u8 func_no,u16 interrupts, +enum pci_barno ,u32 offset);int (*get_msix)(struct pci_epc *epc,u8 func_no);int (*raise_irq)(struct pci_epc *epc,u8 func_no,enum pci_epc_irq_type type,u16 interrupt_num);
@@ -178,7 +179,8 @@ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, phys_addr_t phys_addr);int pci_epc_set_msi (struct pci_epc *epc,u8 func_no,u8 interrupts);int pci_epc_get_msi (struct pci_epc *epc,u8 func_no); -int pci_epc_set_msix (struct pci_epc *epc,u8 func_no,u16 interrupts); +int pci_epc_set_msix (struct pci_epc *epc,u8 func_no,u16 interrupts, +enum pci_barno ,u32 offset);int pci_epc_get_msix (struct pci_epc *epc,u8 func_no);int pci_epc_raise_irq (struct pci_epc *epc,u8 func_no,enum pci_epc_irq_type type,u16 interrupt_num);
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
v2 cover PCIe: Endpoint: Redesign MSI-X support
Existing MSI-X support in Endpoint core has limitations:
1) MSIX table (which is mapped to a BAR) is not allocated by anyone. Ideally this should be allocated by endpoint function driver.
2) Endpoint controller can choose any random BARs for MSIX table (irrespective of whether the endpoint function driver has allocated memory for it or not)
In order to avoid these limitations, pci_epc_set_msix() is modified to include BAR Indicator register (BIR) configuration and MSIX table offset as arguments. This series also fixed MSIX support in dwc driver and add MSI-X support in Cadence PCIe driver.
Changes from v1:
*) Removed Cadence MSI-X support from the series
*) Fixed nits pointed out by Bjorn
Kishon Vijay Abraham I (3):
PCI: endpoint: Fix ->set_msix() to take BIR and offset as arguments
PCI: dwc: Fix dw_pcie_ep_raise_msix_irq() to get correct MSI-X table
address
PCI: keystone: Allow AM654 PCIe Endpoint to raise MSI-X interrupt
drivers/pci/controller/dwc/pci-keystone.c | 5 +- .../pci/controller/dwc/pcie-designware-ep.c | 61 +++++++++---------- drivers/pci/controller/dwc/pcie-designware.h | 1 + drivers/pci/endpoint/functions/pci-epf-test.c | 31 ++++++++-- drivers/pci/endpoint/pci-epc-core.c | 7 ++- drivers/pci/endpoint/pci-epf-core.c | 2 + include/linux/pci-epc.h | 6 +- include/linux/pci-epf.h | 15 +++++ 8 files changed, 86 insertions(+), 42 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 3/3 PCI: keystone: Allow AM654 PCIe Endpoint to raise MSI-X interrupt
AM654 PCIe EP controller has MSI-X capability register and has the ability to raise MSI-X interrupt. Add support in pci-keystone.c for PCIe endpoint controller in AM654 to raise MSI-X interrupts.
--- drivers/pci/controller/dwc/pci-keystone.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-keystone.c +4 -1
@@ -959,6 +959,9 @@ static int ks_pcie_am654_raise_irq(struct dw_pcie_ep *ep, u8 func_no,case PCI_EPC_IRQ_MSI :dw_pcie_ep_raise_msi_irq (ep, func_no, interrupt_num);break ; +case PCI_EPC_IRQ_MSIX : +dw_pcie_ep_raise_msix_irq (ep, func_no, interrupt_num); +break ;default :dev_err (pci->dev,"UNKNOWN IRQ type\n" );return -EINVAL ;
@@ -970,7 +973,7 @@ static int ks_pcie_am654_raise_irq(struct dw_pcie_ep *ep, u8 func_no,static const struct pci_epc_features ks_pcie_am654_epc_features = { .linkup_notifier = false, .msi_capable = true, - .msix_capable = false, + .msix_capable = true, .reserved_bar =1 <<BAR_0 |1 <<BAR_1 , .bar_fixed_64bit =1 <<BAR_0 , .bar_fixed_size[2 ] =SZ_1M ,
Signature · 1 line
2.17.1
PATCH v2 2/3 PCI: dwc: Fix dw_pcie_ep_raise_msix_irq() to get correct MSI-X table address
In reply to Kishon Vijay Abraham Icommit beb4641a787d ("PCI: dwc: Add MSI-X callbacks handler"), in order to raise MSI-X interrupt, obtained MSIX table address from Base Address Register (BAR). However BAR only holds PCI address programmed by the host whereas the MSI-X table should be in the local memory.
Store the MSI-X table address (virtual address) as part of ->set_bar() callback and use that to get the message address and message data here.
--- .../pci/controller/dwc/pcie-designware-ep.c | 46 +++++++------------ drivers/pci/controller/dwc/pcie-designware.h | 1 + drivers/pci/endpoint/pci-epf-core.c | 2 + include/linux/pci-epf.h | 15 ++++++ 4 files changed, 35 insertions(+), 29 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +17 -29
@@ -125,6 +125,7 @@ static void dw_pcie_ep_clear_bar(struct pci_epc *epc, u8 func_no,dw_pcie_disable_atu (pci, atu_index,DW_PCIE_REGION_INBOUND );clear_bit (atu_index, ep->ib_window_map); + ep->epf_bar[bar] =NULL ; } static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no,
@@ -158,6 +159,7 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no,dw_pcie_writel_dbi (pci, reg +4 ,0 ); } + ep->epf_bar[bar] = epf_bar;dw_pcie_dbi_ro_wr_dis (pci);return 0 ;
@@ -420,55 +422,41 @@ int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no, u16 interrupt_num) {struct dw_pcie *pci =to_dw_pcie_from_ep (ep); +struct pci_epf_msix_tbl *msix_tbl;struct pci_epc *epc = ep->epc; -u16 tbl_offset, bir; -u32 bar_addr_upper, bar_addr_lower; -u32 msg_addr_upper, msg_addr_lower; +struct pci_epf_bar *epf_bar;u32 reg, msg_data, vec_ctrl; -u64 tbl_addr, msg_addr, reg_u64; -void __iomem *msix_tbl; +unsigned int aligned_offset; +u32 tbl_offset; +u64 msg_addr;int ret; +u8 bir; reg = ep->msix_cap +PCI_MSIX_TABLE ; tbl_offset =dw_pcie_readl_dbi (pci, reg); bir = (tbl_offset &PCI_MSIX_TABLE_BIR ); tbl_offset &=PCI_MSIX_TABLE_OFFSET ; - reg =PCI_BASE_ADDRESS_0 + (4 * bir); - bar_addr_upper =0 ; - bar_addr_lower =dw_pcie_readl_dbi (pci, reg); - reg_u64 = (bar_addr_lower &PCI_BASE_ADDRESS_MEM_TYPE_MASK ); -if (reg_u64 ==PCI_BASE_ADDRESS_MEM_TYPE_64 ) - bar_addr_upper =dw_pcie_readl_dbi (pci, reg +4 ); + epf_bar = ep->epf_bar[bir]; + msix_tbl = epf_bar->addr; + msix_tbl = (struct pci_epf_msix_tbl *)((char *)msix_tbl + tbl_offset); - tbl_addr = ((u64 ) bar_addr_upper) <<32 | bar_addr_lower; - tbl_addr += (tbl_offset + ((interrupt_num -1 ) *PCI_MSIX_ENTRY_SIZE )); - tbl_addr &=PCI_BASE_ADDRESS_MEM_MASK ; - - msix_tbl =ioremap (ep->phys_base + tbl_addr, -PCI_MSIX_ENTRY_SIZE ); -if (!msix_tbl) -return -EINVAL ; - - msg_addr_lower =readl (msix_tbl +PCI_MSIX_ENTRY_LOWER_ADDR ); - msg_addr_upper =readl (msix_tbl +PCI_MSIX_ENTRY_UPPER_ADDR ); - msg_addr = ((u64 ) msg_addr_upper) <<32 | msg_addr_lower; - msg_data =readl (msix_tbl +PCI_MSIX_ENTRY_DATA ); - vec_ctrl =readl (msix_tbl +PCI_MSIX_ENTRY_VECTOR_CTRL ); - -iounmap (msix_tbl); + msg_addr = msix_tbl[(interrupt_num -1 )].msg_addr; + msg_data = msix_tbl[(interrupt_num -1 )].msg_data; + vec_ctrl = msix_tbl[(interrupt_num -1 )].vector_ctrl;if (vec_ctrl &PCI_MSIX_ENTRY_CTRL_MASKBIT ) {dev_dbg (pci->dev,"MSI-X entry ctrl set\n" );return -EPERM ; } - ret =dw_pcie_ep_map_addr (epc, func_no, ep->msi_mem_phys, msg_addr, + aligned_offset = msg_addr & (epc->mem->page_size -1 ); + ret =dw_pcie_ep_map_addr (epc, func_no, ep->msi_mem_phys, msg_addr, epc->mem->page_size);if (ret)return ret; -writel (msg_data, ep->msi_mem); +writel (msg_data, ep->msi_mem + aligned_offset);dw_pcie_ep_unmap_addr (epc, func_no, ep->msi_mem_phys);
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -233,6 +233,7 @@ struct dw_pcie_ep {phys_addr_t msi_mem_phys;u8 msi_cap;/* MSI capability offset */ u8 msix_cap;/* MSI-X capability offset */ +struct pci_epf_bar *epf_bar[PCI_STD_NUM_BARS ]; };struct dw_pcie_ops {
drivers/pci/endpoint/pci-epf-core.c +2 -0
@@ -87,6 +87,7 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar) epf->bar[bar].phys_addr); epf->bar[bar].phys_addr =0 ; + epf->bar[bar].addr =NULL ; epf->bar[bar].size =0 ; epf->bar[bar].barno =0 ; epf->bar[bar].flags =0 ;
@@ -123,6 +124,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, } epf->bar[bar].phys_addr = phys_addr; + epf->bar[bar].addr = space; epf->bar[bar].size = size; epf->bar[bar].barno = bar; epf->bar[bar].flags |= upper_32_bits(size) ?
include/linux/pci-epf.h +15 -0
@@ -89,10 +89,12 @@ struct pci_epf_driver {/** * struct pci_epf_bar - represents the BAR of EPF device * @phys_addr: physical address that should be mapped to the BAR +* @addr: virtual address corresponding to the @phys_addr * @size: the size of the address space present in BAR */ struct pci_epf_bar {dma_addr_t phys_addr; +void *addr;size_t size;enum pci_barno barno;int flags;
@@ -129,6 +131,19 @@ struct pci_epf {struct mutex lock; }; +/** +* struct pci_epf_msix_tbl - represents the MSIX table entry structure +* @msg_addr: Writes to this address will trigger MSIX interrupt in host +* @msg_data: Data that should be written to @msg_addr to trigger MSIX interrupt +* @vector_ctrl: Identifies if the function is prohibited from sending a message +* using this MSIX table entry +*/ +struct pci_epf_msix_tbl { +u64 msg_addr; +u32 msg_data; +u32 vector_ctrl; +}; +#define to_pci_epf (epf_dev) container_of((epf_dev), struct pci_epf, dev)#define pci_epf_register_driver (driver) \
Signature · 1 line
2.17.1
Lorenzo Pieralisi
AppliedQuoted 23 lines · Kishon Vijay Abraham I
Existing MSI-X support in Endpoint core has limitations:
1) MSIX table (which is mapped to a BAR) is not allocated by anyone. Ideally this should be allocated by endpoint function driver.
2) Endpoint controller can choose any random BARs for MSIX table (irrespective of whether the endpoint function driver has allocated memory for it or not)In order to avoid these limitations,
pci_epc_set_msix()is modified to include BAR Indicator register (BIR) configuration and MSIX table offset as arguments. This series also fixed MSIX support in dwc driver and add MSI-X support in Cadence PCIe driver.Changes from v1:
*) Removed Cadence MSI-X support from the series
*) Fixed nits pointed out by BjornKishon Vijay Abraham I (3):
PCI: endpoint: Fix ->set_msix() to take BIR and offset as arguments
PCI: dwc: Fixdw_pcie_ep_raise_msix_irq()to get correct MSI-X table
address
PCI: keystone: Allow AM654 PCIe Endpoint to raise MSI-X interrupt
Quoted 9 lines
drivers/pci/controller/dwc/pci-keystone.c | 5 +- .../pci/controller/dwc/pcie-designware-ep.c | 61 +++++++++---------- drivers/pci/controller/dwc/pcie-designware.h | 1 + drivers/pci/endpoint/functions/pci-epf-test.c | 31 ++++++++-- drivers/pci/endpoint/pci-epc-core.c | 7 ++- drivers/pci/endpoint/pci-epf-core.c | 2 + include/linux/pci-epc.h | 6 +- include/linux/pci-epf.h | 15 +++++ 8 files changed, 86 insertions(+), 42 deletions(-)
I have applied it to pci/endpoint for v5.7, thanks.
Lorenzo