Skip to contentSkip to conversation

PCI: designware-ep: Add multiple PFs support for DWC

PATCH Superseded Xiaowei Bao 7 participants 50 messages Aug 22, 2019 – Nov 6, 2019

Subsystems (8)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/10 PCI: designware-ep: Add multiple PFs support for DWC

Add multiple PFs support for DWC, different PF have different config space we use pf-offset property which get from the DTS to access the different pF config space.

---
v2:
- Remove duplicate redundant code.
- Reimplement the PF config space access way.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 122 ++++++++++++++++--------
 drivers/pci/controller/dwc/pcie-designware.c    |  59 ++++++++----
 drivers/pci/controller/dwc/pcie-designware.h    |  11 ++-
 3 files changed, 134 insertions(+), 58 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +84 -38
index 2bf5a35..3e2b740 100644
@@ -19,12 +19,17 @@ void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
 	pci_epc_linkup(epc);
 }
 
-static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar,
-				   int flags)
+static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
+				   enum pci_barno bar, int flags)
 {
 	u32 reg;
+	unsigned int func_offset = 0;
+	struct dw_pcie_ep *ep = &pci->ep;
 
-	reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);
 	dw_pcie_dbi_ro_wr_en(pci);
 	dw_pcie_writel_dbi2(pci, reg, 0x0);
 	dw_pcie_writel_dbi(pci, reg, 0x0);
@@ -37,7 +42,12 @@ static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar,
 
 void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
 {
-	__dw_pcie_ep_reset_bar(pci, bar, 0);
+	u8 func_no, funcs;
+
+	funcs = pci->ep.epc->max_functions;
+
+	for (func_no = 0; func_no < funcs; func_no++)
+		__dw_pcie_ep_reset_bar(pci, func_no, bar, 0);
 }
 
 static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie *pci, u8 cap_ptr,
@@ -78,28 +88,32 @@ static int dw_pcie_ep_write_header(struct pci_epc *epc, u8 func_no,
 {
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	dw_pcie_dbi_ro_wr_en(pci);
-	dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, hdr->vendorid);
-	dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, hdr->deviceid);
-	dw_pcie_writeb_dbi(pci, PCI_REVISION_ID, hdr->revid);
-	dw_pcie_writeb_dbi(pci, PCI_CLASS_PROG, hdr->progif_code);
-	dw_pcie_writew_dbi(pci, PCI_CLASS_DEVICE,
+	dw_pcie_writew_dbi(pci, func_offset + PCI_VENDOR_ID, hdr->vendorid);
+	dw_pcie_writew_dbi(pci, func_offset + PCI_DEVICE_ID, hdr->deviceid);
+	dw_pcie_writeb_dbi(pci, func_offset + PCI_REVISION_ID, hdr->revid);
+	dw_pcie_writeb_dbi(pci, func_offset + PCI_CLASS_PROG, hdr->progif_code);
+	dw_pcie_writew_dbi(pci, func_offset + PCI_CLASS_DEVICE,
 			   hdr->subclass_code | hdr->baseclass_code << 8);
-	dw_pcie_writeb_dbi(pci, PCI_CACHE_LINE_SIZE,
+	dw_pcie_writeb_dbi(pci, func_offset + PCI_CACHE_LINE_SIZE,
 			   hdr->cache_line_size);
-	dw_pcie_writew_dbi(pci, PCI_SUBSYSTEM_VENDOR_ID,
+	dw_pcie_writew_dbi(pci, func_offset + PCI_SUBSYSTEM_VENDOR_ID,
 			   hdr->subsys_vendor_id);
-	dw_pcie_writew_dbi(pci, PCI_SUBSYSTEM_ID, hdr->subsys_id);
-	dw_pcie_writeb_dbi(pci, PCI_INTERRUPT_PIN,
+	dw_pcie_writew_dbi(pci, func_offset + PCI_SUBSYSTEM_ID, hdr->subsys_id);
+	dw_pcie_writeb_dbi(pci, func_offset + PCI_INTERRUPT_PIN,
 			   hdr->interrupt_pin);
 	dw_pcie_dbi_ro_wr_dis(pci);
 
 	return 0;
 }
 
-static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar,
-				  dma_addr_t cpu_addr,
+static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no,
+				  enum pci_barno bar, dma_addr_t cpu_addr,
 				  enum dw_pcie_as_type as_type)
 {
 	int ret;
@@ -112,7 +126,7 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar,
 		return -EINVAL;
 	}
 
-	ret = dw_pcie_prog_inbound_atu(pci, free_win, bar, cpu_addr,
+	ret = dw_pcie_prog_inbound_atu(pci, func_no, free_win, bar, cpu_addr,
 				       as_type);
 	if (ret < 0) {
 		dev_err(pci->dev, "Failed to program IB window\n");
@@ -125,7 +139,8 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar,
 	return 0;
 }
 
-static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, phys_addr_t phys_addr,
+static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, u8 func_no,
+				   phys_addr_t phys_addr,
 				   u64 pci_addr, size_t size)
 {
 	u32 free_win;
@@ -137,8 +152,8 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, phys_addr_t phys_addr,
 		return -EINVAL;
 	}
 
-	dw_pcie_prog_outbound_atu(pci, free_win, PCIE_ATU_TYPE_MEM,
-				  phys_addr, pci_addr, size);
+	dw_pcie_prog_ep_outbound_atu(pci, func_no, free_win, PCIE_ATU_TYPE_MEM,
+				     phys_addr, pci_addr, size);
 
 	set_bit(free_win, ep->ob_window_map);
 	ep->outbound_addr[free_win] = phys_addr;
@@ -154,7 +169,7 @@ static void dw_pcie_ep_clear_bar(struct pci_epc *epc, u8 func_no,
 	enum pci_barno bar = epf_bar->barno;
 	u32 atu_index = ep->bar_to_atu[bar];
 
-	__dw_pcie_ep_reset_bar(pci, bar, epf_bar->flags);
+	__dw_pcie_ep_reset_bar(pci, func_no, bar, epf_bar->flags);
 
 	dw_pcie_disable_atu(pci, atu_index, DW_PCIE_REGION_INBOUND);
 	clear_bit(atu_index, ep->ib_window_map);
@@ -170,14 +185,21 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no,
 	size_t size = epf_bar->size;
 	int flags = epf_bar->flags;
 	enum dw_pcie_as_type as_type;
-	u32 reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	u32 reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = PCI_BASE_ADDRESS_0 + (4 * bar) + func_offset;
 
 	if (!(flags & PCI_BASE_ADDRESS_SPACE))
 		as_type = DW_PCIE_AS_MEM;
 	else
 		as_type = DW_PCIE_AS_IO;
 
-	ret = dw_pcie_ep_inbound_atu(ep, bar, epf_bar->phys_addr, as_type);
+	ret = dw_pcie_ep_inbound_atu(ep, func_no, bar,
+				     epf_bar->phys_addr, as_type);
 	if (ret)
 		return ret;
 
@@ -235,7 +257,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no,
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-	ret = dw_pcie_ep_outbound_atu(ep, addr, pci_addr, size);
+	ret = dw_pcie_ep_outbound_atu(ep, func_no, addr, pci_addr, size);
 	if (ret) {
 		dev_err(pci->dev, "Failed to enable address\n");
 		return ret;
@@ -249,11 +271,15 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSI_FLAGS_ENABLE))
 		return -EINVAL;
@@ -268,11 +294,15 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSI_FLAGS_QMASK;
 	val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK;
@@ -288,11 +318,15 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSIX_FLAGS_ENABLE))
 		return -EINVAL;
@@ -307,11 +341,15 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSIX_FLAGS_QSIZE;
 	val |= interrupts;
@@ -398,29 +436,33 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct pci_epc *epc = ep->epc;
 	unsigned int aligned_offset;
+	unsigned int func_offset = 0;
 	u16 msg_ctrl, msg_data;
 	u32 msg_addr_lower, msg_addr_upper, reg;
 	u64 msg_addr;
 	bool has_upper;
 	int ret;
 
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
 	if (!ep->msi_cap)
 		return -EINVAL;
 
 	/* Raise MSI per the PCI Local Bus Specification Revision 3.0, 6.8.1. */
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	msg_ctrl = dw_pcie_readw_dbi(pci, reg);
 	has_upper = !!(msg_ctrl & PCI_MSI_FLAGS_64BIT);
-	reg = ep->msi_cap + PCI_MSI_ADDRESS_LO;
+	reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_LO;
 	msg_addr_lower = dw_pcie_readl_dbi(pci, reg);
 	if (has_upper) {
-		reg = ep->msi_cap + PCI_MSI_ADDRESS_HI;
+		reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_HI;
 		msg_addr_upper = dw_pcie_readl_dbi(pci, reg);
-		reg = ep->msi_cap + PCI_MSI_DATA_64;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_64;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	} else {
 		msg_addr_upper = 0;
-		reg = ep->msi_cap + PCI_MSI_DATA_32;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_32;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	}
 	aligned_offset = msg_addr_lower & (epc->mem->page_size - 1);
@@ -439,11 +481,12 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 }
 
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
-			     u16 interrupt_num)
+			      u16 interrupt_num)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct pci_epc *epc = ep->epc;
 	u16 tbl_offset, bir;
+	unsigned int func_offset = 0;
 	u32 bar_addr_upper, bar_addr_lower;
 	u32 msg_addr_upper, msg_addr_lower;
 	u32 reg, msg_data, vec_ctrl;
@@ -451,12 +494,15 @@ int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 	void __iomem *msix_tbl;
 	int ret;
 
-	reg = ep->msix_cap + PCI_MSIX_TABLE;
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = ep->msix_cap + func_offset + 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);
+	reg = PCI_BASE_ADDRESS_0 + func_offset + (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);
@@ -592,13 +638,13 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 	ep->epc = epc;
 	epc_set_drvdata(epc, ep);
 
-	if (ep->ops->ep_init)
-		ep->ops->ep_init(ep);
-
 	ret = of_property_read_u8(np, "max-functions", &epc->max_functions);
 	if (ret < 0)
 		epc->max_functions = 1;
 
+	if (ep->ops->ep_init)
+		ep->ops->ep_init(ep);
+
 	ret = __pci_epc_mem_init(epc, ep->phys_base, ep->addr_size,
 				 ep->page_size);
 	if (ret < 0) {
drivers/pci/controller/dwc/pcie-designware.c +41 -18

125 lines not on this page · raw message

drivers/pci/controller/dwc/pcie-designware.h +9 -2
index ffed084..a0fdbf7 100644
@@ -71,9 +71,11 @@
 #define PCIE_ATU_TYPE_IO		0x2
 #define PCIE_ATU_TYPE_CFG0		0x4
 #define PCIE_ATU_TYPE_CFG1		0x5
+#define PCIE_ATU_FUNC_NUM(pf)           (pf << 20)
 #define PCIE_ATU_CR2			0x908
 #define PCIE_ATU_ENABLE			BIT(31)
 #define PCIE_ATU_BAR_MODE_ENABLE	BIT(30)
+#define PCIE_ATU_FUNC_NUM_MATCH_EN      BIT(19)
 #define PCIE_ATU_LOWER_BASE		0x90C
 #define PCIE_ATU_UPPER_BASE		0x910
 #define PCIE_ATU_LIMIT			0x914
@@ -197,6 +199,7 @@ struct dw_pcie_ep_ops {
 	int	(*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
 			     enum pci_epc_irq_type type, u16 interrupt_num);
 	const struct pci_epc_features* (*get_features)(struct dw_pcie_ep *ep);
+	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);
 };
 
 struct dw_pcie_ep {
@@ -265,8 +268,12 @@ int dw_pcie_wait_for_link(struct dw_pcie *pci);
 void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
 			       int type, u64 cpu_addr, u64 pci_addr,
 			       u32 size);
-int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
-			     u64 cpu_addr, enum dw_pcie_as_type as_type);
+void dw_pcie_prog_ep_outbound_atu(struct dw_pcie *pci, u8 func_no, int index,
+				  int type, u64 cpu_addr, u64 pci_addr,
+				  u32 size);
+int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, u8 func_no, int index,
+			     int bar, u64 cpu_addr,
+			     enum dw_pcie_as_type as_type);
 void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
 			 enum dw_pcie_region_type type);
 void dw_pcie_setup(struct dw_pcie *pci);
Signature · 1 line
2.9.5
#1 lore raw

PATCH v2 2/10 PCI: designware-ep: Add the doorbell mode of MSI-X in EP mode

Add the doorbell mode of MSI-X in EP mode.

---
v2:
- Remove the macro of no used.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 14 ++++++++++++++
 drivers/pci/controller/dwc/pcie-designware.h    | 12 ++++++++++++
 2 files changed, 26 insertions(+)
drivers/pci/controller/dwc/pcie-designware-ep.c +14 -0
index 3e2b740..b8388f8 100644
@@ -480,6 +480,20 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 	return 0;
 }
 
