From patchwork Tue May 30 07:33:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 768421 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wcQN62gr0z9ryb for ; Tue, 30 May 2017 17:34:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751204AbdE3Hdl (ORCPT ); Tue, 30 May 2017 03:33:41 -0400 Received: from thoth.sbs.de ([192.35.17.2]:47188 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750897AbdE3Hdd (ORCPT ); Tue, 30 May 2017 03:33:33 -0400 Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id v4U7XS2N014760 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 May 2017 09:33:28 +0200 Received: from md1f2u6c.ww002.siemens.net ([146.254.78.6]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id v4U7XQcP020697; Tue, 30 May 2017 09:33:28 +0200 From: Jan Kiszka To: Giuseppe Cavallaro , Alexandre Torgue , David Miller Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: [PATCH v3 5/6] stmmac: pci: Use dmi_system_id table for retrieving PHY addresses Date: Tue, 30 May 2017 09:33:24 +0200 Message-Id: <1ec11df8a4860215c93125f83a04c8c00482a041.1496129604.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: References: In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Avoids reimplementation of DMI matching in stmmac_pci_find_phy_addr. Signed-off-by: Jan Kiszka --- drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 77 ++++++++++++++---------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c index a6e10d3ced5c..a3909ab0da05 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c @@ -31,9 +31,7 @@ * with PHY. */ struct stmmac_pci_dmi_data { - const char *name; - const char *asset_tag; - unsigned int func; + int func; int phy_addr; }; @@ -42,24 +40,19 @@ struct stmmac_pci_info { }; 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; + const struct stmmac_pci_dmi_data *dmi_data; + const struct dmi_system_id *dmi_id; + int func = PCI_FUNC(pdev->devfn); - if (!name) + 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; - } - } + for (dmi_data = dmi_id->driver_data; dmi_data->func >= 0; dmi_data++) + if (dmi_data->func == func) + return dmi_data->phy_addr; return -ENODEV; } @@ -115,34 +108,54 @@ 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_dmi_data galileo_stmmac_dmi_data[] = { { - .name = "Galileo", .func = 6, .phy_addr = 1, }, + {-1, -1}, +}; + +static const struct stmmac_pci_dmi_data iot2040_stmmac_dmi_data[] = { { - .name = "GalileoGen2", .func = 6, .phy_addr = 1, }, { - .name = "SIMATIC IOT2000", - .asset_tag = "6ES7647-0AA00-0YA2", - .func = 6, + .func = 7, .phy_addr = 1, }, + {-1, -1}, +}; + +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, }, {} }; @@ -159,7 +172,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))