Skip to content

Commit ea1d379

Browse files
Ley Foon Tanbjorn-helgaas
authored andcommitted
PCI: altera: Check TLP completion status
Check TLP packet successful completion status. This fix the issue when accessing multi-function devices in enumeration process, TLP will return error when accessing non-exist function number. Returns PCI error code instead of generic errno. Tested on Ethernet adapter card with multi-functions. [bhelgaas: simplify completion status checking code] Signed-off-by: Ley Foon Tan <lftan@altera.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 23ec567 commit ea1d379

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/pci/host/pcie-altera.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define TLP_CFG_DW2(bus, devfn, offset) \
5656
(((bus) << 24) | ((devfn) << 16) | (offset))
5757
#define TLP_REQ_ID(bus, devfn) (((bus) << 8) | (devfn))
58+
#define TLP_COMP_STATUS(s) (((s) >> 12) & 7)
5859
#define TLP_HDR_SIZE 3
5960
#define TLP_LOOP 500
6061
#define RP_DEVFN 0
@@ -171,6 +172,7 @@ static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
171172
bool sop = 0;
172173
u32 ctrl;
173174
u32 reg0, reg1;
175+
u32 comp_status = 1;
174176

175177
/*
176178
* Minimum 2 loops to read TLP headers and 1 loop to read data
@@ -182,19 +184,25 @@ static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
182184
reg0 = cra_readl(pcie, RP_RXCPL_REG0);
183185
reg1 = cra_readl(pcie, RP_RXCPL_REG1);
184186

185-
if (ctrl & RP_RXCPL_SOP)
187+
if (ctrl & RP_RXCPL_SOP) {
186188
sop = true;
189+
comp_status = TLP_COMP_STATUS(reg1);
190+
}
187191

188192
if (ctrl & RP_RXCPL_EOP) {
193+
if (comp_status)
194+
return PCIBIOS_DEVICE_NOT_FOUND;
195+
189196
if (value)
190197
*value = reg0;
198+
191199
return PCIBIOS_SUCCESSFUL;
192200
}
193201
}
194202
udelay(5);
195203
}
196204

197-
return -ENOENT;
205+
return PCIBIOS_DEVICE_NOT_FOUND;
198206
}
199207

200208
static void tlp_write_packet(struct altera_pcie *pcie, u32 *headers,

0 commit comments

Comments
 (0)