+int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
+				       u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	u32 msg_data;
+
+	msg_data = (func_no << PCIE_MSIX_DOORBELL_PF_SHIFT) |
+		   (interrupt_num - 1);
+
+	dw_pcie_writel_dbi(pci, PCIE_MSIX_DOORBELL, msg_data);
+
+	return 0;
+}
+
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 			      u16 interrupt_num)
 {
drivers/pci/controller/dwc/pcie-designware.h +12 -0
index a0fdbf7..895a9ef 100644
@@ -88,6 +88,9 @@
 #define PCIE_MISC_CONTROL_1_OFF		0x8BC
 #define PCIE_DBI_RO_WR_EN		BIT(0)
 
+#define PCIE_MSIX_DOORBELL		0x948
+#define PCIE_MSIX_DOORBELL_PF_SHIFT	24
+
 /*
  * iATU Unroll-specific register definitions
  * From 4.80 core version the address translation will be made by unroll
@@ -400,6 +403,8 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 			     u8 interrupt_num);
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 			     u16 interrupt_num);
+int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
+				       u16 interrupt_num);
 void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);
 #else
 static inline void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
@@ -432,6 +437,13 @@ static inline int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 	return 0;
 }
 
+static inline int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep,
+						     u8 func_no,
+						     u16 interrupt_num)
+{
+	return 0;
+}
+
 static inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
 {
 }
Signature · 1 line
2.9.5
Reviewed-by on v2 2/10
#2 lore raw

Re: [PATCH v2 02/10] PCI: designware-ep: Add the doorbell mode of MSI-X in EP mode

Quoted 60 lines · Xiaowei Bao

Add the doorbell mode of MSI-X in EP mode.

---
v2:
- Remove the macro of no used.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 14 ++++++++++++++
 drivers/pci/controller/dwc/pcie-designware.h    | 12 ++++++++++++
 2 files changed, 26 insertions(+)
drivers/pci/controller/dwc/pcie-designware-ep.c +14 -0
index 3e2b740..b8388f8 100644
@@ -480,6 +480,20 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 	return 0;
 }
 
+int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
+				       u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	u32 msg_data;
+
+	msg_data = (func_no << PCIE_MSIX_DOORBELL_PF_SHIFT) |
+		   (interrupt_num - 1);
+
+	dw_pcie_writel_dbi(pci, PCIE_MSIX_DOORBELL, msg_data);
+
+	return 0;
+}
+
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 			      u16 interrupt_num)
 {
drivers/pci/controller/dwc/pcie-designware.h +5 -0
index a0fdbf7..895a9ef 100644
@@ -88,6 +88,9 @@
 #define PCIE_MISC_CONTROL_1_OFF		0x8BC
 #define PCIE_DBI_RO_WR_EN		BIT(0)
 
+#define PCIE_MSIX_DOORBELL		0x948
+#define PCIE_MSIX_DOORBELL_PF_SHIFT	24
+
 /*
  * iATU Unroll-specific register definitions
  * From 4.80 core version the address translation will be made by unroll
@@ -400,6 +403,8 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 			     u8 interrupt_num);
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 			     u16 interrupt_num);
+int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8 func_no,
+				       u16 interrupt_num);
 void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);
 #else
 static inline void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)

drivers/pci/controller/dwc/pcie-designware.h static inline int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no, · line 446

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.h +7 -0
@@ -432,6 +437,13 @@ static inline int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 	return 0;
 }
 
+static inline int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep,
+						     u8 func_no,
+						     u16 interrupt_num)
+{
+	return 0;
+}
+

Looks OK to me.

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.h +0 -0
 static inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
 {
 }
Signature · 1 line
2.9.5
#3 lore raw

RE: [PATCH v2 02/10] PCI: designware-ep: Add the doorbell mode of MSI-X in EP mode

Quoted 98 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:36
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 02/10] PCI: designware-ep: Add the doorbell mode of MSI-X in EP mode

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep

Quoted 17 lines · Xiaowei Bao

Add the doorbell mode of MSI-X in EP mode.

---
v2:
- Remove the macro of no used.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 14 ++++++++++++++
 drivers/pci/controller/dwc/pcie-designware.h    | 12 ++++++++++++
 2 files changed, 26 insertions(+)
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
index 3e2b740..b8388f8 100644
@@ -480,6 +480,20 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep

*ep, u8 func_no,

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -0
 	return 0;
 }
 
+int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8

func_no,

Quoted 31 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +13 -0
+				       u16 interrupt_num)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	u32 msg_data;
+
+	msg_data = (func_no << PCIE_MSIX_DOORBELL_PF_SHIFT) |
+		   (interrupt_num - 1);
+
+	dw_pcie_writel_dbi(pci, PCIE_MSIX_DOORBELL, msg_data);
+
+	return 0;
+}
+
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 			      u16 interrupt_num)
 {
drivers/pci/controller/dwc/pcie-designware.h +3 -0
index a0fdbf7..895a9ef 100644
@@ -88,6 +88,9 @@
 #define PCIE_MISC_CONTROL_1_OFF		0x8BC
 #define PCIE_DBI_RO_WR_EN		BIT(0)
 
+#define PCIE_MSIX_DOORBELL		0x948
+#define PCIE_MSIX_DOORBELL_PF_SHIFT	24
+
 /*
  * iATU Unroll-specific register definitions
  * From 4.80 core version the address translation will be made by
Quoted 1 line

unroll @@ -400,6 +403,8 @@ int dw_pcie_ep_raise_msi_irq(struct

dw_pcie_ep *ep, u8 func_no,

drivers/pci/controller/dwc/pcie-designware.h int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
 			     u8 interrupt_num);
 int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
 			     u16 interrupt_num);
+int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep *ep, u8

func_no,

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
+				       u16 interrupt_num);
 void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);

#else static inline void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) @@ -432,6 +437,13 @@ static inline int dw_pcie_ep_raise_msix_irq(struct

dw_pcie_ep *ep, u8 func_no,

drivers/pci/controller/dwc/pcie-designware.h

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
 	return 0;
 }
 
+static inline int dw_pcie_ep_raise_msix_irq_doorbell(struct dw_pcie_ep

*ep,

drivers/pci/controller/dwc/pcie-designware.h static inline int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no, · line 446

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.h +6 -0
+						     u8 func_no,
+						     u16 interrupt_num)
+{
+	return 0;
+}
+

Looks OK to me.

Quoted 1 line

Thanks a lot.

Quoted 6 lines
Quoted 6 lines

static inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum
pci_barno bar) { }
--
2.9.5

#4 lore raw

PATCH v2 3/10 PCI: designware-ep: Move the function of getting MSI capability forward

In reply to Xiaowei Bao

Move the function of getting MSI capability to the front of init function, because the init function of the EP platform driver will use the return value by the function of getting MSI capability.

---
v2:
- No change.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -3
index b8388f8..0a6c199 100644
@@ -656,6 +656,10 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 	if (ret < 0)
 		epc->max_functions = 1;
 
+	ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI);
+
+	ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX);
+
 	if (ep->ops->ep_init)
 		ep->ops->ep_init(ep);
 
@@ -672,9 +676,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 		dev_err(dev, "Failed to reserve memory for MSI/MSI-X\n");
 		return -ENOMEM;
 	}
-	ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI);
-
-	ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX);
 
 	offset = dw_pcie_ep_find_ext_capability(pci, PCI_EXT_CAP_ID_REBAR);
 	if (offset) {
Signature · 1 line
2.9.5
Reviewed-by on v2 3/10
#5 lore raw

Re: [PATCH v2 03/10] PCI: designware-ep: Move the function of getting MSI capability forward

Quoted 5 lines · Xiaowei Bao

Move the function of getting MSI capability to the front of init function, because the init function of the EP platform driver will use the return value by the function of getting MSI capability.

Quoted 35 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -3
index b8388f8..0a6c199 100644
@@ -656,6 +656,10 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 	if (ret < 0)
 		epc->max_functions = 1;
 
+	ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI);
+
+	ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX);
+
 	if (ep->ops->ep_init)
 		ep->ops->ep_init(ep);
 
@@ -672,9 +676,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 		dev_err(dev, "Failed to reserve memory for MSI/MSI-X\n");
 		return -ENOMEM;
 	}
-	ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI);
-
-	ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX);
 
 	offset = dw_pcie_ep_find_ext_capability(pci, PCI_EXT_CAP_ID_REBAR);
 	if (offset) {
Signature · 1 line
2.9.5
#6 lore raw

RE: [PATCH v2 03/10] PCI: designware-ep: Move the function of getting MSI capability forward

Quoted 17 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:39
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 03/10] PCI: designware-ep: Move the function of getting MSI capability forward

Quoted 8 lines
Quoted 5 lines · Xiaowei Bao

Move the function of getting MSI capability to the front of init function, because the init function of the EP platform driver will use the return value by the function of getting MSI capability.

Thanks a lot, I think move this to ep_init is better.

Quoted 37 lines
Quoted 37 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -4
index b8388f8..0a6c199 100644
@@ -656,6 +656,10 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 	if (ret < 0)
 		epc->max_functions = 1;
 
+	ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI);
+
+	ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX);
+
 	if (ep->ops->ep_init)
 		ep->ops->ep_init(ep);
 
@@ -672,9 +676,6 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
 		dev_err(dev, "Failed to reserve memory for MSI/MSI-X\n");
 		return -ENOMEM;
 	}
-	ep->msi_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSI);
-
-	ep->msix_cap = dw_pcie_ep_find_capability(pci, PCI_CAP_ID_MSIX);
 
 	offset = dw_pcie_ep_find_ext_capability(pci, PCI_EXT_CAP_ID_REBAR);
 	if (offset) {
--

2.9.5

#7 lore raw

PATCH v2 4/10 dt-bindings: pci: layerscape-pci: add compatible strings for ls1088a and ls2088a

In reply to Xiaowei Bao

Add compatible strings for ls1088a and ls2088a.

---
v2:
- No change.

 Documentation/devicetree/bindings/pci/layerscape-pci.txt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pci/layerscape-pci.txt +4 -1
index e20ceaa..16f592e 100644
@@ -22,7 +22,10 @@ Required properties:
         "fsl,ls1043a-pcie"
         "fsl,ls1012a-pcie"
   EP mode:
-	"fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep"
+	"fsl,ls-pcie-ep"
+	"fsl,ls1046a-pcie-ep"
+	"fsl,ls1088a-pcie-ep"
+	"fsl,ls2088a-pcie-ep"
 - reg: base addresses and lengths of the PCIe controller register blocks.
 - interrupts: A list of interrupt outputs of the controller. Must contain an
   entry for each entry in the interrupt-names property.
Signature · 1 line
2.9.5
maintainer
#8 lore raw

Re: [PATCH v2 04/10] dt-bindings: pci: layerscape-pci: add compatible strings for ls1088a and ls2088a

Quoted 15 lines · Xiaowei Bao

Add compatible strings for ls1088a and ls2088a.

---
v2:
- No change.

 Documentation/devicetree/bindings/pci/layerscape-pci.txt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pci/layerscape-pci.txt +0 -0
index e20ceaa..16f592e 100644

Documentation/devicetree/bindings/pci/layerscape-pci.txt Required properties: · line 25

Quoted 5 lines
Documentation/devicetree/bindings/pci/layerscape-pci.txt +1 -1
@@ -22,7 +22,10 @@ Required properties:
         "fsl,ls1043a-pcie"
         "fsl,ls1012a-pcie"
   EP mode:
-	"fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep"
+	"fsl,ls-pcie-ep"

Wasn't this a fallback? Each line should be one valid combination of compatible strings.

Quoted 9 lines
Documentation/devicetree/bindings/pci/layerscape-pci.txt +3 -0
+	"fsl,ls1046a-pcie-ep"
+	"fsl,ls1088a-pcie-ep"
+	"fsl,ls2088a-pcie-ep"
 - reg: base addresses and lengths of the PCIe controller register blocks.
 - interrupts: A list of interrupt outputs of the controller. Must contain an
   entry for each entry in the interrupt-names property.
Signature · 1 line
2.9.5
#9 lore raw

RE: [PATCH v2 04/10] dt-bindings: pci: layerscape-pci: add compatible strings for ls1088a and ls2088a

Quoted 29 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: 2019年8月28日 6:26
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 04/10] dt-bindings: pci: layerscape-pci: add compatible strings for ls1088a and ls2088a

Quoted 10 lines · Xiaowei Bao

Add compatible strings for ls1088a and ls2088a.

---
v2:
- No change.

 Documentation/devicetree/bindings/pci/layerscape-pci.txt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 14 lines

Documentation/devicetree/bindings/pci/layerscape-pci.txt Required properties: · line 25

Quoted 11 lines
Documentation/devicetree/bindings/pci/layerscape-pci.txt +1 -1
index e20ceaa..16f592e 100644
@@ -22,7 +22,10 @@ Required properties:
         "fsl,ls1043a-pcie"
         "fsl,ls1012a-pcie"
   EP mode:
-	"fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep"
+	"fsl,ls-pcie-ep"

Wasn't this a fallback? Each line should be one valid combination of compatible strings.

Thanks, got it, I will modify it in next version patch.

Thanks
Xiaowei

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/pci/layerscape-pci.txt +3 -1
+	"fsl,ls1046a-pcie-ep"
+	"fsl,ls1088a-pcie-ep"
+	"fsl,ls2088a-pcie-ep"
 - reg: base addresses and lengths of the PCIe controller register blocks.
 - interrupts: A list of interrupt outputs of the controller. Must contain an
   entry for each entry in the interrupt-names property.
--

2.9.5

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw

PATCH v2 5/10 PCI: layerscape: Fix some format issue of the code

In reply to Xiaowei Bao

Fix some format issue of the code in EP driver.

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -2
index be61d96..4e92a95 100644
@@ -62,7 +62,7 @@ static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
-				  enum pci_epc_irq_type type, u16 interrupt_num)
+				enum pci_epc_irq_type type, u16 interrupt_num)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
@@ -86,7 +86,7 @@ static const struct dw_pcie_ep_ops pcie_ep_ops = {
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
-					struct platform_device *pdev)
+				 struct platform_device *pdev)
 {
 	struct dw_pcie *pci = pcie->pci;
 	struct device *dev = pci->dev;
Signature · 1 line
2.9.5
Reviewed-by on v2 5/10
#11 lore raw

Re: [PATCH v2 05/10] PCI: layerscape: Fix some format issue of the code

Quoted 3 lines · Xiaowei Bao

Fix some format issue of the code in EP driver.

Quoted 32 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -2
index be61d96..4e92a95 100644
@@ -62,7 +62,7 @@ static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
-				  enum pci_epc_irq_type type, u16 interrupt_num)
+				enum pci_epc_irq_type type, u16 interrupt_num)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
@@ -86,7 +86,7 @@ static const struct dw_pcie_ep_ops pcie_ep_ops = {
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
-					struct platform_device *pdev)
+				 struct platform_device *pdev)
 {
 	struct dw_pcie *pci = pcie->pci;
 	struct device *dev = pci->dev;
Signature · 1 line
2.9.5
#12 lore raw

RE: [PATCH v2 05/10] PCI: layerscape: Fix some format issue of the code

Quoted 17 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:45
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 05/10] PCI: layerscape: Fix some format issue of the code

Quoted 6 lines
Quoted 3 lines · Xiaowei Bao

Fix some format issue of the code in EP driver.

Thanks.

Quoted 35 lines
Quoted 35 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -3
index be61d96..4e92a95 100644
@@ -62,7 +62,7 @@ static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
-				  enum pci_epc_irq_type type, u16 interrupt_num)
+				enum pci_epc_irq_type type, u16 interrupt_num)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
@@ -86,7 +86,7 @@ static const struct dw_pcie_ep_ops pcie_ep_ops = {
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
-					struct platform_device *pdev)
+				 struct platform_device *pdev)
 {
 	struct dw_pcie *pci = pcie->pci;
 	struct device *dev = pci->dev;
--

2.9.5

#13 lore raw

PATCH v2 6/10 PCI: layerscape: Modify the way of getting capability with different PEX

In reply to Xiaowei Bao

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +19 -7
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id ls_pcie_ep_of_match[] = {
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)
 {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
@@ -118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
 
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	if (!pci)
 		return -ENOMEM;
 
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
Signature · 1 line
2.9.5
#14 lore raw

Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

Quoted 3 lines · Xiaowei Bao

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

please use different pci_epc_features table for different boards.

Thanks
Kishon

Quoted 87 lines

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +19 -7
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id ls_pcie_ep_of_match[] = {
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)
 {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
@@ -118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
 
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	if (!pci)
 		return -ENOMEM;
 
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
#15 lore raw

RE: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 17 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月22日 19:44
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 8 lines

Hi,

Quoted 3 lines · Xiaowei Bao

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

please use different pci_epc_features table for different boards.

Thanks, I think that it will be more flexible to dynamically get MSI or MSIX capability, Thus, we will not need to define the pci_epc_feature for different boards.

Quoted 95 lines

Thanks
Kishon

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id

Quoted 24 lines

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26
+++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id

ls_pcie_ep_of_match[] = {

Quoted 22 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -7
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*  ls_pcie_ep_get_features(struct
 dw_pcie_ep *ep)  {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)  {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id ls_pcie_ep_of_match[] = {

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -1
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, @@
-118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device

*pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
 	if (!pci)
 		return -ENOMEM;
 
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -0
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
#16 lore raw

Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

(Fixed Lorenzo's email address. All the patches in the series have wrong email id)

Quoted 19 lines · Xiaowei Bao
Quoted 19 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月22日 19:44
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

Quoted 8 lines
Quoted 6 lines · Xiaowei Bao
Quoted 3 lines

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

please use different pci_epc_features table for different boards.

Thanks, I think that it will be more flexible to dynamically get MSI or MSIX capability, Thus, we will not need to define the pci_epc_feature for different boards.

Is the restriction because you cannot have different compatible for different boards?

Thanks
Kishon

Quoted 93 lines
Quoted 93 lines

Thanks
Kishon

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id

Quoted 24 lines

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26
+++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id

ls_pcie_ep_of_match[] = {

Quoted 22 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -7
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*  ls_pcie_ep_get_features(struct
 dw_pcie_ep *ep)  {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)  {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id ls_pcie_ep_of_match[] = {

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -1
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, @@
-118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device

*pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
 	if (!pci)
 		return -ENOMEM;
 
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -0
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
Quoted 2 lines
Quoted 2 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev) · line 156

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	ret = ls_add_pcie_ep(pcie, pdev);

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#17 lore raw

RE: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 49 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月23日 11:40
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected] <[email protected]>; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

(Fixed Lorenzo's email address. All the patches in the series have wrong email id)

Quoted 7 lines · Xiaowei Bao
Quoted 7 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月22日 19:44
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo

Li

Quoted 17 lines
Quoted 17 lines

<[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

Quoted 3 lines · Xiaowei Bao

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

please use different pci_epc_features table for different boards.

Thanks, I think that it will be more flexible to dynamically get MSI or MSIX capability, Thus, we will not need to define the pci_epc_feature for

different boards.

Is the restriction because you cannot have different compatible for different boards?

Sorry, I am not very clear what your mean, I think even if I use the same compatible with different boards, each boards will enter the probe function, in there I will get the MSI or MSIX PCIe capability of the current controller in this board. Why do I need to define the pci_epc_feature for different boards?

Quoted 102 lines

Thanks
Kishon

Quoted 72 lines
Quoted 72 lines

Thanks
Kishon

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id

Quoted 24 lines

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26
+++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id

ls_pcie_ep_of_match[] = {

Quoted 31 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -7
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)  {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)  {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
Quoted 3 lines

@@
-118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device

*pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
 	if (!pci)
 		return -ENOMEM;
 
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 17 lines
Quoted 17 lines

"regs");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -0
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
#18 lore raw

Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 52 lines · Xiaowei Bao
Quoted 52 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月23日 11:40
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected] <[email protected]>; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

(Fixed Lorenzo's email address. All the patches in the series have wrong email id)

Quoted 7 lines · Xiaowei Bao
Quoted 7 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月22日 19:44
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo

Li

Quoted 20 lines
Quoted 10 lines

<[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 8 lines

Hi,

Quoted 3 lines · Xiaowei Bao

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

please use different pci_epc_features table for different boards.

Thanks, I think that it will be more flexible to dynamically get MSI or MSIX capability, Thus, we will not need to define the pci_epc_feature for

Quoted 8 lines
Quoted 4 lines

different boards.

Is the restriction because you cannot have different compatible for different boards?

Sorry, I am not very clear what your mean, I think even if I use the same compatible with different boards, each boards will enter the probe function, in there I will get the MSI or MSIX PCIe capability of the current controller in this board. Why do I need to define the pci_epc_feature for different boards?

At present you determine how to set the [msi,msix]_capable flags of pci_epc_features based on reading the function capabilities at probe time. Instead of doing this, is it possible that you can determine the flags based on the compatible type alone? For example, is the MSI/MSIX capability the same for all fsl,ls2088a-pcie-ep devices?

If it isn't *necessary* to probe for this information at probe time, then you could instead create a static pci_epc_features structure and assign it to something in your drvdata. This may provide some benefits.

The dw_pcie_ep_get_features function would then look like:

static const struct pci_epc_features*
ls_pcie_ep_get_features(struct dw_pcie_ep *ep)

{
	struct dw_pcie *pci = to_dw_pcie_from_pp(ep);
	struct ls_pcie_ep *pcie = dev_get_drvdata(pci->dev);
	return pcie->epc_features;
}

This also means you can revert "[v3,03/11] PCI: designware-ep: Move the".

Is this what you had in mind Kishon?

Thanks,

Andrew Murray

Quoted 102 lines
Quoted 102 lines

Thanks
Kishon

Quoted 72 lines
Quoted 72 lines

Thanks
Kishon

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id

Quoted 24 lines

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26
+++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id

ls_pcie_ep_of_match[] = {

Quoted 31 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -7
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)  {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)  {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
Quoted 3 lines

@@
-118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device

*pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
 	if (!pci)
 		return -ENOMEM;
 
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 17 lines
Quoted 17 lines

"regs");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -0
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
#19 lore raw

RE: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 105 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年9月2日 21:37
To: Xiaowei Bao <[email protected]>
Cc: Kishon Vijay Abraham I <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected] <[email protected]>; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 57 lines · Xiaowei Bao
Quoted 57 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月23日 11:40
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo robh+Li
<[email protected]>; [email protected] <[email protected]>; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Hi,

(Fixed Lorenzo's email address. All the patches in the series have wrong email
id)

Quoted 8 lines · Xiaowei Bao
Quoted 8 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: 2019年8月22日 19:44
To: Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; robh+Leo

Li

Quoted 22 lines
Quoted 11 lines

<[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 06/10] PCI: layerscape: Modify the way of getting capability with different PEX

Quoted 8 lines

Hi,

Quoted 3 lines · Xiaowei Bao

The different PCIe controller in one board may be have different capability of MSI or MSIX, so change the way of getting the MSI capability, make it more flexible.

please use different pci_epc_features table for different boards.

Thanks, I think that it will be more flexible to dynamically get MSI or MSIX capability, Thus, we will not need to define the pci_epc_feature for

Quoted 8 lines
Quoted 4 lines

different boards.

Is the restriction because you cannot have different compatible for different boards?

Sorry, I am not very clear what your mean, I think even if I use the same compatible with different boards, each boards will enter the probe function, in there I will get the MSI or MSIX PCIe capability of the current controller in this board. Why do I need to define the

pci_epc_feature for different boards?

At present you determine how to set the [msi,msix]_capable flags of pci_epc_features based on reading the function capabilities at probe time. Instead of doing this, is it possible that you can determine the flags based on the compatible type alone? For example, is the MSI/MSIX capability the same for all fsl,ls2088a-pcie-ep devices?

If it isn't *necessary* to probe for this information at probe time, then you could instead create a static pci_epc_features structure and assign it to something in your drvdata. This may provide some benefits.

The dw_pcie_ep_get_features function would then look like:

static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) {
	struct dw_pcie *pci = to_dw_pcie_from_pp(ep);
	struct ls_pcie_ep *pcie = dev_get_drvdata(pci->dev);
	return pcie->epc_features;
}
Quoted 3 lines

This also means you can revert "[v3,03/11] PCI: designware-ep: Move the".

Is this what you had in mind Kishon?

Yes, I consider this scheme, but there is a issue with my board, e.g. my board have three PCIE controllers, but only two controllers support MSI, I can't said that the board support the MSI feature, so I only set the msi_capabitily by reading the MSI capability struct the current PCIE controller, I am also very entangled in this issue. so, do you have better advice? Thanks a lot.

Thanks
Xiaowei

Quoted 108 lines

Thanks,

Andrew Murray

Quoted 79 lines
Quoted 79 lines

Thanks
Kishon

Quoted 75 lines
Quoted 75 lines

Thanks
Kishon

drivers/pci/controller/dwc/pci-layerscape-ep.c static const struct of_device_id

Quoted 24 lines

---
v2:
- Remove the repeated assignment code.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 26
+++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
index 4e92a95..8461f62 100644
@@ -22,6 +22,7 @@
 
 struct ls_pcie_ep {
 	struct dw_pcie		*pci;
+	struct pci_epc_features	*ls_epc;
 };
 
 #define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
@@ -40,25 +41,26 @@ static const struct of_device_id

ls_pcie_ep_of_match[] = {

Quoted 31 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -7
 	{ },
 };
 
-static const struct pci_epc_features ls_pcie_epc_features = {
-	.linkup_notifier = false,
-	.msi_capable = true,
-	.msix_capable = false,
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)  {
-	return &ls_pcie_epc_features;
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+
+	return pcie->ls_epc;
 }
 
 static void ls_pcie_ep_init(struct dw_pcie_ep *ep)  {
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
 	enum pci_barno bar;
 
 	for (bar = BAR_0; bar <= BAR_5; bar++)
 		dw_pcie_ep_reset_bar(pci, bar);
+
+	pcie->ls_epc->msi_capable = ep->msi_cap ? true : false;
+	pcie->ls_epc->msix_capable = ep->msix_cap ? true : false;
 }
 
 static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8
Quoted 3 lines

func_no, @@
-118,6 +120,7 @@ static int __init ls_pcie_ep_probe(struct platform_device

*pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	struct device *dev = &pdev->dev;
 	struct dw_pcie *pci;
 	struct ls_pcie_ep *pcie;
+	struct pci_epc_features *ls_epc;
 	struct resource *dbi_base;
 	int ret;
@@ -129,6 +132,10 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!pci)
 		return -ENOMEM;
 
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 5 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	ls_epc = devm_kzalloc(dev, sizeof(*ls_epc), GFP_KERNEL);
+	if (!ls_epc)
+		return -ENOMEM;
+
 	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 2 lines
Quoted 2 lines

"regs");

Quoted 1 line
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	pci->dbi_base = devm_pci_remap_cfg_resource(dev,

dbi_base);

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (IS_ERR(pci->dbi_base))
@@ -139,6 +146,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -0
 	pci->ops = &ls_pcie_ep_ops;
 	pcie->pci = pci;
 
+	ls_epc->linkup_notifier = false,
+	ls_epc->bar_fixed_64bit = (1 << BAR_2) | (1 << BAR_4),
+
+	pcie->ls_epc = ls_epc;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
#20 lore raw

PATCH v2 7/10 PCI: layerscape: Modify the MSIX to the doorbell way

In reply to Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
index 8461f62..7ca5fe8 100644
@@ -74,7 +74,8 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
 	case PCI_EPC_IRQ_MSI:
 		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
 	case PCI_EPC_IRQ_MSIX:
-		return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+		return dw_pcie_ep_raise_msix_irq_doorbell(ep, func_no,
+							  interrupt_num);
 	default:
 		dev_err(pci->dev, "UNKNOWN IRQ type\n");
 		return -EINVAL;
Signature · 1 line
2.9.5
#21 lore raw

Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

Thanks,

Andrew Murray

Quoted 25 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
index 8461f62..7ca5fe8 100644
@@ -74,7 +74,8 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
 	case PCI_EPC_IRQ_MSI:
 		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
 	case PCI_EPC_IRQ_MSIX:
-		return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+		return dw_pcie_ep_raise_msix_irq_doorbell(ep, func_no,
+							  interrupt_num);
 	default:
 		dev_err(pci->dev, "UNKNOWN IRQ type\n");
 		return -EINVAL;
Signature · 1 line
2.9.5
#22 lore raw

RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 22 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

Quoted 5 lines

I have no problems with this patch, however...

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Quoted 32 lines

Thanks,

Andrew Murray

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep,

Quoted 14 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
index 8461f62..7ca5fe8 100644
@@ -74,7 +74,8 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep,

u8 func_no,

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -2
 	case PCI_EPC_IRQ_MSI:
 		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
 	case PCI_EPC_IRQ_MSIX:
-		return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+		return dw_pcie_ep_raise_msix_irq_doorbell(ep, func_no,
+							  interrupt_num);
 	default:
 		dev_err(pci->dev, "UNKNOWN IRQ type\n");
 		return -EINVAL;
--

2.9.5

#23 lore raw

Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 24 lines · Xiaowei Bao
Quoted 24 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Quoted 8 lines
Quoted 3 lines

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Given that dw_pcie_ep_raise_msix_irq is used by pcie-designware-plat.c we can assume this function at least works for it's use case.

Please update the commit message - It would be helpful to suggest that dw_pcie_ep_raise_msix_irq was never called in the exisitng driver because msix_capable was always set to false.

Thanks,

Andrew Murray

Quoted 33 lines
Quoted 33 lines

Thanks,

Andrew Murray

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep,

Quoted 14 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
index 8461f62..7ca5fe8 100644
@@ -74,7 +74,8 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep,

u8 func_no,

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -2
 	case PCI_EPC_IRQ_MSI:
 		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
 	case PCI_EPC_IRQ_MSIX:
-		return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+		return dw_pcie_ep_raise_msix_irq_doorbell(ep, func_no,
+							  interrupt_num);
 	default:
 		dev_err(pci->dev, "UNKNOWN IRQ type\n");
 		return -EINVAL;
--

2.9.5

#24 lore raw

RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 62 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月27日 21:25
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 9 lines · Xiaowei Bao
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 13 lines
Quoted 13 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

Quoted 5 lines
Quoted 5 lines

I have no problems with this patch, however...

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more

efficient?

Quoted 5 lines

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX

feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Quoted 6 lines

Given that dw_pcie_ep_raise_msix_irq is used by pcie-designware-plat.c we can assume this function at least works for it's use case.

Please update the commit message - It would be helpful to suggest that dw_pcie_ep_raise_msix_irq was never called in the exisitng driver because msix_capable was always set to false.

Agree, this is much clearer, I will modify the commit message in the next version patch, thanks a lot.

Quoted 40 lines

Thanks,

Andrew Murray

Quoted 22 lines
Quoted 22 lines

Thanks,

Andrew Murray

Quoted 14 lines

---
v2:
- No change.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
index 8461f62..7ca5fe8 100644

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct · line 74

Quoted 1 line
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
@@ -74,7 +74,8 @@ static int ls_pcie_ep_raise_irq(struct
 dw_pcie_ep *ep,

u8 func_no,

Quoted 4 lines
Quoted 4 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	case PCI_EPC_IRQ_MSI:
 		return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
 	case PCI_EPC_IRQ_MSIX:
-		return dw_pcie_ep_raise_msix_irq(ep, func_no,

interrupt_num);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -0
+		return dw_pcie_ep_raise_msix_irq_doorbell(ep, func_no,
+							  interrupt_num);
 	default:
 		dev_err(pci->dev, "UNKNOWN IRQ type\n");

return -EINVAL;
--
2.9.5

#25 lore raw

Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

In reply to Andrew Murray

Gustavo,

Quoted 34 lines · Andrew Murray
Quoted 24 lines · Xiaowei Bao
Quoted 24 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Quoted 8 lines
Quoted 3 lines

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Quoted 7 lines

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

Thanks
Kishon

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#26 lore raw

Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 41 lines · Kishon Vijay Abraham I

Gustavo,

Quoted 38 lines · Andrew Murray
Quoted 24 lines · Xiaowei Bao
Quoted 24 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Quoted 8 lines
Quoted 3 lines

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Quoted 6 lines
Quoted 3 lines

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

This question needs an answer.

Thanks,
Lorenzo

#27 lore raw

RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 67 lines

-----Original Message-----
From: Lorenzo Pieralisi <[email protected]>
Sent: 2019年11月5日 20:38
To: Kishon Vijay Abraham I <[email protected]>
Cc: Andrew Murray <[email protected]>; Xiaowei Bao <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 11 lines · Kishon Vijay Abraham I

Gustavo,

Quoted 8 lines · Andrew Murray
Quoted 7 lines · Xiaowei Bao
Quoted 7 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

[email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Lian <[email protected]>; Mingkai Hu <[email protected]>;

Roy

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I have no problems with this patch, however...

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is

more efficient?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX

feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Quoted 5 lines
Quoted 5 lines

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

This question needs an answer.

This question have answered by Gustavo in "[PATCH v3 08/11] PCI: layerscape:
Modify the MSIX to the doorbell mode", please refer to the comments, due to add a new patch for this sets of patch, this patch number changed from 07/10 of v2 to 08/11 of v3, sorry for causing your confuse.

Thanks
Xiaowei

Quoted 3 lines

Thanks,
Lorenzo

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#28 lore raw

RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

In reply to Kishon Vijay Abraham I

On Thu, Aug 29, 2019 at 6:13:18, Kishon Vijay Abraham I <[email protected]> wrote:

Hi, this email slip away from my attention...

Quoted 41 lines

Gustavo,

Quoted 38 lines · Andrew Murray
Quoted 24 lines · Xiaowei Bao
Quoted 24 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Quoted 8 lines
Quoted 3 lines

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Quoted 6 lines
Quoted 3 lines

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

When I implemented the dw_pcie_ep_raise_msix_irq(), the implementation was working quite fine on DesignWare solution. Otherwise, I wouldn't submit it to the kernel.
From what I have seen and if I recall well, Xiaowei implementation was done having PF's configurated on his solution, which is a configuration that I don't have in my solution, I believe this could be the missing piece that differs between our 2 implementations.

Since patch submission into the kernel related to msix feature on pcitest tool, I didn't touch or re-tested the msix feature by lack of time (other projects requires my full attention for now). However is on my roadmap to came back to add some other features on DesignWare eDMA driver and I can do at that time some tests to see if the dw_pcie_ep_raise_msix_irq_doorbell() is compatible or not with my solution. If so, I can do some patch to simplify and use the dw_pcie_ep_raise_msix_irq_doorbell() if it still works as expected like on dw_pcie_ep_raise_msix_irq(). Agree?

Gustavo

Quoted 3 lines

Thanks
Kishon

#29 lore raw

RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 86 lines

-----Original Message-----
From: Gustavo Pimentel <[email protected]>
Sent: 2019年11月6日 17:40
To: Kishon Vijay Abraham I <[email protected]>; Andrew Murray <[email protected]>; Xiaowei Bao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

On Thu, Aug 29, 2019 at 6:13:18, Kishon Vijay Abraham I <[email protected]> wrote:

Hi, this email slip away from my attention...

Quoted 11 lines

Gustavo,

Quoted 8 lines · Andrew Murray
Quoted 7 lines · Xiaowei Bao
Quoted 7 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected];

[email protected];

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

[email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Lian <[email protected]>; Mingkai Hu <[email protected]>;

Roy

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I have no problems with this patch, however...

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is

more efficient?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX

feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Quoted 11 lines
Quoted 8 lines

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

When I implemented the dw_pcie_ep_raise_msix_irq(), the implementation was working quite fine on DesignWare solution. Otherwise, I wouldn't submit it to the kernel.
From what I have seen and if I recall well, Xiaowei implementation was done having PF's configurated on his solution, which is a configuration that I don't have in my solution, I believe this could be the missing piece that differs between our 2 implementations.

Quoted 10 lines

Since patch submission into the kernel related to msix feature on pcitest tool, I didn't touch or re-tested the msix feature by lack of time (other projects requires my full attention for now). However is on my roadmap to came back to add some other features on DesignWare eDMA driver and I can do at that time some tests to see if the
dw_pcie_ep_raise_msix_irq_doorbell() is compatible or not with my solution. If so, I can do some patch to simplify and use the dw_pcie_ep_raise_msix_irq_doorbell() if it still works as expected like on dw_pcie_ep_raise_msix_irq(). Agree?

Thanks Gustavo, it looks well for me.

Thanks
Xiaowei

Quoted 6 lines

Gustavo

Quoted 3 lines

Thanks
Kishon

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#30 lore raw

Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

In reply to Gustavo Pimentel

Gustavo,

Quoted 53 lines · Gustavo Pimentel

On Thu, Aug 29, 2019 at 6:13:18, Kishon Vijay Abraham I <[email protected]> wrote:

Hi, this email slip away from my attention...

Quoted 41 lines

Gustavo,

Quoted 38 lines · Andrew Murray
Quoted 24 lines · Xiaowei Bao
Quoted 24 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Quoted 8 lines
Quoted 3 lines

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Quoted 6 lines
Quoted 3 lines

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

Quoted 7 lines

When I implemented the dw_pcie_ep_raise_msix_irq(), the implementation was working quite fine on DesignWare solution. Otherwise, I wouldn't submit it to the kernel.
From what I have seen and if I recall well, Xiaowei implementation was done having PF's configurated on his solution, which is a configuration that I don't have in my solution, I believe this could be the missing piece that differs between our 2 implementations.

I haven't debugged the issue yet but in my understanding the MSI-X table should be in the memory (DDR) of EP system. This table will be populated by RC while configuring MSI-X (with msg address and msg data). The EP will use the populated msg address and msg data for raising MSI-X interrupt.

From the dw_pcie_ep_raise_msix_irq() (copied below), nowhere the MSI-X table is being read from the memory of EP system. I've given my comments below.

int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
u16 interrupt_num)

{
	.
	.
	reg = PCI_BASE_ADDRESS_0 + (4 * bir);
	bar_addr_upper = 0;
	bar_addr_lower = dw_pcie_readl_dbi(pci, reg);

BAR register will hold the "PCI address" programmed by the host. So "bar_addr_lower" will have PCI address.

	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);

	tbl_addr = ((u64) bar_addr_upper) << 32 | bar_addr_lower;

The "tbl_addr" now has the PCI address programmed by the host.

	tbl_addr += (tbl_offset + ((interrupt_num - 1) * PCI_MSIX_ENTRY_SIZE));
	tbl_addr &= PCI_BASE_ADDRESS_MEM_MASK;

	msix_tbl = ioremap_nocache(ep->phys_base + tbl_addr,
				   PCI_MSIX_ENTRY_SIZE);

"ep->phys_base" will have EPs outbound memory address and "tbl_addr" will have PCI address. So msix_tbl points to the EPs outbound memory region.

	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);

Here an access to the EP outbound region is made (and the transaction will be based on ATU configuration).
The message address should ideally be obtained from the MSI-X table present in the EP system. There need not be any access to the OB region for getting data from MSI-X table.

	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);

All this should be obtained from the memory of EP.

	.
	.
}

I'm not sure how this worked for you.

Thanks
Kishon

Quoted 11 lines

Since patch submission into the kernel related to msix feature on pcitest tool, I didn't touch or re-tested the msix feature by lack of time (other projects requires my full attention for now). However is on my roadmap to came back to add some other features on DesignWare eDMA driver and I can do at that time some tests to see if the dw_pcie_ep_raise_msix_irq_doorbell() is compatible or not with my solution. If so, I can do some patch to simplify and use the dw_pcie_ep_raise_msix_irq_doorbell() if it still works as expected like on dw_pcie_ep_raise_msix_irq(). Agree?

Quoted 7 lines

Gustavo

Quoted 3 lines

Thanks
Kishon

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#31 lore raw

RE: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

On Wed, Nov 6, 2019 at 13:39:5, Kishon Vijay Abraham I <[email protected]> wrote:

Hi Kishon,

Quoted 64 lines

Gustavo,

Quoted 53 lines · Gustavo Pimentel

On Thu, Aug 29, 2019 at 6:13:18, Kishon Vijay Abraham I <[email protected]> wrote:

Hi, this email slip away from my attention...

Quoted 41 lines

Gustavo,

Quoted 38 lines · Andrew Murray
Quoted 24 lines · Xiaowei Bao
Quoted 24 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:58
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 07/10] PCI: layerscape: Modify the MSIX to the doorbell way

Quoted 3 lines · Xiaowei Bao

The layerscape platform use the doorbell way to trigger MSIX interrupt in EP mode.

I have no problems with this patch, however...

Quoted 8 lines
Quoted 3 lines

Are you able to add to this message a reason for why you are making this change? Did dw_pcie_ep_raise_msix_irq not work when func_no != 0? Or did it work yet dw_pcie_ep_raise_msix_irq_doorbell is more efficient?

The fact is that, this driver is verified in ls1046a platform of NXP before, and ls1046a don't support MSIX feature, so I set the msix_capable of pci_epc_features struct is false, but in other platform, e.g. ls1088a, it support the MSIX feature, I verified the MSIX feature in ls1088a, it is not OK, so I changed to another way. Thanks.

Right, so the existing pci-layerscape-ep.c driver never supported MSIX yet it erroneously had a switch case statement to call dw_pcie_ep_raise_msix_irq which would never get used.

Quoted 6 lines
Quoted 3 lines

Now that we're adding a platform with MSIX support the existing dw_pcie_ep_raise_msix_irq doesn't work (for this platform) so we are adding a different method.

Gustavo, can you confirm dw_pcie_ep_raise_msix_irq() works for designware as it didn't work for both me and Xiaowei?

Quoted 7 lines

When I implemented the dw_pcie_ep_raise_msix_irq(), the implementation was working quite fine on DesignWare solution. Otherwise, I wouldn't submit it to the kernel.
From what I have seen and if I recall well, Xiaowei implementation was done having PF's configurated on his solution, which is a configuration that I don't have in my solution, I believe this could be the missing piece that differs between our 2 implementations.

Quoted 4 lines

I haven't debugged the issue yet but in my understanding the MSI-X table should be in the memory (DDR) of EP system. This table will be populated by RC while configuring MSI-X (with msg address and msg data). The EP will use the populated msg address and msg data for raising MSI-X interrupt.

Right.

Quoted 48 lines

From the dw_pcie_ep_raise_msix_irq() (copied below), nowhere the MSI-X table is being read from the memory of EP system. I've given my comments below.

int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no,
u16 interrupt_num)

{
	.
	.
	reg = PCI_BASE_ADDRESS_0 + (4 * bir);
	bar_addr_upper = 0;
	bar_addr_lower = dw_pcie_readl_dbi(pci, reg);

BAR register will hold the "PCI address" programmed by the host. So "bar_addr_lower" will have PCI address.

	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);

	tbl_addr = ((u64) bar_addr_upper) << 32 | bar_addr_lower;

The "tbl_addr" now has the PCI address programmed by the host.

	tbl_addr += (tbl_offset + ((interrupt_num - 1) * PCI_MSIX_ENTRY_SIZE));
	tbl_addr &= PCI_BASE_ADDRESS_MEM_MASK;

	msix_tbl = ioremap_nocache(ep->phys_base + tbl_addr,
				   PCI_MSIX_ENTRY_SIZE);

"ep->phys_base" will have EPs outbound memory address and "tbl_addr" will have PCI address. So msix_tbl points to the EPs outbound memory region.

	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);

Here an access to the EP outbound region is made (and the transaction will be based on ATU configuration).
The message address should ideally be obtained from the MSI-X table present in the EP system. There need not be any access to the OB region for getting data from MSI-X table.

	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);
Quoted 6 lines

All this should be obtained from the memory of EP.

	.
	.
}

I'm not sure how this worked for you.

Hum, it was a very time ago that I implemented this. I've to debug it to give you an accurate answer.
However, it very likely that my DesignWare prototype solution might have some peculiarities that could allow this type of access. At the time, nobody had the msix feature enabled that was working with pcitest EP in their SOCs that could be used to test my implementation against, at least that I know of.

As soon as I get back to work on PCI, I will retest this with the other function, if it works I'll make a patch to use that function instead, I'm assuming that function is working for other SOCs, right?

Gustavo

Quoted 22 lines

Thanks
Kishon

Quoted 18 lines

Since patch submission into the kernel related to msix feature on pcitest tool, I didn't touch or re-tested the msix feature by lack of time (other projects requires my full attention for now). However is on my roadmap to came back to add some other features on DesignWare eDMA driver and I can do at that time some tests to see if the dw_pcie_ep_raise_msix_irq_doorbell() is compatible or not with my solution. If so, I can do some patch to simplify and use the dw_pcie_ep_raise_msix_irq_doorbell() if it still works as expected like on dw_pcie_ep_raise_msix_irq(). Agree?

Gustavo

Quoted 3 lines

Thanks
Kishon

#32 lore raw

PATCH v2 8/10 PCI: layerscape: Add EP mode support for ls1088a and ls2088a

In reply to Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76 ++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +58 -18
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata;
+};
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)
 {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,
 };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)
 {
@@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
 	}
 }
 
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select,
+};
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
@@ -98,7 +134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space");
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
 	ls_epc->linkup_notifier = false,
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
Signature · 1 line
2.9.5
#33 lore raw

Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Quoted 56 lines
 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76 ++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +15 -11
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata;
+};
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)
 {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,
 };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*
 ls_pcie_ep_get_features(struct dw_pcie_ep *ep)
 {
@@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
 	}
 }
 
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +10 -0
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain the test.

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset);
return pcie->drvdata->func_offset * func_no;

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

Thanks,

Andrew Murray

Quoted 72 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +33 -7
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select,
+};
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
@@ -98,7 +134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space");
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
 	ls_epc->linkup_notifier = false,
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct platform_device *pdev)
 
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
Signature · 1 line
2.9.5
#34 lore raw

RE: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 22 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 4 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

Quoted 6 lines
Quoted 4 lines

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Yes, but I don't know how to comments, ^_^

Quoted 61 lines
Quoted 61 lines

 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)  {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*  ls_pcie_ep_get_features(struct

dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -1
 	}
 }
 
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment
above the test might be helpful to explain the test.

Yes, I have not find the PCI_HEADER_TYPE_MULTIDEVICE define. OK, I will add The comments in next version patch.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

OK, thanks

Quoted 6 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

Thanks a lot, this looks better.

Quoted 4 lines

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

got it, thanks.

Quoted 81 lines

Thanks,

Andrew Murray

Quoted 25 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +21 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@ -98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 14 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
 	ls_epc->linkup_notifier = false,

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 189

Quoted 5 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct
 platform_device *pdev)
 
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

#35 lore raw

Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Le 24/08/2019 à 02:18, Xiaowei Bao a écrit :

Quoted 22 lines
Quoted 22 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 4 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Yes, but I don't know how to comments, ^_^

As far as I can see, in the previous version of the series (https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=125315&state=*), the 8/10 was something completely different, and I can't find any other patch in the series that could have been the v1 of this patch.

Christophe

Quoted 173 lines
Quoted 62 lines
Quoted 62 lines


  drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
  1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
  #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
  };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
  static int ls_pcie_establish_link(struct dw_pcie *pci)  {
  	return 0;
  }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
  	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
  static const struct pci_epc_features*  ls_pcie_ep_get_features(struct

dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
}
}

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -1
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment
above the test might be helpful to explain the test.

Yes, I have not find the PCI_HEADER_TYPE_MULTIDEVICE define. OK, I will add The comments in next version patch.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

OK, thanks

Quoted 6 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

Thanks a lot, this looks better.

Quoted 4 lines

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

got it, thanks.

Quoted 77 lines

Thanks,

Andrew Murray

Quoted 25 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +21 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
  	.ep_init = ls_pcie_ep_init,
  	.raise_irq = ls_pcie_ep_raise_irq,
  	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
  };

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 
  static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@ -98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
  	int ret;
 
  	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines

if (!res)

drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
  	if (!ls_epc)
  		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 14 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
  	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
  	pcie->pci = pci;
 
  	ls_epc->linkup_notifier = false,

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 189

Quoted 5 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct
 platform_device *pdev)
 
  	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
  	platform_set_drvdata(pdev, pcie);
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#36 lore raw

RE: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 53 lines

-----Original Message-----
From: christophe leroy <[email protected]>
Sent: 2019年8月24日 14:45
To: Xiaowei Bao <[email protected]>; Andrew Murray <[email protected]>
Cc: [email protected]; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; Mingkai Hu <[email protected]>; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Le 24/08/2019 à 02:18, Xiaowei Bao a écrit :

Quoted 9 lines
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 13 lines
Quoted 13 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 4 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Yes, but I don't know how to comments, ^_^

Quoted 9 lines

As far as I can see, in the previous version of the series
(https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
work.ozlabs.org%2Fproject%2Flinuxppc-dev%2Flist%2F%3Fseries%3D125315 %26state%3D*&amp;data=02%7C01%7Cxiaowei.bao%40nxp.com%7C1befe9 a67c8046f9535e08d7285eaab6%7C686ea1d3bc2b4c6fa92cd99c5c301635% 7C0%7C0%7C637022259387139020&amp;sdata=p4wbycd04Z7qRUfAoZtwc UP7pR%2FuA3%2FjVcWMz6YyQVQ%3D&amp;reserved=0),
the 8/10 was something completely different, and I can't find any other patch in the series that could have been the v1 of this patch.

Thanks, I will correct it to v1 in next version patch.

Quoted 177 lines

Christophe

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines


  drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
  1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
  #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
  };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
  static int ls_pcie_establish_link(struct dw_pcie *pci)  {
  	return 0;
  }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
  	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
  static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
}
}

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -1
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain

the test.

Quoted 65 lines

Yes, I have not find the PCI_HEADER_TYPE_MULTIDEVICE define. OK, I will add The comments in next version patch.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

OK, thanks

Quoted 6 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

Thanks a lot, this looks better.

Quoted 4 lines

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

got it, thanks.

Quoted 39 lines

Thanks,

Andrew Murray

Quoted 23 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +19 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
  	.ep_init = ls_pcie_ep_init,
  	.raise_irq = ls_pcie_ep_raise_irq,
  	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
  };

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 
  static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@ -98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
  	int ret;
 
  	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines

if (!res)

drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
  	if (!ls_epc)
  		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 13 lines
Quoted 13 lines

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
  	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
  	pcie->pci = pci;
 
Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 189

Quoted 7 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
  	ls_epc->linkup_notifier = false,
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct
 platform_device *pdev)
 
  	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 9 lines
Quoted 9 lines

"regs");

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
  	platform_set_drvdata(pdev, pcie);
 
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.
avast.com%2Fantivirus&amp;data=02%7C01%7Cxiaowei.bao%40nxp.com%7 C1befe9a67c8046f9535e08d7285eaab6%7C686ea1d3bc2b4c6fa92cd99c5c3 01635%7C0%7C0%7C637022259387139020&amp;sdata=JAYds7X%2FHVxgtrg e%2F%2FvnP84zdb2yReXcctQUiSLC11I%3D&amp;reserved=0

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#37 lore raw

Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 63 lines · Xiaowei Bao
Quoted 53 lines

-----Original Message-----
From: christophe leroy <[email protected]>
Sent: 2019年8月24日 14:45
To: Xiaowei Bao <[email protected]>; Andrew Murray <[email protected]>
Cc: [email protected]; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; Mingkai Hu <[email protected]>; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Le 24/08/2019 à 02:18, Xiaowei Bao a écrit :

Quoted 9 lines
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 13 lines
Quoted 13 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 4 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Yes, but I don't know how to comments, ^_^

Quoted 9 lines

As far as I can see, in the previous version of the series
(https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
work.ozlabs.org%2Fproject%2Flinuxppc-dev%2Flist%2F%3Fseries%3D125315 %26state%3D*&amp;data=02%7C01%7Cxiaowei.bao%40nxp.com%7C1befe9 a67c8046f9535e08d7285eaab6%7C686ea1d3bc2b4c6fa92cd99c5c301635% 7C0%7C0%7C637022259387139020&amp;sdata=p4wbycd04Z7qRUfAoZtwc UP7pR%2FuA3%2FjVcWMz6YyQVQ%3D&amp;reserved=0),
the 8/10 was something completely different, and I can't find any other patch in the series that could have been the v1 of this patch.

Quoted 1 line

Thanks, I will correct it to v1 in next version patch.

I think you numbered it correctly (so please leave it as v2, referring to the patch series revision) - I got confused trying to find a previous version of this patch.

Perhaps in the future when new patches are introduced in a series you can indicate that in the description patch revision history (e.g. introduced in v2).

Thanks,

Andrew Murray

Quoted 192 lines
Quoted 191 lines

Christophe

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines


  drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
  1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
  #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
  };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
  static int ls_pcie_establish_link(struct dw_pcie *pci)  {
  	return 0;
  }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
  	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
  static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
}
}

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -1
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain

the test.

Quoted 65 lines

Yes, I have not find the PCI_HEADER_TYPE_MULTIDEVICE define. OK, I will add The comments in next version patch.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

OK, thanks

Quoted 6 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

Thanks a lot, this looks better.

Quoted 4 lines

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

got it, thanks.

Quoted 39 lines

Thanks,

Andrew Murray

Quoted 23 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +19 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
  	.ep_init = ls_pcie_ep_init,
  	.raise_irq = ls_pcie_ep_raise_irq,
  	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
  };

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 
  static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@ -98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
  	int ret;
 
  	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines

if (!res)

drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
  	if (!ls_epc)
  		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 13 lines
Quoted 13 lines

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
  	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
  	pcie->pci = pci;
 
Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 189

Quoted 7 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
  	ls_epc->linkup_notifier = false,
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct
 platform_device *pdev)
 
  	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 9 lines
Quoted 9 lines

"regs");

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
  	platform_set_drvdata(pdev, pcie);
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.
avast.com%2Fantivirus&amp;data=02%7C01%7Cxiaowei.bao%40nxp.com%7 C1befe9a67c8046f9535e08d7285eaab6%7C686ea1d3bc2b4c6fa92cd99c5c3 01635%7C0%7C0%7C637022259387139020&amp;sdata=JAYds7X%2FHVxgtrg e%2F%2FvnP84zdb2yReXcctQUiSLC11I%3D&amp;reserved=0

#38 lore raw

RE: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 90 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月27日 22:49
To: Xiaowei Bao <[email protected]>
Cc: christophe leroy <[email protected]>; [email protected]; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; Mingkai Hu <[email protected]>; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 11 lines · Xiaowei Bao
Quoted 11 lines

-----Original Message-----
From: christophe leroy <[email protected]>
Sent: 2019年8月24日 14:45
To: Xiaowei Bao <[email protected]>; Andrew Murray <[email protected]>
Cc: [email protected]; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 41 lines
Quoted 41 lines

Lian <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; Mingkai Hu <[email protected]>; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Le 24/08/2019 à 02:18, Xiaowei Bao a écrit :

Quoted 10 lines
Quoted 10 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 19 lines
Quoted 19 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Was there a v1 of this patch?

Yes, but I don't know how to comments, ^_^

As far as I can see, in the previous version of the series
(https://patch

work.ozlabs.org%2Fproject%2Flinuxppc-dev%2Flist%2F%3Fseries%3D125315

Quoted 1 line
Quoted 1 line

%26state%3D*&amp;data=02%7C01%7Cxiaowei.bao%40nxp.com%7C1b

efe9

Quoted 1 line
Quoted 1 line

a67c8046f9535e08d7285eaab6%7C686ea1d3bc2b4c6fa92cd99c5c301635%

Quoted 1 line
Quoted 1 line

7C0%7C0%7C637022259387139020&amp;sdata=p4wbycd04Z7qRUfAoZtwc

Quoted 4 lines
Quoted 3 lines

UP7pR%2FuA3%2FjVcWMz6YyQVQ%3D&amp;reserved=0),
the 8/10 was something completely different, and I can't find any other patch in the series that could have been the v1 of this patch.

Quoted 8 lines
Quoted 1 line

Thanks, I will correct it to v1 in next version patch.

I think you numbered it correctly (so please leave it as v2, referring to the patch series revision) - I got confused trying to find a previous version of this patch.

Perhaps in the future when new patches are introduced in a series you can indicate that in the description patch revision history (e.g. introduced in v2).

OK, thanks for your help, I will update it in the next version patch.

Thanks
Xiaowei

Quoted 206 lines

Thanks,

Andrew Murray

Quoted 45 lines
Quoted 45 lines

Christophe

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines


  drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
  1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -5
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
  #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
  };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
  static int ls_pcie_establish_link(struct dw_pcie *pci)  {
  	return 0;
  }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
  	.start_link = ls_pcie_establish_link,  };
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -5
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
  static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8

func_no,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 5 lines
  	}
  }
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -1
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep

*ep,

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +12 -0
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain

Quoted 8 lines
Quoted 8 lines

the test.

Quoted 7 lines

Yes, I have not find the PCI_HEADER_TYPE_MULTIDEVICE define. OK, I will add The comments in next version patch.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test

above.

Quoted 54 lines
Quoted 54 lines
Quoted 54 lines

OK, thanks

Quoted 6 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

Thanks a lot, this looks better.

Quoted 4 lines

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

got it, thanks.

Quoted 35 lines

Thanks,

Andrew Murray

Quoted 30 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +21 -1
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
  	.ep_init = ls_pcie_ep_init,
  	.raise_irq = ls_pcie_ep_raise_irq,
  	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
  };
 
  static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@
-98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep
+*pcie,
  	int ret;
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,

Quoted 5 lines
  	ep = &pci->ep;
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -1
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
  	res = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 38 lines
Quoted 38 lines
Quoted 8 lines
Quoted 8 lines

"addr_space");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines

if (!res)

drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
  	if (!ls_epc)
  		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 13 lines
Quoted 13 lines

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
  	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
  	pcie->pci = pci;
 
Quoted 6 lines
Quoted 6 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 6 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
  	ls_epc->linkup_notifier = false, @@ -152,6 +185,13 @@ static

int __init ls_pcie_ep_probe(struct platform_device *pdev)

  	pcie->ls_epc = ls_epc;
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
+	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 9 lines
Quoted 9 lines

"regs");

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
  	platform_set_drvdata(pdev, pcie);
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.

avast.com%2Fantivirus&amp;data=02%7C01%7Cxiaowei.bao%40nxp.com%7

Quoted 1 line
Quoted 1 line

C1befe9a67c8046f9535e08d7285eaab6%7C686ea1d3bc2b4c6fa92cd99c5c3

Quoted 1 line
Quoted 1 line

01635%7C0%7C0%7C637022259387139020&amp;sdata=JAYds7X%2FHVxgtrg

Quoted 2 lines
Quoted 1 line

e%2F%2FvnP84zdb2yReXcctQUiSLC11I%3D&amp;reserved=0

#39 lore raw

RE: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

In reply to Andrew Murray
Quoted 89 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Quoted 60 lines
 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)  {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*  ls_pcie_ep_get_features(struct

dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -1
 	}
 }
 
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment
above the test might be helpful to explain the test.

OK, I will add a comment above this code.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

Due to the different PCIe controller have different property, e.g. PCIe controller1 support multiple function feature, but PCIe controller2 don't support this feature, so I need to check which controller support it and return the correct offset value, but each board only have one ls_pcie_ep_drvdata, ^_^.

Quoted 10 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

As discussion before, I think the func_offset should not depends on the function number, even if other platforms of NXP may be use write registers way to access the different function config space.

I have added the comments above the code, as follow, do you have any advice? +static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+ u8 func_no)
+{

+       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+       u8 header_type;

+
+ header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+ /*

+        * Read the Header Type register of config space to check
+        * whether this PCI device support the multiple function.
+        */

+ if (header_type & (1 << 7))
+ return pcie->drvdata->func_offset * func_no;
+
+ return 0;
+}

