Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1202175 > unrolled thread
| Started by | David Daney <ddaney.cavm@gmail.com> |
|---|---|
| First post | 2015-08-07 02:40 +0200 |
| Last post | 2015-08-08 02:40 +0200 |
| Articles | 14 — 8 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. David Daney <ddaney.cavm@gmail.com> - 2015-08-07 02:40 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Tomasz Nowicki <tomasz.nowicki@linaro.org> - 2015-08-07 10:10 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Robert Richter <robert.richter@caviumnetworks.com> - 2015-08-07 12:50 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Tomasz Nowicki <tomasz.nowicki@linaro.org> - 2015-08-07 13:10 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Tomasz Nowicki <tomasz.nowicki@linaro.org> - 2015-08-07 14:50 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. David Daney <ddaney@caviumnetworks.com> - 2015-08-07 18:50 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Arnd Bergmann <arnd@arndb.de> - 2015-08-08 13:30 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Mark Rutland <mark.rutland@arm.com> - 2015-08-07 16:10 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Mark Rutland <mark.rutland@arm.com> - 2015-08-07 20:00 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. "Rafael J. Wysocki" <rafael@kernel.org> - 2015-08-08 02:10 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. "Rafael J. Wysocki" <rafael@kernel.org> - 2015-08-08 02:30 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Mark Rutland <mark.rutland@arm.com> - 2015-08-07 20:00 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. Graeme Gregory <gg@slimlogic.co.uk> - 2015-08-07 17:00 +0200
Re: [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. "Rafael J. Wysocki" <rafael@kernel.org> - 2015-08-08 02:40 +0200
| From | David Daney <ddaney.cavm@gmail.com> |
|---|---|
| Date | 2015-08-07 02:40 +0200 |
| Subject | [PATCH 2/2] net, thunder, bgx: Add support for ACPI binding. |
| Message-ID | <pUDRw-8r8-5@gated-at.bofh.it> |
From: David Daney <david.daney@cavium.com>
Find out which PHYs belong to which BGX instance in the ACPI way.
Set the MAC address of the device as provided by ACPI tables. This is
similar to the implementation for devicetree in
of_get_mac_address(). The table is searched for the device property
entries "mac-address", "local-mac-address" and "address" in that
order. The address is provided in a u64 variable and must contain a
valid 6 bytes-len mac addr.
Based on code from: Narinder Dhillon <ndhillon@cavium.com>
Tomasz Nowicki <tomasz.nowicki@linaro.org>
Robert Richter <rrichter@cavium.com>
Signed-off-by: Tomasz Nowicki <tomasz.nowicki@linaro.org>
Signed-off-by: Robert Richter <rrichter@cavium.com>
Signed-off-by: David Daney <david.daney@cavium.com>
---
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 137 +++++++++++++++++++++-
1 file changed, 135 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index 615b2af..2056583 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -6,6 +6,7 @@
* as published by the Free Software Foundation.
*/
+#include <linux/acpi.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
@@ -26,7 +27,7 @@
struct lmac {
struct bgx *bgx;
int dmac;
- unsigned char mac[ETH_ALEN];
+ u8 mac[ETH_ALEN];
bool link_up;
int lmacid; /* ID within BGX */
int lmacid_bd; /* ID on board */
@@ -835,6 +836,133 @@ static void bgx_get_qlm_mode(struct bgx *bgx)
}
}
+#ifdef CONFIG_ACPI
+
+static int bgx_match_phy_id(struct device *dev, void *data)
+{
+ struct phy_device *phydev = to_phy_device(dev);
+ u32 *phy_id = data;
+
+ if (phydev->addr == *phy_id)
+ return 1;
+
+ return 0;
+}
+
+static const char * const addr_propnames[] = {
+ "mac-address",
+ "local-mac-address",
+ "address",
+};
+
+static int acpi_get_mac_address(struct acpi_device *adev, u8 *dst)
+{
+ const union acpi_object *prop;
+ u64 mac_val;
+ u8 mac[ETH_ALEN];
+ int i, j;
+ int ret;
+
+ for (i = 0; i < ARRAY_SIZE(addr_propnames); i++) {
+ ret = acpi_dev_get_property(adev, addr_propnames[i],
+ ACPI_TYPE_INTEGER, &prop);
+ if (ret)
+ continue;
+
+ mac_val = prop->integer.value;
+
+ if (mac_val & (~0ULL << 48))
+ continue; /* more than 6 bytes */
+
+ for (j = 0; j < ARRAY_SIZE(mac); j++)
+ mac[j] = (u8)(mac_val >> (8 * j));
+ if (!is_valid_ether_addr(mac))
+ continue;
+
+ memcpy(dst, mac, ETH_ALEN);
+
+ return 0;
+ }
+
+ return ret ? ret : -EINVAL;
+}
+
+static acpi_status bgx_acpi_register_phy(acpi_handle handle,
+ u32 lvl, void *context, void **rv)
+{
+ struct acpi_reference_args args;
+ const union acpi_object *prop;
+ struct bgx *bgx = context;
+ struct acpi_device *adev;
+ struct device *phy_dev;
+ u32 phy_id;
+
+ if (acpi_bus_get_device(handle, &adev))
+ goto out;
+
+ SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
+
+ acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
+
+ bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
+
+ if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
+ goto out;
+
+ if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
+ goto out;
+
+ phy_id = prop->integer.value;
+
+ phy_dev = bus_find_device(&mdio_bus_type, NULL, (void *)&phy_id,
+ bgx_match_phy_id);
+ if (!phy_dev)
+ goto out;
+
+ bgx->lmac[bgx->lmac_count].phydev = to_phy_device(phy_dev);
+out:
+ bgx->lmac_count++;
+ return AE_OK;
+}
+
+static acpi_status bgx_acpi_match_id(acpi_handle handle, u32 lvl,
+ void *context, void **ret_val)
+{
+ struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
+ struct bgx *bgx = context;
+ char bgx_sel[5];
+
+ snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
+ if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) {
+ pr_warn("Invalid link device\n");
+ return AE_OK;
+ }
+
+ if (strncmp(string.pointer, bgx_sel, 4))
+ return AE_OK;
+
+ acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
+ bgx_acpi_register_phy, NULL, bgx, NULL);
+
+ kfree(string.pointer);
+ return AE_CTRL_TERMINATE;
+}
+
+static int bgx_init_acpi_phy(struct bgx *bgx)
+{
+ acpi_get_devices(NULL, bgx_acpi_match_id, bgx, (void **)NULL);
+ return 0;
+}
+
+#else
+
+static int bgx_init_acpi_phy(struct bgx *bgx)
+{
+ return -ENODEV;
+}
+
+#endif /* CONFIG_ACPI */
+
#if IS_ENABLED(CONFIG_OF_MDIO)
static int bgx_init_of_phy(struct bgx *bgx)
@@ -882,7 +1010,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
static int bgx_init_phy(struct bgx *bgx)
{
- return bgx_init_of_phy(bgx);
+ int err = bgx_init_of_phy(bgx);
+
+ if (err != -ENODEV)
+ return err;
+
+ return bgx_init_acpi_phy(bgx);
}
static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Tomasz Nowicki <tomasz.nowicki@linaro.org> |
|---|---|
| Date | 2015-08-07 10:10 +0200 |
| Message-ID | <pUKT0-21E-7@gated-at.bofh.it> |
| In reply to | #1202175 |
On 07.08.2015 02:33, David Daney wrote:
> From: David Daney <david.daney@cavium.com>
>
> Find out which PHYs belong to which BGX instance in the ACPI way.
>
> Set the MAC address of the device as provided by ACPI tables. This is
> similar to the implementation for devicetree in
> of_get_mac_address(). The table is searched for the device property
> entries "mac-address", "local-mac-address" and "address" in that
> order. The address is provided in a u64 variable and must contain a
> valid 6 bytes-len mac addr.
>
> Based on code from: Narinder Dhillon <ndhillon@cavium.com>
> Tomasz Nowicki <tomasz.nowicki@linaro.org>
> Robert Richter <rrichter@cavium.com>
>
> Signed-off-by: Tomasz Nowicki <tomasz.nowicki@linaro.org>
> Signed-off-by: Robert Richter <rrichter@cavium.com>
> Signed-off-by: David Daney <david.daney@cavium.com>
> ---
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 137 +++++++++++++++++++++-
> 1 file changed, 135 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> index 615b2af..2056583 100644
> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> @@ -6,6 +6,7 @@
> * as published by the Free Software Foundation.
> */
>
> +#include <linux/acpi.h>
> #include <linux/module.h>
> #include <linux/interrupt.h>
> #include <linux/pci.h>
> @@ -26,7 +27,7 @@
> struct lmac {
> struct bgx *bgx;
> int dmac;
> - unsigned char mac[ETH_ALEN];
> + u8 mac[ETH_ALEN];
> bool link_up;
> int lmacid; /* ID within BGX */
> int lmacid_bd; /* ID on board */
> @@ -835,6 +836,133 @@ static void bgx_get_qlm_mode(struct bgx *bgx)
> }
> }
>
> +#ifdef CONFIG_ACPI
> +
> +static int bgx_match_phy_id(struct device *dev, void *data)
> +{
> + struct phy_device *phydev = to_phy_device(dev);
> + u32 *phy_id = data;
> +
> + if (phydev->addr == *phy_id)
> + return 1;
> +
> + return 0;
> +}
> +
> +static const char * const addr_propnames[] = {
> + "mac-address",
> + "local-mac-address",
> + "address",
> +};
> +
> +static int acpi_get_mac_address(struct acpi_device *adev, u8 *dst)
> +{
> + const union acpi_object *prop;
> + u64 mac_val;
> + u8 mac[ETH_ALEN];
> + int i, j;
> + int ret;
> +
> + for (i = 0; i < ARRAY_SIZE(addr_propnames); i++) {
> + ret = acpi_dev_get_property(adev, addr_propnames[i],
> + ACPI_TYPE_INTEGER, &prop);
> + if (ret)
> + continue;
> +
> + mac_val = prop->integer.value;
> +
> + if (mac_val & (~0ULL << 48))
> + continue; /* more than 6 bytes */
> +
> + for (j = 0; j < ARRAY_SIZE(mac); j++)
> + mac[j] = (u8)(mac_val >> (8 * j));
> + if (!is_valid_ether_addr(mac))
> + continue;
> +
> + memcpy(dst, mac, ETH_ALEN);
> +
> + return 0;
> + }
> +
> + return ret ? ret : -EINVAL;
> +}
> +
> +static acpi_status bgx_acpi_register_phy(acpi_handle handle,
> + u32 lvl, void *context, void **rv)
> +{
> + struct acpi_reference_args args;
> + const union acpi_object *prop;
> + struct bgx *bgx = context;
> + struct acpi_device *adev;
> + struct device *phy_dev;
> + u32 phy_id;
> +
> + if (acpi_bus_get_device(handle, &adev))
> + goto out;
> +
> + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
> +
> + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
> +
> + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
> +
> + if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
> + goto out;
> +
> + if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
> + goto out;
> +
> + phy_id = prop->integer.value;
> +
> + phy_dev = bus_find_device(&mdio_bus_type, NULL, (void *)&phy_id,
> + bgx_match_phy_id);
> + if (!phy_dev)
> + goto out;
> +
> + bgx->lmac[bgx->lmac_count].phydev = to_phy_device(phy_dev);
> +out:
> + bgx->lmac_count++;
> + return AE_OK;
> +}
> +
> +static acpi_status bgx_acpi_match_id(acpi_handle handle, u32 lvl,
> + void *context, void **ret_val)
> +{
> + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
> + struct bgx *bgx = context;
> + char bgx_sel[5];
> +
> + snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
> + if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) {
> + pr_warn("Invalid link device\n");
> + return AE_OK;
> + }
> +
> + if (strncmp(string.pointer, bgx_sel, 4))
> + return AE_OK;
> +
> + acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
> + bgx_acpi_register_phy, NULL, bgx, NULL);
> +
> + kfree(string.pointer);
> + return AE_CTRL_TERMINATE;
> +}
> +
> +static int bgx_init_acpi_phy(struct bgx *bgx)
> +{
> + acpi_get_devices(NULL, bgx_acpi_match_id, bgx, (void **)NULL);
> + return 0;
> +}
> +
> +#else
> +
> +static int bgx_init_acpi_phy(struct bgx *bgx)
> +{
> + return -ENODEV;
> +}
> +
> +#endif /* CONFIG_ACPI */
> +
> #if IS_ENABLED(CONFIG_OF_MDIO)
>
> static int bgx_init_of_phy(struct bgx *bgx)
> @@ -882,7 +1010,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
>
> static int bgx_init_phy(struct bgx *bgx)
> {
> - return bgx_init_of_phy(bgx);
> + int err = bgx_init_of_phy(bgx);
> +
> + if (err != -ENODEV)
> + return err;
> +
> + return bgx_init_acpi_phy(bgx);
> }
>
If kernel can work with DT and ACPI (both compiled in), it should take
only one path instead of probing DT and ACPI sequentially. How about:
@@ -902,10 +925,9 @@ static int bgx_probe(struct pci_dev *pdev, const
struct pci_device_id *ent)
bgx_vnic[bgx->bgx_id] = bgx;
bgx_get_qlm_mode(bgx);
- snprintf(bgx_sel, 5, "bgx%d", bgx->bgx_id);
- np = of_find_node_by_name(NULL, bgx_sel);
- if (np)
- bgx_init_of(bgx, np);
+ err = acpi_disabled ? bgx_init_of_phy(bgx) : bgx_init_acpi_phy(bgx);
+ if (err)
+ goto err_enable;
bgx_init_hw(bgx);
Regards,
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Robert Richter <robert.richter@caviumnetworks.com> |
|---|---|
| Date | 2015-08-07 12:50 +0200 |
| Message-ID | <pUNnS-5sC-67@gated-at.bofh.it> |
| In reply to | #1202402 |
On 07.08.15 10:09:04, Tomasz Nowicki wrote:
> On 07.08.2015 02:33, David Daney wrote:
...
> >+#else
> >+
> >+static int bgx_init_acpi_phy(struct bgx *bgx)
> >+{
> >+ return -ENODEV;
> >+}
> >+
> >+#endif /* CONFIG_ACPI */
> >+
> > #if IS_ENABLED(CONFIG_OF_MDIO)
> >
> > static int bgx_init_of_phy(struct bgx *bgx)
> >@@ -882,7 +1010,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
> >
> > static int bgx_init_phy(struct bgx *bgx)
> > {
> >- return bgx_init_of_phy(bgx);
> >+ int err = bgx_init_of_phy(bgx);
> >+
> >+ if (err != -ENODEV)
> >+ return err;
> >+
> >+ return bgx_init_acpi_phy(bgx);
> > }
> >
>
> If kernel can work with DT and ACPI (both compiled in), it should take only
> one path instead of probing DT and ACPI sequentially. How about:
>
> @@ -902,10 +925,9 @@ static int bgx_probe(struct pci_dev *pdev, const struct
> pci_device_id *ent)
> bgx_vnic[bgx->bgx_id] = bgx;
> bgx_get_qlm_mode(bgx);
>
> - snprintf(bgx_sel, 5, "bgx%d", bgx->bgx_id);
> - np = of_find_node_by_name(NULL, bgx_sel);
> - if (np)
> - bgx_init_of(bgx, np);
> + err = acpi_disabled ? bgx_init_of_phy(bgx) : bgx_init_acpi_phy(bgx);
> + if (err)
> + goto err_enable;
>
> bgx_init_hw(bgx);
I would not pollute bgx_probe() with acpi and dt specifics, and instead
keep bgx_init_phy(). The typical design pattern for this is:
static int bgx_init_phy(struct bgx *bgx)
{
#ifdef CONFIG_ACPI
if (!acpi_disabled)
return bgx_init_acpi_phy(bgx);
#endif
return bgx_init_of_phy(bgx);
}
This adds acpi runtime detection (acpi=no), does not call dt code in
case of acpi, and saves the #else for bgx_init_acpi_phy().
-Robert
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Tomasz Nowicki <tomasz.nowicki@linaro.org> |
|---|---|
| Date | 2015-08-07 13:10 +0200 |
| Message-ID | <pUNHc-64q-3@gated-at.bofh.it> |
| In reply to | #1202571 |
On 07.08.2015 12:43, Robert Richter wrote:
> On 07.08.15 10:09:04, Tomasz Nowicki wrote:
>> On 07.08.2015 02:33, David Daney wrote:
>
> ...
>
>>> +#else
>>> +
>>> +static int bgx_init_acpi_phy(struct bgx *bgx)
>>> +{
>>> + return -ENODEV;
>>> +}
>>> +
>>> +#endif /* CONFIG_ACPI */
>>> +
>>> #if IS_ENABLED(CONFIG_OF_MDIO)
>>>
>>> static int bgx_init_of_phy(struct bgx *bgx)
>>> @@ -882,7 +1010,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
>>>
>>> static int bgx_init_phy(struct bgx *bgx)
>>> {
>>> - return bgx_init_of_phy(bgx);
>>> + int err = bgx_init_of_phy(bgx);
>>> +
>>> + if (err != -ENODEV)
>>> + return err;
>>> +
>>> + return bgx_init_acpi_phy(bgx);
>>> }
>>>
>>
>> If kernel can work with DT and ACPI (both compiled in), it should take only
>> one path instead of probing DT and ACPI sequentially. How about:
>>
>> @@ -902,10 +925,9 @@ static int bgx_probe(struct pci_dev *pdev, const struct
>> pci_device_id *ent)
>> bgx_vnic[bgx->bgx_id] = bgx;
>> bgx_get_qlm_mode(bgx);
>>
>> - snprintf(bgx_sel, 5, "bgx%d", bgx->bgx_id);
>> - np = of_find_node_by_name(NULL, bgx_sel);
>> - if (np)
>> - bgx_init_of(bgx, np);
>> + err = acpi_disabled ? bgx_init_of_phy(bgx) : bgx_init_acpi_phy(bgx);
>> + if (err)
>> + goto err_enable;
>>
>> bgx_init_hw(bgx);
>
> I would not pollute bgx_probe() with acpi and dt specifics, and instead
> keep bgx_init_phy(). The typical design pattern for this is:
>
> static int bgx_init_phy(struct bgx *bgx)
> {
> #ifdef CONFIG_ACPI
> if (!acpi_disabled)
> return bgx_init_acpi_phy(bgx);
> #endif
> return bgx_init_of_phy(bgx);
> }
>
> This adds acpi runtime detection (acpi=no), does not call dt code in
> case of acpi, and saves the #else for bgx_init_acpi_phy().
>
I am fine with keeping it in bgx_init_phy(), however we can drop there
#ifdefs since both of bgx_init_{acpi,of}_phy calls have empty stub for
!ACPI and !OF case. Like that:
static int bgx_init_phy(struct bgx *bgx)
{
if (!acpi_disabled)
return bgx_init_acpi_phy(bgx);
else
return bgx_init_of_phy(bgx);
}
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Tomasz Nowicki <tomasz.nowicki@linaro.org> |
|---|---|
| Date | 2015-08-07 14:50 +0200 |
| Message-ID | <pUPfX-89l-3@gated-at.bofh.it> |
| In reply to | #1202585 |
On 07.08.2015 13:56, Robert Richter wrote:
> On 07.08.15 12:52:41, Tomasz Nowicki wrote:
>> On 07.08.2015 12:43, Robert Richter wrote:
>>> On 07.08.15 10:09:04, Tomasz Nowicki wrote:
>>>> On 07.08.2015 02:33, David Daney wrote:
>>>
>>> ...
>>>
>>>>> +#else
>>>>> +
>>>>> +static int bgx_init_acpi_phy(struct bgx *bgx)
>>>>> +{
>>>>> + return -ENODEV;
>>>>> +}
>>>>> +
>>>>> +#endif /* CONFIG_ACPI */
>>>>> +
>>>>> #if IS_ENABLED(CONFIG_OF_MDIO)
>>>>>
>>>>> static int bgx_init_of_phy(struct bgx *bgx)
>>>>> @@ -882,7 +1010,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
>>>>>
>>>>> static int bgx_init_phy(struct bgx *bgx)
>>>>> {
>>>>> - return bgx_init_of_phy(bgx);
>>>>> + int err = bgx_init_of_phy(bgx);
>>>>> +
>>>>> + if (err != -ENODEV)
>>>>> + return err;
>>>>> +
>>>>> + return bgx_init_acpi_phy(bgx);
>>>>> }
>>>>>
>>>>
>>>> If kernel can work with DT and ACPI (both compiled in), it should take only
>>>> one path instead of probing DT and ACPI sequentially. How about:
>>>>
>>>> @@ -902,10 +925,9 @@ static int bgx_probe(struct pci_dev *pdev, const struct
>>>> pci_device_id *ent)
>>>> bgx_vnic[bgx->bgx_id] = bgx;
>>>> bgx_get_qlm_mode(bgx);
>>>>
>>>> - snprintf(bgx_sel, 5, "bgx%d", bgx->bgx_id);
>>>> - np = of_find_node_by_name(NULL, bgx_sel);
>>>> - if (np)
>>>> - bgx_init_of(bgx, np);
>>>> + err = acpi_disabled ? bgx_init_of_phy(bgx) : bgx_init_acpi_phy(bgx);
>>>> + if (err)
>>>> + goto err_enable;
>>>>
>>>> bgx_init_hw(bgx);
>>>
>>> I would not pollute bgx_probe() with acpi and dt specifics, and instead
>>> keep bgx_init_phy(). The typical design pattern for this is:
>>>
>>> static int bgx_init_phy(struct bgx *bgx)
>>> {
>>> #ifdef CONFIG_ACPI
>>> if (!acpi_disabled)
>>> return bgx_init_acpi_phy(bgx);
>>> #endif
>>> return bgx_init_of_phy(bgx);
>>> }
>>>
>>> This adds acpi runtime detection (acpi=no), does not call dt code in
>>> case of acpi, and saves the #else for bgx_init_acpi_phy().
>>>
>>
>> I am fine with keeping it in bgx_init_phy(), however we can drop there
>> #ifdefs since both of bgx_init_{acpi,of}_phy calls have empty stub for !ACPI
>> and !OF case. Like that:
>>
>> static int bgx_init_phy(struct bgx *bgx)
>> {
>>
>> if (!acpi_disabled)
>> return bgx_init_acpi_phy(bgx);
>> else
>> return bgx_init_of_phy(bgx);
>> }
>
> As said, keeping it in #ifdefs makes the empty stub function for !acpi
> obsolete, which makes the code smaller and better readable. This style
> is common practice in the kernel. Apart from that, the 'else' should
> be dropped as it is useless.
>
I would't say the code is better readable (bgx_init_of_phy has still two
stubs) but this is just cosmetic, my point was to use run time detection
using acpi_disabled.
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | David Daney <ddaney@caviumnetworks.com> |
|---|---|
| Date | 2015-08-07 18:50 +0200 |
| Message-ID | <pUT0e-5e5-5@gated-at.bofh.it> |
| In reply to | #1202657 |
On 08/07/2015 05:42 AM, Tomasz Nowicki wrote:
> On 07.08.2015 13:56, Robert Richter wrote:
>> On 07.08.15 12:52:41, Tomasz Nowicki wrote:
[...]
>>>>
>>>> I would not pollute bgx_probe() with acpi and dt specifics, and instead
>>>> keep bgx_init_phy(). The typical design pattern for this is:
>>>>
>>>> static int bgx_init_phy(struct bgx *bgx)
>>>> {
>>>> #ifdef CONFIG_ACPI
>>>> if (!acpi_disabled)
>>>> return bgx_init_acpi_phy(bgx);
>>>> #endif
>>>> return bgx_init_of_phy(bgx);
>>>> }
>>>>
>>>> This adds acpi runtime detection (acpi=no), does not call dt code in
>>>> case of acpi, and saves the #else for bgx_init_acpi_phy().
>>>>
>>>
>>> I am fine with keeping it in bgx_init_phy(), however we can drop there
>>> #ifdefs since both of bgx_init_{acpi,of}_phy calls have empty stub
>>> for !ACPI
>>> and !OF case. Like that:
>>>
>>> static int bgx_init_phy(struct bgx *bgx)
>>> {
>>>
>>> if (!acpi_disabled)
>>> return bgx_init_acpi_phy(bgx);
>>> else
>>> return bgx_init_of_phy(bgx);
>>> }
>>
>> As said, keeping it in #ifdefs makes the empty stub function for !acpi
>> obsolete, which makes the code smaller and better readable. This style
>> is common practice in the kernel. Apart from that, the 'else' should
>> be dropped as it is useless.
>>
>
> I would't say the code is better readable (bgx_init_of_phy has still two
> stubs) but this is just cosmetic, my point was to use run time detection
> using acpi_disabled.
>
Thanks Tomasz and Robert for the input. Because of this, it seems that
another version of the patch will be necessary. In the interests of
code clarity and asthetics, we will go with the code without the
#ifdefs, and rely on the compiler to optimize away any dead code.
David Daney
> Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2015-08-08 13:30 +0200 |
| Message-ID | <pVau5-5J4-3@gated-at.bofh.it> |
| In reply to | #1202571 |
On Friday 07 August 2015 12:43:20 Robert Richter wrote:
>
> I would not pollute bgx_probe() with acpi and dt specifics, and instead
> keep bgx_init_phy(). The typical design pattern for this is:
>
> static int bgx_init_phy(struct bgx *bgx)
> {
> #ifdef CONFIG_ACPI
> if (!acpi_disabled)
> return bgx_init_acpi_phy(bgx);
> #endif
> return bgx_init_of_phy(bgx);
> }
>
> This adds acpi runtime detection (acpi=no), does not call dt code in
> case of acpi, and saves the #else for bgx_init_acpi_phy().
>
What you should really do is to use the same function for both,
using the generic device properties API. If that is not possible,
explain in a comment why not.
Aside from that, if you do have to use compile-time conditionals,
use 'if (IS_ENABLED(CONFIG_ACPI) && !acpi_disabled)' instead of
#ifdef, for readability. The compiler will produce the same binary,
but also give helpful warnings about incorrect code that you don't
get with #ifdef.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Mark Rutland <mark.rutland@arm.com> |
|---|---|
| Date | 2015-08-07 16:10 +0200 |
| Message-ID | <pUQvp-1Hw-33@gated-at.bofh.it> |
| In reply to | #1202175 |
On Fri, Aug 07, 2015 at 01:33:10AM +0100, David Daney wrote:
> From: David Daney <david.daney@cavium.com>
>
> Find out which PHYs belong to which BGX instance in the ACPI way.
>
> Set the MAC address of the device as provided by ACPI tables. This is
> similar to the implementation for devicetree in
> of_get_mac_address(). The table is searched for the device property
> entries "mac-address", "local-mac-address" and "address" in that
> order. The address is provided in a u64 variable and must contain a
> valid 6 bytes-len mac addr.
>
> Based on code from: Narinder Dhillon <ndhillon@cavium.com>
> Tomasz Nowicki <tomasz.nowicki@linaro.org>
> Robert Richter <rrichter@cavium.com>
>
> Signed-off-by: Tomasz Nowicki <tomasz.nowicki@linaro.org>
> Signed-off-by: Robert Richter <rrichter@cavium.com>
> Signed-off-by: David Daney <david.daney@cavium.com>
> ---
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 137 +++++++++++++++++++++-
> 1 file changed, 135 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> index 615b2af..2056583 100644
> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> @@ -6,6 +6,7 @@
> * as published by the Free Software Foundation.
> */
>
> +#include <linux/acpi.h>
> #include <linux/module.h>
> #include <linux/interrupt.h>
> #include <linux/pci.h>
> @@ -26,7 +27,7 @@
> struct lmac {
> struct bgx *bgx;
> int dmac;
> - unsigned char mac[ETH_ALEN];
> + u8 mac[ETH_ALEN];
> bool link_up;
> int lmacid; /* ID within BGX */
> int lmacid_bd; /* ID on board */
> @@ -835,6 +836,133 @@ static void bgx_get_qlm_mode(struct bgx *bgx)
> }
> }
>
> +#ifdef CONFIG_ACPI
> +
> +static int bgx_match_phy_id(struct device *dev, void *data)
> +{
> + struct phy_device *phydev = to_phy_device(dev);
> + u32 *phy_id = data;
> +
> + if (phydev->addr == *phy_id)
> + return 1;
> +
> + return 0;
> +}
> +
> +static const char * const addr_propnames[] = {
> + "mac-address",
> + "local-mac-address",
> + "address",
> +};
If these are going to be generally necessary, then we should get them
adopted as standardised _DSD properties (ideally just one of them).
[...]
> +static acpi_status bgx_acpi_register_phy(acpi_handle handle,
> + u32 lvl, void *context, void **rv)
> +{
> + struct acpi_reference_args args;
> + const union acpi_object *prop;
> + struct bgx *bgx = context;
> + struct acpi_device *adev;
> + struct device *phy_dev;
> + u32 phy_id;
> +
> + if (acpi_bus_get_device(handle, &adev))
> + goto out;
> +
> + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
> +
> + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
> +
> + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
> +
> + if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
> + goto out;
> +
> + if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
> + goto out;
Likewise for any inter-device properties, so that we can actually handle
them in a generic fashion, and avoid / learn from the mistakes we've
already handled with DT.
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Mark Rutland <mark.rutland@arm.com> |
|---|---|
| Date | 2015-08-07 20:00 +0200 |
| Message-ID | <pUU5Y-6KY-5@gated-at.bofh.it> |
| In reply to | #1202721 |
[Correcting the devicetree list address, which I typo'd in my original
reply]
> >> +static const char * const addr_propnames[] = {
> >> + "mac-address",
> >> + "local-mac-address",
> >> + "address",
> >> +};
> >
> > If these are going to be generally necessary, then we should get them
> > adopted as standardised _DSD properties (ideally just one of them).
>
> As far as I can tell, and please correct me if I am wrong, ACPI-6.0
> doesn't contemplate MAC addresses.
>
> Today we are using "mac-address", which is an Integer containing the MAC
> address in its lowest order 48 bits in Little-Endian byte order.
>
> The hardware and ACPI tables are here today, and we would like to
> support it. If some future ACPI specification specifies a standard way
> to do this, we will probably adapt the code to do this in a standard manner.
>
>
> >
> > [...]
> >
> >> +static acpi_status bgx_acpi_register_phy(acpi_handle handle,
> >> + u32 lvl, void *context, void **rv)
> >> +{
> >> + struct acpi_reference_args args;
> >> + const union acpi_object *prop;
> >> + struct bgx *bgx = context;
> >> + struct acpi_device *adev;
> >> + struct device *phy_dev;
> >> + u32 phy_id;
> >> +
> >> + if (acpi_bus_get_device(handle, &adev))
> >> + goto out;
> >> +
> >> + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
> >> +
> >> + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
> >> +
> >> + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
> >> +
> >> + if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
> >> + goto out;
> >> +
> >> + if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
> >> + goto out;
> >
> > Likewise for any inter-device properties, so that we can actually handle
> > them in a generic fashion, and avoid / learn from the mistakes we've
> > already handled with DT.
>
> This is the fallacy of the ACPI is superior to DT argument. The
> specification of PHY topology and MAC addresses is well standardized in
> DT, there is no question about what the proper way to specify it is.
> Under ACPI, it is the Wild West, there is no specification, so each
> system design is forced to invent something, and everybody comes up with
> an incompatible implementation.
Indeed.
If ACPI is going to handle it, it should handle it properly. I really
don't see the point in bodging properties together in a less standard
manner than DT, especially for inter-device relationships.
Doing so is painful for _everyone_, and it's extremely unlikely that
other ACPI-aware OSs will actually support these custom descriptions,
making this Linux-specific, and breaking the rationale for using ACPI in
the first place -- a standard that says "just do non-standard stuff" is
not a usable standard.
For intra-device properties, we should standardise what we can, but
vendor-specific stuff is ok -- this can be self-contained within a
driver.
For inter-device relationships ACPI _must_ gain a better model of
componentised devices. It's simply unworkable otherwise, and as you
point out it's fallacious to say that because ACPI is being used that
something is magically industry standard, portable, etc.
This is not your problem in particular; the entire handling of _DSD so
far is a joke IMO.
Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2015-08-08 02:10 +0200 |
| Message-ID | <pUZS2-7k6-3@gated-at.bofh.it> |
| In reply to | #1202957 |
Hi Mark,
On Fri, Aug 7, 2015 at 7:51 PM, Mark Rutland <mark.rutland@arm.com> wrote:
> [Correcting the devicetree list address, which I typo'd in my original
> reply]
>
>> >> +static const char * const addr_propnames[] = {
>> >> + "mac-address",
>> >> + "local-mac-address",
>> >> + "address",
>> >> +};
>> >
>> > If these are going to be generally necessary, then we should get them
>> > adopted as standardised _DSD properties (ideally just one of them).
>>
>> As far as I can tell, and please correct me if I am wrong, ACPI-6.0
>> doesn't contemplate MAC addresses.
>>
>> Today we are using "mac-address", which is an Integer containing the MAC
>> address in its lowest order 48 bits in Little-Endian byte order.
>>
>> The hardware and ACPI tables are here today, and we would like to
>> support it. If some future ACPI specification specifies a standard way
>> to do this, we will probably adapt the code to do this in a standard manner.
>>
>>
>> >
>> > [...]
>> >
>> >> +static acpi_status bgx_acpi_register_phy(acpi_handle handle,
>> >> + u32 lvl, void *context, void **rv)
>> >> +{
>> >> + struct acpi_reference_args args;
>> >> + const union acpi_object *prop;
>> >> + struct bgx *bgx = context;
>> >> + struct acpi_device *adev;
>> >> + struct device *phy_dev;
>> >> + u32 phy_id;
>> >> +
>> >> + if (acpi_bus_get_device(handle, &adev))
>> >> + goto out;
>> >> +
>> >> + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
>> >> +
>> >> + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
>> >> +
>> >> + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
>> >> +
>> >> + if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
>> >> + goto out;
>> >> +
>> >> + if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
>> >> + goto out;
>> >
>> > Likewise for any inter-device properties, so that we can actually handle
>> > them in a generic fashion, and avoid / learn from the mistakes we've
>> > already handled with DT.
>>
>> This is the fallacy of the ACPI is superior to DT argument. The
>> specification of PHY topology and MAC addresses is well standardized in
>> DT, there is no question about what the proper way to specify it is.
>> Under ACPI, it is the Wild West, there is no specification, so each
>> system design is forced to invent something, and everybody comes up with
>> an incompatible implementation.
>
> Indeed.
>
> If ACPI is going to handle it, it should handle it properly. I really
> don't see the point in bodging properties together in a less standard
> manner than DT, especially for inter-device relationships.
>
> Doing so is painful for _everyone_, and it's extremely unlikely that
> other ACPI-aware OSs will actually support these custom descriptions,
> making this Linux-specific, and breaking the rationale for using ACPI in
> the first place -- a standard that says "just do non-standard stuff" is
> not a usable standard.
>
> For intra-device properties, we should standardise what we can, but
> vendor-specific stuff is ok -- this can be self-contained within a
> driver.
>
> For inter-device relationships ACPI _must_ gain a better model of
> componentised devices. It's simply unworkable otherwise, and as you
> point out it's fallacious to say that because ACPI is being used that
> something is magically industry standard, portable, etc.
>
> This is not your problem in particular; the entire handling of _DSD so
> far is a joke IMO.
It is actually useful to people as far as I can say.
Also, if somebody is going to use properties with ACPI, why whould
they use a different set of properties with DT?
Wouldn't it be more reasonable to use the same set in both cases?
Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2015-08-08 02:30 +0200 |
| Message-ID | <pV0bn-7IV-5@gated-at.bofh.it> |
| In reply to | #1203106 |
Hi David, On Sat, Aug 8, 2015 at 2:11 AM, David Daney <ddaney@caviumnetworks.com> wrote: > On 08/07/2015 05:05 PM, Rafael J. Wysocki wrote: [cut] >> >> It is actually useful to people as far as I can say. >> >> Also, if somebody is going to use properties with ACPI, why whould >> they use a different set of properties with DT? >> >> Wouldn't it be more reasonable to use the same set in both cases? > > > Yes, but there is still quite a bit of leeway to screw things up. That I have to agree with, unfortunately. On the other hand, this is a fairly new concept and we need to gain some experience with it to be able to come up with best practices and so on. Cases like yours are really helpful here. > FWIW: http://www.uefi.org/sites/default/files/resources/nic-request-v2.pdf > > This actually seems to have been adopted by the UEFI people as a > "Standard", I am not sure where a record of this is kept though. Work on this is in progress, but far from completion. Essentially, what's needed is more pressure from vendors who want to use properties in their firmware. > So, we are changing our firmware to use this standard (which is quite > similar the the DT with respect to MAC addresses). Cool. :-) Thanks, Rafael -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Mark Rutland <mark.rutland@arm.com> |
|---|---|
| Date | 2015-08-07 20:00 +0200 |
| Message-ID | <pUU5Y-6KY-13@gated-at.bofh.it> |
| In reply to | #1202721 |
[Correcting the devicetree list address, which I typo'd in my original
reply]
[resending to _really_ correct the address, apologies for the spam]
> >> +static const char * const addr_propnames[] = {
> >> + "mac-address",
> >> + "local-mac-address",
> >> + "address",
> >> +};
> >
> > If these are going to be generally necessary, then we should get them
> > adopted as standardised _DSD properties (ideally just one of them).
>
> As far as I can tell, and please correct me if I am wrong, ACPI-6.0
> doesn't contemplate MAC addresses.
>
> Today we are using "mac-address", which is an Integer containing the MAC
> address in its lowest order 48 bits in Little-Endian byte order.
>
> The hardware and ACPI tables are here today, and we would like to
> support it. If some future ACPI specification specifies a standard way
> to do this, we will probably adapt the code to do this in a standard manner.
>
>
> >
> > [...]
> >
> >> +static acpi_status bgx_acpi_register_phy(acpi_handle handle,
> >> + u32 lvl, void *context, void **rv)
> >> +{
> >> + struct acpi_reference_args args;
> >> + const union acpi_object *prop;
> >> + struct bgx *bgx = context;
> >> + struct acpi_device *adev;
> >> + struct device *phy_dev;
> >> + u32 phy_id;
> >> +
> >> + if (acpi_bus_get_device(handle, &adev))
> >> + goto out;
> >> +
> >> + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
> >> +
> >> + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
> >> +
> >> + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
> >> +
> >> + if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
> >> + goto out;
> >> +
> >> + if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
> >> + goto out;
> >
> > Likewise for any inter-device properties, so that we can actually handle
> > them in a generic fashion, and avoid / learn from the mistakes we've
> > already handled with DT.
>
> This is the fallacy of the ACPI is superior to DT argument. The
> specification of PHY topology and MAC addresses is well standardized in
> DT, there is no question about what the proper way to specify it is.
> Under ACPI, it is the Wild West, there is no specification, so each
> system design is forced to invent something, and everybody comes up with
> an incompatible implementation.
Indeed.
If ACPI is going to handle it, it should handle it properly. I really
don't see the point in bodging properties together in a less standard
manner than DT, especially for inter-device relationships.
Doing so is painful for _everyone_, and it's extremely unlikely that
other ACPI-aware OSs will actually support these custom descriptions,
making this Linux-specific, and breaking the rationale for using ACPI in
the first place -- a standard that says "just do non-standard stuff" is
not a usable standard.
For intra-device properties, we should standardise what we can, but
vendor-specific stuff is ok -- this can be self-contained within a
driver.
For inter-device relationships ACPI _must_ gain a better model of
componentised devices. It's simply unworkable otherwise, and as you
point out it's fallacious to say that because ACPI is being used that
something is magically industry standard, portable, etc.
This is not your problem in particular; the entire handling of _DSD so
far is a joke IMO.
Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Graeme Gregory <gg@slimlogic.co.uk> |
|---|---|
| Date | 2015-08-07 17:00 +0200 |
| Message-ID | <pURhM-2CP-9@gated-at.bofh.it> |
| In reply to | #1202175 |
On Thu, Aug 06, 2015 at 05:33:10PM -0700, David Daney wrote:
> From: David Daney <david.daney@cavium.com>
>
> Find out which PHYs belong to which BGX instance in the ACPI way.
>
> Set the MAC address of the device as provided by ACPI tables. This is
> similar to the implementation for devicetree in
> of_get_mac_address(). The table is searched for the device property
> entries "mac-address", "local-mac-address" and "address" in that
> order. The address is provided in a u64 variable and must contain a
> valid 6 bytes-len mac addr.
>
> Based on code from: Narinder Dhillon <ndhillon@cavium.com>
> Tomasz Nowicki <tomasz.nowicki@linaro.org>
> Robert Richter <rrichter@cavium.com>
>
> Signed-off-by: Tomasz Nowicki <tomasz.nowicki@linaro.org>
> Signed-off-by: Robert Richter <rrichter@cavium.com>
> Signed-off-by: David Daney <david.daney@cavium.com>
> ---
> drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 137 +++++++++++++++++++++-
> 1 file changed, 135 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> index 615b2af..2056583 100644
> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
> @@ -6,6 +6,7 @@
> * as published by the Free Software Foundation.
> */
>
> +#include <linux/acpi.h>
> #include <linux/module.h>
> #include <linux/interrupt.h>
> #include <linux/pci.h>
> @@ -26,7 +27,7 @@
> struct lmac {
> struct bgx *bgx;
> int dmac;
> - unsigned char mac[ETH_ALEN];
> + u8 mac[ETH_ALEN];
> bool link_up;
> int lmacid; /* ID within BGX */
> int lmacid_bd; /* ID on board */
> @@ -835,6 +836,133 @@ static void bgx_get_qlm_mode(struct bgx *bgx)
> }
> }
>
> +#ifdef CONFIG_ACPI
> +
> +static int bgx_match_phy_id(struct device *dev, void *data)
> +{
> + struct phy_device *phydev = to_phy_device(dev);
> + u32 *phy_id = data;
> +
> + if (phydev->addr == *phy_id)
> + return 1;
> +
> + return 0;
> +}
> +
> +static const char * const addr_propnames[] = {
> + "mac-address",
> + "local-mac-address",
> + "address",
> +};
> +
> +static int acpi_get_mac_address(struct acpi_device *adev, u8 *dst)
> +{
> + const union acpi_object *prop;
> + u64 mac_val;
> + u8 mac[ETH_ALEN];
> + int i, j;
> + int ret;
> +
> + for (i = 0; i < ARRAY_SIZE(addr_propnames); i++) {
> + ret = acpi_dev_get_property(adev, addr_propnames[i],
> + ACPI_TYPE_INTEGER, &prop);
Shouldn't this be trying to use device_property_read_* API and making
the DT/ACPI path the same where possible?
Graeme
> + if (ret)
> + continue;
> +
> + mac_val = prop->integer.value;
> +
> + if (mac_val & (~0ULL << 48))
> + continue; /* more than 6 bytes */
> +
> + for (j = 0; j < ARRAY_SIZE(mac); j++)
> + mac[j] = (u8)(mac_val >> (8 * j));
> + if (!is_valid_ether_addr(mac))
> + continue;
> +
> + memcpy(dst, mac, ETH_ALEN);
> +
> + return 0;
> + }
> +
> + return ret ? ret : -EINVAL;
> +}
> +
> +static acpi_status bgx_acpi_register_phy(acpi_handle handle,
> + u32 lvl, void *context, void **rv)
> +{
> + struct acpi_reference_args args;
> + const union acpi_object *prop;
> + struct bgx *bgx = context;
> + struct acpi_device *adev;
> + struct device *phy_dev;
> + u32 phy_id;
> +
> + if (acpi_bus_get_device(handle, &adev))
> + goto out;
> +
> + SET_NETDEV_DEV(&bgx->lmac[bgx->lmac_count].netdev, &bgx->pdev->dev);
> +
> + acpi_get_mac_address(adev, bgx->lmac[bgx->lmac_count].mac);
> +
> + bgx->lmac[bgx->lmac_count].lmacid = bgx->lmac_count;
> +
> + if (acpi_dev_get_property_reference(adev, "phy-handle", 0, &args))
> + goto out;
> +
> + if (acpi_dev_get_property(args.adev, "phy-channel", ACPI_TYPE_INTEGER, &prop))
> + goto out;
> +
> + phy_id = prop->integer.value;
> +
> + phy_dev = bus_find_device(&mdio_bus_type, NULL, (void *)&phy_id,
> + bgx_match_phy_id);
> + if (!phy_dev)
> + goto out;
> +
> + bgx->lmac[bgx->lmac_count].phydev = to_phy_device(phy_dev);
> +out:
> + bgx->lmac_count++;
> + return AE_OK;
> +}
> +
> +static acpi_status bgx_acpi_match_id(acpi_handle handle, u32 lvl,
> + void *context, void **ret_val)
> +{
> + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
> + struct bgx *bgx = context;
> + char bgx_sel[5];
> +
> + snprintf(bgx_sel, 5, "BGX%d", bgx->bgx_id);
> + if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &string))) {
> + pr_warn("Invalid link device\n");
> + return AE_OK;
> + }
> +
> + if (strncmp(string.pointer, bgx_sel, 4))
> + return AE_OK;
> +
> + acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
> + bgx_acpi_register_phy, NULL, bgx, NULL);
> +
> + kfree(string.pointer);
> + return AE_CTRL_TERMINATE;
> +}
> +
> +static int bgx_init_acpi_phy(struct bgx *bgx)
> +{
> + acpi_get_devices(NULL, bgx_acpi_match_id, bgx, (void **)NULL);
> + return 0;
> +}
> +
> +#else
> +
> +static int bgx_init_acpi_phy(struct bgx *bgx)
> +{
> + return -ENODEV;
> +}
> +
> +#endif /* CONFIG_ACPI */
> +
> #if IS_ENABLED(CONFIG_OF_MDIO)
>
> static int bgx_init_of_phy(struct bgx *bgx)
> @@ -882,7 +1010,12 @@ static int bgx_init_of_phy(struct bgx *bgx)
>
> static int bgx_init_phy(struct bgx *bgx)
> {
> - return bgx_init_of_phy(bgx);
> + int err = bgx_init_of_phy(bgx);
> +
> + if (err != -ENODEV)
> + return err;
> +
> + return bgx_init_acpi_phy(bgx);
> }
>
> static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | "Rafael J. Wysocki" <rafael@kernel.org> |
|---|---|
| Date | 2015-08-08 02:40 +0200 |
| Message-ID | <pV0l3-7Uh-3@gated-at.bofh.it> |
| In reply to | #1202777 |
Hi David,
On Fri, Aug 7, 2015 at 8:14 PM, David Daney <ddaney@caviumnetworks.com> wrote:
> On 08/07/2015 07:54 AM, Graeme Gregory wrote:
>>
>> On Thu, Aug 06, 2015 at 05:33:10PM -0700, David Daney wrote:
>>>
>>> From: David Daney <david.daney@cavium.com>
>>>
>>> Find out which PHYs belong to which BGX instance in the ACPI way.
>>>
>>> Set the MAC address of the device as provided by ACPI tables. This is
>>> similar to the implementation for devicetree in
>>> of_get_mac_address(). The table is searched for the device property
>>> entries "mac-address", "local-mac-address" and "address" in that
>>> order. The address is provided in a u64 variable and must contain a
>>> valid 6 bytes-len mac addr.
>>>
>>> Based on code from: Narinder Dhillon <ndhillon@cavium.com>
>>> Tomasz Nowicki <tomasz.nowicki@linaro.org>
>>> Robert Richter <rrichter@cavium.com>
>>>
>>> Signed-off-by: Tomasz Nowicki <tomasz.nowicki@linaro.org>
>>> Signed-off-by: Robert Richter <rrichter@cavium.com>
>>> Signed-off-by: David Daney <david.daney@cavium.com>
>>> ---
>>> drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 137
>>> +++++++++++++++++++++-
>>> 1 file changed, 135 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> index 615b2af..2056583 100644
>>> --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>>> +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
>
> [...]
>>>
>>> +
>>> +static int acpi_get_mac_address(struct acpi_device *adev, u8 *dst)
>>> +{
>>> + const union acpi_object *prop;
>>> + u64 mac_val;
>>> + u8 mac[ETH_ALEN];
>>> + int i, j;
>>> + int ret;
>>> +
>>> + for (i = 0; i < ARRAY_SIZE(addr_propnames); i++) {
>>> + ret = acpi_dev_get_property(adev, addr_propnames[i],
>>> + ACPI_TYPE_INTEGER, &prop);
>>
>>
>> Shouldn't this be trying to use device_property_read_* API and making
>> the DT/ACPI path the same where possible?
>>
>
> Ideally, something like you suggest would be possible. However, there are a
> couple of problems trying to do it in the kernel as it exists today:
>
> 1) There is no 'struct device *' here, so device_property_read_* is not
> applicable.
>
> 2) There is no standard ACPI binding for MAC addresses, so it is impossible
> to create a hypothetical fw_get_mac_address(), which would be analogous to
> of_get_mac_address().
>
> Other e-mail threads have suggested that the path to an elegant solution is
> to inter-mix a bunch of calls to acpi_dev_get_property*() and
> fwnode_property_read*() as to use these more generic fwnode_property_read*()
> functions whereever possible. I rejected this approach as it seems cleaner
> to me to consistently use a single set of APIs.
Actually, that wasn't my intention.
I wanted to say that once you'd got an ACPI device pointer (struct
acpi_device), you could easly convert it to a struct fwnode_handle
pointer and operate that going forward when accessing properties.
That at least would help with the properties that do not differ
between DT and ACPI.
Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web