From patchwork Tue Oct 12 07:03:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 67510 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 1CD83B6EF1 for ; Tue, 12 Oct 2010 18:04:36 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755064Ab0JLHE2 (ORCPT ); Tue, 12 Oct 2010 03:04:28 -0400 Received: from dalsmrelay2.nai.com ([205.227.136.216]:64482 "HELO dalsmrelay2.nai.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751825Ab0JLHE1 (ORCPT ); Tue, 12 Oct 2010 03:04:27 -0400 Received: from (unknown [10.64.5.51]) by dalsmrelay2.nai.com with smtp id 7e07_186a_f308e8ae_d5ce_11df_9a05_00219b929abd; Tue, 12 Oct 2010 07:04:26 +0000 Received: from dalexbr1.corp.nai.org (161.69.111.81) by DALEXHT1.corp.nai.org (10.64.5.51) with Microsoft SMTP Server id 8.2.254.0; Tue, 12 Oct 2010 02:04:25 -0500 Received: from sncexbr1.corp.nai.org ([161.69.5.246]) by dalexbr1.corp.nai.org with Microsoft SMTPSVC(6.0.3790.3959); Tue, 12 Oct 2010 02:04:24 -0500 Received: from STPSMTP01.scur.com ([10.96.96.163]) by sncexbr1.corp.nai.org with Microsoft SMTPSVC(6.0.3790.3959); Tue, 12 Oct 2010 00:04:23 -0700 Received: from cyberguard.com.au ([10.46.129.16]) by STPSMTP01.scur.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 12 Oct 2010 02:04:23 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by bne.snapgear.com (Postfix) with ESMTP id BAA1BEBACC; Tue, 12 Oct 2010 17:04:21 +1000 (EST) X-Virus-Scanned: amavisd-new at snapgear.com Received: from bne.snapgear.com ([127.0.0.1]) by localhost (bne.snapgear.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 768jGxRe0Qh8; Tue, 12 Oct 2010 17:04:13 +1000 (EST) Received: from snapgear.com (bnelabfw.scur.com [10.46.129.16]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by bne.snapgear.com (Postfix) with ESMTP; Tue, 12 Oct 2010 17:04:13 +1000 (EST) Received: from goober.internal.moreton.com.au (localhost [127.0.0.1]) by snapgear.com (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id o9C736iR026820; Tue, 12 Oct 2010 17:03:06 +1000 Received: (from gerg@localhost) by goober.internal.moreton.com.au (8.14.3/8.14.3/Submit) id o9C735Jd026818; Tue, 12 Oct 2010 17:03:05 +1000 Date: Tue, 12 Oct 2010 17:03:05 +1000 From: Greg Ungerer Message-ID: <201010120703.o9C735Jd026818@goober.internal.moreton.com.au> CC: Subject: [PATCH] net: allow FEC driver to use fixed PHY support To: X-Mailer: mail (GNU Mailutils 2.1) X-OriginalArrivalTime: 12 Oct 2010 07:04:23.0476 (UTC) FILETIME=[B3291740:01CB69DB] MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org At least one board using the FEC driver does not have a conventional PHY attached to it, it is directly connected to a somewhat simple ethernet switch (the board is the SnapGear/LITE, and the attached 4-port ethernet switch is a RealTek RTL8305). This switch does not present the usual register interface of a PHY, it presents nothing. So a PHY scan will find nothing - it finds ID's of 0 for each PHY on the attached MII bus. After the FEC driver was changed to use phylib for supporting PHYs it no longer works on this particular board/switch setup. Add code support to use a fixed phy if no PHY is found on the MII bus. This is based on the way the cpmac.c driver solved this same problem. Signed-off-by: Greg Ungerer --- drivers/net/fec.c | 41 +++++++++++++++++++++++++++-------------- 1 files changed, 27 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/fec.c b/drivers/net/fec.c index 768b840..f45dc63 100644 --- a/drivers/net/fec.c +++ b/drivers/net/fec.c @@ -678,24 +678,37 @@ static int fec_enet_mii_probe(struct net_device *dev) { struct fec_enet_private *fep = netdev_priv(dev); struct phy_device *phy_dev = NULL; - int ret; + char mdio_bus_id[MII_BUS_ID_SIZE]; + char phy_name[MII_BUS_ID_SIZE + 3]; + int phy_id; fep->phy_dev = NULL; - /* find the first phy */ - phy_dev = phy_find_first(fep->mii_bus); - if (!phy_dev) { - printk(KERN_ERR "%s: no PHY found\n", dev->name); - return -ENODEV; + /* check for attached phy */ + for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) { + if ((fep->mii_bus->phy_mask & (1 << phy_id))) + continue; + if (fep->mii_bus->phy_map[phy_id] == NULL) + continue; + if (fep->mii_bus->phy_map[phy_id]->phy_id == 0) + continue; + strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE); + break; } - /* attach the mac to the phy */ - ret = phy_connect_direct(dev, phy_dev, - &fec_enet_adjust_link, 0, - PHY_INTERFACE_MODE_MII); - if (ret) { - printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); - return ret; + if (phy_id >= PHY_MAX_ADDR) { + printk(KERN_INFO "%s: no PHY, assuming direct connection " + "to switch\n", dev->name); + strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE); + phy_id = 0; + } + + snprintf(phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id); + phy_dev = phy_connect(dev, phy_name, &fec_enet_adjust_link, 0, + PHY_INTERFACE_MODE_MII); + if (IS_ERR(phy_dev)) { + printk(KERN_ERR "%s: could not attach to PHY\n", dev->name); + return PTR_ERR(phy_dev); } /* mask with MAC supported features */ @@ -738,7 +751,7 @@ static int fec_enet_mii_init(struct platform_device *pdev) fep->mii_bus->read = fec_enet_mdio_read; fep->mii_bus->write = fec_enet_mdio_write; fep->mii_bus->reset = fec_enet_mdio_reset; - snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id); + snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id + 1); fep->mii_bus->priv = fep; fep->mii_bus->parent = &pdev->dev;