Thanks a lot for your detail comments.

Quoted 77 lines

Thanks,

Andrew Murray

Quoted 25 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +21 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@ -98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 14 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
 	ls_epc->linkup_notifier = false,

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 189

Quoted 5 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct
 platform_device *pdev)
 
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 
Quoted 4 lines
Quoted 4 lines

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#40 lore raw

Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 101 lines · Xiaowei Bao
Quoted 89 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Quoted 60 lines
 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)  {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*  ls_pcie_ep_get_features(struct

dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -1
 	}
 }
 
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · line 99

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment
above the test might be helpful to explain the test.

OK, I will add a comment above this code.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

Due to the different PCIe controller have different property, e.g. PCIe controller1 support multiple function feature, but PCIe controller2 don't support this feature, so I need to check which controller support it and return the correct offset value, but each board only have one ls_pcie_ep_drvdata, ^_^.

Yes but if they don't support the feature then func_offset will be 0.

Quoted 8 lines
Quoted 8 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

Quoted 7 lines
Quoted 3 lines

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

As discussion before, I think the func_offset should not depends on the function number, even if other platforms of NXP may be use write registers way to access the different function config space.

I agree that func_offset is an optional parameter. But if you are attempting to determine the offset of a function and you are given a non-zero function number - then something has gone wrong if func_offset is 0.

