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: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
0c461e050c
|
@ -30,42 +30,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_info {
|
||||
struct pci_dev *pdev;
|
||||
int (*setup)(struct plat_stmmacenet_data *plat,
|
||||
struct stmmac_pci_info *info);
|
||||
struct stmmac_pci_dmi_data *dmi;
|
||||
struct stmmac_pci_dmi_data {
|
||||
const struct stmmac_pci_func_data *func;
|
||||
size_t nfuncs;
|
||||
};
|
||||
|
||||
static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info)
|
||||
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,
|
||||
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(info->pdev->devfn);
|
||||
struct stmmac_pci_dmi_data *dmi;
|
||||
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;
|
||||
|
||||
/*
|
||||
* Galileo boards with old firmware don't support DMI. We always return
|
||||
* 1 here, so at least first found MAC controller would be probed.
|
||||
*/
|
||||
if (!name)
|
||||
return 1;
|
||||
dmi_id = dmi_first_match(dmi_list);
|
||||
if (!dmi_id)
|
||||
return -ENODEV;
|
||||
|
||||
for (dmi = info->dmi; 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;
|
||||
}
|
||||
|
@ -100,7 +97,8 @@ static void common_default_data(struct plat_stmmacenet_data *plat)
|
|||
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 */
|
||||
common_default_data(plat);
|
||||
|
@ -112,12 +110,77 @@ static void stmmac_default_data(struct plat_stmmacenet_data *plat)
|
|||
plat->dma_cfg->pbl = 32;
|
||||
plat->dma_cfg->pblx8 = true;
|
||||
/* TODO: AXI */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int quark_default_data(struct plat_stmmacenet_data *plat,
|
||||
struct stmmac_pci_info *info)
|
||||
static const struct stmmac_pci_info stmmac_pci_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;
|
||||
|
||||
/* Set common default data first */
|
||||
|
@ -127,9 +190,19 @@ static int quark_default_data(struct plat_stmmacenet_data *plat,
|
|||
* 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(info);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
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))
|
||||
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->phy_addr = ret;
|
||||
|
@ -143,41 +216,8 @@ static int quark_default_data(struct plat_stmmacenet_data *plat,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
|
||||
{
|
||||
.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 = {
|
||||
static const struct stmmac_pci_info quark_pci_info = {
|
||||
.setup = quark_default_data,
|
||||
.dmi = quark_pci_dmi_data,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -236,15 +276,9 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
|
|||
|
||||
pci_set_master(pdev);
|
||||
|
||||
if (info) {
|
||||
info->pdev = pdev;
|
||||
if (info->setup) {
|
||||
ret = info->setup(plat, info);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
} else
|
||||
stmmac_default_data(plat);
|
||||
ret = info->setup(pdev, plat);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
pci_enable_msi(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);
|
||||
|
||||
#define STMMAC_VENDOR_ID 0x700
|
||||
/* synthetic ID, no official vendor */
|
||||
#define PCI_VENDOR_ID_STMMAC 0x700
|
||||
|
||||
#define STMMAC_QUARK_ID 0x0937
|
||||
#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[] = {
|
||||
{PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
|
||||
{PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
|
||||
{PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
|
||||
STMMAC_DEVICE(STMMAC, STMMAC_DEVICE_ID, stmmac_pci_info),
|
||||
STMMAC_DEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_MAC, stmmac_pci_info),
|
||||
STMMAC_DEVICE(INTEL, STMMAC_QUARK_ID, quark_pci_info),
|
||||
{}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue