build: add integration for managing opkg package feed keys
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.18 / 037-MIPS-BCM47XX-Support-SPROM-prefixes-for-PCI-devices.patch
1 From 9a6a2b96dfd8b01336f8519a5be7fb353cfa62fb Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Sat, 14 Mar 2015 17:55:54 +0100
4 Subject: [PATCH] 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 Cc: linux-mips@linux-mips.org
13 Cc: Hauke Mehrtens <hauke@hauke-m.de>
14 Patchwork: https://patchwork.linux-mips.org/patch/9552/
15 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
16 ---
17 arch/mips/bcm47xx/sprom.c | 33 +++++++++++++++++++++++++++++++++
18 1 file changed, 33 insertions(+)
19
20 diff --git a/arch/mips/bcm47xx/sprom.c b/arch/mips/bcm47xx/sprom.c
21 index 2eff7fe..eff9205 100644
22 --- a/arch/mips/bcm47xx/sprom.c
23 +++ b/arch/mips/bcm47xx/sprom.c
24 @@ -836,6 +836,38 @@ static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
25 #endif
26
27 #if defined(CONFIG_BCM47XX_BCMA)
28 +/*
29 + * Having many NVRAM entries for PCI devices led to repeating prefixes like
30 + * pci/1/1/ all the time and wasting flash space. So at some point Broadcom
31 + * decided to introduce prefixes like 0: 1: 2: etc.
32 + * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0:
33 + * instead of pci/2/1/.
34 + */
35 +static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
36 +{
37 + size_t prefix_len = strlen(prefix);
38 + size_t short_len = prefix_len - 1;
39 + char nvram_var[10];
40 + char buf[20];
41 + int i;
42 +
43 + /* Passed prefix has to end with a slash */
44 + if (prefix_len <= 0 || prefix[prefix_len - 1] != '/')
45 + return;
46 +
47 + for (i = 0; i < 3; i++) {
48 + if (snprintf(nvram_var, sizeof(nvram_var), "devpath%d", i) <= 0)
49 + continue;
50 + if (bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf)) < 0)
51 + continue;
52 + if (!strcmp(buf, prefix) ||
53 + (short_len && strlen(buf) == short_len && !strncmp(buf, prefix, short_len))) {
54 + snprintf(prefix, prefix_size, "%d:", i);
55 + return;
56 + }
57 + }
58 +}
59 +
60 static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
61 {
62 char prefix[10];
63 @@ -847,6 +879,7 @@ static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
64 snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
65 bus->host_pci->bus->number + 1,
66 PCI_SLOT(bus->host_pci->devfn));
67 + bcm47xx_sprom_apply_prefix_alias(prefix, sizeof(prefix));
68 bcm47xx_fill_sprom(out, prefix, false);
69 return 0;
70 case BCMA_HOSTTYPE_SOC:
71 --
72 1.8.4.5
73