Thanks,

Andrew Murray

Quoted 104 lines

I have added the comments above the code, as follow, do you have any advice?

drivers/pci/controller/dwc/pci-layerscape-ep.c +18 -0
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+                                               u8 func_no)
+{
+       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+       u8 header_type;
+
+       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+       /*
+        * Read the Header Type register of config space to check
+        * whether this PCI device support the multiple function.
+        */
+       if (header_type & (1 << 7))
+               return pcie->drvdata->func_offset * func_no;
+
+       return 0;
+}

Thanks a lot for your detail comments.

Quoted 81 lines

Thanks,

Andrew Murray

Quoted 25 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +21 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };

drivers/pci/controller/dwc/pci-layerscape-ep.c static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@ -98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 14 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
 	ls_epc->linkup_notifier = false,

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 189

Quoted 5 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
@@ -152,6 +185,13 @@ static int __init ls_pcie_ep_probe(struct
 platform_device *pdev)
 
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

#41 lore raw

RE: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 145 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月27日 21:34
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 9 lines · Xiaowei Bao
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 70 lines
Quoted 70 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Quoted 50 lines
 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)  {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
}
}

Quoted 2 lines
Quoted 2 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -1
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep

*ep,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -0
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain

the test.

Quoted 11 lines

OK, I will add a comment above this code.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

