Commit 0c461e05 authored by David S. Miller's avatar David S. Miller

Merge branch 'stmmac-pci-Refactor-DMI-probing'

Jan Kiszka says:

====================
stmmac: pci: Refactor DMI probing

Some cleanups of the way we probe DMI platforms in the driver. Reduces
a bit of open-coding and makes the logic easier reusable for any
potential DMI platform != Quark.

Tested on IOT2000 and Galileo Gen2.

Changes in v5:
 - fixed a remaining issue in patch 5
 - dropped patch 6 for now
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 53fa1a6f 8d78b690
...@@ -30,42 +30,39 @@ ...@@ -30,42 +30,39 @@
* negative value of the address means that MAC controller is not connected * negative value of the address means that MAC controller is not connected
* with PHY. * with PHY.
*/ */
struct stmmac_pci_dmi_data { struct stmmac_pci_func_data {
const char *name;
const char *asset_tag;
unsigned int func; unsigned int func;
int phy_addr; int phy_addr;
}; };
struct stmmac_pci_dmi_data {
const struct stmmac_pci_func_data *func;
size_t nfuncs;
};
struct stmmac_pci_info { struct stmmac_pci_info {
struct pci_dev *pdev; int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
int (*setup)(struct plat_stmmacenet_data *plat,
struct stmmac_pci_info *info);
struct stmmac_pci_dmi_data *dmi;
}; };
static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info) static int stmmac_pci_find_phy_addr(struct pci_dev *pdev,
const struct dmi_system_id *dmi_list)
{ {
const char *name = dmi_get_system_info(DMI_BOARD_NAME); const struct stmmac_pci_func_data *func_data;
const char *asset_tag = dmi_get_system_info(DMI_BOARD_ASSET_TAG); const struct stmmac_pci_dmi_data *dmi_data;
unsigned int func = PCI_FUNC(info->pdev->devfn); const struct dmi_system_id *dmi_id;
struct stmmac_pci_dmi_data *dmi; int func = PCI_FUNC(pdev->devfn);
size_t n;
dmi_id = dmi_first_match(dmi_list);
if (!dmi_id)
return -ENODEV;
/* dmi_data = dmi_id->driver_data;
* Galileo boards with old firmware don't support DMI. We always return func_data = dmi_data->func;
* 1 here, so at least first found MAC controller would be probed.
*/
if (!name)
return 1;
for (dmi = info->dmi; dmi->name && *dmi->name; dmi++) { for (n = 0; n < dmi_data->nfuncs; n++, func_data++)
if (!strcmp(dmi->name, name) && dmi->func == func) { if (func_data->func == func)
/* If asset tag is provided, match on it as well. */ return func_data->phy_addr;
if (dmi->asset_tag && strcmp(dmi->asset_tag, asset_tag))
continue;
return dmi->phy_addr;
}
}
return -ENODEV; return -ENODEV;
} }
...@@ -100,7 +97,8 @@ static void common_default_data(struct plat_stmmacenet_data *plat) ...@@ -100,7 +97,8 @@ static void common_default_data(struct plat_stmmacenet_data *plat)
plat->rx_queues_cfg[0].pkt_route = 0x0; plat->rx_queues_cfg[0].pkt_route = 0x0;
} }
static void stmmac_default_data(struct plat_stmmacenet_data *plat) static int stmmac_default_data(struct pci_dev *pdev,
struct plat_stmmacenet_data *plat)
{ {
/* Set common default data first */ /* Set common default data first */
common_default_data(plat); common_default_data(plat);
...@@ -112,12 +110,77 @@ static void stmmac_default_data(struct plat_stmmacenet_data *plat) ...@@ -112,12 +110,77 @@ static void stmmac_default_data(struct plat_stmmacenet_data *plat)
plat->dma_cfg->pbl = 32; plat->dma_cfg->pbl = 32;
plat->dma_cfg->pblx8 = true; plat->dma_cfg->pblx8 = true;
/* TODO: AXI */ /* TODO: AXI */
return 0;
} }
static int quark_default_data(struct plat_stmmacenet_data *plat, static const struct stmmac_pci_info stmmac_pci_info = {
struct stmmac_pci_info *info) .setup = stmmac_default_data,
};
static const struct stmmac_pci_func_data galileo_stmmac_func_data[] = {
{
.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[] = {
{
.func = 6,
.phy_addr = 1,
},
{
.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[] = {
{
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Galileo"),
},
.driver_data = (void *)&galileo_stmmac_dmi_data,
},
{
.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,
},
{}
};
static int quark_default_data(struct pci_dev *pdev,
struct plat_stmmacenet_data *plat)
{ {
struct pci_dev *pdev = info->pdev;
int ret; int ret;
/* Set common default data first */ /* Set common default data first */
...@@ -127,10 +190,20 @@ static int quark_default_data(struct plat_stmmacenet_data *plat, ...@@ -127,10 +190,20 @@ static int quark_default_data(struct plat_stmmacenet_data *plat,
* Refuse to load the driver and register net device if MAC controller * Refuse to load the driver and register net device if MAC controller
* does not connect to any PHY interface. * does not connect to any PHY interface.
*/ */
ret = stmmac_pci_find_phy_addr(info); ret = stmmac_pci_find_phy_addr(pdev, quark_pci_dmi);
if (ret < 0) if (ret < 0) {
/* Return error to the caller on DMI enabled boards. */
if (dmi_get_system_info(DMI_BOARD_NAME))
return ret; return ret;
/*
* Galileo boards with old firmware don't support DMI. We always
* use 1 here as PHY address, so at least the first found MAC
* controller would be probed.
*/
ret = 1;
}
plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn); plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
plat->phy_addr = ret; plat->phy_addr = ret;
plat->interface = PHY_INTERFACE_MODE_RMII; plat->interface = PHY_INTERFACE_MODE_RMII;
...@@ -143,41 +216,8 @@ static int quark_default_data(struct plat_stmmacenet_data *plat, ...@@ -143,41 +216,8 @@ static int quark_default_data(struct plat_stmmacenet_data *plat,
return 0; return 0;
} }
static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = { static const struct stmmac_pci_info quark_pci_info = {
{
.name = "Galileo",
.func = 6,
.phy_addr = 1,
},
{
.name = "GalileoGen2",
.func = 6,
.phy_addr = 1,
},
{
.name = "SIMATIC IOT2000",
.asset_tag = "6ES7647-0AA00-0YA2",
.func = 6,
.phy_addr = 1,
},
{
.name = "SIMATIC IOT2000",
.asset_tag = "6ES7647-0AA00-1YA2",
.func = 6,
.phy_addr = 1,
},
{
.name = "SIMATIC IOT2000",
.asset_tag = "6ES7647-0AA00-1YA2",
.func = 7,
.phy_addr = 1,
},
{}
};
static struct stmmac_pci_info quark_pci_info = {
.setup = quark_default_data, .setup = quark_default_data,
.dmi = quark_pci_dmi_data,
}; };
/** /**
...@@ -236,15 +276,9 @@ static int stmmac_pci_probe(struct pci_dev *pdev, ...@@ -236,15 +276,9 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
pci_set_master(pdev); pci_set_master(pdev);
if (info) { ret = info->setup(pdev, plat);
info->pdev = pdev;
if (info->setup) {
ret = info->setup(plat, info);
if (ret) if (ret)
return ret; return ret;
}
} else
stmmac_default_data(plat);
pci_enable_msi(pdev); pci_enable_msi(pdev);
...@@ -270,14 +304,21 @@ static void stmmac_pci_remove(struct pci_dev *pdev) ...@@ -270,14 +304,21 @@ static void stmmac_pci_remove(struct pci_dev *pdev)
static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume); static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume);
#define STMMAC_VENDOR_ID 0x700 /* synthetic ID, no official vendor */
#define PCI_VENDOR_ID_STMMAC 0x700
#define STMMAC_QUARK_ID 0x0937 #define STMMAC_QUARK_ID 0x0937
#define STMMAC_DEVICE_ID 0x1108 #define STMMAC_DEVICE_ID 0x1108
#define STMMAC_DEVICE(vendor_id, dev_id, info) { \
PCI_VDEVICE(vendor_id, dev_id), \
.driver_data = (kernel_ulong_t)&info \
}
static const struct pci_device_id stmmac_id_table[] = { static const struct pci_device_id stmmac_id_table[] = {
{PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)}, STMMAC_DEVICE(STMMAC, STMMAC_DEVICE_ID, stmmac_pci_info),
{PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)}, STMMAC_DEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_MAC, stmmac_pci_info),
{PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info}, STMMAC_DEVICE(INTEL, STMMAC_QUARK_ID, quark_pci_info),
{} {}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment