123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- From d771759e71dfab46de09fc2efcd1282926a775b8 Mon Sep 17 00:00:00 2001
- From: Jan Kiszka <jan.kiszka@siemens.com>
- Date: Thu, 22 Jun 2017 08:18:01 +0200
- Subject: [PATCH 05/32] stmmac: pci: Use dmi_system_id table for retrieving PHY
- addresses
- Commit 8d78b69091845386b6096f3adae98f28b9bf96ed upstream.
- Avoids reimplementation of DMI matching in stmmac_pci_find_phy_addr.
- Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
- Signed-off-by: David S. Miller <davem@davemloft.net>
- ---
- drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 97 ++++++++++++++++--------
- 1 file changed, 64 insertions(+), 33 deletions(-)
- diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
- index 9fe6368738ec..279a1355d75f 100644
- --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
- +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
- @@ -34,36 +34,39 @@
- * negative value of the address means that MAC controller is not connected
- * with PHY.
- */
- -struct stmmac_pci_dmi_data {
- - const char *name;
- - const char *asset_tag;
- +struct stmmac_pci_func_data {
- unsigned int func;
- int phy_addr;
- };
-
- +struct stmmac_pci_dmi_data {
- + const struct stmmac_pci_func_data *func;
- + size_t nfuncs;
- +};
- +
- struct stmmac_pci_info {
- int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
- };
-
- static int stmmac_pci_find_phy_addr(struct pci_dev *pdev,
- - struct stmmac_pci_dmi_data *dmi_data)
- + const struct dmi_system_id *dmi_list)
- {
- - const char *name = dmi_get_system_info(DMI_BOARD_NAME);
- - const char *asset_tag = dmi_get_system_info(DMI_BOARD_ASSET_TAG);
- - unsigned int func = PCI_FUNC(pdev->devfn);
- - struct stmmac_pci_dmi_data *dmi;
- -
- - if (!name)
- + const struct stmmac_pci_func_data *func_data;
- + const struct stmmac_pci_dmi_data *dmi_data;
- + const struct dmi_system_id *dmi_id;
- + int func = PCI_FUNC(pdev->devfn);
- + size_t n;
- +
- + dmi_id = dmi_first_match(dmi_list);
- + if (!dmi_id)
- return -ENODEV;
-
- - for (dmi = dmi_data; dmi->name && *dmi->name; dmi++) {
- - if (!strcmp(dmi->name, name) && dmi->func == func) {
- - /* If asset tag is provided, match on it as well. */
- - if (dmi->asset_tag && strcmp(dmi->asset_tag, asset_tag))
- - continue;
- - return dmi->phy_addr;
- - }
- - }
- + dmi_data = dmi_id->driver_data;
- + func_data = dmi_data->func;
- +
- + for (n = 0; n < dmi_data->nfuncs; n++, func_data++)
- + if (func_data->func == func)
- + return func_data->phy_addr;
-
- return -ENODEV;
- }
- @@ -97,34 +100,62 @@ static const struct stmmac_pci_info stmmac_pci_info = {
- .setup = stmmac_default_data,
- };
-
- -static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
- +static const struct stmmac_pci_func_data galileo_stmmac_func_data[] = {
- {
- - .name = "Galileo",
- .func = 6,
- .phy_addr = 1,
- },
- +};
- +
- +static const struct stmmac_pci_dmi_data galileo_stmmac_dmi_data = {
- + .func = galileo_stmmac_func_data,
- + .nfuncs = ARRAY_SIZE(galileo_stmmac_func_data),
- +};
- +
- +static const struct stmmac_pci_func_data iot2040_stmmac_func_data[] = {
- {
- - .name = "GalileoGen2",
- .func = 6,
- .phy_addr = 1,
- },
- {
- - .name = "SIMATIC IOT2000",
- - .asset_tag = "6ES7647-0AA00-0YA2",
- - .func = 6,
- + .func = 7,
- .phy_addr = 1,
- },
- +};
- +
- +static const struct stmmac_pci_dmi_data iot2040_stmmac_dmi_data = {
- + .func = iot2040_stmmac_func_data,
- + .nfuncs = ARRAY_SIZE(iot2040_stmmac_func_data),
- +};
- +
- +static const struct dmi_system_id quark_pci_dmi[] = {
- {
- - .name = "SIMATIC IOT2000",
- - .asset_tag = "6ES7647-0AA00-1YA2",
- - .func = 6,
- - .phy_addr = 1,
- + .matches = {
- + DMI_EXACT_MATCH(DMI_BOARD_NAME, "Galileo"),
- + },
- + .driver_data = (void *)&galileo_stmmac_dmi_data,
- },
- {
- - .name = "SIMATIC IOT2000",
- - .asset_tag = "6ES7647-0AA00-1YA2",
- - .func = 7,
- - .phy_addr = 1,
- + .matches = {
- + DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
- + },
- + .driver_data = (void *)&galileo_stmmac_dmi_data,
- + },
- + {
- + .matches = {
- + DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
- + DMI_EXACT_MATCH(DMI_BOARD_ASSET_TAG,
- + "6ES7647-0AA00-0YA2"),
- + },
- + .driver_data = (void *)&galileo_stmmac_dmi_data,
- + },
- + {
- + .matches = {
- + DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
- + DMI_EXACT_MATCH(DMI_BOARD_ASSET_TAG,
- + "6ES7647-0AA00-1YA2"),
- + },
- + .driver_data = (void *)&iot2040_stmmac_dmi_data,
- },
- {}
- };
- @@ -138,7 +169,7 @@ static int quark_default_data(struct pci_dev *pdev,
- * Refuse to load the driver and register net device if MAC controller
- * does not connect to any PHY interface.
- */
- - ret = stmmac_pci_find_phy_addr(pdev, quark_pci_dmi_data);
- + ret = stmmac_pci_find_phy_addr(pdev, quark_pci_dmi);
- if (ret < 0) {
- /* Return error to the caller on DMI enabled boards. */
- if (dmi_get_system_info(DMI_BOARD_NAME))
- --
- 2.16.4
|