Due to the different PCIe controller have different property, e.g. PCIe controller1 support multiple function feature, but PCIe controller2 don't support this feature, so I need to check which controller support it and return the correct offset value, but each board only

have one ls_pcie_ep_drvdata, ^_^.

Yes but if they don't support the feature then func_offset will be 0.

Quoted 12 lines
Quoted 11 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

Quoted 7 lines
Quoted 3 lines

As discussion before, I think the func_offset should not depends on the function number, even if other platforms of NXP may be use write registers way to access the different function config space.

I agree that func_offset is an optional parameter. But if you are attempting to determine the offset of a function and you are given a non-zero function number - then something has gone wrong if func_offset is 0.

I have understood you means, maybe I need to set a flag in the driver_data struct, because I may add other platform of NXP, these platform use the write register method to access different function, e.g.
write func_num to register, then we can access this func_num config space.

I will modify the code like this? Do you have better advice? Case1:

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -2
index 004a7e8..8a0d6df 100644
@@ -23,6 +23,7 @@
 #define to_ls_pcie_ep(x)       dev_get_drvdata((x)->dev)
 
 struct ls_pcie_ep_drvdata {
+       u8                              func_config_flag;
        u32                             func_offset;
        const struct dw_pcie_ep_ops     *ops;
        const struct dw_pcie_ops        *dw_pcie_ops;
@@ -97,8 +98,14 @@ static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
         * Read the Header Type register of config space to check
         * whether this PCI device support the multiple function.
         */
-       if (header_type & (1 << 7))
-               return pcie->drvdata->func_offset * func_no;
+       if (header_type & (1 << 7)) {
+               if (pcie->drvdata->func_config_flag) {
+                       iowrite32((func_num << n), pci->dbi_base + PCI_XXXX_XXX);
+               } else {
+                       WARN_ON(func_no && !pcie->drvdata->func_offset);
+                       return pcie->drvdata->func_offset * func_no;
+               }
+       }
 
        return 0;
 }

Of course, I don't need to set the flag this time, because I don't use the second method(write register method), so the code like this:
case2:
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,

                                               u8 func_no) {
       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
       u8 header_type;

	   of course, this code is not requied, due to the 
	   pcie->drvdata->func_offset is 0, but I think this is more clear
	   if use this code.
       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);

       /*
        * Read the Header Type register of config space to check
        * whether this PCI device support the multiple function.
        */
       if (header_type & (1 << 7)) {
			   WARN_ON(func_no && !pcie->drvdata->func_offset);
               return pcie->drvdata->func_offset * func_no; 
		}
		
       return 0;
}

Or like this:
Case3:
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,

                                               u8 func_no) {
       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);

	   WARN_ON(func_no && !pcie->drvdata->func_offset);
       return pcie->drvdata->func_offset * func_no;

}
Of course, we can return a -1 by adjuring the (func_no && !pcie->drvdata->func_offset) Valu in case1

Thanks
Xiaowei

Quoted 106 lines

Thanks,

Andrew Murray

Quoted 2 lines

I have added the comments above the code, as follow, do you have any

advice?

Quoted 61 lines
(quoted diff) +17 -0
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+                                               u8 func_no) {
+       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+       u8 header_type;
+
+       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+       /*
+        * Read the Header Type register of config space to check
+        * whether this PCI device support the multiple function.
+        */
+       if (header_type & (1 << 7))
+               return pcie->drvdata->func_offset * func_no;
+
+       return 0;
+}

Thanks a lot for your detail comments.

Quoted 41 lines

Thanks,

Andrew Murray

Quoted 25 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +19 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -2
-98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep
+*pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 140

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 13 lines
Quoted 13 lines

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
Quoted 6 lines
Quoted 6 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 6 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	ls_epc->linkup_notifier = false, @@ -152,6 +185,13 @@ static int

__init ls_pcie_ep_probe(struct platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 9 lines
Quoted 9 lines

"regs");

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

ret = ls_add_pcie_ep(pcie, pdev);
--
2.9.5

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#42 lore raw

Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 219 lines · Xiaowei Bao
Quoted 145 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月27日 21:34
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 9 lines · Xiaowei Bao
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 70 lines
Quoted 70 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Quoted 50 lines
 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -10
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)  {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,  };
 
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
}
}

Quoted 2 lines
Quoted 2 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -1
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep

*ep,

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -0
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +4 -0
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain

the test.

Quoted 11 lines

OK, I will add a comment above this code.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test above.

Due to the different PCIe controller have different property, e.g. PCIe controller1 support multiple function feature, but PCIe controller2 don't support this feature, so I need to check which controller support it and return the correct offset value, but each board only

have one ls_pcie_ep_drvdata, ^_^.

Yes but if they don't support the feature then func_offset will be 0.

Quoted 12 lines
Quoted 11 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

Quoted 7 lines
Quoted 3 lines

As discussion before, I think the func_offset should not depends on the function number, even if other platforms of NXP may be use write registers way to access the different function config space.

I agree that func_offset is an optional parameter. But if you are attempting to determine the offset of a function and you are given a non-zero function number - then something has gone wrong if func_offset is 0.

I have understood you means, maybe I need to set a flag in the driver_data struct, because I may add other platform of NXP, these platform use the write register method to access different function, e.g.
write func_num to register, then we can access this func_num config space.

I will modify the code like this? Do you have better advice? Case1:

drivers/pci/controller/dwc/pci-layerscape-ep.c +9 -2
index 004a7e8..8a0d6df 100644
@@ -23,6 +23,7 @@
 #define to_ls_pcie_ep(x)       dev_get_drvdata((x)->dev)
 
 struct ls_pcie_ep_drvdata {
+       u8                              func_config_flag;
        u32                             func_offset;
        const struct dw_pcie_ep_ops     *ops;
        const struct dw_pcie_ops        *dw_pcie_ops;
@@ -97,8 +98,14 @@ static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
         * Read the Header Type register of config space to check
         * whether this PCI device support the multiple function.
         */
-       if (header_type & (1 << 7))
-               return pcie->drvdata->func_offset * func_no;
+       if (header_type & (1 << 7)) {
+               if (pcie->drvdata->func_config_flag) {
+                       iowrite32((func_num << n), pci->dbi_base + PCI_XXXX_XXX);
+               } else {
+                       WARN_ON(func_no && !pcie->drvdata->func_offset);
+                       return pcie->drvdata->func_offset * func_no;
+               }
+       }
 
        return 0;
 }

Of course, I don't need to set the flag this time, because I don't use the second method(write register method), so the code like this:
case2:
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,

                                               u8 func_no) {
       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
       u8 header_type;

	   of course, this code is not requied, due to the 
	   pcie->drvdata->func_offset is 0, but I think this is more clear
	   if use this code.
       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);

       /*
        * Read the Header Type register of config space to check
        * whether this PCI device support the multiple function.
        */
       if (header_type & (1 << 7)) {
			   WARN_ON(func_no && !pcie->drvdata->func_offset);
               return pcie->drvdata->func_offset * func_no; 
		}
		
       return 0;
}

Or like this:
Case3:
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,

Quoted 6 lines
                                               u8 func_no) {
       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);

	   WARN_ON(func_no && !pcie->drvdata->func_offset);
       return pcie->drvdata->func_offset * func_no;

This is better. Given there is only currently one method of calculating an offset for layerscape, I'd recommend you add additional methods when the need arises.

Thanks,

Andrew Murray

Quoted 118 lines

}
Of course, we can return a -1 by adjuring the (func_no && !pcie->drvdata->func_offset) Valu in case1

Thanks
Xiaowei

Quoted 110 lines

Thanks,

Andrew Murray

Quoted 2 lines

I have added the comments above the code, as follow, do you have any

advice?

Quoted 61 lines
(quoted diff) +17 -0
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,
+                                               u8 func_no) {
+       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+       u8 header_type;
+
+       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+       /*
+        * Read the Header Type register of config space to check
+        * whether this PCI device support the multiple function.
+        */
+       if (header_type & (1 << 7))
+               return pcie->drvdata->func_offset * func_no;
+
+       return 0;
+}

Thanks a lot for your detail comments.

Quoted 41 lines

Thanks,

Andrew Murray

Quoted 25 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +19 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data = &ls1_ep_drvdata },
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data = &ls2_ep_drvdata },
+	{ },
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 10 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -2
-98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep
+*pcie,
 	int ret;
 
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"addr_space");

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!res)
@@ -137,14 +173,11 @@ static int __init ls_pcie_ep_probe(struct

platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c static int __init ls_pcie_ep_probe(struct · line 140

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 13 lines
Quoted 13 lines

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -5
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
Quoted 6 lines
Quoted 6 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 6 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	ls_epc->linkup_notifier = false, @@ -152,6 +185,13 @@ static int

__init ls_pcie_ep_probe(struct platform_device *pdev)

drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 13 lines
Quoted 13 lines

"regs");

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +6 -1
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
--

2.9.5

#43 lore raw

RE: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 256 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月28日 17:01
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 9 lines · Xiaowei Bao
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月27日 21:34
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 80 lines
Quoted 80 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 10 lines · Xiaowei Bao
Quoted 10 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 22:28
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 60 lines
Quoted 60 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 08/10] PCI: layerscape: Add EP mode support for ls1088a and ls2088a

Quoted 8 lines · Xiaowei Bao

Add PCIe EP mode support for ls1088a and ls2088a, there are some difference between LS1 and LS2 platform, so refactor the code of the EP driver.

---
v2:
- New mechanism for layerscape EP driver.

Was there a v1 of this patch?

Quoted 39 lines
 drivers/pci/controller/dwc/pci-layerscape-ep.c | 76
++++++++++++++++++++------
 1 file changed, 58 insertions(+), 18 deletions(-)
drivers/pci/controller/dwc/pci-layerscape-ep.c +11 -5
index 7ca5fe8..2a66f07 100644
@@ -20,27 +20,29 @@
 
 #define PCIE_DBI2_OFFSET		0x1000	/* DBI2 base address*/
 
-struct ls_pcie_ep {
-	struct dw_pcie		*pci;
-	struct pci_epc_features	*ls_epc;
+#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+
+struct ls_pcie_ep_drvdata {
+	u32				func_offset;
+	const struct dw_pcie_ep_ops	*ops;
+	const struct dw_pcie_ops	*dw_pcie_ops;
 };
 
-#define to_ls_pcie_ep(x)	dev_get_drvdata((x)->dev)
+struct ls_pcie_ep {
+	struct dw_pcie			*pci;
+	struct pci_epc_features		*ls_epc;
+	const struct ls_pcie_ep_drvdata *drvdata; };
 
 static int ls_pcie_establish_link(struct dw_pcie *pci)  {
 	return 0;
 }
 
-static const struct dw_pcie_ops ls_pcie_ep_ops = {
+static const struct dw_pcie_ops dw_ls_pcie_ep_ops = {
 	.start_link = ls_pcie_establish_link,  };
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -5
-static const struct of_device_id ls_pcie_ep_of_match[] = {
-	{ .compatible = "fsl,ls-pcie-ep",},
-	{ },
-};
-
 static const struct pci_epc_features*

ls_pcie_ep_get_features(struct dw_pcie_ep *ep) { @@ -82,10 +84,44 @@ static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep,

u8 func_no,

Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
Quoted 6 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 6 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -1
 	}
 }
 
-static const struct dw_pcie_ep_ops pcie_ep_ops = {
+static unsigned int ls_pcie_ep_func_conf_select(struct
+dw_pcie_ep

*ep,

Quoted 17 lines
Quoted 17 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 12 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +12 -0
+						u8 func_no)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+	struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+	u8 header_type;
+
+	header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+	if (header_type & (1 << 7))
+		return pcie->drvdata->func_offset * func_no;
+	else
+		return 0;

It looks like there isn't a PCI define for multi function, the nearest I could find was PCI_HEADER_TYPE_MULTIDEVICE in hotplug/ibmphp.h. A comment above the test might be helpful to explain

Quoted 7 lines
Quoted 7 lines

the test.

Quoted 6 lines

OK, I will add a comment above this code.

Quoted 3 lines

As the ls_pcie_ep_drvdata structures are static, the unset .func_offset will be initialised to 0, so you could just drop the test

above.

Quoted 22 lines
Quoted 22 lines
Quoted 6 lines

Due to the different PCIe controller have different property, e.g. PCIe controller1 support multiple function feature, but PCIe controller2 don't support this feature, so I need to check which controller support it and return the correct offset value, but each board only

have one ls_pcie_ep_drvdata, ^_^.

Yes but if they don't support the feature then func_offset will be 0.

Quoted 12 lines
Quoted 11 lines

However something to the effect of the following may help spot misconfiguration:

WARN_ON(func_no && !pcie->drvdata->func_offset); return pcie->drvdata->func_offset * func_no;

The WARN is probably quite useful as if you are attempting to use non-zero functions and func_offset isn't set - then things may appear to work normally but actually will break horribly.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

As discussion before, I think the func_offset should not depends on the function number, even if other platforms of NXP may be use write registers way to access the different function config space.

I agree that func_offset is an optional parameter. But if you are attempting to determine the offset of a function and you are given a non-zero function number - then something has gone wrong if func_offset

is 0.

drivers/pci/controller/dwc/pci-layerscape-ep.c static unsigned int

Quoted 22 lines

I have understood you means, maybe I need to set a flag in the driver_data struct, because I may add other platform of NXP, these platform use the write register method to access different function, e.g. write func_num to register, then we can access this func_num config space.

I will modify the code like this? Do you have better advice? Case1:

drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
index 004a7e8..8a0d6df 100644
@@ -23,6 +23,7 @@
 #define to_ls_pcie_ep(x)       dev_get_drvdata((x)->dev)
 
 struct ls_pcie_ep_drvdata {
+       u8                              func_config_flag;
        u32                             func_offset;
        const struct dw_pcie_ep_ops     *ops;
        const struct dw_pcie_ops        *dw_pcie_ops;
@@ -97,8 +98,14 @@ static unsigned int

ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,

drivers/pci/controller/dwc/pci-layerscape-ep.c static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep *ep,

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -2
         * Read the Header Type register of config space to check
         * whether this PCI device support the multiple function.
         */
-       if (header_type & (1 << 7))
-               return pcie->drvdata->func_offset * func_no;
+       if (header_type & (1 << 7)) {
+               if (pcie->drvdata->func_config_flag) {
+                       iowrite32((func_num << n), pci->dbi_base +

PCI_XXXX_XXX);

drivers/pci/controller/dwc/pci-layerscape-ep.c static unsigned int · line 105

Quoted 2 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -0
+               } else {
+                       WARN_ON(func_no

&& !pcie->drvdata->func_offset);

Quoted 42 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -0
+                       return pcie->drvdata->func_offset * func_no;
+               }
+       }
 
        return 0;
 }

Of course, I don't need to set the flag this time, because I don't use the second method(write register method), so the code like this:
case2:

drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -0
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep
+*ep,
                                               u8 func_no) {
       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
       u8 header_type;
	   of course, this code is not requied, due to the
	   pcie->drvdata->func_offset is 0, but I think this is more clear
	   if use this code.
       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);

       /*
        * Read the Header Type register of config space to check
        * whether this PCI device support the multiple function.
        */
       if (header_type & (1 << 7)) {
			   WARN_ON(func_no && !pcie->drvdata->func_offset);
               return pcie->drvdata->func_offset * func_no;
		}

       return 0;
}

Or like this:
Case3:

drivers/pci/controller/dwc/pci-layerscape-ep.c +2 -0
+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep
+*ep,
                                               u8 func_no) {
       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
Quoted 6 lines
Quoted 2 lines
	   WARN_ON(func_no && !pcie->drvdata->func_offset);
       return pcie->drvdata->func_offset * func_no;

This is better. Given there is only currently one method of calculating an offset for layerscape, I'd recommend you add additional methods when the need arises.

OK, thanks

Quoted 133 lines

Thanks,

Andrew Murray

Quoted 18 lines

}
Of course, we can return a -1 by adjuring the (func_no && !pcie->drvdata->func_offset) Valu in case1

Thanks
Xiaowei

Quoted 10 lines

Thanks,

Andrew Murray

Quoted 3 lines

I have added the comments above the code, as follow, do you have any

advice?

Quoted 1 line

+static unsigned int ls_pcie_ep_func_conf_select(struct dw_pcie_ep

*ep,

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ u8 func_no)

{

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
(quoted diff) +15 -0
+       struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+       struct ls_pcie_ep *pcie = to_ls_pcie_ep(pci);
+       u8 header_type;
+
+       header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
+
+       /*
+        * Read the Header Type register of config space to check
+        * whether this PCI device support the multiple function.
+        */
+       if (header_type & (1 << 7))
+               return pcie->drvdata->func_offset * func_no;
+
+       return 0;
+}

Thanks a lot for your detail comments.

Quoted 16 lines

Thanks,

Andrew Murray

Quoted 11 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -0
+}
+
+static const struct dw_pcie_ep_ops ls_pcie_ep_ops = {
 	.ep_init = ls_pcie_ep_init,
 	.raise_irq = ls_pcie_ep_raise_irq,
 	.get_features = ls_pcie_ep_get_features,
+	.func_conf_select = ls_pcie_ep_func_conf_select, };
+
+static const struct ls_pcie_ep_drvdata ls1_ep_drvdata = {
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 8 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +8 -0
+
+static const struct ls_pcie_ep_drvdata ls2_ep_drvdata = {
+	.func_offset = 0x20000,
+	.ops = &ls_pcie_ep_ops,
+	.dw_pcie_ops = &dw_ls_pcie_ep_ops, };
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+	{ .compatible = "fsl,ls1046a-pcie-ep", .data =

&ls1_ep_drvdata },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 1 line
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
+	{ .compatible = "fsl,ls1088a-pcie-ep", .data =

&ls2_ep_drvdata },

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 1 line
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
+	{ .compatible = "fsl,ls2088a-pcie-ep", .data =

&ls2_ep_drvdata },

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -1
+	{ },
 };
 
 static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie, @@
-98,7
+134,7 @@ static int __init ls_add_pcie_ep(struct ls_pcie_ep
+*pcie,
 	int ret;
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 5 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -1
 	ep = &pci->ep;
-	ep->ops = &pcie_ep_ops;
+	ep->ops = pcie->drvdata->ops;
 
 	res = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

"addr_space");

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -0
 	if (!res)
@@ -137,14 +173,11 @@ static int __init

ls_pcie_ep_probe(struct

platform_device *pdev)

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 4 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
 	if (!ls_epc)
 		return -ENOMEM;
 
-	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 2 lines
Quoted 2 lines

"regs");

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 1 line
drivers/pci/controller/dwc/pci-layerscape-ep.c +0 -1
-	pci->dbi_base = devm_pci_remap_cfg_resource(dev,

dbi_base);

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +3 -4
-	if (IS_ERR(pci->dbi_base))
-		return PTR_ERR(pci->dbi_base);
+	pcie->drvdata = of_device_get_match_data(dev);
 
