4a82b50dc7da85ab301549d224d2466ae68e079d
[openwrt/openwrt.git] / target / linux / brcm47xx / patches-3.18 / 100-MIPS-BCM47XX-Support-SPROM-prefixes-for-PCI-devices.patch
1 From f3505e9283290dd9bb6197bd485e6cbfb5beaf7e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 11 Mar 2015 19:24:42 +0100
4 Subject: [PATCH V2] MIPS: BCM47XX: Support SPROM prefixes for PCI devices
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Support parsing SPROMs with prefixes defined like devpath1=pci/1/1
10
11 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
12 ---
13 V2: I've noticed that Buffalo WZR-1750 uses an extra slash in NVRAM
14 devpaths entries. I added support for them and updated comment.
15 This adds one line over 80 chars, but it improved condition
16 readability so I think it's alright there.
17 ---
18 arch/mips/bcm47xx/sprom.c | 33 +++++++++++++++++++++++++++++++++
19 1 file changed, 33 insertions(+)
20
21 diff --git a/arch/mips/bcm47xx/sprom.c b/arch/mips/bcm47xx/sprom.c
22 index 290309e..5d32afc 100644
23 --- a/arch/mips/bcm47xx/sprom.c
24 +++ b/arch/mips/bcm47xx/sprom.c
25 @@ -822,6 +822,38 @@ static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
26 #endif
27
28 #if defined(CONFIG_BCM47XX_BCMA)
29 +/*
30 + * Having many NVRAM entries for PCI devices led to repeating prefixes like
31 + * pci/1/1/ all the time and wasting flash space. So at some point Broadcom
32 + * decided to introduce prefixes like 0: 1: 2: etc.
33 + * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0:
34 + * instead of pci/2/1/.
35 + */
36 +static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
37 +{
38 + size_t prefix_len = strlen(prefix);
39 + size_t short_len = prefix_len - 1;
40 + char nvram_var[10];
41 + char buf[20];
42 + int i;
43 +
44 + /* Passed prefix has to end with a slash */
45 + if (prefix_len <= 0 || prefix[prefix_len - 1] != '/')
46 + return;
47 +
48 + for (i = 0; i < 3; i++) {
49 + if (snprintf(nvram_var, sizeof(nvram_var), "devpath%d", i) <= 0)
50 + continue;
51 + if (bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf)) < 0)
52 + continue;
53 + if (!strcmp(buf, prefix) ||
54 + (short_len && strlen(buf) == short_len && !strncmp(buf, prefix, short_len))) {
55 + snprintf(prefix, prefix_size, "%d:", i);
56 + return;
57 + }
58 + }
59 +}
60 +
61 static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
62 {
63 char prefix[10];
64 @@ -833,6 +865,7 @@ static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
65 snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
66 bus->host_pci->bus->number + 1,
67 PCI_SLOT(bus->host_pci->devfn));
68 + bcm47xx_sprom_apply_prefix_alias(prefix, sizeof(prefix));
69 bcm47xx_fill_sprom(out, prefix, false);
70 return 0;
71 case BCMA_HOSTTYPE_SOC:
72 --
73 1.8.4.5
74