-	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
 	pci->dev = dev;
-	pci->ops = &ls_pcie_ep_ops;
+	pci->ops = pcie->drvdata->dw_pcie_ops;
+
 	pcie->pci = pci;
 
 	ls_epc->linkup_notifier = false, @@ -152,6 +185,13 @@ static

int __init ls_pcie_ep_probe(struct platform_device *pdev)

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 3 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
 	pcie->ls_epc = ls_epc;
 
+	dbi_base = platform_get_resource_byname(pdev,

IORESOURCE_MEM,

Quoted 2 lines
Quoted 2 lines

"regs");

drivers/pci/controller/dwc/pci-layerscape-ep.c

Quoted 1 line
drivers/pci/controller/dwc/pci-layerscape-ep.c +1 -0
+	pci->dbi_base = devm_pci_remap_cfg_resource(dev,

dbi_base);

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/pci/controller/dwc/pci-layerscape-ep.c +5 -1
+	if (IS_ERR(pci->dbi_base))
+		return PTR_ERR(pci->dbi_base);
+
+	pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+
 	platform_set_drvdata(pdev, pcie);
 
 	ret = ls_add_pcie_ep(pcie, pdev);
--

2.9.5

#44 lore raw

PATCH v2 9/10 arm64: dts: layerscape: Add PCIe EP node for ls1088a

In reply to Xiaowei Bao

Add PCIe EP node for ls1088a to support EP mode.

---
v2:
- Remove the pf-offset proparty.

 arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi | 31 ++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi +31 -0
index dfbead4..79109ad 100644
@@ -471,6 +471,17 @@
 			status = "disabled";
 		};
 
+		pcie_ep@3400000 {
+			compatible = "fsl,ls1088a-pcie-ep","fsl,ls-pcie-ep";
+			reg = <0x00 0x03400000 0x0 0x00100000
+			       0x20 0x00000000 0x8 0x00000000>;
+			reg-names = "regs", "addr_space";
+			num-ib-windows = <24>;
+			num-ob-windows = <128>;
+			max-functions = /bits/ 8 <2>;
+			status = "disabled";
+		};
+
 		pcie@3500000 {
 			compatible = "fsl,ls1088a-pcie";
 			reg = <0x00 0x03500000 0x0 0x00100000   /* controller registers */
@@ -497,6 +508,16 @@
 			status = "disabled";
 		};
 
+		pcie_ep@3500000 {
+			compatible = "fsl,ls1088a-pcie-ep","fsl,ls-pcie-ep";
+			reg = <0x00 0x03500000 0x0 0x00100000
+			       0x28 0x00000000 0x8 0x00000000>;
+			reg-names = "regs", "addr_space";
+			num-ib-windows = <6>;
+			num-ob-windows = <8>;
+			status = "disabled";
+		};
+
 		pcie@3600000 {
 			compatible = "fsl,ls1088a-pcie";
 			reg = <0x00 0x03600000 0x0 0x00100000   /* controller registers */
@@ -523,6 +544,16 @@
 			status = "disabled";
 		};
 
+		pcie_ep@3600000 {
+			compatible = "fsl,ls1088a-pcie-ep","fsl,ls-pcie-ep";
+			reg = <0x00 0x03600000 0x0 0x00100000
+			       0x30 0x00000000 0x8 0x00000000>;
+			reg-names = "regs", "addr_space";
+			num-ib-windows = <6>;
+			num-ob-windows = <8>;
+			status = "disabled";
+		};
+
 		smmu: iommu@5000000 {
 			compatible = "arm,mmu-500";
 			reg = <0 0x5000000 0 0x800000>;
Signature · 1 line
2.9.5
#45 lore raw

PATCH v2 10/10 misc: pci_endpoint_test: Add LS1088a in pci_device_id table

In reply to Xiaowei Bao

Add LS1088a in pci_device_id table so that pci-epf-test can be used for testing PCIe EP in LS1088a.

---
v2:
- No change.

 drivers/misc/pci_endpoint_test.c | 1 +
 1 file changed, 1 insertion(+)
drivers/misc/pci_endpoint_test.c +1 -0
index 6e208a0..d531951 100644
@@ -793,6 +793,7 @@ static const struct pci_device_id pci_endpoint_test_tbl[] = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x81c0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x80c0) },
 	{ PCI_DEVICE_DATA(SYNOPSYS, EDDA, NULL) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_AM654),
 	  .driver_data = (kernel_ulong_t)&am654_data
Signature · 1 line
2.9.5
#46 lore raw
In reply to Xiaowei Bao
Quoted 3 lines · Xiaowei Bao

Add multiple PFs support for DWC, different PF have different config space we use pf-offset property which get from the DTS to access the different pF config space.

It looks like you're missing a --cover-letter again.

Quoted 24 lines

---
v2:
- Remove duplicate redundant code.
- Reimplement the PF config space access way.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 122 ++++++++++++++++--------
 drivers/pci/controller/dwc/pcie-designware.c    |  59 ++++++++----
 drivers/pci/controller/dwc/pcie-designware.h    |  11 ++-
 3 files changed, 134 insertions(+), 58 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +2 -2
index 2bf5a35..3e2b740 100644
@@ -19,12 +19,17 @@ void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
 	pci_epc_linkup(epc);
 }
 
-static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar,
-				   int flags)
+static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
+				   enum pci_barno bar, int flags)

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 32

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +6 -1
 {
 	u32 reg;
+	unsigned int func_offset = 0;
+	struct dw_pcie_ep *ep = &pci->ep;
 
-	reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);

This pattern of checking if func_conf_select exists and using it to get an offset is repeated a lot throughout this file. You could move this functionality into a new function (similar to dw_pcie_read_dbi etc). Or perhaps a new variant of dw_pcie_writel_ should be created that writes takes a func_no argument.

Quoted 18 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
 	dw_pcie_dbi_ro_wr_en(pci);
 	dw_pcie_writel_dbi2(pci, reg, 0x0);
 	dw_pcie_writel_dbi(pci, reg, 0x0);
@@ -235,7 +257,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no,
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-	ret = dw_pcie_ep_outbound_atu(ep, addr, pci_addr, size);
+	ret = dw_pcie_ep_outbound_atu(ep, func_no, addr, pci_addr, size);
 	if (ret) {
 		dev_err(pci->dev, "Failed to enable address\n");
 		return ret;
@@ -249,11 +271,15 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no) · line 282

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;

This makes me nervous.

Quoted 1 line

From a PCI viewpoint, each function has it's own capability structure and

within each function there may exist a MSI capability. Yet what we're doing here is using dw_pcie_ep_find_capability to get the list of capabilities for function 0, and then applying offsets from that for subsequent functions. I.e. we're applying DW specific knowledge to find the correct capability, rather than following the general PCI approach.

I think the above hunk shouldn't be required - but instead dw_pcie_ep_find_capability is updated to take a func_no parameter.

Have I understood this correctly?

Quoted 24 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSI_FLAGS_ENABLE))
 		return -EINVAL;
@@ -268,11 +294,15 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSI_FLAGS_QMASK;
 	val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK;
@@ -288,11 +318,15 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no) · line 329

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;

Same for MSIX.

Quoted 24 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSIX_FLAGS_ENABLE))
 		return -EINVAL;
@@ -307,11 +341,15 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u16 interrupts)
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSIX_FLAGS_QSIZE;
 	val |= interrupts;
@@ -398,29 +436,33 @@ int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no,
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct pci_epc *epc = ep->epc;
 	unsigned int aligned_offset;

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no, · line 448

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -0
+	unsigned int func_offset = 0;
 	u16 msg_ctrl, msg_data;
 	u32 msg_addr_lower, msg_addr_upper, reg;
 	u64 msg_addr;
 	bool has_upper;
 	int ret;
 
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+

You could probably move this hunk below the test for msi_cap to save some cycles.

Quoted 47 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -5
 	if (!ep->msi_cap)
 		return -EINVAL;
 
 	/* Raise MSI per the PCI Local Bus Specification Revision 3.0, 6.8.1. */
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	msg_ctrl = dw_pcie_readw_dbi(pci, reg);
 	has_upper = !!(msg_ctrl & PCI_MSI_FLAGS_64BIT);
-	reg = ep->msi_cap + PCI_MSI_ADDRESS_LO;
+	reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_LO;
 	msg_addr_lower = dw_pcie_readl_dbi(pci, reg);
 	if (has_upper) {
-		reg = ep->msi_cap + PCI_MSI_ADDRESS_HI;
+		reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_HI;
 		msg_addr_upper = dw_pcie_readl_dbi(pci, reg);
-		reg = ep->msi_cap + PCI_MSI_DATA_64;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_64;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	} else {
 		msg_addr_upper = 0;
-		reg = ep->msi_cap + PCI_MSI_DATA_32;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_32;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	}
 	aligned_offset = msg_addr_lower & (epc->mem->page_size - 1);
drivers/pci/controller/dwc/pcie-designware.c +4 -3
index 7d25102..305e73d 100644
@@ -158,9 +158,10 @@ static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,
 	dw_pcie_writel_atu(pci, offset + reg, val);
 }
 
-static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
-					     int type, u64 cpu_addr,
-					     u64 pci_addr, u32 size)
+static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, u8 func_no,
+					     int index, int type,
+					     u64 cpu_addr, u64 pci_addr,
+					     u32 size)
 {
 	u32 retries, val;
 

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, · line 179

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
@@ -175,7 +176,7 @@ static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
 				 upper_32_bits(pci_addr));
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1,
-				 type);
+				 type | PCIE_ATU_FUNC_NUM(func_no));

Much better :)

Quoted 33 lines
drivers/pci/controller/dwc/pcie-designware.c +5 -4
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
 				 PCIE_ATU_ENABLE);
 
@@ -194,8 +195,9 @@ static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
 	dev_err(pci->dev, "Outbound iATU is not being enabled\n");
 }
 
-void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
-			       u64 cpu_addr, u64 pci_addr, u32 size)
+static void __dw_pcie_prog_outbound_atu(struct dw_pcie *pci, u8 func_no,
+					int index, int type, u64 cpu_addr,
+					u64 pci_addr, u32 size)
 {
 	u32 retries, val;
 
@@ -203,8 +205,8 @@ void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
 		cpu_addr = pci->ops->cpu_addr_fixup(pci, cpu_addr);
 
 	if (pci->iatu_unroll_enabled) {
-		dw_pcie_prog_outbound_atu_unroll(pci, index, type, cpu_addr,
-						 pci_addr, size);
+		dw_pcie_prog_outbound_atu_unroll(pci, func_no, index, type,
+						 cpu_addr, pci_addr, size);
 		return;
 	}
 
drivers/pci/controller/dwc/pcie-designware.h +0 -0
index ffed084..a0fdbf7 100644

drivers/pci/controller/dwc/pcie-designware.h line 74

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -71,9 +71,11 @@
 #define PCIE_ATU_TYPE_IO		0x2
 #define PCIE_ATU_TYPE_CFG0		0x4
 #define PCIE_ATU_TYPE_CFG1		0x5
+#define PCIE_ATU_FUNC_NUM(pf)           (pf << 20)

"Macro argument 'pf' may be better as '(pf)' to avoid precedence issues"

drivers/pci/controller/dwc/pcie-designware.h struct dw_pcie_ep_ops { · line 202

Quoted 12 lines
drivers/pci/controller/dwc/pcie-designware.h +2 -0
 #define PCIE_ATU_CR2			0x908
 #define PCIE_ATU_ENABLE			BIT(31)
 #define PCIE_ATU_BAR_MODE_ENABLE	BIT(30)
+#define PCIE_ATU_FUNC_NUM_MATCH_EN      BIT(19)
 #define PCIE_ATU_LOWER_BASE		0x90C
 #define PCIE_ATU_UPPER_BASE		0x910
 #define PCIE_ATU_LIMIT			0x914
@@ -197,6 +199,7 @@ struct dw_pcie_ep_ops {
 	int	(*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
 			     enum pci_epc_irq_type type, u16 interrupt_num);
 	const struct pci_epc_features* (*get_features)(struct dw_pcie_ep *ep);
+	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);

Given that this function will return an offset, I'm not sure the name you have is suitable. Something like get_pf_offset or similar is more descriptive.

Thanks,

Andrew Murray

Quoted 21 lines
drivers/pci/controller/dwc/pcie-designware.h +6 -2
 };
 
 struct dw_pcie_ep {
@@ -265,8 +268,12 @@ int dw_pcie_wait_for_link(struct dw_pcie *pci);
 void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
 			       int type, u64 cpu_addr, u64 pci_addr,
 			       u32 size);
-int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
-			     u64 cpu_addr, enum dw_pcie_as_type as_type);
+void dw_pcie_prog_ep_outbound_atu(struct dw_pcie *pci, u8 func_no, int index,
+				  int type, u64 cpu_addr, u64 pci_addr,
+				  u32 size);
+int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, u8 func_no, int index,
+			     int bar, u64 cpu_addr,
+			     enum dw_pcie_as_type as_type);
 void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
 			 enum dw_pcie_region_type type);
 void dw_pcie_setup(struct dw_pcie *pci);
Signature · 1 line
2.9.5
#47 lore raw
Quoted 56 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:25
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 01/10] PCI: designware-ep: Add multiple PFs support for DWC

Quoted 3 lines · Xiaowei Bao

Add multiple PFs support for DWC, different PF have different config space we use pf-offset property which get from the DTS to access the different pF config space.

It looks like you're missing a --cover-letter again.

Quoted 8 lines

---
v2:
- Remove duplicate redundant code.
- Reimplement the PF config space access way.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 122

++++++++++++++++--------

Quoted 10 lines
 drivers/pci/controller/dwc/pcie-designware.c    |  59 ++++++++----
 drivers/pci/controller/dwc/pcie-designware.h    |  11 ++-
 3 files changed, 134 insertions(+), 58 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
index 2bf5a35..3e2b740 100644

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 22

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -1
@@ -19,12 +19,17 @@ void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
 	pci_epc_linkup(epc);
 }
 
-static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno

bar,

Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
-				   int flags)
+static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
+				   enum pci_barno bar, int flags)
 {
 	u32 reg;
+	unsigned int func_offset = 0;
+	struct dw_pcie_ep *ep = &pci->ep;
 
Quoted 10 lines

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 32

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
-	reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);

This pattern of checking if func_conf_select exists and using it to get an offset is repeated a lot throughout this file. You could move this functionality into a new function (similar to dw_pcie_read_dbi etc). Or perhaps a new variant of dw_pcie_writel_ should be created that writes takes a func_no argument.

Thanks for your comments, I thought about this method before, but there is a issue about the method of access the different func config space, due to our platform use this method that different func have different offset from dbi_base to access the different config space, but others platform maybe use the way that write a register to implement different func config space access, so I think reserve a callback function to different platform to implement the own method, my point is that, if use register method they can implement the code in this function and return offset is 0, if use offset method, they can return the offset value which can be use by dw_pcie_ep driver.

Quoted 42 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_map_addr(struct pci_epc

Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	dw_pcie_dbi_ro_wr_en(pci);
 	dw_pcie_writel_dbi2(pci, reg, 0x0);
 	dw_pcie_writel_dbi(pci, reg, 0x0);
@@ -235,7 +257,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc

*epc, u8 func_no,

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc

Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-	ret = dw_pcie_ep_outbound_atu(ep, addr, pci_addr, size);
+	ret = dw_pcie_ep_outbound_atu(ep, func_no, addr, pci_addr, size);
 	if (ret) {
 		dev_err(pci->dev, "Failed to enable address\n");
 		return ret;
@@ -249,11 +271,15 @@ static int dw_pcie_ep_get_msi(struct pci_epc

*epc, u8 func_no)

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no) · line 282

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;

This makes me nervous.

From a PCI viewpoint, each function has it's own capability structure and within each function there may exist a MSI capability. Yet what we're doing here is using dw_pcie_ep_find_capability to get the list of capabilities for function 0, and then applying offsets from that for subsequent functions. I.e. we're applying DW specific knowledge to find the correct capability, rather than following the general PCI approach.

Quoted 4 lines

I think the above hunk shouldn't be required - but instead dw_pcie_ep_find_capability is updated to take a func_no parameter.

Have I understood this correctly?

Yes, this is a issue, I think the different func maybe have different capability, but the dw_pcie_ep_find_capability function is called by dw_pcie_ep_init function, we can't add func_no parameter to dw_pcie_ep_find_capability, I will try to fix it use a new patch, I think move this function to ep_init callback function If better, thanks.

Quoted 31 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_set_msi(struct pci_epc

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSI_FLAGS_ENABLE))
 		return -EINVAL;
@@ -268,11 +294,15 @@ static int dw_pcie_ep_set_msi(struct pci_epc

*epc, u8 func_no, u8 interrupts)

Quoted 25 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSI_FLAGS_QMASK;
 	val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK; @@ -288,11 +318,15

@@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)

drivers/pci/controller/dwc/pcie-designware-ep.c +4 -0
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no) · line 329

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;

Same for MSIX.

Yes.

Quoted 34 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_set_msix(struct pci_epc

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSIX_FLAGS_ENABLE))
 		return -EINVAL;
@@ -307,11 +341,15 @@ static int dw_pcie_ep_set_msix(struct pci_epc

*epc, u8 func_no, u16 interrupts)

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct

Quoted 17 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSIX_FLAGS_QSIZE;
 	val |= interrupts;
@@ -398,29 +436,33 @@ int dw_pcie_ep_raise_msi_irq(struct

dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -0
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct pci_epc *epc = ep->epc;
 	unsigned int aligned_offset;
+	unsigned int func_offset = 0;
 	u16 msg_ctrl, msg_data;
 	u32 msg_addr_lower, msg_addr_upper, reg;
 	u64 msg_addr;
 	bool has_upper;
 	int ret;
 
Quoted 6 lines

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 31

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +3 -0
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+

You could probably move this hunk below the test for msi_cap to save some cycles.

Sorry, I didn't understand the means, please explain it detailly, thanks a lot, ^_^

Quoted 52 lines

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct

Quoted 35 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -5
 	if (!ep->msi_cap)
 		return -EINVAL;
 
 	/* Raise MSI per the PCI Local Bus Specification Revision 3.0, 6.8.1. */
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	msg_ctrl = dw_pcie_readw_dbi(pci, reg);
 	has_upper = !!(msg_ctrl & PCI_MSI_FLAGS_64BIT);
-	reg = ep->msi_cap + PCI_MSI_ADDRESS_LO;
+	reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_LO;
 	msg_addr_lower = dw_pcie_readl_dbi(pci, reg);
 	if (has_upper) {
-		reg = ep->msi_cap + PCI_MSI_ADDRESS_HI;
+		reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_HI;
 		msg_addr_upper = dw_pcie_readl_dbi(pci, reg);
-		reg = ep->msi_cap + PCI_MSI_DATA_64;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_64;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	} else {
 		msg_addr_upper = 0;
-		reg = ep->msi_cap + PCI_MSI_DATA_32;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_32;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	}
 	aligned_offset = msg_addr_lower & (epc->mem->page_size - 1);
drivers/pci/controller/dwc/pcie-designware.c +0 -0
index 7d25102..305e73d 100644
@@ -158,9 +158,10 @@ static void dw_pcie_writel_ob_unroll(struct

dw_pcie *pci, u32 index, u32 reg,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct · line 160

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -1
 	dw_pcie_writel_atu(pci, offset + reg, val);  }
 
-static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int

index,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -2
-					     int type, u64 cpu_addr,
-					     u64 pci_addr, u32 size)
+static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, u8

func_no,

drivers/pci/controller/dwc/pcie-designware.c static void

Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware.c +3 -0
+					     int index, int type,
+					     u64 cpu_addr, u64 pci_addr,
+					     u32 size)
 {
 	u32 retries, val;
 
@@ -175,7 +176,7 @@ static void

dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, · line 179

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
 				 upper_32_bits(pci_addr));
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1,
-				 type);
+				 type | PCIE_ATU_FUNC_NUM(func_no));

Much better :)

Do you mean that use the expression "a? b:c"

Quoted 44 lines

drivers/pci/controller/dwc/pcie-designware.c static void

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
 				 PCIE_ATU_ENABLE);
 
@@ -194,8 +195,9 @@ static void

dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -2
 	dev_err(pci->dev, "Outbound iATU is not being enabled\n");  }
 
-void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
-			       u64 cpu_addr, u64 pci_addr, u32 size)
+static void __dw_pcie_prog_outbound_atu(struct dw_pcie *pci, u8

func_no,

drivers/pci/controller/dwc/pcie-designware.c void dw_pcie_prog_outbound_atu(struct dw_pcie

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -0
+					int index, int type, u64 cpu_addr,
+					u64 pci_addr, u32 size)
 {
 	u32 retries, val;
 
@@ -203,8 +205,8 @@ void dw_pcie_prog_outbound_atu(struct dw_pcie

*pci, int index, int type,

Quoted 18 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -2
 		cpu_addr = pci->ops->cpu_addr_fixup(pci, cpu_addr);
 
 	if (pci->iatu_unroll_enabled) {
-		dw_pcie_prog_outbound_atu_unroll(pci, index, type, cpu_addr,
-						 pci_addr, size);
+		dw_pcie_prog_outbound_atu_unroll(pci, func_no, index, type,
+						 cpu_addr, pci_addr, size);
 		return;
 	}
 
drivers/pci/controller/dwc/pcie-designware.h +0 -0
index ffed084..a0fdbf7 100644

drivers/pci/controller/dwc/pcie-designware.h line 74

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -71,9 +71,11 @@
 #define PCIE_ATU_TYPE_IO		0x2
 #define PCIE_ATU_TYPE_CFG0		0x4
 #define PCIE_ATU_TYPE_CFG1		0x5
+#define PCIE_ATU_FUNC_NUM(pf)           (pf << 20)

"Macro argument 'pf' may be better as '(pf)' to avoid precedence issues"

Quoted 16 lines

drivers/pci/controller/dwc/pcie-designware.h struct dw_pcie_ep_ops { · line 203

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware.h +2 -0
 #define PCIE_ATU_CR2			0x908
 #define PCIE_ATU_ENABLE			BIT(31)
 #define PCIE_ATU_BAR_MODE_ENABLE	BIT(30)
+#define PCIE_ATU_FUNC_NUM_MATCH_EN      BIT(19)
 #define PCIE_ATU_LOWER_BASE		0x90C
 #define PCIE_ATU_UPPER_BASE		0x910
 #define PCIE_ATU_LIMIT			0x914
@@ -197,6 +199,7 @@ struct dw_pcie_ep_ops {
 	int	(*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
 			     enum pci_epc_irq_type type, u16 interrupt_num);
 	const struct pci_epc_features* (*get_features)(struct dw_pcie_ep
 *ep);
+	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);

Given that this function will return an offset, I'm not sure the name you have is suitable. Something like get_pf_offset or similar is more descriptive.

As above explain, my initial view is that this function can return 0 or offset depends on the platform implement mechanism, so I named it func_conf_select, I think add a comment for this function, like this:
/*
* provide a method to implement the method of different func config space access,
* if use offset method, return the offset from dbi_base, if your register method, implement
* the code in this callback function and return 0.
*/
How about it?

Quoted 27 lines

Thanks,

Andrew Murray

drivers/pci/controller/dwc/pcie-designware.h int dw_pcie_wait_for_link(struct dw_pcie *pci); · line 271

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.h +0 -0
 };
 

struct dw_pcie_ep {

drivers/pci/controller/dwc/pcie-designware.h +1 -2
@@ -265,8 +268,12 @@ int dw_pcie_wait_for_link(struct dw_pcie *pci);
 void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
 			       int type, u64 cpu_addr, u64 pci_addr,
 			       u32 size);
-int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
-			     u64 cpu_addr, enum dw_pcie_as_type as_type);
+void dw_pcie_prog_ep_outbound_atu(struct dw_pcie *pci, u8 func_no, int

index,

Quoted 11 lines
drivers/pci/controller/dwc/pcie-designware.h +5 -1
+				  int type, u64 cpu_addr, u64 pci_addr,
+				  u32 size);
+int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, u8 func_no, int index,
+			     int bar, u64 cpu_addr,
+			     enum dw_pcie_as_type as_type);
 void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
 			 enum dw_pcie_region_type type);
 void dw_pcie_setup(struct dw_pcie *pci);
--

2.9.5

#48 lore raw
Quoted 67 lines · Xiaowei Bao
Quoted 56 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:25
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 01/10] PCI: designware-ep: Add multiple PFs support for DWC

Quoted 3 lines · Xiaowei Bao

Add multiple PFs support for DWC, different PF have different config space we use pf-offset property which get from the DTS to access the different pF config space.

It looks like you're missing a --cover-letter again.

Quoted 8 lines

---
v2:
- Remove duplicate redundant code.
- Reimplement the PF config space access way.

 drivers/pci/controller/dwc/pcie-designware-ep.c | 122

++++++++++++++++--------

Quoted 10 lines
 drivers/pci/controller/dwc/pcie-designware.c    |  59 ++++++++----
 drivers/pci/controller/dwc/pcie-designware.h    |  11 ++-
 3 files changed, 134 insertions(+), 58 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
index 2bf5a35..3e2b740 100644

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 22

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -1
@@ -19,12 +19,17 @@ void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
 	pci_epc_linkup(epc);
 }
 
-static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno

bar,

Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
-				   int flags)
+static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
+				   enum pci_barno bar, int flags)
 {
 	u32 reg;
+	unsigned int func_offset = 0;
+	struct dw_pcie_ep *ep = &pci->ep;
 
Quoted 10 lines

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 32

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
-	reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);

This pattern of checking if func_conf_select exists and using it to get an offset is repeated a lot throughout this file. You could move this functionality into a new function (similar to dw_pcie_read_dbi etc). Or perhaps a new variant of dw_pcie_writel_ should be created that writes takes a func_no argument.

Quoted 5 lines

Thanks for your comments, I thought about this method before, but there is a issue about the method of access the different func config space, due to our platform use this method that different func have different offset from dbi_base to access the different config space, but others platform maybe use the way that write a register to implement different func config space access, so I think reserve a callback function

My point here was really to move out duplicated code to its own small function. I wasn't making any comment about (removing) the callback, just that the test and callback could be in one function.

Quoted 3 lines

to different platform to implement the own method, my point is that, if use register method they can implement the code in this function and return offset is 0, if use offset method, they can return the offset value which can be use by dw_pcie_ep driver.

By the way, I haven't looked to see how many of the dw_pcie_write_xxx functions would benefit from a func_no argument - if there were many calls to dw_pcie_write_xxx that all used a reg value originated from func_conf_select then an approach similar to the implementation of dw_pcie_write_dbi could probably be justified (i.e. rather than change the value of reg) for writing to functions.

Quoted 43 lines
Quoted 43 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_map_addr(struct pci_epc

Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	dw_pcie_dbi_ro_wr_en(pci);
 	dw_pcie_writel_dbi2(pci, reg, 0x0);
 	dw_pcie_writel_dbi(pci, reg, 0x0);
@@ -235,7 +257,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc

*epc, u8 func_no,

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc

Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-	ret = dw_pcie_ep_outbound_atu(ep, addr, pci_addr, size);
+	ret = dw_pcie_ep_outbound_atu(ep, func_no, addr, pci_addr, size);
 	if (ret) {
 		dev_err(pci->dev, "Failed to enable address\n");
 		return ret;
@@ -249,11 +271,15 @@ static int dw_pcie_ep_get_msi(struct pci_epc

*epc, u8 func_no)

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no) · line 282

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;

This makes me nervous.

From a PCI viewpoint, each function has it's own capability structure and within each function there may exist a MSI capability. Yet what we're doing here is using dw_pcie_ep_find_capability to get the list of capabilities for function 0, and then applying offsets from that for subsequent functions. I.e. we're applying DW specific knowledge to find the correct capability, rather than following the general PCI approach.

Quoted 8 lines
Quoted 4 lines

I think the above hunk shouldn't be required - but instead dw_pcie_ep_find_capability is updated to take a func_no parameter.

Have I understood this correctly?

Yes, this is a issue, I think the different func maybe have different capability, but the dw_pcie_ep_find_capability function is called by dw_pcie_ep_init function, we can't add func_no parameter to dw_pcie_ep_find_capability,

Why not?

Given that 'struct dw_pcie' represents a controller - and thus potentially multiple functions - then the _find_capability function should be able to provide the correct offset for the given function. Surely it needs to know which function number? Unless there is some reason why we can assume that all functions share the same capability offset.

Also the 'struct dw_pcie_ep' which represents an endpoint controller - this has msi_cap and msix_cap fields - given this may be a multifunction device what do these fields actually refer to?

Perhaps Jungoo/Gustavo can comment.

Quoted 79 lines

I will try to fix it use a new patch, I think move this function to ep_init callback function If better, thanks.

Quoted 31 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_set_msi(struct pci_epc

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSI_FLAGS_ENABLE))
 		return -EINVAL;
@@ -268,11 +294,15 @@ static int dw_pcie_ep_set_msi(struct pci_epc

*epc, u8 func_no, u8 interrupts)

Quoted 25 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSI_FLAGS_QMASK;
 	val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK; @@ -288,11 +318,15

@@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no)

drivers/pci/controller/dwc/pcie-designware-ep.c +4 -0
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no) · line 329

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;

Same for MSIX.

Yes.

Quoted 34 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_set_msix(struct pci_epc

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSIX_FLAGS_ENABLE))
 		return -EINVAL;
@@ -307,11 +341,15 @@ static int dw_pcie_ep_set_msix(struct pci_epc

*epc, u8 func_no, u16 interrupts)

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct

Quoted 17 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSIX_FLAGS_QSIZE;
 	val |= interrupts;
@@ -398,29 +436,33 @@ int dw_pcie_ep_raise_msi_irq(struct

dw_pcie_ep *ep, u8 func_no,

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -0
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct pci_epc *epc = ep->epc;
 	unsigned int aligned_offset;
+	unsigned int func_offset = 0;
 	u16 msg_ctrl, msg_data;
 	u32 msg_addr_lower, msg_addr_upper, reg;
 	u64 msg_addr;
 	bool has_upper;
 	int ret;
 
Quoted 8 lines
Quoted 6 lines

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 31

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +3 -0
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+

You could probably move this hunk below the test for msi_cap to save some cycles.

Sorry, I didn't understand the means, please explain it detailly, thanks a lot, ^_^

If you insert the call to func_conf_select *after* the test for !msi_cap below - then in the case where msi_cap is NULL then you will save some CPU cycles by not bothering to call func_conf_select.

Quoted 123 lines
Quoted 52 lines

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct

Quoted 35 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -5
 	if (!ep->msi_cap)
 		return -EINVAL;
 
 	/* Raise MSI per the PCI Local Bus Specification Revision 3.0, 6.8.1. */
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	msg_ctrl = dw_pcie_readw_dbi(pci, reg);
 	has_upper = !!(msg_ctrl & PCI_MSI_FLAGS_64BIT);
-	reg = ep->msi_cap + PCI_MSI_ADDRESS_LO;
+	reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_LO;
 	msg_addr_lower = dw_pcie_readl_dbi(pci, reg);
 	if (has_upper) {
-		reg = ep->msi_cap + PCI_MSI_ADDRESS_HI;
+		reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_HI;
 		msg_addr_upper = dw_pcie_readl_dbi(pci, reg);
-		reg = ep->msi_cap + PCI_MSI_DATA_64;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_64;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	} else {
 		msg_addr_upper = 0;
-		reg = ep->msi_cap + PCI_MSI_DATA_32;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_32;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	}
 	aligned_offset = msg_addr_lower & (epc->mem->page_size - 1);
drivers/pci/controller/dwc/pcie-designware.c +0 -0
index 7d25102..305e73d 100644
@@ -158,9 +158,10 @@ static void dw_pcie_writel_ob_unroll(struct

dw_pcie *pci, u32 index, u32 reg,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct · line 160

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -1
 	dw_pcie_writel_atu(pci, offset + reg, val);  }
 
-static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int

index,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -2
-					     int type, u64 cpu_addr,
-					     u64 pci_addr, u32 size)
+static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, u8

func_no,

drivers/pci/controller/dwc/pcie-designware.c static void

Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware.c +3 -0
+					     int index, int type,
+					     u64 cpu_addr, u64 pci_addr,
+					     u32 size)
 {
 	u32 retries, val;
 
@@ -175,7 +176,7 @@ static void

dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, · line 179

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
 				 upper_32_bits(pci_addr));
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1,
-				 type);
+				 type | PCIE_ATU_FUNC_NUM(func_no));

Much better :)

Do you mean that use the expression "a? b:c"

Quoted 44 lines

drivers/pci/controller/dwc/pcie-designware.c static void

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 	dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
 				 PCIE_ATU_ENABLE);
 
@@ -194,8 +195,9 @@ static void

dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -2
 	dev_err(pci->dev, "Outbound iATU is not being enabled\n");  }
 
-void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
-			       u64 cpu_addr, u64 pci_addr, u32 size)
+static void __dw_pcie_prog_outbound_atu(struct dw_pcie *pci, u8

func_no,

drivers/pci/controller/dwc/pcie-designware.c void dw_pcie_prog_outbound_atu(struct dw_pcie

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -0
+					int index, int type, u64 cpu_addr,
+					u64 pci_addr, u32 size)
 {
 	u32 retries, val;
 
@@ -203,8 +205,8 @@ void dw_pcie_prog_outbound_atu(struct dw_pcie

*pci, int index, int type,

Quoted 18 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -2
 		cpu_addr = pci->ops->cpu_addr_fixup(pci, cpu_addr);
 
 	if (pci->iatu_unroll_enabled) {
-		dw_pcie_prog_outbound_atu_unroll(pci, index, type, cpu_addr,
-						 pci_addr, size);
+		dw_pcie_prog_outbound_atu_unroll(pci, func_no, index, type,
+						 cpu_addr, pci_addr, size);
 		return;
 	}
 
drivers/pci/controller/dwc/pcie-designware.h +0 -0
index ffed084..a0fdbf7 100644

drivers/pci/controller/dwc/pcie-designware.h line 74

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -71,9 +71,11 @@
 #define PCIE_ATU_TYPE_IO		0x2
 #define PCIE_ATU_TYPE_CFG0		0x4
 #define PCIE_ATU_TYPE_CFG1		0x5
+#define PCIE_ATU_FUNC_NUM(pf)           (pf << 20)

"Macro argument 'pf' may be better as '(pf)' to avoid precedence issues"

Quoted 16 lines

drivers/pci/controller/dwc/pcie-designware.h struct dw_pcie_ep_ops { · line 203

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware.h +2 -0
 #define PCIE_ATU_CR2			0x908
 #define PCIE_ATU_ENABLE			BIT(31)
 #define PCIE_ATU_BAR_MODE_ENABLE	BIT(30)
+#define PCIE_ATU_FUNC_NUM_MATCH_EN      BIT(19)
 #define PCIE_ATU_LOWER_BASE		0x90C
 #define PCIE_ATU_UPPER_BASE		0x910
 #define PCIE_ATU_LIMIT			0x914
@@ -197,6 +199,7 @@ struct dw_pcie_ep_ops {
 	int	(*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
 			     enum pci_epc_irq_type type, u16 interrupt_num);
 	const struct pci_epc_features* (*get_features)(struct dw_pcie_ep
 *ep);
+	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8 func_no);

Given that this function will return an offset, I'm not sure the name you have is suitable. Something like get_pf_offset or similar is more descriptive.

Quoted 9 lines

As above explain, my initial view is that this function can return 0 or offset depends on the platform implement mechanism, so I named it func_conf_select, I think add a comment for this function, like this:
/*
* provide a method to implement the method of different func config space access,
* if use offset method, return the offset from dbi_base, if your register method, implement
* the code in this callback function and return 0.
*/
How about it?

This means that func_conf_select can never (easily) indicate an error to the caller as this would change the offset. Where func_conf_select doesn't change the offset there probably isn't much else it can do instead (unless it was responsible for doing the write as well). So I'm not sure how well this approach works.

Thanks,

Andrew Murray

Quoted 28 lines
Quoted 28 lines

Thanks,

Andrew Murray

drivers/pci/controller/dwc/pcie-designware.h int dw_pcie_wait_for_link(struct dw_pcie *pci); · line 271

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware.h +0 -0
 };
 

struct dw_pcie_ep {

drivers/pci/controller/dwc/pcie-designware.h +1 -2
@@ -265,8 +268,12 @@ int dw_pcie_wait_for_link(struct dw_pcie *pci);
 void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
 			       int type, u64 cpu_addr, u64 pci_addr,
 			       u32 size);
-int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
-			     u64 cpu_addr, enum dw_pcie_as_type as_type);
+void dw_pcie_prog_ep_outbound_atu(struct dw_pcie *pci, u8 func_no, int

index,

Quoted 11 lines
drivers/pci/controller/dwc/pcie-designware.h +5 -1
+				  int type, u64 cpu_addr, u64 pci_addr,
+				  u32 size);
+int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, u8 func_no, int index,
+			     int bar, u64 cpu_addr,
+			     enum dw_pcie_as_type as_type);
 void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
 			 enum dw_pcie_region_type type);
 void dw_pcie_setup(struct dw_pcie *pci);
--

2.9.5

#49 lore raw
Quoted 106 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月27日 21:11
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; M.h. Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 01/10] PCI: designware-ep: Add multiple PFs support for DWC

Quoted 9 lines · Xiaowei Bao
Quoted 9 lines

-----Original Message-----
From: Andrew Murray <[email protected]>
Sent: 2019年8月23日 21:25
To: Xiaowei Bao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Leo Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];

M.h.

Quoted 22 lines
Quoted 22 lines

Lian <[email protected]>; Mingkai Hu <[email protected]>; Roy Zang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 01/10] PCI: designware-ep: Add multiple PFs support for DWC

Quoted 3 lines · Xiaowei Bao

Add multiple PFs support for DWC, different PF have different config space we use pf-offset property which get from the DTS to access the different pF config space.

It looks like you're missing a --cover-letter again.

Quoted 7 lines

---
v2:
- Remove duplicate redundant code.
- Reimplement the PF config space access way.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
 drivers/pci/controller/dwc/pcie-designware-ep.c | 122

++++++++++++++++--------

Quoted 1 line
 drivers/pci/controller/dwc/pcie-designware.c    |  59

++++++++----

Quoted 9 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep

Quoted 9 lines
 drivers/pci/controller/dwc/pcie-designware.h    |  11 ++-
 3 files changed, 134 insertions(+), 58 deletions(-)
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
index 2bf5a35..3e2b740 100644
@@ -19,12 +19,17 @@ void dw_pcie_ep_linkup(struct dw_pcie_ep

*ep)

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -1
 	pci_epc_linkup(epc);
 }
 
-static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum

pci_barno

bar,

Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
-				   int flags)
+static void __dw_pcie_ep_reset_bar(struct dw_pcie *pci, u8 func_no,
+				   enum pci_barno bar, int flags)
 {
 	u32 reg;
+	unsigned int func_offset = 0;
+	struct dw_pcie_ep *ep = &pci->ep;
Quoted 10 lines
Quoted 10 lines

drivers/pci/controller/dwc/pcie-designware-ep.c void dw_pcie_ep_linkup(struct dw_pcie_ep *ep) · line 32

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -1
-	reg = PCI_BASE_ADDRESS_0 + (4 * bar);
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+
+	reg = func_offset + PCI_BASE_ADDRESS_0 + (4 * bar);

This pattern of checking if func_conf_select exists and using it to get an offset is repeated a lot throughout this file. You could move this functionality into a new function (similar to dw_pcie_read_dbi etc). Or perhaps a new variant of dw_pcie_writel_ should be created that

writes takes a func_no argument.

Quoted 8 lines

Thanks for your comments, I thought about this method before, but there is a issue about the method of access the different func config space, due to our platform use this method that different func have different offset from dbi_base to access the different config space, but others platform maybe use the way that write a register to implement different func config space access, so I think reserve a callback function

My point here was really to move out duplicated code to its own small function.
I wasn't making any comment about (removing) the callback, just that the test and callback could be in one function.

Quoted 3 lines

to different platform to implement the own method, my point is that, if use register method they can implement the code in this function and return offset is 0, if use offset method, they can return the offset value

Quoted 8 lines

which can be use by dw_pcie_ep driver.

By the way, I haven't looked to see how many of the dw_pcie_write_xxx functions would benefit from a func_no argument - if there were many calls to dw_pcie_write_xxx that all used a reg value originated from func_conf_select then an approach similar to the implementation of dw_pcie_write_dbi could probably be justified (i.e. rather than change the value of reg) for writing to functions.

I think you mean that move the if (ep->ops->func_conf_select) func_offset = ep->ops->func_conf_select(ep, func_no); to a new function, I will modify it in next version patch, thanks a lot.

Thanks
Xiaowei

Quoted 64 lines
Quoted 38 lines
Quoted 38 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_map_addr(struct pci_epc

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	dw_pcie_dbi_ro_wr_en(pci);
 	dw_pcie_writel_dbi2(pci, reg, 0x0);
 	dw_pcie_writel_dbi(pci, reg, 0x0);
@@ -235,7 +257,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc

*epc, u8 func_no,

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +2 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-	ret = dw_pcie_ep_outbound_atu(ep, addr, pci_addr, size);
+	ret = dw_pcie_ep_outbound_atu(ep, func_no, addr, pci_addr,
+size);
 	if (ret) {
 		dev_err(pci->dev, "Failed to enable address\n");
 		return ret;
@@ -249,11 +271,15 @@ static int dw_pcie_ep_get_msi(struct pci_epc

*epc, u8 func_no)

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no) · line 282

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;

This makes me nervous.

Quoted 4 lines
Quoted 4 lines

From a PCI viewpoint, each function has it's own capability structure and within each function there may exist a MSI capability. Yet what we're doing here is using dw_pcie_ep_find_capability to get the list of capabilities for function 0, and then applying offsets from that for

subsequent functions. I.e.

Quoted 6 lines
Quoted 6 lines

we're applying DW specific knowledge to find the correct capability, rather than following the general PCI approach.

I think the above hunk shouldn't be required - but instead dw_pcie_ep_find_capability is updated to take a func_no parameter.

Quoted 6 lines
Quoted 1 line

Have I understood this correctly?

Yes, this is a issue, I think the different func maybe have different capability, but the dw_pcie_ep_find_capability function is called by dw_pcie_ep_init function, we can't add func_no parameter to dw_pcie_ep_find_capability,

Why not?

Given that 'struct dw_pcie' represents a controller - and thus potentially multiple functions - then the _find_capability function should be able to provide the correct offset for the given function. Surely it needs to know which function number? Unless there is some reason why we can assume that all functions share the same capability offset.

Quoted 5 lines

Also the 'struct dw_pcie_ep' which represents an endpoint controller - this has msi_cap and msix_cap fields - given this may be a multifunction device what do these fields actually refer to?

Perhaps Jungoo/Gustavo can comment.

I have two method to fix this issue, define the msi_cap to *msi_cap, msi_cap[0] indicate func0, msi_cap[1] indicate func1..., like this:
+ for (func_no = 0; func_no < epc->max_functions; func_no++) {
+ ep->msi_cap[func_no] =
+ dw_pcie_ep_find_capability(pci, func_no,
+ PCI_CAP_ID_MSI);
+ ep->msix_cap[func_no] =
+ dw_pcie_ep_find_capability(pci, func_no,
+ PCI_CAP_ID_MSIX);
+ }
But in Layerscape EP driver, we can't set the msi_capable of pci_epc_features struct by ep->msix_cap, this is not correct, unless we assume if msi_cap[0] is 1, all function will support the MSI feature. and we can return error from the get_msi or set_msi function. I think this is the simplest way in current EP framework.

Another method is that add a callback function in pci_epc_ops, don't use the pci_epc_features mode, but that's a big change, we need to implement the other platform callback function like rickchip and so on.

Thanks
Xiaowei

Quoted 90 lines
Quoted 23 lines

I will try to fix it use a new patch, I think move this function to ep_init callback function If better, thanks.

Quoted 17 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_set_msi(struct pci_epc

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSI_FLAGS_ENABLE))
 		return -EINVAL;
@@ -268,11 +294,15 @@ static int dw_pcie_ep_set_msi(struct pci_epc

*epc, u8 func_no, u8 interrupts)

Quoted 11 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -0
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msi_cap)
 		return -EINVAL;
 
Quoted 6 lines
Quoted 6 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 interrupts)

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +2 -1
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSI_FLAGS_QMASK;
 	val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK; @@ -288,11
+318,15 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8

func_no)

Quoted 60 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -0
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no) · line 329

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;

Same for MSIX.

Yes.

Quoted 41 lines
Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	val = dw_pcie_readw_dbi(pci, reg);
 	if (!(val & PCI_MSIX_FLAGS_ENABLE))
 		return -EINVAL;
@@ -307,11 +341,15 @@ static int dw_pcie_ep_set_msix(struct

pci_epc

*epc, u8 func_no, u16 interrupts)

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct

Quoted 17 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -1
 	struct dw_pcie_ep *ep = epc_get_drvdata(epc);
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	u32 val, reg;
+	unsigned int func_offset = 0;
+
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
 
 	if (!ep->msix_cap)
 		return -EINVAL;
 
-	reg = ep->msix_cap + PCI_MSIX_FLAGS;
+	reg = ep->msix_cap + func_offset + PCI_MSIX_FLAGS;
 	val = dw_pcie_readw_dbi(pci, reg);
 	val &= ~PCI_MSIX_FLAGS_QSIZE;
 	val |= interrupts;
@@ -398,29 +436,33 @@ int dw_pcie_ep_raise_msi_irq(struct

dw_pcie_ep *ep, u8 func_no,

drivers/pci/controller/dwc/pcie-designware-ep.c int dw_pcie_ep_raise_msi_irq(struct dw_pcie_ep *ep, u8 func_no, · line 448

Quoted 13 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +4 -0
 	struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 	struct pci_epc *epc = ep->epc;
 	unsigned int aligned_offset;
+	unsigned int func_offset = 0;
 	u16 msg_ctrl, msg_data;
 	u32 msg_addr_lower, msg_addr_upper, reg;
 	u64 msg_addr;
 	bool has_upper;
 	int ret;
 
+	if (ep->ops->func_conf_select)
+		func_offset = ep->ops->func_conf_select(ep, func_no);
+

You could probably move this hunk below the test for msi_cap to save some cycles.

Quoted 6 lines
Quoted 2 lines

Sorry, I didn't understand the means, please explain it detailly, thanks a lot, ^_^

If you insert the call to func_conf_select *after* the test for !msi_cap below - then in the case where msi_cap is NULL then you will save some CPU cycles by not bothering to call func_conf_select.

Got it, thanks a lot. ^_^

Thanks
Xiaowei

Quoted 147 lines
Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware-ep.c static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no)

Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +0 -0
 	if (!ep->msi_cap)
 		return -EINVAL;
 
 	/* Raise MSI per the PCI Local Bus Specification Revision 3.0, 6.8.1.

*/

Quoted 47 lines
Quoted 47 lines

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct

Quoted 30 lines
drivers/pci/controller/dwc/pcie-designware-ep.c +5 -5
-	reg = ep->msi_cap + PCI_MSI_FLAGS;
+	reg = ep->msi_cap + func_offset + PCI_MSI_FLAGS;
 	msg_ctrl = dw_pcie_readw_dbi(pci, reg);
 	has_upper = !!(msg_ctrl & PCI_MSI_FLAGS_64BIT);
-	reg = ep->msi_cap + PCI_MSI_ADDRESS_LO;
+	reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_LO;
 	msg_addr_lower = dw_pcie_readl_dbi(pci, reg);
 	if (has_upper) {
-		reg = ep->msi_cap + PCI_MSI_ADDRESS_HI;
+		reg = ep->msi_cap + func_offset + PCI_MSI_ADDRESS_HI;
 		msg_addr_upper = dw_pcie_readl_dbi(pci, reg);
-		reg = ep->msi_cap + PCI_MSI_DATA_64;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_64;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	} else {
 		msg_addr_upper = 0;
-		reg = ep->msi_cap + PCI_MSI_DATA_32;
+		reg = ep->msi_cap + func_offset + PCI_MSI_DATA_32;
 		msg_data = dw_pcie_readw_dbi(pci, reg);
 	}
 	aligned_offset = msg_addr_lower & (epc->mem->page_size - 1);
drivers/pci/controller/dwc/pcie-designware.c +0 -0
index 7d25102..305e73d 100644
@@ -158,9 +158,10 @@ static void dw_pcie_writel_ob_unroll(struct

dw_pcie *pci, u32 index, u32 reg,

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -1
 	dw_pcie_writel_atu(pci, offset + reg, val);  }
 
-static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci,

int

index,

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -2
-					     int type, u64 cpu_addr,
-					     u64 pci_addr, u32 size)
+static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci,
+u8

func_no,

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.c +3 -0
+					     int index, int type,
+					     u64 cpu_addr, u64 pci_addr,
+					     u32 size)
 {
 	u32 retries, val;
Quoted 3 lines
Quoted 3 lines

drivers/pci/controller/dwc/pcie-designware.c static void

Quoted 1 line
drivers/pci/controller/dwc/pcie-designware.c +0 -0
@@ -175,7 +176,7 @@ static void

dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

Quoted 1 line
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 	dw_pcie_writel_ob_unroll(pci, index,

PCIE_ATU_UNR_UPPER_TARGET,

Quoted 2 lines
Quoted 2 lines

drivers/pci/controller/dwc/pcie-designware.c static void · line 178

Quoted 2 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 				 upper_32_bits(pci_addr));
 	dw_pcie_writel_ob_unroll(pci, index,

PCIE_ATU_UNR_REGION_CTRL1,

Quoted 9 lines
Quoted 4 lines

drivers/pci/controller/dwc/pcie-designware.c static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, · line 179

Quoted 2 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
-				 type);
+				 type | PCIE_ATU_FUNC_NUM(func_no));

Much better :)

Do you mean that use the expression "a? b:c"

Quoted 2 lines
Quoted 2 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 	dw_pcie_writel_ob_unroll(pci, index,

PCIE_ATU_UNR_REGION_CTRL2,

Quoted 7 lines
Quoted 7 lines

drivers/pci/controller/dwc/pcie-designware.c static void

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -0
 				 PCIE_ATU_ENABLE);
 
@@ -194,8 +195,9 @@ static void

dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.c +0 -1
 	dev_err(pci->dev, "Outbound iATU is not being enabled\n");  }
 
-void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int

type,

Quoted 9 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-designware.c static void · line 197

Quoted 2 lines
drivers/pci/controller/dwc/pcie-designware.c +1 -1
-			       u64 cpu_addr, u64 pci_addr, u32 size)
+static void __dw_pcie_prog_outbound_atu(struct dw_pcie *pci, u8

func_no,

drivers/pci/controller/dwc/pcie-designware.c void dw_pcie_prog_outbound_atu(struct

Quoted 6 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -0
+					int index, int type, u64 cpu_addr,
+					u64 pci_addr, u32 size)
 {
 	u32 retries, val;
 
@@ -203,8 +205,8 @@ void dw_pcie_prog_outbound_atu(struct

dw_pcie

Quoted 35 lines
Quoted 35 lines

*pci, int index, int type,

Quoted 18 lines
drivers/pci/controller/dwc/pcie-designware.c +2 -2
 		cpu_addr = pci->ops->cpu_addr_fixup(pci, cpu_addr);
 
 	if (pci->iatu_unroll_enabled) {
-		dw_pcie_prog_outbound_atu_unroll(pci, index, type, cpu_addr,
-						 pci_addr, size);
+		dw_pcie_prog_outbound_atu_unroll(pci, func_no, index, type,
+						 cpu_addr, pci_addr, size);
 		return;
 	}
 
drivers/pci/controller/dwc/pcie-designware.h +0 -0
index ffed084..a0fdbf7 100644

drivers/pci/controller/dwc/pcie-designware.h line 74

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -71,9 +71,11 @@
 #define PCIE_ATU_TYPE_IO		0x2
 #define PCIE_ATU_TYPE_CFG0		0x4
 #define PCIE_ATU_TYPE_CFG1		0x5
+#define PCIE_ATU_FUNC_NUM(pf)           (pf << 20)

"Macro argument 'pf' may be better as '(pf)' to avoid precedence issues"

Quoted 9 lines
drivers/pci/controller/dwc/pcie-designware.h +1 -0
 #define PCIE_ATU_CR2			0x908
 #define PCIE_ATU_ENABLE			BIT(31)
 #define PCIE_ATU_BAR_MODE_ENABLE	BIT(30)
+#define PCIE_ATU_FUNC_NUM_MATCH_EN      BIT(19)
 #define PCIE_ATU_LOWER_BASE		0x90C
 #define PCIE_ATU_UPPER_BASE		0x910
 #define PCIE_ATU_LIMIT			0x914
@@ -197,6 +199,7 @@ struct dw_pcie_ep_ops {
 	int	(*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
Quoted 8 lines
Quoted 8 lines

drivers/pci/controller/dwc/pcie-designware.h struct dw_pcie_ep_ops { · line 204

Quoted 5 lines
drivers/pci/controller/dwc/pcie-designware.h +2 -0
 			     enum pci_epc_irq_type type, u16 interrupt_num);
 	const struct pci_epc_features* (*get_features)(struct dw_pcie_ep
 *ep);
+	unsigned int (*func_conf_select)(struct dw_pcie_ep *ep, u8
+func_no);

Given that this function will return an offset, I'm not sure the name you have is suitable. Something like get_pf_offset or similar is more

descriptive.

Quoted 12 lines

As above explain, my initial view is that this function can return 0 or offset depends on the platform implement mechanism, so I named it func_conf_select, I think add a comment for this function, like this:
/*
* provide a method to implement the method of different func config
space access,
* if use offset method, return the offset from dbi_base, if your
register method, implement
* the code in this callback function and return 0.
*/
How about it?

Quoted 5 lines

This means that func_conf_select can never (easily) indicate an error to the caller as this would change the offset. Where func_conf_select doesn't change the offset there probably isn't much else it can do instead (unless it was responsible for doing the write as well). So I'm not sure how well this approach works.

We can use int type of this function and return a negative value when a error occurred, that is to say:
if(func_no && !pcie->drvdata->func_offset)

	return -1;

but we need to set a flag to differentiate the method of config space access, that is we can return -1 in func_offset method, another method we only return 0.

Thanks
Xiaowei

Quoted 36 lines

Thanks,

Andrew Murray

Quoted 18 lines
Quoted 18 lines

Thanks,

Andrew Murray

drivers/pci/controller/dwc/pcie-designware.h int dw_pcie_wait_for_link(struct dw_pcie · line 272

Quoted 11 lines
drivers/pci/controller/dwc/pcie-designware.h +2 -2
 };
 
 struct dw_pcie_ep {
@@ -265,8 +268,12 @@ int dw_pcie_wait_for_link(struct dw_pcie
 *pci); void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
 			       int type, u64 cpu_addr, u64 pci_addr,
 			       u32 size);
-int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
-			     u64 cpu_addr, enum dw_pcie_as_type as_type);
+void dw_pcie_prog_ep_outbound_atu(struct dw_pcie *pci, u8
+func_no, int

index,

Quoted 3 lines
Quoted 3 lines

drivers/pci/controller/dwc/pcie-designware.h int dw_pcie_wait_for_link(struct dw_pcie *pci);

Quoted 3 lines
drivers/pci/controller/dwc/pcie-designware.h +3 -0
+				  int type, u64 cpu_addr, u64 pci_addr,
+				  u32 size);
+int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, u8 func_no, int

index,

Quoted 4 lines
Quoted 4 lines

drivers/pci/controller/dwc/pcie-designware.h int dw_pcie_wait_for_link(struct dw_pcie *pci);

Quoted 4 lines
drivers/pci/controller/dwc/pcie-designware.h +2 -0
+			     int bar, u64 cpu_addr,
+			     enum dw_pcie_as_type as_type);
 void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
 			 enum dw_pcie_region_type type);  void

dw_pcie_setup(struct

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

dw_pcie *pci);
--
2.9.5